libpdfviewer/app/src/main/assets/pdf.worker.js

22 lines
985 KiB
JavaScript
Raw Normal View History

/**
* @licstart The following is the entire license notice for the
* Javascript code in this page
*
2021-11-21 23:30:18 +01:00
* Copyright 2021 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
*/
2021-11-21 23:30:18 +01:00
!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()}(this,(function(){return(()=>{"use strict";var e=[,(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});t.WorkerTask=t.WorkerMessageHandler=void 0;var a=r(2),i=r(5),n=r(7),s=r(71),o=r(4),c=r(99),l=r(100),h=r(9);class WorkerTask{constructor(e){this.name=e;this.terminated=!1;this._capability=(0,a.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 r=!1;e.on("test",(function wphSetupTest(t){if(r)return;r=!0;if(!(t instanceof Uint8Array)){e.send("test",null);return}const a=255===t[0];e.postMessageTransfers=a;e.send("test",{supportTransfers:a})}));e.on("configure",(function wphConfigure(e){(0,a.setVerbosityLevel)(e.verbosity)}));e.on("GetDocRequest",(function wphSetupDoc(e){return WorkerMessageHandler.createDocumentHandler(e,t)}))}static createDocumentHandler(e,t){let r,o=!1,u=null;const d=[],f=(0,a.getVerbosityLevel)(),g=e.apiVersion,p="2.10.377";if(g!==p)throw new Error(`The API version "${g}" does not match the Worker version "2.10.377".`);const m=[];for(const e in[])m.push(e);if(m.length)throw new Error("The `Array.prototype` contains unexpected enumerable properties: "+m.join(", ")+"; thus breaking e.g. `for...in` iteration of `Array`s.");if("undefined"==typeof ReadableStream)throw new Error("The browser/environment lacks native support for critical functionality used by the PDF.js library (e.g. `ReadableStream`); please use a `legacy`-build instead.");const b=e.docId,y=e.docBaseUrl,w=e.docId+"_worker";let S=new c.MessageHandler(w,b,t);S.postMessageTransfers=e.postMessageTransfers;function ensureNotTerminated(){if(o)throw new Error("Worker was terminated")}function startWorkerTask(e){d.push(e)}function finishWorkerTask(e){e.finish();const t=d.indexOf(e);d.splice(t,1)}async function loadDocument(e){await r.ensureDoc("checkHeader");await r.ensureDoc("parseStartXRef");await r.ensureDoc("parse",[e]);e||await r.ensureDoc("checkFirstPage");const t=await r.ensureDoc("isPureXfa");if(t){const e=new WorkerTask("loadXfaFonts");startWorkerTask(e);await Promise.all([r.loadXfaFonts(S,e).catch((e=>{})).then((()=>finishWorkerTask(e))),r.loadXfaImages()])}const[a,i]=await Promise.all([r.ensureDoc("numPages"),r.ensureDoc("fingerprints")]);return{numPages:a,fingerprints:i,htmlForXfa:t?await r.ensureDoc("htmlForXfa"):null}}function getPdfManager(e,t,r){const i=(0,a.createPromiseCapability)();let s;const o=e.source;if(o.data){try{s=new n.LocalPdfManager(b,o.data,o.password,t,r,y);i.resolve(s)}catch(e){i.reject(e)}return i.promise}let c,h=[];try{c=new l.PDFWorkerStream(S)}catch(e){i.reject(e);return i.promise}const d=c.getFullReader();d.headersReady.then((function(){if(!d.isRangeSupported)return;const e=o.disableAutoFetch||d.isStreamingSupported;s=new n.NetworkPdfManager(b,c,{msgHandler:S,password:o.password,length:d.contentLength,disableAutoFetch:e,rangeChunkSize:o.rangeChunkSize},t,r,y);for(let e=0;e<h.length;e++)s.sendProgressiveData(h[e]);h=[];i.resolve(s);u=null})).catch((function(e){i.reject(e);u=null}));let f=0;new Promise((function(e,c){const readChunk=function({value:e,done:l}){try{ensureNotTerminated();if(l){s||function(){const e=(0,a.arraysToBytes)(h);o.length&&e.length!==o.length&&(0,a.warn)("reported HTTP length is different from actual");try{s=new n.LocalPdfManager(b,e,o.password,t,r,y);i.resolve(s)}catch(e){i.reject(e)}h=[]}();u=null;return}f+=(0,a.arrayByteLength)(e);d.isStreamingSupported||S.send("DocProgress",{loaded:f,total:Math.max(f,d.contentLength||0)});s?s.sendProgressiveData(e):h.push(e);d.read().then(readChunk,c)}catch(e){c(e)}};d.read().then(readChunk,c)