mirror of
https://github.com/renbaoshuo/S2OJ.git
synced 2024-11-25 15:38:40 +00:00
23 lines
1015 KiB
JavaScript
23 lines
1015 KiB
JavaScript
|
/**
|
||
|
* @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(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 n,r=a(2),i=a(3),s=a(4),o=a(6),c=a(69),l=a(63),h=a(100),u=a(101),d=a(102);class f{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=f;class g{static setup(e,t){let a=!1;e.on("test",(function(t){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 g.createDocumentHandler(e,t)}))}static createDocumentHandler(e,t){let a,n=!1,g=null;const p=[],m=(0,r.getVerbosityLevel)(),{docId:b,apiVersion:y}=e,w="3.3.122";if(y!==w)throw new Error(`The API version "${y}" does not match the Worker version "${w}".`);const x=[];for(const e in[])x.push(e);if(x.length)throw new Error("The `Array.prototype` contains unexpected enumerable properties: "+x.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(h.isNodeJS)throw new Error(e+"please use a `legacy`-build instead.");throw new Error(e+"please update to a supported browser.")}const S=b+"_worker";let k=new u.MessageHandler(S,b,t);function A(){if(n)throw new Error("Worker was terminated")}function v(e){p.push(e)}function C(e){e.finish();const t=p.indexOf(e);p.splice(t,1)}async function F(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 f("loadXfaFonts");v(e),await Promise.all([a.loadXfaFonts(k,e).catch((e=>{})).then((()=>C(e))),a.loadXfaImages()])}const[n,r]=await Promise.all([a.ensureDoc("numPages"),a.ensureDoc("fingerprints")]);return{numPages:n,fingerprints:r,htmlForXfa:t?await a.ensureDoc("htmlForXfa"):null}}function O({data:e,password:t,disableAutoFetch:a,rangeChunkSize:n,length:i,docBaseUrl:s,enableXfa:c,evaluatorOptions:l}){const h=(0,r.createPromiseCapability)();let u;if(e){try{u=new o.LocalPdfManager(b,e,t,k,l,c,s),h.resolve(u)}catch(e){h.reject(e)}return h.promise}let f,p=[];try{f=new d.PDFWorkerStream(k)}catch(e){return h.reject(e),h.promise}const m=f.getFullReader();m.headersReady.then((function(){if(m.isRangeSupported){a=a||m.isStreamingSupported,u=new o.NetworkPdfManager(b,f,{msgHandler:k,password:t,length:m.contentLength,disableAutoFetch:a,rangeChunkSize:n},l,c,s);for(const e of p)u.sendProgressiveData(e);p=[],h.resolve(u),g=null}})).catch((function(e){h.reject(e),g=null}));let y=0;return new Promise((function(e,a){const n=function({value:e,done:d}){try{if(A(),d)return u||function(){const e=(0,r.arraysToBytes)(p);i&&e.length!==i&&(0,r.warn)("reported HTTP length is different from actual");try{u=new o.LocalPdfManager(b,e,t,k,l,c,s),h.resolve(u)}catch(e){h.reject(e)}p=[]}(),void(g=null);y+=(0,r.arrayByteLength)(e),m.isStreamingSupported||k.send("DocProgress",{loaded:y,total:Math.max(y,m.contentLength||0)}),u?u.sendProgressiveData(e):p.push(e),m.read().then(n,a)}catch(e){a(e)}};m.read().then(n,a)})).catch((function(e){h.reject(e),g=null})),g=function(e){f.cancelAllRequests(e)},h.promise}return k.on("GetPage",(function(e){return a.getPage(e.pageIndex).then((function(e){return Promise.all([a.ensure(e,"rotate"),a.ensure(e,"ref"),a.ensure(e,"userUnit"),a.ensure(e,"view")]).then((function([e,t,a,n]){return{rotate:e,ref:t,u
|