const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/pdf-dEEgg0i1.js","assets/index-DtqT604u.js","assets/index-MSkwazQm.css"])))=>i.map(i=>d[i]);
import{i as e,r as t}from"./index-DtqT604u.js";var n=`stillpub-import-pdf/0.1.0`;function r(e){let t=e.slice(0,10).join(`, `),n=e.length-Math.min(e.length,10);return n>0?`${t} and ${n} more`:t}function i(e){return e.replace(/\.pdf$/i,``).trim()||`Imported PDF`}function a(e){let t=[{kind:`pdf-page-image`,message:`Every page was imported as a picture of the original PDF. The text in it is not editable. You can add new text boxes, pictures and shapes on top, then print or export as usual, and you can delete a page picture once you have rebuilt what was on it.`}],n=[],i=[];if(e.pages.forEach((e,t)=>{(e.hasTextLayer?n:i).push(t+1)}),n.length>0){let e=n.length===1;t.push({kind:`pdf-text-not-editable`,message:`${e?`Page`:`Pages`} ${r(n)} ${e?`contains`:`contain`} real text in the PDF, but this import flattens each page to a picture, so that text cannot be edited or reflowed here. Recovering it as editable text boxes is a later feature.`})}if(i.length>0){let e=i.length===1;t.push({kind:`pdf-no-text-layer`,message:`${e?`Page`:`Pages`} ${r(i)} ${e?`has`:`have`} no text layer at all. ${e?`It was`:`They were`} scanned or saved as an image, so no tool can recover editable text from ${e?`it`:`them`} without character recognition.`})}return e.stopReason===`page-cap`?t.push({kind:`pdf-pages-skipped`,message:`This PDF has ${e.totalPages} pages and only the first ${e.pages.length} were imported, because 30 pages is the limit for one import. Split the file and import the rest separately so nothing is lost.`}):e.stopReason===`size-cap`&&t.push({kind:`pdf-pages-skipped`,message:`Importing stopped after ${e.pages.length} of ${e.totalPages} pages because the page pictures reached this import's memory limit. Split the file and import the rest separately so nothing is lost.`}),t}function o(t,r){if(t.pages.length===0)throw Error(`"${r}" has no pages that could be rendered, so there is nothing to import.`);let o={},s=t.pages.map((t,n)=>{let r=e(`asset`);o[r]=t.dataUri;let i={type:`image`,id:e(`obj`),assetId:r,x:0,y:0,width:t.widthPt,height:t.heightPt,name:`Page ${n+1} of the imported PDF`,lockAspectRatio:!0};return{id:e(`page`),width:t.widthPt,height:t.heightPt,objects:[i]}});return{schemaVersion:2,meta:{title:i(r),importedFrom:{format:`pdf`,originalFile:r,importerVersion:n}},fonts:[],pages:s,assets:o,importWarnings:a(t)}}var s=`/app/assets/pdf.worker.min-CHFwMXne.mjs`,c=150/72,l=null;function u(){return l||=t(()=>import(`./pdf-dEEgg0i1.js`).then(e=>(e.GlobalWorkerOptions.workerSrc=s,e)),__vite__mapDeps([0,1,2])),l}function d(e,t){let n=e?.name;if(n===`PasswordException`)return Error(`"${t}" is password protected. Open it in a PDF reader, save an unprotected copy, and import that.`);if(n===`InvalidPDFException`)return Error(`"${t}" is not a readable PDF. The file may be truncated or corrupted.`);let r=e instanceof Error?e.message:String(e);return Error(`"${t}" could not be imported: ${r}`)}function f(e){let t=e.indexOf(`,`),n=t>=0?e.length-t-1:e.length;return Math.floor(n*3/4)}var p=async e=>{let t=(await u()).getDocument({data:e}),n=await t.promise;try{let e=n.numPages,t=Math.min(e,30),r=[],i=0,a=e>30?`page-cap`:void 0;for(let e=1;e<=t;e+=1){let t=await n.getPage(e);try{let e=t.getViewport({scale:1}),n=t.getViewport({scale:c}),o=document.createElement(`canvas`);o.width=Math.max(1,Math.round(n.width)),o.height=Math.max(1,Math.round(n.height));let s=o.getContext(`2d`);if(!s)throw Error(`this browser did not provide a 2D canvas`);s.fillStyle=`#ffffff`,s.fillRect(0,0,o.width,o.height),await t.render({canvas:o,canvasContext:s,viewport:n}).promise;let l=o.toDataURL(`image/png`),u=f(l);if(r.length>0&&i+u>67108864){a=`size-cap`;break}i+=u;let d=(await t.getTextContent()).items.some(e=>`str`in e&&e.str.trim()!==``);r.push({widthPt:e.width,heightPt:e.height,dataUri:l,hasTextLayer:d}),o.width=0,o.height=0}finally{t.cleanup()}}return{pages:r,totalPages:e,stopReason:a}}finally{await t.destroy()}};async function m(e,t=p){let n=new Uint8Array(await e.arrayBuffer()),r;try{r=await t(n)}catch(t){throw d(t,e.name)}return o(r,e.name)}export{m as importPdfFile};