ngx-extended-pdf-viewer
Version:
Embedding PDF files in your Angular application. Highly configurable viewer including the toolbar, sidebar, and all the features you're used to.
21 lines • 704 kB
JavaScript
/**
* @licstart The following is the entire license notice for the
* JavaScript code in this page
*
* Copyright 2024 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
*/var t={641:(t,__webpack_exports__,e)=>{e.d(__webpack_exports__,{NgxConsole:()=>NgxConsole});class NgxConsole{static ngxConsoleFilter=(t,e)=>!0;static log(t,e){NgxConsole.ngxConsoleFilter("log",t)&&(void 0!==e?console.log("%s",t,e):console.log(t))}static error(t,e){NgxConsole.ngxConsoleFilter("error",t)&&(void 0!==e?console.error("%s",t,e):console.error(t))}static warn(t,e){NgxConsole.ngxConsoleFilter("warn",t)&&(void 0!==e?console.warn("%s",t,e):console.warn(t))}static debug(t,e){NgxConsole.ngxConsoleFilter("debug",t)&&(void 0!==e?console.warn("%s",t,e):console.warn(t))}get ngxConsoleFilter(){return NgxConsole.ngxConsoleFilter}set ngxConsoleFilter(t){NgxConsole.ngxConsoleFilter=t}reset(){NgxConsole.ngxConsoleFilter=(t,e)=>!0}}},792:(t,__webpack_exports__,e)=>{e.d(__webpack_exports__,{AnnotationStorage:()=>AnnotationStorage,PrintAnnotationStorage:()=>PrintAnnotationStorage,SerializableEmpty:()=>a});var i=e(292),n=e(310),s=e(651);const a=Object.freeze({map:null,hash:"",transfer:void 0});class AnnotationStorage{#t=!1;#e=null;#i=new Map;constructor(){this.onSetModified=null;this.onResetModified=null;this.onAnnotationEditor=null}getValue(t,e){const i=this.#i.get(t);return void 0===i?e:Object.assign(e,i)}getRawValue(t){return this.#i.get(t)}remove(t){this.#i.delete(t);0===this.#i.size&&this.resetModified();if("function"==typeof this.onAnnotationEditor){for(const t of this.#i.values())if(t instanceof n.AnnotationEditor)return;this.onAnnotationEditor(null)}}setValue(t,e){const i=this.#i.get(t);let s=!1;if(void 0!==i){for(const[t,n]of Object.entries(e))if(i[t]!==n){s=!0;i[t]=n}}else{s=!0;this.#i.set(t,e)}s&&this.#n();e instanceof n.AnnotationEditor&&"function"==typeof this.onAnnotationEditor&&this.onAnnotationEditor(e.constructor._type)}has(t){return this.#i.has(t)}getAll(){return this.#i.size>0?(0,i.objectFromMap)(this.#i):null}setAll(t){for(const[e,i]of Object.entries(t))this.setValue(e,i)}get size(){return this.#i.size}#n(){if(!this.#t){this.#t=!0;"function"==typeof this.onSetModified&&this.onSetModified()}}resetModified(){if(this.#t){this.#t=!1;"function"==typeof this.onResetModified&&this.onResetModified()}}get print(){return new PrintAnnotationStorage(this)}get serializable(){if(0===this.#i.size)return a;const t=new Map,e=new s.MurmurHash3_64,i=[],r=Object.create(null);let o=!1;for(const[i,s]of this.#i){const a=s instanceof n.AnnotationEditor?s.serialize(!1,r):s;if(a){t.set(i,a);e.update(`${i}:${JSON.stringify(a)}`);o||=!!a.bitmap}}if(o)for(const e of t.values())e.bitmap&&i.push(e.bitmap);return t.size>0?{map:t,hash:e.hexdigest(),transfer:i}:a}get editorStats(){let t=null;const e=new Map;for(const i of this.#i.values()){if(!(i instanceof n.AnnotationEditor))continue;const s=i.telemetryFinalData;if(!s)continue;const{type:a}=s;e.has(a)||e.set(a,Object.getPrototypeOf(i).constructor);t||=Object.create(null);const r=t[a]||=new Map;for(const[t,e]of Object.entries(s)){if("type"===t)continue;let i=r.get(t);if(!i){i=new Map;r.set(t,i)}const n=i.get(e)??0;i.set(e,n+1)}}for(const[i,n]of e)t[i]=n.computeTelemetryFinalData(t[i]);return t}resetModifiedIds(){this.#e=null}get modifiedIds(){if(this.#e)return this.#e;const t=[];for(const e of this.#i.values())e instanceof n.AnnotationEditor&&e.annotationElementId&&e.serialize()&&t.push(e.annotationElementId);return this.#e={ids:new Set(t),hash:t.join(",")}}}class PrintAnnotationStorage extends AnnotationStorage{#s;constructor(t){super();const{map:e,hash:i,transfer:n}=t.serializable,s=structuredClone(e,n?{transfer:n}:null);this.#s={map:s,hash:i,transfer:n}}get print(){(0,i.unreachable)("Should not call PrintAnnotationStorage.print")}get serializable(){return this.#s}get modifiedIds(){return(0,i.shadow)(this,"modifiedIds",{ids:new Set,hash:""})}}},925:(t,__webpack_exports__,e)=>{e.d(__webpack_exports__,{PDFDataRangeTransport:()=>PDFDataRangeTransport,PDFWorker:()=>PDFWorker,build:()=>O,getDocument:()=>getDocument,version:()=>B});var i=e(292),n=e(792);class FontLoader{#a=new Set;constructor({ownerDocument:t=globalThis.document,styleElement:e=null}){this._document=t;this.nativeFontFaces=new Set;this.styleElement=null;this.loadingRequests=[];this.loadTestFontId=0}addNativeFontFace(t){this.nativeFontFaces.add(t);this._document.fonts.add(t)}removeNativeFontFace(t){this.nativeFontFaces.delete(t);this._document.fonts.delete(t)}insertRule(t){if(!this.styleElement){this.styleElement=this._document.createElement("style");this._document.documentElement.getElementsByTagName("head")[0].append(this.styleElement)}const e=this.styleElement.sheet;e.insertRule(t,e.cssRules.length)}clear(){for(const t of this.nativeFontFaces)this._document.fonts.delete(t);this.nativeFontFaces.clear();this.#a.clear();if(this.styleElement){this.styleElement.remove();this.styleElement=null}}async loadSystemFont({systemFontInfo:t,_inspectFont:e}){if(t&&!this.#a.has(t.loadedName)){(0,i.assert)(!this.disableFontFace,"loadSystemFont shouldn't be called when `disableFontFace` is set.");if(this.isFontLoadingAPISupported){const{loadedName:n,src:s,style:a}=t,r=new FontFace(n,s,a);this.addNativeFontFace(r);try{await r.load();this.#a.add(n);e?.(t)}catch{(0,i.warn)(`Cannot load system font: ${t.baseFontName}, installing it could help to improve PDF rendering.`);this.removeNativeFontFace(r)}}else(0,i.unreachable)("Not implemented: loadSystemFont without the Font Loading API.")}}async bind(t){if(t.attached||t.missingFile&&!t.systemFontInfo)return;t.attached=!0;if(t.systemFontInfo){await this.loadSystemFont(t);return}if(this.isFontLoadingAPISupported){const e=t.createNativeFontFace();if(e){this.addNativeFontFace(e);try{await e.loaded}catch(n){(0,i.warn)(`Failed to load font '${e.family}': '${n}'.`);t.disableFontFace=!0;throw n}}return}const e=t.createFontFaceRule();if(e){this.insertRule(e);if(this.isSyncFontLoadingSupported)return;await new Promise((e=>{const i=this._queueLoadingCallback(e);this._prepareFontLoadEvent(t,i)}))}}get isFontLoadingAPISupported(){const t=!!this._document?.fonts;return(0,i.shadow)(this,"isFontLoadingAPISupported",t)}get isSyncFontLoadingSupported(){let t=!1;(i.isNodeJS||"undefined"!=typeof navigator&&"string"==typeof navigator?.userAgent&&/Mozilla\/5.0.*?rv:\d+.*? Gecko/.test(navigator.userAgent))&&(t=!0);return(0,i.shadow)(this,"isSyncFontLoadingSupported",t)}_queueLoadingCallback(t){const{loadingRequests:e}=this,n={done:!1,complete:function completeRequest(){(0,i.assert)(!n.done,"completeRequest() cannot be called twice.");n.done=!0;for(;e.length>0&&e[0].done;){const t=e.shift();setTimeout(t.callback,0)}},callback:t};e.push(n);return n}get _loadTestFont(){const t=atob("T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQAABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwAAAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbmFtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAAAADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6AABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAAMQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAAAAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAAAAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQAAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMAAQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAAEAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgcA/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQAAAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAgABAAAAAAAAAAAD6AAAAAAAAA==");return(0,i.shadow)(this,"_loadTestFont",t)}_prepareFontLoadEvent(t,e){function int32(t,e){return t.charCodeAt(e)<<24|t.charCodeAt(e+1)<<16|t.charCodeAt(e+2)<<8|255&t.charCodeAt(e+3)}function spliceString(t,e,i,n){return t.substring(0,e)+n+t.substring(e+i)}let n,s;const a=this._document.createElement("canvas");a.width=1;a.height=1;const r=a.getContext("2d");let o=0;const l=`lt${Date.now()}${this.loadTestFontId++}`;let h=this._loadTestFont;h=spliceString(h,976,l.length,l);const d=1482184792;let c=int32(h,16);for(n=0,s=l.length-3;n<s;n+=4)c=c-d+int32(l,n)|0;n<l.length&&(c=c-d+int32(l+"XXX",n)|0);h=spliceString(h,16,4,(0,i.string32)(c));const u=`@font-face {font-family:"${l}";src:${`url(data:font/opentype;base64,${btoa(h)});`}}`;this.insertRule(u);const p=this._document.createElement("div");p.style.visibility="hidden";p.style.width=p.style.height="10px";p.style.position="absolute";p.style.top=p.style.left="0px";for(const e of[t.loadedName,l]){const t=this._document.createElement("span");t.textContent="Hi";t.style.fontFamily=e;p.append(t)}this._document.body.append(p);!function isFontReady(t,e){if(++o>30){(0,i.warn)("Load test font never loaded.");e();return}r.font="30px "+t;r.fillText(".",0,20);r.getImageData(0,0,1,1).data[3]>0?e():setTimeout(isFontReady.bind(null,t,e))}(l,(()=>{p.remove();e.complete()}))}}class FontFaceObject{constructor(t,{disableFontFace:e=!1,fontExtraProperties:i=!1,inspectFont:n=null}){this.compiledGlyphs=Object.create(null);for(const e in t)this[e]=t[e];this.disableFontFace=!0===e;this.fontExtraProperties=!0===i;this._inspectFont=n}createNativeFontFace(){if(!this.data||this.disableFontFace)return null;let t;if(this.cssFontInfo){const e={weight:this.cssFontInfo.fontWeight};this.cssFontInfo.italicAngle&&(e.style=`oblique ${this.cssFontInfo.italicAngle}deg`);t=new FontFace(this.cssFontInfo.fontFamily,this.data,e)}else t=new FontFace(this.loadedName,this.data,{});this._inspectFont?.(this);return t}createFontFaceRule(){if(!this.data||this.disableFontFace)return null;const t=`url(data:${this.mimetype};base64,${(0,i.toBase64Util)(this.data)});`;let e;if(this.cssFontInfo){let i=`font-weight: ${this.cssFontInfo.fontWeight};`;this.cssFontInfo.italicAngle&&(i+=`font-style: oblique ${this.cssFontInfo.italicAngle}deg;`);e=`@font-face {font-family:"${this.cssFontInfo.fontFamily}";${i}src:${t}}`}else e=`@font-face {font-family:"${this.loadedName}";src:${t}}`;this._inspectFont?.(this,t);return e}getPathGenerator(t,e){if(void 0!==this.compiledGlyphs[e])return this.compiledGlyphs[e];const n=this.loadedName+"_path_"+e;let s;try{s=t.get(n)}catch(t){(0,i.warn)(`getPathGenerator - ignoring character: "${t}".`)}const a=new Path2D(s||"");this.fontExtraProperties||t.delete(n);return this.compiledGlyphs[e]=a}}var s=e(419);const a=1,r=2,o=1,l=2,h=3,d=4,c=5,u=6,p=7,g=8;function onFn(){}function wrapReason(t){if(t instanceof i.AbortException||t instanceof i.InvalidPDFException||t instanceof i.MissingPDFException||t instanceof i.PasswordException||t instanceof i.UnexpectedResponseException||t instanceof i.UnknownErrorException)return t;t instanceof Error||"object"==typeof t&&null!==t||(0,i.unreachable)('wrapReason: Expected "reason" to be a (possibly cloned) Error.');switch(t.name){case"AbortException":return new i.AbortException(t.message);case"InvalidPDFException":return new i.InvalidPDFException(t.message);case"MissingPDFException":return new i.MissingPDFException(t.message);case"PasswordException":return new i.PasswordException(t.message,t.code);case"UnexpectedResponseException":return new i.UnexpectedResponseException(t.message,t.status);case"UnknownErrorException":return new i.UnknownErrorException(t.message,t.details)}return new i.UnknownErrorException(t.message,t.toString())}class MessageHandler{#r=new AbortController;constructor(t,e,i){this.sourceName=t;this.targetName=e;this.comObj=i;this.callbackId=1;this.streamId=1;this.streamSinks=Object.create(null);this.streamControllers=Object.create(null);this.callbackCapabilities=Object.create(null);this.actionHandler=Object.create(null);i.addEventListener("message",this.#o.bind(this),{signal:this.#r.signal})}#o({data:t}){if(t.targetName!==this.sourceName)return;if(t.stream){this.#l(t);return}if(t.callback){const e=t.callbackId,i=this.callbackCapabilities[e];if(!i)throw new Error(`Cannot resolve callback ${e}`);delete this.callbackCapabilities[e];if(t.callback===a)i.resolve(t.data);else{if(t.callback!==r)throw new Error("Unexpected callback case");i.reject(wrapReason(t.reason))}return}const e=this.actionHandler[t.action];if(!e)throw new Error(`Unknown action from worker: ${t.action}`);if(t.callbackId){const i=this.sourceName,n=t.sourceName,s=this.comObj;Promise.try(e,t.data).then((function(e){s.postMessage({sourceName:i,targetName:n,callback:a,callbackId:t.callbackId,data:e})}),(function(e){s.postMessage({sourceName:i,targetName:n,callback:r,callbackId:t.callbackId,reason:wrapReason(e)})}))}else t.streamId?this.#h(t):e(t.data)}on(t,e){const i=this.actionHandler;if(i[t])throw new Error(`There is already an actionName called "${t}"`);i[t]=e}send(t,e,i){this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:t,data:e},i)}sendWithPromise(t,e,i){const n=this.callbackId++,s=Promise.withResolvers();this.callbackCapabilities[n]=s;try{this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:t,callbackId:n,data:e},i)}catch(t){s.reject(t)}return s.promise}sendWithStream(t,e,n,s){const a=this.streamId++,r=this.sourceName,l=this.targetName,h=this.comObj;return new ReadableStream({start:i=>{const n=Promise.withResolvers();this.streamControllers[a]={controller:i,startCall:n,pullCall:null,cancelCall:null,isClosed:!1};h.postMessage({sourceName:r,targetName:l,action:t,streamId:a,data:e,desiredSize:i.desiredSize},s);return n.promise},pull:t=>{const e=Promise.withResolvers();this.streamControllers[a].pullCall=e;h.postMessage({sourceName:r,targetName:l,stream:u,streamId:a,desiredSize:t.desiredSize});return e.promise},cancel:t=>{(0,i.assert)(t instanceof Error,"cancel must have a valid reason");const e=Promise.withResolvers();this.streamControllers[a].cancelCall=e;this.streamControllers[a].isClosed=!0;h.postMessage({sourceName:r,targetName:l,stream:o,streamId:a,reason:wrapReason(t)});return e.promise}},n)}#h(t){const e=t.streamId,n=this.sourceName,s=t.sourceName,a=this.comObj,r=this,o=this.actionHandler[t.action],l={enqueue(t,i=1,r){if(this.isCancelled)return;const o=this.desiredSize;this.desiredSize-=i;if(o>0&&this.desiredSize<=0){this.sinkCapability=Promise.withResolvers();this.ready=this.sinkCapability.promise}a.postMessage({sourceName:n,targetName:s,stream:d,streamId:e,chunk:t},r)},close(){if(!this.isCancelled){this.isCancelled=!0;a.postMessage({sourceName:n,targetName:s,stream:h,streamId:e});delete r.streamSinks[e]}},error(t){(0,i.assert)(t instanceof Error,"error must have a valid reason");if(!this.isCancelled){this.isCancelled=!0;a.postMessage({sourceName:n,targetName:s,stream:c,streamId:e,reason:wrapReason(t)})}},sinkCapability:Promise.withResolvers(),onPull:null,onCancel:null,isCancelled:!1,desiredSize:t.desiredSize,ready:null};l.sinkCapability.resolve();l.ready=l.sinkCapability.promise;this.streamSinks[e]=l;Promise.try(o,t.data,l).then((function(){a.postMessage({sourceName:n,targetName:s,stream:g,streamId:e,success:!0})}),(function(t){a.postMessage({sourceName:n,targetName:s,stream:g,streamId:e,reason:wrapReason(t)})}))}#l(t){const e=t.streamId,n=this.sourceName,s=t.sourceName,a=this.comObj,r=this.streamControllers[e],m=this.streamSinks[e];switch(t.stream){case g:t.success?r.startCall.resolve():r.startCall.reject(wrapReason(t.reason));break;case p:t.success?r.pullCall.resolve():r.pullCall.reject(wrapReason(t.reason));break;case u:if(!m){a.postMessage({sourceName:n,targetName:s,stream:p,streamId:e,success:!0});break}m.desiredSize<=0&&t.desiredSize>0&&m.sinkCapability.resolve();m.desiredSize=t.desiredSize;Promise.try(m.onPull||onFn).then((function(){a.postMessage({sourceName:n,targetName:s,stream:p,streamId:e,success:!0})}),(function(t){a.postMessage({sourceName:n,targetName:s,stream:p,streamId:e,reason:wrapReason(t)})}));break;case d:(0,i.assert)(r,"enqueue should have stream controller");if(r.isClosed)break;r.controller.enqueue(t.chunk);break;case h:(0,i.assert)(r,"close should have stream controller");if(r.isClosed)break;r.isClosed=!0;r.controller.close();this.#d(r,e);break;case c:(0,i.assert)(r,"error should have stream controller");r.controller.error(wrapReason(t.reason));this.#d(r,e);break;case l:t.success?r.cancelCall.resolve():r.cancelCall.reject(wrapReason(t.reason));this.#d(r,e);break;case o:if(!m)break;const f=wrapReason(t.reason);Promise.try(m.onCancel||onFn,f).then((function(){a.postMessage({sourceName:n,targetName:s,stream:l,streamId:e,success:!0})}),(function(t){a.postMessage({sourceName:n,targetName:s,stream:l,streamId:e,reason:wrapReason(t)})}));m.sinkCapability.reject(f);m.isCancelled=!0;delete this.streamSinks[e];break;default:throw new Error("Unexpected stream case")}}async#d(t,e){await Promise.allSettled([t.startCall?.promise,t.pullCall?.promise,t.cancelCall?.promise]);delete this.streamControllers[e]}destroy(){this.#r?.abort();this.#r=null}}class BaseCanvasFactory{#c=!1;constructor({enableHWA:t=!1}){this.#c=t}create(t,e){if(t<=0||e<=0)throw new Error("Invalid canvas size");const i=this._createCanvas(t,e);return{canvas:i,context:i.getContext("2d",{willReadFrequently:!this.#c})}}reset(t,e,i){if(!t.canvas)throw new Error("Canvas is not specified");if(e<=0||i<=0)throw new Error("Invalid canvas size");t.canvas.width=e;t.canvas.height=i}destroy(t){if(!t.canvas)throw new Error("Canvas is not specified");t.canvas.width=0;t.canvas.height=0;t.canvas=null;t.context=null}_createCanvas(t,e){(0,i.unreachable)("Abstract method `_createCanvas` called.")}}class BaseCMapReaderFactory{constructor({baseUrl:t=null,isCompressed:e=!0}){this.baseUrl=t;this.isCompressed=e}async fetch({name:t}){if(!this.baseUrl)throw new Error("Ensure that the `cMapUrl` and `cMapPacked` API parameters are provided.");if(!t)throw new Error("CMap name must be specified.");const e=this.baseUrl+t+(this.isCompressed?".bcmap":"");return this._fetch(e).then((t=>({cMapData:t,isCompressed:this.isCompressed}))).catch((t=>{throw new Error(`Unable to load ${this.isCompressed?"binary ":""}CMap at: ${e}`)}))}async _fetch(t){(0,i.unreachable)("Abstract method `_fetch` called.")}}class DOMCMapReaderFactory extends BaseCMapReaderFactory{async _fetch(t){const e=await(0,s.fetchData)(t,this.isCompressed?"arraybuffer":"text");return e instanceof ArrayBuffer?new Uint8Array(e):(0,i.stringToBytes)(e)}}class BaseFilterFactory{addFilter(t){return"none"}addHCMFilter(t,e){return"none"}addAlphaFilter(t){return"none"}addLuminosityFilter(t){return"none"}addHighlightHCMFilter(t,e,i,n,s){return"none"}destroy(t=!1){}}class BaseStandardFontDataFactory{constructor({baseUrl:t=null}){this.baseUrl=t}async fetch({filename:t}){if(!this.baseUrl)throw new Error("Ensure that the `standardFontDataUrl` API parameter is provided.");if(!t)throw new Error("Font filename must be specified.");const e=`${this.baseUrl}${t}`;return this._fetch(e).catch((t=>{throw new Error(`Unable to load font data at: ${e}`)}))}async _fetch(t){(0,i.unreachable)("Abstract method `_fetch` called.")}}class DOMStandardFontDataFactory extends BaseStandardFontDataFactory{async _fetch(t){const e=await(0,s.fetchData)(t,"arraybuffer");return new Uint8Array(e)}}async function fetchData(t){const e=process.getBuiltinModule("fs"),i=await e.promises.readFile(t);return new Uint8Array(i)}const m="Fill",f="Stroke",b="Shading";function applyBoundingBox(t,e){if(!e)return;const i=e[2]-e[0],n=e[3]-e[1],s=new Path2D;s.rect(e[0],e[1],i,n);t.clip(s)}class BaseShadingPattern{getPattern(){(0,i.unreachable)("Abstract method `getPattern` called.")}}class RadialAxialShadingPattern extends BaseShadingPattern{constructor(t){super();this._type=t[1];this._bbox=t[2];this._colorStops=t[3];this._p0=t[4];this._p1=t[5];this._r0=t[6];this._r1=t[7];this.matrix=null}_createGradient(t){let e;"axial"===this._type?e=t.createLinearGradient(this._p0[0],this._p0[1],this._p1[0],this._p1[1]):"radial"===this._type&&(e=t.createRadialGradient(this._p0[0],this._p0[1],this._r0,this._p1[0],this._p1[1],this._r1));for(const t of this._colorStops)e.addColorStop(t[0],t[1]);return e}getPattern(t,e,n,a){let r;if(a===f||a===m){const o=e.current.getClippedPathBoundingBox(a,(0,s.getCurrentTransform)(t))||[0,0,0,0],l=Math.ceil(o[2]-o[0])||1,h=Math.ceil(o[3]-o[1])||1,d=e.cachedCanvases.getCanvas("pattern",l,h),c=d.context;c.clearRect(0,0,c.canvas.width,c.canvas.height);c.beginPath();c.rect(0,0,c.canvas.width,c.canvas.height);c.translate(-o[0],-o[1]);n=i.Util.transform(n,[1,0,0,1,o[0],o[1]]);c.transform(...e.baseTransform);this.matrix&&c.transform(...this.matrix);applyBoundingBox(c,this._bbox);c.fillStyle=this._createGradient(c);c.fill();r=t.createPattern(d.canvas,"no-repeat");const u=new DOMMatrix(n);r.setTransform(u)}else{applyBoundingBox(t,this._bbox);r=this._createGradient(t)}return r}}function drawTriangle(t,e,i,n,s,a,r,o){const l=e.coords,h=e.colors,d=t.data,c=4*t.width;let u;if(l[i+1]>l[n+1]){u=i;i=n;n=u;u=a;a=r;r=u}if(l[n+1]>l[s+1]){u=n;n=s;s=u;u=r;r=o;o=u}if(l[i+1]>l[n+1]){u=i;i=n;n=u;u=a;a=r;r=u}const p=(l[i]+e.offsetX)*e.scaleX,g=(l[i+1]+e.offsetY)*e.scaleY,m=(l[n]+e.offsetX)*e.scaleX,f=(l[n+1]+e.offsetY)*e.scaleY,b=(l[s]+e.offsetX)*e.scaleX,w=(l[s+1]+e.offsetY)*e.scaleY;if(g>=w)return;const v=h[a],y=h[a+1],A=h[a+2],x=h[r],E=h[r+1],S=h[r+2],P=h[o],_=h[o+1],C=h[o+2],T=Math.round(g),M=Math.round(w);let I,D,L,k,F,R,N,B;for(let t=T;t<=M;t++){if(t<f){const e=t<g?0:(g-t)/(g-f);I=p-(p-m)*e;D=v-(v-x)*e;L=y-(y-E)*e;k=A-(A-S)*e}else{let e;e=t>w?1:f===w?0:(f-t)/(f-w);I=m-(m-b)*e;D=x-(x-P)*e;L=E-(E-_)*e;k=S-(S-C)*e}let e;e=t<g?0:t>w?1:(g-t)/(g-w);F=p-(p-b)*e;R=v-(v-P)*e;N=y-(y-_)*e;B=A-(A-C)*e;const i=Math.round(Math.min(I,F)),n=Math.round(Math.max(I,F));let s=c*t+4*i;for(let t=i;t<=n;t++){e=(I-t)/(I-F);e<0?e=0:e>1&&(e=1);d[s++]=D-(D-R)*e|0;d[s++]=L-(L-N)*e|0;d[s++]=k-(k-B)*e|0;d[s++]=255}}}function drawFigure(t,e,i){const n=e.coords,s=e.colors;let a,r;switch(e.type){case"lattice":const o=e.verticesPerRow,l=Math.floor(n.length/o)-1,h=o-1;for(a=0;a<l;a++){let e=a*o;for(let a=0;a<h;a++,e++){drawTriangle(t,i,n[e],n[e+1],n[e+o],s[e],s[e+1],s[e+o]);drawTriangle(t,i,n[e+o+1],n[e+1],n[e+o],s[e+o+1],s[e+1],s[e+o])}}break;case"triangles":for(a=0,r=n.length;a<r;a+=3)drawTriangle(t,i,n[a],n[a+1],n[a+2],s[a],s[a+1],s[a+2]);break;default:throw new Error("illegal figure")}}class MeshShadingPattern extends BaseShadingPattern{constructor(t){super();this._coords=t[2];this._colors=t[3];this._figures=t[4];this._bounds=t[5];this._bbox=t[7];this._background=t[8];this.matrix=null}_createMeshCanvas(t,e,i){const n=Math.floor(this._bounds[0]),s=Math.floor(this._bounds[1]),a=Math.ceil(this._bounds[2])-n,r=Math.ceil(this._bounds[3])-s,o=Math.min(Math.ceil(Math.abs(a*t[0]*1.1)),3e3),l=Math.min(Math.ceil(Math.abs(r*t[1]*1.1)),3e3),h=a/o,d=r/l,c={coords:this._coords,colors:this._colors,offsetX:-n,offsetY:-s,scaleX:1/h,scaleY:1/d},u=o+4,p=l+4,g=i.getCanvas("mesh",u,p),m=g.context,f=m.createImageData(o,l);if(e){const t=f.data;for(let i=0,n=t.length;i<n;i+=4){t[i]=e[0];t[i+1]=e[1];t[i+2]=e[2];t[i+3]=255}}for(const t of this._figures)drawFigure(f,t,c);m.putImageData(f,2,2);return{canvas:g.canvas,offsetX:n-2*h,offsetY:s-2*d,scaleX:h,scaleY:d}}getPattern(t,e,n,a){applyBoundingBox(t,this._bbox);let r;if(a===b)r=i.Util.singularValueDecompose2dScale((0,s.getCurrentTransform)(t));else{r=i.Util.singularValueDecompose2dScale(e.baseTransform);if(this.matrix){const t=i.Util.singularValueDecompose2dScale(this.matrix);r=[r[0]*t[0],r[1]*t[1]]}}const o=this._createMeshCanvas(r,a===b?null:this._background,e.cachedCanvases);if(a!==b){t.setTransform(...e.baseTransform);this.matrix&&t.transform(...this.matrix)}t.translate(o.offsetX,o.offsetY);t.scale(o.scaleX,o.scaleY);return t.createPattern(o.canvas,"no-repeat")}}class DummyShadingPattern extends BaseShadingPattern{getPattern(){return"hotpink"}}const w=1,v=2;class TilingPattern{static MAX_PATTERN_SIZE=3e3;constructor(t,e,i,n,s){this.operatorList=t[2];this.matrix=t[3];this.bbox=t[4];this.xstep=t[5];this.ystep=t[6];this.paintType=t[7];this.tilingType=t[8];this.color=e;this.ctx=i;this.canvasGraphicsFactory=n;this.baseTransform=s}createPatternCanvas(t){const{bbox:e,operatorList:n,paintType:a,tilingType:r,color:o,canvasGraphicsFactory:l}=this;let{xstep:h,ystep:d}=this;h=Math.abs(h);d=Math.abs(d);(0,i.info)("TilingType: "+r);const c=e[0],u=e[1],p=e[2],g=e[3],m=p-c,f=g-u,b=i.Util.singularValueDecompose2dScale(this.matrix),w=i.Util.singularValueDecompose2dScale(this.baseTransform),v=b[0]*w[0],y=b[1]*w[1];let A=m,x=f,E=!1,S=!1;const P=Math.ceil(h*v),_=Math.ceil(d*y);P>=Math.ceil(m*v)?A=h:E=!0;_>=Math.ceil(f*y)?x=d:S=!0;const C=this.getSizeAndScale(A,this.ctx.canvas.width,v),T=this.getSizeAndScale(x,this.ctx.canvas.height,y),M=t.cachedCanvases.getCanvas("pattern",C.size,T.size),I=M.context,D=l.createCanvasGraphics(I);D.groupLevel=t.groupLevel;this.setFillAndStrokeStyleToContext(D,a,o);I.translate(-C.scale*c,-T.scale*u);D.transform(C.scale,0,0,T.scale,0,0);I.save();this.clipBbox(D,c,u,p,g);D.baseTransform=(0,s.getCurrentTransform)(D.ctx);D.executeOperatorList(n);D.endDrawing();I.restore();if(E||S){const e=M.canvas;E&&(A=h);S&&(x=d);const i=this.getSizeAndScale(A,this.ctx.canvas.width,v),n=this.getSizeAndScale(x,this.ctx.canvas.height,y),s=i.size,a=n.size,r=t.cachedCanvases.getCanvas("pattern-workaround",s,a),o=r.context,l=E?Math.floor(m/h):0,p=S?Math.floor(f/d):0;for(let t=0;t<=l;t++)for(let i=0;i<=p;i++)o.drawImage(e,s*t,a*i,s,a,0,0,s,a);return{canvas:r.canvas,scaleX:i.scale,scaleY:n.scale,offsetX:c,offsetY:u}}return{canvas:M.canvas,scaleX:C.scale,scaleY:T.scale,offsetX:c,offsetY:u}}getSizeAndScale(t,e,i){const n=Math.max(TilingPattern.MAX_PATTERN_SIZE,e);let s=Math.ceil(t*i);s>=n?s=n:i=s/t;return{scale:i,size:s}}clipBbox(t,e,i,n,a){const r=n-e,o=a-i;t.ctx.rect(e,i,r,o);t.current.updateRectMinMax((0,s.getCurrentTransform)(t.ctx),[e,i,n,a]);t.clip();t.endPath()}setFillAndStrokeStyleToContext(t,e,n){const s=t.ctx,a=t.current;switch(e){case w:const t=this.ctx;s.fillStyle=t.fillStyle;s.strokeStyle=t.strokeStyle;a.fillColor=t.fillStyle;a.strokeColor=t.strokeStyle;break;case v:const r=i.Util.makeHexColor(n[0],n[1],n[2]);s.fillStyle=r;s.strokeStyle=r;a.fillColor=r;a.strokeColor=r;break;default:throw new i.FormatError(`Unsupported paint type: ${e}`)}}getPattern(t,e,n,s){let a=n;if(s!==b){a=i.Util.transform(a,e.baseTransform);this.matrix&&(a=i.Util.transform(a,this.matrix))}const r=this.createPatternCanvas(e);let o=new DOMMatrix(a);o=o.translate(r.offsetX,r.offsetY);o=o.scale(1/r.scaleX,1/r.scaleY);const l=t.createPattern(r.canvas,"repeat");l.setTransform(o);return l}}function convertBlackAndWhiteToRGBA({src:t,srcPos:e=0,dest:n,width:s,height:a,nonBlackColor:r=4294967295,inverseDecode:o=!1}){const l=i.FeatureTest.isLittleEndian?4278190080:255,[h,d]=o?[r,l]:[l,r],c=s>>3,u=7&s,p=t.length;n=new Uint32Array(n.buffer);let g=0;for(let i=0;i<a;i++){for(const i=e+c;e<i;e++){const i=e<p?t[e]:255;n[g++]=128&i?d:h;n[g++]=64&i?d:h;n[g++]=32&i?d:h;n[g++]=16&i?d:h;n[g++]=8&i?d:h;n[g++]=4&i?d:h;n[g++]=2&i?d:h;n[g++]=1&i?d:h}if(0===u)continue;const i=e<p?t[e++]:255;for(let t=0;t<u;t++)n[g++]=i&1<<7-t?d:h}return{srcPos:e,destPos:g}}const y=16;class CachedCanvases{constructor(t){this.canvasFactory=t;this.cache=Object.create(null)}getCanvas(t,e,i){let n;if(void 0!==this.cache[t]){n=this.cache[t];this.canvasFactory.reset(n,e,i)}else{n=this.canvasFactory.create(e,i);this.cache[t]=n}return n}delete(t){delete this.cache[t]}clear(){for(const t in this.cache){const e=this.cache[t];this.canvasFactory.destroy(e);delete this.cache[t]}}}function drawImageAtIntegerCoords(t,e,i,n,a,r,o,l,h,d){const[c,u,p,g,m,f]=(0,s.getCurrentTransform)(t);if(0===u&&0===p){const s=o*c+m,b=Math.round(s),w=l*g+f,v=Math.round(w),y=(o+h)*c+m,A=Math.abs(Math.round(y)-b)||1,x=(l+d)*g+f,E=Math.abs(Math.round(x)-v)||1;t.setTransform(Math.sign(c),0,0,Math.sign(g),b,v);t.drawImage(e,i,n,a,r,0,0,A,E);t.setTransform(c,u,p,g,m,f);return[A,E]}if(0===c&&0===g){const s=l*p+m,b=Math.round(s),w=o*u+f,v=Math.round(w),y=(l+d)*p+m,A=Math.abs(Math.round(y)-b)||1,x=(o+h)*u+f,E=Math.abs(Math.round(x)-v)||1;t.setTransform(0,Math.sign(u),Math.sign(p),0,b,v);t.drawImage(e,i,n,a,r,0,0,E,A);t.setTransform(c,u,p,g,m,f);return[E,A]}t.drawImage(e,i,n,a,r,o,l,h,d);return[Math.hypot(c,u)*h,Math.hypot(p,g)*d]}class CanvasExtraState{constructor(t,e){this.alphaIsShape=!1;this.fontSize=0;this.fontSizeScale=1;this.textMatrix=i.IDENTITY_MATRIX;this.textMatrixScale=1;this.fontMatrix=i.FONT_IDENTITY_MATRIX;this.leading=0;this.x=0;this.y=0;this.lineX=0;this.lineY=0;this.charSpacing=0;this.wordSpacing=0;this.textHScale=1;this.textRenderingMode=i.TextRenderingMode.FILL;this.textRise=0;this.fillColor="#000000";this.strokeColor="#000000";this.patternFill=!1;this.patternStroke=!1;this.fillAlpha=1;this.strokeAlpha=1;this.lineWidth=1;this.activeSMask=null;this.transferMaps="none";this.startNewPathAndClipBox([0,0,t,e])}clone(){const t=Object.create(this);t.clipBox=this.clipBox.slice();return t}setCurrentPoint(t,e){this.x=t;this.y=e}updatePathMinMax(t,e,n){[e,n]=i.Util.applyTransform([e,n],t);this.minX=Math.min(this.minX,e);this.minY=Math.min(this.minY,n);this.maxX=Math.max(this.maxX,e);this.maxY=Math.max(this.maxY,n)}updateRectMinMax(t,e){const n=i.Util.applyTransform(e,t),s=i.Util.applyTransform(e.slice(2),t),a=i.Util.applyTransform([e[0],e[3]],t),r=i.Util.applyTransform([e[2],e[1]],t);this.minX=Math.min(this.minX,n[0],s[0],a[0],r[0]);this.minY=Math.min(this.minY,n[1],s[1],a[1],r[1]);this.maxX=Math.max(this.maxX,n[0],s[0],a[0],r[0]);this.maxY=Math.max(this.maxY,n[1],s[1],a[1],r[1])}updateScalingPathMinMax(t,e){i.Util.scaleMinMax(t,e);this.minX=Math.min(this.minX,e[0]);this.minY=Math.min(this.minY,e[1]);this.maxX=Math.max(this.maxX,e[2]);this.maxY=Math.max(this.maxY,e[3])}updateCurvePathMinMax(t,e,n,s,a,r,o,l,h,d){const c=i.Util.bezierBoundingBox(e,n,s,a,r,o,l,h,d);d||this.updateRectMinMax(t,c)}getPathBoundingBox(t=m,e=null){const n=[this.minX,this.minY,this.maxX,this.maxY];if(t===f){e||(0,i.unreachable)("Stroke bounding box must include transform.");const t=i.Util.singularValueDecompose2dScale(e),s=t[0]*this.lineWidth/2,a=t[1]*this.lineWidth/2;n[0]-=s;n[1]-=a;n[2]+=s;n[3]+=a}return n}updateClipFromPath(){const t=i.Util.intersect(this.clipBox,this.getPathBoundingBox());this.startNewPathAndClipBox(t||[0,0,0,0])}isEmptyClip(){return this.minX===1/0}startNewPathAndClipBox(t){this.clipBox=t;this.minX=1/0;this.minY=1/0;this.maxX=0;this.maxY=0}getClippedPathBoundingBox(t=m,e=null){return i.Util.intersect(this.clipBox,this.getPathBoundingBox(t,e))}}function putBinaryImageData(t,e){if(e instanceof ImageData){t.putImageData(e,0,0);return}const n=e.height,s=e.width,a=n%y,r=(n-a)/y,o=0===a?r:r+1,l=t.createImageData(s,y);let h,d=0;const c=e.data,u=l.data;let p,g,m,f;if(e.kind===i.ImageKind.GRAYSCALE_1BPP){const e=c.byteLength,n=new Uint32Array(u.buffer,0,u.byteLength>>2),f=n.length,b=s+7>>3,w=4294967295,v=i.FeatureTest.isLittleEndian?4278190080:255;for(p=0;p<o;p++){m=p<r?y:a;h=0;for(g=0;g<m;g++){const t=e-d;let i=0;const a=t>b?s:8*t-7,r=-8&a;let o=0,l=0;for(;i<r;i+=8){l=c[d++];n[h++]=128&l?w:v;n[h++]=64&l?w:v;n[h++]=32&l?w:v;n[h++]=16&l?w:v;n[h++]=8&l?w:v;n[h++]=4&l?w:v;n[h++]=2&l?w:v;n[h++]=1&l?w:v}for(;i<a;i++){if(0===o){l=c[d++];o=128}n[h++]=l&o?w:v;o>>=1}}for(;h<f;)n[h++]=0;t.putImageData(l,0,p*y)}}else if(e.kind===i.ImageKind.RGBA_32BPP){g=0;f=s*y*4;for(p=0;p<r;p++){u.set(c.subarray(d,d+f));d+=f;t.putImageData(l,0,g);g+=y}if(p<o){f=s*a*4;u.set(c.subarray(d,d+f));t.putImageData(l,0,g)}}else{if(e.kind!==i.ImageKind.RGB_24BPP)throw new Error(`bad image kind: ${e.kind}`);m=y;f=s*m;for(p=0;p<o;p++){if(p>=r){m=a;f=s*m}h=0;for(g=f;g--;){u[h++]=c[d++];u[h++]=c[d++];u[h++]=c[d++];u[h++]=255}t.putImageData(l,0,p*y)}}}function putBinaryImageMask(t,e){if(e.bitmap){t.drawImage(e.bitmap,0,0);return}const i=e.height,n=e.width,s=i%y,a=(i-s)/y,r=0===s?a:a+1,o=t.createImageData(n,y);let l=0;const h=e.data,d=o.data;for(let e=0;e<r;e++){const i=e<a?y:s;({srcPos:l}=convertBlackAndWhiteToRGBA({src:h,srcPos:l,dest:d,width:n,height:i,nonBlackColor:0}));t.putImageData(o,0,e*y)}}function copyCtxState(t,e){const i=["strokeStyle","fillStyle","fillRule","globalAlpha","lineWidth","lineCap","lineJoin","miterLimit","globalCompositeOperation","font","filter"];for(const n of i)void 0!==t[n]&&(e[n]=t[n]);if(void 0!==t.setLineDash){e.setLineDash(t.getLineDash());e.lineDashOffset=t.lineDashOffset}}function resetCtxToDefault(t){t.strokeStyle=t.fillStyle="#000000";t.fillRule="nonzero";t.globalAlpha=1;t.lineWidth=1;t.lineCap="butt";t.lineJoin="miter";t.miterLimit=10;t.globalCompositeOperation="source-over";t.font="10px sans-serif";if(void 0!==t.setLineDash){t.setLineDash([]);t.lineDashOffset=0}if(!i.isNodeJS){const{filter:e}=t;"none"!==e&&""!==e&&(t.filter="none")}}function getImageSmoothingEnabled(t,e){if(e)return!0;const n=i.Util.singularValueDecompose2dScale(t);n[0]=Math.fround(n[0]);n[1]=Math.fround(n[1]);const a=Math.fround((globalThis.devicePixelRatio||1)*s.PixelsPerInch.PDF_TO_CSS_UNITS);return n[0]<=a&&n[1]<=a}const A=["butt","round","square"],x=["miter","round","bevel"],E={},S={};class CanvasGraphics{constructor(t,e,i,n,s,{optionalContentConfig:a,markedContentStack:r=null},o,l){this.ctx=t;this.current=new CanvasExtraState(this.ctx.canvas.width,this.ctx.canvas.height);this.stateStack=[];this.pendingClip=null;this.pendingEOFill=!1;this.res=null;this.xobjs=null;this.commonObjs=e;this.objs=i;this.canvasFactory=n;this.filterFactory=s;this.groupStack=[];this.processingType3=null;this.baseTransform=null;this.baseTransformStack=[];this.groupLevel=0;this.smaskStack=[];this.smaskCounter=0;this.tempSMask=null;this.suspendedCtx=null;this.contentVisible=!0;this.markedContentStack=r||[];this.optionalContentConfig=a;this.cachedCanvases=new CachedCanvases(this.canvasFactory);this.cachedPatterns=new Map;this.annotationCanvasMap=o;this.viewportScale=1;this.outputScaleX=1;this.outputScaleY=1;this.pageColors=l;this._cachedScaleForStroking=[-1,0];this._cachedGetSinglePixelWidth=null;this._cachedBitmapsMap=new Map}getObject(t,e=null){return"string"==typeof t?t.startsWith("g_")?this.commonObjs.get(t):this.objs.get(t):e}beginDrawing({transform:t,viewport:e,transparency:i=!1,background:n=null}){const a=this.ctx.canvas.width,r=this.ctx.canvas.height,o=this.ctx.fillStyle;this.ctx.fillStyle=n||"#ffffff";this.ctx.fillRect(0,0,a,r);this.ctx.fillStyle=o;if(i){const t=this.cachedCanvases.getCanvas("transparent",a,r);this.compositeCtx=this.ctx;this.transparentCanvas=t.canvas;this.ctx=t.context;this.ctx.save();this.ctx.transform(...(0,s.getCurrentTransform)(this.compositeCtx))}this.ctx.save();resetCtxToDefault(this.ctx);if(t){this.ctx.transform(...t);this.outputScaleX=t[0];this.outputScaleY=t[0]}this.ctx.transform(...e.transform);this.viewportScale=e.scale;this.baseTransform=(0,s.getCurrentTransform)(this.ctx)}executeOperatorList(t,e,n,s){const a=t.argsArray,r=t.fnArray;let o=e||0;const l=a.length;if(l===o)return o;const h=l-o>10&&"function"==typeof n,d=h?Date.now()+15:0;let c=0;const u=this.commonObjs,p=this.objs;let g;for(;;){if(void 0!==s&&o===s.nextBreakPoint){s.breakIt(o,n);return o}g=r[o];if(g!==i.OPS.dependency)this[g].apply(this,a[o]);else for(const t of a[o]){const e=t.startsWith("g_")?u:p;if(!e.has(t)){e.get(t,n);return o}}o++;if(o===l)return o;if(h&&++c>10){if(Date.now()>d){n();return o}c=0}}}#u(){for(;this.stateStack.length||this.inSMaskMode;)this.restore();this.current.activeSMask=null;this.ctx.restore();if(this.transparentCanvas){this.ctx=this.compositeCtx;this.ctx.save();this.ctx.setTransform(1,0,0,1,0,0);this.ctx.drawImage(this.transparentCanvas,0,0);this.ctx.restore();this.transparentCanvas=null}}endDrawing(){this.#u();this.cachedCanvases.clear();this.cachedPatterns.clear();for(const t of this._cachedBitmapsMap.values()){for(const e of t.values())"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement&&(e.width=e.height=0);t.clear()}this._cachedBitmapsMap.clear();this.#p()}#p(){if(this.pageColors){const t=this.filterFactory.addHCMFilter(this.pageColors.foreground,this.pageColors.background);if("none"!==t){const e=this.ctx.filter;this.ctx.filter=t;this.ctx.drawImage(this.ctx.canvas,0,0);this.ctx.filter=e}}}_scaleImage(t,e){const i=t.width??t.displayWidth,n=t.height??t.displayHeight;let s,a,r=Math.max(Math.hypot(e[0],e[1]),1),o=Math.max(Math.hypot(e[2],e[3]),1),l=i,h=n,d="prescale1";for(;r>2&&l>1||o>2&&h>1;){let e=l,i=h;if(r>2&&l>1){e=l>=16384?Math.floor(l/2)-1||1:Math.ceil(l/2);r/=l/e}if(o>2&&h>1){i=h>=16384?Math.floor(h/2)-1||1:Math.ceil(h)/2;o/=h/i}s=this.cachedCanvases.getCanvas(d,e,i);a=s.context;a.clearRect(0,0,e,i);a.drawImage(t,0,0,l,h,0,0,e,i);t=s.canvas;l=e;h=i;d="prescale1"===d?"prescale2":"prescale1"}return{img:t,paintWidth:l,paintHeight:h}}_createMaskCanvas(t){const e=this.ctx,{width:n,height:a}=t,r=this.current.fillColor,o=this.current.patternFill,l=(0,s.getCurrentTransform)(e);let h,d,c,u;if((t.bitmap||t.data)&&t.count>1){const e=t.bitmap||t.data.buffer;d=JSON.stringify(o?l:[l.slice(0,4),r]);h=this._cachedBitmapsMap.get(e);if(!h){h=new Map;this._cachedBitmapsMap.set(e,h)}const i=h.get(d);if(i&&!o){return{canvas:i,offsetX:Math.round(Math.min(l[0],l[2])+l[4]),offsetY:Math.round(Math.min(l[1],l[3])+l[5])}}c=i}if(!c){u=this.cachedCanvases.getCanvas("maskCanvas",n,a);putBinaryImageMask(u.context,t)}let p=i.Util.transform(l,[1/n,0,0,-1/a,0,0]);p=i.Util.transform(p,[1,0,0,1,0,-a]);const[g,f,b,w]=i.Util.getAxialAlignedBoundingBox([0,0,n,a],p),v=Math.round(b-g)||1,y=Math.round(w-f)||1,A=this.cachedCanvases.getCanvas("fillCanvas",v,y),x=A.context,E=g,S=f;x.translate(-E,-S);x.transform(...p);if(!c){c=this._scaleImage(u.canvas,(0,s.getCurrentTransformInverse)(x));c=c.img;h&&o&&h.set(d,c)}x.imageSmoothingEnabled=getImageSmoothingEnabled((0,s.getCurrentTransform)(x),t.interpolate);drawImageAtIntegerCoords(x,c,0,0,c.width,c.height,0,0,n,a);x.globalCompositeOperation="source-in";const P=i.Util.transform((0,s.getCurrentTransformInverse)(x),[1,0,0,1,-E,-S]);x.fillStyle=o?r.getPattern(e,this,P,m):r;x.fillRect(0,0,n,a);if(h&&!o){this.cachedCanvases.delete("fillCanvas");h.set(d,A.canvas)}return{canvas:A.canvas,offsetX:Math.round(E),offsetY:Math.round(S)}}setLineWidth(t){t!==this.current.lineWidth&&(this._cachedScaleForStroking[0]=-1);this.current.lineWidth=t;this.ctx.lineWidth=t}setLineCap(t){this.ctx.lineCap=A[t]}setLineJoin(t){this.ctx.lineJoin=x[t]}setMiterLimit(t){this.ctx.miterLimit=t}setDash(t,e){const i=this.ctx;if(void 0!==i.setLineDash){i.setLineDash(t);i.lineDashOffset=e}}setRenderingIntent(t){}setFlatness(t){}setGState(t){for(const[e,i]of t)switch(e){case"LW":this.setLineWidth(i);break;case"LC":this.setLineCap(i);break;case"LJ":this.setLineJoin(i);break;case"ML":this.setMiterLimit(i);break;case"D":this.setDash(i[0],i[1]);break;case"RI":this.setRenderingIntent(i);break;case"FL":this.setFlatness(i);break;case"Font":this.setFont(i[0],i[1]);break;case"CA":this.current.strokeAlpha=i;break;case"ca":this.current.fillAlpha=i;this.ctx.globalAlpha=i;break;case"BM":this.ctx.globalCompositeOperation=i;break;case"SMask":this.current.activeSMask=i?this.tempSMask:null;this.tempSMask=null;this.checkSMaskState();break;case"TR":this.ctx.filter=this.current.transferMaps=this.filterFactory.addFilter(i)}}get inSMaskMode(){return!!this.suspendedCtx}checkSMaskState(){const t=this.inSMaskMode;this.current.activeSMask&&!t?this.beginSMaskMode():!this.current.activeSMask&&t&&this.endSMaskMode()}beginSMaskMode(){if(this.inSMaskMode)throw new Error("beginSMaskMode called while already in smask mode");const t=this.ctx.canvas.width,e=this.ctx.canvas.height,i="smaskGroupAt"+this.groupLevel,n=this.cachedCanvases.getCanvas(i,t,e);this.suspendedCtx=this.ctx;this.ctx=n.context;const a=this.ctx;a.setTransform(...(0,s.getCurrentTransform)(this.suspendedCtx));copyCtxState(this.suspendedCtx,a);!function mirrorContextOperations(t,e){if(t._removeMirroring)throw new Error("Context is already forwarding operations.");t.__originalSave=t.save;t.__originalRestore=t.restore;t.__originalRotate=t.rotate;t.__originalScale=t.scale;t.__originalTranslate=t.translate;t.__originalTransform=t.transform;t.__originalSetTransform=t.setTransform;t.__originalResetTransform=t.resetTransform;t.__originalClip=t.clip;t.__originalMoveTo=t.moveTo;t.__originalLineTo=t.lineTo;t.__originalBezierCurveTo=t.bezierCurveTo;t.__originalRect=t.rect;t.__originalClosePath=t.closePath;t.__originalBeginPath=t.beginPath;t._removeMirroring=()=>{t.save=t.__originalSave;t.restore=t.__originalRestore;t.rotate=t.__originalRotate;t.scale=t.__originalScale;t.translate=t.__originalTranslate;t.transform=t.__originalTransform;t.setTransform=t.__originalSetTransform;t.resetTransform=t.__originalResetTransform;t.clip=t.__originalClip;t.moveTo=t.__originalMoveTo;t.lineTo=t.__originalLineTo;t.bezierCurveTo=t.__originalBezierCurveTo;t.rect=t.__originalRect;t.closePath=t.__originalClosePath;t.beginPath=t.__originalBeginPath;delete t._removeMirroring};t.save=function ctxSave(){e.save();this.__originalSave()};t.restore=function ctxRestore(){e.restore();this.__originalRestore()};t.translate=function ctxTranslate(t,i){e.translate(t,i);this.__originalTranslate(t,i)};t.scale=function ctxScale(t,i){e.scale(t,i);this.__originalScale(t,i)};t.transform=function ctxTransform(t,i,n,s,a,r){e.transform(t,i,n,s,a,r);this.__originalTransform(t,i,n,s,a,r)};t.setTransform=function ctxSetTransform(t,i,n,s,a,r){e.setTransform(t,i,n,s,a,r);this.__originalSetTransform(t,i,n,s,a,r)};t.resetTransform=function ctxResetTransform(){e.resetTransform();this.__originalResetTransform()};t.rotate=function ctxRotate(t){e.rotate(t);this.__originalRotate(t)};t.clip=function ctxRotate(t){e.clip(t);this.__originalClip(t)};t.moveTo=function(t,i){e.moveTo(t,i);this.__originalMoveTo(t,i)};t.lineTo=function(t,i){e.lineTo(t,i);this.__originalLineTo(t,i)};t.bezierCurveTo=function(t,i,n,s,a,r){e.bezierCurveTo(t,i,n,s,a,r);this.__originalBezierCurveTo(t,i,n,s,a,r)};t.rect=function(t,i,n,s){e.rect(t,i,n,s);this.__originalRect(t,i,n,s)};t.closePath=function(){e.closePath();this.__originalClosePath()};t.beginPath=function(){e.beginPath();this.__originalBeginPath()}}(a,this.suspendedCtx);this.setGState([["BM","source-over"],["ca",1],["CA",1]])}endSMaskMode(){if(!this.inSMaskMode)throw new Error("endSMaskMode called while not in smask mode");this.ctx._removeMirroring();copyCtxState(this.ctx,this.suspendedCtx);this.ctx=this.suspendedCtx;this.suspendedCtx=null}compose(t){if(!this.current.activeSMask)return;if(t){t[0]=Math.floor(t[0]);t[1]=Math.floor(t[1]);t[2]=Math.ceil(t[2]);t[3]=Math.ceil(t[3])}else t=[0,0,this.ctx.canvas.width,this.ctx.canvas.height];const e=this.current.activeSMask,i=this.suspendedCtx;this.composeSMask(i,e,this.ctx,t);this.ctx.save();this.ctx.setTransform(1,0,0,1,0,0);this.ctx.clearRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height);this.ctx.restore()}composeSMask(t,e,i,n){const s=n[0],a=n[1],r=n[2]-s,o=n[3]-a;if(0!==r&&0!==o){this.genericComposeSMask(e.context,i,r,o,e.subtype,e.backdrop,e.transferMap,s,a,e.offsetX,e.offsetY);t.save();t.globalAlpha=1;t.globalCompositeOperation="source-over";t.setTransform(1,0,0,1,0,0);t.drawImage(i.canvas,0,0);t.restore()}}genericComposeSMask(t,e,n,s,a,r,o,l,h,d,c){let u=t.canvas,p=l-d,g=h-c;if(r){const e=i.Util.makeHexColor(...r);if(p<0||g<0||p+n>u.width||g+s>u.height){const t=this.cachedCanvases.getCanvas("maskExtension",n,s),i=t.context;i.drawImage(u,-p,-g);i.globalCompositeOperation="destination-atop";i.fillStyle=e;i.fillRect(0,0,n,s);i.globalCompositeOperation="source-over";u=t.canvas;p=g=0}else{t.save();t.globalAlpha=1;t.setTransform(1,0,0,1,0,0);const i=new Path2D;i.rect(p,g,n,s);t.clip(i);t.globalCompositeOperation="destination-atop";t.fillStyle=e;t.fillRect(p,g,n,s);t.restore()}}e.save();e.globalAlpha=1;e.setTransform(1,0,0,1,0,0);"Alpha"===a&&o?e.filter=this.filterFactory.addAlphaFilter(o):"Luminosity"===a&&(e.filter=this.filterFactory.addLuminosityFilter(o));const m=new Path2D;m.rect(l,h,n,s);e.clip(m);e.globalCompositeOperation="destination-in";e.drawImage(u,p,g,n,s,l,h,n,s);e.restore()}save(){if(this.inSMaskMode){copyCtxState(this.ctx,this.suspendedCtx);this.suspendedCtx.save()}else this.ctx.save();const t=this.current;this.stateStack.push(t);this.current=t.clone()}restore(){0===this.stateStack.length&&this.inSMaskMode&&this.endSMaskMode();if(0!==this.stateStack.length){this.current=this.stateStack.pop();if(this.inSMaskMode){this.suspendedCtx.restore();copyCtxState(this.suspendedCtx,this.ctx)}else this.ctx.restore();this.checkSMaskState();this.pendingClip=null;this._cachedScaleForStroking[0]=-1;this._cachedGetSinglePixelWidth=null}}transform(t,e,i,n,s,a){this.ctx.transform(t,e,i,n,s,a);this._cachedScaleForStroking[0]=-1;this._cachedGetSinglePixelWidth=null}constructPath(t,e,n){const a=this.ctx,r=this.current;let o,l,h=r.x,d=r.y;const c=(0,s.getCurrentTransform)(a),u=0===c[0]&&0===c[3]||0===c[1]&&0===c[2],p=u?n.slice(0):null;for(let n=0,s=0,g=t.length;n<g;n++)switch(0|t[n]){case i.OPS.rectangle:h=e[s++];d=e[s++];const t=e[s++],n=e[s++],g=h+t,m=d+n;a.moveTo(h,d);if(0===t||0===n)a.lineTo(g,m);else{a.lineTo(g,d);a.lineTo(g,m);a.lineTo(h,m)}u||r.updateRectMinMax(c,[h,d,g,m]);a.closePath();break;case i.OPS.moveTo:h=e[s++];d=e[s++];a.moveTo(h,d);u||r.updatePathMinMax(c,h,d);break;case i.OPS.lineTo:h=e[s++];d=e[s++];a.lineTo(h,d);u||r.updatePathMinMax(c,h,d);break;case i.OPS.curveTo:o=h;l=d;h=e[s+4];d=e[s+5];a.bezierCurveTo(e[s],e[s+1],e[s+2],e[s+3],h,d);r.updateCurvePathMinMax(c,o,l,e[s],e[s+1],e[s+2],e[s+3],h,d,p);s+=6;break;case i.OPS.curveTo2:o=h;l=d;a.bezierCurveTo(h,d,e[s],e[s+1],e[s+2],e[s+3]);r.updateCurvePathMinMax(c,o,l,h,d,e[s],e[s+1],e[s+2],e[s+3],p);h=e[s+2];d=e[s+3];s+=4;break;case i.OPS.curveTo3:o=h;l=d;h=e[s+2];d=e[s+3];a.bezierCurveTo(e[s],e[s+1],h,d,h,d);r.updateCurvePathMinMax(c,o,l,e[s],e[s+1],h,d,h,d,p);s+=4;break;case i.OPS.closePath:a.closePath()}u&&r.updateScalingPathMinMax(c,p);r.setCurrentPoint(h,d)}closePath(){this.ctx.closePath()}stroke(t=!0){const e=this.ctx,i=this.current.strokeColor;e.globalAlpha=this.current.strokeAlpha;if(this.contentVisible)if("object"==typeof i&&i?.getPattern){e.save();e.strokeStyle=i.getPattern(e,this,(0,s.getCurrentTransformInverse)(e),f);this.rescaleAndStroke(!1);e.restore()}else this.rescaleAndStroke(!0);t&&this.consumePath(this.current.getClippedPathBoundingBox());e.globalAlpha=this.current.fillAlpha}closeStroke(){this.closePath();this.stroke()}fill(t=!0){const e=this.ctx,i=this.current.fillColor;let n=!1;if(this.current.patternFill){e.save();e.fillStyle=i.getPattern(e,this,(0,s.getCurrentTransformInverse)(e),m);n=!0}const a=this.current.getClippedPathBoundingBox();if(this.contentVisible&&null!==a)if(this.pendingEOFill){e.fill("evenodd");this.pendingEOFill=!1}else e.fill();n&&e.restore();t&&this.consumePath(a)}eoFill(){this.pendingEOFill=!0;this.fill()}fillStroke(){this.fill(!1);this.stroke(!1);this.consumePath()}eoFillStroke(){this.pendingEOFill=!0;this.fillStroke()}closeFillStroke(){this.closePath();this.fillStroke()}closeEOFillStroke(){this.pendingEOFill=!0;this.closePath();this.fillStroke()}endPath(){this.consumePath()}clip(){this.pendingClip=E}eoClip(){this.pendingClip=S}beginText(){this.current.textMatrix=i.IDENTITY_MATRIX;this.current.textMatrixScale=1;this.current.x=this.current.lineX=0;this.current.y=this.current.lineY=0}endText(){const t=this.pendingTextPaths,e=this.ctx;if(void 0===t){e.beginPath();return}const i=new Path2D,n=e.getTransform().invertSelf();for(const{transform:e,x:s,y:a,fontSize:r,path:o}of t)i.addPath(o,new DOMMatrix(e).preMultiplySelf(n).translate(s,a).scale(r,-r));e.clip(i);e.beginPath();delete this.pendingTextPaths}setCharSpacing(t){this.current.charSpacing=t}setWordSpacing(t){this.current.wordSpacing=t}setHScale(t){this.current.textHScale=t/100}setLeading(t){this.current.leading=-t}setFont(t,e){const n=this.commonObjs.get(t),s=this.current;if(!n)throw new Error(`Can't find font for ${t}`);s.fontMatrix=n.fontMatrix||i.FONT_IDENTITY_MATRIX;0!==s.fontMatrix[0]&&0!==s.fontMatrix[3]||(0,i.warn)("Invalid font matrix for font "+t);if(e<0){e=-e;s.fontDirection=-1}else s.fontDirection=1;this.current.font=n;this.current.fontSize=e;if(n.isType3Font)return;const a=n.loadedName||"sans-serif",r=n.systemFontInfo?.css||`"${a}", ${n.fallbackName}`;let o="normal";n.black?o="900":n.bold&&(o="bold");const l=n.italic?"italic":"normal";let h=e;e<16?h=16:e>100&&(h=100);this.current.fontSizeScale=e/h;this.ctx.font=`${l} ${o} ${h}px ${r}`}setTextRenderingMode(t){this.current.textRenderingMode=t}setTextRise(t){this.current.textRise=t}moveText(t,e){this.current.x=this.current.lineX+=t;this.current.y=this.current.lineY+=e}setLeadingMoveText(t,e){this.setLeading(-e);this.moveText(t,e)}setTextMatrix(t,e,i,n,s,a){this.current.textMatrix=[t,e,i,n,s,a];this.current.textMatrixScale=Math.hypot(t,e);this.current.x=this.current.lineX=0;this.current.y=this.current.lineY=