import{i as e}from"./vendor-vue-D9nMs6_1.js";import{i as t}from"./backendApi-CRLUmnjv.js";var n={thin:`100`,extralight:`200`,light:`300`,regular:`400`,normal:`400`,medium:`500`,semibold:`600`,bold:`700`,extrabold:`800`,black:`900`};function r(t){let{fetchJson:r,menuUrl:i,fallbackVariants:a=[`400`,`700`]}=t,o=new Map,s=[1e3,4e3,15e3],c=e=>new Promise(t=>setTimeout(t,e));function l(e){return{family:e,variants:[...a],files:{},category:`sans-serif`,kind:`webfonts#webfont`,menu:``}}async function u(e){let t=new FontFace(e.family,`url(${i(e)})`);await t.load(),document.fonts.add(t)}async function d(e,t){let r=[];for(let i of t.variants){let a=t.files[i];if(!a){console.warn(`URL not found for variant: ${i} of font ${e}`);continue}let o=`normal`,s=i;i.endsWith(`italic`)&&(o=`italic`,s=i.replace(`italic`,``),s===``&&(s=`regular`));let c=n[s]||s;if(!/^\d+$|^(normal|bold|lighter|bolder)$/.test(c)){console.warn(`Invalid font weight derived: '${c}' from variant '${i}' for font ${e}. Skipping.`);continue}let l=new FontFace(e,`url(${a})`,{weight:c,style:o});r.push(l.load().then(e=>{document.fonts.add(e)}).catch(t=>{console.error(`Failed to load variant ${i} for font ${e}:`,t)}))}await Promise.all(r)}async function f(e){let t=await r(`/fonts/${e.replace(` `,`+`)}`);if(!t||!t.family||!t.variants||!t.files)throw Error(`Incomplete font data received for "${e}"`);return i?await u(t):await d(e,t),t}return e(`font`,{state(){return{CachedFonts:{Arial:l(`Arial`)},GoogleFonts:[],LocalFonts:[],WebSafeFonts:[`Arial`,`Arial Black`,`Comic Sans MS`,`Courier New`,`Georgia`,`Impact`,`Lucida Console`,`Lucida Sans Unicode`,`Palatino Linotype`,`Tahoma`,`Times New Roman`,`Trebuchet MS`,`Verdana`],LoadingFonts:[]}},getters:{getFont:e=>t=>e.CachedFonts[t],getGoogleFonts:e=>e.GoogleFonts,getLocalFonts:e=>e.LocalFonts,getWebSafeFonts:e=>e.WebSafeFonts,getAllFonts:e=>[...e.GoogleFonts,...e.LocalFonts,...e.WebSafeFonts],hasFont:e=>t=>e.CachedFonts[t]!==void 0||e.WebSafeFonts.includes(t),isLoading:e=>t=>e.LoadingFonts.includes(t)},actions:{async fetchAllFontsAsync(){r(`/fonts`).then(e=>{let t=e;this.GoogleFonts=t.google,this.LocalFonts=t.local,this.WebSafeFonts=t.browser})},async fetchFontAsync(e){if(!e||e.trim().startsWith(`var(`))return this.CachedFonts.Arial;if(this.CachedFonts[e])return this.CachedFonts[e];let t=o.get(e);if(t)return t;let n=f(e);o.set(e,n),this.LoadingFonts.push(e);try{let t=await n;return this.CachedFonts[e]=t,t}catch(t){throw this.CachedFonts[e]=l(e),(async()=>{for(let t of s){await c(t);try{this.CachedFonts[e]=await f(e);return}catch{}}console.warn(`Font "${e}" unavailable after ${s.length+1} attempts, falling back.`)})(),t}finally{o.delete(e),this.LoadingFonts=this.LoadingFonts.filter(t=>t!==e)}}}})}var i=r({fetchJson:e=>t.get(e).then(e=>e.data)});export{i as t};