@zinejs/pdf 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ZineJS=e.ZineJS||{}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=256*1024*1024,n=.35;function r(e){return typeof e==`object`&&!!e&&`numPages`in e&&typeof e.getPage==`function`}async function i(){let e=globalThis;return e.pdfjsLib?e.pdfjsLib:await import(`pdfjs-dist`)}e.PdfSource=class{pageCount=0;#e;#t;#n;#r;#i=null;#a;#o;#s;#c=new Map;#l=0;#u=null;constructor(e,n={}){this.#e=e,this.#t=n.workerSrc,this.#n=n.renderScale??1,this.#r=n.preload??1,this.#a=n.maxCacheBytes??t,this.#o=n.progressive??!1,this.#s=n.disableAutoFetch??!1}onPageUpdate(e){this.#u=e}async open(){if(r(this.#e))this.#i=this.#e;else{let e=await i();e.GlobalWorkerOptions.workerSrc=this.#d(e.GlobalWorkerOptions.workerSrc);let t=typeof this.#e==`string`?{url:this.#e}:{data:this.#e};this.#s&&(t.disableAutoFetch=!0),this.#i=await e.getDocument(t).promise}this.pageCount=this.#i.numPages}#d(e){if(this.#t)return this.#t;if(e)return e;try{return(new
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ZineJS=e.ZineJS||{}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=256*1024*1024,n=.35;function r(e){return typeof e==`object`&&!!e&&`numPages`in e&&typeof e.getPage==`function`}async function i(){let e=globalThis;return e.pdfjsLib?e.pdfjsLib:await import(`pdfjs-dist`)}e.PdfSource=class{pageCount=0;#e;#t;#n;#r;#i=null;#a;#o;#s;#c=new Map;#l=0;#u=null;constructor(e,n={}){this.#e=e,this.#t=n.workerSrc,this.#n=n.renderScale??1,this.#r=n.preload??1,this.#a=n.maxCacheBytes??t,this.#o=n.progressive??!1,this.#s=n.disableAutoFetch??!1}onPageUpdate(e){this.#u=e}async open(){if(r(this.#e))this.#i=this.#e;else{let e=await i();e.GlobalWorkerOptions.workerSrc=this.#d(e.GlobalWorkerOptions.workerSrc);let t=typeof this.#e==`string`?{url:this.#e}:{data:this.#e};this.#s&&(t.disableAutoFetch=!0),this.#i=await e.getDocument(t).promise}this.pageCount=this.#i.numPages}#d(e){if(this.#t)return this.#t;if(e)return e;try{return(() => { throw new Error('PdfSource: pass workerSrc for UMD/CDN'); })()}catch{throw Error(`PdfSource: couldn't auto-resolve pdf.js's worker. Pass a \`workerSrc\` URL (see the @zinejs/pdf README, "The pdf.js worker"), set pdfjs GlobalWorkerOptions.workerSrc yourself, or pass a pre-created pdf.js document.`)}}get(e){let t=this.#f(e);for(let t=1;t<=this.#r;t++)this.prefetch([e-t,e+t]);return t}prefetch(e){for(let t of e)t>=0&&t<this.pageCount&&this.#f(t).catch(()=>{})}destroy(){this.#i?.destroy?.(),this.#c.clear(),this.#l=0,this.#i=null}#f(e){let t=this.#c.get(e);if(t)return this.#c.delete(e),this.#c.set(e,t),t.promise;let r=typeof devicePixelRatio==`number`?devicePixelRatio:1,i=this.#n*r,a=this.#o?i*n:i,o={promise:void 0,bytes:0};return o.promise=this.#h(e,a).then(t=>(o.bytes=t.width*t.height*4,this.#l+=o.bytes,this.#m(e),this.#o&&this.#p(e,o,i),t),t=>{throw this.#c.delete(e),t}),this.#c.set(e,o),o.promise}#p(e,t,n){this.#h(e,n).then(n=>{this.#c.get(e)===t&&(this.#l-=t.bytes,t.promise=Promise.resolve(n),t.bytes=n.width*n.height*4,this.#l+=t.bytes,this.#m(e),this.#u?.(e))}).catch(()=>{})}#m(e){for(let[t,n]of this.#c){if(this.#l<=this.#a)break;t===e||n.bytes===0||(this.#c.delete(t),this.#l-=n.bytes)}}async#h(e,t){if(this.#i===null)throw Error(`PdfSource: use after open() — the document is not loaded.`);let n=await this.#i.getPage(e+1),r=n.getViewport({scale:t}),i=document.createElement(`canvas`);return i.width=Math.ceil(r.width),i.height=Math.ceil(r.height),await n.render({canvasContext:i.getContext(`2d`),viewport:r}).promise,i}}});
|
|
2
2
|
//# sourceMappingURL=index.umd.js.map
|