IA-Logseq-Publish/static/js/pdfjs/pdf.worker.min.js

22 lines
1.0 MiB
JavaScript
Raw Normal View History

/**
* @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()}(this,(()=>(()=>{"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(67),o=a(73),c=a(4),l=a(102),h=a(103),u=a(8);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.14.305";if(m!==b)throw new Error(`The API version "${m}" does not match the Worker version "2.14.305".`);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(c.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 l.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 s;const o=e.source;if(o.data){try{s=new i.LocalPdfManager(w,o.data,o.password,k,t,a,S);n.resolve(s)}catch(e){n.reject(e)}return n.promise}let c,l=[];try{c=new h.PDFWorkerStream(k)}catch(e){n.reject(e);return n.promise}const u=c.getFullReader();u.headersReady.then((function(){if(!u.isRangeSupported)return;const e=o.disableAutoFetch||u.isStreamingSupported;s=new i.NetworkPdfManager(w,c,{msgHandler:k,password:o.password,length:u.contentLength,disableAutoFetch:e,rangeChunkSize:o.rangeChunkSize},t,a,S);for(let e=0;e<l.length;e++)s.sendProgressiveData(l[e]);l=[];n.resolve(s);f=null})).catch((function(e){n.reject(e);f=null}));let d=0;new Promise((function(e,c){const readChunk=function({value:e,done:h}){try{ensureNotTerminated();if(h){s||function(){const e=(0,r.arraysToBytes)(l);o.length&&e.length!==o.length&&(0,r.warn)("reported HTTP length is different from actual");try{s=new i.LocalPdfManager(w,e,o.password,k,t,a,S);n.resolve(s)}catch(e){n.reject(e)}l=[]}();f=null;return}d+=(0,r.arrayByteLength)(e);u.isStreamingSupported||k.send("DocProgress",{loaded:d,total:Math.max(d,u.contentLength||0)});s?s.sendProgressiveData(e):l.push(e);u.read().then(readChunk,c)}catch(e){c(e)}};u.read().then(readChunk,c)})).catch((function(e)