securityos/node_modules/pdfjs-dist/legacy/build/pdf.worker.min.js

22 lines
1.1 MiB
JavaScript
Raw Normal View History

2024-09-06 15:32:35 +00:00
/**
* @licstart The following is the entire license notice for the
* JavaScript code in this page
*
* Copyright 2023 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=e.pdfjsWorker=t():"function"==typeof define&&define.amd?define("pdfjs-dist/build/pdf.worker",[],(()=>e.pdfjsWorker=t())):"object"==typeof exports?exports["pdfjs-dist/build/pdf.worker"]=e.pdfjsWorker=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;a(2);a(84);a(93);a(94);a(97);a(99);a(101);a(105);a(108);a(115);a(116);a(127);a(129);a(132);a(134);a(136);a(138);a(140);a(144);var r=a(145),n=a(150),i=a(151),s=a(153),o=a(157),c=a(219),l=a(224),h=a(258),u=a(259),d=a(223);class WorkerTask{constructor(e){this.name=e;this.terminated=!1;this._capability=new r.PromiseCapability}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(t){if(!a){a=!0;e.send("test",t instanceof Uint8Array)}}));e.on("configure",(function(e){(0,r.setVerbosityLevel)(e.verbosity)}));e.on("GetDocRequest",(function(e){return WorkerMessageHandler.createDocumentHandler(e,t)}))}static createDocumentHandler(e,t){let a,f=!1,g=null;const p=new Set,m=(0,r.getVerbosityLevel)(),{docId:b,apiVersion:y}=e,w="3.11.174";if(y!==w)throw new Error(`The API version "${y}" does not match the Worker version "${w}".`);const S=[];for(const e in[])S.push(e);if(S.length)throw new Error("The `Array.prototype` contains unexpected enumerable properties: "+S.join(", ")+"; thus breaking e.g. `for...in` iteration of `Array`s.");const x=b+"_worker";let C=new h.MessageHandler(x,b,t);function ensureNotTerminated(){if(f)throw new Error("Worker was terminated")}function startWorkerTask(e){p.add(e)}function finishWorkerTask(e){e.finish();p.delete(e)}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(C,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){let{data:t,password:a,disableAutoFetch:i,rangeChunkSize:o,length:c,docBaseUrl:l,enableXfa:h,evaluatorOptions:d}=e;const f={source:null,disableAutoFetch:i,docBaseUrl:l,docId:b,enableXfa:h,evaluatorOptions:d,handler:C,length:c,password:a,rangeChunkSize:o},p=new r.PromiseCapability;let m;if(t){try{f.source=t;m=new s.LocalPdfManager(f);p.resolve(m)}catch(e){p.reject(e)}return p.promise}let y,w=[];try{y=new u.PDFWorkerStream(C)}catch(e){p.reject(e);return p.promise}const S=y.getFullReader();S.headersReady.then((function(){if(S.isRangeSupported){f.source=y;f.length=S.contentLength;f.disableAutoFetch||=S.isStreamingSupported;m=new s.NetworkPdfManager(f);for(const e of w)m.sendProgressiveData(e);w=[];p.resolve(m);g=null}})).catch((function(e){p.reject(e);g=null}));let x=0;new Promise((function(e,t){const readChunk=function(e){let{value:a,done:i}=e;try{ensureNotTerminated();if(i){m||function(){const e=(0,n.arrayBuffersToBytes)(w);c&&e.length!==c&&(0,r.warn)("reported HTTP length is different from actual");try{f.source=e;m=new s.LocalPdfManager(f);p.resolve(m)}catch(e){p.reject(e)}w=[]}();g=null;return}x+=a.byteLength;S.isStreamingSupported||C.send("DocProgress",{loaded:x,total:Math.max(x,S.contentLength||0)});m?m.sendProgressiveData(a):w.push(a);S.read().then(readChunk,t)}catch(e){t(e)}};S.read().then(readChunk,t)})).catch((function(e){p.reject(e);g=null}));g=function(e){y.cancelAllRequests(e)};return p.promise}C.on("GetPage",(function(e){return a.getPage(