@hintergrund/ui 0.3.22 → 0.3.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AssistantPane-CrhAF8vt.js +1 -0
- package/dist/LanguageSelect-C69aKyBG.js +1 -0
- package/dist/{Mail-DhK-KMwR.js → Mail-Bo10s7fg.js} +1 -1
- package/dist/admin.js +2 -2
- package/dist/anthropic-messages-DHRZKE7x.js +2 -0
- package/dist/builder.js +1 -1
- package/dist/github-copilot-headers-CdUV5uSi.js +1 -0
- package/dist/global-BYAZ22F2.js +2 -0
- package/dist/google-generative-ai-C7j3x2d1.js +1 -0
- package/dist/{invoice-pdf-iWI1Ooo_.js → invoice-pdf-C9HTjgW9.js} +1 -1
- package/dist/lib-BhXMDVcn.js +2 -0
- package/dist/login.js +1 -1
- package/dist/mail.js +1 -1
- package/dist/{node.browser-B4qizDL5.js → node.browser-Aw6ESngp.js} +1 -1
- package/dist/{node.browser-B_jD99R9.js → node.browser-CWS7vASg.js} +1 -1
- package/dist/openai-completions-DVZ6Lev9.js +1 -0
- package/dist/openai-decisions-DOdKbisO.js +1 -0
- package/dist/{openai-prompt-cache-C4mUbgCW.js → openai-prompt-cache-C2HSF10I.js} +1 -1
- package/dist/openai-responses-DiTwJ3a8.js +1 -0
- package/dist/openrouter-cost-BcsrXcCZ.js +1 -0
- package/dist/pdf-qgbK-GBD.js +1 -0
- package/dist/pdf.worker.min-CTKKiybZ.js +1 -0
- package/dist/provider-retry-B2k3qccC.js +1 -0
- package/dist/rolldown-runtime-WNHmnFyz.js +1 -0
- package/dist/transform-messages-K0xRLnN6.js +1 -0
- package/package.json +6 -4
- package/dist/AssistantPane-CsTLAgrN.js +0 -1
- package/dist/LanguageSelect-Cw-04J1T.js +0 -1
- package/dist/anthropic-messages-0y1ije7D.js +0 -2
- package/dist/error-body-B13t5xBI.js +0 -1
- package/dist/github-copilot-headers-EfqOaQ0F.js +0 -1
- package/dist/global-DnEot-gX.js +0 -2
- package/dist/google-generative-ai-CFJABM_3.js +0 -1
- package/dist/openai-completions-COWzYlMI.js +0 -1
- package/dist/openai-decisions-CRaIYbAt.js +0 -1
- package/dist/openai-responses-BMenrERi.js +0 -1
- package/dist/provider-retry-DNH2SSUZ.js +0 -1
- package/dist/rolldown-runtime-9urLBz53.js +0 -1
- package/dist/transform-messages-D8-i_dD2.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
void 0===globalThis.process&&(globalThis.process={env:{},platform:"browser",version:"",versions:{},browser:!0,nextTick:function(t){return Promise.resolve().then(t)}});var 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],i=new Float32Array(e),s=[.001,0,0,.001,0,0],n="http://www.w3.org/2000/svg",r={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},a="pdfjs_internal_id_",o="pdfjs_internal_editor_",l={DISABLE:-1,NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15,POPUP:16,SIGNATURE:101,COMMENT:102},h={RESIZE:1,CREATE:2,FREETEXT_SIZE:11,FREETEXT_COLOR:12,FREETEXT_OPACITY:13,INK_COLOR:21,INK_THICKNESS:22,INK_OPACITY:23,INK_COLOR_AND_OPACITY:24,HIGHLIGHT_COLOR:31,HIGHLIGHT_THICKNESS:32,HIGHLIGHT_FREE:33,HIGHLIGHT_SHOW_ALL:34,DRAW_STEP:41},c={PRINT:4,MODIFY_CONTENTS:8,COPY:16,MODIFY_ANNOTATIONS:32,FILL_INTERACTIVE_FORMS:256,COPY_FOR_ACCESSIBILITY:512,ASSEMBLE:1024,PRINT_HIGH_QUALITY:2048},d={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},u={TEXT:1,LINK:2,FREETEXT:3,LINE:4,SQUARE:5,CIRCLE:6,POLYGON:7,POLYLINE:8,HIGHLIGHT:9,UNDERLINE:10,SQUIGGLY:11,STRIKEOUT:12,STAMP:13,CARET:14,INK:15,POPUP:16,FILEATTACHMENT:17,SOUND:18,MOVIE:19,WIDGET:20,SCREEN:21,PRINTERMARK:22,TRAPNET:23,WATERMARK:24,THREED:25,REDACT:26,RICHMEDIA:27},p={ERRORS:0,WARNINGS:1,INFOS:5},g={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},m={NEED_PASSWORD:1,INCORRECT_PASSWORD:2},f=p.WARNINGS;function b(t){Number.isInteger(t)&&(f=t)}function y(){return f}function v(t){}function w(t){throw new Error(t)}function A(t,e){t||w(e)}function x(t,e=null,i=null){if(!t)return null;if(i&&"string"==typeof t&&(i.addDefaultProtocol&&t.startsWith("www.")&&t.match(/\./g)?.length>=2&&(t=`http://${t}`),i.tryConvertEncoding))try{t=decodeURIComponent(escape(t))}catch{}const s=e?URL.parse(t,e):URL.parse(t);return function(t){switch(t?.protocol){case"http:":case"https:":case"ftp:":case"mailto:":case"tel:":return!0;default:return!1}}(s)?s:null}function C(t,e,i=!1){const s=URL.parse(t);return s?(s.hash=e,s.href):i&&x(t,"http://example.com")?t.split("#",1)[0]+""+(e?`#${e}`:""):""}function S(t){return t.substring(t.lastIndexOf("/")+1)}function T(t,e,i,s=!1){return Object.defineProperty(t,e,{value:i,enumerable:!s,configurable:!0,writable:!1}),i}var _=function(){function t(t,e){this.message=t,this.name=e}return t.prototype=/* @__PURE__ */new Error,t.constructor=t,t}(),k=class extends _{constructor(t,e){super(t,"PasswordException"),this.code=e}},E=class extends _{constructor(t,e){super(t,"UnknownErrorException"),this.details=e}},M=class extends _{constructor(t){super(t,"InvalidPDFException")}},P=class extends _{constructor(t,e,i){super(t,"ResponseException"),this.status=e,this.missing=i}},D=class extends _{constructor(t){super(t,"FormatError")}},I=class extends _{constructor(t){super(t,"AbortException")}};function F(t){"string"!=typeof t&&w("Invalid argument for stringToBytes");const e=t.length,i=new Uint8Array(e);for(let s=0;s<e;++s)i[s]=255&t.charCodeAt(s);return i}var L=class{static get isLittleEndian(){const t=/* @__PURE__ */new Uint8Array(4);return t[0]=1,T(this,"isLittleEndian",1===new Uint32Array(t.buffer,0,1)[0])}static get isOffscreenCanvasSupported(){return T(this,"isOffscreenCanvasSupported","undefined"!=typeof OffscreenCanvas)}static get isImageDecoderSupported(){return T(this,"isImageDecoderSupported","undefined"!=typeof ImageDecoder)}static get isVideoFrameSupported(){return T(this,"isVideoFrameSupported","undefined"!=typeof VideoFrame)}static get isFloat16ArraySupported(){return T(this,"isFloat16ArraySupported","undefined"!=typeof Float16Array)}static get isSanitizerSupported(){return T(this,"isSanitizerSupported","undefined"!=typeof Sanitizer)}static get platform(){const{platform:t,userAgent:e}=navigator;return T(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;return this.isOffscreenCanvasSupported?t=new OffscreenCanvas(1,1).getContext("2d"):"undefined"!=typeof document&&(t=document.createElement("canvas").getContext("2d")),T(this,"isCanvasFilterSupported",void 0!==t?.filter)}static get isAlphaColorInputSupported(){if("undefined"==typeof document)return T(this,"isAlphaColorInputSupported",!1);const t=document.createElement("input");return t.type="color",t.setAttribute("alpha",""),t.value="#ff000080",T(this,"isAlphaColorInputSupported","#ff0000"!==t.value)}static get isBackdropFilterSupported(){return T(this,"isBackdropFilterSupported","undefined"!=typeof CSS&&CSS.supports("backdrop-filter","blur(1px)"))}},B=class{static get hexNums(){return T(this,"hexNums",Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0")))}static makeHexColor(t,e,i){return`#${this.hexNums[t]}${this.hexNums[e]}${this.hexNums[i]}`}static get identity0to256Map(){return T(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,i=0){const s=t[i],n=t[i+1];t[i]=s*e[0]+n*e[2]+e[4],t[i+1]=s*e[1]+n*e[3]+e[5]}static applyTransformToBezier(t,e,i=0){const s=e[0],n=e[1],r=e[2],a=e[3],o=e[4],l=e[5];for(let h=0;h<6;h+=2){const e=t[i+h],c=t[i+h+1];t[i+h]=e*s+c*r+o,t[i+h+1]=e*n+c*a+l}}static applyInverseTransform(t,e){const i=t[0],s=t[1],n=e[0]*e[3]-e[1]*e[2];t[0]=(i*e[3]-s*e[2]+e[2]*e[5]-e[4]*e[3])/n,t[1]=(-i*e[1]+s*e[0]+e[4]*e[1]-e[5]*e[0])/n}static axialAlignedBoundingBox(t,e,i){const s=e[0],n=e[1],r=e[2],a=e[3],o=e[4],l=e[5],h=t[0],c=t[1],d=t[2],u=t[3];let p=s*h+o,g=p,m=s*d+o,f=m,b=a*c+l,y=b,v=a*u+l,w=v;if(0!==n||0!==r){const t=n*h,e=n*d,i=r*c,s=r*u;p+=i,f+=i,m+=s,g+=s,b+=t,w+=t,v+=e,y+=e}i[0]=Math.min(i[0],p,m,Math.min(g,f)),i[1]=Math.min(i[1],b,v,Math.min(y,w)),i[2]=Math.max(i[2],p,m,Math.max(g,f)),i[3]=Math.max(i[3],b,v,Math.max(y,w))}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 i=t[0],s=t[1],n=t[2],r=t[3],a=i**2+s**2,o=i*n+s*r,l=n**2+r**2,h=(a+l)/2,c=Math.sqrt(h**2-(a*l-o**2));e[0]=Math.sqrt(h+c||1),e[1]=Math.sqrt(h-c||1)}static normalizeRect(t){const e=t.slice(0);return t[0]>t[2]&&(e[0]=t[2],e[2]=t[0]),t[1]>t[3]&&(e[1]=t[3],e[3]=t[1]),e}static intersect(t,e){const i=Math.max(Math.min(t[0],t[2]),Math.min(e[0],e[2])),s=Math.min(Math.max(t[0],t[2]),Math.max(e[0],e[2]));if(i>s)return null;const n=Math.max(Math.min(t[1],t[3]),Math.min(e[1],e[3])),r=Math.min(Math.max(t[1],t[3]),Math.max(e[1],e[3]));return n>r?null:[i,n,s,r]}static pointBoundingBox(t,e,i){i[0]=Math.min(i[0],t),i[1]=Math.min(i[1],e),i[2]=Math.max(i[2],t),i[3]=Math.max(i[3],e)}static rectBoundingBox(t,e,i,s,n){n[0]=Math.min(n[0],t,i),n[1]=Math.min(n[1],e,s),n[2]=Math.max(n[2],t,i),n[3]=Math.max(n[3],e,s)}static#t(t,e,i,s,n,r,a,o,l,h){if(l<=0||l>=1)return;const c=1-l,d=l*l,u=d*l,p=c*(c*(c*t+3*l*e)+3*d*i)+u*s,g=c*(c*(c*n+3*l*r)+3*d*a)+u*o;h[0]=Math.min(h[0],p),h[1]=Math.min(h[1],g),h[2]=Math.max(h[2],p),h[3]=Math.max(h[3],g)}static#e(t,e,i,s,n,r,a,o,l,h,c,d){if(Math.abs(l)<1e-12)return void(Math.abs(h)>=1e-12&&this.#t(t,e,i,s,n,r,a,o,-c/h,d));const u=h**2-4*c*l;if(u<0)return;const p=Math.sqrt(u),g=2*l;this.#t(t,e,i,s,n,r,a,o,(-h+p)/g,d),this.#t(t,e,i,s,n,r,a,o,(-h-p)/g,d)}static bezierBoundingBox(t,e,i,s,n,r,a,o,l){l[0]=Math.min(l[0],t,a),l[1]=Math.min(l[1],e,o),l[2]=Math.max(l[2],t,a),l[3]=Math.max(l[3],e,o),this.#e(t,i,n,a,e,s,r,o,3*(3*(i-n)-t+a),6*(t-2*i+n),3*(i-t),l),this.#e(t,i,n,a,e,s,r,o,3*(3*(s-r)-e+o),6*(e-2*s+r),3*(s-e),l)}},R=null,O=null;function N(t){return R||(R=/([\u00a0\u00b5\u037e\u0eb3\u2000-\u200a\u202f\u2126\ufb00-\ufb04\ufb06\ufb20-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufba1\ufba4-\ufba9\ufbae-\ufbb1\ufbd3-\ufbdc\ufbde-\ufbe7\ufbea-\ufbf8\ufbfc\ufbfd\ufc00-\ufc5d\ufc64-\ufcf1\ufcf5-\ufd3d\ufd88\ufdf4\ufdfa\ufdfb\ufe71\ufe77\ufe79\ufe7b\ufe7d]+)|(\ufb05+)/gu,O=/* @__PURE__ */new Map([["ſt","ſt"]])),t.replaceAll(R,(t,e,i)=>e?e.normalize("NFKC"):O.get(i))}function z(){if("function"==typeof crypto.randomUUID)return crypto.randomUUID();const t=/* @__PURE__ */new Uint8Array(32);return crypto.getRandomValues(t),function(t){"object"==typeof t&&void 0!==t?.length||w("Invalid argument for bytesToString");const e=t.length,i=8192;if(e<i)return String.fromCharCode.apply(null,t);const s=[];for(let n=0;n<e;n+=i){const r=Math.min(n+i,e),a=t.subarray(n,r);s.push(String.fromCharCode.apply(null,a))}return s.join("")}(t)}var H=()=>[],U=()=>/* @__PURE__ */new Map,G=()=>Object.create(null),W=()=>/* @__PURE__ */new Set;function j(t,e,i){return Math.min(Math.max(t,e),i)}"function"!=typeof Iterator.prototype.join&&(Iterator.prototype.join=function(t){return[...this].join(t)});var V=class{static CSS=96;static PDF=72;static PDF_TO_CSS_UNITS=this.CSS/this.PDF},$=class extends _{constructor(t,e=0){super(t,"RenderingCancelledException"),this.extraDelay=e}};function X(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,i,s]=t.slice(4,-1).split(",").map(t=>parseInt(t,10));return[e,i,s,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 K(t){const e=X(t);return e?e.slice(0,3):[0,0,0]}function Y(t){const{a:e,b:i,c:s,d:n,e:r,f:a}=t.getTransform();return[e,i,s,n,r,a]}function q(t){const{a:e,b:i,c:s,d:n,e:r,f:a}=t.getTransform().invertSelf();return[e,i,s,n,r,a]}var Q=class t{constructor(){const{pixelRatio:e}=t;this.sx=e,this.sy=e}get scaled(){return 1!==this.sx||1!==this.sy}get symmetric(){return this.sx===this.sy}limitCanvas(e,i,s,n,r=-1){let a=1/0,o=1/0,l=1/0;(s=t.capPixels(s,r))>0&&(a=Math.sqrt(s/(e*i))),-1!==n&&(o=n/e,l=n/i);const h=Math.min(a,o,l);return(this.sx>h||this.sy>h)&&(this.sx=h,this.sy=h,!0)}static get pixelRatio(){return globalThis.devicePixelRatio||1}static capPixels(t,e){if(e>=0){const i=Math.ceil(window.screen.availWidth*window.screen.availHeight*this.pixelRatio**2*(1+e/100));return t>0?Math.min(t,i):i}return t}};function J(t,e){const i=255*(1-(e=j(e??1,0,1)));return t.map(t=>Math.round(t*e+i))}function Z(t,e){const i=t[0]/255,s=t[1]/255,n=t[2]/255,r=Math.max(i,s,n),a=Math.min(i,s,n),o=(r+a)/2;if(r===a)e[0]=e[1]=0;else{const t=r-a;switch(e[1]=o<.5?t/(r+a):t/(2-r-a),r){case i:e[0]=60*((s-n)/t+(s<n?6:0));break;case s:e[0]=60*((n-i)/t+2);break;case n:e[0]=60*((i-s)/t+4)}}e[2]=o}function tt(t,e){const i=t[0],s=t[1],n=t[2],r=(1-Math.abs(2*n-1))*s,a=r*(1-Math.abs(i/60%2-1)),o=n-r/2;switch(Math.floor(i/60)){case 0:e[0]=r+o,e[1]=a+o,e[2]=o;break;case 1:e[0]=a+o,e[1]=r+o,e[2]=o;break;case 2:e[0]=o,e[1]=r+o,e[2]=a+o;break;case 3:e[0]=o,e[1]=a+o,e[2]=r+o;break;case 4:e[0]=a+o,e[1]=o,e[2]=r+o;break;case 5:case 6:e[0]=r+o,e[1]=o,e[2]=a+o}}function et(t){return t<=.03928?t/12.92:((t+.055)/1.055)**2.4}function it(t,e,i){tt(t,i),i.map(et);const s=.2126*i[0]+.7152*i[1]+.0722*i[2];tt(e,i),i.map(et);const n=.2126*i[0]+.7152*i[1]+.0722*i[2];return s>n?(s+.05)/(n+.05):(n+.05)/(s+.05)}var st=/* @__PURE__ */new Map;function nt(t,e){const i=t[0]+256*t[1]+65536*t[2]+16777216*e[0]+4294967296*e[1]+1099511627776*e[2];let s=st.get(i);if(s)return s;const n=/* @__PURE__ */new Float32Array(9),r=n.subarray(0,3),a=n.subarray(3,6);Z(t,a);const o=n.subarray(6,9);Z(e,o);const l=o[2]<.5,h=l?12:4.5;if(a[2]=l?Math.sqrt(a[2]):1-Math.sqrt(1-a[2]),it(a,o,r)<h){let t,e;l?(t=a[2],e=1):(t=0,e=a[2]);const i=.005;for(;e-t>i;){const i=a[2]=(t+e)/2;l===it(a,o,r)<h?t=i:e=i}a[2]=l?e:t}return tt(a,r),s=B.makeHexColor(Math.round(255*r[0]),Math.round(255*r[1]),Math.round(255*r[2])),st.set(i,s),s}function rt(t){const e=new Path2D;if(!t)return e;for(let i=0,s=t.length;i<s;)switch(t[i++]){case 0:e.moveTo(t[i++],t[i++]);break;case 1:e.lineTo(t[i++],t[i++]);break;case 2:e.bezierCurveTo(t[i++],t[i++],t[i++],t[i++],t[i++],t[i++]);break;case 3:e.quadraticCurveTo(t[i++],t[i++],t[i++],t[i++]);break;case 4:e.closePath();break;default:v(t[i-1])}return e}var at=class t{constructor({viewBox:t,userUnit:e,scale:i,rotation:s,offsetX:n=0,offsetY:r=0,dontFlip:a=!1}){this.viewBox=t,this.userUnit=e,this.scale=i,this.rotation=s,this.offsetX=n,this.offsetY=r,i*=e;const o=(t[2]+t[0])/2,l=(t[3]+t[1])/2;let h,c,d,u,p,g,m,f;switch((s%=360)<0&&(s+=360),s){case 180:h=-1,c=0,d=0,u=1;break;case 90:h=0,c=1,d=1,u=0;break;case 270:h=0,c=-1,d=-1,u=0;break;case 0:h=1,c=0,d=0,u=-1;break;default:throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.")}a&&(d=-d,u=-u),0===h?(p=Math.abs(l-t[1])*i+n,g=Math.abs(o-t[0])*i+r,m=(t[3]-t[1])*i,f=(t[2]-t[0])*i):(p=Math.abs(o-t[0])*i+n,g=Math.abs(l-t[1])*i+r,m=(t[2]-t[0])*i,f=(t[3]-t[1])*i),this.transform=[h*i,c*i,d*i,u*i,p-h*i*o-d*i*l,g-c*i*o-u*i*l],this.width=m,this.height=f}get rawDims(){const t=this.viewBox;return T(this,"rawDims",{pageWidth:t[2]-t[0],pageHeight:t[3]-t[1],pageX:t[0],pageY:t[1]})}clone({scale:e=this.scale,rotation:i=this.rotation,offsetX:s=this.offsetX,offsetY:n=this.offsetY,dontFlip:r=!1}={}){return new t({viewBox:this.viewBox.slice(),userUnit:this.userUnit,scale:e,rotation:i,offsetX:s,offsetY:n,dontFlip:r})}convertToViewportPoint(t,e){const i=[t,e];return B.applyTransform(i,this.transform),i}convertToPdfPoint(t,e){const i=[t,e];return B.applyInverseTransform(i,this.transform),i}},ot=class t{static textContent(e){const i=[],s={items:i,styles:Object.create(null)};return function e(s){if(!s)return;let n=null;const r=s.name;if("#text"===r)n=s.value;else{if(!t.shouldBuildText(r))return;s?.attributes?.textContent?n=s.attributes.textContent:s.value&&(n=s.value)}if(null!==n&&i.push({str:n}),s.children)for(const t of s.children)e(t)}(e),s}static shouldBuildText(t){return!("textarea"===t||"input"===t||"option"===t||"select"===t)}},lt=/url\(|image-set\(/i,ht=/^on/i,ct=class{static get _allowedHtmlElements(){return T(this,"_allowedHtmlElements",/* @__PURE__ */new Set(["a","b","br","button","div","i","img","input","label","li","ol","option","p","select","span","sub","sup","textarea","ul"]))}static get _allowedSvgElements(){return T(this,"_allowedSvgElements",/* @__PURE__ */new Set(["ellipse","line","path","rect","svg"]))}static get _allowedRichTextElements(){return T(this,"_allowedRichTextElements",/* @__PURE__ */new Set(["a","b","br","div","i","li","ol","p","span","sub","sup","ul"]))}static get _allowedRichTextAttributes(){return T(this,"_allowedRichTextAttributes",/* @__PURE__ */new Set(["class","dir","style"]))}static get _allowedRichTextStyles(){return T(this,"_allowedRichTextStyles",/* @__PURE__ */new Set(["color","font","fontFamily","fontSize","fontStretch","fontStyle","fontWeight","kerningMode","letterSpacing","lineHeight","margin","marginBottom","marginLeft","marginRight","marginTop","orphans","paddingLeft","paddingRight","breakAfter","breakBefore","breakInside","tabInterval","tabStop","textAlign","textDecoration","textIndent","transform","verticalAlign","widows"]))}static setupStorage(t,e,i,s,n){const r=s.getValue(e,{value:null});switch(i.name){case"textarea":if(null!==r.value&&(t.textContent=r.value),"print"===n)break;t.addEventListener("input",t=>{s.setValue(e,{value:t.target.value})});break;case"input":if("radio"===i.attributes.type||"checkbox"===i.attributes.type){if(r.value===i.attributes.xfaOn?t.setAttribute("checked",!0):r.value===i.attributes.xfaOff&&t.removeAttribute("checked"),"print"===n)break;t.addEventListener("change",t=>{s.setValue(e,{value:t.target.checked?t.target.getAttribute("xfaOn"):t.target.getAttribute("xfaOff")})})}else{if(null!==r.value&&t.setAttribute("value",r.value),"print"===n)break;t.addEventListener("input",t=>{s.setValue(e,{value:t.target.value})})}break;case"select":if(null!==r.value){t.setAttribute("value",r.value);for(const t of i.children)t.attributes.value===r.value?t.attributes.selected=!0:Object.hasOwn(t.attributes,"selected")&&delete t.attributes.selected}t.addEventListener("input",t=>{const i=t.target.options,n=-1===i.selectedIndex?"":i[i.selectedIndex].value;s.setValue(e,{value:n})})}}static setAttributes({html:t,element:e,storage:i=null,intent:s,linkService:n}){const{attributes:r}=e,a=t instanceof HTMLAnchorElement;"radio"===r.type&&(r.name=`${r.name}-${s}`);for(const[o,l]of Object.entries(r))if(null!=l&&!ht.test(o)&&("richText"!==s||this._allowedRichTextAttributes.has(o)))switch(o){case"class":l.length&&t.setAttribute(o,l.join(" "));break;case"dataId":break;case"id":t.setAttribute("data-element-id",l);break;case"style":if("richText"===s){const e=this._allowedRichTextStyles;for(const[i,s]of Object.entries(l))e.has(i)&&!lt.test(s)&&(t.style[i]=s)}else Object.assign(t.style,l);break;case"textContent":t.textContent=l;break;default:(!a||"href"!==o&&"newWindow"!==o)&&t.setAttribute(o,l)}a&&n?.addLinkAttributes(t,r.href,r.newWindow),i&&r.dataId&&this.setupStorage(t,r.dataId,e,i)}static#i(t,e,i){return"richText"===i?!e&&this._allowedRichTextElements.has(t)?document.createElement(t):null:e?e===n&&this._allowedSvgElements.has(t)?document.createElementNS(n,t):null:this._allowedHtmlElements.has(t)?document.createElement(t):null}static render(t){const e=t.annotationStorage,i=t.linkService,s=t.xfaHtml,n=t.intent||"display",r=this.#i(s.name,s.attributes?.xmlns,n)??document.createElement("div");s.attributes&&this.setAttributes({html:r,element:s,intent:n,linkService:i});const a="richText"!==n,o=t.div;if(o.append(r),t.viewport){const e=`matrix(${t.viewport.transform.join(",")})`;o.style.transform=e}a&&o.setAttribute("class","xfaLayer xfaFont");const l=[];if(0===s.children.length){if(s.value){const t=document.createTextNode(s.value);r.append(t),a&&ot.shouldBuildText(s.name)&&l.push(t)}return{textDivs:l}}const h=[[s,-1,r]];for(;h.length>0;){const[t,s,r]=h.at(-1);if(s+1===t.children.length){h.pop();continue}const o=t.children[++h.at(-1)[1]];if(null===o)continue;const{name:c}=o;if("#text"===c){const t=document.createTextNode(o.value);l.push(t),r.append(t);continue}const d=this.#i(c,o.attributes?.xmlns,n);if(d)if(r.append(d),o.attributes&&this.setAttributes({html:d,element:o,storage:e,intent:n,linkService:i}),o.children?.length>0)h.push([o,-1,d]);else if(o.value){const t=document.createTextNode(o.value);a&&ot.shouldBuildText(c)&&l.push(t),d.append(t)}}for(const c of o.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea"))c.setAttribute("readOnly",!0);return{textDivs:l}}static update(t){const e=`matrix(${t.viewport.transform.join(",")})`;t.div.style.transform=e,t.div.hidden=!1}static getPageViewport(t,{scale:e=1,rotation:i=0}){const{width:s,height:n}=t.attributes.style;return new at({viewBox:[0,0,parseInt(s,10),parseInt(n,10)],userUnit:1,scale:e,rotation:i})}};async function dt(t,e="text"){if(ft(t,document.baseURI)){const i=await fetch(t);if(!i.ok)throw new Error(i.statusText);switch(e){case"blob":return i.blob();case"bytes":return i.bytes();case"json":return i.json()}return i.text()}return new Promise((i,s)=>{const n=new XMLHttpRequest;n.open("GET",t,!0),n.responseType="bytes"===e?"arraybuffer":e,n.onreadystatechange=()=>{if(n.readyState===XMLHttpRequest.DONE)if(200!==n.status&&0!==n.status)s(new Error(n.statusText));else{switch(e){case"bytes":return void i(new Uint8Array(n.response));case"blob":case"json":return void i(n.response)}i(n.responseText)}},n.send(null)})}function ut(t){const e=t.length;let i=0;for(;i<e&&""===t[i].trim();)i++;return"data:"===t.substring(i,i+5).toLowerCase()}function pt(t){return"string"==typeof t&&/\.pdf$/i.test(t)}function gt(t){return[t]=t.split(/[#?]/,1),S(t)}function mt(t,e="document.pdf"){if("string"!=typeof t)return e;if(ut(t))return e;const i=(t=>{try{return new URL(t)}catch{}try{return new URL(decodeURIComponent(t))}catch{}try{return new URL(t,"https://foo.bar")}catch{}try{return new URL(decodeURIComponent(t),"https://foo.bar")}catch{}return null})(t);if(!i)return e;const s=t=>{try{let e=decodeURIComponent(t);return e.includes("/")&&(e=S(e),4===e.length&&n.test(e))?t:e}catch{return t}},n=/\.pdf$/i,r=S(i.pathname);if(n.test(r))return s(r);if(i.searchParams.size>0){const t=t=>[...t].findLast(t=>n.test(t)),e=t(i.searchParams.values())??t(i.searchParams.keys());if(e)return s(e)}if(i.hash){const{hash:t}=i;let e=-1;for(const{index:i}of t.matchAll(/\.pdf\b/gi))e=i;if(e>0){let i=e;for(;i>0&&!"/?#=".includes(t[i-1]);)i--;if(i<e)return s(t.slice(i,e+4))}}return e}function ft(t,e){const i=e?URL.parse(t,e):URL.parse(t);return/https?:/.test(i?.protocol??"")}function bt(t){t.preventDefault()}function yt(t){t.preventDefault(),t.stopPropagation()}var vt=class{static#s;static toDateObject(t){if(t instanceof Date)return t;if(!t||"string"!=typeof t)return null;this.#s||=/* @__PURE__ */new RegExp("^D:(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?([Z|+\\-])?(\\d{2})?'?(\\d{2})?'?");const e=this.#s.exec(t);if(!e)return null;const i=parseInt(e[1],10);let s=parseInt(e[2],10);s=s>=1&&s<=12?s-1:0;let n=parseInt(e[3],10);n=n>=1&&n<=31?n:1;let r=parseInt(e[4],10);r=r>=0&&r<=23?r:0;let a=parseInt(e[5],10);a=a>=0&&a<=59?a:0;let o=parseInt(e[6],10);o=o>=0&&o<=59?o:0;const l=e[7]||"Z";let h=parseInt(e[8],10);h=h>=0&&h<=23?h:0;let c=parseInt(e[9],10)||0;return c=c>=0&&c<=59?c:0,"-"===l?(r+=h,a+=c):"+"===l&&(r-=h,a-=c),new Date(Date.UTC(i,s,n,r,a,o))}};function wt(t,e,i=!1,s=!0){if(e instanceof at){const{pageWidth:s,pageHeight:n}=e.rawDims,{style:r}=t,a=`round(down, var(--total-scale-factor) * ${s}px, var(--scale-round-x))`,o=`round(down, var(--total-scale-factor) * ${n}px, var(--scale-round-y))`;i&&e.rotation%180!=0?(r.width=o,r.height=a):(r.width=a,r.height=o)}s&&t.setAttribute("data-main-rotation",e.rotation)}var At=/* @__PURE__ */new Set(["image/apng","image/avif","image/bmp","image/gif","image/jpeg","image/png","image/svg+xml","image/webp","image/x-icon"]),xt=class{static get isDarkMode(){return T(this,"isDarkMode",!!window?.matchMedia?.("(prefers-color-scheme: dark)").matches)}},Ct=class{static get commentForegroundColor(){const t=document.createElement("span");t.classList.add("comment","sidebar");const{style:e}=t;e.width=e.height="0",e.display="none",e.color="var(--comment-fg-color)",document.body.append(t);const{color:i}=window.getComputedStyle(t);return t.remove(),T(this,"commentForegroundColor",K(i))}};function St({html:t,dir:e,className:i},s){const n=document.createDocumentFragment();if("string"==typeof t){const i=document.createElement("p");i.dir=e||"auto";const s=t.split(/\r\n?|\n/);for(let t=0,e=s.length;t<e;++t){const n=s[t];i.append(document.createTextNode(n)),t<e-1&&i.append(document.createElement("br"))}n.append(i)}else ct.render({xfaHtml:t,div:n,intent:"richText"});n.firstElementChild.classList.add("richText",i),s.append(n)}var Tt=class t{#n=null;#r=null;#a;#o=null;#l=null;#h=null;#c=null;#d=null;static#u=null;constructor(e){this.#a=e,t.#u||=Object.freeze({freetext:"pdfjs-editor-remove-freetext-button",highlight:"pdfjs-editor-remove-highlight-button",ink:"pdfjs-editor-remove-ink-button",stamp:"pdfjs-editor-remove-stamp-button",signature:"pdfjs-editor-remove-signature-button"})}render(){const e=this.#n=document.createElement("div");e.classList.add("editToolbar","hidden"),e.setAttribute("role","toolbar");const i=this.#a._uiManager._signal;i instanceof AbortSignal&&!i.aborted&&(e.addEventListener("contextmenu",bt,{signal:i}),e.addEventListener("pointerdown",t.#p,{signal:i}));const s=this.#o=document.createElement("div");s.className="buttons",e.append(s);const n=this.#a.toolbarPosition;if(n){const{style:t}=e;t.insetInlineEnd=100*("ltr"===this.#a._uiManager.direction?1-n[0]:n[0])+"%",t.top=`calc(${100*n[1]}% + var(--editor-toolbar-vert-offset))`}return e}get div(){return this.#n}static#p(t){t.stopPropagation()}#g(t){this.#a._focusEventsAllowed=!1,yt(t)}#m(t){this.#a._focusEventsAllowed=!0,yt(t)}#f(t){const e=this.#a._uiManager._signal;return e instanceof AbortSignal&&!e.aborted&&(t.addEventListener("focusin",this.#g.bind(this),{capture:!0,signal:e}),t.addEventListener("focusout",this.#m.bind(this),{capture:!0,signal:e}),t.addEventListener("contextmenu",bt,{signal:e}),!0)}hide(){this.#n.classList.add("hidden"),this.#r?.hideDropdown()}show(){this.#n.classList.remove("hidden"),this.#l?.shown(),this.#h?.shown()}addDeleteButton(){const{editorType:e,_uiManager:i}=this.#a,s=document.createElement("button");s.classList.add("basic","deleteButton"),s.tabIndex=0,s.setAttribute("data-l10n-id",t.#u[e]),this.#f(s)&&s.addEventListener("click",t=>{i.delete()},{signal:i._signal}),this.#o.append(s)}get#b(){const t=document.createElement("div");return t.className="divider",t}async addAltText(t){const e=await t.render();this.#f(e),this.#o.append(e,this.#b),this.#l=t}addComment(t,e=null){if(this.#h)return;const i=t.renderForToolbar();if(!i)return;this.#f(i);const s=this.#c=this.#b;e?(this.#o.insertBefore(i,e),this.#o.insertBefore(s,e)):this.#o.append(i,s),this.#h=t,t.toolbar=this}addColorPicker(t){if(this.#r)return;this.#r=t;const e=t.renderButton();this.#f(e),this.#o.append(e,this.#b)}async addEditSignatureButton(t){const e=this.#d=await t.renderEditButton(this.#a);e&&(this.#f(e),this.#o.append(e,this.#b))}removeButton(t){"comment"===t&&(this.#h?.removeToolbarCommentButton(),this.#h=null,this.#c?.remove(),this.#c=null)}async addButton(t,e){switch(t){case"colorPicker":e&&this.addColorPicker(e);break;case"altText":e&&await this.addAltText(e);break;case"editSignature":e&&await this.addEditSignatureButton(e);break;case"delete":this.addDeleteButton();break;case"comment":e&&this.addComment(e)}}async addButtonBefore(t,e,i){if(!e&&"comment"===t)return;const s=this.#o.querySelector(i);s&&"comment"===t&&this.addComment(e,s)}updateEditSignatureButton(t){this.#d&&(this.#d.title=t)}remove(){this.#n.remove(),this.#r?.destroy(),this.#r=null}},_t=class{#o=null;#n=null;#y;constructor(t){this.#y=t}#v(){const t=this.#n=document.createElement("div");t.className="editToolbar",t.setAttribute("role","toolbar"),t.dir=this.#y.direction;const e=this.#y._signal;e instanceof AbortSignal&&!e.aborted&&t.addEventListener("contextmenu",bt,{signal:e});const i=this.#o=document.createElement("div");return i.className="buttons",t.append(i),this.#y.hasCommentManager()&&this.#w("commentButton","pdfjs-comment-floating-button","pdfjs-comment-floating-button-label",()=>{this.#y.commentSelection("floating_button")}),this.#w("highlightButton","pdfjs-highlight-floating-button1","pdfjs-highlight-floating-button-label",()=>{this.#y.highlightSelection("floating_button")}),t}#A(t,e){let i=0,s=0;for(const n of t){const t=n.y+n.height;if(t<i)continue;const r=n.x+(e?n.width:0);t>i?(s=r,i=t):e?r>s&&(s=r):r<s&&(s=r)}return[e?1-s:s,i]}show(t,e,i){const[s,n]=this.#A(e,i),{style:r}=this.#n||=this.#v();t.append(this.#n),r.insetInlineEnd=100*s+"%",r.top=`calc(${100*n}% + var(--editor-toolbar-vert-offset))`}hide(){this.#n.remove()}#w(t,e,i,s){const n=document.createElement("button");n.classList.add("basic",t),n.tabIndex=0,n.setAttribute("data-l10n-id",e);const r=document.createElement("span");n.append(r),r.className="visuallyHidden",r.setAttribute("data-l10n-id",i);const a=this.#y._signal;a instanceof AbortSignal&&!a.aborted&&(n.addEventListener("contextmenu",bt,{signal:a}),n.addEventListener("click",s,{signal:a})),this.#o.append(n)}},kt=Object.freeze({internal:"0a475cb6-573c-46ed-869d-fa7c5839d995"});function Et(t,e,i){for(const s of i)e.addEventListener(s,t[s].bind(t))}var Mt=class t{static#x=NaN;static#C=null;static#S=NaN;static#T=null;static initializeAndAddPointerId(e){(t.#C||=/* @__PURE__ */new Set).add(e)}static setPointer(e,i){t.#x||=i,t.#T??=e}static setTimeStamp(e){t.#S=e}static isSamePointerId(e){return t.#x===e}static isSamePointerIdOrRemove(e){return t.#x===e||(t.#C?.delete(e),!1)}static isSamePointerType(e){return t.#T===e}static isInitializedAndDifferentPointerType(e){return null!==t.#T&&!t.isSamePointerType(e)}static isSameTimeStamp(e){return t.#S===e}static isUsingMultiplePointers(){return t.#C?.size>=1}static clearPointerType(){t.#T=null}static clearPointerIds(){t.#x=NaN,t.#C=null}static clearTimeStamp(){t.#S=NaN}},Pt=class{#_=0;get id(){return`${o}${this.#_++}`}},Dt=class t{#k=z();#_=0;#E=null;static get _isSVGFittingCanvas(){const t=`data:image/svg+xml;charset=UTF-8,<svg viewBox="0 0 1 1" width="1" height="1" xmlns="${n}"><rect width="1" height="1" style="fill:red;"/></svg>`,e=new OffscreenCanvas(1,3).getContext("2d",{willReadFrequently:!0}),i=new Image;return i.src=t,T(this,"_isSVGFittingCanvas",i.decode().then(()=>(e.drawImage(i,0,0,1,1,0,0,1,3),0===new Uint32Array(e.getImageData(0,0,1,1).data.buffer)[0])))}async#M(e,i){this.#E||=/* @__PURE__ */new Map;let s=this.#E.get(e);if(null===s)return null;if(s?.bitmap)return s.refCounter+=1,s;try{let e;if(s||={bitmap:null,id:`image_${this.#k}_${this.#_++}`,refCounter:0,isSvg:!1},"string"==typeof i?(s.url=i,e=await dt(i,"blob")):i instanceof File?e=s.file=i:i instanceof Blob&&(e=i),"image/svg+xml"===e.type){const i=t._isSVGFittingCanvas,n=new FileReader,r=new Image,a=new Promise((t,e)=>{r.onload=()=>{s.bitmap=r,s.isSvg=!0,t()},n.onload=async()=>{const t=s.svgUrl=n.result;r.src=await i?`${t}#svgView(preserveAspectRatio(none))`:t},r.onerror=n.onerror=e});n.readAsDataURL(e),await a}else s.bitmap=await createImageBitmap(e);s.refCounter=1}catch(n){s=null}return this.#E.set(e,s),s&&this.#E.set(s.id,s),s}async getFromFile(t){const{lastModified:e,name:i,size:s,type:n}=t;return this.#M(`${e}_${i}_${s}_${n}`,t)}async getFromUrl(t){return this.#M(t,t)}async getFromBlob(t,e){const i=await e;return this.#M(t,i)}async getFromId(t){this.#E||=/* @__PURE__ */new Map;const e=this.#E.get(t);if(!e)return null;if(e.bitmap)return e.refCounter+=1,e;if(e.file)return this.getFromFile(e.file);if(e.blobPromise){const{blobPromise:t}=e;return delete e.blobPromise,this.getFromBlob(e.id,t)}return this.getFromUrl(e.url)}getFromCanvas(t,e){this.#E||=/* @__PURE__ */new Map;let i=this.#E.get(t);if(i?.bitmap)return i.refCounter+=1,i;const s=new OffscreenCanvas(e.width,e.height);return s.getContext("2d").drawImage(e,0,0),i={bitmap:s.transferToImageBitmap(),id:`image_${this.#k}_${this.#_++}`,refCounter:1,isSvg:!1},this.#E.set(t,i),this.#E.set(i.id,i),i}getSvgUrl(t){const e=this.#E.get(t);return e?.isSvg?e.svgUrl:null}deleteId(t){this.#E||=/* @__PURE__ */new Map;const e=this.#E.get(t);if(!e)return;if(e.refCounter-=1,0!==e.refCounter)return;const{bitmap:i}=e;if(!e.url&&!e.file){const t=new OffscreenCanvas(i.width,i.height);t.getContext("bitmaprenderer").transferFromImageBitmap(i),e.blobPromise=t.convertToBlob()}i.close?.(),e.bitmap=null}isValidId(t){return t.startsWith(`image_${this.#k}_`)}},It=class{#P=[];#D=!1;#I;#F=-1;constructor(t=128){this.#I=t}add({cmd:t,undo:e,post:i,mustExec:s,type:n=NaN,overwriteIfSameType:r=!1,keepUndo:a=!1}){if(s&&t(),this.#D)return;const o={cmd:t,undo:e,post:i,type:n};if(-1===this.#F)return this.#P.length>0&&(this.#P.length=0),this.#F=0,void this.#P.push(o);if(r&&this.#P[this.#F].type===n)return a&&(o.undo=this.#P[this.#F].undo),void(this.#P[this.#F]=o);const l=this.#F+1;l===this.#I?this.#P.splice(0,1):(this.#F=l,l<this.#P.length&&this.#P.splice(l)),this.#P.push(o)}undo(){if(-1===this.#F)return;this.#D=!0;const{undo:t,post:e}=this.#P[this.#F];t(),e?.(),this.#D=!1,this.#F-=1}redo(){if(this.#F<this.#P.length-1){this.#F+=1,this.#D=!0;const{cmd:t,post:e}=this.#P[this.#F];t(),e?.(),this.#D=!1}}hasSomethingToUndo(){return-1!==this.#F}hasSomethingToRedo(){return this.#F<this.#P.length-1}cleanType(t){if(-1!==this.#F){for(let e=this.#F;e>=0;e--)if(this.#P[e].type!==t)return this.#P.splice(e+1,this.#F-e),void(this.#F=e);this.#P.length=0,this.#F=-1}}destroy(){this.#P=null}},Ft=class t{static ALT=1;static CTRL=2;static META=4;static SHIFT=8;constructor(e){this.callbacks=/* @__PURE__ */new Map;const{isMac:i}=L.platform;for(const[s,n,r={}]of e){const e=s.some(t=>t.startsWith("mac+"));for(const a of s){let s=a;if(e){const t=a.startsWith("mac+");if(i!==t)continue;t&&(s=a.slice(4))}const[o,l]=t.#L(s);null!==o&&this.callbacks.getOrInsertComputed(o,H).push({callback:n,options:r,modifiers:l})}}}static#L(e){let i=null,s=0;for(let n of e.split("+")){if(n=n.trim(),!n)continue;const e=n.toUpperCase(),r=t[e];if(r)s|=r;else{if(null!==i){v();break}i="SPACE"===e?" ":n}}return[i,s]}static#B(t){const e=/^(?:Key([A-Z])|(?:Digit|Numpad)(\d))$/.exec(t);return e?e[1]?.toLowerCase()??e[2]:null}exec(e,i){let s=this.callbacks.get(i.key);if(!s){if(/^[a-z]$/i.test(i.key))return;const e=t.#B(i.code);if(null===e||e===i.key)return;if(s=this.callbacks.get(e),!s)return}const n=(i.altKey?t.ALT:0)|(i.ctrlKey?t.CTRL:0)|(i.metaKey?t.META:0)|(i.shiftKey?t.SHIFT:0),r=s.find(t=>t.modifiers===n);if(!r)return;const{callback:a,options:{bubbles:o=!1,args:l=[],checker:h=null}}=r;h&&!h(e,i)||(a.bind(e,...l,i)(),o||yt(i))}},Lt=class t{static _colorsMapping=/* @__PURE__ */new Map([["CanvasText",[0,0,0]],["Canvas",[255,255,255]]]);get _colors(){const t=/* @__PURE__ */new Map([["CanvasText",null],["Canvas",null]]);return function(t){const e=document.createElement("span");e.style.visibility="hidden",e.style.colorScheme="only light",document.body.append(e);for(const i of t.keys()){e.style.color=i;const s=window.getComputedStyle(e).color;t.set(i,K(s))}e.remove()}(t),T(this,"_colors",t)}convert(e){const i=K(e);if(!window.matchMedia("(forced-colors: active)").matches)return i;for(const[s,n]of this._colors)if(n.every((t,e)=>t===i[e]))return t._colorsMapping.get(s);return i}getHexCode(t){const e=this._colors.get(t);return e?B.makeHexColor(...e):t}},Bt=class t{#R=new AbortController;#O=null;#N=null;#z=/* @__PURE__ */new Map;#H=/* @__PURE__ */new Map;#U=null;#G=null;#W=null;#j=null;#V=null;#$=new It;#X=null;#K=null;#Y=null;#q=0;#Q=/* @__PURE__ */new Set;#J=null;#Z=null;#tt=/* @__PURE__ */new Set;_editorUndoBar=null;#et=!1;#it=!1;#st=!1;#nt=null;#rt=null;#at=null;#ot=null;#lt=!1;#ht=null;#ct=new Pt;#dt=!1;#ut=!1;#pt=!1;#gt=null;#mt=null;#ft=null;#bt=null;#yt=null;#vt=l.NONE;#wt=/* @__PURE__ */new Set;#At=null;#xt=null;#Ct=null;#St=null;#Tt=null;#_t={isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1};#kt=[0,0];#Et=null;#Mt=null;#Pt=null;#Dt=null;#It=null;static TRANSLATE_SMALL=1;static TRANSLATE_BIG=10;static get _keyboardManager(){const e=t.prototype,i=t=>t.#Mt.contains(document.activeElement)&&"BUTTON"!==document.activeElement.tagName&&t.hasSomethingToControl(),s=(t,{target:e})=>{if(e instanceof HTMLInputElement){const{type:t}=e;return"text"!==t&&"number"!==t}return!0},n=this.TRANSLATE_SMALL,r=this.TRANSLATE_BIG;return T(this,"_keyboardManager",new Ft([[["ctrl+a","mac+meta+a"],e.selectAll,{checker:s}],[["ctrl+z","mac+meta+z"],e.undo,{checker:s}],[["ctrl+y","ctrl+shift+z","mac+meta+shift+z","ctrl+shift+Z","mac+meta+shift+Z"],e.redo,{checker:s}],[["Backspace","alt+Backspace","ctrl+Backspace","shift+Backspace","mac+Backspace","mac+alt+Backspace","mac+ctrl+Backspace","Delete","ctrl+Delete","shift+Delete","mac+Delete"],e.delete,{checker:s}],[["Enter"],e.addNewEditorFromKeyboard,{checker:(t,{target:e})=>!(e instanceof HTMLButtonElement)&&t.#Mt.contains(e)&&!t.isEnterHandled}],[["Space"],e.addNewEditorFromKeyboard,{checker:(t,{target:e})=>!(e instanceof HTMLButtonElement)&&t.#Mt.contains(document.activeElement)}],[["Escape"],e.unselectAll],[["ArrowLeft"],e.translateSelectedEditors,{args:[-n,0],checker:i}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],e.translateSelectedEditors,{args:[-r,0],checker:i}],[["ArrowRight"],e.translateSelectedEditors,{args:[n,0],checker:i}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],e.translateSelectedEditors,{args:[r,0],checker:i}],[["ArrowUp"],e.translateSelectedEditors,{args:[0,-n],checker:i}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],e.translateSelectedEditors,{args:[0,-r],checker:i}],[["ArrowDown"],e.translateSelectedEditors,{args:[0,n],checker:i}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],e.translateSelectedEditors,{args:[0,r],checker:i}]]))}constructor(t,e,i,s,n,r,a,o,l,h,c,d,u,p,g,m,f){const b=this._signal=this.#R.signal;this.#Mt=t,this.#Pt=e,this.#Dt=i,this.#W=s,this.#X=n,this.#xt=r,this.#Tt=o,this._eventBus=a;const y={signal:b,...kt};a.on("editingaction",this.onEditingAction.bind(this),y),a.on("pagechanging",this.onPageChanging.bind(this),y),a.on("scalechanging",this.onScaleChanging.bind(this),y),a.on("rotationchanging",this.onRotationChanging.bind(this),y),a.on("setpreference",this.onSetPreference.bind(this),y),a.on("switchannotationeditorparams",t=>this.updateParams(t.type,t.value),y),window.addEventListener("pointerdown",()=>{this.#ut=!0},{capture:!0,signal:b}),window.addEventListener("pointerup",()=>{this.#ut=!1},{capture:!0,signal:b}),window.addEventListener("beforeunload",this.endCurrentEditing.bind(this),{capture:!0,signal:b}),this.#Ft(),this.#Lt(),this.#Bt(),this.#j=o.annotationStorage,this.#nt=o.filterFactory,this.#Ct=l,this.#ot=h||null,this.#et=c,this.#it=d,this.#st=u,this.#yt=p||null,this.viewParameters={realScale:V.PDF_TO_CSS_UNITS,rotation:0},this.isShiftKeyDown=!1,this._editorUndoBar=g||null,this._supportsPinchToZoom=!1!==m,this._keepToolbarInPage=!0===f,n?.setSidebarUiManager(this)}destroy(){this.#It?.resolve(),this.#It=null,this.#R?.abort(),this.#R=null,this._signal=null;for(const t of this.#H.values())t.destroy();this.#H.clear(),this.#z.clear(),this.#tt.clear(),this.#bt?.clear(),this.#O=null,this.#wt.clear(),this.#$.destroy(),this.#W?.destroy(),this.#X?.destroy(),this.#xt?.destroy(),this.#ht?.hide(),this.#ht=null,this.#ft?.destroy(),this.#ft=null,this.#N=null,this.#rt&&(clearTimeout(this.#rt),this.#rt=null),this.#Et&&(clearTimeout(this.#Et),this.#Et=null),this._editorUndoBar?.destroy(),this.#Tt=null}combinedSignal(t){return AbortSignal.any([this._signal,t.signal])}get mlManager(){return this.#yt}get useNewAltTextFlow(){return this.#it}get useNewAltTextWhenAddingImage(){return this.#st}get hcmFilter(){return T(this,"hcmFilter",this.#Ct?this.#nt.addHCMFilter(this.#Ct.foreground,this.#Ct.background):"none")}get direction(){return T(this,"direction",getComputedStyle(this.#Mt).direction)}get _highlightColors(){return T(this,"_highlightColors",this.#ot?new Map(this.#ot.split(",").map(t=>((t=t.split("=").map(t=>t.trim()))[1]=t[1].toUpperCase(),t))):null)}get highlightColors(){const{_highlightColors:t}=this;if(!t)return T(this,"highlightColors",null);const e=/* @__PURE__ */new Map,i=!!this.#Ct;for(const[s,n]of t){const t=s.endsWith("_HCM");i&&t?e.set(s.replace("_HCM",""),n):i||t||e.set(s,n)}return T(this,"highlightColors",e)}get highlightColorNames(){return T(this,"highlightColorNames",this.highlightColors?new Map(Array.from(this.highlightColors,t=>t.reverse())):null)}getNonHCMColor(t){if(!this._highlightColors)return t;const e=this.highlightColorNames.get(t);return this._highlightColors.get(e)||t}getNonHCMColorName(t){return this.highlightColorNames.get(t)||t}setCurrentDrawingSession(t){t?(this.unselectAll(),this.disableUserSelect(!0)):this.disableUserSelect(!1),this.#Y=t}setMainHighlightColorPicker(t){this.#ft=t}editAltText(t,e=!1){this.#W?.editAltText(this,t,e)}hasCommentManager(){return!!this.#X}editComment(t,e,i,s){this.#X?.showDialog(this,t,e,i,s)}selectComment(t,e){(this.#H.get(t)?.getEditorByUID(e))?.toggleComment(!0,!0)}updateComment(t){this.#X?.updateComment(t.getData())}updatePopupColor(t){this.#X?.updatePopupColor(t)}removeComment(t){this.#X?.removeComments([t.uid])}deleteComment(t,e){const i=()=>{t.comment=e};this.addCommands({cmd:()=>{this._editorUndoBar?.show(i,"comment"),this.toggleComment(null),t.comment=null},undo:i,mustExec:!0})}toggleComment(t,e,i=void 0){this.#X?.toggleCommentPopup(t,e,i)}makeCommentColor(t,e){return t&&this.#X?.makeCommentColor(t,e)||null}getCommentDialogElement(){return this.#X?.dialogElement||null}async waitForEditorsRendered(t){if(this.#H.has(t-1))return;const{resolve:e,promise:i}=Promise.withResolvers(),s=i=>{i.pageNumber===t&&(this._eventBus.off("editorsrendered",s),e())};this._eventBus.on("editorsrendered",s,kt),await i}getSignature(t){this.#xt?.getSignature({uiManager:this,editor:t})}get signatureManager(){return this.#xt}switchToMode(t,e){this._eventBus.on("annotationeditormodechanged",e,{once:!0,signal:this._signal,...kt}),this._eventBus.dispatch("showannotationeditorui",{source:this,mode:t})}setPreference(t,e){this._eventBus.dispatch("setpreference",{source:this,name:t,value:e})}onSetPreference({name:t,value:e}){"enableNewAltTextWhenAddingImage"===t&&(this.#st=e)}onPageChanging({pageNumber:t}){this.#q=t-1}deletePage(t){for(const e of this.getEditors(t))e.remove();this.#H.delete(t),this.#q===t&&(this.#q=0)}focusMainContainer(){this.#Mt.focus()}findParent(t,e){for(const i of this.#H.values()){const{x:s,y:n,width:r,height:a}=i.div.getBoundingClientRect();if(t>=s&&t<=s+r&&e>=n&&e<=n+a)return i}return null}disableUserSelect(t=!1){this.#Pt.classList.toggle("noUserSelect",t)}addShouldRescale(t){this.#tt.add(t)}removeShouldRescale(t){this.#tt.delete(t)}onScaleChanging({scale:t}){this.commitOrRemove(),this.viewParameters.realScale=t*V.PDF_TO_CSS_UNITS;for(const e of this.#tt)e.onScaleChanging();this.#Y?.onScaleChanging()}onRotationChanging({pagesRotation:t}){this.commitOrRemove(),this.viewParameters.rotation=t}#Rt({anchorNode:t}){return t.nodeType===Node.TEXT_NODE?t.parentElement:t}#Ot(t){const{currentLayer:e}=this;if(e.hasTextLayer(t))return e;for(const i of this.#H.values())if(i.hasTextLayer(t))return i;return null}highlightSelection(t="",e=!1){const i=document.getSelection();if(!i||i.isCollapsed)return;const{anchorNode:s,anchorOffset:n,focusNode:r,focusOffset:a}=i,o=i.toString(),h=this.#Rt(i).closest(".textLayer"),c=this.getSelectionBoxes(h);if(!c)return;i.empty();const d=this.#Ot(h),u=this.#vt===l.NONE,p=()=>{const i=d?.createAndAddNewEditor({x:0,y:0},!1,{methodOfCreation:t,boxes:c,anchorNode:s,anchorOffset:n,focusNode:r,focusOffset:a,text:o});u&&this.showAllEditors("highlight",!0,!0),e&&i?.editComment()};u?this.switchToMode(l.HIGHLIGHT,p):p()}commentSelection(t=""){this.highlightSelection(t,!0)}endCurrentEditing(){this.commitOrRemove(),this.currentLayer?.endDrawingSession(!1)}#Nt(){const t=document.getSelection();if(!t||t.isCollapsed)return;const e=this.#Rt(t).closest(".textLayer"),i=this.getSelectionBoxes(e);i&&(this.#ht||=new _t(this),this.#ht.show(e,i,"ltr"===this.direction))}getAndRemoveDataFromAnnotationStorage(t){if(!this.#j)return null;const e=`${o}${t}`,i=this.#j.getRawValue(e);return i&&this.#j.remove(e),i}addToAnnotationStorage(t){t.isEmpty()||!this.#j||this.#j.has(t.id)||this.#j.setValue(t.id,t)}a11yAlert(t,e=null){const i=this.#Dt;i&&(i.setAttribute("data-l10n-id",t),e?i.setAttribute("data-l10n-args",JSON.stringify(e)):i.removeAttribute("data-l10n-args"))}#zt(){const t=document.getSelection();if(!t||t.isCollapsed)return void(this.#At&&(this.#ht?.hide(),this.#At=null,this.#Ht({hasSelectedText:!1})));const{anchorNode:e}=t;if(e===this.#At)return;const i=this.#Rt(t).closest(".textLayer");if(i){if(this.#ht?.hide(),this.#At=e,this.#Ht({hasSelectedText:!0}),(this.#vt===l.HIGHLIGHT||this.#vt===l.NONE)&&(this.#vt===l.HIGHLIGHT&&this.showAllEditors("highlight",!0,!0),this.#lt=this.isShiftKeyDown,!this.isShiftKeyDown)){const t=this.#vt===l.HIGHLIGHT?this.#Ot(i):null;if(t?.toggleDrawing(),this.#ut){const e=new AbortController,i=this.combinedSignal(e),s=i=>{"pointerup"===i.type&&0!==i.button||(e.abort(),t?.toggleDrawing(!0),"pointerup"===i.type&&this.#Ut("main_toolbar"))};window.addEventListener("pointerup",s,{signal:i}),window.addEventListener("blur",s,{signal:i})}else t?.toggleDrawing(!0),this.#Ut("main_toolbar")}}else this.#At&&(this.#ht?.hide(),this.#At=null,this.#Ht({hasSelectedText:!1}))}#Ut(t=""){this.#vt===l.HIGHLIGHT?this.highlightSelection(t):this.#et&&this.#Nt()}#Ft(){document.addEventListener("selectionchange",this.#zt.bind(this),{signal:this._signal})}#Gt(){if(this.#at)return;this.#at=new AbortController;const t=this.combinedSignal(this.#at);window.addEventListener("focus",this.focus.bind(this),{signal:t}),window.addEventListener("blur",this.blur.bind(this),{signal:t})}#Wt(){this.#at?.abort(),this.#at=null}blur(){if(this.isShiftKeyDown=!1,this.#lt&&(this.#lt=!1,this.#Ut("main_toolbar")),!this.hasSelection)return;const{activeElement:t}=document;for(const e of this.#wt)if(e.div.contains(t)){this.#mt=[e,t],e._focusEventsAllowed=!1;break}}focus(){if(!this.#mt)return;const[t,e]=this.#mt;this.#mt=null,e.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this._signal}),e.focus()}#Bt(){if(this.#gt)return;this.#gt=new AbortController;const t=this.combinedSignal(this.#gt);window.addEventListener("keydown",this.keydown.bind(this),{signal:t}),window.addEventListener("keyup",this.keyup.bind(this),{signal:t})}#jt(){this.#gt?.abort(),this.#gt=null}#Vt(){if(this.#K)return;this.#K=new AbortController;const t=this.combinedSignal(this.#K);document.addEventListener("copy",this.copy.bind(this),{signal:t}),document.addEventListener("cut",this.cut.bind(this),{signal:t}),document.addEventListener("paste",this.paste.bind(this),{signal:t})}#$t(){this.#K?.abort(),this.#K=null}#Lt(){const t=this._signal;document.addEventListener("dragover",this.dragOver.bind(this),{signal:t}),document.addEventListener("drop",this.drop.bind(this),{signal:t})}addEditListeners(){this.#Bt(),this.setEditingState(!0)}removeEditListeners(){this.#jt(),this.setEditingState(!1)}dragOver(t){for(const{type:e}of t.dataTransfer.items)for(const i of this.#Z)if(i.isHandlingMimeForPasting(e))return t.dataTransfer.dropEffect="copy",void t.preventDefault()}drop(t){for(const e of t.dataTransfer.items)for(const i of this.#Z)if(i.isHandlingMimeForPasting(e.type))return i.paste(e,this.currentLayer),void t.preventDefault()}copy(t){if(t.preventDefault(),this.#O?.commitOrRemove(),!this.hasSelection)return;const e=[];for(const i of this.#wt){const t=i.serialize(!0);t&&e.push(t)}0!==e.length&&t.clipboardData.setData("application/pdfjs",JSON.stringify(e))}cut(t){this.copy(t),this.delete()}async paste(t){t.preventDefault();const{clipboardData:e}=t;for(const r of e.items)for(const t of this.#Z)if(t.isHandlingMimeForPasting(r.type))return void t.paste(r,this.currentLayer);let i=e.getData("application/pdfjs");if(!i)return;try{i=JSON.parse(i)}catch(n){return void n.message}if(!Array.isArray(i))return;this.unselectAll();const s=this.currentLayer;try{const t=[];for(const r of i){const e=await s.deserialize(r);if(!e)return;t.push(e)}const e=()=>{for(const e of t)this.#Xt(e);this.#Kt(t)},n=()=>{for(const e of t)e.remove()};this.addCommands({cmd:e,undo:n,mustExec:!0})}catch(n){n.message}}keydown(e){this.isShiftKeyDown||"Shift"!==e.key||(this.isShiftKeyDown=!0),this.#vt===l.NONE||this.isEditorHandlingKeyboard||t._keyboardManager.exec(this,e)}keyup(t){this.isShiftKeyDown&&"Shift"===t.key&&(this.isShiftKeyDown=!1,this.#lt&&(this.#lt=!1,this.#Ut("main_toolbar")))}onEditingAction({name:t}){switch(t){case"undo":case"redo":case"delete":case"selectAll":this[t]();break;case"highlightSelection":this.highlightSelection("context_menu");break;case"commentSelection":this.commentSelection("context_menu")}}updatePageIndex(t,e){for(const s of this.#G.get(t)||[])s.pageIndex=e;const i=this.#U.get(t);i&&(i.pageIndex=e,this.#H.set(e,i),this.#dt?i.enable():i.disable())}startUpdatePages(){this.#U=new Map(this.#H),this.#H.clear();const t=this.#G=/* @__PURE__ */new Map,e=e=>{t.getOrInsertComputed(e.pageIndex,H).push(e)};for(const i of this.#z.values())e(i);for(const[i,s]of this.#j)i.startsWith(o)&&!this.#z.has(i)&&Number.isInteger(s?.pageIndex)&&e(s)}endUpdatePages(){this.#U=null,this.#G=null}clonePage(t,e){for(const i of this.getEditors(t)){const t=i.serialize(i.mode!==l.HIGHLIGHT);t&&(t.pageIndex=e,t.id=this.getId(),t.isClone=!0,delete t.popupRef,this.#j.setValue(t.id,t))}}findClonesForPage(t){const e=[],{pageIndex:i}=t;for(const[s,n]of this.#j)n.pageIndex===i&&n.isClone&&(this.#j.remove(s),e.push(t.deserialize(n).then(e=>{e&&(e.isClone=!0,t.addOrRebuild(e))})));return Promise.all(e)}#Ht(t){Object.entries(t).some(([t,e])=>this.#_t[t]!==e)&&(this._eventBus.dispatch("editingstateschanged",{source:this,details:Object.assign(this.#_t,t)}),this.#vt===l.HIGHLIGHT&&!1===t.hasSelectedEditor&&this.#Yt([[h.HIGHLIGHT_FREE,!0]]))}#Yt(t){this._eventBus.dispatch("annotationeditorparamschanged",{source:this,details:t})}setEditingState(t){t?(this.#Gt(),this.#Vt(),this.#Ht({isEditing:this.#vt!==l.NONE,isEmpty:this.#qt(),hasSomethingToUndo:this.#$.hasSomethingToUndo(),hasSomethingToRedo:this.#$.hasSomethingToRedo(),hasSelectedEditor:!1})):(this.#Wt(),this.#$t(),this.#Ht({isEditing:!1}),this.disableUserSelect(!1))}registerEditorTypes(t){if(!this.#Z){this.#Z=t;for(const t of this.#Z)this.#Yt(t.defaultPropertiesToUpdate)}}getId(){return this.#ct.id}get currentLayer(){return this.#H.get(this.#q)}getLayer(t){return this.#H.get(t)}get currentPageIndex(){return this.#q}addLayer(t){this.#H.set(t.pageIndex,t),this.#dt?t.enable():t.disable()}removeLayer(t){this.#H.delete(t.pageIndex)}async updateMode(t,e=null,i=!1,s=!1,n=!1,r=!1){if(this.#vt!==t&&(!this.#It||(await this.#It.promise,this.#It))){if(this.#It=Promise.withResolvers(),this.#Y?.commitOrRemove(),this.#vt===l.POPUP&&this.#X?.hideSidebar(),this.#X?.destroyPopup(),this.#vt=t,t===l.NONE){this.setEditingState(!1),this.#Qt();for(const t of this.#z.values())t.hideStandaloneCommentButton();return this._editorUndoBar?.hide(),this.toggleComment(null),void this.#It.resolve()}for(const t of this.#z.values())t.addStandaloneCommentButton();t===l.SIGNATURE&&await(this.#xt?.loadSignatures()),i&&Mt.clearPointerType(),this.setEditingState(!0),await this.#Jt(),this.unselectAll();for(const e of this.#H.values())e.updateMode(t);if(t===l.POPUP){this.#N||=await this.#Tt.getAnnotationsByType(new Set(this.#Z.map(t=>t._editorType)));const t=/* @__PURE__ */new Set,e=[];for(const i of this.#z.values()){const{annotationElementId:s,hasComment:n,deleted:r}=i;s&&t.add(s),n&&!r&&e.push(i.getData())}for(const i of this.#N){const{id:s,popupRef:n,contentsObj:r}=i;n&&r?.str&&!t.has(s)&&!this.#Q.has(s)&&e.push(i)}this.#X?.showSidebar(e)}if(!e)return s&&this.addNewEditorFromKeyboard(),void this.#It.resolve();for(const t of this.#z.values())t.uid===e?(this.setSelected(t),r?t.editComment():n?t.enterInEditMode():t.focus()):t.unselect();this.#It.resolve()}}addNewEditorFromKeyboard(){this.currentLayer.canCreateNewEmptyEditor()&&this.currentLayer.addNewEditor()}updateToolbar(t){t.mode!==this.#vt&&this._eventBus.dispatch("switchannotationeditormode",{source:this,...t})}updateParams(t,e){if(this.#Z){switch(t){case h.CREATE:return void this.currentLayer.addNewEditor(e);case h.HIGHLIGHT_SHOW_ALL:this._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:{type:"highlight",action:"toggle_visibility"}}}),(this.#St||=/* @__PURE__ */new Map).set(t,e),this.showAllEditors("highlight",e)}if(this.hasSelection)for(const i of this.#wt)i.updateParams(t,e);else for(const i of this.#Z)i.updateDefaultParams(t,e)}}showAllEditors(t,e,i=!1){for(const s of this.#z.values())s.editorType===t&&s.show(e);(this.#St?.get(h.HIGHLIGHT_SHOW_ALL)??!0)!==e&&this.#Yt([[h.HIGHLIGHT_SHOW_ALL,e]])}enableWaiting(t=!1){if(this.#pt!==t){this.#pt=t;for(const e of this.#H.values())t?e.disableClick():e.enableClick(),e.div.classList.toggle("waiting",t)}}async#Jt(){if(!this.#dt){this.#dt=!0;const t=[];for(const e of this.#H.values())t.push(e.enable());await Promise.all(t);for(const e of this.#z.values())e.enable()}}#Qt(){if(this.unselectAll(),this.#dt){this.#dt=!1;for(const t of this.#H.values())t.disable();for(const t of this.#z.values())t.disable()}}*getEditors(t){for(const e of this.#z.values())e.pageIndex===t&&(yield e)}getEditor(t){return this.#z.get(t)}addEditor(t){this.#z.set(t.id,t)}removeEditor(t){t.div.contains(document.activeElement)&&(this.#rt&&clearTimeout(this.#rt),this.#rt=setTimeout(()=>{this.focusMainContainer(),this.#rt=null},0)),this.#z.delete(t.id),t.annotationElementId&&this.#bt?.delete(t.annotationElementId),this.unselect(t),t.annotationElementId&&this.#Q.has(t.annotationElementId)||this.#j?.remove(t.id)}addDeletedAnnotationElement(t){this.#Q.add(t.annotationElementId),this.addChangedExistingAnnotation(t),t.deleted=!0}isDeletedAnnotationElement(t){return this.#Q.has(t)}removeDeletedAnnotationElement(t){this.#Q.delete(t.annotationElementId),this.removeChangedExistingAnnotation(t),t.deleted=!1}#Xt(t){const e=this.#H.get(t.pageIndex);e?e.addOrRebuild(t):(this.addEditor(t),this.addToAnnotationStorage(t))}setActiveEditor(t){this.#O!==t&&(this.#O=t,t&&this.#Yt(t.propertiesToUpdate))}get#Zt(){let t=null;for(t of this.#wt);return t}updateUI(t){this.#Zt===t&&this.#Yt(t.propertiesToUpdate)}updateUIForDefaultProperties(t){this.#Yt(t.defaultPropertiesToUpdate)}toggleSelected(t){if(this.#wt.has(t))return this.#wt.delete(t),t.unselect(),void this.#Ht({hasSelectedEditor:this.hasSelection});this.#wt.add(t),t.select(),this.#Yt(t.propertiesToUpdate),this.#Ht({hasSelectedEditor:!0})}setSelected(t){this.updateToolbar({mode:t.mode,editId:t.uid}),this.#Y?.commitOrRemove();for(const e of this.#wt)e!==t&&e.unselect();this.#X?.destroyPopup(),this.#wt.clear(),this.#wt.add(t),t.select(),this.#Yt(t.propertiesToUpdate),this.#Ht({hasSelectedEditor:!0})}get firstSelectedEditor(){return this.#wt.values().next().value}unselect(t){t.unselect(),this.#wt.delete(t),this.#Ht({hasSelectedEditor:this.hasSelection})}get hasSelection(){return 0!==this.#wt.size}get isEnterHandled(){return 1===this.#wt.size&&this.firstSelectedEditor.isEnterHandled}undo(){this.#$.undo(),this.#Ht({hasSomethingToUndo:this.#$.hasSomethingToUndo(),hasSomethingToRedo:this.#$.hasSomethingToRedo(),isEmpty:this.#qt()}),this._editorUndoBar?.hide()}redo(){this.#$.redo(),this.#Ht({hasSomethingToUndo:this.#$.hasSomethingToUndo(),hasSomethingToRedo:this.#$.hasSomethingToRedo(),isEmpty:this.#qt()})}addCommands(t){this.#$.add(t),this.#Ht({hasSomethingToUndo:!0,hasSomethingToRedo:!1,isEmpty:this.#qt()})}cleanUndoStack(t){this.#$.cleanType(t)}#qt(){if(0===this.#z.size)return!0;if(1===this.#z.size)for(const t of this.#z.values())return t.isEmpty();return!1}delete(){this.commitOrRemove();const t=this.currentLayer?.endDrawingSession(!0);if(!this.hasSelection&&!t)return;const e=t?[t]:[...this.#wt],i=()=>{for(const t of e)this.#Xt(t)};this.addCommands({cmd:()=>{this._editorUndoBar?.show(i,1===e.length?e[0].editorType:e.length);for(const t of e)t.remove()},undo:i,mustExec:!0})}commitOrRemove(){this.#O?.commitOrRemove()}hasSomethingToControl(){return this.#O||this.hasSelection}#Kt(t){for(const e of this.#wt)e.unselect();this.#wt.clear();for(const e of t)e.isEmpty()||(this.#wt.add(e),e.select());this.#Ht({hasSelectedEditor:this.hasSelection})}selectAll(){for(const t of this.#wt)t.commit();this.#Kt(this.#z.values())}unselectAll(){if((!this.#O||(this.#O.commitOrRemove(),this.#vt===l.NONE))&&!this.#Y?.commitOrRemove()&&(this.#X?.destroyPopup(),this.hasSelection)){for(const t of this.#wt)t.unselect();this.#wt.clear(),this.#Ht({hasSelectedEditor:!1})}}translateSelectedEditors(t,e,i=!1){if(i||this.commitOrRemove(),!this.hasSelection)return;this.#kt[0]+=t,this.#kt[1]+=e;const[s,n]=this.#kt,r=[...this.#wt];this.#Et&&clearTimeout(this.#Et),this.#Et=setTimeout(()=>{this.#Et=null,this.#kt[0]=this.#kt[1]=0,this.addCommands({cmd:()=>{for(const t of r)this.#z.has(t.id)&&(t.translateInPage(s,n),t.translationDone())},undo:()=>{for(const t of r)this.#z.has(t.id)&&(t.translateInPage(-s,-n),t.translationDone())},mustExec:!1})},1e3);for(const a of r)a.translateInPage(t,e),a.translationDone()}setUpDragSession(){if(this.hasSelection){this.disableUserSelect(!0),this.#J=/* @__PURE__ */new Map;for(const t of this.#wt)this.#J.set(t,{savedX:t.x,savedY:t.y,savedPageIndex:t.pageIndex,newX:0,newY:0,newPageIndex:-1})}}endDragSession(){if(!this.#J)return!1;this.disableUserSelect(!1);const t=this.#J;this.#J=null;let e=!1;for(const[{x:s,y:n,pageIndex:r},a]of t)a.newX=s,a.newY=n,a.newPageIndex=r,e||=s!==a.savedX||n!==a.savedY||r!==a.savedPageIndex;if(!e)return!1;const i=(t,e,i,s)=>{if(this.#z.has(t.id)){const n=this.#H.get(s);n?t._setParentAndPosition(n,e,i):(t.pageIndex=s,t.x=e,t.y=i)}};return this.addCommands({cmd:()=>{for(const[e,{newX:s,newY:n,newPageIndex:r}]of t)i(e,s,n,r)},undo:()=>{for(const[e,{savedX:s,savedY:n,savedPageIndex:r}]of t)i(e,s,n,r)},mustExec:!0}),!0}dragSelectedEditors(t,e){if(this.#J)for(const i of this.#J.keys())i.drag(t,e)}rebuild(t){if(null===t.parent){const e=this.getLayer(t.pageIndex);e?(e.changeParent(t),e.addOrRebuild(t)):(this.addEditor(t),this.addToAnnotationStorage(t),t.rebuild())}else t.parent.addOrRebuild(t)}get isEditorHandlingKeyboard(){return this.getActive()?.shouldGetKeyboardEvents()||1===this.#wt.size&&this.firstSelectedEditor.shouldGetKeyboardEvents()}isActive(t){return this.#O===t}getActive(){return this.#O}getMode(){return this.#vt}isEditingMode(){return this.#vt!==l.NONE}get imageManager(){return T(this,"imageManager",new Dt)}getSelectionBoxes(t){if(!t)return null;const e=document.getSelection();for(let l=0,h=e.rangeCount;l<h;l++)if(!t.contains(e.getRangeAt(l).commonAncestorContainer))return null;const{x:i,y:s,width:n,height:r}=t.getBoundingClientRect();let a;switch(t.getAttribute("data-main-rotation")){case"90":a=(t,e,a,o)=>({x:(e-s)/r,y:1-(t+a-i)/n,width:o/r,height:a/n});break;case"180":a=(t,e,a,o)=>({x:1-(t+a-i)/n,y:1-(e+o-s)/r,width:a/n,height:o/r});break;case"270":a=(t,e,a,o)=>({x:1-(e+o-s)/r,y:(t-i)/n,width:o/r,height:a/n});break;default:a=(t,e,a,o)=>({x:(t-i)/n,y:(e-s)/r,width:a/n,height:o/r})}const o=[];for(let l=0,h=e.rangeCount;l<h;l++){const t=e.getRangeAt(l);if(!t.collapsed)for(const{x:e,y:i,width:s,height:n}of t.getClientRects())0!==s&&0!==n&&o.push(a(e,i,s,n))}return 0===o.length?null:o}addChangedExistingAnnotation({annotationElementId:t,id:e}){(this.#V||=/* @__PURE__ */new Map).set(t,e)}removeChangedExistingAnnotation({annotationElementId:t}){this.#V?.delete(t)}renderAnnotationElement(t){const e=this.#V?.get(t.data.id);if(!e)return;const i=this.#j.getRawValue(e);i&&(this.#vt!==l.NONE||i.hasBeenModified)&&i.renderAnnotationElement(t)}setMissingCanvas(t,e,i){const s=this.#bt?.get(t);s&&(s.setCanvas(e,i),this.#bt.delete(t))}addMissingCanvas(t,e){(this.#bt||=/* @__PURE__ */new Map).set(t,e)}},Rt=class t{#l=null;#te=!1;#ee=null;#ie=null;#se=null;#ne=null;#re=!1;#ae=null;#a=null;#oe=null;#le=null;#he=!1;static#ce=null;static _l10n=null;constructor(e){this.#a=e,this.#he=e._uiManager.useNewAltTextFlow,t.#ce||=Object.freeze({added:"pdfjs-editor-new-alt-text-added-button","added-label":"pdfjs-editor-new-alt-text-added-button-label",missing:"pdfjs-editor-new-alt-text-missing-button","missing-label":"pdfjs-editor-new-alt-text-missing-button-label",review:"pdfjs-editor-new-alt-text-to-review-button","review-label":"pdfjs-editor-new-alt-text-to-review-button-label"})}static initialize(e){t._l10n??=e}async render(){const e=this.#ee=document.createElement("button");e.className="altText",e.tabIndex="0";const i=this.#ie=document.createElement("span");e.append(i),this.#he?(e.classList.add("new"),e.setAttribute("data-l10n-id",t.#ce.missing),i.setAttribute("data-l10n-id",t.#ce["missing-label"])):(e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button"),i.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button-label"));const s=this.#a._uiManager._signal;e.addEventListener("contextmenu",bt,{signal:s}),e.addEventListener("pointerdown",t=>t.stopPropagation(),{signal:s});const n=t=>{t.preventDefault(),this.#a._uiManager.editAltText(this.#a),this.#he&&this.#a._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_clicked",data:{label:this.#de}})};return e.addEventListener("click",n,{capture:!0,signal:s}),e.addEventListener("keydown",t=>{t.target===e&&"Enter"===t.key&&(this.#re=!0,n(t))},{signal:s}),await this.#ue(),e}get#de(){return(this.#l?"added":null===this.#l&&this.guessedText&&"review")||"missing"}finish(){this.#ee&&(this.#ee.focus({focusVisible:this.#re}),this.#re=!1)}isEmpty(){return this.#he?null===this.#l:!this.#l&&!this.#te}hasData(){return this.#he?null!==this.#l||!!this.#oe:this.isEmpty()}get guessedText(){return this.#oe}async setGuessedText(e){null===this.#l&&(this.#oe=e,this.#le=await t._l10n.get("pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer",{generatedAltText:e}),this.#ue())}toggleAltTextBadge(t=!1){if(!this.#he||this.#l)return this.#ae?.remove(),void(this.#ae=null);if(!this.#ae){const t=this.#ae=document.createElement("div");t.className="noAltTextBadge",this.#a.div.append(t)}this.#ae.classList.toggle("hidden",!t)}serialize(t){let e=this.#l;return t||this.#oe!==e||(e=this.#le),{altText:e,decorative:this.#te,guessedText:this.#oe,textWithDisclaimer:this.#le}}get data(){return{altText:this.#l,decorative:this.#te}}set data({altText:t,decorative:e,guessedText:i,textWithDisclaimer:s,cancel:n=!1}){i&&(this.#oe=i,this.#le=s),this.#l===t&&this.#te===e||(n||(this.#l=t,this.#te=e),this.#ue())}toggle(t=!1){this.#ee&&(!t&&this.#ne&&(clearTimeout(this.#ne),this.#ne=null),this.#ee.disabled=!t)}shown(){this.#a._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_displayed",data:{label:this.#de}})}destroy(){this.#ee?.remove(),this.#ee=null,this.#ie=null,this.#se=null,this.#ae?.remove(),this.#ae=null}async#ue(){const e=this.#ee;if(!e)return;if(this.#he){if(e.classList.toggle("done",!!this.#l),e.setAttribute("data-l10n-id",t.#ce[this.#de]),this.#ie?.setAttribute("data-l10n-id",t.#ce[`${this.#de}-label`]),!this.#l)return void this.#se?.remove()}else{if(!this.#l&&!this.#te)return e.classList.remove("done"),void this.#se?.remove();e.classList.add("done"),e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-edit-button")}let i=this.#se;if(!i){this.#se=i=document.createElement("span"),i.className="tooltip",i.setAttribute("role","tooltip"),i.id=`alt-text-tooltip-${this.#a.id}`;const t=100,s=this.#a._uiManager._signal;s.addEventListener("abort",()=>{clearTimeout(this.#ne),this.#ne=null},{once:!0}),e.addEventListener("mouseenter",()=>{this.#ne=setTimeout(()=>{this.#ne=null,this.#se.classList.add("show"),this.#a._reportTelemetry({action:"alt_text_tooltip"})},t)},{signal:s}),e.addEventListener("mouseleave",()=>{this.#ne&&(clearTimeout(this.#ne),this.#ne=null),this.#se?.classList.remove("show")},{signal:s})}this.#te?i.setAttribute("data-l10n-id","pdfjs-editor-alt-text-decorative-tooltip"):(i.removeAttribute("data-l10n-id"),i.textContent=this.#l),i.parentNode||e.append(i),this.#a.getElementForAltText()?.setAttribute("aria-describedby",i.id)}},Ot=class{#pe=null;#ge=null;#me=!1;#a=null;#fe=null;#be=null;#ye=null;#ve=null;#we=!1;#Ae=null;constructor(t){this.#a=t}renderForToolbar(){const t=this.#ge=document.createElement("button");return t.className="comment",this.#v(t,!1)}renderForStandalone(){const t=this.#pe=document.createElement("button");t.className="annotationCommentButton";const e=this.#a.commentButtonPosition;if(e){const{style:i}=t;i.insetInlineEnd=`calc(${100*("ltr"===this.#a._uiManager.direction?1-e[0]:e[0])}% - var(--comment-button-dim))`,i.top=`calc(${100*e[1]}% - var(--comment-button-dim))`;const s=this.#a.commentButtonColor;s&&(i.backgroundColor=s)}return this.#v(t,!0)}focusButton(){setTimeout(()=>{(this.#pe??this.#ge)?.focus()},0)}onUpdatedColor(){if(!this.#pe)return;const t=this.#a.commentButtonColor;t&&(this.#pe.style.backgroundColor=t),this.#a._uiManager.updatePopupColor(this.#a)}get commentButtonWidth(){return(this.#pe?.getBoundingClientRect().width??0)/this.#a.parent.boundingClientRect.width}get commentPopupPositionInLayer(){if(this.#Ae)return this.#Ae;if(!this.#pe)return null;const{x:t,y:e,height:i}=this.#pe.getBoundingClientRect(),{x:s,y:n,width:r,height:a}=this.#a.parent.boundingClientRect;return[(t-s)/r,(e+i-n)/a]}set commentPopupPositionInLayer(t){this.#Ae=t}hasDefaultPopupPosition(){return null===this.#Ae}removeStandaloneCommentButton(){this.#pe?.remove(),this.#pe=null}removeToolbarCommentButton(){this.#ge?.remove(),this.#ge=null}setCommentButtonStates({selected:t,hasPopup:e}){this.#pe&&(this.#pe.classList.toggle("selected",t),this.#pe.ariaExpanded=e)}#v(t,e){if(!this.#a._uiManager.hasCommentManager())return null;t.tabIndex="0",t.ariaHasPopup="dialog",e?(t.ariaControls="commentPopup",t.setAttribute("data-l10n-id","pdfjs-show-comment-button")):(t.ariaControlsElements=[this.#a._uiManager.getCommentDialogElement()],t.setAttribute("data-l10n-id","pdfjs-editor-add-comment-button"));const i=this.#a._uiManager._signal;if(!(i instanceof AbortSignal)||i.aborted)return t;t.addEventListener("contextmenu",bt,{signal:i}),e&&(t.addEventListener("focusin",t=>{this.#a._focusEventsAllowed=!1,yt(t)},{capture:!0,signal:i}),t.addEventListener("focusout",t=>{this.#a._focusEventsAllowed=!0,yt(t)},{capture:!0,signal:i})),t.addEventListener("pointerdown",t=>t.stopPropagation(),{signal:i});const s=e=>{e.preventDefault(),t===this.#ge?this.edit():this.#a.toggleComment(!0)};return t.addEventListener("click",s,{capture:!0,signal:i}),t.addEventListener("keydown",e=>{e.target===t&&"Enter"===e.key&&(this.#me=!0,s(e))},{signal:i}),t.addEventListener("pointerenter",()=>{this.#a.toggleComment(!1,!0)},{signal:i}),t.addEventListener("pointerleave",()=>{this.#a.toggleComment(!1,!1)},{signal:i}),t}edit(t){const e=this.commentPopupPositionInLayer;let i,s;if(e)[i,s]=e;else{[i,s]=this.#a.commentButtonPosition;const{width:t,height:e,x:n,y:r}=this.#a;i=n+i*t,s=r+s*e}const n=this.#a.parent.boundingClientRect,{x:r,y:a,width:o,height:l}=n;this.#a._uiManager.editComment(this.#a,r+i*o,a+s*l,{...t,parentDimensions:n})}finish(){this.#ge&&(this.#ge.focus({focusVisible:this.#me}),this.#me=!1)}isDeleted(){return this.#we||""===this.#ye}isEmpty(){return null===this.#ye}hasBeenEdited(){return this.isDeleted()||this.#ye!==this.#fe}serialize(){return this.data}get data(){return{text:this.#ye,richText:this.#be,date:this.#ve,deleted:this.isDeleted()}}set data(t){if(t!==this.#ye&&(this.#be=null),null===t)return this.#ye="",void(this.#we=!0);this.#ye=t,this.#ve=/* @__PURE__ */new Date,this.#we=!1}restoreData({text:t,richText:e,date:i}){this.#ye=t,this.#be=e,this.#ve=i,this.#we=!1}setInitialText(t,e=null){this.#fe=t,this.data=t,this.#ve=null,this.#be=e}shown(){}destroy(){this.#ge?.remove(),this.#ge=null,this.#pe?.remove(),this.#pe=null,this.#ye="",this.#be=null,this.#ve=null,this.#a=null,this.#me=!1,this.#we=!1}};function Nt(t){t.preventDefault()}var zt=1e-4;function Ht(t){return t.cancelable?(yt(t),!0):(t.stopPropagation(),!1)}var Ut=class{#Mt;#xe=!1;#Ce=null;#Se;#Te;#_e;#ke;#Ee;#Me=!1;#Pe=null;#De;#Ie=/* @__PURE__ */new Set;#Fe=null;#Le;#Be=null;#Re=0;constructor({container:t,isPinchingDisabled:e=null,isPinchingStopped:i=null,onPinchStart:s=null,onPinching:n=null,onPinchEnd:r=null,onPanning:a=null,signal:o}){this.#Mt=t,this.#Ce=i,this.#Se=e,this.#Te=s,this.#_e=n,this.#ke=r,this.#Ee=a,this.#Le=new AbortController,this.#De=AbortSignal.any([o,this.#Le.signal]),t.addEventListener("touchstart",this.#Oe.bind(this),{passive:!1,signal:this.#De})}get MIN_TOUCH_DISTANCE_TO_PINCH(){return 35/Q.pixelRatio}get MIN_TOUCH_DISTANCE_TO_SCALE(){return 4/Q.pixelRatio}#Oe(t){if(this.#Se?.())return;this.#Ne(t);const e=this.#Ie;for(const{identifier:i}of t.changedTouches)e.add(i);if(1!==e.size){if(!this.#Be){this.#Be=new AbortController;const t=AbortSignal.any([this.#De,this.#Be.signal]),e=this.#Mt,i={signal:t,capture:!1,passive:!1};e.addEventListener("touchmove",this.#ze.bind(this),i);const s=this.#He.bind(this);e.addEventListener("touchend",s,i),e.addEventListener("touchcancel",s,i),i.capture=!0,e.addEventListener("pointerdown",yt,i),e.addEventListener("pointermove",yt,i),e.addEventListener("pointercancel",Nt,i),e.addEventListener("pointerup",Nt,i),this.#Te?.()}this.#Me=Ht(t),this.#Ue(t)}else this.#Ge()}#Ge(){if(this.#Pe)return;const t=this.#Pe=new AbortController,e=AbortSignal.any([this.#De,t.signal]),i=this.#Mt,s={capture:!0,signal:e,passive:!1},n=t=>{"touch"===t.pointerType&&(this.#Pe?.abort(),this.#Pe=null)};i.addEventListener("pointerdown",t=>{"touch"===t.pointerType&&(yt(t),n(t))},s),i.addEventListener("pointerup",n,s),i.addEventListener("pointercancel",n,s)}#Ne(t){const e=this.#Ie;if(0===e.size)return;const i=this.#Ie=/* @__PURE__ */new Set;for(const{identifier:s}of t.touches)e.has(s)&&i.add(s)}#We(t){const e=this.#Ie,i=[];for(const s of t.touches)e.has(s.identifier)&&i.push(s);return i}#Ue(t){const e=this.#We(t);if(2!==e.length||this.#Ce?.())return void(this.#Fe=null);const[i,s]=e;this.#Fe={touch0X:i.screenX,touch0Y:i.screenY,touch1X:s.screenX,touch1Y:s.screenY,panX:(i.clientX+s.clientX)/2,panY:(i.clientY+s.clientY)/2,screenPanX:(i.screenX+s.screenX)/2,screenPanY:(i.screenY+s.screenY)/2}}#ze(t){if(!this.#Fe)return;const e=this.#We(t);if(2!==e.length)return;const i=this.#Me;if(this.#Me=Ht(t),!this.#Me)return;if(!i)return void this.#Ue(t);const[s,n]=e,{screenX:r,screenY:a}=s,{screenX:o,screenY:l}=n,h=this.#Fe,{touch0X:c,touch0Y:d,touch1X:u,touch1Y:p,panX:g,panY:m}=h,f=u-c,b=p-d,y=o-r,v=l-a,w=(s.clientX+n.clientX)/2,A=(s.clientY+n.clientY)/2;h.panX=w,h.panY=A;const x=w-g,C=A-m,S=(r+o)/2,T=(a+l)/2,_=Math.hypot(S-h.screenPanX,T-h.screenPanY);h.screenPanX=S,h.screenPanY=T;const k=Math.hypot(y,v),E=Math.hypot(f,b),M=this.#xe?this.MIN_TOUCH_DISTANCE_TO_SCALE:this.MIN_TOUCH_DISTANCE_TO_PINCH+2*_;if(k<zt||E<zt||Math.abs(E-k)<=M)return void((x||C)&&this.#Ee?.(x,C));h.touch0X=r,h.touch0Y=a,h.touch1X=o,h.touch1Y=l;const P=Math.sign(k-E);if(!this.#xe)return this.#xe=!0,this.#Re=P,void((x||C)&&this.#Ee?.(x,C));if(this.#Re){const t=this.#Re;if(this.#Re=0,P!==t&&Math.abs(k-E)<=2*_)return this.#xe=!1,void((x||C)&&this.#Ee?.(x,C))}this.#_e?.([g,m],E,k,x,C)}#He(t){if(this.#Ne(t),this.#Ie.size>=2)return void this.#Ue(t);const e=!!this.#Fe;this.#je(),1===this.#Ie.size&&this.#Ge(),e&&Ht(t)}#je(){this.#Fe=null,this.#xe=!1,this.#Re=0,this.#Me=!1,this.#Be&&(this.#Be.abort(),this.#Be=null,this.#ke?.())}destroy(){this.#je(),this.#Ie.clear(),this.#Le?.abort(),this.#Le=null,this.#Pe?.abort(),this.#Pe=null}},Gt=class t{#Ve=null;#$e=null;#l=null;#h=null;#pe=null;#Xe=!1;#Ke=null;#Ye="";#qe=null;#Qe=null;#Je=null;#Ze=null;#ti=null;#ei="";#ii=!1;#si=null;#ni=!1;#ri=!1;#ai=!1;#oi=null;#li=0;#hi=0;#ci=null;#di=null;isSelected=!1;_isCopy=!1;_editToolbar=null;_initialOptions=Object.create(null);_initialData=null;_isVisible=!0;_uiManager=null;_focusEventsAllowed=!0;static _l10n=null;static _l10nAlert=null;static _l10nResizer=null;#ui=!1;#pi=t._zIndex++;static _borderLineWidth=-1;static _colorManager=new Lt;static _zIndex=1;static _telemetryTimeout=1e3;static get _resizerKeyboardManager(){const e=t.prototype._resizeWithKeyboard,i=Bt.TRANSLATE_SMALL,s=Bt.TRANSLATE_BIG;return T(this,"_resizerKeyboardManager",new Ft([[["ArrowLeft"],e,{args:[-i,0]}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],e,{args:[-s,0]}],[["ArrowRight"],e,{args:[i,0]}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],e,{args:[s,0]}],[["ArrowUp"],e,{args:[0,-i]}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],e,{args:[0,-s]}],[["ArrowDown"],e,{args:[0,i]}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],e,{args:[0,s]}],[["Escape"],t.prototype._stopResizingWithKeyboard]]))}constructor(t){this.parent=t.parent,this.id=t.id,this.width=this.height=null,this.pageIndex=t.parent.pageIndex,this.name=t.name,this.div=null,this._uiManager=t.uiManager,this.annotationElementId=null,this._willKeepAspectRatio=!1,this._initialOptions.isCentered=t.isCentered,this._structTreeParentId=null,this.annotationElementId=t.annotationElementId||null,this.creationDate=t.creationDate||/* @__PURE__ */new Date,this.modificationDate=t.modificationDate||null,this.canAddComment=!0;const{rotation:e,rawDims:{pageWidth:i,pageHeight:s,pageX:n,pageY:r}}=this.parent.viewport;this.rotation=e,this.pageRotation=(360+e-this._uiManager.viewParameters.rotation)%360,this.pageDimensions=[i,s],this.pageTranslation=[n,r];const[a,o]=this.parentDimensions;this.x=t.x/a,this.y=t.y/o,this.isAttachedToDOM=!1,this.deleted=!1}updatePageIndex(t){this.pageIndex=t}get editorType(){return Object.getPrototypeOf(this).constructor._type}get mode(){return Object.getPrototypeOf(this).constructor._editorType}static get isDrawer(){return!1}static get _defaultLineColor(){return T(this,"_defaultLineColor",this._colorManager.getHexCode("CanvasText"))}static deleteAnnotationElement(t){const e=new Wt({id:t._uiManager.getId(),parent:t.parent,uiManager:t._uiManager});e.annotationElementId=t.annotationElementId,e.deleted=!0,e._uiManager.addToAnnotationStorage(e)}static initialize(e,i){if(t._l10n??=e,t._l10nAlert??=Object.freeze({highlight:"pdfjs-editor-highlight-added-alert",freetext:"pdfjs-editor-freetext-added-alert",ink:"pdfjs-editor-ink-added-alert",stamp:"pdfjs-editor-stamp-added-alert",signature:"pdfjs-editor-signature-added-alert"}),t._l10nResizer??=Object.freeze({topLeft:"pdfjs-editor-resizer-top-left",topMiddle:"pdfjs-editor-resizer-top-middle",topRight:"pdfjs-editor-resizer-top-right",middleRight:"pdfjs-editor-resizer-middle-right",bottomRight:"pdfjs-editor-resizer-bottom-right",bottomMiddle:"pdfjs-editor-resizer-bottom-middle",bottomLeft:"pdfjs-editor-resizer-bottom-left",middleLeft:"pdfjs-editor-resizer-middle-left"}),-1!==t._borderLineWidth)return;const s=getComputedStyle(document.documentElement);t._borderLineWidth=parseFloat(s.getPropertyValue("--outline-width"))||0}static updateDefaultParams(t,e){}static get defaultPropertiesToUpdate(){return[]}static isHandlingMimeForPasting(t){return!1}static paste(t,e){w("Not implemented")}get propertiesToUpdate(){return[]}get _isDraggable(){return this.#ui}set _isDraggable(t){this.#ui=t,this.div?.classList.toggle("draggable",t)}get uid(){return this.annotationElementId||this.id}get isEnterHandled(){return!0}center(){const[t,e]=this.pageDimensions;switch(this.parentRotation){case 90:this.x-=this.height*e/(2*t),this.y+=this.width*t/(2*e);break;case 180:this.x+=this.width/2,this.y+=this.height/2;break;case 270:this.x+=this.height*e/(2*t),this.y-=this.width*t/(2*e);break;default:this.x-=this.width/2,this.y-=this.height/2}this.fixAndSetPosition()}addCommands(t){this._uiManager.addCommands(t)}get currentLayer(){return this._uiManager.currentLayer}setInBackground(){this.div.style.zIndex=0}setInForeground(){this.div.style.zIndex=this.#pi}setParent(t){null!==t?(this.pageIndex=t.pageIndex,this.pageDimensions=t.pageDimensions):(this.#gi(),this.#Ze?.remove(),this.#Ze=null),this.parent=t}focusin(t){this._focusEventsAllowed&&(this.#ii?this.#ii=!1:this.parent.setSelected(this))}focusout(t){this._focusEventsAllowed&&this.isAttachedToDOM&&(t.relatedTarget?.closest(`#${this.id}`)||(t.preventDefault(),this.parent?.isMultipleSelection||this.commitOrRemove()))}commitOrRemove(){this.isEmpty()?this.remove():this.commit()}commit(){this.isInEditMode()&&this.addToAnnotationStorage()}addToAnnotationStorage(){this._uiManager.addToAnnotationStorage(this)}setAt(t,e,i,s){const[n,r]=this.parentDimensions;[i,s]=this.screenToPageTranslation(i,s),this.x=(t+i)/n,this.y=(e+s)/r,this.fixAndSetPosition()}_moveAfterPaste(t,e){if(this.isClone)return void delete this.isClone;const[i,s]=this.parentDimensions;this.setAt(t*i,e*s,this.width*i,this.height*s),this._onTranslated()}#mi([t,e],i,s){[i,s]=this.screenToPageTranslation(i,s),this.x+=i/t,this.y+=s/e,this._onTranslating(this.x,this.y),this.fixAndSetPosition()}translate(t,e){this.#mi(this.parentDimensions,t,e)}translateInPage(t,e){this.#si||=[this.x,this.y,this.width,this.height],this.#mi(this.pageDimensions,t,e),this.div.scrollIntoView({block:"nearest"})}translationDone(){this._onTranslated(this.x,this.y)}drag(t,e){this.#si||=[this.x,this.y,this.width,this.height];const{div:i,parentDimensions:[s,n]}=this;if(this.x+=t/s,this.y+=e/n,this.parent&&(this.x<0||this.x>1||this.y<0||this.y>1)){const{x:t,y:e}=this.div.getBoundingClientRect();this.parent.findNewParent(this,t,e)&&(this.x-=Math.floor(this.x),this.y-=Math.floor(this.y))}let{x:r,y:a}=this;const[o,l]=this.getBaseTranslation();r+=o,a+=l;const{style:h}=i;h.left=`${(100*r).toFixed(2)}%`,h.top=`${(100*a).toFixed(2)}%`,this._onTranslating(r,a)}_onTranslating(t,e){}_onTranslated(t,e){}get _hasBeenMoved(){return!!this.#si&&(this.#si[0]!==this.x||this.#si[1]!==this.y)}get _hasBeenResized(){return!!this.#si&&(this.#si[2]!==this.width||this.#si[3]!==this.height)}getBaseTranslation(){const[e,i]=this.parentDimensions,{_borderLineWidth:s}=t,n=s/e,r=s/i;switch(this.rotation){case 90:return[-n,r];case 180:return[n,r];case 270:return[n,-r];default:return[-n,-r]}}get _mustFixPosition(){return!0}fixAndSetPosition(e=this.rotation){const{div:{style:i},pageDimensions:[s,n]}=this;let{x:r,y:a,width:o,height:l}=this;o*=s,l*=n,r*=s,a*=n;let h=0,c=0;const d=this._uiManager._keepToolbarInPage&&this._editToolbar?.div;if(d?.offsetParent){const i=this.parentScale,u=d.offsetLeft+this.div.clientLeft,p=d.offsetTop+this.div.clientTop,g=Math.min(0,u)/i,m=Math.min(0,p)/i,f=o-g+Math.max(0,u+d.offsetWidth-this.div.offsetWidth)/i,b=l-m+Math.max(0,p+d.offsetHeight-this.div.offsetHeight)/i;f<=(e%180?n:s)&&(o=f,h=g),b<=(e%180?s:n)&&(l=b,c=m),[h,c]=t.#fi(h,c,e),r+=h,a+=c}if(this._mustFixPosition)switch(e){case 0:r=j(r,0,s-o),a=j(a,0,n-l);break;case 90:r=j(r,0,s-l),a=j(a,o,n);break;case 180:r=j(r,o,s),a=j(a,l,n);break;case 270:r=j(r,l,s),a=j(a,0,n-o)}this.x=r=(r-h)/s,this.y=a=(a-c)/n;const[u,p]=this.getBaseTranslation();r+=u,a+=p,i.left=`${(100*r).toFixed(2)}%`,i.top=`${(100*a).toFixed(2)}%`,this.moveInDOM()}static#fi(t,e,i){switch(i){case 90:return[e,-t];case 180:return[-t,-e];case 270:return[-e,t];default:return[t,e]}}screenToPageTranslation(e,i){return t.#fi(e,i,this.parentRotation)}pageTranslationToScreen(e,i){return t.#fi(e,i,360-this.parentRotation)}#bi(t){switch(t){case 90:{const[t,e]=this.pageDimensions;return[0,-t/e,e/t,0]}case 180:return[-1,0,0,-1];case 270:{const[t,e]=this.pageDimensions;return[0,t/e,-e/t,0]}default:return[1,0,0,1]}}get parentScale(){return this._uiManager.viewParameters.realScale}get parentRotation(){return(this._uiManager.viewParameters.rotation+this.pageRotation)%360}get parentDimensions(){const{parentScale:t,pageDimensions:[e,i]}=this;return[e*t,i*t]}setDims(){const{div:{style:t},width:e,height:i}=this;t.width=`${(100*e).toFixed(2)}%`,t.height=`${(100*i).toFixed(2)}%`}getInitialTranslation(){return[0,0]}#yi(){if(this.#qe)return;this.#qe=document.createElement("div"),this.#qe.classList.add("resizers");const t=this._willKeepAspectRatio?["topLeft","topRight","bottomRight","bottomLeft"]:["topLeft","topMiddle","topRight","middleRight","bottomRight","bottomMiddle","bottomLeft","middleLeft"],e=this._uiManager._signal;for(const i of t){const t=document.createElement("div");this.#qe.append(t),t.classList.add("resizer",i),t.setAttribute("data-resizer-name",i),t.addEventListener("pointerdown",this.#vi.bind(this,i),{signal:e}),t.addEventListener("contextmenu",bt,{signal:e}),t.tabIndex=-1}this.div.prepend(this.#qe)}#vi(t,e){e.preventDefault();const{isMac:i}=L.platform;if(0!==e.button||e.ctrlKey&&i)return;this.#l?.toggle(!1);const s=this._isDraggable;this._isDraggable=!1,this.#Qe=[e.screenX,e.screenY];const n=new AbortController,r=this._uiManager.combinedSignal(n);this.parent.togglePointerEvents(!1),window.addEventListener("pointermove",this.#wi.bind(this,t),{passive:!0,capture:!0,signal:r}),window.addEventListener("touchmove",yt,{passive:!1,signal:r}),window.addEventListener("contextmenu",bt,{signal:r}),this.#Je={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height};const a=this.parent.div.style.cursor,o=this.div.style.cursor;this.div.style.cursor=this.parent.div.style.cursor=window.getComputedStyle(e.target).cursor;const l=()=>{n.abort(),this.parent.togglePointerEvents(!0),this.#l?.toggle(!0),this._isDraggable=s,this.parent.div.style.cursor=a,this.div.style.cursor=o,this.#Ai()};window.addEventListener("pointerup",l,{signal:r}),window.addEventListener("blur",l,{signal:r})}#xi(t,e,i,s){this.width=i,this.height=s,this.x=t,this.y=e,this.setDims(),this.fixAndSetPosition(),this._onResized()}_onResized(){}#Ai(){if(!this.#Je)return;const{savedX:t,savedY:e,savedWidth:i,savedHeight:s}=this.#Je;this.#Je=null;const n=this.x,r=this.y,a=this.width,o=this.height;n===t&&r===e&&a===i&&o===s||this.addCommands({cmd:this.#xi.bind(this,n,r,a,o),undo:this.#xi.bind(this,t,e,i,s),mustExec:!0})}static _round(t){return Math.round(1e4*t)/1e4}#wi(e,i){const[s,n]=this.parentDimensions,r=this.x,a=this.y,o=this.width,l=this.height,h=t.MIN_SIZE/s,c=t.MIN_SIZE/n,d=this.#bi(this.rotation),u=(t,e)=>[d[0]*t+d[2]*e,d[1]*t+d[3]*e],p=this.#bi(360-this.rotation);let g,m,f=!1,b=!1;switch(e){case"topLeft":f=!0,g=(t,e)=>[0,0],m=(t,e)=>[t,e];break;case"topMiddle":g=(t,e)=>[t/2,0],m=(t,e)=>[t/2,e];break;case"topRight":f=!0,g=(t,e)=>[t,0],m=(t,e)=>[0,e];break;case"middleRight":b=!0,g=(t,e)=>[t,e/2],m=(t,e)=>[0,e/2];break;case"bottomRight":f=!0,g=(t,e)=>[t,e],m=(t,e)=>[0,0];break;case"bottomMiddle":g=(t,e)=>[t/2,e],m=(t,e)=>[t/2,0];break;case"bottomLeft":f=!0,g=(t,e)=>[0,e],m=(t,e)=>[t,0];break;case"middleLeft":b=!0,g=(t,e)=>[0,e/2],m=(t,e)=>[t,e/2]}const y=g(o,l),v=m(o,l);let w=u(...v);const A=t._round(r+w[0]),x=t._round(a+w[1]);let C,S,T=1,_=1;if(i.fromKeyboard)({deltaX:C,deltaY:S}=i);else{const{screenX:t,screenY:e}=i,[s,n]=this.#Qe;[C,S]=this.screenToPageTranslation(t-s,e-n),this.#Qe[0]=t,this.#Qe[1]=e}var k,E;if([C,S]=(k=C/s,E=S/n,[p[0]*k+p[2]*E,p[1]*k+p[3]*E]),f){const t=Math.hypot(o,l);T=_=Math.max(Math.min(Math.hypot(v[0]-y[0]-C,v[1]-y[1]-S)/t,1/o,1/l),h/o,c/l)}else b?T=j(Math.abs(v[0]-y[0]-C),h,1)/o:_=j(Math.abs(v[1]-y[1]-S),c,1)/l;const M=t._round(o*T),P=t._round(l*_);w=u(...m(M,P));const D=A-w[0],I=x-w[1];this.#si||=[this.x,this.y,this.width,this.height],this.width=M,this.height=P,this.x=D,this.y=I,this.setDims(),this.fixAndSetPosition(),this._onResizing()}_onResizing(){}altTextFinish(){this.#l?.finish()}get toolbarButtons(){return null}async addEditToolbar(){if(this._editToolbar||this.#ri)return this._editToolbar;this._editToolbar=new Tt(this),this.div.append(this._editToolbar.render());const{toolbarButtons:t}=this;if(t)for(const[e,i]of t)await this._editToolbar.addButton(e,i);return this.hasComment||this._editToolbar.addButton("comment",this.addCommentButton()),this._editToolbar.addButton("delete"),this._editToolbar}addCommentButtonInToolbar(){this._editToolbar?.addButtonBefore("comment",this.addCommentButton(),".deleteButton")}removeCommentButtonFromToolbar(){this._editToolbar?.removeButton("comment")}removeEditToolbar(){this._editToolbar?.remove(),this._editToolbar=null,this.#l?.destroy()}addContainer(t){const e=this._editToolbar?.div;e?e.before(t):this.div.append(t)}getClientDimensions(){return this.div.getBoundingClientRect()}createAltText(){return this.#l||(Rt.initialize(t._l10n),this.#l=new Rt(this),this.#Ve&&(this.#l.data=this.#Ve,this.#Ve=null)),this.#l}get altTextData(){return this.#l?.data}set altTextData(t){this.#l&&(this.#l.data=t)}get guessedAltText(){return this.#l?.guessedText}async setGuessedAltText(t){await(this.#l?.setGuessedText(t))}serializeAltText(t){return this.#l?.serialize(t)}hasAltText(){return!!this.#l&&!this.#l.isEmpty()}hasAltTextData(){return this.#l?.hasData()??!1}focusCommentButton(){this.#h?.focusButton()}addCommentButton(){return this.canAddComment?this.#h||=new Ot(this):null}addStandaloneCommentButton(){this._uiManager.hasCommentManager()&&(this.#pe?this._uiManager.isEditingMode()&&this.#pe.classList.remove("hidden"):this.hasComment&&(this.#pe=this.#h.renderForStandalone(),this.div.append(this.#pe)))}removeStandaloneCommentButton(){this.#h.removeStandaloneCommentButton(),this.#pe=null}hideStandaloneCommentButton(){this.#pe?.classList.add("hidden")}get comment(){if(!this.#h)return null;const{data:{richText:t,text:e,date:i,deleted:s}}=this.#h;return{text:e,richText:t,date:i,deleted:s,color:this.getNonHCMColor(),opacity:this.opacity??1}}set comment(t){this.#h||=new Ot(this),"object"==typeof t&&null!==t?this.#h.restoreData(t):this.#h.data=t,this.hasComment?(this.removeCommentButtonFromToolbar(),this.addStandaloneCommentButton(),this._uiManager.updateComment(this)):(this.addCommentButtonInToolbar(),this.removeStandaloneCommentButton(),this._uiManager.removeComment(this))}setCommentData({comment:t,popupRef:e,richText:i}){if(!e)return;if(this.#h||=new Ot(this),this.#h.setInitialText(t,i),!this.annotationElementId)return;const s=this._uiManager.getAndRemoveDataFromAnnotationStorage(this.annotationElementId);s&&this.updateFromAnnotationLayer(s)}get hasEditedComment(){return this.#h?.hasBeenEdited()}get hasDeletedComment(){return this.#h?.isDeleted()}get hasComment(){return!!this.#h&&!this.#h.isEmpty()&&!this.#h.isDeleted()}async editComment(t){this.#h||=new Ot(this),this.#h.edit(t)}toggleComment(t,e=void 0){this.hasComment&&this._uiManager.toggleComment(this,t,e)}setSelectedCommentButton(t){this.#h.setSelectedButton(t)}addComment(t){if(this.hasEditedComment){const e=180,i=100,[,,,s]=t.rect,[n]=this.pageDimensions,[r]=this.pageTranslation,a=r+n+1,o=s-i,l=a+e;t.popup={contents:this.comment.text,deleted:this.comment.deleted,rect:[a,o,l,s]}}}updateFromAnnotationLayer({popup:{contents:t,deleted:e}}){this.#h.data=e?null:t}get parentBoundingClientRect(){return this.parent.boundingClientRect}render(){const t=this.div=document.createElement("div");t.setAttribute("data-editor-rotation",(360-this.rotation)%360),t.className=this.name,t.setAttribute("id",this.id),t.tabIndex=this.#Xe?-1:0,t.setAttribute("role","application"),this.defaultL10nId&&t.setAttribute("data-l10n-id",this.defaultL10nId),this._isVisible||t.classList.add("hidden"),this.setInForeground(),this.#Ci();const[e,i]=this.parentDimensions;this.parentRotation%180!=0&&(t.style.maxWidth=`${(100*i/e).toFixed(2)}%`,t.style.maxHeight=`${(100*e/i).toFixed(2)}%`);const[s,n]=this.getInitialTranslation();return this.translate(s,n),Et(this,t,["keydown","pointerdown","dblclick"]),this.#Si(),this.addStandaloneCommentButton(),this._uiManager._editorUndoBar?.hide(),t}#Ti(){this.#Je={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height},this.#l?.toggle(!1),this.parent.togglePointerEvents(!1)}#_i(e,i,s){let n=s/i*.7+1-.7;if(1===n)return;const r=this.#bi(this.rotation),a=(t,e)=>[r[0]*t+r[2]*e,r[1]*t+r[3]*e],[o,l]=this.parentDimensions,h=this.x,c=this.y,d=this.width,u=this.height,p=t.MIN_SIZE/o,g=t.MIN_SIZE/l;n=Math.max(Math.min(n,1/d,1/u),p/d,g/u);const m=t._round(d*n),f=t._round(u*n);if(m===d&&f===u)return;this.#si||=[h,c,d,u];const b=a(d/2,u/2),y=t._round(h+b[0]),v=t._round(c+b[1]),w=a(m/2,f/2);this.x=y-w[0],this.y=v-w[1],this.width=m,this.height=f,this.setDims(),this.fixAndSetPosition(),this._onResizing()}#ki(){this.#l?.toggle(!0),this.parent.togglePointerEvents(!0),this.#Ai()}pointerdown(t){const{isMac:e}=L.platform;0!==t.button||t.ctrlKey&&e?t.preventDefault():(this.#ii=!0,this._isDraggable?this.#Ei(t):this.#Mi(t))}#Mi(t){const{isMac:e}=L.platform;t.ctrlKey&&!e||t.shiftKey||t.metaKey&&e?this.parent.toggleSelected(this):this.parent.setSelected(this)}#Ei(t){const{isSelected:e}=this;this._uiManager.setUpDragSession();let i=!1;const s=new AbortController,n=this._uiManager.combinedSignal(s),r={capture:!0,passive:!1,signal:n},a=t=>{s.abort(),this.#Ke=null,this.#ii=!1,this._uiManager.endDragSession()||this.#Mi(t),i&&this._onStopDragging()};e&&(this.#li=t.clientX,this.#hi=t.clientY,this.#Ke=t.pointerId,this.#Ye=t.pointerType,window.addEventListener("pointermove",t=>{i||(i=!0,this._uiManager.toggleComment(this,!0,!1),this._onStartDragging());const{clientX:e,clientY:s,pointerId:n}=t;if(n!==this.#Ke)return void yt(t);const[r,a]=this.screenToPageTranslation(e-this.#li,s-this.#hi);this.#li=e,this.#hi=s,this._uiManager.dragSelectedEditors(r,a),this.div.scrollIntoView({block:"nearest"})},r),window.addEventListener("touchmove",yt,r),window.addEventListener("pointerdown",t=>{t.pointerType===this.#Ye&&(this.#di||t.isPrimary)&&a(t),yt(t)},r));const o=t=>{this.#Ke&&this.#Ke!==t.pointerId?yt(t):a(t)};window.addEventListener("pointerup",o,{signal:n}),window.addEventListener("blur",o,{signal:n})}_onStartDragging(){}_onStopDragging(){}moveInDOM(){this.#oi&&clearTimeout(this.#oi),this.#oi=setTimeout(()=>{this.#oi=null,this.parent?.moveEditorInDOM(this)},0)}_setParentAndPosition(t,e,i){t.changeParent(this),this.x=e,this.y=i,this.fixAndSetPosition(),this._onTranslated()}getRect(t,e,i=this.rotation){const s=this.parentScale,[n,r]=this.pageDimensions,[a,o]=this.pageTranslation,l=t/s,h=e/s,c=this.x*n,d=this.y*r,u=this.width*n,p=this.height*r;switch(i){case 0:return[c+l+a,r-d-h-p+o,c+l+u+a,r-d-h+o];case 90:return[c+h+a,r-d+l+o,c+h+p+a,r-d+l+u+o];case 180:return[c-l-u+a,r-d+h+o,c-l+a,r-d+h+p+o];case 270:return[c-h-p+a,r-d-l-u+o,c-h+a,r-d-l+o];default:throw new Error("Invalid rotation")}}getRectInCurrentCoords(t,e){const[i,s,n,r]=t,a=n-i,o=r-s;switch(this.rotation){case 0:return[i,e-r,a,o];case 90:return[i,e-s,o,a];case 180:return[n,e-s,a,o];case 270:return[n,e-r,o,a];default:throw new Error("Invalid rotation")}}getPDFRect(){return this.getRect(0,0)}getNonHCMColor(){return this.color&&t._colorManager.convert(this._uiManager.getNonHCMColor(this.color))}onUpdatedColor(){this.#h?.onUpdatedColor()}getData(){const{comment:{text:t,color:e,date:i,opacity:s,deleted:n,richText:r},uid:a,pageIndex:o,creationDate:l,modificationDate:h}=this;return{id:a,pageIndex:o,rect:this.getPDFRect(),richText:r,contentsObj:{str:t},creationDate:l,modificationDate:i||h,popupRef:!n,color:e,opacity:s}}onceAdded(t){}isEmpty(){return!1}enableEditMode(){return!this.isInEditMode()&&(this.parent.setEditingState(!1),this.#ri=!0,!0)}disableEditMode(){return!!this.isInEditMode()&&(this.parent.setEditingState(!0),this.#ri=!1,!0)}isInEditMode(){return this.#ri}shouldGetKeyboardEvents(){return this.#ai}needsToBeRebuilt(){return this.div&&!this.isAttachedToDOM}get isOnScreen(){const{top:t,left:e,bottom:i,right:s}=this.getClientDimensions(),{innerHeight:n,innerWidth:r}=window;return e<r&&s>0&&t<n&&i>0}#Ci(){if(this.#ti||!this.div)return;this.#ti=new AbortController;const t=this._uiManager.combinedSignal(this.#ti);this.div.addEventListener("focusin",this.focusin.bind(this),{signal:t}),this.div.addEventListener("focusout",this.focusout.bind(this),{signal:t})}#Si(){!this.#di&&this.div&&this.isResizable&&this._uiManager._supportsPinchToZoom&&(this.#di=new Ut({container:this.div,isPinchingDisabled:()=>!this.isSelected,onPinchStart:this.#Ti.bind(this),onPinching:this.#_i.bind(this),onPinchEnd:this.#ki.bind(this),signal:this._uiManager._signal}))}rebuild(){this.#Ci(),this.#Si()}rotate(t){}resize(){}serializeDeleted(){return{id:this.annotationElementId,deleted:!0,pageIndex:this.pageIndex,popupRef:this._initialData?.popupRef||""}}serialize(t=!1,e=null){return{annotationType:this.mode,pageIndex:this.pageIndex,rect:this.getPDFRect(),rotation:this.rotation,structTreeParentId:this._structTreeParentId,popupRef:this._initialData?.popupRef||""}}static async deserialize(t,e,i){const s=new this.prototype.constructor({parent:e,id:i.getId(),uiManager:i,annotationElementId:t.annotationElementId,creationDate:t.creationDate,modificationDate:t.modificationDate});s.rotation=t.rotation,s.#Ve=t.accessibilityData,s._isCopy=t.isCopy||!1;const[n,r]=s.pageDimensions,[a,o,l,h]=s.getRectInCurrentCoords(t.rect,r);return s.x=a/n,s.y=o/r,s.width=l/n,s.height=h/r,s}get hasBeenModified(){return!!this.annotationElementId&&(this.deleted||null!==this.serialize())}remove(){if(this.#ti?.abort(),this.#ti=null,this.isEmpty()||this.commit(),this.#di?.destroy(),this.#di=null,this.parent?this.parent.remove(this):this._uiManager.removeEditor(this),this.hideCommentPopup(),this.#oi&&(clearTimeout(this.#oi),this.#oi=null),this.#gi(),this.removeEditToolbar(),this.#ci){for(const t of this.#ci.values())clearTimeout(t);this.#ci=null}this.parent=null,this.#Ze?.remove(),this.#Ze=null}get isResizable(){return!1}makeResizable(){this.isResizable&&(this.#yi(),this.#qe.classList.remove("hidden"))}get toolbarPosition(){return null}get commentButtonPosition(){return"ltr"===this._uiManager.direction?[1,0]:[0,0]}get commentButtonPositionInPage(){const{commentButtonPosition:[e,i]}=this,[s,n,r,a]=this.getPDFRect();return[t._round(s+(r-s)*e),t._round(n+(a-n)*(1-i))]}get commentButtonColor(){return this._uiManager.makeCommentColor(this.getNonHCMColor(),this.opacity)}get commentPopupPosition(){return this.#h.commentPopupPositionInLayer}set commentPopupPosition(t){this.#h.commentPopupPositionInLayer=t}hasDefaultPopupPosition(){return this.#h.hasDefaultPopupPosition()}get commentButtonWidth(){return this.#h.commentButtonWidth}get elementBeforePopup(){return this.div}setCommentButtonStates(t){this.#h?.setCommentButtonStates(t)}keydown(e){if(!this.isResizable||e.target!==this.div||"Enter"!==e.key)return;this._uiManager.setSelected(this),this.#Je={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height};const i=this.#qe.children;if(!this.#$e){this.#$e=Array.from(i);const e=this.#Pi.bind(this),s=this.#Di.bind(this),n=this._uiManager._signal;for(const i of this.#$e){const r=i.getAttribute("data-resizer-name");i.setAttribute("role","spinbutton"),i.addEventListener("keydown",e,{signal:n}),i.addEventListener("blur",s,{signal:n}),i.addEventListener("focus",this.#Ii.bind(this,r),{signal:n}),i.setAttribute("data-l10n-id",t._l10nResizer[r])}}const s=this.#$e[0];let n=0;for(const t of i){if(t===s)break;n++}const r=(360-this.rotation+this.parentRotation)%360/90*(this.#$e.length/4);if(r!==n){if(r<n)for(let t=0;t<n-r;t++)this.#qe.append(this.#qe.firstElementChild);else if(r>n)for(let t=0;t<r-n;t++)this.#qe.firstElementChild.before(this.#qe.lastElementChild);let e=0;for(const s of i){const i=this.#$e[e++].getAttribute("data-resizer-name");s.setAttribute("data-l10n-id",t._l10nResizer[i])}}this.#Fi(0),this.#ai=!0,this.#qe.firstElementChild.focus({focusVisible:!0}),e.preventDefault(),e.stopImmediatePropagation()}#Pi(e){t._resizerKeyboardManager.exec(this,e)}#Di(t){this.#ai&&t.relatedTarget?.parentNode!==this.#qe&&this.#gi()}#Ii(t){this.#ei=this.#ai?t:""}#Fi(t){if(this.#$e)for(const e of this.#$e)e.tabIndex=t}_resizeWithKeyboard(t,e){this.#ai&&this.#wi(this.#ei,{deltaX:t,deltaY:e,fromKeyboard:!0})}#gi(){this.#ai=!1,this.#Fi(-1),this.#Ai()}_stopResizingWithKeyboard(){this.#gi(),this.div.focus()}select(){this.isSelected&&this._editToolbar?this._editToolbar.show():(this.isSelected=!0,this.makeResizable(),this.div?.classList.add("selectedEditor"),this._editToolbar?(this.#Li(),this.#l?.toggleAltTextBadge(!1)):this.addEditToolbar().then(()=>{this.div?.classList.contains("selectedEditor")&&this.#Li()}))}#Li(){this._editToolbar?.show(),this._uiManager._keepToolbarInPage&&(this.fixAndSetPosition(),this._onTranslated())}focus(){this.div&&!this.div.contains(document.activeElement)&&setTimeout(()=>this.div?.focus({preventScroll:!0}),0)}unselect(){this.isSelected&&(this.isSelected=!1,this.#qe?.classList.add("hidden"),this.div?.classList.remove("selectedEditor"),this.div?.contains(document.activeElement)&&this._uiManager.currentLayer.div.focus({preventScroll:!0}),this._editToolbar?.hide(),this.#l?.toggleAltTextBadge(!0),this.hideCommentPopup())}hideCommentPopup(){this.hasComment&&this._uiManager.toggleComment(null)}updateParams(t,e){}disableEditing(){}enableEditing(){}get canChangeContent(){return!1}enterInEditMode(){this.canChangeContent&&(this.enableEditMode(),this.div.focus())}dblclick(t){"BUTTON"!==t.target.nodeName&&(this.enterInEditMode(),this.parent.updateToolbar({mode:this.constructor._editorType,editId:this.uid}))}getElementForAltText(){return this.div}get contentDiv(){return this.div}get isEditing(){return this.#ni}set isEditing(t){this.#ni=t,this.parent&&(t?(this.parent.setSelected(this),this.parent.setActiveEditor(this)):this.parent.setActiveEditor(null))}static get MIN_SIZE(){return 16}static canCreateNewEmptyEditor(){return!0}get telemetryInitialData(){return{action:"added"}}get telemetryFinalData(){return null}_reportTelemetry(e,i=!1){if(i){this.#ci||=/* @__PURE__ */new Map;const{action:i}=e;let s=this.#ci.get(i);return s&&clearTimeout(s),s=setTimeout(()=>{this._reportTelemetry(e),this.#ci.delete(i),0===this.#ci.size&&(this.#ci=null)},t._telemetryTimeout),void this.#ci.set(i,s)}e.type||=this.editorType,this._uiManager._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:e}})}show(t=this._isVisible){this.div.classList.toggle("hidden",!t),this._isVisible=t}enable(){this.div&&(this.div.tabIndex=0),this.#Xe=!1}disable(){this.div&&(this.div.tabIndex=-1),this.#Xe=!0}updateFakeAnnotationElement(t){if(this.#Ze||this.deleted)return this.deleted?(this.#Ze.remove(),void(this.#Ze=null)):void((this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized)&&this.#Ze.updateEdited({rect:this.getPDFRect(),popup:this.comment}));this.#Ze=t.addFakeAnnotation(this)}renderAnnotationElement(t){if(this.deleted)return t.hide(),null;let e=t.container.querySelector(".annotationContent");if(e){if("CANVAS"===e.nodeName){const t=e;e=document.createElement("div"),e.classList.add("annotationContent",this.editorType),t.before(e)}}else e=document.createElement("div"),e.classList.add("annotationContent",this.editorType),t.container.prepend(e);return e}resetAnnotationElement(t){const{firstElementChild:e}=t.container;"DIV"===e?.nodeName&&e.classList.contains("annotationContent")&&e.remove()}},Wt=class extends Gt{constructor(t){super(t),this.annotationElementId=t.annotationElementId,this.deleted=!0}serialize(){return this.serializeDeleted()}},jt=3285377520,Vt=4294901760,$t=65535,Xt=class{constructor(t){this.h1=t?4294967295&t:jt,this.h2=t?4294967295&t:jt}update(t){let e,i;if("string"==typeof t){e=new Uint8Array(2*t.length),i=0;for(let s=0,n=t.length;s<n;s++){const n=t.charCodeAt(s);n<=255?e[i++]=n:(e[i++]=n>>>8,e[i++]=255&n)}}else{if(!ArrayBuffer.isView(t))throw new Error("Invalid data format, must be a string or TypedArray.");e=t.slice(),i=e.byteLength}const s=i>>2,n=i-4*s,r=new Uint32Array(e.buffer,0,s);let a=0,o=0,l=this.h1,h=this.h2;const c=3432918353,d=461845907,u=11601,p=13715;for(let g=0;g<s;g++)1&g?(a=r[g],a=a*c&Vt|a*u&$t,a=a<<15|a>>>17,a=a*d&Vt|a*p&$t,l^=a,l=l<<13|l>>>19,l=5*l+3864292196):(o=r[g],o=o*c&Vt|o*u&$t,o=o<<15|o>>>17,o=o*d&Vt|o*p&$t,h^=o,h=h<<13|h>>>19,h=5*h+3864292196);switch(a=0,n){case 3:a^=e[4*s+2]<<16;case 2:a^=e[4*s+1]<<8;case 1:a^=e[4*s],a=a*c&Vt|a*u&$t,a=a<<15|a>>>17,a=a*d&Vt|a*p&$t,1&s?l^=a:h^=a}this.h1=l,this.h2=h}hexdigest(){let t=this.h1,e=this.h2;return t^=e>>>1,t=3981806797*t&Vt|36045*t&$t,e=4283543511*e&Vt|(2950163797*(e<<16|t>>>16)&Vt)>>>16,t^=e>>>1,t=444984403*t&Vt|60499*t&$t,e=3301882366*e&Vt|(3120437893*(e<<16|t>>>16)&Vt)>>>16,t^=e>>>1,(t>>>0).toString(16).padStart(8,"0")+(e>>>0).toString(16).padStart(8,"0")}},Kt=Object.freeze({map:null,hash:"",transfer:void 0}),Yt=class{#Bi=!1;#Ri=null;#Oi=null;#Ni=/* @__PURE__ */new Map;onSetModified=null;onResetModified=null;onAnnotationEditor=null;getValue(t,e){const i=this.#Ni.get(t);return void 0===i?e:Object.assign(e,i)}getRawValue(t){return this.#Ni.get(t)}remove(t){const e=this.#Ni.get(t);void 0!==e&&(e instanceof Gt&&this.#Oi.delete(e.annotationElementId),this.#Ni.delete(t),0===this.#Ni.size&&this.resetModified(),this.#Ni.values().some(t=>t instanceof Gt)||this.onAnnotationEditor?.(null))}setValue(t,e){const i=this.#Ni.get(t);let s=!1;if(void 0!==i)for(const[n,r]of Object.entries(e))i[n]!==r&&(s=!0,i[n]=r);else s=!0,this.#Ni.set(t,e);s&&this.#zi(),e instanceof Gt&&((this.#Oi||=/* @__PURE__ */new Map).set(e.annotationElementId,e),this.onAnnotationEditor?.(e.constructor._type))}has(t){return this.#Ni.has(t)}get size(){return this.#Ni.size}#zi(){this.#Bi||(this.#Bi=!0,this.onSetModified?.())}resetModified(){this.#Bi&&(this.#Bi=!1,this.onResetModified?.())}get print(){return new qt(this)}get serializable(){if(0===this.#Ni.size)return Kt;const t=/* @__PURE__ */new Map,e=new Xt,i=[],s=Object.create(null);let n=!1;for(const[r,a]of this.#Ni){const i=a instanceof Gt?a.serialize(!1,s):a;a.page&&(a.pageIndex=a.page._pageIndex,delete a.page),i&&(t.set(r,i),e.update(`${r}:${JSON.stringify(i)}`),n||=!!i.bitmap)}if(n)for(const r of t.values())r.bitmap&&i.push(r.bitmap);return t.size>0?{map:t,hash:e.hexdigest(),transfer:i}:Kt}get editorStats(){let t=null;const e=/* @__PURE__ */new Map;let i=0,s=0;for(const n of this.#Ni.values()){if(!(n instanceof Gt)){n.popup&&(n.popup.deleted?s+=1:i+=1);continue}n.isCommentDeleted?s+=1:n.hasEditedComment&&(i+=1);const r=n.telemetryFinalData;if(!r)continue;const{type:a}=r;e.getOrInsertComputed(a,()=>Object.getPrototypeOf(n).constructor),t||=Object.create(null);const o=t[a]||=/* @__PURE__ */new Map;for(const[t,e]of Object.entries(r)){if("type"===t)continue;const i=o.getOrInsertComputed(t,U);i.set(e,(i.get(e)??0)+1)}}if((s>0||i>0)&&(t||=Object.create(null),t.comments={deleted:s,edited:i}),!t)return null;for(const[n,r]of e)t[n]=r.computeTelemetryFinalData(t[n]);return t}resetModifiedIds(){this.#Ri=null}updateEditor(t,e){const i=this.#Oi?.get(t);return!!i&&(i.updateFromAnnotationLayer(e),!0)}getEditor(t){return this.#Oi?.get(t)||null}get modifiedIds(){if(this.#Ri)return this.#Ri;const t=[];if(this.#Oi)for(const i of this.#Oi.values())i.serialize()&&t.push(i.annotationElementId);let e="";if(t.length){const i=new Xt;i.update(t.join(",")),e=i.hexdigest()}return this.#Ri={ids:new Set(t),hash:e}}[Symbol.iterator](){return this.#Ni.entries()}},qt=class extends Yt{#Hi=Kt;constructor(t){super();const{serializable:e}=t;if(e===Kt)return;const{map:i,hash:s,transfer:n}=e,r=structuredClone(i,n?{transfer:n}:null);this.#Hi={map:r,hash:s,transfer:[]}}get print(){w("Should not call PrintAnnotationStorage.print")}get serializable(){return this.#Hi}get modifiedIds(){return T(this,"modifiedIds",{ids:/* @__PURE__ */new Set,hash:""})}};function Qt(t){if("string"!=typeof t)return null;if(t.endsWith("/"))return t;throw new Error(`Invalid factory url: "${t}" must include trailing slash.`)}var Jt=t=>"object"==typeof t&&Number.isInteger(t?.num)&&t.num>=0&&Number.isInteger(t?.gen)&&t.gen>=0,Zt=function(t,e,i){if(!Array.isArray(i)||i.length<2)return!1;const[s,n,...r]=i;if(!t(s)&&!Number.isInteger(s))return!1;if(!e(n))return!1;const a=r.length;let o=!0;switch(n.name){case"XYZ":if(a<2||a>3)return!1;break;case"Fit":case"FitB":return 0===a;case"FitH":case"FitBH":case"FitV":case"FitBV":if(a>1)return!1;break;case"FitR":if(4!==a)return!1;o=!1;break;default:return!1}for(const l of r)if(!("number"==typeof l||o&&null===l))return!1;return!0}.bind(null,Jt,t=>"object"==typeof t&&"string"==typeof t?.name);function te(t){if(!function(t,e){const i=URL.parse(t);if(!i?.origin||"null"===i.origin)return!1;const s=new URL(e,i);return i.origin===s.origin}(window.location,t)){const e=`await import("${new URL(t,window.location).href}");`;return URL.createObjectURL(new Blob([e],{type:"text/javascript"}))}return t}var ee=class{#Ui=/* @__PURE__ */new Map;#Gi=Promise.resolve();postMessage(t,e){const i={data:structuredClone(t,e?{transfer:e}:null)};this.#Gi.then(()=>{for(const[t]of this.#Ui)t.call(this,i)})}addEventListener(t,e,i=null){let s=null;if(i?.signal instanceof AbortSignal){const{signal:n}=i;if(n.aborted)return;const r=()=>this.removeEventListener(t,e);s=()=>n.removeEventListener("abort",r),n.addEventListener("abort",r)}this.#Ui.set(e,s)}removeEventListener(t,e){this.#Ui.get(e)?.(),this.#Ui.delete(e)}terminate(){for(const[,t]of this.#Ui)t?.();this.#Ui.clear()}},ie=class{#Wi=/* @__PURE__ */new Map;times=[];time(t){this.#Wi.has(t),this.#Wi.set(t,Date.now())}timeEnd(t){this.#Wi.has(t),this.times.push({name:t,start:this.#Wi.get(t),end:Date.now()}),this.#Wi.delete(t)}toString(){const t=Math.max(...this.times.map(t=>t.name.length));return this.times.map(e=>`${e.name.padEnd(t)} ${e.end-e.start}ms\n`).join("")}},se=new class{#ji=null;#Vi=null;#$i=null;#Xi=null;async#Ki(){if(!globalThis.navigator?.gpu)return!1;try{const t=await navigator.gpu.requestAdapter();return!!t&&(this.#Xi=navigator.gpu.getPreferredCanvasFormat(),this.#Vi=await t.requestDevice(),!0)}catch{return!1}}init(){return this.#ji||=this.#Ki()}get isReady(){return null!==this.#Vi}loadMeshShader(){if(!this.#Vi||this.#$i)return;const t=this.#Vi.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.#Vi.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.#Xi}]},primitive:{topology:"triangle-list"}})}draw(t,e,i,s,n,r,a,o){this.loadMeshShader();const l=this.#Vi,{offsetX:h,offsetY:c,scaleX:d,scaleY:u}=s,p=l.createBuffer({size:Math.max(t.byteLength,4),usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST});t.byteLength>0&&l.queue.writeBuffer(p,0,t);const g=l.createBuffer({size:Math.max(e.byteLength,4),usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST});e.byteLength>0&&l.queue.writeBuffer(g,0,e);const m=l.createBuffer({size:32,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});l.queue.writeBuffer(m,0,new Float32Array([h,c,d,u,r,a,o,0]));const f=l.createBindGroup({layout:this.#$i.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:m}}]}),b=new OffscreenCanvas(r,a),y=b.getContext("webgpu");y.configure({device:l,format:this.#Xi,alphaMode:n?"opaque":"premultiplied"});const v=n?{r:n[0]/255,g:n[1]/255,b:n[2]/255,a:1}:{r:0,g:0,b:0,a:0},w=l.createCommandEncoder(),A=w.beginRenderPass({colorAttachments:[{view:y.getCurrentTexture().createView(),clearValue:v,loadOp:"clear",storeOp:"store"}]});return i>0&&(A.setPipeline(this.#$i),A.setBindGroup(0,f),A.setVertexBuffer(0,p),A.setVertexBuffer(1,g),A.draw(i)),A.end(),l.queue.submit([w.finish()]),p.destroy(),g.destroy(),m.destroy(),b.transferToImageBitmap()}};function ne(){return se.init()}function re(){return se.isReady}function ae(){}function oe(t){if(t instanceof I||t instanceof M||t instanceof k||t instanceof P||t instanceof E)return t;if("object"!=typeof t||null===t)return new E(String(t),String(t));switch(t.name){case"AbortException":return new I(t.message);case"InvalidPDFException":return new M(t.message);case"PasswordException":return new k(t.message,t.code);case"ResponseException":return new P(t.message,t.status,t.missing);case"UnknownErrorException":return new E(t.message,t.details)}return new E(t.message,t.toString())}var le=class{#Yi=/* @__PURE__ */new Map;#qi=/* @__PURE__ */new Map;#Qi=1;#Ji;#Zi=new AbortController;#ts;#es=/* @__PURE__ */new Map;#is=1;#ss=/* @__PURE__ */new Map;#ns;constructor(t,e,i){this.#ts=t,this.#ns=e,this.#Ji=i,i.addEventListener("message",this.#rs.bind(this),{signal:this.#Zi.signal})}#rs({data:t}){if(t.targetName!==this.#ts)return;if(t.stream)return void this.#as(t);if(t.callback){const{callbackId:e,callback:i}=t,s=this.#qi.get(e);if(!s)throw new Error(`Cannot resolve callback ${e}`);if(this.#qi.delete(e),1===i)s.resolve(t.data);else{if(2!==i)throw new Error("Unexpected callback case");s.reject(oe(t.reason))}return}const e=this.#Yi.get(t.action);if(!e)throw new Error(`Unknown action from worker: ${t.action}`);if(t.callbackId){const i=this.#ts,s=t.sourceName,n=this.#Ji;return void Promise.try(e,t.data).then(e=>{n.postMessage({sourceName:i,targetName:s,callback:1,callbackId:t.callbackId,data:e})}).catch(e=>{n.postMessage({sourceName:i,targetName:s,callback:2,callbackId:t.callbackId,reason:oe(e)})})}t.streamId?this.#os(t):e(t.data)}on(t,e){const i=this.#Yi;if(i.has(t))throw new Error(`There is already a "${t}" handler.`);i.set(t,e)}send(t,e,i){this.#Ji.postMessage({sourceName:this.#ts,targetName:this.#ns,action:t,data:e},i)}sendWithPromise(t,e,i){const s=this.#Qi++,n=Promise.withResolvers();this.#qi.set(s,n);try{this.#Ji.postMessage({sourceName:this.#ts,targetName:this.#ns,action:t,callbackId:s,data:e},i)}catch(r){n.reject(r)}return n.promise}sendWithStream(t,e,i,s){const n=this.#is++,r=this.#ts,a=this.#ns,o=this.#Ji;return new ReadableStream({start:i=>{const l=Promise.withResolvers();return this.#es.set(n,{controller:i,startCall:l,pullCall:null,cancelCall:null,isClosed:!1}),o.postMessage({sourceName:r,targetName:a,action:t,streamId:n,data:e,desiredSize:i.desiredSize},s),l.promise},pull:t=>{const e=Promise.withResolvers();return this.#es.get(n).pullCall=e,o.postMessage({sourceName:r,targetName:a,stream:6,streamId:n,desiredSize:t.desiredSize}),e.promise},cancel:t=>{A(t instanceof Error,"cancel must have a valid reason");const e=Promise.withResolvers();return this.#es.get(n).cancelCall=e,this.#es.get(n).isClosed=!0,o.postMessage({sourceName:r,targetName:a,stream:1,streamId:n,reason:oe(t)}),e.promise}},i)}#os(t){const e=t.streamId,i=this.#ts,s=t.sourceName,n=this.#Ji,r=this.#ss,a=this.#Yi.get(t.action),o={enqueue(t,r=1,a){if(this.isCancelled)return;const o=this.desiredSize;this.desiredSize-=r,o>0&&this.desiredSize<=0&&(this.sinkCapability=Promise.withResolvers(),this.ready=this.sinkCapability.promise),n.postMessage({sourceName:i,targetName:s,stream:4,streamId:e,chunk:t},a)},close(){this.isCancelled||(this.isCancelled=!0,n.postMessage({sourceName:i,targetName:s,stream:3,streamId:e}),r.delete(e))},error(t){this.isCancelled||(this.isCancelled=!0,n.postMessage({sourceName:i,targetName:s,stream:5,streamId:e,reason:oe(t)}))},sinkCapability:Promise.withResolvers(),onPull:null,onCancel:null,isCancelled:!1,desiredSize:t.desiredSize,ready:null};o.sinkCapability.resolve(),o.ready=o.sinkCapability.promise,r.set(e,o),Promise.try(a,t.data,o).then(()=>{n.postMessage({sourceName:i,targetName:s,stream:8,streamId:e,success:!0})},t=>{n.postMessage({sourceName:i,targetName:s,stream:8,streamId:e,reason:oe(t)})})}#as(t){const e=t.streamId,i=this.#ts,s=t.sourceName,n=this.#Ji,r=this.#es.get(e),a=this.#ss.get(e);switch(t.stream){case 8:t.success?r.startCall.resolve():r.startCall.reject(oe(t.reason));break;case 7:t.success?r.pullCall.resolve():r.pullCall.reject(oe(t.reason));break;case 6:if(!a){n.postMessage({sourceName:i,targetName:s,stream:7,streamId:e,success:!0});break}a.desiredSize<=0&&t.desiredSize>0&&a.sinkCapability.resolve(),a.desiredSize=t.desiredSize,Promise.try(a.onPull||ae).then(()=>{n.postMessage({sourceName:i,targetName:s,stream:7,streamId:e,success:!0})},t=>{n.postMessage({sourceName:i,targetName:s,stream:7,streamId:e,reason:oe(t)})});break;case 4:if(A(r,"enqueue should have stream controller"),r.isClosed)break;r.controller.enqueue(t.chunk);break;case 3:if(A(r,"close should have stream controller"),r.isClosed)break;r.isClosed=!0,r.controller.close(),this.#ls(r,e);break;case 5:A(r,"error should have stream controller"),r.controller.error(oe(t.reason)),this.#ls(r,e);break;case 2:t.success?r.cancelCall.resolve():r.cancelCall.reject(oe(t.reason)),this.#ls(r,e);break;case 1:if(!a)break;const o=oe(t.reason);Promise.try(a.onCancel||ae,o).then(()=>{n.postMessage({sourceName:i,targetName:s,stream:2,streamId:e,success:!0})},t=>{n.postMessage({sourceName:i,targetName:s,stream:2,streamId:e,reason:oe(t)})}),a.sinkCapability.reject(o),a.isCancelled=!0,this.#ss.delete(e);break;default:throw new Error("Unexpected stream case")}}async#ls(t,e){await Promise.allSettled([t.startCall?.promise,t.pullCall?.promise,t.cancelCall?.promise]),this.#es.delete(e)}destroy(){this.#Zi?.abort(),this.#Zi=null}get destroyed(){return!this.#Zi}},he=class{#hs=Object.freeze({cMapUrl:"CMap",standardFontDataUrl:"font",wasmUrl:"wasm"});constructor({cMapUrl:t=null,standardFontDataUrl:e=null,wasmUrl:i=null}){this.cMapUrl=t,this.standardFontDataUrl=e,this.wasmUrl=i}async fetch({kind:t,filename:e}){switch(t){case"cMapUrl":case"standardFontDataUrl":case"wasmUrl":break;default:w(`Not implemented: ${t}`)}const i=this[t];if(!i)throw new Error(`Ensure that the \`${t}\` API parameter is provided.`);const s=`${i}${e}`;return this._fetch(s,t).catch(e=>{throw new Error(`Unable to load ${this.#hs[t]} data at: ${s}`)})}async _fetch(t,e){w("Abstract method `_fetch` called.")}},ce=class extends he{async _fetch(t,e){const i=await dt(t,"cMapUrl"!==e||t.endsWith(".bcmap")?"bytes":"text");return i instanceof Uint8Array?i:F(i)}},de=class{#cs=!1;constructor({enableHWA:t=!1}){this.#cs=t}create(t,e){if(t<=0||e<=0)throw new Error("Invalid canvas size");const i=this._createCanvas(t,e);return{canvas:i,context:i.getContext("2d",{willReadFrequently:!this.#cs})}}reset({canvas:t},e,i){if(!t)throw new Error("Canvas is not specified");if(e<=0||i<=0)throw new Error("Invalid canvas size");t.width=e,t.height=i}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.#cs})}_createCanvas(t,e){w("Abstract method `_createCanvas` called.")}},ue=class{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,i,s,n){return"none"}addSelectionHCMFilter(t,e){return"none"}addSelectionFilter(){return"none"}createSelectionStyle(t=null){return null}destroy(t=!1){}},pe=class extends ue{},ge=class extends de{_createCanvas(t,e){return process.getBuiltinModule("module").createRequire(import.meta.url)("@napi-rs/canvas").createCanvas(t,e)}},me=class extends he{async _fetch(t,e){return async function(t){const e=await process.getBuiltinModule("fs/promises").readFile(t);return new Uint8Array(e)}(t)}},fe="__forcedDependency",{floor:be,ceil:ye}=Math;function ve(t,e,i,s,n,r){t[4*e+0]=Math.min(t[4*e+0],i),t[4*e+1]=Math.min(t[4*e+1],s),t[4*e+2]=Math.max(t[4*e+2],n),t[4*e+3]=Math.max(t[4*e+3],r)}var we=new Uint32Array(new Uint8Array([255,255,0,0]).buffer)[0],Ae=class t{#ds;#us;constructor(t,e){this.#ds=t,this.#us=e}static fromBuffer(e){return new t(new Uint32Array(e),new Uint8ClampedArray(e))}get buffer(){return this.#ds.buffer}get length(){return this.#ds.length}isEmpty(t){return this.#ds[t]===we}minX(t){return this.#us[4*t+0]/256}minY(t){return this.#us[4*t+1]/256}maxX(t){return(this.#us[4*t+2]+1)/256}maxY(t){return(this.#us[4*t+3]+1)/256}},xe=(t,e)=>t?.getOrInsertComputed(e,()=>({dependencies:/* @__PURE__ */new Set,isRenderingOperation:!1})),Ce=class{#ps=[[1,0,0,1,0,0]];#gs=[-1/0,-1/0,1/0,1/0];#ms=new Float64Array(e);_pendingBBoxIdx=-1;#fs;#bs;#ys;#ds;_savesStack=[];_markedContentStack=[];constructor(t,e){this.#fs=t.width,this.#bs=t.height,this.#vs(e)}growOperationsCount(t){t>=this.#ds.length&&this.#vs(t,this.#ds)}#vs(t,e){const i=/* @__PURE__ */new ArrayBuffer(4*t);this.#ys=new Uint8ClampedArray(i),this.#ds=new Uint32Array(i),e&&e.length>0?(this.#ds.set(e),this.#ds.fill(we,e.length)):this.#ds.fill(we)}get clipBox(){return this.#gs}save(t){return this.#gs={__proto__:this.#gs},this._savesStack.push(t),this}restore(t,e){const i=Object.getPrototypeOf(this.#gs);if(null===i)return this;this.#gs=i;const s=this._savesStack.pop();return void 0!==s&&(e?.(s,t),this.#ds[t]=this.#ds[s]),this}recordOpenMarker(t){return this._savesStack.push(t),this}getOpenMarker(){return 0===this._savesStack.length?null:this._savesStack.at(-1)}recordCloseMarker(t,e){const i=this._savesStack.pop();return void 0!==i&&(e?.(i,t),this.#ds[t]=this.#ds[i]),this}beginMarkedContent(t){return this._markedContentStack.push(t),this}endMarkedContent(t,e){const i=this._markedContentStack.pop();return void 0!==i&&(e?.(i,t),this.#ds[t]=this.#ds[i]),this}pushBaseTransform(t){return this.#ps.push(B.multiplyByDOMMatrix(this.#ps.at(-1),t.getTransform())),this}popBaseTransform(){return this.#ps.length>1&&this.#ps.pop(),this}resetBBox(t){return this._pendingBBoxIdx!==t&&(this._pendingBBoxIdx=t,this.#ms.set(e,0)),this}recordClipBox(t,i,s,n,r,a){const o=B.multiplyByDOMMatrix(this.#ps.at(-1),i.getTransform()),l=e.slice();B.axialAlignedBoundingBox([s,r,n,a],o,l);const h=B.intersect(this.#gs,l);return h?(this.#gs[0]=h[0],this.#gs[1]=h[1],this.#gs[2]=h[2],this.#gs[3]=h[3]):(this.#gs[0]=this.#gs[1]=1/0,this.#gs[2]=this.#gs[3]=-1/0),this}recordBBox(t,i,s,n,r,a){const o=this.#gs;if(o[0]===1/0)return this;const l=B.multiplyByDOMMatrix(this.#ps.at(-1),i.getTransform());if(o[0]===-1/0)return B.axialAlignedBoundingBox([s,r,n,a],l,this.#ms),this;const h=e.slice();return B.axialAlignedBoundingBox([s,r,n,a],l,h),this.#ms[0]=j(h[0],o[0],this.#ms[0]),this.#ms[1]=j(h[1],o[1],this.#ms[1]),this.#ms[2]=j(h[2],this.#ms[2],o[2]),this.#ms[3]=j(h[3],this.#ms[3],o[3]),this}recordFullPageBBox(t){return this.#ms[0]=Math.max(0,this.#gs[0]),this.#ms[1]=Math.max(0,this.#gs[1]),this.#ms[2]=Math.min(this.#fs,this.#gs[2]),this.#ms[3]=Math.min(this.#bs,this.#gs[3]),this}recordOperation(t,e=!1,i){if(this._pendingBBoxIdx!==t)return this;const s=be(256*this.#ms[0]/this.#fs),n=be(256*this.#ms[1]/this.#bs),r=ye(256*this.#ms[2]/this.#fs),a=ye(256*this.#ms[3]/this.#bs);if(ve(this.#ys,t,s,n,r,a),i)for(const o of i)for(const e of o)e!==t&&ve(this.#ys,e,s,n,r,a);return e||(this._pendingBBoxIdx=-1),this}bboxToClipBoxDropOperation(t){return this._pendingBBoxIdx===t&&(this._pendingBBoxIdx=-1,this.#gs[0]=Math.max(this.#gs[0],this.#ms[0]),this.#gs[1]=Math.max(this.#gs[1],this.#ms[1]),this.#gs[2]=Math.min(this.#gs[2],this.#ms[2]),this.#gs[3]=Math.min(this.#gs[3],this.#ms[3])),this}take(){return new Ae(this.#ds,this.#ys)}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,i){return this}recordFutureForcedDependency(t,e){return this}inheritSimpleDataAsFutureForcedDependencies(t){return this}inheritPendingDependenciesAsFutureForcedDependencies(){return this}recordCharacterBBox(t,e,i,s=1,n=0,r=0,a){return this}getSimpleIndex(t){}recordDependencies(t,e){return this}recordNamedDependency(t,e){return this}recordShowTextOperation(t,e=!1){return this}},Se=class{#ws={__proto__:null};#As={__proto__:null,transform:[],moveText:[],sameLineText:[],[fe]:[]};#xs=/* @__PURE__ */new Map;#Cs=/* @__PURE__ */new Set;#Ss=/* @__PURE__ */new Map;#Ts;#_s;#ks;constructor(t,e=!1){this.#ks=t,e&&(this.#Ts=/* @__PURE__ */new Map,this.#_s=(t,e)=>{xe(this.#Ts,e).dependencies.add(t)})}get clipBox(){return this.#ks.clipBox}growOperationsCount(t){this.#ks.growOperationsCount(t)}save(t){return this.#ws={__proto__:this.#ws},this.#As={__proto__:this.#As,transform:{__proto__:this.#As.transform},moveText:{__proto__:this.#As.moveText},sameLineText:{__proto__:this.#As.sameLineText},[fe]:{__proto__:this.#As[fe]}},this.#ks.save(t),this}restore(t){this.#ks.restore(t,this.#_s);const e=Object.getPrototypeOf(this.#ws);return null===e||(this.#ws=e,this.#As=Object.getPrototypeOf(this.#As)),this}recordOpenMarker(t){return this.#ks.recordOpenMarker(t,this.#_s),this}getOpenMarker(){return this.#ks.getOpenMarker()}recordCloseMarker(t){return this.#ks.recordCloseMarker(t,this.#_s),this}beginMarkedContent(t){return this.#ks.beginMarkedContent(t),this}endMarkedContent(t){return this.#ks.endMarkedContent(t,this.#_s),this}pushBaseTransform(t){return this.#ks.pushBaseTransform(t),this}popBaseTransform(){return this.#ks.popBaseTransform(),this}recordSimpleData(t,e){return this.#ws[t]=e,this}recordIncrementalData(t,e){return this.#As[t].push(e),this}resetIncrementalData(t,e){return this.#As[t].length=0,this}recordNamedData(t,e){return this.#xs.set(t,e),this}recordSimpleDataFromNamed(t,e,i){this.#ws[t]=this.#xs.get(e)??i}recordFutureForcedDependency(t,e){return this.recordIncrementalData(fe,e),this}inheritSimpleDataAsFutureForcedDependencies(t){for(const e of t)e in this.#ws&&this.recordFutureForcedDependency(e,this.#ws[e]);return this}inheritPendingDependenciesAsFutureForcedDependencies(){for(const t of this.#Cs)this.recordFutureForcedDependency(fe,t);return this}resetBBox(t){return this.#ks.resetBBox(t),this}recordClipBox(t,e,i,s,n,r){return this.#ks.recordClipBox(t,e,i,s,n,r),this}recordBBox(t,e,i,s,n,r){return this.#ks.recordBBox(t,e,i,s,n,r),this}recordCharacterBBox(t,e,i,s=1,n=0,r=0,a){const o=i.bbox;let l,h;if(o&&(l=o[2]!==o[0]&&o[3]!==o[1]&&this.#Ss.get(i),!1!==l&&(h=[0,0,0,0],B.axialAlignedBoundingBox(o,i.fontMatrix,h),1===s&&0===n&&0===r||function(t,e,i,s,n){let r;t?(t<0&&(r=n[0],n[0]=n[2],n[2]=r),n[0]*=t,n[2]*=t,e<0&&(r=n[1],n[1]=n[3],n[3]=r),n[1]*=e,n[3]*=e):n.fill(0),n[0]+=i,n[1]+=s,n[2]+=i,n[3]+=s}(s,-s,n,r,h),l)))return this.recordBBox(t,e,h[0],h[2],h[1],h[3]);if(!a)return this.recordFullPageBBox(t);const c=a();return o&&h&&void 0===l&&(l=h[0]<=n-c.actualBoundingBoxLeft&&h[2]>=n+c.actualBoundingBoxRight&&h[1]<=r-c.actualBoundingBoxAscent&&h[3]>=r+c.actualBoundingBoxDescent,this.#Ss.set(i,l),l)?this.recordBBox(t,e,h[0],h[2],h[1],h[3]):this.recordBBox(t,e,n-c.actualBoundingBoxLeft,n+c.actualBoundingBoxRight,r-c.actualBoundingBoxAscent,r+c.actualBoundingBoxDescent)}recordFullPageBBox(t){return this.#ks.recordFullPageBBox(t),this}getSimpleIndex(t){return this.#ws[t]}recordDependencies(t,e){const i=this.#Cs,s=this.#ws,n=this.#As;for(const r of e)r in this.#ws?i.add(s[r]):r in n&&n[r].forEach(i.add,i);return this}recordNamedDependency(t,e){return this.#xs.has(e)&&this.#Cs.add(this.#xs.get(e)),this}recordOperation(t,e=!1){if(this.recordDependencies(t,[fe]),this.#Ts){const e=xe(this.#Ts,t),{dependencies:i}=e;this.#Cs.forEach(i.add,i),this.#ks._savesStack.forEach(i.add,i),this.#ks._markedContentStack.forEach(i.add,i),i.delete(t),e.isRenderingOperation=!0}const i=!e&&t===this.#ks._pendingBBoxIdx;return this.#ks.recordOperation(t,e,[this.#Cs,this.#ks._savesStack,this.#ks._markedContentStack]),i&&this.#Cs.clear(),this}recordShowTextOperation(t,e=!1){const i=Array.from(this.#Cs);this.recordOperation(t,e),this.recordIncrementalData("sameLineText",t);for(const s of i)this.recordIncrementalData("sameLineText",s);return this}bboxToClipBoxDropOperation(t,e=!1){const i=!e&&t===this.#ks._pendingBBoxIdx;return this.#ks.bboxToClipBoxDropOperation(t),i&&this.#Cs.clear(),this}take(){return this.#Ss.clear(),this.#ks.take()}takeDebugMetadata(){return this.#Ts}},Te=class t{#Es;#Ms;#Ps;#Ds=0;#Is=0;constructor(e,i,s){if(e instanceof t&&e.#Ps===!!s)return e;this.#Es=e,this.#Ms=i,this.#Ps=!!s}get clipBox(){return this.#Es.clipBox}growOperationsCount(){throw new Error("Unreachable")}save(t){return this.#Is++,this.#Es.save(this.#Ms),this}restore(t){return this.#Is>0&&(this.#Es.restore(this.#Ms),this.#Is--),this}recordOpenMarker(t){return this.#Ds++,this}getOpenMarker(){return this.#Ds>0?this.#Ms:this.#Es.getOpenMarker()}recordCloseMarker(t){return this.#Ds--,this}beginMarkedContent(t){return this}endMarkedContent(t){return this}pushBaseTransform(t){return this.#Es.pushBaseTransform(t),this}popBaseTransform(){return this.#Es.popBaseTransform(),this}recordSimpleData(t,e){return this.#Es.recordSimpleData(t,this.#Ms),this}recordIncrementalData(t,e){return this.#Es.recordIncrementalData(t,this.#Ms),this}resetIncrementalData(t,e){return this.#Es.resetIncrementalData(t,this.#Ms),this}recordNamedData(t,e){return this}recordSimpleDataFromNamed(t,e,i){return this.#Es.recordSimpleDataFromNamed(t,e,this.#Ms),this}recordFutureForcedDependency(t,e){return this.#Es.recordFutureForcedDependency(t,this.#Ms),this}inheritSimpleDataAsFutureForcedDependencies(t){return this.#Es.inheritSimpleDataAsFutureForcedDependencies(t),this}inheritPendingDependenciesAsFutureForcedDependencies(){return this.#Es.inheritPendingDependenciesAsFutureForcedDependencies(),this}resetBBox(t){return this.#Ps||this.#Es.resetBBox(this.#Ms),this}recordClipBox(t,e,i,s,n,r){return this.#Ps||this.#Es.recordClipBox(this.#Ms,e,i,s,n,r),this}recordBBox(t,e,i,s,n,r){return this.#Ps||this.#Es.recordBBox(this.#Ms,e,i,s,n,r),this}recordCharacterBBox(t,e,i,s,n,r,a){return this.#Ps||this.#Es.recordCharacterBBox(this.#Ms,e,i,s,n,r,a),this}recordFullPageBBox(t){return this.#Ps||this.#Es.recordFullPageBBox(this.#Ms),this}getSimpleIndex(t){return this.#Es.getSimpleIndex(t)}recordDependencies(t,e){return this.#Es.recordDependencies(this.#Ms,e),this}recordNamedDependency(t,e){return this.#Es.recordNamedDependency(this.#Ms,e),this}recordOperation(t){return this.#Es.recordOperation(this.#Ms,!0),this}recordShowTextOperation(t){return this.#Es.recordShowTextOperation(this.#Ms,!0),this}bboxToClipBoxDropOperation(t){return this.#Ps||this.#Es.bboxToClipBoxDropOperation(this.#Ms,!0),this}take(){throw new Error("Unreachable")}takeDebugMetadata(){throw new Error("Unreachable")}},_e=["path","transform","filter","strokeColor","strokeAlpha","lineWidth","lineCap","lineJoin","miterLimit","dash"],ke=["path","transform","filter","fillColor","fillAlpha","globalCompositeOperation","SMask"],Ee=["transform","SMask","filter","fillAlpha","strokeAlpha","globalCompositeOperation"],Me=["filter","fillColor","fillAlpha"],Pe=["transform","leading","charSpacing","wordSpacing","hScale","textRise","moveText","textMatrix","font","fontObj","filter","fillColor","textRenderingMode","SMask","fillAlpha","strokeAlpha","globalCompositeOperation","sameLineText"],De=["transform"],Ie=["transform","filter","fillColor"],Fe=class t{#fs;#bs;#Fs=4;#Ls=0;#us=new t.#Bs(6*this.#Fs);static#Bs=L.isFloat16ArraySupported?Float16Array:Float32Array;constructor(t){this.#fs=t.width,this.#bs=t.height}record(i,s,n,r){if(this.#Ls===this.#Fs){this.#Fs*=2;const e=new t.#Bs(6*this.#Fs);e.set(this.#us),this.#us=e}const a=Y(i);let o;if(r[0]!==1/0){const t=e.slice();B.axialAlignedBoundingBox([0,-n,s,0],a,t);const i=B.intersect(r,t);if(!i)return;const[l,h,c,d]=i;if(l!==t[0]||h!==t[1]||c!==t[2]||d!==t[3]){const t=Math.atan2(a[1],a[0]),e=Math.abs(Math.sin(t)),i=Math.abs(Math.cos(t));if(e<1e-6||i<1e-6||Math.abs(e-i)<1e-6)o=[l,h,l,d,c,h];else{const t=c-l,s=d-h,n=e*e,r=i*i,a=i*e,u=r-n,p=(s*r-t*a)/u;o=[l+(s*a-t*n)/u,h,l,h+p,c,d-p]}}}o||(o=[0,-n,0,0,s,-n],B.applyTransform(o,a,0),B.applyTransform(o,a,2),B.applyTransform(o,a,4)),o[0]/=this.#fs,o[1]/=this.#bs,o[2]/=this.#fs,o[3]/=this.#bs,o[4]/=this.#fs,o[5]/=this.#bs,this.#us.set(o,6*this.#Ls),this.#Ls++}take(){return this.#us.subarray(0,6*this.#Ls)}};function Le({src:t,srcPos:e=0,dest:i,width:s,height:n,nonBlackColor:r=4294967295,inverseDecode:a=!1}){const o=L.isLittleEndian?4278190080:255,[l,h]=a?[r,o]:[o,r],c=s>>3,d=7&s,u=l^h,p=t.length;i=new Uint32Array(i.buffer);let g=0;for(let m=0;m<n;++m){for(const n=e+c;e<n;++e,g+=8){const s=t[e];i[g]=l^-(s>>7&1)&u,i[g+1]=l^-(s>>6&1)&u,i[g+2]=l^-(s>>5&1)&u,i[g+3]=l^-(s>>4&1)&u,i[g+4]=l^-(s>>3&1)&u,i[g+5]=l^-(s>>2&1)&u,i[g+6]=l^-(s>>1&1)&u,i[g+7]=l^-(1&s)&u}if(0===d)continue;const s=e<p?t[e++]:255;for(let t=0;t<d;++t,++g)i[g]=l^-(s>>7-t&1)&u}return{srcPos:e,destPos:g}}function Be({src:t,srcPos:e=0,dest:i,destPos:s=0,width:n,height:r}){let a=0;const o=n*r*3,l=t.byteOffset+e,h=l%4==0?Math.floor(j(t.length-e,0,o)/4):0,c=h>0?new Uint32Array(t.buffer,l,h):null,d=L.isLittleEndian?4278190080:255;if(L.isLittleEndian){for(;a<h-2;a+=3,s+=4){const t=c[a],e=c[a+1],n=c[a+2];i[s]=t|d,i[s+1]=t>>>24|e<<8|d,i[s+2]=e>>>16|n<<16|d,i[s+3]=n>>>8|d}for(let n=e+4*a,r=e+o;n<r;n+=3)i[s++]=t[n]|t[n+1]<<8|t[n+2]<<16|d}else{for(;a<h-2;a+=3,s+=4){const t=c[a],e=c[a+1],n=c[a+2];i[s]=t|d,i[s+1]=t<<24|e>>>8|d,i[s+2]=e<<16|n>>>16|d,i[s+3]=n<<8|d}for(let n=e+4*a,r=e+o;n<r;n+=3)i[s++]=t[n]<<24|t[n+1]<<16|t[n+2]<<8|d}return{srcPos:e+o,destPos:s}}var Re="Fill",Oe="Stroke",Ne="Shading";function ze(t,e){if(!e)return;const i=e[2]-e[0],s=e[3]-e[1],n=new Path2D;n.rect(e[0],e[1],i,s),t.clip(n)}var He=class{matrix=null;isModifyingCurrentTransform(){return!1}getPattern(){w("Abstract method `getPattern` called.")}},Ue=class extends He{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 i,s=this._p0,n=this._p1;if(e&&(s=s.slice(),n=n.slice(),B.applyTransform(s,e),B.applyTransform(n,e)),"axial"===this._type)i=t.createLinearGradient(s[0],s[1],n[0],n[1]);else if("radial"===this._type){let r=this._r0,a=this._r1;if(e){const t=/* @__PURE__ */new Float32Array(2);B.singularValueDecompose2dScale(e,t),r*=t[0],a*=t[0]}i=t.createRadialGradient(s[0],s[1],r,n[0],n[1],a)}for(const r of this._colorStops)i.addColorStop(r[0],r[1]);return i}_createReversedGradient(t,e=null){let i=this._p1,s=this._p0;e&&(i=i.slice(),s=s.slice(),B.applyTransform(i,e),B.applyTransform(s,e));let n=this._r1,r=this._r0;if(e){const t=/* @__PURE__ */new Float32Array(2);B.singularValueDecompose2dScale(e,t),n*=t[0],r*=t[0]}const a=t.createRadialGradient(i[0],i[1],n,s[0],s[1],r),o=this._colorStops.map(([t,e])=>[1-t,e]).reverse();for(const[l,h]of o)a.addColorStop(l,h);return a}_createRasterPattern(t,e,i,s,n,r){const a=Math.ceil(s[2]-s[0])||1,o=Math.ceil(s[3]-s[1])||1,l=e.canvasFactory.create(a,o),h=l.context;h.clearRect(0,0,a,o),h.beginPath(),h.rect(0,0,a,o),h.translate(-s[0],-s[1]),i=B.transform(i,[1,0,0,1,s[0],s[1]]),h.transform(...n),ze(h,this._bbox),this.areConic()&&(h.fillStyle=this._createReversedGradient(h),h.fill()),h.fillStyle=this._createGradient(h),h.fill(),r?.applyToCanvas(h);const c=t.createPattern(l.canvas,"no-repeat");return e.canvasFactory.destroy(l),c.setTransform(new DOMMatrix(i)),c}getPattern(t,e,i,s){const n=e.current.transferMapsFallback;if(s===Oe||s===Re){if(this.isOriginBased()&&!n){let s=B.transform(i,e.baseTransform);this.matrix&&(s=B.transform(s,this.matrix));const n=.001,r=Math.hypot(s[0],s[1]),a=Math.hypot(s[2],s[3]),o=(s[0]*s[2]+s[1]*s[3])/(r*a);if(Math.abs(o)<n){if(!this.isRadial())return this._createGradient(t,s);if(Math.abs(r-a)<n)return this._createGradient(t,s)}}const r=e.current.getClippedPathBoundingBox(s,Y(t))||[0,0,0,0],a=this.matrix?B.transform(e.baseTransform,this.matrix):e.baseTransform;return this._createRasterPattern(t,e,i,r,a,n)}return n&&i?this._createRasterPattern(t,e,i,e.current.clipBox,Y(t),n):(this.areConic()&&(t.save(),ze(t,this._bbox),t.fillStyle=this._createReversedGradient(t),t.fillRect(-1e10,-1e10,2e10,2e10),t.restore()),ze(t,this._bbox),this._createGradient(t))}};function Ge(t,e,i,s,n,r,a,o){const l=e.coords,h=e.colors,c=t.data,d=4*t.width;let u;l[2*i+1]>l[2*s+1]&&(u=i,i=s,s=u,u=r,r=a,a=u),l[2*s+1]>l[2*n+1]&&(u=s,s=n,n=u,u=a,a=o,o=u),l[2*i+1]>l[2*s+1]&&(u=i,i=s,s=u,u=r,r=a,a=u);const p=(l[2*i]+e.offsetX)*e.scaleX,g=(l[2*i+1]+e.offsetY)*e.scaleY,m=(l[2*s]+e.offsetX)*e.scaleX,f=(l[2*s+1]+e.offsetY)*e.scaleY,b=(l[2*n]+e.offsetX)*e.scaleX,y=(l[2*n+1]+e.offsetY)*e.scaleY;if(g>=y)return;const v=h[4*r],w=h[4*r+1],A=h[4*r+2],x=h[4*a],C=h[4*a+1],S=h[4*a+2],T=h[4*o],_=h[4*o+1],k=h[4*o+2],E=Math.round(g),M=Math.round(y);let P,D,I,F,L,B,R,O;for(let N=E;N<=M;N++){if(N<f){const t=N<g?0:(g-N)/(g-f);P=p-(p-m)*t,D=v-(v-x)*t,I=w-(w-C)*t,F=A-(A-S)*t}else{let t;t=N>y?1:f===y?0:(f-N)/(f-y),P=m-(m-b)*t,D=x-(x-T)*t,I=C-(C-_)*t,F=S-(S-k)*t}let t;t=N<g?0:N>y?1:(g-N)/(g-y),L=p-(p-b)*t,B=v-(v-T)*t,R=w-(w-_)*t,O=A-(A-k)*t;const e=Math.round(Math.min(P,L)),i=Math.round(Math.max(P,L));let s=d*N+4*e;for(let n=e;n<=i;n++)t=(P-n)/(P-L),t<0?t=0:t>1&&(t=1),c[s++]=D-(D-B)*t|0,c[s++]=I-(I-R)*t|0,c[s++]=F-(F-O)*t|0,c[s++]=255}}var We=class extends He{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],se.loadMeshShader()}_createMeshCanvas(t,e,i,s=null){const n=Math.floor(this._bounds[0]),r=Math.floor(this._bounds[1]),a=Math.ceil(this._bounds[2])-n,o=Math.ceil(this._bounds[3])-r,l=Math.min(Math.ceil(Math.abs(a*t[0]*1.1)),3e3)||1,h=Math.min(Math.ceil(Math.abs(o*t[1]*1.1)),3e3)||1,c=a?a/l:1,d=o?o/h:1,u={coords:this._posData,colors:this._colData,offsetX:-n,offsetY:-r,scaleX:1/c,scaleY:1/d},p=l+4,g=h+4,m=i.create(p,g);if(re()&&this._vertexCount>48)m.context.drawImage(function(t,e,i,s,n,r,a){return se.draw(t,e,i,s,n,r,a,2)}(this._posData,this._colData,this._vertexCount,u,e,p,g),0,0);else{const t=m.context.createImageData(l,h);if(e){const i=t.data;for(let t=0,s=i.length;t<s;t+=4)i[t]=e[0],i[t+1]=e[1],i[t+2]=e[2],i[t+3]=255}for(let e=0,i=this._vertexCount;e<i;e+=3)Ge(t,u,e,e+1,e+2,e,e+1,e+2);m.context.putImageData(t,2,2)}return s?.applyToCanvas(m.context),{canvas:m.canvas,offsetX:n-2*c,offsetY:r-2*d,scaleX:c,scaleY:d}}isModifyingCurrentTransform(){return!0}getPattern(t,e,i,s){ze(t,this._bbox);const n=/* @__PURE__ */new Float32Array(2);if(s===Ne)B.singularValueDecompose2dScale(Y(t),n);else if(this.matrix){B.singularValueDecompose2dScale(this.matrix,n);const[t,i]=n;B.singularValueDecompose2dScale(e.baseTransform,n),n[0]*=t,n[1]*=i}else B.singularValueDecompose2dScale(e.baseTransform,n);const r=this._createMeshCanvas(n,s===Ne?null:this._background,e.canvasFactory,e.current.transferMapsFallback);s!==Ne&&(t.setTransform(...e.baseTransform),this.matrix&&t.transform(...this.matrix)),t.translate(r.offsetX,r.offsetY),t.scale(r.scaleX,r.scaleY);const a=t.createPattern(r.canvas,"no-repeat");return e.canvasFactory.destroy(r),a}},je=class extends He{getPattern(){return"hotpink"}},Ve=class t{static MAX_PATTERN_SIZE=3e3;constructor(t,e,i,s){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=i,this.baseTransform=s,this.patternBaseMatrix=this.matrix?B.transform(s,this.matrix):s}canSkipPatternCanvas([t,e,i,s]){const[n,r,a,o]=this.bbox,l=Math.abs(this.xstep),h=Math.abs(this.ystep);if(t>l+1e-6||e>h+1e-6)return null;const c=Math.floor((i-a)/l)+1,d=Math.ceil((i+t-n)/l)-1,u=Math.floor((s-o)/h)+1,p=Math.ceil((s+e-r)/h)-1;return d<=c&&p<=u?[c,u]:null}updatePatternDims(t,i){const s=e.slice();B.axialAlignedBoundingBox(t,B.inverseTransform(this.patternBaseMatrix),s),i[0]=s[2]-s[0],i[1]=s[3]-s[1],i[2]=s[0],i[3]=s[1]}_renderTileCanvas(t,e,i,s){const[n,r,a,o]=this.bbox,l=t.canvasFactory.create(i.size,s.size),h=l.context,c=this.canvasGraphicsFactory.createCanvasGraphics(h,e);return c.groupLevel=t.groupLevel,c.current.transferMapsFallback=t.current.transferMapsFallback,this.setFillAndStrokeStyleToContext(c,this.paintType,this.color),h.translate(-i.scale*n,-s.scale*r),c.transform(0,i.scale,0,0,s.scale,0,0),h.save(),c.dependencyTracker?.save(),this.clipBbox(c,n,r,a,o),c.baseTransform=Y(c.ctx),c.executeOperatorList(this.operatorList),c.endDrawing(),c.dependencyTracker?.restore(),h.restore(),l}_getCombinedScales(){const t=/* @__PURE__ */new Float32Array(2);B.singularValueDecompose2dScale(this.matrix,t);const[e,i]=t;return B.singularValueDecompose2dScale(this.baseTransform,t),[e*t[0],i*t[1]]}drawPattern(t,e,i=!1,[s,n],r){const[a,o,l,h]=this.bbox,c=t.dependencyTracker;c&&(t.dependencyTracker=new Te(c,r));try{if(t.save(),i?t.ctx.clip(e,"evenodd"):t.ctx.clip(e),t.ctx.setTransform(...this.patternBaseMatrix),t.ctx.translate(s*this.xstep,n*this.ystep),this.needsIsolation||1!==t.ctx.globalAlpha||"source-over"!==t.ctx.globalCompositeOperation||t.inSMaskMode){const e=l-a,i=h-o,[s,n]=this._getCombinedScales(),c=this.getSizeAndScale(e,this.ctx.canvas.width,s),d=this.getSizeAndScale(i,this.ctx.canvas.height,n),u=this._renderTileCanvas(t,r,c,d);t.ctx.drawImage(u.canvas,a,o,e,i),t.canvasFactory.destroy(u)}else t.resetGraphicsState(),this.setFillAndStrokeStyleToContext(t,this.paintType,this.color),this.clipBbox(t,a,o,l,h),t.baseTransformStack.push(t.baseTransform),t.baseTransform=Y(t.ctx),t.executeOperatorList(this.operatorList),t.baseTransform=t.baseTransformStack.pop();t.restore()}finally{c&&(t.dependencyTracker=c)}}createPatternCanvas(t,e){const[i,s,n,r]=this.bbox,a=n-i,o=r-s;let{xstep:l,ystep:h}=this;l=Math.abs(l),h=Math.abs(h),this.tilingType;const[c,d]=this._getCombinedScales();let u=a,p=o,g=!1,m=!1;Math.ceil(l*c)>=Math.ceil(a*c)?u=l:g=!0,Math.ceil(h*d)>=Math.ceil(o*d)?p=h:m=!0;const f=this.getSizeAndScale(u,this.ctx.canvas.width,c),b=this.getSizeAndScale(p,this.ctx.canvas.height,d),y=this._renderTileCanvas(t,e,f,b);if(g||m){const e=y.canvas;g&&(u=l),m&&(p=h);const n=this.getSizeAndScale(u,this.ctx.canvas.width,c),r=this.getSizeAndScale(p,this.ctx.canvas.height,d),f=n.size,b=r.size,v=t.canvasFactory.create(f,b),w=v.context,A=g?Math.min(Math.floor(a/l),Math.ceil(e.width/f)):0,x=m?Math.min(Math.floor(o/h),Math.ceil(e.height/b)):0;let C=e,S=null;if(m){S=t.canvasFactory.create(e.width,b);const i=S.context;for(let t=x;t>=0;t--)i.drawImage(e,0,b*t,e.width,b,0,0,e.width,b);C=S.canvas}for(let t=A;t>=0;t--)w.drawImage(C,f*t,0,f,b,0,0,f,b);return S&&t.canvasFactory.destroy(S),t.canvasFactory.destroy(y),{canvas:v.canvas,canvasEntry:v,scaleX:n.scale,scaleY:r.scale,offsetX:i,offsetY:s}}return{canvas:y.canvas,canvasEntry:y,scaleX:f.scale,scaleY:b.scale,offsetX:i,offsetY:s}}getSizeAndScale(e,i,s){const n=Math.max(t.MAX_PATTERN_SIZE,i);let r=Math.ceil(e*s);return r>=n?r=n:s=r/e,{scale:s,size:r}}clipBbox(t,e,i,s,n){const r=s-e,a=n-i,o=new Path2D;o.rect(e,i,r,a),B.axialAlignedBoundingBox([e,i,s,n],Y(t.ctx),t.current.minMax),t.ctx.clip(o),t.current.updateClipFromPath()}setFillAndStrokeStyleToContext(t,e,i){switch(e){case 1:i="#000000";break;case 2:break;default:throw new D(`Unsupported paint type: ${e}`)}const{ctx:s,current:n}=t;n.patternFill=n.patternStroke=!1,s.fillStyle=s.strokeStyle=n.transferMapsFallback?.applyToColor(i)??i,n.fillColor=n.strokeColor=i}isModifyingCurrentTransform(){return!1}getPattern(t,e,i,s,n){const r=s!==Ne?B.transform(i,this.patternBaseMatrix):i,a=this.createPatternCanvas(e,n);let o=new DOMMatrix(r);o=o.translate(a.offsetX,a.offsetY),o=o.scale(1/a.scaleX,1/a.scaleY);const l=t.createPattern(a.canvas,"repeat");return e.canvasFactory.destroy(a.canvasEntry),l.setTransform(o),l}},$e=16,Xe=/* @__PURE__ */new Float32Array(2);function Ke(t,e){if(t._removeMirroring)throw new Error("Context is already forwarding operations.");const i=/* @__PURE__ */new Map;for(const s of["save","restore","rotate","scale","translate","transform","setTransform","resetTransform","clip","moveTo","lineTo","bezierCurveTo","quadraticCurveTo","arc","arcTo","ellipse","rect","roundRect","closePath","beginPath"]){const n=t[s];"function"==typeof n&&"function"==typeof e[s]&&(i.set(s,n),t[s]=function(...t){return e[s](...t),n.apply(this,t)})}t._removeMirroring=()=>{for(const[e,s]of i)t[e]=s;delete t._removeMirroring}}function Ye(t,e,i,s,n,r,a,o,l,h){const[c,d,u,p,g,m]=Y(t);if(0===d&&0===u){const f=a*c+g,b=Math.round(f),y=o*p+m,v=Math.round(y),w=(a+l)*c+g,A=Math.abs(Math.round(w)-b)||1,x=(o+h)*p+m,C=Math.abs(Math.round(x)-v)||1;return t.setTransform(Math.sign(c),0,0,Math.sign(p),b,v),t.drawImage(e,i,s,n,r,0,0,A,C),t.setTransform(c,d,u,p,g,m),[A,C]}if(0===c&&0===p){const f=o*u+g,b=Math.round(f),y=a*d+m,v=Math.round(y),w=(o+h)*u+g,A=Math.abs(Math.round(w)-b)||1,x=(a+l)*d+m,C=Math.abs(Math.round(x)-v)||1;return t.setTransform(0,Math.sign(d),Math.sign(u),0,b,v),t.drawImage(e,i,s,n,r,0,0,C,A),t.setTransform(c,d,u,p,g,m),[C,A]}return t.drawImage(e,i,s,n,r,a,o,l,h),[Math.hypot(c,d)*l,Math.hypot(u,p)*h]}var qe=class{alphaIsShape=!1;fontSize=0;fontSizeScale=1;textMatrix=null;textMatrixScale=1;fontMatrix=s;leading=0;x=0;y=0;lineX=0;lineY=0;charSpacing=0;wordSpacing=0;textHScale=1;textRenderingMode=0;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=i.slice();constructor(t,e){this.clipBox=new Float32Array([0,0,t,e])}clone(){const t=Object.create(this);return t.clipBox=this.clipBox.slice(),t.minMax=this.minMax.slice(),t.tilingPatternDims=this.tilingPatternDims?.slice(),t}getPathBoundingBox(t=Re,e=null){const i=this.minMax.slice();if(t===Oe){e||w("Stroke bounding box must include transform."),B.singularValueDecompose2dScale(e,Xe);const t=Xe[0]*this.lineWidth/2,s=Xe[1]*this.lineWidth/2;i[0]-=t,i[1]-=s,i[2]+=t,i[3]+=s}return i}updateClipFromPath(){const t=B.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(i,0)}getClippedPathBoundingBox(t=Re,e=null){return B.intersect(this.clipBox,this.getPathBoundingBox(t,e))}};function Qe(t,e){const{width:i,height:s,kind:n}=e,r=s%$e,a=(s-r)/$e,o=0===r?a:a+1,l=t.createImageData(i,$e);let h=0;const c=e.data,u=l.data;let p;if(n===d.GRAYSCALE_1BPP)for(p=0;p<o;p++)({srcPos:h}=Le({src:c,srcPos:h,dest:u,width:i,height:p<a?$e:r})),t.putImageData(l,0,p*$e);else if(n===d.RGBA_32BPP){let e=0,s=i*$e*4;for(p=0;p<a;p++)u.set(c.subarray(h,h+s)),h+=s,t.putImageData(l,0,e),e+=$e;p<o&&(s=i*r*4,u.set(c.subarray(h,h+s)),t.putImageData(l,0,e))}else{if(n!==d.RGB_24BPP)throw new Error(`bad image kind: ${n}`);for(p=0;p<o;p++)({srcPos:h}=Be({src:c,srcPos:h,dest:new Uint32Array(u.buffer),width:i,height:p<a?$e:r})),t.putImageData(l,0,p*$e)}}function Je(t,e){if(e.bitmap)return void t.drawImage(e.bitmap,0,0);const{width:i,height:s}=e,n=s%$e,r=(s-n)/$e,a=0===n?r:r+1,o=t.createImageData(i,$e);let l=0;const h=e.data,c=o.data;for(let d=0;d<a;d++)({srcPos:l}=Le({src:h,srcPos:l,dest:c,width:i,height:d<r?$e:n,nonBlackColor:0})),t.putImageData(o,0,d*$e)}function Ze(t,e){for(const i of["strokeStyle","fillStyle","fillRule","globalAlpha","lineWidth","lineCap","lineJoin","miterLimit","globalCompositeOperation","font","filter"])void 0!==t[i]&&(e[i]=t[i]);void 0!==t.setLineDash&&(e.setLineDash(t.getLineDash()),e.lineDashOffset=t.lineDashOffset)}function ti(t,e){t.setAttribute?.("data-canvas-name",e),t._pdfjsCanvasName=e}function ei(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",void 0!==t.setLineDash&&(t.setLineDash([]),t.lineDashOffset=0);const{filter:e}=t;"none"!==e&&""!==e&&(t.filter="none")}var ii=class{#Rs;constructor(t){const[e,i=e,s=e]=t,n=B.identity0to256Map.slice();this.#Rs=[e||n,i||n,s||n]}applyToColor(t){if("string"!=typeof t||!t.startsWith("#"))return t;const[e,i,s]=X(t),[n,r,a]=this.#Rs;return B.makeHexColor(n[e],r[i],a[s])}applyToImageData({data:t}){const[e,i,s]=this.#Rs;for(let n=0,r=t.length;n<r;n+=4)t[n]=e[t[n]],t[n+1]=i[t[n+1]],t[n+2]=s[t[n+2]]}applyToCanvas(t){const{width:e,height:i}=t.canvas,s=t.getImageData(0,0,e,i);this.applyToImageData(s),t.putImageData(s,0,0)}};function si(t,e,i){if(e)return!0;B.singularValueDecompose2dScale(t,Xe);const s=Math.fround(i*V.PDF_TO_CSS_UNITS);return Xe[0]<=s&&Xe[1]<=s}var ni=["butt","round","square"],ri=["miter","round","bevel"],ai={},oi={},li=class t{static#Os=null;static#Ns=/* @__PURE__ */new WeakMap;#zs=0;#Hs=0;#Us=null;#Gs=null;#Ws=null;#js=null;#Vs=1;#$s;#Xs=null;#Ks=[];constructor(t,e,i,s,n,{optionalContentConfig:r,markedContentStack:a=null,pixelRatio:o=Q.pixelRatio},l,h,c,d){this.ctx=t,this.current=new qe(this.ctx.canvas.width,this.ctx.canvas.height),this.stateStack=[],this.pendingClip=null,this.pendingEOFill=!1,this.commonObjs=e,this.objs=i,this.canvasFactory=s,this.filterFactory=n,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=a||[],this.optionalContentConfig=r,this.pixelRatio=o,this.cachedPatterns=/* @__PURE__ */new Map,this.annotationCanvasMap=l,this.viewportScale=1,this.outputScaleX=1,this.outputScaleY=1,this.pageColors=h,this._cachedScaleForStroking=[-1,0],this._cachedBitmapsMap=/* @__PURE__ */new Map,this.dependencyTracker=c??null,this.imagesTracker=d??null}getObject(t,e,i=null){return"string"==typeof e?(this.dependencyTracker?.recordNamedDependency(t,e),e.startsWith("g_")?this.commonObjs.get(e):this.objs.get(e)):i}beginDrawing({transform:t,viewport:e,transparency:i=!1,background:s=null}){const n=this.ctx.canvas.width,r=this.ctx.canvas.height,a=this.ctx.fillStyle;if(this.ctx.fillStyle=s||"#ffffff",this.ctx.fillRect(0,0,n,r),this.ctx.fillStyle=a,i){const t=this.transparentCanvasEntry=this.canvasFactory.create(n,r);this.compositeCtx=this.ctx,({canvas:this.transparentCanvas,context:this.ctx}=t),this.ctx.save(),this.ctx.transform(...Y(this.compositeCtx))}this.ctx.save(),ei(this.ctx),t&&(this.ctx.transform(...t),this.outputScaleX=t[0],this.outputScaleY=t[3]),this.ctx.transform(...e.transform),this.viewportScale=e.scale,this.baseTransform=Y(this.ctx)}executeOperatorList(e,i,s,n,r,a){const o=e.argsArray,l=e.fnArray,h=this._pathCache;this._pathCache=e.pathCache??t.#Ns.getOrInsertComputed(e,U);try{let t=i||0;const h=o.length;if(h===t)return t;const c=h-t>10&&"function"==typeof s,d=c?Date.now()+15:0;let u=0;const p=this.commonObjs,m=this.objs;let f,b;for(;;){if(void 0!==r){if(t===r.nextBreakPoint)return r.breakIt(t,s),t;if(r.shouldSkip(t)){if(++t===h)return t;continue}}if(!a||a(t,e))if(f=l[t],b=o[t]??null,f!==g.dependency)null===b?this[f](t):this[f](t,...b);else for(const e of b){this.dependencyTracker?.recordNamedData(e,t);const i=e.startsWith("g_")?p:m;if(!i.has(e))return i.get(e,s,n),t}if(t++,t===h)return t;if(c&&++u>10){if(Date.now()>d)return s(),t;u=0}}}finally{this._pathCache=h}}#Ys(){for(;this.stateStack.length||this.inSMaskMode;)this.restore();this.current.activeSMask=null,this.ctx.restore(),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.#Ys();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.#Ks)this.#qs(t);this.#Ks.length=0,this.#Us=null,this.#Gs=null,this.#Ws=null,this.#js=null,this.#Vs=1,this.#Xs=null,this.#Hs=0,this.#zs=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.#Qs()}#Qs(){if(this.pageColors){const t=this.filterFactory.addHCMFilter(this.pageColors.foreground,this.pageColors.background);if("none"!==t){const e=this.ctx.filter;this.ctx.filter=t,this.ctx.drawImage(this.ctx.canvas,0,0),this.ctx.filter=e}}}_scaleImage(t,e){const i=t.width??t.displayWidth,s=t.height??t.displayHeight,n=[];let r=Math.max(Math.hypot(e[0],e[1]),1),a=Math.max(Math.hypot(e[2],e[3]),1),o=i,l=s;for(;r>2&&o>1||a>2&&l>1;){let t=o,e=l;r>2&&o>1&&(t=Math.ceil(o/2),r/=o/t),a>2&&l>1&&(e=Math.ceil(l/2),a/=l/e),n.push({newWidth:t,newHeight:e}),o=t,l=e}if(0===n.length)return{img:t,paintWidth:i,paintHeight:s,tmpCanvas:null};if(1===n.length){const{newWidth:e,newHeight:r}=n[0],a=this.canvasFactory.create(e,r);return a.context.drawImage(t,0,0,i,s,0,0,e,r),{img:a.canvas,paintWidth:e,paintHeight:r,tmpCanvas:a}}let h=this.canvasFactory.create(1,1),c=this.canvasFactory.create(1,1),d=i,u=s,p=t;for(const{newWidth:g,newHeight:m}of n)this.canvasFactory.reset(c,g,m),c.context.drawImage(p,0,0,d,u,0,0,g,m),[h,c]=[c,h],p=h.canvas,d=g,u=m;return this.canvasFactory.destroy(c),{img:h.canvas,paintWidth:d,paintHeight:u,tmpCanvas:h}}_createMaskCanvas(t,e){const s=this.ctx,{width:n,height:r}=e,a=this.current.patternFill,o=a?this.current.fillColor:s.fillStyle,l=Y(s);let h,c,d,u;if((e.bitmap||e.data)&&e.count>1){const i=e.bitmap||e.data.buffer;c=JSON.stringify(a?l:[l.slice(0,4),o]),h=this._cachedBitmapsMap.getOrInsertComputed(i,U);const s=h.get(c);if(s&&!a){const e=Math.round(Math.min(l[0],l[2])+l[4]),i=Math.round(Math.min(l[1],l[3])+l[5]);return this.dependencyTracker?.recordDependencies(t,Ie),{canvas:s,offsetX:e,offsetY:i}}d=s}d||(u=this.canvasFactory.create(n,r),Je(u.context,e));let p=B.transform(l,[1/n,0,0,-1/r,0,0]);p=B.transform(p,[1,0,0,1,0,-r]);const g=i.slice();B.axialAlignedBoundingBox([0,0,n,r],p,g);const[m,f,b,y]=g,v=Math.round(b-m)||1,w=Math.round(y-f)||1,A=this.canvasFactory.create(v,w),x=A.context,C=m,S=f;x.translate(-C,-S),x.transform(...p);let T=null;if(!d){const t=this._scaleImage(u.canvas,q(x));d=t.img,T=t.tmpCanvas,d!==u.canvas&&(this.canvasFactory.destroy(u),u=null),h&&a&&(h.set(c,d),T=null,u=null)}x.imageSmoothingEnabled=si(Y(x),e.interpolate,this.pixelRatio),Ye(x,d,0,0,d.width,d.height,0,0,n,r),T&&this.canvasFactory.destroy(T),u&&this.canvasFactory.destroy(u),x.globalCompositeOperation="source-in";const _=B.transform(q(x),[1,0,0,1,-C,-S]);return x.fillStyle=a?o.getPattern(s,this,_,Re,t):o,x.fillRect(0,0,n,r),h&&!a&&h.set(c,A.canvas),this.dependencyTracker?.recordDependencies(t,Ie),{canvas:A.canvas,canvasEntry:h&&!a?null:A,offsetX:Math.round(C),offsetY:Math.round(S)}}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=ni[e]}setLineJoin(t,e){this.dependencyTracker?.recordSimpleData("lineJoin",t),this.ctx.lineJoin=ri[e]}setMiterLimit(t,e){this.dependencyTracker?.recordSimpleData("miterLimit",t),this.ctx.miterLimit=e}setDash(t,e,i){this.dependencyTracker?.recordSimpleData("dash",t);const s=this.ctx;void 0!==s.setLineDash&&(s.setLineDash(e),s.lineDashOffset=i)}setRenderingIntent(t,e){}setFlatness(t,e){}setGState(t,e){for(const[i,s]of e)switch(i){case"LW":this.setLineWidth(t,s);break;case"LC":this.setLineCap(t,s);break;case"LJ":this.setLineJoin(t,s);break;case"ML":this.setMiterLimit(t,s);break;case"D":this.setDash(t,s[0],s[1]);break;case"RI":this.setRenderingIntent(t,s);break;case"FL":this.setFlatness(t,s);break;case"Font":this.setFont(t,s[0],s[1]);break;case"CA":this.dependencyTracker?.recordSimpleData("strokeAlpha",t),this.current.strokeAlpha=s;break;case"ca":this.dependencyTracker?.recordSimpleData("fillAlpha",t),this.ctx.globalAlpha=this.current.fillAlpha=s;break;case"BM":this.dependencyTracker?.recordSimpleData("globalCompositeOperation",t),this.ctx.globalCompositeOperation=s;break;case"SMask":this.dependencyTracker?.recordSimpleData("SMask",t),this.current.activeSMask=s?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(s);this.ctx.filter=e;let i=null;!s||"none"!==e&&L.isCanvasFilterSupported&&"none"!==this.ctx.filter&&""!==this.ctx.filter||(this.ctx.filter=e="none",i=new ii(s)),this.current.transferMaps=e,(i||this.current.transferMapsFallback)&&(this.current.transferMapsFallback=i,this.current.patternFill||(this.ctx.fillStyle=this.#Js(this.current.fillColor)),this.current.patternStroke||(this.ctx.strokeStyle=this.#Js(this.current.strokeColor)));break}}}get inSMaskMode(){return!!this.suspendedCtx}_clearPreparedSMask(){this.smaskPreparedEntry&&(this.canvasFactory.destroy(this.smaskPreparedEntry),this.smaskPreparedEntry=null),this.smaskPreparedFor=null,this.smaskPreparedOffsetX=0,this.smaskPreparedOffsetY=0,this.smaskPreparedOOBAlpha=null}_ensurePreparedSMask(t){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:i,backdrop:s,transferMap:n}=t,r="Luminosity"===i||"Alpha"===i&&n;if(!(r||"Luminosity"===i&&s))return void(this.smaskPreparedFor=t);let a;if("Luminosity"===i&&s){const[t,e,i]=X(s),r=Math.round(.3*t+.59*e+.11*i);a=n?.[r]??r}else a=n?.[0]??0;const{width:o,height:l}=this.ctx.canvas,h=o*l<e.width*e.height*4,c=r?{url:"Alpha"===i?this.filterFactory.addAlphaFilter(n):this.filterFactory.addLuminosityFilter(n),subtype:i,transferMap:n}:null,d="Luminosity"===i?s:null;let u,p,g;h?(u=this._bakeSMaskCanvas(e,t.offsetX,t.offsetY,o,l,d,c),p=0,g=0):(u=this._bakeSMaskCanvas(e,0,0,e.width,e.height,d,c),p=t.offsetX,g=t.offsetY),this.smaskPreparedEntry=u,this.smaskPreparedFor=t,this.smaskPreparedOffsetX=p,this.smaskPreparedOffsetY=g,this.smaskPreparedOOBAlpha=h||0===a?null:a}_bakeSMaskCanvas(t,e,i,s,n,r,a){r||a||w("_bakeSMaskCanvas with neither backdrop nor filter");const o=this.canvasFactory.create(s,n),l=o.context;if(l.drawImage(t,e,i),r&&(l.globalCompositeOperation="destination-atop",l.fillStyle=r,l.fillRect(0,0,s,n)),!a)return o;const h=this.canvasFactory.create(s,n),c=h.context;c.filter=a.url;const d=L.isCanvasFilterSupported&&"none"!==c.filter&&""!==c.filter;if(c.drawImage(o.canvas,0,0),L.isCanvasFilterSupported&&(c.filter="none"),!d){const t=c.getImageData(0,0,s,n),{data:e}=t,{transferMap:i}=a;if("Luminosity"===a.subtype)for(let s=0,n=e.length;s<n;s+=4){const t=.3*e[s]+.59*e[s+1]+.11*e[s+2]+.5|0;e[s]=e[s+1]=e[s+2]=0,e[s+3]=i?.[t]??t}else for(let s=3,n=e.length;s<n;s+=4)e[s]=i[e[s]];c.putImageData(t,0,0)}return this.canvasFactory.destroy(o),h}beginSMaskMode(t){if(this.inSMaskMode)throw new Error("beginSMaskMode called while already in smask mode");const{width:e,height:i}=this.ctx.canvas,s=this.canvasFactory.create(e,i);this.smaskScratchCanvas=s,this.suspendedCtx=this.ctx;const n=this.ctx=s.context;n.setTransform(this.suspendedCtx.getTransform()),Ze(this.suspendedCtx,n),Ke(n,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(),Ze(this.ctx,this.suspendedCtx),this.ctx=this.suspendedCtx,this.suspendedCtx=null,this.canvasFactory.destroy(this.smaskScratchCanvas),this.smaskScratchCanvas=null,this._clearPreparedSMask()}#Zs(t,e=null,i=1){const{width:s,height:n}=t,r=e??this.canvasFactory.create(s,n),a=r.context,o=(i=Math.round(255*i)/255)<1;o&&void 0===this.#$s&&(this.#$s=L.isCanvasFilterSupported?/* @__PURE__ */new Map:"none");let l="none";if(o&&this.#$s instanceof Map&&(l=this.#$s.getOrInsertComputed(i,()=>this.filterFactory.addKnockoutFilter(i))),!o||"none"!==l)return e&&(a.save(),a.setTransform(1,0,0,1,0,0),a.clearRect(0,0,s,n),a.restore()),a.filter=l,a.drawImage(t,0,0),a.filter="none",r;const h=t.getContext("2d",{willReadFrequently:!0}).getImageData(0,0,s,n),c=a.createImageData(s,n),d=h.data,u=c.data,p=i>0?1/i:1e6;for(let g=3,m=d.length;g<m;g+=4)u[g]=Math.min(Math.round(d[g]*p),255);return a.putImageData(c,0,0),r}#tn(t,e,i,s){let n=t?.[e]??null;if(!n||n.canvas.width===i&&n.canvas.height===s||(this.canvasFactory.destroy(n),n=null),!n)return n=this.canvasFactory.create(i,s),t&&(t[e]=n),n;const r=n.context;return r.save(),r.setTransform(1,0,0,1,0,0),r.clearRect(0,0,i,s),r.restore(),n}#en(t,e,i={}){const{backdropCanvas:s=null,destTransform:n=[1,0,0,1,0,0],backdropOffset:r=[0,0],reuseMaskEntry:a=null,poolMeta:o=null,sourceAlpha:l=1,sourceFilter:h="none",knockoutAlpha:c=1}=i,{width:d,height:u}=e,p=this.#Zs(e,a,c),g=t.globalCompositeOperation;if(t.save(),t.setTransform(...n),t.globalAlpha=1,L.isCanvasFilterSupported&&(t.filter="none"),t.globalCompositeOperation="destination-out",t.drawImage(p.canvas,0,0),s){const[e,i]=r,n=this.#tn(o,"knockoutBackdropEntry",d,u),a=n.context;a.drawImage(s,e,i,d,u,0,0,d,u),a.globalCompositeOperation="destination-in",a.drawImage(p.canvas,0,0),a.globalCompositeOperation="source-over",t.globalCompositeOperation="destination-over",t.drawImage(n.canvas,0,0),o||this.canvasFactory.destroy(n)}t.globalCompositeOperation=g,t.globalAlpha=l,L.isCanvasFilterSupported&&(t.filter=h??"none"),t.drawImage(e,0,0),t.restore(),a||this.canvasFactory.destroy(p)}#in(t=1){if(0===this.#zs||this.#Hs>0||!this.contentVisible)return!1;this.#Hs++,this.#Vs=t;const e=this.#Ks.at(-1),{canvas:i}=this.ctx,s=this.#tn(e,"knockoutTempEntry",i.width,i.height);this.#Us=s;const n=s.context;return n.save(),n.setTransform(this.ctx.getTransform()),Ze(this.ctx,n),this.#js=n.globalCompositeOperation,n.globalCompositeOperation="source-over",Ke(n,this.ctx),this.#Xs=e,this.#Gs=this.ctx,this.#Ws=this.suspendedCtx,this.ctx=n,this.inSMaskMode&&(this.suspendedCtx=n),!0}#sn(t){if(!t)return;const e=this.#Us,i=this.#Gs,s=this.#Ws,n=e.context;this.#Us=null,this.#Gs=null,this.#Ws=null,this.inSMaskMode&&this.suspendedCtx===n&&this.ctx!==n&&this.endSMaskMode(),this.inSMaskMode&&(this.suspendedCtx=s),this.ctx._removeMirroring(),this.ctx.globalCompositeOperation=this.#js,this.#js=null,Ze(this.ctx,i),this.ctx=i;const r=this.#Xs;this.#Xs=null;const a=this.#Vs;this.#Vs=1;try{this.#en(s??i,e.canvas,{backdropCanvas:r?.backdropCtx?.canvas??null,backdropOffset:r?.backdropCtx?[r.offsetX,r.offsetY]:[0,0],reuseMaskEntry:r?.knockoutMaskEntry??null,poolMeta:r,knockoutAlpha:a})}finally{n.restore(),this.#Hs--,r||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,i=this.suspendedCtx,s=this.#Hs>0&&i===this.ctx;this.composeSMask(s?null:i,e,this.ctx,t),s||(this.ctx.save(),this.ctx.setTransform(1,0,0,1,0,0),this.ctx.clearRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height),this.ctx.restore())}composeSMask(t,e,i,s){const n=s[0],r=s[1],a=s[2]-n,o=s[3]-r;if(0===a||0===o)return;const l=this.smaskPreparedEntry;if(l){let t=n,s=r,h=a,c=o;const d=this.smaskPreparedOOBAlpha,u=null!==d;if(u&&(t=Math.max(n,e.offsetX),s=Math.max(r,e.offsetY),h=Math.min(n+a,e.offsetX+e.canvas.width)-t,c=Math.min(r+o,e.offsetY+e.canvas.height)-s),h>0&&c>0){const e=t-this.smaskPreparedOffsetX,n=s-this.smaskPreparedOffsetY;i.save(),i.globalAlpha=1,i.setTransform(1,0,0,1,0,0);const r=new Path2D;r.rect(t,s,h,c),i.clip(r),i.globalCompositeOperation="destination-in",i.drawImage(l.canvas,e,n,h,c,t,s,h,c),i.restore()}u&&d<255&&this._applySMaskOOBAlpha(i,n,r,a,o,t,s,t+h,s+c,d)}else this.genericComposeSMask(e,i,a,o,n,r);t&&(t.save(),t.globalAlpha=1,t.globalCompositeOperation=e.blendMode||"source-over",t.setTransform(1,0,0,1,0,0),t.drawImage(i.canvas,n,r,a,o,n,r,a,o),t.restore())}_applySMaskOOBAlpha(t,e,i,s,n,r,a,o,l,h){const c=r<o&&a<l;if(c&&r===e&&a===i&&o===e+s&&l===i+n)return;const d=new Path2D;d.rect(e,i,s,n),c&&d.rect(r,a,o-r,l-a),t.save(),t.globalAlpha=h/255,t.setTransform(1,0,0,1,0,0),t.clip(d,"evenodd"),t.globalCompositeOperation="destination-in",t.fillStyle="#000000",t.fillRect(e,i,s,n),t.restore()}genericComposeSMask(t,e,i,s,n,r){const{context:a,offsetX:o,offsetY:l}=t;e.save(),e.globalAlpha=1,e.setTransform(1,0,0,1,0,0);const h=new Path2D;h.rect(n,r,i,s),e.clip(h),e.globalCompositeOperation="destination-in",e.drawImage(a.canvas,n-o,r-l,i,s,n,r,i,s),e.restore()}save(t){this.inSMaskMode&&Ze(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),0!==this.stateStack.length?(this.current=this.stateStack.pop(),this.ctx.restore(),this.inSMaskMode&&(Ze(this.suspendedCtx,this.ctx),this.ctx.setTransform(this.suspendedCtx.getTransform())),this.checkSMaskState(t),this.pendingClip=null,this._cachedScaleForStroking[0]=-1):this.inSMaskMode&&this.endSMaskMode()}resetGraphicsState(){const{clipBox:t,transferMaps:e,transferMapsFallback:i}=this.current,s=this.current=new qe(0,0);s.clipBox=t,s.transferMaps=e,s.transferMapsFallback=i;const n=this.ctx;n.lineWidth=1,n.lineCap="butt",n.lineJoin="miter",n.miterLimit=10,void 0!==n.setLineDash&&(n.setLineDash([]),n.lineDashOffset=0),this._cachedScaleForStroking[0]=-1}transform(t,e,i,s,n,r,a){this.dependencyTracker?.recordIncrementalData("transform",t),this.ctx.transform(e,i,s,n,r,a),this._cachedScaleForStroking[0]=-1}constructPath(t,e,i,s){let n=this._pathCache.get(t);if(!s)return n||(n=new Path2D,this._pathCache.set(t,n)),e!==g.stroke&&e!==g.closeStroke&&(this.current.tilingPatternDims=null),void this[e](t,n);if(null!==this.dependencyTracker){const i=e===g.stroke?this.current.lineWidth/2:0;this.dependencyTracker.resetBBox(t).recordBBox(t,this.ctx,s[0]-i,s[2]+i,s[1]-i,s[3]+i).recordDependencies(t,["transform"])}n||(n=rt(i[0]),this._pathCache.set(t,n)),B.axialAlignedBoundingBox(s,Y(this.ctx),this.current.minMax);const r=this.current.tilingPatternDims;if(r&&e!==g.stroke&&e!==g.closeStroke&&this.current.fillColor instanceof Ve){const t=B.intersect(this.current.clipBox,this.current.minMax);t?this.current.fillColor.updatePatternDims(t,r):this.current.tilingPatternDims=null}this[e](t,n),this._pathStartIdx=t}closePath(t){this.ctx.closePath()}stroke(t,e,i=!0){const s=i&&this.#in(this.current.strokeAlpha),n=this.ctx,r=this.current.strokeColor;if(n.globalAlpha=this.current.strokeAlpha,this.contentVisible)if("object"==typeof r&&r?.getPattern){const i=r.isModifyingCurrentTransform()?n.getTransform():null;if(n.save(),n.strokeStyle=r.getPattern(n,this,q(n),Oe,t),i){const t=new Path2D;t.addPath(e,n.getTransform().invertSelf().multiplySelf(i)),e=t}this.rescaleAndStroke(e,!1),n.restore()}else this.rescaleAndStroke(e,!0);this.dependencyTracker?.recordDependencies(t,_e),i&&this.consumePath(t,e,this.current.getClippedPathBoundingBox(Oe,Y(this.ctx))),n.globalAlpha=this.current.fillAlpha,this.#sn(s)}closeStroke(t,e){this.stroke(t,e)}fill(t,e,i=!0){const s=i&&this.#in(this.current.fillAlpha),n=this.ctx,r=this.current.fillColor,a=this.current.patternFill;let o=!1;const l=this.current.getClippedPathBoundingBox();if(this.dependencyTracker?.recordDependencies(t,ke),a){const a=this.current.tilingPatternDims,h=a&&r.canSkipPatternCanvas(a);if(h){const{pendingClip:n,pendingEOFill:a}=this;return this.pendingClip=null,this.pendingEOFill=!1,r.drawPattern(this,e,a,h,t),this.pendingClip=n,i&&this.consumePath(t,e,l),this.current.tilingPatternDims=null,void this.#sn(s)}const c=r.isModifyingCurrentTransform()?n.getTransform():null;if(this.dependencyTracker?.save(t),n.save(),n.fillStyle=r.getPattern(n,this,q(n),Re,t),c){const t=new Path2D;t.addPath(e,n.getTransform().invertSelf().multiplySelf(c)),e=t}o=!0}this.contentVisible&&null!==l&&(this.pendingEOFill?(n.fill(e,"evenodd"),this.pendingEOFill=!1):n.fill(e)),o&&(n.restore(),this.dependencyTracker?.restore(t)),i&&this.consumePath(t,e,l),this.#sn(s)}eoFill(t,e){this.pendingEOFill=!0,this.fill(t,e)}fillStroke(t,e){const i=this.#in(Math.min(this.current.fillAlpha,this.current.strokeAlpha));this.fill(t,e,!1),this.stroke(t,e,!1),this.consumePath(t,e),this.#sn(i)}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 i=this.#in(this.current.fillAlpha);this.ctx.fill(e),this.dependencyTracker?.recordDependencies(t,Me).recordOperation(t),this.#sn(i)}clip(t){this.dependencyTracker?.recordFutureForcedDependency("clipMode",t),this.pendingClip=ai}eoClip(t){this.dependencyTracker?.recordFutureForcedDependency("clipMode",t),this.pendingClip=oi}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,i=this.ctx;if(this.dependencyTracker){const{dependencyTracker:i}=this;void 0!==e&&i.recordFutureForcedDependency("textClip",i.getOpenMarker()).recordFutureForcedDependency("textClip",t),i.recordCloseMarker(t)}if(void 0!==e){const t=new Path2D,s=i.getTransform().invertSelf();for(const{transform:i,x:n,y:r,fontSize:a,path:o}of e)o&&t.addPath(o,new DOMMatrix(i).preMultiplySelf(s).translate(n,r).scale(a,-a));i.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,i){this.dependencyTracker?.recordSimpleData("font",t).recordSimpleDataFromNamed("fontObj",e,t);const n=this.commonObjs.get(e),r=this.current;if(!n)throw new Error(`Can't find font for ${e}`);if(r.fontMatrix=n.fontMatrix||s,0===r.fontMatrix[0]||r.fontMatrix[3],i<0?(i=-i,r.fontDirection=-1):r.fontDirection=1,this.current.font=n,this.current.fontSize=i,n.isType3Font)return;const a=n.loadedName||"sans-serif",o=n.systemFontInfo?.css||`"${a}", ${n.fallbackName}`;let l="normal";n.black?l="900":n.bold&&(l="bold");const h=n.italic?"italic":"normal",c=j(i,16,100);this.current.fontSizeScale=i/c,this.ctx.font=`${h} ${l} ${c}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,i){this.dependencyTracker?.resetIncrementalData("sameLineText").recordIncrementalData("moveText",t),this.current.x=this.current.lineX+=e,this.current.y=this.current.lineY+=i}setLeadingMoveText(t,e,i){this.setLeading(t,-i),this.moveText(t,e,i)}setTextMatrix(t,e){this.dependencyTracker?.resetIncrementalData("sameLineText").recordSimpleData("textMatrix",t);const{current:i}=this;i.textMatrix=e,i.textMatrixScale=Math.hypot(e[0],e[1]),i.x=i.lineX=0,i.y=i.lineY=0}nextLine(t){this.moveText(t,0,this.current.leading),this.dependencyTracker?.recordIncrementalData("moveText",this.dependencyTracker.getSimpleIndex("leading")??t)}#nn(t,e,i){const s=new Path2D;return s.addPath(t,new DOMMatrix(i).invertSelf().multiplySelf(e)),s}paintChar(t,e,i,s,n,r){const a=this.ctx,o=this.current,l=o.font,h=o.textRenderingMode,c=o.fontSize/o.fontSizeScale,d=3&h,u=!!(4&h),p=o.patternFill&&!l.missingFile,g=o.patternStroke&&!l.missingFile;let m;if((l.disableFontFace||u||p||g)&&!l.missingFile&&(m=l.getPathGenerator(this.commonObjs,e)),m&&(l.disableFontFace||p||g)){let e;if(a.save(),a.translate(i,s),a.scale(c,-c),this.dependencyTracker?.recordCharacterBBox(t,a,l),0===d||2===d)if(n){e=a.getTransform(),a.setTransform(...n);const t=this.#nn(m,e,n);a.fill(t)}else a.fill(m);if(1===d||2===d)if(r){e||=a.getTransform(),a.setTransform(...r);const{a:t,b:i,c:s,d:n}=e,o=B.inverseTransform(r),l=B.transform([t,i,s,n,0,0],o);B.singularValueDecompose2dScale(l,Xe),a.lineWidth*=Math.max(Xe[0],Xe[1])/c,a.stroke(this.#nn(m,e,r))}else a.lineWidth/=c,a.stroke(m);a.restore()}else 0!==d&&2!==d||(a.fillText(e,i,s),this.dependencyTracker?.recordCharacterBBox(t,a,l,c,i,s,()=>a.measureText(e))),1!==d&&2!==d||(this.dependencyTracker&&this.dependencyTracker?.recordCharacterBBox(t,a,l,c,i,s,()=>a.measureText(e)).recordDependencies(t,_e),a.strokeText(e,i,s));u&&((this.pendingTextPaths||=[]).push({transform:Y(a),x:i,y:s,fontSize:c,path:m}),this.dependencyTracker?.recordCharacterBBox(t,a,l,c,i,s))}get isFontSubpixelAAEnabled(){const t=this.canvasFactory.create(10,10),e=t.context;e.scale(1.5,1),e.fillText("I",0,10);const i=e.getImageData(0,0,10,10).data;this.canvasFactory.destroy(t);let s=!1;for(let n=3;n<i.length;n+=4)if(i[n]>0&&i[n]<255){s=!0;break}return T(this,"isFontSubpixelAAEnabled",s)}#rn(t,e,i){const s=this.ctx;s.save();const n=t.getPattern(s,this,q(s),e,i),r=Y(s);return s.restore(),[n,r]}showText(t,e){this.dependencyTracker&&(this.dependencyTracker.recordDependencies(t,Pe).resetBBox(t),4&this.current.textRenderingMode&&this.dependencyTracker.recordFutureForcedDependency("textClip",t).inheritPendingDependenciesAsFutureForcedDependencies());const i=this.current,s=i.font;if(s.isType3Font){const s=this.#in(i.fillAlpha);return this.showType3Text(t,e),this.dependencyTracker?.recordShowTextOperation(t),void this.#sn(s)}const n=i.fontSize;if(0===n)return void this.dependencyTracker?.recordOperation(t);const r=this.#in(i.fillAlpha),a=this.ctx,o=i.fontSizeScale,l=i.charSpacing,h=i.wordSpacing,c=i.fontDirection,d=i.textHScale*c,u=e.length,p=s.vertical,g=p?1:-1,m=n*i.fontMatrix[0],f=0===i.textRenderingMode&&!s.disableFontFace&&!i.patternFill;let b,y;a.save(),i.textMatrix&&a.transform(...i.textMatrix),a.translate(i.x,i.y+i.textRise),c>0?a.scale(d,-1):a.scale(d,1);const v=3&i.textRenderingMode,w=0===v||2===v,A=1===v||2===v;let x=i.lineWidth;const C=i.textMatrixScale;if(0===C||0===x?A&&(x=this.getSinglePixelWidth()):x/=C,1!==o&&(a.scale(o,o),x/=o),a.lineWidth=x,w&&i.patternFill&&([a.fillStyle,b]=this.#rn(i.fillColor,Re,t)),A&&i.patternStroke&&([a.strokeStyle,y]=this.#rn(i.strokeColor,Oe,t)),s.isInvalidPDFjsFont){const s=[];let n=0;for(const t of e)s.push(t.unicode),n+=t.width;const o=s.join("");if(a.fillText(o,0,0),null!==this.dependencyTracker){const e=a.measureText(o);this.dependencyTracker.recordBBox(t,this.ctx,-e.actualBoundingBoxLeft,e.actualBoundingBoxRight,-e.actualBoundingBoxAscent,e.actualBoundingBoxDescent).recordShowTextOperation(t)}return i.x+=n*m*d,a.restore(),this.compose(),void this.#sn(r)}let S,T=0,_=null;for(S=0;S<u;++S){const r=e[S];if("number"==typeof r){T+=g*r*n/1e3;continue}let d=!1;const u=(r.isSpace?h:0)+l,v=r.fontChar,w=r.accent;let A,x,C,k=r.width;if(p){const t=r.vmetric,e=-t[1]*m,i=t[2]*m;if(k=-t[0],A=e/o,x=(T+i)/o,r.isRotated){C=a.measureText(v);const t=m/o,e=r.width/2*t,i=A+e;A=x-380*t-e,x=(C.actualBoundingBoxAscent-C.actualBoundingBoxDescent)/2-i,d=!0,a.save(),a.rotate(Math.PI/2)}}else A=T/o,x=0;const E=r.isRotated?r.width:k;let M=1;if((s.remeasure||r.isRotated)&&E>0){C??=a.measureText(v);const t=1e3*C.width/n*o;E<t&&this.isFontSubpixelAAEnabled?(M=E/t,d||(d=!0,a.save()),a.scale(M,1),A/=M):E!==t&&(A+=(E-t)/2e3*n/o)}if(d&&s.missingFile&&(b||y)&&(_||=/* @__PURE__ */new Map,[a.fillStyle,a.strokeStyle]=_.getOrInsertComputed(r.isRotated?-M:M,()=>[b?this.#rn(i.fillColor,Re,t)[0]:a.fillStyle,y?this.#rn(i.strokeColor,Oe,t)[0]:a.strokeStyle])),this.contentVisible&&(r.isInFont||s.missingFile))if(f&&!w)a.fillText(v,A,x),this.dependencyTracker?.recordCharacterBBox(t,a,C?{bbox:null}:s,n/o,A,x,()=>C??a.measureText(v));else if(this.paintChar(t,v,A,x,b,y),w){const e=A+n*w.offset.x/o,i=x-n*w.offset.y/o;this.paintChar(t,w.fontChar,e,i,b,y)}T+=p?k*m-u*c:k*m+u*c,d&&a.restore()}p?i.y-=T:i.x+=T*d,a.restore(),this.compose(),this.dependencyTracker?.recordShowTextOperation(t),this.#sn(r)}showType3Text(t,e){const i=this.ctx,n=this.current,r=n.font,a=n.fontSize,o=n.fontDirection,l=r.vertical?1:-1,h=n.charSpacing,c=n.wordSpacing,d=n.textHScale*o,u=n.fontMatrix||s,p=e.length,g=3!==n.textRenderingMode;let m,f,b,y;if(0===a)return;this._cachedScaleForStroking[0]=-1,i.save(),n.textMatrix&&i.transform(...n.textMatrix),i.translate(n.x,n.y+n.textRise),i.scale(d,o);const w=this.dependencyTracker;this.dependencyTracker=w?new Te(w,t):null;try{for(m=0;m<p;++m){if(f=e[m],"number"==typeof f){y=l*f*a/1e3,this.ctx.translate(y,0),n.x+=y*d;continue}const t=(f.isSpace?c:0)+h,s=r.charProcOperatorList.get(f.operatorListId);s?this.contentVisible&&g&&(this.save(),i.scale(a,a),i.transform(...u),this.executeOperatorList(s),this.restore()):v(f.operatorListId),b=f.width*u[0]*a+t*o,i.translate(b,0),n.x+=b*d}}finally{w&&(this.dependencyTracker=w)}i.restore()}setCharWidth(t,e,i){}setCharWidthAndBounds(t,e,i,s,n,r,a){const o=new Path2D;o.rect(s,n,r-s,a-n),this.ctx.clip(o),this.dependencyTracker?.recordBBox(t,this.ctx,s,r,n,a).recordClipBox(t,this.ctx,s,r,n,a),this.endPath(t)}getColorN_Pattern(e,i){let s;if("TilingPattern"===i[0]){const e=this.baseTransform||Y(this.ctx);s=new Ve(i,this.ctx,{createCanvasGraphics:(e,i)=>new t(e,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:this.optionalContentConfig,markedContentStack:this.markedContentStack,pixelRatio:this.pixelRatio},void 0,void 0,this.dependencyTracker?new Te(this.dependencyTracker,i,!0):null)},e)}else s=this._getPattern(e,i[1],i[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 i=this.current.fillColor=this.getColorN_Pattern(t,e);this.current.patternFill=!0,this.current.tilingPatternDims=i instanceof Ve?[0,0,0,0]:null}#Js(t){return this.current.transferMapsFallback?.applyToColor(t)??t}setStrokeRGBColor(t,e){this.dependencyTracker?.recordSimpleData("strokeColor",t),this.current.strokeColor=e,this.ctx.strokeStyle=this.#Js(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.#Js(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,i=null){const s=this.cachedPatterns.getOrInsertComputed(e,()=>function(t){switch(t[0]){case"RadialAxial":return new Ue(t);case"Mesh":return new We(t);case"Dummy":return new je}throw new Error(`Unknown IR type: ${t[0]}`)}(this.getObject(t,e)));return i&&(s.matrix=i),s}shadingFill(t,e){if(!this.contentVisible)return;const s=this.#in(this.current.fillAlpha),n=this.ctx;this.save(t),n.fillStyle=this._getPattern(t,e).getPattern(n,this,q(n),Ne,t);const r=q(n);if(r){const{width:t,height:e}=n.canvas,s=i.slice();B.axialAlignedBoundingBox([0,0,t,e],r,s);const[a,o,l,h]=s;this.ctx.fillRect(a,o,l-a,h-o)}else this.ctx.fillRect(-1e10,-1e10,2e10,2e10);this.dependencyTracker?.resetBBox(t).recordFullPageBBox(t).recordDependencies(t,De).recordDependencies(t,ke).recordOperation(t),this.compose(this.current.getClippedPathBoundingBox()),this.restore(t),this.#sn(s)}beginInlineImage(){w("Should not call beginInlineImage")}beginImageData(){w("Should not call beginImageData")}paintFormXObjectBegin(t,e,i){if(this.contentVisible&&(this.save(t),this.baseTransformStack.push(this.baseTransform),e&&this.transform(t,...e),this.baseTransform=Y(this.ctx),i)){B.axialAlignedBoundingBox(i,this.baseTransform,this.current.minMax);const[e,s,n,r]=i,a=new Path2D;a.rect(e,s,n-e,r-s),this.ctx.clip(a),this.dependencyTracker?.recordClipBox(t,this.ctx,e,n,s,r),this.endPath(t)}}paintFormXObjectEnd(t){this.contentVisible&&(this.restore(t),this.baseTransform=this.baseTransformStack.pop())}beginGroup(t,e){if(!this.contentVisible)return;this.save(t);const{inSMaskMode:s}=this;s&&(this.endSMaskMode(),this.current.activeSMask=null);const n=this.ctx;if(!(e.needsIsolation&&(e.isolated||e.hasSoftMask)||e.knockout||e.isGray||0!==this.#zs||1!==n.globalAlpha||"source-over"!==n.globalCompositeOperation||s)){if(e.bbox){let t=new Path2D;const[i,s,r,a]=e.bbox;if(t.rect(i,s,r-i,a-s),e.matrix){const i=new Path2D;i.addPath(t,new DOMMatrix(e.matrix)),t=i}n.clip(t)}return this.groupStack.push(null),this.#Ks.push(null),void this.groupLevel++}!e.isolated&&!e.knockout&&this.#zs;const r=Y(n);e.matrix&&n.transform(...e.matrix);const a=[0,0,n.canvas.width,n.canvas.height];let o;e.bbox?(o=i.slice(),B.axialAlignedBoundingBox(e.bbox,Y(n),o),o=B.intersect(o,a)||[0,0,0,0]):o=a;const l=Math.floor(o[0]),h=Math.floor(o[1]),c=Math.max(Math.ceil(o[2])-l,1),d=Math.max(Math.ceil(o[3])-h,1);this.current.startNewPathAndClipBox([0,0,c,d]);const u=this.canvasFactory.create(c,d);e.smask&&this.smaskGroupCanvases.push(u);const p=u.context,g=e.knockout&&!e.isolated?n:null,m=!e.isolated&&!e.knockout&&!e.smask&&e.needsIsolation&&this.#zs>0,f=e.knockout?this.canvasFactory.create(c,d):null,b=this.#zs;e.knockout?this.#zs++:this.#zs=0,p.translate(-l,-h),p.transform(...r);const y=!e.isolated&&!e.smask&&e.needsIsolation,v=y&&!s&&0===b&&!e.knockout&&!e.isGray&&e.hasSoftMask&&1===n.globalAlpha&&"source-over"===n.globalCompositeOperation&&"none"===this.current.transferMaps&&!this.current.transferMapsFallback;if(y&&(s||v)&&(p.save(),p.setTransform(1,0,0,1,0,0),p.drawImage(n.canvas,-l,-h),p.restore()),e.bbox){let t=new Path2D;const[i,s,n,r]=e.bbox;if(t.rect(i,s,n-i,r-s),e.matrix){const i=new Path2D;i.addPath(t,new DOMMatrix(e.matrix)),t=i}p.clip(t)}e.smask&&this.smaskStack.push({canvas:u.canvas,context:p,offsetX:l,offsetY:h,subtype:e.smask.subtype,backdrop:e.smask.backdrop,transferMap:e.smask.transferMap||null}),e.smask&&!this.dependencyTracker||(n.setTransform(1,0,0,1,0,0),n.translate(l,h),n.save()),Ze(n,p),this.ctx=p,this.dependencyTracker?.inheritSimpleDataAsFutureForcedDependencies(["fillAlpha","strokeAlpha","globalCompositeOperation"]).pushBaseTransform(n),this.setGState(t,[["BM","source-over"],["ca",1],["CA",1],["TR",null]]),this.groupStack.push(n),this.#Ks.push({backdropCtx:g,savedKnockoutLevel:b,offsetX:l,offsetY:h,hasInnerBackdrop:m,replaceBackdrop:v,knockoutMaskEntry:f,knockoutTempEntry:null,knockoutBackdropEntry:null}),this.groupLevel++}endGroup(t,e){if(!this.contentVisible)return;this.groupLevel--;const s=this.ctx,n=this.groupStack.pop(),r=this.#Ks.pop();if(r&&(this.#zs=r.savedKnockoutLevel),null!==n)if(e.isGray&&this.#an(s),this.ctx=n,this.ctx.imageSmoothingEnabled=!1,this.dependencyTracker?.popBaseTransform(),e.smask)this.tempSMask=this.smaskStack.pop(),this.restore(t),this.dependencyTracker&&(this.ctx.restore(),this.inSMaskMode&&this.ctx.setTransform(this.suspendedCtx.getTransform())),this.#qs(r);else{this.ctx.restore();const e=Y(this.ctx);this.restore(t),this.current.transferMapsFallback?.applyToCanvas(s),this.ctx.save(),this.ctx.setTransform(...e);const a=i.slice();B.axialAlignedBoundingBox([0,0,s.canvas.width,s.canvas.height],e,a);const o=this.#Ks.at(-1);if(this.#zs>0)if(r.hasInnerBackdrop){const{width:t,height:i}=s.canvas,a=this.canvasFactory.create(t,i),o=a.context;o.drawImage(n.canvas,r.offsetX,r.offsetY,t,i,0,0,t,i),o.globalCompositeOperation="source-over",o.drawImage(s.canvas,0,0);const l=this.#Zs(s.canvas);o.globalCompositeOperation="destination-in",o.drawImage(l.canvas,0,0);const h=this.ctx.globalCompositeOperation,c=this.ctx.globalAlpha,d=this.ctx.filter;this.ctx.save(),this.ctx.setTransform(...e),this.ctx.globalAlpha=1,L.isCanvasFilterSupported&&(this.ctx.filter="none"),this.ctx.globalCompositeOperation="destination-out",this.ctx.drawImage(l.canvas,0,0),this.ctx.globalCompositeOperation=h,this.ctx.globalAlpha=c,L.isCanvasFilterSupported&&(this.ctx.filter=d??"none"),this.ctx.drawImage(a.canvas,0,0),this.ctx.restore(),this.canvasFactory.destroy(l),this.canvasFactory.destroy(a)}else{const t=o?.backdropCtx??null;this.#en(this.ctx,s.canvas,{backdropCanvas:t?.canvas??null,destTransform:e,backdropOffset:t?[o.offsetX+r.offsetX,o.offsetY+r.offsetY]:[0,0],sourceAlpha:this.ctx.globalAlpha,sourceFilter:this.ctx.filter})}else{if(r.replaceBackdrop){const t=new Path2D;t.rect(0,0,s.canvas.width,s.canvas.height),this.ctx.clip(t),this.ctx.globalCompositeOperation="copy"}this.ctx.drawImage(s.canvas,0,0)}this.ctx.restore(),this.canvasFactory.destroy({canvas:s.canvas,context:s}),this.#qs(r),this.compose(a)}else this.restore(t)}#an(t){const{canvas:e}=t,{width:i,height:s}=e;if(L.isCanvasFilterSupported)return 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),void t.restore();const n=t.getImageData(0,0,i,s),{data:r}=n;for(let a=0,o=r.length;a<o;a+=4){const t=.2126*r[a]+.7152*r[a+1]+.0722*r[a+2]+.5|0;r[a]=r[a+1]=r[a+2]=t}t.putImageData(n,0,0)}#qs(t){t&&(t.knockoutMaskEntry&&(this.canvasFactory.destroy(t.knockoutMaskEntry),t.knockoutMaskEntry=null),t.knockoutTempEntry&&(this.canvasFactory.destroy(t.knockoutTempEntry),t.knockoutTempEntry=null),t.knockoutBackdropEntry&&(this.canvasFactory.destroy(t.knockoutBackdropEntry),t.knockoutBackdropEntry=null))}beginAnnotation(t,e,i,s,n,r,a){if(this.#Ys(),ei(this.ctx),this.ctx.save(),this.save(t),this.baseTransform&&this.ctx.setTransform(...this.baseTransform),i){const n=i[2]-i[0],o=i[3]-i[1];if(r&&this.annotationCanvasMap){(s=s.slice())[4]-=i[0],s[5]-=i[1],B.singularValueDecompose2dScale(Y(this.ctx),Xe);const{viewportScale:t}=this,r=Math.ceil(n*this.outputScaleX*t),l=Math.ceil(o*this.outputScaleY*t);this.annotationCanvas=this.canvasFactory.create(r,l);const{canvas:h,context:c}=this.annotationCanvas;if(a){const t=this.annotationCanvasMap.getOrInsertComputed(e,H);ti(h,a);const i=t.findIndex(t=>function(t){return t._pdfjsCanvasName??null}(t)===a);-1===i?t.push(h):t[i]=h}else this.annotationCanvasMap.set(e,h);this.annotationCanvas.savedCtx=this.ctx,this.ctx=c,this.ctx.save(),this.ctx.setTransform(Xe[0],0,0,-Xe[1],0,o*Xe[1]),ei(this.ctx)}else{ei(this.ctx),this.endPath(t);const e=new Path2D;e.rect(i[0],i[1],n,o),this.ctx.clip(e)}}this.current=new qe(this.ctx.canvas.width,this.ctx.canvas.height),this.baseTransformStack.push(this.baseTransform),this.transform(t,...s),this.transform(t,...n),this.baseTransform=Y(this.ctx)}endAnnotation(t){this.annotationCanvas&&(this.ctx.restore(),this.#Qs(),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 i=e.count;(e=this.getObject(t,e.data,e)).count=i;const s=this.#in(this.current.fillAlpha),n=this.ctx,r=this._createMaskCanvas(t,e),a=r.canvas;n.save(),n.setTransform(1,0,0,1,0,0),n.drawImage(a,r.offsetX,r.offsetY),this.dependencyTracker?.resetBBox(t).recordBBox(t,this.ctx,r.offsetX,r.offsetX+a.width,r.offsetY,r.offsetY+a.height).recordOperation(t),n.restore(),r.canvasEntry&&this.canvasFactory.destroy(r.canvasEntry),this.compose(),this.#sn(s)}paintImageMaskXObjectRepeat(t,e,i,s=0,n=0,r,a){if(!this.contentVisible)return;e=this.getObject(t,e.data,e);const o=this.#in(this.current.fillAlpha),l=this.ctx;l.save();const h=Y(l);l.transform(i,s,n,r,0,0);const c=this._createMaskCanvas(t,e);l.setTransform(1,0,0,1,c.offsetX-h[4],c.offsetY-h[5]),this.dependencyTracker?.resetBBox(t);for(let d=0,u=a.length;d<u;d+=2){const e=B.transform(h,[i,s,n,r,a[d],a[d+1]]);l.drawImage(c.canvas,e[4],e[5]),this.dependencyTracker?.recordBBox(t,this.ctx,e[4],e[4]+c.canvas.width,e[5],e[5]+c.canvas.height)}l.restore(),c.canvasEntry&&this.canvasFactory.destroy(c.canvasEntry),this.compose(),this.dependencyTracker?.recordOperation(t),this.#sn(o)}paintImageMaskXObjectGroup(t,e){if(!this.contentVisible)return;const i=this.#in(this.current.fillAlpha),s=this.ctx,n=this.current.patternFill,r=n?this.current.fillColor:s.fillStyle;this.dependencyTracker?.resetBBox(t).recordDependencies(t,Ie);for(const a of e){const{data:e,width:i,height:o,transform:l}=a,h=this.canvasFactory.create(i,o),c=h.context;c.save(),Je(c,this.getObject(t,e,a)),c.globalCompositeOperation="source-in",c.fillStyle=n?r.getPattern(c,this,q(s),Re,t):r,c.fillRect(0,0,i,o),c.restore(),s.save(),s.transform(...l),s.scale(1,-1),Ye(s,h.canvas,0,0,i,o,0,-1,1,1),this.canvasFactory.destroy(h),this.dependencyTracker?.recordBBox(t,s,0,i,0,o),s.restore()}this.compose(),this.dependencyTracker?.recordOperation(t),this.#sn(i)}paintImageXObject(t,e){if(!this.contentVisible)return;const i=this.getObject(t,e);i&&this.paintInlineImageXObject(t,i)}paintImageXObjectRepeat(t,e,i,s,n){if(!this.contentVisible)return;const r=this.getObject(t,e);if(!r)return;const a=r.width,o=r.height,l=[];for(let h=0,c=n.length;h<c;h+=2)l.push({transform:[i,0,0,s,n[h],n[h+1]],x:0,y:0,w:a,h:o});this.paintInlineImageXObjectGroup(t,r,l)}applyTransferMapsToCanvas(t){return"none"!==this.current.transferMaps?(t.filter=this.current.transferMaps,t.drawImage(t.canvas,0,0),t.filter="none"):this.current.transferMapsFallback?.applyToCanvas(t),t.canvas}applyTransferMapsToBitmap(t){const{transferMaps:e,transferMapsFallback:i}=this.current;if("none"===e&&!i)return{img:t.bitmap,canvasEntry:null};const{bitmap:s,width:n,height:r}=t,a=this.canvasFactory.create(n,r),o=a.context;return o.filter=e,o.drawImage(s,0,0),o.filter="none",i?.applyToCanvas(o),{img:a.canvas,canvasEntry:a}}paintInlineImageXObject(t,e){if(!this.contentVisible)return;const i=e.width,s=e.height,n=this.#in(this.current.fillAlpha),r=this.ctx;this.save(t);const{filter:a}=r;let o;"none"!==a&&""!==a&&(r.filter="none"),r.scale(1/i,-1/s);let l=null;if(e.bitmap){const t=this.applyTransferMapsToBitmap(e);o=t.img,l=t.canvasEntry}else{const t=this.canvasFactory.create(i,s);Qe(t.context,e),o=this.applyTransferMapsToCanvas(t.context),l=t}const h=this._scaleImage(o,q(r));r.imageSmoothingEnabled=si(Y(r),e.interpolate,this.pixelRatio),this.dependencyTracker&&(this.dependencyTracker.resetBBox(t).recordBBox(t,r,0,i,-s,0).recordDependencies(t,Ee).recordOperation(t),this.imagesTracker?.record(r,i,s,this.dependencyTracker.clipBox)),Ye(r,h.img,0,0,h.paintWidth,h.paintHeight,0,-s,i,s),h.tmpCanvas&&this.canvasFactory.destroy(h.tmpCanvas),l&&this.canvasFactory.destroy(l),this.compose(),this.restore(t),this.#sn(n)}paintInlineImageXObjectGroup(t,e,i){if(!this.contentVisible)return;const s=this.#in(this.current.fillAlpha),n=this.ctx;let r,a=null;if(e.bitmap&&!this.current.transferMapsFallback)r=e.bitmap;else if(e.bitmap)({img:r,canvasEntry:a}=this.applyTransferMapsToBitmap(e));else{const t=e.width,i=e.height,s=this.canvasFactory.create(t,i);Qe(s.context,e),r=this.applyTransferMapsToCanvas(s.context),a=s}this.dependencyTracker?.resetBBox(t);for(const o of i)n.save(),n.transform(...o.transform),n.scale(1,-1),Ye(n,r,o.x,o.y,o.w,o.h,0,-1,1,1),this.dependencyTracker?.recordBBox(t,n,0,1,-1,0),n.restore();a&&this.canvasFactory.destroy(a),this.dependencyTracker?.recordOperation(t),this.compose(),this.#sn(s)}paintSolidColorImageMask(t){if(!this.contentVisible)return;const e=this.#in(this.current.fillAlpha);this.dependencyTracker?.resetBBox(t).recordBBox(t,this.ctx,0,1,0,1).recordDependencies(t,ke).recordOperation(t),this.ctx.fillRect(0,0,1,1),this.compose(),this.#sn(e)}markPoint(t,e){}markPointProps(t,e,i){}beginMarkedContent(t,e){this.dependencyTracker?.beginMarkedContent(t),this.markedContentStack.push({visible:!0})}beginMarkedContentProps(t,e,i){this.dependencyTracker?.beginMarkedContent(t),"OC"===e?this.markedContentStack.push({visible:this.optionalContentConfig.isVisible(i)}):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,i){const s=this.current.isEmptyClip();this.pendingClip&&this.current.updateClipFromPath(),this.pendingClip||this.compose(i);const n=this.ctx;this.pendingClip?(s||(this.pendingClip===oi?n.clip(e,"evenodd"):n.clip(e)),this.pendingClip=null,this.dependencyTracker?.bboxToClipBoxDropOperation(t).recordFutureForcedDependency("clipPath",t)):this.dependencyTracker?.recordOperation(t),this.current.startNewPathAndClipBox(this.current.clipBox)}getSinglePixelWidth(){const t=Y(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]),i=Math.hypot(t[0],t[2]),s=Math.hypot(t[1],t[3]);return Math.max(i,s)/e}getScaleForStroking(){if(-1===this._cachedScaleForStroking[0]){const{lineWidth:t}=this.current,{a:e,b:i,c:s,d:n}=this.ctx.getTransform();let r,a;if(0===i&&0===s){const i=Math.abs(e),s=Math.abs(n);if(i===s)if(0===t)r=a=1/i;else{const e=i*t;r=a=e<1?1/e:1}else if(0===t)r=1/i,a=1/s;else{const e=i*t,n=s*t;r=e<1?1/e:1,a=n<1?1/n:1}}else{const o=Math.abs(e*n-i*s),l=Math.hypot(e,i),h=Math.hypot(s,n);if(0===t)r=h/o,a=l/o;else{const e=t*o;r=h>e?h/e:1,a=l>e?l/e:1}}this._cachedScaleForStroking[0]=r,this._cachedScaleForStroking[1]=a}return this._cachedScaleForStroking}rescaleAndStroke(e,i){const{ctx:s,current:{lineWidth:n}}=this,[r,a]=this.getScaleForStroking();if(r===a)return s.lineWidth=(n||1)*r,void s.stroke(e);const o=t.#Os??=new DOMMatrix,l=s.getLineDash();i&&s.save(),s.scale(r,a),o.a=1/r,o.d=1/a;const h=new Path2D;if(h.addPath(e,o),l.length>0){const t=Math.max(r,a);s.setLineDash(l.map(e=>e/t)),s.lineDashOffset/=t}s.lineWidth=n||1,s.stroke(h),i&&s.restore()}isContentVisible(){for(let t=this.markedContentStack.length-1;t>=0;t--)if(!this.markedContentStack[t].visible)return!1;return!0}};for(const Yn in g)void 0!==li.prototype[Yn]&&(li.prototype[g[Yn]]=li.prototype[Yn]);var hi=class extends de{constructor({ownerDocument:t=globalThis.document,enableHWA:e=!1}){super({enableHWA:e}),this._document=t}_createCanvas(t,e){const i=this._document.createElement("canvas");return i.width=t,i.height=e,i}},ci=class extends ue{#on;#ln;#hn;#cn;#dn;#un;#_=0;constructor({docId:t,ownerDocument:e=globalThis.document}){super(),this.#cn=t,this.#dn=e}get#E(){return this.#ln||=/* @__PURE__ */new Map}get#pn(){return this.#un||=/* @__PURE__ */new Map}get#gn(){if(!this.#hn){const t=this.#dn.createElement("div"),{style:e}=t;e.colorScheme="only light",e.visibility="hidden",e.contain="strict",e.width=e.height=0,e.position="absolute",e.top=e.left=0,e.zIndex=-1;const i=this.#dn.createElementNS(n,"svg");i.setAttribute("width",0),i.setAttribute("height",0),this.#hn=this.#dn.createElementNS(n,"defs"),t.append(i),i.append(this.#hn),this.#dn.body.append(t)}return this.#hn}#mn(t){const e=t=>t&&Array.from(t,t=>t/255).join(",");if(1===t.length){const i=e(t[0]);return[i,i,i]}const[i,s,n]=t;return[e(i),e(s),e(n)]}#fn(t){if(void 0===this.#on){this.#on="";const t=this.#dn.URL;t!==this.#dn.baseURI&&(ut(t)||(this.#on=C(t,"")))}return`url(${this.#on}#${t})`}addFilter(t){if(!t)return"none";let e=this.#E.get(t);if(e)return e;const[i,s,n]=this.#mn(t),r=1===t.length?i:`${i}${s}${n}`;if(e=this.#E.get(r),e)return this.#E.set(t,e),e;const a=`g_${this.#cn}_transfer_map_${this.#_++}`,o=this.#fn(a);this.#E.set(t,o),this.#E.set(r,o);const l=this.#bn(a);return this.#yn(i,s,n,l),o}addHCMFilter(t,e){const i=`${t}-${e}`,s="base";let n=this.#pn.get(s);if(n?.key===i)return n.url;if(n?(n.filter?.remove(),n.key=i,n.url="none",n.filter=null):(n={key:i,url:"none",filter:null},this.#pn.set(s,n)),!t||!e)return n.url;const r=this.#vn(t);t=B.makeHexColor(...r);const a=this.#vn(e);if(e=B.makeHexColor(...a),this.#wn(),"#000000"===t&&"#ffffff"===e||t===e)return n.url;const o=Array.from({length:256},(t,e)=>et(e/255)).join(","),l=`g_${this.#cn}_hcm_filter`,h=n.filter=this.#bn(l);this.#yn(o,o,o,h),this.#An(h);const c=(t,e)=>{const i=r[t]/255,s=a[t]/255,n=new Array(e+1);for(let r=0;r<=e;r++)n[r]=i+r/e*(s-i);return n.join(",")};return this.#yn(c(0,5),c(1,5),c(2,5),h),n.url=this.#fn(l),n.url}addSelectionHCMFilter(t,e){return this.addHighlightHCMFilter("selection",t,e,"HighlightText","Highlight")}addSelectionFilter(){return this.addHighlightHCMFilter("selection_default","black","white","HighlightText","Highlight")}createSelectionStyle(t=null){const e=t?this.addSelectionHCMFilter(t.foreground,t.background):this.addSelectionFilter();return"none"!==e&&L.platform.isFirefox?{"backdrop-filter":e,"background-color":"transparent"}:null}addAlphaFilter(t){let e=this.#E.get(t);if(e)return e;const[i]=this.#mn([t]),s=`alpha_${i}`;if(e=this.#E.get(s),e)return this.#E.set(t,e),e;const n=`g_${this.#cn}_alpha_map_${this.#_++}`,r=this.#fn(n);this.#E.set(t,r),this.#E.set(s,r);const a=this.#bn(n);return this.#xn(i,a),r}addLuminosityFilter(t){let e,i,s=this.#E.get(t||"luminosity");if(s)return s;if(t?([e]=this.#mn([t]),i=`luminosity_${e}`):i="luminosity",s=this.#E.get(i),s)return this.#E.set(t,s),s;const n=`g_${this.#cn}_luminosity_map_${this.#_++}`,r=this.#fn(n);this.#E.set(t,r),this.#E.set(i,r);const a=this.#bn(n);return this.#Cn(a),t&&this.#xn(e,a),r}addKnockoutFilter(t=0){const e=t>0?Math.min(1/t,1e6):1e6,i=`knockout_${e}`,s=this.#E.get(i);if(s)return s;const r=`g_${this.#cn}_knockout_filter_${this.#_++}`,a=this.#fn(r);this.#E.set(i,a);const o=this.#bn(r),l=this.#dn.createElementNS(n,"feComponentTransfer");o.append(l);const h=this.#dn.createElementNS(n,"feFuncA");return h.setAttribute("type","linear"),h.setAttribute("slope",`${e}`),h.setAttribute("intercept","0"),l.append(h),a}addHighlightHCMFilter(t,e,i,s,n){const r=`${e}-${i}-${s}-${n}`;let a=this.#pn.get(t);if(a?.key===r)return a.url;if(a?(a.filter?.remove(),a.key=r,a.url="none",a.filter=null):(a={key:r,url:"none",filter:null},this.#pn.set(t,a)),!e||!i)return a.url;const[o,l]=[e,i].map(this.#vn.bind(this));let h=Math.round(.2126*o[0]+.7152*o[1]+.0722*o[2]),c=Math.round(.2126*l[0]+.7152*l[1]+.0722*l[2]),[d,u]=[s,n].map(this.#Sn.bind(this));c<h&&([h,c,d,u]=[c,h,u,d]),this.#wn();const p=(t,e,i)=>{const s=new Array(256),n=(c-h)/i,r=t/255,a=(e-t)/(255*i);let o=0;for(let l=0;l<=i;l++){const t=Math.round(h+l*n),e=r+l*a;for(let i=o;i<=t;i++)s[i]=e;o=t+1}for(let l=o;l<256;l++)s[l]=s[o-1];return s.join(",")},g=`g_${this.#cn}_hcm_${t}_filter`,m=a.filter=this.#bn(g);return this.#An(m),this.#yn(p(d[0],u[0],5),p(d[1],u[1],5),p(d[2],u[2],5),m),a.url=this.#fn(g),a.url}destroy(t=!1){t&&this.#un?.size||(this.#hn?.parentNode.parentNode.remove(),this.#hn=null,this.#ln?.clear(),this.#ln=null,this.#un?.clear(),this.#un=null,this.#_=0)}#Cn(t){const e=this.#dn.createElementNS(n,"feColorMatrix");e.setAttribute("type","matrix"),e.setAttribute("values","0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3 0.59 0.11 0 0"),t.append(e)}#An(t){const e=this.#dn.createElementNS(n,"feColorMatrix");e.setAttribute("type","matrix"),e.setAttribute("values","0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0 0 0 1 0"),t.append(e)}#bn(t){const e=this.#dn.createElementNS(n,"filter");return e.setAttribute("color-interpolation-filters","sRGB"),e.setAttribute("id",t),this.#gn.append(e),e}#Tn(t,e,i){if(!i)return;const s=this.#dn.createElementNS(n,e);s.setAttribute("type","discrete"),s.setAttribute("tableValues",i),t.append(s)}#yn(t,e,i,s){const r=this.#dn.createElementNS(n,"feComponentTransfer");s.append(r),this.#Tn(r,"feFuncR",t),this.#Tn(r,"feFuncG",e),this.#Tn(r,"feFuncB",i)}#xn(t,e){const i=this.#dn.createElementNS(n,"feComponentTransfer");e.append(i),this.#Tn(i,"feFuncA",t)}#vn(t){return this.#gn.style.color="CanvasText",this.#gn.style.backgroundColor=t,K(getComputedStyle(this.#gn).getPropertyValue("background-color"))}#_n(t){return this.#gn.style.color="CanvasText",this.#gn.style.backgroundColor=t,X(getComputedStyle(this.#gn).getPropertyValue("background-color"))}#wn(){this.#gn.style.color="",this.#gn.style.backgroundColor=""}#Sn(t){const[e,i,s,n]=this.#_n(t);if(1===n)return[e,i,s];const[r,a,o]=this.#vn("Canvas");return[di(e,r,n),di(i,a,n),di(s,o,n)]}};function di(t,e,i){return Math.round(i*t+(1-i)*e)}var ui=/\p{Cc}/u;function pi(t){return function(t){const e=t[0];if(t.length<2||'"'!==e&&"'"!==e||t.at(-1)!==e)return!1;const i=t.length-1;for(let s=1;s<i;s++){const n=t[s];if(n===e||ui.test(n))return!1;if("\\"===n&&(++s>=i||ui.test(t[s])))return!1}return!0}(t)?t:`"${t.replaceAll(/["\\\p{Cc}]/gu,t=>'"'===t||"\\"===t?`\\${t}`:`\\${t.codePointAt(0).toString(16)} `)}"`}var gi=class{#kn=/* @__PURE__ */new Set;#En=/* @__PURE__ */new Set;#Mn=null;constructor({ownerDocument:t=globalThis.document,styleElement:e=null}){this._document=t,this.styleElement=null,this.loadingRequests=[],this.loadTestFontId=0}addNativeFontFace(t){this.#kn.add(t),this._document.fonts.add(t)}removeNativeFontFace(t){this.#kn.delete(t),this._document.fonts.delete(t)}insertRule(t){const e=this.#Pn();e.insertRule(t,e.cssRules.length)}#Pn(){if(this.#Mn)return this.#Mn;const t=this._document.defaultView?.CSSStyleSheet||globalThis.CSSStyleSheet;if(!this.styleElement&&t){const{adoptedStyleSheets:e}=this._document;if(e){const i=new t;return e.push(i),this.#Mn=i}}return this.styleElement||(this.styleElement=this._document.createElement("style"),this._document.documentElement.getElementsByTagName("head")[0].append(this.styleElement)),this.#Mn=this.styleElement.sheet}clear(){for(const t of this.#kn)this._document.fonts.delete(t);if(this.#kn.clear(),this.#En.clear(),this.#Mn){const{adoptedStyleSheets:t}=this._document;t?.includes(this.#Mn)&&(this._document.adoptedStyleSheets=t.filter(t=>t!==this.#Mn)),this.#Mn=null}this.styleElement?.remove(),this.styleElement=null}async loadSystemFont({systemFontInfo:t,disableFontFace:e,_inspectFont:i}){if(t&&!this.#En.has(t.loadedName)){if(A(!e,"loadSystemFont shouldn't be called when `disableFontFace` is set."),this.isFontLoadingAPISupported){const{loadedName:e,src:s,style:n}=t,r=new FontFace(e,s,n);this.addNativeFontFace(r);try{await r.load(),this.#En.add(e),i?.(t)}catch{t.baseFontName,this.removeNativeFontFace(r)}return}w("Not implemented: loadSystemFont without the Font Loading API.")}}async bind(t){if(t.attached||t.missingFile&&!t.systemFontInfo)return;if(t.attached=!0,t.systemFontInfo)return void(await this.loadSystemFont(t));if(this.isFontLoadingAPISupported){const e=t.createNativeFontFace();if(e){this.addNativeFontFace(e);try{await e.loaded}catch(i){throw e.family,t.disableFontFace=!0,i}}return}const e=t.createFontFaceRule();if(e){if(this.insertRule(e),this.isSyncFontLoadingSupported)return;await this.#Dn(t)}}get isFontLoadingAPISupported(){return T(this,"isFontLoadingAPISupported",!!this._document?.fonts)}get isSyncFontLoadingSupported(){return T(this,"isSyncFontLoadingSupported",t||L.platform.isFirefox)}#Dn(t){const{loadingRequests:e}=this,{promise:i,resolve:s}=Promise.withResolvers(),n={done:!1,resolve:s};function r(t,e){return t.charCodeAt(e)<<24|t.charCodeAt(e+1)<<16|t.charCodeAt(e+2)<<8|255&t.charCodeAt(e+3)}function a(t,e,i,s){return t.substring(0,e)+s+t.substring(e+i)}let o,l;e.push(n),this._loadTestFont??=atob("T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQAABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwAAAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbmFtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAAAADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6AABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAAMQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAAAAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAAAAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQAAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMAAQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAAEAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgcA/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQAAAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAgABAAAAAAAAAAAD6AAAAAAAAA==");const h=this._document.createElement("canvas");h.width=1,h.height=1;const c=h.getContext("2d");let d=0;const u=`lt${Date.now()}${this.loadTestFontId++}`;let p=this._loadTestFont;p=a(p,976,u.length,u);const g=1482184792;let m=r(p,16);for(o=0,l=u.length-3;o<l;o+=4)m=m-g+r(u,o)|0;var f;o<u.length&&(m=m-g+r(u+"XXX",o)|0),p=a(p,16,4,(f=m,String.fromCharCode(f>>24&255,f>>16&255,f>>8&255,255&f)));const b=`@font-face {font-family:"${u}";src:url(data:font/opentype;base64,${btoa(p)});}`;this.insertRule(b);const y=this._document.createElement("div");y.style.visibility="hidden",y.style.width=y.style.height="10px",y.style.position="absolute",y.style.top=y.style.left="0px";for(const v of[t.loadedName,u]){const t=this._document.createElement("span");t.textContent="Hi",t.style.fontFamily=v,y.append(t)}return this._document.body.append(y),function t(e,i){++d>30?i():(c.font="30px "+e,c.fillText(".",0,20),c.getImageData(0,0,1,1).data[3]>0?i():setTimeout(t.bind(null,e,i)))}(u,()=>{y.remove(),function(){for(A(!n.done,"completeRequest() cannot be called twice."),n.done=!0;e.length>0&&e[0].done;){const t=e.shift();setTimeout(t.resolve,0)}}()}),i}},mi=class{#In=/* @__PURE__ */new Map;#Fn;constructor(t,e=null,i,s){this.#Fn=t,this._inspectFont=e,i&&(this.charProcOperatorList=i),s&&Object.assign(this,s)}createNativeFontFace(){const{data:t}=this;if(!t||this.disableFontFace)return null;let e;if(this.cssFontInfo){const i={weight:this.cssFontInfo.fontWeight};this.cssFontInfo.italicAngle&&(i.style=`oblique ${this.cssFontInfo.italicAngle}deg`),e=new FontFace(pi(this.cssFontInfo.fontFamily),t,i)}else e=new FontFace(this.loadedName,t,{});return this._inspectFont?.(this),e}createFontFaceRule(){const{data:t}=this;if(!t||this.disableFontFace)return null;const e=`url(data:${this.mimetype};base64,${t.toBase64()});`;let i;if(this.cssFontInfo){let t=`font-weight: ${this.cssFontInfo.fontWeight};`;this.cssFontInfo.italicAngle&&(t+=`font-style: oblique ${this.cssFontInfo.italicAngle}deg;`),i=`@font-face {font-family:${pi(this.cssFontInfo.fontFamily)};${t}src:${e}}`}else i=`@font-face {font-family:"${this.loadedName}";src:${e}}`;return this._inspectFont?.(this,e),i}getPathGenerator(t,e){let i=this.#In.get(e);if(i)return i;const s=`${this.loadedName}_path_${e}`;let n;try{n=t.get(s)}catch(r){}return i=rt(n?.path),this.fontExtraProperties||t.delete(s),this.#In.set(e,i),i}get black(){return this.#Fn.black}get bold(){return this.#Fn.bold}get disableFontFace(){return this.#Fn.disableFontFace}set disableFontFace(t){T(this,"disableFontFace",!!t)}get fontExtraProperties(){return this.#Fn.fontExtraProperties}get isInvalidPDFjsFont(){return this.#Fn.isInvalidPDFjsFont}get isType3Font(){return this.#Fn.isType3Font}get italic(){return this.#Fn.italic}get missingFile(){return this.#Fn.missingFile}get remeasure(){return this.#Fn.remeasure}get vertical(){return this.#Fn.vertical}get bbox(){return this.#Fn.bbox}get fontMatrix(){return this.#Fn.fontMatrix}get fallbackName(){return this.#Fn.fallbackName}get loadedName(){return this.#Fn.loadedName}get mimetype(){return this.missingFile?null:"font/opentype"}get data(){return this.#Fn.data}clearData(){this.#Fn.clearData()}get cssFontInfo(){return this.#Fn.cssFontInfo}get systemFontInfo(){return this.#Fn.systemFontInfo}},fi=class{#Ln=null;#Bn=null;_fullReader=null;_rangeReaders=/* @__PURE__ */new Set;_source=null;constructor(t,e,i){this._source=t,this.#Ln=e,this.#Bn=i}get _progressiveDataLength(){return this._fullReader?._loaded??0}getFullReader(){return A(!this._fullReader,"BasePDFStream.getFullReader can only be called once."),this._fullReader=new this.#Ln(this)}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const i=new this.#Bn(this,t,e);return this._rangeReaders.add(i),i}cancelAllRequests(t){this._fullReader?.cancel(t);for(const e of new Set(this._rangeReaders))e.cancel(t)}},bi=class{onProgress=null;_contentLength=0;_filename=null;_headersCapability=Promise.withResolvers();_isRangeSupported=!1;_isStreamingSupported=!1;_loaded=0;_stream=null;constructor(t){this._stream=t}_callOnProgress(){this.onProgress?.({loaded:this._loaded,total:this._contentLength})}get headersReady(){return this._headersCapability.promise}get filename(){return this._filename}get contentLength(){return this._contentLength}get isRangeSupported(){return this._isRangeSupported}get isStreamingSupported(){return this._isStreamingSupported}async read(){w("Abstract method `read` called")}cancel(t){w("Abstract method `cancel` called")}},yi=class{_stream=null;constructor(t,e,i){this._stream=t}async read(){w("Abstract method `read` called")}cancel(t){w("Abstract method `cancel` called")}};function vi(t,e){const i=new Headers;if(!t||!e||"object"!=typeof e)return i;for(const s in e){const t=e[s];void 0!==t&&i.append(s,t)}return i}function wi(t){return URL.parse(t)?.origin??null}function Ai({responseHeaders:t,isHttp:e,rangeChunkSize:i,disableRange:s}){const n={contentLength:0,isRangeSupported:!1},r=parseInt(t.get("Content-Length"),10);return Number.isInteger(r)?(n.contentLength=r,r<=2*i||s||!e||"bytes"!==t.get("Accept-Ranges")||"identity"===(t.get("Content-Encoding")||"identity")&&(n.isRangeSupported=!0),n):n}function xi(t){const e=t.get("Content-Disposition");if(e){let t=function(t){let e=!0,i=s("filename\\*","i").exec(t);if(i){i=i[1];let t=a(i);return t=unescape(t),t=o(t),t=l(t),r(t)}if(i=function(t){const e=[];let i;const n=s("filename\\*((?!0\\d)\\d+)(\\*?)","ig");for(;null!==(i=n.exec(t));){let[,t,s,n]=i;if(t=parseInt(t,10),t in e){if(0===t)break}else e[t]=[s,n]}const r=[];for(let s=0;s<e.length&&s in e;++s){let[t,i]=e[s];i=a(i),t&&(i=unescape(i),0===s&&(i=o(i))),r.push(i)}return r.join("")}(t),i)return r(l(i));if(i=s("filename","i").exec(t),i){i=i[1];let t=a(i);return t=l(t),r(t)}function s(t,e){return new RegExp("(?:^|;)\\s*"+t+'\\s*=\\s*([^";\\s][^;\\s]*|"(?:[^"\\\\]|\\\\"?)+"?)',e)}function n(t,i){if(t){if(!/^[\x00-\xFF]+$/.test(i))return i;try{const s=new TextDecoder(t,{fatal:!0}),n=F(i);i=s.decode(n),e=!1}catch{}}return i}function r(t){return e&&/[\x80-\xff]/.test(t)&&(t=n("utf-8",t),e&&(t=n("iso-8859-1",t))),t}function a(t){if(t.startsWith('"')){const e=t.slice(1).split('\\"');for(let t=0;t<e.length;++t){const i=e[t].indexOf('"');-1!==i&&(e[t]=e[t].slice(0,i),e.length=t+1),e[t]=e[t].replaceAll(/\\(.)/g,"$1")}t=e.join('"')}return t}function o(t){const e=t.indexOf("'");return-1===e?t:n(t.slice(0,e),t.slice(e+1).replace(/^[^']*'/,""))}function l(t){return!t.startsWith("=?")||/[\x00-\x19\x80-\xff]/.test(t)?t:t.replaceAll(/=\?([\w-]*)\?([QB])\?((?:[^?]|\?(?!=))*)\?=/gi,function(t,e,i,s){if("q"===i||"Q"===i)return n(e,s=s.replaceAll("_"," ").replaceAll(/=([0-9a-f]{2})/gi,(t,e)=>String.fromCharCode(parseInt(e,16))));try{s=atob(s)}catch{}return n(e,s)})}return""}(e);if(t.includes("%"))try{t=decodeURIComponent(t)}catch{}if(pt(t))return t}return null}function Ci(t,e){return new P(`Unexpected server response (${t}) while retrieving PDF "${e.href}".`,t,404===t||0===t&&"file:"===e.protocol)}function Si(t,e){if(t!==e)throw new Error(`Expected range response-origin "${t}" to match "${e}".`)}function Ti(t,e,i,s){return fetch(t,{method:"GET",headers:e,signal:s.signal,mode:"cors",credentials:i?"include":"same-origin",redirect:"follow"})}function _i(t,e){if(200!==t&&206!==t)throw Ci(t,e)}function ki(t){if(t instanceof Uint8Array)return t.buffer;if(t instanceof ArrayBuffer)return t;throw new Error(`getArrayBuffer - unexpected data: ${t}`)}var Ei=class extends fi{_responseOrigin=null;constructor(t){super(t,Mi,Pi);const{httpHeaders:e,url:i}=t;A(/https?:/.test(i.protocol),"PDFFetchStream only supports http(s):// URLs."),this.headers=vi(!0,e)}},Mi=class extends bi{_abortController=new AbortController;_reader=null;constructor(t){super(t);const{disableRange:e,disableStream:i,rangeChunkSize:s,url:n,withCredentials:r}=t._source;this._isStreamingSupported=!i,Ti(n,new Headers(t.headers),r,this._abortController).then(i=>{t._responseOrigin=wi(i.url),_i(i.status,n),this._reader=i.body.getReader();const r=i.headers,{contentLength:a,isRangeSupported:o}=Ai({responseHeaders:r,isHttp:!0,rangeChunkSize:s,disableRange:e});this._contentLength=a,this._isRangeSupported=o,this._filename=xi(r),!this._isStreamingSupported&&this._isRangeSupported&&this.cancel(new I("Streaming is disabled.")),this._headersCapability.resolve()}).catch(this._headersCapability.reject)}async read(){await this._headersCapability.promise;const{value:t,done:e}=await this._reader.read();return e?{value:t,done:e}:(this._loaded+=t.byteLength,this._callOnProgress(),{value:ki(t),done:!1})}cancel(t){this._reader?.cancel(t).catch(()=>{}),this._abortController.abort()}},Pi=class extends yi{_abortController=new AbortController;_readCapability=Promise.withResolvers();_reader=null;constructor(t,e,i){super(t,e,i);const{url:s,withCredentials:n}=t._source,r=new Headers(t.headers);r.append("Range",`bytes=${e}-${i-1}`),Ti(s,r,n,this._abortController).then(e=>{Si(wi(e.url),t._responseOrigin),_i(e.status,s),this._reader=e.body.getReader(),this._readCapability.resolve()}).catch(this._readCapability.reject),this._readCapability.promise.catch(()=>{})}async read(){await this._readCapability.promise;const{value:t,done:e}=await this._reader.read();return e?{value:t,done:e}:{value:ki(t),done:!1}}cancel(t){this._reader?.cancel(t).catch(()=>{}),this._abortController.abort()}};function Di(t){return t instanceof Uint8Array&&t.byteLength===t.buffer.byteLength?t.buffer:new Uint8Array(t).buffer}function Ii(){for(const t of this._requests)t.resolve({value:void 0,done:!0});this._requests.length=0}var Fi=class extends fi{_progressiveDone=!1;_queuedChunks=[];constructor(t){super(t,Li,Bi);const{pdfDataRangeTransport:e}=t,{initialData:i,progressiveDone:s}=e;if(i?.length>0){const t=Di(i);this._queuedChunks.push(t)}this._progressiveDone=s,e.transportReady(t=>{switch(t.type){case"range":case"progressiveRead":this.#Rn(t.begin,t.chunk);break;case"progressiveDone":this._fullReader?.progressiveDone(),this._progressiveDone=!0}})}#Rn(t,e){const i=Di(e);if(void 0===t)this._fullReader?this._fullReader._enqueue(i):this._queuedChunks.push(i);else{const e=this._rangeReaders.keys().find(e=>e._begin===t);A(e,"#onReceiveData - no `PDFDataTransportStreamRangeReader` instance found."),e._enqueue(i)}}getFullReader(){const t=super.getFullReader();return this._queuedChunks=null,t}getRangeReader(t,e){const i=super.getRangeReader(t,e);return i&&(i.onDone=()=>this._rangeReaders.delete(i),this._source.pdfDataRangeTransport.requestDataRange(t,e)),i}cancelAllRequests(t){super.cancelAllRequests(t),this._source.pdfDataRangeTransport.abort()}},Li=class extends bi{#On=Ii.bind(this);_done=!1;_queuedChunks=null;_requests=[];constructor(t){super(t);const{pdfDataRangeTransport:e,disableRange:i,disableStream:s}=t._source,{length:n,contentDispositionFilename:r}=e;this._queuedChunks=t._queuedChunks||[];for(const o of this._queuedChunks)this._loaded+=o.byteLength;this._done=t._progressiveDone,this._contentLength=n,this._isStreamingSupported=!s,this._isRangeSupported=!i,pt(r)&&(this._filename=r),this._headersCapability.resolve();const a=this._loaded;Promise.resolve().then(()=>{a>0&&this._loaded===a&&this._callOnProgress()})}_enqueue(t){this._done||(this._requests.length>0?this._requests.shift().resolve({value:t,done:!1}):this._queuedChunks.push(t),this._loaded+=t.byteLength,this._callOnProgress())}async read(){if(this._queuedChunks.length>0)return{value:this._queuedChunks.shift(),done:!1};if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0,this.#On()}progressiveDone(){this._done||=!0,0===this._queuedChunks.length&&this.#On()}},Bi=class extends yi{#On=Ii.bind(this);onDone=null;_begin=-1;_done=!1;_queuedChunk=null;_requests=[];constructor(t,e,i){super(t,e,i),this._begin=e}_enqueue(t){this._done||(0===this._requests.length?this._queuedChunk=t:(this._requests.shift().resolve({value:t,done:!1}),this.#On()),this._done=!0,this.onDone?.())}async read(){if(this._queuedChunk){const t=this._queuedChunk;return this._queuedChunk=null,{value:t,done:!1}}if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0,this.#On(),this.onDone?.()}},Ri=class extends fi{#Nn=/* @__PURE__ */new WeakMap;_responseOrigin=null;constructor(t){super(t,Oi,Ni);const{httpHeaders:e,url:i}=t;this.url=i,this.isHttp=/https?:/.test(i.protocol),this.headers=vi(this.isHttp,e)}_request(t){const e=new XMLHttpRequest,i={validateStatus:null,onHeadersReceived:t.onHeadersReceived,onDone:t.onDone,onError:t.onError,onProgress:t.onProgress};this.#Nn.set(e,i),e.open("GET",this.url),e.withCredentials=this._source.withCredentials;for(const[s,n]of this.headers)e.setRequestHeader(s,n);return this.isHttp&&"begin"in t&&"end"in t?(e.setRequestHeader("Range",`bytes=${t.begin}-${t.end-1}`),i.validateStatus=t=>206===t||200===t):i.validateStatus=t=>200===t,e.responseType="arraybuffer",A(t.onError,"Expected `onError` callback to be provided."),e.onerror=()=>t.onError(e.status),e.onreadystatechange=this.#zn.bind(this,e),e.onprogress=this.#Hn.bind(this,e),e.send(null),e}#Hn(t,e){this.#Nn.get(t)?.onProgress?.(e)}#zn(t,e){const i=this.#Nn.get(t);if(!i)return;if(t.readyState>=2&&i.onHeadersReceived&&(i.onHeadersReceived(),delete i.onHeadersReceived),4!==t.readyState)return;if(!this.#Nn.has(t))return;if(this.#Nn.delete(t),0===t.status&&this.isHttp)return void i.onError(t.status);const s=t.status||200;if(!i.validateStatus(s))return void i.onError(t.status);const n="string"!=typeof(r=t.response)?r:F(r).buffer;var r;if(206===s){const e=t.getResponseHeader("Content-Range");/bytes \d+-\d+\/\d+/.test(e)?i.onDone(n):i.onError(0)}else n?i.onDone(n):i.onError(t.status)}_abortRequest(t){this.#Nn.has(t)&&(this.#Nn.delete(t),t.abort())}getRangeReader(t,e){const i=super.getRangeReader(t,e);return i&&(i.onClosed=()=>this._rangeReaders.delete(i)),i}},Oi=class extends bi{#On=Ii.bind(this);_cachedChunks=[];_done=!1;_requests=[];_storedError=null;constructor(t){super(t),this._fullRequestXhr=t._request({onHeadersReceived:this.#Un.bind(this),onDone:this.#Gn.bind(this),onError:this.#Wn.bind(this),onProgress:this.#Hn.bind(this)})}#Un(){const t=this._stream,{disableRange:e,rangeChunkSize:i}=t._source,s=this._fullRequestXhr;t._responseOrigin=wi(s.responseURL);const n=s.getAllResponseHeaders(),r=new Headers(n?function(t){let e=t.length;for(;e>0&&" "!==t[e-1]&&/\s/.test(t[e-1]);)e--;return t.slice(0,e)}(n.trimStart()).split(/[\r\n]+/).map(t=>{const[e,...i]=t.split(": ");return[e,i.join(": ")]}):[]),{contentLength:a,isRangeSupported:o}=Ai({responseHeaders:r,isHttp:t.isHttp,rangeChunkSize:i,disableRange:e});this._contentLength=a,this._isRangeSupported=o,this._filename=xi(r),this._isRangeSupported&&t._abortRequest(s),this._headersCapability.resolve()}#Gn(t){this._requests.length>0?this._requests.shift().resolve({value:t,done:!1}):this._cachedChunks.push(t),this._done=!0,0===this._cachedChunks.length&&this.#On()}#Wn(t){this._storedError=Ci(t,this._stream.url),this._headersCapability.reject(this._storedError);for(const e of this._requests)e.reject(this._storedError);this._requests.length=0,this._cachedChunks.length=0}#Hn(t){this.onProgress?.({loaded:t.loaded,total:t.lengthComputable?t.total:this._contentLength})}async read(){if(await this._headersCapability.promise,this._storedError)throw this._storedError;if(this._cachedChunks.length>0)return{value:this._cachedChunks.shift(),done:!1};if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0,this._headersCapability.reject(t),this.#On(),this._stream._abortRequest(this._fullRequestXhr),this._fullRequestXhr=null}},Ni=class extends yi{#On=Ii.bind(this);onClosed=null;_done=!1;_queuedChunk=null;_requests=[];_storedError=null;constructor(t,e,i){super(t,e,i),this._requestXhr=t._request({begin:e,end:i,onHeadersReceived:this.#Un.bind(this),onDone:this.#Gn.bind(this),onError:this.#Wn.bind(this),onProgress:null})}#Un(){const t=wi(this._requestXhr?.responseURL);try{Si(t,this._stream._responseOrigin)}catch(e){this._storedError=e,this.#Wn(0)}}#Gn(t){this._requests.length>0?this._requests.shift().resolve({value:t,done:!1}):this._queuedChunk=t,this._done=!0,this.#On(),this.onClosed?.()}#Wn(t){this._storedError??=Ci(t,this._stream.url);for(const e of this._requests)e.reject(this._storedError);this._requests.length=0,this._queuedChunk=null}async read(){if(this._storedError)throw this._storedError;if(null!==this._queuedChunk){const t=this._queuedChunk;return this._queuedChunk=null,{value:t,done:!1}}if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0,this.#On(),this._stream._abortRequest(this._requestXhr),this.onClosed?.()}};function zi(t,e=null){const i=process.getBuiltinModule("fs"),{Readable:s}=process.getBuiltinModule("stream"),n=i.createReadStream(t,e);return s.toWeb(n)}var Hi=class extends fi{constructor(t){super(t,Ui,Gi);const{url:e}=t;A("file:"===e.protocol,"PDFNodeStream only supports file:// URLs.")}},Ui=class extends bi{_reader=null;constructor(t){super(t);const{disableRange:e,disableStream:i,rangeChunkSize:s,url:n}=t._source;this._isStreamingSupported=!i,process.getBuiltinModule("fs/promises").lstat(n).then(t=>{const i=zi(n);this._reader=i.getReader();const{size:r}=t;this._contentLength=r,this._isRangeSupported=!e&&r>2*s,!this._isStreamingSupported&&this._isRangeSupported&&this.cancel(new I("Streaming is disabled.")),this._headersCapability.resolve()}).catch(t=>{"ENOENT"===t.code&&(t=Ci(0,n)),this._headersCapability.reject(t)})}async read(){await this._headersCapability.promise;const{value:t,done:e}=await this._reader.read();return e?{value:t,done:e}:(this._loaded+=t.byteLength,this._callOnProgress(),{value:ki(t),done:!1})}cancel(t){this._reader?.cancel(t).catch(()=>{})}},Gi=class extends yi{_readCapability=Promise.withResolvers();_reader=null;constructor(t,e,i){super(t,e,i);const{url:s}=t._source;try{const t=zi(s,{start:e,end:i-1});this._reader=t.getReader(),this._readCapability.resolve()}catch(n){this._readCapability.reject(n)}this._readCapability.promise.catch(()=>{})}async read(){await this._readCapability.promise;const{value:t,done:e}=await this._reader.read();return e?{value:t,done:e}:{value:ki(t),done:!1}}cancel(t){this._reader?.cancel(t).catch(()=>{})}},Wi=class{static#jn=null;static#Vn=[];static#$n="";static#Xn="";static get rendererPorts(){return this.#Vn}static set rendererPorts(t){if(!Array.isArray(t)||!t.every(t=>"undefined"!=typeof Worker&&t instanceof Worker))throw new Error("Invalid `rendererPorts` type.");this.#Vn=t}static get rendererSrc(){return this.#$n}static set rendererSrc(t){if("string"!=typeof t)throw new Error("Invalid `rendererSrc` type.");this.#$n=t}static get workerPort(){return this.#jn}static set workerPort(t){if(!("undefined"!=typeof Worker&&t instanceof Worker)&&null!==t)throw new Error("Invalid `workerPort` type.");this.#jn=t}static get workerSrc(){return this.#Xn}static set workerSrc(t){if("string"!=typeof t)throw new Error("Invalid `workerSrc` type.");this.#Xn=t}},ji=class{#Kn;#Yn;constructor({parsedData:t,rawData:e}){this.#Kn=t,this.#Yn=e}getRaw(){return this.#Yn}get(t){return this.#Kn.get(t)??null}[Symbol.iterator](){return this.#Kn.entries()}},Vi=class{static strings=["fontFamily","fontWeight","italicAngle"]},$i=class{static strings=["css","loadedName","baseFontName","src"]},Xi=class{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},Ki=class{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},Yi=class{static get decoder(){return T(this,"decoder",new TextDecoder)}static get encoder(){return T(this,"encoder",new TextEncoder)}};function qi(t,e,i,s=0){const{decoder:n}=Yi;for(let a=0;a<i;a++)s+=e.getUint32(s)+4;const r=e.getUint32(s);return n.decode(new Uint8Array(t,s+4,r))}var Qi=class{#qn;#Qn;constructor(t){this.#qn=t,this.#Qn=new DataView(t)}#Jn(t){return A(t<Vi.strings.length,"Invalid string index"),qi(this.#qn,this.#Qn,t)}get fontFamily(){return T(this,"fontFamily",this.#Jn(0))}get fontWeight(){return T(this,"fontWeight",this.#Jn(1))}get italicAngle(){return T(this,"italicAngle",this.#Jn(2))}},Ji=class{#qn;#Qn;constructor(t){this.#qn=t,this.#Qn=new DataView(t)}#Jn(t){return A(t<$i.strings.length,"Invalid string index"),qi(this.#qn,this.#Qn,t,4)}get css(){return T(this,"css",this.#Jn(0))}get loadedName(){return T(this,"loadedName",this.#Jn(1))}get baseFontName(){return T(this,"baseFontName",this.#Jn(2))}get src(){return T(this,"src",this.#Jn(3))}get style(){let t=0;return t+=4+this.#Qn.getUint32(t),T(this,"style",{style:qi(this.#qn,this.#Qn,0,t),weight:qi(this.#qn,this.#Qn,1,t)})}},Zi=class{#qn;#Qn;constructor(t){this.#qn=t,this.#Qn=new DataView(t)}#Zn(t){A(t<Xi.bools.length,"Invalid boolean index");const e=Math.floor(t/4),i=2*t%8,s=this.#Qn.getUint8(e)>>i&3;return 0===s?void 0:2===s}get black(){return T(this,"black",this.#Zn(0))}get bold(){return T(this,"bold",this.#Zn(1))}get disableFontFace(){return T(this,"disableFontFace",this.#Zn(2))}get fontExtraProperties(){return T(this,"fontExtraProperties",this.#Zn(3))}get isInvalidPDFjsFont(){return T(this,"isInvalidPDFjsFont",this.#Zn(4))}get isType3Font(){return T(this,"isType3Font",this.#Zn(5))}get italic(){return T(this,"italic",this.#Zn(6))}get missingFile(){return T(this,"missingFile",this.#Zn(7))}get remeasure(){return T(this,"remeasure",this.#Zn(8))}get vertical(){return T(this,"vertical",this.#Zn(9))}#tr(t,e,i,s){const n=this.#Qn.getUint8(t++);if(0===n)return;A(n===e,"Invalid array length.");const r=new Array(n);for(let a=0;a<n;a++)r[a]=this.#Qn[i](t,!0),t+=s;return r}get bbox(){return T(this,"bbox",this.#tr(Xi.OFFSET_BBOX,4,"getInt16",2))}get fontMatrix(){return T(this,"fontMatrix",this.#tr(Xi.OFFSET_FONT_MATRIX,6,"getFloat64",8))}#Jn(t){return A(t<Xi.strings.length,"Invalid string index"),qi(this.#qn,this.#Qn,t,Xi.OFFSET_STRINGS+4)}get fallbackName(){return T(this,"fallbackName",this.#Jn(0))}get loadedName(){return T(this,"loadedName",this.#Jn(1))}#er(t){let e=Xi.OFFSET_STRINGS;for(let i=0;i<=t;i++)e+=4+this.#Qn.getUint32(e);return{offset:e,length:this.#Qn.getUint32(e)}}get data(){const{offset:t,length:e}=this.#er(2);return e?new Uint8Array(this.#qn,t+4,e):void 0}clearData(){const{offset:t,length:e}=this.#er(2);e&&(this.#Qn.setUint32(t,0),this.#qn=new Uint8Array(this.#qn,0,t+4).slice().buffer,this.#Qn=new DataView(this.#qn))}get cssFontInfo(){const{offset:t,length:e}=this.#er(1);let i=null;if(e){const s=new Uint8Array(this.#qn,t+4,e).slice();i=new Qi(s.buffer)}return T(this,"cssFontInfo",i)}get systemFontInfo(){const{offset:t,length:e}=this.#er(0);let i=null;if(e){const s=new Uint8Array(this.#qn,t+4,e).slice();i=new Ji(s.buffer)}return T(this,"systemFontInfo",i)}},ts=class{constructor(t){this.buffer=t,this.view=new DataView(t),this.data=new Uint8Array(t)}getIR(){const t=this.view,i=this.data[Ki.KIND],s=!!this.data[Ki.HAS_BBOX],n=!!this.data[Ki.HAS_BACKGROUND],r=t.getUint32(Ki.N_COORD,!0),a=t.getUint32(Ki.N_COLOR,!0),o=t.getUint32(Ki.N_STOP,!0);let l=20;const h=new Float32Array(this.buffer,l,2*r);l+=8*r;const c=new Uint8Array(this.buffer,l,4*a);l+=4*a;const d=[];for(let e=0;e<o;++e){const e=t.getFloat32(l,!0);l+=4;const i=t.getUint32(l,!0);l+=4,d.push([e,`#${i.toString(16).padStart(6,"0")}`])}let u=null;if(s){u=[];for(let e=0;e<4;++e)u.push(t.getFloat32(l,!0)),l+=4}let p=null;if(n&&(p=new Uint8Array(this.buffer,l,3),l+=3),1===i)return["RadialAxial","axial",u,d,[h[0],h[1]],[h[2],h[3]],null,null];if(2===i)return["RadialAxial","radial",u,d,[h[0],h[1]],[h[3],h[4]],h[2],h[5]];if(3===i){const t=this.data[Ki.SHADING_TYPE];let i=null;if(h.length>0){i=e.slice();for(let t=0,e=h.length;t<e;t+=2)B.pointBoundingBox(h[t],h[t+1],i)}return["Mesh",t,h,c,r,i,u,p]}throw new Error(`Unsupported pattern kind: ${i}`)}},es=class{#qn;constructor(t){this.#qn=t}get path(){return L.isFloat16ArraySupported?new Float16Array(this.#qn):new Float32Array(this.#qn)}},is=Symbol("INITIAL_DATA"),ss=()=>({...Promise.withResolvers(),data:is}),ns=class{#ir=/* @__PURE__ */new Map;get(t,e=null,i=null){if(e){const s=this.#ir.getOrInsertComputed(t,ss);return s.promise.then(()=>e(s.data),i),null}const s=this.#ir.get(t);if(!s||s.data===is)throw new Error(`Requesting object that isn't resolved yet ${t}.`);return s.data}has(t){const e=this.#ir.get(t);return!!e&&e.data!==is}delete(t){const e=this.#ir.get(t);return!(!e||e.data===is||(this.#ir.delete(t),0))}resolve(t,e=null){const i=this.#ir.getOrInsertComputed(t,ss);if(i.data!==is)throw new Error(`Object already resolved ${t}.`);i.data=e,i.resolve()}reject(t,e){const i=this.#ir.getOrInsertComputed(t,ss);i.data===is&&(i.promise.catch(()=>{}),i.reject(e))}clear(){for(const{data:t}of this.#ir.values())t?.bitmap?.close();this.#ir.clear()}*[Symbol.iterator](){for(const[t,{data:e}]of this.#ir)e!==is&&(yield[t,e])}},rs=class{constructor({messageHandler:t,commonObjs:e,fontLoader:i,pageCache:s,pdfBug:n=!1,shouldCreatePageObjs:r=!1}){this.messageHandler=t,this.commonObjs=e,this.fontLoader=i,this.pageCache=s,this.pdfBug=n,this.shouldCreatePageObjs=r}resolveCommonObject(t,e,i){if("CopyLocalImage"===e){const{imageRef:e}=i;A(e,"The imageRef must be defined.");for(const i of this.pageCache.values()){const s=i.objs||i;for(const[,i]of s){if(i?.ref!==e)continue;if(!i.dataLen)return null;const s=structuredClone(i);return this.commonObjs.resolve(t,s),i.dataLen}}return null}switch(e){case"Font":if("error"in i){const e=i.error;this.commonObjs.resolve(t,e);break}const s=new Zi(i.buffer),n=this.pdfBug&&globalThis.FontInspector?.enabled?(t,e)=>globalThis.FontInspector.fontAdded(t,e):null,r=new mi(s,n,i.charProcOperatorList,i.extra);this.fontLoader.bind(r).catch(()=>this.messageHandler.sendWithPromise("FontFallback",{id:t}).catch(t=>{})).finally(()=>{r.fontExtraProperties||r.clearData(),this.commonObjs.resolve(t,r)});break;case"FontPath":this.commonObjs.resolve(t,new es(i));break;case"Image":this.commonObjs.resolve(t,i);break;case"Pattern":const a=new ts(i);this.commonObjs.resolve(t,a.getIR());break;default:throw new Error(`Got unknown common object type ${e}`)}return null}resolveObject(t,e,i,s){let n=this.pageCache.get(e);if(!n){if(!this.shouldCreatePageObjs)return!1;n=new ns,this.pageCache.set(e,n)}const r=n.objs||n;if(r.has(t))return!1;if(0===n._intentStates?.size)return s?.bitmap?.close(),!1;switch(i){case"Image":case"Pattern":return r.resolve(t,s),!0;default:throw new Error(`Got unknown object type ${i}`)}}},as=Symbol("INTERNAL"),os=class{#sr=!1;#nr=!1;#rr=!1;#ar=!0;constructor(t,{name:e,intent:i,usage:s,rbGroups:n}){this.#sr=!!(2&t),this.#nr=!!(4&t),this.name=e,this.intent=i,this.usage=s,this.rbGroups=n}get visible(){if(this.#rr)return this.#ar;if(!this.#ar)return!1;const{print:t,view:e}=this.usage;return this.#sr?"OFF"!==e?.viewState:!this.#nr||"OFF"!==t?.printState}_setVisible(t,e,i=!1){t!==as&&w("Internal method `_setVisible` called."),this.#rr=i,this.#ar=e}get serializable(){return{userSet:this.#rr,visible:this.#ar}}},ls=class t{#or=null;#lr=/* @__PURE__ */new Map;#hr=null;#cr=null;#dr;creator=null;name=null;constructor(t,e=2,i=null){if(this.#dr=t,this.renderingIntent=e,null!==t){this.name=t.name,this.creator=t.creator,this.#cr=t.order;for(const i of t.groups)this.#lr.set(i.id,new os(e,i));if(i){i.size!==this.#lr.size&&w("Incorrect serialized groupState.");for(const[t,e]of i)this.#lr.get(t)._setVisible(as,e.visible,e.userSet)}else{if("OFF"===t.baseState)for(const t of this.#lr.values())t._setVisible(as,!1);for(const e of t.on)this.#lr.get(e)._setVisible(as,!0);for(const e of t.off)this.#lr.get(e)._setVisible(as,!1)}this.#hr=this.getHash()}}#ur(t){const e=t.length;if(e<2)return!0;const i=t[0];for(let s=1;s<e;s++){const e=t[s];let n;if(Array.isArray(e))n=this.#ur(e);else{if(!this.#lr.has(e))return v(),!0;n=this.#lr.get(e).visible}switch(i){case"And":if(!n)return!1;break;case"Or":if(n)return!0;break;case"Not":return!n;default:return!0}}return"And"===i}isVisible(t){if(0===this.#lr.size)return!0;if(!t)return!0;if("OCG"===t.type)return this.#lr.has(t.id)?this.#lr.get(t.id).visible:(t.id,!0);if("OCMD"===t.type){if(t.expression)return this.#ur(t.expression);if(!t.policy||"AnyOn"===t.policy){for(const e of t.ids){if(!this.#lr.has(e))return v(),!0;if(this.#lr.get(e).visible)return!0}return!1}if("AllOn"===t.policy){for(const e of t.ids){if(!this.#lr.has(e))return v(),!0;if(!this.#lr.get(e).visible)return!1}return!0}if("AnyOff"===t.policy){for(const e of t.ids){if(!this.#lr.has(e))return v(),!0;if(!this.#lr.get(e).visible)return!0}return!1}if("AllOff"===t.policy){for(const e of t.ids){if(!this.#lr.has(e))return v(),!0;if(this.#lr.get(e).visible)return!1}return!0}return t.policy,!0}return t.type,!0}setVisibility(t,e=!0,i=!0){const s=this.#lr.get(t);if(s){if(i&&e&&s.rbGroups.length)for(const e of s.rbGroups)for(const i of e)i!==t&&this.#lr.get(i)?._setVisible(as,!1,!0);s._setVisible(as,!!e,!0),this.#or=null}}setOCGState({state:t,preserveRB:e}){let i;for(const s of t){switch(s){case"ON":case"OFF":case"Toggle":i=s;continue}const t=this.#lr.get(s);if(t)switch(i){case"ON":this.setVisibility(s,!0,e);break;case"OFF":this.setVisibility(s,!1,e);break;case"Toggle":this.setVisibility(s,!t.visible,e)}}this.#or=null}get hasInitialVisibility(){return null===this.#hr||this.getHash()===this.#hr}getOrder(){return this.#lr.size?this.#cr?this.#cr.slice():[...this.#lr.keys()]:null}getGroup(t){return this.#lr.get(t)||null}getHash(){if(null!==this.#or)return this.#or;const t=new Xt;for(const[e,i]of this.#lr)t.update(`${e}:${i.visible}`);return this.#or=t.hexdigest()}[Symbol.iterator](){return this.#lr.entries()}get serializable(){const t=/* @__PURE__ */new Map;for(const[e,i]of this.#lr)t.set(e,i.serializable);return{data:this.#dr,renderingIntent:this.renderingIntent,groupState:t}}static fromSerializable({data:e,renderingIntent:i,groupState:s}){return new t(e,i,s)}},hs=class{#pr=null;#gr=null;#mr=0;#fr=0;#br=null;#yr=null;get pagesNumber(){return this.#mr}set pagesNumber(t){this.#mr!==t&&(this.#mr=this.#fr=t,this.#pr=null,this.#gr=null)}#vr(){if(this.#pr)return;const t=this.#mr,e=this.#pr=new Uint32Array(t);for(let i=0;i<t;i++)e[i]=i+1;this.#gr=new Int32Array(e)}#wr(){const t=/* @__PURE__ */new Map,e=this.#pr;for(let i=0,s=this.#mr;i<s;i++){const s=e[i],n=t.get(s);n?n.push(i+1):t.set(s,[i+1])}return t}movePages(t,e,i){this.#vr();const s=this.#pr,n=e.length,r=new Uint32Array(n);let a=0;for(let d=0;d<n;d++){const t=e[d]-1;r[d]=s[t],t<i&&a++}const o=this.#mr,l=o-n,h=new Int32Array(o),c=j(i-a,0,l);for(let d=0,u=0;d<o;d++)t.has(d+1)||(s[u]=s[d],h[u++]=d+1);s.copyWithin(c+n,c,l),s.set(r,c),h.copyWithin(c+n,c,l),h.set(e,c),this.#gr=h,o===this.#fr&&s.every((t,e)=>t===e+1)&&(this.#pr=null)}deletePages(t){this.#vr();const e=this.#pr,i=this.#wr();this.#yr={pageNumberToId:e.slice(),pagesNumber:this.#mr,prevPageNumbers:this.#gr.slice()};const s=this.#mr-t.length;this.#mr=s;const n=this.#pr=new Uint32Array(s);this.#gr=new Int32Array(s);let r=0,a=0;for(const o of t){const t=o-1;t!==r&&(n.set(e.subarray(r,t),a),a+=t-r),r=t+1}r<e.length&&n.set(e.subarray(r),a),this.#Ar(i,new Set(t))}cancelDelete(){this.#yr&&(this.#pr=this.#yr.pageNumberToId,this.#mr=this.#yr.pagesNumber,this.#gr=this.#yr.prevPageNumbers,this.#yr=null)}cleanSavedData(){this.#yr=null}copyPages(t){this.#vr(),this.#br={pageNumbers:t,pageIds:t.map(t=>this.#pr[t-1])}}cancelCopy(){this.#br=null}pastePages(t){this.#vr();const e=this.#pr,i=this.#wr(),{pageNumbers:s,pageIds:n}=this.#br,r=this.#mr+s.length;this.#mr=r;const a=this.#pr=new Uint32Array(r);this.#gr=new Int32Array(r),a.set(e.subarray(0,t),0),a.set(n,t),a.set(e.subarray(t),t+s.length),this.#Ar(i,null,t,s),this.#br=null}#Ar(t,e=null,i=-1,s=null){const n=this.#gr,r=this.#pr,a=i+(s?.length??0),o=/* @__PURE__ */new Map;for(let l=0,h=this.#mr;l<h;l++){if(l>=i&&l<a){n[l]=-s[l-i];continue}const h=r[l],c=t.get(h);let d=o.get(h)||0;if(e&&c)for(;d<c.length&&e.has(c[d]);)d++;n[l]=c?.[d],o.set(h,d+1)}}hasBeenAltered(){return null!==this.#pr}#xr(t=null){if(!this.#pr)return null;const e=new Int32Array(this.#mr).fill(-1),i=/* @__PURE__ */new Map;if(t)for(const s of t){const t=this.getPageId(s),n=i.get(t)??0;i.set(t,n+1),e[s-1]=n}else for(let s=0,n=this.#mr;s<n;s++){const t=this.#pr[s],n=i.get(t)??0;i.set(t,n+1),e[s]=n}return e}getPageMappingForSaving(t=null,e=this.#xr()){t??=this.#wr();let i=0;for(const n of t.values())i=Math.max(i,n.length);const s=new Array(i);for(let n=0;n<i;n++)s[n]={document:null,pageIndices:[],includePages:[]};for(const[n,r]of t)for(let t=0,e=r.length;t<e;t++)s[t].includePages.push([n-1,r[t]-1]);for(const{includePages:n,pageIndices:r}of s){n.sort((t,e)=>t[0]-e[0]);for(let t=0,e=n.length;t<e;t++)r.push(n[t][1]),n[t]=n[t][0]}return{pageInfos:s,copyLevels:e}}extractPages(t){t=Array.from(t).sort((t,e)=>t-e);const e=/* @__PURE__ */new Map;for(let i=0,s=t.length;i<s;i++){const s=this.getPageId(t[i]);e.getOrInsertComputed(s,H).push(i+1)}return this.getPageMappingForSaving(e,this.#xr(t))}getPrevPageNumber(t){return this.#gr?.[t-1]??0}getPageNumber(t){if(!this.#pr)return t;const e=this.#pr;for(let i=0,s=this.#mr;i<s;i++)if(e[i]===t)return i+1;return 0}getPageId(t){return this.#pr?.[t-1]??t}getMapping(){return this.#pr?.subarray(0,this.pagesNumber)}};function cs({bitmap:t,annotationBitmaps:e}){if(t?.close(),e)for(const[,,i]of e)i.close()}var ds=class{#Cr;#Sr=!1;#Tr;#_r;#kr=0;#_;#Er;#Wn;#Mr;#Pr;#Dr;#Ir;imageCoordinates=null;recordedBBoxes=null;constructor({rendererWorker:t,renderTasks:e,canvas:i,canvasFactory:s,annotationCanvasMap:n,operatorListState:r,initParams:a,onFrame:o,onError:l}){this.#Dr=t,this.#Ir=e,this.#Tr=i,this.#_r=s,this.#Cr=n,this.#Pr=r,this.#Er=a,this.#_=a.renderTaskId,this.#Mr=o,this.#Wn=l}async initialize(t,e){try{await this.#Dr.promise}catch{return!1}if(!this.#Dr.messageHandler||this.#Sr)return!1;try{await this.#Dr.sendWithPromise("InitializeGraphics",{...this.#Er,width:this.#Tr.width,height:this.#Tr.height,transparency:t,optionalContentConfig:e.serializable})}catch(i){return this.#Sr||i.message,!1}return this.#Sr||this.#Ir.set(this.#_,this),!0}async executeOperatorList(t,e,i){const s=this.#Dr.messageHandler;if(!s)throw new Error("Renderer worker was destroyed during rendering.");const{lastChunk:n}=t,r=t.argsArray.length,a=this.#Pr;if(a.sentLength<r){const e=a.sentLength;s.send("AppendOperatorList",{pageProxyId:this.#Er.pageProxyId,operatorListId:a.id,fnArray:t.fnArray.slice(e,r),argsArray:t.argsArray.slice(e,r)}),a.sentLength=r}let o=null;if(i&&this.#kr<r){const e=this.#kr;o=new Uint8Array(r-e);for(let s=e;s<r;s++)o[s-e]=i(s,t)?1:0;this.#kr=r}const l=await this.#Dr.sendWithPromise("ExecuteOperatorList",{renderTaskId:this.#_,operatorListIdx:e,operatorListLength:r,operationsFilterMask:o,lastChunk:n}).catch(t=>{if(!this.#Sr)throw t;return{operatorListIdx:e,aborted:!0}});if(l.aborted&&!this.#Sr)throw new Error("Render task was aborted in the renderer worker.");if(n&&l.operatorListIdx===r){this.#Ir.delete(this.#_);const{recordedBBoxesBuffer:t,imageCoordinates:e}=l;t&&(this.recordedBBoxes=Ae.fromBuffer(t)),this.imageCoordinates=e??null}return l.operatorListIdx}cancel(){this.#Sr=!0,this.#Ir.delete(this.#_),this.#Dr.messageHandler?.send("CleanupRenderTask",{renderTaskId:this.#_})}drawFrame(t){try{t.bitmap&&this.#_r.getNoAlphaContext(this.#Tr).drawImage(t.bitmap,0,0),t.annotationBitmaps&&this.#Fr(t.annotationBitmaps)}catch(e){return void this.#Wn(e)}finally{cs(t)}this.#Mr()}#Fr(t){const e=this.#Cr,i=/* @__PURE__ */new Set;for(const[s,n,r]of t){const{canvas:t,context:a}=this.#_r.create(r.width,r.height);a.drawImage(r,0,0),n?(ti(t,n),i.has(s)?e.get(s).push(t):(i.add(s),e.set(s,[t]))):e.set(s,t)}}},us=class t{#Lr=Promise.withResolvers();#cs;#Br;#Rr=null;#Or=0;#Nr=/* @__PURE__ */new WeakMap;#zr=[];#Nn=/* @__PURE__ */new Set;#jn=null;#Hr=null;#Ur=0;#Ir=/* @__PURE__ */new Map;#Gr=null;#Wr=null;#jr=null;static#Vr=0;static#$r=/* @__PURE__ */new WeakSet;destroyed=!1;constructor({port:t=null,verbosity:e=y(),enableHWA:i=!1,enableWebGPU:s=!1}={}){this.verbosity=e,this.#cs=i,this.#Br=s,t?this.#Xr(t):this.#Kr()}static get isAvailable(){return(!!Wi.rendererSrc||Wi.rendererPorts.length>0)&&"undefined"!=typeof Worker&&L.isOffscreenCanvasSupported&&!!globalThis.document?.fonts}get promise(){return this.#Lr.promise}get messageHandler(){return this.#Rr}get port(){return this.#jn}#Yr(){this.#Rr.on("RenderFrame",t=>{const e=this.#Ir.get(t.renderTaskId);e?e.drawFrame(t):cs(t)}),this.#Lr.resolve(),this.#Rr.send("configure",{verbosity:this.verbosity,enableHWA:this.#cs,enableWebGPU:this.#Br});const t=this.#zr;this.#zr=null;for(const e of t)e()}#qr(t){this.#zr=null,this.#Lr.reject(t)}#Xr(e){t.#$r.add(e),this.#jn=e;const i=t.#Vr++,s=`main${i}`,n=`renderer${i}`;this.#Hr={sourceName:s,targetName:n};const r=new le("main","renderer",e);r.send("Connect",{sourceName:n,targetName:s}),r.destroy(),this.#Qr(e,new le(s,n,e),!0)}#Kr(){try{const{rendererSrc:t}=Wi;if(!t)throw new Error('No "GlobalWorkerOptions.rendererSrc" specified.');const e=new Worker(te(t),{type:"module"});this.#Qr(e,new le("main","renderer",e),!1)}catch(t){this.#qr(t)}}#Qr(t,e,i){let s=null;const n=n=>{this.#Gr=null,clearTimeout(s),r.abort(),e.destroy(),i?this.#jn=null:t.terminate(),this.#qr(/* @__PURE__ */new Error(`Renderer worker failed to initialize: "${n?.message??n}".`))};this.#Gr=n;const r=new AbortController,a=(t,e)=>{this.#Rr?(t.preventDefault(),this.destroy()):n(e)};t.addEventListener("error",t=>a(t,t.error?.message??t.message),{signal:r.signal}),t.addEventListener("messageerror",t=>a(t,"Cannot deserialize a message."),{signal:r.signal}),i&&(s=setTimeout(()=>n("Connection timed out."),5e3)),e.on("ready",a=>{if(!(a?.testObj instanceof Uint8Array))return void n("TypedArray transfer test failed.");const o="6.5.438";o===a.workerVersion?(this.#Gr=null,clearTimeout(s),this.#Rr=e,i||(this.#Wr=t),this.#jr=r,this.#Yr()):n(`The API version "${o}" does not match the Worker version "${a.workerVersion}".`)})}destroy(){this.destroyed=!0,this.#jn&&(this.#Rr&&(this.#Jr(this.#jn),this.#Rr.send("Disconnect",null)),t.#$r.delete(this.#jn),this.#jn=null),this.#Gr?.("Worker was destroyed."),this.#jr?.abort(),this.#jr=null,this.#Wr?.terminate(),this.#Wr=null,this.#Rr?.destroy(),this.#Rr=null;for(const t of this.#Nn)t(/* @__PURE__ */new Error("Renderer worker was destroyed."));this.#Nn.clear()}#Jr(t){const{sourceName:e,targetName:i}=this.#Hr,s=new AbortController,n=setTimeout(()=>s.abort(),5e3);t.addEventListener("message",({data:t})=>{t?.targetName===e&&t.sourceName===i&&("RenderFrame"===t.action?cs(t.data):"Disconnected"===t.action&&(clearTimeout(n),s.abort()))},{signal:s.signal})}static create({ports:e=[],...i}={}){const s=e.find(t=>!this.#$r.has(t))??null;return!s&&e.length,new t({...i,port:s})}sendWithPromise(t,e){const i=this.#Rr;if(!i)return Promise.reject(/* @__PURE__ */new Error("Renderer worker was destroyed."));const{promise:s,resolve:n,reject:r}=Promise.withResolvers();return this.#Nn.add(r),i.sendWithPromise(t,e).then(n,r),s.finally(()=>{this.#Nn.delete(r)})}#Zr(t,e){this.#zr?this.#zr.push(()=>this.#Zr(t,e)):this.#Rr?.send(t,e)}#ta(t,e,i,s,n=!1){try{if(this.#zr){const r=n?structuredClone(e):e;return void this.#zr.push(()=>this.#ta(t,r,i,s))}this.#Rr?.send(t,e)}catch(r){this.#Zr("objFailed",{id:i,pageProxyId:s,reason:r.message})}}sendCommonObj(t,e,i){this.#ta("commonobj",[t,e,i],t,null,"Font"===e)}sendObj(t,e,i,s){this.#ta("obj",[t,e,i,s],t,e)}cleanup(t){this.#Zr("Cleanup",{keepLoadedFonts:t})}cleanupPage(t){this.#Zr("cleanupPage",{pageProxyId:t})}createRenderTask({pageProxyId:t,operatorList:e,params:i,pageColors:s,canvasFactory:n,annotationCanvasMap:r,onFrame:a,onError:o}){const{canvas:l,canvasContext:h,background:c}=i;if(!this.#Rr&&!this.#zr||h||c&&"string"!=typeof c||s||i.recordForDebugger)return null;const d=this.#Nr.getOrInsertComputed(e,()=>({id:this.#Or++,sentLength:0}));return new ds({rendererWorker:this,renderTasks:this.#Ir,canvas:l,canvasFactory:n,annotationCanvasMap:r,operatorListState:d,initParams:{pageProxyId:t,operatorListId:d.id,renderTaskId:this.#Ur++,hasAnnotationCanvasMap:!!r,recordOperations:i.recordOperations,recordImages:i.recordImages,partialFrames:i.partialFrames,transform:i.transform,viewport:i.viewport,background:c,pixelRatio:Q.pixelRatio},onFrame:a,onError:o})}},ps=class t{#Lr=Promise.withResolvers();#Mt=null;#ea=!1;#ia=!!globalThis.FontInspector?.enabled;#sa=null;#na=null;#ra=null;#aa=0;#oa=0;#la=Q.pixelRatio;#ha=null;#ca=null;#da=0;#ua=0;#pa=Object.create(null);#ga=[];#ma=null;#fa=[];#ba=null;static#ya=/* @__PURE__ */new Map;static#va=/* @__PURE__ */new Map;static#wa=/* @__PURE__ */new WeakMap;static#Aa=null;static#xa=/* @__PURE__ */new Set;constructor({textContentSource:e,images:i,container:s,viewport:n}){if(e instanceof ReadableStream)this.#ma=e;else{if("object"!=typeof e)throw new Error('No "textContentSource" parameter specified.');this.#ma=new ReadableStream({start(t){t.enqueue(e),t.close()}})}this.#Mt=this.#ca=s,this.#sa=i,this.#ua=n.scale*this.#la,this.#da=n.rotation,this.#ra={div:null,properties:null,ctx:null};const{pageWidth:r,pageHeight:a,pageX:o,pageY:l}=n.rawDims;this.#ba=[1,0,0,-1,-o,l+a],this.#oa=r,this.#aa=a,t.#Ca(),s.style.setProperty("--min-font-size",t.#Aa),wt(s,n),this.#Lr.promise.finally(()=>{t.#xa.delete(this),this.#ra=null,this.#pa=null}).catch(()=>{})}static get fontFamilyMap(){const{isWindows:t,isFirefox:e}=L.platform;return T(this,"fontFamilyMap",/* @__PURE__ */new Map([["sans-serif",(t&&e?"Calibri, ":"")+"sans-serif"],["monospace",(t&&e?"Lucida Console, ":"")+"monospace"]]))}render(){this.#sa&&this.#Mt.append(this.#sa.render());const e=()=>{this.#ha.read().then(({value:t,done:i})=>{i?this.#Lr.resolve():(this.#na??=t.lang,Object.assign(this.#pa,t.styles),this.#Sa(t.items),e())},this.#Lr.reject)};return this.#ha=this.#ma.getReader(),t.#xa.add(this),e(),this.#Lr.promise}update({viewport:t}){const e=t.scale*Q.pixelRatio,i=t.rotation;i!==this.#da&&(this.#da=i,wt(this.#ca,{rotation:i})),e!==this.#ua&&(this.#ua=e,this.#la=Q.pixelRatio)}cancel(){const t=new I("TextLayer task cancelled.");this.#ha?.cancel(t).catch(()=>{}),this.#ha=null,this.#Lr.reject(t)}get textDivs(){return this.#fa}get textContentItemsStr(){return this.#ga}#Sa(e){if(this.#ea)return;this.#ra.ctx??=t.#Ta(this.#na);const i=this.#fa,s=this.#ga;for(const t of e){if(i.length>1e5)return v(),void(this.#ea=!0);if(void 0!==t.str)s.push(t.str),this.#_a(t);else if("beginMarkedContentProps"===t.type||"beginMarkedContent"===t.type){const e=this.#Mt;this.#Mt=document.createElement("span"),this.#Mt.classList.add("markedContent"),t.id&&this.#Mt.setAttribute("id",t.id),"Artifact"===t.tag&&(this.#Mt.ariaHidden=!0),e.append(this.#Mt)}else"endMarkedContent"===t.type&&(this.#Mt=this.#Mt.parentNode)}}#_a(e){const i=document.createElement("span"),s={angle:0,canvasWidth:0,hasText:""!==e.str,hasEOL:e.hasEOL,fontSize:0};this.#fa.push(i);const n=B.transform(this.#ba,e.transform);let r=Math.atan2(n[1],n[0]);const a=this.#pa[e.fontName];a.vertical&&(r+=Math.PI/2);let o=this.#ia&&a.fontSubstitution||a.fontFamily;o=t.fontFamilyMap.get(o)||o;const l=Math.hypot(n[2],n[3]),h=l*t.#ka(o,a,this.#na);let c,d;0===r?(c=n[4],d=n[5]-h):(c=n[4]+h*Math.sin(r),d=n[5]-h*Math.cos(r));const u=i.style;u.left=`${(100*c/this.#oa).toFixed(2)}%`,u.top=`${(100*d/this.#aa).toFixed(2)}%`;const p=Math.round(100*l)/100;u.setProperty("--font-height",`${p}px`),u.fontFamily=o,s.fontSize=p,i.setAttribute("role","presentation"),i.textContent=e.str,i.dir=e.dir,this.#ia&&(i.dataset.fontName=a.fontSubstitutionLoadedName||e.fontName),0!==r&&(s.angle=r*(180/Math.PI));let g=!1;if(e.str.length>1)g=!0;else if(" "!==e.str&&e.transform[0]!==e.transform[3]){const t=Math.abs(e.transform[0]),i=Math.abs(e.transform[3]);t!==i&&Math.max(t,i)/Math.min(t,i)>1.5&&(g=!0)}if(g&&(s.canvasWidth=a.vertical?e.height:e.width),this.#ra.div=i,this.#ra.properties=s,this.#Ea(this.#ra),s.hasText&&this.#Mt.append(i),s.hasEOL){const t=document.createElement("br");t.setAttribute("role","presentation"),this.#Mt.append(t)}}#Ea(e){const{div:i,properties:s,ctx:n}=e,{style:r}=i,{canvasWidth:a,fontSize:o}=s;if(0!==a&&0!==o&&s.hasText){const{fontFamily:e}=r,s=this.#la,l=t.#Ma(o*this.#ua/s)*s;t.#Pa(n,l,e);const{width:h}=n.measureText(i.textContent);h>0&&r.setProperty("--scale-x",a*l/(h*o))}0!==s.angle&&r.setProperty("--rotate",`${s.angle}deg`)}static cleanup(){if(!(this.#xa.size>0)){this.#ya.clear();for(const{canvas:t}of this.#va.values())t.remove();this.#va.clear()}}static#Ta(t=null){let e=this.#va.get(t||="");if(!e){const i=document.createElement("canvas");i.style.cssText="position:absolute;top:0;left:0;width:0;height:0;display:none;letter-spacing:normal;word-spacing:normal",i.lang=t,document.body.append(i),e=i.getContext("2d",{alpha:!1,willReadFrequently:!0}),this.#va.set(t,e),this.#wa.set(e,{size:0,family:""})}return e}static#Ma(t){t=Math.fround(t);const e=Math.fround(131073*t);return Math.fround(e-Math.fround(e-t))}static#Pa(t,e,i){const s=this.#wa.get(t);e===s.size&&i===s.family||(t.font=`${e}px ${i}`,s.size=e,s.family=i)}static#Ca(){if(null!==this.#Aa)return;const t=document.createElement("div");t.style.opacity=0,t.style.lineHeight=1,t.style.fontSize="1px",t.style.position="absolute",t.textContent="X",document.body.append(t),this.#Aa=t.getBoundingClientRect().height,t.remove()}static#ka(t,e,i){const s=this.#ya.get(t);if(s)return s;const n=this.#Ta(i);this.#Pa(n,30,t);const r=n.measureText(""),a=r.fontBoundingBoxAscent,o=Math.abs(r.fontBoundingBoxDescent);let l=.8;return a?l=a/(a+o):(L.platform.isFirefox,e.ascent?l=e.ascent:e.descent&&(l=1+e.descent)),this.#ya.set(t,l),l}};function gs(e={}){const i=new ms,{docId:s}=i,n=e.url?function(e){if(e instanceof URL)return e;if("string"==typeof e){if(t){if(/^[a-z][a-z0-9\-+.]+:/i.test(e))return new URL(e);const t=process.getBuiltinModule("url");return new URL(t.pathToFileURL(e))}const i=URL.parse(e,window.location);if(i)return i}throw new Error("Invalid PDF url data: either string or URL-object is expected in the url property.")}(e.url):null,r=e.data?function(e){if(t&&"undefined"!=typeof Buffer&&e instanceof Buffer)throw new Error("Please provide binary data as `Uint8Array`, rather than `Buffer`.");if(e instanceof Uint8Array&&e.byteLength===e.buffer.byteLength)return e;if("string"==typeof e)return F(e);if(e instanceof ArrayBuffer||ArrayBuffer.isView(e)||"object"==typeof e&&!isNaN(e?.length))return new Uint8Array(e);throw new Error("Invalid PDF binary data: either TypedArray, string, or array-like object is expected in the data property.")}(e.data):null,a=e.httpHeaders||null,o=!0===e.withCredentials,l=e.password??null,h=e.range instanceof fs?e.range:null,c=Number.isInteger(e.rangeChunkSize)&&e.rangeChunkSize>0?e.rangeChunkSize:65536;let d=e.worker instanceof vs?e.worker:null;const u=e.verbosity,p="string"!=typeof e.docBaseUrl||ut(e.docBaseUrl)?null:e.docBaseUrl,g=Qt(e.cMapUrl),m=!1!==e.cMapPacked,f=Qt(e.iccUrl),y=Qt(e.standardFontDataUrl),v=Qt(e.wasmUrl),w=!0!==e.stopAtErrors,A=Number.isInteger(e.maxImageSize)&&e.maxImageSize>-1?e.maxImageSize:-1,x="boolean"==typeof e.isOffscreenCanvasSupported?e.isOffscreenCanvasSupported:!t,C="boolean"==typeof e.isImageDecoderSupported?e.isImageDecoderSupported:!t,S=Number.isInteger(e.canvasMaxAreaInBytes)?e.canvasMaxAreaInBytes:-1,T="boolean"==typeof e.disableFontFace?e.disableFontFace:t,_=!0===e.fontExtraProperties,k=!0===e.enableXfa,E=e.ownerDocument||globalThis.document,M=!0===e.disableRange,P=!0===e.disableStream,D=!0===e.disableAutoFetch,I=!0===e.pdfBug,L=e.CanvasFactory||(t?ge:hi),B=e.FilterFactory||(t?pe:ci),R=e.BinaryDataFactory||(t?me:ce),O=!0===e.enableHWA,N=!0===e.enableWebGPU;N&&ne();const z=!1!==e.useWasm,H=e.pagesMapper||new hs,U="boolean"==typeof e.useSystemFonts?e.useSystemFonts:!t&&!T,G="boolean"==typeof e.useWorkerFetch?e.useWorkerFetch:!!(R===ce&&g&&m&&y&&v&&ft(g,document.baseURI)&&ft(y,document.baseURI)&&ft(v,document.baseURI)),W=!0===e.disableWorkerRendering||!x||E!==globalThis.document||!us.isAvailable;b(u);const j={canvasFactory:new L({ownerDocument:E,enableHWA:O}),filterFactory:new B({docId:s,ownerDocument:E}),binaryDataFactory:G?null:new R({cMapUrl:g,standardFontDataUrl:y,wasmUrl:v})};if(d||(d=vs.create({verbosity:u,port:Wi.workerPort}),i._worker=d),!W){const t=us.create({verbosity:u,enableHWA:O,enableWebGPU:N,ports:Wi.rendererPorts});t.promise.catch(e=>{t.destroyed||(e.message,t.destroy())}),i._rendererWorker=t}const V={docId:s,apiVersion:"6.5.438",data:r,password:l,disableAutoFetch:D,rangeChunkSize:c,docBaseUrl:p,enableXfa:k,evaluatorOptions:{maxImageSize:A,disableFontFace:T,ignoreErrors:w,isOffscreenCanvasSupported:x,isImageDecoderSupported:C,canvasMaxAreaInBytes:S,fontExtraProperties:_,useSystemFonts:U,useWasm:z,useWorkerFetch:G,cMapUrl:g,cMapPacked:m,iccUrl:f,standardFontDataUrl:y,wasmUrl:v}},$={ownerDocument:E,pdfBug:I,styleElement:null,rendererWorker:i._rendererWorker,enableWebGPU:N,loadingParams:{disableAutoFetch:D,enableXfa:k}};return d.promise.then(function(){if(d.destroyed)throw new Error("Worker was destroyed");const e=d.messageHandler.sendWithPromise("GetDocRequest",V,r?[r.buffer]:null);let l;if(r);else if(h)l=new Fi({pdfDataRangeTransport:h,disableRange:M,disableStream:P});else{if(!n)throw new Error("getDocument - expected either `data`, `range`, or `url` parameter.");l=new(function(e){return ft(e)?Ei:t?Hi:Ri}(n))({url:n,httpHeaders:a,withCredentials:o,rangeChunkSize:c,disableRange:M,disableStream:P})}return e.then(t=>{if(d.destroyed)throw new Error("Worker was destroyed");const e=new le(s,t,d.port),n=new ws(e,i,l,$,j,H);if(i._transport=n,i.destroyed)throw new Error("Loading aborted");e.send("Ready",null)})}).catch(i._capability.reject).finally(i._setupCapability.resolve),i}var ms=class t{static#cn=0;_capability=Promise.withResolvers();_setupCapability=Promise.withResolvers();_transport=null;_worker=null;_rendererWorker=null;docId="d"+t.#cn++;destroyed=!1;onPassword=null;onProgress=null;get promise(){return this._capability.promise}async destroy(){this.destroyed=!0,this._capability.promise.catch(()=>{});try{this._worker?.port&&(this._worker._pendingDestroy=!0),await this._setupCapability.promise,await(this._transport?.destroy())}catch(t){throw this._worker?.port&&delete this._worker._pendingDestroy,t}finally{this._rendererWorker?.destroy(),this._rendererWorker=null}this._transport=null,this._worker?.destroy(),this._worker=null}async getData(){return this._transport.getData()}},fs=class{#Lr=Promise.withResolvers();#Da=null;constructor(t,e,i=!1,s=null){this.length=t,this.initialData=e,this.progressiveDone=i,this.contentDispositionFilename=s}onDataRange(t,e){this.#Da({type:"range",begin:t,chunk:e})}onDataProgressiveRead(t){this.#Lr.promise.then(()=>{this.#Da({type:"progressiveRead",chunk:t})})}onDataProgressiveDone(){this.#Lr.promise.then(()=>{this.#Da({type:"progressiveDone"})})}transportReady(t){this.#Da=t,this.#Lr.resolve()}requestDataRange(t,e){w("Abstract method PDFDataRangeTransport.requestDataRange")}abort(){}},bs=class{constructor(t,e){this._pdfInfo=t,this._transport=e}get pagesMapper(){return this._transport.pagesMapper}get annotationStorage(){return this._transport.annotationStorage}get canvasFactory(){return this._transport.canvasFactory}get filterFactory(){return this._transport.filterFactory}get numPages(){return this._pdfInfo.numPages}get fingerprints(){return this._pdfInfo.fingerprints}get isPureXfa(){return T(this,"isPureXfa",!!this._transport._htmlForXfa)}get allXfaHtml(){return this._transport._htmlForXfa}getPage(t){return this._transport.getPage(t)}getPageIndex(t){return this._transport.getPageIndex(t)}getDestinations(){return this._transport.getDestinations()}getDestination(t){return this._transport.getDestination(t)}getPageLabels(){return this._transport.getPageLabels()}getPageLayout(){return this._transport.getPageLayout()}getPageMode(){return this._transport.getPageMode()}getViewerPreferences(){return this._transport.getViewerPreferences()}getOpenAction(){return this._transport.getOpenAction()}getAttachments(){return this._transport.getAttachments()}getAttachmentContent(t){return this._transport.getAttachmentContent(t)}getAnnotationsByType(t,e){return this._transport.getAnnotationsByType(t,e)}getJSActions(){return this._transport.getDocJSActions()}getOutline(){return this._transport.getOutline()}getOptionalContentConfig({intent:t="display"}={}){const{renderingIntent:e}=this._transport.getRenderingIntent(t);return this._transport.getOptionalContentConfig(e)}getPermissions(){return this._transport.getPermissions()}getMetadata(){return this._transport.getMetadata()}getMarkInfo(){return this._transport.getMarkInfo()}getData(){return this._transport.getData()}saveDocument(t){return this._transport.saveDocument(t)}extractPages(t,e=null){return this._transport.extractPages(t,e)}getDownloadInfo(){return this._transport.downloadInfoCapability.promise}cleanup(t=!1){return this._transport.startCleanup(t||this.isPureXfa)}cachedPageNumber(t){return this._transport.cachedPageNumber(t)}get loadingParams(){return this._transport.loadingParams}get loadingTask(){return this._transport.loadingTask}getFieldObjects(){return this._transport.getFieldObjects()}getSignatures(){return this._transport.getSignatures()}getSignatureData(t){return this._transport.getSignatureData(t)}hasJSActions(){return this._transport.hasJSActions()}getCalculationOrderIds(){return this._transport.getCalculationOrderIds()}},ys=class t{#Ia=!1;#Fa=null;static#La=0;constructor(e,i,s,n,r=!1){this._pageIndex=e,this._id=t.#La++,this._pageInfo=i,this._transport=s,this._stats=r?new ie:null,this._pdfBug=r,this.commonObjs=s.commonObjs,this.objs=new ns,this._intentStates=/* @__PURE__ */new Map,this.destroyed=!1,this.recordedBBoxes=null,this.#Fa=n,this.imageCoordinates=null}clone(e){const i=new t(e,this._pageInfo,this._transport,this.#Fa,this._pdfBug);return i.clonedFromIndex=this.clonedFromIndex??this._pageIndex,this._transport.updatePage(i),i}get pageNumber(){return this._pageIndex+1}set pageNumber(t){this._pageIndex=t-1,this._transport.updatePage(this)}get rotate(){return this._pageInfo.rotate}get ref(){return this._pageInfo.ref}get userUnit(){return this._pageInfo.userUnit}get view(){return this._pageInfo.view}getViewport({scale:t,rotation:e=this.rotate,offsetX:i=0,offsetY:s=0,dontFlip:n=!1}={}){return new at({viewBox:this.view,userUnit:this.userUnit,scale:t,rotation:e,offsetX:i,offsetY:s,dontFlip:n})}getAnnotations({intent:t="display"}={}){const{renderingIntent:e}=this._transport.getRenderingIntent(t);return this._transport.getAnnotations(this._pageIndex,e)}getJSActions(){return this._transport.getPageJSActions(this._pageIndex)}get filterFactory(){return this._transport.filterFactory}get isPureXfa(){return T(this,"isPureXfa",!!this._transport._htmlForXfa)}async getXfa(){return this._transport._htmlForXfa?.children[this._pageIndex]||null}render({canvasContext:t,canvas:e=t.canvas,viewport:i,intent:s="display",annotationMode:n=r.ENABLE,transform:a=null,background:o=null,optionalContentConfigPromise:l=null,annotationCanvasMap:h=null,pageColors:c=null,printAnnotationStorage:d=null,isEditing:u=!1,recordImages:p=!1,recordOperations:g=!1,partialFrames:m=!1,operationsFilter:f=null}){this._stats?.time("Overall");const b=this._transport.getRenderingIntent(s,n,d,u),{renderingIntent:y,cacheKey:v}=b;this.#Ia=!1,l||=this._transport.getOptionalContentConfig(y);const w=this._intentStates.getOrInsertComputed(v,G);w.streamReaderCancelTimeout&&(clearTimeout(w.streamReaderCancelTimeout),w.streamReaderCancelTimeout=null);const A=!!(4&y);w.displayReadyCapability||(w.displayReadyCapability=Promise.withResolvers(),w.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},this._stats?.time("Page Request"),this._pumpOperatorList(b));const x=!(!this._pdfBug||!globalThis.StepperManager?.enabled),C=!!e&&!this.recordedBBoxes&&(g||x),S=!!e&&!this.imageCoordinates&&p,T=t=>{if(w.renderTasks.delete(_),C){const{recordedBBoxes:t}=_;t&&(_.stepper?.setOperatorBBoxes(t,_.debugMetadata),g&&(this.recordedBBoxes=t))}S&&!t&&(this.imageCoordinates=_.imageCoordinates),A&&(this.#Ia=!0),this.#Ba(),t?(_.capability.reject(t),this._abortOperatorList({intentState:w,reason:t instanceof Error?t:new Error(t)})):_.capability.resolve(),this._stats&&(this._stats.timeEnd("Rendering"),this._stats.timeEnd("Overall"),globalThis.Stats?.enabled&&globalThis.Stats.add(this.pageNumber,this._stats))},_=new xs({callback:T,params:{canvas:e,canvasContext:t,viewport:i,transform:a,background:o,recordOperations:C,recordImages:S,partialFrames:m,recordForDebugger:x},objs:this.objs,commonObjs:this.commonObjs,annotationCanvasMap:h,operatorList:w.operatorList,pageIndex:this._pageIndex,pageProxyId:this._id,canvasFactory:this._transport.canvasFactory,filterFactory:this._transport.filterFactory,useRequestAnimationFrame:!A,pdfBug:this._pdfBug,pageColors:c,operationsFilter:f,rendererWorker:this._transport.rendererWorker,waitForGPU:()=>this._transport.waitForGPU()});(w.renderTasks||=/* @__PURE__ */new Set).add(_);const k=_.task;return Promise.all([w.displayReadyCapability.promise,l]).then(async([t,e])=>{if(this.destroyed)T();else{if(this._stats?.time("Rendering"),!(e.renderingIntent&y))throw new Error("Must use the same `intent`-argument when calling the `PDFPageProxy.render` and `PDFDocumentProxy.getOptionalContentConfig` methods.");await _.initializeGraphics({transparency:t,optionalContentConfig:e}),_.operatorListChanged()}}).catch(T),k}getOperatorList({intent:t="display",annotationMode:e=r.ENABLE,printAnnotationStorage:i=null,isEditing:s=!1}={}){const n=this._transport.getRenderingIntent(t,e,i,s,!0),a=this._intentStates.getOrInsertComputed(n.cacheKey,G);let o;return a.opListReadCapability||(o=Object.create(null),o.operatorListChanged=function(){a.operatorList.lastChunk&&(a.opListReadCapability.resolve(a.operatorList),a.renderTasks.delete(o))},a.opListReadCapability=Promise.withResolvers(),(a.renderTasks||=/* @__PURE__ */new Set).add(o),a.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},this._stats?.time("Page Request"),this._pumpOperatorList(n)),a.opListReadCapability.promise}streamTextContent({includeMarkedContent:t=!1,disableNormalization:e=!1}={}){return this._transport.messageHandler.sendWithStream("GetTextContent",{pageId:this.#Fa.getPageId(this._pageIndex+1)-1,pageIndex:this._pageIndex,includeMarkedContent:!0===t,disableNormalization:!0===e},{highWaterMark:100,size:t=>t.items.length})}async getTextContent(t={}){if(this._transport._htmlForXfa)return this.getXfa().then(t=>ot.textContent(t));const e=this.streamTextContent(t).getReader(),i={items:[],styles:Object.create(null),lang:null};for(;;){const{value:t,done:s}=await e.read();if(s)break;i.lang??=t.lang,Object.assign(i.styles,t.styles),i.items.push(...t.items)}return i}getStructTree(){return this._transport.getStructTree(this._pageIndex)}_destroy(){this.destroyed=!0;const t=[];for(const e of this._intentStates.values())if(this._abortOperatorList({intentState:e,reason:/* @__PURE__ */new Error("Page was destroyed."),force:!0}),!e.opListReadCapability)for(const i of e.renderTasks)t.push(i.completed),i.cancel();return this.objs.clear(),this._transport.cleanupPage(this._id),this.#Ia=!1,Promise.all(t)}cleanup(t=!1){this.#Ia=!0;const e=this.#Ba();return t&&e&&(this._stats&&=new ie),e}#Ba(){if(!this.#Ia||this.destroyed)return!1;for(const{renderTasks:t,operatorList:e}of this._intentStates.values())if(t.size>0||!e.lastChunk)return!1;return this._intentStates.clear(),this.objs.clear(),this._transport.cleanupPage(this._id),this.#Ia=!1,!0}_startRenderPage(t,e){const i=this._intentStates.get(e);i&&(this._stats?.timeEnd("Page Request"),i.displayReadyCapability?.resolve(t))}_renderPageChunk(t,e){for(let i=0,s=t.length;i<s;i++)e.operatorList.fnArray.push(t.fnArray[i]),e.operatorList.argsArray.push(t.argsArray[i]);e.operatorList.lastChunk=t.lastChunk,e.operatorList.separateAnnots=t.separateAnnots;for(const i of e.renderTasks)i.operatorListChanged();t.lastChunk&&this.#Ba()}_pumpOperatorList({renderingIntent:t,cacheKey:e,annotationStorageSerializable:i,modifiedIds:s}){const{map:n,transfer:r}=i,a=this._transport.messageHandler.sendWithStream("GetOperatorList",{pageId:this.#Fa.getPageId(this._pageIndex+1)-1,pageIndex:this._pageIndex,pageProxyId:this._id,intent:t,cacheKey:e,annotationStorage:n,modifiedIds:s},void 0,r).getReader(),o=this._intentStates.get(e);o.streamReader=a;const l=()=>{a.read().then(({value:t,done:e})=>{e?o.streamReader=null:this._transport.destroyed||(this._renderPageChunk(t,o),l())},t=>{if(o.streamReader=null,!this._transport.destroyed){if(o.operatorList){o.operatorList.lastChunk=!0;for(const t of o.renderTasks)t.operatorListChanged();this.#Ba()}if(o.displayReadyCapability)o.displayReadyCapability.reject(t);else{if(!o.opListReadCapability)throw t;o.opListReadCapability.reject(t)}}})};l()}_abortOperatorList({intentState:t,reason:e,force:i=!1}){if(t.streamReader){if(t.streamReaderCancelTimeout&&(clearTimeout(t.streamReaderCancelTimeout),t.streamReaderCancelTimeout=null),!i){if(t.renderTasks.size>0)return;if(e instanceof $){let i=100;return e.extraDelay>0&&e.extraDelay<1e3&&(i+=e.extraDelay),void(t.streamReaderCancelTimeout=setTimeout(()=>{t.streamReaderCancelTimeout=null,this._abortOperatorList({intentState:t,reason:e,force:!0})},i))}}if(t.streamReader.cancel(new I(e.message)).catch(()=>{}),t.streamReader=null,!this._transport.destroyed){for(const[e,i]of this._intentStates)if(i===t){this._intentStates.delete(e);break}this.cleanup()}}}get stats(){return this._stats}},vs=class e{#Lr=Promise.withResolvers();#Rr=null;#jn=null;#Wr=null;static#Ra=0;static#Oa=!1;static#Na=/* @__PURE__ */new WeakMap;static{t&&(this.#Oa=!0,Wi.workerSrc||="./pdf.worker.mjs")}constructor({name:t=null,port:i=null,verbosity:s=y()}={}){if(this.name=t,this.destroyed=!1,this.verbosity=s,i){if(e.#Na.has(i))throw new Error("Cannot use more than one PDFWorker per port.");e.#Na.set(i,this),this.#Xr(i)}else this.#Kr()}get promise(){return this.#Lr.promise}#Yr(){this.#Lr.resolve(),this.#Rr.send("configure",{verbosity:this.verbosity})}get port(){return this.#jn}get messageHandler(){return this.#Rr}#Xr(t){this.#jn=t,this.#Rr=new le("main","worker",t),this.#Rr.on("ready",()=>{}),this.#Yr()}#Kr(){if(e.#Oa||e.#za)return void this.#Ha();const{workerSrc:t}=e;try{const e=new Worker(te(t),{type:"module"}),i=new le("main","worker",e),s=()=>{n.abort(),i.destroy(),e.terminate(),this.destroyed?this.#Lr.reject(/* @__PURE__ */new Error("Worker was destroyed")):this.#Ha()},n=new AbortController;e.addEventListener("error",()=>{this.#Wr||s()},{signal:n.signal}),i.on("ready",t=>{n.abort(),!this.destroyed&&t instanceof Uint8Array?(this.#Rr=i,this.#jn=e,this.#Wr=e,this.#Yr()):s()})}catch{this.#Ha()}}#Ha(){e.#Oa||(e.#Oa=!0),e._setupFakeWorkerGlobal.then(t=>{if(this.destroyed)return void this.#Lr.reject(/* @__PURE__ */new Error("Worker was destroyed"));const i=new ee;this.#jn=i;const s="fake"+e.#Ra++,n=new le(s+"_worker",s,i);t.setup(n,i),this.#Rr=new le(s,s+"_worker",i),this.#Yr()}).catch(t=>{this.#Lr.reject(/* @__PURE__ */new Error(`Setting up fake worker failed: "${t.message}".`))})}destroy(){this.destroyed=!0,this.#Wr?.terminate(),this.#Wr=null,e.#Na.delete(this.#jn),this.#jn=null,this.#Rr?.destroy(),this.#Rr=null}static create(t){const i=this.#Na.get(t?.port);if(i){if(i._pendingDestroy)throw new Error("PDFWorker.create - the worker is being destroyed.\nPlease remember to await `PDFDocumentLoadingTask.destroy()`-calls.");return i}return new e(t)}static get workerSrc(){if(Wi.workerSrc)return Wi.workerSrc;throw new Error('No "GlobalWorkerOptions.workerSrc" specified.')}static get#za(){try{return globalThis.pdfjsWorker?.WorkerMessageHandler||null}catch{return null}}static get _setupFakeWorkerGlobal(){return T(this,"_setupFakeWorkerGlobal",(async()=>this.#za?this.#za:(await(import(this.workerSrc))).WorkerMessageHandler)())}},ws=class{downloadInfoCapability=Promise.withResolvers();#Ua=null;#Ga=!1;#Wa=/* @__PURE__ */new Map;#ja=null;#Va=/* @__PURE__ */new Map;#$a=/* @__PURE__ */new Map;#Xa=/* @__PURE__ */new Map;#Ka=null;#Ya=null;constructor(t,e,i,s,n,r){this.messageHandler=t,this.loadingTask=e,this.#ja=i,this.commonObjs=new ns,this.fontLoader=new gi({ownerDocument:s.ownerDocument,styleElement:s.styleElement}),this.rendererWorker=s.rendererWorker,this.loadingParams=s.loadingParams,this._params=s,this.canvasFactory=n.canvasFactory,this.filterFactory=n.filterFactory,this.binaryDataFactory=n.binaryDataFactory,this.pagesMapper=r,this.destroyed=!1,this.destroyCapability=null,this.setupMessageHandler()}updatePage(t){this.#Va.set(t._id,t),this.#$a.set(t._pageIndex,Promise.resolve(t))}#qa(t,e=null){return this.#Wa.getOrInsertComputed(t,()=>this.messageHandler.sendWithPromise(t,e))}#Hn({loaded:t,total:e}){this.loadingTask.onProgress?.({loaded:t,total:e,percent:e?j(Math.round(t/e*100),0,100):NaN})}get annotationStorage(){return T(this,"annotationStorage",new Yt)}getRenderingIntent(t,e=r.ENABLE,i=null,s=!1,n=!1){let a=2,o=Kt;switch(t){case"any":a=1;break;case"display":break;case"print":a=4}const l=4&a&&i instanceof qt?i:this.annotationStorage;switch(e){case r.DISABLE:a+=64;break;case r.ENABLE:break;case r.ENABLE_FORMS:a+=16;break;case r.ENABLE_STORAGE:a+=32,o=l.serializable}s&&(a+=128),n&&(a+=256);const{ids:h,hash:c}=l.modifiedIds;return{renderingIntent:a,cacheKey:[a,o.hash,c].join("_"),annotationStorageSerializable:o,modifiedIds:h}}destroy(){if(this.destroyCapability)return this.destroyCapability.promise;this.destroyed=!0,this.destroyCapability=Promise.withResolvers(),this.#Ka?.reject(/* @__PURE__ */new Error("Worker was destroyed during onPassword callback"));const t=[];for(const i of this.#Va.values())t.push(i._destroy());this.#Va.clear(),this.#$a.clear(),this.#Xa.clear(),Object.hasOwn(this,"annotationStorage")&&this.annotationStorage.resetModified();const e=this.messageHandler.sendWithPromise("Terminate",null);return t.push(e),Promise.all(t).then(()=>{this.commonObjs.clear(),this.fontLoader.clear(),this.#Wa.clear(),this.filterFactory.destroy(),ps.cleanup(),this.#ja?.cancelAllRequests(new I("Worker was terminated.")),this.messageHandler?.destroy(),this.messageHandler=null,this.rendererWorker=null,this.destroyCapability.resolve()},this.destroyCapability.reject),this.destroyCapability.promise}setupMessageHandler(){const{messageHandler:t,loadingTask:e}=this;t.on("GetReader",(t,e)=>{A(this.#ja,"GetReader - no `BasePDFStream` instance available."),this.#Ua=this.#ja.getFullReader(),this.#Ua.onProgress=t=>this.#Hn(t),e.onPull=()=>{this.#Ua.read().then(function({value:t,done:i}){i?e.close():(A(t instanceof ArrayBuffer,"GetReader - expected an ArrayBuffer."),e.enqueue(new Uint8Array(t),1,[t]))}).catch(t=>{e.error(t)})},e.onCancel=t=>{this.#Ua.cancel(t),e.ready.catch(t=>{if(!this.destroyed)throw t})}}),t.on("ReaderHeadersReady",async t=>{await this.#Ua.headersReady;const{isStreamingSupported:e,isRangeSupported:i,contentLength:s}=this.#Ua;return e&&i&&(this.#Ua.onProgress=null),{isStreamingSupported:e,isRangeSupported:i,contentLength:s}}),t.on("GetRangeReader",(t,e)=>{A(this.#ja,"GetRangeReader - no `BasePDFStream` instance available.");const i=this.#ja.getRangeReader(t.begin,t.end);i?(e.onPull=()=>{i.read().then(function({value:t,done:i}){i?e.close():(A(t instanceof ArrayBuffer,"GetRangeReader - expected an ArrayBuffer."),e.enqueue(new Uint8Array(t),1,[t]))}).catch(t=>{e.error(t)})},e.onCancel=t=>{i.cancel(t),e.ready.catch(t=>{if(!this.destroyed)throw t})}):e.close()}),t.on("GetDoc",({pdfInfo:t})=>{this.pagesMapper.pagesNumber=t.numPages,this._numPages=t.numPages,this._htmlForXfa=t.htmlForXfa,delete t.htmlForXfa,e._capability.resolve(new bs(t,this))}),t.on("DocException",t=>{e._capability.reject(oe(t))}),t.on("PasswordRequest",t=>{this.#Ka=Promise.withResolvers();try{if(!e.onPassword)throw oe(t);const i=t=>{t instanceof Error?this.#Ka.reject(t):this.#Ka.resolve({password:t})};e.onPassword(i,t.code)}catch(i){this.#Ka.reject(i)}return this.#Ka.promise}),t.on("DataLoaded",t=>{this.#Hn({loaded:t.length,total:t.length}),this.downloadInfoCapability.resolve(t)}),t.on("StartRenderPage",t=>{this.destroyed||this.#Va.get(t.pageProxyId)._startRenderPage(t.transparency,t.cacheKey)});const i=new rs({messageHandler:t,commonObjs:this.commonObjs,fontLoader:this.fontLoader,pageCache:this.#Va,pdfBug:this._params.pdfBug});this.rendererWorker?.promise.then(()=>{this.rendererWorker?.messageHandler?.on("FontFallback",e=>this.destroyed?null:t.sendWithPromise("FontFallback",e))},()=>{}),t.on("commonobj",([t,e,s])=>{if(this.destroyed)return null;const{rendererWorker:n}=this;if("CopyLocalImage"===e){if(this.commonObjs.has(t))return null;const r=i.resolveCommonObject(t,e,s);return r&&n?.sendCommonObj(t,"Image",this.commonObjs.get(t)),r}return n?.sendCommonObj(t,e,s),this.commonObjs.has(t)||(i.resolveCommonObject(t,e,s),"Pattern"===e&&"Mesh"===this.commonObjs.get(t)[0]&&(this.#Ga=!0)),null}),t.on("obj",([t,e,s,n])=>{this.destroyed||("Pattern"===s&&"Mesh"===n[0]&&(this.#Ga=!0),i.resolveObject(t,e,s,n)&&this.rendererWorker?.sendObj(t,e,s,n))}),t.on("DocProgress",t=>{this.destroyed||this.#Hn(t)}),t.on("FetchBinaryData",async t=>{if(this.destroyed)throw new Error("Worker was destroyed.");if(!this.binaryDataFactory)throw new Error("`BinaryDataFactory` not initialized, see the `useWorkerFetch` parameter.");return this.binaryDataFactory.fetch(t)})}getData(){return this.messageHandler.sendWithPromise("GetData",null)}saveDocument(t=null){this.annotationStorage.size;const{map:e,transfer:i}=this.annotationStorage.serializable;return this.messageHandler.sendWithPromise("SaveDocument",{isPureXfa:!!this._htmlForXfa,numPages:this._numPages,annotationStorage:e,supportsPrintToPDF:null!==this.#Ya,filename:this.#Ua?.filename??null},i).finally(()=>{this.#Ya=null,this.annotationStorage.resetModified()})}extractPages(t,e=null){const i={pageInfos:t};let s;const n=globalThis.ImageBitmap;if("function"==typeof n){const e=Array.isArray(t)?t:[t];for(const t of e)t?.image instanceof n&&(s||=[]).push(t.image)}if(this.annotationStorage.size>0){const t=this.annotationStorage.serializable;let{map:n}=t;t.transfer?.length&&(s?s.push(...t.transfer):s=t.transfer);const r=this.pagesMapper.getMapping();if(r){const t=/* @__PURE__ */new Map;for(const[i,s]of n){if(void 0!==s?.pageIndex&&s.pageIndex>=0&&s.pageIndex<r.length){const n=e?.[s.pageIndex]??0,a=r[s.pageIndex]-1;if(a!==s.pageIndex||0!==n){t.set(i,{...s,pageIndex:a,copyLevel:n});continue}}t.set(i,s)}n=t}i.annotationStorage=n}return this.messageHandler.sendWithPromise("ExtractPages",i,s).finally(()=>{this.annotationStorage.resetModified()})}waitForGPU(){return this._params.enableWebGPU&&this.#Ga&&!re()?ne():null}getPage(t){if(!Number.isInteger(t)||t<=0||t>this.pagesMapper.pagesNumber)return Promise.reject(/* @__PURE__ */new Error("Invalid page request."));const e=t-1,i=this.pagesMapper.getPageId(t)-1,s=this.#$a.get(e);if(s)return s;const n=this.messageHandler.sendWithPromise("GetPage",{pageIndex:i}).then(t=>{if(this.destroyed)throw new Error("Transport destroyed");t.refStr&&this.#Xa.set(t.refStr,i);const s=new ys(e,t,this,this.pagesMapper,this._params.pdfBug);return this.#Va.set(s._id,s),s});return this.#$a.set(e,n),n}async getPageIndex(t){if(!Jt(t))throw new Error("Invalid pageIndex request.");const e=await this.messageHandler.sendWithPromise("GetPageIndex",{num:t.num,gen:t.gen}),i=this.pagesMapper.getPageNumber(e+1);if(0===i)throw new Error("GetPageIndex: page has been removed.");return i-1}getAnnotations(t,e){return this.messageHandler.sendWithPromise("GetAnnotations",{pageIndex:this.pagesMapper.getPageId(t+1)-1,intent:e})}getFieldObjects(){return this.#qa("GetFieldObjects")}getSignatures(){return this.#qa("GetSignatures")}getSignatureData(t){return this.messageHandler.sendWithPromise("GetSignatureData",t)}hasJSActions(){return this.#qa("HasJSActions")}getCalculationOrderIds(){return this.messageHandler.sendWithPromise("GetCalculationOrderIds",null)}getDestinations(){return this.messageHandler.sendWithPromise("GetDestinations",null)}getDestination(t){return"string"!=typeof t?Promise.reject(/* @__PURE__ */new Error("Invalid destination request.")):this.messageHandler.sendWithPromise("GetDestination",{id:t})}getPageLabels(){return this.messageHandler.sendWithPromise("GetPageLabels",null)}getPageLayout(){return this.messageHandler.sendWithPromise("GetPageLayout",null)}getPageMode(){return this.messageHandler.sendWithPromise("GetPageMode",null)}getViewerPreferences(){return this.messageHandler.sendWithPromise("GetViewerPreferences",null)}getOpenAction(){return this.messageHandler.sendWithPromise("GetOpenAction",null)}getAttachments(){return this.messageHandler.sendWithPromise("GetAttachments",null)}getAttachmentContent(t){return this.messageHandler.sendWithPromise("GetAttachmentContent",t)}getAnnotationsByType(t,e){return this.messageHandler.sendWithPromise("GetAnnotationsByType",{types:t,pageIndexesToSkip:e})}getDocJSActions(){return this.#qa("GetDocJSActions")}getPageJSActions(t){return this.messageHandler.sendWithPromise("GetPageJSActions",{pageIndex:this.pagesMapper.getPageId(t+1)-1})}getStructTree(t){return this.messageHandler.sendWithPromise("GetStructTree",{pageIndex:this.pagesMapper.getPageId(t+1)-1})}getOutline(){return this.messageHandler.sendWithPromise("GetOutline",null)}getOptionalContentConfig(t){const e="GetOptionalContentConfig";return this.#Wa.getOrInsertComputed(e,()=>this.messageHandler.sendWithPromise(e,null).catch(t=>null)).then(e=>new ls(e,t))}getPermissions(){return this.messageHandler.sendWithPromise("GetPermissions",null)}getMetadata(){const t="GetMetadata";return this.#Wa.getOrInsertComputed(t,()=>this.messageHandler.sendWithPromise(t,null).then(t=>({info:t[0],metadata:t[1]?new ji(t[1]):null,contentDispositionFilename:this.#Ua?.filename??null,contentLength:this.#Ua?.contentLength??null,hasStructTree:t[2]})))}getMarkInfo(){return this.messageHandler.sendWithPromise("GetMarkInfo",null)}async startCleanup(t=!1){if(!this.destroyed){await this.messageHandler.sendWithPromise("Cleanup",null);for(const t of this.#Va.values())if(!t.cleanup())throw new Error(`startCleanup: Page ${t.pageNumber} is currently rendering.`);this.commonObjs.clear(),t||this.fontLoader.clear(),this.rendererWorker?.cleanup(t),this.#Wa.clear(),this.filterFactory.destroy(!0),ps.cleanup()}}cleanupPage(t){this.destroyed||this.messageHandler.send("CleanupPage",{pageProxyId:t}),this.rendererWorker?.cleanupPage(t)}cachedPageNumber(t){if(!Jt(t))return null;const e=0===t.gen?`${t.num}R`:`${t.num}R${t.gen}`,i=this.#Xa.get(e);if(i>=0){const t=this.pagesMapper.getPageNumber(i+1);if(0!==t)return t}return null}},As=class{_internalRenderTask=null;onContinue=null;onError=null;onFrame=null;constructor(t){this._internalRenderTask=t}get promise(){return this._internalRenderTask.capability.promise}cancel(t=0){this._internalRenderTask.cancel(null,t)}get separateAnnots(){const{separateAnnots:t}=this._internalRenderTask.operatorList;if(!t)return!1;const{annotationCanvasMap:e}=this._internalRenderTask;return t.form||t.canvas&&e?.size>0}get imageCoordinates(){return this._internalRenderTask.imageCoordinates||null}get isWorkerRendering(){return this._internalRenderTask.isWorkerRendering}},xs=class t{#Es=null;#Qa=null;#Ja=null;#Za=null;#to=null;static#eo=/* @__PURE__ */new WeakSet;constructor({callback:t,params:e,objs:i,commonObjs:s,annotationCanvasMap:n,operatorList:r,pageIndex:a,pageProxyId:o,canvasFactory:l,filterFactory:h,useRequestAnimationFrame:c=!1,pdfBug:d=!1,pageColors:u=null,operationsFilter:p=null,rendererWorker:g=null,waitForGPU:m=null}){this.callback=t,this.params=e,this.objs=i,this.commonObjs=s,this.annotationCanvasMap=n,this.operatorListIdx=null,this.operatorList=r,this._pageIndex=a,this.canvasFactory=l,this.filterFactory=h,this._pdfBug=d,this.pageColors=u,this.running=!1,this.graphicsReadyCallback=null,this.graphicsReady=!1,this._useRequestAnimationFrame=!0===c&&"undefined"!=typeof window,this.cancelled=!1,this.capability=Promise.withResolvers(),this.task=new As(this),this._cancelBound=this.cancel.bind(this),this._continueBound=this._continue.bind(this),this._scheduleNextBound=this._scheduleNext.bind(this),this._nextBound=this._next.bind(this),this._canvas=e.canvas,this._canvasContext=e.canvas?null:e.canvasContext,this._operationsFilter=p,this.#to=m,this.#Za=g?.createRenderTask({pageProxyId:o,operatorList:r,params:e,pageColors:u,canvasFactory:l,annotationCanvasMap:n,onFrame:()=>this.task.onFrame?.(),onError:t=>this.cancel(t)})??null}get completed(){return this.capability.promise.catch(()=>{})}get isWorkerRendering(){return!!this.#Za}get imageCoordinates(){return this.#Za?this.#Za.imageCoordinates:this.#Qa?.take()}get recordedBBoxes(){return this.#Za?this.#Za.recordedBBoxes:this.#Es?.take()}get debugMetadata(){return this.#Es?.takeDebugMetadata()??null}async initializeGraphics({transparency:e=!1,optionalContentConfig:i}){if(!this.cancelled){if(this._canvas){if(t.#eo.has(this._canvas))throw new Error("Cannot use the same canvas during multiple render() operations. Use different canvas or ensure previous operations were cancelled or completed.");t.#eo.add(this._canvas)}if(this._pdfBug&&globalThis.StepperManager?.enabled&&(this.stepper=globalThis.StepperManager.create(this._pageIndex),this.stepper.init(this.operatorList),this.stepper.nextBreakPoint=this.stepper.getNextBreakPoint()),this.#Za){const t=await this.#Za.initialize(e,i);if(this.cancelled)return;t||(this.#Za=null)}if(!this.#Za){const{viewport:t,transform:s,background:n,recordOperations:r,recordImages:a,recordForDebugger:o}=this.params,l=this._canvasContext||this.canvasFactory.getNoAlphaContext(this._canvas),{dependencyTracker:h,imagesTracker:c}=function(t,e,{recordOperations:i=!1,recordImages:s=!1,recordDebugMetadata:n=!1}){const r=i||s?new Ce(t,e):null;return{dependencyTracker:i?new Se(r,n):r,imagesTracker:s?new Fe(t):null}}(this._canvas,this.operatorList.fnArray.length,{recordOperations:r,recordImages:a,recordDebugMetadata:o});this.#Es=h,this.#Qa=c,this.gfx=new li(l,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:i},this.annotationCanvasMap,this.pageColors,h,c),this.gfx.beginDrawing({transform:s,viewport:t,transparency:e,background:n})}this.operatorListIdx=0,this.graphicsReady=!0,this.graphicsReadyCallback?.()}}cancel(e=null,i=0){this.running=!1,this.cancelled=!0,this.#Za?.cancel(),this.gfx?.endDrawing(),this.#Ja&&(window.cancelAnimationFrame(this.#Ja),this.#Ja=null),t.#eo.delete(this._canvas),e||=new $(`Rendering cancelled, page ${this._pageIndex+1}`,i),this.callback(e),this.task.onError?.(e)}operatorListChanged(){this.graphicsReady?(this.#Es?.growOperationsCount(this.operatorList.fnArray.length),this.stepper?.updateOperatorList(this.operatorList),this.running||this._continue()):this.graphicsReadyCallback||=this._continueBound}_continue(){this.running=!0,this.cancelled||(this.task.onContinue?this.task.onContinue(this._scheduleNextBound):this._scheduleNext())}_scheduleNext(){this._useRequestAnimationFrame?this.#Ja=window.requestAnimationFrame(()=>{this.#Ja=null,this._nextBound().catch(this._cancelBound)}):Promise.resolve().then(this._nextBound).catch(this._cancelBound)}async _next(){if(this.cancelled)return;if(!this.#Za){const t=this.#to?.();if(t&&(await t,this.cancelled))return}const{operatorList:e}=this,{lastChunk:i}=e;if(this.#Za){if(this.operatorListIdx=await this.#Za.executeOperatorList(e,this.operatorListIdx,this._operationsFilter),this.cancelled)return;if(this.operatorListIdx!==e.argsArray.length||i!==e.lastChunk)return void this._continue()}else this.operatorListIdx=this.gfx.executeOperatorList(e,this.operatorListIdx,this._continueBound,null,this.stepper,this._operationsFilter);this.operatorListIdx===e.argsArray.length&&(this.running=!1,i&&(this.gfx?.endDrawing(),t.#eo.delete(this._canvas),this.callback()))}},Cs="6.5.438",Ss="0a4153349",Ts=class t{#io=null;#so=null;#no;#ro=null;#ao=!1;#oo=!1;#a=null;#lo;#ho=null;#y=null;static#co=null;static get _keyboardManager(){return T(this,"_keyboardManager",new Ft([[["Escape"],t.prototype._hideDropdownFromKeyboard],[["Space"],t.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight"],t.prototype._moveToNext],[["ArrowUp","ArrowLeft"],t.prototype._moveToPrevious],[["Home"],t.prototype._moveToBeginning],[["End"],t.prototype._moveToEnd]]))}constructor({editor:e=null,uiManager:i=null}){e?(this.#oo=!1,this.#a=e):this.#oo=!0,this.#y=e?._uiManager||i,this.#lo=this.#y._eventBus,this.#no=e?.color?.toUpperCase()||this.#y?.highlightColors.values().next().value||"#FFFF98",t.#co||=Object.freeze({blue:"pdfjs-editor-colorpicker-blue",green:"pdfjs-editor-colorpicker-green",pink:"pdfjs-editor-colorpicker-pink",red:"pdfjs-editor-colorpicker-red",yellow:"pdfjs-editor-colorpicker-yellow"})}renderButton(){const t=this.#io=document.createElement("button");t.className="colorPicker",t.tabIndex="0",t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-button"),t.ariaHasPopup="true",this.#a&&(t.ariaControls=`${this.#a.id}_colorpicker_dropdown`);const e=this.#y._signal;t.addEventListener("click",this.#do.bind(this),{signal:e}),t.addEventListener("keydown",this.#uo.bind(this),{signal:e});const i=this.#so=document.createElement("span");return i.className="swatch",i.ariaHidden="true",i.style.backgroundColor=this.#no,t.append(i),t}renderMainDropdown(){const t=this.#ro=this.#po();return t.ariaOrientation="horizontal",t.ariaLabelledBy="highlightColorPickerLabel",t}#po(){const e=document.createElement("div"),i=this.#y._signal;e.addEventListener("contextmenu",bt,{signal:i}),e.className="dropdown",e.role="listbox",e.ariaMultiSelectable="false",e.ariaOrientation="vertical",e.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown"),this.#a&&(e.id=`${this.#a.id}_colorpicker_dropdown`);for(const[s,n]of this.#y.highlightColors){const r=document.createElement("button");r.tabIndex="0",r.role="option",r.setAttribute("data-color",n),r.title=s,r.setAttribute("data-l10n-id",t.#co[s]);const a=document.createElement("span");r.append(a),a.className="swatch",a.style.backgroundColor=n,r.ariaSelected=n===this.#no,r.addEventListener("click",this.#go.bind(this,n),{signal:i}),e.append(r)}return e.addEventListener("keydown",this.#uo.bind(this),{signal:i}),e}#go(t,e){e.stopPropagation(),this.#lo.dispatch("switchannotationeditorparams",{source:this,type:h.HIGHLIGHT_COLOR,value:t}),this.update(t)}_colorSelectFromKeyboard(t){if(t.target===this.#io)return void this.#do(t);const e=t.target.getAttribute("data-color");e&&this.#go(e,t)}_moveToNext(t){this.#mo?t.target!==this.#io?t.target.nextSibling?.focus():this.#ro.firstElementChild?.focus():this.#do(t)}_moveToPrevious(t){t.target!==this.#ro?.firstElementChild&&t.target!==this.#io?(this.#mo||this.#do(t),t.target.previousSibling?.focus()):this.#mo&&this._hideDropdownFromKeyboard()}_moveToBeginning(t){this.#mo?this.#ro.firstElementChild?.focus():this.#do(t)}_moveToEnd(t){this.#mo?this.#ro.lastElementChild?.focus():this.#do(t)}#uo(e){t._keyboardManager.exec(this,e)}#do(t){if(this.#mo)return void this.hideDropdown();if(this.#ao=0===t.detail,this.#ho||(this.#ho=new AbortController,window.addEventListener("pointerdown",this.#p.bind(this),{signal:this.#y.combinedSignal(this.#ho)})),this.#io.ariaExpanded="true",this.#ro)return void this.#ro.classList.remove("hidden");const e=this.#ro=this.#po();this.#io.append(e)}#p(t){this.#ro?.contains(t.target)||this.hideDropdown()}hideDropdown(){this.#ro?.classList.add("hidden"),this.#io.ariaExpanded="false",this.#ho?.abort(),this.#ho=null}get#mo(){return this.#ro&&!this.#ro.classList.contains("hidden")}_hideDropdownFromKeyboard(){this.#oo||(this.#mo?(this.hideDropdown(),this.#io.focus({preventScroll:!0,focusVisible:this.#ao})):this.#a?.unselect())}update(t){if(this.#so&&(this.#so.style.backgroundColor=t),!this.#ro)return;const e=this.#y.highlightColors.values();for(const i of this.#ro.children)i.ariaSelected=e.next().value===t.toUpperCase()}destroy(){this.#io?.remove(),this.#io=null,this.#so=null,this.#ro?.remove(),this.#ro=null}},_s=class t{#fo=null;#bo=!1;#a=null;#y=null;static#co=null;constructor(e){this.#a=e,this.#y=e._uiManager,t.#co||=Object.freeze({freetext:"pdfjs-editor-color-picker-free-text-input",ink:"pdfjs-editor-color-picker-ink-input"})}renderButton(){if(this.#fo)return this.#fo;const{editorType:e,colorType:i,colorAndOpacityType:s,opacityType:n,color:r,opacity:a}=this.#a,o=this.#bo=L.isAlphaColorInputSupported&&void 0!==n,l=this.#fo=document.createElement("input");if(l.type="color",o){l.setAttribute("alpha","");const t=B.hexNums[Math.round(255*(a??1))];l.value=(r||"#000000")+t}else l.value=r||"#000000";return l.className="basicColorPicker",l.tabIndex=0,l.setAttribute("data-l10n-id",t.#co[e]),l.addEventListener("input",()=>{if(o){const t=X(l.value);if(!t)return;const[e,r,a,o]=t,h=B.makeHexColor(e,r,a);void 0!==s?this.#y.updateParams(s,{color:h,opacity:o}):(this.#y.updateParams(i,h),this.#y.updateParams(n,o))}else this.#y.updateParams(i,l.value)},{signal:this.#y._signal}),l}update(t){if(this.#fo)if(this.#bo){const e=B.hexNums[Math.round(255*this.#a.opacity)];this.#fo.value=t+e}else this.#fo.value=t}updateOpacity(t){if(!this.#fo||!this.#bo)return;const e=B.hexNums[Math.round(255*t)];this.#fo.value=this.#a.color+e}destroy(){this.#fo?.remove(),this.#fo=null}hideDropdown(){}};function ks(t){return Math.floor(255*j(t,0,1)).toString(16).padStart(2,"0")}function Es(t){return 255*j(t,0,1)}var Ms=class{static CMYK_G([t,e,i,s]){return["G",1-Math.min(1,.3*t+.59*i+.11*e+s)]}static G_CMYK([t]){return["CMYK",0,0,0,1-t]}static G_RGB([t]){return["RGB",t,t,t]}static G_rgb([t]){return[t=Es(t),t,t]}static G_HTML([t]){const e=ks(t);return`#${e}${e}${e}`}static RGB_G([t,e,i]){return["G",.3*t+.59*e+.11*i]}static RGB_rgb(t){return t.map(Es)}static RGB_HTML(t){return`#${t.map(ks).join("")}`}static T_HTML(){return"#00000000"}static T_rgb(){return[null]}static CMYK_RGB([t,e,i,s]){return["RGB",1-Math.min(1,t+s),1-Math.min(1,i+s),1-Math.min(1,e+s)]}static CMYK_rgb([t,e,i,s]){return[Es(1-Math.min(1,t+s)),Es(1-Math.min(1,i+s)),Es(1-Math.min(1,e+s))]}static CMYK_HTML(t){const e=this.CMYK_RGB(t).slice(1);return this.RGB_HTML(e)}static RGB_CMYK([t,e,i]){const s=1-t,n=1-e,r=1-i;return["CMYK",s,n,r,Math.min(s,n,r)]}},Ps=class{create(t,e,i=!1){if(t<=0||e<=0)throw new Error("Invalid SVG dimensions");const s=this._createSVG("svg:svg");return s.setAttribute("version","1.1"),i||(s.setAttribute("width",`${t}px`),s.setAttribute("height",`${e}px`)),s.setAttribute("preserveAspectRatio","none"),s.setAttribute("viewBox",`0 0 ${t} ${e}`),s}createElement(t){if("string"!=typeof t)throw new Error("Invalid SVG element type");return this._createSVG(t)}_createSVG(t){w("Abstract method `_createSVG` called.")}},Ds=class extends Ps{_createSVG(t){return document.createElementNS(n,t)}},Is=/* @__PURE__ */new WeakSet,Fs=/* @__PURE__ */60*(new Date).getTimezoneOffset()*1e3,Ls=class{static create(t){switch(t.data.annotationType){case u.LINK:return new Os(t);case u.TEXT:return new Ns(t);case u.WIDGET:switch(t.data.fieldType){case"Tx":return new Hs(t);case"Btn":return t.data.radioButton?new Ws(t):t.data.checkBox?new Gs(t):new js(t);case"Ch":return new Vs(t);case"Sig":return new Us(t)}return new zs(t);case u.POPUP:return new $s(t);case u.FREETEXT:return new Ks(t);case u.LINE:return new Ys(t);case u.SQUARE:return new qs(t);case u.CIRCLE:return new Qs(t);case u.POLYLINE:return new Js(t);case u.CARET:return new tn(t);case u.INK:return new en(t);case u.POLYGON:return new Zs(t);case u.HIGHLIGHT:return new sn(t);case u.UNDERLINE:return new nn(t);case u.SQUIGGLY:return new rn(t);case u.STRIKEOUT:return new an(t);case u.STAMP:return new on(t);case u.FILEATTACHMENT:return new ln(t);case u.RICHMEDIA:case u.SCREEN:case u.SOUND:return new hn(t);default:return new Bs(t)}}},Bs=class t{#yo=null;#vo=!1;#wo=null;constructor(t,{isRenderable:e=!1,ignoreBorder:i=!1,createQuadrilaterals:s=!1}={}){this.isRenderable=e,this.data=t.data,this.layer=t.layer,this.linkService=t.linkService,this.downloadManager=t.downloadManager,this.imageResourcesPath=t.imageResourcesPath,this.renderForms=t.renderForms,this.annotationStorage=t.annotationStorage,this.enableComment=t.enableComment,this.enableAnnotationEditing=!1!==t.enableAnnotationEditing,this.enableScripting=t.enableScripting,this.hasJSActions=t.hasJSActions,this._fieldObjects=t.fieldObjects,this.parent=t.parent,this.hasOwnCommentButton=!1,e&&(this.contentElement=this.container=this._createContainer(i)),s&&this._createQuadrilaterals()}static _hasPopupData({contentsObj:t,richText:e}){return!(!t?.str&&!e?.str)}static get _svgFactory(){return T(this,"_svgFactory",new Ds)}get _isEditable(){return this.enableAnnotationEditing&&this.data.isEditable}get hasPopupData(){return t._hasPopupData(this.data)||this.enableComment&&!!this.commentText}get commentData(){const{data:t}=this,e=this.annotationStorage?.getEditor(t.id);return e?e.getData():t}get hasCommentButton(){return this.enableComment&&this.hasPopupElement}get commentButtonPosition(){const t=this.annotationStorage?.getEditor(this.data.id);if(t)return t.commentButtonPositionInPage;const{quadPoints:e,inkLists:i,rect:s}=this.data;let n=-1/0,r=-1/0;if(e?.length>=8){for(let t=0;t<e.length;t+=8)e[t+1]>r?(r=e[t+1],n=e[t+2]):e[t+1]===r&&(n=Math.max(n,e[t+2]));return[n,r]}if(i?.length>=1){for(const t of i)for(let e=0,i=t.length;e<i;e+=2)t[e+1]>r?(r=t[e+1],n=t[e]):t[e+1]===r&&(n=Math.max(n,t[e]));if(n!==1/0)return[n,r]}return s?[s[2],s[3]]:null}_normalizePoint(t){const{page:{view:e},viewport:{rawDims:{pageWidth:i,pageHeight:s,pageX:n,pageY:r}}}=this.parent;return t[1]=e[3]-t[1]+e[1],t[0]=100*(t[0]-n)/i,t[1]=100*(t[1]-r)/s,t}get commentText(){const{data:t}=this;return this.annotationStorage.getRawValue(`${o}${t.id}`)?.popup?.contents||t.contentsObj?.str||""}set commentText(t){const{data:e}=this,i={deleted:!t,contents:t||""};this.annotationStorage.updateEditor(e.id,{popup:i})||this.annotationStorage.setValue(`${o}${e.id}`,{id:e.id,annotationType:e.annotationType,page:this.parent.page,popup:i,popupRef:e.popupRef,modificationDate:/* @__PURE__ */new Date}),t||this.removePopup()}removePopup(){(this.#wo?.popup||this.popup)?.remove(),this.#wo=this.popup=null}updateEdited(t){if(!this.container)return;t.rect&&(this.#yo||={rect:this.data.rect.slice(0)});const{rect:e,popup:i}=t;e&&this.#Ao(e);let s=this.#wo?.popup||this.popup;!s&&i?.text&&(this._createPopup(i),s=this.#wo.popup),s&&(s.updateEdited(t),i?.deleted&&(s.remove(),this.#wo=null,this.popup=null))}resetEdited(){this.#yo&&(this.#Ao(this.#yo.rect),this.#wo?.popup.resetEdited(),this.#yo=null)}#Ao(t){const{container:{style:e},data:{rect:i,rotation:s},parent:{viewport:{rawDims:{pageWidth:n,pageHeight:r,pageX:a,pageY:o}}}}=this;i?.splice(0,4,...t),e.left=100*(t[0]-a)/n+"%",e.top=100*(r-t[3]+o)/r+"%",0===s?(e.width=100*(t[2]-t[0])/n+"%",e.height=100*(t[3]-t[1])/r+"%"):this.setRotation(s)}_createContainer(t){const{data:e,parent:{page:i,viewport:s}}=this,n=document.createElement("section");n.setAttribute("data-annotation-id",e.id),this instanceof zs||this instanceof Os||this instanceof hn||(n.tabIndex=0);const{style:r}=n;if(r.zIndex=this.parent.zIndex,this.parent.zIndex+=2,e.alternativeText&&(n.title=e.alternativeText),e.noRotate&&n.classList.add("norotate"),!e.rect||this instanceof $s){const{rotation:t}=e;return e.hasOwnCanvas||0===t||this.setRotation(t,n),n}const{width:a,height:o}=this;if(!t&&e.borderStyle.width>0){r.borderWidth=`${e.borderStyle.width}px`;const t=e.borderStyle.horizontalCornerRadius,i=e.borderStyle.verticalCornerRadius;switch((t>0||i>0)&&(r.borderRadius=`calc(${t}px * var(--total-scale-factor)) / calc(${i}px * var(--total-scale-factor))`),e.borderStyle.style){case 1:r.borderStyle="solid";break;case 2:r.borderStyle="dashed";break;case 3:case 4:break;case 5:r.borderBottomStyle="solid"}const s=e.borderColor||null;s?(this.#vo=!0,r.borderColor=B.makeHexColor(...s)):r.borderWidth=0}const l=B.normalizeRect([e.rect[0],i.view[3]-e.rect[1]+i.view[1],e.rect[2],i.view[3]-e.rect[3]+i.view[1]]),{pageWidth:h,pageHeight:c,pageX:d,pageY:u}=s.rawDims;r.left=100*(l[0]-d)/h+"%",r.top=100*(l[1]-u)/c+"%";const{rotation:p}=e;return e.hasOwnCanvas||0===p?(r.width=100*a/h+"%",r.height=100*o/c+"%"):this.setRotation(p,n),n}setRotation(t,e=this.container){if(!this.data.rect)return;const{pageWidth:i,pageHeight:s}=this.parent.viewport.rawDims;let{width:n,height:r}=this;t%180!=0&&([n,r]=[r,n]),e.style.width=100*n/i+"%",e.style.height=100*r/s+"%",e.setAttribute("data-main-rotation",(360-t)%360)}get _commonActions(){const t=(t,e,i)=>{const s=i.detail[t],n=s[0],r=s.slice(1);i.target.style[e]=Ms[`${n}_HTML`](r),this.annotationStorage.setValue(this.data.id,{[e]:Ms[`${n}_rgb`](r)})};return T(this,"_commonActions",{display:t=>{const{display:e}=t.detail,i=e%2==1;this.container.style.visibility=i?"hidden":"visible",this.annotationStorage.setValue(this.data.id,{noView:i,noPrint:1===e||2===e})},print:t=>{this.annotationStorage.setValue(this.data.id,{noPrint:!t.detail.print})},hidden:t=>{const{hidden:e}=t.detail;this.container.style.visibility=e?"hidden":"visible",this.annotationStorage.setValue(this.data.id,{noPrint:e,noView:e})},focus:t=>{setTimeout(()=>t.target.focus({preventScroll:!1}),0)},userName:t=>{t.target.title=t.detail.userName},readonly:t=>{t.target.disabled=t.detail.readonly},required:t=>{this._setRequired(t.target,t.detail.required)},bgColor:e=>{t("bgColor","backgroundColor",e)},fillColor:e=>{t("fillColor","backgroundColor",e)},fgColor:e=>{t("fgColor","color",e)},textColor:e=>{t("textColor","color",e)},borderColor:e=>{t("borderColor","borderColor",e)},strokeColor:e=>{t("strokeColor","borderColor",e)},rotation:t=>{const e=t.detail.rotation;this.setRotation(e),this.annotationStorage.setValue(this.data.id,{rotation:e})}})}_dispatchEventFromSandbox(t,e){const i=this._commonActions;for(const s of Object.keys(e.detail))(t[s]||i[s])?.(e)}_setDefaultPropertiesFromJS(t){if(!this.enableScripting)return;const e=this.annotationStorage.getRawValue(this.data.id);if(!e)return;const i=this._commonActions;for(const[s,n]of Object.entries(e)){const r=i[s];r&&(r({detail:{[s]:n},target:t}),delete e[s])}}_createQuadrilaterals(){if(!this.container)return;const{quadPoints:e}=this.data;if(!e)return;const[i,s,r,a]=this.data.rect.map(Math.fround);if(8===e.length){const[t,n,o,l]=e.subarray(2,6);if(r===t&&a===n&&i===o&&s===l)return}const{style:o}=this.container;let l;if(this.#vo){const{borderColor:t,borderWidth:e}=o;o.borderWidth=0,l=["url('data:image/svg+xml;utf8,",`<svg xmlns="${n}" preserveAspectRatio="none" viewBox="0 0 1 1">`,`<g fill="transparent" stroke="${t}" stroke-width="${e}">`],this.container.classList.add("hasBorder")}const h=r-i,c=a-s,d=t._svgFactory,u=d.createElement("svg");u.classList.add("quadrilateralsContainer"),u.setAttribute("width",0),u.setAttribute("height",0),u.role="none";const p=d.createElement("defs");u.append(p);const g=d.createElement("clipPath"),m=`clippath_${this.data.id}`;g.setAttribute("id",m),g.setAttribute("clipPathUnits","objectBoundingBox"),p.append(g);for(let t=2,n=e.length;t<n;t+=8){const s=e[t],n=e[t+1],r=e[t+2],o=e[t+3],u=d.createElement("rect"),p=(r-i)/h,m=(a-n)/c,f=(s-r)/h,b=(n-o)/c;u.setAttribute("x",p),u.setAttribute("y",m),u.setAttribute("width",f),u.setAttribute("height",b),g.append(u),l?.push(`<rect vector-effect="non-scaling-stroke" x="${p}" y="${m}" width="${f}" height="${b}"/>`)}this.#vo&&(l.push("</g></svg>')"),o.backgroundImage=l.join("")),this.container.append(u),this.container.style.clipPath=`url(#${m})`}_createPopup(t=null){const{data:e}=this;let i,s;t?(i={str:t.text},s=t.date):(i=e.contentsObj,s=e.modificationDate),this.#wo=new $s({data:{color:e.color,titleObj:e.titleObj,modificationDate:s,contentsObj:i,richText:e.richText,parentRect:e.rect,borderStyle:0,id:`popup_${e.id}`,rotation:e.rotation,noRotate:!0},linkService:this.linkService,parent:this.parent,elements:[this]})}get hasPopupElement(){return!!(this.#wo||this.popup||this.data.popupRef)}get extraPopupElement(){return this.#wo}render(){w("Abstract method `AnnotationElement.render` called")}_getElementsByName(t,e=null){const i=[];if(this._fieldObjects){const s=this._fieldObjects.get(t)||[];for(const{page:t,id:n,exportValues:r}of s){if(-1===t||n===e)continue;const s="string"==typeof r?r:null,a=document.querySelector(`[data-element-id="${n}"]`);!a||Is.has(a)?i.push({id:n,exportValue:s,domElement:a}):v()}return i}for(const s of document.getElementsByName(t)){const{exportValue:t}=s,n=s.getAttribute("data-element-id");n!==e&&Is.has(s)&&i.push({id:n,exportValue:t,domElement:s})}return i}show(){this.container&&(this.container.hidden=!1),this.popup?.maybeShow()}hide(){this.container&&(this.container.hidden=!0),this.popup?.forceHide()}getElementsToTriggerPopup(){return this.container}addHighlightArea(){const t=this.getElementsToTriggerPopup();if(Array.isArray(t))for(const e of t)e.classList.add("highlightArea");else t.classList.add("highlightArea")}_editOnDoubleClick(){if(!this._isEditable)return;const{annotationEditorType:t,data:{id:e}}=this;this.container.addEventListener("dblclick",()=>{this.linkService.eventBus?.dispatch("switchannotationeditormode",{source:this,mode:t,editId:e,mustEnterInEditMode:!0})})}updateOC(t){this.data.oc&&t&&(t.isVisible(this.data.oc)?this.show():this.hide())}get width(){return this.data.rect[2]-this.data.rect[0]}get height(){return this.data.rect[3]-this.data.rect[1]}_setBackgroundColor(t){const e=this.data.backgroundColor||null;t.style.backgroundColor=null===e?"transparent":B.makeHexColor(...e)}},Rs=class extends Bs{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.editor=t.editor}render(){return this.container.className="editorAnnotation",this.container}createOrUpdatePopup(){const{editor:t}=this;t.hasComment&&this._createPopup(t.comment)}get hasCommentButton(){return this.enableComment&&this.editor.hasComment}get commentButtonPosition(){return this.editor.commentButtonPositionInPage}get commentText(){return this.editor.comment.text}set commentText(t){this.editor.comment=t,t||this.removePopup()}get commentData(){return this.editor.getData()}remove(){this.parent.removeAnnotation(this.data.id),this.container.remove(),this.container=null,this.removePopup()}},Os=class extends Bs{constructor(t,e=null){super(t,{isRenderable:!0,ignoreBorder:!!e?.ignoreBorder,createQuadrilaterals:!0}),this.isTooltipOnly=t.data.isTooltipOnly}render(){const{data:t,linkService:e}=this,i=document.createElement("a");i.setAttribute("data-element-id",t.id);let s=!1;return t.url?(e.addLinkAttributes(i,t.url,t.newWindow),s=!0):t.action?(this._bindNamedAction(i,t.action,t.overlaidText),s=!0):t.attachment?(this.#xo(i,t.attachmentId,t.attachment,t.overlaidText,t.attachmentDest),s=!0):t.setOCGState?(this.#Co(i,t.setOCGState,t.overlaidText),s=!0):t.dest?(this._bindLink(i,t.dest,t.overlaidText),s=!0):(t.actions&&(t.actions.has("Action")||t.actions.has("Mouse Up")||t.actions.has("Mouse Down"))&&this.enableScripting&&this.hasJSActions&&(this._bindJSAction(i,t),s=!0),t.resetForm?(this._bindResetFormAction(i,t.resetForm),s=!0):this.isTooltipOnly&&!s&&(this._bindLink(i,""),s=!0)),this.container.classList.add("linkAnnotation"),s&&(this.contentElement=i,this.container.append(i)),this.container}#So(){this.container.setAttribute("data-internal-link","")}_bindLink(t,e,i=""){t.href=this.linkService.getDestinationHash(e),t.onclick=()=>(e&&this.linkService.goToDestination(e),!1),(e||""===e)&&this.#So(),i&&(t.title=i)}_bindNamedAction(t,e,i=""){t.href=this.linkService.getAnchorUrl(""),t.onclick=()=>(this.linkService.executeNamedAction(e),!1),i&&(t.title=i),this.#So()}#xo(t,e,i,s="",n=null){t.href=this.linkService.getAnchorUrl(""),i.description?t.title=i.description:s&&(t.title=s);const r=async()=>{const t=await this.linkService.getAttachmentContent(e);t&&this.downloadManager?.openOrDownloadData(t,i.filename,n)};t.onclick=()=>(r(),!1),this.#So()}#Co(t,e,i=""){t.href=this.linkService.getAnchorUrl(""),t.onclick=()=>(this.linkService.executeSetOCGState(e),!1),i&&(t.title=i),this.#So()}_bindJSAction(t,{actions:e,id:i,overlaidText:s}){t.href=this.linkService.getAnchorUrl("");const n=/* @__PURE__ */new Map([["Action","onclick"],["Mouse Up","onmouseup"],["Mouse Down","onmousedown"]]);for(const r of e.keys()){const e=n.get(r);e&&(t[e]=()=>(this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:i,name:r}}),!1))}s&&(t.title=s),t.onclick||=()=>!1,this.#So()}_bindResetFormAction(t,e){const i=t.onclick;i||(t.href=this.linkService.getAnchorUrl("")),this.#So(),this._fieldObjects?t.onclick=()=>{i?.();const{fields:t,refs:s,include:n}=e,r=[];if(0!==t.length||0!==s.length){const e=new Set(s);for(const s of t){const t=this._fieldObjects.get(s)||[];for(const{id:i}of t)e.add(i)}const i=/* @__PURE__ */new Map;for(const t of this._fieldObjects.values())for(const{id:e,kidIds:s}of t)s&&i.set(e,s);for(const t of e)for(const s of i.get(t)||[])e.add(s);for(const t of this._fieldObjects.values())for(const i of t)e.has(i.id)===n&&r.push(i)}else for(const e of this._fieldObjects.values())r.push(...e);const a=this.annotationStorage,o=[];for(const e of r){const{id:t}=e;switch(o.push(t),e.type){case"text":{const i=e.defaultValue||"";a.setValue(t,{value:i});break}case"checkbox":case"radiobutton":{const i=e.defaultValue===e.exportValues;a.setValue(t,{value:i});break}case"combobox":case"listbox":{const i=e.defaultValue||"";a.setValue(t,{value:i});break}default:continue}const i=document.querySelector(`[data-element-id="${t}"]`);i&&(Is.has(i)?i.dispatchEvent(new Event("resetform")):v())}return this.enableScripting&&this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:"app",ids:o,name:"ResetForm"}}),!1}:i||(t.onclick=()=>!1)}},Ns=class extends Bs{constructor(t){super(t,{isRenderable:!0})}render(){this.container.classList.add("textAnnotation");const t=document.createElement("img");return t.src=this.imageResourcesPath+"annotation-"+this.data.name.toLowerCase()+".svg",t.setAttribute("data-l10n-id","pdfjs-text-annotation-type"),t.setAttribute("data-l10n-args",JSON.stringify({type:this.data.name})),!this.data.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container.append(t),this.container}},zs=class extends Bs{render(){return this.container}_getKeyModifier(t){return L.platform.isMac?t.metaKey:t.ctrlKey}_setEventListener(t,e,i,s,n){i.includes("mouse")?t.addEventListener(i,t=>{this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:this.data.id,name:s,value:n(t),shift:t.shiftKey,modifier:this._getKeyModifier(t)}})}):t.addEventListener(i,t=>{if("blur"===i){if(!e.focused||!t.relatedTarget)return;e.focused=!1}else if("focus"===i){if(e.focused)return;e.focused=!0}n&&this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:this.data.id,name:s,value:n(t)}})})}_setEventListeners(t,e,i,s){const{actions:n}=this.data;for(const[r,a]of i)("Action"===a||n?.has(a))&&("Focus"!==a&&"Blur"!==a||(e||={focused:!1}),this._setEventListener(t,e,r,a,s),"Focus"!==a||n?.has("Blur")?"Blur"!==a||n?.has("Focus")||this._setEventListener(t,e,"focus","Focus",null):this._setEventListener(t,e,"blur","Blur",null))}_setTextStyle(t){const{fontColor:e}=this.data.defaultAppearanceData,i=this.data.defaultAppearanceData.fontSize||9,s=t.style;let n;const r=t=>Math.round(10*t)/10;if(this.data.multiLine){const t=Math.abs(this.data.rect[3]-this.data.rect[1]-2),e=t/(Math.round(t/(1.35*i))||1);n=Math.min(i,r(e/1.35))}else{const t=Math.abs(this.data.rect[3]-this.data.rect[1]-2);n=Math.min(i,r(t/1.35))}s.fontSize=`calc(${n}px * var(--total-scale-factor))`,s.color=B.makeHexColor(...e),null===this.data.textAlignment||this.data.comb||(s.textAlign=["left","center","right"][this.data.textAlignment])}_setRequired(t,e){e?t.setAttribute("required",!0):t.removeAttribute("required"),t.setAttribute("aria-required",e)}},Hs=class extends zs{constructor(t){super(t,{isRenderable:t.renderForms||t.data.hasOwnCanvas||!t.data.hasAppearance&&!!t.data.fieldValue})}setPropertyOnSiblings(t,e,i,s){const n=this.annotationStorage;for(const r of this._getElementsByName(t.name,t.id))r.domElement&&(r.domElement[e]=i),n.setValue(r.id,{[s]:i})}render(){const t=this.annotationStorage,e=this.data.id;this.container.classList.add("textWidgetAnnotation");let i=null;if(this.renderForms){const s=t.getValue(e,{value:this.data.fieldValue});let n=s.value||"";const r=t.getValue(e,{charLimit:this.data.maxLen}).charLimit;r&&n.length>r&&(n=n.slice(0,r));let a=s.formattedValue||this.data.textContent?.join("\n")||null;a&&this.data.comb&&(a=a.replaceAll(/\s+/g,""));const o={userValue:n,formattedValue:a,lastCommittedValue:null,commitKey:1,focused:!1};this.data.multiLine?(i=document.createElement("textarea"),i.textContent=a??n,this.data.doNotScroll&&(i.style.overflowY="hidden")):(i=document.createElement("input"),i.type=this.data.password?"password":"text",i.setAttribute("value",a??n),this.data.doNotScroll&&(i.style.overflowX="hidden")),this.data.hasOwnCanvas&&(this.container.classList.add("hasOwnCanvas"),t.has(e)&&this.container.classList.add("sandboxModified")),Is.add(i),this.contentElement=i,i.setAttribute("data-element-id",e),i.disabled=this.data.readOnly,i.name=this.data.fieldName,i.tabIndex=0;const{datetimeFormat:l,datetimeType:h,timeStep:c}=this.data,d=!!h&&this.enableScripting;l&&(i.title=l),this._setRequired(i,this.data.required),r&&(i.maxLength=r),i.addEventListener("input",s=>{t.setValue(e,{value:s.target.value}),this.setPropertyOnSiblings(i,"value",s.target.value,"value"),o.formattedValue=null}),i.addEventListener("resetform",t=>{const e=this.data.defaultFieldValue??"";i.value=o.userValue=e,o.formattedValue=null});let u=t=>{const{formattedValue:e}=o;null!=e&&(t.target.value=e),t.target.scrollLeft=0};if(this.enableScripting&&this.hasJSActions){i.addEventListener("focus",t=>{if(o.focused)return;const{target:e}=t;if(d&&(e.type=h,c&&(e.step=c)),o.userValue){const t=o.userValue;if(d)if("time"===h){const i=new Date(t);e.value=[i.getHours(),i.getMinutes(),i.getSeconds()].map(t=>t.toString().padStart(2,"0")).join(":")}else e.value=new Date(t-Fs).toISOString().split("date"===h?"T":".",1)[0];else e.value=t}o.lastCommittedValue=e.value,o.commitKey=1,this.data.actions?.has("Focus")||(o.focused=!0)}),i.addEventListener("updatefromsandbox",i=>{this.container.classList.add("sandboxModified"),this._dispatchEventFromSandbox({value(i){o.userValue=i.detail.value??"",d||t.setValue(e,{value:o.userValue.toString()}),i.target.value=o.userValue},formattedValue(i){const{formattedValue:s}=i.detail;o.formattedValue=s,null!=s&&i.target!==document.activeElement&&(i.target.value=s);const n={formattedValue:s};d&&(n.value=s),t.setValue(e,n)},selRange(t){t.target.setSelectionRange(...t.detail.selRange)},charLimit:i=>{const{charLimit:s}=i.detail,{target:n}=i;if(0===s)return void n.removeAttribute("maxLength");n.setAttribute("maxLength",s);let r=o.userValue;!r||r.length<=s||(r=r.slice(0,s),n.value=o.userValue=r,t.setValue(e,{value:r}),this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:r,willCommit:!0,commitKey:1,selStart:n.selectionStart,selEnd:n.selectionEnd}}))}},i)}),i.addEventListener("keydown",t=>{o.commitKey=1;let i=-1;if("Escape"===t.key?i=0:"Enter"!==t.key||this.data.multiLine?"Tab"===t.key&&(o.commitKey=3):i=2,-1===i)return;const{value:s}=t.target;o.lastCommittedValue!==s&&(o.lastCommittedValue=s,o.userValue=s,this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:s,willCommit:!0,commitKey:i,selStart:t.target.selectionStart,selEnd:t.target.selectionEnd}}))});const s=u;u=null,i.addEventListener("blur",t=>{if(!o.focused||!t.relatedTarget)return;this.data.actions?.has("Blur")||(o.focused=!1);const{target:i}=t;let{value:n}=i;if(d){if(n&&"time"===h){const t=n.split(":").map(t=>parseInt(t,10));n=new Date(2e3,0,1,t[0],t[1],t[2]||0).valueOf(),i.step=""}else n.includes("T")||(n=`${n}T00:00`),n=new Date(n).valueOf();i.type="text"}o.userValue=n,o.lastCommittedValue!==n&&this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:n,willCommit:!0,commitKey:o.commitKey,selStart:t.target.selectionStart,selEnd:t.target.selectionEnd}}),s(t)}),this.data.actions?.has("Keystroke")&&i.addEventListener("beforeinput",t=>{o.lastCommittedValue=null;const{data:i,target:s}=t,{value:n,selectionStart:r,selectionEnd:a}=s;let l=r,h=a;switch(t.inputType){case"deleteWordBackward":{const t=/\w/;for(;l>0&&!t.test(n[l-1]);)l--;for(;l>0&&t.test(n[l-1]);)l--;break}case"deleteWordForward":{const t=n.substring(r).match(/^\W*\w*/);t&&(h+=t[0].length);break}case"deleteContentBackward":r===a&&(l-=1);break;case"deleteContentForward":r===a&&(h+=1)}t.preventDefault(),this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:n,change:i||"",willCommit:!1,selStart:l,selEnd:h}})}),this._setEventListeners(i,o,[["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],t=>t.target.value)}if(u&&i.addEventListener("blur",u),this.data.comb){const t=(this.data.rect[2]-this.data.rect[0])/r;i.classList.add("comb"),i.style.setProperty("--comb-width",`calc(${t}px * var(--total-scale-factor))`);const e=this.data.textAlignment;if(1===e||2===e){const t=()=>{const t=r-i.value.length;i.style.setProperty("--comb-offset",`${1===e?t>>1:t}`)};t();for(const e of["input","blur","resetform","updatefromsandbox"])i.addEventListener(e,t)}}}else i=document.createElement("div"),i.textContent=this.data.fieldValue,i.style.verticalAlign="middle",i.style.display="table-cell",this.data.hasOwnCanvas&&(i.hidden=!0);return this._setTextStyle(i),this._setBackgroundColor(i),this._setDefaultPropertiesFromJS(i),this.container.append(i),this.container}},Us=class extends zs{constructor(t){super(t,{isRenderable:!!t.data.hasOwnCanvas})}},Gs=class extends zs{constructor(t){super(t,{isRenderable:t.renderForms})}render(){const t=this.annotationStorage,e=this.data,i=e.id;let s=t.getValue(i,{value:e.exportValue===e.fieldValue}).value;"string"==typeof s&&(s="Off"!==s,t.setValue(i,{value:s})),this.container.classList.add("buttonWidgetAnnotation","checkBox");const n=document.createElement("input");return Is.add(n),n.setAttribute("data-element-id",i),n.disabled=e.readOnly,this._setRequired(n,this.data.required),n.type="checkbox",n.name=e.fieldName,s&&n.setAttribute("checked",!0),n.setAttribute("exportValue",e.exportValue),n.tabIndex=0,n.addEventListener("change",s=>{const{name:n,checked:r}=s.target;for(const a of this._getElementsByName(n,i)){const i=r&&a.exportValue===e.exportValue;a.domElement&&(a.domElement.checked=i),t.setValue(a.id,{value:i})}t.setValue(i,{value:r})}),n.addEventListener("resetform",t=>{const i=e.defaultFieldValue||"Off";t.target.checked=i===e.exportValue}),this.enableScripting&&this.hasJSActions&&(n.addEventListener("updatefromsandbox",e=>{this._dispatchEventFromSandbox({value(e){e.target.checked="Off"!==e.detail.value,t.setValue(i,{value:e.target.checked})}},e)}),this._setEventListeners(n,null,[["change","Validate"],["change","Action"],["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],t=>t.target.checked)),this._setDefaultPropertiesFromJS(n),this.container.append(n),this.container}},Ws=class extends zs{constructor(t){super(t,{isRenderable:t.renderForms})}render(){this.container.classList.add("buttonWidgetAnnotation","radioButton");const t=this.annotationStorage,e=this.data,i=e.id;let s=t.getValue(i,{value:null!==e.buttonValue&&e.fieldValue===e.buttonValue}).value;if("string"==typeof s&&(s=s!==e.buttonValue,t.setValue(i,{value:s})),s)for(const r of this._getElementsByName(e.fieldName,i))t.setValue(r.id,{value:!1});const n=document.createElement("input");if(Is.add(n),n.setAttribute("data-element-id",i),n.disabled=e.readOnly,this._setRequired(n,this.data.required),n.type="radio",n.name=e.fieldName,s&&n.setAttribute("checked",!0),n.tabIndex=0,n.addEventListener("change",e=>{const{name:s,checked:n}=e.target;for(const r of this._getElementsByName(s,i))t.setValue(r.id,{value:!1});t.setValue(i,{value:n})}),n.addEventListener("resetform",t=>{const i=e.defaultFieldValue;t.target.checked=null!=i&&i===e.buttonValue}),this.enableScripting&&this.hasJSActions){const s=e.buttonValue;n.addEventListener("updatefromsandbox",e=>{this._dispatchEventFromSandbox({value:e=>{const n=s===e.detail.value;for(const s of this._getElementsByName(e.target.name)){const e=n&&s.id===i;s.domElement&&(s.domElement.checked=e),t.setValue(s.id,{value:e})}}},e)}),this._setEventListeners(n,null,[["change","Validate"],["change","Action"],["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],t=>t.target.checked)}return this._setDefaultPropertiesFromJS(n),this.container.append(n),this.container}},js=class extends Os{constructor(t){super(t,{ignoreBorder:t.data.hasAppearance})}render(){const t=super.render();t.classList.add("buttonWidgetAnnotation","pushButton");const e=t.lastChild;return this.enableScripting&&this.hasJSActions&&e&&(this._setDefaultPropertiesFromJS(e),e.addEventListener("updatefromsandbox",t=>{this._dispatchEventFromSandbox({},t)})),t}},Vs=class extends zs{constructor(t){super(t,{isRenderable:t.renderForms})}render(){this.container.classList.add("choiceWidgetAnnotation");const t=this.annotationStorage,e=this.data.id,i=t.getValue(e,{value:this.data.fieldValue}),s=document.createElement("select");Is.add(s),s.setAttribute("data-element-id",e),s.disabled=this.data.readOnly,this._setRequired(s,this.data.required),s.name=this.data.fieldName,s.tabIndex=0;let n=this.data.combo&&this.data.options.length>0;this.data.combo||(s.size=this.data.options.length,this.data.multiSelect&&(s.multiple=!0)),s.addEventListener("resetform",t=>{const e=this.data.defaultFieldValue;for(const i of s.options)i.selected=i.value===e});const r=(t,e)=>{const i=e.replaceAll(" "," ");t.textContent=i,i!==e&&t.setAttribute("display-value",e)};for(const c of this.data.options){const t=document.createElement("option");r(t,c.displayValue),t.value=c.exportValue,i.value.includes(c.exportValue)&&(t.setAttribute("selected",!0),n=!1),s.append(t)}let a=null;if(n){const t=document.createElement("option");t.value=" ",t.setAttribute("hidden",!0),t.setAttribute("selected",!0),s.prepend(t),a=()=>{t.remove(),s.removeEventListener("input",a),a=null},s.addEventListener("input",a)}const o=t=>{const e=t?"value":"textContent",{options:i,multiple:n}=s;return n?Array.prototype.filter.call(i,t=>t.selected).map(t=>t[e]):-1===i.selectedIndex?null:i[i.selectedIndex][e]};let l=o(!1);const h=t=>{const e=t.target.options;return Array.prototype.map.call(e,t=>({displayValue:t.getAttribute("display-value")||t.textContent,exportValue:t.value}))};return this.enableScripting&&this.hasJSActions?(s.addEventListener("updatefromsandbox",i=>{this._dispatchEventFromSandbox({value(i){a?.();const n=i.detail.value,r=new Set(Array.isArray(n)?n:[n]);for(const t of s.options)t.selected=r.has(t.value);t.setValue(e,{value:o(!0)}),l=o(!1)},multipleSelection(t){s.multiple=!0},remove(i){const n=s.options,r=i.detail.remove;n[r].selected=!1,s.remove(r),n.length>0&&-1===Array.prototype.findIndex.call(n,t=>t.selected)&&(n[0].selected=!0),t.setValue(e,{value:o(!0),items:h(i)}),l=o(!1)},clear(i){for(;0!==s.length;)s.remove(0);t.setValue(e,{value:null,items:[]}),l=o(!1)},insert(i){const{index:n,displayValue:a,exportValue:c}=i.detail.insert,d=s.children[n],u=document.createElement("option");r(u,a),u.value=c,d?d.before(u):s.append(u),t.setValue(e,{value:o(!0),items:h(i)}),l=o(!1)},items(i){const{items:n}=i.detail;for(;0!==s.length;)s.remove(0);for(const t of n){const{displayValue:e,exportValue:i}=t,n=document.createElement("option");r(n,e),n.value=i,s.append(n)}s.options.length>0&&(s.options[0].selected=!0),t.setValue(e,{value:o(!0),items:h(i)}),l=o(!1)},indices(i){const s=new Set(i.detail.indices);for(const t of i.target.options)t.selected=s.has(t.index);t.setValue(e,{value:o(!0)}),l=o(!1)},editable(t){t.target.disabled=!t.detail.editable}},i)}),s.addEventListener("input",i=>{const s=o(!0),n=o(!1);t.setValue(e,{value:s}),i.preventDefault(),this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:l,change:n,changeEx:s,willCommit:!1,commitKey:1,keyDown:!1}})}),this._setEventListeners(s,null,[["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"],["input","Action"],["input","Validate"]],t=>t.target.value)):s.addEventListener("input",function(i){t.setValue(e,{value:o(!0)})}),this.data.combo&&this._setTextStyle(s),this._setBackgroundColor(s),this._setDefaultPropertiesFromJS(s),this.container.append(s),this.container}},$s=class extends Bs{constructor(t){const{data:e,elements:i,parent:s}=t,n=!!s._commentManager;if(super(t,{isRenderable:!n&&Bs._hasPopupData(e)}),this.elements=i,n&&Bs._hasPopupData(e)){const t=this.popup=this.#To();for(const e of i)e.popup=t}else this.popup=null}#To(){return new Xs({container:this.container,color:this.data.color,titleObj:this.data.titleObj,modificationDate:this.data.modificationDate||this.data.creationDate,contentsObj:this.data.contentsObj,richText:this.data.richText,rect:this.data.rect,parentRect:this.data.parentRect||null,parent:this.parent,elements:this.elements,open:this.data.open,commentManager:this.parent._commentManager})}render(){const{container:t}=this;t.classList.add("popupAnnotation"),t.role="comment";const e=this.popup=this.#To(),i=[];for(const s of this.elements)s.popup=e,s.container.ariaHasPopup="dialog",i.push(s.data.id),s.addHighlightArea();return this.container.setAttribute("aria-controls",i.map(t=>`${a}${t}`).join(",")),this.container}},Xs=class{#X=null;#_o=this.#uo.bind(this);#ko=this.#Eo.bind(this);#Mo=this.#Po.bind(this);#Do=this.#Io.bind(this);#Fo=null;#Mt=null;#Lo=null;#Bo=null;#Ro=null;#Oo=null;#No=null;#zo=!1;#Ho=null;#Uo=null;#F=null;#Go=null;#Wo=null;#Ae=null;#jo=null;#be=null;#Vo=null;#yo=null;#$o=!1;#Xo=null;#Ko=null;constructor({container:t,color:e,elements:i,titleObj:s,modificationDate:n,contentsObj:r,richText:a,parent:o,rect:l,parentRect:h,open:c,commentManager:d=null}){this.#Mt=t,this.#Vo=s,this.#Lo=r,this.#be=a,this.#Oo=o,this.#Fo=e,this.#jo=l,this.#No=h,this.#Ro=i,this.#X=d,this.#Xo=i[0],this.#Bo=vt.toDateObject(n),this.trigger=i.flatMap(t=>t.getElementsToTriggerPopup()),d||(this.#Yo(),this.#Mt.hidden=!0,c&&this.#Io())}#Yo(){if(this.#Uo)return;this.#Uo=new AbortController;const{signal:t}=this.#Uo;for(const e of this.trigger)e.addEventListener("click",this.#Do,{signal:t}),e.addEventListener("pointerenter",this.#Mo,{signal:t}),e.addEventListener("pointerleave",this.#ko,{signal:t}),e.classList.add("popupTriggerArea");for(const e of this.#Ro)e.container?.addEventListener("keydown",this.#_o,{signal:t})}#qo(){const t=this.#Ro.find(t=>t.hasCommentButton);t&&(this.#Wo=t._normalizePoint(t.commentButtonPosition))}renderCommentButton(){if(this.#Go)return void(this.#Go.parentNode||this.#Xo.container.after(this.#Go));if(this.#Wo||this.#qo(),!this.#Wo)return;const{signal:t}=this.#Uo=new AbortController,e=this.#Xo.hasOwnCommentButton,i=()=>{this.#X.toggleCommentPopup(this,!0,void 0,!e)},s=()=>{this.#X.toggleCommentPopup(this,!1,!0,!e)},n=()=>{this.#X.toggleCommentPopup(this,!1,!1)};if(e){this.#Go=this.#Xo.container;for(const e of this.trigger)e.ariaHasPopup="dialog",e.ariaControls="commentPopup",e.addEventListener("keydown",this.#_o,{signal:t}),e.addEventListener("click",i,{signal:t}),e.addEventListener("pointerenter",s,{signal:t}),e.addEventListener("pointerleave",n,{signal:t}),e.classList.add("popupTriggerArea")}else{const e=this.#Go=document.createElement("button");e.className="annotationCommentButton";const r=this.#Xo.container;e.style.zIndex=parseInt(r.style.zIndex,10)+1,e.tabIndex=0,e.ariaHasPopup="dialog",e.ariaControls="commentPopup",e.setAttribute("data-l10n-id","pdfjs-show-comment-button"),this.#Qo(),this.#Jo(),e.addEventListener("keydown",this.#_o,{signal:t}),e.addEventListener("click",i,{signal:t}),e.addEventListener("pointerenter",s,{signal:t}),e.addEventListener("pointerleave",n,{signal:t}),r.after(e)}}#Jo(){if(this.#Xo.extraPopupElement&&!this.#Xo.editor)return;this.#Go||this.renderCommentButton();const[t,e]=this.#Wo,{style:i}=this.#Go;i.left=`calc(${t}%)`,i.top=`calc(${e}% - var(--comment-button-dim))`}#Qo(){this.#Xo.extraPopupElement||(this.#Go||this.renderCommentButton(),this.#Go.style.backgroundColor=this.commentButtonColor||"")}get commentButtonColor(){const{color:t,opacity:e}=this.#Xo.commentData;return t?this.#Oo._commentManager.makeCommentColor(t,e):null}focusCommentButton(){setTimeout(()=>{this.#Go?.focus()},0)}getData(){const{richText:t,color:e,opacity:i,creationDate:s,modificationDate:n}=this.#Xo.commentData;return{contentsObj:{str:this.comment},richText:t,color:e,opacity:i,creationDate:s,modificationDate:n}}get elementBeforePopup(){return this.#Go}get comment(){return this.#Ko||=this.#Xo.commentText,this.#Ko}set comment(t){t!==this.comment&&(this.#Xo.commentText=this.#Ko=t)}focus(){this.#Xo.container?.focus()}get parentBoundingClientRect(){return this.#Xo.layer.getBoundingClientRect()}setCommentButtonStates({selected:t,hasPopup:e}){this.#Go&&(this.#Go.classList.toggle("selected",t),this.#Go.ariaExpanded=e)}setSelectedCommentButton(t){this.#Go.classList.toggle("selected",t)}get commentPopupPosition(){if(this.#Ae)return this.#Ae;const{x:t,y:e,height:i}=this.#Go.getBoundingClientRect(),{x:s,y:n,width:r,height:a}=this.#Xo.layer.getBoundingClientRect();return[(t-s)/r,(e+i-n)/a]}set commentPopupPosition(t){this.#Ae=t}hasDefaultPopupPosition(){return null===this.#Ae}get commentButtonPosition(){return this.#Wo}get commentButtonWidth(){return this.#Go.getBoundingClientRect().width/this.parentBoundingClientRect.width}editComment(t){const[e,i]=this.#Ae||this.commentButtonPosition.map(t=>t/100),s=this.parentBoundingClientRect,{x:n,y:r,width:a,height:o}=s;this.#X.showDialog(null,this,n+e*a,r+i*o,{...t,parentDimensions:s})}render(){if(this.#Ho)return;const t=this.#Ho=document.createElement("div");if(t.className="popup",this.#Fo){const e=t.style.outlineColor=B.makeHexColor(...this.#Fo);t.style.backgroundColor=`color-mix(in srgb, ${e} 30%, white)`}const e=document.createElement("span");if(e.className="header",this.#Vo?.str){const t=document.createElement("span");t.className="title",e.append(t),({dir:t.dir,str:t.textContent}=this.#Vo)}if(t.append(e),this.#Bo){const t=document.createElement("time");t.className="popupDate",t.setAttribute("data-l10n-id","pdfjs-annotation-date-time-string"),t.setAttribute("data-l10n-args",JSON.stringify({dateObj:this.#Bo.valueOf()})),t.dateTime=this.#Bo.toISOString(),e.append(t)}St({html:this.#Zo||this.#Lo.str,dir:this.#Lo?.dir,className:"popupContent"},t),this.#Mt.append(t)}get#Zo(){const t=this.#be,e=this.#Lo;return!t?.str||e?.str&&e.str!==t.str?null:this.#be.html||null}get#tl(){return this.#Zo?.attributes?.style?.fontSize||0}get#el(){return this.#Zo?.attributes?.style?.color||null}#il(t){const e=[],i={str:t,html:{name:"div",attributes:{dir:"auto"},children:[{name:"p",children:e}]}},s={style:{color:this.#el,fontSize:this.#tl?`calc(${this.#tl}px * var(--total-scale-factor))`:""}};for(const n of t.split("\n"))e.push({name:"span",value:n,attributes:s});return i}#uo(t){t.altKey||t.shiftKey||t.ctrlKey||t.metaKey||("Enter"===t.key||"Escape"===t.key&&this.#zo)&&this.#Io()}updateEdited({rect:t,popup:e,deleted:i}){if(this.#X)return i?(this.remove(),this.#Ko=null):e&&(e.deleted?this.remove():(this.#Qo(),this.#Ko=e.text)),void(t&&(this.#Wo=null,this.#qo(),this.#Jo()));i||e?.deleted?this.remove():(this.#Yo(),this.#yo||={contentsObj:this.#Lo,richText:this.#be},t&&(this.#F=null),e&&e.text&&(this.#be=this.#il(e.text),this.#Bo=vt.toDateObject(e.date),this.#Lo=null),this.#Ho?.remove(),this.#Ho=null)}resetEdited(){this.#yo&&(({contentsObj:this.#Lo,richText:this.#be}=this.#yo),this.#yo=null,this.#Ho?.remove(),this.#Ho=null,this.#F=null)}remove(){if(this.#Uo?.abort(),this.#Uo=null,this.#Ho?.remove(),this.#Ho=null,this.#$o=!1,this.#zo=!1,this.#Go?.remove(),this.#Go=null,this.trigger)for(const t of this.trigger)t.classList.remove("popupTriggerArea")}#sl(){if(null!==this.#F)return;const{page:{view:t},viewport:{rawDims:{pageWidth:e,pageHeight:i,pageX:s,pageY:n}}}=this.#Oo;let r=!!this.#No,a=r?this.#No:this.#jo;for(const u of this.#Ro)if(!a||null!==B.intersect(u.data.rect,a)){a=u.data.rect,r=!0;break}const o=B.normalizeRect([a[0],t[3]-a[1]+t[1],a[2],t[3]-a[3]+t[1]]),l=r?a[2]-a[0]+5:0,h=o[0]+l,c=o[1];this.#F=[100*(h-s)/e,100*(c-n)/i];const{style:d}=this.#Mt;d.left=`${this.#F[0]}%`,d.top=`${this.#F[1]}%`}#Io(){this.#X?this.#X.toggleCommentPopup(this,!1):(this.#zo=!this.#zo,this.#zo?(this.#Po(),this.#Mt.addEventListener("click",this.#Do),this.#Mt.addEventListener("keydown",this.#_o)):(this.#Eo(),this.#Mt.removeEventListener("click",this.#Do),this.#Mt.removeEventListener("keydown",this.#_o)))}#Po(){this.#Ho||this.render(),this.isVisible?this.#zo&&this.#Mt.classList.add("focused"):(this.#sl(),this.#Mt.hidden=!1,this.#Mt.style.zIndex=parseInt(this.#Mt.style.zIndex,10)+1e3)}#Eo(){this.#Mt.classList.remove("focused"),!this.#zo&&this.isVisible&&(this.#Mt.hidden=!0,this.#Mt.style.zIndex=parseInt(this.#Mt.style.zIndex,10)-1e3)}forceHide(){this.#$o=this.isVisible,this.#$o&&(this.#Mt.hidden=!0)}maybeShow(){this.#X||(this.#Yo(),this.#$o&&(this.#Ho||this.#Po(),this.#$o=!1,this.#Mt.hidden=!1))}get isVisible(){return!this.#X&&!1===this.#Mt.hidden}},Ks=class extends Bs{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.textContent=t.data.textContent,this.textPosition=t.data.textPosition,this.annotationEditorType=l.FREETEXT}render(){if(this.container.classList.add("freeTextAnnotation"),this.textContent){const t=this.contentElement=document.createElement("div");t.classList.add("annotationTextContent"),t.setAttribute("role","comment");for(const e of this.textContent){const i=document.createElement("span");i.textContent=e,t.append(i)}this.container.append(t)}return!this.data.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this._editOnDoubleClick(),this.container}},Ys=class extends Bs{#nl=null;constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){this.container.classList.add("lineAnnotation");const{data:t,width:e,height:i}=this,s=Bs._svgFactory,n=s.create(e,i,!0),r=this.#nl=s.createElement("svg:line");return r.setAttribute("x1",t.rect[2]-t.lineCoordinates[0]),r.setAttribute("y1",t.rect[3]-t.lineCoordinates[1]),r.setAttribute("x2",t.rect[2]-t.lineCoordinates[2]),r.setAttribute("y2",t.rect[3]-t.lineCoordinates[3]),r.setAttribute("stroke-width",t.borderStyle.width||1),r.setAttribute("stroke","transparent"),r.setAttribute("fill","transparent"),n.append(r),this.container.append(n),!t.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container}getElementsToTriggerPopup(){return this.#nl}addHighlightArea(){this.container.classList.add("highlightArea")}},qs=class extends Bs{#rl=null;constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){this.container.classList.add("squareAnnotation");const{data:t,width:e,height:i}=this,s=Bs._svgFactory,n=s.create(e,i,!0),r=t.borderStyle.width,a=this.#rl=s.createElement("svg:rect");return a.setAttribute("x",r/2),a.setAttribute("y",r/2),a.setAttribute("width",e-r),a.setAttribute("height",i-r),a.setAttribute("stroke-width",r||1),a.setAttribute("stroke","transparent"),a.setAttribute("fill","transparent"),n.append(a),this.container.append(n),!t.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container}getElementsToTriggerPopup(){return this.#rl}addHighlightArea(){this.container.classList.add("highlightArea")}},Qs=class extends Bs{#al=null;constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){this.container.classList.add("circleAnnotation");const{data:t,width:e,height:i}=this,s=Bs._svgFactory,n=s.create(e,i,!0),r=t.borderStyle.width,a=this.#al=s.createElement("svg:ellipse");return a.setAttribute("cx",e/2),a.setAttribute("cy",i/2),a.setAttribute("rx",e/2-r/2),a.setAttribute("ry",i/2-r/2),a.setAttribute("stroke-width",r||1),a.setAttribute("stroke","transparent"),a.setAttribute("fill","transparent"),n.append(a),this.container.append(n),!t.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container}getElementsToTriggerPopup(){return this.#al}addHighlightArea(){this.container.classList.add("highlightArea")}},Js=class extends Bs{#ol=null;constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.containerClassName="polylineAnnotation",this.svgElementName="svg:polyline"}render(){this.container.classList.add(this.containerClassName);const{data:{rect:t,vertices:e,borderStyle:i,popupRef:s},width:n,height:r}=this;if(!e)return this.container;const a=Bs._svgFactory,o=a.create(n,r,!0);let l=[];for(let c=0,d=e.length;c<d;c+=2){const i=e[c]-t[0],s=t[3]-e[c+1];l.push(`${i},${s}`)}l=l.join(" ");const h=this.#ol=a.createElement(this.svgElementName);return h.setAttribute("points",l),h.setAttribute("stroke-width",i.width||1),h.setAttribute("stroke","transparent"),h.setAttribute("fill","transparent"),o.append(h),this.container.append(o),!s&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container}getElementsToTriggerPopup(){return this.#ol}addHighlightArea(){this.container.classList.add("highlightArea")}},Zs=class extends Js{constructor(t){super(t),this.containerClassName="polygonAnnotation",this.svgElementName="svg:polygon"}},tn=class extends Bs{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){return this.container.classList.add("caretAnnotation"),!this.data.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container}},en=class extends Bs{#ll=null;#hl=[];constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.containerClassName="inkAnnotation",this.svgElementName="svg:polyline",this.annotationEditorType="InkHighlight"===this.data.it?l.HIGHLIGHT:l.INK}#cl(t,e){switch(t){case 90:return{transform:`rotate(90) translate(${-e[0]},${e[1]}) scale(1,-1)`,width:e[3]-e[1],height:e[2]-e[0]};case 180:return{transform:`rotate(180) translate(${-e[2]},${e[1]}) scale(1,-1)`,width:e[2]-e[0],height:e[3]-e[1]};case 270:return{transform:`rotate(270) translate(${-e[2]},${e[3]}) scale(1,-1)`,width:e[3]-e[1],height:e[2]-e[0]};default:return{transform:`translate(${-e[0]},${e[3]}) scale(1,-1)`,width:e[2]-e[0],height:e[3]-e[1]}}}render(){this.container.classList.add(this.containerClassName);const{data:{rect:t,rotation:e,inkLists:i,borderStyle:s,popupRef:n}}=this,{transform:r,width:a,height:o}=this.#cl(e,t),l=Bs._svgFactory,h=l.create(a,o,!0),c=this.#ll=l.createElement("svg:g");h.append(c),c.setAttribute("stroke-width",s.width||1),c.setAttribute("stroke-linecap","round"),c.setAttribute("stroke-linejoin","round"),c.setAttribute("stroke-miterlimit",10),c.setAttribute("stroke","transparent"),c.setAttribute("fill","transparent"),c.setAttribute("transform",r);for(const d of i){const t=l.createElement(this.svgElementName);this.#hl.push(t),t.setAttribute("points",d.join(",")),c.append(t)}return!n&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container.append(h),this._editOnDoubleClick(),this.container}updateEdited(t){super.updateEdited(t);const{thickness:e,points:i,rect:s}=t,n=this.#ll;if(e>=0&&n.setAttribute("stroke-width",e||1),i)for(let r=0,a=this.#hl.length;r<a;r++)this.#hl[r].setAttribute("points",i[r].join(","));if(s){const{transform:t,width:e,height:i}=this.#cl(this.data.rotation,s);n.parentElement.setAttribute("viewBox",`0 0 ${e} ${i}`),n.setAttribute("transform",t)}}getElementsToTriggerPopup(){return this.#hl}addHighlightArea(){this.container.classList.add("highlightArea")}},sn=class extends Bs{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0}),this.annotationEditorType=l.HIGHLIGHT}render(){const{data:{overlaidText:t,popupRef:e}}=this;if(!e&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container.classList.add("highlightAnnotation"),this._editOnDoubleClick(),t){const e=document.createElement("mark");e.classList.add("overlaidText"),e.textContent=t,this.container.append(e)}return this.container}},nn=class extends Bs{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){const{data:{overlaidText:t,popupRef:e}}=this;if(!e&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container.classList.add("underlineAnnotation"),t){const e=document.createElement("u");e.classList.add("overlaidText"),e.textContent=t,this.container.append(e)}return this.container}},rn=class extends Bs{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){const{data:{overlaidText:t,popupRef:e}}=this;if(!e&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container.classList.add("squigglyAnnotation"),t){const e=document.createElement("u");e.classList.add("overlaidText"),e.textContent=t,this.container.append(e)}return this.container}},an=class extends Bs{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){const{data:{overlaidText:t,popupRef:e}}=this;if(!e&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container.classList.add("strikeoutAnnotation"),t){const e=document.createElement("s");e.classList.add("overlaidText"),e.textContent=t,this.container.append(e)}return this.container}},on=class extends Bs{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.annotationEditorType=l.STAMP}render(){return this.container.classList.add("stampAnnotation"),this.container.setAttribute("role","img"),!this.data.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this._editOnDoubleClick(),this.container}},ln=class extends Bs{#dl=null;constructor(t){super(t,{isRenderable:!0});const{fileId:e,file:i}=this.data;this.filename=i.filename,this.content=i.content,this.fileId=e,this.linkService.eventBus?.dispatch("fileattachmentannotation",{source:this,attachmentId:this.fileId,...i})}render(){this.container.classList.add("fileAttachmentAnnotation");const{container:t,data:e}=this;let i;e.hasAppearance||0===e.fillAlpha?i=document.createElement("div"):(i=document.createElement("img"),i.src=`${this.imageResourcesPath}annotation-${/paperclip/i.test(e.name)?"paperclip":"pushpin"}.svg`,e.fillAlpha&&e.fillAlpha<1&&(i.style=`filter: opacity(${Math.round(100*e.fillAlpha)}%);`)),i.addEventListener("dblclick",this.#ul.bind(this)),this.#dl=i;const{isMac:s}=L.platform;return t.addEventListener("keydown",t=>{"Enter"===t.key&&(s?t.metaKey:t.ctrlKey)&&this.#ul()}),!e.popupRef&&this.hasPopupData?(this.hasOwnCommentButton=!0,this._createPopup()):i.classList.add("popupTriggerArea"),t.append(i),t}getElementsToTriggerPopup(){return this.#dl}addHighlightArea(){this.container.classList.add("highlightArea")}async#ul(){const{fileId:t,filename:e,content:i}=this,s=await this.linkService.getAttachmentContent(t)||i;s&&this.downloadManager?.openOrDownloadData(s,e)}},hn=class extends Bs{#R=new AbortController;#pl=null;#gl=null;constructor(t){super(t,{isRenderable:!!t.data.richMedia})}render(){this.container.classList.add("mediaAnnotation");const{filename:t}=this.data.richMedia,e=document.createElement("button");return e.className="mediaPlayButton",e.type="button",e.title=e.ariaLabel=t,e.addEventListener("click",()=>this.#ml(e),{signal:this.#R.signal}),this.container.append(e),this.container}async#ml(t){const{fileId:e,filename:i,contentType:s}=this.data.richMedia;let n;t.disabled=!0;try{n=await this.linkService.getAttachmentContent(e)}catch{return}finally{t.disabled=!1}if(!n||!t.isConnected)return;const{signal:r}=this.#R,a=new Blob([n],{type:s});if(!/^(?:video|audio)\//.test(a.type))return;const o=URL.createObjectURL(a);this.#pl=o;const l=a.type.startsWith("audio/"),h=document.createElement(l?"audio":"video");if(this.#gl=h,h.className="mediaContent",this._setBackgroundColor(h),h.src=o,h.title=i,h.controls=!0,h.autoplay=!0,h.tabIndex=0,l){let t=!1,e=!1;const i=()=>{h.controls=t||e};this.container.addEventListener("pointerenter",()=>{t=!0,i()},{signal:r}),this.container.addEventListener("pointerleave",()=>{t=!1,i()},{signal:r}),this.container.addEventListener("focusin",()=>{e=!0,i()},{signal:r}),this.container.addEventListener("focusout",()=>{e=!1,i()},{signal:r})}h.addEventListener("emptied",()=>this.#fl(o),{once:!0,signal:r}),t.replaceWith(h),h.play().catch(()=>{})}#fl(t=this.#pl){t&&t===this.#pl&&(URL.revokeObjectURL(t),this.#pl=null)}destroy(){this.#R.abort(),this.#gl&&(this.#gl.pause(),this.#gl.removeAttribute("src"),this.#gl.load(),this.#gl=null),this.#fl()}},cn=class t{#bl=null;#Cr=null;#j=null;#yl=/* @__PURE__ */new Map;#vl=null;#wl=null;#Ro=[];#Al=!1;zIndex=0;constructor({div:t,accessibilityManager:e,annotationCanvasMap:i,annotationEditorUIManager:s,page:n,viewport:r,structTreeLayer:a,commentManager:o,linkService:l,annotationStorage:h}){this.div=t,this.#bl=e,this.#Cr=i,this.#vl=a||null,this.#wl=l||null,this.#j=h||new Yt,this.page=n,this.viewport=r,this._annotationEditorUIManager=s,this._commentManager=o||null}hasEditableAnnotations(){return this.#yl.size>0}async render(t){const{annotations:e,optionalContentConfig:i}=t,s=this.div;wt(s,this.viewport);const n=/* @__PURE__ */new Map,r=[],o={data:null,layer:s,linkService:this.#wl,downloadManager:t.downloadManager,imageResourcesPath:t.imageResourcesPath||"",renderForms:!1!==t.renderForms,annotationStorage:this.#j,enableComment:!0===t.enableComment,enableAnnotationEditing:!1!==t.enableAnnotationEditing,enableScripting:!0===t.enableScripting,hasJSActions:t.hasJSActions,fieldObjects:t.fieldObjects,parent:this,elements:null};for(const a of e){if(a.noHTML)continue;const t=a.annotationType===u.POPUP;if(t){const t=n.get(a.id);if(!t)continue;if(!this._commentManager){r.push(a);continue}o.elements=t}else if(a.rect[2]===a.rect[0]||a.rect[3]===a.rect[1])continue;o.data=a;const e=Ls.create(o);if(!e.isRenderable)continue;t||(this.#Ro.push(e),a.popupRef&&n.getOrInsertComputed(a.popupRef,H).push(e));const s=e.render();a.hidden&&(s.style.visibility="hidden"),e.updateOC(i),e._isEditable&&(this.#yl.set(e.data.id,e),this._annotationEditorUIManager?.renderAnnotationElement(e))}await this.#xl();for(const l of r){const t=o.elements=n.get(l.id);o.data=l;const e=Ls.create(o);if(!e.isRenderable)continue;const i=e.render();e.contentElement.id=`${a}${l.id}`,l.hidden&&(i.style.visibility="hidden"),t.at(-1).container.after(i)}this.#Cl()}async#xl(){if(0===this.#Ro.length)return;this.div.replaceChildren();const t=[];if(!this.#Al){this.#Al=!0;for(const{contentElement:e,data:{hidden:i,id:s,oc:n}}of this.#Ro){const r=e.id=`${a}${s}`,o="a"===e.localName&&!i&&!n;t.push(this.#vl?.getAriaAttributes(r,{enableLinkOwnership:o}).then(t=>{if(t)for(const[i,s]of t)e.setAttribute(i,s)}))}}this.#Ro.sort(({data:{rect:[t,e,i,s]}},{data:{rect:[n,r,a,o]}})=>{if(t===i&&e===s)return 1;if(n===a&&r===o)return-1;const l=(e+s)/2,h=(r+o)/2;return l>=o&&h<=e?-1:h>=s&&l<=r?1:(t+i)/2-(n+a)/2});const e=document.createDocumentFragment();for(const i of this.#Ro)e.append(i.container),this._commentManager?(i.extraPopupElement?.popup||i.popup)?.renderCommentButton():i.extraPopupElement&&e.append(i.extraPopupElement.render());if(this.div.append(e),await Promise.all(t),this.#bl){const t=await(this.#vl?.getAnnotationIds());for(const{contentElement:e}of this.#Ro)t?.has(e.id)||this.#bl.addPointerInTextLayer(e,!1)}}async addLinkAnnotations(e){const i={data:null,layer:this.div,linkService:this.#wl,parent:this};for(const s of e){s.borderStyle||=t._defaultBorderStyle,i.data=s;const e=Ls.create(i);e.isRenderable&&(e.render(),e.contentElement.id=`${a}${s.id}`,this.#Ro.push(e))}await this.#xl()}update({viewport:t,optionalContentConfig:e}){const i=this.div;this.viewport=t,wt(i,{rotation:t.rotation});for(const s of this.#Ro)s.updateOC(e);this.#Cl(),i.hidden=!1}destroy(){for(const t of this.#Ro)t.destroy?.(),this.#bl?.removePointerInTextLayer(t.contentElement);this.#Ro.length=0,this.#yl.clear(),this.div.replaceChildren()}#Cl(){if(!this.#Cr)return;const t=this.div;for(const[e,i]of this.#Cr){const s=t.querySelector(`[data-annotation-id="${e}"]`);if(!s)continue;if(Array.isArray(i))for(const t of i)t.className="annotationContent",t.ariaHidden=!0;else i.className="annotationContent",i.ariaHidden=!0;const n=[];for(const t of s.children)"CANVAS"===t.nodeName&&n.push(t);for(const t of n)t.remove();const r=Array.isArray(i)?i[0]:i,{firstChild:a}=s;if(a?a.classList.contains("annotationContent")?a.after(r):a.before(r):s.append(r),Array.isArray(i)){let t=r;for(let e=1,s=i.length;e<s;e++)t.after(i[e]),t=i[e]}this.#Cr.delete(e);const o=this.#yl.get(e);o&&(o._hasNoCanvas?(this._annotationEditorUIManager?.setMissingCanvas(e,s.id,i),o._hasNoCanvas=!1):o.canvas=i)}}refreshCanvases(){this.#Cl()}getEditableAnnotations(){return this.#yl.values()}getEditableAnnotation(t){return this.#yl.get(t)}addFakeAnnotation(t){const{div:e}=this,{id:i,rotation:s}=t,n=new Rs({data:{id:i,rect:t.getPDFRect(),rotation:s},editor:t,layer:e,parent:this,enableComment:!!this._commentManager,linkService:this.#wl,annotationStorage:this.#j});return n.render(),n.contentElement.id=`${a}${i}`,n.createOrUpdatePopup(),this.#Ro.push(n),n}removeAnnotation(t){const e=this.#Ro.findIndex(e=>e.data.id===t);if(e<0)return;const[i]=this.#Ro.splice(e,1);this.#bl?.removePointerInTextLayer(i.contentElement)}updateFakeAnnotations(t){if(0!==t.length){for(const e of t)e.updateFakeAnnotationElement(this);this.#xl()}}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}static get _defaultBorderStyle(){return T(this,"_defaultBorderStyle",Object.freeze({width:1,rawWidth:1,style:1,dashArray:[3],horizontalCornerRadius:0,verticalCornerRadius:0}))}},dn=/\r\n?|\n/g,un=class t extends Gt{#Sl="";#Tl=`${this.id}-editor`;#_l=null;#tl;_colorPicker=null;static _freeTextDefaultContent="";static _internalPadding=0;static _defaultColor=null;static _defaultFontSize=10;static get _keyboardManager(){const e=t.prototype,i=t=>t.isEmpty(),s=Bt.TRANSLATE_SMALL,n=Bt.TRANSLATE_BIG;return T(this,"_keyboardManager",new Ft([[["ctrl+s","mac+meta+s","ctrl+p","mac+meta+p"],e.commitOrRemove,{bubbles:!0}],[["ctrl+Enter","mac+meta+Enter"],e.commitOrRemove],[["Escape"],e.commitOrRemove],[["ArrowLeft"],e._translateEmpty,{args:[-s,0],checker:i}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],e._translateEmpty,{args:[-n,0],checker:i}],[["ArrowRight"],e._translateEmpty,{args:[s,0],checker:i}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],e._translateEmpty,{args:[n,0],checker:i}],[["ArrowUp"],e._translateEmpty,{args:[0,-s],checker:i}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],e._translateEmpty,{args:[0,-n],checker:i}],[["ArrowDown"],e._translateEmpty,{args:[0,s],checker:i}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],e._translateEmpty,{args:[0,n],checker:i}]]))}static _type="freetext";static _editorType=l.FREETEXT;constructor(e){super({...e,name:"freeTextEditor"}),this.color=e.color||t._defaultColor||Gt._defaultLineColor,this.#tl=e.fontSize||t._defaultFontSize,this.annotationElementId||this._uiManager.a11yAlert(Gt._l10nAlert.freetext),this.canAddComment=!1}static initialize(t,e){Gt.initialize(t,e);const i=getComputedStyle(document.documentElement);this._internalPadding=parseFloat(i.getPropertyValue("--freetext-padding"))}static updateDefaultParams(e,i){switch(e){case h.FREETEXT_SIZE:t._defaultFontSize=i;break;case h.FREETEXT_COLOR:t._defaultColor=i}}updateParams(t,e){switch(t){case h.FREETEXT_SIZE:this.#kl(e);break;case h.FREETEXT_COLOR:this.#Qo(e)}}static get defaultPropertiesToUpdate(){return[[h.FREETEXT_SIZE,t._defaultFontSize],[h.FREETEXT_COLOR,t._defaultColor||Gt._defaultLineColor]]}get propertiesToUpdate(){return[[h.FREETEXT_SIZE,this.#tl],[h.FREETEXT_COLOR,this.color]]}get toolbarButtons(){return this._colorPicker||=new _s(this),[["colorPicker",this._colorPicker]]}get colorType(){return h.FREETEXT_COLOR}#kl(t){const e=t=>{this.editorDiv.style.fontSize=`calc(${t}px * var(--total-scale-factor))`,this.translate(0,-(t-this.#tl)*this.parentScale),this.#tl=t,this.#El()},i=this.#tl;this.addCommands({cmd:e.bind(this,t),undo:e.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:h.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})}onUpdatedColor(){this.editorDiv.style.color=this.color,this._colorPicker?.update(this.color),super.onUpdatedColor()}#Qo(t){const e=t=>{this.color=t,this.onUpdatedColor()},i=this.color;this.addCommands({cmd:e.bind(this,t),undo:e.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:h.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})}_translateEmpty(t,e){this._uiManager.translateSelectedEditors(t,e,!0)}getInitialTranslation(){const e=this.parentScale;return[-t._internalPadding*e,-(t._internalPadding+this.#tl)*e]}rebuild(){this.parent&&(super.rebuild(),null!==this.div&&(this.isAttachedToDOM||this.parent.add(this)))}enableEditMode(){if(!super.enableEditMode())return!1;this.overlayDiv.classList.remove("enabled"),this.editorDiv.contentEditable=!0,this._isDraggable=!1,this.div.removeAttribute("aria-activedescendant"),this.#_l=new AbortController;const t=this._uiManager.combinedSignal(this.#_l);return this.editorDiv.addEventListener("keydown",this.editorDivKeydown.bind(this),{signal:t}),this.editorDiv.addEventListener("focus",this.editorDivFocus.bind(this),{signal:t}),this.editorDiv.addEventListener("blur",this.editorDivBlur.bind(this),{signal:t}),this.editorDiv.addEventListener("input",this.editorDivInput.bind(this),{signal:t}),this.editorDiv.addEventListener("paste",this.editorDivPaste.bind(this),{signal:t}),!0}disableEditMode(){return!!super.disableEditMode()&&(this.overlayDiv.classList.add("enabled"),this.editorDiv.contentEditable=!1,this.div.setAttribute("aria-activedescendant",this.#Tl),this._isDraggable=!0,this.#_l?.abort(),this.#_l=null,this.div.focus({preventScroll:!0}),this.isEditing=!1,this.parent.div.classList.add("freetextEditing"),!0)}focusin(t){this._focusEventsAllowed&&(super.focusin(t),t.target!==this.editorDiv&&this.editorDiv.focus())}onceAdded(t){this.width||(this.enableEditMode(),t&&this.editorDiv.focus(),this._initialOptions?.isCentered&&this.center(),this._initialOptions=null)}isEmpty(){return!this.editorDiv||""===this.editorDiv.innerText.trim()}remove(){this.isEditing=!1,this.parent&&(this.parent.setEditingState(!0),this.parent.div.classList.add("freetextEditing")),super.remove()}#Ml(){const e=[];this.editorDiv.normalize();let i=null;for(const s of this.editorDiv.childNodes)i?.nodeType===Node.TEXT_NODE&&"BR"===s.nodeName||(e.push(t.#Pl(s)),i=s);return e.join("\n")}#El(){const[t,e]=this.parentDimensions;let i;if(this.isAttachedToDOM)i=this.div.getBoundingClientRect();else{const{currentLayer:t,div:e}=this,s=e.style.display,n=e.classList.contains("hidden");e.classList.remove("hidden"),e.style.display="hidden",t.div.append(this.div),i=e.getBoundingClientRect(),e.remove(),e.style.display=s,e.classList.toggle("hidden",n)}this.rotation%180==this.parentRotation%180?(this.width=i.width/t,this.height=i.height/e):(this.width=i.height/t,this.height=i.width/e),this.fixAndSetPosition()}commit(){if(!this.isInEditMode())return;super.commit(),this.disableEditMode();const t=this.#Sl,e=this.#Sl=this.#Ml().trimEnd();if(t===e)return;const i=t=>{this.#Sl=t,t?(this.#Dl(),this._uiManager.rebuild(this),this.#El()):this.remove()};this.addCommands({cmd:()=>{i(e)},undo:()=>{i(t)},mustExec:!1}),this.#El()}shouldGetKeyboardEvents(){return this.isInEditMode()}enterInEditMode(){this.enableEditMode(),this.editorDiv.focus()}keydown(t){t.target===this.div&&"Enter"===t.key&&(this.enterInEditMode(),t.preventDefault())}editorDivKeydown(e){t._keyboardManager.exec(this,e)}editorDivFocus(t){this.isEditing=!0}editorDivBlur(t){this.isEditing=!1}editorDivInput(t){this.parent.div.classList.toggle("freetextEditing",this.isEmpty())}disableEditing(){this.editorDiv.setAttribute("role","comment"),this.editorDiv.removeAttribute("aria-multiline")}enableEditing(){this.editorDiv.setAttribute("role","textbox"),this.editorDiv.setAttribute("aria-multiline",!0)}get canChangeContent(){return!0}render(){if(this.div)return this.div;let t,e;(this._isCopy||this.annotationElementId)&&(t=this.x,e=this.y),super.render(),this.editorDiv=document.createElement("div"),this.editorDiv.className="internal",this.editorDiv.setAttribute("id",this.#Tl),this.editorDiv.setAttribute("data-l10n-id","pdfjs-free-text2"),this.editorDiv.setAttribute("data-l10n-attrs","default-content"),this.enableEditing(),this.editorDiv.contentEditable=!0;const{style:i}=this.editorDiv;if(i.fontSize=`calc(${this.#tl}px * var(--total-scale-factor))`,i.color=this.color,this.div.append(this.editorDiv),this.overlayDiv=document.createElement("div"),this.overlayDiv.classList.add("overlay","enabled"),this.div.append(this.overlayDiv),this._isCopy||this.annotationElementId){const[i,s]=this.parentDimensions;if(this.annotationElementId){const{position:n}=this._initialData;let[r,a]=this.getInitialTranslation();[r,a]=this.pageTranslationToScreen(r,a);const[o,l]=this.pageDimensions,[h,c]=this.pageTranslation;let d,u;switch(this.rotation){case 0:d=t+(n[0]-h)/o,u=e+this.height-(n[1]-c)/l;break;case 90:d=t+(n[0]-h)/o,u=e-(n[1]-c)/l,[r,a]=[a,-r];break;case 180:d=t-this.width+(n[0]-h)/o,u=e-(n[1]-c)/l,[r,a]=[-r,-a];break;case 270:d=t+(n[0]-h-this.height*l)/o,u=e+(n[1]-c-this.width*o)/l,[r,a]=[-a,r]}this.setAt(d*i,u*s,r,a)}else this._moveAfterPaste(t,e);this.#Dl(),this._isDraggable=!0,this.editorDiv.contentEditable=!1}else this._isDraggable=!1,this.editorDiv.contentEditable=!0;return this.div}static#Pl(t){return(t.nodeType===Node.TEXT_NODE?t.nodeValue:t.innerText).replaceAll(dn,"")}editorDivPaste(e){const i=e.clipboardData||window.clipboardData,{types:s}=i;if(1===s.length&&"text/plain"===s[0])return;e.preventDefault();const n=t.#Il(i.getData("text")||"").replaceAll(dn,"\n");if(!n)return;const r=window.getSelection();if(!r.rangeCount)return;this.editorDiv.normalize(),r.deleteFromDocument();const a=r.getRangeAt(0);if(!n.includes("\n"))return a.insertNode(document.createTextNode(n)),this.editorDiv.normalize(),void r.collapseToStart();const{startContainer:o,startOffset:l}=a,h=[],c=[];if(o.nodeType===Node.TEXT_NODE){const e=o.parentElement;if(c.push(o.nodeValue.slice(l).replaceAll(dn,"")),e!==this.editorDiv){let i=h;for(const s of this.editorDiv.childNodes)s!==e?i.push(t.#Pl(s)):i=c}h.push(o.nodeValue.slice(0,l).replaceAll(dn,""))}else if(o===this.editorDiv){let e=h,i=0;for(const s of this.editorDiv.childNodes)i++===l&&(e=c),e.push(t.#Pl(s))}this.#Sl=`${h.join("\n")}${n}${c.join("\n")}`,this.#Dl();const d=new Range;let u=Math.sumPrecise(h.map(t=>t.length));for(const{firstChild:t}of this.editorDiv.childNodes)if(t.nodeType===Node.TEXT_NODE){const e=t.nodeValue.length;if(u<=e){d.setStart(t,u),d.setEnd(t,u);break}u-=e}r.removeAllRanges(),r.addRange(d)}#Dl(){if(this.editorDiv.replaceChildren(),this.#Sl)for(const t of this.#Sl.split("\n")){const e=document.createElement("div");e.append(t?document.createTextNode(t):document.createElement("br")),this.editorDiv.append(e)}}#Fl(){return this.#Sl.replaceAll(" "," ")}static#Il(t){return t.replaceAll(" "," ")}get contentDiv(){return this.editorDiv}getPDFRect(){const e=t._internalPadding*this.parentScale;return this.getRect(e,e)}static async deserialize(e,i,s){let n=null;if(e instanceof Ks){const{data:{defaultAppearanceData:{fontSize:t,fontColor:i},rect:s,rotation:r,id:a,popupRef:o,richText:h,contentsObj:c,creationDate:d,modificationDate:u},textContent:p,textPosition:g,parent:{page:{pageNumber:m}}}=e;if(!p?.length)return null;n=e={annotationType:l.FREETEXT,color:Array.from(i),fontSize:t,value:p.join("\n"),position:g,pageIndex:m-1,rect:s.slice(0),rotation:r,annotationElementId:a,id:a,deleted:!1,popupRef:o,comment:c?.str||null,richText:h,creationDate:d,modificationDate:u}}const r=await super.deserialize(e,i,s);return r.#tl=e.fontSize,r.color=B.makeHexColor(...e.color),r.#Sl=t.#Il(e.value),r._initialData=n,e.comment&&r.setCommentData(e),r}serialize(t=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const e=Gt._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:this.color),i=Object.assign(super.serialize(t),{color:e,fontSize:this.#tl,value:this.#Fl()});return this.addComment(i),t?(i.isCopy=!0,i):this.annotationElementId&&!this.#Ll(i)?null:(i.id=this.annotationElementId,i)}#Ll(t){const{value:e,fontSize:i,color:s,pageIndex:n}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||t.value!==e||t.fontSize!==i||t.color.some((t,e)=>t!==s[e])||t.pageIndex!==n}renderAnnotationElement(t){const e=super.renderAnnotationElement(t);if(!e)return null;const{style:i}=e;i.fontSize=`calc(${this.#tl}px * var(--total-scale-factor))`,i.color=this.color,e.replaceChildren();for(const s of this.#Sl.split("\n")){const t=document.createElement("div");t.append(s?document.createTextNode(s):document.createElement("br")),e.append(t)}return t.updateEdited({rect:this.getPDFRect(),popup:this._uiManager.hasCommentManager()||this.hasEditedComment?this.comment:{text:this.#Sl}}),e}resetAnnotationElement(t){super.resetAnnotationElement(t),t.resetEdited()}},pn=class{#Bl=Object.create(null);updateProperty(t,e){this[t]=e,this.updateSVGProperty(t,e)}updateProperties(t){if(t)for(const[e,i]of Object.entries(t))e.startsWith("_")||this.updateProperty(e,i)}updateSVGProperty(t,e){this.#Bl[t]=e}toSVGProperties(){const t=this.#Bl;return this.#Bl=Object.create(null),{root:t}}reset(){this.#Bl=Object.create(null)}updateAll(t=this){this.updateProperties(t)}clone(){w("Not implemented")}},gn=class t extends Gt{#Rl=null;#Ol;_clipPathId=null;_colorPicker=null;_drawId=null;_drawOutlines=null;_focusDrawId=null;static _currentDrawId=-1;static _currentParent=null;static#Nl=null;static#zl=null;static#Hl=null;static#Ul=null;static _INNER_MARGIN=3;constructor(t){super(t),this.#Ol=t.mustBeCommitted||!1,this._addOutlines(t)}onUpdatedColor(){this._colorPicker?.update(this.color),super.onUpdatedColor()}onUpdatedOpacity(){this._colorPicker?.updateOpacity?.(this.opacity)}_addOutlines(t){t.drawOutlines&&(this.#Gl(t),this.#Wl())}#Gl({drawOutlines:t,drawId:e,drawingOptions:i,clipPathId:s}){this._drawOutlines=t,this._drawingOptions||=i,this.annotationElementId||this._uiManager.a11yAlert(Gt._l10nAlert[this.editorType]),e>=0?(this._drawId=e,this._clipPathId=s??null,this.parent.drawLayer.finalizeDraw(e,t.defaultProperties),this.#jl(this.parent)):this._drawId=this.#Vl(t,this.parent),this.#$l(t.box)}#Vl(e,i){const{id:s,clipPathId:n}=i.drawLayer.draw(t._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,this.constructor._hasClipPath);return this.constructor._hasClipPath&&(this._clipPathId=n),this.#jl(i),s}#jl(t){const e=this._drawOutlines.getFocusSVGProperties(this.#Xl);e&&(this._focusDrawId=t.drawLayer.drawOutline(e,this._drawOutlines.focusMustRemoveSelfIntersections))}#Kl(t=this.#Xl){null!==this._focusDrawId&&this.parent?.drawLayer.updateProperties(this._focusDrawId,this._drawOutlines.getFocusSVGProperties(t))}#Yl(t){null!==this._focusDrawId&&this.parent?.drawLayer.updateProperties(this._focusDrawId,{rootClass:t})}#ql(){const{parent:t,_drawId:e,_focusDrawId:i,_isVisible:s}=this;if(!t||null===e)return;const n={hidden:!s};t.drawLayer.updateProperties(e,{rootClass:n}),null!==i&&t.drawLayer.updateProperties(i,{rootClass:n})}static _mergeSVGProperties(t,e){const i=new Set(Object.keys(t));for(const[s,n]of Object.entries(e))i.has(s)?Object.assign(t[s],n):t[s]=n;return t}static getDefaultDrawingOptions(t){w("Not implemented")}static get typesMap(){w("Not implemented")}static get isDrawer(){return!0}static get _hasClipPath(){return!1}static get _hasDrawClass(){return!0}static get supportMultipleDrawings(){return!1}get _drawRotation(){return this.rotation}get _opacityName(){return this.constructor.typesMap.get(this.opacityType)}get#Xl(){return(this.parentRotation-this._drawRotation+360)%360}static updateDefaultParams(e,i){const s=this.typesMap.get(e);s&&this._defaultDrawingOptions.updateProperty(s,i),this._currentParent&&(t.#Nl.updateProperty(s,i),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(t,e){const i=this.constructor.typesMap.get(t);i&&this._updateProperty(t,i,e)}static get defaultPropertiesToUpdate(){const t=[],e=this._defaultDrawingOptions;for(const[i,s]of this.typesMap)t.push([i,e[s]]);return t}get propertiesToUpdate(){const t=[],{_drawingOptions:e}=this;for(const[i,s]of this.constructor.typesMap)t.push([i,e[s]]);return t}_updateProperty(t,e,i){const s=this._drawingOptions,n=s[e],r=i=>{s.updateProperty(e,i);const n=this._drawOutlines.updateProperty(e,i);n&&this.#$l(n),this.parent?.drawLayer.updateProperties(this._drawId,s.toSVGProperties()),t===this.colorType?this.onUpdatedColor():t===this.opacityType&&this.onUpdatedOpacity()};this.addCommands({cmd:r.bind(this,i),undo:r.bind(this,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:t,overwriteIfSameType:!0,keepUndo:!0})}_updateColorAndOpacity(t,e,i=this.colorAndOpacityType){const s=this.constructor.typesMap.get(this.colorType),n=this._opacityName,r=this._drawingOptions,a=r[s],o=r[n],l=(t,e)=>{r.updateProperty(s,t),r.updateProperty(n,e),this._drawOutlines.updateProperty(s,t),this._drawOutlines.updateProperty(n,e),this.parent?.drawLayer.updateProperties(this._drawId,r.toSVGProperties()),this.onUpdatedColor(),this.onUpdatedOpacity()};this.addCommands({cmd:l.bind(this,t,e),undo:l.bind(this,a,o),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:i,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){this.parent?.drawLayer.updateProperties(this._drawId,t._mergeSVGProperties(this._drawOutlines.getPathResizingSVGProperties(this.#Ql()),{bbox:this.#Jl()}))}_onResized(){this.parent?.drawLayer.updateProperties(this._drawId,t._mergeSVGProperties(this._drawOutlines.getPathResizedSVGProperties(this.#Ql()),{bbox:this.#Jl()})),this.#Kl()}_onTranslating(t,e){this.parent?.drawLayer.updateProperties(this._drawId,{bbox:this.#Jl()})}_onTranslated(){this.parent?.drawLayer.updateProperties(this._drawId,t._mergeSVGProperties(this._drawOutlines.getPathTranslatedSVGProperties(this.#Ql(),this.parentDimensions),{bbox:this.#Jl()}))}_onStartDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}get _mustBeDisabledOnCommit(){return!0}commit(){super.commit(),this._mustBeDisabledOnCommit&&(this.disableEditMode(),this.disableEditing())}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(t){this.annotationElementId||null===this._drawId||this.parent.addUndoableEditor(this),this._isDraggable=!0,this.#Ol&&(this.#Ol=!1,this.commit(),this.parent.setSelected(this),t&&this.isOnScreen&&this.div.focus())}remove(){this._uiManager.removeShouldRescale(this),this.#Zl(),super.remove()}rebuild(){this.parent&&(super.rebuild(),null!==this.div&&(this.#Wl(),this.#$l(this._drawOutlines.box),this.isAttachedToDOM||this.parent.add(this)))}setParent(t){let e=!1;this.parent&&!t?(this._uiManager.removeShouldRescale(this),this.#Zl()):t&&(this._uiManager.addShouldRescale(this),this.#Wl(t),e=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(t),this.#ql(),e&&this.select()}#Zl(){if(null===this._drawId||!this.parent)return;const{drawLayer:t}=this.parent;t.remove(this._drawId),this._drawId=null,null!==this._focusDrawId&&(t.remove(this._focusDrawId),this._focusDrawId=null),this._drawingOptions.reset()}#Wl(t=this.parent){if(null===this._drawId||this.parent!==t){if(null!==this._drawId){const{drawLayer:e}=this.parent;return e.updateParent(this._drawId,t.drawLayer),void(null!==this._focusDrawId&&e.updateParent(this._focusDrawId,t.drawLayer))}this._drawingOptions.updateAll(),this._drawId=this.#Vl(this._drawOutlines,t),this._clipPathId&&this.#Rl&&(this.#Rl.style.clipPath=this._clipPathId)}}#th([t,e,i,s]){const{parentDimensions:[n,r],_drawRotation:a}=this;switch(a){case 90:return[e,1-t,i*(r/n),s*(n/r)];case 180:return[1-t,1-e,i,s];case 270:return[1-e,t,i*(r/n),s*(n/r)];default:return[t,e,i,s]}}#Ql(){const{x:t,y:e,width:i,height:s,parentDimensions:[n,r],_drawRotation:a}=this;switch(a){case 90:return[1-e,t,i*(n/r),s*(r/n)];case 180:return[1-t,1-e,i,s];case 270:return[e,1-t,i*(n/r),s*(r/n)];default:return[t,e,i,s]}}#$l(t){[this.x,this.y,this.width,this.height]=this.#th(t),this.div&&(this.fixAndSetPosition(),this.setDims()),this._onResized()}#Jl(t=this.parentRotation){const{x:e,y:i,width:s,height:n,_drawRotation:r,parentDimensions:[a,o]}=this;switch((4*r+t)/90){case 1:return[1-i-n,e,n,s];case 2:return[1-e-s,1-i-n,s,n];case 3:return[i,1-e-s,n,s];case 4:return[e,i-s*(a/o),n*(o/a),s*(a/o)];case 5:return[1-i,e,s*(a/o),n*(o/a)];case 6:return[1-e-n*(o/a),1-i,n*(o/a),s*(a/o)];case 7:return[i-s*(a/o),1-e-n*(o/a),s*(a/o),n*(o/a)];case 8:return[e-s,i-n,s,n];case 9:return[1-i,e-s,n,s];case 10:return[1-e,1-i,s,n];case 11:return[i-n,1-e,n,s];case 12:return[e-n*(o/a),i,n*(o/a),s*(a/o)];case 13:return[1-i-s*(a/o),e-n*(o/a),s*(a/o),n*(o/a)];case 14:return[1-e,1-i-s*(a/o),n*(o/a),s*(a/o)];case 15:return[i,1-e,s*(a/o),n*(o/a)];default:return[e,i,s,n]}}rotate(e=this.parentRotation){if(!this.parent||null===this._drawId)return;const i=(e-this._drawRotation+360)%360;this.parent.drawLayer.updateProperties(this._drawId,t._mergeSVGProperties({bbox:this.#Jl(e)},this._drawOutlines.updateRotation(i))),this.#Kl(i)}show(t=this._isVisible){super.show(t),this.#ql()}select(){super.select(),this.#Yl({hovered:!1,selected:!0})}unselect(){super.unselect(),this.#Yl({selected:!1})}pointerover(){this.isSelected||this.#Yl({hovered:!0})}pointerleave(){this.isSelected||this.#Yl({hovered:!1})}onScaleChanging(){if(!this.parent)return;const t=this._drawOutlines.updateParentDimensions(this.parentDimensions,this.parent.scale);t&&this.#$l(t)}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;let t,e;this._isCopy&&(t=this.x,e=this.y);const i=super.render();this.constructor._hasDrawClass&&i.classList.add("draw");const s=this.#Rl=document.createElement("div");return i.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",this._clipPathId&&(s.style.clipPath=this._clipPathId),Et(this,s,["pointerover","pointerleave"]),this.setDims(),this._uiManager.addShouldRescale(this),this.disableEditing(),this._isCopy&&this._moveAfterPaste(t,e),i}static createDrawerInstance(t){w("Not implemented")}static _getDrawingTarget(t,{target:e}){return e}static _getPointerCoords({offsetX:t,offsetY:e,clientX:i,clientY:s},n=null){if(!n)return[t,e];let r=i-n.clientX,a=s-n.clientY;switch(this._currentParent.viewport.rotation){case 90:[r,a]=[a,-r];break;case 180:[r,a]=[-r,-a];break;case 270:[r,a]=[-a,r]}return[n.offsetX+r,n.offsetY+a]}static _addDrawingListeners(t,e){}static _endDrawingSession(t=!1){return this._currentParent.endDrawingSession(t)}static startDrawing(e,i,s,n){const{pointerId:r,pointerType:a}=n;if(Mt.isInitializedAndDifferentPointerType(a))return;const o=this._getDrawingTarget(e,n),[l,h]=this._getPointerCoords(n),{viewport:{rotation:c}}=e,{x:d,y:u,width:p,height:g}=o.getBoundingClientRect(),m=t.#zl=new AbortController,f=e.combinedSignal(m);if(Mt.setPointer(a,r),window.addEventListener("pointerup",t=>{Mt.isSamePointerIdOrRemove(t.pointerId)&&this._endDraw(t)},{signal:f}),window.addEventListener("pointercancel",t=>{Mt.isSamePointerIdOrRemove(t.pointerId)&&this._endDrawingSession()},{signal:f}),window.addEventListener("pointerdown",e=>{Mt.isSamePointerType(e.pointerType)&&(Mt.initializeAndAddPointerId(e.pointerId),t.#Nl.isCancellable()&&(t.#Nl.removeLastElement(),t.#Nl.isEmpty()?this._endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:f}),window.addEventListener("contextmenu",bt,{signal:f}),o.addEventListener("pointermove",this._drawMove.bind(this),{signal:f}),o.addEventListener("touchmove",t=>{Mt.isSameTimeStamp(t.timeStamp)&&yt(t)},{signal:f}),this._addDrawingListeners(o,f),e.toggleDrawing(),i._editorUndoBar?.hide(),t.#Nl)return void e.drawLayer.updateProperties(this._currentDrawId,t.#Nl.startNew(l,h,p,g,c,n.timeStamp));i.updateUIForDefaultProperties(this),t.#Nl=this.createDrawerInstance({x:l,y:h,box:[d,u,p,g],rotation:c,parent:e,isLTR:s,timeStamp:n.timeStamp}),t.#Hl=this.getDefaultDrawingOptions(),this._currentParent=e;const{id:b,clipPathId:y}=e.drawLayer.draw(this._mergeSVGProperties(t.#Hl.toSVGProperties(),t.#Nl.defaultSVGProperties),!0,this._hasClipPath);this._currentDrawId=b,t.#Ul=this._hasClipPath?y:null}static _drawMove(e){if(Mt.isSameTimeStamp(e.timeStamp),!t.#Nl||!Mt.isSamePointerId(e.pointerId))return;if(Mt.isUsingMultiplePointers())return void this._endDraw(e);let i;const s=e.getCoalescedEvents?.();if(s?.length){const n=[],r=[];for(const t of s)n.push(...this._getPointerCoords(t,e)),r.push(t.timeStamp);i=t.#Nl.addPoints(n,r)}else i=t.#Nl.add(...this._getPointerCoords(e),e.timeStamp);this._currentParent.drawLayer.updateProperties(this._currentDrawId,i),Mt.setTimeStamp(e.timeStamp),yt(e)}static _cleanup(e){e&&(this._currentDrawId=-1,this._currentParent=null,t.#Nl=null,t.#Hl=null,t.#Ul=null,Mt.clearTimeStamp()),t.#zl&&(t.#zl.abort(),t.#zl=null,Mt.clearPointerIds())}static _endDraw(e){const i=this._currentParent;if(i){if(i.toggleDrawing(!0),this._cleanup(!1),i.drawLayer.updateProperties(this._currentDrawId,e?.target===i.div?t.#Nl.end(...this._getPointerCoords(e),e.timeStamp):t.#Nl.end()),this.supportMultipleDrawings){const e=t.#Nl,s=this._currentDrawId,n=e.getLastElement();return void i.addCommands({cmd:()=>{i.drawLayer.updateProperties(s,e.setLastElement(n))},undo:()=>{i.drawLayer.updateProperties(s,e.removeLastElement())},mustExec:!1,type:h.DRAW_STEP})}this.endDrawing(!1)}}static endDrawing(e){const i=this._currentParent;if(!i)return null;if(i.toggleDrawing(!0),i.cleanUndoStack(h.DRAW_STEP),!t.#Nl.isEmpty()){const{pageDimensions:[s,n],scale:r}=i,a=i.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,clipPathId:t.#Ul,drawOutlines:t.#Nl.getOutlines(s*r,n*r,r,this._INNER_MARGIN),drawingOptions:t.#Hl,mustBeCommitted:!e});return this._cleanup(!0),a}return i.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(t){}static deserializeDraw(t,e,i,s,n,r,a){w("Not implemented")}static async deserialize(t,e,i){const{rawDims:{pageWidth:s,pageHeight:n,pageX:r,pageY:a}}=e.viewport,o=this.deserializeDraw(r,a,s,n,this._INNER_MARGIN,t,i),l=await super.deserialize(t,e,i);return l.createDrawingOptions(t),l.#Gl({drawOutlines:o}),l.#Wl(),l.onScaleChanging(),l.rotate(),l}serializeDraw(t){const[e,i]=this.pageTranslation,[s,n]=this.pageDimensions;return this._drawOutlines.serialize([e,i,s,n],t)}renderAnnotationElement(t){return t.updateEdited({rect:this.getPDFRect()}),null}static canCreateNewEmptyEditor(){return!1}},mn=class{static PRECISION=1e-4;focusOutline=null;toSVGPath(){w("Abstract method `toSVGPath` must be implemented.")}get box(){w("Abstract getter `box` must be implemented.")}serialize(t,e){w("Abstract method `serialize` must be implemented.")}get defaultSVGProperties(){w("Abstract getter `defaultSVGProperties` must be implemented.")}get defaultProperties(){return this.defaultSVGProperties}getFocusSVGProperties(t){return null}get focusMustRemoveSelfIntersections(){return!1}updateProperty(t,e){return null}updateParentDimensions(t,e){return null}serializeQuadPoints(t,e){return null}updateRotation(t){return{}}getPathResizingSVGProperties(t){return{}}getPathResizedSVGProperties(t){return{}}getPathTranslatedSVGProperties(t,e){return{}}static _rotateBox([t,e,i,s],n){switch(n){case 90:return[1-e-s,t,s,i];case 180:return[1-t-i,1-e-s,i,s];case 270:return[e,1-t-i,s,i]}return[t,e,i,s]}static _rescale(t,e,i,s,n,r){r||=new Float32Array(t.length);for(let a=0,o=t.length;a<o;a+=2)r[a]=e+t[a]*s,r[a+1]=i+t[a+1]*n;return r}static _rescaleAndSwap(t,e,i,s,n,r){r||=new Float32Array(t.length);for(let a=0,o=t.length;a<o;a+=2)r[a]=e+t[a+1]*s,r[a+1]=i+t[a]*n;return r}static _translate(t,e,i,s){s||=new Float32Array(t.length);for(let n=0,r=t.length;n<r;n+=2)s[n]=e+t[n],s[n+1]=i+t[n+1];return s}static svgRound(t){return Math.round(1e4*t)}static _normalizePoint(t,e,i,s,n,r=[]){switch(n){case 90:r[0]=1-e/i,r[1]=t/s;break;case 180:r[0]=1-t/i,r[1]=1-e/s;break;case 270:r[0]=e/i,r[1]=1-t/s;break;default:r[0]=t/i,r[1]=e/s}return r}static createBezierPoints(t,e,i,s,n,r,a=[]){return a.push((t+5*i)/6,(e+5*s)/6,(5*i+n)/6,(5*s+r)/6,(i+n)/2,(s+r)/2),a}},fn=class t{#eh;#ih=[];#sh;#nh;#rh=[];#ah=/* @__PURE__ */new Float32Array(18);#oh;#lh;#hh;#ch;#dh;#uh;#ph=[];static#gh=8;static#mh=2;static#fh=t.#gh+t.#mh;constructor(e,i,s,n,r,a,o=0){this.#eh=s,this.#uh=r*n,this.#nh=a,this.#ah.set([NaN,NaN,NaN,NaN,e,i],6),this.#sh=o,this.#ch=t.#gh*n,this.#hh=t.#fh*n,this.#dh=n,this.#ph.push(e,i)}isEmpty(){return isNaN(this.#ah[8])}isCancellable(){return this.#ph.length<=10}removeLastElement(){return this.#ah.fill(NaN),this.#rh.length=this.#ih.length=this.#ph.length=0,{path:{d:""}}}#bh(){const t=this.#ah.subarray(4,6),e=this.#ah.subarray(16,18),[i,s,n,r]=this.#eh;return[(this.#oh+(t[0]-e[0])/2-i)/n,(this.#lh+(t[1]-e[1])/2-s)/r,(this.#oh+(e[0]-t[0])/2-i)/n,(this.#lh+(e[1]-t[1])/2-s)/r]}add(t,e){this.#oh=t,this.#lh=e;const[i,s,n,r]=this.#eh;let[a,o,l,h]=this.#ah.subarray(8,12);const c=t-l,d=e-h,u=Math.hypot(c,d);if(u<this.#hh)return!1;const p=u-this.#ch,g=p/u,m=g*c,f=g*d;let b=a,y=o;a=l,o=h,l+=m,h+=f,this.#ph?.push(t,e);const v=m/p,w=-f/p*this.#uh,A=v*this.#uh;return this.#ah.set(this.#ah.subarray(2,8),0),this.#ah.set([l+w,h+A],4),this.#ah.set(this.#ah.subarray(14,18),12),this.#ah.set([l-w,h-A],16),isNaN(this.#ah[6])?(0===this.#rh.length&&(this.#ah.set([a+w,o+A],2),this.#rh.push(NaN,NaN,NaN,NaN,(a+w-i)/n,(o+A-s)/r),this.#ah.set([a-w,o-A],14),this.#ih.push(NaN,NaN,NaN,NaN,(a-w-i)/n,(o-A-s)/r)),this.#ah.set([b,y,a,o,l,h],6),!this.isEmpty()):(this.#ah.set([b,y,a,o,l,h],6),Math.abs(Math.atan2(y-o,b-a)-Math.atan2(f,m))<Math.PI/2?([a,o,l,h]=this.#ah.subarray(2,6),this.#rh.push(NaN,NaN,NaN,NaN,((a+l)/2-i)/n,((o+h)/2-s)/r),[a,o,b,y]=this.#ah.subarray(14,18),this.#ih.push(NaN,NaN,NaN,NaN,((b+a)/2-i)/n,((y+o)/2-s)/r),!0):([b,y,a,o,l,h]=this.#ah.subarray(0,6),this.#rh.push(((b+5*a)/6-i)/n,((y+5*o)/6-s)/r,((5*a+l)/6-i)/n,((5*o+h)/6-s)/r,((a+l)/2-i)/n,((o+h)/2-s)/r),[l,h,a,o,b,y]=this.#ah.subarray(12,18),this.#ih.push(((b+5*a)/6-i)/n,((y+5*o)/6-s)/r,((5*a+l)/6-i)/n,((5*o+h)/6-s)/r,((a+l)/2-i)/n,((o+h)/2-s)/r),!0))}toSVGPath(){if(this.isEmpty())return"";const t=this.#rh,e=this.#ih;if(isNaN(this.#ah[6])&&!this.isEmpty())return this.#yh();const i=[];i.push(`M${t[4]} ${t[5]}`);for(let s=6;s<t.length;s+=6)isNaN(t[s])?i.push(`L${t[s+4]} ${t[s+5]}`):i.push(`C${t[s]} ${t[s+1]} ${t[s+2]} ${t[s+3]} ${t[s+4]} ${t[s+5]}`);this.#vh(i);for(let s=e.length-6;s>=6;s-=6)isNaN(e[s])?i.push(`L${e[s+4]} ${e[s+5]}`):i.push(`C${e[s]} ${e[s+1]} ${e[s+2]} ${e[s+3]} ${e[s+4]} ${e[s+5]}`);return this.#wh(i),i.join(" ")}#yh(){const[t,e,i,s]=this.#eh,[n,r,a,o]=this.#bh();return`M${(this.#ah[2]-t)/i} ${(this.#ah[3]-e)/s} L${(this.#ah[4]-t)/i} ${(this.#ah[5]-e)/s} L${n} ${r} L${a} ${o} L${(this.#ah[16]-t)/i} ${(this.#ah[17]-e)/s} L${(this.#ah[14]-t)/i} ${(this.#ah[15]-e)/s} Z`}#wh(t){const e=this.#ih;t.push(`L${e[4]} ${e[5]} Z`)}#vh(t){const[e,i,s,n]=this.#eh,r=this.#ah.subarray(4,6),a=this.#ah.subarray(16,18),[o,l,h,c]=this.#bh();t.push(`L${(r[0]-e)/s} ${(r[1]-i)/n} L${o} ${l} L${h} ${c} L${(a[0]-e)/s} ${(a[1]-i)/n}`)}newFreeDrawOutline(t,e,i,s,n,r){return new bn(t,e,i,s,n,r)}getOutlines(){const t=this.#rh,e=this.#ih,i=this.#ah,[s,n,r,a]=this.#eh,o=new Float32Array((this.#ph?.length??0)+2);for(let c=0,d=o.length-2;c<d;c+=2)o[c]=(this.#ph[c]-s)/r,o[c+1]=(this.#ph[c+1]-n)/a;if(o[o.length-2]=(this.#oh-s)/r,o[o.length-1]=(this.#lh-n)/a,isNaN(i[6])&&!this.isEmpty())return this.#Ah(o);const l=new Float32Array(this.#rh.length+24+this.#ih.length);let h=t.length;for(let c=0;c<h;c+=2)isNaN(t[c])?l[c]=l[c+1]=NaN:(l[c]=t[c],l[c+1]=t[c+1]);h=this.#xh(l,h);for(let c=e.length-6;c>=6;c-=6)for(let t=0;t<6;t+=2)isNaN(e[c+t])?(l[h]=l[h+1]=NaN,h+=2):(l[h]=e[c+t],l[h+1]=e[c+t+1],h+=2);return this.#Ch(l,h),this.newFreeDrawOutline(l,o,this.#eh,this.#dh,this.#sh,this.#nh)}#Ah(t){const e=this.#ah,[i,s,n,r]=this.#eh,[a,o,l,h]=this.#bh(),c=/* @__PURE__ */new Float32Array(36);return c.set([NaN,NaN,NaN,NaN,(e[2]-i)/n,(e[3]-s)/r,NaN,NaN,NaN,NaN,(e[4]-i)/n,(e[5]-s)/r,NaN,NaN,NaN,NaN,a,o,NaN,NaN,NaN,NaN,l,h,NaN,NaN,NaN,NaN,(e[16]-i)/n,(e[17]-s)/r,NaN,NaN,NaN,NaN,(e[14]-i)/n,(e[15]-s)/r],0),this.newFreeDrawOutline(c,t,this.#eh,this.#dh,this.#sh,this.#nh)}#Ch(t,e){const i=this.#ih;return t.set([NaN,NaN,NaN,NaN,i[4],i[5]],e),e+6}#xh(t,e){const i=this.#ah.subarray(4,6),s=this.#ah.subarray(16,18),[n,r,a,o]=this.#eh,[l,h,c,d]=this.#bh();return t.set([NaN,NaN,NaN,NaN,(i[0]-n)/a,(i[1]-r)/o,NaN,NaN,NaN,NaN,l,h,NaN,NaN,NaN,NaN,c,d,NaN,NaN,NaN,NaN,(s[0]-n)/a,(s[1]-r)/o],e),e+24}},bn=class extends mn{#eh;#Sh=/* @__PURE__ */new Float32Array(4);#sh;#nh;#ph;#dh;#Th;constructor(t,e,i,s,n,r){super(),this.#Th=t,this.#ph=e,this.#eh=i,this.#dh=s,this.#sh=n,this.#nh=r,this.firstPoint=[NaN,NaN],this.lastPoint=[NaN,NaN],this.#_h(r);const[a,o,l,h]=this.#Sh;for(let c=0,d=t.length;c<d;c+=2)t[c]=(t[c]-a)/l,t[c+1]=(t[c+1]-o)/h;for(let c=0,d=e.length;c<d;c+=2)e[c]=(e[c]-a)/l,e[c+1]=(e[c+1]-o)/h}toSVGPath(){const t=[`M${this.#Th[4]} ${this.#Th[5]}`];for(let e=6,i=this.#Th.length;e<i;e+=6)isNaN(this.#Th[e])?t.push(`L${this.#Th[e+4]} ${this.#Th[e+5]}`):t.push(`C${this.#Th[e]} ${this.#Th[e+1]} ${this.#Th[e+2]} ${this.#Th[e+3]} ${this.#Th[e+4]} ${this.#Th[e+5]}`);return t.push("Z"),t.join(" ")}serialize([t,e,i,s],n){const r=i-t,a=s-e;let o,l;switch(n){case 0:o=mn._rescale(this.#Th,t,s,r,-a),l=mn._rescale(this.#ph,t,s,r,-a);break;case 90:o=mn._rescaleAndSwap(this.#Th,t,e,r,a),l=mn._rescaleAndSwap(this.#ph,t,e,r,a);break;case 180:o=mn._rescale(this.#Th,i,e,-r,a),l=mn._rescale(this.#ph,i,e,-r,a);break;case 270:o=mn._rescaleAndSwap(this.#Th,i,s,-r,-a),l=mn._rescaleAndSwap(this.#ph,i,s,-r,-a)}return{outline:Array.from(o),points:[Array.from(l)]}}#_h(t){const i=this.#Th;let s=i[4],n=i[5];const r=[s,n,s,n];let a=s,o=n,l=s,h=n;const c=t?Math.max:Math.min,d=/* @__PURE__ */new Float32Array(4);for(let p=6,g=i.length;p<g;p+=6){const t=i[p+4],u=i[p+5];isNaN(i[p])?(B.pointBoundingBox(t,u,r),o>u?(a=t,o=u):o===u&&(a=c(a,t)),h<u?(l=t,h=u):h===u&&(l=c(l,t))):(d.set(e,0),B.bezierBoundingBox(s,n,...i.slice(p,p+6),d),B.rectBoundingBox(...d,r),o>d[1]?(a=d[0],o=d[1]):o===d[1]&&(a=c(a,d[0])),h<d[3]?(l=d[2],h=d[3]):h===d[3]&&(l=c(l,d[2]))),s=t,n=u}const u=this.#Sh;u[0]=r[0]-this.#sh,u[1]=r[1]-this.#sh,u[2]=r[2]-r[0]+2*this.#sh,u[3]=r[3]-r[1]+2*this.#sh,this.firstPoint=[a,o],this.lastPoint=[l,h]}get box(){return this.#Sh}newOutliner(t,e,i,s,n,r,a=0){return new fn(t,e,i,s,n,r,a)}updateThickness(t){const e=this.getNewOutline(t);return this.#Th=e.#Th,this.#ph=e.#ph,this.#Sh.set(e.#Sh),this.firstPoint=e.firstPoint,this.lastPoint=e.lastPoint,this.#Sh}getNewOutline(t,e){const[i,s,n,r]=this.#Sh,[a,o,l,h]=this.#eh,c=n*l,d=r*h,u=i*l+a,p=s*h+o,g=this.#ph,m=this.newOutliner(g[0]*c+u,g[1]*d+p,this.#eh,this.#dh,t,this.#nh,e??this.#sh);for(let f=2,b=g.length;f<b;f+=2)m.add(g[f]*c+u,g[f+1]*d+p);return m.getOutlines()}};function yn(t){return{bbox:t.box,root:{viewBox:"0 0 1 1"},rootClass:{highlight:!0,free:t.isFree},path:{d:t.toSVGPath()}}}function vn(t,e){const{focusOutline:i}=t;return{bbox:mn._rotateBox(i.box,e),root:{"data-main-rotation":e},rootClass:{highlightOutline:!0,free:t.isFree},path:{d:i.toSVGPath()}}}var wn=class{#eh;#kh;#Eh;#Mh=[];#Ph=[];constructor(t,i=0,s=0,n=!0){const r=e.slice(),a=10**-4;for(const{x:e,y:m,width:f,height:b}of t){const t=Math.floor((e-i)/a)*a,s=Math.ceil((e+f+i)/a)*a,n=Math.floor((m-i)/a)*a,o=Math.ceil((m+b+i)/a)*a,l=[t,n,o,!0],h=[s,n,o,!1];this.#Mh.push(l,h),B.rectBoundingBox(t,n,s,o,r)}const o=r[2]-r[0]+2*s,l=r[3]-r[1]+2*s,h=r[0]-s,c=r[1]-s;let d=n?-1/0:1/0,u=1/0;const p=this.#Mh.at(n?-1:-2),g=[p[0],p[2]];for(const e of this.#Mh){const[t,i,s,r]=e;!r&&n?i<u?(u=i,d=t):i===u&&(d=Math.max(d,t)):r&&!n&&(i<u?(u=i,d=t):i===u&&(d=Math.min(d,t))),e[0]=(t-h)/o,e[1]=(i-c)/l,e[2]=(s-c)/l}this.#eh=new Float32Array([h,c,o,l]),this.#kh=[d,u],this.#Eh=g}getOutlines(){this.#Mh.sort((t,e)=>t[0]-e[0]||t[1]-e[1]||t[2]-e[2]);const t=[];for(const e of this.#Mh)e[3]?(t.push(...this.#Dh(e)),this.#Ih(e)):(this.#Fh(e),t.push(...this.#Dh(e)));return this.#Lh(t)}#Lh(t){const e=[],i=/* @__PURE__ */new Set;for(const n of t){const[t,i,s]=n;e.push([t,i,n],[t,s,n])}e.sort((t,e)=>t[1]-e[1]||t[0]-e[0]);for(let n=0,r=e.length;n<r;n+=2){const t=e[n][2],s=e[n+1][2];t.push(s),s.push(t),i.add(t),i.add(s)}const s=[];for(;i.size>0;){const t=i.values().next().value;let[e,n,r,a,o]=t;i.delete(t);let l=e,h=n;const c=[e,r];for(s.push(c);;){let t;if(i.has(a))t=a;else{if(!i.has(o))break;t=o}i.delete(t),[e,n,r,a,o]=t,l!==e&&(c.push(l,h,e,h===n?n:r),l=e),h=h===n?r:n}c.push(l,h)}return new An(s,this.#eh,this.#kh,this.#Eh)}#Bh(t){const e=this.#Ph;let i=0,s=e.length-1;for(;i<=s;){const n=i+s>>1,r=e[n][0];if(r===t)return n;r<t?i=n+1:s=n-1}return s+1}#Ih([,t,e]){const i=this.#Bh(t);this.#Ph.splice(i,0,[t,e])}#Fh([,t,e]){const i=this.#Bh(t);for(let s=i;s<this.#Ph.length;s++){const[i,n]=this.#Ph[s];if(i!==t)break;if(i===t&&n===e)return void this.#Ph.splice(s,1)}for(let s=i-1;s>=0;s--){const[i,n]=this.#Ph[s];if(i!==t)break;if(i===t&&n===e)return void this.#Ph.splice(s,1)}}#Dh(t){const[e,i,s]=t,n=[[e,i,s]],r=this.#Bh(s);for(let a=0;a<r;a++){const[t,i]=this.#Ph[a];for(let s=0,r=n.length;s<r;s++){const[,a,o]=n[s];if(!(i<=a||o<=t))if(a>=t)if(o>i)n[s][1]=i;else{if(1===r)return[];n.splice(s,1),s--,r--}else n[s][2]=t,o>i&&n.push([e,i,o])}}return n}},An=class extends mn{#eh;#Rh=null;#Oh;constructor(t,e,i,s){super(),this.#Oh=t,this.#eh=e,this.firstPoint=i,this.lastPoint=s}static build(t,e){const i=new wn(t,.001).getOutlines();return i.#Rh=t,i.focusOutline=new wn(t,.0025,.001,e).getOutlines(),i}get isFree(){return!1}get defaultSVGProperties(){return yn(this)}getFocusSVGProperties(t){return vn(this,t)}updateRotation(t){return{root:{"data-main-rotation":t}}}serializeQuadPoints([t,e],[i,s]){const n=this.#Rh,r=new Float32Array(8*n.length);let a=0;for(const{x:o,y:l,width:h,height:c}of n){const n=o*i+t,d=(1-l)*s+e;r[a]=r[a+4]=n,r[a+1]=r[a+3]=d,r[a+2]=r[a+6]=n+h*i,r[a+5]=r[a+7]=d-c*s,a+=8}return r}toSVGPath(){const t=[];for(const e of this.#Oh){let[i,s]=e;t.push(`M${i} ${s}`);for(let n=2;n<e.length;n+=2){const r=e[n],a=e[n+1];r===i?(t.push(`V${a}`),s=a):a===s&&(t.push(`H${r}`),i=r)}t.push("Z")}return t.join(" ")}serialize([t,e,i,s],n){const r=[],a=i-t,o=s-e;for(const l of this.#Oh){const e=new Array(l.length);for(let i=0;i<l.length;i+=2)e[i]=t+l[i]*a,e[i+1]=s-l[i+1]*o;r.push(e)}return r}get box(){return this.#eh}},xn=class extends fn{newFreeDrawOutline(t,e,i,s,n,r){return new Sn(t,e,i,s,n,r)}},Cn=class{#Nh;#uh;constructor(t,e,i,s,n,r,a){this.#Nh=new xn(t,e,i,s,n,r,a),this.#uh=n}add(t,e){return this.#Nh.add(t,e)?{path:{d:this.#Nh.toSVGPath()}}:null}addPoints(t){let e=!1;for(let i=0,s=t.length;i<s;i+=2)e=this.#Nh.add(t[i],t[i+1])||e;return e?{path:{d:this.#Nh.toSVGPath()}}:null}end(t,e){return void 0===t?null:this.add(t,e)}isEmpty(){return this.#Nh.isEmpty()}isCancellable(){return this.#Nh.isCancellable()}removeLastElement(){return this.#Nh.removeLastElement()}updateProperty(t,e){return null}getOutlines(){const t=this.#Nh.getOutlines();return t.buildFocusOutline(2*this.#uh),t}get defaultSVGProperties(){return{bbox:[0,0,1,1],root:{viewBox:"0 0 1 1"},rootClass:{highlight:!0,free:!0},path:{d:this.#Nh.toSVGPath()}}}},Sn=class t extends bn{static#zh=1.5;newOutliner(t,e,i,s,n,r,a=0){return new xn(t,e,i,s,n,r,a)}get isFree(){return!0}buildFocusOutline(e){this.focusOutline=this.getNewOutline(e/2+t.#zh,.0025)}get defaultSVGProperties(){return yn(this)}getFocusSVGProperties(t){return vn(this,t)}get focusMustRemoveSelfIntersections(){return!0}updateRotation(t){return{root:{"data-main-rotation":t}}}updateProperty(t,e){if("thickness"!==t)return null;const i=this.updateThickness(e/2);return this.buildFocusOutline(e),i}getPathResizedSVGProperties(){return{path:{d:this.toSVGPath()}}}},Tn=class t extends pn{constructor(t=null){super(),super.updateProperties(t)}updateSVGProperty(t,e){"thickness"!==t&&super.updateSVGProperty(t,e)}clone(){const e=new t;return e.updateAll(this),e}},_n=class t extends gn{#Hh=null;#Uh=0;#Gh=null;#Wh=0;#jh="";#ye="";static _DEFAULT_OPACITY=1;static _DEFAULT_THICKNESS=12;static _defaultDrawingOptions=null;static _type="highlight";static _editorType=l.HIGHLIGHT;static get _keyboardManager(){const e=t.prototype;return T(this,"_keyboardManager",new Ft([[["ArrowLeft"],e._moveCaret,{args:[0]}],[["ArrowRight"],e._moveCaret,{args:[1]}],[["ArrowUp"],e._moveCaret,{args:[2]}],[["ArrowDown"],e._moveCaret,{args:[3]}]]))}constructor(t){super({...t,name:"highlightEditor"}),this.#Hh=t.anchorNode||null,this.#Uh=t.anchorOffset||0,this.#Gh=t.focusNode||null,this.#Wh=t.focusOffset||0,this.#jh=t.methodOfCreation||(this._drawOutlines?.isFree?"main_toolbar":""),this.#ye=t.text||"",this._isDraggable=!1,this.defaultL10nId="pdfjs-editor-highlight-editor",this.rotate()}static initialize(e,i){Gt.initialize(e,i),this._defaultDrawingOptions||=new Tn({fill:i.highlightColors?.values().next().value||"#fff066","fill-opacity":t._DEFAULT_OPACITY,thickness:t._DEFAULT_THICKNESS})}static getDefaultDrawingOptions(t){const e=this._defaultDrawingOptions.clone();return e.updateProperties(t),e}static get typesMap(){return T(this,"typesMap",/* @__PURE__ */new Map([[h.HIGHLIGHT_COLOR,"fill"],[h.HIGHLIGHT_THICKNESS,"thickness"]]))}static get isDrawer(){return!1}static get _hasClipPath(){return!0}static get _hasDrawClass(){return!1}_addOutlines(e){const{boxes:i,drawOutlines:s}=e;(i||s)&&(this._drawingOptions||=e.drawingOptions||t.getDefaultDrawingOptions(),i&&(e={...e,drawOutlines:An.build(i,"ltr"===this._uiManager.direction)}),super._addOutlines(e))}get colorType(){return h.HIGHLIGHT_COLOR}get color(){return this._drawingOptions.fill}get opacity(){return this._drawingOptions["fill-opacity"]}get _opacityName(){return"fill-opacity"}get _drawRotation(){return this._drawOutlines?.isFree?this.rotation:0}get isResizable(){return!1}get _mustBeDisabledOnCommit(){return!1}get _mustFixPosition(){return!this._drawOutlines?.isFree}get telemetryInitialData(){return{action:"added",type:this._drawOutlines.isFree?"free_highlight":"highlight",color:this._uiManager.getNonHCMColorName(this.color),thickness:this._drawingOptions.thickness,methodOfCreation:this.#jh}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.getNonHCMColorName(this.color)}}static computeTelemetryFinalData(t){return{numberOfColors:t.get("color").size}}translateInPage(t,e){}get toolbarPosition(){return this.#Vh(this._drawOutlines.focusOutline.lastPoint)}get commentButtonPosition(){return this.#Vh(this._drawOutlines.firstPoint)}#Vh([t,e]){const[i,s,n,r]=this._drawOutlines.box;return[(t-i)/n,(e-s)/r]}updateParams(e,i){switch(e){case h.HIGHLIGHT_COLOR:this._updateColorAndOpacity(i,t._DEFAULT_OPACITY,e),this._reportTelemetry({action:"color_changed",color:this._uiManager.getNonHCMColorName(i)},!0);break;case h.HIGHLIGHT_THICKNESS:super.updateParams(e,i),this._reportTelemetry({action:"thickness_changed",thickness:i},!0)}}get propertiesToUpdate(){const t=super.propertiesToUpdate;return t.push([h.HIGHLIGHT_FREE,this._drawOutlines.isFree]),t}get toolbarButtons(){return this._uiManager.highlightColors?(this._colorPicker=new Ts({editor:this}),[["colorPicker",this._colorPicker]]):super.toolbarButtons}fixAndSetPosition(){return super.fixAndSetPosition(this._drawRotation)}getRect(t,e){return super.getRect(t,e,this._drawRotation)}onceAdded(t){this.annotationElementId||this.parent.addUndoableEditor(this),t&&this.div.focus()}remove(){this._reportTelemetry({action:"deleted"}),super.remove()}render(){if(this.div)return this.div;const t=super.render();return this.#ye&&(t.setAttribute("aria-label",this.#ye),t.setAttribute("role","mark")),this._drawOutlines.isFree?t.classList.add("free"):t.addEventListener("keydown",this.#$h.bind(this),{signal:this._uiManager._signal}),this.enableEditing(),t}#$h(e){t._keyboardManager.exec(this,e)}_moveCaret(t){switch(this.parent.unselect(this),t){case 0:case 2:this.#Xh(!0);break;case 1:case 3:this.#Xh(!1)}}#Xh(t){if(!this.#Hh)return;const e=window.getSelection();t?e.setPosition(this.#Hh,this.#Uh):e.setPosition(this.#Gh,this.#Wh)}unselect(){super.unselect(),this._drawOutlines.isFree||this.#Xh(!1)}static createDrawerInstance({x:t,y:e,box:i,parent:s,isLTR:n}){return new Cn(t,e,i,s.scale,this._defaultDrawingOptions.thickness/2,n,.001)}static _getDrawingTarget(t,{target:e}){return e.closest(".textLayer")}static _getPointerCoords({x:t,y:e}){return[t,e]}static _addDrawingListeners(t,e){t.classList.add("free"),e.addEventListener("abort",()=>t.classList.remove("free"),{once:!0}),window.addEventListener("blur",()=>this._endDraw(null),{signal:e}),window.addEventListener("pointerdown",yt,{capture:!0,passive:!1,signal:e})}static _endDrawingSession(t=!1){return this.endDrawing(t)}createDrawingOptions({color:e,opacity:i,thickness:s}){const{_defaultDrawingOptions:n,_DEFAULT_OPACITY:r}=t;this._drawingOptions=t.getDefaultDrawingOptions({fill:B.makeHexColor(...e),"fill-opacity":i||r,thickness:s||n.thickness})}static deserializeDraw(t,e,i,s,n,r,a){const{quadPoints:o}=r;if(o){const n=[];for(let r=0,a=o.length;r<a;r+=8)n.push({x:(o[r]-t)/i,y:1-(o[r+1]-e)/s,width:(o[r+2]-o[r])/i,height:(o[r+1]-o[r+5])/s});return An.build(n,"ltr"===a.direction)}const l=r.thickness||this._defaultDrawingOptions.thickness,h=(r.inkLists||r.outlines.points)[0],c=new xn(h[0]-t,s-(h[1]-e),[0,0,i,s],1,l/2,!0,.001);for(let u=0,p=h.length;u<p;u+=2)c.add(h[u]-t,s-(h[u+1]-e));const d=c.getOutlines();return d.buildFocusOutline(l),d}static async deserialize(t,e,i){let s=null;if(t instanceof sn){const{data:{quadPoints:e,rect:i,rotation:n,id:r,color:a,opacity:o,popupRef:h,richText:c,contentsObj:d,creationDate:u,modificationDate:p},parent:{page:{pageNumber:g}}}=t;s=t={annotationType:l.HIGHLIGHT,color:Array.from(a),opacity:o,quadPoints:e,pageIndex:g-1,rect:i.slice(0),rotation:n,annotationElementId:r,id:r,deleted:!1,popupRef:h,richText:c,comment:d?.str||null,creationDate:u,modificationDate:p}}else if(t instanceof en){const{data:{inkLists:e,rect:i,rotation:n,id:r,color:a,borderStyle:{rawWidth:o},popupRef:h,richText:c,contentsObj:d,creationDate:u,modificationDate:p},parent:{page:{pageNumber:g}}}=t;s=t={annotationType:l.HIGHLIGHT,color:Array.from(a),thickness:o,inkLists:e,pageIndex:g-1,rect:i.slice(0),rotation:n,annotationElementId:r,id:r,deleted:!1,popupRef:h,richText:c,comment:d?.str||null,creationDate:u,modificationDate:p}}const n=await super.deserialize(t,e,i);return n._initialData=s,t.comment&&n.setCommentData(t),n}serialize(t=!1){if(this.isEmpty()||t)return null;if(this.deleted)return this.serializeDeleted();const e=super.serialize(t);return Object.assign(e,{color:Gt._colorManager.convert(this._uiManager.getNonHCMColor(this.color)),opacity:this.opacity,thickness:this._drawingOptions.thickness,quadPoints:this._drawOutlines.serializeQuadPoints(this.pageTranslation,this.pageDimensions),outlines:this._drawOutlines.serialize(e.rect,this._drawRotation)}),this.addComment(e),this.annotationElementId&&!this.#Ll(e)?null:(e.id=this.annotationElementId,e)}#Ll(t){const{color:e}=this._initialData;return this.hasEditedComment||t.color.some((t,i)=>t!==e[i])}renderAnnotationElement(t){return this.deleted?(t.hide(),null):(t.updateEdited({rect:this.getPDFRect(),popup:this.comment}),null)}},kn=class t{static#Kh=10;static#Yh=1e3/180;static#qh=100;static#Qh=.001;#Jh;#Zh;#tc;constructor(t,e,i){this.#Jh=[t,e,i],this.#Zh=this.#tc=i}add(e,i,s){const n=this.#Jh,r=n.at(-1);s=s>r?s:r+t.#Qh,n.push(e,i,s);const a=this.#ec(s-t.#Kh,!0),o=this.#ic(this.#tc-t.#Kh);return o>=n.length/2&&(n.copyWithin(0,o),n.length-=o),a}get pendingPoints(){return this.#ec(1/0,!1)}end(){return this.#ec(1/0,!0)}#ec(e,i){const s=this.#Jh,n=this.#Zh,r=s.at(-1),a=[],o=this.#tc;for(let l=this.#ic(o)+3;l<s.length;l+=3){const h=s[l-1],c=s[l+2]-h,d=Math.min(Math.ceil(c/t.#Yh),t.#qh);for(let u=1;u<=d;u++){const p=u===d?s[l+2]:h+c*u/d;if(p<=o)continue;if(p>e)return a;const g=Math.min(t.#Kh,p-n,r-p);this.#sc(p-g,p+g,a),i&&(this.#tc=p)}}return a}#ic(t){const e=this.#Jh;let i=0,s=e.length/3-1;for(;i<s;){const n=i+s+1>>1;e[3*n+2]<=t?i=n:s=n-1}return 3*i}#sc(t,e,i){const s=this.#Jh,n=this.#ic(t);let r=0,a=0,o=0;for(let l=n;l<s.length-3&&s[l+2]<e;l+=3){const i=s[l],n=s[l+1],h=s[l+2],c=s[l+5],d=Math.max(h,t),u=Math.min(c,e);if(u<=d)continue;const p=u-d,g=(d+u-2*h)/(c-h);r+=p*(i+g*(s[l+3]-i)/2),a+=p*(n+g*(s[l+4]-n)/2),o+=p}0===o?i.push(s[n],s[n+1]):i.push(r/o,a/o)}};function En(t,e){return`${mn.svgRound(t[e])} ${mn.svgRound(t[e+1])}`}function Mn(t,e,i){for(let s=i,n=e.length;s<n;s+=6)t.push(`C${En(e,s)} ${En(e,s+2)} ${En(e,s+4)}`)}function Pn(t){const e=`M${En(t,4)}`;if(6===t.length)return`${e}Z`;if(12===t.length&&isNaN(t[6]))return`${e}L${En(t,10)}`;const i=[e];return Mn(i,t,6),i.join("")}var Dn=class{#ah=/* @__PURE__ */new Float64Array(6);#nc=/* @__PURE__ */new Float64Array(2);#nl;#rc;#da;#ac=null;#uh;#ph;#oc=1;#lc=/* @__PURE__ */new Float64Array(2);#hc="";#cc=0;#Oh=new In;#dc;#uc;constructor(t,e,i,s,n,r,a){this.#dc=i,this.#uc=s,this.#da=n,this.#uh=r,this.#rc=[],this.#pc(t,e,a)}#pc(t,e,i){[t,e]=this.#gc(t,e);const s=this.#nl=[NaN,NaN,NaN,NaN,t,e];this.#ph=[t,e],this.#rc.push({line:s,points:this.#ph}),this.#ah.set(s,0),this.#cc=0,this.#oc=1,this.#lc.set(this.#nc),this.#ac=void 0===i?null:new kn(t,e,i)}updateProperty(t,e){"stroke-width"===t&&(this.#uh=e)}#gc(t,e){return mn._normalizePoint(t,e,this.#dc,this.#uc,this.#da,this.#nc)}isEmpty(){return!this.#rc?.length}isCancellable(){return this.#oc<=5}add(t,e,i){return this.#mc(t,e,i),{path:{d:this.#fc()}}}addPoints(t,e){for(let i=0,s=t.length;i<s;i+=2)this.#mc(t[i],t[i+1],e?.[i/2]);return{path:{d:this.#fc()}}}#mc(t,e,i){[t,e]=this.#gc(t,e);const[s,n]=this.#lc;this.#bc(t,e,s,n)||(this.#oc++,this.#lc.set(this.#nc)),this.#ac?this.#yc(this.#ac.add(t,e,i)):this.#vc(t,e)}#bc(t,e,i,s){return Math.hypot(this.#dc*(t-i),this.#uc*(e-s))<=2}#yc(t){for(let e=0,i=t.length;e<i;e+=2)this.#vc(t[e],t[e+1])}#vc(t,e){const[,,i,s,n,r]=this.#ah;this.#bc(t,e,n,r)||(this.#ph.push(t,e),isNaN(i)?this.#nl.push(NaN,NaN,NaN,NaN,t,e):(isNaN(this.#ah[0])&&this.#nl.splice(6,6),mn.createBezierPoints(i,s,n,r,t,e,this.#nl)),this.#ah.copyWithin(0,2),this.#ah[4]=t,this.#ah[5]=e)}#wc(){const t=this.#nl;if(this.#ph.length<6||this.#cc===t.length)return;const e=[this.#hc];0===this.#cc&&(e.push(`M${En(t,4)}`),this.#cc=6),Mn(e,t,this.#cc),this.#hc=e.join(""),this.#cc=t.length}#Ac(){if(this.#nl){if(this.#ac&&(this.#yc(this.#ac.end()),this.#ac=null),this.#ph.length<6)this.#hc+=Pn(this.#nl);else{const[,,t,e,i,s]=this.#ah;mn.createBezierPoints(t,e,i,s,i,s,this.#nl),this.#wc()}this.#nl=this.#ph=null}}end(t,e,i){return this.#nl&&void 0!==t&&this.#mc(t,e,i),this.#Ac(),{path:{d:this.#hc}}}startNew(t,e,i,s,n,r){this.#dc=i,this.#uc=s,this.#da=n;const a=this.#rc.at(-1);return a&&(a.line=new Float32Array(a.line),a.points=new Float32Array(a.points)),this.#pc(t,e,r),null}getLastElement(){return this.#rc.at(-1)}setLastElement(t){return this.#rc?(this.#rc.push(t),this.#hc+=Pn(t.line),{path:{d:this.#hc}}):this.#Oh.setLastElement(t)}removeLastElement(){return this.#rc?(this.#nl=this.#ph=this.#ac=null,this.#rc.pop(),this.#hc=this.#rc.map(({line:t})=>Pn(t)).join(""),{path:{d:this.#hc}}):this.#Oh.removeLastElement()}#fc(){this.#wc();const t=[this.#hc];0===this.#cc&&(t.push(`M${En(this.#nl,4)}`),4===this.#ph.length&&t.push(`L${En(this.#nl,10)}`));let e=this.#ac?.pendingPoints;e?.length||(e=this.#nc);for(let i=0,s=e.length;i<s;i+=2)t.push(`L${En(e,i)}`);return t.join("")}getOutlines(t,e,i,s){this.#Ac();const n=this.#rc.at(-1);return n.line=new Float32Array(n.line),n.points=new Float32Array(n.points),this.#Oh.build(this.#rc,t,e,i,this.#da,this.#uh,s),this.#ah=null,this.#nl=null,this.#rc=null,this.#hc=null,this.#Oh}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}},In=class extends mn{#Sh;#xc=0;#sh;#rc;#dc;#uc;#Cc;#da;#uh;build(t,e,i,s,n,r,a){this.#dc=e,this.#uc=i,this.#Cc=s,this.#da=n,this.#uh=r,this.#sh=a??0,this.#rc=t,this.#Sc()}get thickness(){return this.#uh}setLastElement(t){return this.#rc.push(t),{path:{d:this.toSVGPath()}}}removeLastElement(){return this.#rc.pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){return this.#rc.map(({line:t})=>Pn(t)).join("")}serialize([t,e,i,s],n){const r=[],a=[],[o,l,h,c]=this.#Tc();let d,u,p,g,m,f,b,y,v;switch(this.#da){case 0:v=mn._rescale,d=t,u=e+s,p=i,g=-s,m=t+o*i,f=e+(1-l-c)*s,b=t+(o+h)*i,y=e+(1-l)*s;break;case 90:v=mn._rescaleAndSwap,d=t,u=e,p=i,g=s,m=t+l*i,f=e+o*s,b=t+(l+c)*i,y=e+(o+h)*s;break;case 180:v=mn._rescale,d=t+i,u=e,p=-i,g=s,m=t+(1-o-h)*i,f=e+l*s,b=t+(1-o)*i,y=e+(l+c)*s;break;case 270:v=mn._rescaleAndSwap,d=t+i,u=e+s,p=-i,g=-s,m=t+(1-l-c)*i,f=e+(1-o-h)*s,b=t+(1-l)*i,y=e+(1-o)*s}for(const{line:w,points:A}of this.#rc)r.push(v(w,d,u,p,g,n?new Array(w.length):null)),a.push(v(A,d,u,p,g,n?new Array(A.length):null));return{lines:r,points:a,rect:[m,f,b,y]}}static deserialize(t,e,i,s,n,{paths:{lines:r,points:a},rotation:o,thickness:l}){const h=[];let c,d,u,p,g;switch(o){case 0:g=mn._rescale,c=-t/i,d=e/s+1,u=1/i,p=-1/s;break;case 90:g=mn._rescaleAndSwap,c=-e/s,d=-t/i,u=1/s,p=1/i;break;case 180:g=mn._rescale,c=t/i+1,d=-e/s,u=-1/i,p=1/s;break;case 270:g=mn._rescaleAndSwap,c=e/s+1,d=t/i+1,u=-1/s,p=-1/i}if(!r){r=[];for(const t of a){const e=t.length;if(2===e){r.push(new Float32Array([NaN,NaN,NaN,NaN,t[0],t[1]]));continue}if(4===e){r.push(new Float32Array([NaN,NaN,NaN,NaN,t[0],t[1],NaN,NaN,NaN,NaN,t[2],t[3]]));continue}const i=new Float32Array(3*e);r.push(i);let[s,n,a,o]=t.subarray(0,4);i.set([NaN,NaN,NaN,NaN,s,n],0);for(let r=4;r<=e;r+=2){const l=Math.min(r,e-2),h=t[l],c=t[l+1];i.set(mn.createBezierPoints(s,n,a,o,h,c),3*(r-2)),[s,n,a,o]=[a,o,h,c]}}}for(let f=0,b=r.length;f<b;f++)h.push({line:g(r[f].map(t=>t??NaN),c,d,u,p),points:g(a[f].map(t=>t??NaN),c,d,u,p)});const m=new this.prototype.constructor;return m.build(h,i,s,1,o,l,n),m}#_c(t=this.#uh){const e=this.#sh+t/2*this.#Cc;return this.#da%180==0?[e/this.#dc,e/this.#uc]:[e/this.#uc,e/this.#dc]}#Tc(){const[t,e,i,s]=this.#Sh,[n,r]=this.#_c(0);return[t+n,e+r,i-2*n,s-2*r]}#Sc(){const t=this.#Sh=i.slice();for(const{line:i}of this.#rc){if(i.length<=12){for(let e=4,s=i.length;e<s;e+=6)B.pointBoundingBox(i[e],i[e+1],t);continue}let e=i[4],s=i[5];for(let n=6,r=i.length;n<r;n+=6){const[r,a,o,l,h,c]=i.subarray(n,n+6);B.bezierBoundingBox(e,s,r,a,o,l,h,c,t),e=h,s=c}}const[e,s]=this.#_c();t[0]=j(t[0]-e,0,1),t[1]=j(t[1]-s,0,1),t[2]=j(t[2]+e,0,1),t[3]=j(t[3]+s,0,1),t[2]-=t[0],t[3]-=t[1]}get box(){return this.#Sh}updateProperty(t,e){return"stroke-width"===t?this.#kc(e):null}#kc(t){const[e,i]=this.#_c();this.#uh=t;const[s,n]=this.#_c(),[r,a]=[s-e,n-i],o=this.#Sh;return o[0]-=r,o[1]-=a,o[2]+=2*r,o[3]+=2*a,o}updateParentDimensions([t,e],i){const[s,n]=this.#_c();this.#dc=t,this.#uc=e,this.#Cc=i;const[r,a]=this.#_c(),o=r-s,l=a-n,h=this.#Sh;return h[0]-=o,h[1]-=l,h[2]+=2*o,h[3]+=2*l,h}updateRotation(t){return this.#xc=t,{path:{transform:this.rotationTransform}}}get viewBox(){return this.#Sh.map(mn.svgRound).join(" ")}get defaultProperties(){const[t,e]=this.#Sh;return{root:{viewBox:this.viewBox},path:{"transform-origin":`${mn.svgRound(t)} ${mn.svgRound(e)}`}}}get rotationTransform(){const[,,t,e]=this.#Sh;let i=0,s=0,n=0,r=0,a=0,o=0;switch(this.#xc){case 90:s=e/t,n=-t/e,a=t;break;case 180:i=-1,r=-1,a=t,o=e;break;case 270:s=-e/t,n=t/e,o=e;break;default:return""}return`matrix(${i} ${s} ${n} ${r} ${mn.svgRound(a)} ${mn.svgRound(o)})`}getPathResizingSVGProperties([t,e,i,s]){const[n,r]=this.#_c(),[a,o,l,h]=this.#Sh;if(Math.abs(l-n)<=mn.PRECISION||Math.abs(h-r)<=mn.PRECISION){const n=t+i/2-(a+l/2),r=e+s/2-(o+h/2);return{path:{"transform-origin":`${mn.svgRound(t)} ${mn.svgRound(e)}`,transform:`${this.rotationTransform} translate(${n} ${r})`}}}const c=(i-2*n)/(l-2*n),d=(s-2*r)/(h-2*r),u=l/i,p=h/s;return{path:{"transform-origin":`${mn.svgRound(a)} ${mn.svgRound(o)}`,transform:`${this.rotationTransform} scale(${u} ${p}) translate(${mn.svgRound(n)} ${mn.svgRound(r)}) scale(${c} ${d}) translate(${mn.svgRound(-n)} ${mn.svgRound(-r)})`}}}getPathResizedSVGProperties([t,e,i,s]){const[n,r]=this.#_c(),a=this.#Sh,[o,l,h,c]=a;if(a[0]=t,a[1]=e,a[2]=i,a[3]=s,Math.abs(h-n)<=mn.PRECISION||Math.abs(c-r)<=mn.PRECISION){const n=t+i/2-(o+h/2),r=e+s/2-(l+c/2);for(const{line:t,points:e}of this.#rc)mn._translate(t,n,r,t),mn._translate(e,n,r,e);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${mn.svgRound(t)} ${mn.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const d=(i-2*n)/(h-2*n),u=(s-2*r)/(c-2*r),p=-d*(o+n)+t+n,g=-u*(l+r)+e+r;if(1!==d||1!==u||0!==p||0!==g)for(const{line:m,points:f}of this.#rc)mn._rescale(m,p,g,d,u,m),mn._rescale(f,p,g,d,u,f);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${mn.svgRound(t)} ${mn.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([t,e],i){const[s,n]=i,r=this.#Sh,a=t-r[0],o=e-r[1];if(this.#dc===s&&this.#uc===n)for(const{line:l,points:h}of this.#rc)mn._translate(l,a,o,l),mn._translate(h,a,o,h);else{const t=this.#dc/s,e=this.#uc/n;this.#dc=s,this.#uc=n;for(const{line:i,points:s}of this.#rc)mn._rescale(i,a,o,t,e,i),mn._rescale(s,a,o,t,e,s);r[2]*=t,r[3]*=e}return r[0]=t,r[1]=e,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${mn.svgRound(t)} ${mn.svgRound(e)}`}}}get defaultSVGProperties(){const t=this.#Sh;return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${mn.svgRound(t[0])} ${mn.svgRound(t[1])}`,transform:this.rotationTransform||null},bbox:t}}},Fn=class t extends pn{constructor(t){super(),this._viewParameters=t,super.updateProperties({fill:"none",stroke:Gt._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(t,e){"stroke-width"===t&&(e??=this["stroke-width"],e*=this._viewParameters.realScale),super.updateSVGProperty(t,e)}clone(){const e=new t(this._viewParameters);return e.updateAll(this),e}},Ln=class t extends gn{static _type="ink";static _editorType=l.INK;static _defaultDrawingOptions=null;constructor(t){super({...t,name:"inkEditor"}),this._willKeepAspectRatio=!0,this.defaultL10nId="pdfjs-editor-ink-editor"}static initialize(t,e){Gt.initialize(t,e),this._defaultDrawingOptions=new Fn(e.viewParameters)}static getDefaultDrawingOptions(t){const e=this._defaultDrawingOptions.clone();return e.updateProperties(t),e}static get supportMultipleDrawings(){return!0}static get typesMap(){return T(this,"typesMap",/* @__PURE__ */new Map([[h.INK_THICKNESS,"stroke-width"],[h.INK_COLOR,"stroke"],[h.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance({x:t,y:e,box:[,,i,s],rotation:n,timeStamp:r}){return new Dn(t,e,i,s,n,this._defaultDrawingOptions["stroke-width"],r)}static deserializeDraw(t,e,i,s,n,r){return In.deserialize(t,e,i,s,n,r)}static async deserialize(t,e,i){let s=null;if(t instanceof en){const{data:{inkLists:e,rect:i,rotation:n,id:r,color:a,opacity:o,borderStyle:{rawWidth:h},popupRef:c,richText:d,contentsObj:u,creationDate:p,modificationDate:g},parent:{page:{pageNumber:m}}}=t;s=t={annotationType:l.INK,color:Array.from(a),thickness:h,opacity:o,paths:{points:e},boxes:null,pageIndex:m-1,rect:i.slice(0),rotation:n,annotationElementId:r,id:r,deleted:!1,popupRef:c,richText:d,comment:u?.str||null,creationDate:p,modificationDate:g}}const n=await super.deserialize(t,e,i);return n._initialData=s,t.comment&&n.setCommentData(t),n}get toolbarButtons(){return this._colorPicker||=new _s(this),[["colorPicker",this._colorPicker]]}get colorType(){return h.INK_COLOR}get colorAndOpacityType(){return h.INK_COLOR_AND_OPACITY}get opacityType(){return h.INK_OPACITY}updateParams(t,e){t!==h.INK_COLOR_AND_OPACITY?super.updateParams(t,e):this._updateColorAndOpacity(e.color,e.opacity)}static updateDefaultParams(t,e){if(t===h.INK_COLOR_AND_OPACITY)return super.updateDefaultParams(h.INK_COLOR,e.color),void super.updateDefaultParams(h.INK_OPACITY,e.opacity);super.updateDefaultParams(t,e)}get color(){return this._drawingOptions.stroke}get opacity(){return this._drawingOptions["stroke-opacity"]}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();const{_drawId:t,_drawingOptions:e,parent:i}=this;e.updateSVGProperty("stroke-width"),i.drawLayer.updateProperties(t,e.toSVGProperties())}static onScaleChangingWhenDrawing(){const t=this._currentParent;t&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),t.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:e,thickness:i,opacity:s}){this._drawingOptions=t.getDefaultDrawingOptions({stroke:B.makeHexColor(...e),"stroke-width":i,"stroke-opacity":s})}serialize(t=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:e,points:i}=this.serializeDraw(t),{_drawingOptions:{stroke:s,"stroke-opacity":n,"stroke-width":r}}=this,a=Object.assign(super.serialize(t),{color:Gt._colorManager.convert(s),opacity:n,thickness:r,paths:{lines:e,points:i}});return this.addComment(a),t?(a.isCopy=!0,a):this.annotationElementId&&!this.#Ll(a)?null:(a.id=this.annotationElementId,a)}#Ll(t){const{color:e,thickness:i,opacity:s,pageIndex:n}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized||t.color.some((t,i)=>t!==e[i])||t.thickness!==i||t.opacity!==s||t.pageIndex!==n}renderAnnotationElement(t){if(this.deleted)return t.hide(),null;const{points:e,rect:i}=this.serializeDraw(!1);return t.updateEdited({rect:i,thickness:this._drawingOptions["stroke-width"],points:e,popup:this.comment}),null}},Bn=class extends In{toSVGPath(){let t=super.toSVGPath();return t.endsWith("Z")||(t+="Z"),t}},Rn=class{static#Ec={maxDim:512,sigmaSFactor:.02,sigmaR:25,kernelSize:16};static#Mc(t,e,i,s){return s-=e,0===(i-=t)?s>0?0:4:1===i?s+6:2-s}static#Pc=new Int32Array([0,1,-1,1,-1,0,-1,-1,0,-1,1,-1,1,0,1,1]);static#Dc(t,e,i,s,n,r,a){const o=this.#Mc(i,s,n,r);for(let l=0;l<8;l++){const n=(-l+o-a+16)%8;if(0!==t[(i+this.#Pc[2*n])*e+(s+this.#Pc[2*n+1])])return n}return-1}static#Ic(t,e,i,s,n,r,a){const o=this.#Mc(i,s,n,r);for(let l=0;l<8;l++){const n=(l+o+a+16)%8;if(0!==t[(i+this.#Pc[2*n])*e+(s+this.#Pc[2*n+1])])return n}return-1}static#Fc(t,e,i,s){const n=t.length,r=new Int32Array(n);for(let h=0;h<n;h++)r[h]=t[h]<=s?1:0;for(let h=1;h<i-1;h++)r[h*e]=r[h*e+e-1]=0;for(let h=0;h<e;h++)r[h]=r[e*i-1-h]=0;let a,o=1;const l=[];for(let h=1;h<i-1;h++){a=1;for(let t=1;t<e-1;t++){const i=h*e+t,s=r[i];if(0===s)continue;let n=h,c=t;if(1===s&&0===r[i-1])o+=1,c-=1;else{if(!(s>=1&&0===r[i+1])){1!==s&&(a=Math.abs(s));continue}o+=1,c+=1,s>1&&(a=s)}const d=[t,h],u=c===t+1,p={isHole:u,points:d,id:o,parent:0};let g;l.push(p);for(const t of l)if(t.id===a){g=t;break}g?g.isHole?p.parent=u?g.parent:a:p.parent=u?a:g.parent:p.parent=u?a:0;const m=this.#Dc(r,e,h,t,n,c,0);if(-1===m){r[i]=-o,1!==r[i]&&(a=Math.abs(r[i]));continue}let f=this.#Pc[2*m],b=this.#Pc[2*m+1];const y=h+f,v=t+b;n=y,c=v;let w=h,A=t;for(;;){const s=this.#Ic(r,e,w,A,n,c,1);f=this.#Pc[2*s],b=this.#Pc[2*s+1];const l=w+f,u=A+b;d.push(u,l);const p=w*e+A;if(0===r[p+1]?r[p]=-o:1===r[p]&&(r[p]=o),l===h&&u===t&&w===y&&A===v){1!==r[i]&&(a=Math.abs(r[i]));break}n=w,c=A,w=l,A=u}}}return l}static#Lc(t,e,i,s){if(i-e<=4){for(let n=e;n<i-2;n+=2)s.push(t[n],t[n+1]);return}const n=t[e],r=t[e+1],a=t[i-4]-n,o=t[i-3]-r,l=Math.hypot(a,o),h=a/l,c=o/l,d=h*r-c*n,u=o/a,p=1/l,g=Math.atan(u),m=Math.cos(g),f=Math.sin(g),b=p*(Math.abs(m)+Math.abs(f)),y=p*(1-b+b**2),v=Math.max(Math.atan(Math.abs(f+m)*y),Math.atan(Math.abs(f-m)*y));let w=0,A=e;for(let x=e+2;x<i-2;x+=2){const e=Math.abs(d-h*t[x+1]+c*t[x]);e>w&&(A=x,w=e)}w>(l*v)**2?(this.#Lc(t,e,A+2,s),this.#Lc(t,A,i,s)):s.push(n,r)}static#Bc(t){const e=[],i=t.length;return this.#Lc(t,0,i,e),e.push(t[i-2],t[i-1]),e.length<=4?null:e}static#Rc(t,e,i,s,n,r){const a=new Float32Array(r**2),o=-2*s**2,l=r>>1;for(let g=0;g<r;g++){const t=(g-l)**2;for(let e=0;e<r;e++)a[g*r+e]=Math.exp((t+(e-l)**2)/o)}const h=/* @__PURE__ */new Float32Array(256),c=-2*n**2;for(let g=0;g<256;g++)h[g]=Math.exp(g**2/c);const d=t.length,u=new Uint8Array(d),p=/* @__PURE__ */new Uint32Array(256);for(let g=0;g<i;g++)for(let s=0;s<e;s++){const n=g*e+s,o=t[n];let c=0,d=0;for(let u=0;u<r;u++){const n=g+u-l;if(!(n<0||n>=i))for(let i=0;i<r;i++){const p=s+i-l;if(p<0||p>=e)continue;const g=t[n*e+p],m=a[u*r+i]*h[Math.abs(g-o)];c+=g*m,d+=m}}p[u[n]=Math.round(c/d)]++}return[u,p]}static#Oc(t){const e=/* @__PURE__ */new Uint32Array(256);for(const i of t)e[i]++;return e}static#Nc(t){const e=t.length,i=new Uint8ClampedArray(e>>2);let s=-1/0,n=1/0;for(let a=0,o=i.length;a<o;a++){const e=i[a]=t[a<<2];s=Math.max(s,e),n=Math.min(n,e)}const r=255/(s-n);for(let a=0,o=i.length;a<o;a++)i[a]=(i[a]-n)*r;return i}static#zc(t){let e,i=-1/0,s=-1/0;const n=t.findIndex(t=>0!==t);let r=n,a=n;for(e=n;e<256;e++){const n=t[e];n>i&&(e-r>s&&(s=e-r,a=e-1),i=n,r=e)}for(e=a-1;e>=0&&!(t[e]>t[e+1]);e--);return e}static#Hc(t){const e=t,{width:i,height:s}=t,{maxDim:n}=this.#Ec;let r=i,a=s;if(i>n||s>n){let o=i,l=s,h=Math.log2(Math.max(i,s)/n);const c=Math.floor(h);h=h===c?c-1:c;for(let i=0;i<h;i++){r=Math.ceil(o/2),a=Math.ceil(l/2);const i=new OffscreenCanvas(r,a);i.getContext("2d").drawImage(t,0,0,o,l,0,0,r,a),o=r,l=a,t!==e&&t.close(),t=i.transferToImageBitmap()}const d=Math.min(n/r,n/a);r=Math.round(r*d),a=Math.round(a*d)}const o=new OffscreenCanvas(r,a).getContext("2d",{willReadFrequently:!0});o.fillStyle="white",o.fillRect(0,0,r,a),o.filter="grayscale(1)",o.drawImage(t,0,0,t.width,t.height,0,0,r,a);const l=o.getImageData(0,0,r,a).data;return[this.#Nc(l),r,a]}static extractContoursFromText(t,{fontFamily:e,fontStyle:i,fontWeight:s},n,r,a,o){let l=new OffscreenCanvas(1,1),h=l.getContext("2d",{alpha:!1});const c=h.font=`${i} ${s} 200px ${e}`,{actualBoundingBoxLeft:d,actualBoundingBoxRight:u,actualBoundingBoxAscent:p,actualBoundingBoxDescent:g,fontBoundingBoxAscent:m,fontBoundingBoxDescent:f,width:b}=h.measureText(t),y=Math.ceil(1.5*Math.max(Math.abs(d)+Math.abs(u)||0,b)),v=Math.ceil(1.5*Math.max(Math.abs(p)+Math.abs(g)||200,Math.abs(m)+Math.abs(f)||200));l=new OffscreenCanvas(y,v),h=l.getContext("2d",{alpha:!0,willReadFrequently:!0}),h.font=c,h.filter="grayscale(1)",h.fillStyle="white",h.fillRect(0,0,y,v),h.fillStyle="black",h.fillText(t,.5*y/2,1.5*v/2);const w=this.#Nc(h.getImageData(0,0,y,v).data),A=this.#Oc(w),x=this.#zc(A),C=this.#Fc(w,y,v,x);return this.processDrawnLines({lines:{curves:C,width:y,height:v},pageWidth:n,pageHeight:r,rotation:a,innerMargin:o,mustSmooth:!0,areContours:!0})}static process(t,e,i,s,n){const[r,a,o]=this.#Hc(t),[l,h]=this.#Rc(r,a,o,Math.hypot(a,o)*this.#Ec.sigmaSFactor,this.#Ec.sigmaR,this.#Ec.kernelSize),c=this.#zc(h),d=this.#Fc(l,a,o,c);return this.processDrawnLines({lines:{curves:d,width:a,height:o},pageWidth:e,pageHeight:i,rotation:s,innerMargin:n,mustSmooth:!0,areContours:!0})}static processDrawnLines({lines:t,pageWidth:e,pageHeight:i,rotation:s,innerMargin:n,mustSmooth:r,areContours:a}){s%180!=0&&([e,i]=[i,e]);const{curves:o,width:l,height:h}=t,c=t.thickness??0,d=[],u=Math.min(e/l,i/h),p=u/e,g=u/i,m=[];for(const{points:b}of o){const t=r?this.#Bc(b):b;if(!t)continue;m.push(t);const e=t.length,i=new Float32Array(e),s=new Float32Array(3*(2===e?2:e-2));if(d.push({line:s,points:i}),2===e){i[0]=t[0]*p,i[1]=t[1]*g,s.set([NaN,NaN,NaN,NaN,i[0],i[1]],0);continue}let[n,a,o,l]=t;n*=p,a*=g,o*=p,l*=g,i.set([n,a,o,l],0),s.set([NaN,NaN,NaN,NaN,n,a],0);for(let r=4;r<e;r+=2){const e=i[r]=t[r]*p,h=i[r+1]=t[r+1]*g;s.set(mn.createBezierPoints(n,a,o,l,e,h),3*(r-2)),[n,a,o,l]=[o,l,e,h]}}if(0===d.length)return null;const f=a?new Bn:new In;return f.build(d,e,i,1,s,a?0:c,n),{outline:f,newCurves:m,areContours:a,thickness:c,width:l,height:h}}static async compressSignature({outlines:t,areContours:e,thickness:i,width:s,height:n}){let r,a=1/0,o=-1/0,l=0;for(const f of t){l+=f.length;for(let t=2,e=f.length;t<e;t++){const e=f[t]-f[t-2];a=Math.min(a,e),o=Math.max(o,e)}}r=a>=-128&&o<=127?Int8Array:a>=-32768&&o<=32767?Int16Array:Int32Array;const h=t.length,c=8+3*h,d=new Uint32Array(c);let u=0;d[u++]=c*Uint32Array.BYTES_PER_ELEMENT+(l-2*h)*r.BYTES_PER_ELEMENT,d[u++]=0,d[u++]=s,d[u++]=n,d[u++]=e?0:1,d[u++]=Math.max(0,Math.floor(i??0)),d[u++]=h,d[u++]=r.BYTES_PER_ELEMENT;for(const f of t)d[u++]=f.length-2,d[u++]=f[0],d[u++]=f[1];const p=new CompressionStream("deflate-raw"),g=p.writable.getWriter();await g.ready,g.write(d);const m=r.prototype.constructor;for(const f of t){const t=new m(f.length-2);for(let e=2,i=f.length;e<i;e++)t[e-2]=f[e]-f[e-2];g.write(t)}return g.close(),(await new Response(p.readable).bytes()).toBase64()}static async decompressSignature(t){try{const e=Uint8Array.fromBase64(t),{readable:i,writable:s}=new DecompressionStream("deflate-raw"),n=s.getWriter();await n.ready,n.write(e).then(async()=>{await n.ready,await n.close()}).catch(()=>{});let r=null,a=0;for await(const t of i)r||=new Uint8Array(new Uint32Array(t.buffer,0,4)[0]),r.set(t,a),a+=t.length;const o=new Uint32Array(r.buffer,0,r.length>>2),l=o[1];if(0!==l)throw new Error(`Invalid version: ${l}`);const h=o[2],c=o[3],d=0===o[4],u=o[5],p=o[6],g=o[7],m=[],f=(8+3*p)*Uint32Array.BYTES_PER_ELEMENT;let b;switch(g){case Int8Array.BYTES_PER_ELEMENT:b=new Int8Array(r.buffer,f);break;case Int16Array.BYTES_PER_ELEMENT:b=new Int16Array(r.buffer,f);break;case Int32Array.BYTES_PER_ELEMENT:b=new Int32Array(r.buffer,f)}a=0;for(let t=0;t<p;t++){const e=o[3*t+8],i=new Float32Array(e+2);m.push(i);for(let s=0;s<2;s++)i[s]=o[3*t+8+s+1];for(let t=0;t<e;t++)i[t+2]=i[t]+b[a++]}return{areContours:d,thickness:u,outlines:m,width:h,height:c}}catch(e){return null}}},On=class t extends pn{constructor(){super(),super.updateProperties({fill:Gt._defaultLineColor,"stroke-width":0})}clone(){const e=new t;return e.updateAll(this),e}},Nn=class t extends Fn{constructor(t){super(t),super.updateProperties({stroke:Gt._defaultLineColor,"stroke-width":1})}clone(){const e=new t(this._viewParameters);return e.updateAll(this),e}},zn=class t extends gn{#Uc=!1;#Gc=null;#Wc=null;#jc=null;#Vc=!1;static _type="signature";static _editorType=l.SIGNATURE;static _defaultDrawingOptions=null;constructor(t){super({...t,mustBeCommitted:!0,name:"signatureEditor"}),this._willKeepAspectRatio=!0,this.#Wc=t.signatureData||null,this.#Gc=null,this.defaultL10nId="pdfjs-editor-signature-editor1"}static initialize(t,e){Gt.initialize(t,e),this._defaultDrawingOptions=new On,this._defaultDrawnSignatureOptions=new Nn(e.viewParameters)}static getDefaultDrawingOptions(t){const e=this._defaultDrawingOptions.clone();return e.updateProperties(t),e}static get supportMultipleDrawings(){return!1}static get typesMap(){return T(this,"typesMap",/* @__PURE__ */new Map)}static get isDrawer(){return!1}get telemetryFinalData(){return{type:"signature",hasDescription:!!this.#Gc}}static computeTelemetryFinalData(t){const e=t.get("hasDescription");return{hasAltText:e.get(!0)??0,hasNoAltText:e.get(!1)??0}}get isResizable(){return!0}onceAdded(t){this.#Vc=null===this._drawId,super.onceAdded(t)}onScaleChanging(){null!==this._drawId&&super.onScaleChanging()}render(){if(this.div)return this.div;let e,i;const{_isCopy:s}=this;if(s&&(this._isCopy=!1,e=this.x,i=this.y),super.render(),null===this._drawId)if(this.#Wc){const{lines:e,mustSmooth:i,areContours:s,description:n,uuid:r,heightInPage:a}=this.#Wc,{rawDims:{pageWidth:o,pageHeight:l},rotation:h}=this.parent.viewport,c=Rn.processDrawnLines({lines:e,pageWidth:o,pageHeight:l,rotation:h,innerMargin:t._INNER_MARGIN,mustSmooth:i,areContours:s});this.addSignature(c,a,n,r)}else this.div.setAttribute("data-l10n-args",JSON.stringify({description:""})),this.div.hidden=!0,this._uiManager.getSignature(this);else this.div.setAttribute("data-l10n-args",JSON.stringify({description:this.#Gc||""}));return s&&(this._isCopy=!0,this._moveAfterPaste(e,i)),this.div}setUuid(t){this.#jc=t,this.addEditToolbar()}getUuid(){return this.#jc}get description(){return this.#Gc}set description(t){this.#Gc=t,this.div&&(this.div.setAttribute("data-l10n-args",JSON.stringify({description:t})),super.addEditToolbar().then(e=>{e?.updateEditSignatureButton(t)}))}getSignaturePreview(){const{newCurves:t,areContours:e,thickness:i,width:s,height:n}=this.#Wc,r=Math.max(s,n);return{areContours:e,outline:Rn.processDrawnLines({lines:{curves:t.map(t=>({points:t})),thickness:i,width:s,height:n},pageWidth:r,pageHeight:r,rotation:0,innerMargin:0,mustSmooth:!1,areContours:e}).outline}}get toolbarButtons(){return this._uiManager.signatureManager?[["editSignature",this._uiManager.signatureManager]]:super.toolbarButtons}addSignature(e,i,s,n){const{x:r,y:a}=this,{outline:o}=this.#Wc=e;let l;this.#Uc=o instanceof Bn,this.description=s,this.#Uc?l=t.getDefaultDrawingOptions():(l=t._defaultDrawnSignatureOptions.clone(),l.updateProperties({"stroke-width":o.thickness})),this._addOutlines({drawOutlines:o,drawingOptions:l});const[,h]=this.pageDimensions;let c=i/h;c=c>=1?.5:c,this.width*=c/this.height,this.width>=1&&(c*=.9/this.width,this.width=.9),this.height=c,this.setDims(),this.x=r,this.y=a,this.center(),this._onResized(),this.onScaleChanging(),this.rotate(),this._uiManager.addToAnnotationStorage(this),this.setUuid(n),this._reportTelemetry({action:"pdfjs.signature.inserted",data:{hasBeenSaved:!!n,hasDescription:!!s}}),this.div.hidden=!1,this.#Vc&&(this.#Vc=!1,this.parent.addUndoableEditor(this))}getFromImage(e){const{rawDims:{pageWidth:i,pageHeight:s},rotation:n}=this.parent.viewport;return Rn.process(e,i,s,n,t._INNER_MARGIN)}getFromText(e,i){const{rawDims:{pageWidth:s,pageHeight:n},rotation:r}=this.parent.viewport;return Rn.extractContoursFromText(e,i,s,n,r,t._INNER_MARGIN)}getDrawnSignature(e){const{rawDims:{pageWidth:i,pageHeight:s},rotation:n}=this.parent.viewport;return Rn.processDrawnLines({lines:e,pageWidth:i,pageHeight:s,rotation:n,innerMargin:t._INNER_MARGIN,mustSmooth:!1,areContours:!1})}createDrawingOptions({areContours:e,thickness:i}){e?this._drawingOptions=t.getDefaultDrawingOptions():(this._drawingOptions=t._defaultDrawnSignatureOptions.clone(),this._drawingOptions.updateProperties({"stroke-width":i}))}serialize(t=!1){if(this.isEmpty())return null;const{lines:e,points:i}=this.serializeDraw(t),{_drawingOptions:{"stroke-width":s}}=this,n=Object.assign(super.serialize(t),{isSignature:!0,areContours:this.#Uc,color:[0,0,0],thickness:this.#Uc?0:s});return this.addComment(n),t?(n.paths={lines:e,points:i},n.uuid=this.#jc,n.isCopy=!0):n.lines=e,this.#Gc&&(n.accessibilityData={type:"Figure",alt:this.#Gc}),n}static deserializeDraw(t,e,i,s,n,r){return r.areContours?Bn.deserialize(t,e,i,s,n,r):In.deserialize(t,e,i,s,n,r)}static async deserialize(t,e,i){const s=await super.deserialize(t,e,i);return s.#Uc=t.areContours,s.description=t.accessibilityData?.alt||"",s.#jc=t.uuid,s}},Hn=class extends Gt{#$c=null;#Xc=null;#Kc=null;#Yc=null;#qc=null;#Qc="";#Tr=null;#Jc=!1;#Zc=null;#td=!1;#ed=!1;static _type="stamp";static _editorType=l.STAMP;constructor(t){super({...t,name:"stampEditor"}),this.#Yc=t.bitmapUrl,this.#qc=t.bitmapFile,this.defaultL10nId="pdfjs-editor-stamp-editor"}static initialize(t,e){Gt.initialize(t,e)}static isHandlingMimeForPasting(t){return At.has(t)}static paste(t,e){e.pasteEditor({mode:l.STAMP},{bitmapFile:t.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){return{type:"stamp",hasAltText:!!this.altTextData?.altText}}static computeTelemetryFinalData(t){const e=t.get("hasAltText");return{hasAltText:e.get(!0)??0,hasNoAltText:e.get(!1)??0}}#id(t,e=!1){t?(this.#$c=t.bitmap,e||(this.#Xc=t.id,this.#td=t.isSvg),t.file&&(this.#Qc=t.file.name),this.#sd()):this.remove()}#nd(){if(this.#Kc=null,this._uiManager.enableWaiting(!1),this.#Tr)if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#$c)this.addEditToolbar().then(()=>{this._editToolbar.hide(),this._uiManager.editAltText(this,!0)});else{if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#$c){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}}async mlGuessAltText(t=null,e=!0){if(this.hasAltTextData())return null;const{mlManager:i}=this._uiManager;if(!i)throw new Error("No ML.");if(!(await i.isEnabledFor("altText")))throw new Error("ML isn't enabled for alt text.");const{data:s,width:n,height:r}=t||this.copyCanvas(null,null,!0).imageData,a=await i.guess({name:"altText",request:{data:s,width:n,height:r,channels:s.length/(n*r)}});if(!a)throw new Error("No response from the AI service.");if(a.error)throw new Error("Error from the AI service.");if(a.cancel)return null;if(!a.output)throw new Error("No valid response from the AI service.");const o=a.output;return await this.setGuessedAltText(o),e&&!this.hasAltTextData()&&(this.altTextData={alt:o,decorative:!1}),o}#rd(){if(this.#Xc)return this._uiManager.enableWaiting(!0),void this._uiManager.imageManager.getFromId(this.#Xc).then(t=>this.#id(t,!0)).finally(()=>this.#nd());if(this.#Yc){const t=this.#Yc;return this.#Yc=null,this._uiManager.enableWaiting(!0),void(this.#Kc=this._uiManager.imageManager.getFromUrl(t).then(t=>this.#id(t)).finally(()=>this.#nd()))}if(this.#qc){const t=this.#qc;return this.#qc=null,this._uiManager.enableWaiting(!0),void(this.#Kc=this._uiManager.imageManager.getFromFile(t).then(t=>this.#id(t)).finally(()=>this.#nd()))}const t=document.createElement("input");t.type="file",t.accept=At.keys().join(",");const e=this._uiManager._signal;this.#Kc=new Promise(i=>{t.addEventListener("change",async()=>{if(t.files&&0!==t.files.length){this._uiManager.enableWaiting(!0);const e=await this._uiManager.imageManager.getFromFile(t.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),this.#id(e)}else this.remove();i()},{signal:e}),t.addEventListener("cancel",()=>{this.remove(),i()},{signal:e})}).finally(()=>this.#nd()),t.click()}remove(){this.#Xc&&(this.#$c=null,this._uiManager.imageManager.deleteId(this.#Xc),this.#Tr?.remove(),this.#Tr=null,this.#Zc&&(clearTimeout(this.#Zc),this.#Zc=null)),super.remove()}rebuild(){this.parent?(super.rebuild(),null!==this.div&&(this.#Xc&&null===this.#Tr&&this.#rd(),this.isAttachedToDOM||this.parent.add(this))):this.#Xc&&this.#rd()}onceAdded(t){this._isDraggable=!0,t&&this.div.focus()}isEmpty(){return!(this.#Kc||this.#$c||this.#Yc||this.#qc||this.#Xc||this.#Jc)}get toolbarButtons(){return[["altText",this.createAltText()]]}get isResizable(){return!0}render(){if(this.div)return this.div;let t,e;return this._isCopy&&(t=this.x,e=this.y),super.render(),this.div.hidden=!0,this.createAltText(),this.#Jc||(this.#$c?this.#sd():this.#rd()),this._isCopy&&this._moveAfterPaste(t,e),this._uiManager.addShouldRescale(this),this.div}setCanvas(t,e){const{id:i,bitmap:s}=this._uiManager.imageManager.getFromCanvas(t,e);e.remove(),i&&this._uiManager.imageManager.isValidId(i)&&(this.#Xc=i,s&&(this.#$c=s),this.#Jc=!1,this.#sd())}_onResized(){this.onScaleChanging()}onScaleChanging(){this.parent&&(null!==this.#Zc&&clearTimeout(this.#Zc),this.#Zc=setTimeout(()=>{this.#Zc=null,this.#ad()},200))}#sd(){const{div:t}=this;let{width:e,height:i}=this.#$c;const[s,n]=this.pageDimensions,r=.75;if(this.width)e=this.width*s,i=this.height*n;else if(e>r*s||i>r*n){const t=Math.min(r*s/e,r*n/i);e*=t,i*=t}this._uiManager.enableWaiting(!1);const a=this.#Tr=document.createElement("canvas");a.setAttribute("role","img"),this.addContainer(a),this.width=e/s,this.height=i/n,this.setDims(),this._initialOptions?.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&!this.annotationElementId||(t.hidden=!1),this.#ad(),this.#ed||(this.parent.addUndoableEditor(this),this.#ed=!0),this._reportTelemetry({action:"inserted_image"}),this.#Qc&&this.div.setAttribute("aria-description",this.#Qc),this.annotationElementId||this._uiManager.a11yAlert(Gt._l10nAlert.stamp)}copyCanvas(t,e,i=!1){t||=224;const{width:s,height:n}=this.#$c,r=new Q;let a=this.#$c,o=s,l=n,h=null;if(e){if(s>e||n>e){const t=Math.min(e/s,e/n);o=Math.floor(s*t),l=Math.floor(n*t)}h=document.createElement("canvas");const t=h.width=Math.ceil(o*r.sx),i=h.height=Math.ceil(l*r.sy);this.#td||(a=this.#od(t,i));const c=h.getContext("2d");c.filter=this._uiManager.hcmFilter;let d="white",u="#cfcfd8";"none"!==this._uiManager.hcmFilter?u="black":xt.isDarkMode&&(d="#8f8f9d",u="#42414d");const p=15,g=p*r.sx,m=p*r.sy,f=new OffscreenCanvas(2*g,2*m),b=f.getContext("2d");b.fillStyle=d,b.fillRect(0,0,2*g,2*m),b.fillStyle=u,b.fillRect(0,0,g,m),b.fillRect(g,m,g,m),c.fillStyle=c.createPattern(f,"repeat"),c.fillRect(0,0,t,i),c.drawImage(a,0,0,a.width,a.height,0,0,t,i)}let c=null;if(i){let e,i;if(r.symmetric&&a.width<t&&a.height<t)e=a.width,i=a.height;else if(a=this.#$c,s>t||n>t){const r=Math.min(t/s,t/n);e=Math.floor(s*r),i=Math.floor(n*r),this.#td||(a=this.#od(e,i))}const o=new OffscreenCanvas(e,i).getContext("2d",{willReadFrequently:!0});o.drawImage(a,0,0,a.width,a.height,0,0,e,i),c={width:e,height:i,data:o.getImageData(0,0,e,i).data}}return{canvas:h,width:o,height:l,imageData:c}}#od(t,e){const{width:i,height:s}=this.#$c;let n=i,r=s,a=this.#$c;for(;n>2*t||r>2*e;){const i=n,s=r;n>2*t&&(n=Math.ceil(n/2)),r>2*e&&(r=Math.ceil(r/2));const o=new OffscreenCanvas(n,r);o.getContext("2d").drawImage(a,0,0,i,s,0,0,n,r),a=o.transferToImageBitmap()}return a}#ad(){const[t,e]=this.parentDimensions,{width:i,height:s}=this,n=new Q,r=Math.ceil(i*t*n.sx),a=Math.ceil(s*e*n.sy),o=this.#Tr;if(!o||o.width===r&&o.height===a)return;o.width=r,o.height=a;const l=this.#td?this.#$c:this.#od(r,a),h=o.getContext("2d");h.filter=this._uiManager.hcmFilter,h.drawImage(l,0,0,l.width,l.height,0,0,r,a)}#ld(t){if(t){if(this.#td){const t=this._uiManager.imageManager.getSvgUrl(this.#Xc);if(t)return t}const t=document.createElement("canvas");return({width:t.width,height:t.height}=this.#$c),t.getContext("2d").drawImage(this.#$c,0,0),t.toDataURL()}if(this.#td){const[t,e]=this.pageDimensions,i=Math.round(this.width*t*V.PDF_TO_CSS_UNITS),s=Math.round(this.height*e*V.PDF_TO_CSS_UNITS),n=new OffscreenCanvas(i,s);return n.getContext("2d").drawImage(this.#$c,0,0,this.#$c.width,this.#$c.height,0,0,i,s),n.transferToImageBitmap()}return structuredClone(this.#$c)}static async deserialize(t,e,i){let s=null,n=!1;if(t instanceof on){const{data:{rect:r,rotation:o,id:h,structParent:c,popupRef:d,richText:u,contentsObj:p,creationDate:g,modificationDate:m},container:f,parent:{page:{pageNumber:b}},canvas:y}=t;let v,w;y?(delete t.canvas,({id:v,bitmap:w}=i.imageManager.getFromCanvas(f.id,y)),y.remove()):(n=!0,t._hasNoCanvas=!0);const A=(await e._structTree.getAriaAttributes(`${a}${h}`))?.get("aria-label")||"";s=t={annotationType:l.STAMP,bitmapId:v,bitmap:w,pageIndex:b-1,rect:r.slice(0),rotation:o,annotationElementId:h,id:h,deleted:!1,accessibilityData:{decorative:!1,altText:A},isSvg:!1,structParent:c,popupRef:d,richText:u,comment:p?.str||null,creationDate:g,modificationDate:m}}const r=await super.deserialize(t,e,i),{rect:o,bitmap:h,bitmapUrl:c,bitmapId:d,isSvg:u,accessibilityData:p}=t;n?(i.addMissingCanvas(t.id,r),r.#Jc=!0):d&&i.imageManager.isValidId(d)?(r.#Xc=d,h&&(r.#$c=h)):r.#Yc=c,r.#td=u;const[g,m]=r.pageDimensions;return r.width=(o[2]-o[0])/g,r.height=(o[3]-o[1])/m,p&&(r.altTextData=p),r._initialData=s,t.comment&&r.setCommentData(t),r.#ed=!!s,r}serialize(t=!1,e=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const i=Object.assign(super.serialize(t),{bitmapId:this.#Xc,isSvg:this.#td});if(this.addComment(i),t)return i.bitmapUrl=this.#ld(!0),i.accessibilityData=this.serializeAltText(!0),i.isCopy=!0,i;const{decorative:s,altText:n}=this.serializeAltText(!1);if(!s&&n&&(i.accessibilityData={type:"Figure",alt:n}),this.annotationElementId){const t=this.#Ll(i);if(t.isSame)return null;if(t.isSameAltText)delete i.accessibilityData;else{const t=this._initialData.structParent??-1;i.accessibilityData?i.accessibilityData.structParent=t:t>=0&&(i.accessibilityData={type:"Figure",alt:"",structParent:t})}return i.id=this.annotationElementId,delete i.bitmapId,i}if(null===e)return i;e.stamps||=/* @__PURE__ */new Map;const r=this.#td?(i.rect[2]-i.rect[0])*(i.rect[3]-i.rect[1]):null;if(e.stamps.has(this.#Xc)){if(this.#td){const t=e.stamps.get(this.#Xc);r>t.area&&(t.area=r,t.serialized.bitmap.close(),t.serialized.bitmap=this.#ld(!1))}}else e.stamps.set(this.#Xc,{area:r,serialized:i}),i.bitmap=this.#ld(!1);return i}#Ll(t){const{pageIndex:e,accessibilityData:{altText:i}}=this._initialData,s=t.pageIndex===e,n=(t.accessibilityData?.alt||"")===i;return{isSame:!this.hasEditedComment&&!this._hasBeenMoved&&!this._hasBeenResized&&s&&n,isSameAltText:n}}renderAnnotationElement(t){return this.deleted?(t.hide(),null):(t.updateEdited({rect:this.getPDFRect(),popup:this.comment}),null)}},Un=class t{#bl;#hd=!1;#cd=null;#dd=null;#ud=null;#pd=/* @__PURE__ */new Map;#gd=!1;#md=!1;#fd=!1;#bd=null;#yd=null;#vd=null;#wd=null;#Ad=null;#xd=-1;#y;static _initialized=!1;static#Z=new Map([un,Ln,Hn,_n,zn].map(t=>[t._editorType,t]));constructor({uiManager:e,pageIndex:i,div:s,structTreeLayer:n,accessibilityManager:r,annotationLayer:a,drawLayer:o,textLayer:l,viewport:h,l10n:c}){const d=[...t.#Z.values()];if(!t._initialized){t._initialized=!0;for(const t of d)t.initialize(c,e)}e.registerEditorTypes(d),this.#y=e,this.pageIndex=i,this.div=s,this.#bl=r,this.#cd=a,this.viewport=h,this.#vd=l,this.drawLayer=o,this._structTree=n,this.#y.addLayer(this)}get isEmpty(){return 0===this.#pd.size}get isInvisible(){return this.isEmpty&&this.#y.getMode()===l.NONE}updateToolbar(t){this.#y.updateToolbar(t)}updateMode(e=this.#y.getMode()){switch(this.#Cd(),e){case l.NONE:return this.div.classList.toggle("nonEditing",!0),this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),void this.disableClick();case l.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case l.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);const{classList:i}=this.div;if(i.toggle("nonEditing",!1),e===l.POPUP)i.toggle("commentEditing",!0);else{i.toggle("commentEditing",!1);for(const s of t.#Z.values())i.toggle(`${s._type}Editing`,e===s._editorType)}this.div.hidden=!1}hasTextLayer(t){return t===this.#vd?.div}setEditingState(t){this.#y.setEditingState(t)}addCommands(t){this.#y.addCommands(t)}cleanUndoStack(t){this.#y.cleanUndoStack(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){this.#cd?.togglePointerEvents(t)}get#Sd(){return 0!==this.#pd.size?this.#pd.values():this.#y.getEditors(this.pageIndex)}async enable(){this.#fd=!0,this.div.tabIndex=0,this.togglePointerEvents(!0),this.div.classList.toggle("nonEditing",!1),this.#Ad?.abort(),this.#Ad=null;const t=/* @__PURE__ */new Set;for(const i of this.#Sd)i.enableEditing(),i.show(!0),i.annotationElementId&&(this.#y.removeChangedExistingAnnotation(i),t.add(i.annotationElementId));const e=this.#cd;if(e)for(const i of e.getEditableAnnotations()){if(i.hide(),this.#y.isDeletedAnnotationElement(i.data.id)||t.has(i.data.id))continue;const e=await this.deserialize(i);e&&(this.addOrRebuild(e),e.enableEditing())}this.#fd=!1,this.#y._eventBus.dispatch("editorsrendered",{source:this,pageNumber:this.pageIndex+1})}disable(){if(this.#md=!0,this.div.tabIndex=-1,this.togglePointerEvents(!1),this.div.classList.toggle("nonEditing",!0),this.#vd&&!this.#Ad){this.#Ad=new AbortController;const t=this.#y.combinedSignal(this.#Ad);this.#vd.div.addEventListener("pointerdown",t=>{const{clientX:e,clientY:i,timeStamp:s}=t;if(s-this.#xd>500)return void(this.#xd=s);this.#xd=-1;const{classList:n}=this.div;n.toggle("getElements",!0);const r=document.elementsFromPoint(e,i);if(n.toggle("getElements",!1),!this.div.contains(r[0]))return;let a;const l=new RegExp(`^${o}[0-9]+$`);for(const o of r)if(l.test(o.id)){a=o.id;break}if(!a)return;const h=this.#pd.get(a);null===h?.annotationElementId&&(yt(t),h.dblclick(t))},{signal:t,capture:!0})}const e=this.#cd,i=[];if(e){const t=/* @__PURE__ */new Map,s=/* @__PURE__ */new Map;for(const e of this.#Sd)e.disableEditing(),e.annotationElementId?null===e.serialize()?(s.set(e.annotationElementId,e),this.getEditableAnnotation(e.annotationElementId)?.show(),e.remove()):t.set(e.annotationElementId,e):i.push(e);for(const i of e.getEditableAnnotations()){const{id:e}=i.data;if(this.#y.isDeletedAnnotationElement(e)){i.updateEdited({deleted:!0});continue}let n=s.get(e);n?(n.resetAnnotationElement(i),n.show(!1),i.show()):(n=t.get(e),n&&(this.#y.addChangedExistingAnnotation(n),n.renderAnnotationElement(i)&&n.show(!1)),i.show())}}this.#Cd(),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const n of t.#Z.values())s.remove(`${n._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),e?.updateFakeAnnotations(i),this.#md=!1}getEditableAnnotation(t){return this.#cd?.getEditableAnnotation(t)||null}setActiveEditor(t){this.#y.getActive()!==t&&this.#y.setActiveEditor(t)}enableTextSelection(){if(this.div.tabIndex=-1,this.#vd?.div&&!this.#wd){this.#wd=new AbortController;const t=this.#y.combinedSignal(this.#wd);this.#vd.div.addEventListener("pointerdown",this.#Td.bind(this),{signal:t}),this.#vd.div.classList.add("highlighting")}}disableTextSelection(){this.div.tabIndex=0,this.#vd?.div&&this.#wd&&(this.#wd.abort(),this.#wd=null,this.#vd.div.classList.remove("highlighting"))}#Td(t){this.#y.unselectAll();const{target:e}=t;if(e===this.#vd.div||("img"===e.getAttribute("role")||e.classList.contains("endOfContent")||e.classList.contains("textLayerImages")||e.classList.contains("textLayerImagePlaceholder"))&&this.#vd.div.contains(e)){const{isMac:e}=L.platform;if(0!==t.button||t.ctrlKey&&e)return;this.#y.showAllEditors("highlight",!0,!0),_n.startDrawing(this,this.#y,"ltr"===this.#y.direction,t),t.preventDefault()}}enableClick(){if(this.#dd)return;this.#dd=new AbortController;const t=this.#y.combinedSignal(this.#dd);this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t});const e=this.pointerup.bind(this);this.div.addEventListener("pointerup",e,{signal:t}),this.div.addEventListener("pointercancel",e,{signal:t})}disableClick(){this.#dd?.abort(),this.#dd=null}attach(t){this.#pd.set(t.id,t);const{annotationElementId:e}=t;e&&this.#y.isDeletedAnnotationElement(e)&&this.#y.removeDeletedAnnotationElement(t)}detach(t){this.#pd.delete(t.id),this.#bl?.removePointerInTextLayer(t.contentDiv),!this.#md&&t.annotationElementId&&this.#y.addDeletedAnnotationElement(t)}remove(t){this.detach(t),this.#y.removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){t.parent!==this&&(t.parent&&t.annotationElementId&&(this.#y.addDeletedAnnotationElement(t),Gt.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),t.parent?.detach(t),t.setParent(this),t.div&&t.isAttachedToDOM&&(t.div.remove(),this.div.append(t.div)))}add(t){if(t.parent!==this||!t.isAttachedToDOM){if(this.changeParent(t),this.#y.addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!this.#fd),this.#y.addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!this.#ud&&(t._focusEventsAllowed=!1,this.#ud=setTimeout(()=>{this.#ud=null,t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this.#y._signal}),e.focus())},0)),t._structTreeParentId=this.#bl?.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){t.needsToBeRebuilt()?(t.parent||=this,t.rebuild(),t.show()):this.add(t)}addUndoableEditor(t){this.addCommands({cmd:()=>t._uiManager.rebuild(t),undo:()=>{t.remove()},mustExec:!1})}getEditorByUID(t){for(const e of this.#pd.values())if(e.uid===t)return e;return null}get#_d(){return t.#Z.get(this.#y.getMode())}combinedSignal(t){return this.#y.combinedSignal(t)}#kd(t){const e=this.#_d;return e?new e.prototype.constructor(t):null}canCreateNewEmptyEditor(){return this.#_d?.canCreateNewEmptyEditor()}async pasteEditor(t,e){this.updateToolbar(t),await this.#y.updateMode(t.mode);const{offsetX:i,offsetY:s}=this.#Ed(),n=this.#y.getId(),r=this.#kd({parent:this,id:n,x:i,y:s,uiManager:this.#y,isCentered:!0,...e});r&&this.add(r)}async deserialize(e){return await(t.#Z.get(e.annotationType??e.annotationEditorType)?.deserialize(e,this,this.#y))||null}createAndAddNewEditor(t,e,i={}){const s=this.#y.getId(),n=this.#kd({parent:this,id:s,x:t.offsetX,y:t.offsetY,uiManager:this.#y,isCentered:e,...i});return n&&this.add(n),n}get boundingClientRect(){return this.div.getBoundingClientRect()}#Ed(){const{x:t,y:e,width:i,height:s}=this.boundingClientRect,n=Math.max(0,t),r=Math.max(0,e),a=(n+Math.min(window.innerWidth,t+i))/2-t,o=(r+Math.min(window.innerHeight,e+s))/2-e,[l,h]=this.viewport.rotation%180==0?[a,o]:[o,a];return{offsetX:l,offsetY:h}}addNewEditor(t={}){this.createAndAddNewEditor(this.#Ed(),!0,t)}setSelected(t){this.#y.setSelected(t)}toggleSelected(t){this.#y.toggleSelected(t)}unselect(t){this.#y.unselect(t)}pointerup(t){const{isMac:e}=L.platform;if(0!==t.button||t.ctrlKey&&e)return;if(t.target!==this.div)return;if(!this.#gd)return;if(this.#gd=!1,this.#_d?.isDrawer&&this.#_d.supportMultipleDrawings)return;if(!this.#hd)return void(this.#hd=!0);const i=this.#y.getMode();i!==l.STAMP&&i!==l.POPUP&&i!==l.SIGNATURE?this.createAndAddNewEditor(t,!1):this.#y.unselectAll()}pointerdown(t){if(this.#y.getMode()===l.HIGHLIGHT&&this.enableTextSelection(),this.#gd)return void(this.#gd=!1);const{isMac:e}=L.platform;if(0!==t.button||t.ctrlKey&&e)return;if(t.target!==this.div)return;if(this.#gd=!0,this.#_d?.isDrawer)return void this.startDrawingSession(t);const i=this.#y.getActive();this.#hd=!i||i.isEmpty()}startDrawingSession(t){if(this.div.focus({preventScroll:!0}),this.#bd)return void this.#_d.startDrawing(this,this.#y,!1,t);this.#y.setCurrentDrawingSession(this),this.#bd=new AbortController;const e=this.#y.combinedSignal(this.#bd);this.div.addEventListener("blur",({relatedTarget:t})=>{t&&!this.div.contains(t)&&(this.#yd=null,this.commitOrRemove())},{signal:e}),this.#_d.startDrawing(this,this.#y,!1,t)}pause(t){if(t){const{activeElement:t}=document;return void(this.div.contains(t)&&(this.#yd=t))}this.#yd&&setTimeout(()=>{this.#yd?.focus(),this.#yd=null},0)}endDrawingSession(t=!1){return this.#bd?(this.#y.setCurrentDrawingSession(null),this.#bd.abort(),this.#bd=null,this.#yd=null,this.#_d.endDrawing(t)):null}findNewParent(t,e,i){const s=this.#y.findParent(e,i);return null!==s&&s!==this&&(s.changeParent(t),!0)}commitOrRemove(){return!!this.#bd&&(this.endDrawingSession(),!0)}onScaleChanging(){this.#bd&&this.#_d.onScaleChangingWhenDrawing(this)}destroy(){this.commitOrRemove(),this.#y.getActive()?.parent===this&&(this.#y.commitOrRemove(),this.#y.setActiveEditor(null)),this.#ud&&(clearTimeout(this.#ud),this.#ud=null);for(const t of this.#pd.values())this.#bl?.removePointerInTextLayer(t.contentDiv),t.setParent(null),t.isAttachedToDOM=!1,t.div.remove();this.div=null,this.#pd.clear(),this.#y.removeLayer(this)}#Cd(){for(const t of this.#pd.values())t.isEmpty()&&t.remove()}async render({viewport:t}){this.viewport=t,wt(this.div,t);for(const e of this.#y.getEditors(this.pageIndex))this.add(e),e.rebuild();await this.#y.findClonesForPage(this),this.div.hidden=this.isEmpty,this.updateMode()}update({viewport:t}){this.#y.commitOrRemove(),this.#Cd();const e=this.viewport.rotation,i=t.rotation;if(this.viewport=t,wt(this.div,{rotation:i}),e!==i)for(const s of this.#pd.values())s.rotate(i)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return this.#y.viewParameters.realScale}};function Gn(t,e){return t===e?0:t.compareDocumentPosition(e)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1}function Wn(t){return t?t.nodeType===Node.ELEMENT_NODE?t.closest(".textLayer"):t.parentElement?.closest(".textLayer")||null:null}function jn(t,e,i,s){if(t===i)return e<=s;const n=t.compareDocumentPosition(i);return!!(n&Node.DOCUMENT_POSITION_FOLLOWING)||!(n&Node.DOCUMENT_POSITION_PRECEDING)&&null}function Vn(t,e,i){if(t.nodeType!==Node.ELEMENT_NODE||!t.classList.contains("textLayer")||e!==t.childNodes.length)return{container:t,offset:e};let s=t.lastChild;return s?.nodeType===Node.ELEMENT_NODE&&s.classList.contains("endOfContent")&&(s=s.previousSibling),s&&i.contains(s)?s.nodeType===Node.TEXT_NODE?{container:s,offset:s.textContent.length}:{container:s,offset:s.childNodes.length}:null}var $n=class t{#Oo=null;#Md=/* @__PURE__ */new Map;#vd=null;#nt=null;#Ct=null;#Pd=null;#Dd=/* @__PURE__ */new Map;static#_=0;static#Id=0;static#Fd=null;static#Ld=/* @__PURE__ */new Set;static#Bd=!1;static#Rd=/* @__PURE__ */new Set;static#Od=/* @__PURE__ */new WeakMap;constructor({filterFactory:e=null,pageColors:i=null,pageIndex:s,textLayer:n=null}){if(this.pageIndex=s,this.#nt=e,this.#Ct=i,n){const e=t.#Od.get(n);if(e?.selectionDiv&&(e.selectionDiv.remove(),t.#Ld.delete(e.selectionDiv)),t.#Od.set(n,{drawLayer:this}),t.#Rd.add(n),this.#vd=n,this.#Pd=new MutationObserver(e=>{if(this.#Oo&&this.#vd?.isConnected&&t.#Nd())for(const{addedNodes:i}of e)for(const e of i)if(e.nodeType===Node.ELEMENT_NODE&&e.classList.contains("endOfContent"))return void t.#zt()}),this.#Pd.observe(n,{childList:!0}),null===t.#Fd){t.#Fd=new AbortController;const{signal:e}=t.#Fd;document.addEventListener("selectionchange",t.#zt.bind(t),{signal:e}),document.addEventListener("pointerdown",()=>{t.#Bd=!0},{signal:e}),document.addEventListener("pointerup",()=>{t.#Bd=!1},{signal:e}),window.addEventListener("blur",()=>{t.#Bd=!1},{signal:e})}}}setParent(e){if(!this.#Oo)return this.#Oo=e,void(this.#vd?.isConnected&&t.#Nd()&&t.#zt());if(this.#Oo!==e){if(this.#Md.size>0)for(const t of this.#Md.values())t.remove(),e.append(t);this.#Oo=e}}static#zd(t){const e=this.#Od.get(t);e?.selectionDiv&&(e.selectionDiv.remove(),this.#Ld.delete(e.selectionDiv),e.selectionDiv=null,e.path=null)}static#Nd(){const t=document.getSelection();return!!t&&!t.isCollapsed}static#Hd(){return this.#Rd.keys().filter(t=>t.isConnected).toArray().sort(Gn)}static#zt(){const e=document.getSelection();if(!e||e.isCollapsed){for(const t of this.#Ld)t.remove();return void this.#Ld.clear()}const i=/* @__PURE__ */new WeakMap,s=this.#Hd(),n=[];for(let t=0,a=e.rangeCount;t<a;t++){const i=e.getRangeAt(t);if(i.collapsed)continue;let{startContainer:r,startOffset:a,endContainer:o,endOffset:l}=i,h=Wn(r),c=Wn(o);const d=null===h,u=null===c;if(this.#Bd&&d!==u)return;if(1===e.rangeCount){const{anchorNode:t,anchorOffset:i,focusNode:s,focusOffset:n}=e,d=Wn(t),u=Wn(s),p=jn(t,i,s,n);d&&u&&null!==p&&(p?(r=t,a=i,h=d,o=s,l=n,c=u):(r=s,a=n,h=u,o=t,l=i,c=d))}const p=s.filter(t=>i.intersectsNode(t));if(0===p.length)continue;let g=!1;if(h||(h=p[0],r=h,a=0,g=!0),c||(c=p.at(-1),o=c,l=c.childNodes.length,g=!0),o.nodeType===Node.ELEMENT_NODE)if(o.classList.contains("endOfContent")){const t=o.previousSibling;if(!t)continue;o=t,l=t.nodeType===Node.TEXT_NODE?t.textContent.length:t.childNodes.length}else if(o.classList.contains("textLayer")&&o.childNodes.length===l){const t=Vn(o,l,c);if(!t)continue;o=t.container,l=t.offset}if(r.nodeType===Node.ELEMENT_NODE){const t=Vn(r,a,h);if(!t)continue;r=t.container,a=t.offset}if(h!==c||g||!p.includes(h))for(const t of p){const e=t.firstChild;if(!e)continue;const i=document.createRange();if(t===h?i.setStart(r,a):i.setStartBefore(e),t===c)i.setEnd(o,l);else{const e=t.lastChild;if(!e)continue;if(e.nodeType===Node.ELEMENT_NODE&&e.classList.contains("endOfContent")){const t=e.previousSibling;if(!t)continue;i.setEndAfter(t)}else i.setEndAfter(e)}i.collapsed||n.push([i,t])}else n.push([i,h])}const r=new Set(n.map(t=>t[1]));for(const t of this.#Rd)r.has(t)||this.#zd(t);for(const[a,o]of n){const e=t.#Od.get(o);if(!e)continue;let s=i.get(o);if(!s){const t=o.getBoundingClientRect();s=(e,i,s,n)=>({x:(e-t.x)/t.width,y:(i-t.y)/t.height,width:s/t.width,height:n/t.height}),i.set(o,s)}const n=[];for(let{x:t,y:i,width:o,height:c}of a.getClientRects())0!==o&&0!==c&&(({x:t,y:i,width:o,height:c}=s(t,i,o,c)),1===o&&1===c||n.push(`M${t} ${i} h${o} v${c} h-${o} Z`));if(0===n.length)continue;const r=e.drawLayer;let l=e.selectionDiv,h=e.path;if(!l){const i="clip_selection_"+t.#Id++;l=document.createElement("div"),l.className="selection",l.style.clipPath=`url(#${i})`;const s=r.#nt?.createSelectionStyle(r.#Ct);if(s)for(const[t,e]of Object.entries(s))l.style.setProperty(t,e);const n=t._svgFactory.create(1,1,!0);n.setAttribute("aria-hidden","true"),n.setAttribute("width","100%"),n.setAttribute("height","100%");const a=t._svgFactory.createElement("clipPath");a.setAttribute("id",i),a.setAttribute("clipPathUnits","objectBoundingBox"),h=t._svgFactory.createElement("path"),a.append(h),n.append(a),l.append(n),e.path=h,e.selectionDiv=l}r.#Oo&&l.parentNode!==r.#Oo&&(r.#Oo.append(l),this.#Ld.add(l)),h.setAttribute("d",n.join(" "))}}static get _svgFactory(){return T(this,"_svgFactory",new Ds)}static#Ud(t,[e,i,s,n]){const{style:r}=t;r.top=100*i+"%",r.left=100*e+"%",r.width=100*s+"%",r.height=100*n+"%"}#Gd(){const e=t._svgFactory.create(1,1,!0);return this.#Oo.append(e),e.setAttribute("aria-hidden","true"),e}#Wd(e,i){const s=t._svgFactory.createElement("clipPath");e.append(s);const n=`clip_${i}`;s.setAttribute("id",n),s.setAttribute("clipPathUnits","objectBoundingBox");const r=t._svgFactory.createElement("use");return s.append(r),r.setAttribute("href",`#${i}`),r.classList.add("clip"),n}#jd(t,e){for(const[i,s]of Object.entries(e))null===s?t.removeAttribute(i):t.setAttribute(i,s)}draw(e,i=!1,s=!1){const n=t.#_++,r=this.#Gd(),a=t._svgFactory.createElement("defs");r.append(a);const o=t._svgFactory.createElement("path");a.append(o);const l=`path_${n}`;o.setAttribute("id",l),o.setAttribute("vector-effect","non-scaling-stroke"),i&&this.#Dd.set(n,o);const h=s?this.#Wd(a,l):null,c=t._svgFactory.createElement("use");return r.append(c),c.setAttribute("href",`#${l}`),this.updateProperties(r,e),this.#Md.set(n,r),{id:n,clipPathId:`url(#${h})`}}drawOutline(e,i){const s=t.#_++,n=this.#Gd(),r=t._svgFactory.createElement("defs");n.append(r);const a=t._svgFactory.createElement("path");r.append(a);const o=`path_${s}`;let l;if(a.setAttribute("id",o),a.setAttribute("vector-effect","non-scaling-stroke"),i){const e=t._svgFactory.createElement("mask");r.append(e),l=`mask_${s}`,e.setAttribute("id",l),e.setAttribute("maskUnits","objectBoundingBox");const i=t._svgFactory.createElement("rect");e.append(i),i.setAttribute("width","1"),i.setAttribute("height","1"),i.setAttribute("fill","white");const n=t._svgFactory.createElement("use");e.append(n),n.setAttribute("href",`#${o}`),n.setAttribute("stroke","none"),n.setAttribute("fill","black"),n.setAttribute("fill-rule","nonzero"),n.classList.add("mask")}const h=t._svgFactory.createElement("use");n.append(h),h.setAttribute("href",`#${o}`),l&&h.setAttribute("mask",`url(#${l})`);const c=h.cloneNode();return n.append(c),h.classList.add("mainOutline"),c.classList.add("secondaryOutline"),this.updateProperties(n,e),this.#Md.set(s,n),s}finalizeDraw(t,e){this.#Dd.delete(t),this.updateProperties(t,e)}updateProperties(e,i){if(!i)return;const{root:s,bbox:n,rootClass:r,path:a}=i,o="number"==typeof e?this.#Md.get(e):e;if(o){if(s&&this.#jd(o,s),n&&t.#Ud(o,n),r){const{classList:t}=o;for(const[e,i]of Object.entries(r))t.toggle(e,i)}if(a){const t=o.firstElementChild.firstElementChild;this.#jd(t,a)}}}updateParent(t,e){if(e===this)return;const i=this.#Md.get(t);i&&(e.#Oo.append(i),this.#Md.delete(t),e.#Md.set(t,i))}remove(t){this.#Dd.delete(t),null!==this.#Oo&&(this.#Md.get(t).remove(),this.#Md.delete(t))}destroy(){this.#Oo=null;for(const t of this.#Md.values())t.remove();this.#Md.clear(),this.#Dd.clear(),this.#Pd?.disconnect(),this.#Pd=null,this.#vd&&(t.#Od.get(this.#vd)?.drawLayer===this&&(t.#zd(this.#vd),t.#Od.delete(this.#vd),t.#Rd.delete(this.#vd),0===t.#Rd.size&&(t.#Fd?.abort(),t.#Fd=null,t.#Bd=!1)),this.#vd=null)}};function Xn(t){return`${(100*t).toFixed(2)}%`}var Kn=class t{#Vd=[];#$d=/* @__PURE__ */new Map;#Xd=null;#Kd=0;#oa=0;#aa=0;static#Yd=null;constructor(t,e,i,s){this.#Kd=t,this.#Vd=e,this.#oa=i.rawDims.pageWidth,this.#aa=i.rawDims.pageHeight,this.#Xd=s}render(){const e=document.createElement("div");e.className="textLayerImages";for(let t=0;t<this.#Vd.length;t+=6){const i=this.#qd(this.#Vd.subarray(t,t+6));i&&e.append(i)}return e.addEventListener("contextmenu",e=>{if(!(e.target instanceof HTMLCanvasElement))return;const i=e.target,s=this.#$d.get(i);if(!s)return;const n=t.#Yd?.deref();if(n===i)return;n&&(n.width=0,n.height=0),t.#Yd=new WeakRef(i);const{inverseTransform:r,x1:a,y1:o,width:l,height:h}=s,c=this.#Xd(),d=Math.ceil(a*c.width),u=Math.ceil(o*c.height),p=Math.floor((a+l/this.#oa)*c.width),g=Math.floor((o+h/this.#aa)*c.height);i.width=p-d,i.height=g-u;const m=i.getContext("2d");m.setTransform(...r),m.translate(-d,-u),m.drawImage(c,0,0)}),e}#qd([t,e,i,s,n,r]){const a=Math.hypot((n-t)*this.#oa,(r-e)*this.#aa),o=Math.hypot((i-t)*this.#oa,(s-e)*this.#aa);if(a<this.#Kd||o<this.#Kd)return null;const l=[(n-t)*this.#oa/a,(r-e)*this.#aa/a,(i-t)*this.#oa/o,(s-e)*this.#aa/o,0,0],h=B.inverseTransform(l),c=document.createElement("canvas");return c.className="textLayerImagePlaceholder",c.width=0,c.height=0,Object.assign(c.style,{opacity:0,position:"absolute",left:Xn(t),top:Xn(e),width:Xn(a/this.#oa),height:Xn(o/this.#aa),transformOrigin:"0% 0%",transform:`matrix(${l.join(",")})`}),this.#$d.set(c,{inverseTransform:h,width:a,height:o,x1:t,y1:e}),c}};globalThis._pdfjsTestingUtils={HighlightOutliner:wn},globalThis.pdfjsLib={AbortException:I,AnnotationEditorLayer:Un,AnnotationEditorParamsType:h,AnnotationEditorType:l,AnnotationEditorUIManager:Bt,AnnotationLayer:cn,AnnotationMode:r,AnnotationType:u,applyOpacity:J,build:Ss,ColorPicker:Ts,createValidAbsoluteUrl:x,CSSConstants:Ct,DOMSVGFactory:Ds,DrawLayer:$n,FeatureTest:L,fetchData:dt,findContrastColor:nt,getDocument:gs,getFilenameFromUrl:gt,getPdfFilenameFromUrl:mt,getRGB:K,getRGBA:X,getUuid:z,GlobalWorkerOptions:Wi,ImageKind:d,InvalidPDFException:M,isDataScheme:ut,isPdfFile:pt,isValidExplicitDest:Zt,makeArr:H,makeMap:U,makeObj:G,makeSet:W,MathClamp:j,noContextMenu:bt,normalizeUnicode:N,OPS:g,OutputScale:Q,PasswordException:k,PasswordResponses:m,PDFDataRangeTransport:fs,PDFDateString:vt,PDFWorker:vs,PermissionFlag:c,PixelsPerInch:V,RenderingCancelledException:$,renderRichText:St,ResponseException:P,setLayerDimensions:wt,shadow:T,SignatureExtractor:Rn,stopEvent:yt,SupportedImageMimeTypes:At,TextLayer:ps,TextLayerImages:Kn,TouchManager:Ut,updateUrlHash:C,Util:B,VerbosityLevel:p,version:Cs,XfaLayer:ct};export{I as AbortException,Un as AnnotationEditorLayer,h as AnnotationEditorParamsType,l as AnnotationEditorType,Bt as AnnotationEditorUIManager,cn as AnnotationLayer,r as AnnotationMode,u as AnnotationType,Ct as CSSConstants,Ts as ColorPicker,Ds as DOMSVGFactory,$n as DrawLayer,L as FeatureTest,Wi as GlobalWorkerOptions,d as ImageKind,M as InvalidPDFException,j as MathClamp,g as OPS,Q as OutputScale,fs as PDFDataRangeTransport,vt as PDFDateString,vs as PDFWorker,k as PasswordException,m as PasswordResponses,c as PermissionFlag,V as PixelsPerInch,$ as RenderingCancelledException,P as ResponseException,Rn as SignatureExtractor,At as SupportedImageMimeTypes,ps as TextLayer,Kn as TextLayerImages,Ut as TouchManager,B as Util,p as VerbosityLevel,ct as XfaLayer,J as applyOpacity,Ss as build,x as createValidAbsoluteUrl,dt as fetchData,nt as findContrastColor,gs as getDocument,gt as getFilenameFromUrl,mt as getPdfFilenameFromUrl,K as getRGB,X as getRGBA,z as getUuid,ut as isDataScheme,pt as isPdfFile,Zt as isValidExplicitDest,H as makeArr,U as makeMap,G as makeObj,W as makeSet,bt as noContextMenu,N as normalizeUnicode,St as renderRichText,wt as setLayerDimensions,T as shadow,yt as stopEvent,C as updateUrlHash,Cs as version};
|