yamlover 0.3.21 → 0.3.22

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.
@@ -1,4 +1,4 @@
1
- import{g as Yn,r as R,j as K,k as Kn,h as Qn,e as Jn,c as Zn,D as ai,f as tr,b as er}from"./index-DqdQvRi4.js";import{u as sr}from"./paged-COP9CRTO.js";const Et=typeof process=="object"&&process+""=="[object process]"&&!process.versions.nw&&!(process.versions.electron&&process.type&&process.type!=="browser"),Ts=[.001,0,0,.001,0,0],As=1.35,Rt={ANY:1,DISPLAY:2,PRINT:4,ANNOTATIONS_FORMS:16,ANNOTATIONS_STORAGE:32,ANNOTATIONS_DISABLE:64,IS_EDITING:128,OPLIST:256},Wt={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},Me="pdfjs_internal_editor_",V={DISABLE:-1,NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15,POPUP:16,SIGNATURE:101,COMMENT:102},Q={RESIZE:1,CREATE:2,FREETEXT_SIZE:11,FREETEXT_COLOR:12,FREETEXT_OPACITY:13,INK_COLOR:21,INK_THICKNESS:22,INK_OPACITY:23,HIGHLIGHT_COLOR:31,HIGHLIGHT_THICKNESS:32,HIGHLIGHT_FREE:33,HIGHLIGHT_SHOW_ALL:34,DRAW_STEP:41},$i={PRINT:4,MODIFY_CONTENTS:8,COPY:16,MODIFY_ANNOTATIONS:32,FILL_INTERACTIVE_FORMS:256,COPY_FOR_ACCESSIBILITY:512,ASSEMBLE:1024,PRINT_HIGH_QUALITY:2048},At={FILL:0,STROKE:1,FILL_STROKE:2,INVISIBLE:3,FILL_STROKE_MASK:3,ADD_TO_PATH_FLAG:4},ke={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},ct={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},ce={SOLID:1,DASHED:2,BEVELED:3,INSET:4,UNDERLINE:5},Oe={ERRORS:0,WARNINGS:1,INFOS:5},Ae={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},Xe={moveTo:0,lineTo:1,curveTo:2,closePath:3},Gi={NEED_PASSWORD:1,INCORRECT_PASSWORD:2};let os=Oe.WARNINGS;function ir(c){Number.isInteger(c)&&(os=c)}function nr(){return os}function ls(c){os>=Oe.INFOS&&console.info(`Info: ${c}`)}function W(c){os>=Oe.WARNINGS&&console.warn(`Warning: ${c}`)}function nt(c){throw new Error(c)}function J(c,t){c||nt(t)}function rr(c){switch(c?.protocol){case"http:":case"https:":case"ftp:":case"mailto:":case"tel:":return!0;default:return!1}}function Hs(c,t=null,e=null){if(!c)return null;if(e&&typeof c=="string"&&(e.addDefaultProtocol&&c.startsWith("www.")&&c.match(/\./g)?.length>=2&&(c=`http://${c}`),e.tryConvertEncoding))try{c=cr(c)}catch{}const s=t?URL.parse(c,t):URL.parse(c);return rr(s)?s:null}function Us(c,t,e=!1){const s=URL.parse(c);return s?(s.hash=t,s.href):e&&Hs(c,"http://example.com")?c.split("#",1)[0]+`${t?`#${t}`:""}`:""}function Y(c,t,e,s=!1){return Object.defineProperty(c,t,{value:e,enumerable:!s,configurable:!0,writable:!1}),e}const ae=function(){function t(e,s){this.message=e,this.name=s}return t.prototype=new Error,t.constructor=t,t}();class oi extends ae{constructor(t,e){super(t,"PasswordException"),this.code=e}}class ws extends ae{constructor(t,e){super(t,"UnknownErrorException"),this.details=e}}class is extends ae{constructor(t){super(t,"InvalidPDFException")}}class Le extends ae{constructor(t,e,s){super(t,"ResponseException"),this.status=e,this.missing=s}}class ar extends ae{constructor(t){super(t,"FormatError")}}class qt extends ae{constructor(t){super(t,"AbortException")}}function zi(c){(typeof c!="object"||c?.length===void 0)&&nt("Invalid argument for bytesToString");const t=c.length,e=8192;if(t<e)return String.fromCharCode.apply(null,c);const s=[];for(let i=0;i<t;i+=e){const n=Math.min(i+e,t),r=c.subarray(i,n);s.push(String.fromCharCode.apply(null,r))}return s.join("")}function Be(c){typeof c!="string"&&nt("Invalid argument for stringToBytes");const t=c.length,e=new Uint8Array(t);for(let s=0;s<t;++s)e[s]=c.charCodeAt(s)&255;return e}function or(c){return String.fromCharCode(c>>24&255,c>>16&255,c>>8&255,c&255)}function lr(){const c=new Uint8Array(4);return c[0]=1,new Uint32Array(c.buffer,0,1)[0]===1}function hr(){try{return new Function(""),!0}catch{return!1}}class bt{static get isLittleEndian(){return Y(this,"isLittleEndian",lr())}static get isEvalSupported(){return Y(this,"isEvalSupported",hr())}static get isOffscreenCanvasSupported(){return Y(this,"isOffscreenCanvasSupported",typeof OffscreenCanvas<"u")}static get isImageDecoderSupported(){return Y(this,"isImageDecoderSupported",typeof ImageDecoder<"u")}static get platform(){const{platform:t,userAgent:e}=navigator;return Y(this,"platform",{isAndroid:e.includes("Android"),isLinux:t.includes("Linux"),isMac:t.includes("Mac"),isWindows:t.includes("Win"),isFirefox:e.includes("Firefox")})}static get isCSSRoundSupported(){return Y(this,"isCSSRoundSupported",globalThis.CSS?.supports?.("width: round(1.5px, 1px)"))}}const vs=Array.from(Array(256).keys(),c=>c.toString(16).padStart(2,"0"));class I{static makeHexColor(t,e,s){return`#${vs[t]}${vs[e]}${vs[s]}`}static domMatrixToTransform(t){return[t.a,t.b,t.c,t.d,t.e,t.f]}static scaleMinMax(t,e){let s;t[0]?(t[0]<0&&(s=e[0],e[0]=e[2],e[2]=s),e[0]*=t[0],e[2]*=t[0],t[3]<0&&(s=e[1],e[1]=e[3],e[3]=s),e[1]*=t[3],e[3]*=t[3]):(s=e[0],e[0]=e[1],e[1]=s,s=e[2],e[2]=e[3],e[3]=s,t[1]<0&&(s=e[1],e[1]=e[3],e[3]=s),e[1]*=t[1],e[3]*=t[1],t[2]<0&&(s=e[0],e[0]=e[2],e[2]=s),e[0]*=t[2],e[2]*=t[2]),e[0]+=t[4],e[1]+=t[5],e[2]+=t[4],e[3]+=t[5]}static transform(t,e){return[t[0]*e[0]+t[2]*e[1],t[1]*e[0]+t[3]*e[1],t[0]*e[2]+t[2]*e[3],t[1]*e[2]+t[3]*e[3],t[0]*e[4]+t[2]*e[5]+t[4],t[1]*e[4]+t[3]*e[5]+t[5]]}static multiplyByDOMMatrix(t,e){return[t[0]*e.a+t[2]*e.b,t[1]*e.a+t[3]*e.b,t[0]*e.c+t[2]*e.d,t[1]*e.c+t[3]*e.d,t[0]*e.e+t[2]*e.f+t[4],t[1]*e.e+t[3]*e.f+t[5]]}static applyTransform(t,e,s=0){const i=t[s],n=t[s+1];t[s]=i*e[0]+n*e[2]+e[4],t[s+1]=i*e[1]+n*e[3]+e[5]}static applyTransformToBezier(t,e,s=0){const i=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 d=t[s+h],u=t[s+h+1];t[s+h]=d*i+u*r+o,t[s+h+1]=d*n+u*a+l}}static applyInverseTransform(t,e){const s=t[0],i=t[1],n=e[0]*e[3]-e[1]*e[2];t[0]=(s*e[3]-i*e[2]+e[2]*e[5]-e[4]*e[3])/n,t[1]=(-s*e[1]+i*e[0]+e[4]*e[1]-e[5]*e[0])/n}static axialAlignedBoundingBox(t,e,s){const i=e[0],n=e[1],r=e[2],a=e[3],o=e[4],l=e[5],h=t[0],d=t[1],u=t[2],f=t[3];let g=i*h+o,p=g,b=i*u+o,m=b,y=a*d+l,A=y,v=a*f+l,w=v;if(n!==0||r!==0){const _=n*h,S=n*u,E=r*d,C=r*f;g+=E,m+=E,b+=C,p+=C,y+=_,w+=_,v+=S,A+=S}s[0]=Math.min(s[0],g,b,p,m),s[1]=Math.min(s[1],y,v,A,w),s[2]=Math.max(s[2],g,b,p,m),s[3]=Math.max(s[3],y,v,A,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 s=t[0],i=t[1],n=t[2],r=t[3],a=s**2+i**2,o=s*n+i*r,l=n**2+r**2,h=(a+l)/2,d=Math.sqrt(h**2-(a*l-o**2));e[0]=Math.sqrt(h+d||1),e[1]=Math.sqrt(h-d||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 s=Math.max(Math.min(t[0],t[2]),Math.min(e[0],e[2])),i=Math.min(Math.max(t[0],t[2]),Math.max(e[0],e[2]));if(s>i)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:[s,n,i,r]}static pointBoundingBox(t,e,s){s[0]=Math.min(s[0],t),s[1]=Math.min(s[1],e),s[2]=Math.max(s[2],t),s[3]=Math.max(s[3],e)}static rectBoundingBox(t,e,s,i,n){n[0]=Math.min(n[0],t,s),n[1]=Math.min(n[1],e,i),n[2]=Math.max(n[2],t,s),n[3]=Math.max(n[3],e,i)}static#t(t,e,s,i,n,r,a,o,l,h){if(l<=0||l>=1)return;const d=1-l,u=l*l,f=u*l,g=d*(d*(d*t+3*l*e)+3*u*s)+f*i,p=d*(d*(d*n+3*l*r)+3*u*a)+f*o;h[0]=Math.min(h[0],g),h[1]=Math.min(h[1],p),h[2]=Math.max(h[2],g),h[3]=Math.max(h[3],p)}static#e(t,e,s,i,n,r,a,o,l,h,d,u){if(Math.abs(l)<1e-12){Math.abs(h)>=1e-12&&this.#t(t,e,s,i,n,r,a,o,-d/h,u);return}const f=h**2-4*d*l;if(f<0)return;const g=Math.sqrt(f),p=2*l;this.#t(t,e,s,i,n,r,a,o,(-h+g)/p,u),this.#t(t,e,s,i,n,r,a,o,(-h-g)/p,u)}static bezierBoundingBox(t,e,s,i,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,s,n,a,e,i,r,o,3*(-t+3*(s-n)+a),6*(t-2*s+n),3*(s-t),l),this.#e(t,s,n,a,e,i,r,o,3*(-e+3*(i-r)+o),6*(e-2*i+r),3*(i-e),l)}}function cr(c){return decodeURIComponent(escape(c))}let _s=null,li=null;function Vi(c){return _s||(_s=/([\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,li=new Map([["ſt","ſt"]])),c.replaceAll(_s,(t,e,s)=>e?e.normalize("NFKC"):li.get(s))}function js(){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();const c=new Uint8Array(32);return crypto.getRandomValues(c),zi(c)}const $s="pdfjs_internal_id_";function dr(c,t,e){if(!Array.isArray(e)||e.length<2)return!1;const[s,i,...n]=e;if(!c(s)&&!Number.isInteger(s)||!t(i))return!1;const r=n.length;let a=!0;switch(i.name){case"XYZ":if(r<2||r>3)return!1;break;case"Fit":case"FitB":return r===0;case"FitH":case"FitBH":case"FitV":case"FitBV":if(r>1)return!1;break;case"FitR":if(r!==4)return!1;a=!1;break;default:return!1}for(const o of n)if(!(typeof o=="number"||a&&o===null))return!1;return!0}function _t(c,t,e){return Math.min(Math.max(c,t),e)}function Wi(c){return Uint8Array.prototype.toBase64?c.toBase64():btoa(zi(c))}function ur(c){return Uint8Array.fromBase64?Uint8Array.fromBase64(c):Be(atob(c))}typeof Promise.try!="function"&&(Promise.try=function(c,...t){return new Promise(e=>{e(c(...t))})});typeof Math.sumPrecise!="function"&&(Math.sumPrecise=function(c){return c.reduce((t,e)=>t+e,0)});class De{static textContent(t){const e=[],s={items:e,styles:Object.create(null)};function i(n){if(!n)return;let r=null;const a=n.name;if(a==="#text")r=n.value;else if(De.shouldBuildText(a))n?.attributes?.textContent?r=n.attributes.textContent:n.value&&(r=n.value);else return;if(r!==null&&e.push({str:r}),!!n.children)for(const o of n.children)i(o)}return i(t),s}static shouldBuildText(t){return!(t==="textarea"||t==="input"||t==="option"||t==="select")}}class Gs{static setupStorage(t,e,s,i,n){const r=i.getValue(e,{value:null});switch(s.name){case"textarea":if(r.value!==null&&(t.textContent=r.value),n==="print")break;t.addEventListener("input",a=>{i.setValue(e,{value:a.target.value})});break;case"input":if(s.attributes.type==="radio"||s.attributes.type==="checkbox"){if(r.value===s.attributes.xfaOn?t.setAttribute("checked",!0):r.value===s.attributes.xfaOff&&t.removeAttribute("checked"),n==="print")break;t.addEventListener("change",a=>{i.setValue(e,{value:a.target.checked?a.target.getAttribute("xfaOn"):a.target.getAttribute("xfaOff")})})}else{if(r.value!==null&&t.setAttribute("value",r.value),n==="print")break;t.addEventListener("input",a=>{i.setValue(e,{value:a.target.value})})}break;case"select":if(r.value!==null){t.setAttribute("value",r.value);for(const a of s.children)a.attributes.value===r.value?a.attributes.selected=!0:a.attributes.hasOwnProperty("selected")&&delete a.attributes.selected}t.addEventListener("input",a=>{const o=a.target.options,l=o.selectedIndex===-1?"":o[o.selectedIndex].value;i.setValue(e,{value:l})});break}}static setAttributes({html:t,element:e,storage:s=null,intent:i,linkService:n}){const{attributes:r}=e,a=t instanceof HTMLAnchorElement;r.type==="radio"&&(r.name=`${r.name}-${i}`);for(const[o,l]of Object.entries(r))if(l!=null)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":Object.assign(t.style,l);break;case"textContent":t.textContent=l;break;default:(!a||o!=="href"&&o!=="newWindow")&&t.setAttribute(o,l)}a&&n.addLinkAttributes(t,r.href,r.newWindow),s&&r.dataId&&this.setupStorage(t,r.dataId,e,s)}static render(t){const e=t.annotationStorage,s=t.linkService,i=t.xfaHtml,n=t.intent||"display",r=document.createElement(i.name);i.attributes&&this.setAttributes({html:r,element:i,intent:n,linkService:s});const a=n!=="richText",o=t.div;if(o.append(r),t.viewport){const d=`matrix(${t.viewport.transform.join(",")})`;o.style.transform=d}a&&o.setAttribute("class","xfaLayer xfaFont");const l=[];if(i.children.length===0){if(i.value){const d=document.createTextNode(i.value);r.append(d),a&&De.shouldBuildText(i.name)&&l.push(d)}return{textDivs:l}}const h=[[i,-1,r]];for(;h.length>0;){const[d,u,f]=h.at(-1);if(u+1===d.children.length){h.pop();continue}const g=d.children[++h.at(-1)[1]];if(g===null)continue;const{name:p}=g;if(p==="#text"){const m=document.createTextNode(g.value);l.push(m),f.append(m);continue}const b=g?.attributes?.xmlns?document.createElementNS(g.attributes.xmlns,p):document.createElement(p);if(f.append(b),g.attributes&&this.setAttributes({html:b,element:g,storage:e,intent:n,linkService:s}),g.children?.length>0)h.push([g,-1,b]);else if(g.value){const m=document.createTextNode(g.value);a&&De.shouldBuildText(p)&&l.push(m),b.append(m)}}for(const d of o.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea"))d.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}}const Xt="http://www.w3.org/2000/svg";class ie{static CSS=96;static PDF=72;static PDF_TO_CSS_UNITS=this.CSS/this.PDF}async function ve(c,t="text"){if(Te(c,document.baseURI)){const e=await fetch(c);if(!e.ok)throw new Error(e.statusText);switch(t){case"arraybuffer":return e.arrayBuffer();case"blob":return e.blob();case"json":return e.json()}return e.text()}return new Promise((e,s)=>{const i=new XMLHttpRequest;i.open("GET",c,!0),i.responseType=t,i.onreadystatechange=()=>{if(i.readyState===XMLHttpRequest.DONE){if(i.status===200||i.status===0){switch(t){case"arraybuffer":case"blob":case"json":e(i.response);return}e(i.responseText);return}s(new Error(i.statusText))}},i.send(null)})}class He{constructor({viewBox:t,userUnit:e,scale:s,rotation:i,offsetX:n=0,offsetY:r=0,dontFlip:a=!1}){this.viewBox=t,this.userUnit=e,this.scale=s,this.rotation=i,this.offsetX=n,this.offsetY=r,s*=e;const o=(t[2]+t[0])/2,l=(t[3]+t[1])/2;let h,d,u,f;switch(i%=360,i<0&&(i+=360),i){case 180:h=-1,d=0,u=0,f=1;break;case 90:h=0,d=1,u=1,f=0;break;case 270:h=0,d=-1,u=-1,f=0;break;case 0:h=1,d=0,u=0,f=-1;break;default:throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.")}a&&(u=-u,f=-f);let g,p,b,m;h===0?(g=Math.abs(l-t[1])*s+n,p=Math.abs(o-t[0])*s+r,b=(t[3]-t[1])*s,m=(t[2]-t[0])*s):(g=Math.abs(o-t[0])*s+n,p=Math.abs(l-t[1])*s+r,b=(t[2]-t[0])*s,m=(t[3]-t[1])*s),this.transform=[h*s,d*s,u*s,f*s,g-h*s*o-u*s*l,p-d*s*o-f*s*l],this.width=b,this.height=m}get rawDims(){const t=this.viewBox;return Y(this,"rawDims",{pageWidth:t[2]-t[0],pageHeight:t[3]-t[1],pageX:t[0],pageY:t[1]})}clone({scale:t=this.scale,rotation:e=this.rotation,offsetX:s=this.offsetX,offsetY:i=this.offsetY,dontFlip:n=!1}={}){return new He({viewBox:this.viewBox.slice(),userUnit:this.userUnit,scale:t,rotation:e,offsetX:s,offsetY:i,dontFlip:n})}convertToViewportPoint(t,e){const s=[t,e];return I.applyTransform(s,this.transform),s}convertToViewportRectangle(t){const e=[t[0],t[1]];I.applyTransform(e,this.transform);const s=[t[2],t[3]];return I.applyTransform(s,this.transform),[e[0],e[1],s[0],s[1]]}convertToPdfPoint(t,e){const s=[t,e];return I.applyInverseTransform(s,this.transform),s}}class hs extends ae{constructor(t,e=0){super(t,"RenderingCancelledException"),this.extraDelay=e}}function Ue(c){const t=c.length;let e=0;for(;e<t&&c[e].trim()==="";)e++;return c.substring(e,e+5).toLowerCase()==="data:"}function cs(c){return typeof c=="string"&&/\.pdf$/i.test(c)}function Xi(c){return[c]=c.split(/[#?]/,1),c.substring(c.lastIndexOf("/")+1)}function qi(c,t="document.pdf"){if(typeof c!="string")return t;if(Ue(c))return W('getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.'),t;const s=(a=>{try{return new URL(a)}catch{try{return new URL(decodeURIComponent(a))}catch{try{return new URL(a,"https://foo.bar")}catch{try{return new URL(decodeURIComponent(a),"https://foo.bar")}catch{return null}}}}})(c);if(!s)return t;const i=a=>{try{let o=decodeURIComponent(a);return o.includes("/")?(o=o.split("/").at(-1),o.test(/^\.pdf$/i)?o:a):o}catch{return a}},n=/\.pdf$/i,r=s.pathname.split("/").at(-1);if(n.test(r))return i(r);if(s.searchParams.size>0){const a=Array.from(s.searchParams.values()).reverse();for(const l of a)if(n.test(l))return i(l);const o=Array.from(s.searchParams.keys()).reverse();for(const l of o)if(n.test(l))return i(l)}if(s.hash){const o=/[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i.exec(s.hash);if(o)return i(o[0])}return t}class hi{started=Object.create(null);times=[];time(t){t in this.started&&W(`Timer is already running for ${t}`),this.started[t]=Date.now()}timeEnd(t){t in this.started||W(`Timer has not been started for ${t}`),this.times.push({name:t,start:this.started[t],end:Date.now()}),delete this.started[t]}toString(){const t=[];let e=0;for(const{name:s}of this.times)e=Math.max(s.length,e);for(const{name:s,start:i,end:n}of this.times)t.push(`${s.padEnd(e)} ${n-i}ms
1
+ import{g as Yn,r as R,j as K,u as Kn,a as Qn,e as Jn,c as Zn,D as ai,f as tr,b as er}from"./index-Dwsn6NQE.js";import{u as sr}from"./paged-DMHOhYfR.js";const Et=typeof process=="object"&&process+""=="[object process]"&&!process.versions.nw&&!(process.versions.electron&&process.type&&process.type!=="browser"),Ts=[.001,0,0,.001,0,0],As=1.35,Rt={ANY:1,DISPLAY:2,PRINT:4,ANNOTATIONS_FORMS:16,ANNOTATIONS_STORAGE:32,ANNOTATIONS_DISABLE:64,IS_EDITING:128,OPLIST:256},Wt={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},Me="pdfjs_internal_editor_",V={DISABLE:-1,NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15,POPUP:16,SIGNATURE:101,COMMENT:102},Q={RESIZE:1,CREATE:2,FREETEXT_SIZE:11,FREETEXT_COLOR:12,FREETEXT_OPACITY:13,INK_COLOR:21,INK_THICKNESS:22,INK_OPACITY:23,HIGHLIGHT_COLOR:31,HIGHLIGHT_THICKNESS:32,HIGHLIGHT_FREE:33,HIGHLIGHT_SHOW_ALL:34,DRAW_STEP:41},$i={PRINT:4,MODIFY_CONTENTS:8,COPY:16,MODIFY_ANNOTATIONS:32,FILL_INTERACTIVE_FORMS:256,COPY_FOR_ACCESSIBILITY:512,ASSEMBLE:1024,PRINT_HIGH_QUALITY:2048},At={FILL:0,STROKE:1,FILL_STROKE:2,INVISIBLE:3,FILL_STROKE_MASK:3,ADD_TO_PATH_FLAG:4},ke={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},ct={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},ce={SOLID:1,DASHED:2,BEVELED:3,INSET:4,UNDERLINE:5},Oe={ERRORS:0,WARNINGS:1,INFOS:5},Ae={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},Xe={moveTo:0,lineTo:1,curveTo:2,closePath:3},Gi={NEED_PASSWORD:1,INCORRECT_PASSWORD:2};let os=Oe.WARNINGS;function ir(c){Number.isInteger(c)&&(os=c)}function nr(){return os}function ls(c){os>=Oe.INFOS&&console.info(`Info: ${c}`)}function W(c){os>=Oe.WARNINGS&&console.warn(`Warning: ${c}`)}function nt(c){throw new Error(c)}function J(c,t){c||nt(t)}function rr(c){switch(c?.protocol){case"http:":case"https:":case"ftp:":case"mailto:":case"tel:":return!0;default:return!1}}function Hs(c,t=null,e=null){if(!c)return null;if(e&&typeof c=="string"&&(e.addDefaultProtocol&&c.startsWith("www.")&&c.match(/\./g)?.length>=2&&(c=`http://${c}`),e.tryConvertEncoding))try{c=cr(c)}catch{}const s=t?URL.parse(c,t):URL.parse(c);return rr(s)?s:null}function Us(c,t,e=!1){const s=URL.parse(c);return s?(s.hash=t,s.href):e&&Hs(c,"http://example.com")?c.split("#",1)[0]+`${t?`#${t}`:""}`:""}function Y(c,t,e,s=!1){return Object.defineProperty(c,t,{value:e,enumerable:!s,configurable:!0,writable:!1}),e}const ae=function(){function t(e,s){this.message=e,this.name=s}return t.prototype=new Error,t.constructor=t,t}();class oi extends ae{constructor(t,e){super(t,"PasswordException"),this.code=e}}class ws extends ae{constructor(t,e){super(t,"UnknownErrorException"),this.details=e}}class is extends ae{constructor(t){super(t,"InvalidPDFException")}}class Le extends ae{constructor(t,e,s){super(t,"ResponseException"),this.status=e,this.missing=s}}class ar extends ae{constructor(t){super(t,"FormatError")}}class qt extends ae{constructor(t){super(t,"AbortException")}}function zi(c){(typeof c!="object"||c?.length===void 0)&&nt("Invalid argument for bytesToString");const t=c.length,e=8192;if(t<e)return String.fromCharCode.apply(null,c);const s=[];for(let i=0;i<t;i+=e){const n=Math.min(i+e,t),r=c.subarray(i,n);s.push(String.fromCharCode.apply(null,r))}return s.join("")}function Be(c){typeof c!="string"&&nt("Invalid argument for stringToBytes");const t=c.length,e=new Uint8Array(t);for(let s=0;s<t;++s)e[s]=c.charCodeAt(s)&255;return e}function or(c){return String.fromCharCode(c>>24&255,c>>16&255,c>>8&255,c&255)}function lr(){const c=new Uint8Array(4);return c[0]=1,new Uint32Array(c.buffer,0,1)[0]===1}function hr(){try{return new Function(""),!0}catch{return!1}}class bt{static get isLittleEndian(){return Y(this,"isLittleEndian",lr())}static get isEvalSupported(){return Y(this,"isEvalSupported",hr())}static get isOffscreenCanvasSupported(){return Y(this,"isOffscreenCanvasSupported",typeof OffscreenCanvas<"u")}static get isImageDecoderSupported(){return Y(this,"isImageDecoderSupported",typeof ImageDecoder<"u")}static get platform(){const{platform:t,userAgent:e}=navigator;return Y(this,"platform",{isAndroid:e.includes("Android"),isLinux:t.includes("Linux"),isMac:t.includes("Mac"),isWindows:t.includes("Win"),isFirefox:e.includes("Firefox")})}static get isCSSRoundSupported(){return Y(this,"isCSSRoundSupported",globalThis.CSS?.supports?.("width: round(1.5px, 1px)"))}}const vs=Array.from(Array(256).keys(),c=>c.toString(16).padStart(2,"0"));class I{static makeHexColor(t,e,s){return`#${vs[t]}${vs[e]}${vs[s]}`}static domMatrixToTransform(t){return[t.a,t.b,t.c,t.d,t.e,t.f]}static scaleMinMax(t,e){let s;t[0]?(t[0]<0&&(s=e[0],e[0]=e[2],e[2]=s),e[0]*=t[0],e[2]*=t[0],t[3]<0&&(s=e[1],e[1]=e[3],e[3]=s),e[1]*=t[3],e[3]*=t[3]):(s=e[0],e[0]=e[1],e[1]=s,s=e[2],e[2]=e[3],e[3]=s,t[1]<0&&(s=e[1],e[1]=e[3],e[3]=s),e[1]*=t[1],e[3]*=t[1],t[2]<0&&(s=e[0],e[0]=e[2],e[2]=s),e[0]*=t[2],e[2]*=t[2]),e[0]+=t[4],e[1]+=t[5],e[2]+=t[4],e[3]+=t[5]}static transform(t,e){return[t[0]*e[0]+t[2]*e[1],t[1]*e[0]+t[3]*e[1],t[0]*e[2]+t[2]*e[3],t[1]*e[2]+t[3]*e[3],t[0]*e[4]+t[2]*e[5]+t[4],t[1]*e[4]+t[3]*e[5]+t[5]]}static multiplyByDOMMatrix(t,e){return[t[0]*e.a+t[2]*e.b,t[1]*e.a+t[3]*e.b,t[0]*e.c+t[2]*e.d,t[1]*e.c+t[3]*e.d,t[0]*e.e+t[2]*e.f+t[4],t[1]*e.e+t[3]*e.f+t[5]]}static applyTransform(t,e,s=0){const i=t[s],n=t[s+1];t[s]=i*e[0]+n*e[2]+e[4],t[s+1]=i*e[1]+n*e[3]+e[5]}static applyTransformToBezier(t,e,s=0){const i=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 d=t[s+h],u=t[s+h+1];t[s+h]=d*i+u*r+o,t[s+h+1]=d*n+u*a+l}}static applyInverseTransform(t,e){const s=t[0],i=t[1],n=e[0]*e[3]-e[1]*e[2];t[0]=(s*e[3]-i*e[2]+e[2]*e[5]-e[4]*e[3])/n,t[1]=(-s*e[1]+i*e[0]+e[4]*e[1]-e[5]*e[0])/n}static axialAlignedBoundingBox(t,e,s){const i=e[0],n=e[1],r=e[2],a=e[3],o=e[4],l=e[5],h=t[0],d=t[1],u=t[2],f=t[3];let g=i*h+o,p=g,b=i*u+o,m=b,y=a*d+l,A=y,v=a*f+l,w=v;if(n!==0||r!==0){const _=n*h,S=n*u,E=r*d,C=r*f;g+=E,m+=E,b+=C,p+=C,y+=_,w+=_,v+=S,A+=S}s[0]=Math.min(s[0],g,b,p,m),s[1]=Math.min(s[1],y,v,A,w),s[2]=Math.max(s[2],g,b,p,m),s[3]=Math.max(s[3],y,v,A,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 s=t[0],i=t[1],n=t[2],r=t[3],a=s**2+i**2,o=s*n+i*r,l=n**2+r**2,h=(a+l)/2,d=Math.sqrt(h**2-(a*l-o**2));e[0]=Math.sqrt(h+d||1),e[1]=Math.sqrt(h-d||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 s=Math.max(Math.min(t[0],t[2]),Math.min(e[0],e[2])),i=Math.min(Math.max(t[0],t[2]),Math.max(e[0],e[2]));if(s>i)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:[s,n,i,r]}static pointBoundingBox(t,e,s){s[0]=Math.min(s[0],t),s[1]=Math.min(s[1],e),s[2]=Math.max(s[2],t),s[3]=Math.max(s[3],e)}static rectBoundingBox(t,e,s,i,n){n[0]=Math.min(n[0],t,s),n[1]=Math.min(n[1],e,i),n[2]=Math.max(n[2],t,s),n[3]=Math.max(n[3],e,i)}static#t(t,e,s,i,n,r,a,o,l,h){if(l<=0||l>=1)return;const d=1-l,u=l*l,f=u*l,g=d*(d*(d*t+3*l*e)+3*u*s)+f*i,p=d*(d*(d*n+3*l*r)+3*u*a)+f*o;h[0]=Math.min(h[0],g),h[1]=Math.min(h[1],p),h[2]=Math.max(h[2],g),h[3]=Math.max(h[3],p)}static#e(t,e,s,i,n,r,a,o,l,h,d,u){if(Math.abs(l)<1e-12){Math.abs(h)>=1e-12&&this.#t(t,e,s,i,n,r,a,o,-d/h,u);return}const f=h**2-4*d*l;if(f<0)return;const g=Math.sqrt(f),p=2*l;this.#t(t,e,s,i,n,r,a,o,(-h+g)/p,u),this.#t(t,e,s,i,n,r,a,o,(-h-g)/p,u)}static bezierBoundingBox(t,e,s,i,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,s,n,a,e,i,r,o,3*(-t+3*(s-n)+a),6*(t-2*s+n),3*(s-t),l),this.#e(t,s,n,a,e,i,r,o,3*(-e+3*(i-r)+o),6*(e-2*i+r),3*(i-e),l)}}function cr(c){return decodeURIComponent(escape(c))}let _s=null,li=null;function Vi(c){return _s||(_s=/([\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,li=new Map([["ſt","ſt"]])),c.replaceAll(_s,(t,e,s)=>e?e.normalize("NFKC"):li.get(s))}function js(){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();const c=new Uint8Array(32);return crypto.getRandomValues(c),zi(c)}const $s="pdfjs_internal_id_";function dr(c,t,e){if(!Array.isArray(e)||e.length<2)return!1;const[s,i,...n]=e;if(!c(s)&&!Number.isInteger(s)||!t(i))return!1;const r=n.length;let a=!0;switch(i.name){case"XYZ":if(r<2||r>3)return!1;break;case"Fit":case"FitB":return r===0;case"FitH":case"FitBH":case"FitV":case"FitBV":if(r>1)return!1;break;case"FitR":if(r!==4)return!1;a=!1;break;default:return!1}for(const o of n)if(!(typeof o=="number"||a&&o===null))return!1;return!0}function _t(c,t,e){return Math.min(Math.max(c,t),e)}function Wi(c){return Uint8Array.prototype.toBase64?c.toBase64():btoa(zi(c))}function ur(c){return Uint8Array.fromBase64?Uint8Array.fromBase64(c):Be(atob(c))}typeof Promise.try!="function"&&(Promise.try=function(c,...t){return new Promise(e=>{e(c(...t))})});typeof Math.sumPrecise!="function"&&(Math.sumPrecise=function(c){return c.reduce((t,e)=>t+e,0)});class De{static textContent(t){const e=[],s={items:e,styles:Object.create(null)};function i(n){if(!n)return;let r=null;const a=n.name;if(a==="#text")r=n.value;else if(De.shouldBuildText(a))n?.attributes?.textContent?r=n.attributes.textContent:n.value&&(r=n.value);else return;if(r!==null&&e.push({str:r}),!!n.children)for(const o of n.children)i(o)}return i(t),s}static shouldBuildText(t){return!(t==="textarea"||t==="input"||t==="option"||t==="select")}}class Gs{static setupStorage(t,e,s,i,n){const r=i.getValue(e,{value:null});switch(s.name){case"textarea":if(r.value!==null&&(t.textContent=r.value),n==="print")break;t.addEventListener("input",a=>{i.setValue(e,{value:a.target.value})});break;case"input":if(s.attributes.type==="radio"||s.attributes.type==="checkbox"){if(r.value===s.attributes.xfaOn?t.setAttribute("checked",!0):r.value===s.attributes.xfaOff&&t.removeAttribute("checked"),n==="print")break;t.addEventListener("change",a=>{i.setValue(e,{value:a.target.checked?a.target.getAttribute("xfaOn"):a.target.getAttribute("xfaOff")})})}else{if(r.value!==null&&t.setAttribute("value",r.value),n==="print")break;t.addEventListener("input",a=>{i.setValue(e,{value:a.target.value})})}break;case"select":if(r.value!==null){t.setAttribute("value",r.value);for(const a of s.children)a.attributes.value===r.value?a.attributes.selected=!0:a.attributes.hasOwnProperty("selected")&&delete a.attributes.selected}t.addEventListener("input",a=>{const o=a.target.options,l=o.selectedIndex===-1?"":o[o.selectedIndex].value;i.setValue(e,{value:l})});break}}static setAttributes({html:t,element:e,storage:s=null,intent:i,linkService:n}){const{attributes:r}=e,a=t instanceof HTMLAnchorElement;r.type==="radio"&&(r.name=`${r.name}-${i}`);for(const[o,l]of Object.entries(r))if(l!=null)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":Object.assign(t.style,l);break;case"textContent":t.textContent=l;break;default:(!a||o!=="href"&&o!=="newWindow")&&t.setAttribute(o,l)}a&&n.addLinkAttributes(t,r.href,r.newWindow),s&&r.dataId&&this.setupStorage(t,r.dataId,e,s)}static render(t){const e=t.annotationStorage,s=t.linkService,i=t.xfaHtml,n=t.intent||"display",r=document.createElement(i.name);i.attributes&&this.setAttributes({html:r,element:i,intent:n,linkService:s});const a=n!=="richText",o=t.div;if(o.append(r),t.viewport){const d=`matrix(${t.viewport.transform.join(",")})`;o.style.transform=d}a&&o.setAttribute("class","xfaLayer xfaFont");const l=[];if(i.children.length===0){if(i.value){const d=document.createTextNode(i.value);r.append(d),a&&De.shouldBuildText(i.name)&&l.push(d)}return{textDivs:l}}const h=[[i,-1,r]];for(;h.length>0;){const[d,u,f]=h.at(-1);if(u+1===d.children.length){h.pop();continue}const g=d.children[++h.at(-1)[1]];if(g===null)continue;const{name:p}=g;if(p==="#text"){const m=document.createTextNode(g.value);l.push(m),f.append(m);continue}const b=g?.attributes?.xmlns?document.createElementNS(g.attributes.xmlns,p):document.createElement(p);if(f.append(b),g.attributes&&this.setAttributes({html:b,element:g,storage:e,intent:n,linkService:s}),g.children?.length>0)h.push([g,-1,b]);else if(g.value){const m=document.createTextNode(g.value);a&&De.shouldBuildText(p)&&l.push(m),b.append(m)}}for(const d of o.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea"))d.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}}const Xt="http://www.w3.org/2000/svg";class ie{static CSS=96;static PDF=72;static PDF_TO_CSS_UNITS=this.CSS/this.PDF}async function ve(c,t="text"){if(Te(c,document.baseURI)){const e=await fetch(c);if(!e.ok)throw new Error(e.statusText);switch(t){case"arraybuffer":return e.arrayBuffer();case"blob":return e.blob();case"json":return e.json()}return e.text()}return new Promise((e,s)=>{const i=new XMLHttpRequest;i.open("GET",c,!0),i.responseType=t,i.onreadystatechange=()=>{if(i.readyState===XMLHttpRequest.DONE){if(i.status===200||i.status===0){switch(t){case"arraybuffer":case"blob":case"json":e(i.response);return}e(i.responseText);return}s(new Error(i.statusText))}},i.send(null)})}class He{constructor({viewBox:t,userUnit:e,scale:s,rotation:i,offsetX:n=0,offsetY:r=0,dontFlip:a=!1}){this.viewBox=t,this.userUnit=e,this.scale=s,this.rotation=i,this.offsetX=n,this.offsetY=r,s*=e;const o=(t[2]+t[0])/2,l=(t[3]+t[1])/2;let h,d,u,f;switch(i%=360,i<0&&(i+=360),i){case 180:h=-1,d=0,u=0,f=1;break;case 90:h=0,d=1,u=1,f=0;break;case 270:h=0,d=-1,u=-1,f=0;break;case 0:h=1,d=0,u=0,f=-1;break;default:throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.")}a&&(u=-u,f=-f);let g,p,b,m;h===0?(g=Math.abs(l-t[1])*s+n,p=Math.abs(o-t[0])*s+r,b=(t[3]-t[1])*s,m=(t[2]-t[0])*s):(g=Math.abs(o-t[0])*s+n,p=Math.abs(l-t[1])*s+r,b=(t[2]-t[0])*s,m=(t[3]-t[1])*s),this.transform=[h*s,d*s,u*s,f*s,g-h*s*o-u*s*l,p-d*s*o-f*s*l],this.width=b,this.height=m}get rawDims(){const t=this.viewBox;return Y(this,"rawDims",{pageWidth:t[2]-t[0],pageHeight:t[3]-t[1],pageX:t[0],pageY:t[1]})}clone({scale:t=this.scale,rotation:e=this.rotation,offsetX:s=this.offsetX,offsetY:i=this.offsetY,dontFlip:n=!1}={}){return new He({viewBox:this.viewBox.slice(),userUnit:this.userUnit,scale:t,rotation:e,offsetX:s,offsetY:i,dontFlip:n})}convertToViewportPoint(t,e){const s=[t,e];return I.applyTransform(s,this.transform),s}convertToViewportRectangle(t){const e=[t[0],t[1]];I.applyTransform(e,this.transform);const s=[t[2],t[3]];return I.applyTransform(s,this.transform),[e[0],e[1],s[0],s[1]]}convertToPdfPoint(t,e){const s=[t,e];return I.applyInverseTransform(s,this.transform),s}}class hs extends ae{constructor(t,e=0){super(t,"RenderingCancelledException"),this.extraDelay=e}}function Ue(c){const t=c.length;let e=0;for(;e<t&&c[e].trim()==="";)e++;return c.substring(e,e+5).toLowerCase()==="data:"}function cs(c){return typeof c=="string"&&/\.pdf$/i.test(c)}function Xi(c){return[c]=c.split(/[#?]/,1),c.substring(c.lastIndexOf("/")+1)}function qi(c,t="document.pdf"){if(typeof c!="string")return t;if(Ue(c))return W('getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.'),t;const s=(a=>{try{return new URL(a)}catch{try{return new URL(decodeURIComponent(a))}catch{try{return new URL(a,"https://foo.bar")}catch{try{return new URL(decodeURIComponent(a),"https://foo.bar")}catch{return null}}}}})(c);if(!s)return t;const i=a=>{try{let o=decodeURIComponent(a);return o.includes("/")?(o=o.split("/").at(-1),o.test(/^\.pdf$/i)?o:a):o}catch{return a}},n=/\.pdf$/i,r=s.pathname.split("/").at(-1);if(n.test(r))return i(r);if(s.searchParams.size>0){const a=Array.from(s.searchParams.values()).reverse();for(const l of a)if(n.test(l))return i(l);const o=Array.from(s.searchParams.keys()).reverse();for(const l of o)if(n.test(l))return i(l)}if(s.hash){const o=/[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i.exec(s.hash);if(o)return i(o[0])}return t}class hi{started=Object.create(null);times=[];time(t){t in this.started&&W(`Timer is already running for ${t}`),this.started[t]=Date.now()}timeEnd(t){t in this.started||W(`Timer has not been started for ${t}`),this.times.push({name:t,start:this.started[t],end:Date.now()}),delete this.started[t]}toString(){const t=[];let e=0;for(const{name:s}of this.times)e=Math.max(s.length,e);for(const{name:s,start:i,end:n}of this.times)t.push(`${s.padEnd(e)} ${n-i}ms
2
2
  `);return t.join("")}}function Te(c,t){const e=t?URL.parse(c,t):URL.parse(c);return e?.protocol==="http:"||e?.protocol==="https:"}function Dt(c){c.preventDefault()}function lt(c){c.preventDefault(),c.stopPropagation()}function fr(c){console.log("Deprecated API usage: "+c)}class ns{static#t;static toDateObject(t){if(t instanceof Date)return t;if(!t||typeof t!="string")return null;this.#t||=new RegExp("^D:(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?([Z|+|-])?(\\d{2})?'?(\\d{2})?'?");const e=this.#t.exec(t);if(!e)return null;const s=parseInt(e[1],10);let i=parseInt(e[2],10);i=i>=1&&i<=12?i-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 d=parseInt(e[9],10)||0;return d=d>=0&&d<=59?d:0,l==="-"?(r+=h,a+=d):l==="+"&&(r-=h,a-=d),new Date(Date.UTC(s,i,n,r,a,o))}}function Yi(c,{scale:t=1,rotation:e=0}){const{width:s,height:i}=c.attributes.style,n=[0,0,parseInt(s),parseInt(i)];return new He({viewBox:n,userUnit:1,scale:t,rotation:e})}function _e(c){if(c.startsWith("#")){const t=parseInt(c.slice(1),16);return[(t&16711680)>>16,(t&65280)>>8,t&255]}return c.startsWith("rgb(")?c.slice(4,-1).split(",").map(t=>parseInt(t)):c.startsWith("rgba(")?c.slice(5,-1).split(",").map(t=>parseInt(t)).slice(0,3):(W(`Not a valid color format: "${c}"`),[0,0,0])}function pr(c){const t=document.createElement("span");t.style.visibility="hidden",t.style.colorScheme="only light",document.body.append(t);for(const e of c.keys()){t.style.color=e;const s=window.getComputedStyle(t).color;c.set(e,_e(s))}t.remove()}function ot(c){const{a:t,b:e,c:s,d:i,e:n,f:r}=c.getTransform();return[t,e,s,i,n,r]}function Ut(c){const{a:t,b:e,c:s,d:i,e:n,f:r}=c.getTransform().invertSelf();return[t,e,s,i,n,r]}function Zt(c,t,e=!1,s=!0){if(t instanceof He){const{pageWidth:i,pageHeight:n}=t.rawDims,{style:r}=c,a=bt.isCSSRoundSupported,o=`var(--total-scale-factor) * ${i}px`,l=`var(--total-scale-factor) * ${n}px`,h=a?`round(down, ${o}, var(--scale-round-x))`:`calc(${o})`,d=a?`round(down, ${l}, var(--scale-round-y))`:`calc(${l})`;!e||t.rotation%180===0?(r.width=h,r.height=d):(r.width=d,r.height=h)}s&&c.setAttribute("data-main-rotation",t.rotation)}class Ht{constructor(){const{pixelRatio:t}=Ht;this.sx=t,this.sy=t}get scaled(){return this.sx!==1||this.sy!==1}get symmetric(){return this.sx===this.sy}limitCanvas(t,e,s,i,n=-1){let r=1/0,a=1/0,o=1/0;s=Ht.capPixels(s,n),s>0&&(r=Math.sqrt(s/(t*e))),i!==-1&&(a=i/t,o=i/e);const l=Math.min(r,a,o);return this.sx>l||this.sy>l?(this.sx=l,this.sy=l,!0):!1}static get pixelRatio(){return globalThis.devicePixelRatio||1}static capPixels(t,e){if(e>=0){const s=Math.ceil(window.screen.availWidth*window.screen.availHeight*this.pixelRatio**2*(1+e/100));return t>0?Math.min(t,s):s}return t}}const rs=["image/apng","image/avif","image/bmp","image/gif","image/jpeg","image/png","image/svg+xml","image/webp","image/x-icon"];class gr{static get isDarkMode(){return Y(this,"isDarkMode",!!window?.matchMedia?.("(prefers-color-scheme: dark)").matches)}}class Ki{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:s}=window.getComputedStyle(t);return t.remove(),Y(this,"commentForegroundColor",_e(s))}}function Qi(c,t,e,s){s=Math.min(Math.max(s??1,0),1);const i=255*(1-s);return c=Math.round(c*s+i),t=Math.round(t*s+i),e=Math.round(e*s+i),[c,t,e]}function ci(c,t){const e=c[0]/255,s=c[1]/255,i=c[2]/255,n=Math.max(e,s,i),r=Math.min(e,s,i),a=(n+r)/2;if(n===r)t[0]=t[1]=0;else{const o=n-r;switch(t[1]=a<.5?o/(n+r):o/(2-n-r),n){case e:t[0]=((s-i)/o+(s<i?6:0))*60;break;case s:t[0]=((i-e)/o+2)*60;break;case i:t[0]=((e-s)/o+4)*60;break}}t[2]=a}function Ps(c,t){const e=c[0],s=c[1],i=c[2],n=(1-Math.abs(2*i-1))*s,r=n*(1-Math.abs(e/60%2-1)),a=i-n/2;switch(Math.floor(e/60)){case 0:t[0]=n+a,t[1]=r+a,t[2]=a;break;case 1:t[0]=r+a,t[1]=n+a,t[2]=a;break;case 2:t[0]=a,t[1]=n+a,t[2]=r+a;break;case 3:t[0]=a,t[1]=r+a,t[2]=n+a;break;case 4:t[0]=r+a,t[1]=a,t[2]=n+a;break;case 5:case 6:t[0]=n+a,t[1]=a,t[2]=r+a;break}}function di(c){return c<=.03928?c/12.92:((c+.055)/1.055)**2.4}function ui(c,t,e){Ps(c,e),e.map(di);const s=.2126*e[0]+.7152*e[1]+.0722*e[2];Ps(t,e),e.map(di);const i=.2126*e[0]+.7152*e[1]+.0722*e[2];return s>i?(s+.05)/(i+.05):(i+.05)/(s+.05)}const fi=new Map;function Ji(c,t){const e=c[0]+c[1]*256+c[2]*65536+t[0]*16777216+t[1]*4294967296+t[2]*1099511627776;let s=fi.get(e);if(s)return s;const i=new Float32Array(9),n=i.subarray(0,3),r=i.subarray(3,6);ci(c,r);const a=i.subarray(6,9);ci(t,a);const o=a[2]<.5,l=o?12:4.5;if(r[2]=o?Math.sqrt(r[2]):1-Math.sqrt(1-r[2]),ui(r,a,n)<l){let h,d;o?(h=r[2],d=1):(h=0,d=r[2]);const u=.005;for(;d-h>u;){const f=r[2]=(h+d)/2;o===ui(r,a,n)<l?h=f:d=f}r[2]=o?d:h}return Ps(r,n),s=I.makeHexColor(Math.round(n[0]*255),Math.round(n[1]*255),Math.round(n[2]*255)),fi.set(e,s),s}function zs({html:c,dir:t,className:e},s){const i=document.createDocumentFragment();if(typeof c=="string"){const n=document.createElement("p");n.dir=t||"auto";const r=c.split(/(?:\r\n?|\n)/);for(let a=0,o=r.length;a<o;++a){const l=r[a];n.append(document.createTextNode(l)),a<o-1&&n.append(document.createElement("br"))}i.append(n)}else Gs.render({xfaHtml:c,div:i,intent:"richText"});i.firstChild.classList.add("richText",e),s.append(i)}class Re{#t=null;#e=null;#i;#s=null;#a=null;#n=null;#r=null;#o=null;static#h=null;constructor(t){this.#i=t,Re.#h||=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 t=this.#t=document.createElement("div");t.classList.add("editToolbar","hidden"),t.setAttribute("role","toolbar");const e=this.#i._uiManager._signal;e instanceof AbortSignal&&!e.aborted&&(t.addEventListener("contextmenu",Dt,{signal:e}),t.addEventListener("pointerdown",Re.#l,{signal:e}));const s=this.#s=document.createElement("div");s.className="buttons",t.append(s);const i=this.#i.toolbarPosition;if(i){const{style:n}=t,r=this.#i._uiManager.direction==="ltr"?1-i[0]:i[0];n.insetInlineEnd=`${100*r}%`,n.top=`calc(${100*i[1]}% + var(--editor-toolbar-vert-offset))`}return t}get div(){return this.#t}static#l(t){t.stopPropagation()}#u(t){this.#i._focusEventsAllowed=!1,lt(t)}#d(t){this.#i._focusEventsAllowed=!0,lt(t)}#f(t){const e=this.#i._uiManager._signal;return!(e instanceof AbortSignal)||e.aborted?!1:(t.addEventListener("focusin",this.#u.bind(this),{capture:!0,signal:e}),t.addEventListener("focusout",this.#d.bind(this),{capture:!0,signal:e}),t.addEventListener("contextmenu",Dt,{signal:e}),!0)}hide(){this.#t.classList.add("hidden"),this.#e?.hideDropdown()}show(){this.#t.classList.remove("hidden"),this.#a?.shown(),this.#n?.shown()}addDeleteButton(){const{editorType:t,_uiManager:e}=this.#i,s=document.createElement("button");s.classList.add("basic","deleteButton"),s.tabIndex=0,s.setAttribute("data-l10n-id",Re.#h[t]),this.#f(s)&&s.addEventListener("click",i=>{e.delete()},{signal:e._signal}),this.#s.append(s)}get#m(){const t=document.createElement("div");return t.className="divider",t}async addAltText(t){const e=await t.render();this.#f(e),this.#s.append(e,this.#m),this.#a=t}addComment(t,e=null){if(this.#n)return;const s=t.renderForToolbar();if(!s)return;this.#f(s);const i=this.#r=this.#m;e?(this.#s.insertBefore(s,e),this.#s.insertBefore(i,e)):this.#s.append(s,i),this.#n=t,t.toolbar=this}addColorPicker(t){if(this.#e)return;this.#e=t;const e=t.renderButton();this.#f(e),this.#s.append(e,this.#m)}async addEditSignatureButton(t){const e=this.#o=await t.renderEditButton(this.#i);this.#f(e),this.#s.append(e,this.#m)}removeButton(t){switch(t){case"comment":this.#n?.removeToolbarCommentButton(),this.#n=null,this.#r?.remove(),this.#r=null;break}}async addButton(t,e){switch(t){case"colorPicker":this.addColorPicker(e);break;case"altText":await this.addAltText(e);break;case"editSignature":await this.addEditSignatureButton(e);break;case"delete":this.addDeleteButton();break;case"comment":this.addComment(e);break}}async addButtonBefore(t,e,s){const i=this.#s.querySelector(s);i&&t==="comment"&&this.addComment(e,i)}updateEditSignatureButton(t){this.#o&&(this.#o.title=t)}remove(){this.#t.remove(),this.#e?.destroy(),this.#e=null}}class mr{#t=null;#e=null;#i;constructor(t){this.#i=t}#s(){const t=this.#e=document.createElement("div");t.className="editToolbar",t.setAttribute("role","toolbar");const e=this.#i._signal;e instanceof AbortSignal&&!e.aborted&&t.addEventListener("contextmenu",Dt,{signal:e});const s=this.#t=document.createElement("div");return s.className="buttons",t.append(s),this.#i.hasCommentManager()&&this.#n("commentButton","pdfjs-comment-floating-button","pdfjs-comment-floating-button-label",()=>{this.#i.commentSelection("floating_button")}),this.#n("highlightButton","pdfjs-highlight-floating-button1","pdfjs-highlight-floating-button-label",()=>{this.#i.highlightSelection("floating_button")}),t}#a(t,e){let s=0,i=0;for(const n of t){const r=n.y+n.height;if(r<s)continue;const a=n.x+(e?n.width:0);if(r>s){i=a,s=r;continue}e?a>i&&(i=a):a<i&&(i=a)}return[e?1-i:i,s]}show(t,e,s){const[i,n]=this.#a(e,s),{style:r}=this.#e||=this.#s();t.append(this.#e),r.insetInlineEnd=`${100*i}%`,r.top=`calc(${100*n}% + var(--editor-toolbar-vert-offset))`}hide(){this.#e.remove()}#n(t,e,s,i){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",s);const a=this.#i._signal;a instanceof AbortSignal&&!a.aborted&&(n.addEventListener("contextmenu",Dt,{signal:a}),n.addEventListener("click",i,{signal:a})),this.#t.append(n)}}function Zi(c,t,e){for(const s of e)t.addEventListener(s,c[s].bind(c))}class br{#t=0;get id(){return`${Me}${this.#t++}`}}class Vs{#t=js();#e=0;#i=null;static get _isSVGFittingCanvas(){const t='data:image/svg+xml;charset=UTF-8,<svg viewBox="0 0 1 1" width="1" height="1" xmlns="http://www.w3.org/2000/svg"><rect width="1" height="1" style="fill:red;"/></svg>',s=new OffscreenCanvas(1,3).getContext("2d",{willReadFrequently:!0}),i=new Image;i.src=t;const n=i.decode().then(()=>(s.drawImage(i,0,0,1,1,0,0,1,3),new Uint32Array(s.getImageData(0,0,1,1).data.buffer)[0]===0));return Y(this,"_isSVGFittingCanvas",n)}async#s(t,e){this.#i||=new Map;let s=this.#i.get(t);if(s===null)return null;if(s?.bitmap)return s.refCounter+=1,s;try{s||={bitmap:null,id:`image_${this.#t}_${this.#e++}`,refCounter:0,isSvg:!1};let i;if(typeof e=="string"?(s.url=e,i=await ve(e,"blob")):e instanceof File?i=s.file=e:e instanceof Blob&&(i=e),i.type==="image/svg+xml"){const n=Vs._isSVGFittingCanvas,r=new FileReader,a=new Image,o=new Promise((l,h)=>{a.onload=()=>{s.bitmap=a,s.isSvg=!0,l()},r.onload=async()=>{const d=s.svgUrl=r.result;a.src=await n?`${d}#svgView(preserveAspectRatio(none))`:d},a.onerror=r.onerror=h});r.readAsDataURL(i),await o}else s.bitmap=await createImageBitmap(i);s.refCounter=1}catch(i){W(i),s=null}return this.#i.set(t,s),s&&this.#i.set(s.id,s),s}async getFromFile(t){const{lastModified:e,name:s,size:i,type:n}=t;return this.#s(`${e}_${s}_${i}_${n}`,t)}async getFromUrl(t){return this.#s(t,t)}async getFromBlob(t,e){const s=await e;return this.#s(t,s)}async getFromId(t){this.#i||=new Map;const e=this.#i.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:s}=e;return delete e.blobPromise,this.getFromBlob(e.id,s)}return this.getFromUrl(e.url)}getFromCanvas(t,e){this.#i||=new Map;let s=this.#i.get(t);if(s?.bitmap)return s.refCounter+=1,s;const i=new OffscreenCanvas(e.width,e.height);return i.getContext("2d").drawImage(e,0,0),s={bitmap:i.transferToImageBitmap(),id:`image_${this.#t}_${this.#e++}`,refCounter:1,isSvg:!1},this.#i.set(t,s),this.#i.set(s.id,s),s}getSvgUrl(t){const e=this.#i.get(t);return e?.isSvg?e.svgUrl:null}deleteId(t){this.#i||=new Map;const e=this.#i.get(t);if(!e||(e.refCounter-=1,e.refCounter!==0))return;const{bitmap:s}=e;if(!e.url&&!e.file){const i=new OffscreenCanvas(s.width,s.height);i.getContext("bitmaprenderer").transferFromImageBitmap(s),e.blobPromise=i.convertToBlob()}s.close?.(),e.bitmap=null}isValidId(t){return t.startsWith(`image_${this.#t}_`)}}class yr{#t=[];#e=!1;#i;#s=-1;constructor(t=128){this.#i=t}add({cmd:t,undo:e,post:s,mustExec:i,type:n=NaN,overwriteIfSameType:r=!1,keepUndo:a=!1}){if(i&&t(),this.#e)return;const o={cmd:t,undo:e,post:s,type:n};if(this.#s===-1){this.#t.length>0&&(this.#t.length=0),this.#s=0,this.#t.push(o);return}if(r&&this.#t[this.#s].type===n){a&&(o.undo=this.#t[this.#s].undo),this.#t[this.#s]=o;return}const l=this.#s+1;l===this.#i?this.#t.splice(0,1):(this.#s=l,l<this.#t.length&&this.#t.splice(l)),this.#t.push(o)}undo(){if(this.#s===-1)return;this.#e=!0;const{undo:t,post:e}=this.#t[this.#s];t(),e?.(),this.#e=!1,this.#s-=1}redo(){if(this.#s<this.#t.length-1){this.#s+=1,this.#e=!0;const{cmd:t,post:e}=this.#t[this.#s];t(),e?.(),this.#e=!1}}hasSomethingToUndo(){return this.#s!==-1}hasSomethingToRedo(){return this.#s<this.#t.length-1}cleanType(t){if(this.#s!==-1){for(let e=this.#s;e>=0;e--)if(this.#t[e].type!==t){this.#t.splice(e+1,this.#s-e),this.#s=e;return}this.#t.length=0,this.#s=-1}}destroy(){this.#t=null}}class je{constructor(t){this.buffer=[],this.callbacks=new Map,this.allKeys=new Set;const{isMac:e}=bt.platform;for(const[s,i,n={}]of t)for(const r of s){const a=r.startsWith("mac+");e&&a?(this.callbacks.set(r.slice(4),{callback:i,options:n}),this.allKeys.add(r.split("+").at(-1))):!e&&!a&&(this.callbacks.set(r,{callback:i,options:n}),this.allKeys.add(r.split("+").at(-1)))}}#t(t){t.altKey&&this.buffer.push("alt"),t.ctrlKey&&this.buffer.push("ctrl"),t.metaKey&&this.buffer.push("meta"),t.shiftKey&&this.buffer.push("shift"),this.buffer.push(t.key);const e=this.buffer.join("+");return this.buffer.length=0,e}exec(t,e){if(!this.allKeys.has(e.key))return;const s=this.callbacks.get(this.#t(e));if(!s)return;const{callback:i,options:{bubbles:n=!1,args:r=[],checker:a=null}}=s;a&&!a(t,e)||(i.bind(t,...r,e)(),n||lt(e))}}class Ws{static _colorsMapping=new Map([["CanvasText",[0,0,0]],["Canvas",[255,255,255]]]);get _colors(){const t=new Map([["CanvasText",null],["Canvas",null]]);return pr(t),Y(this,"_colors",t)}convert(t){const e=_e(t);if(!window.matchMedia("(forced-colors: active)").matches)return e;for(const[s,i]of this._colors)if(i.every((n,r)=>n===e[r]))return Ws._colorsMapping.get(s);return e}getHexCode(t){const e=this._colors.get(t);return e?I.makeHexColor(...e):t}}class Yt{#t=new AbortController;#e=null;#i=null;#s=new Map;#a=new Map;#n=null;#r=null;#o=null;#h=new yr;#l=null;#u=null;#d=null;#f=0;#m=new Set;#p=null;#c=null;#g=new Set;_editorUndoBar=null;#b=!1;#A=!1;#y=!1;#C=null;#S=null;#w=null;#T=null;#_=!1;#E=null;#R=new br;#P=!1;#k=!1;#O=!1;#L=null;#I=null;#B=null;#F=null;#z=null;#x=V.NONE;#v=new Set;#D=null;#H=null;#j=null;#X=null;#W=null;#q={isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1};#$=[0,0];#N=null;#V=null;#J=null;#Z=null;#U=null;static TRANSLATE_SMALL=1;static TRANSLATE_BIG=10;static get _keyboardManager(){const t=Yt.prototype,e=r=>r.#V.contains(document.activeElement)&&document.activeElement.tagName!=="BUTTON"&&r.hasSomethingToControl(),s=(r,{target:a})=>{if(a instanceof HTMLInputElement){const{type:o}=a;return o!=="text"&&o!=="number"}return!0},i=this.TRANSLATE_SMALL,n=this.TRANSLATE_BIG;return Y(this,"_keyboardManager",new je([[["ctrl+a","mac+meta+a"],t.selectAll,{checker:s}],[["ctrl+z","mac+meta+z"],t.undo,{checker:s}],[["ctrl+y","ctrl+shift+z","mac+meta+shift+z","ctrl+shift+Z","mac+meta+shift+Z"],t.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"],t.delete,{checker:s}],[["Enter","mac+Enter"],t.addNewEditorFromKeyboard,{checker:(r,{target:a})=>!(a instanceof HTMLButtonElement)&&r.#V.contains(a)&&!r.isEnterHandled}],[[" ","mac+ "],t.addNewEditorFromKeyboard,{checker:(r,{target:a})=>!(a instanceof HTMLButtonElement)&&r.#V.contains(document.activeElement)}],[["Escape","mac+Escape"],t.unselectAll],[["ArrowLeft","mac+ArrowLeft"],t.translateSelectedEditors,{args:[-i,0],checker:e}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],t.translateSelectedEditors,{args:[-n,0],checker:e}],[["ArrowRight","mac+ArrowRight"],t.translateSelectedEditors,{args:[i,0],checker:e}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],t.translateSelectedEditors,{args:[n,0],checker:e}],[["ArrowUp","mac+ArrowUp"],t.translateSelectedEditors,{args:[0,-i],checker:e}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],t.translateSelectedEditors,{args:[0,-n],checker:e}],[["ArrowDown","mac+ArrowDown"],t.translateSelectedEditors,{args:[0,i],checker:e}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],t.translateSelectedEditors,{args:[0,n],checker:e}]]))}constructor(t,e,s,i,n,r,a,o,l,h,d,u,f,g,p,b){const m=this._signal=this.#t.signal;this.#V=t,this.#J=e,this.#Z=s,this.#n=i,this.#l=n,this.#H=r,this.#W=o,this._eventBus=a,a._on("editingaction",this.onEditingAction.bind(this),{signal:m}),a._on("pagechanging",this.onPageChanging.bind(this),{signal:m}),a._on("scalechanging",this.onScaleChanging.bind(this),{signal:m}),a._on("rotationchanging",this.onRotationChanging.bind(this),{signal:m}),a._on("setpreference",this.onSetPreference.bind(this),{signal:m}),a._on("switchannotationeditorparams",y=>this.updateParams(y.type,y.value),{signal:m}),window.addEventListener("pointerdown",()=>{this.#k=!0},{capture:!0,signal:m}),window.addEventListener("pointerup",()=>{this.#k=!1},{capture:!0,signal:m}),this.#lt(),this.#ut(),this.#et(),this.#r=o.annotationStorage,this.#C=o.filterFactory,this.#j=l,this.#T=h||null,this.#b=d,this.#A=u,this.#y=f,this.#z=g||null,this.viewParameters={realScale:ie.PDF_TO_CSS_UNITS,rotation:0},this.isShiftKeyDown=!1,this._editorUndoBar=p||null,this._supportsPinchToZoom=b!==!1,n?.setSidebarUiManager(this)}destroy(){this.#U?.resolve(),this.#U=null,this.#t?.abort(),this.#t=null,this._signal=null;for(const t of this.#a.values())t.destroy();this.#a.clear(),this.#s.clear(),this.#g.clear(),this.#F?.clear(),this.#e=null,this.#v.clear(),this.#h.destroy(),this.#n?.destroy(),this.#l?.destroy(),this.#H?.destroy(),this.#E?.hide(),this.#E=null,this.#B?.destroy(),this.#B=null,this.#i=null,this.#S&&(clearTimeout(this.#S),this.#S=null),this.#N&&(clearTimeout(this.#N),this.#N=null),this._editorUndoBar?.destroy(),this.#W=null}combinedSignal(t){return AbortSignal.any([this._signal,t.signal])}get mlManager(){return this.#z}get useNewAltTextFlow(){return this.#A}get useNewAltTextWhenAddingImage(){return this.#y}get hcmFilter(){return Y(this,"hcmFilter",this.#j?this.#C.addHCMFilter(this.#j.foreground,this.#j.background):"none")}get direction(){return Y(this,"direction",getComputedStyle(this.#V).direction)}get _highlightColors(){return Y(this,"_highlightColors",this.#T?new Map(this.#T.split(",").map(t=>(t=t.split("=").map(e=>e.trim()),t[1]=t[1].toUpperCase(),t))):null)}get highlightColors(){const{_highlightColors:t}=this;if(!t)return Y(this,"highlightColors",null);const e=new Map,s=!!this.#j;for(const[i,n]of t){const r=i.endsWith("_HCM");if(s&&r){e.set(i.replace("_HCM",""),n);continue}!s&&!r&&e.set(i,n)}return Y(this,"highlightColors",e)}get highlightColorNames(){return Y(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.#d=t}setMainHighlightColorPicker(t){this.#B=t}editAltText(t,e=!1){this.#n?.editAltText(this,t,e)}hasCommentManager(){return!!this.#l}editComment(t,e,s,i){this.#l?.showDialog(this,t,e,s,i)}selectComment(t,e){this.#a.get(t)?.getEditorByUID(e)?.toggleComment(!0,!0)}updateComment(t){this.#l?.updateComment(t.getData())}updatePopupColor(t){this.#l?.updatePopupColor(t)}removeComment(t){this.#l?.removeComments([t.uid])}toggleComment(t,e,s=void 0){this.#l?.toggleCommentPopup(t,e,s)}makeCommentColor(t,e){return t&&this.#l?.makeCommentColor(t,e)||null}getCommentDialogElement(){return this.#l?.dialogElement||null}async waitForEditorsRendered(t){if(this.#a.has(t-1))return;const{resolve:e,promise:s}=Promise.withResolvers(),i=n=>{n.pageNumber===t&&(this._eventBus._off("editorsrendered",i),e())};this._eventBus.on("editorsrendered",i),await s}getSignature(t){this.#H?.getSignature({uiManager:this,editor:t})}get signatureManager(){return this.#H}switchToMode(t,e){this._eventBus.on("annotationeditormodechanged",e,{once:!0,signal:this._signal}),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}){switch(t){case"enableNewAltTextWhenAddingImage":this.#y=e;break}}onPageChanging({pageNumber:t}){this.#f=t-1}focusMainContainer(){this.#V.focus()}findParent(t,e){for(const s of this.#a.values()){const{x:i,y:n,width:r,height:a}=s.div.getBoundingClientRect();if(t>=i&&t<=i+r&&e>=n&&e<=n+a)return s}return null}disableUserSelect(t=!1){this.#J.classList.toggle("noUserSelect",t)}addShouldRescale(t){this.#g.add(t)}removeShouldRescale(t){this.#g.delete(t)}onScaleChanging({scale:t}){this.commitOrRemove(),this.viewParameters.realScale=t*ie.PDF_TO_CSS_UNITS;for(const e of this.#g)e.onScaleChanging();this.#d?.onScaleChanging()}onRotationChanging({pagesRotation:t}){this.commitOrRemove(),this.viewParameters.rotation=t}#Q({anchorNode:t}){return t.nodeType===Node.TEXT_NODE?t.parentElement:t}#tt(t){const{currentLayer:e}=this;if(e.hasTextLayer(t))return e;for(const s of this.#a.values())if(s.hasTextLayer(t))return s;return null}highlightSelection(t="",e=!1){const s=document.getSelection();if(!s||s.isCollapsed)return;const{anchorNode:i,anchorOffset:n,focusNode:r,focusOffset:a}=s,o=s.toString(),h=this.#Q(s).closest(".textLayer"),d=this.getSelectionBoxes(h);if(!d)return;s.empty();const u=this.#tt(h),f=this.#x===V.NONE,g=()=>{const p=u?.createAndAddNewEditor({x:0,y:0},!1,{methodOfCreation:t,boxes:d,anchorNode:i,anchorOffset:n,focusNode:r,focusOffset:a,text:o});f&&this.showAllEditors("highlight",!0,!0),e&&p?.editComment()};if(f){this.switchToMode(V.HIGHLIGHT,g);return}g()}commentSelection(t=""){this.highlightSelection(t,!0)}#at(){const t=document.getSelection();if(!t||t.isCollapsed)return;const s=this.#Q(t).closest(".textLayer"),i=this.getSelectionBoxes(s);i&&(this.#E||=new mr(this),this.#E.show(s,i,this.direction==="ltr"))}getAndRemoveDataFromAnnotationStorage(t){if(!this.#r)return null;const e=`${Me}${t}`,s=this.#r.getRawValue(e);return s&&this.#r.remove(e),s}addToAnnotationStorage(t){!t.isEmpty()&&this.#r&&!this.#r.has(t.id)&&this.#r.setValue(t.id,t)}a11yAlert(t,e=null){const s=this.#Z;s&&(s.setAttribute("data-l10n-id",t),e?s.setAttribute("data-l10n-args",JSON.stringify(e)):s.removeAttribute("data-l10n-args"))}#ot(){const t=document.getSelection();if(!t||t.isCollapsed){this.#D&&(this.#E?.hide(),this.#D=null,this.#M({hasSelectedText:!1}));return}const{anchorNode:e}=t;if(e===this.#D)return;const i=this.#Q(t).closest(".textLayer");if(!i){this.#D&&(this.#E?.hide(),this.#D=null,this.#M({hasSelectedText:!1}));return}if(this.#E?.hide(),this.#D=e,this.#M({hasSelectedText:!0}),!(this.#x!==V.HIGHLIGHT&&this.#x!==V.NONE)&&(this.#x===V.HIGHLIGHT&&this.showAllEditors("highlight",!0,!0),this.#_=this.isShiftKeyDown,!this.isShiftKeyDown)){const n=this.#x===V.HIGHLIGHT?this.#tt(i):null;if(n?.toggleDrawing(),this.#k){const r=new AbortController,a=this.combinedSignal(r),o=l=>{l.type==="pointerup"&&l.button!==0||(r.abort(),n?.toggleDrawing(!0),l.type==="pointerup"&&this.#Y("main_toolbar"))};window.addEventListener("pointerup",o,{signal:a}),window.addEventListener("blur",o,{signal:a})}else n?.toggleDrawing(!0),this.#Y("main_toolbar")}}#Y(t=""){this.#x===V.HIGHLIGHT?this.highlightSelection(t):this.#b&&this.#at()}#lt(){document.addEventListener("selectionchange",this.#ot.bind(this),{signal:this._signal})}#ht(){if(this.#w)return;this.#w=new AbortController;const t=this.combinedSignal(this.#w);window.addEventListener("focus",this.focus.bind(this),{signal:t}),window.addEventListener("blur",this.blur.bind(this),{signal:t})}#ct(){this.#w?.abort(),this.#w=null}blur(){if(this.isShiftKeyDown=!1,this.#_&&(this.#_=!1,this.#Y("main_toolbar")),!this.hasSelection)return;const{activeElement:t}=document;for(const e of this.#v)if(e.div.contains(t)){this.#I=[e,t],e._focusEventsAllowed=!1;break}}focus(){if(!this.#I)return;const[t,e]=this.#I;this.#I=null,e.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this._signal}),e.focus()}#et(){if(this.#L)return;this.#L=new AbortController;const t=this.combinedSignal(this.#L);window.addEventListener("keydown",this.keydown.bind(this),{signal:t}),window.addEventListener("keyup",this.keyup.bind(this),{signal:t})}#dt(){this.#L?.abort(),this.#L=null}#st(){if(this.#u)return;this.#u=new AbortController;const t=this.combinedSignal(this.#u);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})}#it(){this.#u?.abort(),this.#u=null}#ut(){const t=this._signal;document.addEventListener("dragover",this.dragOver.bind(this),{signal:t}),document.addEventListener("drop",this.drop.bind(this),{signal:t})}addEditListeners(){this.#et(),this.#st()}removeEditListeners(){this.#dt(),this.#it()}dragOver(t){for(const{type:e}of t.dataTransfer.items)for(const s of this.#c)if(s.isHandlingMimeForPasting(e)){t.dataTransfer.dropEffect="copy",t.preventDefault();return}}drop(t){for(const e of t.dataTransfer.items)for(const s of this.#c)if(s.isHandlingMimeForPasting(e.type)){s.paste(e,this.currentLayer),t.preventDefault();return}}copy(t){if(t.preventDefault(),this.#e?.commitOrRemove(),!this.hasSelection)return;const e=[];for(const s of this.#v){const i=s.serialize(!0);i&&e.push(i)}e.length!==0&&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 n of e.items)for(const r of this.#c)if(r.isHandlingMimeForPasting(n.type)){r.paste(n,this.currentLayer);return}let s=e.getData("application/pdfjs");if(!s)return;try{s=JSON.parse(s)}catch(n){W(`paste: "${n.message}".`);return}if(!Array.isArray(s))return;this.unselectAll();const i=this.currentLayer;try{const n=[];for(const o of s){const l=await i.deserialize(o);if(!l)return;n.push(l)}const r=()=>{for(const o of n)this.#nt(o);this.#rt(n)},a=()=>{for(const o of n)o.remove()};this.addCommands({cmd:r,undo:a,mustExec:!0})}catch(n){W(`paste: "${n.message}".`)}}keydown(t){!this.isShiftKeyDown&&t.key==="Shift"&&(this.isShiftKeyDown=!0),this.#x!==V.NONE&&!this.isEditorHandlingKeyboard&&Yt._keyboardManager.exec(this,t)}keyup(t){this.isShiftKeyDown&&t.key==="Shift"&&(this.isShiftKeyDown=!1,this.#_&&(this.#_=!1,this.#Y("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");break}}#M(t){Object.entries(t).some(([s,i])=>this.#q[s]!==i)&&(this._eventBus.dispatch("annotationeditorstateschanged",{source:this,details:Object.assign(this.#q,t)}),this.#x===V.HIGHLIGHT&&t.hasSelectedEditor===!1&&this.#G([[Q.HIGHLIGHT_FREE,!0]]))}#G(t){this._eventBus.dispatch("annotationeditorparamschanged",{source:this,details:t})}setEditingState(t){t?(this.#ht(),this.#st(),this.#M({isEditing:this.#x!==V.NONE,isEmpty:this.#K(),hasSomethingToUndo:this.#h.hasSomethingToUndo(),hasSomethingToRedo:this.#h.hasSomethingToRedo(),hasSelectedEditor:!1})):(this.#ct(),this.#it(),this.#M({isEditing:!1}),this.disableUserSelect(!1))}registerEditorTypes(t){if(!this.#c){this.#c=t;for(const e of this.#c)this.#G(e.defaultPropertiesToUpdate)}}getId(){return this.#R.id}get currentLayer(){return this.#a.get(this.#f)}getLayer(t){return this.#a.get(t)}get currentPageIndex(){return this.#f}addLayer(t){this.#a.set(t.pageIndex,t),this.#P?t.enable():t.disable()}removeLayer(t){this.#a.delete(t.pageIndex)}async updateMode(t,e=null,s=!1,i=!1,n=!1){if(this.#x!==t&&!(this.#U&&(await this.#U.promise,!this.#U))){if(this.#U=Promise.withResolvers(),this.#d?.commitOrRemove(),this.#x===V.POPUP&&this.#l?.hideSidebar(),this.#l?.destroyPopup(),this.#x=t,t===V.NONE){this.setEditingState(!1),this.#pt();for(const r of this.#s.values())r.hideStandaloneCommentButton();this._editorUndoBar?.hide(),this.toggleComment(null),this.#U.resolve();return}for(const r of this.#s.values())r.addStandaloneCommentButton();t===V.SIGNATURE&&await this.#H?.loadSignatures(),this.setEditingState(!0),await this.#ft(),this.unselectAll();for(const r of this.#a.values())r.updateMode(t);if(t===V.POPUP){this.#i||=await this.#W.getAnnotationsByType(new Set(this.#c.map(o=>o._editorType)));const r=new Set,a=[];for(const o of this.#s.values()){const{annotationElementId:l,hasComment:h,deleted:d}=o;l&&r.add(l),h&&!d&&a.push(o.getData())}for(const o of this.#i){const{id:l,popupRef:h,contentsObj:d}=o;h&&d?.str&&!r.has(l)&&!this.#m.has(l)&&a.push(o)}this.#l?.showSidebar(a)}if(!e){s&&this.addNewEditorFromKeyboard(),this.#U.resolve();return}for(const r of this.#s.values())r.uid===e?(this.setSelected(r),n?r.editComment():i?r.enterInEditMode():r.focus()):r.unselect();this.#U.resolve()}}addNewEditorFromKeyboard(){this.currentLayer.canCreateNewEmptyEditor()&&this.currentLayer.addNewEditor()}updateToolbar(t){t.mode!==this.#x&&this._eventBus.dispatch("switchannotationeditormode",{source:this,...t})}updateParams(t,e){if(this.#c){switch(t){case Q.CREATE:this.currentLayer.addNewEditor(e);return;case Q.HIGHLIGHT_SHOW_ALL:this._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:{type:"highlight",action:"toggle_visibility"}}}),(this.#X||=new Map).set(t,e),this.showAllEditors("highlight",e);break}if(this.hasSelection)for(const s of this.#v)s.updateParams(t,e);else for(const s of this.#c)s.updateDefaultParams(t,e)}}showAllEditors(t,e,s=!1){for(const n of this.#s.values())n.editorType===t&&n.show(e);(this.#X?.get(Q.HIGHLIGHT_SHOW_ALL)??!0)!==e&&this.#G([[Q.HIGHLIGHT_SHOW_ALL,e]])}enableWaiting(t=!1){if(this.#O!==t){this.#O=t;for(const e of this.#a.values())t?e.disableClick():e.enableClick(),e.div.classList.toggle("waiting",t)}}async#ft(){if(!this.#P){this.#P=!0;const t=[];for(const e of this.#a.values())t.push(e.enable());await Promise.all(t);for(const e of this.#s.values())e.enable()}}#pt(){if(this.unselectAll(),this.#P){this.#P=!1;for(const t of this.#a.values())t.disable();for(const t of this.#s.values())t.disable()}}*getEditors(t){for(const e of this.#s.values())e.pageIndex===t&&(yield e)}getEditor(t){return this.#s.get(t)}addEditor(t){this.#s.set(t.id,t)}removeEditor(t){t.div.contains(document.activeElement)&&(this.#S&&clearTimeout(this.#S),this.#S=setTimeout(()=>{this.focusMainContainer(),this.#S=null},0)),this.#s.delete(t.id),t.annotationElementId&&this.#F?.delete(t.annotationElementId),this.unselect(t),(!t.annotationElementId||!this.#m.has(t.annotationElementId))&&this.#r?.remove(t.id)}addDeletedAnnotationElement(t){this.#m.add(t.annotationElementId),this.addChangedExistingAnnotation(t),t.deleted=!0}isDeletedAnnotationElement(t){return this.#m.has(t)}removeDeletedAnnotationElement(t){this.#m.delete(t.annotationElementId),this.removeChangedExistingAnnotation(t),t.deleted=!1}#nt(t){const e=this.#a.get(t.pageIndex);e?e.addOrRebuild(t):(this.addEditor(t),this.addToAnnotationStorage(t))}setActiveEditor(t){this.#e!==t&&(this.#e=t,t&&this.#G(t.propertiesToUpdate))}get#gt(){let t=null;for(t of this.#v);return t}updateUI(t){this.#gt===t&&this.#G(t.propertiesToUpdate)}updateUIForDefaultProperties(t){this.#G(t.defaultPropertiesToUpdate)}toggleSelected(t){if(this.#v.has(t)){this.#v.delete(t),t.unselect(),this.#M({hasSelectedEditor:this.hasSelection});return}this.#v.add(t),t.select(),this.#G(t.propertiesToUpdate),this.#M({hasSelectedEditor:!0})}setSelected(t){this.updateToolbar({mode:t.mode,editId:t.id}),this.#d?.commitOrRemove();for(const e of this.#v)e!==t&&e.unselect();this.#v.clear(),this.#v.add(t),t.select(),this.#G(t.propertiesToUpdate),this.#M({hasSelectedEditor:!0})}isSelected(t){return this.#v.has(t)}get firstSelectedEditor(){return this.#v.values().next().value}unselect(t){t.unselect(),this.#v.delete(t),this.#M({hasSelectedEditor:this.hasSelection})}get hasSelection(){return this.#v.size!==0}get isEnterHandled(){return this.#v.size===1&&this.firstSelectedEditor.isEnterHandled}undo(){this.#h.undo(),this.#M({hasSomethingToUndo:this.#h.hasSomethingToUndo(),hasSomethingToRedo:!0,isEmpty:this.#K()}),this._editorUndoBar?.hide()}redo(){this.#h.redo(),this.#M({hasSomethingToUndo:!0,hasSomethingToRedo:this.#h.hasSomethingToRedo(),isEmpty:this.#K()})}addCommands(t){this.#h.add(t),this.#M({hasSomethingToUndo:!0,hasSomethingToRedo:!1,isEmpty:this.#K()})}cleanUndoStack(t){this.#h.cleanType(t)}#K(){if(this.#s.size===0)return!0;if(this.#s.size===1)for(const t of this.#s.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.#v],s=()=>{this._editorUndoBar?.show(i,e.length===1?e[0].editorType:e.length);for(const n of e)n.remove()},i=()=>{for(const n of e)this.#nt(n)};this.addCommands({cmd:s,undo:i,mustExec:!0})}commitOrRemove(){this.#e?.commitOrRemove()}hasSomethingToControl(){return this.#e||this.hasSelection}#rt(t){for(const e of this.#v)e.unselect();this.#v.clear();for(const e of t)e.isEmpty()||(this.#v.add(e),e.select());this.#M({hasSelectedEditor:this.hasSelection})}selectAll(){for(const t of this.#v)t.commit();this.#rt(this.#s.values())}unselectAll(){if(!(this.#e&&(this.#e.commitOrRemove(),this.#x!==V.NONE))&&!this.#d?.commitOrRemove()&&this.hasSelection){for(const t of this.#v)t.unselect();this.#v.clear(),this.#M({hasSelectedEditor:!1})}}translateSelectedEditors(t,e,s=!1){if(s||this.commitOrRemove(),!this.hasSelection)return;this.#$[0]+=t,this.#$[1]+=e;const[i,n]=this.#$,r=[...this.#v],a=1e3;this.#N&&clearTimeout(this.#N),this.#N=setTimeout(()=>{this.#N=null,this.#$[0]=this.#$[1]=0,this.addCommands({cmd:()=>{for(const o of r)this.#s.has(o.id)&&(o.translateInPage(i,n),o.translationDone())},undo:()=>{for(const o of r)this.#s.has(o.id)&&(o.translateInPage(-i,-n),o.translationDone())},mustExec:!1})},a);for(const o of r)o.translateInPage(t,e),o.translationDone()}setUpDragSession(){if(this.hasSelection){this.disableUserSelect(!0),this.#p=new Map;for(const t of this.#v)this.#p.set(t,{savedX:t.x,savedY:t.y,savedPageIndex:t.pageIndex,newX:0,newY:0,newPageIndex:-1})}}endDragSession(){if(!this.#p)return!1;this.disableUserSelect(!1);const t=this.#p;this.#p=null;let e=!1;for(const[{x:i,y:n,pageIndex:r},a]of t)a.newX=i,a.newY=n,a.newPageIndex=r,e||=i!==a.savedX||n!==a.savedY||r!==a.savedPageIndex;if(!e)return!1;const s=(i,n,r,a)=>{if(this.#s.has(i.id)){const o=this.#a.get(a);o?i._setParentAndPosition(o,n,r):(i.pageIndex=a,i.x=n,i.y=r)}};return this.addCommands({cmd:()=>{for(const[i,{newX:n,newY:r,newPageIndex:a}]of t)s(i,n,r,a)},undo:()=>{for(const[i,{savedX:n,savedY:r,savedPageIndex:a}]of t)s(i,n,r,a)},mustExec:!0}),!0}dragSelectedEditors(t,e){if(this.#p)for(const s of this.#p.keys())s.drag(t,e)}rebuild(t){if(t.parent===null){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()||this.#v.size===1&&this.firstSelectedEditor.shouldGetKeyboardEvents()}isActive(t){return this.#e===t}getActive(){return this.#e}getMode(){return this.#x}isEditingMode(){return this.#x!==V.NONE}get imageManager(){return Y(this,"imageManager",new Vs)}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:s,y:i,width:n,height:r}=t.getBoundingClientRect();let a;switch(t.getAttribute("data-main-rotation")){case"90":a=(l,h,d,u)=>({x:(h-i)/r,y:1-(l+d-s)/n,width:u/r,height:d/n});break;case"180":a=(l,h,d,u)=>({x:1-(l+d-s)/n,y:1-(h+u-i)/r,width:d/n,height:u/r});break;case"270":a=(l,h,d,u)=>({x:1-(h+u-i)/r,y:(l-s)/n,width:u/r,height:d/n});break;default:a=(l,h,d,u)=>({x:(l-s)/n,y:(h-i)/r,width:d/n,height:u/r});break}const o=[];for(let l=0,h=e.rangeCount;l<h;l++){const d=e.getRangeAt(l);if(!d.collapsed)for(const{x:u,y:f,width:g,height:p}of d.getClientRects())g===0||p===0||o.push(a(u,f,g,p))}return o.length===0?null:o}addChangedExistingAnnotation({annotationElementId:t,id:e}){(this.#o||=new Map).set(t,e)}removeChangedExistingAnnotation({annotationElementId:t}){this.#o?.delete(t)}renderAnnotationElement(t){const e=this.#o?.get(t.data.id);if(!e)return;const s=this.#r.getRawValue(e);s&&(this.#x===V.NONE&&!s.hasBeenModified||s.renderAnnotationElement(t))}setMissingCanvas(t,e,s){const i=this.#F?.get(t);i&&(i.setCanvas(e,s),this.#F.delete(t))}addMissingCanvas(t,e){(this.#F||=new Map).set(t,e)}}class zt{#t=null;#e=!1;#i=null;#s=null;#a=null;#n=null;#r=!1;#o=null;#h=null;#l=null;#u=null;#d=!1;static#f=null;static _l10n=null;constructor(t){this.#h=t,this.#d=t._uiManager.useNewAltTextFlow,zt.#f||=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(t){zt._l10n??=t}async render(){const t=this.#i=document.createElement("button");t.className="altText",t.tabIndex="0";const e=this.#s=document.createElement("span");t.append(e),this.#d?(t.classList.add("new"),t.setAttribute("data-l10n-id",zt.#f.missing),e.setAttribute("data-l10n-id",zt.#f["missing-label"])):(t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button"),e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button-label"));const s=this.#h._uiManager._signal;t.addEventListener("contextmenu",Dt,{signal:s}),t.addEventListener("pointerdown",n=>n.stopPropagation(),{signal:s});const i=n=>{n.preventDefault(),this.#h._uiManager.editAltText(this.#h),this.#d&&this.#h._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_clicked",data:{label:this.#m}})};return t.addEventListener("click",i,{capture:!0,signal:s}),t.addEventListener("keydown",n=>{n.target===t&&n.key==="Enter"&&(this.#r=!0,i(n))},{signal:s}),await this.#p(),t}get#m(){return this.#t&&"added"||this.#t===null&&this.guessedText&&"review"||"missing"}finish(){this.#i&&(this.#i.focus({focusVisible:this.#r}),this.#r=!1)}isEmpty(){return this.#d?this.#t===null:!this.#t&&!this.#e}hasData(){return this.#d?this.#t!==null||!!this.#l:this.isEmpty()}get guessedText(){return this.#l}async setGuessedText(t){this.#t===null&&(this.#l=t,this.#u=await zt._l10n.get("pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer",{generatedAltText:t}),this.#p())}toggleAltTextBadge(t=!1){if(!this.#d||this.#t){this.#o?.remove(),this.#o=null;return}if(!this.#o){const e=this.#o=document.createElement("div");e.className="noAltTextBadge",this.#h.div.append(e)}this.#o.classList.toggle("hidden",!t)}serialize(t){let e=this.#t;return!t&&this.#l===e&&(e=this.#u),{altText:e,decorative:this.#e,guessedText:this.#l,textWithDisclaimer:this.#u}}get data(){return{altText:this.#t,decorative:this.#e}}set data({altText:t,decorative:e,guessedText:s,textWithDisclaimer:i,cancel:n=!1}){s&&(this.#l=s,this.#u=i),!(this.#t===t&&this.#e===e)&&(n||(this.#t=t,this.#e=e),this.#p())}toggle(t=!1){this.#i&&(!t&&this.#n&&(clearTimeout(this.#n),this.#n=null),this.#i.disabled=!t)}shown(){this.#h._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_displayed",data:{label:this.#m}})}destroy(){this.#i?.remove(),this.#i=null,this.#s=null,this.#a=null,this.#o?.remove(),this.#o=null}async#p(){const t=this.#i;if(!t)return;if(this.#d){if(t.classList.toggle("done",!!this.#t),t.setAttribute("data-l10n-id",zt.#f[this.#m]),this.#s?.setAttribute("data-l10n-id",zt.#f[`${this.#m}-label`]),!this.#t){this.#a?.remove();return}}else{if(!this.#t&&!this.#e){t.classList.remove("done"),this.#a?.remove();return}t.classList.add("done"),t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-edit-button")}let e=this.#a;if(!e){this.#a=e=document.createElement("span"),e.className="tooltip",e.setAttribute("role","tooltip"),e.id=`alt-text-tooltip-${this.#h.id}`;const i=100,n=this.#h._uiManager._signal;n.addEventListener("abort",()=>{clearTimeout(this.#n),this.#n=null},{once:!0}),t.addEventListener("mouseenter",()=>{this.#n=setTimeout(()=>{this.#n=null,this.#a.classList.add("show"),this.#h._reportTelemetry({action:"alt_text_tooltip"})},i)},{signal:n}),t.addEventListener("mouseleave",()=>{this.#n&&(clearTimeout(this.#n),this.#n=null),this.#a?.classList.remove("show")},{signal:n})}this.#e?e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-decorative-tooltip"):(e.removeAttribute("data-l10n-id"),e.textContent=this.#t),e.parentNode||t.append(e),this.#h.getElementForAltText()?.setAttribute("aria-describedby",e.id)}}class qe{#t=null;#e=null;#i=!1;#s=null;#a=null;#n=null;#r=null;#o=null;#h=!1;#l=null;constructor(t){this.#s=t}renderForToolbar(){const t=this.#e=document.createElement("button");return t.className="comment",this.#u(t,!1)}renderForStandalone(){const t=this.#t=document.createElement("button");t.className="annotationCommentButton";const e=this.#s.commentButtonPosition;if(e){const{style:s}=t;s.insetInlineEnd=`calc(${100*(this.#s._uiManager.direction==="ltr"?1-e[0]:e[0])}% - var(--comment-button-dim))`,s.top=`calc(${100*e[1]}% - var(--comment-button-dim))`;const i=this.#s.commentButtonColor;i&&(s.backgroundColor=i)}return this.#u(t,!0)}focusButton(){setTimeout(()=>{(this.#t??this.#e)?.focus()},0)}onUpdatedColor(){if(!this.#t)return;const t=this.#s.commentButtonColor;t&&(this.#t.style.backgroundColor=t),this.#s._uiManager.updatePopupColor(this.#s)}get commentButtonWidth(){return(this.#t?.getBoundingClientRect().width??0)/this.#s.parent.boundingClientRect.width}get commentPopupPositionInLayer(){if(this.#l)return this.#l;if(!this.#t)return null;const{x:t,y:e,height:s}=this.#t.getBoundingClientRect(),{x:i,y:n,width:r,height:a}=this.#s.parent.boundingClientRect;return[(t-i)/r,(e+s-n)/a]}set commentPopupPositionInLayer(t){this.#l=t}hasDefaultPopupPosition(){return this.#l===null}removeStandaloneCommentButton(){this.#t?.remove(),this.#t=null}removeToolbarCommentButton(){this.#e?.remove(),this.#e=null}setCommentButtonStates({selected:t,hasPopup:e}){this.#t&&(this.#t.classList.toggle("selected",t),this.#t.ariaExpanded=e)}#u(t,e){if(!this.#s._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.#s._uiManager.getCommentDialogElement()],t.setAttribute("data-l10n-id","pdfjs-editor-edit-comment-button"));const s=this.#s._uiManager._signal;if(!(s instanceof AbortSignal)||s.aborted)return t;t.addEventListener("contextmenu",Dt,{signal:s}),e&&(t.addEventListener("focusin",n=>{this.#s._focusEventsAllowed=!1,lt(n)},{capture:!0,signal:s}),t.addEventListener("focusout",n=>{this.#s._focusEventsAllowed=!0,lt(n)},{capture:!0,signal:s})),t.addEventListener("pointerdown",n=>n.stopPropagation(),{signal:s});const i=n=>{n.preventDefault(),t===this.#e?this.edit():this.#s.toggleComment(!0)};return t.addEventListener("click",i,{capture:!0,signal:s}),t.addEventListener("keydown",n=>{n.target===t&&n.key==="Enter"&&(this.#i=!0,i(n))},{signal:s}),t.addEventListener("pointerenter",()=>{this.#s.toggleComment(!1,!0)},{signal:s}),t.addEventListener("pointerleave",()=>{this.#s.toggleComment(!1,!1)},{signal:s}),t}edit(t){const e=this.commentPopupPositionInLayer;let s,i;if(e)[s,i]=e;else{[s,i]=this.#s.commentButtonPosition;const{width:h,height:d,x:u,y:f}=this.#s;s=u+s*h,i=f+i*d}const n=this.#s.parent.boundingClientRect,{x:r,y:a,width:o,height:l}=n;this.#s._uiManager.editComment(this.#s,r+s*o,a+i*l,{...t,parentDimensions:n})}finish(){this.#e&&(this.#e.focus({focusVisible:this.#i}),this.#i=!1)}isDeleted(){return this.#h||this.#r===""}isEmpty(){return this.#r===null}hasBeenEdited(){return this.isDeleted()||this.#r!==this.#a}serialize(){return this.data}get data(){return{text:this.#r,richText:this.#n,date:this.#o,deleted:this.isDeleted()}}set data(t){if(t!==this.#r&&(this.#n=null),t===null){this.#r="",this.#h=!0;return}this.#r=t,this.#o=new Date,this.#h=!1}setInitialText(t,e=null){this.#a=t,this.data=t,this.#o=null,this.#n=e}shown(){}destroy(){this.#e?.remove(),this.#e=null,this.#t?.remove(),this.#t=null,this.#r="",this.#n=null,this.#o=null,this.#s=null,this.#i=!1,this.#h=!1}}class $e{#t;#e=!1;#i=null;#s;#a;#n;#r;#o=null;#h;#l=null;#u;#d=null;constructor({container:t,isPinchingDisabled:e=null,isPinchingStopped:s=null,onPinchStart:i=null,onPinching:n=null,onPinchEnd:r=null,signal:a}){this.#t=t,this.#i=s,this.#s=e,this.#a=i,this.#n=n,this.#r=r,this.#u=new AbortController,this.#h=AbortSignal.any([a,this.#u.signal]),t.addEventListener("touchstart",this.#f.bind(this),{passive:!1,signal:this.#h})}get MIN_TOUCH_DISTANCE_TO_PINCH(){return 35/Ht.pixelRatio}#f(t){if(this.#s?.())return;if(t.touches.length===1){if(this.#o)return;const i=this.#o=new AbortController,n=AbortSignal.any([this.#h,i.signal]),r=this.#t,a={capture:!0,signal:n,passive:!1},o=l=>{l.pointerType==="touch"&&(this.#o?.abort(),this.#o=null)};r.addEventListener("pointerdown",l=>{l.pointerType==="touch"&&(lt(l),o(l))},a),r.addEventListener("pointerup",o,a),r.addEventListener("pointercancel",o,a);return}if(!this.#d){this.#d=new AbortController;const i=AbortSignal.any([this.#h,this.#d.signal]),n=this.#t,r={signal:i,capture:!1,passive:!1};n.addEventListener("touchmove",this.#m.bind(this),r);const a=this.#p.bind(this);n.addEventListener("touchend",a,r),n.addEventListener("touchcancel",a,r),r.capture=!0,n.addEventListener("pointerdown",lt,r),n.addEventListener("pointermove",lt,r),n.addEventListener("pointercancel",lt,r),n.addEventListener("pointerup",lt,r),this.#a?.()}if(lt(t),t.touches.length!==2||this.#i?.()){this.#l=null;return}let[e,s]=t.touches;e.identifier>s.identifier&&([e,s]=[s,e]),this.#l={touch0X:e.screenX,touch0Y:e.screenY,touch1X:s.screenX,touch1Y:s.screenY}}#m(t){if(!this.#l||t.touches.length!==2)return;lt(t);let[e,s]=t.touches;e.identifier>s.identifier&&([e,s]=[s,e]);const{screenX:i,screenY:n}=e,{screenX:r,screenY:a}=s,o=this.#l,{touch0X:l,touch0Y:h,touch1X:d,touch1Y:u}=o,f=d-l,g=u-h,p=r-i,b=a-n,m=Math.hypot(p,b)||1,y=Math.hypot(f,g)||1;if(!this.#e&&Math.abs(y-m)<=$e.MIN_TOUCH_DISTANCE_TO_PINCH)return;if(o.touch0X=i,o.touch0Y=n,o.touch1X=r,o.touch1Y=a,!this.#e){this.#e=!0;return}const A=[(i+r)/2,(n+a)/2];this.#n?.(A,y,m)}#p(t){t.touches.length>=2||(this.#d&&(this.#d.abort(),this.#d=null,this.#r?.()),this.#l&&(lt(t),this.#l=null,this.#e=!1))}destroy(){this.#u?.abort(),this.#u=null,this.#o?.abort(),this.#o=null}}class B{#t=null;#e=null;#i=null;#s=null;#a=null;#n=!1;#r=null;#o="";#h=null;#l=null;#u=null;#d=null;#f=null;#m="";#p=!1;#c=null;#g=!1;#b=!1;#A=!1;#y=null;#C=0;#S=0;#w=null;#T=null;isSelected=!1;_isCopy=!1;_editToolbar=null;_initialOptions=Object.create(null);_initialData=null;_isVisible=!0;_uiManager=null;_focusEventsAllowed=!0;static _l10n=null;static _l10nResizer=null;#_=!1;#E=B._zIndex++;static _borderLineWidth=-1;static _colorManager=new Ws;static _zIndex=1;static _telemetryTimeout=1e3;static get _resizerKeyboardManager(){const t=B.prototype._resizeWithKeyboard,e=Yt.TRANSLATE_SMALL,s=Yt.TRANSLATE_BIG;return Y(this,"_resizerKeyboardManager",new je([[["ArrowLeft","mac+ArrowLeft"],t,{args:[-e,0]}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],t,{args:[-s,0]}],[["ArrowRight","mac+ArrowRight"],t,{args:[e,0]}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],t,{args:[s,0]}],[["ArrowUp","mac+ArrowUp"],t,{args:[0,-e]}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],t,{args:[0,-s]}],[["ArrowDown","mac+ArrowDown"],t,{args:[0,e]}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],t,{args:[0,s]}],[["Escape","mac+Escape"],B.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||new Date,this.modificationDate=t.modificationDate||null;const{rotation:e,rawDims:{pageWidth:s,pageHeight:i,pageX:n,pageY:r}}=this.parent.viewport;this.rotation=e,this.pageRotation=(360+e-this._uiManager.viewParameters.rotation)%360,this.pageDimensions=[s,i],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}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 Y(this,"_defaultLineColor",this._colorManager.getHexCode("CanvasText"))}static deleteAnnotationElement(t){const e=new Ar({id:t.parent.getNextId(),parent:t.parent,uiManager:t._uiManager});e.annotationElementId=t.annotationElementId,e.deleted=!0,e._uiManager.addToAnnotationStorage(e)}static initialize(t,e){if(B._l10n??=t,B._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"}),B._borderLineWidth!==-1)return;const s=getComputedStyle(document.documentElement);B._borderLineWidth=parseFloat(s.getPropertyValue("--outline-width"))||0}static updateDefaultParams(t,e){}static get defaultPropertiesToUpdate(){return[]}static isHandlingMimeForPasting(t){return!1}static paste(t,e){nt("Not implemented")}get propertiesToUpdate(){return[]}get _isDraggable(){return this.#_}set _isDraggable(t){this.#_=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/(t*2),this.y+=this.width*t/(e*2);break;case 180:this.x+=this.width/2,this.y+=this.height/2;break;case 270:this.x+=this.height*e/(t*2),this.y-=this.width*t/(e*2);break;default:this.x-=this.width/2,this.y-=this.height/2;break}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.#E}setParent(t){t!==null?(this.pageIndex=t.pageIndex,this.pageDimensions=t.pageDimensions):(this.#N(),this.#d?.remove(),this.#d=null),this.parent=t}focusin(t){this._focusEventsAllowed&&(this.#p?this.#p=!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,s,i){const[n,r]=this.parentDimensions;[s,i]=this.screenToPageTranslation(s,i),this.x=(t+s)/n,this.y=(e+i)/r,this.fixAndSetPosition()}_moveAfterPaste(t,e){const[s,i]=this.parentDimensions;this.setAt(t*s,e*i,this.width*s,this.height*i),this._onTranslated()}#R([t,e],s,i){[s,i]=this.screenToPageTranslation(s,i),this.x+=s/t,this.y+=i/e,this._onTranslating(this.x,this.y),this.fixAndSetPosition()}translate(t,e){this.#R(this.parentDimensions,t,e)}translateInPage(t,e){this.#c||=[this.x,this.y,this.width,this.height],this.#R(this.pageDimensions,t,e),this.div.scrollIntoView({block:"nearest"})}translationDone(){this._onTranslated(this.x,this.y)}drag(t,e){this.#c||=[this.x,this.y,this.width,this.height];const{div:s,parentDimensions:[i,n]}=this;if(this.x+=t/i,this.y+=e/n,this.parent&&(this.x<0||this.x>1||this.y<0||this.y>1)){const{x:d,y:u}=this.div.getBoundingClientRect();this.parent.findNewParent(this,d,u)&&(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}=s;h.left=`${(100*r).toFixed(2)}%`,h.top=`${(100*a).toFixed(2)}%`,this._onTranslating(r,a),s.scrollIntoView({block:"nearest"})}_onTranslating(t,e){}_onTranslated(t,e){}get _hasBeenMoved(){return!!this.#c&&(this.#c[0]!==this.x||this.#c[1]!==this.y)}get _hasBeenResized(){return!!this.#c&&(this.#c[2]!==this.width||this.#c[3]!==this.height)}getBaseTranslation(){const[t,e]=this.parentDimensions,{_borderLineWidth:s}=B,i=s/t,n=s/e;switch(this.rotation){case 90:return[-i,n];case 180:return[i,n];case 270:return[i,-n];default:return[-i,-n]}}get _mustFixPosition(){return!0}fixAndSetPosition(t=this.rotation){const{div:{style:e},pageDimensions:[s,i]}=this;let{x:n,y:r,width:a,height:o}=this;if(a*=s,o*=i,n*=s,r*=i,this._mustFixPosition)switch(t){case 0:n=_t(n,0,s-a),r=_t(r,0,i-o);break;case 90:n=_t(n,0,s-o),r=_t(r,a,i);break;case 180:n=_t(n,a,s),r=_t(r,o,i);break;case 270:n=_t(n,o,s),r=_t(r,0,i-a);break}this.x=n/=s,this.y=r/=i;const[l,h]=this.getBaseTranslation();n+=l,r+=h,e.left=`${(100*n).toFixed(2)}%`,e.top=`${(100*r).toFixed(2)}%`,this.moveInDOM()}static#P(t,e,s){switch(s){case 90:return[e,-t];case 180:return[-t,-e];case 270:return[-e,t];default:return[t,e]}}screenToPageTranslation(t,e){return B.#P(t,e,this.parentRotation)}pageTranslationToScreen(t,e){return B.#P(t,e,360-this.parentRotation)}#k(t){switch(t){case 90:{const[e,s]=this.pageDimensions;return[0,-e/s,s/e,0]}case 180:return[-1,0,0,-1];case 270:{const[e,s]=this.pageDimensions;return[0,e/s,-s/e,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,s]}=this;return[e*t,s*t]}setDims(){const{div:{style:t},width:e,height:s}=this;t.width=`${(100*e).toFixed(2)}%`,t.height=`${(100*s).toFixed(2)}%`}getInitialTranslation(){return[0,0]}#O(){if(this.#h)return;this.#h=document.createElement("div"),this.#h.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 s of t){const i=document.createElement("div");this.#h.append(i),i.classList.add("resizer",s),i.setAttribute("data-resizer-name",s),i.addEventListener("pointerdown",this.#L.bind(this,s),{signal:e}),i.addEventListener("contextmenu",Dt,{signal:e}),i.tabIndex=-1}this.div.prepend(this.#h)}#L(t,e){e.preventDefault();const{isMac:s}=bt.platform;if(e.button!==0||e.ctrlKey&&s)return;this.#i?.toggle(!1);const i=this._isDraggable;this._isDraggable=!1,this.#l=[e.screenX,e.screenY];const n=new AbortController,r=this._uiManager.combinedSignal(n);this.parent.togglePointerEvents(!1),window.addEventListener("pointermove",this.#F.bind(this,t),{passive:!0,capture:!0,signal:r}),window.addEventListener("touchmove",lt,{passive:!1,signal:r}),window.addEventListener("contextmenu",Dt,{signal:r}),this.#u={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.#i?.toggle(!0),this._isDraggable=i,this.parent.div.style.cursor=a,this.div.style.cursor=o,this.#B()};window.addEventListener("pointerup",l,{signal:r}),window.addEventListener("blur",l,{signal:r})}#I(t,e,s,i){this.width=s,this.height=i,this.x=t,this.y=e,this.setDims(),this.fixAndSetPosition(),this._onResized()}_onResized(){}#B(){if(!this.#u)return;const{savedX:t,savedY:e,savedWidth:s,savedHeight:i}=this.#u;this.#u=null;const n=this.x,r=this.y,a=this.width,o=this.height;n===t&&r===e&&a===s&&o===i||this.addCommands({cmd:this.#I.bind(this,n,r,a,o),undo:this.#I.bind(this,t,e,s,i),mustExec:!0})}static _round(t){return Math.round(t*1e4)/1e4}#F(t,e){const[s,i]=this.parentDimensions,n=this.x,r=this.y,a=this.width,o=this.height,l=B.MIN_SIZE/s,h=B.MIN_SIZE/i,d=this.#k(this.rotation),u=(M,F)=>[d[0]*M+d[2]*F,d[1]*M+d[3]*F],f=this.#k(360-this.rotation),g=(M,F)=>[f[0]*M+f[2]*F,f[1]*M+f[3]*F];let p,b,m=!1,y=!1;switch(t){case"topLeft":m=!0,p=(M,F)=>[0,0],b=(M,F)=>[M,F];break;case"topMiddle":p=(M,F)=>[M/2,0],b=(M,F)=>[M/2,F];break;case"topRight":m=!0,p=(M,F)=>[M,0],b=(M,F)=>[0,F];break;case"middleRight":y=!0,p=(M,F)=>[M,F/2],b=(M,F)=>[0,F/2];break;case"bottomRight":m=!0,p=(M,F)=>[M,F],b=(M,F)=>[0,0];break;case"bottomMiddle":p=(M,F)=>[M/2,F],b=(M,F)=>[M/2,0];break;case"bottomLeft":m=!0,p=(M,F)=>[0,F],b=(M,F)=>[M,0];break;case"middleLeft":y=!0,p=(M,F)=>[0,F/2],b=(M,F)=>[M,F/2];break}const A=p(a,o),v=b(a,o);let w=u(...v);const _=B._round(n+w[0]),S=B._round(r+w[1]);let E=1,C=1,T,P;if(e.fromKeyboard)({deltaX:T,deltaY:P}=e);else{const{screenX:M,screenY:F}=e,[z,Z]=this.#l;[T,P]=this.screenToPageTranslation(M-z,F-Z),this.#l[0]=M,this.#l[1]=F}if([T,P]=g(T/s,P/i),m){const M=Math.hypot(a,o);E=C=Math.max(Math.min(Math.hypot(v[0]-A[0]-T,v[1]-A[1]-P)/M,1/a,1/o),l/a,h/o)}else y?E=_t(Math.abs(v[0]-A[0]-T),l,1)/a:C=_t(Math.abs(v[1]-A[1]-P),h,1)/o;const $=B._round(a*E),G=B._round(o*C);w=u(...b($,G));const O=_-w[0],H=S-w[1];this.#c||=[this.x,this.y,this.width,this.height],this.width=$,this.height=G,this.x=O,this.y=H,this.setDims(),this.fixAndSetPosition(),this._onResizing()}_onResizing(){}altTextFinish(){this.#i?.finish()}get toolbarButtons(){return null}async addEditToolbar(){if(this._editToolbar||this.#b)return this._editToolbar;this._editToolbar=new Re(this),this.div.append(this._editToolbar.render());const{toolbarButtons:t}=this;if(t)for(const[e,s]of t)await this._editToolbar.addButton(e,s);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.#i?.destroy()}addContainer(t){const e=this._editToolbar?.div;e?e.before(t):this.div.append(t)}getClientDimensions(){return this.div.getBoundingClientRect()}createAltText(){return this.#i||(zt.initialize(B._l10n),this.#i=new zt(this),this.#t&&(this.#i.data=this.#t,this.#t=null)),this.#i}get altTextData(){return this.#i?.data}set altTextData(t){this.#i&&(this.#i.data=t)}get guessedAltText(){return this.#i?.guessedText}async setGuessedAltText(t){await this.#i?.setGuessedText(t)}serializeAltText(t){return this.#i?.serialize(t)}hasAltText(){return!!this.#i&&!this.#i.isEmpty()}hasAltTextData(){return this.#i?.hasData()??!1}focusCommentButton(){this.#s?.focusButton()}addCommentButton(){return this.#s||=new qe(this)}addStandaloneCommentButton(){if(this.#a){this._uiManager.isEditingMode()&&this.#a.classList.remove("hidden");return}this.hasComment&&(this.#a=this.#s.renderForStandalone(),this.div.append(this.#a))}removeStandaloneCommentButton(){this.#s.removeStandaloneCommentButton(),this.#a=null}hideStandaloneCommentButton(){this.#a?.classList.add("hidden")}get comment(){const{data:{richText:t,text:e,date:s,deleted:i}}=this.#s;return{text:e,richText:t,date:s,deleted:i,color:this.getNonHCMColor(),opacity:this.opacity??1}}set comment(t){this.#s||=new qe(this),this.#s.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:s}){if(!e||(this.#s||=new qe(this),this.#s.setInitialText(t,s),!this.annotationElementId))return;const i=this._uiManager.getAndRemoveDataFromAnnotationStorage(this.annotationElementId);i&&this.updateFromAnnotationLayer(i)}get hasEditedComment(){return this.#s?.hasBeenEdited()}get hasDeletedComment(){return this.#s?.isDeleted()}get hasComment(){return!!this.#s&&!this.#s.isEmpty()&&!this.#s.isDeleted()}async editComment(t){this.#s||=new qe(this),this.#s.edit(t)}toggleComment(t,e=void 0){this.hasComment&&this._uiManager.toggleComment(this,t,e)}setSelectedCommentButton(t){this.#s.setSelectedButton(t)}addComment(t){if(this.hasEditedComment){const[,,,i]=t.rect,[n]=this.pageDimensions,[r]=this.pageTranslation,a=r+n+1,o=i-100,l=a+180;t.popup={contents:this.comment.text,deleted:this.comment.deleted,rect:[a,o,l,i]}}}updateFromAnnotationLayer({popup:{contents:t,deleted:e}}){this.#s.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.#n?-1:0,t.setAttribute("role","application"),this.defaultL10nId&&t.setAttribute("data-l10n-id",this.defaultL10nId),this._isVisible||t.classList.add("hidden"),this.setInForeground(),this.#j();const[e,s]=this.parentDimensions;this.parentRotation%180!==0&&(t.style.maxWidth=`${(100*s/e).toFixed(2)}%`,t.style.maxHeight=`${(100*e/s).toFixed(2)}%`);const[i,n]=this.getInitialTranslation();return this.translate(i,n),Zi(this,t,["keydown","pointerdown","dblclick"]),this.isResizable&&this._uiManager._supportsPinchToZoom&&(this.#T||=new $e({container:t,isPinchingDisabled:()=>!this.isSelected,onPinchStart:this.#z.bind(this),onPinching:this.#x.bind(this),onPinchEnd:this.#v.bind(this),signal:this._uiManager._signal})),this.addStandaloneCommentButton(),this._uiManager._editorUndoBar?.hide(),t}#z(){this.#u={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height},this.#i?.toggle(!1),this.parent.togglePointerEvents(!1)}#x(t,e,s){let n=.7*(s/e)+1-.7;if(n===1)return;const r=this.#k(this.rotation),a=(_,S)=>[r[0]*_+r[2]*S,r[1]*_+r[3]*S],[o,l]=this.parentDimensions,h=this.x,d=this.y,u=this.width,f=this.height,g=B.MIN_SIZE/o,p=B.MIN_SIZE/l;n=Math.max(Math.min(n,1/u,1/f),g/u,p/f);const b=B._round(u*n),m=B._round(f*n);if(b===u&&m===f)return;this.#c||=[h,d,u,f];const y=a(u/2,f/2),A=B._round(h+y[0]),v=B._round(d+y[1]),w=a(b/2,m/2);this.x=A-w[0],this.y=v-w[1],this.width=b,this.height=m,this.setDims(),this.fixAndSetPosition(),this._onResizing()}#v(){this.#i?.toggle(!0),this.parent.togglePointerEvents(!0),this.#B()}pointerdown(t){const{isMac:e}=bt.platform;if(t.button!==0||t.ctrlKey&&e){t.preventDefault();return}if(this.#p=!0,this._isDraggable){this.#H(t);return}this.#D(t)}#D(t){const{isMac:e}=bt.platform;t.ctrlKey&&!e||t.shiftKey||t.metaKey&&e?this.parent.toggleSelected(this):this.parent.setSelected(this)}#H(t){const{isSelected:e}=this;this._uiManager.setUpDragSession();let s=!1;const i=new AbortController,n=this._uiManager.combinedSignal(i),r={capture:!0,passive:!1,signal:n},a=l=>{i.abort(),this.#r=null,this.#p=!1,this._uiManager.endDragSession()||this.#D(l),s&&this._onStopDragging()};e&&(this.#C=t.clientX,this.#S=t.clientY,this.#r=t.pointerId,this.#o=t.pointerType,window.addEventListener("pointermove",l=>{s||(s=!0,this._uiManager.toggleComment(this,!0,!1),this._onStartDragging());const{clientX:h,clientY:d,pointerId:u}=l;if(u!==this.#r){lt(l);return}const[f,g]=this.screenToPageTranslation(h-this.#C,d-this.#S);this.#C=h,this.#S=d,this._uiManager.dragSelectedEditors(f,g)},r),window.addEventListener("touchmove",lt,r),window.addEventListener("pointerdown",l=>{l.pointerType===this.#o&&(this.#T||l.isPrimary)&&a(l),lt(l)},r));const o=l=>{if(!this.#r||this.#r===l.pointerId){a(l);return}lt(l)};window.addEventListener("pointerup",o,{signal:n}),window.addEventListener("blur",o,{signal:n})}_onStartDragging(){}_onStopDragging(){}moveInDOM(){this.#y&&clearTimeout(this.#y),this.#y=setTimeout(()=>{this.#y=null,this.parent?.moveEditorInDOM(this)},0)}_setParentAndPosition(t,e,s){t.changeParent(this),this.x=e,this.y=s,this.fixAndSetPosition(),this._onTranslated()}getRect(t,e,s=this.rotation){const i=this.parentScale,[n,r]=this.pageDimensions,[a,o]=this.pageTranslation,l=t/i,h=e/i,d=this.x*n,u=this.y*r,f=this.width*n,g=this.height*r;switch(s){case 0:return[d+l+a,r-u-h-g+o,d+l+f+a,r-u-h+o];case 90:return[d+h+a,r-u+l+o,d+h+g+a,r-u+l+f+o];case 180:return[d-l-f+a,r-u+h+o,d-l+a,r-u+h+g+o];case 270:return[d-h-g+a,r-u-l-f+o,d-h+a,r-u-l+o];default:throw new Error("Invalid rotation")}}getRectInCurrentCoords(t,e){const[s,i,n,r]=t,a=n-s,o=r-i;switch(this.rotation){case 0:return[s,e-r,a,o];case 90:return[s,e-i,o,a];case 180:return[n,e-i,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&&B._colorManager.convert(this._uiManager.getNonHCMColor(this.color))}onUpdatedColor(){this.#s?.onUpdatedColor()}getData(){const{comment:{text:t,color:e,date:s,opacity:i,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:s||h,popupRef:!n,color:e,opacity:i}}onceAdded(t){}isEmpty(){return!1}enableEditMode(){return this.isInEditMode()?!1:(this.parent.setEditingState(!1),this.#b=!0,!0)}disableEditMode(){return this.isInEditMode()?(this.parent.setEditingState(!0),this.#b=!1,!0):!1}isInEditMode(){return this.#b}shouldGetKeyboardEvents(){return this.#A}needsToBeRebuilt(){return this.div&&!this.isAttachedToDOM}get isOnScreen(){const{top:t,left:e,bottom:s,right:i}=this.getClientDimensions(),{innerHeight:n,innerWidth:r}=window;return e<r&&i>0&&t<n&&s>0}#j(){if(this.#f||!this.div)return;this.#f=new AbortController;const t=this._uiManager.combinedSignal(this.#f);this.div.addEventListener("focusin",this.focusin.bind(this),{signal:t}),this.div.addEventListener("focusout",this.focusout.bind(this),{signal:t})}rebuild(){this.#j()}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,s){const i=new this.prototype.constructor({parent:e,id:e.getNextId(),uiManager:s,annotationElementId:t.annotationElementId,creationDate:t.creationDate,modificationDate:t.modificationDate});i.rotation=t.rotation,i.#t=t.accessibilityData,i._isCopy=t.isCopy||!1;const[n,r]=i.pageDimensions,[a,o,l,h]=i.getRectInCurrentCoords(t.rect,r);return i.x=a/n,i.y=o/r,i.width=l/n,i.height=h/r,i}get hasBeenModified(){return!!this.annotationElementId&&(this.deleted||this.serialize()!==null)}remove(){if(this.#f?.abort(),this.#f=null,this.isEmpty()||this.commit(),this.parent?this.parent.remove(this):this._uiManager.removeEditor(this),this.#y&&(clearTimeout(this.#y),this.#y=null),this.#N(),this.removeEditToolbar(),this.#w){for(const t of this.#w.values())clearTimeout(t);this.#w=null}this.parent=null,this.#T?.destroy(),this.#T=null}get isResizable(){return!1}makeResizable(){this.isResizable&&(this.#O(),this.#h.classList.remove("hidden"))}get toolbarPosition(){return null}get commentButtonPosition(){return this._uiManager.direction==="ltr"?[1,0]:[0,0]}get commentButtonPositionInPage(){const{commentButtonPosition:[t,e]}=this,[s,i,n,r]=this.getPDFRect();return[B._round(s+(n-s)*t),B._round(i+(r-i)*(1-e))]}get commentButtonColor(){return this._uiManager.makeCommentColor(this.getNonHCMColor(),this.opacity)}get commentPopupPosition(){return this.#s.commentPopupPositionInLayer}set commentPopupPosition(t){this.#s.commentPopupPositionInLayer=t}hasDefaultPopupPosition(){return this.#s.hasDefaultPopupPosition()}get commentButtonWidth(){return this.#s.commentButtonWidth}get elementBeforePopup(){return this.div}setCommentButtonStates(t){this.#s.setCommentButtonStates(t)}keydown(t){if(!this.isResizable||t.target!==this.div||t.key!=="Enter")return;this._uiManager.setSelected(this),this.#u={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height};const e=this.#h.children;if(!this.#e){this.#e=Array.from(e);const r=this.#X.bind(this),a=this.#W.bind(this),o=this._uiManager._signal;for(const l of this.#e){const h=l.getAttribute("data-resizer-name");l.setAttribute("role","spinbutton"),l.addEventListener("keydown",r,{signal:o}),l.addEventListener("blur",a,{signal:o}),l.addEventListener("focus",this.#q.bind(this,h),{signal:o}),l.setAttribute("data-l10n-id",B._l10nResizer[h])}}const s=this.#e[0];let i=0;for(const r of e){if(r===s)break;i++}const n=(360-this.rotation+this.parentRotation)%360/90*(this.#e.length/4);if(n!==i){if(n<i)for(let a=0;a<i-n;a++)this.#h.append(this.#h.firstChild);else if(n>i)for(let a=0;a<n-i;a++)this.#h.firstChild.before(this.#h.lastChild);let r=0;for(const a of e){const l=this.#e[r++].getAttribute("data-resizer-name");a.setAttribute("data-l10n-id",B._l10nResizer[l])}}this.#$(0),this.#A=!0,this.#h.firstChild.focus({focusVisible:!0}),t.preventDefault(),t.stopImmediatePropagation()}#X(t){B._resizerKeyboardManager.exec(this,t)}#W(t){this.#A&&t.relatedTarget?.parentNode!==this.#h&&this.#N()}#q(t){this.#m=this.#A?t:""}#$(t){if(this.#e)for(const e of this.#e)e.tabIndex=t}_resizeWithKeyboard(t,e){this.#A&&this.#F(this.#m,{deltaX:t,deltaY:e,fromKeyboard:!0})}#N(){this.#A=!1,this.#$(-1),this.#B()}_stopResizingWithKeyboard(){this.#N(),this.div.focus()}select(){if(this.isSelected&&this._editToolbar){this._editToolbar.show();return}if(this.isSelected=!0,this.makeResizable(),this.div?.classList.add("selectedEditor"),!this._editToolbar){this.addEditToolbar().then(()=>{this.div?.classList.contains("selectedEditor")&&this._editToolbar?.show()});return}this._editToolbar?.show(),this.#i?.toggleAltTextBadge(!1)}focus(){this.div&&!this.div.contains(document.activeElement)&&setTimeout(()=>this.div?.focus({preventScroll:!0}),0)}unselect(){this.isSelected&&(this.isSelected=!1,this.#h?.classList.add("hidden"),this.div?.classList.remove("selectedEditor"),this.div?.contains(document.activeElement)&&this._uiManager.currentLayer.div.focus({preventScroll:!0}),this._editToolbar?.hide(),this.#i?.toggleAltTextBadge(!0),this.hasComment&&this._uiManager.toggleComment(this,!1,!1))}updateParams(t,e){}disableEditing(){}enableEditing(){}get canChangeContent(){return!1}enterInEditMode(){this.canChangeContent&&(this.enableEditMode(),this.div.focus())}dblclick(t){t.target.nodeName!=="BUTTON"&&(this.enterInEditMode(),this.parent.updateToolbar({mode:this.constructor._editorType,editId:this.id}))}getElementForAltText(){return this.div}get contentDiv(){return this.div}get isEditing(){return this.#g}set isEditing(t){this.#g=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(t,e=!1){if(e){this.#w||=new Map;const{action:s}=t;let i=this.#w.get(s);i&&clearTimeout(i),i=setTimeout(()=>{this._reportTelemetry(t),this.#w.delete(s),this.#w.size===0&&(this.#w=null)},B._telemetryTimeout),this.#w.set(s,i);return}t.type||=this.editorType,this._uiManager._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:t}})}show(t=this._isVisible){this.div.classList.toggle("hidden",!t),this._isVisible=t}enable(){this.div&&(this.div.tabIndex=0),this.#n=!1}disable(){this.div&&(this.div.tabIndex=-1),this.#n=!0}updateFakeAnnotationElement(t){if(!this.#d&&!this.deleted){this.#d=t.addFakeAnnotation(this);return}if(this.deleted){this.#d.remove(),this.#d=null;return}(this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized)&&this.#d.updateEdited({rect:this.getPDFRect(),popup:this.comment})}renderAnnotationElement(t){if(this.deleted)return t.hide(),null;let e=t.container.querySelector(".annotationContent");if(!e)e=document.createElement("div"),e.classList.add("annotationContent",this.editorType),t.container.prepend(e);else if(e.nodeName==="CANVAS"){const s=e;e=document.createElement("div"),e.classList.add("annotationContent",this.editorType),s.before(e)}return e}resetAnnotationElement(t){const{firstChild:e}=t.container;e?.nodeName==="DIV"&&e.classList.contains("annotationContent")&&e.remove()}}class Ar extends B{constructor(t){super(t),this.annotationElementId=t.annotationElementId,this.deleted=!0}serialize(){return this.serializeDeleted()}}const pi=3285377520,Ft=4294901760,jt=65535;class tn{constructor(t){this.h1=t?t&4294967295:pi,this.h2=t?t&4294967295:pi}update(t){let e,s;if(typeof t=="string"){e=new Uint8Array(t.length*2),s=0;for(let p=0,b=t.length;p<b;p++){const m=t.charCodeAt(p);m<=255?e[s++]=m:(e[s++]=m>>>8,e[s++]=m&255)}}else if(ArrayBuffer.isView(t))e=t.slice(),s=e.byteLength;else throw new Error("Invalid data format, must be a string or TypedArray.");const i=s>>2,n=s-i*4,r=new Uint32Array(e.buffer,0,i);let a=0,o=0,l=this.h1,h=this.h2;const d=3432918353,u=461845907,f=d&jt,g=u&jt;for(let p=0;p<i;p++)p&1?(a=r[p],a=a*d&Ft|a*f&jt,a=a<<15|a>>>17,a=a*u&Ft|a*g&jt,l^=a,l=l<<13|l>>>19,l=l*5+3864292196):(o=r[p],o=o*d&Ft|o*f&jt,o=o<<15|o>>>17,o=o*u&Ft|o*g&jt,h^=o,h=h<<13|h>>>19,h=h*5+3864292196);switch(a=0,n){case 3:a^=e[i*4+2]<<16;case 2:a^=e[i*4+1]<<8;case 1:a^=e[i*4],a=a*d&Ft|a*f&jt,a=a<<15|a>>>17,a=a*u&Ft|a*g&jt,i&1?l^=a:h^=a}this.h1=l,this.h2=h}hexdigest(){let t=this.h1,e=this.h2;return t^=e>>>1,t=t*3981806797&Ft|t*36045&jt,e=e*4283543511&Ft|((e<<16|t>>>16)*2950163797&Ft)>>>16,t^=e>>>1,t=t*444984403&Ft|t*60499&jt,e=e*3301882366&Ft|((e<<16|t>>>16)*3120437893&Ft)>>>16,t^=e>>>1,(t>>>0).toString(16).padStart(8,"0")+(e>>>0).toString(16).padStart(8,"0")}}const ks=Object.freeze({map:null,hash:"",transfer:void 0});class Xs{#t=!1;#e=null;#i=null;#s=new Map;constructor(){this.onSetModified=null,this.onResetModified=null,this.onAnnotationEditor=null}getValue(t,e){const s=this.#s.get(t);return s===void 0?e:Object.assign(e,s)}getRawValue(t){return this.#s.get(t)}remove(t){const e=this.#s.get(t);if(e!==void 0&&(e instanceof B&&this.#i.delete(e.annotationElementId),this.#s.delete(t),this.#s.size===0&&this.resetModified(),typeof this.onAnnotationEditor=="function")){for(const s of this.#s.values())if(s instanceof B)return;this.onAnnotationEditor(null)}}setValue(t,e){const s=this.#s.get(t);let i=!1;if(s!==void 0)for(const[n,r]of Object.entries(e))s[n]!==r&&(i=!0,s[n]=r);else i=!0,this.#s.set(t,e);i&&this.#a(),e instanceof B&&((this.#i||=new Map).set(e.annotationElementId,e),typeof this.onAnnotationEditor=="function"&&this.onAnnotationEditor(e.constructor._type))}has(t){return this.#s.has(t)}get size(){return this.#s.size}#a(){this.#t||(this.#t=!0,typeof this.onSetModified=="function"&&this.onSetModified())}resetModified(){this.#t&&(this.#t=!1,typeof this.onResetModified=="function"&&this.onResetModified())}get print(){return new en(this)}get serializable(){if(this.#s.size===0)return ks;const t=new Map,e=new tn,s=[],i=Object.create(null);let n=!1;for(const[r,a]of this.#s){const o=a instanceof B?a.serialize(!1,i):a;o&&(t.set(r,o),e.update(`${r}:${JSON.stringify(o)}`),n||=!!o.bitmap)}if(n)for(const r of t.values())r.bitmap&&s.push(r.bitmap);return t.size>0?{map:t,hash:e.hexdigest(),transfer:s}:ks}get editorStats(){let t=null;const e=new Map;let s=0,i=0;for(const n of this.#s.values()){if(!(n instanceof B)){n.popup&&(n.popup.deleted?i+=1:s+=1);continue}n.isCommentDeleted?i+=1:n.hasEditedComment&&(s+=1);const r=n.telemetryFinalData;if(!r)continue;const{type:a}=r;e.has(a)||e.set(a,Object.getPrototypeOf(n).constructor),t||=Object.create(null);const o=t[a]||=new Map;for(const[l,h]of Object.entries(r)){if(l==="type")continue;let d=o.get(l);d||(d=new Map,o.set(l,d));const u=d.get(h)??0;d.set(h,u+1)}}if((i>0||s>0)&&(t||=Object.create(null),t.comments={deleted:i,edited:s}),!t)return null;for(const[n,r]of e)t[n]=r.computeTelemetryFinalData(t[n]);return t}resetModifiedIds(){this.#e=null}updateEditor(t,e){const s=this.#i?.get(t);return s?(s.updateFromAnnotationLayer(e),!0):!1}getEditor(t){return this.#i?.get(t)||null}get modifiedIds(){if(this.#e)return this.#e;const t=[];if(this.#i)for(const e of this.#i.values())e.serialize()&&t.push(e.annotationElementId);return this.#e={ids:new Set(t),hash:t.join(",")}}[Symbol.iterator](){return this.#s.entries()}}class en extends Xs{#t;constructor(t){super();const{map:e,hash:s,transfer:i}=t.serializable,n=structuredClone(e,i?{transfer:i}:null);this.#t={map:n,hash:s,transfer:i}}get print(){nt("Should not call PrintAnnotationStorage.print")}get serializable(){return this.#t}get modifiedIds(){return Y(this,"modifiedIds",{ids:new Set,hash:""})}}class wr{#t=new Set;constructor({ownerDocument:t=globalThis.document,styleElement:e=null}){this._document=t,this.nativeFontFaces=new Set,this.styleElement=null,this.loadingRequests=[],this.loadTestFontId=0}addNativeFontFace(t){this.nativeFontFaces.add(t),this._document.fonts.add(t)}removeNativeFontFace(t){this.nativeFontFaces.delete(t),this._document.fonts.delete(t)}insertRule(t){this.styleElement||(this.styleElement=this._document.createElement("style"),this._document.documentElement.getElementsByTagName("head")[0].append(this.styleElement));const e=this.styleElement.sheet;e.insertRule(t,e.cssRules.length)}clear(){for(const t of this.nativeFontFaces)this._document.fonts.delete(t);this.nativeFontFaces.clear(),this.#t.clear(),this.styleElement&&(this.styleElement.remove(),this.styleElement=null)}async loadSystemFont({systemFontInfo:t,disableFontFace:e,_inspectFont:s}){if(!(!t||this.#t.has(t.loadedName))){if(J(!e,"loadSystemFont shouldn't be called when `disableFontFace` is set."),this.isFontLoadingAPISupported){const{loadedName:i,src:n,style:r}=t,a=new FontFace(i,n,r);this.addNativeFontFace(a);try{await a.load(),this.#t.add(i),s?.(t)}catch{W(`Cannot load system font: ${t.baseFontName}, installing it could help to improve PDF rendering.`),this.removeNativeFontFace(a)}return}nt("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){await this.loadSystemFont(t);return}if(this.isFontLoadingAPISupported){const s=t.createNativeFontFace();if(s){this.addNativeFontFace(s);try{await s.loaded}catch(i){throw W(`Failed to load font '${s.family}': '${i}'.`),t.disableFontFace=!0,i}}return}const e=t.createFontFaceRule();if(e){if(this.insertRule(e),this.isSyncFontLoadingSupported)return;await new Promise(s=>{const i=this._queueLoadingCallback(s);this._prepareFontLoadEvent(t,i)})}}get isFontLoadingAPISupported(){const t=!!this._document?.fonts;return Y(this,"isFontLoadingAPISupported",t)}get isSyncFontLoadingSupported(){return Y(this,"isSyncFontLoadingSupported",Et||bt.platform.isFirefox)}_queueLoadingCallback(t){function e(){for(J(!i.done,"completeRequest() cannot be called twice."),i.done=!0;s.length>0&&s[0].done;){const n=s.shift();setTimeout(n.callback,0)}}const{loadingRequests:s}=this,i={done:!1,complete:e,callback:t};return s.push(i),i}get _loadTestFont(){const t=atob("T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQAABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwAAAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbmFtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAAAADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6AABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAAMQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAAAAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAAAAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQAAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMAAQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAAEAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgcA/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQAAAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAgABAAAAAAAAAAAD6AAAAAAAAA==");return Y(this,"_loadTestFont",t)}_prepareFontLoadEvent(t,e){function s(v,w){return v.charCodeAt(w)<<24|v.charCodeAt(w+1)<<16|v.charCodeAt(w+2)<<8|v.charCodeAt(w+3)&255}function i(v,w,_,S){const E=v.substring(0,w),C=v.substring(w+_);return E+S+C}let n,r;const a=this._document.createElement("canvas");a.width=1,a.height=1;const o=a.getContext("2d");let l=0;function h(v,w){if(++l>30){W("Load test font never loaded."),w();return}if(o.font="30px "+v,o.fillText(".",0,20),o.getImageData(0,0,1,1).data[3]>0){w();return}setTimeout(h.bind(null,v,w))}const d=`lt${Date.now()}${this.loadTestFontId++}`;let u=this._loadTestFont;u=i(u,976,d.length,d);const g=16,p=1482184792;let b=s(u,g);for(n=0,r=d.length-3;n<r;n+=4)b=b-p+s(d,n)|0;n<d.length&&(b=b-p+s(d+"XXX",n)|0),u=i(u,g,4,or(b));const m=`url(data:font/opentype;base64,${btoa(u)});`,y=`@font-face {font-family:"${d}";src:${m}}`;this.insertRule(y);const A=this._document.createElement("div");A.style.visibility="hidden",A.style.width=A.style.height="10px",A.style.position="absolute",A.style.top=A.style.left="0px";for(const v of[t.loadedName,d]){const w=this._document.createElement("span");w.textContent="Hi",w.style.fontFamily=v,A.append(w)}this._document.body.append(A),h(d,()=>{A.remove(),e.complete()})}}class vr{#t;constructor(t,e=null,s,i){this.compiledGlyphs=Object.create(null),this.#t=t,this._inspectFont=e,s&&Object.assign(this,s),i&&(this.charProcOperatorList=i)}createNativeFontFace(){if(!this.data||this.disableFontFace)return null;let t;if(!this.cssFontInfo)t=new FontFace(this.loadedName,this.data,{});else{const e={weight:this.cssFontInfo.fontWeight};this.cssFontInfo.italicAngle&&(e.style=`oblique ${this.cssFontInfo.italicAngle}deg`),t=new FontFace(this.cssFontInfo.fontFamily,this.data,e)}return this._inspectFont?.(this),t}createFontFaceRule(){if(!this.data||this.disableFontFace)return null;const t=`url(data:${this.mimetype};base64,${Wi(this.data)});`;let e;if(!this.cssFontInfo)e=`@font-face {font-family:"${this.loadedName}";src:${t}}`;else{let s=`font-weight: ${this.cssFontInfo.fontWeight};`;this.cssFontInfo.italicAngle&&(s+=`font-style: oblique ${this.cssFontInfo.italicAngle}deg;`),e=`@font-face {font-family:"${this.cssFontInfo.fontFamily}";${s}src:${t}}`}return this._inspectFont?.(this,t),e}getPathGenerator(t,e){if(this.compiledGlyphs[e]!==void 0)return this.compiledGlyphs[e];const s=this.loadedName+"_path_"+e;let i;try{i=t.get(s)}catch(r){W(`getPathGenerator - ignoring character: "${r}".`)}const n=new Path2D(i||"");return this.fontExtraProperties||t.delete(s),this.compiledGlyphs[e]=n}get black(){return this.#t.black}get bold(){return this.#t.bold}get disableFontFace(){return this.#t.disableFontFace??!1}get fontExtraProperties(){return this.#t.fontExtraProperties??!1}get isInvalidPDFjsFont(){return this.#t.isInvalidPDFjsFont}get isType3Font(){return this.#t.isType3Font}get italic(){return this.#t.italic}get missingFile(){return this.#t.missingFile}get remeasure(){return this.#t.remeasure}get vertical(){return this.#t.vertical}get ascent(){return this.#t.ascent}get defaultWidth(){return this.#t.defaultWidth}get descent(){return this.#t.descent}get bbox(){return this.#t.bbox}get fontMatrix(){return this.#t.fontMatrix}get fallbackName(){return this.#t.fallbackName}get loadedName(){return this.#t.loadedName}get mimetype(){return this.#t.mimetype}get name(){return this.#t.name}get data(){return this.#t.data}clearData(){this.#t.clearData()}get cssFontInfo(){return this.#t.cssFontInfo}get systemFontInfo(){return this.#t.systemFontInfo}get defaultVMetrics(){return this.#t.defaultVMetrics}}function _r(c){if(c instanceof URL)return c.href;if(typeof c=="string"){if(Et)return c;const t=URL.parse(c,window.location);if(t)return t.href}throw new Error("Invalid PDF url data: either string or URL-object is expected in the url property.")}function Sr(c){if(Et&&typeof Buffer<"u"&&c instanceof Buffer)throw new Error("Please provide binary data as `Uint8Array`, rather than `Buffer`.");if(c instanceof Uint8Array&&c.byteLength===c.buffer.byteLength)return c;if(typeof c=="string")return Be(c);if(c instanceof ArrayBuffer||ArrayBuffer.isView(c)||typeof c=="object"&&!isNaN(c?.length))return new Uint8Array(c);throw new Error("Invalid PDF binary data: either TypedArray, string, or array-like object is expected in the data property.")}function Ye(c){if(typeof c!="string")return null;if(c.endsWith("/"))return c;throw new Error(`Invalid factory url: "${c}" must include trailing slash.`)}const Rs=c=>typeof c=="object"&&Number.isInteger(c?.num)&&c.num>=0&&Number.isInteger(c?.gen)&&c.gen>=0,Er=c=>typeof c=="object"&&typeof c?.name=="string",sn=dr.bind(null,Rs,Er);class Cr{#t=new Map;#e=Promise.resolve();postMessage(t,e){const s={data:structuredClone(t,e?{transfer:e}:null)};this.#e.then(()=>{for(const[i]of this.#t)i.call(this,s)})}addEventListener(t,e,s=null){let i=null;if(s?.signal instanceof AbortSignal){const{signal:n}=s;if(n.aborted){W("LoopbackPort - cannot use an `aborted` signal.");return}const r=()=>this.removeEventListener(t,e);i=()=>n.removeEventListener("abort",r),n.addEventListener("abort",r)}this.#t.set(e,i)}removeEventListener(t,e){this.#t.get(e)?.(),this.#t.delete(e)}terminate(){for(const[,t]of this.#t)t?.();this.#t.clear()}}const Ke={DATA:1,ERROR:2},ut={CANCEL:1,CANCEL_COMPLETE:2,CLOSE:3,ENQUEUE:4,ERROR:5,PULL:6,PULL_COMPLETE:7,START_COMPLETE:8};function gi(){}function Tt(c){if(c instanceof qt||c instanceof is||c instanceof oi||c instanceof Le||c instanceof ws)return c;switch(c instanceof Error||typeof c=="object"&&c!==null||nt('wrapReason: Expected "reason" to be a (possibly cloned) Error.'),c.name){case"AbortException":return new qt(c.message);case"InvalidPDFException":return new is(c.message);case"PasswordException":return new oi(c.message,c.code);case"ResponseException":return new Le(c.message,c.status,c.missing);case"UnknownErrorException":return new ws(c.message,c.details)}return new ws(c.message,c.toString())}class Pe{#t=new AbortController;constructor(t,e,s){this.sourceName=t,this.targetName=e,this.comObj=s,this.callbackId=1,this.streamId=1,this.streamSinks=Object.create(null),this.streamControllers=Object.create(null),this.callbackCapabilities=Object.create(null),this.actionHandler=Object.create(null),s.addEventListener("message",this.#e.bind(this),{signal:this.#t.signal})}#e({data:t}){if(t.targetName!==this.sourceName)return;if(t.stream){this.#s(t);return}if(t.callback){const s=t.callbackId,i=this.callbackCapabilities[s];if(!i)throw new Error(`Cannot resolve callback ${s}`);if(delete this.callbackCapabilities[s],t.callback===Ke.DATA)i.resolve(t.data);else if(t.callback===Ke.ERROR)i.reject(Tt(t.reason));else throw new Error("Unexpected callback case");return}const e=this.actionHandler[t.action];if(!e)throw new Error(`Unknown action from worker: ${t.action}`);if(t.callbackId){const s=this.sourceName,i=t.sourceName,n=this.comObj;Promise.try(e,t.data).then(function(r){n.postMessage({sourceName:s,targetName:i,callback:Ke.DATA,callbackId:t.callbackId,data:r})},function(r){n.postMessage({sourceName:s,targetName:i,callback:Ke.ERROR,callbackId:t.callbackId,reason:Tt(r)})});return}if(t.streamId){this.#i(t);return}e(t.data)}on(t,e){const s=this.actionHandler;if(s[t])throw new Error(`There is already an actionName called "${t}"`);s[t]=e}send(t,e,s){this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:t,data:e},s)}sendWithPromise(t,e,s){const i=this.callbackId++,n=Promise.withResolvers();this.callbackCapabilities[i]=n;try{this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:t,callbackId:i,data:e},s)}catch(r){n.reject(r)}return n.promise}sendWithStream(t,e,s,i){const n=this.streamId++,r=this.sourceName,a=this.targetName,o=this.comObj;return new ReadableStream({start:l=>{const h=Promise.withResolvers();return this.streamControllers[n]={controller:l,startCall:h,pullCall:null,cancelCall:null,isClosed:!1},o.postMessage({sourceName:r,targetName:a,action:t,streamId:n,data:e,desiredSize:l.desiredSize},i),h.promise},pull:l=>{const h=Promise.withResolvers();return this.streamControllers[n].pullCall=h,o.postMessage({sourceName:r,targetName:a,stream:ut.PULL,streamId:n,desiredSize:l.desiredSize}),h.promise},cancel:l=>{J(l instanceof Error,"cancel must have a valid reason");const h=Promise.withResolvers();return this.streamControllers[n].cancelCall=h,this.streamControllers[n].isClosed=!0,o.postMessage({sourceName:r,targetName:a,stream:ut.CANCEL,streamId:n,reason:Tt(l)}),h.promise}},s)}#i(t){const e=t.streamId,s=this.sourceName,i=t.sourceName,n=this.comObj,r=this,a=this.actionHandler[t.action],o={enqueue(l,h=1,d){if(this.isCancelled)return;const u=this.desiredSize;this.desiredSize-=h,u>0&&this.desiredSize<=0&&(this.sinkCapability=Promise.withResolvers(),this.ready=this.sinkCapability.promise),n.postMessage({sourceName:s,targetName:i,stream:ut.ENQUEUE,streamId:e,chunk:l},d)},close(){this.isCancelled||(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:ut.CLOSE,streamId:e}),delete r.streamSinks[e])},error(l){J(l instanceof Error,"error must have a valid reason"),!this.isCancelled&&(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:ut.ERROR,streamId:e,reason:Tt(l)}))},sinkCapability:Promise.withResolvers(),onPull:null,onCancel:null,isCancelled:!1,desiredSize:t.desiredSize,ready:null};o.sinkCapability.resolve(),o.ready=o.sinkCapability.promise,this.streamSinks[e]=o,Promise.try(a,t.data,o).then(function(){n.postMessage({sourceName:s,targetName:i,stream:ut.START_COMPLETE,streamId:e,success:!0})},function(l){n.postMessage({sourceName:s,targetName:i,stream:ut.START_COMPLETE,streamId:e,reason:Tt(l)})})}#s(t){const e=t.streamId,s=this.sourceName,i=t.sourceName,n=this.comObj,r=this.streamControllers[e],a=this.streamSinks[e];switch(t.stream){case ut.START_COMPLETE:t.success?r.startCall.resolve():r.startCall.reject(Tt(t.reason));break;case ut.PULL_COMPLETE:t.success?r.pullCall.resolve():r.pullCall.reject(Tt(t.reason));break;case ut.PULL:if(!a){n.postMessage({sourceName:s,targetName:i,stream:ut.PULL_COMPLETE,streamId:e,success:!0});break}a.desiredSize<=0&&t.desiredSize>0&&a.sinkCapability.resolve(),a.desiredSize=t.desiredSize,Promise.try(a.onPull||gi).then(function(){n.postMessage({sourceName:s,targetName:i,stream:ut.PULL_COMPLETE,streamId:e,success:!0})},function(l){n.postMessage({sourceName:s,targetName:i,stream:ut.PULL_COMPLETE,streamId:e,reason:Tt(l)})});break;case ut.ENQUEUE:if(J(r,"enqueue should have stream controller"),r.isClosed)break;r.controller.enqueue(t.chunk);break;case ut.CLOSE:if(J(r,"close should have stream controller"),r.isClosed)break;r.isClosed=!0,r.controller.close(),this.#a(r,e);break;case ut.ERROR:J(r,"error should have stream controller"),r.controller.error(Tt(t.reason)),this.#a(r,e);break;case ut.CANCEL_COMPLETE:t.success?r.cancelCall.resolve():r.cancelCall.reject(Tt(t.reason)),this.#a(r,e);break;case ut.CANCEL:if(!a)break;const o=Tt(t.reason);Promise.try(a.onCancel||gi,o).then(function(){n.postMessage({sourceName:s,targetName:i,stream:ut.CANCEL_COMPLETE,streamId:e,success:!0})},function(l){n.postMessage({sourceName:s,targetName:i,stream:ut.CANCEL_COMPLETE,streamId:e,reason:Tt(l)})}),a.sinkCapability.reject(o),a.isCancelled=!0,delete this.streamSinks[e];break;default:throw new Error("Unexpected stream case")}}async#a(t,e){await Promise.allSettled([t.startCall?.promise,t.pullCall?.promise,t.cancelCall?.promise]),delete this.streamControllers[e]}destroy(){this.#t?.abort(),this.#t=null}}class nn{#t=!1;constructor({enableHWA:t=!1}){this.#t=t}create(t,e){if(t<=0||e<=0)throw new Error("Invalid canvas size");const s=this._createCanvas(t,e);return{canvas:s,context:s.getContext("2d",{willReadFrequently:!this.#t})}}reset(t,e,s){if(!t.canvas)throw new Error("Canvas is not specified");if(e<=0||s<=0)throw new Error("Invalid canvas size");t.canvas.width=e,t.canvas.height=s}destroy(t){if(!t.canvas)throw new Error("Canvas is not specified");t.canvas.width=0,t.canvas.height=0,t.canvas=null,t.context=null}_createCanvas(t,e){nt("Abstract method `_createCanvas` called.")}}class xr extends nn{constructor({ownerDocument:t=globalThis.document,enableHWA:e=!1}){super({enableHWA:e}),this._document=t}_createCanvas(t,e){const s=this._document.createElement("canvas");return s.width=t,s.height=e,s}}class rn{constructor({baseUrl:t=null,isCompressed:e=!0}){this.baseUrl=t,this.isCompressed=e}async fetch({name:t}){if(!this.baseUrl)throw new Error("Ensure that the `cMapUrl` and `cMapPacked` API parameters are provided.");if(!t)throw new Error("CMap name must be specified.");const e=this.baseUrl+t+(this.isCompressed?".bcmap":"");return this._fetch(e).then(s=>({cMapData:s,isCompressed:this.isCompressed})).catch(s=>{throw new Error(`Unable to load ${this.isCompressed?"binary ":""}CMap at: ${e}`)})}async _fetch(t){nt("Abstract method `_fetch` called.")}}class mi extends rn{async _fetch(t){const e=await ve(t,this.isCompressed?"arraybuffer":"text");return e instanceof ArrayBuffer?new Uint8Array(e):Be(e)}}class an{addFilter(t){return"none"}addHCMFilter(t,e){return"none"}addAlphaFilter(t){return"none"}addLuminosityFilter(t){return"none"}addHighlightHCMFilter(t,e,s,i,n){return"none"}destroy(t=!1){}}class Tr extends an{#t;#e;#i;#s;#a;#n;#r=0;constructor({docId:t,ownerDocument:e=globalThis.document}){super(),this.#s=t,this.#a=e}get#o(){return this.#e||=new Map}get#h(){return this.#n||=new Map}get#l(){if(!this.#i){const t=this.#a.createElement("div"),{style:e}=t;e.visibility="hidden",e.contain="strict",e.width=e.height=0,e.position="absolute",e.top=e.left=0,e.zIndex=-1;const s=this.#a.createElementNS(Xt,"svg");s.setAttribute("width",0),s.setAttribute("height",0),this.#i=this.#a.createElementNS(Xt,"defs"),t.append(s),s.append(this.#i),this.#a.body.append(t)}return this.#i}#u(t){if(t.length===1){const o=t[0],l=new Array(256);for(let d=0;d<256;d++)l[d]=o[d]/255;const h=l.join(",");return[h,h,h]}const[e,s,i]=t,n=new Array(256),r=new Array(256),a=new Array(256);for(let o=0;o<256;o++)n[o]=e[o]/255,r[o]=s[o]/255,a[o]=i[o]/255;return[n.join(","),r.join(","),a.join(",")]}#d(t){if(this.#t===void 0){this.#t="";const e=this.#a.URL;e!==this.#a.baseURI&&(Ue(e)?W('#createUrl: ignore "data:"-URL for performance reasons.'):this.#t=Us(e,""))}return`url(${this.#t}#${t})`}addFilter(t){if(!t)return"none";let e=this.#o.get(t);if(e)return e;const[s,i,n]=this.#u(t),r=t.length===1?s:`${s}${i}${n}`;if(e=this.#o.get(r),e)return this.#o.set(t,e),e;const a=`g_${this.#s}_transfer_map_${this.#r++}`,o=this.#d(a);this.#o.set(t,o),this.#o.set(r,o);const l=this.#p(a);return this.#g(s,i,n,l),o}addHCMFilter(t,e){const s=`${t}-${e}`,i="base";let n=this.#h.get(i);if(n?.key===s||(n?(n.filter?.remove(),n.key=s,n.url="none",n.filter=null):(n={key:s,url:"none",filter:null},this.#h.set(i,n)),!t||!e))return n.url;const r=this.#A(t);t=I.makeHexColor(...r);const a=this.#A(e);if(e=I.makeHexColor(...a),this.#l.style.color="",t==="#000000"&&e==="#ffffff"||t===e)return n.url;const o=new Array(256);for(let f=0;f<=255;f++){const g=f/255;o[f]=g<=.03928?g/12.92:((g+.055)/1.055)**2.4}const l=o.join(","),h=`g_${this.#s}_hcm_filter`,d=n.filter=this.#p(h);this.#g(l,l,l,d),this.#m(d);const u=(f,g)=>{const p=r[f]/255,b=a[f]/255,m=new Array(g+1);for(let y=0;y<=g;y++)m[y]=p+y/g*(b-p);return m.join(",")};return this.#g(u(0,5),u(1,5),u(2,5),d),n.url=this.#d(h),n.url}addAlphaFilter(t){let e=this.#o.get(t);if(e)return e;const[s]=this.#u([t]),i=`alpha_${s}`;if(e=this.#o.get(i),e)return this.#o.set(t,e),e;const n=`g_${this.#s}_alpha_map_${this.#r++}`,r=this.#d(n);this.#o.set(t,r),this.#o.set(i,r);const a=this.#p(n);return this.#b(s,a),r}addLuminosityFilter(t){let e=this.#o.get(t||"luminosity");if(e)return e;let s,i;if(t?([s]=this.#u([t]),i=`luminosity_${s}`):i="luminosity",e=this.#o.get(i),e)return this.#o.set(t,e),e;const n=`g_${this.#s}_luminosity_map_${this.#r++}`,r=this.#d(n);this.#o.set(t,r),this.#o.set(i,r);const a=this.#p(n);return this.#f(a),t&&this.#b(s,a),r}addHighlightHCMFilter(t,e,s,i,n){const r=`${e}-${s}-${i}-${n}`;let a=this.#h.get(t);if(a?.key===r||(a?(a.filter?.remove(),a.key=r,a.url="none",a.filter=null):(a={key:r,url:"none",filter:null},this.#h.set(t,a)),!e||!s))return a.url;const[o,l]=[e,s].map(this.#A.bind(this));let h=Math.round(.2126*o[0]+.7152*o[1]+.0722*o[2]),d=Math.round(.2126*l[0]+.7152*l[1]+.0722*l[2]),[u,f]=[i,n].map(this.#A.bind(this));d<h&&([h,d,u,f]=[d,h,f,u]),this.#l.style.color="";const g=(m,y,A)=>{const v=new Array(256),w=(d-h)/A,_=m/255,S=(y-m)/(255*A);let E=0;for(let C=0;C<=A;C++){const T=Math.round(h+C*w),P=_+C*S;for(let $=E;$<=T;$++)v[$]=P;E=T+1}for(let C=E;C<256;C++)v[C]=v[E-1];return v.join(",")},p=`g_${this.#s}_hcm_${t}_filter`,b=a.filter=this.#p(p);return this.#m(b),this.#g(g(u[0],f[0],5),g(u[1],f[1],5),g(u[2],f[2],5),b),a.url=this.#d(p),a.url}destroy(t=!1){t&&this.#n?.size||(this.#i?.parentNode.parentNode.remove(),this.#i=null,this.#e?.clear(),this.#e=null,this.#n?.clear(),this.#n=null,this.#r=0)}#f(t){const e=this.#a.createElementNS(Xt,"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)}#m(t){const e=this.#a.createElementNS(Xt,"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)}#p(t){const e=this.#a.createElementNS(Xt,"filter");return e.setAttribute("color-interpolation-filters","sRGB"),e.setAttribute("id",t),this.#l.append(e),e}#c(t,e,s){const i=this.#a.createElementNS(Xt,e);i.setAttribute("type","discrete"),i.setAttribute("tableValues",s),t.append(i)}#g(t,e,s,i){const n=this.#a.createElementNS(Xt,"feComponentTransfer");i.append(n),this.#c(n,"feFuncR",t),this.#c(n,"feFuncG",e),this.#c(n,"feFuncB",s)}#b(t,e){const s=this.#a.createElementNS(Xt,"feComponentTransfer");e.append(s),this.#c(s,"feFuncA",t)}#A(t){return this.#l.style.color=t,_e(getComputedStyle(this.#l).getPropertyValue("color"))}}class on{constructor({baseUrl:t=null}){this.baseUrl=t}async fetch({filename:t}){if(!this.baseUrl)throw new Error("Ensure that the `standardFontDataUrl` API parameter is provided.");if(!t)throw new Error("Font filename must be specified.");const e=`${this.baseUrl}${t}`;return this._fetch(e).catch(s=>{throw new Error(`Unable to load font data at: ${e}`)})}async _fetch(t){nt("Abstract method `_fetch` called.")}}class bi extends on{async _fetch(t){const e=await ve(t,"arraybuffer");return new Uint8Array(e)}}class ln{constructor({baseUrl:t=null}){this.baseUrl=t}async fetch({filename:t}){if(!this.baseUrl)throw new Error("Ensure that the `wasmUrl` API parameter is provided.");if(!t)throw new Error("Wasm filename must be specified.");const e=`${this.baseUrl}${t}`;return this._fetch(e).catch(s=>{throw new Error(`Unable to load wasm data at: ${e}`)})}async _fetch(t){nt("Abstract method `_fetch` called.")}}class yi extends ln{async _fetch(t){const e=await ve(t,"arraybuffer");return new Uint8Array(e)}}Et&&W("Please use the `legacy` build in Node.js environments.");async function qs(c){const e=await process.getBuiltinModule("fs").promises.readFile(c);return new Uint8Array(e)}class Pr extends an{}class kr extends nn{_createCanvas(t,e){return process.getBuiltinModule("module").createRequire(import.meta.url)("@napi-rs/canvas").createCanvas(t,e)}}class Rr extends rn{async _fetch(t){return qs(t)}}class Mr extends on{async _fetch(t){return qs(t)}}class Lr extends ln{async _fetch(t){return qs(t)}}const he="__forcedDependency",{floor:Ai,ceil:wi}=Math;function Qe(c,t,e,s,i,n){c[t*4+0]=Math.min(c[t*4+0],e),c[t*4+1]=Math.min(c[t*4+1],s),c[t*4+2]=Math.max(c[t*4+2],i),c[t*4+3]=Math.max(c[t*4+3],n)}const Ms=new Uint32Array(new Uint8Array([255,255,0,0]).buffer)[0];class Dr{#t;#e;constructor(t,e){this.#t=t,this.#e=e}get length(){return this.#t.length}isEmpty(t){return this.#t[t]===Ms}minX(t){return this.#e[t*4+0]/256}minY(t){return this.#e[t*4+1]/256}maxX(t){return(this.#e[t*4+2]+1)/256}maxY(t){return(this.#e[t*4+3]+1)/256}}const Je=(c,t)=>{if(!c)return;let e=c.get(t);return e||(e={dependencies:new Set,isRenderingOperation:!1},c.set(t,e)),e};class Ir{#t={__proto__:null};#e={__proto__:null,transform:[],moveText:[],sameLineText:[],[he]:[]};#i=new Map;#s=[];#a=[];#n=[[1,0,0,1,0,0]];#r=[-1/0,-1/0,1/0,1/0];#o=new Float64Array([1/0,1/0,-1/0,-1/0]);#h=-1;#l=new Set;#u=new Map;#d=new Map;#f;#m;#p;#c;#g;constructor(t,e,s=!1){this.#f=t.width,this.#m=t.height,this.#b(e),s&&(this.#g=new Map)}growOperationsCount(t){t>=this.#c.length&&this.#b(t,this.#c)}#b(t,e){const s=new ArrayBuffer(t*4);this.#p=new Uint8ClampedArray(s),this.#c=new Uint32Array(s),e&&e.length>0?(this.#c.set(e),this.#c.fill(Ms,e.length)):this.#c.fill(Ms)}save(t){return this.#t={__proto__:this.#t},this.#e={__proto__:this.#e,transform:{__proto__:this.#e.transform},moveText:{__proto__:this.#e.moveText},sameLineText:{__proto__:this.#e.sameLineText},[he]:{__proto__:this.#e[he]}},this.#r={__proto__:this.#r},this.#s.push(t),this}restore(t){const e=Object.getPrototypeOf(this.#t);if(e===null)return this;this.#t=e,this.#e=Object.getPrototypeOf(this.#e),this.#r=Object.getPrototypeOf(this.#r);const s=this.#s.pop();return s!==void 0&&(Je(this.#g,t)?.dependencies.add(s),this.#c[t]=this.#c[s]),this}recordOpenMarker(t){return this.#s.push(t),this}getOpenMarker(){return this.#s.length===0?null:this.#s.at(-1)}recordCloseMarker(t){const e=this.#s.pop();return e!==void 0&&(Je(this.#g,t)?.dependencies.add(e),this.#c[t]=this.#c[e]),this}beginMarkedContent(t){return this.#a.push(t),this}endMarkedContent(t){const e=this.#a.pop();return e!==void 0&&(Je(this.#g,t)?.dependencies.add(e),this.#c[t]=this.#c[e]),this}pushBaseTransform(t){return this.#n.push(I.multiplyByDOMMatrix(this.#n.at(-1),t.getTransform())),this}popBaseTransform(){return this.#n.length>1&&this.#n.pop(),this}recordSimpleData(t,e){return this.#t[t]=e,this}recordIncrementalData(t,e){return this.#e[t].push(e),this}resetIncrementalData(t,e){return this.#e[t].length=0,this}recordNamedData(t,e){return this.#i.set(t,e),this}recordSimpleDataFromNamed(t,e,s){this.#t[t]=this.#i.get(e)??s}recordFutureForcedDependency(t,e){return this.recordIncrementalData(he,e),this}inheritSimpleDataAsFutureForcedDependencies(t){for(const e of t)e in this.#t&&this.recordFutureForcedDependency(e,this.#t[e]);return this}inheritPendingDependenciesAsFutureForcedDependencies(){for(const t of this.#l)this.recordFutureForcedDependency(he,t);return this}resetBBox(t){return this.#h!==t&&(this.#h=t,this.#o[0]=1/0,this.#o[1]=1/0,this.#o[2]=-1/0,this.#o[3]=-1/0),this}recordClipBox(t,e,s,i,n,r){const a=I.multiplyByDOMMatrix(this.#n.at(-1),e.getTransform()),o=[1/0,1/0,-1/0,-1/0];I.axialAlignedBoundingBox([s,n,i,r],a,o);const l=I.intersect(this.#r,o);return l?(this.#r[0]=l[0],this.#r[1]=l[1],this.#r[2]=l[2],this.#r[3]=l[3]):(this.#r[0]=this.#r[1]=1/0,this.#r[2]=this.#r[3]=-1/0),this}recordBBox(t,e,s,i,n,r){const a=this.#r;if(a[0]===1/0)return this;const o=I.multiplyByDOMMatrix(this.#n.at(-1),e.getTransform());if(a[0]===-1/0)return I.axialAlignedBoundingBox([s,n,i,r],o,this.#o),this;const l=[1/0,1/0,-1/0,-1/0];return I.axialAlignedBoundingBox([s,n,i,r],o,l),this.#o[0]=Math.min(this.#o[0],Math.max(l[0],a[0])),this.#o[1]=Math.min(this.#o[1],Math.max(l[1],a[1])),this.#o[2]=Math.max(this.#o[2],Math.min(l[2],a[2])),this.#o[3]=Math.max(this.#o[3],Math.min(l[3],a[3])),this}recordCharacterBBox(t,e,s,i=1,n=0,r=0,a){const o=s.bbox;let l,h;if(o&&(l=o[2]!==o[0]&&o[3]!==o[1]&&this.#d.get(s),l!==!1&&(h=[0,0,0,0],I.axialAlignedBoundingBox(o,s.fontMatrix,h),(i!==1||n!==0||r!==0)&&I.scaleMinMax([i,0,0,-i,n,r],h),l)))return this.recordBBox(t,e,h[0],h[2],h[1],h[3]);if(!a)return this.recordFullPageBBox(t);const d=a();return o&&h&&l===void 0&&(l=h[0]<=n-d.actualBoundingBoxLeft&&h[2]>=n+d.actualBoundingBoxRight&&h[1]<=r-d.actualBoundingBoxAscent&&h[3]>=r+d.actualBoundingBoxDescent,this.#d.set(s,l),l)?this.recordBBox(t,e,h[0],h[2],h[1],h[3]):this.recordBBox(t,e,n-d.actualBoundingBoxLeft,n+d.actualBoundingBoxRight,r-d.actualBoundingBoxAscent,r+d.actualBoundingBoxDescent)}recordFullPageBBox(t){return this.#o[0]=Math.max(0,this.#r[0]),this.#o[1]=Math.max(0,this.#r[1]),this.#o[2]=Math.min(this.#f,this.#r[2]),this.#o[3]=Math.min(this.#m,this.#r[3]),this}getSimpleIndex(t){return this.#t[t]}recordDependencies(t,e){const s=this.#l,i=this.#t,n=this.#e;for(const r of e)r in this.#t?s.add(i[r]):r in n&&n[r].forEach(s.add,s);return this}recordNamedDependency(t,e){return this.#i.has(e)&&this.#l.add(this.#i.get(e)),this}recordOperation(t,e=!1){if(this.recordDependencies(t,[he]),this.#g){const s=Je(this.#g,t),{dependencies:i}=s;this.#l.forEach(i.add,i),this.#s.forEach(i.add,i),this.#a.forEach(i.add,i),i.delete(t),s.isRenderingOperation=!0}if(this.#h===t){const s=Ai(this.#o[0]*256/this.#f),i=Ai(this.#o[1]*256/this.#m),n=wi(this.#o[2]*256/this.#f),r=wi(this.#o[3]*256/this.#m);Qe(this.#p,t,s,i,n,r);for(const a of this.#l)a!==t&&Qe(this.#p,a,s,i,n,r);for(const a of this.#s)a!==t&&Qe(this.#p,a,s,i,n,r);for(const a of this.#a)a!==t&&Qe(this.#p,a,s,i,n,r);e||(this.#l.clear(),this.#h=-1)}return this}recordShowTextOperation(t,e=!1){const s=Array.from(this.#l);this.recordOperation(t,e),this.recordIncrementalData("sameLineText",t);for(const i of s)this.recordIncrementalData("sameLineText",i);return this}bboxToClipBoxDropOperation(t,e=!1){return this.#h===t&&(this.#h=-1,this.#r[0]=Math.max(this.#r[0],this.#o[0]),this.#r[1]=Math.max(this.#r[1],this.#o[1]),this.#r[2]=Math.min(this.#r[2],this.#o[2]),this.#r[3]=Math.min(this.#r[3],this.#o[3]),e||this.#l.clear()),this}_takePendingDependencies(){const t=this.#l;return this.#l=new Set,t}_extractOperation(t){const e=this.#u.get(t);return this.#u.delete(t),e}_pushPendingDependencies(t){for(const e of t)this.#l.add(e)}take(){return this.#d.clear(),new Dr(this.#c,this.#p)}takeDebugMetadata(){return this.#g}}class as{#t;#e;#i;#s=0;#a=0;constructor(t,e,s){if(t instanceof as&&t.#i===!!s)return t;this.#t=t,this.#e=e,this.#i=!!s}growOperationsCount(){throw new Error("Unreachable")}save(t){return this.#a++,this.#t.save(this.#e),this}restore(t){return this.#a>0&&(this.#t.restore(this.#e),this.#a--),this}recordOpenMarker(t){return this.#s++,this}getOpenMarker(){return this.#s>0?this.#e:this.#t.getOpenMarker()}recordCloseMarker(t){return this.#s--,this}beginMarkedContent(t){return this}endMarkedContent(t){return this}pushBaseTransform(t){return this.#t.pushBaseTransform(t),this}popBaseTransform(){return this.#t.popBaseTransform(),this}recordSimpleData(t,e){return this.#t.recordSimpleData(t,this.#e),this}recordIncrementalData(t,e){return this.#t.recordIncrementalData(t,this.#e),this}resetIncrementalData(t,e){return this.#t.resetIncrementalData(t,this.#e),this}recordNamedData(t,e){return this}recordSimpleDataFromNamed(t,e,s){return this.#t.recordSimpleDataFromNamed(t,e,this.#e),this}recordFutureForcedDependency(t,e){return this.#t.recordFutureForcedDependency(t,this.#e),this}inheritSimpleDataAsFutureForcedDependencies(t){return this.#t.inheritSimpleDataAsFutureForcedDependencies(t),this}inheritPendingDependenciesAsFutureForcedDependencies(){return this.#t.inheritPendingDependenciesAsFutureForcedDependencies(),this}resetBBox(t){return this.#i||this.#t.resetBBox(this.#e),this}recordClipBox(t,e,s,i,n,r){return this.#i||this.#t.recordClipBox(this.#e,e,s,i,n,r),this}recordBBox(t,e,s,i,n,r){return this.#i||this.#t.recordBBox(this.#e,e,s,i,n,r),this}recordCharacterBBox(t,e,s,i,n,r,a){return this.#i||this.#t.recordCharacterBBox(this.#e,e,s,i,n,r,a),this}recordFullPageBBox(t){return this.#i||this.#t.recordFullPageBBox(this.#e),this}getSimpleIndex(t){return this.#t.getSimpleIndex(t)}recordDependencies(t,e){return this.#t.recordDependencies(this.#e,e),this}recordNamedDependency(t,e){return this.#t.recordNamedDependency(this.#e,e),this}recordOperation(t){return this.#t.recordOperation(this.#e,!0),this}recordShowTextOperation(t){return this.#t.recordShowTextOperation(this.#e,!0),this}bboxToClipBoxDropOperation(t){return this.#i||this.#t.bboxToClipBoxDropOperation(this.#e,!0),this}take(){throw new Error("Unreachable")}takeDebugMetadata(){throw new Error("Unreachable")}}const Nt={stroke:["path","transform","filter","strokeColor","strokeAlpha","lineWidth","lineCap","lineJoin","miterLimit","dash"],fill:["path","transform","filter","fillColor","fillAlpha","globalCompositeOperation","SMask"],imageXObject:["transform","SMask","filter","fillAlpha","strokeAlpha","globalCompositeOperation"],rawFillPath:["filter","fillColor","fillAlpha"],showText:["transform","leading","charSpacing","wordSpacing","hScale","textRise","moveText","textMatrix","font","fontObj","filter","fillColor","textRenderingMode","SMask","fillAlpha","strokeAlpha","globalCompositeOperation","sameLineText"],transform:["transform"],transformAndFill:["transform","fillColor"]},wt={FILL:"Fill",STROKE:"Stroke",SHADING:"Shading"};function Ls(c,t){if(!t)return;const e=t[2]-t[0],s=t[3]-t[1],i=new Path2D;i.rect(t[0],t[1],e,s),c.clip(i)}class Ys{isModifyingCurrentTransform(){return!1}getPattern(){nt("Abstract method `getPattern` called.")}}class Fr extends Ys{constructor(t){super(),this._type=t[1],this._bbox=t[2],this._colorStops=t[3],this._p0=t[4],this._p1=t[5],this._r0=t[6],this._r1=t[7],this.matrix=null}_createGradient(t){let e;this._type==="axial"?e=t.createLinearGradient(this._p0[0],this._p0[1],this._p1[0],this._p1[1]):this._type==="radial"&&(e=t.createRadialGradient(this._p0[0],this._p0[1],this._r0,this._p1[0],this._p1[1],this._r1));for(const s of this._colorStops)e.addColorStop(s[0],s[1]);return e}getPattern(t,e,s,i){let n;if(i===wt.STROKE||i===wt.FILL){const r=e.current.getClippedPathBoundingBox(i,ot(t))||[0,0,0,0],a=Math.ceil(r[2]-r[0])||1,o=Math.ceil(r[3]-r[1])||1,l=e.cachedCanvases.getCanvas("pattern",a,o),h=l.context;h.clearRect(0,0,h.canvas.width,h.canvas.height),h.beginPath(),h.rect(0,0,h.canvas.width,h.canvas.height),h.translate(-r[0],-r[1]),s=I.transform(s,[1,0,0,1,r[0],r[1]]),h.transform(...e.baseTransform),this.matrix&&h.transform(...this.matrix),Ls(h,this._bbox),h.fillStyle=this._createGradient(h),h.fill(),n=t.createPattern(l.canvas,"no-repeat");const d=new DOMMatrix(s);n.setTransform(d)}else Ls(t,this._bbox),n=this._createGradient(t);return n}}function Ss(c,t,e,s,i,n,r,a){const o=t.coords,l=t.colors,h=c.data,d=c.width*4;let u;o[e+1]>o[s+1]&&(u=e,e=s,s=u,u=n,n=r,r=u),o[s+1]>o[i+1]&&(u=s,s=i,i=u,u=r,r=a,a=u),o[e+1]>o[s+1]&&(u=e,e=s,s=u,u=n,n=r,r=u);const f=(o[e]+t.offsetX)*t.scaleX,g=(o[e+1]+t.offsetY)*t.scaleY,p=(o[s]+t.offsetX)*t.scaleX,b=(o[s+1]+t.offsetY)*t.scaleY,m=(o[i]+t.offsetX)*t.scaleX,y=(o[i+1]+t.offsetY)*t.scaleY;if(g>=y)return;const A=l[n],v=l[n+1],w=l[n+2],_=l[r],S=l[r+1],E=l[r+2],C=l[a],T=l[a+1],P=l[a+2],$=Math.round(g),G=Math.round(y);let O,H,M,F,z,Z,yt,Ct;for(let x=$;x<=G;x++){if(x<b){const k=x<g?0:(g-x)/(g-b);O=f-(f-p)*k,H=A-(A-_)*k,M=v-(v-S)*k,F=w-(w-E)*k}else{let k;x>y?k=1:b===y?k=0:k=(b-x)/(b-y),O=p-(p-m)*k,H=_-(_-C)*k,M=S-(S-T)*k,F=E-(E-P)*k}let N;x<g?N=0:x>y?N=1:N=(g-x)/(g-y),z=f-(f-m)*N,Z=A-(A-C)*N,yt=v-(v-T)*N,Ct=w-(w-P)*N;const L=Math.round(Math.min(O,z)),j=Math.round(Math.max(O,z));let X=d*x+L*4;for(let k=L;k<=j;k++)N=(O-k)/(O-z),N<0?N=0:N>1&&(N=1),h[X++]=H-(H-Z)*N|0,h[X++]=M-(M-yt)*N|0,h[X++]=F-(F-Ct)*N|0,h[X++]=255}}function Nr(c,t,e){const s=t.coords,i=t.colors;let n,r;switch(t.type){case"lattice":const a=t.verticesPerRow,o=Math.floor(s.length/a)-1,l=a-1;for(n=0;n<o;n++){let h=n*a;for(let d=0;d<l;d++,h++)Ss(c,e,s[h],s[h+1],s[h+a],i[h],i[h+1],i[h+a]),Ss(c,e,s[h+a+1],s[h+1],s[h+a],i[h+a+1],i[h+1],i[h+a])}break;case"triangles":for(n=0,r=s.length;n<r;n+=3)Ss(c,e,s[n],s[n+1],s[n+2],i[n],i[n+1],i[n+2]);break;default:throw new Error("illegal figure")}}class Or extends Ys{constructor(t){super(),this._coords=t[2],this._colors=t[3],this._figures=t[4],this._bounds=t[5],this._bbox=t[6],this._background=t[7],this.matrix=null}_createMeshCanvas(t,e,s){const a=Math.floor(this._bounds[0]),o=Math.floor(this._bounds[1]),l=Math.ceil(this._bounds[2])-a,h=Math.ceil(this._bounds[3])-o,d=Math.min(Math.ceil(Math.abs(l*t[0]*1.1)),3e3),u=Math.min(Math.ceil(Math.abs(h*t[1]*1.1)),3e3),f=l/d,g=h/u,p={coords:this._coords,colors:this._colors,offsetX:-a,offsetY:-o,scaleX:1/f,scaleY:1/g},b=d+2*2,m=u+2*2,y=s.getCanvas("mesh",b,m),A=y.context,v=A.createImageData(d,u);if(e){const _=v.data;for(let S=0,E=_.length;S<E;S+=4)_[S]=e[0],_[S+1]=e[1],_[S+2]=e[2],_[S+3]=255}for(const _ of this._figures)Nr(v,_,p);return A.putImageData(v,2,2),{canvas:y.canvas,offsetX:a-2*f,offsetY:o-2*g,scaleX:f,scaleY:g}}isModifyingCurrentTransform(){return!0}getPattern(t,e,s,i){Ls(t,this._bbox);const n=new Float32Array(2);if(i===wt.SHADING)I.singularValueDecompose2dScale(ot(t),n);else if(this.matrix){I.singularValueDecompose2dScale(this.matrix,n);const[a,o]=n;I.singularValueDecompose2dScale(e.baseTransform,n),n[0]*=a,n[1]*=o}else I.singularValueDecompose2dScale(e.baseTransform,n);const r=this._createMeshCanvas(n,i===wt.SHADING?null:this._background,e.cachedCanvases);return i!==wt.SHADING&&(t.setTransform(...e.baseTransform),this.matrix&&t.transform(...this.matrix)),t.translate(r.offsetX,r.offsetY),t.scale(r.scaleX,r.scaleY),t.createPattern(r.canvas,"no-repeat")}}class Br extends Ys{getPattern(){return"hotpink"}}function Hr(c){switch(c[0]){case"RadialAxial":return new Fr(c);case"Mesh":return new Or(c);case"Dummy":return new Br}throw new Error(`Unknown IR type: ${c[0]}`)}const vi={COLORED:1,UNCOLORED:2};class Ks{static MAX_PATTERN_SIZE=3e3;constructor(t,e,s,i){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.ctx=e,this.canvasGraphicsFactory=s,this.baseTransform=i}createPatternCanvas(t,e){const{bbox:s,operatorList:i,paintType:n,tilingType:r,color:a,canvasGraphicsFactory:o}=this;let{xstep:l,ystep:h}=this;l=Math.abs(l),h=Math.abs(h),ls("TilingType: "+r);const d=s[0],u=s[1],f=s[2],g=s[3],p=f-d,b=g-u,m=new Float32Array(2);I.singularValueDecompose2dScale(this.matrix,m);const[y,A]=m;I.singularValueDecompose2dScale(this.baseTransform,m);const v=y*m[0],w=A*m[1];let _=p,S=b,E=!1,C=!1;const T=Math.ceil(l*v),P=Math.ceil(h*w),$=Math.ceil(p*v),G=Math.ceil(b*w);T>=$?_=l:E=!0,P>=G?S=h:C=!0;const O=this.getSizeAndScale(_,this.ctx.canvas.width,v),H=this.getSizeAndScale(S,this.ctx.canvas.height,w),M=t.cachedCanvases.getCanvas("pattern",O.size,H.size),F=M.context,z=o.createCanvasGraphics(F,e);if(z.groupLevel=t.groupLevel,this.setFillAndStrokeStyleToContext(z,n,a),F.translate(-O.scale*d,-H.scale*u),z.transform(0,O.scale,0,0,H.scale,0,0),F.save(),z.dependencyTracker?.save(),this.clipBbox(z,d,u,f,g),z.baseTransform=ot(z.ctx),z.executeOperatorList(i),z.endDrawing(),z.dependencyTracker?.restore(),F.restore(),E||C){const Z=M.canvas;E&&(_=l),C&&(S=h);const yt=this.getSizeAndScale(_,this.ctx.canvas.width,v),Ct=this.getSizeAndScale(S,this.ctx.canvas.height,w),x=yt.size,N=Ct.size,L=t.cachedCanvases.getCanvas("pattern-workaround",x,N),j=L.context,X=E?Math.floor(p/l):0,k=C?Math.floor(b/h):0;for(let q=0;q<=X;q++)for(let rt=0;rt<=k;rt++)j.drawImage(Z,x*q,N*rt,x,N,0,0,x,N);return{canvas:L.canvas,scaleX:yt.scale,scaleY:Ct.scale,offsetX:d,offsetY:u}}return{canvas:M.canvas,scaleX:O.scale,scaleY:H.scale,offsetX:d,offsetY:u}}getSizeAndScale(t,e,s){const i=Math.max(Ks.MAX_PATTERN_SIZE,e);let n=Math.ceil(t*s);return n>=i?n=i:s=n/t,{scale:s,size:n}}clipBbox(t,e,s,i,n){const r=i-e,a=n-s;t.ctx.rect(e,s,r,a),I.axialAlignedBoundingBox([e,s,i,n],ot(t.ctx),t.current.minMax),t.clip(),t.endPath()}setFillAndStrokeStyleToContext(t,e,s){const i=t.ctx,n=t.current;switch(e){case vi.COLORED:const{fillStyle:r,strokeStyle:a}=this.ctx;i.fillStyle=n.fillColor=r,i.strokeStyle=n.strokeColor=a;break;case vi.UNCOLORED:i.fillStyle=i.strokeStyle=s,n.fillColor=n.strokeColor=s;break;default:throw new ar(`Unsupported paint type: ${e}`)}}isModifyingCurrentTransform(){return!1}getPattern(t,e,s,i,n){let r=s;i!==wt.SHADING&&(r=I.transform(r,e.baseTransform),this.matrix&&(r=I.transform(r,this.matrix)));const 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 l.setTransform(o),l}}function Ur({src:c,srcPos:t=0,dest:e,width:s,height:i,nonBlackColor:n=4294967295,inverseDecode:r=!1}){const a=bt.isLittleEndian?4278190080:255,[o,l]=r?[n,a]:[a,n],h=s>>3,d=s&7,u=c.length;e=new Uint32Array(e.buffer);let f=0;for(let g=0;g<i;g++){for(const b=t+h;t<b;t++){const m=t<u?c[t]:255;e[f++]=m&128?l:o,e[f++]=m&64?l:o,e[f++]=m&32?l:o,e[f++]=m&16?l:o,e[f++]=m&8?l:o,e[f++]=m&4?l:o,e[f++]=m&2?l:o,e[f++]=m&1?l:o}if(d===0)continue;const p=t<u?c[t++]:255;for(let b=0;b<d;b++)e[f++]=p&1<<7-b?l:o}return{srcPos:t,destPos:f}}const _i=16,Si=100,jr=15,Ei=10,Pt=16,Es=new DOMMatrix,Lt=new Float32Array(2),ue=new Float32Array([1/0,1/0,-1/0,-1/0]);function $r(c,t){if(c._removeMirroring)throw new Error("Context is already forwarding operations.");c.__originalSave=c.save,c.__originalRestore=c.restore,c.__originalRotate=c.rotate,c.__originalScale=c.scale,c.__originalTranslate=c.translate,c.__originalTransform=c.transform,c.__originalSetTransform=c.setTransform,c.__originalResetTransform=c.resetTransform,c.__originalClip=c.clip,c.__originalMoveTo=c.moveTo,c.__originalLineTo=c.lineTo,c.__originalBezierCurveTo=c.bezierCurveTo,c.__originalRect=c.rect,c.__originalClosePath=c.closePath,c.__originalBeginPath=c.beginPath,c._removeMirroring=()=>{c.save=c.__originalSave,c.restore=c.__originalRestore,c.rotate=c.__originalRotate,c.scale=c.__originalScale,c.translate=c.__originalTranslate,c.transform=c.__originalTransform,c.setTransform=c.__originalSetTransform,c.resetTransform=c.__originalResetTransform,c.clip=c.__originalClip,c.moveTo=c.__originalMoveTo,c.lineTo=c.__originalLineTo,c.bezierCurveTo=c.__originalBezierCurveTo,c.rect=c.__originalRect,c.closePath=c.__originalClosePath,c.beginPath=c.__originalBeginPath,delete c._removeMirroring},c.save=function(){t.save(),this.__originalSave()},c.restore=function(){t.restore(),this.__originalRestore()},c.translate=function(e,s){t.translate(e,s),this.__originalTranslate(e,s)},c.scale=function(e,s){t.scale(e,s),this.__originalScale(e,s)},c.transform=function(e,s,i,n,r,a){t.transform(e,s,i,n,r,a),this.__originalTransform(e,s,i,n,r,a)},c.setTransform=function(e,s,i,n,r,a){t.setTransform(e,s,i,n,r,a),this.__originalSetTransform(e,s,i,n,r,a)},c.resetTransform=function(){t.resetTransform(),this.__originalResetTransform()},c.rotate=function(e){t.rotate(e),this.__originalRotate(e)},c.clip=function(e){t.clip(e),this.__originalClip(e)},c.moveTo=function(e,s){t.moveTo(e,s),this.__originalMoveTo(e,s)},c.lineTo=function(e,s){t.lineTo(e,s),this.__originalLineTo(e,s)},c.bezierCurveTo=function(e,s,i,n,r,a){t.bezierCurveTo(e,s,i,n,r,a),this.__originalBezierCurveTo(e,s,i,n,r,a)},c.rect=function(e,s,i,n){t.rect(e,s,i,n),this.__originalRect(e,s,i,n)},c.closePath=function(){t.closePath(),this.__originalClosePath()},c.beginPath=function(){t.beginPath(),this.__originalBeginPath()}}class Gr{constructor(t){this.canvasFactory=t,this.cache=Object.create(null)}getCanvas(t,e,s){let i;return this.cache[t]!==void 0?(i=this.cache[t],this.canvasFactory.reset(i,e,s)):(i=this.canvasFactory.create(e,s),this.cache[t]=i),i}delete(t){delete this.cache[t]}clear(){for(const t in this.cache){const e=this.cache[t];this.canvasFactory.destroy(e),delete this.cache[t]}}}function Ze(c,t,e,s,i,n,r,a,o,l){const[h,d,u,f,g,p]=ot(c);if(d===0&&u===0){const y=r*h+g,A=Math.round(y),v=a*f+p,w=Math.round(v),_=(r+o)*h+g,S=Math.abs(Math.round(_)-A)||1,E=(a+l)*f+p,C=Math.abs(Math.round(E)-w)||1;return c.setTransform(Math.sign(h),0,0,Math.sign(f),A,w),c.drawImage(t,e,s,i,n,0,0,S,C),c.setTransform(h,d,u,f,g,p),[S,C]}if(h===0&&f===0){const y=a*u+g,A=Math.round(y),v=r*d+p,w=Math.round(v),_=(a+l)*u+g,S=Math.abs(Math.round(_)-A)||1,E=(r+o)*d+p,C=Math.abs(Math.round(E)-w)||1;return c.setTransform(0,Math.sign(d),Math.sign(u),0,A,w),c.drawImage(t,e,s,i,n,0,0,C,S),c.setTransform(h,d,u,f,g,p),[C,S]}c.drawImage(t,e,s,i,n,r,a,o,l);const b=Math.hypot(h,d),m=Math.hypot(u,f);return[b*o,m*l]}class Ci{alphaIsShape=!1;fontSize=0;fontSizeScale=1;textMatrix=null;textMatrixScale=1;fontMatrix=Ts;leading=0;x=0;y=0;lineX=0;lineY=0;charSpacing=0;wordSpacing=0;textHScale=1;textRenderingMode=At.FILL;textRise=0;fillColor="#000000";strokeColor="#000000";patternFill=!1;patternStroke=!1;fillAlpha=1;strokeAlpha=1;lineWidth=1;activeSMask=null;transferMaps="none";constructor(t,e,s){s?.(this),this.clipBox=new Float32Array([0,0,t,e]),this.minMax=ue.slice()}clone(){const t=Object.create(this);return t.clipBox=this.clipBox.slice(),t.minMax=this.minMax.slice(),t}getPathBoundingBox(t=wt.FILL,e=null){const s=this.minMax.slice();if(t===wt.STROKE){e||nt("Stroke bounding box must include transform."),I.singularValueDecompose2dScale(e,Lt);const i=Lt[0]*this.lineWidth/2,n=Lt[1]*this.lineWidth/2;s[0]-=i,s[1]-=n,s[2]+=i,s[3]+=n}return s}updateClipFromPath(){const t=I.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(ue,0)}getClippedPathBoundingBox(t=wt.FILL,e=null){return I.intersect(this.clipBox,this.getPathBoundingBox(t,e))}}function xi(c,t){if(t instanceof ImageData){c.putImageData(t,0,0);return}const e=t.height,s=t.width,i=e%Pt,n=(e-i)/Pt,r=i===0?n:n+1,a=c.createImageData(s,Pt);let o=0,l;const h=t.data,d=a.data;let u,f,g,p;if(t.kind===ke.GRAYSCALE_1BPP){const b=h.byteLength,m=new Uint32Array(d.buffer,0,d.byteLength>>2),y=m.length,A=s+7>>3,v=4294967295,w=bt.isLittleEndian?4278190080:255;for(u=0;u<r;u++){for(g=u<n?Pt:i,l=0,f=0;f<g;f++){const _=b-o;let S=0;const E=_>A?s:_*8-7,C=E&-8;let T=0,P=0;for(;S<C;S+=8)P=h[o++],m[l++]=P&128?v:w,m[l++]=P&64?v:w,m[l++]=P&32?v:w,m[l++]=P&16?v:w,m[l++]=P&8?v:w,m[l++]=P&4?v:w,m[l++]=P&2?v:w,m[l++]=P&1?v:w;for(;S<E;S++)T===0&&(P=h[o++],T=128),m[l++]=P&T?v:w,T>>=1}for(;l<y;)m[l++]=0;c.putImageData(a,0,u*Pt)}}else if(t.kind===ke.RGBA_32BPP){for(f=0,p=s*Pt*4,u=0;u<n;u++)d.set(h.subarray(o,o+p)),o+=p,c.putImageData(a,0,f),f+=Pt;u<r&&(p=s*i*4,d.set(h.subarray(o,o+p)),c.putImageData(a,0,f))}else if(t.kind===ke.RGB_24BPP)for(g=Pt,p=s*g,u=0;u<r;u++){for(u>=n&&(g=i,p=s*g),l=0,f=p;f--;)d[l++]=h[o++],d[l++]=h[o++],d[l++]=h[o++],d[l++]=255;c.putImageData(a,0,u*Pt)}else throw new Error(`bad image kind: ${t.kind}`)}function Ti(c,t){if(t.bitmap){c.drawImage(t.bitmap,0,0);return}const e=t.height,s=t.width,i=e%Pt,n=(e-i)/Pt,r=i===0?n:n+1,a=c.createImageData(s,Pt);let o=0;const l=t.data,h=a.data;for(let d=0;d<r;d++){const u=d<n?Pt:i;({srcPos:o}=Ur({src:l,srcPos:o,dest:h,width:s,height:u,nonBlackColor:0})),c.putImageData(a,0,d*Pt)}}function Se(c,t){const e=["strokeStyle","fillStyle","fillRule","globalAlpha","lineWidth","lineCap","lineJoin","miterLimit","globalCompositeOperation","font","filter"];for(const s of e)c[s]!==void 0&&(t[s]=c[s]);c.setLineDash!==void 0&&(t.setLineDash(c.getLineDash()),t.lineDashOffset=c.lineDashOffset)}function ts(c){c.strokeStyle=c.fillStyle="#000000",c.fillRule="nonzero",c.globalAlpha=1,c.lineWidth=1,c.lineCap="butt",c.lineJoin="miter",c.miterLimit=10,c.globalCompositeOperation="source-over",c.font="10px sans-serif",c.setLineDash!==void 0&&(c.setLineDash([]),c.lineDashOffset=0);const{filter:t}=c;t!=="none"&&t!==""&&(c.filter="none")}function Pi(c,t){if(t)return!0;I.singularValueDecompose2dScale(c,Lt);const e=Math.fround(Ht.pixelRatio*ie.PDF_TO_CSS_UNITS);return Lt[0]<=e&&Lt[1]<=e}const zr=["butt","round","square"],Vr=["miter","round","bevel"],Wr={},ki={};class pe{constructor(t,e,s,i,n,{optionalContentConfig:r,markedContentStack:a=null},o,l,h){this.ctx=t,this.current=new Ci(this.ctx.canvas.width,this.ctx.canvas.height),this.stateStack=[],this.pendingClip=null,this.pendingEOFill=!1,this.res=null,this.xobjs=null,this.commonObjs=e,this.objs=s,this.canvasFactory=i,this.filterFactory=n,this.groupStack=[],this.baseTransform=null,this.baseTransformStack=[],this.groupLevel=0,this.smaskStack=[],this.smaskCounter=0,this.tempSMask=null,this.suspendedCtx=null,this.contentVisible=!0,this.markedContentStack=a||[],this.optionalContentConfig=r,this.cachedCanvases=new Gr(this.canvasFactory),this.cachedPatterns=new Map,this.annotationCanvasMap=o,this.viewportScale=1,this.outputScaleX=1,this.outputScaleY=1,this.pageColors=l,this._cachedScaleForStroking=[-1,0],this._cachedGetSinglePixelWidth=null,this._cachedBitmapsMap=new Map,this.dependencyTracker=h??null}getObject(t,e,s=null){return typeof e=="string"?(this.dependencyTracker?.recordNamedDependency(t,e),e.startsWith("g_")?this.commonObjs.get(e):this.objs.get(e)):s}beginDrawing({transform:t,viewport:e,transparency:s=!1,background:i=null}){const n=this.ctx.canvas.width,r=this.ctx.canvas.height,a=this.ctx.fillStyle;if(this.ctx.fillStyle=i||"#ffffff",this.ctx.fillRect(0,0,n,r),this.ctx.fillStyle=a,s){const o=this.cachedCanvases.getCanvas("transparent",n,r);this.compositeCtx=this.ctx,this.transparentCanvas=o.canvas,this.ctx=o.context,this.ctx.save(),this.ctx.transform(...ot(this.compositeCtx))}this.ctx.save(),ts(this.ctx),t&&(this.ctx.transform(...t),this.outputScaleX=t[0],this.outputScaleY=t[0]),this.ctx.transform(...e.transform),this.viewportScale=e.scale,this.baseTransform=ot(this.ctx)}executeOperatorList(t,e,s,i,n){const r=t.argsArray,a=t.fnArray;let o=e||0;const l=r.length;if(l===o)return o;const h=l-o>Ei&&typeof s=="function",d=h?Date.now()+jr:0;let u=0;const f=this.commonObjs,g=this.objs;let p,b;for(;;){if(i!==void 0&&o===i.nextBreakPoint)return i.breakIt(o,s),o;if(!n||n(o))if(p=a[o],b=r[o]??null,p!==Ae.dependency)b===null?this[p](o):this[p](o,...b);else for(const m of b){this.dependencyTracker?.recordNamedData(m,o);const y=m.startsWith("g_")?f:g;if(!y.has(m))return y.get(m,s),o}if(o++,o===l)return o;if(h&&++u>Ei){if(Date.now()>d)return s(),o;u=0}}}#t(){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.transparentCanvas=null)}endDrawing(){this.#t(),this.cachedCanvases.clear(),this.cachedPatterns.clear();for(const t of this._cachedBitmapsMap.values()){for(const e of t.values())typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement&&(e.width=e.height=0);t.clear()}this._cachedBitmapsMap.clear(),this.#e()}#e(){if(this.pageColors){const t=this.filterFactory.addHCMFilter(this.pageColors.foreground,this.pageColors.background);if(t!=="none"){const e=this.ctx.filter;this.ctx.filter=t,this.ctx.drawImage(this.ctx.canvas,0,0),this.ctx.filter=e}}}_scaleImage(t,e){const s=t.width??t.displayWidth,i=t.height??t.displayHeight;let n=Math.max(Math.hypot(e[0],e[1]),1),r=Math.max(Math.hypot(e[2],e[3]),1),a=s,o=i,l="prescale1",h,d;for(;n>2&&a>1||r>2&&o>1;){let u=a,f=o;n>2&&a>1&&(u=a>=16384?Math.floor(a/2)-1||1:Math.ceil(a/2),n/=a/u),r>2&&o>1&&(f=o>=16384?Math.floor(o/2)-1||1:Math.ceil(o)/2,r/=o/f),h=this.cachedCanvases.getCanvas(l,u,f),d=h.context,d.clearRect(0,0,u,f),d.drawImage(t,0,0,a,o,0,0,u,f),t=h.canvas,a=u,o=f,l=l==="prescale1"?"prescale2":"prescale1"}return{img:t,paintWidth:a,paintHeight:o}}_createMaskCanvas(t,e){const s=this.ctx,{width:i,height:n}=e,r=this.current.fillColor,a=this.current.patternFill,o=ot(s);let l,h,d,u;if((e.bitmap||e.data)&&e.count>1){const T=e.bitmap||e.data.buffer;h=JSON.stringify(a?o:[o.slice(0,4),r]),l=this._cachedBitmapsMap.get(T),l||(l=new Map,this._cachedBitmapsMap.set(T,l));const P=l.get(h);if(P&&!a){const $=Math.round(Math.min(o[0],o[2])+o[4]),G=Math.round(Math.min(o[1],o[3])+o[5]);return this.dependencyTracker?.recordDependencies(t,Nt.transformAndFill),{canvas:P,offsetX:$,offsetY:G}}d=P}d||(u=this.cachedCanvases.getCanvas("maskCanvas",i,n),Ti(u.context,e));let f=I.transform(o,[1/i,0,0,-1/n,0,0]);f=I.transform(f,[1,0,0,1,0,-n]);const g=ue.slice();I.axialAlignedBoundingBox([0,0,i,n],f,g);const[p,b,m,y]=g,A=Math.round(m-p)||1,v=Math.round(y-b)||1,w=this.cachedCanvases.getCanvas("fillCanvas",A,v),_=w.context,S=p,E=b;_.translate(-S,-E),_.transform(...f),d||(d=this._scaleImage(u.canvas,Ut(_)),d=d.img,l&&a&&l.set(h,d)),_.imageSmoothingEnabled=Pi(ot(_),e.interpolate),Ze(_,d,0,0,d.width,d.height,0,0,i,n),_.globalCompositeOperation="source-in";const C=I.transform(Ut(_),[1,0,0,1,-S,-E]);return _.fillStyle=a?r.getPattern(s,this,C,wt.FILL,t):r,_.fillRect(0,0,i,n),l&&!a&&(this.cachedCanvases.delete("fillCanvas"),l.set(h,w.canvas)),this.dependencyTracker?.recordDependencies(t,Nt.transformAndFill),{canvas:w.canvas,offsetX:Math.round(S),offsetY:Math.round(E)}}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=zr[e]}setLineJoin(t,e){this.dependencyTracker?.recordSimpleData("lineJoin",t),this.ctx.lineJoin=Vr[e]}setMiterLimit(t,e){this.dependencyTracker?.recordSimpleData("miterLimit",t),this.ctx.miterLimit=e}setDash(t,e,s){this.dependencyTracker?.recordSimpleData("dash",t);const i=this.ctx;i.setLineDash!==void 0&&(i.setLineDash(e),i.lineDashOffset=s)}setRenderingIntent(t,e){}setFlatness(t,e){}setGState(t,e){for(const[s,i]of e)switch(s){case"LW":this.setLineWidth(t,i);break;case"LC":this.setLineCap(t,i);break;case"LJ":this.setLineJoin(t,i);break;case"ML":this.setMiterLimit(t,i);break;case"D":this.setDash(t,i[0],i[1]);break;case"RI":this.setRenderingIntent(t,i);break;case"FL":this.setFlatness(t,i);break;case"Font":this.setFont(t,i[0],i[1]);break;case"CA":this.dependencyTracker?.recordSimpleData("strokeAlpha",t),this.current.strokeAlpha=i;break;case"ca":this.dependencyTracker?.recordSimpleData("fillAlpha",t),this.ctx.globalAlpha=this.current.fillAlpha=i;break;case"BM":this.dependencyTracker?.recordSimpleData("globalCompositeOperation",t),this.ctx.globalCompositeOperation=i;break;case"SMask":this.dependencyTracker?.recordSimpleData("SMask",t),this.current.activeSMask=i?this.tempSMask:null,this.tempSMask=null,this.checkSMaskState();break;case"TR":this.dependencyTracker?.recordSimpleData("filter",t),this.ctx.filter=this.current.transferMaps=this.filterFactory.addFilter(i);break}}get inSMaskMode(){return!!this.suspendedCtx}checkSMaskState(){const t=this.inSMaskMode;this.current.activeSMask&&!t?this.beginSMaskMode():!this.current.activeSMask&&t&&this.endSMaskMode()}beginSMaskMode(t){if(this.inSMaskMode)throw new Error("beginSMaskMode called while already in smask mode");const e=this.ctx.canvas.width,s=this.ctx.canvas.height,i="smaskGroupAt"+this.groupLevel,n=this.cachedCanvases.getCanvas(i,e,s);this.suspendedCtx=this.ctx;const r=this.ctx=n.context;r.setTransform(this.suspendedCtx.getTransform()),Se(this.suspendedCtx,r),$r(r,this.suspendedCtx),this.setGState(t,[["BM","source-over"]])}endSMaskMode(){if(!this.inSMaskMode)throw new Error("endSMaskMode called while not in smask mode");this.ctx._removeMirroring(),Se(this.ctx,this.suspendedCtx),this.ctx=this.suspendedCtx,this.suspendedCtx=null}compose(t){if(!this.current.activeSMask)return;t?(t[0]=Math.floor(t[0]),t[1]=Math.floor(t[1]),t[2]=Math.ceil(t[2]),t[3]=Math.ceil(t[3])):t=[0,0,this.ctx.canvas.width,this.ctx.canvas.height];const e=this.current.activeSMask,s=this.suspendedCtx;this.composeSMask(s,e,this.ctx,t),this.ctx.save(),this.ctx.setTransform(1,0,0,1,0,0),this.ctx.clearRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height),this.ctx.restore()}composeSMask(t,e,s,i){const n=i[0],r=i[1],a=i[2]-n,o=i[3]-r;a===0||o===0||(this.genericComposeSMask(e.context,s,a,o,e.subtype,e.backdrop,e.transferMap,n,r,e.offsetX,e.offsetY),t.save(),t.globalAlpha=1,t.globalCompositeOperation="source-over",t.setTransform(1,0,0,1,0,0),t.drawImage(s.canvas,0,0),t.restore())}genericComposeSMask(t,e,s,i,n,r,a,o,l,h,d){let u=t.canvas,f=o-h,g=l-d;if(r)if(f<0||g<0||f+s>u.width||g+i>u.height){const b=this.cachedCanvases.getCanvas("maskExtension",s,i),m=b.context;m.drawImage(u,-f,-g),m.globalCompositeOperation="destination-atop",m.fillStyle=r,m.fillRect(0,0,s,i),m.globalCompositeOperation="source-over",u=b.canvas,f=g=0}else{t.save(),t.globalAlpha=1,t.setTransform(1,0,0,1,0,0);const b=new Path2D;b.rect(f,g,s,i),t.clip(b),t.globalCompositeOperation="destination-atop",t.fillStyle=r,t.fillRect(f,g,s,i),t.restore()}e.save(),e.globalAlpha=1,e.setTransform(1,0,0,1,0,0),n==="Alpha"&&a?e.filter=this.filterFactory.addAlphaFilter(a):n==="Luminosity"&&(e.filter=this.filterFactory.addLuminosityFilter(a));const p=new Path2D;p.rect(o,l,s,i),e.clip(p),e.globalCompositeOperation="destination-in",e.drawImage(u,f,g,s,i,o,l,s,i),e.restore()}save(t){this.inSMaskMode&&Se(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){if(this.dependencyTracker?.restore(t),this.stateStack.length===0){this.inSMaskMode&&this.endSMaskMode();return}this.current=this.stateStack.pop(),this.ctx.restore(),this.inSMaskMode&&Se(this.suspendedCtx,this.ctx),this.checkSMaskState(),this.pendingClip=null,this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null}transform(t,e,s,i,n,r,a){this.dependencyTracker?.recordIncrementalData("transform",t),this.ctx.transform(e,s,i,n,r,a),this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null}constructPath(t,e,s,i){let[n]=s;if(!i){n||=s[0]=new Path2D,this[e](t,n);return}if(this.dependencyTracker!==null){const r=e===Ae.stroke?this.current.lineWidth/2:0;this.dependencyTracker.resetBBox(t).recordBBox(t,this.ctx,i[0]-r,i[2]+r,i[1]-r,i[3]+r).recordDependencies(t,["transform"])}if(!(n instanceof Path2D)){const r=s[0]=new Path2D;for(let a=0,o=n.length;a<o;)switch(n[a++]){case Xe.moveTo:r.moveTo(n[a++],n[a++]);break;case Xe.lineTo:r.lineTo(n[a++],n[a++]);break;case Xe.curveTo:r.bezierCurveTo(n[a++],n[a++],n[a++],n[a++],n[a++],n[a++]);break;case Xe.closePath:r.closePath();break;default:W(`Unrecognized drawing path operator: ${n[a-1]}`);break}n=r}I.axialAlignedBoundingBox(i,ot(this.ctx),this.current.minMax),this[e](t,n),this._pathStartIdx=t}closePath(t){this.ctx.closePath()}stroke(t,e,s=!0){const i=this.ctx,n=this.current.strokeColor;if(i.globalAlpha=this.current.strokeAlpha,this.contentVisible)if(typeof n=="object"&&n?.getPattern){const r=n.isModifyingCurrentTransform()?i.getTransform():null;if(i.save(),i.strokeStyle=n.getPattern(i,this,Ut(i),wt.STROKE,t),r){const a=new Path2D;a.addPath(e,i.getTransform().invertSelf().multiplySelf(r)),e=a}this.rescaleAndStroke(e,!1),i.restore()}else this.rescaleAndStroke(e,!0);this.dependencyTracker?.recordDependencies(t,Nt.stroke),s&&this.consumePath(t,e,this.current.getClippedPathBoundingBox(wt.STROKE,ot(this.ctx))),i.globalAlpha=this.current.fillAlpha}closeStroke(t,e){this.stroke(t,e)}fill(t,e,s=!0){const i=this.ctx,n=this.current.fillColor,r=this.current.patternFill;let a=!1;if(r){const l=n.isModifyingCurrentTransform()?i.getTransform():null;if(this.dependencyTracker?.save(t),i.save(),i.fillStyle=n.getPattern(i,this,Ut(i),wt.FILL,t),l){const h=new Path2D;h.addPath(e,i.getTransform().invertSelf().multiplySelf(l)),e=h}a=!0}const o=this.current.getClippedPathBoundingBox();this.contentVisible&&o!==null&&(this.pendingEOFill?(i.fill(e,"evenodd"),this.pendingEOFill=!1):i.fill(e)),this.dependencyTracker?.recordDependencies(t,Nt.fill),a&&(i.restore(),this.dependencyTracker?.restore(t)),s&&this.consumePath(t,e,o)}eoFill(t,e){this.pendingEOFill=!0,this.fill(t,e)}fillStroke(t,e){this.fill(t,e,!1),this.stroke(t,e,!1),this.consumePath(t,e)}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){this.ctx.fill(e),this.dependencyTracker?.recordDependencies(t,Nt.rawFillPath).recordOperation(t)}clip(t){this.dependencyTracker?.recordFutureForcedDependency("clipMode",t),this.pendingClip=Wr}eoClip(t){this.dependencyTracker?.recordFutureForcedDependency("clipMode",t),this.pendingClip=ki}beginText(t){this.current.textMatrix=null,this.current.textMatrixScale=1,this.current.x=this.current.lineX=0,this.current.y=this.current.lineY=0,this.dependencyTracker?.recordOpenMarker(t).resetIncrementalData("sameLineText").resetIncrementalData("moveText",t)}endText(t){const e=this.pendingTextPaths,s=this.ctx;if(this.dependencyTracker){const{dependencyTracker:i}=this;e!==void 0&&i.recordFutureForcedDependency("textClip",i.getOpenMarker()).recordFutureForcedDependency("textClip",t),i.recordCloseMarker(t)}if(e!==void 0){const i=new Path2D,n=s.getTransform().invertSelf();for(const{transform:r,x:a,y:o,fontSize:l,path:h}of e)h&&i.addPath(h,new DOMMatrix(r).preMultiplySelf(n).translate(a,o).scale(l,-l));s.clip(i)}delete this.pendingTextPaths}setCharSpacing(t,e){this.dependencyTracker?.recordSimpleData("charSpacing",t),this.current.charSpacing=e}setWordSpacing(t,e){this.dependencyTracker?.recordSimpleData("wordSpacing",t),this.current.wordSpacing=e}setHScale(t,e){this.dependencyTracker?.recordSimpleData("hScale",t),this.current.textHScale=e/100}setLeading(t,e){this.dependencyTracker?.recordSimpleData("leading",t),this.current.leading=-e}setFont(t,e,s){this.dependencyTracker?.recordSimpleData("font",t).recordSimpleDataFromNamed("fontObj",e,t);const i=this.commonObjs.get(e),n=this.current;if(!i)throw new Error(`Can't find font for ${e}`);if(n.fontMatrix=i.fontMatrix||Ts,(n.fontMatrix[0]===0||n.fontMatrix[3]===0)&&W("Invalid font matrix for font "+e),s<0?(s=-s,n.fontDirection=-1):n.fontDirection=1,this.current.font=i,this.current.fontSize=s,i.isType3Font)return;const r=i.loadedName||"sans-serif",a=i.systemFontInfo?.css||`"${r}", ${i.fallbackName}`;let o="normal";i.black?o="900":i.bold&&(o="bold");const l=i.italic?"italic":"normal";let h=s;s<_i?h=_i:s>Si&&(h=Si),this.current.fontSizeScale=s/h,this.ctx.font=`${l} ${o} ${h}px ${a}`}setTextRenderingMode(t,e){this.dependencyTracker?.recordSimpleData("textRenderingMode",t),this.current.textRenderingMode=e}setTextRise(t,e){this.dependencyTracker?.recordSimpleData("textRise",t),this.current.textRise=e}moveText(t,e,s){this.dependencyTracker?.resetIncrementalData("sameLineText").recordIncrementalData("moveText",t),this.current.x=this.current.lineX+=e,this.current.y=this.current.lineY+=s}setLeadingMoveText(t,e,s){this.setLeading(t,-s),this.moveText(t,e,s)}setTextMatrix(t,e){this.dependencyTracker?.recordSimpleData("textMatrix",t);const{current:s}=this;s.textMatrix=e,s.textMatrixScale=Math.hypot(e[0],e[1]),s.x=s.lineX=0,s.y=s.lineY=0}nextLine(t){this.moveText(t,0,this.current.leading),this.dependencyTracker?.recordIncrementalData("moveText",this.dependencyTracker.getSimpleIndex("leading")??t)}#i(t,e,s){const i=new Path2D;return i.addPath(t,new DOMMatrix(s).invertSelf().multiplySelf(e)),i}paintChar(t,e,s,i,n,r){const a=this.ctx,o=this.current,l=o.font,h=o.textRenderingMode,d=o.fontSize/o.fontSizeScale,u=h&At.FILL_STROKE_MASK,f=!!(h&At.ADD_TO_PATH_FLAG),g=o.patternFill&&!l.missingFile,p=o.patternStroke&&!l.missingFile;let b;if((l.disableFontFace||f||g||p)&&!l.missingFile&&(b=l.getPathGenerator(this.commonObjs,e)),b&&(l.disableFontFace||g||p)){a.save(),a.translate(s,i),a.scale(d,-d),this.dependencyTracker?.recordCharacterBBox(t,a,l);let m;if(u===At.FILL||u===At.FILL_STROKE)if(n){m=a.getTransform(),a.setTransform(...n);const y=this.#i(b,m,n);a.fill(y)}else a.fill(b);if(u===At.STROKE||u===At.FILL_STROKE)if(r){m||=a.getTransform(),a.setTransform(...r);const{a:y,b:A,c:v,d:w}=m,_=I.inverseTransform(r),S=I.transform([y,A,v,w,0,0],_);I.singularValueDecompose2dScale(S,Lt),a.lineWidth*=Math.max(Lt[0],Lt[1])/d,a.stroke(this.#i(b,m,r))}else a.lineWidth/=d,a.stroke(b);a.restore()}else(u===At.FILL||u===At.FILL_STROKE)&&(a.fillText(e,s,i),this.dependencyTracker?.recordCharacterBBox(t,a,l,d,s,i,()=>a.measureText(e))),(u===At.STROKE||u===At.FILL_STROKE)&&(this.dependencyTracker&&this.dependencyTracker?.recordCharacterBBox(t,a,l,d,s,i,()=>a.measureText(e)).recordDependencies(t,Nt.stroke),a.strokeText(e,s,i));f&&((this.pendingTextPaths||=[]).push({transform:ot(a),x:s,y:i,fontSize:d,path:b}),this.dependencyTracker?.recordCharacterBBox(t,a,l,d,s,i))}get isFontSubpixelAAEnabled(){const{context:t}=this.cachedCanvases.getCanvas("isFontSubpixelAAEnabled",10,10);t.scale(1.5,1),t.fillText("I",0,10);const e=t.getImageData(0,0,10,10).data;let s=!1;for(let i=3;i<e.length;i+=4)if(e[i]>0&&e[i]<255){s=!0;break}return Y(this,"isFontSubpixelAAEnabled",s)}showText(t,e){this.dependencyTracker&&(this.dependencyTracker.recordDependencies(t,Nt.showText).resetBBox(t),this.current.textRenderingMode&At.ADD_TO_PATH_FLAG&&this.dependencyTracker.recordFutureForcedDependency("textClip",t).inheritPendingDependenciesAsFutureForcedDependencies());const s=this.current,i=s.font;if(i.isType3Font){this.showType3Text(t,e),this.dependencyTracker?.recordShowTextOperation(t);return}const n=s.fontSize;if(n===0){this.dependencyTracker?.recordOperation(t);return}const r=this.ctx,a=s.fontSizeScale,o=s.charSpacing,l=s.wordSpacing,h=s.fontDirection,d=s.textHScale*h,u=e.length,f=i.vertical,g=f?1:-1,p=i.defaultVMetrics,b=n*s.fontMatrix[0],m=s.textRenderingMode===At.FILL&&!i.disableFontFace&&!s.patternFill;r.save(),s.textMatrix&&r.transform(...s.textMatrix),r.translate(s.x,s.y+s.textRise),h>0?r.scale(d,-1):r.scale(d,1);let y,A;if(s.patternFill){r.save();const E=s.fillColor.getPattern(r,this,Ut(r),wt.FILL,t);y=ot(r),r.restore(),r.fillStyle=E}if(s.patternStroke){r.save();const E=s.strokeColor.getPattern(r,this,Ut(r),wt.STROKE,t);A=ot(r),r.restore(),r.strokeStyle=E}let v=s.lineWidth;const w=s.textMatrixScale;if(w===0||v===0){const E=s.textRenderingMode&At.FILL_STROKE_MASK;(E===At.STROKE||E===At.FILL_STROKE)&&(v=this.getSinglePixelWidth())}else v/=w;if(a!==1&&(r.scale(a,a),v/=a),r.lineWidth=v,i.isInvalidPDFjsFont){const E=[];let C=0;for(const P of e)E.push(P.unicode),C+=P.width;const T=E.join("");if(r.fillText(T,0,0),this.dependencyTracker!==null){const P=r.measureText(T);this.dependencyTracker.recordBBox(t,this.ctx,-P.actualBoundingBoxLeft,P.actualBoundingBoxRight,-P.actualBoundingBoxAscent,P.actualBoundingBoxDescent).recordShowTextOperation(t)}s.x+=C*b*d,r.restore(),this.compose();return}let _=0,S;for(S=0;S<u;++S){const E=e[S];if(typeof E=="number"){_+=g*E*n/1e3;continue}let C=!1;const T=(E.isSpace?l:0)+o,P=E.fontChar,$=E.accent;let G,O,H=E.width;if(f){const z=E.vmetric||p,Z=-(E.vmetric?z[1]:H*.5)*b,yt=z[2]*b;H=z?-z[0]:H,G=Z/a,O=(_+yt)/a}else G=_/a,O=0;let M;if(i.remeasure&&H>0){M=r.measureText(P);const z=M.width*1e3/n*a;if(H<z&&this.isFontSubpixelAAEnabled){const Z=H/z;C=!0,r.save(),r.scale(Z,1),G/=Z}else H!==z&&(G+=(H-z)/2e3*n/a)}if(this.contentVisible&&(E.isInFont||i.missingFile)){if(m&&!$)r.fillText(P,G,O),this.dependencyTracker?.recordCharacterBBox(t,r,M?{bbox:null}:i,n/a,G,O,()=>M??r.measureText(P));else if(this.paintChar(t,P,G,O,y,A),$){const z=G+n*$.offset.x/a,Z=O-n*$.offset.y/a;this.paintChar(t,$.fontChar,z,Z,y,A)}}const F=f?H*b-T*h:H*b+T*h;_+=F,C&&r.restore()}f?s.y-=_:s.x+=_*d,r.restore(),this.compose(),this.dependencyTracker?.recordShowTextOperation(t)}showType3Text(t,e){const s=this.ctx,i=this.current,n=i.font,r=i.fontSize,a=i.fontDirection,o=n.vertical?1:-1,l=i.charSpacing,h=i.wordSpacing,d=i.textHScale*a,u=i.fontMatrix||Ts,f=e.length,g=i.textRenderingMode===At.INVISIBLE;let p,b,m,y;if(g||r===0)return;this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null,s.save(),i.textMatrix&&s.transform(...i.textMatrix),s.translate(i.x,i.y+i.textRise),s.scale(d,a);const A=this.dependencyTracker;for(this.dependencyTracker=A?new as(A,t):null,p=0;p<f;++p){if(b=e[p],typeof b=="number"){y=o*b*r/1e3,this.ctx.translate(y,0),i.x+=y*d;continue}const v=(b.isSpace?h:0)+l,w=n.charProcOperatorList[b.operatorListId];w?this.contentVisible&&(this.save(),s.scale(r,r),s.transform(...u),this.executeOperatorList(w),this.restore()):W(`Type3 character "${b.operatorListId}" is not available.`);const _=[b.width,0];I.applyTransform(_,u),m=_[0]*r+v,s.translate(m,0),i.x+=m*d}s.restore(),A&&(this.dependencyTracker=A)}setCharWidth(t,e,s){}setCharWidthAndBounds(t,e,s,i,n,r,a){const o=new Path2D;o.rect(i,n,r-i,a-n),this.ctx.clip(o),this.dependencyTracker?.recordBBox(t,this.ctx,i,r,n,a).recordClipBox(t,this.ctx,i,r,n,a),this.endPath(t)}getColorN_Pattern(t,e){let s;if(e[0]==="TilingPattern"){const i=this.baseTransform||ot(this.ctx),n={createCanvasGraphics:(r,a)=>new pe(r,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:this.optionalContentConfig,markedContentStack:this.markedContentStack},void 0,void 0,this.dependencyTracker?new as(this.dependencyTracker,a,!0):null)};s=new Ks(e,this.ctx,n,i)}else s=this._getPattern(t,e[1],e[2]);return s}setStrokeColorN(t,...e){this.dependencyTracker?.recordSimpleData("strokeColor",t),this.current.strokeColor=this.getColorN_Pattern(t,e),this.current.patternStroke=!0}setFillColorN(t,...e){this.dependencyTracker?.recordSimpleData("fillColor",t),this.current.fillColor=this.getColorN_Pattern(t,e),this.current.patternFill=!0}setStrokeRGBColor(t,e){this.dependencyTracker?.recordSimpleData("strokeColor",t),this.ctx.strokeStyle=this.current.strokeColor=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.ctx.fillStyle=this.current.fillColor=e,this.current.patternFill=!1}setFillTransparent(t){this.dependencyTracker?.recordSimpleData("fillColor",t),this.ctx.fillStyle=this.current.fillColor="transparent",this.current.patternFill=!1}_getPattern(t,e,s=null){let i;return this.cachedPatterns.has(e)?i=this.cachedPatterns.get(e):(i=Hr(this.getObject(t,e)),this.cachedPatterns.set(e,i)),s&&(i.matrix=s),i}shadingFill(t,e){if(!this.contentVisible)return;const s=this.ctx;this.save(t);const i=this._getPattern(t,e);s.fillStyle=i.getPattern(s,this,Ut(s),wt.SHADING,t);const n=Ut(s);if(n){const{width:r,height:a}=s.canvas,o=ue.slice();I.axialAlignedBoundingBox([0,0,r,a],n,o);const[l,h,d,u]=o;this.ctx.fillRect(l,h,d-l,u-h)}else this.ctx.fillRect(-1e10,-1e10,2e10,2e10);this.dependencyTracker?.resetBBox(t).recordFullPageBBox(t).recordDependencies(t,Nt.transform).recordDependencies(t,Nt.fill).recordOperation(t),this.compose(this.current.getClippedPathBoundingBox()),this.restore(t)}beginInlineImage(){nt("Should not call beginInlineImage")}beginImageData(){nt("Should not call beginImageData")}paintFormXObjectBegin(t,e,s){if(this.contentVisible&&(this.save(t),this.baseTransformStack.push(this.baseTransform),e&&this.transform(t,...e),this.baseTransform=ot(this.ctx),s)){I.axialAlignedBoundingBox(s,this.baseTransform,this.current.minMax);const[i,n,r,a]=s,o=new Path2D;o.rect(i,n,r-i,a-n),this.ctx.clip(o),this.dependencyTracker?.recordClipBox(t,this.ctx,i,r,n,a),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),this.inSMaskMode&&(this.endSMaskMode(),this.current.activeSMask=null);const s=this.ctx;e.isolated||ls("TODO: Support non-isolated groups."),e.knockout&&W("Knockout groups not supported.");const i=ot(s);if(e.matrix&&s.transform(...e.matrix),!e.bbox)throw new Error("Bounding box is required.");let n=ue.slice();I.axialAlignedBoundingBox(e.bbox,ot(s),n);const r=[0,0,s.canvas.width,s.canvas.height];n=I.intersect(n,r)||[0,0,0,0];const a=Math.floor(n[0]),o=Math.floor(n[1]),l=Math.max(Math.ceil(n[2])-a,1),h=Math.max(Math.ceil(n[3])-o,1);this.current.startNewPathAndClipBox([0,0,l,h]);let d="groupAt"+this.groupLevel;e.smask&&(d+="_smask_"+this.smaskCounter++%2);const u=this.cachedCanvases.getCanvas(d,l,h),f=u.context;f.translate(-a,-o),f.transform(...i);let g=new Path2D;const[p,b,m,y]=e.bbox;if(g.rect(p,b,m-p,y-b),e.matrix){const A=new Path2D;A.addPath(g,new DOMMatrix(e.matrix)),g=A}f.clip(g),e.smask&&this.smaskStack.push({canvas:u.canvas,context:f,offsetX:a,offsetY:o,subtype:e.smask.subtype,backdrop:e.smask.backdrop,transferMap:e.smask.transferMap||null,startTransformInverse:null}),(!e.smask||this.dependencyTracker)&&(s.setTransform(1,0,0,1,0,0),s.translate(a,o),s.save()),Se(s,f),this.ctx=f,this.dependencyTracker?.inheritSimpleDataAsFutureForcedDependencies(["fillAlpha","strokeAlpha","globalCompositeOperation"]).pushBaseTransform(s),this.setGState(t,[["BM","source-over"],["ca",1],["CA",1]]),this.groupStack.push(s),this.groupLevel++}endGroup(t,e){if(!this.contentVisible)return;this.groupLevel--;const s=this.ctx,i=this.groupStack.pop();if(this.ctx=i,this.ctx.imageSmoothingEnabled=!1,this.dependencyTracker?.popBaseTransform(),e.smask)this.tempSMask=this.smaskStack.pop(),this.restore(t),this.dependencyTracker&&this.ctx.restore();else{this.ctx.restore();const n=ot(this.ctx);this.restore(t),this.ctx.save(),this.ctx.setTransform(...n);const r=ue.slice();I.axialAlignedBoundingBox([0,0,s.canvas.width,s.canvas.height],n,r),this.ctx.drawImage(s.canvas,0,0),this.ctx.restore(),this.compose(r)}}beginAnnotation(t,e,s,i,n,r){if(this.#t(),ts(this.ctx),this.ctx.save(),this.save(t),this.baseTransform&&this.ctx.setTransform(...this.baseTransform),s){const a=s[2]-s[0],o=s[3]-s[1];if(r&&this.annotationCanvasMap){i=i.slice(),i[4]-=s[0],i[5]-=s[1],s=s.slice(),s[0]=s[1]=0,s[2]=a,s[3]=o,I.singularValueDecompose2dScale(ot(this.ctx),Lt);const{viewportScale:l}=this,h=Math.ceil(a*this.outputScaleX*l),d=Math.ceil(o*this.outputScaleY*l);this.annotationCanvas=this.canvasFactory.create(h,d);const{canvas:u,context:f}=this.annotationCanvas;this.annotationCanvasMap.set(e,u),this.annotationCanvas.savedCtx=this.ctx,this.ctx=f,this.ctx.save(),this.ctx.setTransform(Lt[0],0,0,-Lt[1],0,o*Lt[1]),ts(this.ctx)}else{ts(this.ctx),this.endPath(t);const l=new Path2D;l.rect(s[0],s[1],a,o),this.ctx.clip(l)}}this.current=new Ci(this.ctx.canvas.width,this.ctx.canvas.height),this.transform(t,...i),this.transform(t,...n)}endAnnotation(t){this.annotationCanvas&&(this.ctx.restore(),this.#e(),this.ctx=this.annotationCanvas.savedCtx,delete this.annotationCanvas.savedCtx,delete this.annotationCanvas)}paintImageMaskXObject(t,e){if(!this.contentVisible)return;const s=e.count;e=this.getObject(t,e.data,e),e.count=s;const i=this.ctx,n=this._createMaskCanvas(t,e),r=n.canvas;i.save(),i.setTransform(1,0,0,1,0,0),i.drawImage(r,n.offsetX,n.offsetY),this.dependencyTracker?.resetBBox(t).recordBBox(t,this.ctx,n.offsetX,n.offsetX+r.width,n.offsetY,n.offsetY+r.height).recordOperation(t),i.restore(),this.compose()}paintImageMaskXObjectRepeat(t,e,s,i=0,n=0,r,a){if(!this.contentVisible)return;e=this.getObject(t,e.data,e);const o=this.ctx;o.save();const l=ot(o);o.transform(s,i,n,r,0,0);const h=this._createMaskCanvas(t,e);o.setTransform(1,0,0,1,h.offsetX-l[4],h.offsetY-l[5]),this.dependencyTracker?.resetBBox(t);for(let d=0,u=a.length;d<u;d+=2){const f=I.transform(l,[s,i,n,r,a[d],a[d+1]]);o.drawImage(h.canvas,f[4],f[5]),this.dependencyTracker?.recordBBox(t,this.ctx,f[4],f[4]+h.canvas.width,f[5],f[5]+h.canvas.height)}o.restore(),this.compose(),this.dependencyTracker?.recordOperation(t)}paintImageMaskXObjectGroup(t,e){if(!this.contentVisible)return;const s=this.ctx,i=this.current.fillColor,n=this.current.patternFill;this.dependencyTracker?.resetBBox(t).recordDependencies(t,Nt.transformAndFill);for(const r of e){const{data:a,width:o,height:l,transform:h}=r,d=this.cachedCanvases.getCanvas("maskCanvas",o,l),u=d.context;u.save();const f=this.getObject(t,a,r);Ti(u,f),u.globalCompositeOperation="source-in",u.fillStyle=n?i.getPattern(u,this,Ut(s),wt.FILL,t):i,u.fillRect(0,0,o,l),u.restore(),s.save(),s.transform(...h),s.scale(1,-1),Ze(s,d.canvas,0,0,o,l,0,-1,1,1),this.dependencyTracker?.recordBBox(t,s,0,o,0,l),s.restore()}this.compose(),this.dependencyTracker?.recordOperation(t)}paintImageXObject(t,e){if(!this.contentVisible)return;const s=this.getObject(t,e);if(!s){W("Dependent image isn't ready yet");return}this.paintInlineImageXObject(t,s)}paintImageXObjectRepeat(t,e,s,i,n){if(!this.contentVisible)return;const r=this.getObject(t,e);if(!r){W("Dependent image isn't ready yet");return}const a=r.width,o=r.height,l=[];for(let h=0,d=n.length;h<d;h+=2)l.push({transform:[s,0,0,i,n[h],n[h+1]],x:0,y:0,w:a,h:o});this.paintInlineImageXObjectGroup(t,r,l)}applyTransferMapsToCanvas(t){return this.current.transferMaps!=="none"&&(t.filter=this.current.transferMaps,t.drawImage(t.canvas,0,0),t.filter="none"),t.canvas}applyTransferMapsToBitmap(t){if(this.current.transferMaps==="none")return t.bitmap;const{bitmap:e,width:s,height:i}=t,n=this.cachedCanvases.getCanvas("inlineImage",s,i),r=n.context;return r.filter=this.current.transferMaps,r.drawImage(e,0,0),r.filter="none",n.canvas}paintInlineImageXObject(t,e){if(!this.contentVisible)return;const s=e.width,i=e.height,n=this.ctx;this.save(t);const{filter:r}=n;r!=="none"&&r!==""&&(n.filter="none"),n.scale(1/s,-1/i);let a;if(e.bitmap)a=this.applyTransferMapsToBitmap(e);else if(typeof HTMLElement=="function"&&e instanceof HTMLElement||!e.data)a=e;else{const h=this.cachedCanvases.getCanvas("inlineImage",s,i).context;xi(h,e),a=this.applyTransferMapsToCanvas(h)}const o=this._scaleImage(a,Ut(n));n.imageSmoothingEnabled=Pi(ot(n),e.interpolate),this.dependencyTracker?.resetBBox(t).recordBBox(t,n,0,s,-i,0).recordDependencies(t,Nt.imageXObject).recordOperation(t),Ze(n,o.img,0,0,o.paintWidth,o.paintHeight,0,-i,s,i),this.compose(),this.restore(t)}paintInlineImageXObjectGroup(t,e,s){if(!this.contentVisible)return;const i=this.ctx;let n;if(e.bitmap)n=e.bitmap;else{const r=e.width,a=e.height,l=this.cachedCanvases.getCanvas("inlineImage",r,a).context;xi(l,e),n=this.applyTransferMapsToCanvas(l)}this.dependencyTracker?.resetBBox(t);for(const r of s)i.save(),i.transform(...r.transform),i.scale(1,-1),Ze(i,n,r.x,r.y,r.w,r.h,0,-1,1,1),this.dependencyTracker?.recordBBox(t,i,0,1,-1,0),i.restore();this.dependencyTracker?.recordOperation(t),this.compose()}paintSolidColorImageMask(t){this.contentVisible&&(this.dependencyTracker?.resetBBox(t).recordBBox(t,this.ctx,0,1,0,1).recordDependencies(t,Nt.fill).recordOperation(t),this.ctx.fillRect(0,0,1,1),this.compose())}markPoint(t,e){}markPointProps(t,e,s){}beginMarkedContent(t,e){this.dependencyTracker?.beginMarkedContent(t),this.markedContentStack.push({visible:!0})}beginMarkedContentProps(t,e,s){this.dependencyTracker?.beginMarkedContent(t),e==="OC"?this.markedContentStack.push({visible:this.optionalContentConfig.isVisible(s)}):this.markedContentStack.push({visible:!0}),this.contentVisible=this.isContentVisible()}endMarkedContent(t){this.dependencyTracker?.endMarkedContent(t),this.markedContentStack.pop(),this.contentVisible=this.isContentVisible()}beginCompat(t){}endCompat(t){}consumePath(t,e,s){const i=this.current.isEmptyClip();this.pendingClip&&this.current.updateClipFromPath(),this.pendingClip||this.compose(s);const n=this.ctx;this.pendingClip?(i||(this.pendingClip===ki?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(){if(!this._cachedGetSinglePixelWidth){const t=ot(this.ctx);if(t[1]===0&&t[2]===0)this._cachedGetSinglePixelWidth=1/Math.min(Math.abs(t[0]),Math.abs(t[3]));else{const e=Math.abs(t[0]*t[3]-t[2]*t[1]),s=Math.hypot(t[0],t[2]),i=Math.hypot(t[1],t[3]);this._cachedGetSinglePixelWidth=Math.max(s,i)/e}}return this._cachedGetSinglePixelWidth}getScaleForStroking(){if(this._cachedScaleForStroking[0]===-1){const{lineWidth:t}=this.current,{a:e,b:s,c:i,d:n}=this.ctx.getTransform();let r,a;if(s===0&&i===0){const o=Math.abs(e),l=Math.abs(n);if(o===l)if(t===0)r=a=1/o;else{const h=o*t;r=a=h<1?1/h:1}else if(t===0)r=1/o,a=1/l;else{const h=o*t,d=l*t;r=h<1?1/h:1,a=d<1?1/d:1}}else{const o=Math.abs(e*n-s*i),l=Math.hypot(e,s),h=Math.hypot(i,n);if(t===0)r=h/o,a=l/o;else{const d=t*o;r=h>d?h/d:1,a=l>d?l/d:1}}this._cachedScaleForStroking[0]=r,this._cachedScaleForStroking[1]=a}return this._cachedScaleForStroking}rescaleAndStroke(t,e){const{ctx:s,current:{lineWidth:i}}=this,[n,r]=this.getScaleForStroking();if(n===r){s.lineWidth=(i||1)*n,s.stroke(t);return}const a=s.getLineDash();e&&s.save(),s.scale(n,r),Es.a=1/n,Es.d=1/r;const o=new Path2D;if(o.addPath(t,Es),a.length>0){const l=Math.max(n,r);s.setLineDash(a.map(h=>h/l)),s.lineDashOffset/=l}s.lineWidth=i||1,s.stroke(o),e&&s.restore()}isContentVisible(){for(let t=this.markedContentStack.length-1;t>=0;t--)if(!this.markedContentStack[t].visible)return!1;return!0}}for(const c in Ae)pe.prototype[c]!==void 0&&(pe.prototype[Ae[c]]=pe.prototype[c]);class ge{#t;#e;#i;static strings=["fontFamily","fontWeight","italicAngle"];static write(t){const e=new TextEncoder,s={};let i=0;for(const l of ge.strings){const h=e.encode(t[l]);s[l]=h,i+=4+h.length}const n=new ArrayBuffer(i),r=new Uint8Array(n),a=new DataView(n);let o=0;for(const l of ge.strings){const h=s[l],d=h.length;a.setUint32(o,d),r.set(h,o+4),o+=4+d}return J(o===n.byteLength,"CssFontInfo.write: Buffer overflow"),n}constructor(t){this.#t=t,this.#e=new DataView(this.#t),this.#i=new TextDecoder}#s(t){J(t<ge.strings.length,"Invalid string index");let e=0;for(let i=0;i<t;i++)e+=this.#e.getUint32(e)+4;const s=this.#e.getUint32(e);return this.#i.decode(new Uint8Array(this.#t,e+4,s))}get fontFamily(){return this.#s(0)}get fontWeight(){return this.#s(1)}get italicAngle(){return this.#s(2)}}class me{#t;#e;#i;static strings=["css","loadedName","baseFontName","src"];static write(t){const e=new TextEncoder,s={};let i=0;for(const u of me.strings){const f=e.encode(t[u]);s[u]=f,i+=4+f.length}i+=4;let n,r,a=1+i;t.style&&(n=e.encode(t.style.style),r=e.encode(t.style.weight),a+=4+n.length+4+r.length);const o=new ArrayBuffer(a),l=new Uint8Array(o),h=new DataView(o);let d=0;h.setUint8(d++,t.guessFallback?1:0),h.setUint32(d,0),d+=4,i=0;for(const u of me.strings){const f=s[u],g=f.length;i+=4+g,h.setUint32(d,g),l.set(f,d+4),d+=4+g}return h.setUint32(d-i-4,i),t.style&&(h.setUint32(d,n.length),l.set(n,d+4),d+=4+n.length,h.setUint32(d,r.length),l.set(r,d+4),d+=4+r.length),J(d<=o.byteLength,"SubstitionInfo.write: Buffer overflow"),o.transferToFixedLength(d)}constructor(t){this.#t=t,this.#e=new DataView(this.#t),this.#i=new TextDecoder}get guessFallback(){return this.#e.getUint8(0)!==0}#s(t){J(t<me.strings.length,"Invalid string index");let e=5;for(let i=0;i<t;i++)e+=this.#e.getUint32(e)+4;const s=this.#e.getUint32(e);return this.#i.decode(new Uint8Array(this.#t,e+4,s))}get css(){return this.#s(0)}get loadedName(){return this.#s(1)}get baseFontName(){return this.#s(2)}get src(){return this.#s(3)}get style(){let t=1;t+=4+this.#e.getUint32(t);const e=this.#e.getUint32(t),s=this.#i.decode(new Uint8Array(this.#t,t+4,e));t+=4+e;const i=this.#e.getUint32(t),n=this.#i.decode(new Uint8Array(this.#t,t+4,i));return{style:s,weight:n}}}class st{static bools=["black","bold","disableFontFace","fontExtraProperties","isInvalidPDFjsFont","isType3Font","italic","missingFile","remeasure","vertical"];static numbers=["ascent","defaultWidth","descent"];static strings=["fallbackName","loadedName","mimetype","name"];static#t=Math.ceil(this.bools.length*2/8);static#e=this.#t+this.numbers.length*8;static#i=this.#e+1+2*4;static#s=this.#i+1+8*6;static#a=this.#s+1+2*3;#n;#r;#o;constructor({data:t,extra:e}){this.#n=t,this.#r=new TextDecoder,this.#o=new DataView(this.#n),e&&Object.assign(this,e)}#h(t){J(t<st.bools.length,"Invalid boolean index");const e=Math.floor(t/4),s=t*2%8,i=this.#o.getUint8(e)>>s&3;return i===0?void 0:i===2}get black(){return this.#h(0)}get bold(){return this.#h(1)}get disableFontFace(){return this.#h(2)}get fontExtraProperties(){return this.#h(3)}get isInvalidPDFjsFont(){return this.#h(4)}get isType3Font(){return this.#h(5)}get italic(){return this.#h(6)}get missingFile(){return this.#h(7)}get remeasure(){return this.#h(8)}get vertical(){return this.#h(9)}#l(t){return J(t<st.numbers.length,"Invalid number index"),this.#o.getFloat64(st.#t+t*8)}get ascent(){return this.#l(0)}get defaultWidth(){return this.#l(1)}get descent(){return this.#l(2)}get bbox(){let t=st.#e;if(this.#o.getUint8(t)===0)return;t+=1;const s=[];for(let i=0;i<4;i++)s.push(this.#o.getInt16(t,!0)),t+=2;return s}get fontMatrix(){let t=st.#i;if(this.#o.getUint8(t)===0)return;t+=1;const s=[];for(let i=0;i<6;i++)s.push(this.#o.getFloat64(t,!0)),t+=8;return s}get defaultVMetrics(){let t=st.#s;if(this.#o.getUint8(t)===0)return;t+=1;const s=[];for(let i=0;i<3;i++)s.push(this.#o.getInt16(t,!0)),t+=2;return s}#u(t){J(t<st.strings.length,"Invalid string index");let e=st.#a+4;for(let n=0;n<t;n++)e+=this.#o.getUint32(e)+4;const s=this.#o.getUint32(e),i=new Uint8Array(s);return i.set(new Uint8Array(this.#n,e+4,s)),this.#r.decode(i)}get fallbackName(){return this.#u(0)}get loadedName(){return this.#u(1)}get mimetype(){return this.#u(2)}get name(){return this.#u(3)}get data(){let t=st.#a;const e=this.#o.getUint32(t);t+=4+e;const s=this.#o.getUint32(t);t+=4+s;const i=this.#o.getUint32(t);t+=4+i;const n=this.#o.getUint32(t);if(n!==0)return new Uint8Array(this.#n,t+4,n)}clearData(){let t=st.#a;const e=this.#o.getUint32(t);t+=4+e;const s=this.#o.getUint32(t);t+=4+s;const i=this.#o.getUint32(t);t+=4+i;const n=this.#o.getUint32(t);new Uint8Array(this.#n,t+4,n).fill(0),this.#o.setUint32(t,0)}get cssFontInfo(){let t=st.#a;const e=this.#o.getUint32(t);t+=4+e;const s=this.#o.getUint32(t);t+=4+s;const i=this.#o.getUint32(t);if(i===0)return null;const n=new Uint8Array(i);return n.set(new Uint8Array(this.#n,t+4,i)),new ge(n.buffer)}get systemFontInfo(){let t=st.#a;const e=this.#o.getUint32(t);t+=4+e;const s=this.#o.getUint32(t);if(s===0)return null;const i=new Uint8Array(s);return i.set(new Uint8Array(this.#n,t+4,s)),new me(i.buffer)}static write(t){const e=t.systemFontInfo?me.write(t.systemFontInfo):null,s=t.cssFontInfo?ge.write(t.cssFontInfo):null,i=new TextEncoder,n={};let r=0;for(const p of st.strings)n[p]=i.encode(t[p]),r+=4+n[p].length;const a=st.#a+4+r+4+(e?e.byteLength:0)+4+(s?s.byteLength:0)+4+(t.data?t.data.length:0),o=new ArrayBuffer(a),l=new Uint8Array(o),h=new DataView(o);let d=0;const u=st.bools.length;let f=0,g=0;for(let p=0;p<u;p++){const b=t[st.bools[p]];f|=(b===void 0?0:b?2:1)<<g,g+=2,(g===8||p===u-1)&&(h.setUint8(d++,f),f=0,g=0)}J(d===st.#t,"FontInfo.write: Boolean properties offset mismatch");for(const p of st.numbers)h.setFloat64(d,t[p]),d+=8;if(J(d===st.#e,"FontInfo.write: Number properties offset mismatch"),t.bbox){h.setUint8(d++,4);for(const p of t.bbox)h.setInt16(d,p,!0),d+=2}else h.setUint8(d++,0),d+=2*4;if(J(d===st.#i,"FontInfo.write: BBox properties offset mismatch"),t.fontMatrix){h.setUint8(d++,6);for(const p of t.fontMatrix)h.setFloat64(d,p,!0),d+=8}else h.setUint8(d++,0),d+=8*6;if(J(d===st.#s,"FontInfo.write: FontMatrix properties offset mismatch"),t.defaultVMetrics){h.setUint8(d++,1);for(const p of t.defaultVMetrics)h.setInt16(d,p,!0),d+=2}else h.setUint8(d++,0),d+=3*2;J(d===st.#a,"FontInfo.write: DefaultVMetrics properties offset mismatch"),h.setUint32(st.#a,0),d+=4;for(const p of st.strings){const b=n[p],m=b.length;h.setUint32(d,m),l.set(b,d+4),d+=4+m}if(h.setUint32(st.#a,d-st.#a-4),!e)h.setUint32(d,0),d+=4;else{const p=e.byteLength;h.setUint32(d,p),J(d+4+p<=o.byteLength,"FontInfo.write: Buffer overflow at systemFontInfo"),l.set(new Uint8Array(e),d+4),d+=4+p}if(!s)h.setUint32(d,0),d+=4;else{const p=s.byteLength;h.setUint32(d,p),J(d+4+p<=o.byteLength,"FontInfo.write: Buffer overflow at cssFontInfo"),l.set(new Uint8Array(s),d+4),d+=4+p}return t.data===void 0?(h.setUint32(d,0),d+=4):(h.setUint32(d,t.data.length),l.set(t.data,d+4),d+=4+t.data.length),J(d<=o.byteLength,"FontInfo.write: Buffer overflow"),o.transferToFixedLength(d)}}class Jt{static#t=null;static#e="";static get workerPort(){return this.#t}static set workerPort(t){if(!(typeof Worker<"u"&&t instanceof Worker)&&t!==null)throw new Error("Invalid `workerPort` type.");this.#t=t}static get workerSrc(){return this.#e}static set workerSrc(t){if(typeof t!="string")throw new Error("Invalid `workerSrc` type.");this.#e=t}}class Xr{#t;#e;constructor({parsedData:t,rawData:e}){this.#t=t,this.#e=e}getRaw(){return this.#e}get(t){return this.#t.get(t)??null}[Symbol.iterator](){return this.#t.entries()}}const de=Symbol("INTERNAL");class qr{#t=!1;#e=!1;#i=!1;#s=!0;constructor(t,{name:e,intent:s,usage:i,rbGroups:n}){this.#t=!!(t&Rt.DISPLAY),this.#e=!!(t&Rt.PRINT),this.name=e,this.intent=s,this.usage=i,this.rbGroups=n}get visible(){if(this.#i)return this.#s;if(!this.#s)return!1;const{print:t,view:e}=this.usage;return this.#t?e?.viewState!=="OFF":this.#e?t?.printState!=="OFF":!0}_setVisible(t,e,s=!1){t!==de&&nt("Internal method `_setVisible` called."),this.#i=s,this.#s=e}}class Yr{#t=null;#e=new Map;#i=null;#s=null;constructor(t,e=Rt.DISPLAY){if(this.renderingIntent=e,this.name=null,this.creator=null,t!==null){this.name=t.name,this.creator=t.creator,this.#s=t.order;for(const s of t.groups)this.#e.set(s.id,new qr(e,s));if(t.baseState==="OFF")for(const s of this.#e.values())s._setVisible(de,!1);for(const s of t.on)this.#e.get(s)._setVisible(de,!0);for(const s of t.off)this.#e.get(s)._setVisible(de,!1);this.#i=this.getHash()}}#a(t){const e=t.length;if(e<2)return!0;const s=t[0];for(let i=1;i<e;i++){const n=t[i];let r;if(Array.isArray(n))r=this.#a(n);else if(this.#e.has(n))r=this.#e.get(n).visible;else return W(`Optional content group not found: ${n}`),!0;switch(s){case"And":if(!r)return!1;break;case"Or":if(r)return!0;break;case"Not":return!r;default:return!0}}return s==="And"}isVisible(t){if(this.#e.size===0)return!0;if(!t)return ls("Optional content group not defined."),!0;if(t.type==="OCG")return this.#e.has(t.id)?this.#e.get(t.id).visible:(W(`Optional content group not found: ${t.id}`),!0);if(t.type==="OCMD"){if(t.expression)return this.#a(t.expression);if(!t.policy||t.policy==="AnyOn"){for(const e of t.ids){if(!this.#e.has(e))return W(`Optional content group not found: ${e}`),!0;if(this.#e.get(e).visible)return!0}return!1}else if(t.policy==="AllOn"){for(const e of t.ids){if(!this.#e.has(e))return W(`Optional content group not found: ${e}`),!0;if(!this.#e.get(e).visible)return!1}return!0}else if(t.policy==="AnyOff"){for(const e of t.ids){if(!this.#e.has(e))return W(`Optional content group not found: ${e}`),!0;if(!this.#e.get(e).visible)return!0}return!1}else if(t.policy==="AllOff"){for(const e of t.ids){if(!this.#e.has(e))return W(`Optional content group not found: ${e}`),!0;if(this.#e.get(e).visible)return!1}return!0}return W(`Unknown optional content policy ${t.policy}.`),!0}return W(`Unknown group type ${t.type}.`),!0}setVisibility(t,e=!0,s=!0){const i=this.#e.get(t);if(!i){W(`Optional content group not found: ${t}`);return}if(s&&e&&i.rbGroups.length)for(const n of i.rbGroups)for(const r of n)r!==t&&this.#e.get(r)?._setVisible(de,!1,!0);i._setVisible(de,!!e,!0),this.#t=null}setOCGState({state:t,preserveRB:e}){let s;for(const i of t){switch(i){case"ON":case"OFF":case"Toggle":s=i;continue}const n=this.#e.get(i);if(n)switch(s){case"ON":this.setVisibility(i,!0,e);break;case"OFF":this.setVisibility(i,!1,e);break;case"Toggle":this.setVisibility(i,!n.visible,e);break}}this.#t=null}get hasInitialVisibility(){return this.#i===null||this.getHash()===this.#i}getOrder(){return this.#e.size?this.#s?this.#s.slice():[...this.#e.keys()]:null}getGroup(t){return this.#e.get(t)||null}getHash(){if(this.#t!==null)return this.#t;const t=new tn;for(const[e,s]of this.#e)t.update(`${e}:${s.visible}`);return this.#t=t.hexdigest()}[Symbol.iterator](){return this.#e.entries()}}class Kr{constructor(t,{disableRange:e=!1,disableStream:s=!1}){J(t,'PDFDataTransportStream - missing required "pdfDataRangeTransport" argument.');const{length:i,initialData:n,progressiveDone:r,contentDispositionFilename:a}=t;if(this._queuedChunks=[],this._progressiveDone=r,this._contentDispositionFilename=a,n?.length>0){const o=n instanceof Uint8Array&&n.byteLength===n.buffer.byteLength?n.buffer:new Uint8Array(n).buffer;this._queuedChunks.push(o)}this._pdfDataRangeTransport=t,this._isStreamingSupported=!s,this._isRangeSupported=!e,this._contentLength=i,this._fullRequestReader=null,this._rangeReaders=[],t.addRangeListener((o,l)=>{this._onReceiveData({begin:o,chunk:l})}),t.addProgressListener((o,l)=>{this._onProgress({loaded:o,total:l})}),t.addProgressiveReadListener(o=>{this._onReceiveData({chunk:o})}),t.addProgressiveDoneListener(()=>{this._onProgressiveDone()}),t.transportReady()}_onReceiveData({begin:t,chunk:e}){const s=e instanceof Uint8Array&&e.byteLength===e.buffer.byteLength?e.buffer:new Uint8Array(e).buffer;if(t===void 0)this._fullRequestReader?this._fullRequestReader._enqueue(s):this._queuedChunks.push(s);else{const i=this._rangeReaders.some(function(n){return n._begin!==t?!1:(n._enqueue(s),!0)});J(i,"_onReceiveData - no `PDFDataTransportStreamRangeReader` instance found.")}}get _progressiveDataLength(){return this._fullRequestReader?._loaded??0}_onProgress(t){t.total===void 0?this._rangeReaders[0]?.onProgress?.({loaded:t.loaded}):this._fullRequestReader?.onProgress?.({loaded:t.loaded,total:t.total})}_onProgressiveDone(){this._fullRequestReader?.progressiveDone(),this._progressiveDone=!0}_removeRangeReader(t){const e=this._rangeReaders.indexOf(t);e>=0&&this._rangeReaders.splice(e,1)}getFullReader(){J(!this._fullRequestReader,"PDFDataTransportStream.getFullReader can only be called once.");const t=this._queuedChunks;return this._queuedChunks=null,new Qr(this,t,this._progressiveDone,this._contentDispositionFilename)}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new Jr(this,t,e);return this._pdfDataRangeTransport.requestDataRange(t,e),this._rangeReaders.push(s),s}cancelAllRequests(t){this._fullRequestReader?.cancel(t);for(const e of this._rangeReaders.slice(0))e.cancel(t);this._pdfDataRangeTransport.abort()}}class Qr{constructor(t,e,s=!1,i=null){this._stream=t,this._done=s||!1,this._filename=cs(i)?i:null,this._queuedChunks=e||[],this._loaded=0;for(const n of this._queuedChunks)this._loaded+=n.byteLength;this._requests=[],this._headersReady=Promise.resolve(),t._fullRequestReader=this,this.onProgress=null}_enqueue(t){this._done||(this._requests.length>0?this._requests.shift().resolve({value:t,done:!1}):this._queuedChunks.push(t),this._loaded+=t.byteLength)}get headersReady(){return this._headersReady}get filename(){return this._filename}get isRangeSupported(){return this._stream._isRangeSupported}get isStreamingSupported(){return this._stream._isStreamingSupported}get contentLength(){return this._stream._contentLength}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;for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0}progressiveDone(){this._done||(this._done=!0)}}class Jr{constructor(t,e,s){this._stream=t,this._begin=e,this._end=s,this._queuedChunk=null,this._requests=[],this._done=!1,this.onProgress=null}_enqueue(t){if(!this._done){if(this._requests.length===0)this._queuedChunk=t;else{this._requests.shift().resolve({value:t,done:!1});for(const s of this._requests)s.resolve({value:void 0,done:!0});this._requests.length=0}this._done=!0,this._stream._removeRangeReader(this)}}get isStreamingSupported(){return!1}async read(){if(this._queuedChunk){const e=this._queuedChunk;return this._queuedChunk=null,{value:e,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;for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0,this._stream._removeRangeReader(this)}}function Zr(c){let t=!0,e=s("filename\\*","i").exec(c);if(e){e=e[1];let h=a(e);return h=unescape(h),h=o(h),h=l(h),n(h)}if(e=r(c),e){const h=l(e);return n(h)}if(e=s("filename","i").exec(c),e){e=e[1];let h=a(e);return h=l(h),n(h)}function s(h,d){return new RegExp("(?:^|;)\\s*"+h+'\\s*=\\s*([^";\\s][^;\\s]*|"(?:[^"\\\\]|\\\\"?)+"?)',d)}function i(h,d){if(h){if(!/^[\x00-\xFF]+$/.test(d))return d;try{const u=new TextDecoder(h,{fatal:!0}),f=Be(d);d=u.decode(f),t=!1}catch{}}return d}function n(h){return t&&/[\x80-\xff]/.test(h)&&(h=i("utf-8",h),t&&(h=i("iso-8859-1",h))),h}function r(h){const d=[];let u;const f=s("filename\\*((?!0\\d)\\d+)(\\*?)","ig");for(;(u=f.exec(h))!==null;){let[,p,b,m]=u;if(p=parseInt(p,10),p in d){if(p===0)break;continue}d[p]=[b,m]}const g=[];for(let p=0;p<d.length&&p in d;++p){let[b,m]=d[p];m=a(m),b&&(m=unescape(m),p===0&&(m=o(m))),g.push(m)}return g.join("")}function a(h){if(h.startsWith('"')){const d=h.slice(1).split('\\"');for(let u=0;u<d.length;++u){const f=d[u].indexOf('"');f!==-1&&(d[u]=d[u].slice(0,f),d.length=u+1),d[u]=d[u].replaceAll(/\\(.)/g,"$1")}h=d.join('"')}return h}function o(h){const d=h.indexOf("'");if(d===-1)return h;const u=h.slice(0,d),g=h.slice(d+1).replace(/^[^']*'/,"");return i(u,g)}function l(h){return!h.startsWith("=?")||/[\x00-\x19\x80-\xff]/.test(h)?h:h.replaceAll(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g,function(d,u,f,g){if(f==="q"||f==="Q")return g=g.replaceAll("_"," "),g=g.replaceAll(/=([0-9a-fA-F]{2})/g,function(p,b){return String.fromCharCode(parseInt(b,16))}),i(u,g);try{g=atob(g)}catch{}return i(u,g)})}return""}function hn(c,t){const e=new Headers;if(!c||!t||typeof t!="object")return e;for(const s in t){const i=t[s];i!==void 0&&e.append(s,i)}return e}function ds(c){return URL.parse(c)?.origin??null}function cn({responseHeaders:c,isHttp:t,rangeChunkSize:e,disableRange:s}){const i={allowRangeRequests:!1,suggestedLength:void 0},n=parseInt(c.get("Content-Length"),10);return!Number.isInteger(n)||(i.suggestedLength=n,n<=2*e)||s||!t||c.get("Accept-Ranges")!=="bytes"||(c.get("Content-Encoding")||"identity")!=="identity"||(i.allowRangeRequests=!0),i}function dn(c){const t=c.get("Content-Disposition");if(t){let e=Zr(t);if(e.includes("%"))try{e=decodeURIComponent(e)}catch{}if(cs(e))return e}return null}function Ge(c,t){return new Le(`Unexpected server response (${c}) while retrieving PDF "${t}".`,c,c===404||c===0&&t.startsWith("file:"))}function un(c){return c===200||c===206}function fn(c,t,e){return{method:"GET",headers:c,signal:e.signal,mode:"cors",credentials:t?"include":"same-origin",redirect:"follow"}}function pn(c){return c instanceof Uint8Array?c.buffer:c instanceof ArrayBuffer?c:(W(`getArrayBuffer - unexpected data format: ${c}`),new Uint8Array(c).buffer)}class ta{_responseOrigin=null;constructor(t){this.source=t,this.isHttp=/^https?:/i.test(t.url),this.headers=hn(this.isHttp,t.httpHeaders),this._fullRequestReader=null,this._rangeRequestReaders=[]}get _progressiveDataLength(){return this._fullRequestReader?._loaded??0}getFullReader(){return J(!this._fullRequestReader,"PDFFetchStream.getFullReader can only be called once."),this._fullRequestReader=new ea(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new sa(this,t,e);return this._rangeRequestReaders.push(s),s}cancelAllRequests(t){this._fullRequestReader?.cancel(t);for(const e of this._rangeRequestReaders.slice(0))e.cancel(t)}}class ea{constructor(t){this._stream=t,this._reader=null,this._loaded=0,this._filename=null;const e=t.source;this._withCredentials=e.withCredentials||!1,this._contentLength=e.length,this._headersCapability=Promise.withResolvers(),this._disableRange=e.disableRange||!1,this._rangeChunkSize=e.rangeChunkSize,!this._rangeChunkSize&&!this._disableRange&&(this._disableRange=!0),this._abortController=new AbortController,this._isStreamingSupported=!e.disableStream,this._isRangeSupported=!e.disableRange;const s=new Headers(t.headers),i=e.url;fetch(i,fn(s,this._withCredentials,this._abortController)).then(n=>{if(t._responseOrigin=ds(n.url),!un(n.status))throw Ge(n.status,i);this._reader=n.body.getReader(),this._headersCapability.resolve();const r=n.headers,{allowRangeRequests:a,suggestedLength:o}=cn({responseHeaders:r,isHttp:t.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});this._isRangeSupported=a,this._contentLength=o||this._contentLength,this._filename=dn(r),!this._isStreamingSupported&&this._isRangeSupported&&this.cancel(new qt("Streaming is disabled."))}).catch(this._headersCapability.reject),this.onProgress=null}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(){await this._headersCapability.promise;const{value:t,done:e}=await this._reader.read();return e?{value:t,done:e}:(this._loaded+=t.byteLength,this.onProgress?.({loaded:this._loaded,total:this._contentLength}),{value:pn(t),done:!1})}cancel(t){this._reader?.cancel(t),this._abortController.abort()}}class sa{constructor(t,e,s){this._stream=t,this._reader=null,this._loaded=0;const i=t.source;this._withCredentials=i.withCredentials||!1,this._readCapability=Promise.withResolvers(),this._isStreamingSupported=!i.disableStream,this._abortController=new AbortController;const n=new Headers(t.headers);n.append("Range",`bytes=${e}-${s-1}`);const r=i.url;fetch(r,fn(n,this._withCredentials,this._abortController)).then(a=>{const o=ds(a.url);if(o!==t._responseOrigin)throw new Error(`Expected range response-origin "${o}" to match "${t._responseOrigin}".`);if(!un(a.status))throw Ge(a.status,r);this._readCapability.resolve(),this._reader=a.body.getReader()}).catch(this._readCapability.reject),this.onProgress=null}get isStreamingSupported(){return this._isStreamingSupported}async read(){await this._readCapability.promise;const{value:t,done:e}=await this._reader.read();return e?{value:t,done:e}:(this._loaded+=t.byteLength,this.onProgress?.({loaded:this._loaded}),{value:pn(t),done:!1})}cancel(t){this._reader?.cancel(t),this._abortController.abort()}}const Cs=200,xs=206;function ia(c){const t=c.response;return typeof t!="string"?t:Be(t).buffer}class na{_responseOrigin=null;constructor({url:t,httpHeaders:e,withCredentials:s}){this.url=t,this.isHttp=/^https?:/i.test(t),this.headers=hn(this.isHttp,e),this.withCredentials=s||!1,this.currXhrId=0,this.pendingRequests=Object.create(null)}request(t){const e=new XMLHttpRequest,s=this.currXhrId++,i=this.pendingRequests[s]={xhr:e};e.open("GET",this.url),e.withCredentials=this.withCredentials;for(const[n,r]of this.headers)e.setRequestHeader(n,r);return this.isHttp&&"begin"in t&&"end"in t?(e.setRequestHeader("Range",`bytes=${t.begin}-${t.end-1}`),i.expectedStatus=xs):i.expectedStatus=Cs,e.responseType="arraybuffer",J(t.onError,"Expected `onError` callback to be provided."),e.onerror=()=>{t.onError(e.status)},e.onreadystatechange=this.onStateChange.bind(this,s),e.onprogress=this.onProgress.bind(this,s),i.onHeadersReceived=t.onHeadersReceived,i.onDone=t.onDone,i.onError=t.onError,i.onProgress=t.onProgress,e.send(null),s}onProgress(t,e){const s=this.pendingRequests[t];s&&s.onProgress?.(e)}onStateChange(t,e){const s=this.pendingRequests[t];if(!s)return;const i=s.xhr;if(i.readyState>=2&&s.onHeadersReceived&&(s.onHeadersReceived(),delete s.onHeadersReceived),i.readyState!==4||!(t in this.pendingRequests))return;if(delete this.pendingRequests[t],i.status===0&&this.isHttp){s.onError(i.status);return}const n=i.status||Cs;if(!(n===Cs&&s.expectedStatus===xs)&&n!==s.expectedStatus){s.onError(i.status);return}const a=ia(i);if(n===xs){const o=i.getResponseHeader("Content-Range"),l=/bytes (\d+)-(\d+)\/(\d+)/.exec(o);l?s.onDone({begin:parseInt(l[1],10),chunk:a}):(W('Missing or invalid "Content-Range" header.'),s.onError(0))}else a?s.onDone({begin:0,chunk:a}):s.onError(i.status)}getRequestXhr(t){return this.pendingRequests[t].xhr}isPendingRequest(t){return t in this.pendingRequests}abortRequest(t){const e=this.pendingRequests[t].xhr;delete this.pendingRequests[t],e.abort()}}class ra{constructor(t){this._source=t,this._manager=new na(t),this._rangeChunkSize=t.rangeChunkSize,this._fullRequestReader=null,this._rangeRequestReaders=[]}_onRangeRequestReaderClosed(t){const e=this._rangeRequestReaders.indexOf(t);e>=0&&this._rangeRequestReaders.splice(e,1)}getFullReader(){return J(!this._fullRequestReader,"PDFNetworkStream.getFullReader can only be called once."),this._fullRequestReader=new aa(this._manager,this._source),this._fullRequestReader}getRangeReader(t,e){const s=new oa(this._manager,t,e);return s.onClosed=this._onRangeRequestReaderClosed.bind(this),this._rangeRequestReaders.push(s),s}cancelAllRequests(t){this._fullRequestReader?.cancel(t);for(const e of this._rangeRequestReaders.slice(0))e.cancel(t)}}class aa{constructor(t,e){this._manager=t,this._url=e.url,this._fullRequestId=t.request({onHeadersReceived:this._onHeadersReceived.bind(this),onDone:this._onDone.bind(this),onError:this._onError.bind(this),onProgress:this._onProgress.bind(this)}),this._headersCapability=Promise.withResolvers(),this._disableRange=e.disableRange||!1,this._contentLength=e.length,this._rangeChunkSize=e.rangeChunkSize,!this._rangeChunkSize&&!this._disableRange&&(this._disableRange=!0),this._isStreamingSupported=!1,this._isRangeSupported=!1,this._cachedChunks=[],this._requests=[],this._done=!1,this._storedError=void 0,this._filename=null,this.onProgress=null}_onHeadersReceived(){const t=this._fullRequestId,e=this._manager.getRequestXhr(t);this._manager._responseOrigin=ds(e.responseURL);const s=e.getAllResponseHeaders(),i=new Headers(s?s.trimStart().replace(/[^\S ]+$/,"").split(/[\r\n]+/).map(a=>{const[o,...l]=a.split(": ");return[o,l.join(": ")]}):[]),{allowRangeRequests:n,suggestedLength:r}=cn({responseHeaders:i,isHttp:this._manager.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});n&&(this._isRangeSupported=!0),this._contentLength=r||this._contentLength,this._filename=dn(i),this._isRangeSupported&&this._manager.abortRequest(t),this._headersCapability.resolve()}_onDone(t){if(t&&(this._requests.length>0?this._requests.shift().resolve({value:t.chunk,done:!1}):this._cachedChunks.push(t.chunk)),this._done=!0,!(this._cachedChunks.length>0)){for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0}}_onError(t){this._storedError=Ge(t,this._url),this._headersCapability.reject(this._storedError);for(const e of this._requests)e.reject(this._storedError);this._requests.length=0,this._cachedChunks.length=0}_onProgress(t){this.onProgress?.({loaded:t.loaded,total:t.lengthComputable?t.total:this._contentLength})}get filename(){return this._filename}get isRangeSupported(){return this._isRangeSupported}get isStreamingSupported(){return this._isStreamingSupported}get contentLength(){return this._contentLength}get headersReady(){return this._headersCapability.promise}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);for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0,this._manager.isPendingRequest(this._fullRequestId)&&this._manager.abortRequest(this._fullRequestId),this._fullRequestReader=null}}class oa{constructor(t,e,s){this._manager=t,this._url=t.url,this._requestId=t.request({begin:e,end:s,onHeadersReceived:this._onHeadersReceived.bind(this),onDone:this._onDone.bind(this),onError:this._onError.bind(this),onProgress:this._onProgress.bind(this)}),this._requests=[],this._queuedChunk=null,this._done=!1,this._storedError=void 0,this.onProgress=null,this.onClosed=null}_onHeadersReceived(){const t=ds(this._manager.getRequestXhr(this._requestId)?.responseURL);t!==this._manager._responseOrigin&&(this._storedError=new Error(`Expected range response-origin "${t}" to match "${this._manager._responseOrigin}".`),this._onError(0))}_close(){this.onClosed?.(this)}_onDone(t){const e=t.chunk;this._requests.length>0?this._requests.shift().resolve({value:e,done:!1}):this._queuedChunk=e,this._done=!0;for(const s of this._requests)s.resolve({value:void 0,done:!0});this._requests.length=0,this._close()}_onError(t){this._storedError??=Ge(t,this._url);for(const e of this._requests)e.reject(this._storedError);this._requests.length=0,this._queuedChunk=null}_onProgress(t){this.isStreamingSupported||this.onProgress?.({loaded:t.loaded})}get isStreamingSupported(){return!1}async read(){if(this._storedError)throw this._storedError;if(this._queuedChunk!==null){const e=this._queuedChunk;return this._queuedChunk=null,{value:e,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;for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0,this._manager.isPendingRequest(this._requestId)&&this._manager.abortRequest(this._requestId),this._close()}}const la=/^[a-z][a-z0-9\-+.]+:/i;function ha(c){if(la.test(c))return new URL(c);const t=process.getBuiltinModule("url");return new URL(t.pathToFileURL(c))}class ca{constructor(t){this.source=t,this.url=ha(t.url),J(this.url.protocol==="file:","PDFNodeStream only supports file:// URLs."),this._fullRequestReader=null,this._rangeRequestReaders=[]}get _progressiveDataLength(){return this._fullRequestReader?._loaded??0}getFullReader(){return J(!this._fullRequestReader,"PDFNodeStream.getFullReader can only be called once."),this._fullRequestReader=new da(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new ua(this,t,e);return this._rangeRequestReaders.push(s),s}cancelAllRequests(t){this._fullRequestReader?.cancel(t);for(const e of this._rangeRequestReaders.slice(0))e.cancel(t)}}class da{constructor(t){this._url=t.url,this._done=!1,this._storedError=null,this.onProgress=null;const e=t.source;this._contentLength=e.length,this._loaded=0,this._filename=null,this._disableRange=e.disableRange||!1,this._rangeChunkSize=e.rangeChunkSize,!this._rangeChunkSize&&!this._disableRange&&(this._disableRange=!0),this._isStreamingSupported=!e.disableStream,this._isRangeSupported=!e.disableRange,this._readableStream=null,this._readCapability=Promise.withResolvers(),this._headersCapability=Promise.withResolvers();const s=process.getBuiltinModule("fs");s.promises.lstat(this._url).then(i=>{this._contentLength=i.size,this._setReadableStream(s.createReadStream(this._url)),this._headersCapability.resolve()},i=>{i.code==="ENOENT"&&(i=Ge(0,this._url.href)),this._storedError=i,this._headersCapability.reject(i)})}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(){if(await this._readCapability.promise,this._done)return{value:void 0,done:!0};if(this._storedError)throw this._storedError;const t=this._readableStream.read();return t===null?(this._readCapability=Promise.withResolvers(),this.read()):(this._loaded+=t.length,this.onProgress?.({loaded:this._loaded,total:this._contentLength}),{value:new Uint8Array(t).buffer,done:!1})}cancel(t){if(!this._readableStream){this._error(t);return}this._readableStream.destroy(t)}_error(t){this._storedError=t,this._readCapability.resolve()}_setReadableStream(t){this._readableStream=t,t.on("readable",()=>{this._readCapability.resolve()}),t.on("end",()=>{t.destroy(),this._done=!0,this._readCapability.resolve()}),t.on("error",e=>{this._error(e)}),!this._isStreamingSupported&&this._isRangeSupported&&this._error(new qt("streaming is disabled")),this._storedError&&this._readableStream.destroy(this._storedError)}}class ua{constructor(t,e,s){this._url=t.url,this._done=!1,this._storedError=null,this.onProgress=null,this._loaded=0,this._readableStream=null,this._readCapability=Promise.withResolvers();const i=t.source;this._isStreamingSupported=!i.disableStream;const n=process.getBuiltinModule("fs");this._setReadableStream(n.createReadStream(this._url,{start:e,end:s-1}))}get isStreamingSupported(){return this._isStreamingSupported}async read(){if(await this._readCapability.promise,this._done)return{value:void 0,done:!0};if(this._storedError)throw this._storedError;const t=this._readableStream.read();return t===null?(this._readCapability=Promise.withResolvers(),this.read()):(this._loaded+=t.length,this.onProgress?.({loaded:this._loaded}),{value:new Uint8Array(t).buffer,done:!1})}cancel(t){if(!this._readableStream){this._error(t);return}this._readableStream.destroy(t)}_error(t){this._storedError=t,this._readCapability.resolve()}_setReadableStream(t){this._readableStream=t,t.on("readable",()=>{this._readCapability.resolve()}),t.on("end",()=>{t.destroy(),this._done=!0,this._readCapability.resolve()}),t.on("error",e=>{this._error(e)}),this._storedError&&this._readableStream.destroy(this._storedError)}}const Ee=Symbol("INITIAL_DATA");class gn{#t=Object.create(null);#e(t){return this.#t[t]||={...Promise.withResolvers(),data:Ee}}get(t,e=null){if(e){const i=this.#e(t);return i.promise.then(()=>e(i.data)),null}const s=this.#t[t];if(!s||s.data===Ee)throw new Error(`Requesting object that isn't resolved yet ${t}.`);return s.data}has(t){const e=this.#t[t];return!!e&&e.data!==Ee}delete(t){const e=this.#t[t];return!e||e.data===Ee?!1:(delete this.#t[t],!0)}resolve(t,e=null){const s=this.#e(t);s.data=e,s.resolve()}clear(){for(const t in this.#t){const{data:e}=this.#t[t];e?.bitmap?.close()}this.#t=Object.create(null)}*[Symbol.iterator](){for(const t in this.#t){const{data:e}=this.#t[t];e!==Ee&&(yield[t,e])}}}const fa=1e5,Ri=30;let Ie=class Ot{#t=Promise.withResolvers();#e=null;#i=!1;#s=!!globalThis.FontInspector?.enabled;#a=null;#n=null;#r=0;#o=0;#h=null;#l=null;#u=0;#d=0;#f=Object.create(null);#m=[];#p=null;#c=[];#g=new WeakMap;#b=null;static#A=new Map;static#y=new Map;static#C=new WeakMap;static#S=null;static#w=new Set;constructor({textContentSource:t,container:e,viewport:s}){if(t instanceof ReadableStream)this.#p=t;else if(typeof t=="object")this.#p=new ReadableStream({start(o){o.enqueue(t),o.close()}});else throw new Error('No "textContentSource" parameter specified.');this.#e=this.#l=e,this.#d=s.scale*Ht.pixelRatio,this.#u=s.rotation,this.#n={div:null,properties:null,ctx:null};const{pageWidth:i,pageHeight:n,pageX:r,pageY:a}=s.rawDims;this.#b=[1,0,0,-1,-r,a+n],this.#o=i,this.#r=n,Ot.#k(),Zt(e,s),this.#t.promise.finally(()=>{Ot.#w.delete(this),this.#n=null,this.#f=null}).catch(()=>{})}static get fontFamilyMap(){const{isWindows:t,isFirefox:e}=bt.platform;return Y(this,"fontFamilyMap",new Map([["sans-serif",`${t&&e?"Calibri, ":""}sans-serif`],["monospace",`${t&&e?"Lucida Console, ":""}monospace`]]))}render(){const t=()=>{this.#h.read().then(({value:e,done:s})=>{if(s){this.#t.resolve();return}this.#a??=e.lang,Object.assign(this.#f,e.styles),this.#T(e.items),t()},this.#t.reject)};return this.#h=this.#p.getReader(),Ot.#w.add(this),t(),this.#t.promise}update({viewport:t,onBefore:e=null}){const s=t.scale*Ht.pixelRatio,i=t.rotation;if(i!==this.#u&&(e?.(),this.#u=i,Zt(this.#l,{rotation:i})),s!==this.#d){e?.(),this.#d=s;const n={div:null,properties:null,ctx:Ot.#R(this.#a)};for(const r of this.#c)n.properties=this.#g.get(r),n.div=r,this.#E(n)}}cancel(){const t=new qt("TextLayer task cancelled.");this.#h?.cancel(t).catch(()=>{}),this.#h=null,this.#t.reject(t)}get textDivs(){return this.#c}get textContentItemsStr(){return this.#m}#T(t){if(this.#i)return;this.#n.ctx??=Ot.#R(this.#a);const e=this.#c,s=this.#m;for(const i of t){if(e.length>fa){W("Ignoring additional textDivs for performance reasons."),this.#i=!0;return}if(i.str===void 0){if(i.type==="beginMarkedContentProps"||i.type==="beginMarkedContent"){const n=this.#e;this.#e=document.createElement("span"),this.#e.classList.add("markedContent"),i.id&&this.#e.setAttribute("id",`${i.id}`),n.append(this.#e)}else i.type==="endMarkedContent"&&(this.#e=this.#e.parentNode);continue}s.push(i.str),this.#_(i)}}#_(t){const e=document.createElement("span"),s={angle:0,canvasWidth:0,hasText:t.str!=="",hasEOL:t.hasEOL,fontSize:0};this.#c.push(e);const i=I.transform(this.#b,t.transform);let n=Math.atan2(i[1],i[0]);const r=this.#f[t.fontName];r.vertical&&(n+=Math.PI/2);let a=this.#s&&r.fontSubstitution||r.fontFamily;a=Ot.fontFamilyMap.get(a)||a;const o=Math.hypot(i[2],i[3]),l=o*Ot.#O(a,r,this.#a);let h,d;n===0?(h=i[4],d=i[5]-l):(h=i[4]+l*Math.sin(n),d=i[5]-l*Math.cos(n));const u="calc(var(--total-scale-factor) *",f=e.style;this.#e===this.#l?(f.left=`${(100*h/this.#o).toFixed(2)}%`,f.top=`${(100*d/this.#r).toFixed(2)}%`):(f.left=`${u}${h.toFixed(2)}px)`,f.top=`${u}${d.toFixed(2)}px)`),f.fontSize=`${u}${(Ot.#S*o).toFixed(2)}px)`,f.fontFamily=a,s.fontSize=o,e.setAttribute("role","presentation"),e.textContent=t.str,e.dir=t.dir,this.#s&&(e.dataset.fontName=r.fontSubstitutionLoadedName||t.fontName),n!==0&&(s.angle=n*(180/Math.PI));let g=!1;if(t.str.length>1)g=!0;else if(t.str!==" "&&t.transform[0]!==t.transform[3]){const p=Math.abs(t.transform[0]),b=Math.abs(t.transform[3]);p!==b&&Math.max(p,b)/Math.min(p,b)>1.5&&(g=!0)}if(g&&(s.canvasWidth=r.vertical?t.height:t.width),this.#g.set(e,s),this.#n.div=e,this.#n.properties=s,this.#E(this.#n),s.hasText&&this.#e.append(e),s.hasEOL){const p=document.createElement("br");p.setAttribute("role","presentation"),this.#e.append(p)}}#E(t){const{div:e,properties:s,ctx:i}=t,{style:n}=e;let r="";if(Ot.#S>1&&(r=`scale(${1/Ot.#S})`),s.canvasWidth!==0&&s.hasText){const{fontFamily:a}=n,{canvasWidth:o,fontSize:l}=s;Ot.#P(i,l*this.#d,a);const{width:h}=i.measureText(e.textContent);h>0&&(r=`scaleX(${o*this.#d/h}) ${r}`)}s.angle!==0&&(r=`rotate(${s.angle}deg) ${r}`),r.length>0&&(n.transform=r)}static cleanup(){if(!(this.#w.size>0)){this.#A.clear();for(const{canvas:t}of this.#y.values())t.remove();this.#y.clear()}}static#R(t=null){let e=this.#y.get(t||="");if(!e){const s=document.createElement("canvas");s.className="hiddenCanvasElement",s.lang=t,document.body.append(s),e=s.getContext("2d",{alpha:!1,willReadFrequently:!0}),this.#y.set(t,e),this.#C.set(e,{size:0,family:""})}return e}static#P(t,e,s){const i=this.#C.get(t);e===i.size&&s===i.family||(t.font=`${e}px ${s}`,i.size=e,i.family=s)}static#k(){if(this.#S!==null)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.#S=t.getBoundingClientRect().height,t.remove()}static#O(t,e,s){const i=this.#A.get(t);if(i)return i;const n=this.#R(s);n.canvas.width=n.canvas.height=Ri,this.#P(n,Ri,t);const r=n.measureText(""),a=r.fontBoundingBoxAscent,o=Math.abs(r.fontBoundingBoxDescent);n.canvas.width=n.canvas.height=0;let l=.8;return a?l=a/(a+o):(bt.platform.isFirefox&&W("Enable the `dom.textMetrics.fontBoundingBox.enabled` preference in `about:config` to improve TextLayer rendering."),e.ascent?l=e.ascent:e.descent&&(l=1+e.descent)),this.#A.set(t,l),l}};const pa=100;function Qs(c={}){typeof c=="string"||c instanceof URL?c={url:c}:(c instanceof ArrayBuffer||ArrayBuffer.isView(c))&&(c={data:c});const t=new Js,{docId:e}=t,s=c.url?_r(c.url):null,i=c.data?Sr(c.data):null,n=c.httpHeaders||null,r=c.withCredentials===!0,a=c.password??null,o=c.range instanceof Zs?c.range:null,l=Number.isInteger(c.rangeChunkSize)&&c.rangeChunkSize>0?c.rangeChunkSize:2**16;let h=c.worker instanceof mt?c.worker:null;const d=c.verbosity,u=typeof c.docBaseUrl=="string"&&!Ue(c.docBaseUrl)?c.docBaseUrl:null,f=Ye(c.cMapUrl),g=c.cMapPacked!==!1,p=c.CMapReaderFactory||(Et?Rr:mi),b=Ye(c.iccUrl),m=Ye(c.standardFontDataUrl),y=c.StandardFontDataFactory||(Et?Mr:bi),A=Ye(c.wasmUrl),v=c.WasmFactory||(Et?Lr:yi),w=c.stopAtErrors!==!0,_=Number.isInteger(c.maxImageSize)&&c.maxImageSize>-1?c.maxImageSize:-1,S=c.isEvalSupported!==!1,E=typeof c.isOffscreenCanvasSupported=="boolean"?c.isOffscreenCanvasSupported:!Et,C=typeof c.isImageDecoderSupported=="boolean"?c.isImageDecoderSupported:!Et&&(bt.platform.isFirefox||!globalThis.chrome),T=Number.isInteger(c.canvasMaxAreaInBytes)?c.canvasMaxAreaInBytes:-1,P=typeof c.disableFontFace=="boolean"?c.disableFontFace:Et,$=c.fontExtraProperties===!0,G=c.enableXfa===!0,O=c.ownerDocument||globalThis.document,H=c.disableRange===!0,M=c.disableStream===!0,F=c.disableAutoFetch===!0,z=c.pdfBug===!0,Z=c.CanvasFactory||(Et?kr:xr),yt=c.FilterFactory||(Et?Pr:Tr),Ct=c.enableHWA===!0,x=c.useWasm!==!1,N=o?o.length:c.length??NaN,L=typeof c.useSystemFonts=="boolean"?c.useSystemFonts:!Et&&!P,j=typeof c.useWorkerFetch=="boolean"?c.useWorkerFetch:!!(p===mi&&y===bi&&v===yi&&f&&m&&A&&Te(f,document.baseURI)&&Te(m,document.baseURI)&&Te(A,document.baseURI)),X=null;ir(d);const k={canvasFactory:new Z({ownerDocument:O,enableHWA:Ct}),filterFactory:new yt({docId:e,ownerDocument:O}),cMapReaderFactory:j?null:new p({baseUrl:f,isCompressed:g}),standardFontDataFactory:j?null:new y({baseUrl:m}),wasmFactory:j?null:new v({baseUrl:A})};h||(h=mt.create({verbosity:d,port:Jt.workerPort}),t._worker=h);const q={docId:e,apiVersion:"5.4.296",data:i,password:a,disableAutoFetch:F,rangeChunkSize:l,length:N,docBaseUrl:u,enableXfa:G,evaluatorOptions:{maxImageSize:_,disableFontFace:P,ignoreErrors:w,isEvalSupported:S,isOffscreenCanvasSupported:E,isImageDecoderSupported:C,canvasMaxAreaInBytes:T,fontExtraProperties:$,useSystemFonts:L,useWasm:x,useWorkerFetch:j,cMapUrl:f,iccUrl:b,standardFontDataUrl:m,wasmUrl:A}},rt={ownerDocument:O,pdfBug:z,styleElement:X,loadingParams:{disableAutoFetch:F,enableXfa:G}};return h.promise.then(function(){if(t.destroyed)throw new Error("Loading aborted");if(h.destroyed)throw new Error("Worker was destroyed");const It=h.messageHandler.sendWithPromise("GetDocRequest",q,i?[i.buffer]:null);let xt;if(o)xt=new Kr(o,{disableRange:H,disableStream:M});else if(!i){if(!s)throw new Error("getDocument - no `url` parameter provided.");const tt=Te(s)?ta:Et?ca:ra;xt=new tt({url:s,length:N,httpHeaders:n,withCredentials:r,rangeChunkSize:l,disableRange:H,disableStream:M})}return It.then(tt=>{if(t.destroyed)throw new Error("Loading aborted");if(h.destroyed)throw new Error("Worker was destroyed");const et=new Pe(e,tt,h.port),ft=new ba(et,t,xt,rt,k,Ct);t._transport=ft,et.send("Ready",null)})}).catch(t._capability.reject),t}class Js{static#t=0;_capability=Promise.withResolvers();_transport=null;_worker=null;docId=`d${Js.#t++}`;destroyed=!1;onPassword=null;onProgress=null;get promise(){return this._capability.promise}async destroy(){this.destroyed=!0;try{this._worker?.port&&(this._worker._pendingDestroy=!0),await this._transport?.destroy()}catch(t){throw this._worker?.port&&delete this._worker._pendingDestroy,t}this._transport=null,this._worker?.destroy(),this._worker=null}async getData(){return this._transport.getData()}}let Zs=class{#t=Promise.withResolvers();#e=[];#i=[];#s=[];#a=[];constructor(t,e,s=!1,i=null){this.length=t,this.initialData=e,this.progressiveDone=s,this.contentDispositionFilename=i}addRangeListener(t){this.#a.push(t)}addProgressListener(t){this.#s.push(t)}addProgressiveReadListener(t){this.#i.push(t)}addProgressiveDoneListener(t){this.#e.push(t)}onDataRange(t,e){for(const s of this.#a)s(t,e)}onDataProgress(t,e){this.#t.promise.then(()=>{for(const s of this.#s)s(t,e)})}onDataProgressiveRead(t){this.#t.promise.then(()=>{for(const e of this.#i)e(t)})}onDataProgressiveDone(){this.#t.promise.then(()=>{for(const t of this.#e)t()})}transportReady(){this.#t.resolve()}requestDataRange(t,e){nt("Abstract method PDFDataRangeTransport.requestDataRange")}abort(){}};class ga{constructor(t,e){this._pdfInfo=t,this._transport=e}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 Y(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()}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(){return this._transport.saveDocument()}getDownloadInfo(){return this._transport.downloadInfoCapability.promise}cleanup(t=!1){return this._transport.startCleanup(t||this.isPureXfa)}destroy(){return this.loadingTask.destroy()}cachedPageNumber(t){return this._transport.cachedPageNumber(t)}get loadingParams(){return this._transport.loadingParams}get loadingTask(){return this._transport.loadingTask}getFieldObjects(){return this._transport.getFieldObjects()}hasJSActions(){return this._transport.hasJSActions()}getCalculationOrderIds(){return this._transport.getCalculationOrderIds()}}class ma{#t=!1;constructor(t,e,s,i=!1){this._pageIndex=t,this._pageInfo=e,this._transport=s,this._stats=i?new hi:null,this._pdfBug=i,this.commonObjs=s.commonObjs,this.objs=new gn,this._intentStates=new Map,this.destroyed=!1,this.recordedBBoxes=null}get pageNumber(){return this._pageIndex+1}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:s=0,offsetY:i=0,dontFlip:n=!1}={}){return new He({viewBox:this.view,userUnit:this.userUnit,scale:t,rotation:e,offsetX:s,offsetY:i,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 Y(this,"isPureXfa",!!this._transport._htmlForXfa)}async getXfa(){return this._transport._htmlForXfa?.children[this._pageIndex]||null}render({canvasContext:t,canvas:e=t.canvas,viewport:s,intent:i="display",annotationMode:n=Wt.ENABLE,transform:r=null,background:a=null,optionalContentConfigPromise:o=null,annotationCanvasMap:l=null,pageColors:h=null,printAnnotationStorage:d=null,isEditing:u=!1,recordOperations:f=!1,operationsFilter:g=null}){this._stats?.time("Overall");const p=this._transport.getRenderingIntent(i,n,d,u),{renderingIntent:b,cacheKey:m}=p;this.#t=!1,o||=this._transport.getOptionalContentConfig(b);let y=this._intentStates.get(m);y||(y=Object.create(null),this._intentStates.set(m,y)),y.streamReaderCancelTimeout&&(clearTimeout(y.streamReaderCancelTimeout),y.streamReaderCancelTimeout=null);const A=!!(b&Rt.PRINT);y.displayReadyCapability||(y.displayReadyCapability=Promise.withResolvers(),y.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},this._stats?.time("Page Request"),this._pumpOperatorList(p));const v=!!(this._pdfBug&&globalThis.StepperManager?.enabled),w=!this.recordedBBoxes&&(f||v),_=C=>{if(y.renderTasks.delete(S),w){const T=S.gfx?.dependencyTracker.take();T&&(S.stepper&&S.stepper.setOperatorBBoxes(T,S.gfx.dependencyTracker.takeDebugMetadata()),f&&(this.recordedBBoxes=T))}A&&(this.#t=!0),this.#e(),C?(S.capability.reject(C),this._abortOperatorList({intentState:y,reason:C instanceof Error?C:new Error(C)})):S.capability.resolve(),this._stats&&(this._stats.timeEnd("Rendering"),this._stats.timeEnd("Overall"),globalThis.Stats?.enabled&&globalThis.Stats.add(this.pageNumber,this._stats))},S=new fe({callback:_,params:{canvas:e,canvasContext:t,dependencyTracker:w?new Ir(e,y.operatorList.length,v):null,viewport:s,transform:r,background:a},objs:this.objs,commonObjs:this.commonObjs,annotationCanvasMap:l,operatorList:y.operatorList,pageIndex:this._pageIndex,canvasFactory:this._transport.canvasFactory,filterFactory:this._transport.filterFactory,useRequestAnimationFrame:!A,pdfBug:this._pdfBug,pageColors:h,enableHWA:this._transport.enableHWA,operationsFilter:g});(y.renderTasks||=new Set).add(S);const E=S.task;return Promise.all([y.displayReadyCapability.promise,o]).then(([C,T])=>{if(this.destroyed){_();return}if(this._stats?.time("Rendering"),!(T.renderingIntent&b))throw new Error("Must use the same `intent`-argument when calling the `PDFPageProxy.render` and `PDFDocumentProxy.getOptionalContentConfig` methods.");S.initializeGraphics({transparency:C,optionalContentConfig:T}),S.operatorListChanged()}).catch(_),E}getOperatorList({intent:t="display",annotationMode:e=Wt.ENABLE,printAnnotationStorage:s=null,isEditing:i=!1}={}){function n(){a.operatorList.lastChunk&&(a.opListReadCapability.resolve(a.operatorList),a.renderTasks.delete(o))}const r=this._transport.getRenderingIntent(t,e,s,i,!0);let a=this._intentStates.get(r.cacheKey);a||(a=Object.create(null),this._intentStates.set(r.cacheKey,a));let o;return a.opListReadCapability||(o=Object.create(null),o.operatorListChanged=n,a.opListReadCapability=Promise.withResolvers(),(a.renderTasks||=new Set).add(o),a.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},this._stats?.time("Page Request"),this._pumpOperatorList(r)),a.opListReadCapability.promise}streamTextContent({includeMarkedContent:t=!1,disableNormalization:e=!1}={}){return this._transport.messageHandler.sendWithStream("GetTextContent",{pageIndex:this._pageIndex,includeMarkedContent:t===!0,disableNormalization:e===!0},{highWaterMark:100,size(i){return i.items.length}})}getTextContent(t={}){if(this._transport._htmlForXfa)return this.getXfa().then(s=>De.textContent(s));const e=this.streamTextContent(t);return new Promise(function(s,i){function n(){r.read().then(function({value:o,done:l}){if(l){s(a);return}a.lang??=o.lang,Object.assign(a.styles,o.styles),a.items.push(...o.items),n()},i)}const r=e.getReader(),a={items:[],styles:Object.create(null),lang:null};n()})}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:new Error("Page was destroyed."),force:!0}),!e.opListReadCapability)for(const s of e.renderTasks)t.push(s.completed),s.cancel();return this.objs.clear(),this.#t=!1,Promise.all(t)}cleanup(t=!1){this.#t=!0;const e=this.#e();return t&&e&&(this._stats&&=new hi),e}#e(){if(!this.#t||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.#t=!1,!0}_startRenderPage(t,e){const s=this._intentStates.get(e);s&&(this._stats?.timeEnd("Page Request"),s.displayReadyCapability?.resolve(t))}_renderPageChunk(t,e){for(let s=0,i=t.length;s<i;s++)e.operatorList.fnArray.push(t.fnArray[s]),e.operatorList.argsArray.push(t.argsArray[s]);e.operatorList.lastChunk=t.lastChunk,e.operatorList.separateAnnots=t.separateAnnots;for(const s of e.renderTasks)s.operatorListChanged();t.lastChunk&&this.#e()}_pumpOperatorList({renderingIntent:t,cacheKey:e,annotationStorageSerializable:s,modifiedIds:i}){const{map:n,transfer:r}=s,o=this._transport.messageHandler.sendWithStream("GetOperatorList",{pageIndex:this._pageIndex,intent:t,cacheKey:e,annotationStorage:n,modifiedIds:i},r).getReader(),l=this._intentStates.get(e);l.streamReader=o;const h=()=>{o.read().then(({value:d,done:u})=>{if(u){l.streamReader=null;return}this._transport.destroyed||(this._renderPageChunk(d,l),h())},d=>{if(l.streamReader=null,!this._transport.destroyed){if(l.operatorList){l.operatorList.lastChunk=!0;for(const u of l.renderTasks)u.operatorListChanged();this.#e()}if(l.displayReadyCapability)l.displayReadyCapability.reject(d);else if(l.opListReadCapability)l.opListReadCapability.reject(d);else throw d}})};h()}_abortOperatorList({intentState:t,reason:e,force:s=!1}){if(t.streamReader){if(t.streamReaderCancelTimeout&&(clearTimeout(t.streamReaderCancelTimeout),t.streamReaderCancelTimeout=null),!s){if(t.renderTasks.size>0)return;if(e instanceof hs){let i=pa;e.extraDelay>0&&e.extraDelay<1e3&&(i+=e.extraDelay),t.streamReaderCancelTimeout=setTimeout(()=>{t.streamReaderCancelTimeout=null,this._abortOperatorList({intentState:t,reason:e,force:!0})},i);return}}if(t.streamReader.cancel(new qt(e.message)).catch(()=>{}),t.streamReader=null,!this._transport.destroyed){for(const[i,n]of this._intentStates)if(n===t){this._intentStates.delete(i);break}this.cleanup()}}}get stats(){return this._stats}}class mt{#t=Promise.withResolvers();#e=null;#i=null;#s=null;static#a=0;static#n=!1;static#r=new WeakMap;static{Et&&(this.#n=!0,Jt.workerSrc||="./pdf.worker.mjs"),this._isSameOrigin=(t,e)=>{const s=URL.parse(t);if(!s?.origin||s.origin==="null")return!1;const i=new URL(e,s);return s.origin===i.origin},this._createCDNWrapper=t=>{const e=`await import("${t}");`;return URL.createObjectURL(new Blob([e],{type:"text/javascript"}))},this.fromPort=t=>{if(fr("`PDFWorker.fromPort` - please use `PDFWorker.create` instead."),!t?.port)throw new Error("PDFWorker.fromPort - invalid method signature.");return this.create(t)}}constructor({name:t=null,port:e=null,verbosity:s=nr()}={}){if(this.name=t,this.destroyed=!1,this.verbosity=s,e){if(mt.#r.has(e))throw new Error("Cannot use more than one PDFWorker per port.");mt.#r.set(e,this),this.#h(e)}else this.#l()}get promise(){return this.#t.promise}#o(){this.#t.resolve(),this.#e.send("configure",{verbosity:this.verbosity})}get port(){return this.#i}get messageHandler(){return this.#e}#h(t){this.#i=t,this.#e=new Pe("main","worker",t),this.#e.on("ready",()=>{}),this.#o()}#l(){if(mt.#n||mt.#d){this.#u();return}let{workerSrc:t}=mt;try{mt._isSameOrigin(window.location,t)||(t=mt._createCDNWrapper(new URL(t,window.location).href));const e=new Worker(t,{type:"module"}),s=new Pe("main","worker",e),i=()=>{n.abort(),s.destroy(),e.terminate(),this.destroyed?this.#t.reject(new Error("Worker was destroyed")):this.#u()},n=new AbortController;e.addEventListener("error",()=>{this.#s||i()},{signal:n.signal}),s.on("test",a=>{if(n.abort(),this.destroyed||!a){i();return}this.#e=s,this.#i=e,this.#s=e,this.#o()}),s.on("ready",a=>{if(n.abort(),this.destroyed){i();return}try{r()}catch{this.#u()}});const r=()=>{const a=new Uint8Array;s.send("test",a,[a.buffer])};r();return}catch{ls("The worker has been disabled.")}this.#u()}#u(){mt.#n||(W("Setting up fake worker."),mt.#n=!0),mt._setupFakeWorkerGlobal.then(t=>{if(this.destroyed){this.#t.reject(new Error("Worker was destroyed"));return}const e=new Cr;this.#i=e;const s=`fake${mt.#a++}`,i=new Pe(s+"_worker",s,e);t.setup(i,e),this.#e=new Pe(s,s+"_worker",e),this.#o()}).catch(t=>{this.#t.reject(new Error(`Setting up fake worker failed: "${t.message}".`))})}destroy(){this.destroyed=!0,this.#s?.terminate(),this.#s=null,mt.#r.delete(this.#i),this.#i=null,this.#e?.destroy(),this.#e=null}static create(t){const e=this.#r.get(t?.port);if(e){if(e._pendingDestroy)throw new Error("PDFWorker.create - the worker is being destroyed.\nPlease remember to await `PDFDocumentLoadingTask.destroy()`-calls.");return e}return new mt(t)}static get workerSrc(){if(Jt.workerSrc)return Jt.workerSrc;throw new Error('No "GlobalWorkerOptions.workerSrc" specified.')}static get#d(){try{return globalThis.pdfjsWorker?.WorkerMessageHandler||null}catch{return null}}static get _setupFakeWorkerGlobal(){return Y(this,"_setupFakeWorkerGlobal",(async()=>this.#d?this.#d:(await import(this.workerSrc)).WorkerMessageHandler)())}}class ba{#t=new Map;#e=new Map;#i=new Map;#s=new Map;#a=null;constructor(t,e,s,i,n,r){this.messageHandler=t,this.loadingTask=e,this.commonObjs=new gn,this.fontLoader=new wr({ownerDocument:i.ownerDocument,styleElement:i.styleElement}),this.loadingParams=i.loadingParams,this._params=i,this.canvasFactory=n.canvasFactory,this.filterFactory=n.filterFactory,this.cMapReaderFactory=n.cMapReaderFactory,this.standardFontDataFactory=n.standardFontDataFactory,this.wasmFactory=n.wasmFactory,this.destroyed=!1,this.destroyCapability=null,this._networkStream=s,this._fullReader=null,this._lastProgress=null,this.downloadInfoCapability=Promise.withResolvers(),this.enableHWA=r,this.setupMessageHandler()}#n(t,e=null){const s=this.#t.get(t);if(s)return s;const i=this.messageHandler.sendWithPromise(t,e);return this.#t.set(t,i),i}get annotationStorage(){return Y(this,"annotationStorage",new Xs)}getRenderingIntent(t,e=Wt.ENABLE,s=null,i=!1,n=!1){let r=Rt.DISPLAY,a=ks;switch(t){case"any":r=Rt.ANY;break;case"display":break;case"print":r=Rt.PRINT;break;default:W(`getRenderingIntent - invalid intent: ${t}`)}const o=r&Rt.PRINT&&s instanceof en?s:this.annotationStorage;switch(e){case Wt.DISABLE:r+=Rt.ANNOTATIONS_DISABLE;break;case Wt.ENABLE:break;case Wt.ENABLE_FORMS:r+=Rt.ANNOTATIONS_FORMS;break;case Wt.ENABLE_STORAGE:r+=Rt.ANNOTATIONS_STORAGE,a=o.serializable;break;default:W(`getRenderingIntent - invalid annotationMode: ${e}`)}i&&(r+=Rt.IS_EDITING),n&&(r+=Rt.OPLIST);const{ids:l,hash:h}=o.modifiedIds,d=[r,a.hash,h];return{renderingIntent:r,cacheKey:d.join("_"),annotationStorageSerializable:a,modifiedIds:l}}destroy(){if(this.destroyCapability)return this.destroyCapability.promise;this.destroyed=!0,this.destroyCapability=Promise.withResolvers(),this.#a?.reject(new Error("Worker was destroyed during onPassword callback"));const t=[];for(const s of this.#e.values())t.push(s._destroy());this.#e.clear(),this.#i.clear(),this.#s.clear(),this.hasOwnProperty("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.#t.clear(),this.filterFactory.destroy(),Ie.cleanup(),this._networkStream?.cancelAllRequests(new qt("Worker was terminated.")),this.messageHandler?.destroy(),this.messageHandler=null,this.destroyCapability.resolve()},this.destroyCapability.reject),this.destroyCapability.promise}setupMessageHandler(){const{messageHandler:t,loadingTask:e}=this;t.on("GetReader",(s,i)=>{J(this._networkStream,"GetReader - no `IPDFStream` instance available."),this._fullReader=this._networkStream.getFullReader(),this._fullReader.onProgress=n=>{this._lastProgress={loaded:n.loaded,total:n.total}},i.onPull=()=>{this._fullReader.read().then(function({value:n,done:r}){if(r){i.close();return}J(n instanceof ArrayBuffer,"GetReader - expected an ArrayBuffer."),i.enqueue(new Uint8Array(n),1,[n])}).catch(n=>{i.error(n)})},i.onCancel=n=>{this._fullReader.cancel(n),i.ready.catch(r=>{if(!this.destroyed)throw r})}}),t.on("ReaderHeadersReady",async s=>{await this._fullReader.headersReady;const{isStreamingSupported:i,isRangeSupported:n,contentLength:r}=this._fullReader;return(!i||!n)&&(this._lastProgress&&e.onProgress?.(this._lastProgress),this._fullReader.onProgress=a=>{e.onProgress?.({loaded:a.loaded,total:a.total})}),{isStreamingSupported:i,isRangeSupported:n,contentLength:r}}),t.on("GetRangeReader",(s,i)=>{J(this._networkStream,"GetRangeReader - no `IPDFStream` instance available.");const n=this._networkStream.getRangeReader(s.begin,s.end);if(!n){i.close();return}i.onPull=()=>{n.read().then(function({value:r,done:a}){if(a){i.close();return}J(r instanceof ArrayBuffer,"GetRangeReader - expected an ArrayBuffer."),i.enqueue(new Uint8Array(r),1,[r])}).catch(r=>{i.error(r)})},i.onCancel=r=>{n.cancel(r),i.ready.catch(a=>{if(!this.destroyed)throw a})}}),t.on("GetDoc",({pdfInfo:s})=>{this._numPages=s.numPages,this._htmlForXfa=s.htmlForXfa,delete s.htmlForXfa,e._capability.resolve(new ga(s,this))}),t.on("DocException",s=>{e._capability.reject(Tt(s))}),t.on("PasswordRequest",s=>{this.#a=Promise.withResolvers();try{if(!e.onPassword)throw Tt(s);const i=n=>{n instanceof Error?this.#a.reject(n):this.#a.resolve({password:n})};e.onPassword(i,s.code)}catch(i){this.#a.reject(i)}return this.#a.promise}),t.on("DataLoaded",s=>{e.onProgress?.({loaded:s.length,total:s.length}),this.downloadInfoCapability.resolve(s)}),t.on("StartRenderPage",s=>{if(this.destroyed)return;this.#e.get(s.pageIndex)._startRenderPage(s.transparency,s.cacheKey)}),t.on("commonobj",([s,i,n])=>{if(this.destroyed||this.commonObjs.has(s))return null;switch(i){case"Font":if("error"in n){const h=n.error;W(`Error during font loading: ${h}`),this.commonObjs.resolve(s,h);break}const r=new st(n),a=this._params.pdfBug&&globalThis.FontInspector?.enabled?(h,d)=>globalThis.FontInspector.fontAdded(h,d):null,o=new vr(r,a,n.extra,n.charProcOperatorList);this.fontLoader.bind(o).catch(()=>t.sendWithPromise("FontFallback",{id:s})).finally(()=>{!o.fontExtraProperties&&o.data&&o.clearData(),this.commonObjs.resolve(s,o)});break;case"CopyLocalImage":const{imageRef:l}=n;J(l,"The imageRef must be defined.");for(const h of this.#e.values())for(const[,d]of h.objs)if(d?.ref===l)return d.dataLen?(this.commonObjs.resolve(s,structuredClone(d)),d.dataLen):null;break;case"FontPath":case"Image":case"Pattern":this.commonObjs.resolve(s,n);break;default:throw new Error(`Got unknown common object type ${i}`)}return null}),t.on("obj",([s,i,n,r])=>{if(this.destroyed)return;const a=this.#e.get(i);if(!a.objs.has(s)){if(a._intentStates.size===0){r?.bitmap?.close();return}switch(n){case"Image":case"Pattern":a.objs.resolve(s,r);break;default:throw new Error(`Got unknown object type ${n}`)}}}),t.on("DocProgress",s=>{this.destroyed||e.onProgress?.({loaded:s.loaded,total:s.total})}),t.on("FetchBinaryData",async s=>{if(this.destroyed)throw new Error("Worker was destroyed.");const i=this[s.type];if(!i)throw new Error(`${s.type} not initialized, see the \`useWorkerFetch\` parameter.`);return i.fetch(s)})}getData(){return this.messageHandler.sendWithPromise("GetData",null)}saveDocument(){this.annotationStorage.size<=0&&W("saveDocument called while `annotationStorage` is empty, please use the getData-method instead.");const{map:t,transfer:e}=this.annotationStorage.serializable;return this.messageHandler.sendWithPromise("SaveDocument",{isPureXfa:!!this._htmlForXfa,numPages:this._numPages,annotationStorage:t,filename:this._fullReader?.filename??null},e).finally(()=>{this.annotationStorage.resetModified()})}getPage(t){if(!Number.isInteger(t)||t<=0||t>this._numPages)return Promise.reject(new Error("Invalid page request."));const e=t-1,s=this.#i.get(e);if(s)return s;const i=this.messageHandler.sendWithPromise("GetPage",{pageIndex:e}).then(n=>{if(this.destroyed)throw new Error("Transport destroyed");n.refStr&&this.#s.set(n.refStr,t);const r=new ma(e,n,this,this._params.pdfBug);return this.#e.set(e,r),r});return this.#i.set(e,i),i}getPageIndex(t){return Rs(t)?this.messageHandler.sendWithPromise("GetPageIndex",{num:t.num,gen:t.gen}):Promise.reject(new Error("Invalid pageIndex request."))}getAnnotations(t,e){return this.messageHandler.sendWithPromise("GetAnnotations",{pageIndex:t,intent:e})}getFieldObjects(){return this.#n("GetFieldObjects")}hasJSActions(){return this.#n("HasJSActions")}getCalculationOrderIds(){return this.messageHandler.sendWithPromise("GetCalculationOrderIds",null)}getDestinations(){return this.messageHandler.sendWithPromise("GetDestinations",null)}getDestination(t){return typeof t!="string"?Promise.reject(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)}getAnnotationsByType(t,e){return this.messageHandler.sendWithPromise("GetAnnotationsByType",{types:t,pageIndexesToSkip:e})}getDocJSActions(){return this.#n("GetDocJSActions")}getPageJSActions(t){return this.messageHandler.sendWithPromise("GetPageJSActions",{pageIndex:t})}getStructTree(t){return this.messageHandler.sendWithPromise("GetStructTree",{pageIndex:t})}getOutline(){return this.messageHandler.sendWithPromise("GetOutline",null)}getOptionalContentConfig(t){return this.#n("GetOptionalContentConfig").then(e=>new Yr(e,t))}getPermissions(){return this.messageHandler.sendWithPromise("GetPermissions",null)}getMetadata(){const t="GetMetadata",e=this.#t.get(t);if(e)return e;const s=this.messageHandler.sendWithPromise(t,null).then(i=>({info:i[0],metadata:i[1]?new Xr(i[1]):null,contentDispositionFilename:this._fullReader?.filename??null,contentLength:this._fullReader?.contentLength??null}));return this.#t.set(t,s),s}getMarkInfo(){return this.messageHandler.sendWithPromise("GetMarkInfo",null)}async startCleanup(t=!1){if(!this.destroyed){await this.messageHandler.sendWithPromise("Cleanup",null);for(const e of this.#e.values())if(!e.cleanup())throw new Error(`startCleanup: Page ${e.pageNumber} is currently rendering.`);this.commonObjs.clear(),t||this.fontLoader.clear(),this.#t.clear(),this.filterFactory.destroy(!0),Ie.cleanup()}}cachedPageNumber(t){if(!Rs(t))return null;const e=t.gen===0?`${t.num}R`:`${t.num}R${t.gen}`;return this.#s.get(e)??null}}class ya{#t=null;onContinue=null;onError=null;constructor(t){this.#t=t}get promise(){return this.#t.capability.promise}cancel(t=0){this.#t.cancel(null,t)}get separateAnnots(){const{separateAnnots:t}=this.#t.operatorList;if(!t)return!1;const{annotationCanvasMap:e}=this.#t;return t.form||t.canvas&&e?.size>0}}class fe{#t=null;static#e=new WeakSet;constructor({callback:t,params:e,objs:s,commonObjs:i,annotationCanvasMap:n,operatorList:r,pageIndex:a,canvasFactory:o,filterFactory:l,useRequestAnimationFrame:h=!1,pdfBug:d=!1,pageColors:u=null,enableHWA:f=!1,operationsFilter:g=null}){this.callback=t,this.params=e,this.objs=s,this.commonObjs=i,this.annotationCanvasMap=n,this.operatorListIdx=null,this.operatorList=r,this._pageIndex=a,this.canvasFactory=o,this.filterFactory=l,this._pdfBug=d,this.pageColors=u,this.running=!1,this.graphicsReadyCallback=null,this.graphicsReady=!1,this._useRequestAnimationFrame=h===!0&&typeof window<"u",this.cancelled=!1,this.capability=Promise.withResolvers(),this.task=new ya(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._enableHWA=f,this._dependencyTracker=e.dependencyTracker,this._operationsFilter=g}get completed(){return this.capability.promise.catch(function(){})}initializeGraphics({transparency:t=!1,optionalContentConfig:e}){if(this.cancelled)return;if(this._canvas){if(fe.#e.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.");fe.#e.add(this._canvas)}this._pdfBug&&globalThis.StepperManager?.enabled&&(this.stepper=globalThis.StepperManager.create(this._pageIndex),this.stepper.init(this.operatorList),this.stepper.nextBreakPoint=this.stepper.getNextBreakPoint());const{viewport:s,transform:i,background:n,dependencyTracker:r}=this.params,a=this._canvasContext||this._canvas.getContext("2d",{alpha:!1,willReadFrequently:!this._enableHWA});this.gfx=new pe(a,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:e},this.annotationCanvasMap,this.pageColors,r),this.gfx.beginDrawing({transform:i,viewport:s,transparency:t,background:n}),this.operatorListIdx=0,this.graphicsReady=!0,this.graphicsReadyCallback?.()}cancel(t=null,e=0){this.running=!1,this.cancelled=!0,this.gfx?.endDrawing(),this.#t&&(window.cancelAnimationFrame(this.#t),this.#t=null),fe.#e.delete(this._canvas),t||=new hs(`Rendering cancelled, page ${this._pageIndex+1}`,e),this.callback(t),this.task.onError?.(t)}operatorListChanged(){if(!this.graphicsReady){this.graphicsReadyCallback||=this._continueBound;return}this.gfx.dependencyTracker?.growOperationsCount(this.operatorList.fnArray.length),this.stepper?.updateOperatorList(this.operatorList),!this.running&&this._continue()}_continue(){this.running=!0,!this.cancelled&&(this.task.onContinue?this.task.onContinue(this._scheduleNextBound):this._scheduleNext())}_scheduleNext(){this._useRequestAnimationFrame?this.#t=window.requestAnimationFrame(()=>{this.#t=null,this._nextBound().catch(this._cancelBound)}):Promise.resolve().then(this._nextBound).catch(this._cancelBound)}async _next(){this.cancelled||(this.operatorListIdx=this.gfx.executeOperatorList(this.operatorList,this.operatorListIdx,this._continueBound,this.stepper,this._operationsFilter),this.operatorListIdx===this.operatorList.argsArray.length&&(this.running=!1,this.operatorList.lastChunk&&(this.gfx.endDrawing(),fe.#e.delete(this._canvas),this.callback())))}}const mn="5.4.296",bn="f56dc8601";class Mt{#t=null;#e=null;#i;#s=null;#a=!1;#n=!1;#r=null;#o;#h=null;#l=null;static#u=null;static get _keyboardManager(){return Y(this,"_keyboardManager",new je([[["Escape","mac+Escape"],Mt.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],Mt.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],Mt.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],Mt.prototype._moveToPrevious],[["Home","mac+Home"],Mt.prototype._moveToBeginning],[["End","mac+End"],Mt.prototype._moveToEnd]]))}constructor({editor:t=null,uiManager:e=null}){t?(this.#n=!1,this.#r=t):this.#n=!0,this.#l=t?._uiManager||e,this.#o=this.#l._eventBus,this.#i=t?.color?.toUpperCase()||this.#l?.highlightColors.values().next().value||"#FFFF98",Mt.#u||=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.#t=document.createElement("button");t.className="colorPicker",t.tabIndex="0",t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-button"),t.ariaHasPopup="true",this.#r&&(t.ariaControls=`${this.#r.id}_colorpicker_dropdown`);const e=this.#l._signal;t.addEventListener("click",this.#p.bind(this),{signal:e}),t.addEventListener("keydown",this.#m.bind(this),{signal:e});const s=this.#e=document.createElement("span");return s.className="swatch",s.ariaHidden="true",s.style.backgroundColor=this.#i,t.append(s),t}renderMainDropdown(){const t=this.#s=this.#d();return t.ariaOrientation="horizontal",t.ariaLabelledBy="highlightColorPickerLabel",t}#d(){const t=document.createElement("div"),e=this.#l._signal;t.addEventListener("contextmenu",Dt,{signal:e}),t.className="dropdown",t.role="listbox",t.ariaMultiSelectable="false",t.ariaOrientation="vertical",t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown"),this.#r&&(t.id=`${this.#r.id}_colorpicker_dropdown`);for(const[s,i]of this.#l.highlightColors){const n=document.createElement("button");n.tabIndex="0",n.role="option",n.setAttribute("data-color",i),n.title=s,n.setAttribute("data-l10n-id",Mt.#u[s]);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.ariaSelected=i===this.#i,n.addEventListener("click",this.#f.bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",this.#m.bind(this),{signal:e}),t}#f(t,e){e.stopPropagation(),this.#o.dispatch("switchannotationeditorparams",{source:this,type:Q.HIGHLIGHT_COLOR,value:t}),this.updateColor(t)}_colorSelectFromKeyboard(t){if(t.target===this.#t){this.#p(t);return}const e=t.target.getAttribute("data-color");e&&this.#f(e,t)}_moveToNext(t){if(!this.#g){this.#p(t);return}if(t.target===this.#t){this.#s.firstChild?.focus();return}t.target.nextSibling?.focus()}_moveToPrevious(t){if(t.target===this.#s?.firstChild||t.target===this.#t){this.#g&&this._hideDropdownFromKeyboard();return}this.#g||this.#p(t),t.target.previousSibling?.focus()}_moveToBeginning(t){if(!this.#g){this.#p(t);return}this.#s.firstChild?.focus()}_moveToEnd(t){if(!this.#g){this.#p(t);return}this.#s.lastChild?.focus()}#m(t){Mt._keyboardManager.exec(this,t)}#p(t){if(this.#g){this.hideDropdown();return}if(this.#a=t.detail===0,this.#h||(this.#h=new AbortController,window.addEventListener("pointerdown",this.#c.bind(this),{signal:this.#l.combinedSignal(this.#h)})),this.#t.ariaExpanded="true",this.#s){this.#s.classList.remove("hidden");return}const e=this.#s=this.#d();this.#t.append(e)}#c(t){this.#s?.contains(t.target)||this.hideDropdown()}hideDropdown(){this.#s?.classList.add("hidden"),this.#t.ariaExpanded="false",this.#h?.abort(),this.#h=null}get#g(){return this.#s&&!this.#s.classList.contains("hidden")}_hideDropdownFromKeyboard(){if(!this.#n){if(!this.#g){this.#r?.unselect();return}this.hideDropdown(),this.#t.focus({preventScroll:!0,focusVisible:this.#a})}}updateColor(t){if(this.#e&&(this.#e.style.backgroundColor=t),!this.#s)return;const e=this.#l.highlightColors.values();for(const s of this.#s.children)s.ariaSelected=e.next().value===t.toUpperCase()}destroy(){this.#t?.remove(),this.#t=null,this.#e=null,this.#s?.remove(),this.#s=null}}class Fe{#t=null;#e=null;#i=null;static#s=null;constructor(t){this.#e=t,this.#i=t._uiManager,Fe.#s||=Object.freeze({freetext:"pdfjs-editor-color-picker-free-text-input",ink:"pdfjs-editor-color-picker-ink-input"})}renderButton(){if(this.#t)return this.#t;const{editorType:t,colorType:e,colorValue:s}=this.#e,i=this.#t=document.createElement("input");return i.type="color",i.value=s||"#000000",i.className="basicColorPicker",i.tabIndex=0,i.setAttribute("data-l10n-id",Fe.#s[t]),i.addEventListener("input",()=>{this.#i.updateParams(e,i.value)},{signal:this.#i._signal}),i}update(t){this.#t&&(this.#t.value=t)}destroy(){this.#t?.remove(),this.#t=null}hideDropdown(){}}function Mi(c){return Math.floor(Math.max(0,Math.min(1,c))*255).toString(16).padStart(2,"0")}function Ce(c){return Math.max(0,Math.min(255,255*c))}class Li{static CMYK_G([t,e,s,i]){return["G",1-Math.min(1,.3*t+.59*s+.11*e+i)]}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=Ce(t),[t,t,t]}static G_HTML([t]){const e=Mi(t);return`#${e}${e}${e}`}static RGB_G([t,e,s]){return["G",.3*t+.59*e+.11*s]}static RGB_rgb(t){return t.map(Ce)}static RGB_HTML(t){return`#${t.map(Mi).join("")}`}static T_HTML(){return"#00000000"}static T_rgb(){return[null]}static CMYK_RGB([t,e,s,i]){return["RGB",1-Math.min(1,t+i),1-Math.min(1,s+i),1-Math.min(1,e+i)]}static CMYK_rgb([t,e,s,i]){return[Ce(1-Math.min(1,t+i)),Ce(1-Math.min(1,s+i)),Ce(1-Math.min(1,e+i))]}static CMYK_HTML(t){const e=this.CMYK_RGB(t).slice(1);return this.RGB_HTML(e)}static RGB_CMYK([t,e,s]){const i=1-t,n=1-e,r=1-s,a=Math.min(i,n,r);return["CMYK",i,n,r,a]}}class Aa{create(t,e,s=!1){if(t<=0||e<=0)throw new Error("Invalid SVG dimensions");const i=this._createSVG("svg:svg");return i.setAttribute("version","1.1"),s||(i.setAttribute("width",`${t}px`),i.setAttribute("height",`${e}px`)),i.setAttribute("preserveAspectRatio","none"),i.setAttribute("viewBox",`0 0 ${t} ${e}`),i}createElement(t){if(typeof t!="string")throw new Error("Invalid SVG element type");return this._createSVG(t)}_createSVG(t){nt("Abstract method `_createSVG` called.")}}class Ne extends Aa{_createSVG(t){return document.createElementNS(Xt,t)}}const wa=9,ne=new WeakSet,va=new Date().getTimezoneOffset()*60*1e3;class Di{static create(t){switch(t.data.annotationType){case ct.LINK:return new ti(t);case ct.TEXT:return new Sa(t);case ct.WIDGET:switch(t.data.fieldType){case"Tx":return new Ea(t);case"Btn":return t.data.radioButton?new yn(t):t.data.checkBox?new xa(t):new Ta(t);case"Ch":return new Pa(t);case"Sig":return new Ca(t)}return new oe(t);case ct.POPUP:return new Ds(t);case ct.FREETEXT:return new An(t);case ct.LINE:return new Ra(t);case ct.SQUARE:return new Ma(t);case ct.CIRCLE:return new La(t);case ct.POLYLINE:return new wn(t);case ct.CARET:return new Ia(t);case ct.INK:return new ei(t);case ct.POLYGON:return new Da(t);case ct.HIGHLIGHT:return new vn(t);case ct.UNDERLINE:return new Fa(t);case ct.SQUIGGLY:return new Na(t);case ct.STRIKEOUT:return new Oa(t);case ct.STAMP:return new _n(t);case ct.FILEATTACHMENT:return new Ba(t);default:return new ht(t)}}}class ht{#t=null;#e=!1;#i=null;constructor(t,{isRenderable:e=!1,ignoreBorder:s=!1,createQuadrilaterals:i=!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.svgFactory=t.svgFactory,this.annotationStorage=t.annotationStorage,this.enableComment=t.enableComment,this.enableScripting=t.enableScripting,this.hasJSActions=t.hasJSActions,this._fieldObjects=t.fieldObjects,this.parent=t.parent,e&&(this.container=this._createContainer(s)),i&&this._createQuadrilaterals()}static _hasPopupData({contentsObj:t,richText:e}){return!!(t?.str||e?.str)}get _isEditable(){return this.data.isEditable}get hasPopupData(){return ht._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:s,rect:i}=this.data;let n=-1/0,r=-1/0;if(e?.length>=8){for(let a=0;a<e.length;a+=8)e[a+1]>r?(r=e[a+1],n=e[a+2]):e[a+1]===r&&(n=Math.max(n,e[a+2]));return[n,r]}if(s?.length>=1){for(const a of s)for(let o=0,l=a.length;o<l;o+=2)a[o+1]>r?(r=a[o+1],n=a[o]):a[o+1]===r&&(n=Math.max(n,a[o]));if(n!==1/0)return[n,r]}return i?[i[2],i[3]]:null}_normalizePoint(t){const{page:{view:e},viewport:{rawDims:{pageWidth:s,pageHeight:i,pageX:n,pageY:r}}}=this.parent;return t[1]=e[3]-t[1]+e[1],t[0]=100*(t[0]-n)/s,t[1]=100*(t[1]-r)/i,t}get commentText(){const{data:t}=this;return this.annotationStorage.getRawValue(`${Me}${t.id}`)?.popup?.contents||t.contentsObj?.str||""}set commentText(t){const{data:e}=this,s={deleted:!t,contents:t||""};this.annotationStorage.updateEditor(e.id,{popup:s})||this.annotationStorage.setValue(`${Me}${e.id}`,{id:e.id,annotationType:e.annotationType,pageIndex:this.parent.page._pageIndex,popup:s,popupRef:e.popupRef,modificationDate:new Date}),t||this.removePopup()}removePopup(){(this.#i?.popup||this.popup)?.remove(),this.#i=this.popup=null}updateEdited(t){if(!this.container)return;t.rect&&(this.#t||={rect:this.data.rect.slice(0)});const{rect:e,popup:s}=t;e&&this.#s(e);let i=this.#i?.popup||this.popup;!i&&s?.text&&(this._createPopup(s),i=this.#i.popup),i&&(i.updateEdited(t),s?.deleted&&(i.remove(),this.#i=null,this.popup=null))}resetEdited(){this.#t&&(this.#s(this.#t.rect),this.#i?.popup.resetEdited(),this.#t=null)}#s(t){const{container:{style:e},data:{rect:s,rotation:i},parent:{viewport:{rawDims:{pageWidth:n,pageHeight:r,pageX:a,pageY:o}}}}=this;s?.splice(0,4,...t),e.left=`${100*(t[0]-a)/n}%`,e.top=`${100*(r-t[3]+o)/r}%`,i===0?(e.width=`${100*(t[2]-t[0])/n}%`,e.height=`${100*(t[3]-t[1])/r}%`):this.setRotation(i)}_createContainer(t){const{data:e,parent:{page:s,viewport:i}}=this,n=document.createElement("section");n.setAttribute("data-annotation-id",e.id),!(this instanceof oe)&&!(this instanceof ti)&&(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 Ds){const{rotation:p}=e;return!e.hasOwnCanvas&&p!==0&&this.setRotation(p,n),n}const{width:a,height:o}=this;if(!t&&e.borderStyle.width>0){r.borderWidth=`${e.borderStyle.width}px`;const p=e.borderStyle.horizontalCornerRadius,b=e.borderStyle.verticalCornerRadius;if(p>0||b>0){const y=`calc(${p}px * var(--total-scale-factor)) / calc(${b}px * var(--total-scale-factor))`;r.borderRadius=y}else if(this instanceof yn){const y=`calc(${a}px * var(--total-scale-factor)) / calc(${o}px * var(--total-scale-factor))`;r.borderRadius=y}switch(e.borderStyle.style){case ce.SOLID:r.borderStyle="solid";break;case ce.DASHED:r.borderStyle="dashed";break;case ce.BEVELED:W("Unimplemented border style: beveled");break;case ce.INSET:W("Unimplemented border style: inset");break;case ce.UNDERLINE:r.borderBottomStyle="solid";break}const m=e.borderColor||null;m?(this.#e=!0,r.borderColor=I.makeHexColor(m[0]|0,m[1]|0,m[2]|0)):r.borderWidth=0}const l=I.normalizeRect([e.rect[0],s.view[3]-e.rect[1]+s.view[1],e.rect[2],s.view[3]-e.rect[3]+s.view[1]]),{pageWidth:h,pageHeight:d,pageX:u,pageY:f}=i.rawDims;r.left=`${100*(l[0]-u)/h}%`,r.top=`${100*(l[1]-f)/d}%`;const{rotation:g}=e;return e.hasOwnCanvas||g===0?(r.width=`${100*a/h}%`,r.height=`${100*o/d}%`):this.setRotation(g,n),n}setRotation(t,e=this.container){if(!this.data.rect)return;const{pageWidth:s,pageHeight:i}=this.parent.viewport.rawDims;let{width:n,height:r}=this;t%180!==0&&([n,r]=[r,n]),e.style.width=`${100*n/s}%`,e.style.height=`${100*r/i}%`,e.setAttribute("data-main-rotation",(360-t)%360)}get _commonActions(){const t=(e,s,i)=>{const n=i.detail[e],r=n[0],a=n.slice(1);i.target.style[s]=Li[`${r}_HTML`](a),this.annotationStorage.setValue(this.data.id,{[s]:Li[`${r}_rgb`](a)})};return Y(this,"_commonActions",{display:e=>{const{display:s}=e.detail,i=s%2===1;this.container.style.visibility=i?"hidden":"visible",this.annotationStorage.setValue(this.data.id,{noView:i,noPrint:s===1||s===2})},print:e=>{this.annotationStorage.setValue(this.data.id,{noPrint:!e.detail.print})},hidden:e=>{const{hidden:s}=e.detail;this.container.style.visibility=s?"hidden":"visible",this.annotationStorage.setValue(this.data.id,{noPrint:s,noView:s})},focus:e=>{setTimeout(()=>e.target.focus({preventScroll:!1}),0)},userName:e=>{e.target.title=e.detail.userName},readonly:e=>{e.target.disabled=e.detail.readonly},required:e=>{this._setRequired(e.target,e.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:e=>{const s=e.detail.rotation;this.setRotation(s),this.annotationStorage.setValue(this.data.id,{rotation:s})}})}_dispatchEventFromSandbox(t,e){const s=this._commonActions;for(const i of Object.keys(e.detail))(t[i]||s[i])?.(e)}_setDefaultPropertiesFromJS(t){if(!this.enableScripting)return;const e=this.annotationStorage.getRawValue(this.data.id);if(!e)return;const s=this._commonActions;for(const[i,n]of Object.entries(e)){const r=s[i];if(r){const a={detail:{[i]:n},target:t};r(a),delete e[i]}}}_createQuadrilaterals(){if(!this.container)return;const{quadPoints:t}=this.data;if(!t)return;const[e,s,i,n]=this.data.rect.map(p=>Math.fround(p));if(t.length===8){const[p,b,m,y]=t.subarray(2,6);if(i===p&&n===b&&e===m&&s===y)return}const{style:r}=this.container;let a;if(this.#e){const{borderColor:p,borderWidth:b}=r;r.borderWidth=0,a=["url('data:image/svg+xml;utf8,",'<svg xmlns="http://www.w3.org/2000/svg"',' preserveAspectRatio="none" viewBox="0 0 1 1">',`<g fill="transparent" stroke="${p}" stroke-width="${b}">`],this.container.classList.add("hasBorder")}const o=i-e,l=n-s,{svgFactory:h}=this,d=h.createElement("svg");d.classList.add("quadrilateralsContainer"),d.setAttribute("width",0),d.setAttribute("height",0),d.role="none";const u=h.createElement("defs");d.append(u);const f=h.createElement("clipPath"),g=`clippath_${this.data.id}`;f.setAttribute("id",g),f.setAttribute("clipPathUnits","objectBoundingBox"),u.append(f);for(let p=2,b=t.length;p<b;p+=8){const m=t[p],y=t[p+1],A=t[p+2],v=t[p+3],w=h.createElement("rect"),_=(A-e)/o,S=(n-y)/l,E=(m-A)/o,C=(y-v)/l;w.setAttribute("x",_),w.setAttribute("y",S),w.setAttribute("width",E),w.setAttribute("height",C),f.append(w),a?.push(`<rect vector-effect="non-scaling-stroke" x="${_}" y="${S}" width="${E}" height="${C}"/>`)}this.#e&&(a.push("</g></svg>')"),r.backgroundImage=a.join("")),this.container.append(d),this.container.style.clipPath=`url(#${g})`}_createPopup(t=null){const{data:e}=this;let s,i;t?(s={str:t.text},i=t.date):(s=e.contentsObj,i=e.modificationDate);const n=this.#i=new Ds({data:{color:e.color,titleObj:e.titleObj,modificationDate:i,contentsObj:s,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]});this.parent._commentManager||this.parent.div.append(n.render())}get hasPopupElement(){return!!(this.#i||this.popup||this.data.popupRef)}get extraPopupElement(){return this.#i}render(){nt("Abstract method `AnnotationElement.render` called")}_getElementsByName(t,e=null){const s=[];if(this._fieldObjects){const i=this._fieldObjects[t];if(i)for(const{page:n,id:r,exportValues:a}of i){if(n===-1||r===e)continue;const o=typeof a=="string"?a:null,l=document.querySelector(`[data-element-id="${r}"]`);if(l&&!ne.has(l)){W(`_getElementsByName - element not allowed: ${r}`);continue}s.push({id:r,exportValue:o,domElement:l})}return s}for(const i of document.getElementsByName(t)){const{exportValue:n}=i,r=i.getAttribute("data-element-id");r!==e&&ne.has(i)&&s.push({id:r,exportValue:n,domElement:i})}return s}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})})}get width(){return this.data.rect[2]-this.data.rect[0]}get height(){return this.data.rect[3]-this.data.rect[1]}}class _a extends ht{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),this.extraPopupElement.popup.renderCommentButton())}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.container.remove(),this.container=null,this.removePopup()}}class ti extends ht{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,s=document.createElement("a");s.setAttribute("data-element-id",t.id);let i=!1;return t.url?(e.addLinkAttributes(s,t.url,t.newWindow),i=!0):t.action?(this._bindNamedAction(s,t.action,t.overlaidText),i=!0):t.attachment?(this.#e(s,t.attachment,t.overlaidText,t.attachmentDest),i=!0):t.setOCGState?(this.#i(s,t.setOCGState,t.overlaidText),i=!0):t.dest?(this._bindLink(s,t.dest,t.overlaidText),i=!0):(t.actions&&(t.actions.Action||t.actions["Mouse Up"]||t.actions["Mouse Down"])&&this.enableScripting&&this.hasJSActions&&(this._bindJSAction(s,t),i=!0),t.resetForm?(this._bindResetFormAction(s,t.resetForm),i=!0):this.isTooltipOnly&&!i&&(this._bindLink(s,""),i=!0)),this.container.classList.add("linkAnnotation"),i&&this.container.append(s),this.container}#t(){this.container.setAttribute("data-internal-link","")}_bindLink(t,e,s=""){t.href=this.linkService.getDestinationHash(e),t.onclick=()=>(e&&this.linkService.goToDestination(e),!1),(e||e==="")&&this.#t(),s&&(t.title=s)}_bindNamedAction(t,e,s=""){t.href=this.linkService.getAnchorUrl(""),t.onclick=()=>(this.linkService.executeNamedAction(e),!1),s&&(t.title=s),this.#t()}#e(t,e,s="",i=null){t.href=this.linkService.getAnchorUrl(""),e.description?t.title=e.description:s&&(t.title=s),t.onclick=()=>(this.downloadManager?.openOrDownloadData(e.content,e.filename,i),!1),this.#t()}#i(t,e,s=""){t.href=this.linkService.getAnchorUrl(""),t.onclick=()=>(this.linkService.executeSetOCGState(e),!1),s&&(t.title=s),this.#t()}_bindJSAction(t,e){t.href=this.linkService.getAnchorUrl("");const s=new Map([["Action","onclick"],["Mouse Up","onmouseup"],["Mouse Down","onmousedown"]]);for(const i of Object.keys(e.actions)){const n=s.get(i);n&&(t[n]=()=>(this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e.id,name:i}}),!1))}e.overlaidText&&(t.title=e.overlaidText),t.onclick||(t.onclick=()=>!1),this.#t()}_bindResetFormAction(t,e){const s=t.onclick;if(s||(t.href=this.linkService.getAnchorUrl("")),this.#t(),!this._fieldObjects){W('_bindResetFormAction - "resetForm" action not supported, ensure that the `fieldObjects` parameter is provided.'),s||(t.onclick=()=>!1);return}t.onclick=()=>{s?.();const{fields:i,refs:n,include:r}=e,a=[];if(i.length!==0||n.length!==0){const h=new Set(n);for(const d of i){const u=this._fieldObjects[d]||[];for(const{id:f}of u)h.add(f)}for(const d of Object.values(this._fieldObjects))for(const u of d)h.has(u.id)===r&&a.push(u)}else for(const h of Object.values(this._fieldObjects))a.push(...h);const o=this.annotationStorage,l=[];for(const h of a){const{id:d}=h;switch(l.push(d),h.type){case"text":{const f=h.defaultValue||"";o.setValue(d,{value:f});break}case"checkbox":case"radiobutton":{const f=h.defaultValue===h.exportValues;o.setValue(d,{value:f});break}case"combobox":case"listbox":{const f=h.defaultValue||"";o.setValue(d,{value:f});break}default:continue}const u=document.querySelector(`[data-element-id="${d}"]`);if(u){if(!ne.has(u)){W(`_bindResetFormAction - element not allowed: ${d}`);continue}}else continue;u.dispatchEvent(new Event("resetform"))}return this.enableScripting&&this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:"app",ids:l,name:"ResetForm"}}),!1}}}class Sa extends ht{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._createPopup(),this.container.append(t),this.container}}class oe extends ht{render(){return this.container}showElementAndHideCanvas(t){this.data.hasOwnCanvas&&(t.previousSibling?.nodeName==="CANVAS"&&(t.previousSibling.hidden=!0),t.hidden=!1)}_getKeyModifier(t){return bt.platform.isMac?t.metaKey:t.ctrlKey}_setEventListener(t,e,s,i,n){s.includes("mouse")?t.addEventListener(s,r=>{this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:this.data.id,name:i,value:n(r),shift:r.shiftKey,modifier:this._getKeyModifier(r)}})}):t.addEventListener(s,r=>{if(s==="blur"){if(!e.focused||!r.relatedTarget)return;e.focused=!1}else if(s==="focus"){if(e.focused)return;e.focused=!0}n&&this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:this.data.id,name:i,value:n(r)}})})}_setEventListeners(t,e,s,i){for(const[n,r]of s)(r==="Action"||this.data.actions?.[r])&&((r==="Focus"||r==="Blur")&&(e||={focused:!1}),this._setEventListener(t,e,n,r,i),r==="Focus"&&!this.data.actions?.Blur?this._setEventListener(t,e,"blur","Blur",null):r==="Blur"&&!this.data.actions?.Focus&&this._setEventListener(t,e,"focus","Focus",null))}_setBackgroundColor(t){const e=this.data.backgroundColor||null;t.style.backgroundColor=e===null?"transparent":I.makeHexColor(e[0],e[1],e[2])}_setTextStyle(t){const e=["left","center","right"],{fontColor:s}=this.data.defaultAppearanceData,i=this.data.defaultAppearanceData.fontSize||wa,n=t.style;let r;const a=2,o=l=>Math.round(10*l)/10;if(this.data.multiLine){const l=Math.abs(this.data.rect[3]-this.data.rect[1]-a),h=Math.round(l/(As*i))||1,d=l/h;r=Math.min(i,o(d/As))}else{const l=Math.abs(this.data.rect[3]-this.data.rect[1]-a);r=Math.min(i,o(l/As))}n.fontSize=`calc(${r}px * var(--total-scale-factor))`,n.color=I.makeHexColor(s[0],s[1],s[2]),this.data.textAlignment!==null&&(n.textAlign=e[this.data.textAlignment])}_setRequired(t,e){e?t.setAttribute("required",!0):t.removeAttribute("required"),t.setAttribute("aria-required",e)}}class Ea extends oe{constructor(t){const e=t.renderForms||t.data.hasOwnCanvas||!t.data.hasAppearance&&!!t.data.fieldValue;super(t,{isRenderable:e})}setPropertyOnSiblings(t,e,s,i){const n=this.annotationStorage;for(const r of this._getElementsByName(t.name,t.id))r.domElement&&(r.domElement[e]=s),n.setValue(r.id,{[i]:s})}render(){const t=this.annotationStorage,e=this.data.id;this.container.classList.add("textWidgetAnnotation");let s=null;if(this.renderForms){const i=t.getValue(e,{value:this.data.fieldValue});let n=i.value||"";const r=t.getValue(e,{charLimit:this.data.maxLen}).charLimit;r&&n.length>r&&(n=n.slice(0,r));let a=i.formattedValue||this.data.textContent?.join(`
3
3
  `)||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?(s=document.createElement("textarea"),s.textContent=a??n,this.data.doNotScroll&&(s.style.overflowY="hidden")):(s=document.createElement("input"),s.type=this.data.password?"password":"text",s.setAttribute("value",a??n),this.data.doNotScroll&&(s.style.overflowX="hidden")),this.data.hasOwnCanvas&&(s.hidden=!0),ne.add(s),s.setAttribute("data-element-id",e),s.disabled=this.data.readOnly,s.name=this.data.fieldName,s.tabIndex=0;const{datetimeFormat:l,datetimeType:h,timeStep:d}=this.data,u=!!h&&this.enableScripting;l&&(s.title=l),this._setRequired(s,this.data.required),r&&(s.maxLength=r),s.addEventListener("input",g=>{t.setValue(e,{value:g.target.value}),this.setPropertyOnSiblings(s,"value",g.target.value,"value"),o.formattedValue=null}),s.addEventListener("resetform",g=>{const p=this.data.defaultFieldValue??"";s.value=o.userValue=p,o.formattedValue=null});let f=g=>{const{formattedValue:p}=o;p!=null&&(g.target.value=p),g.target.scrollLeft=0};if(this.enableScripting&&this.hasJSActions){s.addEventListener("focus",p=>{if(o.focused)return;const{target:b}=p;if(u&&(b.type=h,d&&(b.step=d)),o.userValue){const m=o.userValue;if(u)if(h==="time"){const y=new Date(m),A=[y.getHours(),y.getMinutes(),y.getSeconds()];b.value=A.map(v=>v.toString().padStart(2,"0")).join(":")}else b.value=new Date(m-va).toISOString().split(h==="date"?"T":".",1)[0];else b.value=m}o.lastCommittedValue=b.value,o.commitKey=1,this.data.actions?.Focus||(o.focused=!0)}),s.addEventListener("updatefromsandbox",p=>{this.showElementAndHideCanvas(p.target);const b={value(m){o.userValue=m.detail.value??"",u||t.setValue(e,{value:o.userValue.toString()}),m.target.value=o.userValue},formattedValue(m){const{formattedValue:y}=m.detail;o.formattedValue=y,y!=null&&m.target!==document.activeElement&&(m.target.value=y);const A={formattedValue:y};u&&(A.value=y),t.setValue(e,A)},selRange(m){m.target.setSelectionRange(...m.detail.selRange)},charLimit:m=>{const{charLimit:y}=m.detail,{target:A}=m;if(y===0){A.removeAttribute("maxLength");return}A.setAttribute("maxLength",y);let v=o.userValue;!v||v.length<=y||(v=v.slice(0,y),A.value=o.userValue=v,t.setValue(e,{value:v}),this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:v,willCommit:!0,commitKey:1,selStart:A.selectionStart,selEnd:A.selectionEnd}}))}};this._dispatchEventFromSandbox(b,p)}),s.addEventListener("keydown",p=>{o.commitKey=1;let b=-1;if(p.key==="Escape"?b=0:p.key==="Enter"&&!this.data.multiLine?b=2:p.key==="Tab"&&(o.commitKey=3),b===-1)return;const{value:m}=p.target;o.lastCommittedValue!==m&&(o.lastCommittedValue=m,o.userValue=m,this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:m,willCommit:!0,commitKey:b,selStart:p.target.selectionStart,selEnd:p.target.selectionEnd}}))});const g=f;f=null,s.addEventListener("blur",p=>{if(!o.focused||!p.relatedTarget)return;this.data.actions?.Blur||(o.focused=!1);const{target:b}=p;let{value:m}=b;if(u){if(m&&h==="time"){const y=m.split(":").map(A=>parseInt(A,10));m=new Date(2e3,0,1,y[0],y[1],y[2]||0).valueOf(),b.step=""}else m.includes("T")||(m=`${m}T00:00`),m=new Date(m).valueOf();b.type="text"}o.userValue=m,o.lastCommittedValue!==m&&this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:m,willCommit:!0,commitKey:o.commitKey,selStart:p.target.selectionStart,selEnd:p.target.selectionEnd}}),g(p)}),this.data.actions?.Keystroke&&s.addEventListener("beforeinput",p=>{o.lastCommittedValue=null;const{data:b,target:m}=p,{value:y,selectionStart:A,selectionEnd:v}=m;let w=A,_=v;switch(p.inputType){case"deleteWordBackward":{const S=y.substring(0,A).match(/\w*[^\w]*$/);S&&(w-=S[0].length);break}case"deleteWordForward":{const S=y.substring(A).match(/^[^\w]*\w*/);S&&(_+=S[0].length);break}case"deleteContentBackward":A===v&&(w-=1);break;case"deleteContentForward":A===v&&(_+=1);break}p.preventDefault(),this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:y,change:b||"",willCommit:!1,selStart:w,selEnd:_}})}),this._setEventListeners(s,o,[["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],p=>p.target.value)}if(f&&s.addEventListener("blur",f),this.data.comb){const p=(this.data.rect[2]-this.data.rect[0])/r;s.classList.add("comb"),s.style.letterSpacing=`calc(${p}px * var(--total-scale-factor) - 1ch)`}}else s=document.createElement("div"),s.textContent=this.data.fieldValue,s.style.verticalAlign="middle",s.style.display="table-cell",this.data.hasOwnCanvas&&(s.hidden=!0);return this._setTextStyle(s),this._setBackgroundColor(s),this._setDefaultPropertiesFromJS(s),this.container.append(s),this.container}}class Ca extends oe{constructor(t){super(t,{isRenderable:!!t.data.hasOwnCanvas})}}class xa extends oe{constructor(t){super(t,{isRenderable:t.renderForms})}render(){const t=this.annotationStorage,e=this.data,s=e.id;let i=t.getValue(s,{value:e.exportValue===e.fieldValue}).value;typeof i=="string"&&(i=i!=="Off",t.setValue(s,{value:i})),this.container.classList.add("buttonWidgetAnnotation","checkBox");const n=document.createElement("input");return ne.add(n),n.setAttribute("data-element-id",s),n.disabled=e.readOnly,this._setRequired(n,this.data.required),n.type="checkbox",n.name=e.fieldName,i&&n.setAttribute("checked",!0),n.setAttribute("exportValue",e.exportValue),n.tabIndex=0,n.addEventListener("change",r=>{const{name:a,checked:o}=r.target;for(const l of this._getElementsByName(a,s)){const h=o&&l.exportValue===e.exportValue;l.domElement&&(l.domElement.checked=h),t.setValue(l.id,{value:h})}t.setValue(s,{value:o})}),n.addEventListener("resetform",r=>{const a=e.defaultFieldValue||"Off";r.target.checked=a===e.exportValue}),this.enableScripting&&this.hasJSActions&&(n.addEventListener("updatefromsandbox",r=>{const a={value(o){o.target.checked=o.detail.value!=="Off",t.setValue(s,{value:o.target.checked})}};this._dispatchEventFromSandbox(a,r)}),this._setEventListeners(n,null,[["change","Validate"],["change","Action"],["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],r=>r.target.checked)),this._setBackgroundColor(n),this._setDefaultPropertiesFromJS(n),this.container.append(n),this.container}}class yn extends oe{constructor(t){super(t,{isRenderable:t.renderForms})}render(){this.container.classList.add("buttonWidgetAnnotation","radioButton");const t=this.annotationStorage,e=this.data,s=e.id;let i=t.getValue(s,{value:e.fieldValue===e.buttonValue}).value;if(typeof i=="string"&&(i=i!==e.buttonValue,t.setValue(s,{value:i})),i)for(const r of this._getElementsByName(e.fieldName,s))t.setValue(r.id,{value:!1});const n=document.createElement("input");if(ne.add(n),n.setAttribute("data-element-id",s),n.disabled=e.readOnly,this._setRequired(n,this.data.required),n.type="radio",n.name=e.fieldName,i&&n.setAttribute("checked",!0),n.tabIndex=0,n.addEventListener("change",r=>{const{name:a,checked:o}=r.target;for(const l of this._getElementsByName(a,s))t.setValue(l.id,{value:!1});t.setValue(s,{value:o})}),n.addEventListener("resetform",r=>{const a=e.defaultFieldValue;r.target.checked=a!=null&&a===e.buttonValue}),this.enableScripting&&this.hasJSActions){const r=e.buttonValue;n.addEventListener("updatefromsandbox",a=>{const o={value:l=>{const h=r===l.detail.value;for(const d of this._getElementsByName(l.target.name)){const u=h&&d.id===s;d.domElement&&(d.domElement.checked=u),t.setValue(d.id,{value:u})}}};this._dispatchEventFromSandbox(o,a)}),this._setEventListeners(n,null,[["change","Validate"],["change","Action"],["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],a=>a.target.checked)}return this._setBackgroundColor(n),this._setDefaultPropertiesFromJS(n),this.container.append(n),this.container}}class Ta extends ti{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",s=>{this._dispatchEventFromSandbox({},s)})),t}}class Pa extends oe{constructor(t){super(t,{isRenderable:t.renderForms})}render(){this.container.classList.add("choiceWidgetAnnotation");const t=this.annotationStorage,e=this.data.id,s=t.getValue(e,{value:this.data.fieldValue}),i=document.createElement("select");ne.add(i),i.setAttribute("data-element-id",e),i.disabled=this.data.readOnly,this._setRequired(i,this.data.required),i.name=this.data.fieldName,i.tabIndex=0;let n=this.data.combo&&this.data.options.length>0;this.data.combo||(i.size=this.data.options.length,this.data.multiSelect&&(i.multiple=!0)),i.addEventListener("resetform",h=>{const d=this.data.defaultFieldValue;for(const u of i.options)u.selected=u.value===d});for(const h of this.data.options){const d=document.createElement("option");d.textContent=h.displayValue,d.value=h.exportValue,s.value.includes(h.exportValue)&&(d.setAttribute("selected",!0),n=!1),i.append(d)}let r=null;if(n){const h=document.createElement("option");h.value=" ",h.setAttribute("hidden",!0),h.setAttribute("selected",!0),i.prepend(h),r=()=>{h.remove(),i.removeEventListener("input",r),r=null},i.addEventListener("input",r)}const a=h=>{const d=h?"value":"textContent",{options:u,multiple:f}=i;return f?Array.prototype.filter.call(u,g=>g.selected).map(g=>g[d]):u.selectedIndex===-1?null:u[u.selectedIndex][d]};let o=a(!1);const l=h=>{const d=h.target.options;return Array.prototype.map.call(d,u=>({displayValue:u.textContent,exportValue:u.value}))};return this.enableScripting&&this.hasJSActions?(i.addEventListener("updatefromsandbox",h=>{const d={value(u){r?.();const f=u.detail.value,g=new Set(Array.isArray(f)?f:[f]);for(const p of i.options)p.selected=g.has(p.value);t.setValue(e,{value:a(!0)}),o=a(!1)},multipleSelection(u){i.multiple=!0},remove(u){const f=i.options,g=u.detail.remove;f[g].selected=!1,i.remove(g),f.length>0&&Array.prototype.findIndex.call(f,b=>b.selected)===-1&&(f[0].selected=!0),t.setValue(e,{value:a(!0),items:l(u)}),o=a(!1)},clear(u){for(;i.length!==0;)i.remove(0);t.setValue(e,{value:null,items:[]}),o=a(!1)},insert(u){const{index:f,displayValue:g,exportValue:p}=u.detail.insert,b=i.children[f],m=document.createElement("option");m.textContent=g,m.value=p,b?b.before(m):i.append(m),t.setValue(e,{value:a(!0),items:l(u)}),o=a(!1)},items(u){const{items:f}=u.detail;for(;i.length!==0;)i.remove(0);for(const g of f){const{displayValue:p,exportValue:b}=g,m=document.createElement("option");m.textContent=p,m.value=b,i.append(m)}i.options.length>0&&(i.options[0].selected=!0),t.setValue(e,{value:a(!0),items:l(u)}),o=a(!1)},indices(u){const f=new Set(u.detail.indices);for(const g of u.target.options)g.selected=f.has(g.index);t.setValue(e,{value:a(!0)}),o=a(!1)},editable(u){u.target.disabled=!u.detail.editable}};this._dispatchEventFromSandbox(d,h)}),i.addEventListener("input",h=>{const d=a(!0),u=a(!1);t.setValue(e,{value:d}),h.preventDefault(),this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:o,change:u,changeEx:d,willCommit:!1,commitKey:1,keyDown:!1}})}),this._setEventListeners(i,null,[["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"],["input","Action"],["input","Validate"]],h=>h.target.value)):i.addEventListener("input",function(h){t.setValue(e,{value:a(!0)})}),this.data.combo&&this._setTextStyle(i),this._setBackgroundColor(i),this._setDefaultPropertiesFromJS(i),this.container.append(i),this.container}}class Ds extends ht{constructor(t){const{data:e,elements:s,parent:i}=t,n=!!i._commentManager;if(super(t,{isRenderable:!n&&ht._hasPopupData(e)}),this.elements=s,n&&ht._hasPopupData(e)){const r=this.popup=this.#t();for(const a of s)a.popup=r}else this.popup=null}#t(){return new ka({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.#t(),s=[];for(const i of this.elements)i.popup=e,i.container.ariaHasPopup="dialog",s.push(i.data.id),i.addHighlightArea();return this.container.setAttribute("aria-controls",s.map(i=>`${$s}${i}`).join(",")),this.container}}class ka{#t=null;#e=this.#z.bind(this);#i=this.#H.bind(this);#s=this.#D.bind(this);#a=this.#v.bind(this);#n=null;#r=null;#o=null;#h=null;#l=null;#u=null;#d=null;#f=!1;#m=null;#p=null;#c=null;#g=null;#b=null;#A=null;#y=null;#C=null;#S=null;#w=null;#T=!1;#_=null;#E=null;constructor({container:t,color:e,elements:s,titleObj:i,modificationDate:n,contentsObj:r,richText:a,parent:o,rect:l,parentRect:h,open:d,commentManager:u=null}){this.#r=t,this.#S=i,this.#o=r,this.#C=a,this.#u=o,this.#n=e,this.#y=l,this.#d=h,this.#l=s,this.#t=u,this.#_=s[0],this.#h=ns.toDateObject(n),this.trigger=s.flatMap(f=>f.getElementsToTriggerPopup()),u?this.renderCommentButton():(this.#R(),this.#r.hidden=!0,d&&this.#v())}#R(){if(this.#p)return;this.#p=new AbortController;const{signal:t}=this.#p;for(const e of this.trigger)e.addEventListener("click",this.#a,{signal:t}),e.addEventListener("pointerenter",this.#s,{signal:t}),e.addEventListener("pointerleave",this.#i,{signal:t}),e.classList.add("popupTriggerArea");for(const e of this.#l)e.container?.addEventListener("keydown",this.#e,{signal:t})}#P(){const t=this.#l.find(e=>e.hasCommentButton);t&&(this.#b=t._normalizePoint(t.commentButtonPosition))}renderCommentButton(){if(this.#g||(this.#b||this.#P(),!this.#b))return;const{signal:t}=this.#p=new AbortController,e=!!this.#_.extraPopupElement,s=()=>{this.#t.toggleCommentPopup(this,!0,void 0,!e)},i=()=>{this.#t.toggleCommentPopup(this,!1,!0,!e)},n=()=>{this.#t.toggleCommentPopup(this,!1,!1)};if(e){this.#g=this.#_.container;for(const r of this.trigger)r.ariaHasPopup="dialog",r.ariaControls="commentPopup",r.addEventListener("keydown",this.#e,{signal:t}),r.addEventListener("click",s,{signal:t}),r.addEventListener("pointerenter",i,{signal:t}),r.addEventListener("pointerleave",n,{signal:t}),r.classList.add("popupTriggerArea")}else{const r=this.#g=document.createElement("button");r.className="annotationCommentButton";const a=this.#_.container;r.style.zIndex=a.style.zIndex+1,r.tabIndex=0,r.ariaHasPopup="dialog",r.ariaControls="commentPopup",r.setAttribute("data-l10n-id","pdfjs-show-comment-button"),this.#O(),this.#k(),r.addEventListener("keydown",this.#e,{signal:t}),r.addEventListener("click",s,{signal:t}),r.addEventListener("pointerenter",i,{signal:t}),r.addEventListener("pointerleave",n,{signal:t}),a.after(r)}}#k(){if(this.#_.extraPopupElement&&!this.#_.editor)return;this.renderCommentButton();const[t,e]=this.#b,{style:s}=this.#g;s.left=`calc(${t}%)`,s.top=`calc(${e}% - var(--comment-button-dim))`}#O(){this.#_.extraPopupElement||(this.renderCommentButton(),this.#g.style.backgroundColor=this.commentButtonColor||"")}get commentButtonColor(){const{color:t,opacity:e}=this.#_.commentData;return t?this.#u._commentManager.makeCommentColor(t,e):null}focusCommentButton(){setTimeout(()=>{this.#g?.focus()},0)}getData(){const{richText:t,color:e,opacity:s,creationDate:i,modificationDate:n}=this.#_.commentData;return{contentsObj:{str:this.comment},richText:t,color:e,opacity:s,creationDate:i,modificationDate:n}}get elementBeforePopup(){return this.#g}get comment(){return this.#E||=this.#_.commentText,this.#E}set comment(t){t!==this.comment&&(this.#_.commentText=this.#E=t)}get parentBoundingClientRect(){return this.#_.layer.getBoundingClientRect()}setCommentButtonStates({selected:t,hasPopup:e}){this.#g&&(this.#g.classList.toggle("selected",t),this.#g.ariaExpanded=e)}setSelectedCommentButton(t){this.#g.classList.toggle("selected",t)}get commentPopupPosition(){if(this.#A)return this.#A;const{x:t,y:e,height:s}=this.#g.getBoundingClientRect(),{x:i,y:n,width:r,height:a}=this.#_.layer.getBoundingClientRect();return[(t-i)/r,(e+s-n)/a]}set commentPopupPosition(t){this.#A=t}hasDefaultPopupPosition(){return this.#A===null}get commentButtonPosition(){return this.#b}get commentButtonWidth(){return this.#g.getBoundingClientRect().width/this.parentBoundingClientRect.width}editComment(t){const[e,s]=this.#A||this.commentButtonPosition.map(l=>l/100),i=this.parentBoundingClientRect,{x:n,y:r,width:a,height:o}=i;this.#t.showDialog(null,this,n+e*a,r+s*o,{...t,parentDimensions:i})}render(){if(this.#m)return;const t=this.#m=document.createElement("div");if(t.className="popup",this.#n){const s=t.style.outlineColor=I.makeHexColor(...this.#n);t.style.backgroundColor=`color-mix(in srgb, ${s} 30%, white)`}const e=document.createElement("span");if(e.className="header",this.#S?.str){const s=document.createElement("span");s.className="title",e.append(s),{dir:s.dir,str:s.textContent}=this.#S}if(t.append(e),this.#h){const s=document.createElement("time");s.className="popupDate",s.setAttribute("data-l10n-id","pdfjs-annotation-date-time-string"),s.setAttribute("data-l10n-args",JSON.stringify({dateObj:this.#h.valueOf()})),s.dateTime=this.#h.toISOString(),e.append(s)}zs({html:this.#L||this.#o.str,dir:this.#o?.dir,className:"popupContent"},t),this.#r.append(t)}get#L(){const t=this.#C,e=this.#o;return t?.str&&(!e?.str||e.str===t.str)&&this.#C.html||null}get#I(){return this.#L?.attributes?.style?.fontSize||0}get#B(){return this.#L?.attributes?.style?.color||null}#F(t){const e=[],s={str:t,html:{name:"div",attributes:{dir:"auto"},children:[{name:"p",children:e}]}},i={style:{color:this.#B,fontSize:this.#I?`calc(${this.#I}px * var(--total-scale-factor))`:""}};for(const n of t.split(`
4
4
  `))e.push({name:"span",value:n,attributes:i});return s}#z(t){t.altKey||t.shiftKey||t.ctrlKey||t.metaKey||(t.key==="Enter"||t.key==="Escape"&&this.#f)&&this.#v()}updateEdited({rect:t,popup:e,deleted:s}){if(this.#t){s?(this.remove(),this.#E=null):e&&(e.deleted?this.remove():(this.#O(),this.#E=e.text)),t&&(this.#b=null,this.#P(),this.#k());return}if(s||e?.deleted){this.remove();return}this.#R(),this.#w||={contentsObj:this.#o,richText:this.#C},t&&(this.#c=null),e&&e.text&&(this.#C=this.#F(e.text),this.#h=ns.toDateObject(e.date),this.#o=null),this.#m?.remove(),this.#m=null}resetEdited(){this.#w&&({contentsObj:this.#o,richText:this.#C}=this.#w,this.#w=null,this.#m?.remove(),this.#m=null,this.#c=null)}remove(){if(this.#p?.abort(),this.#p=null,this.#m?.remove(),this.#m=null,this.#T=!1,this.#f=!1,this.#g?.remove(),this.#g=null,this.trigger)for(const t of this.trigger)t.classList.remove("popupTriggerArea")}#x(){if(this.#c!==null)return;const{page:{view:t},viewport:{rawDims:{pageWidth:e,pageHeight:s,pageX:i,pageY:n}}}=this.#u;let r=!!this.#d,a=r?this.#d:this.#y;for(const g of this.#l)if(!a||I.intersect(g.data.rect,a)!==null){a=g.data.rect,r=!0;break}const o=I.normalizeRect([a[0],t[3]-a[1]+t[1],a[2],t[3]-a[3]+t[1]]),h=r?a[2]-a[0]+5:0,d=o[0]+h,u=o[1];this.#c=[100*(d-i)/e,100*(u-n)/s];const{style:f}=this.#r;f.left=`${this.#c[0]}%`,f.top=`${this.#c[1]}%`}#v(){if(this.#t){this.#t.toggleCommentPopup(this,!1);return}this.#f=!this.#f,this.#f?(this.#D(),this.#r.addEventListener("click",this.#a),this.#r.addEventListener("keydown",this.#e)):(this.#H(),this.#r.removeEventListener("click",this.#a),this.#r.removeEventListener("keydown",this.#e))}#D(){this.#m||this.render(),this.isVisible?this.#f&&this.#r.classList.add("focused"):(this.#x(),this.#r.hidden=!1,this.#r.style.zIndex=parseInt(this.#r.style.zIndex)+1e3)}#H(){this.#r.classList.remove("focused"),!(this.#f||!this.isVisible)&&(this.#r.hidden=!0,this.#r.style.zIndex=parseInt(this.#r.style.zIndex)-1e3)}forceHide(){this.#T=this.isVisible,this.#T&&(this.#r.hidden=!0)}maybeShow(){this.#t||(this.#R(),this.#T&&(this.#m||this.#D(),this.#T=!1,this.#r.hidden=!1))}get isVisible(){return this.#t?!1:this.#r.hidden===!1}}class An extends ht{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.textContent=t.data.textContent,this.textPosition=t.data.textPosition,this.annotationEditorType=V.FREETEXT}render(){if(this.container.classList.add("freeTextAnnotation"),this.textContent){const t=document.createElement("div");t.classList.add("annotationTextContent"),t.setAttribute("role","comment");for(const e of this.textContent){const s=document.createElement("span");s.textContent=e,t.append(s)}this.container.append(t)}return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this._editOnDoubleClick(),this.container}}class Ra extends ht{#t=null;constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){this.container.classList.add("lineAnnotation");const{data:t,width:e,height:s}=this,i=this.svgFactory.create(e,s,!0),n=this.#t=this.svgFactory.createElement("svg:line");return n.setAttribute("x1",t.rect[2]-t.lineCoordinates[0]),n.setAttribute("y1",t.rect[3]-t.lineCoordinates[1]),n.setAttribute("x2",t.rect[2]-t.lineCoordinates[2]),n.setAttribute("y2",t.rect[3]-t.lineCoordinates[3]),n.setAttribute("stroke-width",t.borderStyle.width||1),n.setAttribute("stroke","transparent"),n.setAttribute("fill","transparent"),i.append(n),this.container.append(i),!t.popupRef&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return this.#t}addHighlightArea(){this.container.classList.add("highlightArea")}}class Ma extends ht{#t=null;constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){this.container.classList.add("squareAnnotation");const{data:t,width:e,height:s}=this,i=this.svgFactory.create(e,s,!0),n=t.borderStyle.width,r=this.#t=this.svgFactory.createElement("svg:rect");return r.setAttribute("x",n/2),r.setAttribute("y",n/2),r.setAttribute("width",e-n),r.setAttribute("height",s-n),r.setAttribute("stroke-width",n||1),r.setAttribute("stroke","transparent"),r.setAttribute("fill","transparent"),i.append(r),this.container.append(i),!t.popupRef&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return this.#t}addHighlightArea(){this.container.classList.add("highlightArea")}}class La extends ht{#t=null;constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){this.container.classList.add("circleAnnotation");const{data:t,width:e,height:s}=this,i=this.svgFactory.create(e,s,!0),n=t.borderStyle.width,r=this.#t=this.svgFactory.createElement("svg:ellipse");return r.setAttribute("cx",e/2),r.setAttribute("cy",s/2),r.setAttribute("rx",e/2-n/2),r.setAttribute("ry",s/2-n/2),r.setAttribute("stroke-width",n||1),r.setAttribute("stroke","transparent"),r.setAttribute("fill","transparent"),i.append(r),this.container.append(i),!t.popupRef&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return this.#t}addHighlightArea(){this.container.classList.add("highlightArea")}}class wn extends ht{#t=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:s,popupRef:i},width:n,height:r}=this;if(!e)return this.container;const a=this.svgFactory.create(n,r,!0);let o=[];for(let h=0,d=e.length;h<d;h+=2){const u=e[h]-t[0],f=t[3]-e[h+1];o.push(`${u},${f}`)}o=o.join(" ");const l=this.#t=this.svgFactory.createElement(this.svgElementName);return l.setAttribute("points",o),l.setAttribute("stroke-width",s.width||1),l.setAttribute("stroke","transparent"),l.setAttribute("fill","transparent"),a.append(l),this.container.append(a),!i&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return this.#t}addHighlightArea(){this.container.classList.add("highlightArea")}}class Da extends wn{constructor(t){super(t),this.containerClassName="polygonAnnotation",this.svgElementName="svg:polygon"}}class Ia extends ht{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){return this.container.classList.add("caretAnnotation"),!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container}}class ei extends ht{#t=null;#e=[];constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.containerClassName="inkAnnotation",this.svgElementName="svg:polyline",this.annotationEditorType=this.data.it==="InkHighlight"?V.HIGHLIGHT:V.INK}#i(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:s,borderStyle:i,popupRef:n}}=this,{transform:r,width:a,height:o}=this.#i(e,t),l=this.svgFactory.create(a,o,!0),h=this.#t=this.svgFactory.createElement("svg:g");l.append(h),h.setAttribute("stroke-width",i.width||1),h.setAttribute("stroke-linecap","round"),h.setAttribute("stroke-linejoin","round"),h.setAttribute("stroke-miterlimit",10),h.setAttribute("stroke","transparent"),h.setAttribute("fill","transparent"),h.setAttribute("transform",r);for(let d=0,u=s.length;d<u;d++){const f=this.svgFactory.createElement(this.svgElementName);this.#e.push(f),f.setAttribute("points",s[d].join(",")),h.append(f)}return!n&&this.hasPopupData&&this._createPopup(),this.container.append(l),this._editOnDoubleClick(),this.container}updateEdited(t){super.updateEdited(t);const{thickness:e,points:s,rect:i}=t,n=this.#t;if(e>=0&&n.setAttribute("stroke-width",e||1),s)for(let r=0,a=this.#e.length;r<a;r++)this.#e[r].setAttribute("points",s[r].join(","));if(i){const{transform:r,width:a,height:o}=this.#i(this.data.rotation,i);n.parentElement.setAttribute("viewBox",`0 0 ${a} ${o}`),n.setAttribute("transform",r)}}getElementsToTriggerPopup(){return this.#e}addHighlightArea(){this.container.classList.add("highlightArea")}}class vn extends ht{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0}),this.annotationEditorType=V.HIGHLIGHT}render(){const{data:{overlaidText:t,popupRef:e}}=this;if(!e&&this.hasPopupData&&this._createPopup(),this.container.classList.add("highlightAnnotation"),this._editOnDoubleClick(),t){const s=document.createElement("mark");s.classList.add("overlaidText"),s.textContent=t,this.container.append(s)}return this.container}}class Fa extends ht{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){const{data:{overlaidText:t,popupRef:e}}=this;if(!e&&this.hasPopupData&&this._createPopup(),this.container.classList.add("underlineAnnotation"),t){const s=document.createElement("u");s.classList.add("overlaidText"),s.textContent=t,this.container.append(s)}return this.container}}class Na extends ht{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){const{data:{overlaidText:t,popupRef:e}}=this;if(!e&&this.hasPopupData&&this._createPopup(),this.container.classList.add("squigglyAnnotation"),t){const s=document.createElement("u");s.classList.add("overlaidText"),s.textContent=t,this.container.append(s)}return this.container}}class Oa extends ht{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){const{data:{overlaidText:t,popupRef:e}}=this;if(!e&&this.hasPopupData&&this._createPopup(),this.container.classList.add("strikeoutAnnotation"),t){const s=document.createElement("s");s.classList.add("overlaidText"),s.textContent=t,this.container.append(s)}return this.container}}class _n extends ht{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.annotationEditorType=V.STAMP}render(){return this.container.classList.add("stampAnnotation"),this.container.setAttribute("role","img"),!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this._editOnDoubleClick(),this.container}}class Ba extends ht{#t=null;constructor(t){super(t,{isRenderable:!0});const{file:e}=this.data;this.filename=e.filename,this.content=e.content,this.linkService.eventBus?.dispatch("fileattachmentannotation",{source:this,...e})}render(){this.container.classList.add("fileAttachmentAnnotation");const{container:t,data:e}=this;let s;e.hasAppearance||e.fillAlpha===0?s=document.createElement("div"):(s=document.createElement("img"),s.src=`${this.imageResourcesPath}annotation-${/paperclip/i.test(e.name)?"paperclip":"pushpin"}.svg`,e.fillAlpha&&e.fillAlpha<1&&(s.style=`filter: opacity(${Math.round(e.fillAlpha*100)}%);`)),s.addEventListener("dblclick",this.#e.bind(this)),this.#t=s;const{isMac:i}=bt.platform;return t.addEventListener("keydown",n=>{n.key==="Enter"&&(i?n.metaKey:n.ctrlKey)&&this.#e()}),!e.popupRef&&this.hasPopupData?this._createPopup():s.classList.add("popupTriggerArea"),t.append(s),t}getElementsToTriggerPopup(){return this.#t}addHighlightArea(){this.container.classList.add("highlightArea")}#e(){this.downloadManager?.openOrDownloadData(this.content,this.filename)}}let si=class Sn{#t=null;#e=null;#i=null;#s=new Map;#a=null;#n=null;constructor({div:t,accessibilityManager:e,annotationCanvasMap:s,annotationEditorUIManager:i,page:n,viewport:r,structTreeLayer:a,commentManager:o,linkService:l,annotationStorage:h}){this.div=t,this.#t=e,this.#e=s,this.#a=a||null,this.#n=l||null,this.#i=h||new Xs,this.page=n,this.viewport=r,this.zIndex=0,this._annotationEditorUIManager=i,this._commentManager=o||null}hasEditableAnnotations(){return this.#s.size>0}async#r(t,e,s){const i=t.firstChild||t,n=i.id=`${$s}${e}`,r=await this.#a?.getAriaAttributes(n);if(r)for(const[a,o]of r)i.setAttribute(a,o);s?s.at(-1).container.after(t):(this.div.append(t),this.#t?.moveElementInDOM(this.div,t,i,!1))}async render(t){const{annotations:e}=t,s=this.div;Zt(s,this.viewport);const i=new Map,n={data:null,layer:s,linkService:this.#n,downloadManager:t.downloadManager,imageResourcesPath:t.imageResourcesPath||"",renderForms:t.renderForms!==!1,svgFactory:new Ne,annotationStorage:this.#i,enableComment:t.enableComment===!0,enableScripting:t.enableScripting===!0,hasJSActions:t.hasJSActions,fieldObjects:t.fieldObjects,parent:this,elements:null};for(const r of e){if(r.noHTML)continue;const a=r.annotationType===ct.POPUP;if(a){const h=i.get(r.id);if(!h)continue;n.elements=h}else if(r.rect[2]===r.rect[0]||r.rect[3]===r.rect[1])continue;n.data=r;const o=Di.create(n);if(!o.isRenderable)continue;if(!a&&r.popupRef){const h=i.get(r.popupRef);h?h.push(o):i.set(r.popupRef,[o])}const l=o.render();r.hidden&&(l.style.visibility="hidden"),await this.#r(l,r.id,n.elements),o.extraPopupElement?.popup?.renderCommentButton(),o._isEditable&&(this.#s.set(o.data.id,o),this._annotationEditorUIManager?.renderAnnotationElement(o))}this.#o()}async addLinkAnnotations(t){const e={data:null,layer:this.div,linkService:this.#n,svgFactory:new Ne,parent:this};for(const s of t){s.borderStyle||=Sn._defaultBorderStyle,e.data=s;const i=Di.create(e);if(!i.isRenderable)continue;const n=i.render();await this.#r(n,s.id,null)}}update({viewport:t}){const e=this.div;this.viewport=t,Zt(e,{rotation:t.rotation}),this.#o(),e.hidden=!1}#o(){if(!this.#e)return;const t=this.div;for(const[e,s]of this.#e){const i=t.querySelector(`[data-annotation-id="${e}"]`);if(!i)continue;s.className="annotationContent";const{firstChild:n}=i;n?n.nodeName==="CANVAS"?n.replaceWith(s):n.classList.contains("annotationContent")?n.after(s):n.before(s):i.append(s);const r=this.#s.get(e);r&&(r._hasNoCanvas?(this._annotationEditorUIManager?.setMissingCanvas(e,i.id,s),r._hasNoCanvas=!1):r.canvas=s)}this.#e.clear()}getEditableAnnotations(){return Array.from(this.#s.values())}getEditableAnnotation(t){return this.#s.get(t)}addFakeAnnotation(t){const{div:e}=this,{id:s,rotation:i}=t,n=new _a({data:{id:s,rect:t.getPDFRect(),rotation:i},editor:t,layer:e,parent:this,enableComment:!!this._commentManager,linkService:this.#n,annotationStorage:this.#i}),r=n.render();return e.append(r),this.#t?.moveElementInDOM(e,r,r,!1),n.createOrUpdatePopup(),n}static get _defaultBorderStyle(){return Y(this,"_defaultBorderStyle",Object.freeze({width:1,rawWidth:1,style:ce.SOLID,dashArray:[3],horizontalCornerRadius:0,verticalCornerRadius:0}))}};const es=/\r\n?|\n/g;class pt extends B{#t="";#e=`${this.id}-editor`;#i=null;#s;_colorPicker=null;static _freeTextDefaultContent="";static _internalPadding=0;static _defaultColor=null;static _defaultFontSize=10;static get _keyboardManager(){const t=pt.prototype,e=n=>n.isEmpty(),s=Yt.TRANSLATE_SMALL,i=Yt.TRANSLATE_BIG;return Y(this,"_keyboardManager",new je([[["ctrl+s","mac+meta+s","ctrl+p","mac+meta+p"],t.commitOrRemove,{bubbles:!0}],[["ctrl+Enter","mac+meta+Enter","Escape","mac+Escape"],t.commitOrRemove],[["ArrowLeft","mac+ArrowLeft"],t._translateEmpty,{args:[-s,0],checker:e}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],t._translateEmpty,{args:[-i,0],checker:e}],[["ArrowRight","mac+ArrowRight"],t._translateEmpty,{args:[s,0],checker:e}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],t._translateEmpty,{args:[i,0],checker:e}],[["ArrowUp","mac+ArrowUp"],t._translateEmpty,{args:[0,-s],checker:e}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],t._translateEmpty,{args:[0,-i],checker:e}],[["ArrowDown","mac+ArrowDown"],t._translateEmpty,{args:[0,s],checker:e}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],t._translateEmpty,{args:[0,i],checker:e}]]))}static _type="freetext";static _editorType=V.FREETEXT;constructor(t){super({...t,name:"freeTextEditor"}),this.color=t.color||pt._defaultColor||B._defaultLineColor,this.#s=t.fontSize||pt._defaultFontSize,this.annotationElementId||this._uiManager.a11yAlert("pdfjs-editor-freetext-added-alert")}static initialize(t,e){B.initialize(t,e);const s=getComputedStyle(document.documentElement);this._internalPadding=parseFloat(s.getPropertyValue("--freetext-padding"))}static updateDefaultParams(t,e){switch(t){case Q.FREETEXT_SIZE:pt._defaultFontSize=e;break;case Q.FREETEXT_COLOR:pt._defaultColor=e;break}}updateParams(t,e){switch(t){case Q.FREETEXT_SIZE:this.#a(e);break;case Q.FREETEXT_COLOR:this.#n(e);break}}static get defaultPropertiesToUpdate(){return[[Q.FREETEXT_SIZE,pt._defaultFontSize],[Q.FREETEXT_COLOR,pt._defaultColor||B._defaultLineColor]]}get propertiesToUpdate(){return[[Q.FREETEXT_SIZE,this.#s],[Q.FREETEXT_COLOR,this.color]]}get toolbarButtons(){return this._colorPicker||=new Fe(this),[["colorPicker",this._colorPicker]]}get colorType(){return Q.FREETEXT_COLOR}#a(t){const e=i=>{this.editorDiv.style.fontSize=`calc(${i}px * var(--total-scale-factor))`,this.translate(0,-(i-this.#s)*this.parentScale),this.#s=i,this.#o()},s=this.#s;this.addCommands({cmd:e.bind(this,t),undo:e.bind(this,s),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Q.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})}onUpdatedColor(){this.editorDiv.style.color=this.color,this._colorPicker?.update(this.color),super.onUpdatedColor()}#n(t){const e=i=>{this.color=i,this.onUpdatedColor()},s=this.color;this.addCommands({cmd:e.bind(this,t),undo:e.bind(this,s),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Q.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})}_translateEmpty(t,e){this._uiManager.translateSelectedEditors(t,e,!0)}getInitialTranslation(){const t=this.parentScale;return[-pt._internalPadding*t,-(pt._internalPadding+this.#s)*t]}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(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.#i=new AbortController;const t=this._uiManager.combinedSignal(this.#i);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.#e),this._isDraggable=!0,this.#i?.abort(),this.#i=null,this.div.focus({preventScroll:!0}),this.isEditing=!1,this.parent.div.classList.add("freetextEditing"),!0):!1}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()}#r(){const t=[];this.editorDiv.normalize();let e=null;for(const s of this.editorDiv.childNodes)e?.nodeType===Node.TEXT_NODE&&s.nodeName==="BR"||(t.push(pt.#h(s)),e=s);return t.join(`