async function B(t){if(t instanceof ArrayBuffer)return t;if(t instanceof Uint8Array){let o=new ArrayBuffer(t.byteLength);return new Uint8Array(o).set(t),o}if(t instanceof Blob)return t.arrayBuffer();throw new TypeError(`Unsupported DocxInput type: ${typeof t}`)}var l=new Set,f=new Map,u=new Set,d=false;function h(t,o=[400,700],n=["normal","italic"]){let e=encodeURIComponent(t),s=[];for(let r of n){let i=r==="italic"?1:0;for(let c of o)s.push(`${i},${c}`);}s.sort();let a=s.join(";");return `https://fonts.googleapis.com/css2?family=${e}:ital,wght@${a}&display=swap`}async function m(t,o){if(typeof document>"u")return  false;let n=t.trim();if(l.has(n))return  true;let e=f.get(n);if(e)return e;let s=(async()=>{d=true;try{let a=h(n,o?.weights,o?.styles),r=document.createElement("link");return r.rel="stylesheet",r.href=a,await new Promise(c=>{r.onload=()=>c(!0),r.onerror=()=>c(!1),document.head.appendChild(r),setTimeout(()=>c(!1),5e3);})?(await p(n,3e3),l.add(n),y([n]),!0):!1}catch(a){return console.warn(`Failed to load font "${n}":`,a),false}finally{f.delete(n),f.size===0&&(d=false);}})();return f.set(n,s),s}async function w(t,o){let n=t.filter(e=>!l.has(e.trim()));n.length!==0&&await Promise.all(n.map(e=>m(e,o)));}function S(t){return l.has(t.trim())}function $(){return d}function L(){return Array.from(l)}function T(t){return u.add(t),()=>{u.delete(t);}}function y(t){for(let o of u)try{o(t);}catch(n){console.warn("Font load callback error:",n);}}async function p(t,o){if("fonts"in document)try{let n=`400 16px "${t}"`;return await Promise.race([document.fonts.load(n),new Promise(e=>setTimeout(e,o))]),document.fonts.check(n)}catch{}return await new Promise(n=>setTimeout(n,100)),true}function v(t,o="sans-serif"){if(typeof document>"u")return  false;let n=(s,a)=>{let i=document.createElement("canvas").getContext("2d");if(!i)return  false;i.textBaseline="top";let c="abcdefghijklmnopqrstuvwxyz0123456789";i.font=`72px ${a}`;let g=i.measureText(c).width;return i.font=`72px "${s}", ${a}`,i.measureText(c).width!==g};return n(t,o)?true:n(t,o==="sans-serif"?"serif":"sans-serif")}async function G(t,o,n){let e=t.trim();if(l.has(e))return  true;try{let s=new Blob([o],{type:"font/ttf"}),a=URL.createObjectURL(s),r=document.createElement("style");return r.textContent=`
      @font-face {
        font-family: "${e}";
        src: url(${a}) format('truetype');
        font-weight: ${n?.weight??"normal"};
        font-style: ${n?.style??"normal"};
        font-display: swap;
      }
    `,document.head.appendChild(r),await p(e,3e3),l.add(e),y([e]),!0}catch(s){return console.warn(`Failed to load font "${e}" from buffer:`,s),false}}var F={Calibri:"Carlito",Cambria:"Caladea",Arial:"Arimo","Times New Roman":"Tinos","Courier New":"Cousine",Garamond:"EB Garamond","Book Antiqua":"EB Garamond",Georgia:"Tinos",Verdana:"Open Sans",Tahoma:"Open Sans","Trebuchet MS":"Source Sans Pro","Century Gothic":"Poppins","Franklin Gothic":"Libre Franklin",Palatino:"EB Garamond","Palatino Linotype":"EB Garamond","Lucida Sans":"Open Sans","Segoe UI":"Open Sans",Impact:"Anton","Comic Sans MS":"Comic Neue",Consolas:"Inconsolata","Lucida Console":"Inconsolata",Monaco:"Fira Code"};function b(t){let o=t.trim();return F[o]||o}async function x(t){let o=t.trim(),n=b(o);if(n!==o){let e=await m(n);return e&&l.add(o),e}return m(n)}async function A(t){let o=[...new Set(t.map(n=>n.trim()))];await Promise.all(o.map(n=>x(n)));}async function E(){await w(["Carlito","Caladea","Arimo","Tinos","Cousine","EB Garamond"]);}function P(t){let o=new Set,n=t;if(!n?.package)return o;let e=n.package?.document?.content;if(Array.isArray(e)){for(let a of e)if(a?.type==="paragraph"&&Array.isArray(a.content)){for(let r of a.content)if(r?.type==="run"&&r.formatting?.fontFamily){let{ascii:i,hAnsi:c}=r.formatting.fontFamily;i&&o.add(i),c&&c!==i&&o.add(c);}}}let s=n.package?.styles?.styles;if(Array.isArray(s)){for(let a of s)if(a?.runProperties?.fontFamily){let{ascii:r,hAnsi:i}=a.runProperties.fontFamily;r&&o.add(r),i&&i!==r&&o.add(i);}}return o}async function I(t){let o=P(t);o.size!==0&&await A(Array.from(o));}export{B as a,m as b,w as c,S as d,$ as e,L as f,T as g,v as h,G as i,A as j,E as k,I as l};