pdfjs-dist
Version:
Generic build of Mozilla's PDF.js library.
25 lines • 122 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
*/
/**
* pdfjsVersion = 6.5.438
* pdfjsBuild = 0a4153349
*/
const t=!("object"!=typeof process||process+""!="[object process]"||process.versions.nw||process.versions.electron&&process.type&&"browser"!==process.type),e=[1/0,1/0,-1/0,-1/0],s=new Float32Array(e),r=[.001,0,0,.001,0,0],a=2,n=4,i=0,o=1,c=2,l=3,h=3,d=4,p=1,u=2,f=3,m=1,g=5,x={dependency:1,setLineWidth:2,setLineCap:3,setLineJoin:4,setMiterLimit:5,setDash:6,setRenderingIntent:7,setFlatness:8,setGState:9,save:10,restore:11,transform:12,moveTo:13,lineTo:14,curveTo:15,curveTo2:16,curveTo3:17,closePath:18,rectangle:19,stroke:20,closeStroke:21,fill:22,eoFill:23,fillStroke:24,eoFillStroke:25,closeFillStroke:26,closeEOFillStroke:27,endPath:28,clip:29,eoClip:30,beginText:31,endText:32,setCharSpacing:33,setWordSpacing:34,setHScale:35,setLeading:36,setFont:37,setTextRenderingMode:38,setTextRise:39,moveText:40,setLeadingMoveText:41,setTextMatrix:42,nextLine:43,showText:44,showSpacedText:45,nextLineShowText:46,nextLineSetSpacingShowText:47,setCharWidth:48,setCharWidthAndBounds:49,setStrokeColorSpace:50,setFillColorSpace:51,setStrokeColor:52,setStrokeColorN:53,setFillColor:54,setFillColorN:55,setStrokeGray:56,setFillGray:57,setStrokeRGBColor:58,setFillRGBColor:59,setStrokeCMYKColor:60,setFillCMYKColor:61,shadingFill:62,beginInlineImage:63,beginImageData:64,endInlineImage:65,paintXObject:66,markPoint:67,markPointProps:68,beginMarkedContent:69,beginMarkedContentProps:70,endMarkedContent:71,beginCompat:72,endCompat:73,paintFormXObjectBegin:74,paintFormXObjectEnd:75,beginGroup:76,endGroup:77,beginAnnotation:80,endAnnotation:81,paintImageMaskXObject:83,paintImageMaskXObjectGroup:84,paintImageXObject:85,paintInlineImageXObject:86,paintInlineImageXObjectGroup:87,paintImageXObjectRepeat:88,paintImageMaskXObjectRepeat:89,paintSolidColorImageMask:90,constructPath:91,setStrokeTransparent:92,setFillTransparent:93,rawFillPath:94},k=0,b=1,y=2,v=3,C=4;let S=m;function info(t){S>=g&&console.info(`Info: ${t}`)}function warn(t){S>=m&&console.warn(`Warning: ${t}`)}function unreachable(t){throw new Error(t)}function assert(t,e){t||unreachable(e)}function shadow(t,e,s,r=!1){Object.defineProperty(t,e,{value:s,enumerable:!r,configurable:!0,writable:!1});return s}const M=function BaseExceptionClosure(){function BaseException(t,e){this.message=t;this.name=e}BaseException.prototype=new Error;BaseException.constructor=BaseException;return BaseException}();class PasswordException extends M{constructor(t,e){super(t,"PasswordException");this.code=e}}class UnknownErrorException extends M{constructor(t,e){super(t,"UnknownErrorException");this.details=e}}class InvalidPDFException extends M{constructor(t){super(t,"InvalidPDFException")}}class ResponseException extends M{constructor(t,e,s){super(t,"ResponseException");this.status=e;this.missing=s}}class FormatError extends M{constructor(t){super(t,"FormatError")}}class AbortException extends M{constructor(t){super(t,"AbortException")}}class FeatureTest{static get isLittleEndian(){const t=new Uint8Array(4);t[0]=1;return shadow(this,"isLittleEndian",1===new Uint32Array(t.buffer,0,1)[0])}static get isOffscreenCanvasSupported(){return shadow(this,"isOffscreenCanvasSupported","undefined"!=typeof OffscreenCanvas)}static get isImageDecoderSupported(){return shadow(this,"isImageDecoderSupported","undefined"!=typeof ImageDecoder)}static get isVideoFrameSupported(){return shadow(this,"isVideoFrameSupported","undefined"!=typeof VideoFrame)}static get isFloat16ArraySupported(){return shadow(this,"isFloat16ArraySupported","undefined"!=typeof Float16Array)}static get isSanitizerSupported(){return shadow(this,"isSanitizerSupported","undefined"!=typeof Sanitizer)}static get platform(){const{platform:t,userAgent:e}=navigator;return shadow(this,"platform",{isAndroid:e.includes("Android"),isLinux:t.includes("Linux"),isMac:t.includes("Mac"),isWindows:t.includes("Win"),isFirefox:e.includes("Firefox")})}static get isCanvasFilterSupported(){let t;this.isOffscreenCanvasSupported&&(t=new OffscreenCanvas(1,1).getContext("2d"));return shadow(this,"isCanvasFilterSupported",void 0!==t?.filter)}static get isAlphaColorInputSupported(){return shadow(this,"isAlphaColorInputSupported",!1)}static get isBackdropFilterSupported(){return shadow(this,"isBackdropFilterSupported","undefined"!=typeof CSS&&CSS.supports("backdrop-filter","blur(1px)"))}}class Util{static get hexNums(){return shadow(this,"hexNums",Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0")))}static makeHexColor(t,e,s){return`#${this.hexNums[t]}${this.hexNums[e]}${this.hexNums[s]}`}static get identity0to256Map(){return shadow(this,"identity0to256Map",Uint8Array.from({length:256},(t,e)=>e))}static transform(t,e){return[t[0]*e[0]+t[2]*e[1],t[1]*e[0]+t[3]*e[1],t[0]*e[2]+t[2]*e[3],t[1]*e[2]+t[3]*e[3],t[0]*e[4]+t[2]*e[5]+t[4],t[1]*e[4]+t[3]*e[5]+t[5]]}static multiplyByDOMMatrix(t,e){return[t[0]*e.a+t[2]*e.b,t[1]*e.a+t[3]*e.b,t[0]*e.c+t[2]*e.d,t[1]*e.c+t[3]*e.d,t[0]*e.e+t[2]*e.f+t[4],t[1]*e.e+t[3]*e.f+t[5]]}static applyTransform(t,e,s=0){const r=t[s],a=t[s+1];t[s]=r*e[0]+a*e[2]+e[4];t[s+1]=r*e[1]+a*e[3]+e[5]}static applyTransformToBezier(t,e,s=0){const r=e[0],a=e[1],n=e[2],i=e[3],o=e[4],c=e[5];for(let e=0;e<6;e+=2){const l=t[s+e],h=t[s+e+1];t[s+e]=l*r+h*n+o;t[s+e+1]=l*a+h*i+c}}static applyInverseTransform(t,e){const s=t[0],r=t[1],a=e[0]*e[3]-e[1]*e[2];t[0]=(s*e[3]-r*e[2]+e[2]*e[5]-e[4]*e[3])/a;t[1]=(-s*e[1]+r*e[0]+e[4]*e[1]-e[5]*e[0])/a}static axialAlignedBoundingBox(t,e,s){const r=e[0],a=e[1],n=e[2],i=e[3],o=e[4],c=e[5],l=t[0],h=t[1],d=t[2],p=t[3];let u=r*l+o,f=u,m=r*d+o,g=m,x=i*h+c,k=x,b=i*p+c,y=b;if(0!==a||0!==n){const t=a*l,e=a*d,s=n*h,r=n*p;u+=s;g+=s;m+=r;f+=r;x+=t;y+=t;b+=e;k+=e}s[0]=Math.min(s[0],u,m,Math.min(f,g));s[1]=Math.min(s[1],x,b,Math.min(k,y));s[2]=Math.max(s[2],u,m,Math.max(f,g));s[3]=Math.max(s[3],x,b,Math.max(k,y))}static inverseTransform(t){const e=t[0]*t[3]-t[1]*t[2];return[t[3]/e,-t[1]/e,-t[2]/e,t[0]/e,(t[2]*t[5]-t[4]*t[3])/e,(t[4]*t[1]-t[5]*t[0])/e]}static singularValueDecompose2dScale(t,e){const s=t[0],r=t[1],a=t[2],n=t[3],i=s**2+r**2,o=s*a+r*n,c=a**2+n**2,l=(i+c)/2,h=Math.sqrt(l**2-(i*c-o**2));e[0]=Math.sqrt(l+h||1);e[1]=Math.sqrt(l-h||1)}static normalizeRect(t){const e=t.slice(0);if(t[0]>t[2]){e[0]=t[2];e[2]=t[0]}if(t[1]>t[3]){e[1]=t[3];e[3]=t[1]}return e}static intersect(t,e){const s=Math.max(Math.min(t[0],t[2]),Math.min(e[0],e[2])),r=Math.min(Math.max(t[0],t[2]),Math.max(e[0],e[2]));if(s>r)return null;const a=Math.max(Math.min(t[1],t[3]),Math.min(e[1],e[3])),n=Math.min(Math.max(t[1],t[3]),Math.max(e[1],e[3]));return a>n?null:[s,a,r,n]}static pointBoundingBox(t,e,s){s[0]=Math.min(s[0],t);s[1]=Math.min(s[1],e);s[2]=Math.max(s[2],t);s[3]=Math.max(s[3],e)}static rectBoundingBox(t,e,s,r,a){a[0]=Math.min(a[0],t,s);a[1]=Math.min(a[1],e,r);a[2]=Math.max(a[2],t,s);a[3]=Math.max(a[3],e,r)}static#t(t,e,s,r,a,n,i,o,c,l){if(c<=0||c>=1)return;const h=1-c,d=c*c,p=d*c,u=h*(h*(h*t+3*c*e)+3*d*s)+p*r,f=h*(h*(h*a+3*c*n)+3*d*i)+p*o;l[0]=Math.min(l[0],u);l[1]=Math.min(l[1],f);l[2]=Math.max(l[2],u);l[3]=Math.max(l[3],f)}static#e(t,e,s,r,a,n,i,o,c,l,h,d){if(Math.abs(c)<1e-12){Math.abs(l)>=1e-12&&this.#t(t,e,s,r,a,n,i,o,-h/l,d);return}const p=l**2-4*h*c;if(p<0)return;const u=Math.sqrt(p),f=2*c;this.#t(t,e,s,r,a,n,i,o,(-l+u)/f,d);this.#t(t,e,s,r,a,n,i,o,(-l-u)/f,d)}static bezierBoundingBox(t,e,s,r,a,n,i,o,c){c[0]=Math.min(c[0],t,i);c[1]=Math.min(c[1],e,o);c[2]=Math.max(c[2],t,i);c[3]=Math.max(c[3],e,o);this.#e(t,s,a,i,e,r,n,o,3*(3*(s-a)-t+i),6*(t-2*s+a),3*(s-t),c);this.#e(t,s,a,i,e,r,n,o,3*(3*(r-n)-e+o),6*(e-2*r+n),3*(r-e),c)}}const makeArr=()=>[],makeMap=()=>new Map;"function"!=typeof Iterator.prototype.join&&(Iterator.prototype.join=function(t){return[...this].join(t)});class PixelsPerInch{static CSS=96;static PDF=72;static PDF_TO_CSS_UNITS=this.CSS/this.PDF}function getRGBA(t){if(t.startsWith("#")){const e=t.slice(1);return[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16),e.length>=8?parseInt(e.slice(6,8),16)/255:1]}if(t.startsWith("rgb(")){const[e,s,r]=t.slice(4,-1).split(",").map(t=>parseInt(t,10));return[e,s,r,1]}if(t.startsWith("rgba(")){const e=t.slice(5,-1).split(",");return[parseInt(e[0],10),parseInt(e[1],10),parseInt(e[2],10),parseFloat(e[3])]}const e=t.match(/^color\(srgb\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)(?:\s*\/\s*([\d.]+|none))?\)$/);return e?[Math.round(255*parseFloat(e[1])),Math.round(255*parseFloat(e[2])),Math.round(255*parseFloat(e[3])),void 0!==e[4]&&"none"!==e[4]?parseFloat(e[4]):1]:null}function getCurrentTransform(t){const{a:e,b:s,c:r,d:a,e:n,f:i}=t.getTransform();return[e,s,r,a,n,i]}function getCurrentTransformInverse(t){const{a:e,b:s,c:r,d:a,e:n,f:i}=t.getTransform().invertSelf();return[e,s,r,a,n,i]}class OutputScale{constructor(){const{pixelRatio:t}=OutputScale;this.sx=t;this.sy=t}get scaled(){return 1!==this.sx||1!==this.sy}get symmetric(){return this.sx===this.sy}limitCanvas(t,e,s,r,a=-1){return!1}static get pixelRatio(){return globalThis.devicePixelRatio||1}static capPixels(t,e){return t}}new Map;function makePathFromDrawOPS(t){const e=new Path2D;if(!t)return e;for(let s=0,r=t.length;s<r;)switch(t[s++]){case k:e.moveTo(t[s++],t[s++]);break;case b:e.lineTo(t[s++],t[s++]);break;case y:e.bezierCurveTo(t[s++],t[s++],t[s++],t[s++],t[s++],t[s++]);break;case v:e.quadraticCurveTo(t[s++],t[s++],t[s++],t[s++]);break;case C:e.closePath();break;default:warn(`Unrecognized drawing path operator: ${t[s-1]}`)}return e}function math_clamp_MathClamp(t,e,s){return Math.min(Math.max(t,e),s)}const T="__forcedDependency",{floor:F,ceil:w}=Math;function expandBBox(t,e,s,r,a,n){t[4*e+0]=Math.min(t[4*e+0],s);t[4*e+1]=Math.min(t[4*e+1],r);t[4*e+2]=Math.max(t[4*e+2],a);t[4*e+3]=Math.max(t[4*e+3],n)}const B=new Uint32Array(new Uint8Array([255,255,0,0]).buffer)[0];class BBoxReader{#s;#r;constructor(t,e){this.#s=t;this.#r=e}static fromBuffer(t){return new BBoxReader(new Uint32Array(t),new Uint8ClampedArray(t))}get buffer(){return this.#s.buffer}get length(){return this.#s.length}isEmpty(t){return this.#s[t]===B}minX(t){return this.#r[4*t+0]/256}minY(t){return this.#r[4*t+1]/256}maxX(t){return(this.#r[4*t+2]+1)/256}maxY(t){return(this.#r[4*t+3]+1)/256}}const ensureDebugMetadata=(t,e)=>t?.getOrInsertComputed(e,()=>({dependencies:new Set,isRenderingOperation:!1}));class CanvasBBoxTracker{#a=[[1,0,0,1,0,0]];#n=[-1/0,-1/0,1/0,1/0];#i=new Float64Array(e);_pendingBBoxIdx=-1;#o;#c;#l;#s;_savesStack=[];_markedContentStack=[];constructor(t,e){this.#o=t.width;this.#c=t.height;this.#h(e)}growOperationsCount(t){t>=this.#s.length&&this.#h(t,this.#s)}#h(t,e){const s=new ArrayBuffer(4*t);this.#l=new Uint8ClampedArray(s);this.#s=new Uint32Array(s);if(e&&e.length>0){this.#s.set(e);this.#s.fill(B,e.length)}else this.#s.fill(B)}get clipBox(){return this.#n}save(t){this.#n={__proto__:this.#n};this._savesStack.push(t);return this}restore(t,e){const s=Object.getPrototypeOf(this.#n);if(null===s)return this;this.#n=s;const r=this._savesStack.pop();if(void 0!==r){e?.(r,t);this.#s[t]=this.#s[r]}return this}recordOpenMarker(t){this._savesStack.push(t);return this}getOpenMarker(){return 0===this._savesStack.length?null:this._savesStack.at(-1)}recordCloseMarker(t,e){const s=this._savesStack.pop();if(void 0!==s){e?.(s,t);this.#s[t]=this.#s[s]}return this}beginMarkedContent(t){this._markedContentStack.push(t);return this}endMarkedContent(t,e){const s=this._markedContentStack.pop();if(void 0!==s){e?.(s,t);this.#s[t]=this.#s[s]}return this}pushBaseTransform(t){this.#a.push(Util.multiplyByDOMMatrix(this.#a.at(-1),t.getTransform()));return this}popBaseTransform(){this.#a.length>1&&this.#a.pop();return this}resetBBox(t){if(this._pendingBBoxIdx!==t){this._pendingBBoxIdx=t;this.#i.set(e,0)}return this}recordClipBox(t,s,r,a,n,i){const o=Util.multiplyByDOMMatrix(this.#a.at(-1),s.getTransform()),c=e.slice();Util.axialAlignedBoundingBox([r,n,a,i],o,c);const l=Util.intersect(this.#n,c);if(l){this.#n[0]=l[0];this.#n[1]=l[1];this.#n[2]=l[2];this.#n[3]=l[3]}else{this.#n[0]=this.#n[1]=1/0;this.#n[2]=this.#n[3]=-1/0}return this}recordBBox(t,s,r,a,n,i){const o=this.#n;if(o[0]===1/0)return this;const c=Util.multiplyByDOMMatrix(this.#a.at(-1),s.getTransform());if(o[0]===-1/0){Util.axialAlignedBoundingBox([r,n,a,i],c,this.#i);return this}const l=e.slice();Util.axialAlignedBoundingBox([r,n,a,i],c,l);this.#i[0]=math_clamp_MathClamp(l[0],o[0],this.#i[0]);this.#i[1]=math_clamp_MathClamp(l[1],o[1],this.#i[1]);this.#i[2]=math_clamp_MathClamp(l[2],this.#i[2],o[2]);this.#i[3]=math_clamp_MathClamp(l[3],this.#i[3],o[3]);return this}recordFullPageBBox(t){this.#i[0]=Math.max(0,this.#n[0]);this.#i[1]=Math.max(0,this.#n[1]);this.#i[2]=Math.min(this.#o,this.#n[2]);this.#i[3]=Math.min(this.#c,this.#n[3]);return this}recordOperation(t,e=!1,s){if(this._pendingBBoxIdx!==t)return this;const r=F(256*this.#i[0]/this.#o),a=F(256*this.#i[1]/this.#c),n=w(256*this.#i[2]/this.#o),i=w(256*this.#i[3]/this.#c);expandBBox(this.#l,t,r,a,n,i);if(s)for(const e of s)for(const s of e)s!==t&&expandBBox(this.#l,s,r,a,n,i);e||(this._pendingBBoxIdx=-1);return this}bboxToClipBoxDropOperation(t){if(this._pendingBBoxIdx===t){this._pendingBBoxIdx=-1;this.#n[0]=Math.max(this.#n[0],this.#i[0]);this.#n[1]=Math.max(this.#n[1],this.#i[1]);this.#n[2]=Math.min(this.#n[2],this.#i[2]);this.#n[3]=Math.min(this.#n[3],this.#i[3])}return this}take(){return new BBoxReader(this.#s,this.#l)}takeDebugMetadata(){throw new Error("Unreachable")}recordSimpleData(t,e){return this}recordIncrementalData(t,e){return this}resetIncrementalData(t,e){return this}recordNamedData(t,e){return this}recordSimpleDataFromNamed(t,e,s){return this}recordFutureForcedDependency(t,e){return this}inheritSimpleDataAsFutureForcedDependencies(t){return this}inheritPendingDependenciesAsFutureForcedDependencies(){return this}recordCharacterBBox(t,e,s,r=1,a=0,n=0,i){return this}getSimpleIndex(t){}recordDependencies(t,e){return this}recordNamedDependency(t,e){return this}recordShowTextOperation(t,e=!1){return this}}class CanvasDependencyTracker{#d={__proto__:null};#p={__proto__:null,transform:[],moveText:[],sameLineText:[],[T]:[]};#u=new Map;#f=new Set;#m=new Map;#g;#x;#k;constructor(t,e=!1){this.#k=t;if(e){this.#g=new Map;this.#x=(t,e)=>{ensureDebugMetadata(this.#g,e).dependencies.add(t)}}}get clipBox(){return this.#k.clipBox}growOperationsCount(t){this.#k.growOperationsCount(t)}save(t){this.#d={__proto__:this.#d};this.#p={__proto__:this.#p,transform:{__proto__:this.#p.transform},moveText:{__proto__:this.#p.moveText},sameLineText:{__proto__:this.#p.sameLineText},[T]:{__proto__:this.#p[T]}};this.#k.save(t);return this}restore(t){this.#k.restore(t,this.#x);const e=Object.getPrototypeOf(this.#d);if(null===e)return this;this.#d=e;this.#p=Object.getPrototypeOf(this.#p);return this}recordOpenMarker(t){this.#k.recordOpenMarker(t,this.#x);return this}getOpenMarker(){return this.#k.getOpenMarker()}recordCloseMarker(t){this.#k.recordCloseMarker(t,this.#x);return this}beginMarkedContent(t){this.#k.beginMarkedContent(t);return this}endMarkedContent(t){this.#k.endMarkedContent(t,this.#x);return this}pushBaseTransform(t){this.#k.pushBaseTransform(t);return this}popBaseTransform(){this.#k.popBaseTransform();return this}recordSimpleData(t,e){this.#d[t]=e;return this}recordIncrementalData(t,e){this.#p[t].push(e);return this}resetIncrementalData(t,e){this.#p[t].length=0;return this}recordNamedData(t,e){this.#u.set(t,e);return this}recordSimpleDataFromNamed(t,e,s){this.#d[t]=this.#u.get(e)??s}recordFutureForcedDependency(t,e){this.recordIncrementalData(T,e);return this}inheritSimpleDataAsFutureForcedDependencies(t){for(const e of t)e in this.#d&&this.recordFutureForcedDependency(e,this.#d[e]);return this}inheritPendingDependenciesAsFutureForcedDependencies(){for(const t of this.#f)this.recordFutureForcedDependency(T,t);return this}resetBBox(t){this.#k.resetBBox(t);return this}recordClipBox(t,e,s,r,a,n){this.#k.recordClipBox(t,e,s,r,a,n);return this}recordBBox(t,e,s,r,a,n){this.#k.recordBBox(t,e,s,r,a,n);return this}recordCharacterBBox(t,e,s,r=1,a=0,n=0,i){const o=s.bbox;let c,l;if(o){c=o[2]!==o[0]&&o[3]!==o[1]&&this.#m.get(s);if(!1!==c){l=[0,0,0,0];Util.axialAlignedBoundingBox(o,s.fontMatrix,l);1===r&&0===a&&0===n||function scaleCharBBox(t,e,s,r,a){let n;if(t){if(t<0){n=a[0];a[0]=a[2];a[2]=n}a[0]*=t;a[2]*=t;if(e<0){n=a[1];a[1]=a[3];a[3]=n}a[1]*=e;a[3]*=e}else a.fill(0);a[0]+=s;a[1]+=r;a[2]+=s;a[3]+=r}(r,-r,a,n,l);if(c)return this.recordBBox(t,e,l[0],l[2],l[1],l[3])}}if(!i)return this.recordFullPageBBox(t);const h=i();if(o&&l&&void 0===c){c=l[0]<=a-h.actualBoundingBoxLeft&&l[2]>=a+h.actualBoundingBoxRight&&l[1]<=n-h.actualBoundingBoxAscent&&l[3]>=n+h.actualBoundingBoxDescent;this.#m.set(s,c);if(c)return this.recordBBox(t,e,l[0],l[2],l[1],l[3])}return this.recordBBox(t,e,a-h.actualBoundingBoxLeft,a+h.actualBoundingBoxRight,n-h.actualBoundingBoxAscent,n+h.actualBoundingBoxDescent)}recordFullPageBBox(t){this.#k.recordFullPageBBox(t);return this}getSimpleIndex(t){return this.#d[t]}recordDependencies(t,e){const s=this.#f,r=this.#d,a=this.#p;for(const t of e)t in this.#d?s.add(r[t]):t in a&&a[t].forEach(s.add,s);return this}recordNamedDependency(t,e){this.#u.has(e)&&this.#f.add(this.#u.get(e));return this}recordOperation(t,e=!1){this.recordDependencies(t,[T]);if(this.#g){const e=ensureDebugMetadata(this.#g,t),{dependencies:s}=e;this.#f.forEach(s.add,s);this.#k._savesStack.forEach(s.add,s);this.#k._markedContentStack.forEach(s.add,s);s.delete(t);e.isRenderingOperation=!0}const s=!e&&t===this.#k._pendingBBoxIdx;this.#k.recordOperation(t,e,[this.#f,this.#k._savesStack,this.#k._markedContentStack]);s&&this.#f.clear();return this}recordShowTextOperation(t,e=!1){const s=Array.from(this.#f);this.recordOperation(t,e);this.recordIncrementalData("sameLineText",t);for(const t of s)this.recordIncrementalData("sameLineText",t);return this}bboxToClipBoxDropOperation(t,e=!1){const s=!e&&t===this.#k._pendingBBoxIdx;this.#k.bboxToClipBoxDropOperation(t);s&&this.#f.clear();return this}take(){this.#m.clear();return this.#k.take()}takeDebugMetadata(){return this.#g}}class CanvasNestedDependencyTracker{#b;#y;#v;#C=0;#S=0;constructor(t,e,s){if(t instanceof CanvasNestedDependencyTracker&&t.#v===!!s)return t;this.#b=t;this.#y=e;this.#v=!!s}get clipBox(){return this.#b.clipBox}growOperationsCount(){throw new Error("Unreachable")}save(t){this.#S++;this.#b.save(this.#y);return this}restore(t){if(this.#S>0){this.#b.restore(this.#y);this.#S--}return this}recordOpenMarker(t){this.#C++;return this}getOpenMarker(){return this.#C>0?this.#y:this.#b.getOpenMarker()}recordCloseMarker(t){this.#C--;return this}beginMarkedContent(t){return this}endMarkedContent(t){return this}pushBaseTransform(t){this.#b.pushBaseTransform(t);return this}popBaseTransform(){this.#b.popBaseTransform();return this}recordSimpleData(t,e){this.#b.recordSimpleData(t,this.#y);return this}recordIncrementalData(t,e){this.#b.recordIncrementalData(t,this.#y);return this}resetIncrementalData(t,e){this.#b.resetIncrementalData(t,this.#y);return this}recordNamedData(t,e){return this}recordSimpleDataFromNamed(t,e,s){this.#b.recordSimpleDataFromNamed(t,e,this.#y);return this}recordFutureForcedDependency(t,e){this.#b.recordFutureForcedDependency(t,this.#y);return this}inheritSimpleDataAsFutureForcedDependencies(t){this.#b.inheritSimpleDataAsFutureForcedDependencies(t);return this}inheritPendingDependenciesAsFutureForcedDependencies(){this.#b.inheritPendingDependenciesAsFutureForcedDependencies();return this}resetBBox(t){this.#v||this.#b.resetBBox(this.#y);return this}recordClipBox(t,e,s,r,a,n){this.#v||this.#b.recordClipBox(this.#y,e,s,r,a,n);return this}recordBBox(t,e,s,r,a,n){this.#v||this.#b.recordBBox(this.#y,e,s,r,a,n);return this}recordCharacterBBox(t,e,s,r,a,n,i){this.#v||this.#b.recordCharacterBBox(this.#y,e,s,r,a,n,i);return this}recordFullPageBBox(t){this.#v||this.#b.recordFullPageBBox(this.#y);return this}getSimpleIndex(t){return this.#b.getSimpleIndex(t)}recordDependencies(t,e){this.#b.recordDependencies(this.#y,e);return this}recordNamedDependency(t,e){this.#b.recordNamedDependency(this.#y,e);return this}recordOperation(t){this.#b.recordOperation(this.#y,!0);return this}recordShowTextOperation(t){this.#b.recordShowTextOperation(this.#y,!0);return this}bboxToClipBoxDropOperation(t){this.#v||this.#b.bboxToClipBoxDropOperation(this.#y,!0);return this}take(){throw new Error("Unreachable")}takeDebugMetadata(){throw new Error("Unreachable")}}const I=["path","transform","filter","strokeColor","strokeAlpha","lineWidth","lineCap","lineJoin","miterLimit","dash"],O=["path","transform","filter","fillColor","fillAlpha","globalCompositeOperation","SMask"],D=["transform","SMask","filter","fillAlpha","strokeAlpha","globalCompositeOperation"],P=["filter","fillColor","fillAlpha"],A=["transform","leading","charSpacing","wordSpacing","hScale","textRise","moveText","textMatrix","font","fontObj","filter","fillColor","textRenderingMode","SMask","fillAlpha","strokeAlpha","globalCompositeOperation","sameLineText"],_=["transform"],E=["transform","filter","fillColor"];class CanvasImagesTracker{#o;#c;#M=4;#T=0;#r=new CanvasImagesTracker.#F(6*this.#M);static#F=FeatureTest.isFloat16ArraySupported?Float16Array:Float32Array;constructor(t){this.#o=t.width;this.#c=t.height}record(t,s,r,a){if(this.#T===this.#M){this.#M*=2;const t=new CanvasImagesTracker.#F(6*this.#M);t.set(this.#r);this.#r=t}const n=getCurrentTransform(t);let i;if(a[0]!==1/0){const t=e.slice();Util.axialAlignedBoundingBox([0,-r,s,0],n,t);const o=Util.intersect(a,t);if(!o)return;const[c,l,h,d]=o;if(c!==t[0]||l!==t[1]||h!==t[2]||d!==t[3]){const t=Math.atan2(n[1],n[0]),e=Math.abs(Math.sin(t)),s=Math.abs(Math.cos(t));if(e<1e-6||s<1e-6||Math.abs(e-s)<1e-6)i=[c,l,c,d,h,l];else{const t=h-c,r=d-l,a=e*e,n=s*s,o=s*e,p=n-a,u=(r*n-t*o)/p;i=[c+(r*o-t*a)/p,l,c,l+u,h,d-u]}}}if(!i){i=[0,-r,0,0,s,-r];Util.applyTransform(i,n,0);Util.applyTransform(i,n,2);Util.applyTransform(i,n,4)}i[0]/=this.#o;i[1]/=this.#c;i[2]/=this.#o;i[3]/=this.#c;i[4]/=this.#o;i[5]/=this.#c;this.#r.set(i,6*this.#T);this.#T++}take(){return this.#r.subarray(0,6*this.#T)}}function convertBlackAndWhiteToRGBA({src:t,srcPos:e=0,dest:s,width:r,height:a,nonBlackColor:n=4294967295,inverseDecode:i=!1}){const o=FeatureTest.isLittleEndian?4278190080:255,[c,l]=i?[n,o]:[o,n],h=r>>3,d=7&r,p=c^l,u=t.length;s=new Uint32Array(s.buffer);let f=0;for(let r=0;r<a;++r){for(const r=e+h;e<r;++e,f+=8){const r=t[e];s[f]=c^-(r>>7&1)&p;s[f+1]=c^-(r>>6&1)&p;s[f+2]=c^-(r>>5&1)&p;s[f+3]=c^-(r>>4&1)&p;s[f+4]=c^-(r>>3&1)&p;s[f+5]=c^-(r>>2&1)&p;s[f+6]=c^-(r>>1&1)&p;s[f+7]=c^-(1&r)&p}if(0===d)continue;const r=e<u?t[e++]:255;for(let t=0;t<d;++t,++f)s[f]=c^-(r>>7-t&1)&p}return{srcPos:e,destPos:f}}function convertRGBToRGBA({src:t,srcPos:e=0,dest:s,destPos:r=0,width:a,height:n}){let i=0;const o=a*n*3,c=t.byteOffset+e,l=c%4==0?Math.floor(math_clamp_MathClamp(t.length-e,0,o)/4):0,h=l>0?new Uint32Array(t.buffer,c,l):null,d=FeatureTest.isLittleEndian?4278190080:255;if(FeatureTest.isLittleEndian){for(;i<l-2;i+=3,r+=4){const t=h[i],e=h[i+1],a=h[i+2];s[r]=t|d;s[r+1]=t>>>24|e<<8|d;s[r+2]=e>>>16|a<<16|d;s[r+3]=a>>>8|d}for(let a=e+4*i,n=e+o;a<n;a+=3)s[r++]=t[a]|t[a+1]<<8|t[a+2]<<16|d}else{for(;i<l-2;i+=3,r+=4){const t=h[i],e=h[i+1],a=h[i+2];s[r]=t|d;s[r+1]=t<<24|e>>>8|d;s[r+2]=e<<16|a>>>16|d;s[r+3]=a<<8|d}for(let a=e+4*i,n=e+o;a<n;a+=3)s[r++]=t[a]<<24|t[a+1]<<16|t[a+2]<<8|d}return{srcPos:e+o,destPos:r}}const N=new class WebGPU{#w=null;#B=null;#I=null;#O=null;async#D(){if(!globalThis.navigator?.gpu)return!1;try{const t=await navigator.gpu.requestAdapter();if(!t)return!1;this.#O=navigator.gpu.getPreferredCanvasFormat();this.#B=await t.requestDevice();return!0}catch{return!1}}init(){return this.#w||=this.#D()}get isReady(){return null!==this.#B}loadMeshShader(){if(!this.#B||this.#I)return;const t=this.#B.createShaderModule({code:"\nstruct Uniforms {\n offsetX : f32,\n offsetY : f32,\n scaleX : f32,\n scaleY : f32,\n paddedWidth : f32,\n paddedHeight : f32,\n borderSize : f32,\n _pad : f32,\n};\n\n@group(0) @binding(0) var<uniform> u : Uniforms;\n\nstruct VertexInput {\n @location(0) position : vec2<f32>,\n @location(1) color : vec4<f32>,\n};\n\nstruct VertexOutput {\n @builtin(position) position : vec4<f32>,\n @location(0) color : vec3<f32>,\n};\n\n@vertex\nfn vs_main(in : VertexInput) -> VertexOutput {\n var out : VertexOutput;\n let cx = (in.position.x + u.offsetX) * u.scaleX;\n let cy = (in.position.y + u.offsetY) * u.scaleY;\n out.position = vec4<f32>(\n ((cx + u.borderSize) / u.paddedWidth) * 2.0 - 1.0,\n 1.0 - ((cy + u.borderSize) / u.paddedHeight) * 2.0,\n 0.0,\n 1.0\n );\n out.color = in.color.rgb;\n return out;\n}\n\n@fragment\nfn fs_main(in : VertexOutput) -> @location(0) vec4<f32> {\n return vec4<f32>(in.color, 1.0);\n}\n"});this.#I=this.#B.createRenderPipeline({layout:"auto",vertex:{module:t,entryPoint:"vs_main",buffers:[{arrayStride:8,attributes:[{shaderLocation:0,offset:0,format:"float32x2"}]},{arrayStride:4,attributes:[{shaderLocation:1,offset:0,format:"unorm8x4"}]}]},fragment:{module:t,entryPoint:"fs_main",targets:[{format:this.#O}]},primitive:{topology:"triangle-list"}})}draw(t,e,s,r,a,n,i,o){this.loadMeshShader();const c=this.#B,{offsetX:l,offsetY:h,scaleX:d,scaleY:p}=r,u=c.createBuffer({size:Math.max(t.byteLength,4),usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST});t.byteLength>0&&c.queue.writeBuffer(u,0,t);const f=c.createBuffer({size:Math.max(e.byteLength,4),usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST});e.byteLength>0&&c.queue.writeBuffer(f,0,e);const m=c.createBuffer({size:32,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});c.queue.writeBuffer(m,0,new Float32Array([l,h,d,p,n,i,o,0]));const g=c.createBindGroup({layout:this.#I.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:m}}]}),x=new OffscreenCanvas(n,i),k=x.getContext("webgpu");k.configure({device:c,format:this.#O,alphaMode:a?"opaque":"premultiplied"});const b=a?{r:a[0]/255,g:a[1]/255,b:a[2]/255,a:1}:{r:0,g:0,b:0,a:0},y=c.createCommandEncoder(),v=y.beginRenderPass({colorAttachments:[{view:k.getCurrentTexture().createView(),clearValue:b,loadOp:"clear",storeOp:"store"}]});if(s>0){v.setPipeline(this.#I);v.setBindGroup(0,g);v.setVertexBuffer(0,u);v.setVertexBuffer(1,f);v.draw(s)}v.end();c.queue.submit([y.finish()]);u.destroy();f.destroy();m.destroy();return x.transferToImageBitmap()}};function initGPU(){return N.init()}function isGPUReady(){return N.isReady}const R="Fill",L="Stroke",U="Shading";function applyBoundingBox(t,e){if(!e)return;const s=e[2]-e[0],r=e[3]-e[1],a=new Path2D;a.rect(e[0],e[1],s,r);t.clip(a)}class BaseShadingPattern{matrix=null;isModifyingCurrentTransform(){return!1}getPattern(){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]}isOriginBased(){return 0===this._p0[0]&&0===this._p0[1]&&(!this.isRadial()||0===this._p1[0]&&0===this._p1[1])}isRadial(){return"radial"===this._type}areConic(){if(!this.isRadial())return!1;const t=Math.hypot(this._p0[0]-this._p1[0],this._p0[1]-this._p1[1]);return t+this._r1>this._r0&&t+this._r0>this._r1}_createGradient(t,e=null){let s,r=this._p0,a=this._p1;if(e){r=r.slice();a=a.slice();Util.applyTransform(r,e);Util.applyTransform(a,e)}if("axial"===this._type)s=t.createLinearGradient(r[0],r[1],a[0],a[1]);else if("radial"===this._type){let n=this._r0,i=this._r1;if(e){const t=new Float32Array(2);Util.singularValueDecompose2dScale(e,t);n*=t[0];i*=t[0]}s=t.createRadialGradient(r[0],r[1],n,a[0],a[1],i)}for(const t of this._colorStops)s.addColorStop(t[0],t[1]);return s}_createReversedGradient(t,e=null){let s=this._p1,r=this._p0;if(e){s=s.slice();r=r.slice();Util.applyTransform(s,e);Util.applyTransform(r,e)}let a=this._r1,n=this._r0;if(e){const t=new Float32Array(2);Util.singularValueDecompose2dScale(e,t);a*=t[0];n*=t[0]}const i=t.createRadialGradient(s[0],s[1],a,r[0],r[1],n),o=this._colorStops.map(([t,e])=>[1-t,e]).reverse();for(const[t,e]of o)i.addColorStop(t,e);return i}_createRasterPattern(t,e,s,r,a,n){const i=Math.ceil(r[2]-r[0])||1,o=Math.ceil(r[3]-r[1])||1,c=e.canvasFactory.create(i,o),l=c.context;l.clearRect(0,0,i,o);l.beginPath();l.rect(0,0,i,o);l.translate(-r[0],-r[1]);s=Util.transform(s,[1,0,0,1,r[0],r[1]]);l.transform(...a);applyBoundingBox(l,this._bbox);if(this.areConic()){l.fillStyle=this._createReversedGradient(l);l.fill()}l.fillStyle=this._createGradient(l);l.fill();n?.applyToCanvas(l);const h=t.createPattern(c.canvas,"no-repeat");e.canvasFactory.destroy(c);h.setTransform(new DOMMatrix(s));return h}getPattern(t,e,s,r){const a=e.current.transferMapsFallback;if(r===L||r===R){if(this.isOriginBased()&&!a){let r=Util.transform(s,e.baseTransform);this.matrix&&(r=Util.transform(r,this.matrix));const a=.001,n=Math.hypot(r[0],r[1]),i=Math.hypot(r[2],r[3]),o=(r[0]*r[2]+r[1]*r[3])/(n*i);if(Math.abs(o)<a){if(!this.isRadial())return this._createGradient(t,r);if(Math.abs(n-i)<a)return this._createGradient(t,r)}}const n=e.current.getClippedPathBoundingBox(r,getCurrentTransform(t))||[0,0,0,0],i=this.matrix?Util.transform(e.baseTransform,this.matrix):e.baseTransform;return this._createRasterPattern(t,e,s,n,i,a)}if(a&&s)return this._createRasterPattern(t,e,s,e.current.clipBox,getCurrentTransform(t),a);if(this.areConic()){t.save();applyBoundingBox(t,this._bbox);t.fillStyle=this._createReversedGradient(t);t.fillRect(-1e10,-1e10,2e10,2e10);t.restore()}applyBoundingBox(t,this._bbox);return this._createGradient(t)}}function drawTriangle(t,e,s,r,a,n,i,o){const c=e.coords,l=e.colors,h=t.data,d=4*t.width;let p;if(c[2*s+1]>c[2*r+1]){p=s;s=r;r=p;p=n;n=i;i=p}if(c[2*r+1]>c[2*a+1]){p=r;r=a;a=p;p=i;i=o;o=p}if(c[2*s+1]>c[2*r+1]){p=s;s=r;r=p;p=n;n=i;i=p}const u=(c[2*s]+e.offsetX)*e.scaleX,f=(c[2*s+1]+e.offsetY)*e.scaleY,m=(c[2*r]+e.offsetX)*e.scaleX,g=(c[2*r+1]+e.offsetY)*e.scaleY,x=(c[2*a]+e.offsetX)*e.scaleX,k=(c[2*a+1]+e.offsetY)*e.scaleY;if(f>=k)return;const b=l[4*n],y=l[4*n+1],v=l[4*n+2],C=l[4*i],S=l[4*i+1],M=l[4*i+2],T=l[4*o],F=l[4*o+1],w=l[4*o+2],B=Math.round(f),I=Math.round(k);let O,D,P,A,_,E,N,R;for(let t=B;t<=I;t++){if(t<g){const e=t<f?0:(f-t)/(f-g);O=u-(u-m)*e;D=b-(b-C)*e;P=y-(y-S)*e;A=v-(v-M)*e}else{let e;e=t>k?1:g===k?0:(g-t)/(g-k);O=m-(m-x)*e;D=C-(C-T)*e;P=S-(S-F)*e;A=M-(M-w)*e}let e;e=t<f?0:t>k?1:(f-t)/(f-k);_=u-(u-x)*e;E=b-(b-T)*e;N=y-(y-F)*e;R=v-(v-w)*e;const s=Math.round(Math.min(O,_)),r=Math.round(Math.max(O,_));let a=d*t+4*s;for(let t=s;t<=r;t++){e=(O-t)/(O-_);e<0?e=0:e>1&&(e=1);h[a++]=D-(D-E)*e|0;h[a++]=P-(P-N)*e|0;h[a++]=A-(A-R)*e|0;h[a++]=255}}}class MeshShadingPattern extends BaseShadingPattern{constructor(t){super();this._posData=t[2];this._colData=t[3];this._vertexCount=t[4];this._bounds=t[5];this._bbox=t[6];this._background=t[7];!function loadMeshShader(){N.loadMeshShader()}()}_createMeshCanvas(t,e,s,r=null){const a=Math.floor(this._bounds[0]),n=Math.floor(this._bounds[1]),i=Math.ceil(this._bounds[2])-a,o=Math.ceil(this._bounds[3])-n,c=Math.min(Math.ceil(Math.abs(i*t[0]*1.1)),3e3)||1,l=Math.min(Math.ceil(Math.abs(o*t[1]*1.1)),3e3)||1,h=i?i/c:1,d=o?o/l:1,p={coords:this._posData,colors:this._colData,offsetX:-a,offsetY:-n,scaleX:1/h,scaleY:1/d},u=c+4,f=l+4,m=s.create(u,f);if(isGPUReady()&&this._vertexCount>48)m.context.drawImage(function drawMeshWithGPU(t,e,s,r,a,n,i,o){return N.draw(t,e,s,r,a,n,i,o)}(this._posData,this._colData,this._vertexCount,p,e,u,f,2),0,0);else{const t=m.context.createImageData(c,l);if(e){const s=t.data;for(let t=0,r=s.length;t<r;t+=4){s[t]=e[0];s[t+1]=e[1];s[t+2]=e[2];s[t+3]=255}}for(let e=0,s=this._vertexCount;e<s;e+=3)drawTriangle(t,p,e,e+1,e+2,e,e+1,e+2);m.context.putImageData(t,2,2)}r?.applyToCanvas(m.context);return{canvas:m.canvas,offsetX:a-2*h,offsetY:n-2*d,scaleX:h,scaleY:d}}isModifyingCurrentTransform(){return!0}getPattern(t,e,s,r){applyBoundingBox(t,this._bbox);const a=new Float32Array(2);if(r===U)Util.singularValueDecompose2dScale(getCurrentTransform(t),a);else if(this.matrix){Util.singularValueDecompose2dScale(this.matrix,a);const[t,s]=a;Util.singularValueDecompose2dScale(e.baseTransform,a);a[0]*=t;a[1]*=s}else Util.singularValueDecompose2dScale(e.baseTransform,a);const n=this._createMeshCanvas(a,r===U?null:this._background,e.canvasFactory,e.current.transferMapsFallback);if(r!==U){t.setTransform(...e.baseTransform);this.matrix&&t.transform(...this.matrix)}t.translate(n.offsetX,n.offsetY);t.scale(n.scaleX,n.scaleY);const i=t.createPattern(n.canvas,"no-repeat");e.canvasFactory.destroy(n);return i}}class DummyShadingPattern extends BaseShadingPattern{getPattern(){return"hotpink"}}const j=1,G=2;class TilingPattern{static MAX_PATTERN_SIZE=3e3;constructor(t,e,s,r){this.color=t[1];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.needsIsolation=t[9]??!0;this.ctx=e;this.canvasGraphicsFactory=s;this.baseTransform=r;this.patternBaseMatrix=this.matrix?Util.transform(r,this.matrix):r}canSkipPatternCanvas([t,e,s,r]){const[a,n,i,o]=this.bbox,c=Math.abs(this.xstep),l=Math.abs(this.ystep);if(t>c+1e-6||e>l+1e-6)return null;const h=Math.floor((s-i)/c)+1,d=Math.ceil((s+t-a)/c)-1,p=Math.floor((r-o)/l)+1,u=Math.ceil((r+e-n)/l)-1;return d<=h&&u<=p?[h,p]:null}updatePatternDims(t,s){const r=e.slice();Util.axialAlignedBoundingBox(t,Util.inverseTransform(this.patternBaseMatrix),r);s[0]=r[2]-r[0];s[1]=r[3]-r[1];s[2]=r[0];s[3]=r[1]}_renderTileCanvas(t,e,s,r){const[a,n,i,o]=this.bbox,c=t.canvasFactory.create(s.size,r.size),l=c.context,h=this.canvasGraphicsFactory.createCanvasGraphics(l,e);h.groupLevel=t.groupLevel;h.current.transferMapsFallback=t.current.transferMapsFallback;this.setFillAndStrokeStyleToContext(h,this.paintType,this.color);l.translate(-s.scale*a,-r.scale*n);h.transform(0,s.scale,0,0,r.scale,0,0);l.save();h.dependencyTracker?.save();this.clipBbox(h,a,n,i,o);h.baseTransform=getCurrentTransform(h.ctx);h.executeOperatorList(this.operatorList);h.endDrawing();h.dependencyTracker?.restore();l.restore();return c}_getCombinedScales(){const t=new Float32Array(2);Util.singularValueDecompose2dScale(this.matrix,t);const[e,s]=t;Util.singularValueDecompose2dScale(this.baseTransform,t);return[e*t[0],s*t[1]]}drawPattern(t,e,s=!1,[r,a],n){const[i,o,c,l]=this.bbox,h=t.dependencyTracker;h&&(t.dependencyTracker=new CanvasNestedDependencyTracker(h,n));try{t.save();s?t.ctx.clip(e,"evenodd"):t.ctx.clip(e);t.ctx.setTransform(...this.patternBaseMatrix);t.ctx.translate(r*this.xstep,a*this.ystep);if(this.needsIsolation||1!==t.ctx.globalAlpha||"source-over"!==t.ctx.globalCompositeOperation||t.inSMaskMode){const e=c-i,s=l-o,[r,a]=this._getCombinedScales(),h=this.getSizeAndScale(e,this.ctx.canvas.width,r),d=this.getSizeAndScale(s,this.ctx.canvas.height,a),p=this._renderTileCanvas(t,n,h,d);t.ctx.drawImage(p.canvas,i,o,e,s);t.canvasFactory.destroy(p)}else{t.resetGraphicsState();this.setFillAndStrokeStyleToContext(t,this.paintType,this.color);this.clipBbox(t,i,o,c,l);t.baseTransformStack.push(t.baseTransform);t.baseTransform=getCurrentTransform(t.ctx);t.executeOperatorList(this.operatorList);t.baseTransform=t.baseTransformStack.pop()}t.restore()}finally{h&&(t.dependencyTracker=h)}}createPatternCanvas(t,e){const[s,r,a,n]=this.bbox,i=a-s,o=n-r;let{xstep:c,ystep:l}=this;c=Math.abs(c);l=Math.abs(l);info("TilingType: "+this.tilingType);const[h,d]=this._getCombinedScales();let p=i,u=o,f=!1,m=!1;Math.ceil(c*h)>=Math.ceil(i*h)?p=c:f=!0;Math.ceil(l*d)>=Math.ceil(o*d)?u=l:m=!0;const g=this.getSizeAndScale(p,this.ctx.canvas.width,h),x=this.getSizeAndScale(u,this.ctx.canvas.height,d),k=this._renderTileCanvas(t,e,g,x);if(f||m){const e=k.canvas;f&&(p=c);m&&(u=l);const a=this.getSizeAndScale(p,this.ctx.canvas.width,h),n=this.getSizeAndScale(u,this.ctx.canvas.height,d),g=a.size,x=n.size,b=t.canvasFactory.create(g,x),y=b.context,v=f?Math.min(Math.floor(i/c),Math.ceil(e.width/g)):0,C=m?Math.min(Math.floor(o/l),Math.ceil(e.height/x)):0;let S=e,M=null;if(m){M=t.canvasFactory.create(e.width,x);const s=M.context;for(let t=C;t>=0;t--)s.drawImage(e,0,x*t,e.width,x,0,0,e.width,x);S=M.canvas}for(let t=v;t>=0;t--)y.drawImage(S,g*t,0,g,x,0,0,g,x);M&&t.canvasFactory.destroy(M);t.canvasFactory.destroy(k);return{canvas:b.canvas,canvasEntry:b,scaleX:a.scale,scaleY:n.scale,offsetX:s,offsetY:r}}return{canvas:k.canvas,canvasEntry:k,scaleX:g.scale,scaleY:x.scale,offsetX:s,offsetY:r}}getSizeAndScale(t,e,s){const r=Math.max(TilingPattern.MAX_PATTERN_SIZE,e);let a=Math.ceil(t*s);a>=r?a=r:s=a/t;return{scale:s,size:a}}clipBbox(t,e,s,r,a){const n=r-e,i=a-s,o=new Path2D;o.rect(e,s,n,i);Util.axialAlignedBoundingBox([e,s,r,a],getCurrentTransform(t.ctx),t.current.minMax);t.ctx.clip(o);t.current.updateClipFromPath()}setFillAndStrokeStyleToContext(t,e,s){switch(e){case j:s="#000000";break;case G:break;default:throw new FormatError(`Unsupported paint type: ${e}`)}const{ctx:r,current:a}=t;a.patternFill=a.patternStroke=!1;r.fillStyle=r.strokeStyle=a.transferMapsFallback?.applyToColor(s)??s;a.fillColor=a.strokeColor=s}isModifyingCurrentTransform(){return!1}getPattern(t,e,s,r,a){const n=r!==U?Util.transform(s,this.patternBaseMatrix):s,i=this.createPatternCanvas(e,a);let o=new DOMMatrix(n);o=o.translate(i.offsetX,i.offsetY);o=o.scale(1/i.scaleX,1/i.scaleY);const c=t.createPattern(i.canvas,"repeat");e.canvasFactory.destroy(i.canvasEntry);c.setTransform(o);return c}}const W=16,X=new Float32Array(2);function mirrorContextOperations(t,e){if(t._removeMirroring)throw new Error("Context is already forwarding operations.");const s=new Map;for(const r of["save","restore","rotate","scale","translate","transform","setTransform","resetTransform","clip","moveTo","lineTo","bezierCurveTo","quadraticCurveTo","arc","arcTo","ellipse","rect","roundRect","closePath","beginPath"]){const a=t[r];if("function"==typeof a&&"function"==typeof e[r]){s.set(r,a);t[r]=function(...t){e[r](...t);return a.apply(this,t)}}}t._removeMirroring=()=>{for(const[e,r]of s)t[e]=r;delete t._removeMirroring}}function drawImageAtIntegerCoords(t,e,s,r,a,n,i,o,c,l){const[h,d,p,u,f,m]=getCurrentTransform(t);if(0===d&&0===p){const g=i*h+f,x=Math.round(g),k=o*u+m,b=Math.round(k),y=(i+c)*h+f,v=Math.abs(Math.round(y)-x)||1,C=(o+l)*u+m,S=Math.abs(Math.round(C)-b)||1;t.setTransform(Math.sign(h),0,0,Math.sign(u),x,b);t.drawImage(e,s,r,a,n,0,0,v,S);t.setTransform(h,d,p,u,f,m);return[v,S]}if(0===h&&0===u){const g=o*p+f,x=Math.round(g),k=i*d+m,b=Math.round(k),y=(o+l)*p+f,v=Math.abs(Math.round(y)-x)||1,C=(i+c)*d+m,S=Math.abs(Math.round(C)-b)||1;t.setTransform(0,Math.sign(d),Math.sign(p),0,x,b);t.drawImage(e,s,r,a,n,0,0,S,v);t.setTransform(h,d,p,u,f,m);return[S,v]}t.drawImage(e,s,r,a,n,i,o,c,l);return[Math.hypot(h,d)*c,Math.hypot(p,u)*l]}class CanvasExtraState{alphaIsShape=!1;fontSize=0;fontSizeScale=1;textMatrix=null;textMatrixScale=1;fontMatrix=r;leading=0;x=0;y=0;lineX=0;lineY=0;charSpacing=0;wordSpacing=0;textHScale=1;textRenderingMode=i;textRise=0;fillColor="#000000";strokeColor="#000000";tilingPatternDims=null;patternFill=!1;patternStroke=!1;fillAlpha=1;strokeAlpha=1;lineWidth=1;activeSMask=null;transferMaps="none";transferMapsFallback=null;minMax=s.slice();constructor(t,e){this.clipBox=new Float32Array([0,0,t,e])}clone(){const t=Object.create(this);t.clipBox=this.clipBox.slice();t.minMax=this.minMax.slice();t.tilingPatternDims=this.tilingPatternDims?.slice();return t}getPathBoundingBox(t=R,e=null){const s=this.minMax.slice();if(t===L){e||unreachable("Stroke bounding box must include transform.");Util.singularValueDecompose2dScale(e,X);const t=X[0]*this.lineWidth/2,r=X[1]*this.lineWidth/2;s[0]-=t;s[1]-=r;s[2]+=t;s[3]+=r}return s}updateClipFromPath(){const t=Util.intersect(this.clipBox,this.getPathBoundingBox());this.startNewPathAndClipBox(t||[0,0,0,0])}isEmptyClip(){return this.minMax[0]===1/0}startNewPathAndClipBox(t){this.clipBox.set(t,0);this.minMax.set(s,0)}getClippedPathBoundingBox(t=R,e=null){return Util.intersect(this.clipBox,this.getPathBoundingBox(t,e))}}function putBinaryImageData(t,e){const{width:s,height:r,kind:a}=e,n=r%W,i=(r-n)/W,o=0===n?i:i+1,c=t.createImageData(s,W);let l=0;const h=e.data,d=c.data;let m;if(a===p)for(m=0;m<o;m++){({srcPos:l}=convertBlackAndWhiteToRGBA({src:h,srcPos:l,dest:d,width:s,height:m<i?W:n}));t.putImageData(c,0,m*W)}else if(a===f){let e=0,r=s*W*4;for(m=0;m<i;m++){d.set(h.subarray(l,l+r));l+=r;t.putImageData(c,0,e);e+=W}if(m<o){r=s*n*4;d.set(h.subarray(l,l+r));t.putImageData(c,0,e)}}else{if(a!==u)throw new Error(`bad image kind: ${a}`);for(m=0;m<o;m++){({srcPos:l}=convertRGBToRGBA({src:h,srcPos:l,dest:new Uint32Array(d.buffer),width:s,height:m<i?W:n}));t.putImageData(c,0,m*W)}}}function putBinaryImageMask(t,e){if(e.bitmap){t.drawImage(e.bitmap,0,0);return}const{width:s,height:r}=e,a=r%W,n=(r-a)/W,i=0===a?n:n+1,o=t.createImageData(s,W);let c=0;const l=e.data,h=o.data;for(let e=0;e<i;e++){({srcPos:c}=convertBlackAndWhiteToRGBA({src:l,srcPos:c,dest:h,width:s,height:e<n?W:a,nonBlackColor:0}));t.putImageData(o,0,e*W)}}function copyCtxState(t,e){const s=["strokeStyle","fillStyle","fillRule","globalAlpha","lineWidth","lineCap","lineJoin","miterLimit","globalCompositeOperation","font","filter"];for(const r of s)void 0!==t[r]&&(e[r]=t[r]);if(void 0!==t.setLineDash){e.setLineDash(t.getLineDash());e.lineDashOffset=t.lineDashOffset}}function getAnnotationCanvasName(t){return t._pdfjsCanvasName??null}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}const{filter:e}=t;"none"!==e&&""!==e&&(t.filter="none")}class TransferMapsFallback{#P;constructor(t){const[e,s=e,r=e]=t,a=Util.identity0to256Map.slice();this.#P=[e||a,s||a,r||a]}applyToColor(t){if("string"!=typeof t||!t.startsWith("#"))return t;const[e,s,r]=getRGBA(t),[a,n,i]=this.#P;return Util.makeHexColor(a[e],n[s],i[r])}applyToImageData({data:t}){const[e,s,r]=this.#P;for(let a=0,n=t.length;a<n;a+=4){t[a]=e[t[a]];t[a+1]=s[t[a+1]];t[a+2]=r[t[a+2]]}}applyToCanvas(t){const{width:e,height:s}=t.canvas,r=t.getImageData(0,0,e,s);this.applyToImageData(r);t.putImageData(r,0,0)}}function getImageSmoothingEnabled(t,e,s){if(e)return!0;Util.singularValueDecompose2dScale(t,X);const r=Math.fround(s*PixelsPerInch.PDF_TO_CSS_UNITS);return X[0]<=r&&X[1]<=r}const H=["butt","round","square"],V=["miter","round","bevel"],z={},Y={};class CanvasGraphics{static#A=null;static#_=new WeakMap;#E=0;#N=0;#R=null;#L=null;#U=null;#j=null;#G=1;#W;#X=null;#H=[];constructor(t,e,s,r,a,{optionalContentConfig:n,markedContentStack:i=null,pixelRatio:o=OutputScale.pixelRatio},c,l,h,d){this.ctx=t;this.current=new CanvasExtraState(this.ctx.canvas.width,this.ctx.canvas.height);this.stateStack=[];this.pendingClip=null;this.pendingEOFill=!1;this.commonObjs=e;this.objs=s;this.canvasFactory=r;this.filterFactory=a;this.groupStack=[];this.baseTransform=null;this.baseTransformStack=[];this.groupLevel=0;this.smaskStack=[];this.tempSMask=null;this.smaskGroupCanvases=[];this.smaskPreparedEntry=null;this.smaskPreparedFor=null;this.smaskPreparedOffsetX=0;this.smaskPreparedOffsetY=0;this.smaskPreparedOOBAlpha=null;this.suspendedCtx=null;this.contentVisible=!0;this.markedContentStack=i||[];this.optionalContentConfig=n;this.pixelRatio=o;this.cachedPatterns=new Map;this.annotationCanvasMap=c;this.viewportScale=1;this.outputScaleX=1;this.outputScaleY=1;this.pageColors=l;this._cachedScaleForStroking=[-1,0];this._cachedBitmapsMap=new Map;this.dependencyTracker=h??null;this.imagesTracker=d??null}getObject(t,e,s=null){if("string"==typeof e){this.dependencyTracker?.recordNamedDependency(t,e);return e.startsWith("g_")?this.commonObjs.get(e):this.objs.get(e)}return s}beginDrawing({transform:t,viewport:e,transparency:s=!1,background:r=null}){const a=this.ctx.canvas.width,n=this.ctx.canvas.height,i=this.ctx.fillStyle;this.ctx.fillStyle=r||"#ffffff";this.ctx.fillRect(0,0,a,n);this.ctx.fillStyle=i;if(s){const t=this.transparentCanvasEntry=this.canvasFactory.create(a,n);this.compositeCtx=this.ctx;({canvas:this.transparentCanvas,context:this.ctx}=t);this.ctx.save();this.ctx.transform(...getCurrentTransform(this.compositeCtx))}this.ctx.save();resetCtxToDefault(this.ctx);if(t){this.ctx.transform(...t);this.outputScaleX=t[0];this.outputScaleY=t[3]}this.ctx.transform(...e.transform);this.viewportScale=e.scale;this.baseTransform=getCurrentTransform(this.ctx)}executeOperatorList(t,e,s,r,a,n){const i=t.argsArray,o=t.fnArray,c=this._pathCache;this._pathCache=t.pathCache??CanvasGraphics.#_.getOrInsertComputed(t,makeMap);try{let c=e||0;const l=i.length;if(l===c)return c;const h=l-c>10&&"function"==typeof s,d=h?Date.now()+15:0;let p=0;const u=this.commonObjs,f=this.objs;let m,g;for(;;){if(void 0!==a){if(c===a.nextBreakPoint){a.breakIt(c,s);return c}if(a.shouldSkip(c)){if(++c===l)return c;continue}}if(!n||n(c,t)){m=o[c];g=i[c]??null;if(m!==x.dependency)null===g?this[m](c):this[m](c,...g);else for(const t of g){this.dependencyTracker?.recordNamedData(t,c);const e=t.startsWith("g_")?u:f;if(!e.has(t)){e.get(t,s,r);return c}}}c++;if(c===l)return c;if(h&&++p>10){if(Date.now()>d){s();return c}p=0}}}finally{this._pathCache=c}}#V(){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.canvasFactory.destroy(this.transparentCanvasEntry);this.transparentCanvas=null;this.transparentCanvasEntry=null}}endDrawing(){this.#V();for(const t of this.smaskGroupCanvases)this.canvasFactory.destroy(t);this.smaskGroupCanvases.length=0;this._clearPreparedSMask();this.tempSMask=null;this.smaskStack.length=0;for(const t of this.#H)this.#z(t);this.#H.length=0;this.#R=null;this.#L=null;this.#U=null;this.#j=null;this.#G=1;this.#X=null;this.#N=0;this.#E=0;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.#Y()}#Y(){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 s=t.width??t.displayWidth,r=t.height??t.displayHeight,a=[];let n=Math.max(Math.hypot(e[0],e[1]),1),i=Math.max(Math.hypot(e[2],e[3]),1),o=s,c=r;for(;n>2&&o>1||i>2&&c>1;){let t=o,e=c;if(n>2&&o>1){t=Math.ceil(o/2);n/=o/t}if(i>2&&c>1){e=Math.ceil(c/2);i/=c/e}a.push({newWidth:t,newHeight:e});o=t;c=e}if(0===a.length)return{img:t,paintWidth:s,paintHeight:r,tmpCanvas:null};if(1===a.length){const{newWidth:e,newHeight:n}=a[0],i=this.canvasFactory.create(e,n);i.context.drawImage(t,0,0,s,r,0,0,e,n);return{img:i.canvas,paintWidth:e,paintHeight:n,tmpCanvas:i}}let l=this.canvasFactory.create(1,1),h=this.canvasFactory.create(1,1),d=s,p=r,u=t;for(const{newWidth:t,newHeight:e}of a){this.canvasFactory.reset(h,t,e);h.context.drawImage(u,0,0,d,p,0,0,t,e);[l,h]=[h,l];u=l.canvas;d=t;p=e}this.canvasFactory.destroy(h);return{img:l.canvas,paintWidth:d,paintHeight:p,tmpCanvas:l}}_createMaskCanvas(t,e){const r=this.ctx,{width:a,height:n}=e,i=this.current.patternFill,o=i?this.current.fillColor:r.fillStyle,c=getCurrentTransform(r);let l,h,d,p;if((e.bitmap||e.data)&&e.count>1){const s=e.bitmap||e.data.buffer;h=JSON.stringify(i?c:[c.slice(0,4),o]);l=this._cachedBitmapsMap.getOrInsertComputed(s,makeMap);const r=l.get(h);if(r&&!i){const e=Math.round(Math.min(c[0],c[2])+c[4]),s=Math.round(Math.min(c[1],c[3])+c[5]);this.dependencyTracker?.recordDependencies(t,E);return{canvas:r,offsetX:e,offsetY:s}}d=r}if(!d){p=this.canvasFactory.create(a,n);putBinaryImageMask(p.context,e)}let u=Util.transform(c,[1/a,0,0,-1/n,0,0]);u=Util.transform(u,[1,0,0,1,0,-n]);const f=s.slice();Util.axialAlignedBoundingBox([0,0,a,n],u,f);const[m,g,x,k]=f,b=Math.round(x-m)||1,y=Math.round(k-g)||1,v=this.canvasFactory.create(b,y),C=v.context,S=m,M=g;C.translate(-S,-M);C.transform(...u);let T=null;if(!d){const t=this._scaleImage(p.canvas,getCurrentTransformInverse(C));d=t.img;T=t.tmpCanvas;if(d!==p.canvas){this.canvasFactory.destroy(p);p=null}if(l&&i){l.set(h,d);T=null;p=null}}C.imageSmoothingEnabled=getImageSmoothingEnabled(getCurrentTransform(C),e.interpolate,this.pixelRatio);drawImageAtIntegerCoords(C,d,0,0,d.width,d.height,0,0,a,n);T&&this.canvasFactory.destroy(T);p&&this.canvasFactory.destroy(p);C.globalCompositeOperation="source-in";const F=Util.transform(getCurrentTransformInverse(C),[1,0,0,1,-S,-M]);C.fillStyle=i?o.getPattern(r,this,F,R,t):o;C.fillRect(0,0,a,n);l&&!i&&l.set(h,v.canvas);this.dependencyTracker?.recordDependencies(t,E);return{canvas:v.canvas,canvasEntry:l&&!i?null:v,offsetX:Math.round(S),offsetY:Math.round(M)}}setLineWidth(t,e){this.dependencyTracker?.recordSimpleData("lineWidth",t);e!==this.current.lineWidth&&(this._cachedScaleForStroking[0]=-1);this.current.lineWidth=e;this.ctx.lineWidth=e}setLineCap(t,e){this.dependencyTracker?.recordSimpleData("lineCap",t);this.ctx.lineCap=H[e]}setLineJoin(t,e){this.dependencyTracker?.recordSimpleData("lineJoin",t);this.ctx.lineJoin=V[e]}setMiterLimit(t,e){this.dependencyTracker?.recordSimpleData("miterLimit",t);this.ctx.miterLimit=e}setDash(t,e,s){this.dependencyTracker?.recordSimpleData("dash",t);const r=this.ctx;if(void 0!==r.setLineDash){r.setLineDash(e);r.lineDashOffset=s}}setRenderingIntent(t,e){}setFlatness(t,e){}setGState(t,e){for(const[s,r]of e)switch(s){case"LW":this.setLineWidth(t,r);break;case"LC":this.setLineCap(t,r);break;case"LJ":this.setLineJoin(t,r);break;case"ML":this.setMiterLimit(t,r);break;case"D":this.setDash(t,r[0],r[1]);break;case"RI":this.setRenderingIntent(t,r);break;case"FL":this.setFlatness(t,r);break;case"Font":this.setFont(t,r[0],r[1]);break;case"CA":this.dependencyTracker?.recordSimpleData("strokeAlpha",t);this.current.strokeAlpha=r;break;case"ca":this.dependencyTracker?.recordSimpleData("fillAlpha",t);this.ctx.globalAlpha=this.current.fillAlpha=r;break;case"BM":this.dependencyTracker?.recordSimpleData("globalCompositeOperation",t);this.ctx.globalCompositeOperation=r;break;case"SMask":this.dependencyTracker?.recordSimpleData("SMask",t);this.current.activeSMask=r?this.tempSMask:null;this.current.activeSMask&&(this.current.activeSMask.blendMode=this.ctx.globalCompositeOperation);this.tempSMask=null;this.checkSMaskState(t);break;case"TR":{this.dependencyTracker?.recordSimpleData("filter",t);let e=this.filterFactory.addFilter(r);this.ctx.filter=e;let s=null;if(r&&("none"===e||!FeatureTest.isCanvasFilterSupported||"none"===this.ctx.filter||""===this.ctx.filter)){this.ctx.filter=e="none";s=new TransferMapsFallback(r)}this.current.transferMaps=e;if(s||this.current.transferMapsFallback){this.current.transferMapsFallback=s;this.current.patternFill||(this.ctx.fillStyle=this.#$(this.current.fillColor));this.current.patternStroke||(this.ctx.strokeStyle=this.#$(this.current.strokeColor))}break}}}get inSMaskMode(){return!!this.suspendedCtx}_clearPreparedSMask(){if(this.smaskPreparedEntry){this.canvasFactory.destroy(this.smaskPreparedEntry);this.smaskPreparedEntry=null}this.smaskPreparedFor=null;this.smaskPreparedOffsetX=0;this.smaskPreparedOffsetY=0;this.smaskPreparedOOBAlpha=null}_ensurePreparedSMask(t){if(t!==this.smaskPreparedFor){this._clearPreparedSMask();this._prepareSMaskCanvas(t)}}checkSMaskState(t){const e=this.inSMaskMode;this.current.activeSMask&&!e?this.beginSMaskMode(t):!this.current.activeSMask&&e?this.endSMaskMode():this.current.activeSMask&&e&&this._ensurePreparedSMask(this.current.activeSMask)}_prepareSMaskCanvas(t){const{canvas:e,subtype:s,backdrop:r,transferMap:a}=t,n="Luminosity"===s||"Alpha"===s&&a;if(!(n||"Luminosity"===s&&r)){this.smaskPreparedFor=t;return}let i;if("Luminosity"===s&&r){const[t,e,s]=getRGBA(r),n=Math.round(.3*t+.59*e+.11*s);i=a?.[n]??n}else i=a?.[0]??0;const{width:o,height:c}=this.ctx.canvas,l=o*c<4*(e.width*e.height),h=n?{url:"Alpha"===s?this.filterFactory.addAlphaFilter(a):this.filterFactory.addLuminosityFilter(a),subtype:s,transferMap:a}:null,d="Luminosity"===s?r:null;let p,u,f;if(l){p=this._bakeSMaskCanvas(e,t.offsetX,t.offsetY,o,c,d,h);u=0;f=0}else{p=this._bakeSMaskCanvas(e,0,0,e.width,e.height,d,h);u=t.offsetX;f=t.offsetY}this.smaskPreparedEntry=p;this.smaskPreparedFor=t;this.smaskPreparedOffsetX=u;this.smaskPreparedOffsetY=f;this.smaskPreparedOOBAlpha=l||0===i?null:i}_bakeSMaskCanvas(t,e,s,r,a,n,i){n||i||unreachable("_bakeSMaskCanvas with neither backdrop nor filter");const o=this.canvasFactory.create(r,a),c=o.context;c.drawImage(t,e,s);if(n){c.globalCompositeOperation="destination-atop";c.fillStyle=n;c.fillRect(0,0,r,a)}if(!i)return o;const l=this.canvasFactory.create(r,a),h=l.context;h.filter=i.url;const d=FeatureTest.isCanvasFilterSupported&&"none"!==h.filter&&""!==h.filter;h.drawImage(o.canvas,0,0);FeatureTest.isCanvasFilterSupported&&(h.filter="none");if(!d){const t=h.getImageData(0,0,r,a),{data:e}=t,{transferMap:s}=i;if("Luminosity"===i.subtype)for(let t=0,r=e.length;t<r;t+=4){const r=.3*e[t]+.59*e[t+1]+.11*e[t+2]+.5|0;e[t]=e[t+1]=e[t+2]=0;e[t+3]=s?.[r]??r}else for(let t=3,r=e.length;t<r;t+=4)e[t]=s[e[t]];h.putImageData(t,0,0)}this.canvasFactory.destroy(o);return l}beginSMaskMode(t){if(this.inSMaskMode)throw new Error("beginSMaskMode called while already in smask mode");const{width:e,height:s}=this.ctx.canvas,r=this.canvasFactory.create(e,s);this.smaskScratchCanvas=r;this.suspendedCtx=this.ctx;const a=this.ctx=r.context;a.setTransform(this.suspendedCtx.getTransform());copyCtxState(this.suspendedCtx,a);mirrorContextOperations(a,this.suspendedCtx);this._ensurePreparedSMask(this.current.activeSMask);this.setGState(t,[["BM","source-over"]])}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;this.canvasFactory.destroy(this.smaskScratchCanvas);this.smaskScratchCanvas=null;this._clearPreparedSMask()}#K(t,e=null,s=1){const{width:r,height:a}=t,n=e??this.canvasFactory.create(r,a),i=n.context,o=(s=Math.round(255*s)/255)<1;o&&void 0===this.#W&&(this.#W=FeatureTest.isCanvasFilterSupported?new Map:"none");let c="none";o&&this.#W instanceof Map&&(c=this.#W.getOrInsertComputed(s,()=>this.filterFactory.addKnockoutFilter(s)));if(!o||"none"!==c){if(e){i.save();i.setTransform(1,0,0,1,0,0);i.clearRect(0,0,r,a);i.restore()}i.filter=c;i.drawImage(t,0,0);i.filter="none";return n}const l=t.getContext("2d",{willReadFrequently:!0}).getImageData(0,0,r,a),h=i.createImageData(r,a),d=l.data,p=h.data,u=s>0?1/s:1e6;for(let t=3,e=d.length;t<e;t+=4)p[t]=Math.min(Math.round(d[t]*u),255);i.putImageData(h,0,0);return n}#q(t,e,s,r){let a=t?.[e]??null;if(a&&(a.canvas.width!==s||a.canvas.height!==r)){this.canvasFactory.destroy(a);a=null}if(!a){a=this.canvasFactory.create(s,r);t&&(t[e]=a);return a}const n=a.context;n.save();n.setTransform(1,0,0,1,0,0);n.clearRect(0,0,s,r);n.restore();return a}#J(t,e,s={}){const{backdropCanvas:r=null,destTransform:a=[1,0,0,1,0,0],backdropOffset:n=[0,0],reuseMaskEntry:i=null,poolMeta:o=null,sourceAlpha:c=1,sourceFilter:l="none",knockoutAlpha:h=1}=s,{width:d,height:p}=e,u=this.#K(e,i,h),f=t.globalCompositeOperation;t.save();t.setTransform(...a);t.globalAlpha=1;FeatureTest.isCanvasFilterSupported&&(t.filter="none");t.globalCompositeOperation="destination-out";t.drawImage(u.canvas,0,0);if(r){const[e,s]=n,a=this.#q(o,"knockoutBackdropEntry",d,p),i=a.context;i.drawImage(r,e,s,d,p,0,0,d,p);i.globalCompositeOperation="destination-in";i.drawImage(u.canvas,0,0);i.globalCompositeOperation="source-over";t.globalCompositeOperation="destination-over";t.drawImage(a.canvas,0,0);o||this.canvasFactory.destroy(a)}t.globalCompositeOperation=f;t.globalAlpha=c;FeatureTest.isCanvasFilterSupported&&(t.filter=l??"none");t.drawImage(e,0,0);t.restore();i||this.canvasFactory.destroy(u)}#Z(t=1){if(0===this.#E||this.#N>0||!this.contentVisible)return!1;this.#N++;this.#G=t;const e=this.#H.at(-1),{canvas:s}=this.ctx,r=this.#q(e,"knockoutTempEntry",s.width,s.height);this.#R=r;const a=r.context;a.save();a.setTransform(this.ctx.getTransform());copyCtxState(this.ctx,a);this.#j=a.globalCompositeOperation;a.globalCompositeOperation="source-over";mirrorContextOperations(a,this.ctx);this.#X=e;this.#L=this.ctx;this.#U=this.suspendedCtx;this.ctx=a;this.inSMaskMode&&(this.suspendedCtx=a);return!0}#Q(t){if(!t)return;const e=this.#R,s=this.#L,r=this.#U,a=e.context;this.#R=null;this.#L=null;this.#U=null;this.inSMaskMode&&this.suspendedCtx===a&&this.ctx!==a&&this.endSMaskMode();this.inSMaskMode&&(this.suspendedCtx=r);this.ctx._removeMirroring();this.ctx.globalCompositeOperation=this.#j;this.#j=null;copyCtxState(this.ctx,s);this.ctx=s;const n=this.#X;this.#X=null;const i=this.#G;this.#G=1;try{this.#J(r??s,e.canvas,{backdropCanvas:n?.backdropCtx?.canvas??null,backdropOffset:n?.backdropCtx?[n.offsetX,n.offsetY]:[0,0],reuseMaskEntry:n?.knockoutMaskEntry??null,poolMeta:n,knockoutAlpha:i})}finally{a.restore();this.#N--;n||this.canvasFactory.destroy(e)}}compose(t){if(!this.current.activeSMask)return;t=t?[Math.floor(t[0]),Math.floor(t[1]),Math.ceil(t[2]),Math.ceil(t[3])]:[0,0,this.ctx.canvas.width,this.ctx.canvas.height];const e=this.current.activeSMask,s=this.suspendedCtx,r=this.#N>0&&s===this.ctx;this.composeSMask(r?null:s,e,this.ctx,t);if(!r){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,s,r){const a=r[0],n=r[1],i=r[2]-a,o=r[3]-n;if(0===i||0===o)return;const c=this.smaskPreparedEntry;if(c){let t=a,r=n,l=i,h=o;const d=this.smaskPreparedOOBAlpha,p=null!==d;if(p){t=Math.max(a,e.offsetX);r=Math.max(n,e.offsetY);l=Math.min(a+i,e.offsetX+e.canvas.width)-t;h=Math.min(n+o,e.offsetY+e.canvas.height)-r}if(l>0&&h>0){const e=t-this.smaskPreparedOffsetX,a=r-this.smaskPreparedOffsetY;s.save();s.globalAlpha=1;s.setTransform(1,0,0,1,0,0);const n=new Path2D;n.rect(t,r,l,h);s.clip(n);s.globalCompositeOperation="destination-in";s.drawImage(c.canvas,e,a,l,h,t,r,l,h);s.restore()}p&&d<255&&this._applySMaskOOBAlpha(s,a,n,i,o,t,r,t+l,r+h,d)}else this.genericComposeSMask(e,s,i,o,a,n);if(t){t.save();t.globalAlpha=1;t.globalCompositeOperation=e.blendMode||"source-over";t.setTransform(1,0,0,1,0,0);t.drawImage(s.canvas,a,n,i,o,a,n,i,o);t.restore()}}_applySMaskOOBAlpha(t,e,s,r,a,n,i,o,c,l){const h=n<o&&i<c;if(h&&n===e&&i===s&&o===e+r&&c===s+a)return;const d=new Path2D;d.rect(e,s,r,a);h&&d.rect(n,i,o-n,c-i);t.save();t.globalAlpha=l/255;t.setTransform(1,0,0,1,0,0);t.clip(d,"evenodd");t.globalCompositeOperation="destination-in";t.fillStyle="#000000";t.fillRect(e,s,r,a);t.restore()}genericComposeSMask(t,e,s,r,a,n){const{context:i,offsetX:o,offsetY:c}=t;e.save();e.globalAlpha=1;e.setTransform(1,0,0,1,0,0);const l=new Path2D;l.rect(a,n,s,r);e.clip(l);e.globalCompositeOperation="destination-in";e.drawImage(i.canvas,a-o,n-c,s,r,a,n,s,r);e.restore()}save(t){this.inSMaskMode&©CtxState(this.ctx,this.suspendedCtx);this.ctx.save();const e=this.current;this.stateStack.push(e);this.current=e.clone();this.dependencyTracker?.save(t)}restore(t){this.dependencyTracker?.restore(t);if(0!==this.stateStack.length){this.current=this.stateStack.pop();this.ctx.restore();if(this.inSMaskMode){copyCtxState(this.suspendedCtx,this.ctx);this.ctx.setTransform(this.suspendedCtx.getTransform())}this.checkSMaskState(t);this.pendingClip=null;this._cachedScaleForStroking[0]=-1}else this.inSMaskMode&&this.endSMaskMode()}resetGraphicsState(){const{clipBox:t,transferMaps:e,transferMapsFallback:s}=this.current,r=this.current=new CanvasExtraState(0,0);r.clipBox=t;r.transferMaps=e;r.transferMapsFallback=s;const a=this.ctx;a.lineWidth=1;a.lineCap="butt";a.lineJoin="miter";a.miterLimit=10;if(void 0!==a.setLineDash){a.setLineDash([]);a.lineDashOffset=0}this._cachedScaleForStroking[0]=-1}transform(t,e,s,r,a,n,i){this.dependencyTracker?.recordIncrementalData("transform",t);this.ctx.transform(e,s,r,a,n,i);this._cachedScaleForStroking[0]=-1}constructPath(t,e,s,r){let a=this._pathCache.get(t);if(!r){if(!a){a=new Path2D;this._pathCache.set(t,a)}e!==x.stroke&&e!==x.closeStroke&&(this.current.tilingPatternDims=null);this[e](t,a);return}if(null!==this.dependencyTracker){const s=e===x.stroke?this.current.lineWidth/2:0;this.dependencyTracker.resetBBox(t).recordBBox(t,this.ctx,r[0]-s,r[2]+s,r[1]-s,r[3]+s).recordDependencies(t,["transform"])}if(!a){a=makePathFromDrawOPS(s[0]);this._pathCache.set(t,a)}Util.axialAlignedBoundingBox(r,getCurrentTransform(this.ctx),this.current.minMax);const n=this.current.tilingPatternDims;if(n&&e!==x.stroke&&e!==x.closeStroke&&this.current.fillColor instanceof TilingPattern){const t=Util.intersect(this.current.clipBox,this.current.minMax);t?this.current.fillColor.updatePatternDims(t,n):this.current.tilingPatternDims=null}this[e](t,a);this._pathStartIdx=t}closePath(t){this.ctx.closePath()}stroke(t,e,s=!0){const r=s&&this.#Z(this.current.strokeAlpha),a=this.ctx,n=this.current.strokeColor;a.globalAlpha=this.current.strokeAlpha;if(this.contentVisible)if("object"==typeof n&&n?.getPattern){const s=n.isModifyingCurrentTransform()?a.getTransform():null;a.save();a.strokeStyle=n.getPattern(a,this,getCurrentTransformInverse(a),L,t);if(s){const t=new Path2D;t.addPath(e,a.getTransform().invertSelf().multiplySelf(s));e=t}this.rescaleAndStroke(e,!1);a.restore()}else this.rescaleAndStroke(e,!0);this.dependencyTracker?.recordDependencies(t,I);s&&this.consumePath(t,e,this.current.getClippedPathBoundingBox(L,getCurrentTransform(this.ctx)));a.globalAlpha=this.current.fillAlpha;this.#Q(r)}closeStroke(t,e){this.stroke(t,e)}fill(t,e,s=!0){const r=s&&this.#Z(this.current.fillAlpha),a=this.ctx,n=this.current.fillColor,i=this.current.patternFill;let o=!1;const c=this.current.getClippedPathBoundingBox();this.dependencyTracker?.recordDependencies(t,O);if(i){const i=this.current.tilingPatternDims,l=i&&n.canSkipPatternCanvas(i);if(l){const{pendingClip:a,pendingEOFill:i}=this;this.pendingClip=null;this.pendingEOFill=!1;n.drawPattern(this,e,i,l,t);this.pendingClip=a;s&&this.consumePath(t,e,c);this.current.tilingPatternDims=null;this.#Q(r);return}const h=n.isModifyingCurrentTransform()?a.getTransform():null;this.dependencyTracker?.save(t);a.save();a.fillStyle=n.getPattern(a,this,getCurrentTransformInverse(a),R,t);if(h){const t=new Path2D;t.addPath(e,a.getTransform().invertSelf().multiplySelf(h));e=t}o=!0}if(this.contentVisible&&null!==c)if(this.pendingEOFill){a.fill(e,"evenodd");this.pendingEOFill=!1}else a.fill(e);if(o){a.restore();this.dependencyTracker?.restore(t)}s&&this.consumePath(t,e,c);this.#Q(r)}eoFill(t,e){this.pendingEOFill=!0;this.fill(t,e)}fillStroke(t,e){const s=this.#Z(Math.min(this.current.fillAlpha,this.current.strokeAlpha));this.fill(t,e,!1);this.stroke(t,e,!1);this.consumePath(t,e);this.#Q(s)}eoFillStroke(t,e){this.pendingEOFill=!0;this.fillStroke(t,e)}closeFillStroke(t,e){this.fillStroke(t,e)}closeEOFillStroke(t,e){this.pendingEOFill=!0;this.fillStroke(t,e)}endPath(t,e){this.consumePath(t,e)}rawFillPath(t,e){const s=this.#Z(this.current.fillAlpha);this.ctx.fill(e);this.dependencyTracker?.recordDependencies(t,P).recordOperation(t);this.#Q(s)}clip(t){this.dependencyTracker?.recordFutureForcedDependency("clipMode",t);this.pendingClip=z}eoClip(t){this.dependencyTracker?.recordFutureForcedDependency("clipMode",t);this.pendingClip=Y}beginText(t){this.current.textMatrix=null;this.current.textMatrixScale=1;this.current.x=this.current.lineX=0;this.current.y=this.current.lineY=0;this.dependencyTracker?.recordOpenMarker(t).resetIncrementalData("sameLineText").resetIncrementalData("moveText",t)}endText(t){const e=this.pendingTextPaths,s=this.ctx;if(this.dependencyTracker){const{dependencyTracker:s}=this;void 0!==e&&s.recordFutureForcedDependency("textClip",s.getOpenMarker()).recordFutureForcedDependency("textClip",t);s.recordCloseMarker(t)}if(void 0!==e){const t=new Path2D,r=s.getTransform().invertSelf();for(const{transform:s,x:a,y:n,fontSize:i,path:o}of e)o&&t.addPath(o,new DOMMatrix(s).preMultiplySelf(r).translate(a,n).scale(i,-i));s.clip(t)}delete this.pendingTextPaths}setCharSpacing(t,e){this.dependencyTracker?.recordSimpleData("charSpacing",t);this.current.charSpacing=e}setWordSpacing(t,e){this.dependencyTracker?.recordSimpleData("wordSpacing",t);this.current.wordSpacing=e}setHScale(t,e){this.dependencyTracker?.recordSimpleData("hScale",t);this.current.textHScale=e/100}setLeading(t,e){this.dependencyTracker?.recordSimpleData("leading",t);this.current.leading=-e}setFont(t,e,s){this.dependencyTracker?.recordSimpleData("font",t).recordSimpleDataFromNamed("fontObj",e,t);const a=this.commonObjs.get(e),n=this.current;if(!a)throw new Error(`Can't find font for ${e}`);n.fontMatrix=a.fontMatrix||r;0!==n.fontMatrix[0]&&0!==n.fontMatrix[3]||warn("Invalid font matrix for font "+e);if(s<0){s=-s;n.fontDirection=-1}else n.fontDirection=1;this.current.font=a;this.current.fontSize=s;if(a.isType3Font)return;const i=a.loadedName||"sans-serif",o=a.systemFontInfo?.css||`"${i}", ${a.fallbackName}`;let c="normal";a.black?c="900":a.bold&&(c="bold");const l=a.italic?"italic":"normal",h=math_clamp_MathClamp(s,16,100);this.current.fontSizeScale=s/h;this.ctx.font=`${l} ${c} ${h}px ${o}`}setTextRenderingMode(t,e){this.dependencyTracker?.recordSimpleData("textRenderingMode",t);this.current.textRenderingMode=e}setTextRise(t,e){this.dependencyTracker?.recordSimpleData("textRise",t);this.current.textRise=e}moveText(t,e,s){this.dependencyTracker?.resetIncrementalData("sameLineText").recordIncrementalData("moveText",t);this.current.x=this.current.lineX+=e;this.current.y=this.current.lineY+=s}setLeadingMoveText(t,e,s){this.setLeading(t,-s);this.moveText(t,e,s)}setTextMatrix(t,e){this.dependencyTracker?.resetIncrementalData("sameLineText").recordSimpleData("textMatrix",t);const{current:s}=this;s.textMatrix=e;s.textMatrixScale=Math.hypot(e[0],e[1]);s.x=s.lineX=0;s.y=s.lineY=0}nextLine(t){this.moveText(t,0,this.current.leading);this.dependencyTracker?.recordIncrementalData("moveText",this.dependencyTracker.getSimpleIndex("leading")??t)}#tt(t,e,s){const r=new Path2D;r.addPath(t,new DOMMatrix(s).invertSelf().multiplySelf(e));return r}paintChar(t,e,s,r,a,n){const l=this.ctx,p=this.current,u=p.font,f=p.textRenderingMode,m=p.fontSize/p.fontSizeScale,g=f&h,x=!!(f&d),k=p.patternFill&&!u.missingFile,b=p.patternStroke&&!u.missingFile;let y;(u.disableFontFace||x||k||b)&&!u.missingFile&&(y=u.getPathGenerator(this.commonObjs,e));if(y&&(u.disableFontFace||k||b)){l.save();l.translate(s,r);l.scale(m,-m);this.dependencyTracker?.recordCharacterBBox(t,l,u);let e;if(g===i||g===c)if(a){e=l.getTransform();l.setTransform(...a);const t=this.#tt(y,e,a);l.fill(t)}else l.fill(y);if(g===o||g===c)if(n){e||=l.getTransform();l.setTransform(...n);const{a:t,b:s,c:r,d:a}=e,i=Util.inverseTransform(n),o=Util.transform([t,s,r,a,0,0],i);Util.singularValueDecompose2dScale(o,X);l.lineWidth*=Math.max(X[0],X[1])/m;l.stroke(this.#tt(y,e,n))}else{l.lineWidth/=m;l.stroke(y)}l.restore()}else{if(g===i||g===c){l.fillText(e,s,r);this.dependencyTracker?.recordCharacterBBox(t,l,u,m,s,r,()=>l.measureText(e))}if(g===o||g===c){this.dependencyTracker&&this.dependencyTracker?.recordCharacterBBox(t,l,u,m,s,r,()=>l.measureText(e)).recordDependencies(t,I);l.strokeText(e,s,r)}}if(x){(this.pendingTextPaths||=[]).push({transform:getCurrentTransform(l),x:s,y:r,fontSize:m,path:y});this.dependencyTracker?.recordCharacterBBox(t,l,u,m,s,r)}}get isFontSubpixelAAEnabled(){const t=this.canvasFactory.create(10,10),e=t.context;e.scale(1.5,1);e.fillText("I",0,10);const s=e.getImageData(0,0,10,10).data;this.canvasFactory.destroy(t);let r=!1;for(let t=3;t<s.length;t+=4)if(s[t]>0&&s[t]<255){r=!0;break}return shadow(this,"isFontSubpixelAAEnabled",r)}#et(t,e,s){const r=this.ctx;r.save();const a=t.getPattern(r,this,getCurrentTransformInverse(r),e,s),n=getCurrentTransform(r);r.restore();return[a,n]}showText(t,e){if(this.dependencyTracker){this.dependencyTracker.recordDependencies(t,A).resetBBox(t);this.current.textRenderingMode&d&&this.dependencyTracker.recordFutureForcedDependency("textClip",t).inheritPendingDependenciesAsFutureForcedDependencies()}const s=this.current,r=s.font;if(r.isType3Font){const r=this.#Z(s.fillAlpha);this.showType3Text(t,e);this.dependencyTracker?.recordShowTextOperation(t);this.#Q(r);return}const a=s.fontSize;if(0===a){this.dependencyTracker?.recordOperation(t);return}const n=this.#Z(s.fillAlpha),l=this.ctx,p=s.fontSizeScale,u=s.charSpacing,f=s.wordSpacing,m=s.fontDirection,g=s.textHScale*m,x=e.length,k=r.vertical,b=k?1:-1,y=a*s.fontMatrix[0],v=s.textRenderingMode===i&&!r.disableFontFace&&!s.patternFill;l.save();s.textMatrix&&l.transform(...s.textMatrix);l.translate(s.x,s.y+s.textRise);m>0?l.scale(g,-1):l.scale(g,1);let C,S;const M=s.textRenderingMode&h,T=M===i||M===c,F=M===o||M===c;let w=s.lineWidth;const B=s.textMatrixScale;0===B||0===w?F&&(w=this.getSinglePixelWidth()):w/=B;if(1!==p){l.scale(p,p);w/=p}l.lineWidth=w;T&&s.patternFill&&([l.fillStyle,C]=this.#et(s.fillColor,R,t));F&&s.patternStroke&&([l.strokeStyle,S]=this.#et(s.strokeColor,L,t));if(r.isInvalidPDFjsFont){const r=[];let a=0;for(const t of e){r.push(t.unicode);a+=t.width}const i=r.join("");l.fillText(i,0,0);if(null!==this.dependencyTracker){const e=l.measureText(i);this.dependencyTracker.recordBBox(t,this.ctx,-e.actualBoundingBoxLeft,e.actualBoundingBoxRight,-e.actualBoundingBoxAscent,e.actualBoundingBoxDescent).recordShowTextOperation(t)}s.x+=a*y*g;l.restore();this.compose();this.#Q(n);return}let I,O=0,D=null;for(I=0;I<x;++I){const n=e[I];if("number"==typeof n){O+=b*n*a/1e3;continue}let i=!1;const o=(n.isSpace?f:0)+u,c=n.fontChar,h=n.accent;let d,g,x,M=n.width;if(k){const t=n.vmetric,e=-t[1]*y,s=t[2]*y;M=-t[0];d=e/p;g=(O+s)/p;if(n.isRotated){x=l.measureText(c);const t=y/p,e=n.width/2*t,s=d+e;d=g-380*t-e;g=(x.actualBoundingBoxAscent-x.actualBoundingBoxDescent)/2-s;i=!0;l.save();l.rotate(Math.PI/2)}}else{d=O/p;g=0}const T=n.isRotated?n.width:M;let F=1;if((r.remeasure||n.isRotated)&&T>0){x??=l.measureText(c);const t=1e3*x.width/a*p;if(T<t&&this.isFontSubpixelAAEnabled){F=T/t;if(!i){i=!0;l.save()}l.scale(F,1);d/=F}else T!==t&&(d+=(T-t)/2e3*a/p)}if(i&&r.missingFile&&(C||S)){D||=new Map;[l.fillStyle,l.strokeStyle]=D.getOrInsertComputed(n.isRotated?-F:F,()=>[C?this.#et(s.fillColor,R,t)[0]:l.fillStyle,S?this.#et(s.strokeColor,L,t)[0]:l.strokeStyle])}if(this.contentVisible&&(n.isInFont||r.missingFile))if(v&&!h){l.fillText(c,d,g);this.dependencyTracker?.recordCharacterBBox(t,l,x?{bbox:null}:r,a/p,d,g,()=>x??l.measureText(c))}else{this.paintChar(t,c,d,g,C,S);if(h){const e=d+a*h.offset.x/p,s=g-a*h.offset.y/p;this.paintChar(t,h.fontChar,e,s,C,S)}}O+=k?M*y-o*m:M*y+o*m;i&&l.restore()}k?s.y-=O:s.x+=O*g;l.restore();this.compose();this.dependencyTracker?.recordShowTextOperation(t);this.#Q(n)}showType3Text(t,e){const s=this.ctx,a=this.current,n=a.font,i=a.fontSize,o=a.fontDirection,c=n.vertical?1:-1,h=a.charSpacing,d=a.wordSpacing,p=a.textHScale*o,u=a.fontMatrix||r,f=e.length,m=a.textRenderingMode!==l;let g,x,k,b;if(0===i)return;this._cachedScaleForStroking[0]=-1;s.save();a.textMatrix&&s.transform(...a.textMatrix);s.translate(a.x,a.y+a.textRise);s.scale(p,o);const y=this.dependencyTracker;this.dependencyTracker=y?new CanvasNestedDependencyTracker(y,t):null;try{for(g=0;g<f;++g){x=e[g];if("number"==typeof x){b=c*x*i/1e3;this.ctx.translate(b,0);a.x+=b*p;continue}const t=(x.isSpace?d:0)+h,r=n.charProcOperatorList.get(x.operatorListId);if(r){if(this.contentVisible&&m){this.save();s.scale(i,i);s.transform(...u);this.executeOperatorList(r);this.restore()}}else warn(`Type3 character "${x.operatorListId}" is not available.`);k=x.width*u[0]*i+t*o;s.translate(k,0);a.x+=k*p}}finally{y&&(this.dependencyTracker=y)}s.restore()}setCharWidth(t,e,s){}setCharWidthAndBounds(t,e,s,r,a,n,i){const o=new Path2D;o.rect(r,a,n-r,i-a);this.ctx.clip(o);this.dependencyTracker?.recordBBox(t,this.ctx,r,n,a,i).recordClipBox(t,this.ctx,r,n,a,i);this.endPath(t)}getColorN_Pattern(t,e){let s;if("TilingPattern"===e[0]){const t=this.baseTransform||getCurrentTransform(this.ctx),r={createCanvasGraphics:(t,e)=>new CanvasGraphics(t,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:this.optionalContentConfig,markedContentStack:this.markedContentStack,pixelRatio:this.pixelRatio},void 0,void 0,this.dependencyTracker?new CanvasNestedDependencyTracker(this.dependencyTracker,e,!0):null)};s=new TilingPattern(e,this.ctx,r,t)}else s=this._getPattern(t,e[1],e[2]);return s}setStrokeColorN(t,...e){this.dependencyTracker?.recordSimpleData("strokeColor",t);this.current.strokeColor=this.getColorN_Pattern(t,e);this.current.patternStroke=!0}setFillColorN(t,...e){this.dependencyTracker?.recordSimpleData("fillColor",t);const s=this.current.fillColor=this.getColorN_Pattern(t,e);this.current.patternFill=!0;this.current.tilingPatternDims=s instanceof TilingPattern?[0,0,0,0]:null}#$(t){return this.current.transferMapsFallback?.applyToColor(t)??t}setStrokeRGBColor(t,e){this.dependencyTracker?.recordSimpleData("strokeColor",t);this.current.strokeColor=e;this.ctx.strokeStyle=this.#$(e);this.current.patternStroke=!1}setStrokeTransparent(t){this.dependencyTracker?.recordSimpleData("strokeColor",t);this.ctx.strokeStyle=this.current.strokeColor="transparent";this.current.patternStroke=!1}setFillRGBColor(t,e){this.dependencyTracker?.recordSimpleData("fillColor",t);this.current.fillColor=e;this.ctx.fillStyle=this.#$(e);this.current.patternFill=!1;this.current.tilingPatternDims=null}setFillTransparent(t){this.dependencyTracker?.recordSimpleData("fillColor",t);this.ctx.fillStyle=this.current.fillColor="transparent";this.current.patternFill=!1;this.current.tilingPatternDims=null}_getPattern(t,e,s=null){const r=this.cachedPatterns.getOrInsertComputed(e,()=>function getShadingPattern(t){switch(t[0]){case"RadialAxial":return new RadialAxialShadingPattern(t);case"Mesh":return new MeshShadingPattern(t);case"Dummy":return new DummyShadingPattern}throw new Error(`Unknown IR type: ${t[0]}`)}(this.getObject(t,e)));s&&(r.matrix=s);return r}shadingFill(t,e){if(!this.contentVisible)return;const r=this.#Z(this.current.fillAlpha),a=this.ctx;this.save(t);const n=this._getPattern(t,e);a.fillStyle=n.getPattern(a,this,getCurrentTransformInverse(a),U,t);const i=getCurrentTransformInverse(a);if(i){const{width:t,height:e}=a.canvas,r=s.slice();Util.axialAlignedBoundingBox([0,0,t,e],i,r);const[n,o,c,l]=r;this.ctx.fillRect(n,o,c-n,l-o)}else this.ctx.fillRect(-1e10,-1e10,2e10,2e10);this.dependencyTracker?.resetBBox(t).recordFullPageBBox(t).recordDependencies(t,_).recordDependencies(t,O).recordOperation(t);this.compose(this.current.getClippedPathBoundingBox());this.restore(t);this.#Q(r)}beginInlineImage(){unreachable("Should not call beginInlineImage")}beginImageData(){unreachable("Should not call beginImageData")}paintFormXObjectBegin(t,e,s){if(this.contentVisible){this.save(t);this.baseTransformStack.push(this.baseTransform);e&&this.transform(t,...e);this.baseTransform=getCurrentTransform(this.ctx);if(s){Util.axialAlignedBoundingBox(s,this.baseTransform,this.current.minMax);const[e,r,a,n]=s,i=new Path2D;i.rect(e,r,a-e,n-r);this.ctx.clip(i);this.dependencyTracker?.recordClipBox(t,this.ctx,e,a,r,n);this.endPath(t)}}}paintFormXObjectEnd(t){if(this.contentVisible){this.restore(t);this.baseTransform=this.baseTransformStack.pop()}}beginGroup(t,e){if(!this.contentVisible)return;this.save(t);const{inSMaskMode:r}=this;if(r){this.endSMaskMode();this.current.activeSMask=null}const a=this.ctx;if(!(e.needsIsolation&&(e.isolated||e.hasSoftMask)||e.knockout||e.isGray||0!==this.#E||1!==a.globalAlpha||"source-over"!==a.globalCompositeOperation||r)){if(e.bbox){let t=new Path2D;const[s,r,n,i]=e.bbox;t.rect(s,r,n-s,i-r);if(e.matrix){const s=new Path2D;s.addPath(t,new DOMMatrix(e.matrix));t=s}a.clip(t)}this.groupStack.push(null);this.#H.push(null);this.groupLevel++;return}e.isolated||e.knockout||0!==this.#E||info("TODO: Fully support non-isolated non-knockout groups.");const n=getCurrentTransform(a);e.matrix&&a.transform(...e.matrix);const i=[0,0,a.canvas.width,a.canvas.height];let o;if(e.bbox){o=s.slice();Util.axialAlignedBoundingBox(e.bbox,getCurrentTransform(a),o);o=Util.intersect(o,i)||[0,0,0,0]}else o=i;const c=Math.floor(o[0]),l=Math.floor(o[1]),h=Math.max(Math.ceil(o[2])-c,1),d=Math.max(Math.ceil(o[3])-l,1);this.current.startNewPathAndClipBox([0,0,h,d]);const p=this.canvasFactory.create(h,d);e.smask&&this.smaskGroupCanvases.push(p);const u=p.context,f=e.knockout&&!e.isolated?a:null,m=!e.isolated&&!e.knockout&&!e.smask&&e.needsIsolation&&this.#E>0,g=e.knockout?this.canvasFactory.create(h,d):null,x=this.#E;e.knockout?this.#E++:this.#E=0;u.translate(-c,-l);u.transform(...n);const k=!e.isolated&&!e.smask&&e.needsIsolation,b=k&&!r&&0===x&&!e.knockout&&!e.isGray&&e.hasSoftMask&&1===a.globalAlpha&&"source-over"===a.globalCompositeOperation&&"none"===this.current.transferMaps&&!this.current.transferMapsFallback;if(k&&(r||b)){u.save();u.setTransform(1,0,0,1,0,0);u.drawImage(a.canvas,-c,-l);u.restore()}if(e.bbox){let t=new Path2D;const[s,r,a,n]=e.bbox;t.rect(s,r,a-s,n-r);if(e.matrix){const s=new Path2D;s.addPath(t,new DOMMatrix(e.matrix));t=s}u.clip(t)}e.smask&&this.smaskStack.push({canvas:p.canvas,context:u,offsetX:c,offsetY:l,subtype:e.smask.subtype,backdrop:e.smask.backdrop,transferMap:e.smask.transferMap||null});if(!e.smask||this.dependencyTracker){a.setTransform(1,0,0,1,0,0);a.translate(c,l);a.save()}copyCtxState(a,u);this.ctx=u;this.dependencyTracker?.inheritSimpleDataAsFutureForcedDependencies(["fillAlpha","strokeAlpha","globalCompositeOperation"]).pushBaseTransform(a);this.setGState(t,[["BM","source-over"],["ca",1],["CA",1],["TR",null]]);this.groupStack.push(a);this.#H.push({backdropCtx:f,savedKnockoutLevel:x,offsetX:c,offsetY:l,hasInnerBackdrop:m,replaceBackdrop:b,knockoutMaskEntry:g,knockoutTempEntry:null,knockoutBackdropEntry:null});this.groupLevel++}endGroup(t,e){if(!this.contentVisible)return;this.groupLevel--;const r=this.ctx,a=this.groupStack.pop(),n=this.#H.pop();n&&(this.#E=n.savedKnockoutLevel);if(null!==a){e.isGray&&this.#st(r);this.ctx=a;this.ctx.imageSmoothingEnabled=!1;this.dependencyTracker?.popBaseTransform();if(e.smask){this.tempSMask=this.smaskStack.pop();this.restore(t);if(this.dependencyTracker){this.ctx.restore();this.inSMaskMode&&this.ctx.setTransform(this.suspendedCtx.getTransform())}this.#z(n)}else{this.ctx.restore();const e=getCurrentTransform(this.ctx);this.restore(t);this.current.transferMapsFallback?.applyToCanvas(r);this.ctx.save();this.ctx.setTransform(...e);const i=s.slice();Util.axialAlignedBoundingBox([0,0,r.canvas.width,r.canvas.height],e,i);const o=this.#H.at(-1);if(this.#E>0)if(n.hasInnerBackdrop){const{width:t,height:s}=r.canvas,i=this.canvasFactory.create(t,s),o=i.context;o.drawImage(a.canvas,n.offsetX,n.offsetY,t,s,0,0,t,s);o.globalCompositeOperation="source-over";o.drawImage(r.canvas,0,0);const c=this.#K(r.canvas);o.globalCompositeOperation="destination-in";o.drawImage(c.canvas,0,0);const l=this.ctx.globalCompositeOperation,h=this.ctx.globalAlpha,d=this.ctx.filter;this.ctx.save();this.ctx.setTransform(...e);this.ctx.globalAlpha=1;FeatureTest.isCanvasFilterSupported&&(this.ctx.filter="none");this.ctx.globalCompositeOperation="destination-out";this.ctx.drawImage(c.canvas,0,0);this.ctx.globalCompositeOperation=l;this.ctx.globalAlpha=h;FeatureTest.isCanvasFilterSupported&&(this.ctx.filter=d??"none");this.ctx.drawImage(i.canvas,0,0);this.ctx.restore();this.canvasFactory.destroy(c);this.canvasFactory.destroy(i)}else{const t=o?.backdropCtx??null;this.#J(this.ctx,r.canvas,{backdropCanvas:t?.canvas??null,destTransform:e,backdropOffset:t?[o.offsetX+n.offsetX,o.offsetY+n.offsetY]:[0,0],sourceAlpha:this.ctx.globalAlpha,sourceFilter:this.ctx.filter})}else{if(n.replaceBackdrop){const t=new Path2D;t.rect(0,0,r.canvas.width,r.canvas.height);this.ctx.clip(t);this.ctx.globalCompositeOperation="copy"}this.ctx.drawImage(r.canvas,0,0)}this.ctx.restore();this.canvasFactory.destroy({canvas:r.canvas,context:r});this.#z(n);this.compose(i)}}else this.restore(t)}#st(t){const{canvas:e}=t,{width:s,height:r}=e;if(FeatureTest.isCanvasFilterSupported){t.save();t.setTransform(1,0,0,1,0,0);t.filter="grayscale(1)";t.globalAlpha=1;t.globalCompositeOperation="copy";t.drawImage(e,0,0);t.restore();return}const a=t.getImageData(0,0,s,r),{data:n}=a;for(let t=0,e=n.length;t<e;t+=4){const e=.2126*n[t]+.7152*n[t+1]+.0722*n[t+2]+.5|0;n[t]=n[t+1]=n[t+2]=e}t.putImageData(a,0,0)}#z(t){if(t){if(t.knockoutMaskEntry){this.canvasFactory.destroy(t.knockoutMaskEntry);t.knockoutMaskEntry=null}if(t.knockoutTempEntry){this.canvasFactory.destroy(t.knockoutTempEntry);t.knockoutTempEntry=null}if(t.knockoutBackdropEntry){this.canvasFactory.destroy(t.knockoutBackdropEntry);t.knockoutBackdropEntry=null}}}beginAnnotation(t,e,s,r,a,n,i){this.#V();resetCtxToDefault(this.ctx);this.ctx.save();this.save(t);this.baseTransform&&this.ctx.setTransform(...this.baseTransform);if(s){const a=s[2]-s[0],o=s[3]-s[1];if(n&&this.annotationCanvasMap){(r=r.slice())[4]-=s[0];r[5]-=s[1];Util.singularValueDecompose2dScale(getCurrentTransform(this.ctx),X);const{viewportScale:t}=this,n=Math.ceil(a*this.outputScaleX*t),c=Math.ceil(o*this.outputScaleY*t);this.annotationCanvas=this.canvasFactory.create(n,c);const{canvas:l,context:h}=this.annotationCanvas;if(i){const t=this.annotationCanvasMap.getOrInsertComputed(e,makeArr);!function setAnnotationCanvasName(t,e){t.setAttribute?.("data-canvas-name",e);t._pdfjsCanvasName=e}(l,i);const s=t.findIndex(t=>getAnnotationCanvasName(t)===i);-1===s?t.push(l):t[s]=l}else this.annotationCanvasMap.set(e,l);this.annotationCanvas.savedCtx=this.ctx;this.ctx=h;this.ctx.save();this.ctx.setTransform(X[0],0,0,-X[1],0,o*X[1]);resetCtxToDefault(this.ctx)}else{resetCtxToDefault(this.ctx);this.endPath(t);const e=new Path2D;e.rect(s[0],s[1],a,o);this.ctx.clip(e)}}this.current=new CanvasExtraState(this.ctx.canvas.width,this.ctx.canvas.height);this.baseTransformStack.push(this.baseTransform);this.transform(t,...r);this.transform(t,...a);this.baseTransform=getCurrentTransform(this.ctx)}endAnnotation(t){if(this.annotationCanvas){this.ctx.restore();this.#Y();this.ctx=this.annotationCanvas.savedCtx;delete this.annotationCanvas.savedCtx;delete this.annotationCanvas}this.baseTransform=this.baseTransformStack.pop()}paintImageMaskXObject(t,e){if(!this.contentVisible)return;const s=e.count;(e=this.getObject(t,e.data,e)).count=s;const r=this.#Z(this.current.fillAlpha),a=this.ctx,n=this._createMaskCanvas(t,e),i=n.canvas;a.save();a.setTransform(1,0,0,1,0,0);a.drawImage(i,n.offsetX,n.offsetY);this.dependencyTracker?.resetBBox(t).recordBBox(t,this.ctx,n.offsetX,n.offsetX+i.width,n.offsetY,n.offsetY+i.height).recordOperation(t);a.restore();n.canvasEntry&&this.canvasFactory.destroy(n.canvasEntry);this.compose();this.#Q(r)}paintImageMaskXObjectRepeat(t,e,s,r=0,a=0,n,i){if(!this.contentVisible)return;e=this.getObject(t,e.data,e);const o=this.#Z(this.current.fillAlpha),c=this.ctx;c.save();const l=getCurrentTransform(c);c.transform(s,r,a,n,0,0);const h=this._createMaskCanvas(t,e);c.setTransform(1,0,0,1,h.offsetX-l[4],h.offsetY-l[5]);this.dependencyTracker?.resetBBox(t);for(let e=0,o=i.length;e<o;e+=2){const o=Util.transform(l,[s,r,a,n,i[e],i[e+1]]);c.drawImage(h.canvas,o[4],o[5]);this.dependencyTracker?.recordBBox(t,this.ctx,o[4],o[4]+h.canvas.width,o[5],o[5]+h.canvas.height)}c.restore();h.canvasEntry&&this.canvasFactory.destroy(h.canvasEntry);this.compose();this.dependencyTracker?.recordOperation(t);this.#Q(o)}paintImageMaskXObjectGroup(t,e){if(!this.contentVisible)return;const s=this.#Z(this.current.fillAlpha),r=this.ctx,a=this.current.patternFill,n=a?this.current.fillColor:r.fillStyle;this.dependencyTracker?.resetBBox(t).recordDependencies(t,E);for(const s of e){const{data:e,width:i,height:o,transform:c}=s,l=this.canvasFactory.create(i,o),h=l.context;h.save();putBinaryImageMask(h,this.getObject(t,e,s));h.globalCompositeOperation="source-in";h.fillStyle=a?n.getPattern(h,this,getCurrentTransformInverse(r),R,t):n;h.fillRect(0,0,i,o);h.restore();r.save();r.transform(...c);r.scale(1,-1);drawImageAtIntegerCoords(r,l.canvas,0,0,i,o,0,-1,1,1);this.canvasFactory.destroy(l);this.dependencyTracker?.recordBBox(t,r,0,i,0,o);r.restore()}this.compose();this.dependencyTracker?.recordOperation(t);this.#Q(s)}paintImageXObject(t,e){if(!this.contentVisible)return;const s=this.getObject(t,e);s?this.paintInlineImageXObject(t,s):warn("Dependent image isn't ready yet")}paintImageXObjectRepeat(t,e,s,r,a){if(!this.contentVisible)return;const n=this.getObject(t,e);if(!n){warn("Dependent image isn't ready yet");return}const i=n.width,o=n.height,c=[];for(let t=0,e=a.length;t<e;t+=2)c.push({transform:[s,0,0,r,a[t],a[t+1]],x:0,y:0,w:i,h:o});this.paintInlineImageXObjectGroup(t,n,c)}applyTransferMapsToCanvas(t){if("none"!==this.current.transferMaps){t.filter=this.current.transferMaps;t.drawImage(t.canvas,0,0);t.filter="none"}else this.current.transferMapsFallback?.applyToCanvas(t);return t.canvas}applyTransferMapsToBitmap(t){const{transferMaps:e,transferMapsFallback:s}=this.current;if("none"===e&&!s)return{img:t.bitmap,canvasEntry:null};const{bitmap:r,width:a,height:n}=t,i=this.canvasFactory.create(a,n),o=i.context;o.filter=e;o.drawImage(r,0,0);o.filter="none";s?.applyToCanvas(o);return{img:i.canvas,canvasEntry:i}}paintInlineImageXObject(t,e){if(!this.contentVisible)return;const s=e.width,r=e.height,a=this.#Z(this.current.fillAlpha),n=this.ctx;this.save(t);const{filter:i}=n;"none"!==i&&""!==i&&(n.filter="none");n.scale(1/s,-1/r);let o,c=null;if(e.bitmap){const t=this.applyTransferMapsToBitmap(e);o=t.img;c=t.canvasEntry}else{const t=this.canvasFactory.create(s,r);putBinaryImageData(t.context,e);o=this.applyTransferMapsToCanvas(t.context);c=t}const l=this._scaleImage(o,getCurrentTransformInverse(n));n.imageSmoothingEnabled=getImageSmoothingEnabled(getCurrentTransform(n),e.interpolate,this.pixelRatio);if(this.dependencyTracker){this.dependencyTracker.resetBBox(t).recordBBox(t,n,0,s,-r,0).recordDependencies(t,D).recordOperation(t);this.imagesTracker?.record(n,s,r,this.dependencyTracker.clipBox)}drawImageAtIntegerCoords(n,l.img,0,0,l.paintWidth,l.paintHeight,0,-r,s,r);l.tmpCanvas&&this.canvasFactory.destroy(l.tmpCanvas);c&&this.canvasFactory.destroy(c);this.compose();this.restore(t);this.#Q(a)}paintInlineImageXObjectGroup(t,e,s){if(!this.contentVisible)return;const r=this.#Z(this.current.fillAlpha),a=this.ctx;let n,i=null;if(e.bitmap&&!this.current.transferMapsFallback)n=e.bitmap;else if(e.bitmap)({img:n,canvasEntry:i}=this.applyTransferMapsToBitmap(e));else{const t=e.width,s=e.height,r=this.canvasFactory.create(t,s);putBinaryImageData(r.context,e);n=this.applyTransferMapsToCanvas(r.context);i=r}this.dependencyTracker?.resetBBox(t);for(const e of s){a.save();a.transform(...e.transform);a.scale(1,-1);drawImageAtIntegerCoords(a,n,e.x,e.y,e.w,e.h,0,-1,1,1);this.dependencyTracker?.recordBBox(t,a,0,1,-1,0);a.restore()}i&&this.canvasFactory.destroy(i);this.dependencyTracker?.recordOperation(t);this.compose();this.#Q(r)}paintSolidColorImageMask(t){if(!this.contentVisible)return;const e=this.#Z(this.current.fillAlpha);this.dependencyTracker?.resetBBox(t).recordBBox(t,this.ctx,0,1,0,1).recordDependencies(t,O).recordOperation(t);this.ctx.fillRect(0,0,1,1);this.compose();this.#Q(e)}markPoint(t,e){}markPointProps(t,e,s){}beginMarkedContent(t,e){this.dependencyTracker?.beginMarkedContent(t);this.markedContentStack.push({visible:!0})}beginMarkedContentProps(t,e,s){this.dependencyTracker?.beginMarkedContent(t);"OC"===e?this.markedContentStack.push({visible:this.optionalContentConfig.isVisible(s)}):this.markedContentStack.push({visible:!0});this.contentVisible=this.isContentVisible()}endMarkedContent(t){this.dependencyTracker?.endMarkedContent(t);this.markedContentStack.pop();this.contentVisible=this.isContentVisible()}beginCompat(t){}endCompat(t){}consumePath(t,e,s){const r=this.current.isEmptyClip();this.pendingClip&&this.current.updateClipFromPath();this.pendingClip||this.compose(s);const a=this.ctx;if(this.pendingClip){r||(this.pendingClip===Y?a.clip(e,"evenodd"):a.clip(e));this.pendingClip=null;this.dependencyTracker?.bboxToClipBoxDropOperation(t).recordFutureForcedDependency("clipPath",t)}else this.dependencyTracker?.recordOperation(t);this.current.startNewPathAndClipBox(this.current.clipBox)}getSinglePixelWidth(){const t=getCurrentTransform(this.ctx);if(0===t[1]&&0===t[2])return 1/Math.min(Math.abs(t[0]),Math.abs(t[3]));const e=Math.abs(t[0]*t[3]-t[2]*t[1]),s=Math.hypot(t[0],t[2]),r=Math.hypot(t[1],t[3]);return Math.max(s,r)/e}getScaleForStroking(){if(-1===this._cachedScaleForStroking[0]){const{lineWidth:t}=this.current,{a:e,b:s,c:r,d:a}=this.ctx.getTransform();let n,i;if(0===s&&0===r){const s=Math.abs(e),r=Math.abs(a);if(s===r)if(0===t)n=i=1/s;else{const e=s*t;n=i=e<1?1/e:1}else if(0===t){n=1/s;i=1/r}else{const e=s*t,a=r*t;n=e<1?1/e:1;i=a<1?1/a:1}}else{const o=Math.abs(e*a-s*r),c=Math.hypot(e,s),l=Math.hypot(r,a);if(0===t){n=l/o;i=c/o}else{const e=t*o;n=l>e?l/e:1;i=c>e?c/e:1}}this._cachedScaleForStroking[0]=n;this._cachedScaleForStroking[1]=i}return this._cachedScaleForStroking}rescaleAndStroke(t,e){const{ctx:s,current:{lineWidth:r}}=this,[a,n]=this.getScaleForStroking();if(a===n){s.lineWidth=(r||1)*a;s.stroke(t);return}const i=CanvasGraphics.#A??=new DOMMatrix,o=s.getLineDash();e&&s.save();s.scale(a,n);i.a=1/a;i.d=1/n;const c=new Path2D;c.addPath(t,i);if(o.length>0){const t=Math.max(a,n);s.setLineDash(o.map(e=>e/t));s.lineDashOffset/=t}s.lineWidth=r||1;s.stroke(c);e&&s.restore()}isContentVisible(){for(let t=this.markedContentStack.length-1;t>=0;t--)if(!this.markedContentStack[t].visible)return!1;return!0}}for(const t in x)void 0!==CanvasGraphics.prototype[t]&&(CanvasGraphics.prototype[x[t]]=CanvasGraphics.prototype[t]);const $=/\p{Cc}/u;function serializeFontFamily(t){if(function isCSSString(t){const e=t[0];if(t.length<2||'"'!==e&&"'"!==e||t.at(-1)!==e)return!1;const s=t.length-1;for(let r=1;r<s;r++){const a=t[r];if(a===e||$.test(a))return!1;if("\\"===a&&(++r>=s||$.test(t[r])))return!1}return!0}(t))return t;return`"${t.replaceAll(/["\\\p{Cc}]/gu,t=>'"'===t||"\\"===t?`\\${t}`:`\\${t.codePointAt(0).toString(16)} `)}"`}class FontLoader{#rt=new Set;#at=new Set;#nt=null;constructor({ownerDocument:t=globalThis.document,styleElement:e=null}){this._document=t;this.styleElement=null}addNativeFontFace(t){this.#rt.add(t);this._document.fonts.add(t)}removeNativeFontFace(t){this.#rt.delete(t);this._document.fonts.delete(t)}insertRule(t){throw new Error("Not implemented: insertRule")}#it(){throw new Error("Not implemented: #getStyleSheet")}clear(){for(const t of this.#rt)this._document.fonts.delete(t);this.#rt.clear();this.#at.clear()}async loadSystemFont({systemFontInfo:t,disableFontFace:e,_inspectFont:s}){if(t&&!this.#at.has(t.loadedName)){assert(!e,"loadSystemFont shouldn't be called when `disableFontFace` is set.");if(this.isFontLoadingAPISupported){const{loadedName:e,src:r,style:a}=t,n=new FontFace(e,r,a);this.addNativeFontFace(n);try{await n.load();this.#at.add(e);s?.(t)}catch{warn(`Cannot load system font: ${t.baseFontName}, installing it could help to improve PDF rendering.`);this.removeNativeFontFace(n)}return}unreachable("Not implemented: loadSystemFont without the Font Loading API.")}}async bind(t){if(!(t.attached||t.missingFile&&!t.systemFontInfo)){t.attached=!0;if(!t.systemFontInfo){if(this.isFontLoadingAPISupported){const e=t.createNativeFontFace();if(e){this.addNativeFontFace(e);try{await e.loaded}catch(s){warn(`Failed to load font '${e.family}': '${s}'.`);t.disableFontFace=!0;throw s}}return}throw new Error("Not implemented: DOM font loading")}await this.loadSystemFont(t)}}get isFontLoadingAPISupported(){return shadow(this,"isFontLoadingAPISupported",!!this._document?.fonts)}get isSyncFontLoadingSupported(){return shadow(this,"isSyncFontLoadingSupported",t||FeatureTest.platform.isFirefox)}#ot(t){throw new Error("Not implemented: #testFontLoaded")}}class FontFaceObject{#ct=new Map;#lt;constructor(t,e=null,s,r){this.#lt=t;this._inspectFont=e;s&&(this.charProcOperatorList=s);r&&Object.assign(this,r)}createNativeFontFace(){const{data:t}=this;if(!t||this.disableFontFace)return null;let e;if(this.cssFontInfo){const s={weight:this.cssFontInfo.fontWeight};this.cssFontInfo.italicAngle&&(s.style=`oblique ${this.cssFontInfo.italicAngle}deg`);e=new FontFace(serializeFontFamily(this.cssFontInfo.fontFamily),t,s)}else e=new FontFace(this.loadedName,t,{});this._inspectFont?.(this);return e}createFontFaceRule(){throw new Error("Not implemented: createFontFaceRule")}getPathGenerator(t,e){let s=this.#ct.get(e);if(s)return s;const r=`${this.loadedName}_path_${e}`;let a;try{a=t.get(r)}catch(t){warn(`getPathGenerator - ignoring character: "${t}".`)}s=makePathFromDrawOPS(a?.path);this.fontExtraProperties||t.delete(r);this.#ct.set(e,s);return s}get black(){return this.#lt.black}get bold(){return this.#lt.bold}get disableFontFace(){return this.#lt.disableFontFace}set disableFontFace(t){shadow(this,"disableFontFace",!!t)}get fontExtraProperties(){return this.#lt.fontExtraProperties}get isInvalidPDFjsFont(){return this.#lt.isInvalidPDFjsFont}get isType3Font(){return this.#lt.isType3Font}get italic(){return this.#lt.italic}get missingFile(){return this.#lt.missingFile}get remeasure(){return this.#lt.remeasure}get vertical(){return this.#lt.vertical}get bbox(){return this.#lt.bbox}get fontMatrix(){return this.#lt.fontMatrix}get fallbackName(){return this.#lt.fallbackName}get loadedName(){return this.#lt.loadedName}get mimetype(){return this.missingFile?null:"font/opentype"}get data(){return this.#lt.data}clearData(){this.#lt.clearData()}get cssFontInfo(){return this.#lt.cssFontInfo}get systemFontInfo(){return this.#lt.systemFontInfo}}const K=1,q=2,J=1,Z=2,Q=3,tt=4,et=5,st=6,rt=7,at=8;function onFn(){}function wrapReason(t){if(t instanceof AbortException||t instanceof InvalidPDFException||t instanceof PasswordException||t instanceof ResponseException||t instanceof UnknownErrorException)return t;if("object"!=typeof t||null===t)return new UnknownErrorException(String(t),String(t));switch(t.name){case"AbortException":return new AbortException(t.message);case"InvalidPDFException":return new InvalidPDFException(t.message);case"PasswordException":return new PasswordException(t.message,t.code);case"ResponseException":return new ResponseException(t.message,t.status,t.missing);case"UnknownErrorException":return new UnknownErrorException(t.message,t.details)}return new UnknownErrorException(t.message,t.toString())}class MessageHandler{#ht=new Map;#dt=new Map;#pt=1;#ut;#ft=new AbortController;#mt;#gt=new Map;#xt=1;#kt=new Map;#bt;constructor(t,e,s){this.#mt=t;this.#bt=e;this.#ut=s;s.addEventListener("message",this.#yt.bind(this),{signal:this.#ft.signal})}#yt({data:t}){if(t.targetName!==this.#mt)return;if(t.stream){this.#vt(t);return}if(t.callback){const{callbackId:e,callback:s}=t,r=this.#dt.get(e);if(!r)throw new Error(`Cannot resolve callback ${e}`);this.#dt.delete(e);if(s===K)r.resolve(t.data);else{if(s!==q)throw new Error("Unexpected callback case");r.reject(wrapReason(t.reason))}return}const e=this.#ht.get(t.action);if(!e)throw new Error(`Unknown action from worker: ${t.action}`);if(t.callbackId){const s=this.#mt,r=t.sourceName,a=this.#ut;Promise.try(e,t.data).then(e=>{a.postMessage({sourceName:s,targetName:r,callback:K,callbackId:t.callbackId,data:e})}).catch(e=>{a.postMessage({sourceName:s,targetName:r,callback:q,callbackId:t.callbackId,reason:wrapReason(e)})});return}t.streamId?this.#Ct(t):e(t.data)}on(t,e){const s=this.#ht;if(s.has(t))throw new Error(`There is already a "${t}" handler.`);s.set(t,e)}send(t,e,s){this.#ut.postMessage({sourceName:this.#mt,targetName:this.#bt,action:t,data:e},s)}sendWithPromise(t,e,s){const r=this.#pt++,a=Promise.withResolvers();this.#dt.set(r,a);try{this.#ut.postMessage({sourceName:this.#mt,targetName:this.#bt,action:t,callbackId:r,data:e},s)}catch(t){a.reject(t)}return a.promise}sendWithStream(t,e,s,r){const a=this.#xt++,n=this.#mt,i=this.#bt,o=this.#ut;return new ReadableStream({start:s=>{const c=Promise.withResolvers();this.#gt.set(a,{controller:s,startCall:c,pullCall:null,cancelCall:null,isClosed:!1});o.postMessage({sourceName:n,targetName:i,action:t,streamId:a,data:e,desiredSize:s.desiredSize},r);return c.promise},pull:t=>{const e=Promise.withResolvers();this.#gt.get(a).pullCall=e;o.postMessage({sourceName:n,targetName:i,stream:st,streamId:a,desiredSize:t.desiredSize});return e.promise},cancel:t=>{assert(t instanceof Error,"cancel must have a valid reason");const e=Promise.withResolvers();this.#gt.get(a).cancelCall=e;this.#gt.get(a).isClosed=!0;o.postMessage({sourceName:n,targetName:i,stream:J,streamId:a,reason:wrapReason(t)});return e.promise}},s)}#Ct(t){const e=t.streamId,s=this.#mt,r=t.sourceName,a=this.#ut,n=this.#kt,i=this.#ht.get(t.action),o={enqueue(t,n=1,i){if(this.isCancelled)return;const o=this.desiredSize;this.desiredSize-=n;if(o>0&&this.desiredSize<=0){this.sinkCapability=Promise.withResolvers();this.ready=this.sinkCapability.promise}a.postMessage({sourceName:s,targetName:r,stream:tt,streamId:e,chunk:t},i)},close(){if(!this.isCancelled){this.isCancelled=!0;a.postMessage({sourceName:s,targetName:r,stream:Q,streamId:e});n.delete(e)}},error(t){if(!this.isCancelled){this.isCancelled=!0;a.postMessage({sourceName:s,targetName:r,stream:et,streamId:e,reason:wrapReason(t)})}},sinkCapability:Promise.withResolvers(),onPull:null,onCancel:null,isCancelled:!1,desiredSize:t.desiredSize,ready:null};o.sinkCapability.resolve();o.ready=o.sinkCapability.promise;n.set(e,o);Promise.try(i,t.data,o).then(()=>{a.postMessage({sourceName:s,targetName:r,stream:at,streamId:e,success:!0})},t=>{a.postMessage({sourceName:s,targetName:r,stream:at,streamId:e,reason:wrapReason(t)})})}#vt(t){const e=t.streamId,s=this.#mt,r=t.sourceName,a=this.#ut,n=this.#gt.get(e),i=this.#kt.get(e);switch(t.stream){case at:t.success?n.startCall.resolve():n.startCall.reject(wrapReason(t.reason));break;case rt:t.success?n.pullCall.resolve():n.pullCall.reject(wrapReason(t.reason));break;case st:if(!i){a.postMessage({sourceName:s,targetName:r,stream:rt,streamId:e,success:!0});break}i.desiredSize<=0&&t.desiredSize>0&&i.sinkCapability.resolve();i.desiredSize=t.desiredSize;Promise.try(i.onPull||onFn).then(()=>{a.postMessage({sourceName:s,targetName:r,stream:rt,streamId:e,success:!0})},t=>{a.postMessage({sourceName:s,targetName:r,stream:rt,streamId:e,reason:wrapReason(t)})});break;case tt:assert(n,"enqueue should have stream controller");if(n.isClosed)break;n.controller.enqueue(t.chunk);break;case Q:assert(n,"close should have stream controller");if(n.isClosed)break;n.isClosed=!0;n.controller.close();this.#St(n,e);break;case et:assert(n,"error should have stream controller");n.controller.error(wrapReason(t.reason));this.#St(n,e);break;case Z:t.success?n.cancelCall.resolve():n.cancelCall.reject(wrapReason(t.reason));this.#St(n,e);break;case J:if(!i)break;const o=wrapReason(t.reason);Promise.try(i.onCancel||onFn,o).then(()=>{a.postMessage({sourceName:s,targetName:r,stream:Z,streamId:e,success:!0})},t=>{a.postMessage({sourceName:s,targetName:r,stream:Z,streamId:e,reason:wrapReason(t)})});i.sinkCapability.reject(o);i.isCancelled=!0;this.#kt.delete(e);break;default:throw new Error("Unexpected stream case")}}async#St(t,e){await Promise.allSettled([t.startCall?.promise,t.pullCall?.promise,t.cancelCall?.promise]);this.#gt.delete(e)}destroy(){this.#ft?.abort();this.#ft=null}get destroyed(){return!this.#ft}}class CSS_FONT_INFO{static strings=["fontFamily","fontWeight","italicAngle"]}class SYSTEM_FONT_INFO{static strings=["css","loadedName","baseFontName","src"]}class FONT_INFO{static bools=["black","bold","disableFontFace","fontExtraProperties","isInvalidPDFjsFont","isType3Font","italic","missingFile","remeasure","vertical"];static strings=["fallbackName","loadedName"];static OFFSET_BBOX=Math.ceil(2*this.bools.length/8);static OFFSET_FONT_MATRIX=this.OFFSET_BBOX+1+8;static OFFSET_STRINGS=this.OFFSET_FONT_MATRIX+1+48}class PATTERN_INFO{static KIND=0;static HAS_BBOX=1;static HAS_BACKGROUND=2;static SHADING_TYPE=3;static N_COORD=4;static N_COLOR=8;static N_STOP=12;static N_FIGURES=16}class InfoUtils{static get decoder(){return shadow(this,"decoder",new TextDecoder)}static get encoder(){return shadow(this,"encoder",new TextEncoder)}}function readString(t,e,s,r=0){const{decoder:a}=InfoUtils;for(let t=0;t<s;t++)r+=e.getUint32(r)+4;const n=e.getUint32(r);return a.decode(new Uint8Array(t,r+4,n))}class CssFontInfo{#Mt;#Tt;constructor(t){this.#Mt=t;this.#Tt=new DataView(t)}#Ft(t){assert(t<CSS_FONT_INFO.strings.length,"Invalid string index");return readString(this.#Mt,this.#Tt,t)}get fontFamily(){return shadow(this,"fontFamily",this.#Ft(0))}get fontWeight(){return shadow(this,"fontWeight",this.#Ft(1))}get italicAngle(){return shadow(this,"italicAngle",this.#Ft(2))}}class SystemFontInfo{#Mt;#Tt;constructor(t){this.#Mt=t;this.#Tt=new DataView(t)}#Ft(t){assert(t<SYSTEM_FONT_INFO.strings.length,"Invalid string index");return readString(this.#Mt,this.#Tt,t,4)}get css(){return shadow(this,"css",this.#Ft(0))}get loadedName(){return shadow(this,"loadedName",this.#Ft(1))}get baseFontName(){return shadow(this,"baseFontName",this.#Ft(2))}get src(){return shadow(this,"src",this.#Ft(3))}get style(){let t=0;t+=4+this.#Tt.getUint32(t);return shadow(this,"style",{style:readString(this.#Mt,this.#Tt,0,t),weight:readString(this.#Mt,this.#Tt,1,t)})}}class FontInfo{#Mt;#Tt;constructor(t){this.#Mt=t;this.#Tt=new DataView(t)}#wt(t){assert(t<FONT_INFO.bools.length,"Invalid boolean index");const e=Math.floor(t/4),s=2*t%8,r=this.#Tt.getUint8(e)>>s&3;return 0===r?void 0:2===r}get black(){return shadow(this,"black",this.#wt(0))}get bold(){return shadow(this,"bold",this.#wt(1))}get disableFontFace(){return shadow(this,"disableFontFace",this.#wt(2))}get fontExtraProperties(){return shadow(this,"fontExtraProperties",this.#wt(3))}get isInvalidPDFjsFont(){return shadow(this,"isInvalidPDFjsFont",this.#wt(4))}get isType3Font(){return shadow(this,"isType3Font",this.#wt(5))}get italic(){return shadow(this,"italic",this.#wt(6))}get missingFile(){return shadow(this,"missingFile",this.#wt(7))}get remeasure(){return shadow(this,"remeasure",this.#wt(8))}get vertical(){return shadow(this,"vertical",this.#wt(9))}#Bt(t,e,s,r){const a=this.#Tt.getUint8(t++);if(0===a)return;assert(a===e,"Invalid array length.");const n=new Array(a);for(let e=0;e<a;e++){n[e]=this.#Tt[s](t,!0);t+=r}return n}get bbox(){return shadow(this,"bbox",this.#Bt(FONT_INFO.OFFSET_BBOX,4,"getInt16",2))}get fontMatrix(){return shadow(this,"fontMatrix",this.#Bt(FONT_INFO.OFFSET_FONT_MATRIX,6,"getFloat64",8))}#Ft(t){assert(t<FONT_INFO.strings.length,"Invalid string index");return readString(this.#Mt,this.#Tt,t,FONT_INFO.OFFSET_STRINGS+4)}get fallbackName(){return shadow(this,"fallbackName",this.#Ft(0))}get loadedName(){return shadow(this,"loadedName",this.#Ft(1))}#It(t){let e=FONT_INFO.OFFSET_STRINGS;for(let s=0;s<=t;s++)e+=4+this.#Tt.getUint32(e);return{offset:e,length:this.#Tt.getUint32(e)}}get data(){const{offset:t,length:e}=this.#It(2);return e?new Uint8Array(this.#Mt,t+4,e):void 0}clearData(){const{offset:t,length:e}=this.#It(2);if(e){this.#Tt.setUint32(t,0);this.#Mt=new Uint8Array(this.#Mt,0,t+4).slice().buffer;this.#Tt=new DataView(this.#Mt)}}get cssFontInfo(){const{offset:t,length:e}=this.#It(1);let s=null;if(e){const r=new Uint8Array(this.#Mt,t+4,e).slice();s=new CssFontInfo(r.buffer)}return shadow(this,"cssFontInfo",s)}get systemFontInfo(){const{offset:t,length:e}=this.#It(0);let s=null;if(e){const r=new Uint8Array(this.#Mt,t+4,e).slice();s=new SystemFontInfo(r.buffer)}return shadow(this,"systemFontInfo",s)}}class PatternInfo{constructor(t){this.buffer=t;this.view=new DataView(t);this.data=new Uint8Array(t)}getIR(){const t=this.view,s=this.data[PATTERN_INFO.KIND],r=!!this.data[PATTERN_INFO.HAS_BBOX],a=!!this.data[PATTERN_INFO.HAS_BACKGROUND],n=t.getUint32(PATTERN_INFO.N_COORD,!0),i=t.getUint32(PATTERN_INFO.N_COLOR,!0),o=t.getUint32(PATTERN_INFO.N_STOP,!0);let c=20;const l=new Float32Array(this.buffer,c,2*n);c+=8*n;const h=new Uint8Array(this.buffer,c,4*i);c+=4*i;const d=[];for(let e=0;e<o;++e){const e=t.getFloat32(c,!0);c+=4;const s=t.getUint32(c,!0);c+=4;d.push([e,`#${s.toString(16).padStart(6,"0")}`])}let p=null;if(r){p=[];for(let e=0;e<4;++e){p.push(t.getFloat32(c,!0));c+=4}}let u=null;if(a){u=new Uint8Array(this.buffer,c,3);c+=3}if(1===s)return["RadialAxial","axial",p,d,[l[0],l[1]],[l[2],l[3]],null,null];if(2===s)return["RadialAxial","radial",p,d,[l[0],l[1]],[l[3],l[4]],l[2],l[5]];if(3===s){const t=this.data[PATTERN_INFO.SHADING_TYPE];let s=null;if(l.length>0){s=e.slice();for(let t=0,e=l.length;t<e;t+=2)Util.pointBoundingBox(l[t],l[t+1],s)}return["Mesh",t,l,h,n,s,p,u]}throw new Error(`Unsupported pattern kind: ${s}`)}}class FontPathInfo{#Mt;constructor(t){this.#Mt=t}get path(){return FeatureTest.isFloat16ArraySupported?new Float16Array(this.#Mt):new Float32Array(this.#Mt)}}const nt=Symbol("INITIAL_DATA"),dataObj=()=>({...Promise.withResolvers(),data:nt});class PDFObjects{#Ot=new Map;get(t,e=null,s=null){if(e){const r=this.#Ot.getOrInsertComputed(t,dataObj);r.promise.then(()=>e(r.data),s);return null}const r=this.#Ot.get(t);if(!r||r.data===nt)throw new Error(`Requesting object that isn't resolved yet ${t}.`);return r.data}has(t){const e=this.#Ot.get(t);return!!e&&e.data!==nt}delete(t){const e=this.#Ot.get(t);if(!e||e.data===nt)return!1;this.#Ot.delete(t);return!0}resolve(t,e=null){const s=this.#Ot.getOrInsertComputed(t,dataObj);if(s.data!==nt)throw new Error(`Object already resolved ${t}.`);s.data=e;s.resolve()}reject(t,e){const s=this.#Ot.getOrInsertComputed(t,dataObj);if(s.data===nt){s.promise.catch(()=>{});s.reject(e)}}clear(){for(const{data:t}of this.#Ot.values())t?.bitmap?.close();this.#Ot.clear()}*[Symbol.iterator](){for(const[t,{data:e}]of this.#Ot)e!==nt&&(yield[t,e])}}class ObjectHandler{constructor({messageHandler:t,commonObjs:e,fontLoader:s,pageCache:r,pdfBug:a=!1,shouldCreatePageObjs:n=!1}){this.messageHandler=t;this.commonObjs=e;this.fontLoader=s;this.pageCache=r;this.pdfBug=a;this.shouldCreatePageObjs=n}resolveCommonObject(t,e,s){if("CopyLocalImage"===e){const{imageRef:e}=s;assert(e,"The imageRef must be defined.");for(const s of this.pageCache.values()){const r=s.objs||s;for(const[,s]of r){if(s?.ref!==e)continue;if(!s.dataLen)return null;const r=structuredClone(s);this.commonObjs.resolve(t,r);return s.dataLen}}return null}switch(e){case"Font":if("error"in s){const e=s.error;warn(`Error during font loading: ${e}`);this.commonObjs.resolve(t,e);break}const r=new FontInfo(s.buffer),a=new FontFaceObject(r,null,s.charProcOperatorList,s.extra);this.fontLoader.bind(a).catch(()=>this.messageHandler.sendWithPromise("FontFallback",{id:t}).catch(e=>{warn(`FontFallback failed for "${t}": ${e}`)})).finally(()=>{a.fontExtraProperties||a.clearData();this.commonObjs.resolve(t,a)});break;case"FontPath":this.commonObjs.resolve(t,new FontPathInfo(s));break;case"Image":this.commonObjs.resolve(t,s);break;case"Pattern":const n=new PatternInfo(s);this.commonObjs.resolve(t,n.getIR());break;default:throw new Error(`Got unknown common object type ${e}`)}return null}resolveObject(t,e,s,r){let a=this.pageCache.get(e);if(!a){if(!this.shouldCreatePageObjs)return!1;a=new PDFObjects;this.pageCache.set(e,a)}const n=a.objs||a;if(n.has(t))return!1;if(0===a._intentStates?.size){r?.bitmap?.close();return!1}switch(s){case"Image":case"Pattern":n.resolve(t,r);return!0;default:throw new Error(`Got unknown object type ${s}`)}}}class BaseCanvasFactory{#Dt=!1;constructor({enableHWA:t=!1}){this.#Dt=t}create(t,e){if(t<=0||e<=0)throw new Error("Invalid canvas size");const s=this._createCanvas(t,e);return{canvas:s,context:s.getContext("2d",{willReadFrequently:!this.#Dt})}}reset({canvas:t},e,s){if(!t)throw new Error("Canvas is not specified");if(e<=0||s<=0)throw new Error("Invalid canvas size");t.width=e;t.height=s}destroy(t){const{canvas:e}=t;if(!e)throw new Error("Canvas is not specified");e.width=e.height=0;t.canvas=null;t.context=null}getNoAlphaContext(t){return t.getContext("2d",{alpha:!1,willReadFrequently:!this.#Dt})}_createCanvas(t,e){unreachable("Abstract method `_createCanvas` called.")}}class OffscreenCanvasFactory extends BaseCanvasFactory{_createCanvas(t,e){return new OffscreenCanvas(t,e)}}const it=3285377520,ot=4294901760,ct=65535;class MurmurHash3_64{constructor(t){this.h1=t?4294967295&t:it;this.h2=t?4294967295&t:it}update(t){let e,s;if("string"==typeof t){e=new Uint8Array(2*t.length);s=0;for(let r=0,a=t.length;r<a;r++){const a=t.charCodeAt(r);if(a<=255)e[s++]=a;else{e[s++]=a>>>8;e[s++]=255&a}}}else{if(!ArrayBuffer.isView(t))throw new Error("Invalid data format, must be a string or TypedArray.");e=t.slice();s=e.byteLength}const r=s>>2,a=s-4*r,n=new Uint32Array(e.buffer,0,r);let i=0,o=0,c=this.h1,l=this.h2;const h=3432918353,d=461845907,p=11601,u=13715;for(let t=0;t<r;t++)if(1&t){i=n[t];i=i*h&ot|i*p&ct;i=i<<15|i>>>17;i=i*d&ot|i*u&ct;c^=i;c=c<<13|c>>>19;c=5*c+3864292196}else{o=n[t];o=o*h&ot|o*p&ct;o=o<<15|o>>>17;o=o*d&ot|o*u&ct;l^=o;l=l<<13|l>>>19;l=5*l+3864292196}i=0;switch(a){case 3:i^=e[4*r+2]<<16;case 2:i^=e[4*r+1]<<8;case 1:i^=e[4*r];i=i*h&ot|i*p&ct;i=i<<15|i>>>17;i=i*d&ot|i*u&ct;1&r?c^=i:l^=i}this.h1=c;this.h2=l}hexdigest(){let t=this.h1,e=this.h2;t^=e>>>1;t=3981806797*t&ot|36045*t&ct;e=4283543511*e&ot|(2950163797*(e<<16|t>>>16)&ot)>>>16;t^=e>>>1;t=444984403*t&ot|60499*t&ct;e=3301882366*e&ot|(3120437893*(e<<16|t>>>16)&ot)>>>16;t^=e>>>1;return(t>>>0).toString(16).padStart(8,"0")+(e>>>0).toString(16).padStart(8,"0")}}const lt=Symbol("INTERNAL");class OptionalContentGroup{#Pt=!1;#At=!1;#_t=!1;#Et=!0;constructor(t,{name:e,intent:s,usage:r,rbGroups:i}){this.#Pt=!!(t&a);this.#At=!!(t&n);this.name=e;this.intent=s;this.usage=r;this.rbGroups=i}get visible(){if(this.#_t)return this.#Et;if(!this.#Et)return!1;const{print:t,view:e}=this.usage;return this.#Pt?"OFF"!==e?.viewState:!this.#At||"OFF"!==t?.printState}_setVisible(t,e,s=!1){t!==lt&&unreachable("Internal method `_setVisible` called.");this.#_t=s;this.#Et=e}get serializable(){return{userSet:this.#_t,visible:this.#Et}}}class OptionalContentConfig{#Nt=null;#Rt=new Map;#Lt=null;#Ut=null;#jt;creator=null;name=null;constructor(t,e=a,s=null){this.#jt=t;this.renderingIntent=e;if(null!==t){this.name=t.name;this.creator=t.creator;this.#Ut=t.order;for(const s of t.groups)this.#Rt.set(s.id,new OptionalContentGroup(e,s));if(s){s.size!==this.#Rt.size&&unreachable("Incorrect serialized groupState.");for(const[t,e]of s)this.#Rt.get(t)._setVisible(lt,e.visible,e.userSet)}else{if("OFF"===t.baseState)for(const t of this.#Rt.values())t._setVisible(lt,!1);for(const e of t.on)this.#Rt.get(e)._setVisible(lt,!0);for(const e of t.off)this.#Rt.get(e)._setVisible(lt,!1)}this.#Lt=this.getHash()}}#Gt(t){const e=t.length;if(e<2)return!0;const s=t[0];for(let r=1;r<e;r++){const e=t[r];let a;if(Array.isArray(e))a=this.#Gt(e);else{if(!this.#Rt.has(e)){warn(`Optional content group not found: ${e}`);return!0}a=this.#Rt.get(e).visible}switch(s){case"And":if(!a)return!1;break;case"Or":if(a)return!0;break;case"Not":return!a;default:return!0}}return"And"===s}isVisible(t){if(0===this.#Rt.size)return!0;if(!t){info("Optional content group not defined.");return!0}if("OCG"===t.type){if(!this.#Rt.has(t.id)){warn(`Optional content group not found: ${t.id}`);return!0}return this.#Rt.get(t.id).visible}if("OCMD"===t.type){if(t.expression)return this.#Gt(t.expression);if(!t.policy||"AnyOn"===t.policy){for(const e of t.ids){if(!this.#Rt.has(e)){warn(`Optional content group not found: ${e}`);return!0}if(this.#Rt.get(e).visible)return!0}return!1}if("AllOn"===t.policy){for(const e of t.ids){if(!this.#Rt.has(e)){warn(`Optional content group not found: ${e}`);return!0}if(!this.#Rt.get(e).visible)return!1}return!0}if("AnyOff"===t.policy){for(const e of t.ids){if(!this.#Rt.has(e)){warn(`Optional content group not found: ${e}`);return!0}if(!this.#Rt.get(e).visible)return!0}return!1}if("AllOff"===t.policy){for(const e of t.ids){if(!this.#Rt.has(e)){warn(`Optional content group not found: ${e}`);return!0}if(this.#Rt.get(e).visible)return!1}return!0}warn(`Unknown optional content policy ${t.policy}.`);return!0}warn(`Unknown group type ${t.type}.`);return!0}setVisibility(t,e=!0,s=!0){throw new Error("Not implemented: setVisibility")}setOCGState({state:t,preserveRB:e}){throw new Error("Not implemented: setOCGState")}get hasInitialVisibility(){return null===this.#Lt||this.getHash()===this.#Lt}getOrder(){throw new Error("Not implemented: getOrder")}getGroup(t){return this.#Rt.get(t)||null}getHash(){if(null!==this.#Nt)return this.#Nt;const t=new MurmurHash3_64;for(const[e,s]of this.#Rt)t.update(`${e}:${s.visible}`);return this.#Nt=t.hexdigest()}[Symbol.iterator](){return this.#Rt.entries()}get serializable(){const t=new Map;for(const[e,s]of this.#Rt)t.set(e,s.serializable);return{data:this.#jt,renderingIntent:this.renderingIntent,groupState:t}}static fromSerializable({data:t,renderingIntent:e,groupState:s}){return new OptionalContentConfig(t,e,s)}}class BaseFilterFactory{addFilter(t){return"none"}addHCMFilter(t,e){return"none"}addAlphaFilter(t){return"none"}addLuminosityFilter(t){return"none"}addKnockoutFilter(t=0){return"none"}addHighlightHCMFilter(t,e,s,r,a){return"none"}addSelectionHCMFilter(t,e){return"none"}addSelectionFilter(){return"none"}createSelectionStyle(t=null){return null}destroy(t=!1){}}class WorkerFilterFactory extends BaseFilterFactory{}class RendererMessageHandler{static#Wt;static#Xt=new PDFObjects;static#Ht=null;static#Dt=!1;static#Vt=!1;static#zt;static#Yt=new FontLoader({ownerDocument:globalThis});static#$t=!1;static#Kt=new Map;static#qt=new Map;static#Jt=new Map;static#Zt=null;static#Qt=[];static{"undefined"==typeof window&&!t&&"undefined"!=typeof self&&"function"==typeof self.postMessage&&"onmessage"in self&&this.#te(self)}static#ee(t){return this.#Kt.getOrInsertComputed(t,()=>new PDFObjects)}static#se(t,e){return this.#qt.getOrInsertComputed(t,makeMap).getOrInsertComputed(e,()=>({fnArray:[],argsArray:[],pathCache:new Map}))}static#re(t,e){const s=t.gfx?.annotationCanvasMap;if(!s?.size)return null;const r=[];for(const[t,a]of s)for(const s of Array.isArray(a)?a:[a]){const a=s.transferToImageBitmap();r.push([t,getAnnotationCanvasName(s),a]);e.push(a)}return r}static async#ae(t,e,s){const{canvas:r,renderTaskId:a}=e;let n=null;if(0===r.width||0===r.height){if(!s)return}else if(s)n=r.transferToImageBitmap();else{const{transparentCanvas:t}=e.gfx;if(t){const e=new OffscreenCanvas(r.width,r.height),s=e.getContext("2d");s.drawImage(r,0,0);s.drawImage(t,0,0);n=e.transferToImageBitmap();e.width=e.height=0}else{n=await createImageBitmap(r);if(e.aborted){n.close();return}}}const i=n?[n]:[],o=s?this.#re(e,i):null;t.send("RenderFrame",{renderTaskId:a,bitmap:n,annotationBitmaps:o},i)}static async#ne(t,e){if(!(!e.partialFrames||e.aborted||Date.now()-e.lastFrameTime<500||e.operatorListIdx===e.lastFrameIdx)){try{await this.#ae(t,e,!1)}catch(t){warn(`Failed to send an interim frame: ${t.message}`)}e.lastFrameTime=Date.now();e.lastFrameIdx=e.operatorListIdx}}static#ie(t){this.#Kt.get(t)?.clear();this.#Kt.delete(t);this.#qt.delete(t);for(const[e,s]of this.#Jt)s.pageProxyId===t&&this.#oe(e)}static#oe(t,e=!1){const s=this.#Jt.get(t);if(s){s.aborted=!0;s.continueResolve?.();s.gfx?.endDrawing();e||this.#ce(s);this.#Jt.delete(t)}}static#ce({canvas:t,gfx:e}){t.width=t.height=0;const s=e?.annotationCanvasMap;if(s){for(const t of s.values())for(const e of Array.isArray(t)?t:[t])e.width=e.height=0;s.clear()}}static#le(t,e,s,r){const{operatorList:a,sharedOperatorList:n}=t,{fnArray:i,argsArray:o}=n;for(let t=a.fnArray.length;t<e;t++){a.fnArray.push(i[t]);a.argsArray.push(o[t])}if(s){const e=t.operationsFilterMask||=[];for(let t=0,r=s.length;t<r;t++)e.push(s[t])}a.lastChunk=r;t.dependencyTracker?.growOperationsCount(a.fnArray.length)}static async#he(t,e){const{operatorList:s,gfx:r,operationsFilterMask:a}=e,n=a?t=>a[t]:null;for(;!e.aborted;){const{promise:a,resolve:i,reject:o}=Promise.withResolvers();e.continueResolve=i;e.operatorListIdx=r.executeOperatorList(s,e.operatorListIdx,i,o,void 0,n);if(e.operatorListIdx===s.argsArray.length)return e.operatorListIdx;await this.#ne(t,e);await a;if(e.aborted)break;await this.#de()}return e.operatorListIdx}static#de(){if(!this.#Zt){this.#Zt=new MessageChannel;this.#Zt.port1.onmessage=()=>{this.#Qt.shift()()}}const{promise:t,resolve:e}=Promise.withResolvers();this.#Qt.push(e);this.#Zt.port2.postMessage(null);return t}static#pe(t){const e=new ObjectHandler({messageHandler:t,commonObjs:this.#Xt,fontLoader:this.#Yt,pageCache:this.#Kt,shouldCreatePageObjs:!0});t.on("commonobj",([t,s,r])=>{if(!this.#Xt.has(t)){e.resolveCommonObject(t,s,r);"Pattern"===s&&"Mesh"===this.#Xt.get(t)[0]&&(this.#$t=!0)}});t.on("obj",([t,s,r,a])=>{"Pattern"===r&&"Mesh"===a[0]&&(this.#$t=!0);e.resolveObject(t,s,r,a)});t.on("objFailed",({id:t,pageProxyId:e,reason:s})=>{const r=new Error(s);null!==e?this.#ee(e).reject(t,r):this.#Xt.reject(t,r)})}static#ue(t){t.on("configure",t=>{!function setVerbosityLevel(t){Number.isInteger(t)&&(S=t)}(t.verbosity);this.#Dt=t.enableHWA;this.#Vt=t.enableWebGPU;this.#Vt&&initGPU()});this.#pe(t);t.on("cleanupPage",({pageProxyId:t})=>{this.#ie(t)});t.on("Cleanup",({keepLoadedFonts:t})=>{this.#Xt.clear();t||this.#Yt.clear();this.#zt?.destroy(!0)});t.on("CleanupRenderTask",({renderTaskId:t})=>{this.#oe(t)});t.on("AppendOperatorList",({pageProxyId:t,operatorListId:e,fnArray:s,argsArray:r})=>{const a=this.#se(t,e);for(let t=0,e=s.length;t<e;t++){a.fnArray.push(s[t]);a.argsArray.push(r[t])}});t.on("InitializeGraphics",async t=>{const{width:e,height:s,pageProxyId:r,operatorListId:a,renderTaskId:n,hasAnnotationCanvasMap:i=!1,transform:o,viewport:c,transparency:l,background:h,pixelRatio:d,recordOperations:p=!1,recordImages:u=!1,partialFrames:f=!1}=t,m=new OffscreenCanvas(e,s),g=this.#se(r,a),x={pageProxyId:r,renderTaskId:n,canvas:m,partialFrames:f,lastFrameTime:Date.now(),gfx:null,sharedOperatorList:g,dependencyTracker:null,imagesTracker:null,operatorList:{fnArray:[],argsArray:[],lastChunk:!1,pathCache:g.pathCache},operatorListIdx:0,lastFrameIdx:0,operationsFilterMask:null,continueResolve:null,aborted:!1};this.#Jt.set(n,x);try{const e=this.#ee(r),s=OptionalContentConfig.fromSerializable(t.optionalContentConfig),a=this.#Wt??=new OffscreenCanvasFactory({enableHWA:this.#Dt}),n=this.#zt??=new WorkerFilterFactory,f=i?new Map:null,{dependencyTracker:g,imagesTracker:k}=function createCanvasTrackers(t,e,{recordOperations:s=!1,recordImages:r=!1,recordDebugMetadata:a=!1}){const n=s||r?new CanvasBBoxTracker(t,e):null;return{dependencyTracker:s?new CanvasDependencyTracker(n,a):n,imagesTracker:r?new CanvasImagesTracker(t):null}}(m,0,{recordOperations:p,recordImages:u}),b=new CanvasGraphics(a.getNoAlphaContext(m),this.#Xt,e,a,n,{optionalContentConfig:s,pixelRatio:d},f,null,g,k);b.beginDrawing({transform:o,viewport:c,transparency:l,background:h});x.gfx=b;x.dependencyTracker=g;x.imagesTracker=k}catch(t){this.#oe(n);throw t}});t.on("ExecuteOperatorList",async e=>{const{renderTaskId:s,operatorListIdx:r,operatorListLength:a,operationsFilterMask:n,lastChunk:i}=e,o=this.#Jt.get(s);if(!o)return{operatorListIdx:r,aborted:!0};if(this.#$t&&this.#Vt&&!isGPUReady()){await initGPU();if(o.aborted)return{operatorListIdx:r,aborted:!0}}o.operatorListIdx=r;this.#le(o,a,n,i);const c=await this.#he(t,o);let l=null,h=null;if(o.operatorList.lastChunk&&c===o.operatorList.argsArray.length){l=o.dependencyTracker?.take().buffer??null;h=o.imagesTracker?.take()??null;const e=o.aborted;this.#oe(s,!e);if(!e)try{await this.#ae(t,o,!0)}finally{this.#ce(o)}}else await this.#ne(t,o);return{operatorListIdx:c,recordedBBoxesBuffer:l,imageCoordinates:h}})}static#te(t){const e=new MessageHandler("renderer","main",t);this.#ue(e);e.on("Connect",({sourceName:e,targetName:s})=>{this.#fe();const r=new MessageHandler(e,s,t);this.#Ht=r;this.#ue(r);r.on("Disconnect",()=>{this.#fe()});this.#me(r)});this.#me(e)}static#fe(){if(this.#Ht){for(const t of this.#Jt.keys())this.#oe(t);for(const t of this.#Kt.values())t.clear();this.#Kt.clear();this.#qt.clear();this.#$t=!1;this.#Xt.clear();this.#Yt.clear();this.#Xt=new PDFObjects;this.#Yt=new FontLoader({ownerDocument:globalThis});this.#Wt=null;this.#zt?.destroy();this.#zt=null;this.#Ht.send("Disconnected",null);this.#Ht.destroy();this.#Ht=null}}static#me(t){const e=new Uint8Array;t.send("ready",{testObj:e,workerVersion:"6.5.438"},[e.buffer])}}