var gdjs;(function(i){const s=new i.Logger("Font manager"),d=["font"];class l{constructor(e){this._loadedFontFamily=new i.ResourceCache;this._loadedFontFamilySet=new Set;this._resourceLoader=e}getResourceKinds(){return d}getFontFamily(e){return this._loadedFontFamily.getFromName(e)||"Arial"}getFontFile(e){const t=this._resourceLoader.getResource(e);return t?t.file||"":e}_getFontFamilyFromFilename(e){let t="gdjs_font_"+e.file.toLowerCase().replace(/[^\w]/gi,"-");const o=t;let n=2;for(;this._loadedFontFamilySet.has(t);)t=t+"-"+n,n++;return o}_loadFont(e,t){const o={},n="url("+encodeURI(t)+")";if(typeof FontFace!="undefined")return fetch(this._resourceLoader.getFullUrl(t),{credentials:this._resourceLoader.checkIfCredentialsRequired(t)?"include":"same-origin"}).then(r=>{if(!r.ok){const a="Unable to fetch "+t+" to be loaded as a font. HTTP status is: "+r.status+".";throw s.error(a),new Error(a)}return r.arrayBuffer()}).then(r=>{const a=new FontFace(e,r,o);document.fonts.add(a)});{const r=document.createElement("style");return r.appendChild(document.createTextNode("@font-face { font-family: '"+e+"'; src: "+n+"; }")),document.head.appendChild(r),new FontFaceObserver(e,o).load()}}async processResource(e){}async loadResource(e){const t=this._resourceLoader.getResource(e);if(!t){s.warn('Unable to find font for resource "'+e+'".');return}if(this._loadedFontFamily.get(t))return;const o=t.file;if(!o)return;const n=this._getFontFamilyFromFilename(t);this._loadedFontFamily.set(t,n),this._loadedFontFamilySet.add(n);try{await this._loadFont(n,o)}catch(r){throw s.error('Error loading font resource "'+t.name+'" (file: '+o+"): "+(r.message||"Unknown error")),r}}dispose(){this._loadedFontFamily.clear(),this._loadedFontFamilySet.clear()}unloadResource(e){this._loadedFontFamily.getFromName(e.name)&&this._loadedFontFamily.delete(e);const o=this._getFontFamilyFromFilename(e);o&&this._loadedFontFamilySet.delete(o)}}i.FontFaceObserverFontManager=l,i.FontManager=l})(gdjs||(gdjs={}));
//# sourceMappingURL=fontfaceobserver-font-manager.js.map
