UNPKG

@expofp/floorplan

Version:

Interactive floor plan library for expos and events

2 lines (1 loc) 1.48 kB
import r from"fontfaceobserver";import{FONT_FACE as c}from"../constants";import i from"../utils/browser";export async function loadJson(t){return await(await fetch(t,{credentials:"same-origin"})).json()}export function loadCss(t,o){const e=document.createElement("link");e.rel="stylesheet",e.href=t,e.setAttribute("fetchpriority","high"),o.appendChild(e)}export async function loadFont(t,o,e){e={style:"normal",weight:"normal",...e||{}};const s=`url("${o}")`;if(!window.FontFace)return t.startsWith("Font Awesome")||a(t,s,e),Promise.resolve();t.indexOf(" ")!==-1&&i.getEngine()?.name==="Gecko"&&(t=`'${t}'`);let n;try{n=new FontFace(t,s,e)}catch{n=new FontFace(`'${t}'`,s,e)}return document.fonts.add(n),n.load()}function a(t,o,e){const s=document.createElement("style");s.appendChild(document.createTextNode(`@font-face { font-family: ${t}; font-weight: ${e.weight}; font-style: ${e.style}; src: ${o} format('woff2'); font-display: swap; }`)),document.head.appendChild(s);const n=document.createElement("div");n.setAttribute("style",`font-family: oswald; font-weight: ${e.weight}; position: fixed; left: -1000px; top: 0; visibility: hidden`),n.innerHTML="Oswald",document.body.appendChild(n)}export async function loadCustomFonts(t){const o=getComputedStyle(document.documentElement).getPropertyValue(c)||t.match(/--expofp-font-face:\s*([^;]*)/)?.[1];if(!o)return;const s=o.replace(/"/g,"").split(", ").map(n=>n.trim()).map(n=>new r(n).load());return Promise.allSettled(s)}