var S=Object.defineProperty;var b=e=>{throw TypeError(e)};var $=(e,t,a)=>t in e?S(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a;var d=(e,t,a)=>$(e,typeof t!="symbol"?t+"":t,a),M=(e,t,a)=>t.has(e)||b("Cannot "+a);var C=(e,t,a)=>(M(e,t,"read from private field"),a?a.call(e):t.get(e)),_=(e,t,a)=>t.has(e)?b("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,a),E=(e,t,a,s)=>(M(e,t,"write to private field"),s?s.call(e,a):t.set(e,a),a);import{_ as k}from"./preload-helper-2LWRYvkK.js";function R(){typeof globalThis.DOMMatrix<"u"||(globalThis.DOMMatrix=class{constructor(t){d(this,"a");d(this,"b");d(this,"c");d(this,"d");d(this,"e");d(this,"f");Array.isArray(t)&&t.length===6?(this.a=t[0],this.b=t[1],this.c=t[2],this.d=t[3],this.e=t[4],this.f=t[5]):(this.a=1,this.b=0,this.c=0,this.d=1,this.e=0,this.f=0)}translateSelf(t,a=0){return this.e=this.a*t+this.c*a+this.e,this.f=this.b*t+this.d*a+this.f,this}scaleSelf(t,a=t){return this.a*=t,this.b*=t,this.c*=a,this.d*=a,this}})}function U(){R()}let y;var F,I;const T=((I=(F=globalThis.process)==null?void 0:F.release)==null?void 0:I.name)==="node",B=typeof window<"u";async function g(e,t={}){const{getDocument:a}=await v();let s={};if(T)try{const r=import.meta.resolve("pdfjs-dist/package.json");s={disableFontFace:!0,standardFontDataUrl:new URL("./standard_fonts/",r).href}}catch{}return await a({data:e,isEvalSupported:!1,useSystemFonts:!0,...s,...t}).promise}async function v(){return y||await f(),y}async function f(e,{reload:t=!1}={}){if(!(y&&!t)){if(U(),e)try{y=await O(e());return}catch(a){throw new Error(`PDF.js could not be resolved: ${a}`)}try{y=await k(()=>import("./pdfjs-wNX4mDgf.js"),[])}catch(a){throw new Error(`Serverless PDF.js bundle could not be resolved: ${a}`)}}}function w(e){return typeof e=="object"&&e!==null&&"_pdfInfo"in e}async function O(e){const t=await e;return t.default||t}let h;/**
 * Derived from the PDF.js project by the Mozilla Foundation.
 * @see https://github.com/mozilla/pdf.js/blob/b8de9a372f9bbf7e33adb362eeae5ef1919dba73/src/display/canvas_factory.js#L18
 * @license Apache-2.0
 */var P;class j{constructor({enableHWA:t=!1}={}){_(this,P,!1);E(this,P,t)}create(t,a){const s=this._createCanvas(t,a);return{canvas:s,context:s.getContext("2d",{willReadFrequently:!C(this,P)})}}reset({canvas:t},a,s){if(!t)throw new Error("Canvas is not specified");t.width=a,t.height=s}destroy(t){if(!t.canvas)throw new Error("Canvas is not specified");t.canvas.width=0,t.canvas.height=0,t.canvas=void 0,t.context=void 0}_createCanvas(t,a){throw new Error("Not implemented")}}P=new WeakMap;/**
 * Derived from the PDF.js project by the Mozilla Foundation.
 * @see https://github.com/mozilla/pdf.js/blob/b8de9a372f9bbf7e33adb362eeae5ef1919dba73/src/display/canvas_factory.js#L18
 * @license Apache-2.0
 */class N extends j{constructor({ownerDocument:a=globalThis.document,enableHWA:s=!1}={}){super({enableHWA:s});d(this,"_document");this._document=a}_createCanvas(a,s){const n=this._document.createElement("canvas");return n.width=a,n.height=s,n}}class V extends j{constructor({enableHWA:t=!1}={}){super({enableHWA:t})}_createCanvas(t,a){if(!h)throw new Error("@napi-rs/canvas module is not resolved");return h.createCanvas(t,a)}}async function J(e){h??(h=await O(e()))}function q(){h&&(globalThis.DOMMatrix=h.DOMMatrix,typeof globalThis.ImageData>"u"&&(globalThis.ImageData=h.ImageData),typeof globalThis.Path2D>"u"&&(globalThis.Path2D=h.Path2D))}async function W(e,t){const a=w(e)?e:await g(e);if(t<1||t>a.numPages)throw new Error(`Invalid page number. Must be between 1 and ${a.numPages}.`);const s=await a.getPage(t),n=await s.getOperatorList(),{OPS:r}=await v(),c=[];for(let i=0;i<n.fnArray.length;i++){if(n.fnArray[i]!==r.paintImageXObject)continue;const o=n.argsArray[i][0],u=await new Promise(L=>(o.startsWith("g_")?s.commonObjs:s.objs).get(o,L));if(!u||!u.data||!u.width||!u.height)continue;const{width:m,height:p,data:D}=u,x=D.length/(m*p);if(![1,3,4].includes(x))continue;const A=x;c.push({data:D,width:m,height:p,channels:A,key:o})}return c}async function X(e,t,a={}){const s=await z(a.canvasImport),n=w(e)?e:await g(e,{CanvasFactory:s}),r=await n.getPage(t);if(t<1||t>n.numPages)throw new Error(`Invalid page number. Must be between 1 and ${n.numPages}.`);const c=r.getViewport({scale:1});let i=a.scale||1;a.width?i=a.width/c.width:a.height&&(i=a.height/c.height);const l=r.getViewport({scale:Math.max(0,i)}),o=new s().create(l.width,l.height);await r.render({canvas:o.canvas,canvasContext:o.context,viewport:l}).promise;const u=o.canvas.toDataURL();return a.toDataURL?u:await(await fetch(u)).arrayBuffer()}async function z(e){if(B)return N;if(T){if(!e)throw new Error('Parameter "canvasImport" is required in Node.js environment.');return await J(e),q(),V}throw new Error("Unsupported environment for canvas creation.")}async function G(e){const t=w(e)?e:await g(e),a=await Promise.all(Array.from({length:t.numPages},(s,n)=>H(t,n+1)));return{totalPages:t.numPages,links:a.flat()}}async function H(e,t){const s=await(await e.getPage(t)).getAnnotations(),n=[];for(const r of s)r.subtype==="Link"&&r.url&&n.push(r.url);return n}const K=["xmp:createdate","xmp:modifydate","xmp:metadatadate","xap:createdate","xap:modifydate","xap:metadatadate"];async function Q(e,t={}){const s=await(w(e)?e:await g(e)).getMetadata(),n=(s==null?void 0:s.info)||{};if(t.parseDates){const{PDFDateString:r}=await v();n!=null&&n.CreationDate&&(n.CreationDate=r.toDateObject(n==null?void 0:n.CreationDate)),n!=null&&n.ModDate&&(n.ModDate=r.toDateObject(n==null?void 0:n.ModDate)),s.metadata&&(s.metadata=new Proxy(s.metadata,{get(c,i){return i==="get"?l=>{const o=c.get(l);return K.includes(l)&&o?Y(o):o}:c[i]}}))}return{info:n,metadata:(s==null?void 0:s.metadata)||{}}}function Y(e){if(!e)return;const t=Date.parse(e);if(!Number.isNaN(t))return new Date(t)}async function Z(e){const t=w(e)?e:await g(e),a=await Promise.all(Array.from({length:t.numPages},(s,n)=>tt(t,n+1)));return{totalPages:t.numPages,items:a}}async function tt(e,t){const s=await(await e.getPage(t)).getTextContent(),n=s.styles;return s.items.filter(r=>r.str!=null).map(r=>{var p;const[c,i,l,o,u,m]=r.transform;return{str:r.str,x:u,y:m,width:r.width,height:r.height,fontSize:Math.hypot(l,o),fontFamily:((p=n[r.fontName])==null?void 0:p.fontFamily)??"",dir:r.dir,hasEOL:r.hasEOL}})}async function et(e,t={}){const{mergePages:a=!1}=t,s=w(e)?e:await g(e),n=await Promise.all(Array.from({length:s.numPages},(r,c)=>at(s,c+1)));return{totalPages:s.numPages,text:a?n.join(`
`).replace(/\s+/g," "):n}}async function at(e,t){return(await(await e.getPage(t)).getTextContent()).items.filter(n=>n.str!=null).map(n=>n.str+(n.hasEOL?`
`:"")).join("")}async function ot(e){await f(e,{reload:!0})}async function it(e){await f(e.pdfjs,{reload:!0})}const ct=async(...e)=>(await f(),await Q(...e)),ut=async(...e)=>(await f(),await et(...e)),lt=async(...e)=>(await f(),await Z(...e)),ft=async(...e)=>(await f(),await W(...e)),dt=async(...e)=>(await f(),await X(...e)),ht=async(...e)=>(await f(),await G(...e));export{it as configureUnPDF,z as createIsomorphicCanvasFactory,ot as definePDFJSModule,ft as extractImages,ht as extractLinks,ut as extractText,lt as extractTextItems,g as getDocumentProxy,ct as getMeta,v as getResolvedPDFJS,dt as renderPageAsImage,f as resolvePDFJSImport};
