You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
1.0 MiB

/**
* @licstart The following is the entire license notice for the
* JavaScript code in this page
*
* Copyright 2022 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @licend The above is the entire license notice for the
* JavaScript code in this page
*/
!function webpackUniversalModuleDefinition(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("pdfjs-dist/build/pdf.worker",[],t):"object"==typeof exports?exports["pdfjs-dist/build/pdf.worker"]=t():e["pdfjs-dist/build/pdf.worker"]=e.pdfjsWorker=t()}(globalThis,(()=>(()=>{"use strict";var e=[,(e,t,a)=>{Object.defineProperty(t,"__esModule",{value:!0});t.WorkerTask=t.WorkerMessageHandler=void 0;var r=a(2),n=a(5),i=a(6),s=a(8),o=a(71),c=a(65),l=a(4),h=a(102),u=a(103);class WorkerTask{constructor(e){this.name=e;this.terminated=!1;this._capability=(0,r.createPromiseCapability)()}get finished(){return this._capability.promise}finish(){this._capability.resolve()}terminate(){this.terminated=!0}ensureNotTerminated(){if(this.terminated)throw new Error("Worker task was terminated")}}t.WorkerTask=WorkerTask;class WorkerMessageHandler{static setup(e,t){let a=!1;e.on("test",(function wphSetupTest(t){if(!a){a=!0;e.send("test",t instanceof Uint8Array)}}));e.on("configure",(function wphConfigure(e){(0,r.setVerbosityLevel)(e.verbosity)}));e.on("GetDocRequest",(function wphSetupDoc(e){return WorkerMessageHandler.createDocumentHandler(e,t)}))}static createDocumentHandler(e,t){let a,d=!1,f=null;const g=[],p=(0,r.getVerbosityLevel)(),m=e.apiVersion,b="2.16.105";if(m!==b)throw new Error(`The API version "${m}" does not match the Worker version "2.16.105".`);const y=[];for(const e in[])y.push(e);if(y.length)throw new Error("The `Array.prototype` contains unexpected enumerable properties: "+y.join(", ")+"; thus breaking e.g. `for...in` iteration of `Array`s.");if("undefined"==typeof ReadableStream){const e="The browser/environment lacks native support for critical functionality used by the PDF.js library (e.g. `ReadableStream`); ";if(l.isNodeJS)throw new Error(e+"please use a `legacy`-build instead.");throw new Error(e+"please update to a supported browser.")}const w=e.docId,S=e.docBaseUrl,x=e.docId+"_worker";let k=new h.MessageHandler(x,w,t);function ensureNotTerminated(){if(d)throw new Error("Worker was terminated")}function startWorkerTask(e){g.push(e)}function finishWorkerTask(e){e.finish();const t=g.indexOf(e);g.splice(t,1)}async function loadDocument(e){await a.ensureDoc("checkHeader");await a.ensureDoc("parseStartXRef");await a.ensureDoc("parse",[e]);await a.ensureDoc("checkFirstPage",[e]);await a.ensureDoc("checkLastPage",[e]);const t=await a.ensureDoc("isPureXfa");if(t){const e=new WorkerTask("loadXfaFonts");startWorkerTask(e);await Promise.all([a.loadXfaFonts(k,e).catch((e=>{})).then((()=>finishWorkerTask(e))),a.loadXfaImages()])}const[r,n]=await Promise.all([a.ensureDoc("numPages"),a.ensureDoc("fingerprints")]);return{numPages:r,fingerprints:n,htmlForXfa:t?await a.ensureDoc("htmlForXfa"):null}}function getPdfManager(e,t,a){const n=(0,r.createPromiseCapability)();let i;const o=e.source;if(o.data){try{i=new s.LocalPdfManager(w,o.data,o.password,k,t,a,S);n.resolve(i)}catch(e){n.reject(e)}return n.promise}let c,l=[];try{c=new u.PDFWorkerStream(k)}catch(e){n.reject(e);return n.promise}const h=c.getFullReader();h.headersReady.then((function(){if(!h.isRangeSupported)return;const e=o.disableAutoFetch||h.isStreamingSupported;i=new s.NetworkPdfManager(w,c,{msgHandler:k,password:o.password,length:h.contentLength,disableAutoFetch:e,rangeChunkSize:o.rangeChunkSize},t,a,S);for(const e of l)i.sendProgressiveData(e);l=[];n.resolve(i);f=null})).catch((function(e){n.reject(e);f=null}));let d=0;new Promise((function(e,c){const readChunk=function({value:e,done:u}){try{ensureNotTerminated();if(u){i||function(){const e=(0,r.arraysToBytes)(l);o.length&&e.length!==o.length&&(0,r.warn)("reported HTTP length is different from actual");try{i=new s.LocalPdfManager(w,e,o.password,k,t,a,S);n.resolve(i)}catch(e){n.reject(e)}l=[]}();f=null;return}d+=(0,r.arrayByteLength)(e);h.isStreamingSupported||k.send("DocProgress",{loaded:d,total:Math.max(d,h.contentLength||0)});i?i.sendProgressiveData(e):l.push(e);h.read().then(readChunk,c)}catch(e){c(e)}};h.read().then(readChunk,c)})).catch((function(e){n.reje