@yuuichi/openlist-assets 4.2.6-ym.10 → 4.2.6-ym.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/ym-pdfjs-viewer.js +11 -11
- package/package.json +1 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
var es={d:(c,t)=>{for(var e in t)es.o(t,e)&&!es.o(c,e)&&Object.defineProperty(c,e,{enumerable:!0,get:t[e]})},o:(c,t)=>Object.prototype.hasOwnProperty.call(c,t)},R=globalThis.pdfjsLib={};es.d(R,{AbortException:()=>lt,AnnotationEditorLayer:()=>bi,AnnotationEditorParamsType:()=>B,AnnotationEditorType:()=>L,AnnotationEditorUIManager:()=>Mt,AnnotationLayer:()=>oi,AnnotationMode:()=>bt,ColorPicker:()=>Ne,DOMSVGFactory:()=>Xt,DrawLayer:()=>vi,FeatureTest:()=>K,GlobalWorkerOptions:()=>xt,ImageKind:()=>re,InvalidPDFException:()=>Ht,MissingPDFException:()=>St,OPS:()=>at,OutputScale:()=>Vt,PDFDataRangeTransport:()=>Se,PDFDateString:()=>le,PDFWorker:()=>Pt,PasswordResponses:()=>Fn,PermissionFlag:()=>cn,PixelsPerInch:()=>At,RenderingCancelledException:()=>jt,TextLayer:()=>Wt,TouchManager:()=>ue,UnexpectedResponseException:()=>It,Util:()=>C,VerbosityLevel:()=>$e,XfaLayer:()=>Me,build:()=>nr,createValidAbsoluteUrl:()=>Bn,fetchData:()=>Ve,getDocument:()=>sr,getFilenameFromUrl:()=>Hn,getPdfFilenameFromUrl:()=>zn,getXfaPageViewport:()=>jn,isDataScheme:()=>Ge,isPdfFile:()=>_i,noContextMenu:()=>ot,normalizeUnicode:()=>$n,setLayerDimensions:()=>Et,shadow:()=>N,stopEvent:()=>it,version:()=>ir});var Q=!(typeof process!="object"||process+""!="[object process]"||process.versions.nw||process.versions.electron&&process.type&&process.type!=="browser"),ji=[1,0,0,1,0,0],ss=[.001,0,0,.001,0,0],Xe=1.35,nn=1,Ai=2,ae=4,rn=16,an=32,on=64,hn=128,ln=256,bt={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},L={DISABLE:-1,NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15},B={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_DEFAULT_COLOR:32,HIGHLIGHT_THICKNESS:33,HIGHLIGHT_FREE:34,HIGHLIGHT_SHOW_ALL:35,DRAW_STEP:41},cn={PRINT:4,MODIFY_CONTENTS:8,COPY:16,MODIFY_ANNOTATIONS:32,FILL_INTERACTIVE_FORMS:256,COPY_FOR_ACCESSIBILITY:512,ASSEMBLE:1024,PRINT_HIGH_QUALITY:2048},ne=0,Ye=1,Lt=2,dn=3,Ei=3,un=4,re={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},pn=1,gn=2,fn=3,mn=4,bn=5,vn=6,An=7,wn=8,yn=9,_n=10,xn=11,Sn=12,En=13,Cn=14,Mn=15,Vi=16,kn=17,Tn=20,Rn=1,Pn=2,In=3,Ln=4,Dn=5,$e={ERRORS:0,WARNINGS:1,INFOS:5},at={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},Fn={NEED_PASSWORD:1,INCORRECT_PASSWORD:2},He=$e.WARNINGS;function Nn(c){Number.isInteger(c)&&(He=c)}function On(){return He}function ze(c){He>=$e.INFOS&&console.log(`Info: ${c}`)}function D(c){He>=$e.WARNINGS&&console.log(`Warning: ${c}`)}function z(c){throw new Error(c)}function X(c,t){c||z(t)}function Bn(c,t=null,e=null){if(!c)return null;try{if(e&&typeof c=="string"&&(e.addDefaultProtocol&&c.startsWith("www.")&&c.match(/\./g)?.length>=2&&(c=`http://${c}`),e.tryConvertEncoding))try{c=(function(n){return decodeURIComponent(escape(n))})(c)}catch{}let s=t?new URL(c,t):new URL(c);if((function(n){switch(n?.protocol){case"http:":case"https:":case"ftp:":case"mailto:":case"tel:":return!0;default:return!1}})(s))return s}catch{}return null}function N(c,t,e,s=!1){return Object.defineProperty(c,t,{value:e,enumerable:!s,configurable:!0,writable:!1}),e}var wt=(function(){function t(e,s){this.message=e,this.name=s}return t.prototype=new Error,t.constructor=t,t})(),oe=class extends wt{constructor(t,e){super(t,"PasswordException"),this.code=e}},Bt=class extends wt{constructor(t,e){super(t,"UnknownErrorException"),this.details=e}},Ht=class extends wt{constructor(t){super(t,"InvalidPDFException")}},St=class extends wt{constructor(t){super(t,"MissingPDFException")}},It=class extends wt{constructor(t,e){super(t,"UnexpectedResponseException"),this.status=e}},is=class extends wt{constructor(t){super(t,"FormatError")}},lt=class extends wt{constructor(t){super(t,"AbortException")}};function Gi(c){typeof c=="object"&&c?.length!==void 0||z("Invalid argument for bytesToString");let t=c.length,e=8192;if(t<e)return String.fromCharCode.apply(null,c);let s=[];for(let i=0;i<t;i+=e){let n=Math.min(i+e,t),r=c.subarray(i,n);s.push(String.fromCharCode.apply(null,r))}return s.join("")}function je(c){typeof c!="string"&&z("Invalid argument for stringToBytes");let t=c.length,e=new Uint8Array(t);for(let s=0;s<t;++s)e[s]=255&c.charCodeAt(s);return e}function wi(c){let t=Object.create(null);for(let[e,s]of c)t[e]=s;return t}var K=class{static get isLittleEndian(){return N(this,"isLittleEndian",(function(){let e=new Uint8Array(4);return e[0]=1,new Uint32Array(e.buffer,0,1)[0]===1})())}static get isEvalSupported(){return N(this,"isEvalSupported",(function(){try{return new Function(""),!0}catch{return!1}})())}static get isOffscreenCanvasSupported(){return N(this,"isOffscreenCanvasSupported",typeof OffscreenCanvas<"u")}static get isImageDecoderSupported(){return N(this,"isImageDecoderSupported",typeof ImageDecoder<"u")}static get platform(){return typeof navigator<"u"&&typeof navigator?.platform=="string"?N(this,"platform",{isMac:navigator.platform.includes("Mac"),isWindows:navigator.platform.includes("Win"),isFirefox:typeof navigator?.userAgent=="string"&&navigator.userAgent.includes("Firefox")}):N(this,"platform",{isMac:!1,isWindows:!1,isFirefox:!1})}static get isCSSRoundSupported(){return N(this,"isCSSRoundSupported",globalThis.CSS?.supports?.("width: round(1.5px, 1px)"))}},Ke=Array.from(Array(256).keys(),(c=>c.toString(16).padStart(2,"0"))),C=class{static makeHexColor(t,e,s){return`#${Ke[t]}${Ke[e]}${Ke[s]}`}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 applyTransform(t,e){return[t[0]*e[0]+t[1]*e[2]+e[4],t[0]*e[1]+t[1]*e[3]+e[5]]}static applyInverseTransform(t,e){let s=e[0]*e[3]-e[1]*e[2];return[(t[0]*e[3]-t[1]*e[2]+e[2]*e[5]-e[4]*e[3])/s,(-t[0]*e[1]+t[1]*e[0]+e[4]*e[1]-e[5]*e[0])/s]}static getAxialAlignedBoundingBox(t,e){let s=this.applyTransform(t,e),i=this.applyTransform(t.slice(2,4),e),n=this.applyTransform([t[0],t[3]],e),r=this.applyTransform([t[2],t[1]],e);return[Math.min(s[0],i[0],n[0],r[0]),Math.min(s[1],i[1],n[1],r[1]),Math.max(s[0],i[0],n[0],r[0]),Math.max(s[1],i[1],n[1],r[1])]}static inverseTransform(t){let 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){let e=[t[0],t[2],t[1],t[3]],s=t[0]*e[0]+t[1]*e[2],i=t[0]*e[1]+t[1]*e[3],n=t[2]*e[0]+t[3]*e[2],r=t[2]*e[1]+t[3]*e[3],a=(s+r)/2,o=Math.sqrt((s+r)**2-4*(s*r-n*i))/2,h=a+o||1,l=a-o||1;return[Math.sqrt(h),Math.sqrt(l)]}static normalizeRect(t){let 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){let 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;let 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#t(t,e,s,i,n,r,a,o,h,l){if(h<=0||h>=1)return;let d=1-h,u=h*h,p=u*h,g=d*(d*(d*t+3*h*e)+3*u*s)+p*i,f=d*(d*(d*n+3*h*r)+3*u*a)+p*o;l[0]=Math.min(l[0],g),l[1]=Math.min(l[1],f),l[2]=Math.max(l[2],g),l[3]=Math.max(l[3],f)}static#e(t,e,s,i,n,r,a,o,h,l,d,u){if(Math.abs(h)<1e-12){Math.abs(l)>=1e-12&&this.#t(t,e,s,i,n,r,a,o,-d/l,u);return}let p=l**2-4*d*h;if(p<0)return;let g=Math.sqrt(p),f=2*h;this.#t(t,e,s,i,n,r,a,o,(-l+g)/f,u),this.#t(t,e,s,i,n,r,a,o,(-l-g)/f,u)}static bezierBoundingBox(t,e,s,i,n,r,a,o,h){return h?(h[0]=Math.min(h[0],t,a),h[1]=Math.min(h[1],e,o),h[2]=Math.max(h[2],t,a),h[3]=Math.max(h[3],e,o)):h=[Math.min(t,a),Math.min(e,o),Math.max(t,a),Math.max(e,o)],this.#e(t,s,n,a,e,i,r,o,3*(3*(s-n)-t+a),6*(t-2*s+n),3*(s-t),h),this.#e(t,s,n,a,e,i,r,o,3*(3*(i-r)-e+o),6*(e-2*i+r),3*(i-e),h),h}},Qe=null,Ci=null;function $n(c){return Qe||(Qe=/([\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,Ci=new Map([["\uFB05","\u017Ft"]])),c.replaceAll(Qe,((t,e,s)=>e?e.normalize("NFKC"):Ci.get(s)))}var yi="pdfjs_internal_id_";typeof Promise.try!="function"&&(Promise.try=function(c,...t){return new Promise((e=>{e(c(...t))}))});var pt="http://www.w3.org/2000/svg",At=class{static CSS=96;static PDF=72;static PDF_TO_CSS_UNITS=this.CSS/this.PDF};async function Ve(c,t="text"){if(Ot(c,document.baseURI)){let 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)=>{let 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)s(new Error(i.statusText));else{switch(t){case"arraybuffer":case"blob":case"json":e(i.response);return}e(i.responseText)}},i.send(null)}))}var zt=class c{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;let o=(t[2]+t[0])/2,h=(t[3]+t[1])/2,l,d,u,p,g,f,m,b;switch((i%=360)<0&&(i+=360),i){case 180:l=-1,d=0,u=0,p=1;break;case 90:l=0,d=1,u=1,p=0;break;case 270:l=0,d=-1,u=-1,p=0;break;case 0:l=1,d=0,u=0,p=-1;break;default:throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.")}a&&(u=-u,p=-p),l===0?(g=Math.abs(h-t[1])*s+n,f=Math.abs(o-t[0])*s+r,m=(t[3]-t[1])*s,b=(t[2]-t[0])*s):(g=Math.abs(o-t[0])*s+n,f=Math.abs(h-t[1])*s+r,m=(t[2]-t[0])*s,b=(t[3]-t[1])*s),this.transform=[l*s,d*s,u*s,p*s,g-l*s*o-u*s*h,f-d*s*o-p*s*h],this.width=m,this.height=b}get rawDims(){let{userUnit:t,viewBox:e}=this,s=e.map((i=>i*t));return N(this,"rawDims",{pageWidth:s[2]-s[0],pageHeight:s[3]-s[1],pageX:s[0],pageY:s[1]})}clone({scale:t=this.scale,rotation:e=this.rotation,offsetX:s=this.offsetX,offsetY:i=this.offsetY,dontFlip:n=!1}={}){return new c({viewBox:this.viewBox.slice(),userUnit:this.userUnit,scale:t,rotation:e,offsetX:s,offsetY:i,dontFlip:n})}convertToViewportPoint(t,e){return C.applyTransform([t,e],this.transform)}convertToViewportRectangle(t){let e=C.applyTransform([t[0],t[1]],this.transform),s=C.applyTransform([t[2],t[3]],this.transform);return[e[0],e[1],s[0],s[1]]}convertToPdfPoint(t,e){return C.applyInverseTransform([t,e],this.transform)}},jt=class extends wt{constructor(t,e=0){super(t,"RenderingCancelledException"),this.extraDelay=e}};function Ge(c){let t=c.length,e=0;for(;e<t&&c[e].trim()==="";)e++;return c.substring(e,e+5).toLowerCase()==="data:"}function _i(c){return typeof c=="string"&&/\.pdf$/i.test(c)}function Hn(c){return[c]=c.split(/[#?]/,1),c.substring(c.lastIndexOf("/")+1)}function zn(c,t="document.pdf"){if(typeof c!="string")return t;if(Ge(c))return D('getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.'),t;let e=/[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i,s=/^(?:(?:[^:]+:)?\/\/[^/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/.exec(c),i=e.exec(s[1])||e.exec(s[2])||e.exec(s[3]);if(i&&(i=i[0],i.includes("%")))try{i=e.exec(decodeURIComponent(i))[0]}catch{}return i||t}var he=class{started=Object.create(null);times=[];time(t){t in this.started&&D(`Timer is already running for ${t}`),this.started[t]=Date.now()}timeEnd(t){t in this.started||D(`Timer has not been started for ${t}`),this.times.push({name:t,start:this.started[t],end:Date.now()}),delete this.started[t]}toString(){let t=[],e=0;for(let{name:s}of this.times)e=Math.max(s.length,e);for(let{name:s,start:i,end:n}of this.times)t.push(`${s.padEnd(e)} ${n-i}ms
|
|
2
|
-
`);return t.join("")}};function Ot(c,t){try{let{protocol:e}=t?new URL(c,t):new URL(c);return e==="http:"||e==="https:"}catch{return!1}}function ot(c){c.preventDefault()}function it(c){c.preventDefault(),c.stopPropagation()}var le=class{static#t;static toDateObject(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})?'?");let e=this.#t.exec(t);if(!e)return null;let s=parseInt(e[1],10),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;let h=e[7]||"Z",l=parseInt(e[8],10);l=l>=0&&l<=23?l:0;let d=parseInt(e[9],10)||0;return d=d>=0&&d<=59?d:0,h==="-"?(r+=l,a+=d):h==="+"&&(r-=l,a-=d),new Date(Date.UTC(s,i,n,r,a,o))}};function jn(c,{scale:t=1,rotation:e=0}){let{width:s,height:i}=c.attributes.style,n=[0,0,parseInt(s),parseInt(i)];return new zt({viewBox:n,userUnit:1,scale:t,rotation:e})}function ns(c){if(c.startsWith("#")){let t=parseInt(c.slice(1),16);return[(16711680&t)>>16,(65280&t)>>8,255&t]}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):(D(`Not a valid color format: "${c}"`),[0,0,0])}function G(c){let{a:t,b:e,c:s,d:i,e:n,f:r}=c.getTransform();return[t,e,s,i,n,r]}function ht(c){let{a:t,b:e,c:s,d:i,e:n,f:r}=c.getTransform().invertSelf();return[t,e,s,i,n,r]}function Et(c,t,e=!1,s=!0){if(t instanceof zt){let{pageWidth:i,pageHeight:n}=t.rawDims,{style:r}=c,a=K.isCSSRoundSupported,o=`var(--scale-factor) * ${i}px`,h=`var(--scale-factor) * ${n}px`,l=a?`round(down, ${o}, var(--scale-round-x, 1px))`:`calc(${o})`,d=a?`round(down, ${h}, var(--scale-round-y, 1px))`:`calc(${h})`;e&&t.rotation%180!=0?(r.width=d,r.height=l):(r.width=l,r.height=d)}s&&c.setAttribute("data-main-rotation",t.rotation)}var Vt=class{constructor(){let t=window.devicePixelRatio||1;this.sx=t,this.sy=t}get scaled(){return this.sx!==1||this.sy!==1}get symmetric(){return this.sx===this.sy}},rs=class c{#t=null;#e=null;#s;#i=null;#r=null;static#n=null;constructor(t){this.#s=t,c.#n||=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"})}render(){let t=this.#t=document.createElement("div");t.classList.add("editToolbar","hidden"),t.setAttribute("role","toolbar");let e=this.#s._uiManager._signal;t.addEventListener("contextmenu",ot,{signal:e}),t.addEventListener("pointerdown",c.#h,{signal:e});let s=this.#i=document.createElement("div");s.className="buttons",t.append(s);let i=this.#s.toolbarPosition;if(i){let{style:n}=t,r=this.#s._uiManager.direction==="ltr"?1-i[0]:i[0];n.insetInlineEnd=100*r+"%",n.top=`calc(${100*i[1]}% + var(--editor-toolbar-vert-offset))`}return this.#u(),t}get div(){return this.#t}static#h(t){t.stopPropagation()}#o(t){this.#s._focusEventsAllowed=!1,it(t)}#c(t){this.#s._focusEventsAllowed=!0,it(t)}#l(t){let e=this.#s._uiManager._signal;t.addEventListener("focusin",this.#o.bind(this),{capture:!0,signal:e}),t.addEventListener("focusout",this.#c.bind(this),{capture:!0,signal:e}),t.addEventListener("contextmenu",ot,{signal:e})}hide(){this.#t.classList.add("hidden"),this.#e?.hideDropdown()}show(){this.#t.classList.remove("hidden"),this.#r?.shown()}#u(){let{editorType:t,_uiManager:e}=this.#s,s=document.createElement("button");s.className="delete",s.tabIndex=0,s.setAttribute("data-l10n-id",c.#n[t]),this.#l(s),s.addEventListener("click",(i=>{e.delete()}),{signal:e._signal}),this.#i.append(s)}get#d(){let t=document.createElement("div");return t.className="divider",t}async addAltText(t){let e=await t.render();this.#l(e),this.#i.prepend(e,this.#d),this.#r=t}addColorPicker(t){this.#e=t;let e=t.renderButton();this.#l(e),this.#i.prepend(e,this.#d)}remove(){this.#t.remove(),this.#e?.destroy(),this.#e=null}},as=class{#t=null;#e=null;#s;constructor(t){this.#s=t}#i(){let t=this.#e=document.createElement("div");t.className="editToolbar",t.setAttribute("role","toolbar"),t.addEventListener("contextmenu",ot,{signal:this.#s._signal});let e=this.#t=document.createElement("div");return e.className="buttons",t.append(e),this.#n(),t}#r(t,e){let s=0,i=0;for(let n of t){let r=n.y+n.height;if(r<s)continue;let a=n.x+(e?n.width:0);r>s?(i=a,s=r):e?a>i&&(i=a):a<i&&(i=a)}return[e?1-i:i,s]}show(t,e,s){let[i,n]=this.#r(e,s),{style:r}=this.#e||=this.#i();t.append(this.#e),r.insetInlineEnd=100*i+"%",r.top=`calc(${100*n}% + var(--editor-toolbar-vert-offset))`}hide(){this.#e.remove()}#n(){let t=document.createElement("button");t.className="highlightButton",t.tabIndex=0,t.setAttribute("data-l10n-id","pdfjs-highlight-floating-button1");let e=document.createElement("span");t.append(e),e.className="visuallyHidden",e.setAttribute("data-l10n-id","pdfjs-highlight-floating-button-label");let s=this.#s._signal;t.addEventListener("contextmenu",ot,{signal:s}),t.addEventListener("click",(()=>{this.#s.highlightSelection("floating_button")}),{signal:s}),this.#t.append(t)}};function ce(c,t,e){for(let s of e)t.addEventListener(s,c[s].bind(c))}var os=class{#t=0;get id(){return"pdfjs_internal_editor_"+this.#t++}},hs=class c{#t=(function(){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();let e=new Uint8Array(32);return crypto.getRandomValues(e),Gi(e)})();#e=0;#s=null;static get _isSVGFittingCanvas(){let t=new OffscreenCanvas(1,3).getContext("2d",{willReadFrequently:!0}),e=new Image;return e.src='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>',N(this,"_isSVGFittingCanvas",e.decode().then((()=>(t.drawImage(e,0,0,1,1,0,0,1,3),new Uint32Array(t.getImageData(0,0,1,1).data.buffer)[0]===0))))}async#i(t,e){this.#s||=new Map;let s=this.#s.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"){let n=c._isSVGFittingCanvas,r=new FileReader,a=new Image,o=new Promise(((h,l)=>{a.onload=()=>{s.bitmap=a,s.isSvg=!0,h()},r.onload=async()=>{let d=s.svgUrl=r.result;a.src=await n?`${d}#svgView(preserveAspectRatio(none))`:d},a.onerror=r.onerror=l}));r.readAsDataURL(i),await o}else s.bitmap=await createImageBitmap(i);s.refCounter=1}catch(i){D(i),s=null}return this.#s.set(t,s),s&&this.#s.set(s.id,s),s}async getFromFile(t){let{lastModified:e,name:s,size:i,type:n}=t;return this.#i(`${e}_${s}_${i}_${n}`,t)}async getFromUrl(t){return this.#i(t,t)}async getFromBlob(t,e){let s=await e;return this.#i(t,s)}async getFromId(t){this.#s||=new Map;let e=this.#s.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){let{blobPromise:s}=e;return delete e.blobPromise,this.getFromBlob(e.id,s)}return this.getFromUrl(e.url)}getFromCanvas(t,e){this.#s||=new Map;let s=this.#s.get(t);if(s?.bitmap)return s.refCounter+=1,s;let 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.#s.set(t,s),this.#s.set(s.id,s),s}getSvgUrl(t){let e=this.#s.get(t);return e?.isSvg?e.svgUrl:null}deleteId(t){this.#s||=new Map;let e=this.#s.get(t);if(!e||(e.refCounter-=1,e.refCounter!==0))return;let{bitmap:s}=e;if(!e.url&&!e.file){let 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}_`)}},ls=class{#t=[];#e=!1;#s;#i=-1;constructor(t=128){this.#s=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;let o={cmd:t,undo:e,post:s,type:n};if(this.#i===-1){this.#t.length>0&&(this.#t.length=0),this.#i=0,this.#t.push(o);return}if(r&&this.#t[this.#i].type===n){a&&(o.undo=this.#t[this.#i].undo),this.#t[this.#i]=o;return}let h=this.#i+1;h===this.#s?this.#t.splice(0,1):(this.#i=h,h<this.#t.length&&this.#t.splice(h)),this.#t.push(o)}undo(){if(this.#i===-1)return;this.#e=!0;let{undo:t,post:e}=this.#t[this.#i];t(),e?.(),this.#e=!1,this.#i-=1}redo(){if(this.#i<this.#t.length-1){this.#i+=1,this.#e=!0;let{cmd:t,post:e}=this.#t[this.#i];t(),e?.(),this.#e=!1}}hasSomethingToUndo(){return this.#i!==-1}hasSomethingToRedo(){return this.#i<this.#t.length-1}cleanType(t){if(this.#i!==-1){for(let e=this.#i;e>=0;e--)if(this.#t[e].type!==t){this.#t.splice(e+1,this.#i-e),this.#i=e;return}this.#t.length=0,this.#i=-1}}destroy(){this.#t=null}},Ct=class{constructor(t){this.buffer=[],this.callbacks=new Map,this.allKeys=new Set;let{isMac:e}=K.platform;for(let[s,i,n={}]of t)for(let r of s){let 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);let e=this.buffer.join("+");return this.buffer.length=0,e}exec(t,e){if(!this.allKeys.has(e.key))return;let s=this.callbacks.get(this.#t(e));if(!s)return;let{callback:i,options:{bubbles:n=!1,args:r=[],checker:a=null}}=s;(!a||a(t,e))&&(i.bind(t,...r,e)(),n||it(e))}},cs=class c{static _colorsMapping=new Map([["CanvasText",[0,0,0]],["Canvas",[255,255,255]]]);get _colors(){let t=new Map([["CanvasText",null],["Canvas",null]]);return(function(s){let i=document.createElement("span");i.style.visibility="hidden",document.body.append(i);for(let n of s.keys()){i.style.color=n;let r=window.getComputedStyle(i).color;s.set(n,ns(r))}i.remove()})(t),N(this,"_colors",t)}convert(t){let e=ns(t);if(!window.matchMedia("(forced-colors: active)").matches)return e;for(let[s,i]of this._colors)if(i.every(((n,r)=>n===e[r])))return c._colorsMapping.get(s);return e}getHexCode(t){let e=this._colors.get(t);return e?C.makeHexColor(...e):t}},Mt=class c{#t=new AbortController;#e=null;#s=new Map;#i=new Map;#r=null;#n=null;#h=null;#o=new ls;#c=null;#l=null;#u=0;#d=new Set;#p=null;#a=null;#g=new Set;_editorUndoBar=null;#m=!1;#f=!1;#b=!1;#w=null;#v=null;#y=null;#x=null;#E=!1;#M=null;#T=new os;#_=!1;#k=!1;#C=null;#P=null;#D=null;#N=null;#S=L.NONE;#A=new Set;#L=null;#z=null;#j=null;#V={isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1};#O=[0,0];#F=null;#B=null;#G=null;#I=null;static TRANSLATE_SMALL=1;static TRANSLATE_BIG=10;static get _keyboardManager(){let t=c.prototype,e=r=>r.#B.contains(document.activeElement)&&document.activeElement.tagName!=="BUTTON"&&r.hasSomethingToControl(),s=(r,{target:a})=>{if(a instanceof HTMLInputElement){let{type:o}=a;return o!=="text"&&o!=="number"}return!0},i=this.TRANSLATE_SMALL,n=this.TRANSLATE_BIG;return N(this,"_keyboardManager",new Ct([[["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.#B.contains(a)&&!r.isEnterHandled}],[[" ","mac+ "],t.addNewEditorFromKeyboard,{checker:(r,{target:a})=>!(a instanceof HTMLButtonElement)&&r.#B.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,h,l,d,u,p){let g=this._signal=this.#t.signal;this.#B=t,this.#G=e,this.#r=s,this._eventBus=i,i._on("editingaction",this.onEditingAction.bind(this),{signal:g}),i._on("pagechanging",this.onPageChanging.bind(this),{signal:g}),i._on("scalechanging",this.onScaleChanging.bind(this),{signal:g}),i._on("rotationchanging",this.onRotationChanging.bind(this),{signal:g}),i._on("setpreference",this.onSetPreference.bind(this),{signal:g}),i._on("switchannotationeditorparams",(f=>this.updateParams(f.type,f.value)),{signal:g}),this.#et(),this.#rt(),this.#X(),this.#n=n.annotationStorage,this.#w=n.filterFactory,this.#z=r,this.#x=a||null,this.#m=o,this.#f=h,this.#b=l,this.#N=d||null,this.viewParameters={realScale:At.PDF_TO_CSS_UNITS,rotation:0},this.isShiftKeyDown=!1,this._editorUndoBar=u||null,this._supportsPinchToZoom=p!==!1}destroy(){this.#I?.resolve(),this.#I=null,this.#t?.abort(),this.#t=null,this._signal=null;for(let t of this.#i.values())t.destroy();this.#i.clear(),this.#s.clear(),this.#g.clear(),this.#e=null,this.#A.clear(),this.#o.destroy(),this.#r?.destroy(),this.#M?.hide(),this.#M=null,this.#v&&(clearTimeout(this.#v),this.#v=null),this.#F&&(clearTimeout(this.#F),this.#F=null),this._editorUndoBar?.destroy()}combinedSignal(t){return AbortSignal.any([this._signal,t.signal])}get mlManager(){return this.#N}get useNewAltTextFlow(){return this.#f}get useNewAltTextWhenAddingImage(){return this.#b}get hcmFilter(){return N(this,"hcmFilter",this.#z?this.#w.addHCMFilter(this.#z.foreground,this.#z.background):"none")}get direction(){return N(this,"direction",getComputedStyle(this.#B).direction)}get highlightColors(){return N(this,"highlightColors",this.#x?new Map(this.#x.split(",").map((t=>t.split("=").map((e=>e.trim()))))):null)}get highlightColorNames(){return N(this,"highlightColorNames",this.highlightColors?new Map(Array.from(this.highlightColors,(t=>t.reverse()))):null)}setCurrentDrawingSession(t){t?(this.unselectAll(),this.disableUserSelect(!0)):this.disableUserSelect(!1),this.#l=t}setMainHighlightColorPicker(t){this.#D=t}editAltText(t,e=!1){this.#r?.editAltText(this,t,e)}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}){t==="enableNewAltTextWhenAddingImage"&&(this.#b=e)}onPageChanging({pageNumber:t}){this.#u=t-1}focusMainContainer(){this.#B.focus()}findParent(t,e){for(let s of this.#i.values()){let{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.#G.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*At.PDF_TO_CSS_UNITS;for(let e of this.#g)e.onScaleChanging();this.#l?.onScaleChanging()}onRotationChanging({pagesRotation:t}){this.commitOrRemove(),this.viewParameters.rotation=t}#$({anchorNode:t}){return t.nodeType===Node.TEXT_NODE?t.parentElement:t}#q(t){let{currentLayer:e}=this;if(e.hasTextLayer(t))return e;for(let s of this.#i.values())if(s.hasTextLayer(t))return s;return null}highlightSelection(t=""){let e=document.getSelection();if(!e||e.isCollapsed)return;let{anchorNode:s,anchorOffset:i,focusNode:n,focusOffset:r}=e,a=e.toString(),o=this.#$(e).closest(".textLayer"),h=this.getSelectionBoxes(o);if(!h)return;e.empty();let l=this.#q(o),d=this.#S===L.NONE,u=()=>{l?.createAndAddNewEditor({x:0,y:0},!1,{methodOfCreation:t,boxes:h,anchorNode:s,anchorOffset:i,focusNode:n,focusOffset:r,text:a}),d&&this.showAllEditors("highlight",!0,!0)};d?this.switchToMode(L.HIGHLIGHT,u):u()}#Z(){let t=document.getSelection();if(!t||t.isCollapsed)return;let e=this.#$(t).closest(".textLayer"),s=this.getSelectionBoxes(e);s&&(this.#M||=new as(this),this.#M.show(e,s,this.direction==="ltr"))}addToAnnotationStorage(t){t.isEmpty()||!this.#n||this.#n.has(t.id)||this.#n.setValue(t.id,t)}#tt(){let t=document.getSelection();if(!t||t.isCollapsed){this.#L&&(this.#M?.hide(),this.#L=null,this.#R({hasSelectedText:!1}));return}let{anchorNode:e}=t;if(e===this.#L)return;let s=this.#$(t).closest(".textLayer");if(s){if(this.#M?.hide(),this.#L=e,this.#R({hasSelectedText:!0}),(this.#S===L.HIGHLIGHT||this.#S===L.NONE)&&(this.#S===L.HIGHLIGHT&&this.showAllEditors("highlight",!0,!0),this.#E=this.isShiftKeyDown,!this.isShiftKeyDown)){let i=this.#S===L.HIGHLIGHT?this.#q(s):null;i?.toggleDrawing();let n=new AbortController,r=this.combinedSignal(n),a=o=>{(o.type!=="pointerup"||o.button===0)&&(n.abort(),i?.toggleDrawing(!0),o.type==="pointerup"&&this.#W("main_toolbar"))};window.addEventListener("pointerup",a,{signal:r}),window.addEventListener("blur",a,{signal:r})}}else this.#L&&(this.#M?.hide(),this.#L=null,this.#R({hasSelectedText:!1}))}#W(t=""){this.#S===L.HIGHLIGHT?this.highlightSelection(t):this.#m&&this.#Z()}#et(){document.addEventListener("selectionchange",this.#tt.bind(this),{signal:this._signal})}#st(){if(this.#y)return;this.#y=new AbortController;let t=this.combinedSignal(this.#y);window.addEventListener("focus",this.focus.bind(this),{signal:t}),window.addEventListener("blur",this.blur.bind(this),{signal:t})}#it(){this.#y?.abort(),this.#y=null}blur(){if(this.isShiftKeyDown=!1,this.#E&&(this.#E=!1,this.#W("main_toolbar")),!this.hasSelection)return;let{activeElement:t}=document;for(let e of this.#A)if(e.div.contains(t)){this.#P=[e,t],e._focusEventsAllowed=!1;break}}focus(){if(!this.#P)return;let[t,e]=this.#P;this.#P=null,e.addEventListener("focusin",(()=>{t._focusEventsAllowed=!0}),{once:!0,signal:this._signal}),e.focus()}#X(){if(this.#C)return;this.#C=new AbortController;let t=this.combinedSignal(this.#C);window.addEventListener("keydown",this.keydown.bind(this),{signal:t}),window.addEventListener("keyup",this.keyup.bind(this),{signal:t})}#nt(){this.#C?.abort(),this.#C=null}#Y(){if(this.#c)return;this.#c=new AbortController;let t=this.combinedSignal(this.#c);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})}#K(){this.#c?.abort(),this.#c=null}#rt(){let t=this._signal;document.addEventListener("dragover",this.dragOver.bind(this),{signal:t}),document.addEventListener("drop",this.drop.bind(this),{signal:t})}addEditListeners(){this.#X(),this.#Y()}removeEditListeners(){this.#nt(),this.#K()}dragOver(t){for(let{type:e}of t.dataTransfer.items)for(let s of this.#a)if(s.isHandlingMimeForPasting(e)){t.dataTransfer.dropEffect="copy",t.preventDefault();return}}drop(t){for(let e of t.dataTransfer.items)for(let s of this.#a)if(s.isHandlingMimeForPasting(e.type)){s.paste(e,this.currentLayer),t.preventDefault();return}}copy(t){if(t.preventDefault(),this.#e?.commitOrRemove(),!this.hasSelection)return;let e=[];for(let s of this.#A){let 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();let{clipboardData:e}=t;for(let n of e.items)for(let r of this.#a)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){D(`paste: "${n.message}".`);return}if(!Array.isArray(s))return;this.unselectAll();let i=this.currentLayer;try{let n=[];for(let o of s){let h=await i.deserialize(o);if(!h)return;n.push(h)}let r=()=>{for(let o of n)this.#Q(o);this.#J(n)},a=()=>{for(let o of n)o.remove()};this.addCommands({cmd:r,undo:a,mustExec:!0})}catch(n){D(`paste: "${n.message}".`)}}keydown(t){this.isShiftKeyDown||t.key!=="Shift"||(this.isShiftKeyDown=!0),this.#S===L.NONE||this.isEditorHandlingKeyboard||c._keyboardManager.exec(this,t)}keyup(t){this.isShiftKeyDown&&t.key==="Shift"&&(this.isShiftKeyDown=!1,this.#E&&(this.#E=!1,this.#W("main_toolbar")))}onEditingAction({name:t}){switch(t){case"undo":case"redo":case"delete":case"selectAll":this[t]();break;case"highlightSelection":this.highlightSelection("context_menu")}}#R(t){Object.entries(t).some((([e,s])=>this.#V[e]!==s))&&(this._eventBus.dispatch("annotationeditorstateschanged",{source:this,details:Object.assign(this.#V,t)}),this.#S===L.HIGHLIGHT&&t.hasSelectedEditor===!1&&this.#H([[B.HIGHLIGHT_FREE,!0]]))}#H(t){this._eventBus.dispatch("annotationeditorparamschanged",{source:this,details:t})}setEditingState(t){t?(this.#st(),this.#Y(),this.#R({isEditing:this.#S!==L.NONE,isEmpty:this.#U(),hasSomethingToUndo:this.#o.hasSomethingToUndo(),hasSomethingToRedo:this.#o.hasSomethingToRedo(),hasSelectedEditor:!1})):(this.#it(),this.#K(),this.#R({isEditing:!1}),this.disableUserSelect(!1))}registerEditorTypes(t){if(!this.#a){this.#a=t;for(let e of this.#a)this.#H(e.defaultPropertiesToUpdate)}}getId(){return this.#T.id}get currentLayer(){return this.#i.get(this.#u)}getLayer(t){return this.#i.get(t)}get currentPageIndex(){return this.#u}addLayer(t){this.#i.set(t.pageIndex,t),this.#_?t.enable():t.disable()}removeLayer(t){this.#i.delete(t.pageIndex)}async updateMode(t,e=null,s=!1){if(this.#S!==t){if(this.#I&&(await this.#I.promise,!this.#I))return;if(this.#I=Promise.withResolvers(),this.#S=t,t!==L.NONE){this.setEditingState(!0),await this.#at(),this.unselectAll();for(let i of this.#i.values())i.updateMode(t);if(e){for(let i of this.#s.values())i.annotationElementId===e?(this.setSelected(i),i.enterInEditMode()):i.unselect();this.#I.resolve()}else s&&this.addNewEditorFromKeyboard(),this.#I.resolve()}else this.setEditingState(!1),this.#ot(),this._editorUndoBar?.hide(),this.#I.resolve()}}addNewEditorFromKeyboard(){this.currentLayer.canCreateNewEmptyEditor()&&this.currentLayer.addNewEditor()}updateToolbar(t){t!==this.#S&&this._eventBus.dispatch("switchannotationeditormode",{source:this,mode:t})}updateParams(t,e){if(this.#a){switch(t){case B.CREATE:this.currentLayer.addNewEditor();return;case B.HIGHLIGHT_DEFAULT_COLOR:this.#D?.updateColor(e);break;case B.HIGHLIGHT_SHOW_ALL:this._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:{type:"highlight",action:"toggle_visibility"}}}),(this.#j||=new Map).set(t,e),this.showAllEditors("highlight",e)}for(let s of this.#A)s.updateParams(t,e);for(let s of this.#a)s.updateDefaultParams(t,e)}}showAllEditors(t,e,s=!1){for(let i of this.#s.values())i.editorType===t&&i.show(e);(this.#j?.get(B.HIGHLIGHT_SHOW_ALL)??!0)!==e&&this.#H([[B.HIGHLIGHT_SHOW_ALL,e]])}enableWaiting(t=!1){if(this.#k!==t){this.#k=t;for(let e of this.#i.values())t?e.disableClick():e.enableClick(),e.div.classList.toggle("waiting",t)}}async#at(){if(!this.#_){this.#_=!0;let t=[];for(let e of this.#i.values())t.push(e.enable());await Promise.all(t);for(let e of this.#s.values())e.enable()}}#ot(){if(this.unselectAll(),this.#_){this.#_=!1;for(let t of this.#i.values())t.disable();for(let t of this.#s.values())t.disable()}}getEditors(t){let e=[];for(let s of this.#s.values())s.pageIndex===t&&e.push(s);return e}getEditor(t){return this.#s.get(t)}addEditor(t){this.#s.set(t.id,t)}removeEditor(t){t.div.contains(document.activeElement)&&(this.#v&&clearTimeout(this.#v),this.#v=setTimeout((()=>{this.focusMainContainer(),this.#v=null}),0)),this.#s.delete(t.id),this.unselect(t),t.annotationElementId&&this.#d.has(t.annotationElementId)||this.#n?.remove(t.id)}addDeletedAnnotationElement(t){this.#d.add(t.annotationElementId),this.addChangedExistingAnnotation(t),t.deleted=!0}isDeletedAnnotationElement(t){return this.#d.has(t)}removeDeletedAnnotationElement(t){this.#d.delete(t.annotationElementId),this.removeChangedExistingAnnotation(t),t.deleted=!1}#Q(t){let e=this.#i.get(t.pageIndex);e?e.addOrRebuild(t):(this.addEditor(t),this.addToAnnotationStorage(t))}setActiveEditor(t){this.#e!==t&&(this.#e=t,t&&this.#H(t.propertiesToUpdate))}get#ht(){let t=null;for(t of this.#A);return t}updateUI(t){this.#ht===t&&this.#H(t.propertiesToUpdate)}updateUIForDefaultProperties(t){this.#H(t.defaultPropertiesToUpdate)}toggleSelected(t){this.#A.has(t)?(this.#A.delete(t),t.unselect(),this.#R({hasSelectedEditor:this.hasSelection})):(this.#A.add(t),t.select(),this.#H(t.propertiesToUpdate),this.#R({hasSelectedEditor:!0}))}setSelected(t){this.#l?.commitOrRemove();for(let e of this.#A)e!==t&&e.unselect();this.#A.clear(),this.#A.add(t),t.select(),this.#H(t.propertiesToUpdate),this.#R({hasSelectedEditor:!0})}isSelected(t){return this.#A.has(t)}get firstSelectedEditor(){return this.#A.values().next().value}unselect(t){t.unselect(),this.#A.delete(t),this.#R({hasSelectedEditor:this.hasSelection})}get hasSelection(){return this.#A.size!==0}get isEnterHandled(){return this.#A.size===1&&this.firstSelectedEditor.isEnterHandled}undo(){this.#o.undo(),this.#R({hasSomethingToUndo:this.#o.hasSomethingToUndo(),hasSomethingToRedo:!0,isEmpty:this.#U()}),this._editorUndoBar?.hide()}redo(){this.#o.redo(),this.#R({hasSomethingToUndo:!0,hasSomethingToRedo:this.#o.hasSomethingToRedo(),isEmpty:this.#U()})}addCommands(t){this.#o.add(t),this.#R({hasSomethingToUndo:!0,hasSomethingToRedo:!1,isEmpty:this.#U()})}cleanUndoStack(t){this.#o.cleanType(t)}#U(){if(this.#s.size===0)return!0;if(this.#s.size===1)for(let t of this.#s.values())return t.isEmpty();return!1}delete(){this.commitOrRemove();let t=this.currentLayer?.endDrawingSession(!0);if(!this.hasSelection&&!t)return;let e=t?[t]:[...this.#A],s=()=>{for(let i of e)this.#Q(i)};this.addCommands({cmd:()=>{this._editorUndoBar?.show(s,e.length===1?e[0].editorType:e.length);for(let i of e)i.remove()},undo:s,mustExec:!0})}commitOrRemove(){this.#e?.commitOrRemove()}hasSomethingToControl(){return this.#e||this.hasSelection}#J(t){for(let e of this.#A)e.unselect();this.#A.clear();for(let e of t)e.isEmpty()||(this.#A.add(e),e.select());this.#R({hasSelectedEditor:this.hasSelection})}selectAll(){for(let t of this.#A)t.commit();this.#J(this.#s.values())}unselectAll(){if(!(this.#e&&(this.#e.commitOrRemove(),this.#S!==L.NONE))&&!this.#l?.commitOrRemove()&&this.hasSelection){for(let t of this.#A)t.unselect();this.#A.clear(),this.#R({hasSelectedEditor:!1})}}translateSelectedEditors(t,e,s=!1){if(s||this.commitOrRemove(),!this.hasSelection)return;this.#O[0]+=t,this.#O[1]+=e;let[i,n]=this.#O,r=[...this.#A];this.#F&&clearTimeout(this.#F),this.#F=setTimeout((()=>{this.#F=null,this.#O[0]=this.#O[1]=0,this.addCommands({cmd:()=>{for(let a of r)this.#s.has(a.id)&&a.translateInPage(i,n)},undo:()=>{for(let a of r)this.#s.has(a.id)&&a.translateInPage(-i,-n)},mustExec:!1})}),1e3);for(let a of r)a.translateInPage(t,e)}setUpDragSession(){if(this.hasSelection){this.disableUserSelect(!0),this.#p=new Map;for(let t of this.#A)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);let t=this.#p;this.#p=null;let e=!1;for(let[{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;let s=(i,n,r,a)=>{if(this.#s.has(i.id)){let o=this.#i.get(a);o?i._setParentAndPosition(o,n,r):(i.pageIndex=a,i.x=n,i.y=r)}};return this.addCommands({cmd:()=>{for(let[i,{newX:n,newY:r,newPageIndex:a}]of t)s(i,n,r,a)},undo:()=>{for(let[i,{savedX:n,savedY:r,savedPageIndex:a}]of t)s(i,n,r,a)},mustExec:!0}),!0}dragSelectedEditors(t,e){if(this.#p)for(let s of this.#p.keys())s.drag(t,e)}rebuild(t){if(t.parent===null){let 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.#A.size===1&&this.firstSelectedEditor.shouldGetKeyboardEvents()}isActive(t){return this.#e===t}getActive(){return this.#e}getMode(){return this.#S}get imageManager(){return N(this,"imageManager",new hs)}getSelectionBoxes(t){if(!t)return null;let e=document.getSelection();for(let h=0,l=e.rangeCount;h<l;h++)if(!t.contains(e.getRangeAt(h).commonAncestorContainer))return null;let{x:s,y:i,width:n,height:r}=t.getBoundingClientRect(),a;switch(t.getAttribute("data-main-rotation")){case"90":a=(h,l,d,u)=>({x:(l-i)/r,y:1-(h+d-s)/n,width:u/r,height:d/n});break;case"180":a=(h,l,d,u)=>({x:1-(h+d-s)/n,y:1-(l+u-i)/r,width:d/n,height:u/r});break;case"270":a=(h,l,d,u)=>({x:1-(l+u-i)/r,y:(h-s)/n,width:u/r,height:d/n});break;default:a=(h,l,d,u)=>({x:(h-s)/n,y:(l-i)/r,width:d/n,height:u/r})}let o=[];for(let h=0,l=e.rangeCount;h<l;h++){let d=e.getRangeAt(h);if(!d.collapsed)for(let{x:u,y:p,width:g,height:f}of d.getClientRects())g!==0&&f!==0&&o.push(a(u,p,g,f))}return o.length===0?null:o}addChangedExistingAnnotation({annotationElementId:t,id:e}){(this.#h||=new Map).set(t,e)}removeChangedExistingAnnotation({annotationElementId:t}){this.#h?.delete(t)}renderAnnotationElement(t){let e=this.#h?.get(t.data.id);if(!e)return;let s=this.#n.getRawValue(e);s&&(this.#S!==L.NONE||s.hasBeenModified)&&s.renderAnnotationElement(t)}},de=class c{#t=null;#e=!1;#s=null;#i=null;#r=null;#n=null;#h=!1;#o=null;#c=null;#l=null;#u=null;#d=!1;static#p=null;static _l10n=null;constructor(t){this.#c=t,this.#d=t._uiManager.useNewAltTextFlow,c.#p||=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){c._l10n??=t}async render(){let t=this.#s=document.createElement("button");t.className="altText",t.tabIndex="0";let e=this.#i=document.createElement("span");t.append(e),this.#d?(t.classList.add("new"),t.setAttribute("data-l10n-id",c.#p.missing),e.setAttribute("data-l10n-id",c.#p["missing-label"])):(t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button"),e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button-label"));let s=this.#c._uiManager._signal;t.addEventListener("contextmenu",ot,{signal:s}),t.addEventListener("pointerdown",(n=>n.stopPropagation()),{signal:s});let i=n=>{n.preventDefault(),this.#c._uiManager.editAltText(this.#c),this.#d&&this.#c._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_clicked",data:{label:this.#a}})};return t.addEventListener("click",i,{capture:!0,signal:s}),t.addEventListener("keydown",(n=>{n.target===t&&n.key==="Enter"&&(this.#h=!0,i(n))}),{signal:s}),await this.#g(),t}get#a(){return(this.#t?"added":this.#t===null&&this.guessedText&&"review")||"missing"}finish(){this.#s&&(this.#s.focus({focusVisible:this.#h}),this.#h=!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 c._l10n.get("pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer",{generatedAltText:t}),this.#g())}toggleAltTextBadge(t=!1){if(this.#d&&!this.#t){if(!this.#o){let e=this.#o=document.createElement("div");e.className="noAltTextBadge",this.#c.div.append(e)}this.#o.classList.toggle("hidden",!t)}else this.#o?.remove(),this.#o=null}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.#g())}toggle(t=!1){this.#s&&(!t&&this.#n&&(clearTimeout(this.#n),this.#n=null),this.#s.disabled=!t)}shown(){this.#c._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_displayed",data:{label:this.#a}})}destroy(){this.#s?.remove(),this.#s=null,this.#i=null,this.#r=null,this.#o?.remove(),this.#o=null}async#g(){let t=this.#s;if(!t)return;if(this.#d){if(t.classList.toggle("done",!!this.#t),t.setAttribute("data-l10n-id",c.#p[this.#a]),this.#i?.setAttribute("data-l10n-id",c.#p[`${this.#a}-label`]),!this.#t){this.#r?.remove();return}}else{if(!this.#t&&!this.#e){t.classList.remove("done"),this.#r?.remove();return}t.classList.add("done"),t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-edit-button")}let e=this.#r;if(!e){this.#r=e=document.createElement("span"),e.className="tooltip",e.setAttribute("role","tooltip"),e.id=`alt-text-tooltip-${this.#c.id}`;let i=100,n=this.#c._uiManager._signal;n.addEventListener("abort",(()=>{clearTimeout(this.#n),this.#n=null}),{once:!0}),t.addEventListener("mouseenter",(()=>{this.#n=setTimeout((()=>{this.#n=null,this.#r.classList.add("show"),this.#c._reportTelemetry({action:"alt_text_tooltip"})}),i)}),{signal:n}),t.addEventListener("mouseleave",(()=>{this.#n&&(clearTimeout(this.#n),this.#n=null),this.#r?.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.#c.getImageForAltText()?.setAttribute("aria-describedby",e.id)}},ue=class c{#t;#e=!1;#s=null;#i;#r;#n;#h;#o;#c=null;#l;#u=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.#s=s,this.#i=e,this.#r=i,this.#n=n,this.#h=r,this.#l=new AbortController,this.#o=AbortSignal.any([a,this.#l.signal]),t.addEventListener("touchstart",this.#d.bind(this),{passive:!1,signal:this.#o})}get MIN_TOUCH_DISTANCE_TO_PINCH(){return N(this,"MIN_TOUCH_DISTANCE_TO_PINCH",35/(window.devicePixelRatio||1))}#d(t){if(this.#i?.()||t.touches.length<2)return;if(!this.#u){this.#u=new AbortController;let i=AbortSignal.any([this.#o,this.#u.signal]),n=this.#t,r={signal:i,passive:!1};n.addEventListener("touchmove",this.#p.bind(this),r),n.addEventListener("touchend",this.#a.bind(this),r),n.addEventListener("touchcancel",this.#a.bind(this),r),this.#r?.()}if(it(t),t.touches.length!==2||this.#s?.()){this.#c=null;return}let[e,s]=t.touches;e.identifier>s.identifier&&([e,s]=[s,e]),this.#c={touch0X:e.screenX,touch0Y:e.screenY,touch1X:s.screenX,touch1Y:s.screenY}}#p(t){if(!this.#c||t.touches.length!==2)return;let[e,s]=t.touches;e.identifier>s.identifier&&([e,s]=[s,e]);let{screenX:i,screenY:n}=e,{screenX:r,screenY:a}=s,o=this.#c,{touch0X:h,touch0Y:l,touch1X:d,touch1Y:u}=o,p=d-h,g=u-l,f=r-i,m=a-n,b=Math.hypot(f,m)||1,v=Math.hypot(p,g)||1;if(!this.#e&&Math.abs(v-b)<=c.MIN_TOUCH_DISTANCE_TO_PINCH)return;if(o.touch0X=i,o.touch0Y=n,o.touch1X=r,o.touch1Y=a,t.preventDefault(),!this.#e){this.#e=!0;return}let A=[(i+r)/2,(n+a)/2];this.#n?.(A,v,b)}#a(t){this.#u.abort(),this.#u=null,this.#h?.(),this.#c&&(t.preventDefault(),this.#c=null,this.#e=!1)}destroy(){this.#l?.abort(),this.#l=null}},U=class c{#t=null;#e=null;#s=null;#i=!1;#r=null;#n="";#h=!1;#o=null;#c=null;#l=null;#u=null;#d="";#p=!1;#a=null;#g=!1;#m=!1;#f=!1;#b=null;#w=0;#v=0;#y=null;#x=null;_editToolbar=null;_initialOptions=Object.create(null);_initialData=null;_isVisible=!0;_uiManager=null;_focusEventsAllowed=!0;static _l10n=null;static _l10nResizer=null;#E=!1;#M=c._zIndex++;static _borderLineWidth=-1;static _colorManager=new cs;static _zIndex=1;static _telemetryTimeout=1e3;static get _resizerKeyboardManager(){let t=c.prototype._resizeWithKeyboard,e=Mt.TRANSLATE_SMALL,s=Mt.TRANSLATE_BIG;return N(this,"_resizerKeyboardManager",new Ct([[["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"],c.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;let{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];let[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}static get isDrawer(){return!1}static get _defaultLineColor(){return N(this,"_defaultLineColor",this._colorManager.getHexCode("CanvasText"))}static deleteAnnotationElement(t){let e=new ds({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(c._l10n??=t,c._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"}),c._borderLineWidth!==-1)return;let s=getComputedStyle(document.documentElement);c._borderLineWidth=parseFloat(s.getPropertyValue("--outline-width"))||0}static updateDefaultParams(t,e){}static get defaultPropertiesToUpdate(){return[]}static isHandlingMimeForPasting(t){return!1}static paste(t,e){z("Not implemented")}get propertiesToUpdate(){return[]}get _isDraggable(){return this.#E}set _isDraggable(t){this.#E=t,this.div?.classList.toggle("draggable",t)}get isEnterHandled(){return!0}center(){let[t,e]=this.pageDimensions;switch(this.parentRotation){case 90:this.x-=this.height*e/(2*t),this.y+=this.width*t/(2*e);break;case 180:this.x+=this.width/2,this.y+=this.height/2;break;case 270:this.x+=this.height*e/(2*t),this.y-=this.width*t/(2*e);break;default:this.x-=this.width/2,this.y-=this.height/2}this.fixAndSetPosition()}addCommands(t){this._uiManager.addCommands(t)}get currentLayer(){return this._uiManager.currentLayer}setInBackground(){this.div.style.zIndex=0}setInForeground(){this.div.style.zIndex=this.#M}setParent(t){t!==null?(this.pageIndex=t.pageIndex,this.pageDimensions=t.pageDimensions):this.#$(),this.parent=t}focusin(t){this._focusEventsAllowed&&(this.#p?this.#p=!1:this.parent.setSelected(this))}focusout(t){if(!this._focusEventsAllowed||!this.isAttachedToDOM)return;t.relatedTarget?.closest(`#${this.id}`)||(t.preventDefault(),this.parent?.isMultipleSelection||this.commitOrRemove())}commitOrRemove(){this.isEmpty()?this.remove():this.commit()}commit(){this.addToAnnotationStorage()}addToAnnotationStorage(){this._uiManager.addToAnnotationStorage(this)}setAt(t,e,s,i){let[n,r]=this.parentDimensions;[s,i]=this.screenToPageTranslation(s,i),this.x=(t+s)/n,this.y=(e+i)/r,this.fixAndSetPosition()}#T([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.#T(this.parentDimensions,t,e)}translateInPage(t,e){this.#a||=[this.x,this.y,this.width,this.height],this.#T(this.pageDimensions,t,e),this.div.scrollIntoView({block:"nearest"})}drag(t,e){this.#a||=[this.x,this.y,this.width,this.height];let{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)){let{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,[o,h]=this.getBaseTranslation();r+=o,a+=h;let{style:l}=s;l.left=`${(100*r).toFixed(2)}%`,l.top=`${(100*a).toFixed(2)}%`,this._onTranslating(r,a),s.scrollIntoView({block:"nearest"})}_onTranslating(t,e){}_onTranslated(t,e){}get _hasBeenMoved(){return!!this.#a&&(this.#a[0]!==this.x||this.#a[1]!==this.y)}get _hasBeenResized(){return!!this.#a&&(this.#a[2]!==this.width||this.#a[3]!==this.height)}getBaseTranslation(){let[t,e]=this.parentDimensions,{_borderLineWidth:s}=c,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){let{div:{style:e},pageDimensions:[s,i]}=this,{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=Math.max(0,Math.min(s-a,n)),r=Math.max(0,Math.min(i-o,r));break;case 90:n=Math.max(0,Math.min(s-o,n)),r=Math.min(i,Math.max(a,r));break;case 180:n=Math.min(s,Math.max(a,n)),r=Math.min(i,Math.max(o,r));break;case 270:n=Math.min(s,Math.max(o,n)),r=Math.max(0,Math.min(i-a,r))}this.x=n/=s,this.y=r/=i;let[h,l]=this.getBaseTranslation();n+=h,r+=l,e.left=`${(100*n).toFixed(2)}%`,e.top=`${(100*r).toFixed(2)}%`,this.moveInDOM()}static#_(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 c.#_(t,e,this.parentRotation)}pageTranslationToScreen(t,e){return c.#_(t,e,360-this.parentRotation)}#k(t){switch(t){case 90:{let[e,s]=this.pageDimensions;return[0,-e/s,s/e,0]}case 180:return[-1,0,0,-1];case 270:{let[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(){let{parentScale:t,pageDimensions:[e,s]}=this;return[e*t,s*t]}setDims(t,e){let[s,i]=this.parentDimensions,{style:n}=this.div;n.width=`${(100*t/s).toFixed(2)}%`,this.#h||(n.height=`${(100*e/i).toFixed(2)}%`)}fixDims(){let{style:t}=this.div,{height:e,width:s}=t,i=s.endsWith("%"),n=!this.#h&&e.endsWith("%");if(i&&n)return;let[r,a]=this.parentDimensions;i||(t.width=`${(100*parseFloat(s)/r).toFixed(2)}%`),this.#h||n||(t.height=`${(100*parseFloat(e)/a).toFixed(2)}%`)}getInitialTranslation(){return[0,0]}#C(){if(this.#o)return;this.#o=document.createElement("div"),this.#o.classList.add("resizers");let t=this._willKeepAspectRatio?["topLeft","topRight","bottomRight","bottomLeft"]:["topLeft","topMiddle","topRight","middleRight","bottomRight","bottomMiddle","bottomLeft","middleLeft"],e=this._uiManager._signal;for(let s of t){let i=document.createElement("div");this.#o.append(i),i.classList.add("resizer",s),i.setAttribute("data-resizer-name",s),i.addEventListener("pointerdown",this.#P.bind(this,s),{signal:e}),i.addEventListener("contextmenu",ot,{signal:e}),i.tabIndex=-1}this.div.prepend(this.#o)}#P(t,e){e.preventDefault();let{isMac:s}=K.platform;if(e.button!==0||e.ctrlKey&&s)return;this.#s?.toggle(!1);let i=this._isDraggable;this._isDraggable=!1,this.#c=[e.screenX,e.screenY];let n=new AbortController,r=this._uiManager.combinedSignal(n);this.parent.togglePointerEvents(!1),window.addEventListener("pointermove",this.#S.bind(this,t),{passive:!0,capture:!0,signal:r}),window.addEventListener("touchmove",it,{passive:!1,signal:r}),window.addEventListener("contextmenu",ot,{signal:r}),this.#l={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height};let 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;let h=()=>{n.abort(),this.parent.togglePointerEvents(!0),this.#s?.toggle(!0),this._isDraggable=i,this.parent.div.style.cursor=a,this.div.style.cursor=o,this.#N()};window.addEventListener("pointerup",h,{signal:r}),window.addEventListener("blur",h,{signal:r})}#D(t,e,s,i){this.width=s,this.height=i,this.x=t,this.y=e;let[n,r]=this.parentDimensions;this.setDims(n*s,r*i),this.fixAndSetPosition(),this._onResized()}_onResized(){}#N(){if(!this.#l)return;let{savedX:t,savedY:e,savedWidth:s,savedHeight:i}=this.#l;this.#l=null;let n=this.x,r=this.y,a=this.width,o=this.height;n===t&&r===e&&a===s&&o===i||this.addCommands({cmd:this.#D.bind(this,n,r,a,o),undo:this.#D.bind(this,t,e,s,i),mustExec:!0})}static _round(t){return Math.round(1e4*t)/1e4}#S(t,e){let[s,i]=this.parentDimensions,n=this.x,r=this.y,a=this.width,o=this.height,h=c.MIN_SIZE/s,l=c.MIN_SIZE/i,d=this.#k(this.rotation),u=(k,I)=>[d[0]*k+d[2]*I,d[1]*k+d[3]*I],p=this.#k(360-this.rotation),g,f,m=!1,b=!1;switch(t){case"topLeft":m=!0,g=(k,I)=>[0,0],f=(k,I)=>[k,I];break;case"topMiddle":g=(k,I)=>[k/2,0],f=(k,I)=>[k/2,I];break;case"topRight":m=!0,g=(k,I)=>[k,0],f=(k,I)=>[0,I];break;case"middleRight":b=!0,g=(k,I)=>[k,I/2],f=(k,I)=>[0,I/2];break;case"bottomRight":m=!0,g=(k,I)=>[k,I],f=(k,I)=>[0,0];break;case"bottomMiddle":g=(k,I)=>[k/2,I],f=(k,I)=>[k/2,0];break;case"bottomLeft":m=!0,g=(k,I)=>[0,I],f=(k,I)=>[k,0];break;case"middleLeft":b=!0,g=(k,I)=>[0,I/2],f=(k,I)=>[k,I/2]}let v=g(a,o),A=f(a,o),y=u(...A),w=c._round(n+y[0]),x=c._round(r+y[1]),_,E,M=1,T=1;if(e.fromKeyboard)({deltaX:_,deltaY:E}=e);else{let{screenX:k,screenY:I}=e,[nt,dt]=this.#c;[_,E]=this.screenToPageTranslation(k-nt,I-dt),this.#c[0]=k,this.#c[1]=I}[_,E]=(P=_/s,O=E/i,[p[0]*P+p[2]*O,p[1]*P+p[3]*O]);var P,O;if(m){let k=Math.hypot(a,o);M=T=Math.max(Math.min(Math.hypot(A[0]-v[0]-_,A[1]-v[1]-E)/k,1/a,1/o),h/a,l/o)}else b?M=Math.max(h,Math.min(1,Math.abs(A[0]-v[0]-_)))/a:T=Math.max(l,Math.min(1,Math.abs(A[1]-v[1]-E)))/o;let $=c._round(a*M),F=c._round(o*T);y=u(...f($,F));let j=w-y[0],V=x-y[1];this.#a||=[this.x,this.y,this.width,this.height],this.width=$,this.height=F,this.x=j,this.y=V,this.setDims(s*$,i*F),this.fixAndSetPosition(),this._onResizing()}_onResizing(){}altTextFinish(){this.#s?.finish()}async addEditToolbar(){return this._editToolbar||this.#m?this._editToolbar:(this._editToolbar=new rs(this),this.div.append(this._editToolbar.render()),this.#s&&await this._editToolbar.addAltText(this.#s),this._editToolbar)}removeEditToolbar(){this._editToolbar&&(this._editToolbar.remove(),this._editToolbar=null,this.#s?.destroy())}addContainer(t){let e=this._editToolbar?.div;e?e.before(t):this.div.append(t)}getClientDimensions(){return this.div.getBoundingClientRect()}async addAltTextButton(){this.#s||(de.initialize(c._l10n),this.#s=new de(this),this.#t&&(this.#s.data=this.#t,this.#t=null),await this.addEditToolbar())}get altTextData(){return this.#s?.data}set altTextData(t){this.#s&&(this.#s.data=t)}get guessedAltText(){return this.#s?.guessedText}async setGuessedAltText(t){await this.#s?.setGuessedText(t)}serializeAltText(t){return this.#s?.serialize(t)}hasAltText(){return!!this.#s&&!this.#s.isEmpty()}hasAltTextData(){return this.#s?.hasData()??!1}render(){this.div=document.createElement("div"),this.div.setAttribute("data-editor-rotation",(360-this.rotation)%360),this.div.className=this.name,this.div.setAttribute("id",this.id),this.div.tabIndex=this.#i?-1:0,this._isVisible||this.div.classList.add("hidden"),this.setInForeground(),this.#O();let[t,e]=this.parentDimensions;this.parentRotation%180!=0&&(this.div.style.maxWidth=`${(100*e/t).toFixed(2)}%`,this.div.style.maxHeight=`${(100*t/e).toFixed(2)}%`);let[s,i]=this.getInitialTranslation();return this.translate(s,i),ce(this,this.div,["pointerdown"]),this.isResizable&&this._uiManager._supportsPinchToZoom&&(this.#x||=new ue({container:this.div,isPinchingDisabled:()=>!this.isSelected,onPinchStart:this.#A.bind(this),onPinching:this.#L.bind(this),onPinchEnd:this.#z.bind(this),signal:this._uiManager._signal})),this._uiManager._editorUndoBar?.hide(),this.div}#A(){this.#l={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height},this.#s?.toggle(!1),this.parent.togglePointerEvents(!1)}#L(t,e,s){let i=s/e*.7+1-.7;if(i===1)return;let n=this.#k(this.rotation),r=(w,x)=>[n[0]*w+n[2]*x,n[1]*w+n[3]*x],[a,o]=this.parentDimensions,h=this.x,l=this.y,d=this.width,u=this.height,p=c.MIN_SIZE/a,g=c.MIN_SIZE/o;i=Math.max(Math.min(i,1/d,1/u),p/d,g/u);let f=c._round(d*i),m=c._round(u*i);if(f===d&&m===u)return;this.#a||=[h,l,d,u];let b=r(d/2,u/2),v=c._round(h+b[0]),A=c._round(l+b[1]),y=r(f/2,m/2);this.x=v-y[0],this.y=A-y[1],this.width=f,this.height=m,this.setDims(a*f,o*m),this.fixAndSetPosition(),this._onResizing()}#z(){this.#s?.toggle(!0),this.parent.togglePointerEvents(!0),this.#N()}pointerdown(t){let{isMac:e}=K.platform;t.button!==0||t.ctrlKey&&e?t.preventDefault():(this.#p=!0,this._isDraggable?this.#V(t):this.#j(t))}get isSelected(){return this._uiManager.isSelected(this)}#j(t){let{isMac:e}=K.platform;t.ctrlKey&&!e||t.shiftKey||t.metaKey&&e?this.parent.toggleSelected(this):this.parent.setSelected(this)}#V(t){let{isSelected:e}=this;this._uiManager.setUpDragSession();let s=!1,i=new AbortController,n=this._uiManager.combinedSignal(i),r={capture:!0,passive:!1,signal:n},a=h=>{i.abort(),this.#r=null,this.#p=!1,this._uiManager.endDragSession()||this.#j(h),s&&this._onStopDragging()};e&&(this.#w=t.clientX,this.#v=t.clientY,this.#r=t.pointerId,this.#n=t.pointerType,window.addEventListener("pointermove",(h=>{s||(s=!0,this._onStartDragging());let{clientX:l,clientY:d,pointerId:u}=h;if(u!==this.#r){it(h);return}let[p,g]=this.screenToPageTranslation(l-this.#w,d-this.#v);this.#w=l,this.#v=d,this._uiManager.dragSelectedEditors(p,g)}),r),window.addEventListener("touchmove",it,r),window.addEventListener("pointerdown",(h=>{h.pointerType===this.#n&&(this.#x||h.isPrimary)&&a(h),it(h)}),r));let o=h=>{this.#r&&this.#r!==h.pointerId?it(h):a(h)};window.addEventListener("pointerup",o,{signal:n}),window.addEventListener("blur",o,{signal:n})}_onStartDragging(){}_onStopDragging(){}moveInDOM(){this.#b&&clearTimeout(this.#b),this.#b=setTimeout((()=>{this.#b=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){let i=this.parentScale,[n,r]=this.pageDimensions,[a,o]=this.pageTranslation,h=t/i,l=e/i,d=this.x*n,u=this.y*r,p=this.width*n,g=this.height*r;switch(s){case 0:return[d+h+a,r-u-l-g+o,d+h+p+a,r-u-l+o];case 90:return[d+l+a,r-u+h+o,d+l+g+a,r-u+h+p+o];case 180:return[d-h-p+a,r-u+l+o,d-h+a,r-u+l+g+o];case 270:return[d-l-g+a,r-u-h-p+o,d-l+a,r-u-h+o];default:throw new Error("Invalid rotation")}}getRectInCurrentCoords(t,e){let[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")}}onceAdded(t){}isEmpty(){return!1}enableEditMode(){this.#m=!0}disableEditMode(){this.#m=!1}isInEditMode(){return this.#m}shouldGetKeyboardEvents(){return this.#f}needsToBeRebuilt(){return this.div&&!this.isAttachedToDOM}get isOnScreen(){let{top:t,left:e,bottom:s,right:i}=this.getClientDimensions(),{innerHeight:n,innerWidth:r}=window;return e<r&&i>0&&t<n&&s>0}#O(){if(this.#u||!this.div)return;this.#u=new AbortController;let t=this._uiManager.combinedSignal(this.#u);this.div.addEventListener("focusin",this.focusin.bind(this),{signal:t}),this.div.addEventListener("focusout",this.focusout.bind(this),{signal:t})}rebuild(){this.#O()}rotate(t){}resize(){}serializeDeleted(){return{id:this.annotationElementId,deleted:!0,pageIndex:this.pageIndex,popupRef:this._initialData?.popupRef||""}}serialize(t=!1,e=null){z("An editor must be serializable")}static async deserialize(t,e,s){let i=new this.prototype.constructor({parent:e,id:e.getNextId(),uiManager:s});i.rotation=t.rotation,i.#t=t.accessibilityData;let[n,r]=i.pageDimensions,[a,o,h,l]=i.getRectInCurrentCoords(t.rect,r);return i.x=a/n,i.y=o/r,i.width=h/n,i.height=l/r,i}get hasBeenModified(){return!!this.annotationElementId&&(this.deleted||this.serialize()!==null)}remove(){if(this.#u?.abort(),this.#u=null,this.isEmpty()||this.commit(),this.parent?this.parent.remove(this):this._uiManager.removeEditor(this),this.#b&&(clearTimeout(this.#b),this.#b=null),this.#$(),this.removeEditToolbar(),this.#y){for(let t of this.#y.values())clearTimeout(t);this.#y=null}this.parent=null,this.#x?.destroy(),this.#x=null}get isResizable(){return!1}makeResizable(){this.isResizable&&(this.#C(),this.#o.classList.remove("hidden"),ce(this,this.div,["keydown"]))}get toolbarPosition(){return null}keydown(t){if(!this.isResizable||t.target!==this.div||t.key!=="Enter")return;this._uiManager.setSelected(this),this.#l={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height};let e=this.#o.children;if(!this.#e){this.#e=Array.from(e);let r=this.#F.bind(this),a=this.#B.bind(this),o=this._uiManager._signal;for(let h of this.#e){let l=h.getAttribute("data-resizer-name");h.setAttribute("role","spinbutton"),h.addEventListener("keydown",r,{signal:o}),h.addEventListener("blur",a,{signal:o}),h.addEventListener("focus",this.#G.bind(this,l),{signal:o}),h.setAttribute("data-l10n-id",c._l10nResizer[l])}}let s=this.#e[0],i=0;for(let r of e){if(r===s)break;i++}let 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.#o.append(this.#o.firstChild);else if(n>i)for(let a=0;a<n-i;a++)this.#o.firstChild.before(this.#o.lastChild);let r=0;for(let a of e){let o=this.#e[r++].getAttribute("data-resizer-name");a.setAttribute("data-l10n-id",c._l10nResizer[o])}}this.#I(0),this.#f=!0,this.#o.firstChild.focus({focusVisible:!0}),t.preventDefault(),t.stopImmediatePropagation()}#F(t){c._resizerKeyboardManager.exec(this,t)}#B(t){this.#f&&t.relatedTarget?.parentNode!==this.#o&&this.#$()}#G(t){this.#d=this.#f?t:""}#I(t){if(this.#e)for(let e of this.#e)e.tabIndex=t}_resizeWithKeyboard(t,e){this.#f&&this.#S(this.#d,{deltaX:t,deltaY:e,fromKeyboard:!0})}#$(){this.#f=!1,this.#I(-1),this.#N()}_stopResizingWithKeyboard(){this.#$(),this.div.focus()}select(){this.makeResizable(),this.div?.classList.add("selectedEditor"),this._editToolbar?(this._editToolbar?.show(),this.#s?.toggleAltTextBadge(!1)):this.addEditToolbar().then((()=>{this.div?.classList.contains("selectedEditor")&&this._editToolbar?.show()}))}unselect(){this.#o?.classList.add("hidden"),this.div?.classList.remove("selectedEditor"),this.div?.contains(document.activeElement)&&this._uiManager.currentLayer.div.focus({preventScroll:!0}),this._editToolbar?.hide(),this.#s?.toggleAltTextBadge(!0)}updateParams(t,e){}disableEditing(){}enableEditing(){}enterInEditMode(){}getImageForAltText(){return null}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))}setAspectRatio(t,e){this.#h=!0;let s=t/e,{style:i}=this.div;i.aspectRatio=s,i.height="auto"}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.#y||=new Map;let{action:s}=t,i=this.#y.get(s);i&&clearTimeout(i),i=setTimeout((()=>{this._reportTelemetry(t),this.#y.delete(s),this.#y.size===0&&(this.#y=null)}),c._telemetryTimeout),this.#y.set(s,i)}else 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.#i=!1}disable(){this.div&&(this.div.tabIndex=-1),this.#i=!0}renderAnnotationElement(t){let e=t.container.querySelector(".annotationContent");if(e){if(e.nodeName==="CANVAS"){let s=e;e=document.createElement("div"),e.classList.add("annotationContent",this.editorType),s.before(e)}}else e=document.createElement("div"),e.classList.add("annotationContent",this.editorType),t.container.prepend(e);return e}resetAnnotationElement(t){let{firstChild:e}=t.container;e?.nodeName==="DIV"&&e.classList.contains("annotationContent")&&e.remove()}},ds=class extends U{constructor(t){super(t),this.annotationElementId=t.annotationElementId,this.deleted=!0}serialize(){return this.serializeDeleted()}},Mi=3285377520,rt=4294901760,mt=65535,pe=class{constructor(t){this.h1=t?4294967295&t:Mi,this.h2=t?4294967295&t:Mi}update(t){let e,s;if(typeof t=="string"){e=new Uint8Array(2*t.length),s=0;for(let f=0,m=t.length;f<m;f++){let b=t.charCodeAt(f);b<=255?e[s++]=b:(e[s++]=b>>>8,e[s++]=255&b)}}else{if(!ArrayBuffer.isView(t))throw new Error("Invalid data format, must be a string or TypedArray.");e=t.slice(),s=e.byteLength}let i=s>>2,n=s-4*i,r=new Uint32Array(e.buffer,0,i),a=0,o=0,h=this.h1,l=this.h2,d=3432918353,u=461845907,p=11601,g=13715;for(let f=0;f<i;f++)1&f?(a=r[f],a=a*d&rt|a*p&mt,a=a<<15|a>>>17,a=a*u&rt|a*g&mt,h^=a,h=h<<13|h>>>19,h=5*h+3864292196):(o=r[f],o=o*d&rt|o*p&mt,o=o<<15|o>>>17,o=o*u&rt|o*g&mt,l^=o,l=l<<13|l>>>19,l=5*l+3864292196);switch(a=0,n){case 3:a^=e[4*i+2]<<16;case 2:a^=e[4*i+1]<<8;case 1:a^=e[4*i],a=a*d&rt|a*p&mt,a=a<<15|a>>>17,a=a*u&rt|a*g&mt,1&i?h^=a:l^=a}this.h1=h,this.h2=l}hexdigest(){let t=this.h1,e=this.h2;return t^=e>>>1,t=3981806797*t&rt|36045*t&mt,e=4283543511*e&rt|(2950163797*(e<<16|t>>>16)&rt)>>>16,t^=e>>>1,t=444984403*t&rt|60499*t&mt,e=3301882366*e&rt|(3120437893*(e<<16|t>>>16)&rt)>>>16,t^=e>>>1,(t>>>0).toString(16).padStart(8,"0")+(e>>>0).toString(16).padStart(8,"0")}},us=Object.freeze({map:null,hash:"",transfer:void 0}),Gt=class{#t=!1;#e=null;#s=new Map;constructor(){this.onSetModified=null,this.onResetModified=null,this.onAnnotationEditor=null}getValue(t,e){let s=this.#s.get(t);return s===void 0?e:Object.assign(e,s)}getRawValue(t){return this.#s.get(t)}remove(t){if(this.#s.delete(t),this.#s.size===0&&this.resetModified(),typeof this.onAnnotationEditor=="function"){for(let e of this.#s.values())if(e instanceof U)return;this.onAnnotationEditor(null)}}setValue(t,e){let s=this.#s.get(t),i=!1;if(s!==void 0)for(let[n,r]of Object.entries(e))s[n]!==r&&(i=!0,s[n]=r);else i=!0,this.#s.set(t,e);i&&this.#i(),e instanceof U&&typeof this.onAnnotationEditor=="function"&&this.onAnnotationEditor(e.constructor._type)}has(t){return this.#s.has(t)}getAll(){return this.#s.size>0?wi(this.#s):null}setAll(t){for(let[e,s]of Object.entries(t))this.setValue(e,s)}get size(){return this.#s.size}#i(){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 ge(this)}get serializable(){if(this.#s.size===0)return us;let t=new Map,e=new pe,s=[],i=Object.create(null),n=!1;for(let[r,a]of this.#s){let o=a instanceof U?a.serialize(!1,i):a;o&&(t.set(r,o),e.update(`${r}:${JSON.stringify(o)}`),n||=!!o.bitmap)}if(n)for(let r of t.values())r.bitmap&&s.push(r.bitmap);return t.size>0?{map:t,hash:e.hexdigest(),transfer:s}:us}get editorStats(){let t=null,e=new Map;for(let s of this.#s.values()){if(!(s instanceof U))continue;let i=s.telemetryFinalData;if(!i)continue;let{type:n}=i;e.has(n)||e.set(n,Object.getPrototypeOf(s).constructor),t||=Object.create(null);let r=t[n]||=new Map;for(let[a,o]of Object.entries(i)){if(a==="type")continue;let h=r.get(a);h||(h=new Map,r.set(a,h));let l=h.get(o)??0;h.set(o,l+1)}}for(let[s,i]of e)t[s]=i.computeTelemetryFinalData(t[s]);return t}resetModifiedIds(){this.#e=null}get modifiedIds(){if(this.#e)return this.#e;let t=[];for(let e of this.#s.values())e instanceof U&&e.annotationElementId&&e.serialize()&&t.push(e.annotationElementId);return this.#e={ids:new Set(t),hash:t.join(",")}}},ge=class extends Gt{#t;constructor(t){super();let{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(){z("Should not call PrintAnnotationStorage.print")}get serializable(){return this.#t}get modifiedIds(){return N(this,"modifiedIds",{ids:new Set,hash:""})}},ps=class{#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));let e=this.styleElement.sheet;e.insertRule(t,e.cssRules.length)}clear(){for(let 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,_inspectFont:e}){if(t&&!this.#t.has(t.loadedName))if(X(!this.disableFontFace,"loadSystemFont shouldn't be called when `disableFontFace` is set."),this.isFontLoadingAPISupported){let{loadedName:s,src:i,style:n}=t,r=new FontFace(s,i,n);this.addNativeFontFace(r);try{await r.load(),this.#t.add(s),e?.(t)}catch{D(`Cannot load system font: ${t.baseFontName}, installing it could help to improve PDF rendering.`),this.removeNativeFontFace(r)}}else z("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){let s=t.createNativeFontFace();if(s){this.addNativeFontFace(s);try{await s.loaded}catch(i){throw D(`Failed to load font '${s.family}': '${i}'.`),t.disableFontFace=!0,i}}return}let e=t.createFontFaceRule();if(e){if(this.insertRule(e),this.isSyncFontLoadingSupported)return;await new Promise((s=>{let i=this._queueLoadingCallback(s);this._prepareFontLoadEvent(t,i)}))}}get isFontLoadingAPISupported(){return N(this,"isFontLoadingAPISupported",!!this._document?.fonts)}get isSyncFontLoadingSupported(){let t=!1;return(Q||typeof navigator<"u"&&typeof navigator?.userAgent=="string"&&/Mozilla\/5.0.*?rv:\d+.*? Gecko/.test(navigator.userAgent))&&(t=!0),N(this,"isSyncFontLoadingSupported",t)}_queueLoadingCallback(t){let{loadingRequests:e}=this,s={done:!1,complete:function(){for(X(!s.done,"completeRequest() cannot be called twice."),s.done=!0;e.length>0&&e[0].done;){let n=e.shift();setTimeout(n.callback,0)}},callback:t};return e.push(s),s}get _loadTestFont(){return N(this,"_loadTestFont",atob("T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQAABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwAAAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbmFtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAAAADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6AABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAAMQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAAAAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAAAAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQAAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMAAQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAAEAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgcA/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQAAAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAgABAAAAAAAAAAAD6AAAAAAAAA=="))}_prepareFontLoadEvent(t,e){function s(m,b){return m.charCodeAt(b)<<24|m.charCodeAt(b+1)<<16|m.charCodeAt(b+2)<<8|255&m.charCodeAt(b+3)}function i(m,b,v,A){return m.substring(0,b)+A+m.substring(b+v)}let n,r,a=this._document.createElement("canvas");a.width=1,a.height=1;let o=a.getContext("2d"),h=0,l=`lt${Date.now()}${this.loadTestFontId++}`,d=this._loadTestFont;d=i(d,976,l.length,l);let u=1482184792,p=s(d,16);for(n=0,r=l.length-3;n<r;n+=4)p=p-u+s(l,n)|0;n<l.length&&(p=p-u+s(l+"XXX",n)|0),d=i(d,16,4,(function(b){return String.fromCharCode(b>>24&255,b>>16&255,b>>8&255,255&b)})(p));let g=`@font-face {font-family:"${l}";src:${`url(data:font/opentype;base64,${btoa(d)});`}}`;this.insertRule(g);let f=this._document.createElement("div");f.style.visibility="hidden",f.style.width=f.style.height="10px",f.style.position="absolute",f.style.top=f.style.left="0px";for(let m of[t.loadedName,l]){let b=this._document.createElement("span");b.textContent="Hi",b.style.fontFamily=m,f.append(b)}this._document.body.append(f),(function m(b,v){if(++h>30){D("Load test font never loaded."),v();return}o.font="30px "+b,o.fillText(".",0,20),o.getImageData(0,0,1,1).data[3]>0?v():setTimeout(m.bind(null,b,v))})(l,(()=>{f.remove(),e.complete()}))}},gs=class{constructor(t,{disableFontFace:e=!1,fontExtraProperties:s=!1,inspectFont:i=null}){this.compiledGlyphs=Object.create(null);for(let n in t)this[n]=t[n];this.disableFontFace=e===!0,this.fontExtraProperties=s===!0,this._inspectFont=i}createNativeFontFace(){if(!this.data||this.disableFontFace)return null;let t;if(this.cssFontInfo){let e={weight:this.cssFontInfo.fontWeight};this.cssFontInfo.italicAngle&&(e.style=`oblique ${this.cssFontInfo.italicAngle}deg`),t=new FontFace(this.cssFontInfo.fontFamily,this.data,e)}else t=new FontFace(this.loadedName,this.data,{});return this._inspectFont?.(this),t}createFontFaceRule(){if(!this.data||this.disableFontFace)return null;let t=`url(data:${this.mimetype};base64,${(function(i){return Uint8Array.prototype.toBase64?i.toBase64():btoa(Gi(i))})(this.data)});`,e;if(this.cssFontInfo){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}}`}else e=`@font-face {font-family:"${this.loadedName}";src:${t}}`;return this._inspectFont?.(this,t),e}getPathGenerator(t,e){if(this.compiledGlyphs[e]!==void 0)return this.compiledGlyphs[e];let s=this.loadedName+"_path_"+e,i;try{i=t.get(s)}catch(r){D(`getPathGenerator - ignoring character: "${r}".`)}let n=new Path2D(i||"");return this.fontExtraProperties||t.delete(s),this.compiledGlyphs[e]=n}},ki=1,Ti=2,Ri=1,Je=2,Pi=3,Ii=4,Li=5,Di=6,te=7,Ze=8;function Fi(){}function tt(c){if(c instanceof lt||c instanceof Ht||c instanceof St||c instanceof oe||c instanceof It||c instanceof Bt)return c;switch(c instanceof Error||typeof c=="object"&&c!==null||z('wrapReason: Expected "reason" to be a (possibly cloned) Error.'),c.name){case"AbortException":return new lt(c.message);case"InvalidPDFException":return new Ht(c.message);case"MissingPDFException":return new St(c.message);case"PasswordException":return new oe(c.message,c.code);case"UnexpectedResponseException":return new It(c.message,c.status);case"UnknownErrorException":return new Bt(c.message,c.details)}return new Bt(c.message,c.toString())}var yt=class{#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.#i(t);return}if(t.callback){let s=t.callbackId,i=this.callbackCapabilities[s];if(!i)throw new Error(`Cannot resolve callback ${s}`);if(delete this.callbackCapabilities[s],t.callback===ki)i.resolve(t.data);else{if(t.callback!==Ti)throw new Error("Unexpected callback case");i.reject(tt(t.reason))}return}let e=this.actionHandler[t.action];if(!e)throw new Error(`Unknown action from worker: ${t.action}`);if(t.callbackId){let s=this.sourceName,i=t.sourceName,n=this.comObj;Promise.try(e,t.data).then((function(r){n.postMessage({sourceName:s,targetName:i,callback:ki,callbackId:t.callbackId,data:r})}),(function(r){n.postMessage({sourceName:s,targetName:i,callback:Ti,callbackId:t.callbackId,reason:tt(r)})}))}else t.streamId?this.#s(t):e(t.data)}on(t,e){let 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){let 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){let n=this.streamId++,r=this.sourceName,a=this.targetName,o=this.comObj;return new ReadableStream({start:h=>{let l=Promise.withResolvers();return this.streamControllers[n]={controller:h,startCall:l,pullCall:null,cancelCall:null,isClosed:!1},o.postMessage({sourceName:r,targetName:a,action:t,streamId:n,data:e,desiredSize:h.desiredSize},i),l.promise},pull:h=>{let l=Promise.withResolvers();return this.streamControllers[n].pullCall=l,o.postMessage({sourceName:r,targetName:a,stream:Di,streamId:n,desiredSize:h.desiredSize}),l.promise},cancel:h=>{X(h instanceof Error,"cancel must have a valid reason");let l=Promise.withResolvers();return this.streamControllers[n].cancelCall=l,this.streamControllers[n].isClosed=!0,o.postMessage({sourceName:r,targetName:a,stream:Ri,streamId:n,reason:tt(h)}),l.promise}},s)}#s(t){let e=t.streamId,s=this.sourceName,i=t.sourceName,n=this.comObj,r=this,a=this.actionHandler[t.action],o={enqueue(h,l=1,d){if(this.isCancelled)return;let u=this.desiredSize;this.desiredSize-=l,u>0&&this.desiredSize<=0&&(this.sinkCapability=Promise.withResolvers(),this.ready=this.sinkCapability.promise),n.postMessage({sourceName:s,targetName:i,stream:Ii,streamId:e,chunk:h},d)},close(){this.isCancelled||(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:Pi,streamId:e}),delete r.streamSinks[e])},error(h){X(h instanceof Error,"error must have a valid reason"),this.isCancelled||(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:Li,streamId:e,reason:tt(h)}))},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:Ze,streamId:e,success:!0})}),(function(h){n.postMessage({sourceName:s,targetName:i,stream:Ze,streamId:e,reason:tt(h)})}))}#i(t){let e=t.streamId,s=this.sourceName,i=t.sourceName,n=this.comObj,r=this.streamControllers[e],a=this.streamSinks[e];switch(t.stream){case Ze:t.success?r.startCall.resolve():r.startCall.reject(tt(t.reason));break;case te:t.success?r.pullCall.resolve():r.pullCall.reject(tt(t.reason));break;case Di:if(!a){n.postMessage({sourceName:s,targetName:i,stream:te,streamId:e,success:!0});break}a.desiredSize<=0&&t.desiredSize>0&&a.sinkCapability.resolve(),a.desiredSize=t.desiredSize,Promise.try(a.onPull||Fi).then((function(){n.postMessage({sourceName:s,targetName:i,stream:te,streamId:e,success:!0})}),(function(h){n.postMessage({sourceName:s,targetName:i,stream:te,streamId:e,reason:tt(h)})}));break;case Ii:if(X(r,"enqueue should have stream controller"),r.isClosed)break;r.controller.enqueue(t.chunk);break;case Pi:if(X(r,"close should have stream controller"),r.isClosed)break;r.isClosed=!0,r.controller.close(),this.#r(r,e);break;case Li:X(r,"error should have stream controller"),r.controller.error(tt(t.reason)),this.#r(r,e);break;case Je:t.success?r.cancelCall.resolve():r.cancelCall.reject(tt(t.reason)),this.#r(r,e);break;case Ri:if(!a)break;let o=tt(t.reason);Promise.try(a.onCancel||Fi,o).then((function(){n.postMessage({sourceName:s,targetName:i,stream:Je,streamId:e,success:!0})}),(function(h){n.postMessage({sourceName:s,targetName:i,stream:Je,streamId:e,reason:tt(h)})})),a.sinkCapability.reject(o),a.isCancelled=!0,delete this.streamSinks[e];break;default:throw new Error("Unexpected stream case")}}async#r(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}},fe=class{#t=!1;constructor({enableHWA:t=!1}){this.#t=t}create(t,e){if(t<=0||e<=0)throw new Error("Invalid canvas size");let 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){z("Abstract method `_createCanvas` called.")}},me=class{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.");let 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){z("Abstract method `_fetch` called.")}},be=class extends me{async _fetch(t){let e=await Ve(t,this.isCompressed?"arraybuffer":"text");return e instanceof ArrayBuffer?new Uint8Array(e):je(e)}},ve=class{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){}},Ae=class{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.");let e=`${this.baseUrl}${t}`;return this._fetch(e).catch((s=>{throw new Error(`Unable to load font data at: ${e}`)}))}async _fetch(t){z("Abstract method `_fetch` called.")}},we=class extends Ae{async _fetch(t){let e=await Ve(t,"arraybuffer");return new Uint8Array(e)}};Q&&D("Please use the `legacy` build in Node.js environments.");async function Ui(c){let t=process.getBuiltinModule("fs"),e=await t.promises.readFile(c);return new Uint8Array(e)}var _t="Fill",ye="Stroke",$t="Shading";function fs(c,t){if(!t)return;let e=t[2]-t[0],s=t[3]-t[1],i=new Path2D;i.rect(t[0],t[1],e,s),c.clip(i)}var Ut=class{getPattern(){z("Abstract method `getPattern` called.")}},ms=class extends Ut{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(let s of this._colorStops)e.addColorStop(s[0],s[1]);return e}getPattern(t,e,s,i){let n;if(i===ye||i===_t){let r=e.current.getClippedPathBoundingBox(i,G(t))||[0,0,0,0],a=Math.ceil(r[2]-r[0])||1,o=Math.ceil(r[3]-r[1])||1,h=e.cachedCanvases.getCanvas("pattern",a,o),l=h.context;l.clearRect(0,0,l.canvas.width,l.canvas.height),l.beginPath(),l.rect(0,0,l.canvas.width,l.canvas.height),l.translate(-r[0],-r[1]),s=C.transform(s,[1,0,0,1,r[0],r[1]]),l.transform(...e.baseTransform),this.matrix&&l.transform(...this.matrix),fs(l,this._bbox),l.fillStyle=this._createGradient(l),l.fill(),n=t.createPattern(h.canvas,"no-repeat");let d=new DOMMatrix(s);n.setTransform(d)}else fs(t,this._bbox),n=this._createGradient(t);return n}};function ts(c,t,e,s,i,n,r,a){let o=t.coords,h=t.colors,l=c.data,d=4*c.width,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);let p=(o[e]+t.offsetX)*t.scaleX,g=(o[e+1]+t.offsetY)*t.scaleY,f=(o[s]+t.offsetX)*t.scaleX,m=(o[s+1]+t.offsetY)*t.scaleY,b=(o[i]+t.offsetX)*t.scaleX,v=(o[i+1]+t.offsetY)*t.scaleY;if(g>=v)return;let A=h[n],y=h[n+1],w=h[n+2],x=h[r],_=h[r+1],E=h[r+2],M=h[a],T=h[a+1],P=h[a+2],O=Math.round(g),$=Math.round(v),F,j,V,k,I,nt,dt,ut;for(let J=O;J<=$;J++){if(J<m){let W=J<g?0:(g-J)/(g-m);F=p-(p-f)*W,j=A-(A-x)*W,V=y-(y-_)*W,k=w-(w-E)*W}else{let W;W=J>v?1:m===v?0:(m-J)/(m-v),F=f-(f-b)*W,j=x-(x-M)*W,V=_-(_-T)*W,k=E-(E-P)*W}let Y;Y=J<g?0:J>v?1:(g-J)/(g-v),I=p-(p-b)*Y,nt=A-(A-M)*Y,dt=y-(y-T)*Y,ut=w-(w-P)*Y;let ft=Math.round(Math.min(F,I)),st=Math.round(Math.max(F,I)),H=d*J+4*ft;for(let W=ft;W<=st;W++)Y=(F-W)/(F-I),Y<0?Y=0:Y>1&&(Y=1),l[H++]=j-(j-nt)*Y|0,l[H++]=V-(V-dt)*Y|0,l[H++]=k-(k-ut)*Y|0,l[H++]=255}}function Vn(c,t,e){let s=t.coords,i=t.colors,n,r;switch(t.type){case"lattice":let a=t.verticesPerRow,o=Math.floor(s.length/a)-1,h=a-1;for(n=0;n<o;n++){let l=n*a;for(let d=0;d<h;d++,l++)ts(c,e,s[l],s[l+1],s[l+a],i[l],i[l+1],i[l+a]),ts(c,e,s[l+a+1],s[l+1],s[l+a],i[l+a+1],i[l+1],i[l+a])}break;case"triangles":for(n=0,r=s.length;n<r;n+=3)ts(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")}}var bs=class extends Ut{constructor(t){super(),this._coords=t[2],this._colors=t[3],this._figures=t[4],this._bounds=t[5],this._bbox=t[7],this._background=t[8],this.matrix=null}_createMeshCanvas(t,e,s){let i=Math.floor(this._bounds[0]),n=Math.floor(this._bounds[1]),r=Math.ceil(this._bounds[2])-i,a=Math.ceil(this._bounds[3])-n,o=Math.min(Math.ceil(Math.abs(r*t[0]*1.1)),3e3),h=Math.min(Math.ceil(Math.abs(a*t[1]*1.1)),3e3),l=r/o,d=a/h,u={coords:this._coords,colors:this._colors,offsetX:-i,offsetY:-n,scaleX:1/l,scaleY:1/d},p=o+4,g=h+4,f=s.getCanvas("mesh",p,g),m=f.context,b=m.createImageData(o,h);if(e){let v=b.data;for(let A=0,y=v.length;A<y;A+=4)v[A]=e[0],v[A+1]=e[1],v[A+2]=e[2],v[A+3]=255}for(let v of this._figures)Vn(b,v,u);return m.putImageData(b,2,2),{canvas:f.canvas,offsetX:i-2*l,offsetY:n-2*d,scaleX:l,scaleY:d}}getPattern(t,e,s,i){fs(t,this._bbox);let n;if(i===$t)n=C.singularValueDecompose2dScale(G(t));else if(n=C.singularValueDecompose2dScale(e.baseTransform),this.matrix){let a=C.singularValueDecompose2dScale(this.matrix);n=[n[0]*a[0],n[1]*a[1]]}let r=this._createMeshCanvas(n,i===$t?null:this._background,e.cachedCanvases);return i!==$t&&(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")}},vs=class extends Ut{getPattern(){return"hotpink"}},Gn=1,Un=2,As=class c{static MAX_PATTERN_SIZE=3e3;constructor(t,e,s,i,n){this.operatorList=t[2],this.matrix=t[3],this.bbox=t[4],this.xstep=t[5],this.ystep=t[6],this.paintType=t[7],this.tilingType=t[8],this.color=e,this.ctx=s,this.canvasGraphicsFactory=i,this.baseTransform=n}createPatternCanvas(t){let{bbox:e,operatorList:s,paintType:i,tilingType:n,color:r,canvasGraphicsFactory:a}=this,{xstep:o,ystep:h}=this;o=Math.abs(o),h=Math.abs(h),ze("TilingType: "+n);let l=e[0],d=e[1],u=e[2],p=e[3],g=u-l,f=p-d,m=C.singularValueDecompose2dScale(this.matrix),b=C.singularValueDecompose2dScale(this.baseTransform),v=m[0]*b[0],A=m[1]*b[1],y=g,w=f,x=!1,_=!1,E=Math.ceil(o*v),M=Math.ceil(h*A);E>=Math.ceil(g*v)?y=o:x=!0,M>=Math.ceil(f*A)?w=h:_=!0;let T=this.getSizeAndScale(y,this.ctx.canvas.width,v),P=this.getSizeAndScale(w,this.ctx.canvas.height,A),O=t.cachedCanvases.getCanvas("pattern",T.size,P.size),$=O.context,F=a.createCanvasGraphics($);if(F.groupLevel=t.groupLevel,this.setFillAndStrokeStyleToContext(F,i,r),$.translate(-T.scale*l,-P.scale*d),F.transform(T.scale,0,0,P.scale,0,0),$.save(),this.clipBbox(F,l,d,u,p),F.baseTransform=G(F.ctx),F.executeOperatorList(s),F.endDrawing(),$.restore(),x||_){let j=O.canvas;x&&(y=o),_&&(w=h);let V=this.getSizeAndScale(y,this.ctx.canvas.width,v),k=this.getSizeAndScale(w,this.ctx.canvas.height,A),I=V.size,nt=k.size,dt=t.cachedCanvases.getCanvas("pattern-workaround",I,nt),ut=dt.context,J=x?Math.floor(g/o):0,Y=_?Math.floor(f/h):0;for(let ft=0;ft<=J;ft++)for(let st=0;st<=Y;st++)ut.drawImage(j,I*ft,nt*st,I,nt,0,0,I,nt);return{canvas:dt.canvas,scaleX:V.scale,scaleY:k.scale,offsetX:l,offsetY:d}}return{canvas:O.canvas,scaleX:T.scale,scaleY:P.scale,offsetX:l,offsetY:d}}getSizeAndScale(t,e,s){let i=Math.max(c.MAX_PATTERN_SIZE,e),n=Math.ceil(t*s);return n>=i?n=i:s=n/t,{scale:s,size:n}}clipBbox(t,e,s,i,n){let r=i-e,a=n-s;t.ctx.rect(e,s,r,a),t.current.updateRectMinMax(G(t.ctx),[e,s,i,n]),t.clip(),t.endPath()}setFillAndStrokeStyleToContext(t,e,s){let i=t.ctx,n=t.current;switch(e){case Gn:let r=this.ctx;i.fillStyle=r.fillStyle,i.strokeStyle=r.strokeStyle,n.fillColor=r.fillStyle,n.strokeColor=r.strokeStyle;break;case Un:let a=C.makeHexColor(s[0],s[1],s[2]);i.fillStyle=a,i.strokeStyle=a,n.fillColor=a,n.strokeColor=a;break;default:throw new is(`Unsupported paint type: ${e}`)}}getPattern(t,e,s,i){let n=s;i!==$t&&(n=C.transform(n,e.baseTransform),this.matrix&&(n=C.transform(n,this.matrix)));let r=this.createPatternCanvas(e),a=new DOMMatrix(n);a=a.translate(r.offsetX,r.offsetY),a=a.scale(1/r.scaleX,1/r.scaleY);let o=t.createPattern(r.canvas,"repeat");return o.setTransform(a),o}};function Wn({src:c,srcPos:t=0,dest:e,width:s,height:i,nonBlackColor:n=4294967295,inverseDecode:r=!1}){let a=K.isLittleEndian?4278190080:255,[o,h]=r?[n,a]:[a,n],l=s>>3,d=7&s,u=c.length;e=new Uint32Array(e.buffer);let p=0;for(let g=0;g<i;g++){for(let m=t+l;t<m;t++){let b=t<u?c[t]:255;e[p++]=128&b?h:o,e[p++]=64&b?h:o,e[p++]=32&b?h:o,e[p++]=16&b?h:o,e[p++]=8&b?h:o,e[p++]=4&b?h:o,e[p++]=2&b?h:o,e[p++]=1&b?h:o}if(d===0)continue;let f=t<u?c[t++]:255;for(let m=0;m<d;m++)e[p++]=f&1<<7-m?h:o}return{srcPos:t,destPos:p}}var et=16,ws=class{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(let t in this.cache){let e=this.cache[t];this.canvasFactory.destroy(e),delete this.cache[t]}}};function ee(c,t,e,s,i,n,r,a,o,h){let[l,d,u,p,g,f]=G(c);if(d===0&&u===0){let m=r*l+g,b=Math.round(m),v=a*p+f,A=Math.round(v),y=(r+o)*l+g,w=Math.abs(Math.round(y)-b)||1,x=(a+h)*p+f,_=Math.abs(Math.round(x)-A)||1;return c.setTransform(Math.sign(l),0,0,Math.sign(p),b,A),c.drawImage(t,e,s,i,n,0,0,w,_),c.setTransform(l,d,u,p,g,f),[w,_]}if(l===0&&p===0){let m=a*u+g,b=Math.round(m),v=r*d+f,A=Math.round(v),y=(a+h)*u+g,w=Math.abs(Math.round(y)-b)||1,x=(r+o)*d+f,_=Math.abs(Math.round(x)-A)||1;return c.setTransform(0,Math.sign(d),Math.sign(u),0,b,A),c.drawImage(t,e,s,i,n,0,0,_,w),c.setTransform(l,d,u,p,g,f),[_,w]}return c.drawImage(t,e,s,i,n,r,a,o,h),[Math.hypot(l,d)*o,Math.hypot(u,p)*h]}var _e=class{constructor(t,e){this.alphaIsShape=!1,this.fontSize=0,this.fontSizeScale=1,this.textMatrix=ji,this.textMatrixScale=1,this.fontMatrix=ss,this.leading=0,this.x=0,this.y=0,this.lineX=0,this.lineY=0,this.charSpacing=0,this.wordSpacing=0,this.textHScale=1,this.textRenderingMode=ne,this.textRise=0,this.fillColor="#000000",this.strokeColor="#000000",this.patternFill=!1,this.patternStroke=!1,this.fillAlpha=1,this.strokeAlpha=1,this.lineWidth=1,this.activeSMask=null,this.transferMaps="none",this.startNewPathAndClipBox([0,0,t,e])}clone(){let t=Object.create(this);return t.clipBox=this.clipBox.slice(),t}setCurrentPoint(t,e){this.x=t,this.y=e}updatePathMinMax(t,e,s){[e,s]=C.applyTransform([e,s],t),this.minX=Math.min(this.minX,e),this.minY=Math.min(this.minY,s),this.maxX=Math.max(this.maxX,e),this.maxY=Math.max(this.maxY,s)}updateRectMinMax(t,e){let s=C.applyTransform(e,t),i=C.applyTransform(e.slice(2),t),n=C.applyTransform([e[0],e[3]],t),r=C.applyTransform([e[2],e[1]],t);this.minX=Math.min(this.minX,s[0],i[0],n[0],r[0]),this.minY=Math.min(this.minY,s[1],i[1],n[1],r[1]),this.maxX=Math.max(this.maxX,s[0],i[0],n[0],r[0]),this.maxY=Math.max(this.maxY,s[1],i[1],n[1],r[1])}updateScalingPathMinMax(t,e){C.scaleMinMax(t,e),this.minX=Math.min(this.minX,e[0]),this.minY=Math.min(this.minY,e[1]),this.maxX=Math.max(this.maxX,e[2]),this.maxY=Math.max(this.maxY,e[3])}updateCurvePathMinMax(t,e,s,i,n,r,a,o,h,l){let d=C.bezierBoundingBox(e,s,i,n,r,a,o,h,l);l||this.updateRectMinMax(t,d)}getPathBoundingBox(t=_t,e=null){let s=[this.minX,this.minY,this.maxX,this.maxY];if(t===ye){e||z("Stroke bounding box must include transform.");let i=C.singularValueDecompose2dScale(e),n=i[0]*this.lineWidth/2,r=i[1]*this.lineWidth/2;s[0]-=n,s[1]-=r,s[2]+=n,s[3]+=r}return s}updateClipFromPath(){let t=C.intersect(this.clipBox,this.getPathBoundingBox());this.startNewPathAndClipBox(t||[0,0,0,0])}isEmptyClip(){return this.minX===1/0}startNewPathAndClipBox(t){this.clipBox=t,this.minX=1/0,this.minY=1/0,this.maxX=0,this.maxY=0}getClippedPathBoundingBox(t=_t,e=null){return C.intersect(this.clipBox,this.getPathBoundingBox(t,e))}};function Ni(c,t){if(t instanceof ImageData){c.putImageData(t,0,0);return}let e=t.height,s=t.width,i=e%et,n=(e-i)/et,r=i===0?n:n+1,a=c.createImageData(s,et),o,h=0,l=t.data,d=a.data,u,p,g,f;if(t.kind===re.GRAYSCALE_1BPP){let m=l.byteLength,b=new Uint32Array(d.buffer,0,d.byteLength>>2),v=b.length,A=s+7>>3,y=4294967295,w=K.isLittleEndian?4278190080:255;for(u=0;u<r;u++){for(g=u<n?et:i,o=0,p=0;p<g;p++){let x=m-h,_=0,E=x>A?s:8*x-7,M=-8&E,T=0,P=0;for(;_<M;_+=8)P=l[h++],b[o++]=128&P?y:w,b[o++]=64&P?y:w,b[o++]=32&P?y:w,b[o++]=16&P?y:w,b[o++]=8&P?y:w,b[o++]=4&P?y:w,b[o++]=2&P?y:w,b[o++]=1&P?y:w;for(;_<E;_++)T===0&&(P=l[h++],T=128),b[o++]=P&T?y:w,T>>=1}for(;o<v;)b[o++]=0;c.putImageData(a,0,u*et)}}else if(t.kind===re.RGBA_32BPP){for(p=0,f=s*et*4,u=0;u<n;u++)d.set(l.subarray(h,h+f)),h+=f,c.putImageData(a,0,p),p+=et;u<r&&(f=s*i*4,d.set(l.subarray(h,h+f)),c.putImageData(a,0,p))}else{if(t.kind!==re.RGB_24BPP)throw new Error(`bad image kind: ${t.kind}`);for(g=et,f=s*g,u=0;u<r;u++){for(u>=n&&(g=i,f=s*g),o=0,p=f;p--;)d[o++]=l[h++],d[o++]=l[h++],d[o++]=l[h++],d[o++]=255;c.putImageData(a,0,u*et)}}}function Oi(c,t){if(t.bitmap){c.drawImage(t.bitmap,0,0);return}let e=t.height,s=t.width,i=e%et,n=(e-i)/et,r=i===0?n:n+1,a=c.createImageData(s,et),o=0,h=t.data,l=a.data;for(let d=0;d<r;d++){let u=d<n?et:i;({srcPos:o}=Wn({src:h,srcPos:o,dest:l,width:s,height:u,nonBlackColor:0})),c.putImageData(a,0,d*et)}}function Dt(c,t){let e=["strokeStyle","fillStyle","fillRule","globalAlpha","lineWidth","lineCap","lineJoin","miterLimit","globalCompositeOperation","font","filter"];for(let s of e)c[s]!==void 0&&(t[s]=c[s]);c.setLineDash!==void 0&&(t.setLineDash(c.getLineDash()),t.lineDashOffset=c.lineDashOffset)}function se(c){if(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),!Q){let{filter:t}=c;t!=="none"&&t!==""&&(c.filter="none")}}function Bi(c,t){if(t)return!0;let e=C.singularValueDecompose2dScale(c);e[0]=Math.fround(e[0]),e[1]=Math.fround(e[1]);let s=Math.fround((globalThis.devicePixelRatio||1)*At.PDF_TO_CSS_UNITS);return e[0]<=s&&e[1]<=s}var qn=["butt","round","square"],Xn=["miter","round","bevel"],Yn={},$i={},Rt=class c{constructor(t,e,s,i,n,{optionalContentConfig:r,markedContentStack:a=null},o,h){this.ctx=t,this.current=new _e(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.processingType3=null,this.baseTransform=null,this.baseTransformStack=[],this.groupLevel=0,this.smaskStack=[],this.smaskCounter=0,this.tempSMask=null,this.suspendedCtx=null,this.contentVisible=!0,this.markedContentStack=a||[],this.optionalContentConfig=r,this.cachedCanvases=new ws(this.canvasFactory),this.cachedPatterns=new Map,this.annotationCanvasMap=o,this.viewportScale=1,this.outputScaleX=1,this.outputScaleY=1,this.pageColors=h,this._cachedScaleForStroking=[-1,0],this._cachedGetSinglePixelWidth=null,this._cachedBitmapsMap=new Map}getObject(t,e=null){return typeof t=="string"?t.startsWith("g_")?this.commonObjs.get(t):this.objs.get(t):e}beginDrawing({transform:t,viewport:e,transparency:s=!1,background:i=null}){let 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){let 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(...G(this.compositeCtx))}this.ctx.save(),se(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=G(this.ctx)}executeOperatorList(t,e,s,i){let n=t.argsArray,r=t.fnArray,a=e||0,o=n.length;if(o===a)return a;let h=o-a>10&&typeof s=="function",l=h?Date.now()+15:0,d=0,u=this.commonObjs,p=this.objs,g;for(;;){if(i!==void 0&&a===i.nextBreakPoint)return i.breakIt(a,s),a;if(g=r[a],g!==at.dependency)this[g].apply(this,n[a]);else for(let f of n[a]){let m=f.startsWith("g_")?u:p;if(!m.has(f))return m.get(f,s),a}if(a++,a===o)return a;if(h&&++d>10){if(Date.now()>l)return s(),a;d=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(let t of this._cachedBitmapsMap.values()){for(let 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){let t=this.filterFactory.addHCMFilter(this.pageColors.foreground,this.pageColors.background);if(t!=="none"){let e=this.ctx.filter;this.ctx.filter=t,this.ctx.drawImage(this.ctx.canvas,0,0),this.ctx.filter=e}}}_scaleImage(t,e){let s=t.width??t.displayWidth,i=t.height??t.displayHeight,n,r,a=Math.max(Math.hypot(e[0],e[1]),1),o=Math.max(Math.hypot(e[2],e[3]),1),h=s,l=i,d="prescale1";for(;a>2&&h>1||o>2&&l>1;){let u=h,p=l;a>2&&h>1&&(u=h>=16384?Math.floor(h/2)-1||1:Math.ceil(h/2),a/=h/u),o>2&&l>1&&(p=l>=16384?Math.floor(l/2)-1||1:Math.ceil(l)/2,o/=l/p),n=this.cachedCanvases.getCanvas(d,u,p),r=n.context,r.clearRect(0,0,u,p),r.drawImage(t,0,0,h,l,0,0,u,p),t=n.canvas,h=u,l=p,d=d==="prescale1"?"prescale2":"prescale1"}return{img:t,paintWidth:h,paintHeight:l}}_createMaskCanvas(t){let e=this.ctx,{width:s,height:i}=t,n=this.current.fillColor,r=this.current.patternFill,a=G(e),o,h,l,d;if((t.bitmap||t.data)&&t.count>1){let E=t.bitmap||t.data.buffer;h=JSON.stringify(r?a:[a.slice(0,4),n]),o=this._cachedBitmapsMap.get(E),o||(o=new Map,this._cachedBitmapsMap.set(E,o));let M=o.get(h);if(M&&!r)return{canvas:M,offsetX:Math.round(Math.min(a[0],a[2])+a[4]),offsetY:Math.round(Math.min(a[1],a[3])+a[5])};l=M}l||(d=this.cachedCanvases.getCanvas("maskCanvas",s,i),Oi(d.context,t));let u=C.transform(a,[1/s,0,0,-1/i,0,0]);u=C.transform(u,[1,0,0,1,0,-i]);let[p,g,f,m]=C.getAxialAlignedBoundingBox([0,0,s,i],u),b=Math.round(f-p)||1,v=Math.round(m-g)||1,A=this.cachedCanvases.getCanvas("fillCanvas",b,v),y=A.context,w=p,x=g;y.translate(-w,-x),y.transform(...u),l||(l=this._scaleImage(d.canvas,ht(y)),l=l.img,o&&r&&o.set(h,l)),y.imageSmoothingEnabled=Bi(G(y),t.interpolate),ee(y,l,0,0,l.width,l.height,0,0,s,i),y.globalCompositeOperation="source-in";let _=C.transform(ht(y),[1,0,0,1,-w,-x]);return y.fillStyle=r?n.getPattern(e,this,_,_t):n,y.fillRect(0,0,s,i),o&&!r&&(this.cachedCanvases.delete("fillCanvas"),o.set(h,A.canvas)),{canvas:A.canvas,offsetX:Math.round(w),offsetY:Math.round(x)}}setLineWidth(t){t!==this.current.lineWidth&&(this._cachedScaleForStroking[0]=-1),this.current.lineWidth=t,this.ctx.lineWidth=t}setLineCap(t){this.ctx.lineCap=qn[t]}setLineJoin(t){this.ctx.lineJoin=Xn[t]}setMiterLimit(t){this.ctx.miterLimit=t}setDash(t,e){let s=this.ctx;s.setLineDash!==void 0&&(s.setLineDash(t),s.lineDashOffset=e)}setRenderingIntent(t){}setFlatness(t){}setGState(t){for(let[e,s]of t)switch(e){case"LW":this.setLineWidth(s);break;case"LC":this.setLineCap(s);break;case"LJ":this.setLineJoin(s);break;case"ML":this.setMiterLimit(s);break;case"D":this.setDash(s[0],s[1]);break;case"RI":this.setRenderingIntent(s);break;case"FL":this.setFlatness(s);break;case"Font":this.setFont(s[0],s[1]);break;case"CA":this.current.strokeAlpha=s;break;case"ca":this.current.fillAlpha=s,this.ctx.globalAlpha=s;break;case"BM":this.ctx.globalCompositeOperation=s;break;case"SMask":this.current.activeSMask=s?this.tempSMask:null,this.tempSMask=null,this.checkSMaskState();break;case"TR":this.ctx.filter=this.current.transferMaps=this.filterFactory.addFilter(s)}}get inSMaskMode(){return!!this.suspendedCtx}checkSMaskState(){let t=this.inSMaskMode;this.current.activeSMask&&!t?this.beginSMaskMode():!this.current.activeSMask&&t&&this.endSMaskMode()}beginSMaskMode(){if(this.inSMaskMode)throw new Error("beginSMaskMode called while already in smask mode");let t=this.ctx.canvas.width,e=this.ctx.canvas.height,s="smaskGroupAt"+this.groupLevel,i=this.cachedCanvases.getCanvas(s,t,e);this.suspendedCtx=this.ctx,this.ctx=i.context;let n=this.ctx;n.setTransform(...G(this.suspendedCtx)),Dt(this.suspendedCtx,n),(function(a,o){if(a._removeMirroring)throw new Error("Context is already forwarding operations.");a.__originalSave=a.save,a.__originalRestore=a.restore,a.__originalRotate=a.rotate,a.__originalScale=a.scale,a.__originalTranslate=a.translate,a.__originalTransform=a.transform,a.__originalSetTransform=a.setTransform,a.__originalResetTransform=a.resetTransform,a.__originalClip=a.clip,a.__originalMoveTo=a.moveTo,a.__originalLineTo=a.lineTo,a.__originalBezierCurveTo=a.bezierCurveTo,a.__originalRect=a.rect,a.__originalClosePath=a.closePath,a.__originalBeginPath=a.beginPath,a._removeMirroring=()=>{a.save=a.__originalSave,a.restore=a.__originalRestore,a.rotate=a.__originalRotate,a.scale=a.__originalScale,a.translate=a.__originalTranslate,a.transform=a.__originalTransform,a.setTransform=a.__originalSetTransform,a.resetTransform=a.__originalResetTransform,a.clip=a.__originalClip,a.moveTo=a.__originalMoveTo,a.lineTo=a.__originalLineTo,a.bezierCurveTo=a.__originalBezierCurveTo,a.rect=a.__originalRect,a.closePath=a.__originalClosePath,a.beginPath=a.__originalBeginPath,delete a._removeMirroring},a.save=function(){o.save(),this.__originalSave()},a.restore=function(){o.restore(),this.__originalRestore()},a.translate=function(l,d){o.translate(l,d),this.__originalTranslate(l,d)},a.scale=function(l,d){o.scale(l,d),this.__originalScale(l,d)},a.transform=function(l,d,u,p,g,f){o.transform(l,d,u,p,g,f),this.__originalTransform(l,d,u,p,g,f)},a.setTransform=function(l,d,u,p,g,f){o.setTransform(l,d,u,p,g,f),this.__originalSetTransform(l,d,u,p,g,f)},a.resetTransform=function(){o.resetTransform(),this.__originalResetTransform()},a.rotate=function(l){o.rotate(l),this.__originalRotate(l)},a.clip=function(l){o.clip(l),this.__originalClip(l)},a.moveTo=function(h,l){o.moveTo(h,l),this.__originalMoveTo(h,l)},a.lineTo=function(h,l){o.lineTo(h,l),this.__originalLineTo(h,l)},a.bezierCurveTo=function(h,l,d,u,p,g){o.bezierCurveTo(h,l,d,u,p,g),this.__originalBezierCurveTo(h,l,d,u,p,g)},a.rect=function(h,l,d,u){o.rect(h,l,d,u),this.__originalRect(h,l,d,u)},a.closePath=function(){o.closePath(),this.__originalClosePath()},a.beginPath=function(){o.beginPath(),this.__originalBeginPath()}})(n,this.suspendedCtx),this.setGState([["BM","source-over"],["ca",1],["CA",1]])}endSMaskMode(){if(!this.inSMaskMode)throw new Error("endSMaskMode called while not in smask mode");this.ctx._removeMirroring(),Dt(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];let 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){let 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,h,l,d){let u=t.canvas,p=o-l,g=h-d;if(r){let m=C.makeHexColor(...r);if(p<0||g<0||p+s>u.width||g+i>u.height){let b=this.cachedCanvases.getCanvas("maskExtension",s,i),v=b.context;v.drawImage(u,-p,-g),v.globalCompositeOperation="destination-atop",v.fillStyle=m,v.fillRect(0,0,s,i),v.globalCompositeOperation="source-over",u=b.canvas,p=g=0}else{t.save(),t.globalAlpha=1,t.setTransform(1,0,0,1,0,0);let b=new Path2D;b.rect(p,g,s,i),t.clip(b),t.globalCompositeOperation="destination-atop",t.fillStyle=m,t.fillRect(p,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));let f=new Path2D;f.rect(o,h,s,i),e.clip(f),e.globalCompositeOperation="destination-in",e.drawImage(u,p,g,s,i,o,h,s,i),e.restore()}save(){this.inSMaskMode?(Dt(this.ctx,this.suspendedCtx),this.suspendedCtx.save()):this.ctx.save();let t=this.current;this.stateStack.push(t),this.current=t.clone()}restore(){this.stateStack.length===0&&this.inSMaskMode&&this.endSMaskMode(),this.stateStack.length!==0&&(this.current=this.stateStack.pop(),this.inSMaskMode?(this.suspendedCtx.restore(),Dt(this.suspendedCtx,this.ctx)):this.ctx.restore(),this.checkSMaskState(),this.pendingClip=null,this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null)}transform(t,e,s,i,n,r){this.ctx.transform(t,e,s,i,n,r),this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null}constructPath(t,e,s){let i=this.ctx,n=this.current,r,a,o=n.x,h=n.y,l=G(i),d=l[0]===0&&l[3]===0||l[1]===0&&l[2]===0,u=d?s.slice(0):null;for(let p=0,g=0,f=t.length;p<f;p++)switch(0|t[p]){case at.rectangle:o=e[g++],h=e[g++];let m=e[g++],b=e[g++],v=o+m,A=h+b;i.moveTo(o,h),m===0||b===0?i.lineTo(v,A):(i.lineTo(v,h),i.lineTo(v,A),i.lineTo(o,A)),d||n.updateRectMinMax(l,[o,h,v,A]),i.closePath();break;case at.moveTo:o=e[g++],h=e[g++],i.moveTo(o,h),d||n.updatePathMinMax(l,o,h);break;case at.lineTo:o=e[g++],h=e[g++],i.lineTo(o,h),d||n.updatePathMinMax(l,o,h);break;case at.curveTo:r=o,a=h,o=e[g+4],h=e[g+5],i.bezierCurveTo(e[g],e[g+1],e[g+2],e[g+3],o,h),n.updateCurvePathMinMax(l,r,a,e[g],e[g+1],e[g+2],e[g+3],o,h,u),g+=6;break;case at.curveTo2:r=o,a=h,i.bezierCurveTo(o,h,e[g],e[g+1],e[g+2],e[g+3]),n.updateCurvePathMinMax(l,r,a,o,h,e[g],e[g+1],e[g+2],e[g+3],u),o=e[g+2],h=e[g+3],g+=4;break;case at.curveTo3:r=o,a=h,o=e[g+2],h=e[g+3],i.bezierCurveTo(e[g],e[g+1],o,h,o,h),n.updateCurvePathMinMax(l,r,a,e[g],e[g+1],o,h,o,h,u),g+=4;break;case at.closePath:i.closePath()}d&&n.updateScalingPathMinMax(l,u),n.setCurrentPoint(o,h)}closePath(){this.ctx.closePath()}stroke(t=!0){let e=this.ctx,s=this.current.strokeColor;e.globalAlpha=this.current.strokeAlpha,this.contentVisible&&(typeof s=="object"&&s?.getPattern?(e.save(),e.strokeStyle=s.getPattern(e,this,ht(e),ye),this.rescaleAndStroke(!1),e.restore()):this.rescaleAndStroke(!0)),t&&this.consumePath(this.current.getClippedPathBoundingBox()),e.globalAlpha=this.current.fillAlpha}closeStroke(){this.closePath(),this.stroke()}fill(t=!0){let e=this.ctx,s=this.current.fillColor,i=!1;this.current.patternFill&&(e.save(),e.fillStyle=s.getPattern(e,this,ht(e),_t),i=!0);let n=this.current.getClippedPathBoundingBox();this.contentVisible&&n!==null&&(this.pendingEOFill?(e.fill("evenodd"),this.pendingEOFill=!1):e.fill()),i&&e.restore(),t&&this.consumePath(n)}eoFill(){this.pendingEOFill=!0,this.fill()}fillStroke(){this.fill(!1),this.stroke(!1),this.consumePath()}eoFillStroke(){this.pendingEOFill=!0,this.fillStroke()}closeFillStroke(){this.closePath(),this.fillStroke()}closeEOFillStroke(){this.pendingEOFill=!0,this.closePath(),this.fillStroke()}endPath(){this.consumePath()}clip(){this.pendingClip=Yn}eoClip(){this.pendingClip=$i}beginText(){this.current.textMatrix=ji,this.current.textMatrixScale=1,this.current.x=this.current.lineX=0,this.current.y=this.current.lineY=0}endText(){let t=this.pendingTextPaths,e=this.ctx;if(t===void 0){e.beginPath();return}let s=new Path2D,i=e.getTransform().invertSelf();for(let{transform:n,x:r,y:a,fontSize:o,path:h}of t)s.addPath(h,new DOMMatrix(n).preMultiplySelf(i).translate(r,a).scale(o,-o));e.clip(s),e.beginPath(),delete this.pendingTextPaths}setCharSpacing(t){this.current.charSpacing=t}setWordSpacing(t){this.current.wordSpacing=t}setHScale(t){this.current.textHScale=t/100}setLeading(t){this.current.leading=-t}setFont(t,e){let s=this.commonObjs.get(t),i=this.current;if(!s)throw new Error(`Can't find font for ${t}`);if(i.fontMatrix=s.fontMatrix||ss,i.fontMatrix[0]!==0&&i.fontMatrix[3]!==0||D("Invalid font matrix for font "+t),e<0?(e=-e,i.fontDirection=-1):i.fontDirection=1,this.current.font=s,this.current.fontSize=e,s.isType3Font)return;let n=s.loadedName||"sans-serif",r=s.systemFontInfo?.css||`"${n}", ${s.fallbackName}`,a="normal";s.black?a="900":s.bold&&(a="bold");let o=s.italic?"italic":"normal",h=e;e<16?h=16:e>100&&(h=100),this.current.fontSizeScale=e/h,this.ctx.font=`${o} ${a} ${h}px ${r}`}setTextRenderingMode(t){this.current.textRenderingMode=t}setTextRise(t){this.current.textRise=t}moveText(t,e){this.current.x=this.current.lineX+=t,this.current.y=this.current.lineY+=e}setLeadingMoveText(t,e){this.setLeading(-e),this.moveText(t,e)}setTextMatrix(t,e,s,i,n,r){this.current.textMatrix=[t,e,s,i,n,r],this.current.textMatrixScale=Math.hypot(t,e),this.current.x=this.current.lineX=0,this.current.y=this.current.lineY=0}nextLine(){this.moveText(0,this.current.leading)}#s(t,e,s){let i=new Path2D;return i.addPath(t,new DOMMatrix(s).invertSelf().multiplySelf(e)),i}paintChar(t,e,s,i,n){let r=this.ctx,a=this.current,o=a.font,h=a.textRenderingMode,l=a.fontSize/a.fontSizeScale,d=h&Ei,u=!!(h&un),p=a.patternFill&&!o.missingFile,g=a.patternStroke&&!o.missingFile,f;if((o.disableFontFace||u||p||g)&&(f=o.getPathGenerator(this.commonObjs,t)),o.disableFontFace||p||g){if(r.save(),r.translate(e,s),r.scale(l,-l),d===ne||d===Lt)if(i){let m=r.getTransform();r.setTransform(...i),r.fill(this.#s(f,m,i))}else r.fill(f);if(d===Ye||d===Lt)if(n){let m=r.getTransform();r.setTransform(...n),r.stroke(this.#s(f,m,n))}else r.lineWidth/=l,r.stroke(f);r.restore()}else d!==ne&&d!==Lt||r.fillText(t,e,s),d!==Ye&&d!==Lt||r.strokeText(t,e,s);u&&(this.pendingTextPaths||=[]).push({transform:G(r),x:e,y:s,fontSize:l,path:f})}get isFontSubpixelAAEnabled(){let{context:t}=this.cachedCanvases.getCanvas("isFontSubpixelAAEnabled",10,10);t.scale(1.5,1),t.fillText("I",0,10);let e=t.getImageData(0,0,10,10).data,s=!1;for(let i=3;i<e.length;i+=4)if(e[i]>0&&e[i]<255){s=!0;break}return N(this,"isFontSubpixelAAEnabled",s)}showText(t){let e=this.current,s=e.font;if(s.isType3Font)return this.showType3Text(t);let i=e.fontSize;if(i===0)return;let n=this.ctx,r=e.fontSizeScale,a=e.charSpacing,o=e.wordSpacing,h=e.fontDirection,l=e.textHScale*h,d=t.length,u=s.vertical,p=u?1:-1,g=s.defaultVMetrics,f=i*e.fontMatrix[0],m=e.textRenderingMode===ne&&!s.disableFontFace&&!e.patternFill;n.save(),n.transform(...e.textMatrix),n.translate(e.x,e.y+e.textRise),h>0?n.scale(l,-1):n.scale(l,1);let b,v;if(e.patternFill){n.save();let _=e.fillColor.getPattern(n,this,ht(n),_t);b=G(n),n.restore(),n.fillStyle=_}if(e.patternStroke){n.save();let _=e.strokeColor.getPattern(n,this,ht(n),ye);v=G(n),n.restore(),n.strokeStyle=_}let A=e.lineWidth,y=e.textMatrixScale;if(y===0||A===0){let _=e.textRenderingMode&Ei;_!==Ye&&_!==Lt||(A=this.getSinglePixelWidth())}else A/=y;if(r!==1&&(n.scale(r,r),A/=r),n.lineWidth=A,s.isInvalidPDFjsFont){let _=[],E=0;for(let M of t)_.push(M.unicode),E+=M.width;n.fillText(_.join(""),0,0),e.x+=E*f*l,n.restore(),this.compose();return}let w,x=0;for(w=0;w<d;++w){let _=t[w];if(typeof _=="number"){x+=p*_*i/1e3;continue}let E=!1,M=(_.isSpace?o:0)+a,T=_.fontChar,P=_.accent,O,$,F=_.width;if(u){let j=_.vmetric||g,V=-(_.vmetric?j[1]:.5*F)*f,k=j[2]*f;F=j?-j[0]:F,O=V/r,$=(x+k)/r}else O=x/r,$=0;if(s.remeasure&&F>0){let j=1e3*n.measureText(T).width/i*r;if(F<j&&this.isFontSubpixelAAEnabled){let V=F/j;E=!0,n.save(),n.scale(V,1),O/=V}else F!==j&&(O+=(F-j)/2e3*i/r)}if(this.contentVisible&&(_.isInFont||s.missingFile)){if(m&&!P)n.fillText(T,O,$);else if(this.paintChar(T,O,$,b,v),P){let j=O+i*P.offset.x/r,V=$-i*P.offset.y/r;this.paintChar(P.fontChar,j,V,b,v)}}x+=u?F*f-M*h:F*f+M*h,E&&n.restore()}u?e.y-=x:e.x+=x*l,n.restore(),this.compose()}showType3Text(t){let e=this.ctx,s=this.current,i=s.font,n=s.fontSize,r=s.fontDirection,a=i.vertical?1:-1,o=s.charSpacing,h=s.wordSpacing,l=s.textHScale*r,d=s.fontMatrix||ss,u=t.length,p,g,f,m;if(s.textRenderingMode!==dn&&n!==0){for(this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null,e.save(),e.transform(...s.textMatrix),e.translate(s.x,s.y),e.scale(l,r),p=0;p<u;++p){if(g=t[p],typeof g=="number"){m=a*g*n/1e3,this.ctx.translate(m,0),s.x+=m*l;continue}let b=(g.isSpace?h:0)+o,v=i.charProcOperatorList[g.operatorListId];if(!v){D(`Type3 character "${g.operatorListId}" is not available.`);continue}this.contentVisible&&(this.processingType3=g,this.save(),e.scale(n,n),e.transform(...d),this.executeOperatorList(v),this.restore()),f=C.applyTransform([g.width,0],d)[0]*n+b,e.translate(f,0),s.x+=f*l}e.restore(),this.processingType3=null}}setCharWidth(t,e){}setCharWidthAndBounds(t,e,s,i,n,r){this.ctx.rect(s,i,n-s,r-i),this.ctx.clip(),this.endPath()}getColorN_Pattern(t){let e;if(t[0]==="TilingPattern"){let s=t[1],i=this.baseTransform||G(this.ctx),n={createCanvasGraphics:r=>new c(r,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:this.optionalContentConfig,markedContentStack:this.markedContentStack})};e=new As(t,s,this.ctx,n,i)}else e=this._getPattern(t[1],t[2]);return e}setStrokeColorN(){this.current.strokeColor=this.getColorN_Pattern(arguments),this.current.patternStroke=!0}setFillColorN(){this.current.fillColor=this.getColorN_Pattern(arguments),this.current.patternFill=!0}setStrokeRGBColor(t,e,s){this.ctx.strokeStyle=this.current.strokeColor=C.makeHexColor(t,e,s),this.current.patternStroke=!1}setStrokeTransparent(){this.ctx.strokeStyle=this.current.strokeColor="transparent",this.current.patternStroke=!1}setFillRGBColor(t,e,s){this.ctx.fillStyle=this.current.fillColor=C.makeHexColor(t,e,s),this.current.patternFill=!1}setFillTransparent(){this.ctx.fillStyle=this.current.fillColor="transparent",this.current.patternFill=!1}_getPattern(t,e=null){let s;return this.cachedPatterns.has(t)?s=this.cachedPatterns.get(t):(s=(function(n){switch(n[0]){case"RadialAxial":return new ms(n);case"Mesh":return new bs(n);case"Dummy":return new vs}throw new Error(`Unknown IR type: ${n[0]}`)})(this.getObject(t)),this.cachedPatterns.set(t,s)),e&&(s.matrix=e),s}shadingFill(t){if(!this.contentVisible)return;let e=this.ctx;this.save();let s=this._getPattern(t);e.fillStyle=s.getPattern(e,this,ht(e),$t);let i=ht(e);if(i){let{width:n,height:r}=e.canvas,[a,o,h,l]=C.getAxialAlignedBoundingBox([0,0,n,r],i);this.ctx.fillRect(a,o,h-a,l-o)}else this.ctx.fillRect(-1e10,-1e10,2e10,2e10);this.compose(this.current.getClippedPathBoundingBox()),this.restore()}beginInlineImage(){z("Should not call beginInlineImage")}beginImageData(){z("Should not call beginImageData")}paintFormXObjectBegin(t,e){if(this.contentVisible&&(this.save(),this.baseTransformStack.push(this.baseTransform),t&&this.transform(...t),this.baseTransform=G(this.ctx),e)){let s=e[2]-e[0],i=e[3]-e[1];this.ctx.rect(e[0],e[1],s,i),this.current.updateRectMinMax(G(this.ctx),e),this.clip(),this.endPath()}}paintFormXObjectEnd(){this.contentVisible&&(this.restore(),this.baseTransform=this.baseTransformStack.pop())}beginGroup(t){if(!this.contentVisible)return;this.save(),this.inSMaskMode&&(this.endSMaskMode(),this.current.activeSMask=null);let e=this.ctx;t.isolated||ze("TODO: Support non-isolated groups."),t.knockout&&D("Knockout groups not supported.");let s=G(e);if(t.matrix&&e.transform(...t.matrix),!t.bbox)throw new Error("Bounding box is required.");let i=C.getAxialAlignedBoundingBox(t.bbox,G(e)),n=[0,0,e.canvas.width,e.canvas.height];i=C.intersect(i,n)||[0,0,0,0];let r=Math.floor(i[0]),a=Math.floor(i[1]),o=Math.max(Math.ceil(i[2])-r,1),h=Math.max(Math.ceil(i[3])-a,1);this.current.startNewPathAndClipBox([0,0,o,h]);let l="groupAt"+this.groupLevel;t.smask&&(l+="_smask_"+this.smaskCounter++%2);let d=this.cachedCanvases.getCanvas(l,o,h),u=d.context;u.translate(-r,-a),u.transform(...s),t.smask?this.smaskStack.push({canvas:d.canvas,context:u,offsetX:r,offsetY:a,subtype:t.smask.subtype,backdrop:t.smask.backdrop,transferMap:t.smask.transferMap||null,startTransformInverse:null}):(e.setTransform(1,0,0,1,0,0),e.translate(r,a),e.save()),Dt(e,u),this.ctx=u,this.setGState([["BM","source-over"],["ca",1],["CA",1]]),this.groupStack.push(e),this.groupLevel++}endGroup(t){if(!this.contentVisible)return;this.groupLevel--;let e=this.ctx,s=this.groupStack.pop();if(this.ctx=s,this.ctx.imageSmoothingEnabled=!1,t.smask)this.tempSMask=this.smaskStack.pop(),this.restore();else{this.ctx.restore();let i=G(this.ctx);this.restore(),this.ctx.save(),this.ctx.setTransform(...i);let n=C.getAxialAlignedBoundingBox([0,0,e.canvas.width,e.canvas.height],i);this.ctx.drawImage(e.canvas,0,0),this.ctx.restore(),this.compose(n)}}beginAnnotation(t,e,s,i,n){if(this.#t(),se(this.ctx),this.ctx.save(),this.save(),this.baseTransform&&this.ctx.setTransform(...this.baseTransform),e){let r=e[2]-e[0],a=e[3]-e[1];if(n&&this.annotationCanvasMap){(s=s.slice())[4]-=e[0],s[5]-=e[1],(e=e.slice())[0]=e[1]=0,e[2]=r,e[3]=a;let[o,h]=C.singularValueDecompose2dScale(G(this.ctx)),{viewportScale:l}=this,d=Math.ceil(r*this.outputScaleX*l),u=Math.ceil(a*this.outputScaleY*l);this.annotationCanvas=this.canvasFactory.create(d,u);let{canvas:p,context:g}=this.annotationCanvas;this.annotationCanvasMap.set(t,p),this.annotationCanvas.savedCtx=this.ctx,this.ctx=g,this.ctx.save(),this.ctx.setTransform(o,0,0,-h,0,a*h),se(this.ctx)}else se(this.ctx),this.endPath(),this.ctx.rect(e[0],e[1],r,a),this.ctx.clip(),this.ctx.beginPath()}this.current=new _e(this.ctx.canvas.width,this.ctx.canvas.height),this.transform(...s),this.transform(...i)}endAnnotation(){this.annotationCanvas&&(this.ctx.restore(),this.#e(),this.ctx=this.annotationCanvas.savedCtx,delete this.annotationCanvas.savedCtx,delete this.annotationCanvas)}paintImageMaskXObject(t){if(!this.contentVisible)return;let e=t.count;(t=this.getObject(t.data,t)).count=e;let s=this.ctx,i=this.processingType3;if(i&&(i.compiled===void 0&&(i.compiled=(function(o){let{width:h,height:l}=o;if(h>1e3||l>1e3)return null;let d=new Uint8Array([0,2,4,0,1,0,5,4,8,10,0,8,0,2,1,0]),u=h+1,p,g,f,m=new Uint8Array(u*(l+1)),b=h+7&-8,v=new Uint8Array(b*l),A=0;for(let _ of o.data){let E=128;for(;E>0;)v[A++]=_&E?0:255,E>>=1}let y=0;for(A=0,v[A]!==0&&(m[0]=1,++y),g=1;g<h;g++)v[A]!==v[A+1]&&(m[g]=v[A]?2:1,++y),A++;for(v[A]!==0&&(m[g]=2,++y),p=1;p<l;p++){A=p*b,f=p*u,v[A-b]!==v[A]&&(m[f]=v[A]?1:8,++y);let _=(v[A]?4:0)+(v[A-b]?8:0);for(g=1;g<h;g++)_=(_>>2)+(v[A+1]?4:0)+(v[A-b+1]?8:0),d[_]&&(m[f+g]=d[_],++y),A++;if(v[A-b]!==v[A]&&(m[f+g]=v[A]?2:4,++y),y>1e3)return null}for(A=b*(l-1),f=p*u,v[A]!==0&&(m[f]=8,++y),g=1;g<h;g++)v[A]!==v[A+1]&&(m[f+g]=v[A]?4:8,++y),A++;if(v[A]!==0&&(m[f+g]=4,++y),y>1e3)return null;let w=new Int32Array([0,u,-1,0,-u,0,0,0,1]),x=new Path2D;for(p=0;y&&p<=l;p++){let _=p*u,E=_+h;for(;_<E&&!m[_];)_++;if(_===E)continue;x.moveTo(_%u,p);let M=_,T=m[_];do{let P=w[T];do _+=P;while(!m[_]);let O=m[_];O!==5&&O!==10?(T=O,m[_]=0):(T=O&51*T>>4,m[_]&=T>>2|T<<2),x.lineTo(_%u,_/u|0),m[_]||--y}while(M!==_);--p}return v=null,m=null,function(_){_.save(),_.scale(1/h,-1/l),_.translate(0,-l),_.fill(x),_.beginPath(),_.restore()}})(t)),i.compiled)){i.compiled(s);return}let n=this._createMaskCanvas(t),r=n.canvas;s.save(),s.setTransform(1,0,0,1,0,0),s.drawImage(r,n.offsetX,n.offsetY),s.restore(),this.compose()}paintImageMaskXObjectRepeat(t,e,s=0,i=0,n,r){if(!this.contentVisible)return;t=this.getObject(t.data,t);let a=this.ctx;a.save();let o=G(a);a.transform(e,s,i,n,0,0);let h=this._createMaskCanvas(t);a.setTransform(1,0,0,1,h.offsetX-o[4],h.offsetY-o[5]);for(let l=0,d=r.length;l<d;l+=2){let u=C.transform(o,[e,s,i,n,r[l],r[l+1]]),[p,g]=C.applyTransform([0,0],u);a.drawImage(h.canvas,p,g)}a.restore(),this.compose()}paintImageMaskXObjectGroup(t){if(!this.contentVisible)return;let e=this.ctx,s=this.current.fillColor,i=this.current.patternFill;for(let n of t){let{data:r,width:a,height:o,transform:h}=n,l=this.cachedCanvases.getCanvas("maskCanvas",a,o),d=l.context;d.save(),Oi(d,this.getObject(r,n)),d.globalCompositeOperation="source-in",d.fillStyle=i?s.getPattern(d,this,ht(e),_t):s,d.fillRect(0,0,a,o),d.restore(),e.save(),e.transform(...h),e.scale(1,-1),ee(e,l.canvas,0,0,a,o,0,-1,1,1),e.restore()}this.compose()}paintImageXObject(t){if(!this.contentVisible)return;let e=this.getObject(t);e?this.paintInlineImageXObject(e):D("Dependent image isn't ready yet")}paintImageXObjectRepeat(t,e,s,i){if(!this.contentVisible)return;let n=this.getObject(t);if(!n){D("Dependent image isn't ready yet");return}let r=n.width,a=n.height,o=[];for(let h=0,l=i.length;h<l;h+=2)o.push({transform:[e,0,0,s,i[h],i[h+1]],x:0,y:0,w:r,h:a});this.paintInlineImageXObjectGroup(n,o)}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;let{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){if(!this.contentVisible)return;let e=t.width,s=t.height,i=this.ctx;if(this.save(),!Q){let{filter:a}=i;a!=="none"&&a!==""&&(i.filter="none")}i.scale(1/e,-1/s);let n;if(t.bitmap)n=this.applyTransferMapsToBitmap(t);else if(typeof HTMLElement=="function"&&t instanceof HTMLElement||!t.data)n=t;else{let a=this.cachedCanvases.getCanvas("inlineImage",e,s).context;Ni(a,t),n=this.applyTransferMapsToCanvas(a)}let r=this._scaleImage(n,ht(i));i.imageSmoothingEnabled=Bi(G(i),t.interpolate),ee(i,r.img,0,0,r.paintWidth,r.paintHeight,0,-s,e,s),this.compose(),this.restore()}paintInlineImageXObjectGroup(t,e){if(!this.contentVisible)return;let s=this.ctx,i;if(t.bitmap)i=t.bitmap;else{let n=t.width,r=t.height,a=this.cachedCanvases.getCanvas("inlineImage",n,r).context;Ni(a,t),i=this.applyTransferMapsToCanvas(a)}for(let n of e)s.save(),s.transform(...n.transform),s.scale(1,-1),ee(s,i,n.x,n.y,n.w,n.h,0,-1,1,1),s.restore();this.compose()}paintSolidColorImageMask(){this.contentVisible&&(this.ctx.fillRect(0,0,1,1),this.compose())}markPoint(t){}markPointProps(t,e){}beginMarkedContent(t){this.markedContentStack.push({visible:!0})}beginMarkedContentProps(t,e){t==="OC"?this.markedContentStack.push({visible:this.optionalContentConfig.isVisible(e)}):this.markedContentStack.push({visible:!0}),this.contentVisible=this.isContentVisible()}endMarkedContent(){this.markedContentStack.pop(),this.contentVisible=this.isContentVisible()}beginCompat(){}endCompat(){}consumePath(t){let e=this.current.isEmptyClip();this.pendingClip&&this.current.updateClipFromPath(),this.pendingClip||this.compose(t);let s=this.ctx;this.pendingClip&&(e||(this.pendingClip===$i?s.clip("evenodd"):s.clip()),this.pendingClip=null),this.current.startNewPathAndClipBox(this.current.clipBox),s.beginPath()}getSinglePixelWidth(){if(!this._cachedGetSinglePixelWidth){let t=G(this.ctx);if(t[1]===0&&t[2]===0)this._cachedGetSinglePixelWidth=1/Math.min(Math.abs(t[0]),Math.abs(t[3]));else{let 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){let{lineWidth:t}=this.current,{a:e,b:s,c:i,d:n}=this.ctx.getTransform(),r,a;if(s===0&&i===0){let o=Math.abs(e),h=Math.abs(n);if(o===h)if(t===0)r=a=1/o;else{let l=o*t;r=a=l<1?1/l:1}else if(t===0)r=1/o,a=1/h;else{let l=o*t,d=h*t;r=l<1?1/l:1,a=d<1?1/d:1}}else{let o=Math.abs(e*n-s*i),h=Math.hypot(e,s),l=Math.hypot(i,n);if(t===0)r=l/o,a=h/o;else{let d=t*o;r=l>d?l/d:1,a=h>d?h/d:1}}this._cachedScaleForStroking[0]=r,this._cachedScaleForStroking[1]=a}return this._cachedScaleForStroking}rescaleAndStroke(t){let{ctx:e}=this,{lineWidth:s}=this.current,[i,n]=this.getScaleForStroking();if(e.lineWidth=s||1,i===1&&n===1){e.stroke();return}let r=e.getLineDash();if(t&&e.save(),e.scale(i,n),r.length>0){let a=Math.max(i,n);e.setLineDash(r.map((o=>o/a))),e.lineDashOffset/=a}e.stroke(),t&&e.restore()}isContentVisible(){for(let t=this.markedContentStack.length-1;t>=0;t--)if(!this.markedContentStack[t].visible)return!1;return!0}};for(let c in at)Rt.prototype[c]!==void 0&&(Rt.prototype[at[c]]=Rt.prototype[c]);var xt=class{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}},ys=class{#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}getAll(){return wi(this.#t)}has(t){return this.#t.has(t)}},Tt=Symbol("INTERNAL"),_s=class{#t=!1;#e=!1;#s=!1;#i=!0;constructor(t,{name:e,intent:s,usage:i,rbGroups:n}){this.#t=!!(t&Ai),this.#e=!!(t&ae),this.name=e,this.intent=s,this.usage=i,this.rbGroups=n}get visible(){if(this.#s)return this.#i;if(!this.#i)return!1;let{print:t,view:e}=this.usage;return this.#t?e?.viewState!=="OFF":!this.#e||t?.printState!=="OFF"}_setVisible(t,e,s=!1){t!==Tt&&z("Internal method `_setVisible` called."),this.#s=s,this.#i=e}},xs=class{#t=null;#e=new Map;#s=null;#i=null;constructor(t,e=Ai){if(this.renderingIntent=e,this.name=null,this.creator=null,t!==null){this.name=t.name,this.creator=t.creator,this.#i=t.order;for(let s of t.groups)this.#e.set(s.id,new _s(e,s));if(t.baseState==="OFF")for(let s of this.#e.values())s._setVisible(Tt,!1);for(let s of t.on)this.#e.get(s)._setVisible(Tt,!0);for(let s of t.off)this.#e.get(s)._setVisible(Tt,!1);this.#s=this.getHash()}}#r(t){let e=t.length;if(e<2)return!0;let s=t[0];for(let i=1;i<e;i++){let n=t[i],r;if(Array.isArray(n))r=this.#r(n);else{if(!this.#e.has(n))return D(`Optional content group not found: ${n}`),!0;r=this.#e.get(n).visible}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 ze("Optional content group not defined."),!0;if(t.type==="OCG")return this.#e.has(t.id)?this.#e.get(t.id).visible:(D(`Optional content group not found: ${t.id}`),!0);if(t.type==="OCMD"){if(t.expression)return this.#r(t.expression);if(!t.policy||t.policy==="AnyOn"){for(let e of t.ids){if(!this.#e.has(e))return D(`Optional content group not found: ${e}`),!0;if(this.#e.get(e).visible)return!0}return!1}if(t.policy==="AllOn"){for(let e of t.ids){if(!this.#e.has(e))return D(`Optional content group not found: ${e}`),!0;if(!this.#e.get(e).visible)return!1}return!0}if(t.policy==="AnyOff"){for(let e of t.ids){if(!this.#e.has(e))return D(`Optional content group not found: ${e}`),!0;if(!this.#e.get(e).visible)return!0}return!1}if(t.policy==="AllOff"){for(let e of t.ids){if(!this.#e.has(e))return D(`Optional content group not found: ${e}`),!0;if(this.#e.get(e).visible)return!1}return!0}return D(`Unknown optional content policy ${t.policy}.`),!0}return D(`Unknown group type ${t.type}.`),!0}setVisibility(t,e=!0,s=!0){let i=this.#e.get(t);if(i){if(s&&e&&i.rbGroups.length)for(let n of i.rbGroups)for(let r of n)r!==t&&this.#e.get(r)?._setVisible(Tt,!1,!0);i._setVisible(Tt,!!e,!0),this.#t=null}else D(`Optional content group not found: ${t}`)}setOCGState({state:t,preserveRB:e}){let s;for(let i of t){switch(i){case"ON":case"OFF":case"Toggle":s=i;continue}let 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)}}this.#t=null}get hasInitialVisibility(){return this.#s===null||this.getHash()===this.#s}getOrder(){return this.#e.size?this.#i?this.#i.slice():[...this.#e.keys()]:null}getGroups(){return this.#e.size>0?wi(this.#e):null}getGroup(t){return this.#e.get(t)||null}getHash(){if(this.#t!==null)return this.#t;let t=new pe;for(let[e,s]of this.#e)t.update(`${e}:${s.visible}`);return this.#t=t.hexdigest()}},Ss=class{constructor(t,{disableRange:e=!1,disableStream:s=!1}){X(t,'PDFDataTransportStream - missing required "pdfDataRangeTransport" argument.');let{length:i,initialData:n,progressiveDone:r,contentDispositionFilename:a}=t;if(this._queuedChunks=[],this._progressiveDone=r,this._contentDispositionFilename=a,n?.length>0){let 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,h)=>{this._onReceiveData({begin:o,chunk:h})})),t.addProgressListener(((o,h)=>{this._onProgress({loaded:o,total:h})})),t.addProgressiveReadListener((o=>{this._onReceiveData({chunk:o})})),t.addProgressiveDoneListener((()=>{this._onProgressiveDone()})),t.transportReady()}_onReceiveData({begin:t,chunk:e}){let s=e instanceof Uint8Array&&e.byteLength===e.buffer.byteLength?e.buffer:new Uint8Array(e).buffer;t===void 0?this._fullRequestReader?this._fullRequestReader._enqueue(s):this._queuedChunks.push(s):X(this._rangeReaders.some((function(i){return i._begin!==t?!1:(i._enqueue(s),!0)})),"_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){let e=this._rangeReaders.indexOf(t);e>=0&&this._rangeReaders.splice(e,1)}getFullReader(){X(!this._fullRequestReader,"PDFDataTransportStream.getFullReader can only be called once.");let t=this._queuedChunks;return this._queuedChunks=null,new Es(this,t,this._progressiveDone,this._contentDispositionFilename)}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;let s=new Cs(this,t,e);return this._pdfDataRangeTransport.requestDataRange(t,e),this._rangeReaders.push(s),s}cancelAllRequests(t){this._fullRequestReader?.cancel(t);for(let e of this._rangeReaders.slice(0))e.cancel(t);this._pdfDataRangeTransport.abort()}},Es=class{constructor(t,e,s=!1,i=null){this._stream=t,this._done=s||!1,this._filename=_i(i)?i:null,this._queuedChunks=e||[],this._loaded=0;for(let 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};let t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0;for(let e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0}progressiveDone(){this._done||(this._done=!0)}},Cs=class{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(let e of this._requests)e.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){let e=this._queuedChunk;return this._queuedChunk=null,{value:e,done:!1}}if(this._done)return{value:void 0,done:!0};let t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0;for(let e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0,this._stream._removeRangeReader(this)}};function Wi(c,t){let e=new Headers;if(!c||!t||typeof t!="object")return e;for(let s in t){let i=t[s];i!==void 0&&e.append(s,i)}return e}function Ue(c){try{return new URL(c).origin}catch{}return null}function qi({responseHeaders:c,isHttp:t,rangeChunkSize:e,disableRange:s}){let 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 Xi(c){let t=c.get("Content-Disposition");if(t){let e=(function(i){let n=!0,r=a("filename\\*","i").exec(i);if(r){r=r[1];let p=l(r);return p=unescape(p),p=d(p),p=u(p),h(p)}if(r=(function(g){let f=[],m,b=a("filename\\*((?!0\\d)\\d+)(\\*?)","ig");for(;(m=b.exec(g))!==null;){let[,A,y,w]=m;if(A=parseInt(A,10),A in f){if(A===0)break}else f[A]=[y,w]}let v=[];for(let A=0;A<f.length&&A in f;++A){let[y,w]=f[A];w=l(w),y&&(w=unescape(w),A===0&&(w=d(w))),v.push(w)}return v.join("")})(i),r)return h(u(r));if(r=a("filename","i").exec(i),r){r=r[1];let p=l(r);return p=u(p),h(p)}function a(p,g){return new RegExp("(?:^|;)\\s*"+p+'\\s*=\\s*([^";\\s][^;\\s]*|"(?:[^"\\\\]|\\\\"?)+"?)',g)}function o(p,g){if(p){if(!/^[\x00-\xFF]+$/.test(g))return g;try{let f=new TextDecoder(p,{fatal:!0}),m=je(g);g=f.decode(m),n=!1}catch{}}return g}function h(p){return n&&/[\x80-\xff]/.test(p)&&(p=o("utf-8",p),n&&(p=o("iso-8859-1",p))),p}function l(p){if(p.startsWith('"')){let g=p.slice(1).split('\\"');for(let f=0;f<g.length;++f){let m=g[f].indexOf('"');m!==-1&&(g[f]=g[f].slice(0,m),g.length=f+1),g[f]=g[f].replaceAll(/\\(.)/g,"$1")}p=g.join('"')}return p}function d(p){let g=p.indexOf("'");return g===-1?p:o(p.slice(0,g),p.slice(g+1).replace(/^[^']*'/,""))}function u(p){return!p.startsWith("=?")||/[\x00-\x19\x80-\xff]/.test(p)?p:p.replaceAll(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g,(function(g,f,m,b){if(m==="q"||m==="Q")return o(f,b=(b=b.replaceAll("_"," ")).replaceAll(/=([0-9a-fA-F]{2})/g,(function(v,A){return String.fromCharCode(parseInt(A,16))})));try{b=atob(b)}catch{}return o(f,b)}))}return""})(t);if(e.includes("%"))try{e=decodeURIComponent(e)}catch{}if(_i(e))return e}return null}function We(c,t){return c===404||c===0&&t.startsWith("file:")?new St('Missing PDF "'+t+'".'):new It(`Unexpected server response (${c}) while retrieving PDF "${t}".`,c)}function Yi(c){return c===200||c===206}function Ki(c,t,e){return{method:"GET",headers:c,signal:e.signal,mode:"cors",credentials:t?"include":"same-origin",redirect:"follow"}}function Qi(c){return c instanceof Uint8Array?c.buffer:c instanceof ArrayBuffer?c:(D(`getArrayBuffer - unexpected data format: ${c}`),new Uint8Array(c).buffer)}var xe=class{_responseOrigin=null;constructor(t){this.source=t,this.isHttp=/^https?:/i.test(t.url),this.headers=Wi(this.isHttp,t.httpHeaders),this._fullRequestReader=null,this._rangeRequestReaders=[]}get _progressiveDataLength(){return this._fullRequestReader?._loaded??0}getFullReader(){return X(!this._fullRequestReader,"PDFFetchStream.getFullReader can only be called once."),this._fullRequestReader=new Ms(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;let s=new ks(this,t,e);return this._rangeRequestReaders.push(s),s}cancelAllRequests(t){this._fullRequestReader?.cancel(t);for(let e of this._rangeRequestReaders.slice(0))e.cancel(t)}},Ms=class{constructor(t){this._stream=t,this._reader=null,this._loaded=0,this._filename=null;let 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;let s=new Headers(t.headers),i=e.url;fetch(i,Ki(s,this._withCredentials,this._abortController)).then((n=>{if(t._responseOrigin=Ue(n.url),!Yi(n.status))throw We(n.status,i);this._reader=n.body.getReader(),this._headersCapability.resolve();let r=n.headers,{allowRangeRequests:a,suggestedLength:o}=qi({responseHeaders:r,isHttp:t.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});this._isRangeSupported=a,this._contentLength=o||this._contentLength,this._filename=Xi(r),!this._isStreamingSupported&&this._isRangeSupported&&this.cancel(new lt("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;let{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:Qi(t),done:!1})}cancel(t){this._reader?.cancel(t),this._abortController.abort()}},ks=class{constructor(t,e,s){this._stream=t,this._reader=null,this._loaded=0;let i=t.source;this._withCredentials=i.withCredentials||!1,this._readCapability=Promise.withResolvers(),this._isStreamingSupported=!i.disableStream,this._abortController=new AbortController;let n=new Headers(t.headers);n.append("Range",`bytes=${e}-${s-1}`);let r=i.url;fetch(r,Ki(n,this._withCredentials,this._abortController)).then((a=>{let o=Ue(a.url);if(o!==t._responseOrigin)throw new Error(`Expected range response-origin "${o}" to match "${t._responseOrigin}".`);if(!Yi(a.status))throw We(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;let{value:t,done:e}=await this._reader.read();return e?{value:t,done:e}:(this._loaded+=t.byteLength,this.onProgress?.({loaded:this._loaded}),{value:Qi(t),done:!1})}cancel(t){this._reader?.cancel(t),this._abortController.abort()}},Ts=class{_responseOrigin=null;constructor({url:t,httpHeaders:e,withCredentials:s}){this.url=t,this.isHttp=/^https?:/i.test(t),this.headers=Wi(this.isHttp,e),this.withCredentials=s||!1,this.currXhrId=0,this.pendingRequests=Object.create(null)}request(t){let e=new XMLHttpRequest,s=this.currXhrId++,i=this.pendingRequests[s]={xhr:e};e.open("GET",this.url),e.withCredentials=this.withCredentials;for(let[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=206):i.expectedStatus=200,e.responseType="arraybuffer",X(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){let s=this.pendingRequests[t];s&&s.onProgress?.(e)}onStateChange(t,e){let s=this.pendingRequests[t];if(!s)return;let 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}let n=i.status||200;if(!(n===200&&s.expectedStatus===206)&&n!==s.expectedStatus){s.onError(i.status);return}let r=(function(o){let h=o.response;return typeof h!="string"?h:je(h).buffer})(i);if(n===206){let a=i.getResponseHeader("Content-Range"),o=/bytes (\d+)-(\d+)\/(\d+)/.exec(a);o?s.onDone({begin:parseInt(o[1],10),chunk:r}):(D('Missing or invalid "Content-Range" header.'),s.onError(0))}else r?s.onDone({begin:0,chunk:r}):s.onError(i.status)}getRequestXhr(t){return this.pendingRequests[t].xhr}isPendingRequest(t){return t in this.pendingRequests}abortRequest(t){let e=this.pendingRequests[t].xhr;delete this.pendingRequests[t],e.abort()}},Rs=class{constructor(t){this._source=t,this._manager=new Ts(t),this._rangeChunkSize=t.rangeChunkSize,this._fullRequestReader=null,this._rangeRequestReaders=[]}_onRangeRequestReaderClosed(t){let e=this._rangeRequestReaders.indexOf(t);e>=0&&this._rangeRequestReaders.splice(e,1)}getFullReader(){return X(!this._fullRequestReader,"PDFNetworkStream.getFullReader can only be called once."),this._fullRequestReader=new Ps(this._manager,this._source),this._fullRequestReader}getRangeReader(t,e){let s=new Is(this._manager,t,e);return s.onClosed=this._onRangeRequestReaderClosed.bind(this),this._rangeRequestReaders.push(s),s}cancelAllRequests(t){this._fullRequestReader?.cancel(t);for(let e of this._rangeRequestReaders.slice(0))e.cancel(t)}},Ps=class{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(){let t=this._fullRequestId,e=this._manager.getRequestXhr(t);this._manager._responseOrigin=Ue(e.responseURL);let s=e.getAllResponseHeaders(),i=new Headers(s?s.trimStart().replace(/[^\S ]+$/,"").split(/[\r\n]+/).map((a=>{let[o,...h]=a.split(": ");return[o,h.join(": ")]})):[]),{allowRangeRequests:n,suggestedLength:r}=qi({responseHeaders:i,isHttp:this._manager.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});n&&(this._isRangeSupported=!0),this._contentLength=r||this._contentLength,this._filename=Xi(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(let e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0}}_onError(t){this._storedError=We(t,this._url),this._headersCapability.reject(this._storedError);for(let 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};let t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0,this._headersCapability.reject(t);for(let 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}},Is=class{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(){let t=Ue(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){let e=t.chunk;this._requests.length>0?this._requests.shift().resolve({value:e,done:!1}):this._queuedChunk=e,this._done=!0;for(let s of this._requests)s.resolve({value:void 0,done:!0});this._requests.length=0,this._close()}_onError(t){this._storedError??=We(t,this._url);for(let 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){let e=this._queuedChunk;return this._queuedChunk=null,{value:e,done:!1}}if(this._done)return{value:void 0,done:!0};let t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0;for(let 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()}},Kn=/^[a-z][a-z0-9\-+.]+:/i,Ls=class{constructor(t){this.source=t,this.url=(function(s){if(Kn.test(s))return new URL(s);let i=process.getBuiltinModule("url");return new URL(i.pathToFileURL(s))})(t.url),X(this.url.protocol==="file:","PDFNodeStream only supports file:// URLs."),this._fullRequestReader=null,this._rangeRequestReaders=[]}get _progressiveDataLength(){return this._fullRequestReader?._loaded??0}getFullReader(){return X(!this._fullRequestReader,"PDFNodeStream.getFullReader can only be called once."),this._fullRequestReader=new Ds(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;let s=new Fs(this,t,e);return this._rangeRequestReaders.push(s),s}cancelAllRequests(t){this._fullRequestReader?.cancel(t);for(let e of this._rangeRequestReaders.slice(0))e.cancel(t)}},Ds=class{constructor(t){this._url=t.url,this._done=!1,this._storedError=null,this.onProgress=null;let 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();let 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=new St(`Missing PDF "${this._url}".`)),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;let 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){this._readableStream?this._readableStream.destroy(t):this._error(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 lt("streaming is disabled")),this._storedError&&this._readableStream.destroy(this._storedError)}},Fs=class{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();let i=t.source;this._isStreamingSupported=!i.disableStream;let 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;let 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){this._readableStream?this._readableStream.destroy(t):this._error(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)}},Z=30,Wt=class c{#t=Promise.withResolvers();#e=null;#s=!1;#i=!!globalThis.FontInspector?.enabled;#r=null;#n=null;#h=0;#o=0;#c=null;#l=null;#u=0;#d=0;#p=Object.create(null);#a=[];#g=null;#m=[];#f=new WeakMap;#b=null;static#w=new Map;static#v=new Map;static#y=new WeakMap;static#x=null;static#E=new Set;constructor({textContentSource:t,container:e,viewport:s}){if(t instanceof ReadableStream)this.#g=t;else{if(typeof t!="object")throw new Error('No "textContentSource" parameter specified.');this.#g=new ReadableStream({start(o){o.enqueue(t),o.close()}})}this.#e=this.#l=e,this.#d=s.scale*(globalThis.devicePixelRatio||1),this.#u=s.rotation,this.#n={div:null,properties:null,ctx:null};let{pageWidth:i,pageHeight:n,pageX:r,pageY:a}=s.rawDims;this.#b=[1,0,0,-1,-r,a+n],this.#o=i,this.#h=n,c.#P(),Et(e,s),this.#t.promise.finally((()=>{c.#E.delete(this),this.#n=null,this.#p=null})).catch((()=>{}))}static get fontFamilyMap(){let{isWindows:t,isFirefox:e}=K.platform;return N(this,"fontFamilyMap",new Map([["sans-serif",(t&&e?"Calibri, ":"")+"sans-serif"],["monospace",(t&&e?"Lucida Console, ":"")+"monospace"]]))}render(){let t=()=>{this.#c.read().then((({value:e,done:s})=>{s?this.#t.resolve():(this.#r??=e.lang,Object.assign(this.#p,e.styles),this.#M(e.items),t())}),this.#t.reject)};return this.#c=this.#g.getReader(),c.#E.add(this),t(),this.#t.promise}update({viewport:t,onBefore:e=null}){let s=t.scale*(globalThis.devicePixelRatio||1),i=t.rotation;if(i!==this.#u&&(e?.(),this.#u=i,Et(this.#l,{rotation:i})),s!==this.#d){e?.(),this.#d=s;let n={div:null,properties:null,ctx:c.#k(this.#r)};for(let r of this.#m)n.properties=this.#f.get(r),n.div=r,this.#_(n)}}cancel(){let t=new lt("TextLayer task cancelled.");this.#c?.cancel(t).catch((()=>{})),this.#c=null,this.#t.reject(t)}get textDivs(){return this.#m}get textContentItemsStr(){return this.#a}#M(t){if(this.#s)return;this.#n.ctx??=c.#k(this.#r);let e=this.#m,s=this.#a;for(let i of t){if(e.length>1e5){D("Ignoring additional textDivs for performance reasons."),this.#s=!0;return}if(i.str!==void 0)s.push(i.str),this.#T(i);else if(i.type==="beginMarkedContentProps"||i.type==="beginMarkedContent"){let n=this.#e;this.#e=document.createElement("span"),this.#e.classList.add("markedContent"),i.id!==null&&this.#e.setAttribute("id",`${i.id}`),n.append(this.#e)}else i.type==="endMarkedContent"&&(this.#e=this.#e.parentNode)}}#T(t){let e=document.createElement("span"),s={angle:0,canvasWidth:0,hasText:t.str!=="",hasEOL:t.hasEOL,fontSize:0};this.#m.push(e);let i=C.transform(this.#b,t.transform),n=Math.atan2(i[1],i[0]),r=this.#p[t.fontName];r.vertical&&(n+=Math.PI/2);let a=this.#i&&r.fontSubstitution||r.fontFamily;a=c.fontFamilyMap.get(a)||a;let o=Math.hypot(i[2],i[3]),h=o*c.#D(a,this.#r),l,d;n===0?(l=i[4],d=i[5]-h):(l=i[4]+h*Math.sin(n),d=i[5]-h*Math.cos(n));let u="calc(var(--scale-factor)*",p=e.style;this.#e===this.#l?(p.left=`${(100*l/this.#o).toFixed(2)}%`,p.top=`${(100*d/this.#h).toFixed(2)}%`):(p.left=`${u}${l.toFixed(2)}px)`,p.top=`${u}${d.toFixed(2)}px)`),p.fontSize=`${u}${(c.#x*o).toFixed(2)}px)`,p.fontFamily=a,s.fontSize=o,e.setAttribute("role","presentation"),e.textContent=t.str,e.dir=t.dir,this.#i&&(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]){let f=Math.abs(t.transform[0]),m=Math.abs(t.transform[3]);f!==m&&Math.max(f,m)/Math.min(f,m)>1.5&&(g=!0)}if(g&&(s.canvasWidth=r.vertical?t.height:t.width),this.#f.set(e,s),this.#n.div=e,this.#n.properties=s,this.#_(this.#n),s.hasText&&this.#e.append(e),s.hasEOL){let f=document.createElement("br");f.setAttribute("role","presentation"),this.#e.append(f)}}#_(t){let{div:e,properties:s,ctx:i}=t,{style:n}=e,r="";if(c.#x>1&&(r=`scale(${1/c.#x})`),s.canvasWidth!==0&&s.hasText){let{fontFamily:a}=n,{canvasWidth:o,fontSize:h}=s;c.#C(i,h*this.#d,a);let{width:l}=i.measureText(e.textContent);l>0&&(r=`scaleX(${o*this.#d/l}) ${r}`)}s.angle!==0&&(r=`rotate(${s.angle}deg) ${r}`),r.length>0&&(n.transform=r)}static cleanup(){if(!(this.#E.size>0)){this.#w.clear();for(let{canvas:t}of this.#v.values())t.remove();this.#v.clear()}}static#k(t=null){let e=this.#v.get(t||="");if(!e){let s=document.createElement("canvas");s.className="hiddenCanvasElement",s.lang=t,document.body.append(s),e=s.getContext("2d",{alpha:!1,willReadFrequently:!0}),this.#v.set(t,e),this.#y.set(e,{size:0,family:""})}return e}static#C(t,e,s){let i=this.#y.get(t);(e!==i.size||s!==i.family)&&(t.font=`${e}px ${s}`,i.size=e,i.family=s)}static#P(){if(this.#x!==null)return;let 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.#x=t.getBoundingClientRect().height,t.remove()}static#D(t,e){let s=this.#w.get(t);if(s)return s;let i=this.#k(e);i.canvas.width=i.canvas.height=Z,this.#C(i,Z,t);let n=i.measureText(""),r=n.fontBoundingBoxAscent,a=Math.abs(n.fontBoundingBoxDescent);if(r){let l=r/(r+a);return this.#w.set(t,l),i.canvas.width=i.canvas.height=0,l}i.strokeStyle="red",i.clearRect(0,0,Z,Z),i.strokeText("g",0,0);let o=i.getImageData(0,0,Z,Z).data;a=0;for(let l=o.length-1-3;l>=0;l-=4)if(o[l]>0){a=Math.ceil(l/4/Z);break}i.clearRect(0,0,Z,Z),i.strokeText("A",0,Z),o=i.getImageData(0,0,Z,Z).data,r=0;for(let l=0,d=o.length;l<d;l+=4)if(o[l]>0){r=Z-Math.floor(l/4/Z);break}i.canvas.width=i.canvas.height=0;let h=r?r/(r+a):.8;return this.#w.set(t,h),h}},qt=class c{static textContent(t){let e=[],s={items:e,styles:Object.create(null)};return(function i(n){if(!n)return;let r=null,a=n.name;if(a==="#text")r=n.value;else{if(!c.shouldBuildText(a))return;n?.attributes?.textContent?r=n.attributes.textContent:n.value&&(r=n.value)}if(r!==null&&e.push({str:r}),n.children)for(let o of n.children)i(o)})(t),s}static shouldBuildText(t){return!(t==="textarea"||t==="input"||t==="option"||t==="select")}},Qn=65536,Jn=Q?class extends fe{_createCanvas(t,e){return process.getBuiltinModule("module").createRequire(import.meta.url)("@napi-rs/canvas").createCanvas(t,e)}}:class extends fe{constructor({ownerDocument:t=globalThis.document,enableHWA:e=!1}){super({enableHWA:e}),this._document=t}_createCanvas(t,e){let s=this._document.createElement("canvas");return s.width=t,s.height=e,s}},Zn=Q?class extends me{async _fetch(t){return Ui(t)}}:be,tr=Q?class extends ve{}:class extends ve{#t;#e;#s;#i;#r;#n;#h=0;constructor({docId:t,ownerDocument:e=globalThis.document}){super(),this.#i=t,this.#r=e}get#o(){return this.#e||=new Map}get#c(){return this.#n||=new Map}get#l(){if(!this.#s){let t=this.#r.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;let s=this.#r.createElementNS(pt,"svg");s.setAttribute("width",0),s.setAttribute("height",0),this.#s=this.#r.createElementNS(pt,"defs"),t.append(s),s.append(this.#s),this.#r.body.append(t)}return this.#s}#u(t){if(t.length===1){let o=t[0],h=new Array(256);for(let d=0;d<256;d++)h[d]=o[d]/255;let l=h.join(",");return[l,l,l]}let[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="";let e=this.#r.URL;e!==this.#r.baseURI&&(Ge(e)?D('#createUrl: ignore "data:"-URL for performance reasons.'):this.#t=e.split("#",1)[0])}return`url(${this.#t}#${t})`}addFilter(t){if(!t)return"none";let e=this.#o.get(t);if(e)return e;let[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;let a=`g_${this.#i}_transfer_map_${this.#h++}`,o=this.#d(a);this.#o.set(t,o),this.#o.set(r,o);let h=this.#g(a);return this.#f(s,i,n,h),o}addHCMFilter(t,e){let s=`${t}-${e}`,i="base",n=this.#c.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.#c.set(i,n)),!t||!e))return n.url;let r=this.#w(t);t=C.makeHexColor(...r);let a=this.#w(e);if(e=C.makeHexColor(...a),this.#l.style.color="",t==="#000000"&&e==="#ffffff"||t===e)return n.url;let o=new Array(256);for(let p=0;p<=255;p++){let g=p/255;o[p]=g<=.03928?g/12.92:((g+.055)/1.055)**2.4}let h=o.join(","),l=`g_${this.#i}_hcm_filter`,d=n.filter=this.#g(l);this.#f(h,h,h,d),this.#a(d);let u=(p,g)=>{let f=r[p]/255,m=a[p]/255,b=new Array(g+1);for(let v=0;v<=g;v++)b[v]=f+v/g*(m-f);return b.join(",")};return this.#f(u(0,5),u(1,5),u(2,5),d),n.url=this.#d(l),n.url}addAlphaFilter(t){let e=this.#o.get(t);if(e)return e;let[s]=this.#u([t]),i=`alpha_${s}`;if(e=this.#o.get(i),e)return this.#o.set(t,e),e;let n=`g_${this.#i}_alpha_map_${this.#h++}`,r=this.#d(n);this.#o.set(t,r),this.#o.set(i,r);let a=this.#g(n);return this.#b(s,a),r}addLuminosityFilter(t){let e,s,i=this.#o.get(t||"luminosity");if(i)return i;if(t?([e]=this.#u([t]),s=`luminosity_${e}`):s="luminosity",i=this.#o.get(s),i)return this.#o.set(t,i),i;let n=`g_${this.#i}_luminosity_map_${this.#h++}`,r=this.#d(n);this.#o.set(t,r),this.#o.set(s,r);let a=this.#g(n);return this.#p(a),t&&this.#b(e,a),r}addHighlightHCMFilter(t,e,s,i,n){let r=`${e}-${s}-${i}-${n}`,a=this.#c.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.#c.set(t,a)),!e||!s))return a.url;let[o,h]=[e,s].map(this.#w.bind(this)),l=Math.round(.2126*o[0]+.7152*o[1]+.0722*o[2]),d=Math.round(.2126*h[0]+.7152*h[1]+.0722*h[2]),[u,p]=[i,n].map(this.#w.bind(this));d<l&&([l,d,u,p]=[d,l,p,u]),this.#l.style.color="";let g=(b,v,A)=>{let y=new Array(256),w=(d-l)/A,x=b/255,_=(v-b)/(255*A),E=0;for(let M=0;M<=A;M++){let T=Math.round(l+M*w),P=x+M*_;for(let O=E;O<=T;O++)y[O]=P;E=T+1}for(let M=E;M<256;M++)y[M]=y[E-1];return y.join(",")},f=`g_${this.#i}_hcm_${t}_filter`,m=a.filter=this.#g(f);return this.#a(m),this.#f(g(u[0],p[0],5),g(u[1],p[1],5),g(u[2],p[2],5),m),a.url=this.#d(f),a.url}destroy(t=!1){(!t||!this.#n?.size)&&(this.#s?.parentNode.parentNode.remove(),this.#s=null,this.#e?.clear(),this.#e=null,this.#n?.clear(),this.#n=null,this.#h=0)}#p(t){let e=this.#r.createElementNS(pt,"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)}#a(t){let e=this.#r.createElementNS(pt,"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)}#g(t){let e=this.#r.createElementNS(pt,"filter");return e.setAttribute("color-interpolation-filters","sRGB"),e.setAttribute("id",t),this.#l.append(e),e}#m(t,e,s){let i=this.#r.createElementNS(pt,e);i.setAttribute("type","discrete"),i.setAttribute("tableValues",s),t.append(i)}#f(t,e,s,i){let n=this.#r.createElementNS(pt,"feComponentTransfer");i.append(n),this.#m(n,"feFuncR",t),this.#m(n,"feFuncG",e),this.#m(n,"feFuncB",s)}#b(t,e){let s=this.#r.createElementNS(pt,"feComponentTransfer");e.append(s),this.#m(s,"feFuncA",t)}#w(t){return this.#l.style.color=t,ns(getComputedStyle(this.#l).getPropertyValue("color"))}},er=Q?class extends Ae{async _fetch(t){return Ui(t)}}:we;function sr(c={}){typeof c=="string"||c instanceof URL?c={url:c}:(c instanceof ArrayBuffer||ArrayBuffer.isView(c))&&(c={data:c});let t=new Ns,{docId:e}=t,s=c.url?(function(H){if(H instanceof URL)return H.href;try{return new URL(H,window.location).href}catch{if(Q&&typeof H=="string")return H}throw new Error("Invalid PDF url data: either string or URL-object is expected in the url property.")})(c.url):null,i=c.data?(function(H){if(Q&&typeof Buffer<"u"&&H instanceof Buffer)throw new Error("Please provide binary data as `Uint8Array`, rather than `Buffer`.");if(H instanceof Uint8Array&&H.byteLength===H.buffer.byteLength)return H;if(typeof H=="string")return je(H);if(H instanceof ArrayBuffer||ArrayBuffer.isView(H)||typeof H=="object"&&!isNaN(H?.length))return new Uint8Array(H);throw new Error("Invalid PDF binary data: either TypedArray, string, or array-like object is expected in the data property.")})(c.data):null,n=c.httpHeaders||null,r=c.withCredentials===!0,a=c.password??null,o=c.range instanceof Se?c.range:null,h=Number.isInteger(c.rangeChunkSize)&&c.rangeChunkSize>0?c.rangeChunkSize:Qn,l=c.worker instanceof Pt?c.worker:null,d=c.verbosity,u=typeof c.docBaseUrl!="string"||Ge(c.docBaseUrl)?null:c.docBaseUrl,p=typeof c.cMapUrl=="string"?c.cMapUrl:null,g=c.cMapPacked!==!1,f=c.CMapReaderFactory||Zn,m=typeof c.standardFontDataUrl=="string"?c.standardFontDataUrl:null,b=c.StandardFontDataFactory||er,v=c.stopAtErrors!==!0,A=Number.isInteger(c.maxImageSize)&&c.maxImageSize>-1?c.maxImageSize:-1,y=c.isEvalSupported!==!1,w=typeof c.isOffscreenCanvasSupported=="boolean"?c.isOffscreenCanvasSupported:!Q,x=typeof c.isImageDecoderSupported=="boolean"?c.isImageDecoderSupported:!Q&&(K.platform.isFirefox||!globalThis.chrome),_=Number.isInteger(c.canvasMaxAreaInBytes)?c.canvasMaxAreaInBytes:-1,E=typeof c.disableFontFace=="boolean"?c.disableFontFace:Q,M=c.fontExtraProperties===!0,T=c.enableXfa===!0,P=c.ownerDocument||globalThis.document,O=c.disableRange===!0,$=c.disableStream===!0,F=c.disableAutoFetch===!0,j=c.pdfBug===!0,V=c.CanvasFactory||Jn,k=c.FilterFactory||tr,I=c.enableHWA===!0,nt=o?o.length:c.length??NaN,dt=typeof c.useSystemFonts=="boolean"?c.useSystemFonts:!Q&&!E,ut=typeof c.useWorkerFetch=="boolean"?c.useWorkerFetch:f===be&&b===we&&p&&m&&Ot(p,document.baseURI)&&Ot(m,document.baseURI);Nn(d);let J={canvasFactory:new V({ownerDocument:P,enableHWA:I}),filterFactory:new k({docId:e,ownerDocument:P}),cMapReaderFactory:ut?null:new f({baseUrl:p,isCompressed:g}),standardFontDataFactory:ut?null:new b({baseUrl:m})};if(!l){let st={verbosity:d,port:xt.workerPort};l=st.port?Pt.fromPort(st):new Pt(st),t._worker=l}let Y={docId:e,apiVersion:"4.10.38",data:i,password:a,disableAutoFetch:F,rangeChunkSize:h,length:nt,docBaseUrl:u,enableXfa:T,evaluatorOptions:{maxImageSize:A,disableFontFace:E,ignoreErrors:v,isEvalSupported:y,isOffscreenCanvasSupported:w,isImageDecoderSupported:x,canvasMaxAreaInBytes:_,fontExtraProperties:M,useSystemFonts:dt,cMapUrl:ut?p:null,standardFontDataUrl:ut?m:null}},ft={disableFontFace:E,fontExtraProperties:M,ownerDocument:P,pdfBug:j,styleElement:null,loadingParams:{disableAutoFetch:F,enableXfa:T}};return l.promise.then((function(){if(t.destroyed)throw new Error("Loading aborted");if(l.destroyed)throw new Error("Worker was destroyed");let st=l.messageHandler.sendWithPromise("GetDocRequest",Y,i?[i.buffer]:null),H;if(o)H=new Ss(o,{disableRange:O,disableStream:$});else if(!i){if(!s)throw new Error("getDocument - no `url` parameter provided.");let W;if(Q)if(Ot(s)){if(typeof fetch>"u"||typeof Response>"u"||!("body"in Response.prototype))throw new Error("getDocument - the Fetch API was disabled in Node.js, see `--no-experimental-fetch`.");W=xe}else W=Ls;else W=Ot(s)?xe:Rs;H=new W({url:s,length:nt,httpHeaders:n,withCredentials:r,rangeChunkSize:h,disableRange:O,disableStream:$})}return st.then((W=>{if(t.destroyed)throw new Error("Loading aborted");if(l.destroyed)throw new Error("Worker was destroyed");let Si=new yt(e,W,l.port),sn=new Hs(Si,t,H,ft,J);t._transport=sn,Si.send("Ready",null)}))})).catch(t._capability.reject),t}function Hi(c){return typeof c=="object"&&Number.isInteger(c?.num)&&c.num>=0&&Number.isInteger(c?.gen)&&c.gen>=0}var Ns=class c{static#t=0;constructor(){this._capability=Promise.withResolvers(),this._transport=null,this._worker=null,this.docId="d"+c.#t++,this.destroyed=!1,this.onPassword=null,this.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}},Se=class{constructor(t,e,s=!1,i=null){this.length=t,this.initialData=e,this.progressiveDone=s,this.contentDispositionFilename=i,this._rangeListeners=[],this._progressListeners=[],this._progressiveReadListeners=[],this._progressiveDoneListeners=[],this._readyCapability=Promise.withResolvers()}addRangeListener(t){this._rangeListeners.push(t)}addProgressListener(t){this._progressListeners.push(t)}addProgressiveReadListener(t){this._progressiveReadListeners.push(t)}addProgressiveDoneListener(t){this._progressiveDoneListeners.push(t)}onDataRange(t,e){for(let s of this._rangeListeners)s(t,e)}onDataProgress(t,e){this._readyCapability.promise.then((()=>{for(let s of this._progressListeners)s(t,e)}))}onDataProgressiveRead(t){this._readyCapability.promise.then((()=>{for(let e of this._progressiveReadListeners)e(t)}))}onDataProgressiveDone(){this._readyCapability.promise.then((()=>{for(let t of this._progressiveDoneListeners)t()}))}transportReady(){this._readyCapability.resolve()}requestDataRange(t,e){z("Abstract method PDFDataRangeTransport.requestDataRange")}abort(){}},Os=class{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 N(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()}getJSActions(){return this._transport.getDocJSActions()}getOutline(){return this._transport.getOutline()}getOptionalContentConfig({intent:t="display"}={}){let{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()}},Bs=class{#t=null;#e=!1;constructor(t,e,s,i=!1){this._pageIndex=t,this._pageInfo=e,this._transport=s,this._stats=i?new he:null,this._pdfBug=i,this.commonObjs=s.commonObjs,this.objs=new Ee,this._maybeCleanupAfterRender=!1,this._intentStates=new Map,this.destroyed=!1}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 zt({viewBox:this.view,userUnit:this.userUnit,scale:t,rotation:e,offsetX:s,offsetY:i,dontFlip:n})}getAnnotations({intent:t="display"}={}){let{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 N(this,"isPureXfa",!!this._transport._htmlForXfa)}async getXfa(){return this._transport._htmlForXfa?.children[this._pageIndex]||null}render({canvasContext:t,viewport:e,intent:s="display",annotationMode:i=bt.ENABLE,transform:n=null,background:r=null,optionalContentConfigPromise:a=null,annotationCanvasMap:o=null,pageColors:h=null,printAnnotationStorage:l=null,isEditing:d=!1}){this._stats?.time("Overall");let u=this._transport.getRenderingIntent(s,i,l,d),{renderingIntent:p,cacheKey:g}=u;this.#e=!1,this.#i(),a||=this._transport.getOptionalContentConfig(p);let f=this._intentStates.get(g);f||(f=Object.create(null),this._intentStates.set(g,f)),f.streamReaderCancelTimeout&&(clearTimeout(f.streamReaderCancelTimeout),f.streamReaderCancelTimeout=null);let m=!!(p&ae);f.displayReadyCapability||(f.displayReadyCapability=Promise.withResolvers(),f.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},this._stats?.time("Page Request"),this._pumpOperatorList(u));let b=y=>{f.renderTasks.delete(v),(this._maybeCleanupAfterRender||m)&&(this.#e=!0),this.#s(!m),y?(v.capability.reject(y),this._abortOperatorList({intentState:f,reason:y instanceof Error?y:new Error(y)})):v.capability.resolve(),this._stats&&(this._stats.timeEnd("Rendering"),this._stats.timeEnd("Overall"),globalThis.Stats?.enabled&&globalThis.Stats.add(this.pageNumber,this._stats))},v=new js({callback:b,params:{canvasContext:t,viewport:e,transform:n,background:r},objs:this.objs,commonObjs:this.commonObjs,annotationCanvasMap:o,operatorList:f.operatorList,pageIndex:this._pageIndex,canvasFactory:this._transport.canvasFactory,filterFactory:this._transport.filterFactory,useRequestAnimationFrame:!m,pdfBug:this._pdfBug,pageColors:h});(f.renderTasks||=new Set).add(v);let A=v.task;return Promise.all([f.displayReadyCapability.promise,a]).then((([y,w])=>{if(this.destroyed)b();else{if(this._stats?.time("Rendering"),!(w.renderingIntent&p))throw new Error("Must use the same `intent`-argument when calling the `PDFPageProxy.render` and `PDFDocumentProxy.getOptionalContentConfig` methods.");v.initializeGraphics({transparency:y,optionalContentConfig:w}),v.operatorListChanged()}})).catch(b),A}getOperatorList({intent:t="display",annotationMode:e=bt.ENABLE,printAnnotationStorage:s=null,isEditing:i=!1}={}){let n=this._transport.getRenderingIntent(t,e,s,i,!0),r,a=this._intentStates.get(n.cacheKey);return a||(a=Object.create(null),this._intentStates.set(n.cacheKey,a)),a.opListReadCapability||(r=Object.create(null),r.operatorListChanged=function(){a.operatorList.lastChunk&&(a.opListReadCapability.resolve(a.operatorList),a.renderTasks.delete(r))},a.opListReadCapability=Promise.withResolvers(),(a.renderTasks||=new Set).add(r),a.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},this._stats?.time("Page Request"),this._pumpOperatorList(n)),a.opListReadCapability.promise}streamTextContent({includeMarkedContent:t=!1,disableNormalization:e=!1}={}){return this._transport.messageHandler.sendWithStream("GetTextContent",{pageIndex:this._pageIndex,includeMarkedContent:t===!0,disableNormalization:e===!0},{highWaterMark:100,size:s=>s.items.length})}getTextContent(t={}){if(this._transport._htmlForXfa)return this.getXfa().then((s=>qt.textContent(s)));let e=this.streamTextContent(t);return new Promise((function(s,i){let n=e.getReader(),r={items:[],styles:Object.create(null),lang:null};(function a(){n.read().then((function({value:o,done:h}){h?s(r):(r.lang??=o.lang,Object.assign(r.styles,o.styles),r.items.push(...o.items),a())}),i)})()}))}getStructTree(){return this._transport.getStructTree(this._pageIndex)}_destroy(){this.destroyed=!0;let t=[];for(let e of this._intentStates.values())if(this._abortOperatorList({intentState:e,reason:new Error("Page was destroyed."),force:!0}),!e.opListReadCapability)for(let s of e.renderTasks)t.push(s.completed),s.cancel();return this.objs.clear(),this.#e=!1,this.#i(),Promise.all(t)}cleanup(t=!1){this.#e=!0;let e=this.#s(!1);return t&&e&&(this._stats&&=new he),e}#s(t=!1){if(this.#i(),!this.#e||this.destroyed)return!1;if(t)return this.#t=setTimeout((()=>{this.#t=null,this.#s(!1)}),5e3),!1;for(let{renderTasks:e,operatorList:s}of this._intentStates.values())if(e.size>0||!s.lastChunk)return!1;return this._intentStates.clear(),this.objs.clear(),this.#e=!1,!0}#i(){this.#t&&(clearTimeout(this.#t),this.#t=null)}_startRenderPage(t,e){let 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(let s of e.renderTasks)s.operatorListChanged();t.lastChunk&&this.#s(!0)}_pumpOperatorList({renderingIntent:t,cacheKey:e,annotationStorageSerializable:s,modifiedIds:i}){let{map:n,transfer:r}=s,a=this._transport.messageHandler.sendWithStream("GetOperatorList",{pageIndex:this._pageIndex,intent:t,cacheKey:e,annotationStorage:n,modifiedIds:i},r).getReader(),o=this._intentStates.get(e);o.streamReader=a;let h=()=>{a.read().then((({value:l,done:d})=>{d?o.streamReader=null:this._transport.destroyed||(this._renderPageChunk(l,o),h())}),(l=>{if(o.streamReader=null,!this._transport.destroyed){if(o.operatorList){o.operatorList.lastChunk=!0;for(let d of o.renderTasks)d.operatorListChanged();this.#s(!0)}if(o.displayReadyCapability)o.displayReadyCapability.reject(l);else{if(!o.opListReadCapability)throw l;o.opListReadCapability.reject(l)}}}))};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 jt){let i=100;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 lt(e.message)).catch((()=>{})),t.streamReader=null,!this._transport.destroyed){for(let[i,n]of this._intentStates)if(n===t){this._intentStates.delete(i);break}this.cleanup()}}}get stats(){return this._stats}},$s=class{#t=new Map;#e=Promise.resolve();postMessage(t,e){let s={data:structuredClone(t,e?{transfer:e}:null)};this.#e.then((()=>{for(let[i]of this.#t)i.call(this,s)}))}addEventListener(t,e,s=null){let i=null;if(s?.signal instanceof AbortSignal){let{signal:n}=s;if(n.aborted){D("LoopbackPort - cannot use an `aborted` signal.");return}let 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(let[,t]of this.#t)t?.();this.#t.clear()}},Pt=class c{static#t=0;static#e=!1;static#s;static{Q&&(this.#e=!0,xt.workerSrc||="./pdf.worker.mjs"),this._isSameOrigin=(t,e)=>{let s;try{if(s=new URL(t),!s.origin||s.origin==="null")return!1}catch{return!1}let i=new URL(e,s);return s.origin===i.origin},this._createCDNWrapper=t=>{let e=`await import("${t}");`;return URL.createObjectURL(new Blob([e],{type:"text/javascript"}))}}constructor({name:t=null,port:e=null,verbosity:s=On()}={}){if(this.name=t,this.destroyed=!1,this.verbosity=s,this._readyCapability=Promise.withResolvers(),this._port=null,this._webWorker=null,this._messageHandler=null,e){if(c.#s?.has(e))throw new Error("Cannot use more than one PDFWorker per port.");(c.#s||=new WeakMap).set(e,this),this._initializeFromPort(e)}else this._initialize()}get promise(){return this._readyCapability.promise}#i(){this._readyCapability.resolve(),this._messageHandler.send("configure",{verbosity:this.verbosity})}get port(){return this._port}get messageHandler(){return this._messageHandler}_initializeFromPort(t){this._port=t,this._messageHandler=new yt("main","worker",t),this._messageHandler.on("ready",(function(){})),this.#i()}_initialize(){if(c.#e||c.#r){this._setupFakeWorker();return}let{workerSrc:t}=c;try{c._isSameOrigin(window.location.href,t)||(t=c._createCDNWrapper(new URL(t,window.location).href));let e=new Worker(t,{type:"module"}),s=new yt("main","worker",e),i=()=>{n.abort(),s.destroy(),e.terminate(),this.destroyed?this._readyCapability.reject(new Error("Worker was destroyed")):this._setupFakeWorker()},n=new AbortController;e.addEventListener("error",(()=>{this._webWorker||i()}),{signal:n.signal}),s.on("test",(a=>{n.abort(),!this.destroyed&&a?(this._messageHandler=s,this._port=e,this._webWorker=e,this.#i()):i()})),s.on("ready",(a=>{if(n.abort(),this.destroyed)i();else try{r()}catch{this._setupFakeWorker()}}));let r=()=>{let a=new Uint8Array;s.send("test",a,[a.buffer])};r();return}catch{ze("The worker has been disabled.")}this._setupFakeWorker()}_setupFakeWorker(){c.#e||(D("Setting up fake worker."),c.#e=!0),c._setupFakeWorkerGlobal.then((t=>{if(this.destroyed){this._readyCapability.reject(new Error("Worker was destroyed"));return}let e=new $s;this._port=e;let s="fake"+c.#t++,i=new yt(s+"_worker",s,e);t.setup(i,e),this._messageHandler=new yt(s,s+"_worker",e),this.#i()})).catch((t=>{this._readyCapability.reject(new Error(`Setting up fake worker failed: "${t.message}".`))}))}destroy(){this.destroyed=!0,this._webWorker?.terminate(),this._webWorker=null,c.#s?.delete(this._port),this._port=null,this._messageHandler?.destroy(),this._messageHandler=null}static fromPort(t){if(!t?.port)throw new Error("PDFWorker.fromPort - invalid method signature.");let e=this.#s?.get(t.port);if(e){if(e._pendingDestroy)throw new Error("PDFWorker.fromPort - the worker is being destroyed.\nPlease remember to await `PDFDocumentLoadingTask.destroy()`-calls.");return e}return new c(t)}static get workerSrc(){if(xt.workerSrc)return xt.workerSrc;throw new Error('No "GlobalWorkerOptions.workerSrc" specified.')}static get#r(){try{return globalThis.pdfjsWorker?.WorkerMessageHandler||null}catch{return null}}static get _setupFakeWorkerGlobal(){return N(this,"_setupFakeWorkerGlobal",(async()=>this.#r?this.#r:(await import(this.workerSrc)).WorkerMessageHandler)())}},Hs=class{#t=new Map;#e=new Map;#s=new Map;#i=new Map;#r=null;constructor(t,e,s,i,n){this.messageHandler=t,this.loadingTask=e,this.commonObjs=new Ee,this.fontLoader=new ps({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.destroyed=!1,this.destroyCapability=null,this._networkStream=s,this._fullReader=null,this._lastProgress=null,this.downloadInfoCapability=Promise.withResolvers(),this.setupMessageHandler()}#n(t,e=null){let s=this.#t.get(t);if(s)return s;let i=this.messageHandler.sendWithPromise(t,e);return this.#t.set(t,i),i}get annotationStorage(){return N(this,"annotationStorage",new Gt)}getRenderingIntent(t,e=bt.ENABLE,s=null,i=!1,n=!1){let r=Ai,a=us;switch(t){case"any":r=nn;break;case"display":break;case"print":r=ae;break;default:D(`getRenderingIntent - invalid intent: ${t}`)}let o=r&ae&&s instanceof ge?s:this.annotationStorage;switch(e){case bt.DISABLE:r+=on;break;case bt.ENABLE:break;case bt.ENABLE_FORMS:r+=rn;break;case bt.ENABLE_STORAGE:r+=an,a=o.serializable;break;default:D(`getRenderingIntent - invalid annotationMode: ${e}`)}i&&(r+=hn),n&&(r+=ln);let{ids:h,hash:l}=o.modifiedIds;return{renderingIntent:r,cacheKey:[r,a.hash,l].join("_"),annotationStorageSerializable:a,modifiedIds:h}}destroy(){if(this.destroyCapability)return this.destroyCapability.promise;this.destroyed=!0,this.destroyCapability=Promise.withResolvers(),this.#r?.reject(new Error("Worker was destroyed during onPassword callback"));let t=[];for(let s of this.#e.values())t.push(s._destroy());this.#e.clear(),this.#s.clear(),this.#i.clear(),this.hasOwnProperty("annotationStorage")&&this.annotationStorage.resetModified();let 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(),Wt.cleanup(),this._networkStream?.cancelAllRequests(new lt("Worker was terminated.")),this.messageHandler?.destroy(),this.messageHandler=null,this.destroyCapability.resolve()}),this.destroyCapability.reject),this.destroyCapability.promise}setupMessageHandler(){let{messageHandler:t,loadingTask:e}=this;t.on("GetReader",((s,i)=>{X(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}){r?i.close():(X(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;let{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)=>{X(this._networkStream,"GetRangeReader - no `IPDFStream` instance available.");let n=this._networkStream.getRangeReader(s.begin,s.end);n?(i.onPull=()=>{n.read().then((function({value:r,done:a}){a?i.close():(X(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}))}):i.close()})),t.on("GetDoc",(({pdfInfo:s})=>{this._numPages=s.numPages,this._htmlForXfa=s.htmlForXfa,delete s.htmlForXfa,e._capability.resolve(new Os(s,this))})),t.on("DocException",(s=>{e._capability.reject(tt(s))})),t.on("PasswordRequest",(s=>{this.#r=Promise.withResolvers();try{if(!e.onPassword)throw tt(s);let i=n=>{n instanceof Error?this.#r.reject(n):this.#r.resolve({password:n})};e.onPassword(i,s.code)}catch(i){this.#r.reject(i)}return this.#r.promise})),t.on("DataLoaded",(s=>{e.onProgress?.({loaded:s.length,total:s.length}),this.downloadInfoCapability.resolve(s)})),t.on("StartRenderPage",(s=>{this.destroyed||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":let{disableFontFace:r,fontExtraProperties:a,pdfBug:o}=this._params;if("error"in n){let u=n.error;D(`Error during font loading: ${u}`),this.commonObjs.resolve(s,u);break}let h=o&&globalThis.FontInspector?.enabled?(u,p)=>globalThis.FontInspector.fontAdded(u,p):null,l=new gs(n,{disableFontFace:r,fontExtraProperties:a,inspectFont:h});this.fontLoader.bind(l).catch((()=>t.sendWithPromise("FontFallback",{id:s}))).finally((()=>{!a&&l.data&&(l.data=null),this.commonObjs.resolve(s,l)}));break;case"CopyLocalImage":let{imageRef:d}=n;X(d,"The imageRef must be defined.");for(let u of this.#e.values())for(let[,p]of u.objs)if(p?.ref===d)return p.dataLen?(this.commonObjs.resolve(s,structuredClone(p)),p.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;let a=this.#e.get(i);if(!a.objs.has(s))if(a._intentStates.size!==0)switch(n){case"Image":a.objs.resolve(s,r),r?.dataLen>1e7&&(a._maybeCleanupAfterRender=!0);break;case"Pattern":a.objs.resolve(s,r);break;default:throw new Error(`Got unknown object type ${n}`)}else r?.bitmap?.close()})),t.on("DocProgress",(s=>{this.destroyed||e.onProgress?.({loaded:s.loaded,total:s.total})})),t.on("FetchBuiltInCMap",(async s=>{if(this.destroyed)throw new Error("Worker was destroyed.");if(!this.cMapReaderFactory)throw new Error("CMapReaderFactory not initialized, see the `useWorkerFetch` parameter.");return this.cMapReaderFactory.fetch(s)})),t.on("FetchStandardFontData",(async s=>{if(this.destroyed)throw new Error("Worker was destroyed.");if(!this.standardFontDataFactory)throw new Error("StandardFontDataFactory not initialized, see the `useWorkerFetch` parameter.");return this.standardFontDataFactory.fetch(s)}))}getData(){return this.messageHandler.sendWithPromise("GetData",null)}saveDocument(){this.annotationStorage.size<=0&&D("saveDocument called while `annotationStorage` is empty, please use the getData-method instead.");let{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."));let e=t-1,s=this.#s.get(e);if(s)return s;let i=this.messageHandler.sendWithPromise("GetPage",{pageIndex:e}).then((n=>{if(this.destroyed)throw new Error("Transport destroyed");n.refStr&&this.#i.set(n.refStr,t);let r=new Bs(e,n,this,this._params.pdfBug);return this.#e.set(e,r),r}));return this.#s.set(e,i),i}getPageIndex(t){return Hi(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)}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 xs(e,t)))}getPermissions(){return this.messageHandler.sendWithPromise("GetPermissions",null)}getMetadata(){let t="GetMetadata",e=this.#t.get(t);if(e)return e;let s=this.messageHandler.sendWithPromise(t,null).then((i=>({info:i[0],metadata:i[1]?new ys(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(let 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),Wt.cleanup()}}cachedPageNumber(t){if(!Hi(t))return null;let e=t.gen===0?`${t.num}R`:`${t.num}R${t.gen}`;return this.#i.get(e)??null}},Ft=Symbol("INITIAL_DATA"),Ee=class{#t=Object.create(null);#e(t){return this.#t[t]||={...Promise.withResolvers(),data:Ft}}get(t,e=null){if(e){let i=this.#e(t);return i.promise.then((()=>e(i.data))),null}let s=this.#t[t];if(!s||s.data===Ft)throw new Error(`Requesting object that isn't resolved yet ${t}.`);return s.data}has(t){let e=this.#t[t];return!!e&&e.data!==Ft}delete(t){let e=this.#t[t];return!e||e.data===Ft?!1:(delete this.#t[t],!0)}resolve(t,e=null){let s=this.#e(t);s.data=e,s.resolve()}clear(){for(let t in this.#t){let{data:e}=this.#t[t];e?.bitmap?.close()}this.#t=Object.create(null)}*[Symbol.iterator](){for(let t in this.#t){let{data:e}=this.#t[t];e!==Ft&&(yield[t,e])}}},zs=class{#t=null;constructor(t){this.#t=t,this.onContinue=null}get promise(){return this.#t.capability.promise}cancel(t=0){this.#t.cancel(null,t)}get separateAnnots(){let{separateAnnots:t}=this.#t.operatorList;if(!t)return!1;let{annotationCanvasMap:e}=this.#t;return t.form||t.canvas&&e?.size>0}},js=class c{#t=null;static#e=new WeakSet;constructor({callback:t,params:e,objs:s,commonObjs:i,annotationCanvasMap:n,operatorList:r,pageIndex:a,canvasFactory:o,filterFactory:h,useRequestAnimationFrame:l=!1,pdfBug:d=!1,pageColors:u=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=h,this._pdfBug=d,this.pageColors=u,this.running=!1,this.graphicsReadyCallback=null,this.graphicsReady=!1,this._useRequestAnimationFrame=l===!0&&typeof window<"u",this.cancelled=!1,this.capability=Promise.withResolvers(),this.task=new zs(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.canvasContext.canvas}get completed(){return this.capability.promise.catch((function(){}))}initializeGraphics({transparency:t=!1,optionalContentConfig:e}){if(this.cancelled)return;if(this._canvas){if(c.#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.");c.#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());let{canvasContext:s,viewport:i,transform:n,background:r}=this.params;this.gfx=new Rt(s,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:e},this.annotationCanvasMap,this.pageColors),this.gfx.beginDrawing({transform:n,viewport:i,transparency:t,background:r}),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),c.#e.delete(this._canvas),this.callback(t||new jt(`Rendering cancelled, page ${this._pageIndex+1}`,e))}operatorListChanged(){this.graphicsReady?(this.stepper?.updateOperatorList(this.operatorList),this.running||this._continue()):this.graphicsReadyCallback||=this._continueBound}_continue(){this.running=!0,this.cancelled||(this.task.onContinue?this.task.onContinue(this._scheduleNextBound):this._scheduleNext())}_scheduleNext(){this._useRequestAnimationFrame?this.#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.operatorListIdx===this.operatorList.argsArray.length&&(this.running=!1,this.operatorList.lastChunk&&(this.gfx.endDrawing(),c.#e.delete(this._canvas),this.callback())))}},ir="4.10.38",nr="f9bea397f";function zi(c){return Math.floor(255*Math.max(0,Math.min(1,c))).toString(16).padStart(2,"0")}function Nt(c){return Math.max(0,Math.min(255,255*c))}var Ce=class{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=Nt(t),t,t]}static G_HTML([t]){let e=zi(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(Nt)}static RGB_HTML(t){return`#${t.map(zi).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[Nt(1-Math.min(1,t+i)),Nt(1-Math.min(1,s+i)),Nt(1-Math.min(1,e+i))]}static CMYK_HTML(t){let e=this.CMYK_RGB(t).slice(1);return this.RGB_HTML(e)}static RGB_CMYK([t,e,s]){let i=1-t,n=1-e,r=1-s;return["CMYK",i,n,r,Math.min(i,n,r)]}},Vs=class{create(t,e,s=!1){if(t<=0||e<=0)throw new Error("Invalid SVG dimensions");let 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){z("Abstract method `_createSVG` called.")}},Xt=class extends Vs{_createSVG(t){return document.createElementNS(pt,t)}},Me=class{static setupStorage(t,e,s,i,n){let 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(let 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=>{let o=a.target.options,h=o.selectedIndex===-1?"":o[o.selectedIndex].value;i.setValue(e,{value:h})}))}}static setAttributes({html:t,element:e,storage:s=null,intent:i,linkService:n}){let{attributes:r}=e,a=t instanceof HTMLAnchorElement;r.type==="radio"&&(r.name=`${r.name}-${i}`);for(let[o,h]of Object.entries(r))if(h!=null)switch(o){case"class":h.length&&t.setAttribute(o,h.join(" "));break;case"dataId":break;case"id":t.setAttribute("data-element-id",h);break;case"style":Object.assign(t.style,h);break;case"textContent":t.textContent=h;break;default:(!a||o!=="href"&&o!=="newWindow")&&t.setAttribute(o,h)}a&&n.addLinkAttributes(t,r.href,r.newWindow),s&&r.dataId&&this.setupStorage(t,r.dataId,e,s)}static render(t){let 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});let a=n!=="richText",o=t.div;if(o.append(r),t.viewport){let d=`matrix(${t.viewport.transform.join(",")})`;o.style.transform=d}a&&o.setAttribute("class","xfaLayer xfaFont");let h=[];if(i.children.length===0){if(i.value){let d=document.createTextNode(i.value);r.append(d),a&&qt.shouldBuildText(i.name)&&h.push(d)}return{textDivs:h}}let l=[[i,-1,r]];for(;l.length>0;){let[d,u,p]=l.at(-1);if(u+1===d.children.length){l.pop();continue}let g=d.children[++l.at(-1)[1]];if(g===null)continue;let{name:f}=g;if(f==="#text"){let b=document.createTextNode(g.value);h.push(b),p.append(b);continue}let m=g?.attributes?.xmlns?document.createElementNS(g.attributes.xmlns,f):document.createElement(f);if(p.append(m),g.attributes&&this.setAttributes({html:m,element:g,storage:e,intent:n,linkService:s}),g.children?.length>0)l.push([g,-1,m]);else if(g.value){let b=document.createTextNode(g.value);a&&qt.shouldBuildText(f)&&h.push(b),m.append(b)}}for(let d of o.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea"))d.setAttribute("readOnly",!0);return{textDivs:h}}static update(t){let e=`matrix(${t.viewport.transform.join(",")})`;t.div.style.transform=e,t.div.hidden=!1}},Zt=1e3,kt=new WeakSet;function vt(c){return{width:c[2]-c[0],height:c[3]-c[1]}}var Gs=class{static create(t){switch(t.data.annotationType){case gn:return new ke(t);case pn:return new Us(t);case Tn:switch(t.data.fieldType){case"Tx":return new Ws(t);case"Btn":return t.data.radioButton?new Te(t):t.data.checkBox?new Xs(t):new Ys(t);case"Ch":return new Ks(t);case"Sig":return new qs(t)}return new gt(t);case Vi:return new Yt(t);case fn:return new Re(t);case mn:return new Js(t);case bn:return new Zs(t);case vn:return new ti(t);case wn:return new Pe(t);case Cn:return new si(t);case Mn:return new Kt(t);case An:return new ei(t);case yn:return new Ie(t);case _n:return new ii(t);case xn:return new ni(t);case Sn:return new ri(t);case En:return new Le(t);case kn:return new ai(t);default:return new q(t)}}},q=class c{#t=null;#e=!1;#s=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.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({titleObj:t,contentsObj:e,richText:s}){return!!(t?.str||e?.str||s?.str)}get _isEditable(){return this.data.isEditable}get hasPopupData(){return c._hasPopupData(this.data)}updateEdited(t){if(!this.container)return;this.#t||={rect:this.data.rect.slice(0)};let{rect:e}=t;e&&this.#i(e),this.#s?.popup.updateEdited(t)}resetEdited(){this.#t&&(this.#i(this.#t.rect),this.#s?.popup.resetEdited(),this.#t=null)}#i(t){let{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);let{width:h,height:l}=vt(t);e.left=100*(t[0]-a)/n+"%",e.top=100*(r-t[3]+o)/r+"%",i===0?(e.width=100*h/n+"%",e.height=100*l/r+"%"):this.setRotation(i)}_createContainer(t){let{data:e,parent:{page:s,viewport:i}}=this,n=document.createElement("section");n.setAttribute("data-annotation-id",e.id),this instanceof gt||(n.tabIndex=Zt);let{style:r}=n;if(r.zIndex=this.parent.zIndex++,e.alternativeText&&(n.title=e.alternativeText),e.noRotate&&n.classList.add("norotate"),!e.rect||this instanceof Yt){let{rotation:f}=e;return e.hasOwnCanvas||f===0||this.setRotation(f,n),n}let{width:a,height:o}=vt(e.rect);if(!t&&e.borderStyle.width>0){r.borderWidth=`${e.borderStyle.width}px`;let f=e.borderStyle.horizontalCornerRadius,m=e.borderStyle.verticalCornerRadius;if(f>0||m>0){let v=`calc(${f}px * var(--scale-factor)) / calc(${m}px * var(--scale-factor))`;r.borderRadius=v}else if(this instanceof Te){let v=`calc(${a}px * var(--scale-factor)) / calc(${o}px * var(--scale-factor))`;r.borderRadius=v}switch(e.borderStyle.style){case Rn:r.borderStyle="solid";break;case Pn:r.borderStyle="dashed";break;case In:D("Unimplemented border style: beveled");break;case Ln:D("Unimplemented border style: inset");break;case Dn:r.borderBottomStyle="solid"}let b=e.borderColor||null;b?(this.#e=!0,r.borderColor=C.makeHexColor(0|b[0],0|b[1],0|b[2])):r.borderWidth=0}let h=C.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:l,pageHeight:d,pageX:u,pageY:p}=i.rawDims;r.left=100*(h[0]-u)/l+"%",r.top=100*(h[1]-p)/d+"%";let{rotation:g}=e;return e.hasOwnCanvas||g===0?(r.width=100*a/l+"%",r.height=100*o/d+"%"):this.setRotation(g,n),n}setRotation(t,e=this.container){if(!this.data.rect)return;let{pageWidth:s,pageHeight:i}=this.parent.viewport.rawDims,{width:n,height:r}=vt(this.data.rect),a,o;t%180==0?(a=100*n/s,o=100*r/i):(a=100*r/s,o=100*n/i),e.style.width=`${a}%`,e.style.height=`${o}%`,e.setAttribute("data-main-rotation",(360-t)%360)}get _commonActions(){let t=(e,s,i)=>{let n=i.detail[e],r=n[0],a=n.slice(1);i.target.style[s]=Ce[`${r}_HTML`](a),this.annotationStorage.setValue(this.data.id,{[s]:Ce[`${r}_rgb`](a)})};return N(this,"_commonActions",{display:e=>{let{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=>{let{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=>{let s=e.detail.rotation;this.setRotation(s),this.annotationStorage.setValue(this.data.id,{rotation:s})}})}_dispatchEventFromSandbox(t,e){let s=this._commonActions;for(let i of Object.keys(e.detail))(t[i]||s[i])?.(e)}_setDefaultPropertiesFromJS(t){if(!this.enableScripting)return;let e=this.annotationStorage.getRawValue(this.data.id);if(!e)return;let s=this._commonActions;for(let[i,n]of Object.entries(e)){let r=s[i];r&&(r({detail:{[i]:n},target:t}),delete e[i])}}_createQuadrilaterals(){if(!this.container)return;let{quadPoints:t}=this.data;if(!t)return;let[e,s,i,n]=this.data.rect.map((f=>Math.fround(f)));if(t.length===8){let[f,m,b,v]=t.subarray(2,6);if(i===f&&n===m&&e===b&&s===v)return}let{style:r}=this.container,a;if(this.#e){let{borderColor:f,borderWidth:m}=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="${f}" stroke-width="${m}">`],this.container.classList.add("hasBorder")}let o=i-e,h=n-s,{svgFactory:l}=this,d=l.createElement("svg");d.classList.add("quadrilateralsContainer"),d.setAttribute("width",0),d.setAttribute("height",0);let u=l.createElement("defs");d.append(u);let p=l.createElement("clipPath"),g=`clippath_${this.data.id}`;p.setAttribute("id",g),p.setAttribute("clipPathUnits","objectBoundingBox"),u.append(p);for(let f=2,m=t.length;f<m;f+=8){let b=t[f],v=t[f+1],A=t[f+2],y=t[f+3],w=l.createElement("rect"),x=(A-e)/o,_=(n-v)/h,E=(b-A)/o,M=(v-y)/h;w.setAttribute("x",x),w.setAttribute("y",_),w.setAttribute("width",E),w.setAttribute("height",M),p.append(w),a?.push(`<rect vector-effect="non-scaling-stroke" x="${x}" y="${_}" width="${E}" height="${M}"/>`)}this.#e&&(a.push("</g></svg>')"),r.backgroundImage=a.join("")),this.container.append(d),this.container.style.clipPath=`url(#${g})`}_createPopup(){let{data:t}=this,e=this.#s=new Yt({data:{color:t.color,titleObj:t.titleObj,modificationDate:t.modificationDate,contentsObj:t.contentsObj,richText:t.richText,parentRect:t.rect,borderStyle:0,id:`popup_${t.id}`,rotation:t.rotation},parent:this.parent,elements:[this]});this.parent.div.append(e.render())}render(){z("Abstract method `AnnotationElement.render` called")}_getElementsByName(t,e=null){let s=[];if(this._fieldObjects){let i=this._fieldObjects[t];if(i)for(let{page:n,id:r,exportValues:a}of i){if(n===-1||r===e)continue;let o=typeof a=="string"?a:null,h=document.querySelector(`[data-element-id="${r}"]`);!h||kt.has(h)?s.push({id:r,exportValue:o,domElement:h}):D(`_getElementsByName - element not allowed: ${r}`)}return s}for(let i of document.getElementsByName(t)){let{exportValue:n}=i,r=i.getAttribute("data-element-id");r!==e&&kt.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(){let t=this.getElementsToTriggerPopup();if(Array.isArray(t))for(let e of t)e.classList.add("highlightArea");else t.classList.add("highlightArea")}_editOnDoubleClick(){if(!this._isEditable)return;let{annotationEditorType:t,data:{id:e}}=this;this.container.addEventListener("dblclick",(()=>{this.linkService.eventBus?.dispatch("switchannotationeditormode",{source:this,mode:t,editId:e})}))}},ke=class extends q{constructor(t,e=null){super(t,{isRenderable:!0,ignoreBorder:!!e?.ignoreBorder,createQuadrilaterals:!0}),this.isTooltipOnly=t.data.isTooltipOnly}render(){let{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),i=!0):t.attachment?(this.#e(s,t.attachment,t.attachmentDest),i=!0):t.setOCGState?(this.#s(s,t.setOCGState),i=!0):t.dest?(this._bindLink(s,t.dest),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){t.href=this.linkService.getDestinationHash(e),t.onclick=()=>(e&&this.linkService.goToDestination(e),!1),(e||e==="")&&this.#t()}_bindNamedAction(t,e){t.href=this.linkService.getAnchorUrl(""),t.onclick=()=>(this.linkService.executeNamedAction(e),!1),this.#t()}#e(t,e,s=null){t.href=this.linkService.getAnchorUrl(""),e.description&&(t.title=e.description),t.onclick=()=>(this.downloadManager?.openOrDownloadData(e.content,e.filename,s),!1),this.#t()}#s(t,e){t.href=this.linkService.getAnchorUrl(""),t.onclick=()=>(this.linkService.executeSetOCGState(e),!1),this.#t()}_bindJSAction(t,e){t.href=this.linkService.getAnchorUrl("");let s=new Map([["Action","onclick"],["Mouse Up","onmouseup"],["Mouse Down","onmousedown"]]);for(let i of Object.keys(e.actions)){let n=s.get(i);n&&(t[n]=()=>(this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e.id,name:i}}),!1))}t.onclick||(t.onclick=()=>!1),this.#t()}_bindResetFormAction(t,e){let s=t.onclick;s||(t.href=this.linkService.getAnchorUrl("")),this.#t(),this._fieldObjects?t.onclick=()=>{s?.();let{fields:i,refs:n,include:r}=e,a=[];if(i.length!==0||n.length!==0){let l=new Set(n);for(let d of i){let u=this._fieldObjects[d]||[];for(let{id:p}of u)l.add(p)}for(let d of Object.values(this._fieldObjects))for(let u of d)l.has(u.id)===r&&a.push(u)}else for(let l of Object.values(this._fieldObjects))a.push(...l);let o=this.annotationStorage,h=[];for(let l of a){let{id:d}=l;switch(h.push(d),l.type){case"text":{let p=l.defaultValue||"";o.setValue(d,{value:p});break}case"checkbox":case"radiobutton":{let p=l.defaultValue===l.exportValues;o.setValue(d,{value:p});break}case"combobox":case"listbox":{let p=l.defaultValue||"";o.setValue(d,{value:p});break}default:continue}let u=document.querySelector(`[data-element-id="${d}"]`);u&&(kt.has(u)?u.dispatchEvent(new Event("resetform")):D(`_bindResetFormAction - element not allowed: ${d}`))}return this.enableScripting&&this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:"app",ids:h,name:"ResetForm"}}),!1}:(D('_bindResetFormAction - "resetForm" action not supported, ensure that the `fieldObjects` parameter is provided.'),s||(t.onclick=()=>!1))}},Us=class extends q{constructor(t){super(t,{isRenderable:!0})}render(){this.container.classList.add("textAnnotation");let 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}},gt=class extends q{render(){return this.container}showElementAndHideCanvas(t){this.data.hasOwnCanvas&&(t.previousSibling?.nodeName==="CANVAS"&&(t.previousSibling.hidden=!0),t.hidden=!1)}_getKeyModifier(t){return K.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(let[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?r!=="Blur"||this.data.actions?.Focus||this._setEventListener(t,e,"focus","Focus",null):this._setEventListener(t,e,"blur","Blur",null))}_setBackgroundColor(t){let e=this.data.backgroundColor||null;t.style.backgroundColor=e===null?"transparent":C.makeHexColor(e[0],e[1],e[2])}_setTextStyle(t){let e=["left","center","right"],{fontColor:s}=this.data.defaultAppearanceData,i=this.data.defaultAppearanceData.fontSize||9,n=t.style,r,a=o=>Math.round(10*o)/10;if(this.data.multiLine){let o=Math.abs(this.data.rect[3]-this.data.rect[1]-2),h=o/(Math.round(o/(Xe*i))||1);r=Math.min(i,a(h/Xe))}else{let o=Math.abs(this.data.rect[3]-this.data.rect[1]-2);r=Math.min(i,a(o/Xe))}n.fontSize=`calc(${r}px * var(--scale-factor))`,n.color=C.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)}},Ws=class extends gt{constructor(t){super(t,{isRenderable:t.renderForms||t.data.hasOwnCanvas||!t.data.hasAppearance&&!!t.data.fieldValue})}setPropertyOnSiblings(t,e,s,i){let n=this.annotationStorage;for(let r of this._getElementsByName(t.name,t.id))r.domElement&&(r.domElement[e]=s),n.setValue(r.id,{[i]:s})}render(){let t=this.annotationStorage,e=this.data.id;this.container.classList.add("textWidgetAnnotation");let s=null;if(this.renderForms){let i=t.getValue(e,{value:this.data.fieldValue}),n=i.value||"",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
|
-
`)||null;a&&this.data.comb&&(a=a.replaceAll(/\s+/g,""));let 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="text",s.setAttribute("value",a??n),this.data.doNotScroll&&(s.style.overflowX="hidden")),this.data.hasOwnCanvas&&(s.hidden=!0),kt.add(s),s.setAttribute("data-element-id",e),s.disabled=this.data.readOnly,s.name=this.data.fieldName,s.tabIndex=Zt,this._setRequired(s,this.data.required),r&&(s.maxLength=r),s.addEventListener("input",(l=>{t.setValue(e,{value:l.target.value}),this.setPropertyOnSiblings(s,"value",l.target.value,"value"),o.formattedValue=null})),s.addEventListener("resetform",(l=>{let d=this.data.defaultFieldValue??"";s.value=o.userValue=d,o.formattedValue=null}));let h=l=>{let{formattedValue:d}=o;d!=null&&(l.target.value=d),l.target.scrollLeft=0};if(this.enableScripting&&this.hasJSActions){s.addEventListener("focus",(d=>{if(o.focused)return;let{target:u}=d;o.userValue&&(u.value=o.userValue),o.lastCommittedValue=u.value,o.commitKey=1,this.data.actions?.Focus||(o.focused=!0)})),s.addEventListener("updatefromsandbox",(d=>{this.showElementAndHideCanvas(d.target);let u={value(p){o.userValue=p.detail.value??"",t.setValue(e,{value:o.userValue.toString()}),p.target.value=o.userValue},formattedValue(p){let{formattedValue:g}=p.detail;o.formattedValue=g,g!=null&&p.target!==document.activeElement&&(p.target.value=g),t.setValue(e,{formattedValue:g})},selRange(p){p.target.setSelectionRange(...p.detail.selRange)},charLimit:p=>{let{charLimit:g}=p.detail,{target:f}=p;if(g===0){f.removeAttribute("maxLength");return}f.setAttribute("maxLength",g);let m=o.userValue;m&&!(m.length<=g)&&(m=m.slice(0,g),f.value=o.userValue=m,t.setValue(e,{value:m}),this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:m,willCommit:!0,commitKey:1,selStart:f.selectionStart,selEnd:f.selectionEnd}}))}};this._dispatchEventFromSandbox(u,d)})),s.addEventListener("keydown",(d=>{o.commitKey=1;let u=-1;if(d.key==="Escape"?u=0:d.key!=="Enter"||this.data.multiLine?d.key==="Tab"&&(o.commitKey=3):u=2,u===-1)return;let{value:p}=d.target;o.lastCommittedValue!==p&&(o.lastCommittedValue=p,o.userValue=p,this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:p,willCommit:!0,commitKey:u,selStart:d.target.selectionStart,selEnd:d.target.selectionEnd}}))}));let l=h;h=null,s.addEventListener("blur",(d=>{if(!o.focused||!d.relatedTarget)return;this.data.actions?.Blur||(o.focused=!1);let{value:u}=d.target;o.userValue=u,o.lastCommittedValue!==u&&this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:u,willCommit:!0,commitKey:o.commitKey,selStart:d.target.selectionStart,selEnd:d.target.selectionEnd}}),l(d)})),this.data.actions?.Keystroke&&s.addEventListener("beforeinput",(d=>{o.lastCommittedValue=null;let{data:u,target:p}=d,{value:g,selectionStart:f,selectionEnd:m}=p,b=f,v=m;switch(d.inputType){case"deleteWordBackward":{let A=g.substring(0,f).match(/\w*[^\w]*$/);A&&(b-=A[0].length);break}case"deleteWordForward":{let A=g.substring(f).match(/^[^\w]*\w*/);A&&(v+=A[0].length);break}case"deleteContentBackward":f===m&&(b-=1);break;case"deleteContentForward":f===m&&(v+=1)}d.preventDefault(),this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:g,change:u||"",willCommit:!1,selStart:b,selEnd:v}})})),this._setEventListeners(s,o,[["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],(d=>d.target.value))}if(h&&s.addEventListener("blur",h),this.data.comb){let l=(this.data.rect[2]-this.data.rect[0])/r;s.classList.add("comb"),s.style.letterSpacing=`calc(${l}px * var(--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}},qs=class extends gt{constructor(t){super(t,{isRenderable:!!t.data.hasOwnCanvas})}},Xs=class extends gt{constructor(t){super(t,{isRenderable:t.renderForms})}render(){let t=this.annotationStorage,e=this.data,s=e.id,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");let n=document.createElement("input");return kt.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=Zt,n.addEventListener("change",(r=>{let{name:a,checked:o}=r.target;for(let h of this._getElementsByName(a,s)){let l=o&&h.exportValue===e.exportValue;h.domElement&&(h.domElement.checked=l),t.setValue(h.id,{value:l})}t.setValue(s,{value:o})})),n.addEventListener("resetform",(r=>{let a=e.defaultFieldValue||"Off";r.target.checked=a===e.exportValue})),this.enableScripting&&this.hasJSActions&&(n.addEventListener("updatefromsandbox",(r=>{let 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}},Te=class extends gt{constructor(t){super(t,{isRenderable:t.renderForms})}render(){this.container.classList.add("buttonWidgetAnnotation","radioButton");let t=this.annotationStorage,e=this.data,s=e.id,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(let r of this._getElementsByName(e.fieldName,s))t.setValue(r.id,{value:!1});let n=document.createElement("input");if(kt.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=Zt,n.addEventListener("change",(r=>{let{name:a,checked:o}=r.target;for(let h of this._getElementsByName(a,s))t.setValue(h.id,{value:!1});t.setValue(s,{value:o})})),n.addEventListener("resetform",(r=>{let a=e.defaultFieldValue;r.target.checked=a!=null&&a===e.buttonValue})),this.enableScripting&&this.hasJSActions){let r=e.buttonValue;n.addEventListener("updatefromsandbox",(a=>{let o={value:h=>{let l=r===h.detail.value;for(let d of this._getElementsByName(h.target.name)){let u=l&&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}},Ys=class extends ke{constructor(t){super(t,{ignoreBorder:t.data.hasAppearance})}render(){let t=super.render();t.classList.add("buttonWidgetAnnotation","pushButton");let e=t.lastChild;return this.enableScripting&&this.hasJSActions&&e&&(this._setDefaultPropertiesFromJS(e),e.addEventListener("updatefromsandbox",(s=>{this._dispatchEventFromSandbox({},s)}))),t}},Ks=class extends gt{constructor(t){super(t,{isRenderable:t.renderForms})}render(){this.container.classList.add("choiceWidgetAnnotation");let t=this.annotationStorage,e=this.data.id,s=t.getValue(e,{value:this.data.fieldValue}),i=document.createElement("select");kt.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=Zt;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",(l=>{let d=this.data.defaultFieldValue;for(let u of i.options)u.selected=u.value===d}));for(let l of this.data.options){let d=document.createElement("option");d.textContent=l.displayValue,d.value=l.exportValue,s.value.includes(l.exportValue)&&(d.setAttribute("selected",!0),n=!1),i.append(d)}let r=null;if(n){let l=document.createElement("option");l.value=" ",l.setAttribute("hidden",!0),l.setAttribute("selected",!0),i.prepend(l),r=()=>{l.remove(),i.removeEventListener("input",r),r=null},i.addEventListener("input",r)}let a=l=>{let d=l?"value":"textContent",{options:u,multiple:p}=i;return p?Array.prototype.filter.call(u,(g=>g.selected)).map((g=>g[d])):u.selectedIndex===-1?null:u[u.selectedIndex][d]},o=a(!1),h=l=>{let d=l.target.options;return Array.prototype.map.call(d,(u=>({displayValue:u.textContent,exportValue:u.value})))};return this.enableScripting&&this.hasJSActions?(i.addEventListener("updatefromsandbox",(l=>{let d={value(u){r?.();let p=u.detail.value,g=new Set(Array.isArray(p)?p:[p]);for(let f of i.options)f.selected=g.has(f.value);t.setValue(e,{value:a(!0)}),o=a(!1)},multipleSelection(u){i.multiple=!0},remove(u){let p=i.options,g=u.detail.remove;p[g].selected=!1,i.remove(g),p.length>0&&Array.prototype.findIndex.call(p,(f=>f.selected))===-1&&(p[0].selected=!0),t.setValue(e,{value:a(!0),items:h(u)}),o=a(!1)},clear(u){for(;i.length!==0;)i.remove(0);t.setValue(e,{value:null,items:[]}),o=a(!1)},insert(u){let{index:p,displayValue:g,exportValue:f}=u.detail.insert,m=i.children[p],b=document.createElement("option");b.textContent=g,b.value=f,m?m.before(b):i.append(b),t.setValue(e,{value:a(!0),items:h(u)}),o=a(!1)},items(u){let{items:p}=u.detail;for(;i.length!==0;)i.remove(0);for(let g of p){let{displayValue:f,exportValue:m}=g,b=document.createElement("option");b.textContent=f,b.value=m,i.append(b)}i.options.length>0&&(i.options[0].selected=!0),t.setValue(e,{value:a(!0),items:h(u)}),o=a(!1)},indices(u){let p=new Set(u.detail.indices);for(let g of u.target.options)g.selected=p.has(g.index);t.setValue(e,{value:a(!0)}),o=a(!1)},editable(u){u.target.disabled=!u.detail.editable}};this._dispatchEventFromSandbox(d,l)})),i.addEventListener("input",(l=>{let d=a(!0),u=a(!1);t.setValue(e,{value:d}),l.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"]],(l=>l.target.value))):i.addEventListener("input",(function(l){t.setValue(e,{value:a(!0)})})),this.data.combo&&this._setTextStyle(i),this._setBackgroundColor(i),this._setDefaultPropertiesFromJS(i),this.container.append(i),this.container}},Yt=class extends q{constructor(t){let{data:e,elements:s}=t;super(t,{isRenderable:q._hasPopupData(e)}),this.elements=s,this.popup=null}render(){this.container.classList.add("popupAnnotation");let t=this.popup=new Qs({container:this.container,color:this.data.color,titleObj:this.data.titleObj,modificationDate:this.data.modificationDate,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}),e=[];for(let s of this.elements)s.popup=t,s.container.ariaHasPopup="dialog",e.push(s.data.id),s.addHighlightArea();return this.container.setAttribute("aria-controls",e.map((s=>`${yi}${s}`)).join(",")),this.container}},Qs=class{#t=this.#M.bind(this);#e=this.#C.bind(this);#s=this.#k.bind(this);#i=this.#_.bind(this);#r=null;#n=null;#h=null;#o=null;#c=null;#l=null;#u=null;#d=!1;#p=null;#a=null;#g=null;#m=null;#f=null;#b=null;#w=!1;constructor({container:t,color:e,elements:s,titleObj:i,modificationDate:n,contentsObj:r,richText:a,parent:o,rect:h,parentRect:l,open:d}){this.#n=t,this.#f=i,this.#h=r,this.#m=a,this.#l=o,this.#r=e,this.#g=h,this.#u=l,this.#c=s,this.#o=le.toDateObject(n),this.trigger=s.flatMap((u=>u.getElementsToTriggerPopup()));for(let u of this.trigger)u.addEventListener("click",this.#i),u.addEventListener("mouseenter",this.#s),u.addEventListener("mouseleave",this.#e),u.classList.add("popupTriggerArea");for(let u of s)u.container?.addEventListener("keydown",this.#t);this.#n.hidden=!0,d&&this.#_()}render(){if(this.#p)return;let t=this.#p=document.createElement("div");if(t.className="popup",this.#r){let n=t.style.outlineColor=C.makeHexColor(...this.#r);CSS.supports("background-color","color-mix(in srgb, red 30%, white)")?t.style.backgroundColor=`color-mix(in srgb, ${n} 30%, white)`:t.style.backgroundColor=C.makeHexColor(...this.#r.map((a=>Math.floor(.7*(255-a)+a))))}let e=document.createElement("span");e.className="header";let s=document.createElement("h1");if(e.append(s),{dir:s.dir,str:s.textContent}=this.#f,t.append(e),this.#o){let n=document.createElement("span");n.classList.add("popupDate"),n.setAttribute("data-l10n-id","pdfjs-annotation-date-time-string"),n.setAttribute("data-l10n-args",JSON.stringify({dateObj:this.#o.valueOf()})),e.append(n)}let i=this.#v;if(i)Me.render({xfaHtml:i,intent:"richText",div:t}),t.lastChild.classList.add("richText","popupContent");else{let n=this._formatContents(this.#h);t.append(n)}this.#n.append(t)}get#v(){let t=this.#m,e=this.#h;return!t?.str||e?.str&&e.str!==t.str?null:this.#m.html||null}get#y(){return this.#v?.attributes?.style?.fontSize||0}get#x(){return this.#v?.attributes?.style?.color||null}#E(t){let e=[],s={str:t,html:{name:"div",attributes:{dir:"auto"},children:[{name:"p",children:e}]}},i={style:{color:this.#x,fontSize:this.#y?`calc(${this.#y}px * var(--scale-factor))`:""}};for(let n of t.split(`
|
|
4
|
-
`))e.push({name:"span",value:n,attributes:i});return s}_formatContents({str:t,dir:e}){let s=document.createElement("p");s.classList.add("popupContent"),s.dir=e;let i=t.split(/(?:\r\n?|\n)/);for(let n=0,r=i.length;n<r;++n){let a=i[n];s.append(document.createTextNode(a)),n<r-1&&s.append(document.createElement("br"))}return s}#M(t){t.altKey||t.shiftKey||t.ctrlKey||t.metaKey||(t.key==="Enter"||t.key==="Escape"&&this.#d)&&this.#_()}updateEdited({rect:t,popupContent:e}){this.#b||={contentsObj:this.#h,richText:this.#m},t&&(this.#a=null),e&&(this.#m=this.#E(e),this.#h=null),this.#p?.remove(),this.#p=null}resetEdited(){this.#b&&({contentsObj:this.#h,richText:this.#m}=this.#b,this.#b=null,this.#p?.remove(),this.#p=null,this.#a=null)}#T(){if(this.#a!==null)return;let{page:{view:t},viewport:{rawDims:{pageWidth:e,pageHeight:s,pageX:i,pageY:n}}}=this.#l,r=!!this.#u,a=r?this.#u:this.#g;for(let p of this.#c)if(!a||C.intersect(p.data.rect,a)!==null){a=p.data.rect,r=!0;break}let o=C.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,l=o[0]+h,d=o[1];this.#a=[100*(l-i)/e,100*(d-n)/s];let{style:u}=this.#n;u.left=`${this.#a[0]}%`,u.top=`${this.#a[1]}%`}#_(){this.#d=!this.#d,this.#d?(this.#k(),this.#n.addEventListener("click",this.#i),this.#n.addEventListener("keydown",this.#t)):(this.#C(),this.#n.removeEventListener("click",this.#i),this.#n.removeEventListener("keydown",this.#t))}#k(){this.#p||this.render(),this.isVisible?this.#d&&this.#n.classList.add("focused"):(this.#T(),this.#n.hidden=!1,this.#n.style.zIndex=parseInt(this.#n.style.zIndex)+1e3)}#C(){this.#n.classList.remove("focused"),!this.#d&&this.isVisible&&(this.#n.hidden=!0,this.#n.style.zIndex=parseInt(this.#n.style.zIndex)-1e3)}forceHide(){this.#w=this.isVisible,this.#w&&(this.#n.hidden=!0)}maybeShow(){this.#w&&(this.#p||this.#k(),this.#w=!1,this.#n.hidden=!1)}get isVisible(){return this.#n.hidden===!1}},Re=class extends q{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.textContent=t.data.textContent,this.textPosition=t.data.textPosition,this.annotationEditorType=L.FREETEXT}render(){if(this.container.classList.add("freeTextAnnotation"),this.textContent){let t=document.createElement("div");t.classList.add("annotationTextContent"),t.setAttribute("role","comment");for(let e of this.textContent){let 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}},Js=class extends q{#t=null;constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){this.container.classList.add("lineAnnotation");let t=this.data,{width:e,height:s}=vt(t.rect),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")}},Zs=class extends q{#t=null;constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){this.container.classList.add("squareAnnotation");let t=this.data,{width:e,height:s}=vt(t.rect),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")}},ti=class extends q{#t=null;constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){this.container.classList.add("circleAnnotation");let t=this.data,{width:e,height:s}=vt(t.rect),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")}},Pe=class extends q{#t=null;constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.containerClassName="polylineAnnotation",this.svgElementName="svg:polyline"}render(){this.container.classList.add(this.containerClassName);let{data:{rect:t,vertices:e,borderStyle:s,popupRef:i}}=this;if(!e)return this.container;let{width:n,height:r}=vt(t),a=this.svgFactory.create(n,r,!0),o=[];for(let l=0,d=e.length;l<d;l+=2){let u=e[l]-t[0],p=t[3]-e[l+1];o.push(`${u},${p}`)}o=o.join(" ");let h=this.#t=this.svgFactory.createElement(this.svgElementName);return h.setAttribute("points",o),h.setAttribute("stroke-width",s.width||1),h.setAttribute("stroke","transparent"),h.setAttribute("fill","transparent"),a.append(h),this.container.append(a),!i&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return this.#t}addHighlightArea(){this.container.classList.add("highlightArea")}},ei=class extends Pe{constructor(t){super(t),this.containerClassName="polygonAnnotation",this.svgElementName="svg:polygon"}},si=class extends q{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){return this.container.classList.add("caretAnnotation"),!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container}},Kt=class extends q{#t=null;#e=[];constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.containerClassName="inkAnnotation",this.svgElementName="svg:polyline",this.annotationEditorType=this.data.it==="InkHighlight"?L.HIGHLIGHT:L.INK}#s(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);let{data:{rect:t,rotation:e,inkLists:s,borderStyle:i,popupRef:n}}=this,{transform:r,width:a,height:o}=this.#s(e,t),h=this.svgFactory.create(a,o,!0),l=this.#t=this.svgFactory.createElement("svg:g");h.append(l),l.setAttribute("stroke-width",i.width||1),l.setAttribute("stroke-linecap","round"),l.setAttribute("stroke-linejoin","round"),l.setAttribute("stroke-miterlimit",10),l.setAttribute("stroke","transparent"),l.setAttribute("fill","transparent"),l.setAttribute("transform",r);for(let d=0,u=s.length;d<u;d++){let p=this.svgFactory.createElement(this.svgElementName);this.#e.push(p),p.setAttribute("points",s[d].join(",")),l.append(p)}return!n&&this.hasPopupData&&this._createPopup(),this.container.append(h),this._editOnDoubleClick(),this.container}updateEdited(t){super.updateEdited(t);let{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){let{transform:r,width:a,height:o}=this.#s(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")}},Ie=class extends q{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0}),this.annotationEditorType=L.HIGHLIGHT}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("highlightAnnotation"),this._editOnDoubleClick(),this.container}},ii=class extends q{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("underlineAnnotation"),this.container}},ni=class extends q{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("squigglyAnnotation"),this.container}},ri=class extends q{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("strikeoutAnnotation"),this.container}},Le=class extends q{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.annotationEditorType=L.STAMP}render(){return this.container.classList.add("stampAnnotation"),this.container.setAttribute("role","img"),!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this._editOnDoubleClick(),this.container}},ai=class extends q{#t=null;constructor(t){super(t,{isRenderable:!0});let{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");let{container:t,data:e}=this,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(100*e.fillAlpha)}%);`)),s.addEventListener("dblclick",this.#e.bind(this)),this.#t=s;let{isMac:i}=K.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)}},oi=class{#t=null;#e=null;#s=new Map;#i=null;constructor({div:t,accessibilityManager:e,annotationCanvasMap:s,annotationEditorUIManager:i,page:n,viewport:r,structTreeLayer:a}){this.div=t,this.#t=e,this.#e=s,this.#i=a||null,this.page=n,this.viewport=r,this.zIndex=0,this._annotationEditorUIManager=i}hasEditableAnnotations(){return this.#s.size>0}async#r(t,e){let s=t.firstChild||t,i=s.id=`${yi}${e}`,n=await this.#i?.getAriaAttributes(i);if(n)for(let[r,a]of n)s.setAttribute(r,a);this.div.append(t),this.#t?.moveElementInDOM(this.div,t,s,!1)}async render(t){let{annotations:e}=t,s=this.div;Et(s,this.viewport);let i=new Map,n={data:null,layer:s,linkService:t.linkService,downloadManager:t.downloadManager,imageResourcesPath:t.imageResourcesPath||"",renderForms:t.renderForms!==!1,svgFactory:new Xt,annotationStorage:t.annotationStorage||new Gt,enableScripting:t.enableScripting===!0,hasJSActions:t.hasJSActions,fieldObjects:t.fieldObjects,parent:this,elements:null};for(let r of e){if(r.noHTML)continue;let a=r.annotationType===Vi;if(a){let l=i.get(r.id);if(!l)continue;n.elements=l}else{let{width:l,height:d}=vt(r.rect);if(l<=0||d<=0)continue}n.data=r;let o=Gs.create(n);if(!o.isRenderable)continue;if(!a&&r.popupRef){let l=i.get(r.popupRef);l?l.push(o):i.set(r.popupRef,[o])}let h=o.render();r.hidden&&(h.style.visibility="hidden"),await this.#r(h,r.id),o._isEditable&&(this.#s.set(o.data.id,o),this._annotationEditorUIManager?.renderAnnotationElement(o))}this.#n()}update({viewport:t}){let e=this.div;this.viewport=t,Et(e,{rotation:t.rotation}),this.#n(),e.hidden=!1}#n(){if(!this.#e)return;let t=this.div;for(let[e,s]of this.#e){let i=t.querySelector(`[data-annotation-id="${e}"]`);if(!i)continue;s.className="annotationContent";let{firstChild:n}=i;n?n.nodeName==="CANVAS"?n.replaceWith(s):n.classList.contains("annotationContent")?n.after(s):n.before(s):i.append(s)}this.#e.clear()}getEditableAnnotations(){return Array.from(this.#s.values())}getEditableAnnotation(t){return this.#s.get(t)}},ie=/\r\n?|\n/g,hi=class c extends U{#t;#e="";#s=`${this.id}-editor`;#i=null;#r;static _freeTextDefaultContent="";static _internalPadding=0;static _defaultColor=null;static _defaultFontSize=10;static get _keyboardManager(){let t=c.prototype,e=n=>n.isEmpty(),s=Mt.TRANSLATE_SMALL,i=Mt.TRANSLATE_BIG;return N(this,"_keyboardManager",new Ct([[["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=L.FREETEXT;constructor(t){super({...t,name:"freeTextEditor"}),this.#t=t.color||c._defaultColor||U._defaultLineColor,this.#r=t.fontSize||c._defaultFontSize}static initialize(t,e){U.initialize(t,e);let s=getComputedStyle(document.documentElement);this._internalPadding=parseFloat(s.getPropertyValue("--freetext-padding"))}static updateDefaultParams(t,e){switch(t){case B.FREETEXT_SIZE:c._defaultFontSize=e;break;case B.FREETEXT_COLOR:c._defaultColor=e}}updateParams(t,e){switch(t){case B.FREETEXT_SIZE:this.#n(e);break;case B.FREETEXT_COLOR:this.#h(e)}}static get defaultPropertiesToUpdate(){return[[B.FREETEXT_SIZE,c._defaultFontSize],[B.FREETEXT_COLOR,c._defaultColor||U._defaultLineColor]]}get propertiesToUpdate(){return[[B.FREETEXT_SIZE,this.#r],[B.FREETEXT_COLOR,this.#t]]}#n(t){let e=i=>{this.editorDiv.style.fontSize=`calc(${i}px * var(--scale-factor))`,this.translate(0,-(i-this.#r)*this.parentScale),this.#r=i,this.#c()},s=this.#r;this.addCommands({cmd:e.bind(this,t),undo:e.bind(this,s),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:B.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})}#h(t){let e=i=>{this.#t=this.editorDiv.style.color=i},s=this.#t;this.addCommands({cmd:e.bind(this,t),undo:e.bind(this,s),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:B.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})}_translateEmpty(t,e){this._uiManager.translateSelectedEditors(t,e,!0)}getInitialTranslation(){let t=this.parentScale;return[-c._internalPadding*t,-(c._internalPadding+this.#r)*t]}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.isAttachedToDOM||this.parent.add(this)))}enableEditMode(){if(this.isInEditMode())return;this.parent.setEditingState(!1),this.parent.updateToolbar(L.FREETEXT),super.enableEditMode(),this.overlayDiv.classList.remove("enabled"),this.editorDiv.contentEditable=!0,this._isDraggable=!1,this.div.removeAttribute("aria-activedescendant"),this.#i=new AbortController;let t=this._uiManager.combinedSignal(this.#i);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})}disableEditMode(){this.isInEditMode()&&(this.parent.setEditingState(!0),super.disableEditMode(),this.overlayDiv.classList.add("enabled"),this.editorDiv.contentEditable=!1,this.div.setAttribute("aria-activedescendant",this.#s),this._isDraggable=!0,this.#i?.abort(),this.#i=null,this.div.focus({preventScroll:!0}),this.isEditing=!1,this.parent.div.classList.add("freetextEditing"))}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()}#o(){let t=[];this.editorDiv.normalize();let e=null;for(let s of this.editorDiv.childNodes)(e?.nodeType!==Node.TEXT_NODE||s.nodeName!=="BR")&&(t.push(c.#l(s)),e=s);return t.join(`
|
|
5
|
-
`)}#c(){let[t,e]=this.parentDimensions,s;if(this.isAttachedToDOM)s=this.div.getBoundingClientRect();else{let{currentLayer:i,div:n}=this,r=n.style.display,a=n.classList.contains("hidden");n.classList.remove("hidden"),n.style.display="hidden",i.div.append(this.div),s=n.getBoundingClientRect(),n.remove(),n.style.display=r,n.classList.toggle("hidden",a)}this.rotation%180==this.parentRotation%180?(this.width=s.width/t,this.height=s.height/e):(this.width=s.height/t,this.height=s.width/e),this.fixAndSetPosition()}commit(){if(!this.isInEditMode())return;super.commit(),this.disableEditMode();let t=this.#e,e=this.#e=this.#o().trimEnd();if(t===e)return;let s=i=>{this.#e=i,i?(this.#u(),this._uiManager.rebuild(this),this.#c()):this.remove()};this.addCommands({cmd:()=>{s(e)},undo:()=>{s(t)},mustExec:!1}),this.#c()}shouldGetKeyboardEvents(){return this.isInEditMode()}enterInEditMode(){this.enableEditMode(),this.editorDiv.focus()}dblclick(t){this.enterInEditMode()}keydown(t){t.target===this.div&&t.key==="Enter"&&(this.enterInEditMode(),t.preventDefault())}editorDivKeydown(t){
|
|
1
|
+
var bs={d:(o,t)=>{for(var e in t)bs.o(t,e)&&!bs.o(o,e)&&Object.defineProperty(o,e,{enumerable:!0,get:t[e]})},o:(o,t)=>Object.prototype.hasOwnProperty.call(o,t)},T=globalThis.pdfjsLib={};bs.d(T,{AbortException:()=>gt,AnnotationEditorLayer:()=>Li,AnnotationEditorParamsType:()=>B,AnnotationEditorType:()=>D,AnnotationEditorUIManager:()=>Ft,AnnotationLayer:()=>xi,AnnotationMode:()=>St,ColorPicker:()=>Xe,DOMSVGFactory:()=>ne,DrawLayer:()=>Di,FeatureTest:()=>Z,GlobalWorkerOptions:()=>Rt,ImageKind:()=>be,InvalidPDFException:()=>Kt,MissingPDFException:()=>It,OPS:()=>ut,OutputScale:()=>Zt,PDFDataRangeTransport:()=>Ne,PDFDateString:()=>ve,PDFWorker:()=>Ht,PasswordResponses:()=>mr,PermissionFlag:()=>Un,PixelsPerInch:()=>Ct,RenderingCancelledException:()=>Jt,TextLayer:()=>se,TouchManager:()=>Se,UnexpectedResponseException:()=>jt,Util:()=>k,VerbosityLevel:()=>Qe,XfaLayer:()=>Be,build:()=>Br,createValidAbsoluteUrl:()=>wr,fetchData:()=>es,getDocument:()=>Or,getFilenameFromUrl:()=>vr,getPdfFilenameFromUrl:()=>_r,getXfaPageViewport:()=>xr,isDataScheme:()=>ss,isPdfFile:()=>$i,noContextMenu:()=>ft,normalizeUnicode:()=>Ar,setLayerDimensions:()=>Lt,shadow:()=>N,stopEvent:()=>ht,version:()=>$r});var et=!(typeof process!="object"||process+""!="[object process]"||process.versions.nw||process.versions.electron&&process.type&&process.type!=="browser"),cn=[1,0,0,1,0,0],ys=[.001,0,0,.001,0,0],cs=1.35,Bn=1,Fi=2,ye=4,Hn=16,jn=32,Vn=64,zn=128,Gn=256,St={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},D={DISABLE:-1,NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15},B={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_DEFAULT_COLOR:32,HIGHLIGHT_THICKNESS:33,HIGHLIGHT_FREE:34,HIGHLIGHT_SHOW_ALL:35,DRAW_STEP:41},Un={PRINT:4,MODIFY_CONTENTS:8,COPY:16,MODIFY_ANNOTATIONS:32,FILL_INTERACTIVE_FORMS:256,COPY_FOR_ACCESSIBILITY:512,ASSEMBLE:1024,PRINT_HIGH_QUALITY:2048},me=0,ds=1,zt=2,qn=3,qi=3,Wn=4,be={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},Xn=1,Yn=2,Kn=3,Qn=4,Jn=5,Zn=6,tr=7,er=8,sr=9,ir=10,nr=11,rr=12,ar=13,or=14,lr=15,dn=16,hr=17,cr=20,dr=1,ur=2,fr=3,pr=4,gr=5,Qe={ERRORS:0,WARNINGS:1,INFOS:5},ut={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},mr={NEED_PASSWORD:1,INCORRECT_PASSWORD:2},Je=Qe.WARNINGS;function br(o){Number.isInteger(o)&&(Je=o)}function yr(){return Je}function Ze(o){Je>=Qe.INFOS&&console.log(`Info: ${o}`)}function F(o){Je>=Qe.WARNINGS&&console.log(`Warning: ${o}`)}function z(o){throw new Error(o)}function Q(o,t){o||z(t)}function wr(o,t=null,e=null){if(!o)return null;try{if(e&&typeof o=="string"&&(e.addDefaultProtocol&&o.startsWith("www.")&&o.match(/\./g)?.length>=2&&(o=`http://${o}`),e.tryConvertEncoding))try{o=(function(n){return decodeURIComponent(escape(n))})(o)}catch{}let s=t?new URL(o,t):new URL(o);if((function(n){switch(n?.protocol){case"http:":case"https:":case"ftp:":case"mailto:":case"tel:":return!0;default:return!1}})(s))return s}catch{}return null}function N(o,t,e,s=!1){return Object.defineProperty(o,t,{value:e,enumerable:!s,configurable:!0,writable:!1}),e}var kt=(function(){function t(e,s){this.message=e,this.name=s}return t.prototype=new Error,t.constructor=t,t})(),we=class extends kt{constructor(t,e){super(t,"PasswordException"),this.code=e}},Xt=class extends kt{constructor(t,e){super(t,"UnknownErrorException"),this.details=e}},Kt=class extends kt{constructor(t){super(t,"InvalidPDFException")}},It=class extends kt{constructor(t){super(t,"MissingPDFException")}},jt=class extends kt{constructor(t,e){super(t,"UnexpectedResponseException"),this.status=e}},ws=class extends kt{constructor(t){super(t,"FormatError")}},gt=class extends kt{constructor(t){super(t,"AbortException")}};function un(o){typeof o=="object"&&o?.length!==void 0||z("Invalid argument for bytesToString");let t=o.length,e=8192;if(t<e)return String.fromCharCode.apply(null,o);let s=[];for(let i=0;i<t;i+=e){let n=Math.min(i+e,t),r=o.subarray(i,n);s.push(String.fromCharCode.apply(null,r))}return s.join("")}function ts(o){typeof o!="string"&&z("Invalid argument for stringToBytes");let t=o.length,e=new Uint8Array(t);for(let s=0;s<t;++s)e[s]=255&o.charCodeAt(s);return e}function Ni(o){let t=Object.create(null);for(let[e,s]of o)t[e]=s;return t}var Z=class{static get isLittleEndian(){return N(this,"isLittleEndian",(function(){let e=new Uint8Array(4);return e[0]=1,new Uint32Array(e.buffer,0,1)[0]===1})())}static get isEvalSupported(){return N(this,"isEvalSupported",(function(){try{return new Function(""),!0}catch{return!1}})())}static get isOffscreenCanvasSupported(){return N(this,"isOffscreenCanvasSupported",typeof OffscreenCanvas<"u")}static get isImageDecoderSupported(){return N(this,"isImageDecoderSupported",typeof ImageDecoder<"u")}static get platform(){return typeof navigator<"u"&&typeof navigator?.platform=="string"?N(this,"platform",{isMac:navigator.platform.includes("Mac"),isWindows:navigator.platform.includes("Win"),isFirefox:typeof navigator?.userAgent=="string"&&navigator.userAgent.includes("Firefox")}):N(this,"platform",{isMac:!1,isWindows:!1,isFirefox:!1})}static get isCSSRoundSupported(){return N(this,"isCSSRoundSupported",globalThis.CSS?.supports?.("width: round(1.5px, 1px)"))}},us=Array.from(Array(256).keys(),(o=>o.toString(16).padStart(2,"0"))),k=class{static makeHexColor(t,e,s){return`#${us[t]}${us[e]}${us[s]}`}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 applyTransform(t,e){return[t[0]*e[0]+t[1]*e[2]+e[4],t[0]*e[1]+t[1]*e[3]+e[5]]}static applyInverseTransform(t,e){let s=e[0]*e[3]-e[1]*e[2];return[(t[0]*e[3]-t[1]*e[2]+e[2]*e[5]-e[4]*e[3])/s,(-t[0]*e[1]+t[1]*e[0]+e[4]*e[1]-e[5]*e[0])/s]}static getAxialAlignedBoundingBox(t,e){let s=this.applyTransform(t,e),i=this.applyTransform(t.slice(2,4),e),n=this.applyTransform([t[0],t[3]],e),r=this.applyTransform([t[2],t[1]],e);return[Math.min(s[0],i[0],n[0],r[0]),Math.min(s[1],i[1],n[1],r[1]),Math.max(s[0],i[0],n[0],r[0]),Math.max(s[1],i[1],n[1],r[1])]}static inverseTransform(t){let 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){let e=[t[0],t[2],t[1],t[3]],s=t[0]*e[0]+t[1]*e[2],i=t[0]*e[1]+t[1]*e[3],n=t[2]*e[0]+t[3]*e[2],r=t[2]*e[1]+t[3]*e[3],a=(s+r)/2,l=Math.sqrt((s+r)**2-4*(s*r-n*i))/2,h=a+l||1,c=a-l||1;return[Math.sqrt(h),Math.sqrt(c)]}static normalizeRect(t){let 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){let 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;let 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#t(t,e,s,i,n,r,a,l,h,c){if(h<=0||h>=1)return;let d=1-h,u=h*h,f=u*h,p=d*(d*(d*t+3*h*e)+3*u*s)+f*i,g=d*(d*(d*n+3*h*r)+3*u*a)+f*l;c[0]=Math.min(c[0],p),c[1]=Math.min(c[1],g),c[2]=Math.max(c[2],p),c[3]=Math.max(c[3],g)}static#e(t,e,s,i,n,r,a,l,h,c,d,u){if(Math.abs(h)<1e-12){Math.abs(c)>=1e-12&&this.#t(t,e,s,i,n,r,a,l,-d/c,u);return}let f=c**2-4*d*h;if(f<0)return;let p=Math.sqrt(f),g=2*h;this.#t(t,e,s,i,n,r,a,l,(-c+p)/g,u),this.#t(t,e,s,i,n,r,a,l,(-c-p)/g,u)}static bezierBoundingBox(t,e,s,i,n,r,a,l,h){return h?(h[0]=Math.min(h[0],t,a),h[1]=Math.min(h[1],e,l),h[2]=Math.max(h[2],t,a),h[3]=Math.max(h[3],e,l)):h=[Math.min(t,a),Math.min(e,l),Math.max(t,a),Math.max(e,l)],this.#e(t,s,n,a,e,i,r,l,3*(3*(s-n)-t+a),6*(t-2*s+n),3*(s-t),h),this.#e(t,s,n,a,e,i,r,l,3*(3*(i-r)-e+l),6*(e-2*i+r),3*(i-e),h),h}},fs=null,Wi=null;function Ar(o){return fs||(fs=/([\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,Wi=new Map([["\uFB05","\u017Ft"]])),o.replaceAll(fs,((t,e,s)=>e?e.normalize("NFKC"):Wi.get(s)))}var Oi="pdfjs_internal_id_";typeof Promise.try!="function"&&(Promise.try=function(o,...t){return new Promise((e=>{e(o(...t))}))});var At="http://www.w3.org/2000/svg",Ct=class{static CSS=96;static PDF=72;static PDF_TO_CSS_UNITS=this.CSS/this.PDF};async function es(o,t="text"){if(Wt(o,document.baseURI)){let e=await fetch(o);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)=>{let i=new XMLHttpRequest;i.open("GET",o,!0),i.responseType=t,i.onreadystatechange=()=>{if(i.readyState===XMLHttpRequest.DONE)if(i.status!==200&&i.status!==0)s(new Error(i.statusText));else{switch(t){case"arraybuffer":case"blob":case"json":e(i.response);return}e(i.responseText)}},i.send(null)}))}var Qt=class o{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;let l=(t[2]+t[0])/2,h=(t[3]+t[1])/2,c,d,u,f,p,g,m,b;switch((i%=360)<0&&(i+=360),i){case 180:c=-1,d=0,u=0,f=1;break;case 90:c=0,d=1,u=1,f=0;break;case 270:c=0,d=-1,u=-1,f=0;break;case 0:c=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),c===0?(p=Math.abs(h-t[1])*s+n,g=Math.abs(l-t[0])*s+r,m=(t[3]-t[1])*s,b=(t[2]-t[0])*s):(p=Math.abs(l-t[0])*s+n,g=Math.abs(h-t[1])*s+r,m=(t[2]-t[0])*s,b=(t[3]-t[1])*s),this.transform=[c*s,d*s,u*s,f*s,p-c*s*l-u*s*h,g-d*s*l-f*s*h],this.width=m,this.height=b}get rawDims(){let{userUnit:t,viewBox:e}=this,s=e.map((i=>i*t));return N(this,"rawDims",{pageWidth:s[2]-s[0],pageHeight:s[3]-s[1],pageX:s[0],pageY:s[1]})}clone({scale:t=this.scale,rotation:e=this.rotation,offsetX:s=this.offsetX,offsetY:i=this.offsetY,dontFlip:n=!1}={}){return new o({viewBox:this.viewBox.slice(),userUnit:this.userUnit,scale:t,rotation:e,offsetX:s,offsetY:i,dontFlip:n})}convertToViewportPoint(t,e){return k.applyTransform([t,e],this.transform)}convertToViewportRectangle(t){let e=k.applyTransform([t[0],t[1]],this.transform),s=k.applyTransform([t[2],t[3]],this.transform);return[e[0],e[1],s[0],s[1]]}convertToPdfPoint(t,e){return k.applyInverseTransform([t,e],this.transform)}},Jt=class extends kt{constructor(t,e=0){super(t,"RenderingCancelledException"),this.extraDelay=e}};function ss(o){let t=o.length,e=0;for(;e<t&&o[e].trim()==="";)e++;return o.substring(e,e+5).toLowerCase()==="data:"}function $i(o){return typeof o=="string"&&/\.pdf$/i.test(o)}function vr(o){return[o]=o.split(/[#?]/,1),o.substring(o.lastIndexOf("/")+1)}function _r(o,t="document.pdf"){if(typeof o!="string")return t;if(ss(o))return F('getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.'),t;let e=/[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i,s=/^(?:(?:[^:]+:)?\/\/[^/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/.exec(o),i=e.exec(s[1])||e.exec(s[2])||e.exec(s[3]);if(i&&(i=i[0],i.includes("%")))try{i=e.exec(decodeURIComponent(i))[0]}catch{}return i||t}var Ae=class{started=Object.create(null);times=[];time(t){t in this.started&&F(`Timer is already running for ${t}`),this.started[t]=Date.now()}timeEnd(t){t in this.started||F(`Timer has not been started for ${t}`),this.times.push({name:t,start:this.started[t],end:Date.now()}),delete this.started[t]}toString(){let t=[],e=0;for(let{name:s}of this.times)e=Math.max(s.length,e);for(let{name:s,start:i,end:n}of this.times)t.push(`${s.padEnd(e)} ${n-i}ms
|
|
2
|
+
`);return t.join("")}};function Wt(o,t){try{let{protocol:e}=t?new URL(o,t):new URL(o);return e==="http:"||e==="https:"}catch{return!1}}function ft(o){o.preventDefault()}function ht(o){o.preventDefault(),o.stopPropagation()}var ve=class{static#t;static toDateObject(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})?'?");let e=this.#t.exec(t);if(!e)return null;let s=parseInt(e[1],10),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 l=parseInt(e[6],10);l=l>=0&&l<=59?l:0;let h=e[7]||"Z",c=parseInt(e[8],10);c=c>=0&&c<=23?c:0;let d=parseInt(e[9],10)||0;return d=d>=0&&d<=59?d:0,h==="-"?(r+=c,a+=d):h==="+"&&(r-=c,a-=d),new Date(Date.UTC(s,i,n,r,a,l))}};function xr(o,{scale:t=1,rotation:e=0}){let{width:s,height:i}=o.attributes.style,n=[0,0,parseInt(s),parseInt(i)];return new Qt({viewBox:n,userUnit:1,scale:t,rotation:e})}function As(o){if(o.startsWith("#")){let t=parseInt(o.slice(1),16);return[(16711680&t)>>16,(65280&t)>>8,255&t]}return o.startsWith("rgb(")?o.slice(4,-1).split(",").map((t=>parseInt(t))):o.startsWith("rgba(")?o.slice(5,-1).split(",").map((t=>parseInt(t))).slice(0,3):(F(`Not a valid color format: "${o}"`),[0,0,0])}function U(o){let{a:t,b:e,c:s,d:i,e:n,f:r}=o.getTransform();return[t,e,s,i,n,r]}function pt(o){let{a:t,b:e,c:s,d:i,e:n,f:r}=o.getTransform().invertSelf();return[t,e,s,i,n,r]}function Lt(o,t,e=!1,s=!0){if(t instanceof Qt){let{pageWidth:i,pageHeight:n}=t.rawDims,{style:r}=o,a=Z.isCSSRoundSupported,l=`var(--scale-factor) * ${i}px`,h=`var(--scale-factor) * ${n}px`,c=a?`round(down, ${l}, var(--scale-round-x, 1px))`:`calc(${l})`,d=a?`round(down, ${h}, var(--scale-round-y, 1px))`:`calc(${h})`;e&&t.rotation%180!=0?(r.width=d,r.height=c):(r.width=c,r.height=d)}s&&o.setAttribute("data-main-rotation",t.rotation)}var Zt=class{constructor(){let t=window.devicePixelRatio||1;this.sx=t,this.sy=t}get scaled(){return this.sx!==1||this.sy!==1}get symmetric(){return this.sx===this.sy}},vs=class o{#t=null;#e=null;#s;#i=null;#r=null;static#n=null;constructor(t){this.#s=t,o.#n||=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"})}render(){let t=this.#t=document.createElement("div");t.classList.add("editToolbar","hidden"),t.setAttribute("role","toolbar");let e=this.#s._uiManager._signal;t.addEventListener("contextmenu",ft,{signal:e}),t.addEventListener("pointerdown",o.#l,{signal:e});let s=this.#i=document.createElement("div");s.className="buttons",t.append(s);let i=this.#s.toolbarPosition;if(i){let{style:n}=t,r=this.#s._uiManager.direction==="ltr"?1-i[0]:i[0];n.insetInlineEnd=100*r+"%",n.top=`calc(${100*i[1]}% + var(--editor-toolbar-vert-offset))`}return this.#u(),t}get div(){return this.#t}static#l(t){t.stopPropagation()}#o(t){this.#s._focusEventsAllowed=!1,ht(t)}#c(t){this.#s._focusEventsAllowed=!0,ht(t)}#h(t){let e=this.#s._uiManager._signal;t.addEventListener("focusin",this.#o.bind(this),{capture:!0,signal:e}),t.addEventListener("focusout",this.#c.bind(this),{capture:!0,signal:e}),t.addEventListener("contextmenu",ft,{signal:e})}hide(){this.#t.classList.add("hidden"),this.#e?.hideDropdown()}show(){this.#t.classList.remove("hidden"),this.#r?.shown()}#u(){let{editorType:t,_uiManager:e}=this.#s,s=document.createElement("button");s.className="delete",s.tabIndex=0,s.setAttribute("data-l10n-id",o.#n[t]),this.#h(s),s.addEventListener("click",(i=>{e.delete()}),{signal:e._signal}),this.#i.append(s)}get#d(){let t=document.createElement("div");return t.className="divider",t}async addAltText(t){let e=await t.render();this.#h(e),this.#i.prepend(e,this.#d),this.#r=t}addColorPicker(t){this.#e=t;let e=t.renderButton();this.#h(e),this.#i.prepend(e,this.#d)}remove(){this.#t.remove(),this.#e?.destroy(),this.#e=null}},_s=class{#t=null;#e=null;#s;constructor(t){this.#s=t}#i(){let t=this.#e=document.createElement("div");t.className="editToolbar",t.setAttribute("role","toolbar"),t.addEventListener("contextmenu",ft,{signal:this.#s._signal});let e=this.#t=document.createElement("div");return e.className="buttons",t.append(e),this.#n(),t}#r(t,e){let s=0,i=0;for(let n of t){let r=n.y+n.height;if(r<s)continue;let a=n.x+(e?n.width:0);r>s?(i=a,s=r):e?a>i&&(i=a):a<i&&(i=a)}return[e?1-i:i,s]}show(t,e,s){let[i,n]=this.#r(e,s),{style:r}=this.#e||=this.#i();t.append(this.#e),r.insetInlineEnd=100*i+"%",r.top=`calc(${100*n}% + var(--editor-toolbar-vert-offset))`}hide(){this.#e.remove()}#n(){let t=document.createElement("button");t.className="highlightButton",t.tabIndex=0,t.setAttribute("data-l10n-id","pdfjs-highlight-floating-button1");let e=document.createElement("span");t.append(e),e.className="visuallyHidden",e.setAttribute("data-l10n-id","pdfjs-highlight-floating-button-label");let s=this.#s._signal;t.addEventListener("contextmenu",ft,{signal:s}),t.addEventListener("click",(()=>{this.#s.highlightSelection("floating_button")}),{signal:s}),this.#t.append(t)}};function _e(o,t,e){for(let s of e)t.addEventListener(s,o[s].bind(o))}var xs=class{#t=0;get id(){return"pdfjs_internal_editor_"+this.#t++}},Ss=class o{#t=(function(){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();let e=new Uint8Array(32);return crypto.getRandomValues(e),un(e)})();#e=0;#s=null;static get _isSVGFittingCanvas(){let t=new OffscreenCanvas(1,3).getContext("2d",{willReadFrequently:!0}),e=new Image;return e.src='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>',N(this,"_isSVGFittingCanvas",e.decode().then((()=>(t.drawImage(e,0,0,1,1,0,0,1,3),new Uint32Array(t.getImageData(0,0,1,1).data.buffer)[0]===0))))}async#i(t,e){this.#s||=new Map;let s=this.#s.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 es(e,"blob")):e instanceof File?i=s.file=e:e instanceof Blob&&(i=e),i.type==="image/svg+xml"){let n=o._isSVGFittingCanvas,r=new FileReader,a=new Image,l=new Promise(((h,c)=>{a.onload=()=>{s.bitmap=a,s.isSvg=!0,h()},r.onload=async()=>{let d=s.svgUrl=r.result;a.src=await n?`${d}#svgView(preserveAspectRatio(none))`:d},a.onerror=r.onerror=c}));r.readAsDataURL(i),await l}else s.bitmap=await createImageBitmap(i);s.refCounter=1}catch(i){F(i),s=null}return this.#s.set(t,s),s&&this.#s.set(s.id,s),s}async getFromFile(t){let{lastModified:e,name:s,size:i,type:n}=t;return this.#i(`${e}_${s}_${i}_${n}`,t)}async getFromUrl(t){return this.#i(t,t)}async getFromBlob(t,e){let s=await e;return this.#i(t,s)}async getFromId(t){this.#s||=new Map;let e=this.#s.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){let{blobPromise:s}=e;return delete e.blobPromise,this.getFromBlob(e.id,s)}return this.getFromUrl(e.url)}getFromCanvas(t,e){this.#s||=new Map;let s=this.#s.get(t);if(s?.bitmap)return s.refCounter+=1,s;let 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.#s.set(t,s),this.#s.set(s.id,s),s}getSvgUrl(t){let e=this.#s.get(t);return e?.isSvg?e.svgUrl:null}deleteId(t){this.#s||=new Map;let e=this.#s.get(t);if(!e||(e.refCounter-=1,e.refCounter!==0))return;let{bitmap:s}=e;if(!e.url&&!e.file){let 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}_`)}},Es=class{#t=[];#e=!1;#s;#i=-1;constructor(t=128){this.#s=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;let l={cmd:t,undo:e,post:s,type:n};if(this.#i===-1){this.#t.length>0&&(this.#t.length=0),this.#i=0,this.#t.push(l);return}if(r&&this.#t[this.#i].type===n){a&&(l.undo=this.#t[this.#i].undo),this.#t[this.#i]=l;return}let h=this.#i+1;h===this.#s?this.#t.splice(0,1):(this.#i=h,h<this.#t.length&&this.#t.splice(h)),this.#t.push(l)}undo(){if(this.#i===-1)return;this.#e=!0;let{undo:t,post:e}=this.#t[this.#i];t(),e?.(),this.#e=!1,this.#i-=1}redo(){if(this.#i<this.#t.length-1){this.#i+=1,this.#e=!0;let{cmd:t,post:e}=this.#t[this.#i];t(),e?.(),this.#e=!1}}hasSomethingToUndo(){return this.#i!==-1}hasSomethingToRedo(){return this.#i<this.#t.length-1}cleanType(t){if(this.#i!==-1){for(let e=this.#i;e>=0;e--)if(this.#t[e].type!==t){this.#t.splice(e+1,this.#i-e),this.#i=e;return}this.#t.length=0,this.#i=-1}}destroy(){this.#t=null}},Dt=class{constructor(t){this.buffer=[],this.callbacks=new Map,this.allKeys=new Set;let{isMac:e}=Z.platform;for(let[s,i,n={}]of t)for(let r of s){let 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);let e=this.buffer.join("+");return this.buffer.length=0,e}exec(t,e){if(!this.allKeys.has(e.key))return;let s=this.callbacks.get(this.#t(e));if(!s)return;let{callback:i,options:{bubbles:n=!1,args:r=[],checker:a=null}}=s;(!a||a(t,e))&&(i.bind(t,...r,e)(),n||ht(e))}},Cs=class o{static _colorsMapping=new Map([["CanvasText",[0,0,0]],["Canvas",[255,255,255]]]);get _colors(){let t=new Map([["CanvasText",null],["Canvas",null]]);return(function(s){let i=document.createElement("span");i.style.visibility="hidden",document.body.append(i);for(let n of s.keys()){i.style.color=n;let r=window.getComputedStyle(i).color;s.set(n,As(r))}i.remove()})(t),N(this,"_colors",t)}convert(t){let e=As(t);if(!window.matchMedia("(forced-colors: active)").matches)return e;for(let[s,i]of this._colors)if(i.every(((n,r)=>n===e[r])))return o._colorsMapping.get(s);return e}getHexCode(t){let e=this._colors.get(t);return e?k.makeHexColor(...e):t}},Ft=class o{#t=new AbortController;#e=null;#s=new Map;#i=new Map;#r=null;#n=null;#l=null;#o=new Es;#c=null;#h=null;#u=0;#d=new Set;#f=null;#a=null;#p=new Set;_editorUndoBar=null;#m=!1;#g=!1;#b=!1;#A=null;#y=null;#v=null;#x=null;#E=!1;#k=null;#T=new xs;#_=!1;#M=!1;#C=null;#R=null;#D=null;#N=null;#S=D.NONE;#w=new Set;#L=null;#j=null;#V=null;#z={isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1};#O=[0,0];#F=null;#$=null;#G=null;#I=null;static TRANSLATE_SMALL=1;static TRANSLATE_BIG=10;static get _keyboardManager(){let t=o.prototype,e=r=>r.#$.contains(document.activeElement)&&document.activeElement.tagName!=="BUTTON"&&r.hasSomethingToControl(),s=(r,{target:a})=>{if(a instanceof HTMLInputElement){let{type:l}=a;return l!=="text"&&l!=="number"}return!0},i=this.TRANSLATE_SMALL,n=this.TRANSLATE_BIG;return N(this,"_keyboardManager",new Dt([[["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.#$.contains(a)&&!r.isEnterHandled}],[[" ","mac+ "],t.addNewEditorFromKeyboard,{checker:(r,{target:a})=>!(a instanceof HTMLButtonElement)&&r.#$.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,l,h,c,d,u,f){let p=this._signal=this.#t.signal;this.#$=t,this.#G=e,this.#r=s,this._eventBus=i,i._on("editingaction",this.onEditingAction.bind(this),{signal:p}),i._on("pagechanging",this.onPageChanging.bind(this),{signal:p}),i._on("scalechanging",this.onScaleChanging.bind(this),{signal:p}),i._on("rotationchanging",this.onRotationChanging.bind(this),{signal:p}),i._on("setpreference",this.onSetPreference.bind(this),{signal:p}),i._on("switchannotationeditorparams",(g=>this.updateParams(g.type,g.value)),{signal:p}),this.#et(),this.#rt(),this.#X(),this.#n=n.annotationStorage,this.#A=n.filterFactory,this.#j=r,this.#x=a||null,this.#m=l,this.#g=h,this.#b=c,this.#N=d||null,this.viewParameters={realScale:Ct.PDF_TO_CSS_UNITS,rotation:0},this.isShiftKeyDown=!1,this._editorUndoBar=u||null,this._supportsPinchToZoom=f!==!1}destroy(){this.#I?.resolve(),this.#I=null,this.#t?.abort(),this.#t=null,this._signal=null;for(let t of this.#i.values())t.destroy();this.#i.clear(),this.#s.clear(),this.#p.clear(),this.#e=null,this.#w.clear(),this.#o.destroy(),this.#r?.destroy(),this.#k?.hide(),this.#k=null,this.#y&&(clearTimeout(this.#y),this.#y=null),this.#F&&(clearTimeout(this.#F),this.#F=null),this._editorUndoBar?.destroy()}combinedSignal(t){return AbortSignal.any([this._signal,t.signal])}get mlManager(){return this.#N}get useNewAltTextFlow(){return this.#g}get useNewAltTextWhenAddingImage(){return this.#b}get hcmFilter(){return N(this,"hcmFilter",this.#j?this.#A.addHCMFilter(this.#j.foreground,this.#j.background):"none")}get direction(){return N(this,"direction",getComputedStyle(this.#$).direction)}get highlightColors(){return N(this,"highlightColors",this.#x?new Map(this.#x.split(",").map((t=>t.split("=").map((e=>e.trim()))))):null)}get highlightColorNames(){return N(this,"highlightColorNames",this.highlightColors?new Map(Array.from(this.highlightColors,(t=>t.reverse()))):null)}setCurrentDrawingSession(t){t?(this.unselectAll(),this.disableUserSelect(!0)):this.disableUserSelect(!1),this.#h=t}setMainHighlightColorPicker(t){this.#D=t}editAltText(t,e=!1){this.#r?.editAltText(this,t,e)}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}){t==="enableNewAltTextWhenAddingImage"&&(this.#b=e)}onPageChanging({pageNumber:t}){this.#u=t-1}focusMainContainer(){this.#$.focus()}findParent(t,e){for(let s of this.#i.values()){let{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.#G.classList.toggle("noUserSelect",t)}addShouldRescale(t){this.#p.add(t)}removeShouldRescale(t){this.#p.delete(t)}onScaleChanging({scale:t}){this.commitOrRemove(),this.viewParameters.realScale=t*Ct.PDF_TO_CSS_UNITS;for(let e of this.#p)e.onScaleChanging();this.#h?.onScaleChanging()}onRotationChanging({pagesRotation:t}){this.commitOrRemove(),this.viewParameters.rotation=t}#B({anchorNode:t}){return t.nodeType===Node.TEXT_NODE?t.parentElement:t}#W(t){let{currentLayer:e}=this;if(e.hasTextLayer(t))return e;for(let s of this.#i.values())if(s.hasTextLayer(t))return s;return null}highlightSelection(t=""){let e=document.getSelection();if(!e||e.isCollapsed)return;let{anchorNode:s,anchorOffset:i,focusNode:n,focusOffset:r}=e,a=e.toString(),l=this.#B(e).closest(".textLayer"),h=this.getSelectionBoxes(l);if(!h)return;e.empty();let c=this.#W(l),d=this.#S===D.NONE,u=()=>{c?.createAndAddNewEditor({x:0,y:0},!1,{methodOfCreation:t,boxes:h,anchorNode:s,anchorOffset:i,focusNode:n,focusOffset:r,text:a}),d&&this.showAllEditors("highlight",!0,!0)};d?this.switchToMode(D.HIGHLIGHT,u):u()}#Z(){let t=document.getSelection();if(!t||t.isCollapsed)return;let e=this.#B(t).closest(".textLayer"),s=this.getSelectionBoxes(e);s&&(this.#k||=new _s(this),this.#k.show(e,s,this.direction==="ltr"))}addToAnnotationStorage(t){t.isEmpty()||!this.#n||this.#n.has(t.id)||this.#n.setValue(t.id,t)}#tt(){let t=document.getSelection();if(!t||t.isCollapsed){this.#L&&(this.#k?.hide(),this.#L=null,this.#P({hasSelectedText:!1}));return}let{anchorNode:e}=t;if(e===this.#L)return;let s=this.#B(t).closest(".textLayer");if(s){if(this.#k?.hide(),this.#L=e,this.#P({hasSelectedText:!0}),(this.#S===D.HIGHLIGHT||this.#S===D.NONE)&&(this.#S===D.HIGHLIGHT&&this.showAllEditors("highlight",!0,!0),this.#E=this.isShiftKeyDown,!this.isShiftKeyDown)){let i=this.#S===D.HIGHLIGHT?this.#W(s):null;i?.toggleDrawing();let n=new AbortController,r=this.combinedSignal(n),a=l=>{(l.type!=="pointerup"||l.button===0)&&(n.abort(),i?.toggleDrawing(!0),l.type==="pointerup"&&this.#q("main_toolbar"))};window.addEventListener("pointerup",a,{signal:r}),window.addEventListener("blur",a,{signal:r})}}else this.#L&&(this.#k?.hide(),this.#L=null,this.#P({hasSelectedText:!1}))}#q(t=""){this.#S===D.HIGHLIGHT?this.highlightSelection(t):this.#m&&this.#Z()}#et(){document.addEventListener("selectionchange",this.#tt.bind(this),{signal:this._signal})}#st(){if(this.#v)return;this.#v=new AbortController;let t=this.combinedSignal(this.#v);window.addEventListener("focus",this.focus.bind(this),{signal:t}),window.addEventListener("blur",this.blur.bind(this),{signal:t})}#it(){this.#v?.abort(),this.#v=null}blur(){if(this.isShiftKeyDown=!1,this.#E&&(this.#E=!1,this.#q("main_toolbar")),!this.hasSelection)return;let{activeElement:t}=document;for(let e of this.#w)if(e.div.contains(t)){this.#R=[e,t],e._focusEventsAllowed=!1;break}}focus(){if(!this.#R)return;let[t,e]=this.#R;this.#R=null,e.addEventListener("focusin",(()=>{t._focusEventsAllowed=!0}),{once:!0,signal:this._signal}),e.focus()}#X(){if(this.#C)return;this.#C=new AbortController;let t=this.combinedSignal(this.#C);window.addEventListener("keydown",this.keydown.bind(this),{signal:t}),window.addEventListener("keyup",this.keyup.bind(this),{signal:t})}#nt(){this.#C?.abort(),this.#C=null}#Y(){if(this.#c)return;this.#c=new AbortController;let t=this.combinedSignal(this.#c);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})}#K(){this.#c?.abort(),this.#c=null}#rt(){let t=this._signal;document.addEventListener("dragover",this.dragOver.bind(this),{signal:t}),document.addEventListener("drop",this.drop.bind(this),{signal:t})}addEditListeners(){this.#X(),this.#Y()}removeEditListeners(){this.#nt(),this.#K()}dragOver(t){for(let{type:e}of t.dataTransfer.items)for(let s of this.#a)if(s.isHandlingMimeForPasting(e)){t.dataTransfer.dropEffect="copy",t.preventDefault();return}}drop(t){for(let e of t.dataTransfer.items)for(let s of this.#a)if(s.isHandlingMimeForPasting(e.type)){s.paste(e,this.currentLayer),t.preventDefault();return}}copy(t){if(t.preventDefault(),this.#e?.commitOrRemove(),!this.hasSelection)return;let e=[];for(let s of this.#w){let 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();let{clipboardData:e}=t;for(let n of e.items)for(let r of this.#a)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){F(`paste: "${n.message}".`);return}if(!Array.isArray(s))return;this.unselectAll();let i=this.currentLayer;try{let n=[];for(let l of s){let h=await i.deserialize(l);if(!h)return;n.push(h)}let r=()=>{for(let l of n)this.#Q(l);this.#J(n)},a=()=>{for(let l of n)l.remove()};this.addCommands({cmd:r,undo:a,mustExec:!0})}catch(n){F(`paste: "${n.message}".`)}}keydown(t){this.isShiftKeyDown||t.key!=="Shift"||(this.isShiftKeyDown=!0),this.#S===D.NONE||this.isEditorHandlingKeyboard||o._keyboardManager.exec(this,t)}keyup(t){this.isShiftKeyDown&&t.key==="Shift"&&(this.isShiftKeyDown=!1,this.#E&&(this.#E=!1,this.#q("main_toolbar")))}onEditingAction({name:t}){switch(t){case"undo":case"redo":case"delete":case"selectAll":this[t]();break;case"highlightSelection":this.highlightSelection("context_menu")}}#P(t){Object.entries(t).some((([e,s])=>this.#z[e]!==s))&&(this._eventBus.dispatch("annotationeditorstateschanged",{source:this,details:Object.assign(this.#z,t)}),this.#S===D.HIGHLIGHT&&t.hasSelectedEditor===!1&&this.#H([[B.HIGHLIGHT_FREE,!0]]))}#H(t){this._eventBus.dispatch("annotationeditorparamschanged",{source:this,details:t})}setEditingState(t){t?(this.#st(),this.#Y(),this.#P({isEditing:this.#S!==D.NONE,isEmpty:this.#U(),hasSomethingToUndo:this.#o.hasSomethingToUndo(),hasSomethingToRedo:this.#o.hasSomethingToRedo(),hasSelectedEditor:!1})):(this.#it(),this.#K(),this.#P({isEditing:!1}),this.disableUserSelect(!1))}registerEditorTypes(t){if(!this.#a){this.#a=t;for(let e of this.#a)this.#H(e.defaultPropertiesToUpdate)}}getId(){return this.#T.id}get currentLayer(){return this.#i.get(this.#u)}getLayer(t){return this.#i.get(t)}get currentPageIndex(){return this.#u}addLayer(t){this.#i.set(t.pageIndex,t),this.#_?t.enable():t.disable()}removeLayer(t){this.#i.delete(t.pageIndex)}async updateMode(t,e=null,s=!1){if(this.#S!==t){if(this.#I&&(await this.#I.promise,!this.#I))return;if(this.#I=Promise.withResolvers(),this.#S=t,t!==D.NONE){this.setEditingState(!0),await this.#at(),this.unselectAll();for(let i of this.#i.values())i.updateMode(t);if(e){for(let i of this.#s.values())i.annotationElementId===e?(this.setSelected(i),i.enterInEditMode()):i.unselect();this.#I.resolve()}else s&&this.addNewEditorFromKeyboard(),this.#I.resolve()}else this.setEditingState(!1),this.#ot(),this._editorUndoBar?.hide(),this.#I.resolve()}}addNewEditorFromKeyboard(){this.currentLayer.canCreateNewEmptyEditor()&&this.currentLayer.addNewEditor()}updateToolbar(t){t!==this.#S&&this._eventBus.dispatch("switchannotationeditormode",{source:this,mode:t})}updateParams(t,e){if(this.#a){switch(t){case B.CREATE:this.currentLayer.addNewEditor();return;case B.HIGHLIGHT_DEFAULT_COLOR:this.#D?.updateColor(e);break;case B.HIGHLIGHT_SHOW_ALL:this._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:{type:"highlight",action:"toggle_visibility"}}}),(this.#V||=new Map).set(t,e),this.showAllEditors("highlight",e)}for(let s of this.#w)s.updateParams(t,e);for(let s of this.#a)s.updateDefaultParams(t,e)}}showAllEditors(t,e,s=!1){for(let i of this.#s.values())i.editorType===t&&i.show(e);(this.#V?.get(B.HIGHLIGHT_SHOW_ALL)??!0)!==e&&this.#H([[B.HIGHLIGHT_SHOW_ALL,e]])}enableWaiting(t=!1){if(this.#M!==t){this.#M=t;for(let e of this.#i.values())t?e.disableClick():e.enableClick(),e.div.classList.toggle("waiting",t)}}async#at(){if(!this.#_){this.#_=!0;let t=[];for(let e of this.#i.values())t.push(e.enable());await Promise.all(t);for(let e of this.#s.values())e.enable()}}#ot(){if(this.unselectAll(),this.#_){this.#_=!1;for(let t of this.#i.values())t.disable();for(let t of this.#s.values())t.disable()}}getEditors(t){let e=[];for(let s of this.#s.values())s.pageIndex===t&&e.push(s);return e}getEditor(t){return this.#s.get(t)}addEditor(t){this.#s.set(t.id,t)}removeEditor(t){t.div.contains(document.activeElement)&&(this.#y&&clearTimeout(this.#y),this.#y=setTimeout((()=>{this.focusMainContainer(),this.#y=null}),0)),this.#s.delete(t.id),this.unselect(t),t.annotationElementId&&this.#d.has(t.annotationElementId)||this.#n?.remove(t.id)}addDeletedAnnotationElement(t){this.#d.add(t.annotationElementId),this.addChangedExistingAnnotation(t),t.deleted=!0}isDeletedAnnotationElement(t){return this.#d.has(t)}removeDeletedAnnotationElement(t){this.#d.delete(t.annotationElementId),this.removeChangedExistingAnnotation(t),t.deleted=!1}#Q(t){let e=this.#i.get(t.pageIndex);e?e.addOrRebuild(t):(this.addEditor(t),this.addToAnnotationStorage(t))}setActiveEditor(t){this.#e!==t&&(this.#e=t,t&&this.#H(t.propertiesToUpdate))}get#lt(){let t=null;for(t of this.#w);return t}updateUI(t){this.#lt===t&&this.#H(t.propertiesToUpdate)}updateUIForDefaultProperties(t){this.#H(t.defaultPropertiesToUpdate)}toggleSelected(t){this.#w.has(t)?(this.#w.delete(t),t.unselect(),this.#P({hasSelectedEditor:this.hasSelection})):(this.#w.add(t),t.select(),this.#H(t.propertiesToUpdate),this.#P({hasSelectedEditor:!0}))}setSelected(t){this.#h?.commitOrRemove();for(let e of this.#w)e!==t&&e.unselect();this.#w.clear(),this.#w.add(t),t.select(),this.#H(t.propertiesToUpdate),this.#P({hasSelectedEditor:!0})}isSelected(t){return this.#w.has(t)}get firstSelectedEditor(){return this.#w.values().next().value}unselect(t){t.unselect(),this.#w.delete(t),this.#P({hasSelectedEditor:this.hasSelection})}get hasSelection(){return this.#w.size!==0}get isEnterHandled(){return this.#w.size===1&&this.firstSelectedEditor.isEnterHandled}undo(){this.#o.undo(),this.#P({hasSomethingToUndo:this.#o.hasSomethingToUndo(),hasSomethingToRedo:!0,isEmpty:this.#U()}),this._editorUndoBar?.hide()}redo(){this.#o.redo(),this.#P({hasSomethingToUndo:!0,hasSomethingToRedo:this.#o.hasSomethingToRedo(),isEmpty:this.#U()})}addCommands(t){this.#o.add(t),this.#P({hasSomethingToUndo:!0,hasSomethingToRedo:!1,isEmpty:this.#U()})}cleanUndoStack(t){this.#o.cleanType(t)}#U(){if(this.#s.size===0)return!0;if(this.#s.size===1)for(let t of this.#s.values())return t.isEmpty();return!1}delete(){this.commitOrRemove();let t=this.currentLayer?.endDrawingSession(!0);if(!this.hasSelection&&!t)return;let e=t?[t]:[...this.#w],s=()=>{for(let i of e)this.#Q(i)};this.addCommands({cmd:()=>{this._editorUndoBar?.show(s,e.length===1?e[0].editorType:e.length);for(let i of e)i.remove()},undo:s,mustExec:!0})}commitOrRemove(){this.#e?.commitOrRemove()}hasSomethingToControl(){return this.#e||this.hasSelection}#J(t){for(let e of this.#w)e.unselect();this.#w.clear();for(let e of t)e.isEmpty()||(this.#w.add(e),e.select());this.#P({hasSelectedEditor:this.hasSelection})}selectAll(){for(let t of this.#w)t.commit();this.#J(this.#s.values())}unselectAll(){if(!(this.#e&&(this.#e.commitOrRemove(),this.#S!==D.NONE))&&!this.#h?.commitOrRemove()&&this.hasSelection){for(let t of this.#w)t.unselect();this.#w.clear(),this.#P({hasSelectedEditor:!1})}}translateSelectedEditors(t,e,s=!1){if(s||this.commitOrRemove(),!this.hasSelection)return;this.#O[0]+=t,this.#O[1]+=e;let[i,n]=this.#O,r=[...this.#w];this.#F&&clearTimeout(this.#F),this.#F=setTimeout((()=>{this.#F=null,this.#O[0]=this.#O[1]=0,this.addCommands({cmd:()=>{for(let a of r)this.#s.has(a.id)&&a.translateInPage(i,n)},undo:()=>{for(let a of r)this.#s.has(a.id)&&a.translateInPage(-i,-n)},mustExec:!1})}),1e3);for(let a of r)a.translateInPage(t,e)}setUpDragSession(){if(this.hasSelection){this.disableUserSelect(!0),this.#f=new Map;for(let t of this.#w)this.#f.set(t,{savedX:t.x,savedY:t.y,savedPageIndex:t.pageIndex,newX:0,newY:0,newPageIndex:-1})}}endDragSession(){if(!this.#f)return!1;this.disableUserSelect(!1);let t=this.#f;this.#f=null;let e=!1;for(let[{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;let s=(i,n,r,a)=>{if(this.#s.has(i.id)){let l=this.#i.get(a);l?i._setParentAndPosition(l,n,r):(i.pageIndex=a,i.x=n,i.y=r)}};return this.addCommands({cmd:()=>{for(let[i,{newX:n,newY:r,newPageIndex:a}]of t)s(i,n,r,a)},undo:()=>{for(let[i,{savedX:n,savedY:r,savedPageIndex:a}]of t)s(i,n,r,a)},mustExec:!0}),!0}dragSelectedEditors(t,e){if(this.#f)for(let s of this.#f.keys())s.drag(t,e)}rebuild(t){if(t.parent===null){let 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.#w.size===1&&this.firstSelectedEditor.shouldGetKeyboardEvents()}isActive(t){return this.#e===t}getActive(){return this.#e}getMode(){return this.#S}get imageManager(){return N(this,"imageManager",new Ss)}getSelectionBoxes(t){if(!t)return null;let e=document.getSelection();for(let h=0,c=e.rangeCount;h<c;h++)if(!t.contains(e.getRangeAt(h).commonAncestorContainer))return null;let{x:s,y:i,width:n,height:r}=t.getBoundingClientRect(),a;switch(t.getAttribute("data-main-rotation")){case"90":a=(h,c,d,u)=>({x:(c-i)/r,y:1-(h+d-s)/n,width:u/r,height:d/n});break;case"180":a=(h,c,d,u)=>({x:1-(h+d-s)/n,y:1-(c+u-i)/r,width:d/n,height:u/r});break;case"270":a=(h,c,d,u)=>({x:1-(c+u-i)/r,y:(h-s)/n,width:u/r,height:d/n});break;default:a=(h,c,d,u)=>({x:(h-s)/n,y:(c-i)/r,width:d/n,height:u/r})}let l=[];for(let h=0,c=e.rangeCount;h<c;h++){let d=e.getRangeAt(h);if(!d.collapsed)for(let{x:u,y:f,width:p,height:g}of d.getClientRects())p!==0&&g!==0&&l.push(a(u,f,p,g))}return l.length===0?null:l}addChangedExistingAnnotation({annotationElementId:t,id:e}){(this.#l||=new Map).set(t,e)}removeChangedExistingAnnotation({annotationElementId:t}){this.#l?.delete(t)}renderAnnotationElement(t){let e=this.#l?.get(t.data.id);if(!e)return;let s=this.#n.getRawValue(e);s&&(this.#S!==D.NONE||s.hasBeenModified)&&s.renderAnnotationElement(t)}},xe=class o{#t=null;#e=!1;#s=null;#i=null;#r=null;#n=null;#l=!1;#o=null;#c=null;#h=null;#u=null;#d=!1;static#f=null;static _l10n=null;constructor(t){this.#c=t,this.#d=t._uiManager.useNewAltTextFlow,o.#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){o._l10n??=t}async render(){let t=this.#s=document.createElement("button");t.className="altText",t.tabIndex="0";let e=this.#i=document.createElement("span");t.append(e),this.#d?(t.classList.add("new"),t.setAttribute("data-l10n-id",o.#f.missing),e.setAttribute("data-l10n-id",o.#f["missing-label"])):(t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button"),e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button-label"));let s=this.#c._uiManager._signal;t.addEventListener("contextmenu",ft,{signal:s}),t.addEventListener("pointerdown",(n=>n.stopPropagation()),{signal:s});let i=n=>{n.preventDefault(),this.#c._uiManager.editAltText(this.#c),this.#d&&this.#c._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_clicked",data:{label:this.#a}})};return t.addEventListener("click",i,{capture:!0,signal:s}),t.addEventListener("keydown",(n=>{n.target===t&&n.key==="Enter"&&(this.#l=!0,i(n))}),{signal:s}),await this.#p(),t}get#a(){return(this.#t?"added":this.#t===null&&this.guessedText&&"review")||"missing"}finish(){this.#s&&(this.#s.focus({focusVisible:this.#l}),this.#l=!1)}isEmpty(){return this.#d?this.#t===null:!this.#t&&!this.#e}hasData(){return this.#d?this.#t!==null||!!this.#h:this.isEmpty()}get guessedText(){return this.#h}async setGuessedText(t){this.#t===null&&(this.#h=t,this.#u=await o._l10n.get("pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer",{generatedAltText:t}),this.#p())}toggleAltTextBadge(t=!1){if(this.#d&&!this.#t){if(!this.#o){let e=this.#o=document.createElement("div");e.className="noAltTextBadge",this.#c.div.append(e)}this.#o.classList.toggle("hidden",!t)}else this.#o?.remove(),this.#o=null}serialize(t){let e=this.#t;return t||this.#h!==e||(e=this.#u),{altText:e,decorative:this.#e,guessedText:this.#h,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.#h=s,this.#u=i),(this.#t!==t||this.#e!==e)&&(n||(this.#t=t,this.#e=e),this.#p())}toggle(t=!1){this.#s&&(!t&&this.#n&&(clearTimeout(this.#n),this.#n=null),this.#s.disabled=!t)}shown(){this.#c._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_displayed",data:{label:this.#a}})}destroy(){this.#s?.remove(),this.#s=null,this.#i=null,this.#r=null,this.#o?.remove(),this.#o=null}async#p(){let t=this.#s;if(!t)return;if(this.#d){if(t.classList.toggle("done",!!this.#t),t.setAttribute("data-l10n-id",o.#f[this.#a]),this.#i?.setAttribute("data-l10n-id",o.#f[`${this.#a}-label`]),!this.#t){this.#r?.remove();return}}else{if(!this.#t&&!this.#e){t.classList.remove("done"),this.#r?.remove();return}t.classList.add("done"),t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-edit-button")}let e=this.#r;if(!e){this.#r=e=document.createElement("span"),e.className="tooltip",e.setAttribute("role","tooltip"),e.id=`alt-text-tooltip-${this.#c.id}`;let i=100,n=this.#c._uiManager._signal;n.addEventListener("abort",(()=>{clearTimeout(this.#n),this.#n=null}),{once:!0}),t.addEventListener("mouseenter",(()=>{this.#n=setTimeout((()=>{this.#n=null,this.#r.classList.add("show"),this.#c._reportTelemetry({action:"alt_text_tooltip"})}),i)}),{signal:n}),t.addEventListener("mouseleave",(()=>{this.#n&&(clearTimeout(this.#n),this.#n=null),this.#r?.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.#c.getImageForAltText()?.setAttribute("aria-describedby",e.id)}},Se=class o{#t;#e=!1;#s=null;#i;#r;#n;#l;#o;#c=null;#h;#u=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.#s=s,this.#i=e,this.#r=i,this.#n=n,this.#l=r,this.#h=new AbortController,this.#o=AbortSignal.any([a,this.#h.signal]),t.addEventListener("touchstart",this.#d.bind(this),{passive:!1,signal:this.#o})}get MIN_TOUCH_DISTANCE_TO_PINCH(){return N(this,"MIN_TOUCH_DISTANCE_TO_PINCH",35/(window.devicePixelRatio||1))}#d(t){if(this.#i?.()||t.touches.length<2)return;if(!this.#u){this.#u=new AbortController;let i=AbortSignal.any([this.#o,this.#u.signal]),n=this.#t,r={signal:i,passive:!1};n.addEventListener("touchmove",this.#f.bind(this),r),n.addEventListener("touchend",this.#a.bind(this),r),n.addEventListener("touchcancel",this.#a.bind(this),r),this.#r?.()}if(ht(t),t.touches.length!==2||this.#s?.()){this.#c=null;return}let[e,s]=t.touches;e.identifier>s.identifier&&([e,s]=[s,e]),this.#c={touch0X:e.screenX,touch0Y:e.screenY,touch1X:s.screenX,touch1Y:s.screenY}}#f(t){if(!this.#c||t.touches.length!==2)return;let[e,s]=t.touches;e.identifier>s.identifier&&([e,s]=[s,e]);let{screenX:i,screenY:n}=e,{screenX:r,screenY:a}=s,l=this.#c,{touch0X:h,touch0Y:c,touch1X:d,touch1Y:u}=l,f=d-h,p=u-c,g=r-i,m=a-n,b=Math.hypot(g,m)||1,y=Math.hypot(f,p)||1;if(!this.#e&&Math.abs(y-b)<=o.MIN_TOUCH_DISTANCE_TO_PINCH)return;if(l.touch0X=i,l.touch0Y=n,l.touch1X=r,l.touch1Y=a,t.preventDefault(),!this.#e){this.#e=!0;return}let w=[(i+r)/2,(n+a)/2];this.#n?.(w,y,b)}#a(t){this.#u.abort(),this.#u=null,this.#l?.(),this.#c&&(t.preventDefault(),this.#c=null,this.#e=!1)}destroy(){this.#h?.abort(),this.#h=null}},W=class o{#t=null;#e=null;#s=null;#i=!1;#r=null;#n="";#l=!1;#o=null;#c=null;#h=null;#u=null;#d="";#f=!1;#a=null;#p=!1;#m=!1;#g=!1;#b=null;#A=0;#y=0;#v=null;#x=null;_editToolbar=null;_initialOptions=Object.create(null);_initialData=null;_isVisible=!0;_uiManager=null;_focusEventsAllowed=!0;static _l10n=null;static _l10nResizer=null;#E=!1;#k=o._zIndex++;static _borderLineWidth=-1;static _colorManager=new Cs;static _zIndex=1;static _telemetryTimeout=1e3;static get _resizerKeyboardManager(){let t=o.prototype._resizeWithKeyboard,e=Ft.TRANSLATE_SMALL,s=Ft.TRANSLATE_BIG;return N(this,"_resizerKeyboardManager",new Dt([[["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"],o.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;let{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];let[a,l]=this.parentDimensions;this.x=t.x/a,this.y=t.y/l,this.isAttachedToDOM=!1,this.deleted=!1}get editorType(){return Object.getPrototypeOf(this).constructor._type}static get isDrawer(){return!1}static get _defaultLineColor(){return N(this,"_defaultLineColor",this._colorManager.getHexCode("CanvasText"))}static deleteAnnotationElement(t){let e=new ks({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(o._l10n??=t,o._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"}),o._borderLineWidth!==-1)return;let s=getComputedStyle(document.documentElement);o._borderLineWidth=parseFloat(s.getPropertyValue("--outline-width"))||0}static updateDefaultParams(t,e){}static get defaultPropertiesToUpdate(){return[]}static isHandlingMimeForPasting(t){return!1}static paste(t,e){z("Not implemented")}get propertiesToUpdate(){return[]}get _isDraggable(){return this.#E}set _isDraggable(t){this.#E=t,this.div?.classList.toggle("draggable",t)}get isEnterHandled(){return!0}center(){let[t,e]=this.pageDimensions;switch(this.parentRotation){case 90:this.x-=this.height*e/(2*t),this.y+=this.width*t/(2*e);break;case 180:this.x+=this.width/2,this.y+=this.height/2;break;case 270:this.x+=this.height*e/(2*t),this.y-=this.width*t/(2*e);break;default:this.x-=this.width/2,this.y-=this.height/2}this.fixAndSetPosition()}addCommands(t){this._uiManager.addCommands(t)}get currentLayer(){return this._uiManager.currentLayer}setInBackground(){this.div.style.zIndex=0}setInForeground(){this.div.style.zIndex=this.#k}setParent(t){t!==null?(this.pageIndex=t.pageIndex,this.pageDimensions=t.pageDimensions):this.#B(),this.parent=t}focusin(t){this._focusEventsAllowed&&(this.#f?this.#f=!1:this.parent.setSelected(this))}focusout(t){if(!this._focusEventsAllowed||!this.isAttachedToDOM)return;t.relatedTarget?.closest(`#${this.id}`)||(t.preventDefault(),this.parent?.isMultipleSelection||this.commitOrRemove())}commitOrRemove(){this.isEmpty()?this.remove():this.commit()}commit(){this.addToAnnotationStorage()}addToAnnotationStorage(){this._uiManager.addToAnnotationStorage(this)}setAt(t,e,s,i){let[n,r]=this.parentDimensions;[s,i]=this.screenToPageTranslation(s,i),this.x=(t+s)/n,this.y=(e+i)/r,this.fixAndSetPosition()}#T([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.#T(this.parentDimensions,t,e)}translateInPage(t,e){this.#a||=[this.x,this.y,this.width,this.height],this.#T(this.pageDimensions,t,e),this.div.scrollIntoView({block:"nearest"})}drag(t,e){this.#a||=[this.x,this.y,this.width,this.height];let{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)){let{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,[l,h]=this.getBaseTranslation();r+=l,a+=h;let{style:c}=s;c.left=`${(100*r).toFixed(2)}%`,c.top=`${(100*a).toFixed(2)}%`,this._onTranslating(r,a),s.scrollIntoView({block:"nearest"})}_onTranslating(t,e){}_onTranslated(t,e){}get _hasBeenMoved(){return!!this.#a&&(this.#a[0]!==this.x||this.#a[1]!==this.y)}get _hasBeenResized(){return!!this.#a&&(this.#a[2]!==this.width||this.#a[3]!==this.height)}getBaseTranslation(){let[t,e]=this.parentDimensions,{_borderLineWidth:s}=o,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){let{div:{style:e},pageDimensions:[s,i]}=this,{x:n,y:r,width:a,height:l}=this;if(a*=s,l*=i,n*=s,r*=i,this._mustFixPosition)switch(t){case 0:n=Math.max(0,Math.min(s-a,n)),r=Math.max(0,Math.min(i-l,r));break;case 90:n=Math.max(0,Math.min(s-l,n)),r=Math.min(i,Math.max(a,r));break;case 180:n=Math.min(s,Math.max(a,n)),r=Math.min(i,Math.max(l,r));break;case 270:n=Math.min(s,Math.max(l,n)),r=Math.max(0,Math.min(i-a,r))}this.x=n/=s,this.y=r/=i;let[h,c]=this.getBaseTranslation();n+=h,r+=c,e.left=`${(100*n).toFixed(2)}%`,e.top=`${(100*r).toFixed(2)}%`,this.moveInDOM()}static#_(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 o.#_(t,e,this.parentRotation)}pageTranslationToScreen(t,e){return o.#_(t,e,360-this.parentRotation)}#M(t){switch(t){case 90:{let[e,s]=this.pageDimensions;return[0,-e/s,s/e,0]}case 180:return[-1,0,0,-1];case 270:{let[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(){let{parentScale:t,pageDimensions:[e,s]}=this;return[e*t,s*t]}setDims(t,e){let[s,i]=this.parentDimensions,{style:n}=this.div;n.width=`${(100*t/s).toFixed(2)}%`,this.#l||(n.height=`${(100*e/i).toFixed(2)}%`)}fixDims(){let{style:t}=this.div,{height:e,width:s}=t,i=s.endsWith("%"),n=!this.#l&&e.endsWith("%");if(i&&n)return;let[r,a]=this.parentDimensions;i||(t.width=`${(100*parseFloat(s)/r).toFixed(2)}%`),this.#l||n||(t.height=`${(100*parseFloat(e)/a).toFixed(2)}%`)}getInitialTranslation(){return[0,0]}#C(){if(this.#o)return;this.#o=document.createElement("div"),this.#o.classList.add("resizers");let t=this._willKeepAspectRatio?["topLeft","topRight","bottomRight","bottomLeft"]:["topLeft","topMiddle","topRight","middleRight","bottomRight","bottomMiddle","bottomLeft","middleLeft"],e=this._uiManager._signal;for(let s of t){let i=document.createElement("div");this.#o.append(i),i.classList.add("resizer",s),i.setAttribute("data-resizer-name",s),i.addEventListener("pointerdown",this.#R.bind(this,s),{signal:e}),i.addEventListener("contextmenu",ft,{signal:e}),i.tabIndex=-1}this.div.prepend(this.#o)}#R(t,e){e.preventDefault();let{isMac:s}=Z.platform;if(e.button!==0||e.ctrlKey&&s)return;this.#s?.toggle(!1);let i=this._isDraggable;this._isDraggable=!1,this.#c=[e.screenX,e.screenY];let n=new AbortController,r=this._uiManager.combinedSignal(n);this.parent.togglePointerEvents(!1),window.addEventListener("pointermove",this.#S.bind(this,t),{passive:!0,capture:!0,signal:r}),window.addEventListener("touchmove",ht,{passive:!1,signal:r}),window.addEventListener("contextmenu",ft,{signal:r}),this.#h={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height};let a=this.parent.div.style.cursor,l=this.div.style.cursor;this.div.style.cursor=this.parent.div.style.cursor=window.getComputedStyle(e.target).cursor;let h=()=>{n.abort(),this.parent.togglePointerEvents(!0),this.#s?.toggle(!0),this._isDraggable=i,this.parent.div.style.cursor=a,this.div.style.cursor=l,this.#N()};window.addEventListener("pointerup",h,{signal:r}),window.addEventListener("blur",h,{signal:r})}#D(t,e,s,i){this.width=s,this.height=i,this.x=t,this.y=e;let[n,r]=this.parentDimensions;this.setDims(n*s,r*i),this.fixAndSetPosition(),this._onResized()}_onResized(){}#N(){if(!this.#h)return;let{savedX:t,savedY:e,savedWidth:s,savedHeight:i}=this.#h;this.#h=null;let n=this.x,r=this.y,a=this.width,l=this.height;n===t&&r===e&&a===s&&l===i||this.addCommands({cmd:this.#D.bind(this,n,r,a,l),undo:this.#D.bind(this,t,e,s,i),mustExec:!0})}static _round(t){return Math.round(1e4*t)/1e4}#S(t,e){let[s,i]=this.parentDimensions,n=this.x,r=this.y,a=this.width,l=this.height,h=o.MIN_SIZE/s,c=o.MIN_SIZE/i,d=this.#M(this.rotation),u=(R,L)=>[d[0]*R+d[2]*L,d[1]*R+d[3]*L],f=this.#M(360-this.rotation),p,g,m=!1,b=!1;switch(t){case"topLeft":m=!0,p=(R,L)=>[0,0],g=(R,L)=>[R,L];break;case"topMiddle":p=(R,L)=>[R/2,0],g=(R,L)=>[R/2,L];break;case"topRight":m=!0,p=(R,L)=>[R,0],g=(R,L)=>[0,L];break;case"middleRight":b=!0,p=(R,L)=>[R,L/2],g=(R,L)=>[0,L/2];break;case"bottomRight":m=!0,p=(R,L)=>[R,L],g=(R,L)=>[0,0];break;case"bottomMiddle":p=(R,L)=>[R/2,L],g=(R,L)=>[R/2,0];break;case"bottomLeft":m=!0,p=(R,L)=>[0,L],g=(R,L)=>[R,0];break;case"middleLeft":b=!0,p=(R,L)=>[0,L/2],g=(R,L)=>[R,L/2]}let y=p(a,l),w=g(a,l),A=u(...w),_=o._round(n+A[0]),x=o._round(r+A[1]),v,C,M=1,I=1;if(e.fromKeyboard)({deltaX:v,deltaY:C}=e);else{let{screenX:R,screenY:L}=e,[ct,yt]=this.#c;[v,C]=this.screenToPageTranslation(R-ct,L-yt),this.#c[0]=R,this.#c[1]=L}[v,C]=(P=v/s,O=C/i,[f[0]*P+f[2]*O,f[1]*P+f[3]*O]);var P,O;if(m){let R=Math.hypot(a,l);M=I=Math.max(Math.min(Math.hypot(w[0]-y[0]-v,w[1]-y[1]-C)/R,1/a,1/l),h/a,c/l)}else b?M=Math.max(h,Math.min(1,Math.abs(w[0]-y[0]-v)))/a:I=Math.max(c,Math.min(1,Math.abs(w[1]-y[1]-C)))/l;let G=o._round(a*M),$=o._round(l*I);A=u(...g(G,$));let H=_-A[0],q=x-A[1];this.#a||=[this.x,this.y,this.width,this.height],this.width=G,this.height=$,this.x=H,this.y=q,this.setDims(s*G,i*$),this.fixAndSetPosition(),this._onResizing()}_onResizing(){}altTextFinish(){this.#s?.finish()}async addEditToolbar(){return this._editToolbar||this.#m?this._editToolbar:(this._editToolbar=new vs(this),this.div.append(this._editToolbar.render()),this.#s&&await this._editToolbar.addAltText(this.#s),this._editToolbar)}removeEditToolbar(){this._editToolbar&&(this._editToolbar.remove(),this._editToolbar=null,this.#s?.destroy())}addContainer(t){let e=this._editToolbar?.div;e?e.before(t):this.div.append(t)}getClientDimensions(){return this.div.getBoundingClientRect()}async addAltTextButton(){this.#s||(xe.initialize(o._l10n),this.#s=new xe(this),this.#t&&(this.#s.data=this.#t,this.#t=null),await this.addEditToolbar())}get altTextData(){return this.#s?.data}set altTextData(t){this.#s&&(this.#s.data=t)}get guessedAltText(){return this.#s?.guessedText}async setGuessedAltText(t){await this.#s?.setGuessedText(t)}serializeAltText(t){return this.#s?.serialize(t)}hasAltText(){return!!this.#s&&!this.#s.isEmpty()}hasAltTextData(){return this.#s?.hasData()??!1}render(){this.div=document.createElement("div"),this.div.setAttribute("data-editor-rotation",(360-this.rotation)%360),this.div.className=this.name,this.div.setAttribute("id",this.id),this.div.tabIndex=this.#i?-1:0,this._isVisible||this.div.classList.add("hidden"),this.setInForeground(),this.#O();let[t,e]=this.parentDimensions;this.parentRotation%180!=0&&(this.div.style.maxWidth=`${(100*e/t).toFixed(2)}%`,this.div.style.maxHeight=`${(100*t/e).toFixed(2)}%`);let[s,i]=this.getInitialTranslation();return this.translate(s,i),_e(this,this.div,["pointerdown"]),this.isResizable&&this._uiManager._supportsPinchToZoom&&(this.#x||=new Se({container:this.div,isPinchingDisabled:()=>!this.isSelected,onPinchStart:this.#w.bind(this),onPinching:this.#L.bind(this),onPinchEnd:this.#j.bind(this),signal:this._uiManager._signal})),this._uiManager._editorUndoBar?.hide(),this.div}#w(){this.#h={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height},this.#s?.toggle(!1),this.parent.togglePointerEvents(!1)}#L(t,e,s){let i=s/e*.7+1-.7;if(i===1)return;let n=this.#M(this.rotation),r=(_,x)=>[n[0]*_+n[2]*x,n[1]*_+n[3]*x],[a,l]=this.parentDimensions,h=this.x,c=this.y,d=this.width,u=this.height,f=o.MIN_SIZE/a,p=o.MIN_SIZE/l;i=Math.max(Math.min(i,1/d,1/u),f/d,p/u);let g=o._round(d*i),m=o._round(u*i);if(g===d&&m===u)return;this.#a||=[h,c,d,u];let b=r(d/2,u/2),y=o._round(h+b[0]),w=o._round(c+b[1]),A=r(g/2,m/2);this.x=y-A[0],this.y=w-A[1],this.width=g,this.height=m,this.setDims(a*g,l*m),this.fixAndSetPosition(),this._onResizing()}#j(){this.#s?.toggle(!0),this.parent.togglePointerEvents(!0),this.#N()}pointerdown(t){let{isMac:e}=Z.platform;t.button!==0||t.ctrlKey&&e?t.preventDefault():(this.#f=!0,this._isDraggable?this.#z(t):this.#V(t))}get isSelected(){return this._uiManager.isSelected(this)}#V(t){let{isMac:e}=Z.platform;t.ctrlKey&&!e||t.shiftKey||t.metaKey&&e?this.parent.toggleSelected(this):this.parent.setSelected(this)}#z(t){let{isSelected:e}=this;this._uiManager.setUpDragSession();let s=!1,i=new AbortController,n=this._uiManager.combinedSignal(i),r={capture:!0,passive:!1,signal:n},a=h=>{i.abort(),this.#r=null,this.#f=!1,this._uiManager.endDragSession()||this.#V(h),s&&this._onStopDragging()};e&&(this.#A=t.clientX,this.#y=t.clientY,this.#r=t.pointerId,this.#n=t.pointerType,window.addEventListener("pointermove",(h=>{s||(s=!0,this._onStartDragging());let{clientX:c,clientY:d,pointerId:u}=h;if(u!==this.#r){ht(h);return}let[f,p]=this.screenToPageTranslation(c-this.#A,d-this.#y);this.#A=c,this.#y=d,this._uiManager.dragSelectedEditors(f,p)}),r),window.addEventListener("touchmove",ht,r),window.addEventListener("pointerdown",(h=>{h.pointerType===this.#n&&(this.#x||h.isPrimary)&&a(h),ht(h)}),r));let l=h=>{this.#r&&this.#r!==h.pointerId?ht(h):a(h)};window.addEventListener("pointerup",l,{signal:n}),window.addEventListener("blur",l,{signal:n})}_onStartDragging(){}_onStopDragging(){}moveInDOM(){this.#b&&clearTimeout(this.#b),this.#b=setTimeout((()=>{this.#b=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){let i=this.parentScale,[n,r]=this.pageDimensions,[a,l]=this.pageTranslation,h=t/i,c=e/i,d=this.x*n,u=this.y*r,f=this.width*n,p=this.height*r;switch(s){case 0:return[d+h+a,r-u-c-p+l,d+h+f+a,r-u-c+l];case 90:return[d+c+a,r-u+h+l,d+c+p+a,r-u+h+f+l];case 180:return[d-h-f+a,r-u+c+l,d-h+a,r-u+c+p+l];case 270:return[d-c-p+a,r-u-h-f+l,d-c+a,r-u-h+l];default:throw new Error("Invalid rotation")}}getRectInCurrentCoords(t,e){let[s,i,n,r]=t,a=n-s,l=r-i;switch(this.rotation){case 0:return[s,e-r,a,l];case 90:return[s,e-i,l,a];case 180:return[n,e-i,a,l];case 270:return[n,e-r,l,a];default:throw new Error("Invalid rotation")}}onceAdded(t){}isEmpty(){return!1}enableEditMode(){this.#m=!0}disableEditMode(){this.#m=!1}isInEditMode(){return this.#m}shouldGetKeyboardEvents(){return this.#g}needsToBeRebuilt(){return this.div&&!this.isAttachedToDOM}get isOnScreen(){let{top:t,left:e,bottom:s,right:i}=this.getClientDimensions(),{innerHeight:n,innerWidth:r}=window;return e<r&&i>0&&t<n&&s>0}#O(){if(this.#u||!this.div)return;this.#u=new AbortController;let t=this._uiManager.combinedSignal(this.#u);this.div.addEventListener("focusin",this.focusin.bind(this),{signal:t}),this.div.addEventListener("focusout",this.focusout.bind(this),{signal:t})}rebuild(){this.#O()}rotate(t){}resize(){}serializeDeleted(){return{id:this.annotationElementId,deleted:!0,pageIndex:this.pageIndex,popupRef:this._initialData?.popupRef||""}}serialize(t=!1,e=null){z("An editor must be serializable")}static async deserialize(t,e,s){let i=new this.prototype.constructor({parent:e,id:e.getNextId(),uiManager:s});i.rotation=t.rotation,i.#t=t.accessibilityData;let[n,r]=i.pageDimensions,[a,l,h,c]=i.getRectInCurrentCoords(t.rect,r);return i.x=a/n,i.y=l/r,i.width=h/n,i.height=c/r,i}get hasBeenModified(){return!!this.annotationElementId&&(this.deleted||this.serialize()!==null)}remove(){if(this.#u?.abort(),this.#u=null,this.isEmpty()||this.commit(),this.parent?this.parent.remove(this):this._uiManager.removeEditor(this),this.#b&&(clearTimeout(this.#b),this.#b=null),this.#B(),this.removeEditToolbar(),this.#v){for(let t of this.#v.values())clearTimeout(t);this.#v=null}this.parent=null,this.#x?.destroy(),this.#x=null}get isResizable(){return!1}makeResizable(){this.isResizable&&(this.#C(),this.#o.classList.remove("hidden"),_e(this,this.div,["keydown"]))}get toolbarPosition(){return null}keydown(t){if(!this.isResizable||t.target!==this.div||t.key!=="Enter")return;this._uiManager.setSelected(this),this.#h={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height};let e=this.#o.children;if(!this.#e){this.#e=Array.from(e);let r=this.#F.bind(this),a=this.#$.bind(this),l=this._uiManager._signal;for(let h of this.#e){let c=h.getAttribute("data-resizer-name");h.setAttribute("role","spinbutton"),h.addEventListener("keydown",r,{signal:l}),h.addEventListener("blur",a,{signal:l}),h.addEventListener("focus",this.#G.bind(this,c),{signal:l}),h.setAttribute("data-l10n-id",o._l10nResizer[c])}}let s=this.#e[0],i=0;for(let r of e){if(r===s)break;i++}let 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.#o.append(this.#o.firstChild);else if(n>i)for(let a=0;a<n-i;a++)this.#o.firstChild.before(this.#o.lastChild);let r=0;for(let a of e){let l=this.#e[r++].getAttribute("data-resizer-name");a.setAttribute("data-l10n-id",o._l10nResizer[l])}}this.#I(0),this.#g=!0,this.#o.firstChild.focus({focusVisible:!0}),t.preventDefault(),t.stopImmediatePropagation()}#F(t){o._resizerKeyboardManager.exec(this,t)}#$(t){this.#g&&t.relatedTarget?.parentNode!==this.#o&&this.#B()}#G(t){this.#d=this.#g?t:""}#I(t){if(this.#e)for(let e of this.#e)e.tabIndex=t}_resizeWithKeyboard(t,e){this.#g&&this.#S(this.#d,{deltaX:t,deltaY:e,fromKeyboard:!0})}#B(){this.#g=!1,this.#I(-1),this.#N()}_stopResizingWithKeyboard(){this.#B(),this.div.focus()}select(){this.makeResizable(),this.div?.classList.add("selectedEditor"),this._editToolbar?(this._editToolbar?.show(),this.#s?.toggleAltTextBadge(!1)):this.addEditToolbar().then((()=>{this.div?.classList.contains("selectedEditor")&&this._editToolbar?.show()}))}unselect(){this.#o?.classList.add("hidden"),this.div?.classList.remove("selectedEditor"),this.div?.contains(document.activeElement)&&this._uiManager.currentLayer.div.focus({preventScroll:!0}),this._editToolbar?.hide(),this.#s?.toggleAltTextBadge(!0)}updateParams(t,e){}disableEditing(){}enableEditing(){}enterInEditMode(){}getImageForAltText(){return null}get contentDiv(){return this.div}get isEditing(){return this.#p}set isEditing(t){this.#p=t,this.parent&&(t?(this.parent.setSelected(this),this.parent.setActiveEditor(this)):this.parent.setActiveEditor(null))}setAspectRatio(t,e){this.#l=!0;let s=t/e,{style:i}=this.div;i.aspectRatio=s,i.height="auto"}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.#v||=new Map;let{action:s}=t,i=this.#v.get(s);i&&clearTimeout(i),i=setTimeout((()=>{this._reportTelemetry(t),this.#v.delete(s),this.#v.size===0&&(this.#v=null)}),o._telemetryTimeout),this.#v.set(s,i)}else 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.#i=!1}disable(){this.div&&(this.div.tabIndex=-1),this.#i=!0}renderAnnotationElement(t){let e=t.container.querySelector(".annotationContent");if(e){if(e.nodeName==="CANVAS"){let s=e;e=document.createElement("div"),e.classList.add("annotationContent",this.editorType),s.before(e)}}else e=document.createElement("div"),e.classList.add("annotationContent",this.editorType),t.container.prepend(e);return e}resetAnnotationElement(t){let{firstChild:e}=t.container;e?.nodeName==="DIV"&&e.classList.contains("annotationContent")&&e.remove()}},ks=class extends W{constructor(t){super(t),this.annotationElementId=t.annotationElementId,this.deleted=!0}serialize(){return this.serializeDeleted()}},Xi=3285377520,dt=4294901760,xt=65535,Ee=class{constructor(t){this.h1=t?4294967295&t:Xi,this.h2=t?4294967295&t:Xi}update(t){let e,s;if(typeof t=="string"){e=new Uint8Array(2*t.length),s=0;for(let g=0,m=t.length;g<m;g++){let b=t.charCodeAt(g);b<=255?e[s++]=b:(e[s++]=b>>>8,e[s++]=255&b)}}else{if(!ArrayBuffer.isView(t))throw new Error("Invalid data format, must be a string or TypedArray.");e=t.slice(),s=e.byteLength}let i=s>>2,n=s-4*i,r=new Uint32Array(e.buffer,0,i),a=0,l=0,h=this.h1,c=this.h2,d=3432918353,u=461845907,f=11601,p=13715;for(let g=0;g<i;g++)1&g?(a=r[g],a=a*d&dt|a*f&xt,a=a<<15|a>>>17,a=a*u&dt|a*p&xt,h^=a,h=h<<13|h>>>19,h=5*h+3864292196):(l=r[g],l=l*d&dt|l*f&xt,l=l<<15|l>>>17,l=l*u&dt|l*p&xt,c^=l,c=c<<13|c>>>19,c=5*c+3864292196);switch(a=0,n){case 3:a^=e[4*i+2]<<16;case 2:a^=e[4*i+1]<<8;case 1:a^=e[4*i],a=a*d&dt|a*f&xt,a=a<<15|a>>>17,a=a*u&dt|a*p&xt,1&i?h^=a:c^=a}this.h1=h,this.h2=c}hexdigest(){let t=this.h1,e=this.h2;return t^=e>>>1,t=3981806797*t&dt|36045*t&xt,e=4283543511*e&dt|(2950163797*(e<<16|t>>>16)&dt)>>>16,t^=e>>>1,t=444984403*t&dt|60499*t&xt,e=3301882366*e&dt|(3120437893*(e<<16|t>>>16)&dt)>>>16,t^=e>>>1,(t>>>0).toString(16).padStart(8,"0")+(e>>>0).toString(16).padStart(8,"0")}},Ms=Object.freeze({map:null,hash:"",transfer:void 0}),te=class{#t=!1;#e=null;#s=new Map;constructor(){this.onSetModified=null,this.onResetModified=null,this.onAnnotationEditor=null}getValue(t,e){let s=this.#s.get(t);return s===void 0?e:Object.assign(e,s)}getRawValue(t){return this.#s.get(t)}remove(t){if(this.#s.delete(t),this.#s.size===0&&this.resetModified(),typeof this.onAnnotationEditor=="function"){for(let e of this.#s.values())if(e instanceof W)return;this.onAnnotationEditor(null)}}setValue(t,e){let s=this.#s.get(t),i=!1;if(s!==void 0)for(let[n,r]of Object.entries(e))s[n]!==r&&(i=!0,s[n]=r);else i=!0,this.#s.set(t,e);i&&this.#i(),e instanceof W&&typeof this.onAnnotationEditor=="function"&&this.onAnnotationEditor(e.constructor._type)}has(t){return this.#s.has(t)}getAll(){return this.#s.size>0?Ni(this.#s):null}setAll(t){for(let[e,s]of Object.entries(t))this.setValue(e,s)}get size(){return this.#s.size}#i(){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 Ce(this)}get serializable(){if(this.#s.size===0)return Ms;let t=new Map,e=new Ee,s=[],i=Object.create(null),n=!1;for(let[r,a]of this.#s){let l=a instanceof W?a.serialize(!1,i):a;l&&(t.set(r,l),e.update(`${r}:${JSON.stringify(l)}`),n||=!!l.bitmap)}if(n)for(let r of t.values())r.bitmap&&s.push(r.bitmap);return t.size>0?{map:t,hash:e.hexdigest(),transfer:s}:Ms}get editorStats(){let t=null,e=new Map;for(let s of this.#s.values()){if(!(s instanceof W))continue;let i=s.telemetryFinalData;if(!i)continue;let{type:n}=i;e.has(n)||e.set(n,Object.getPrototypeOf(s).constructor),t||=Object.create(null);let r=t[n]||=new Map;for(let[a,l]of Object.entries(i)){if(a==="type")continue;let h=r.get(a);h||(h=new Map,r.set(a,h));let c=h.get(l)??0;h.set(l,c+1)}}for(let[s,i]of e)t[s]=i.computeTelemetryFinalData(t[s]);return t}resetModifiedIds(){this.#e=null}get modifiedIds(){if(this.#e)return this.#e;let t=[];for(let e of this.#s.values())e instanceof W&&e.annotationElementId&&e.serialize()&&t.push(e.annotationElementId);return this.#e={ids:new Set(t),hash:t.join(",")}}},Ce=class extends te{#t;constructor(t){super();let{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(){z("Should not call PrintAnnotationStorage.print")}get serializable(){return this.#t}get modifiedIds(){return N(this,"modifiedIds",{ids:new Set,hash:""})}},Ts=class{#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));let e=this.styleElement.sheet;e.insertRule(t,e.cssRules.length)}clear(){for(let 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,_inspectFont:e}){if(t&&!this.#t.has(t.loadedName))if(Q(!this.disableFontFace,"loadSystemFont shouldn't be called when `disableFontFace` is set."),this.isFontLoadingAPISupported){let{loadedName:s,src:i,style:n}=t,r=new FontFace(s,i,n);this.addNativeFontFace(r);try{await r.load(),this.#t.add(s),e?.(t)}catch{F(`Cannot load system font: ${t.baseFontName}, installing it could help to improve PDF rendering.`),this.removeNativeFontFace(r)}}else z("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){let s=t.createNativeFontFace();if(s){this.addNativeFontFace(s);try{await s.loaded}catch(i){throw F(`Failed to load font '${s.family}': '${i}'.`),t.disableFontFace=!0,i}}return}let e=t.createFontFaceRule();if(e){if(this.insertRule(e),this.isSyncFontLoadingSupported)return;await new Promise((s=>{let i=this._queueLoadingCallback(s);this._prepareFontLoadEvent(t,i)}))}}get isFontLoadingAPISupported(){return N(this,"isFontLoadingAPISupported",!!this._document?.fonts)}get isSyncFontLoadingSupported(){let t=!1;return(et||typeof navigator<"u"&&typeof navigator?.userAgent=="string"&&/Mozilla\/5.0.*?rv:\d+.*? Gecko/.test(navigator.userAgent))&&(t=!0),N(this,"isSyncFontLoadingSupported",t)}_queueLoadingCallback(t){let{loadingRequests:e}=this,s={done:!1,complete:function(){for(Q(!s.done,"completeRequest() cannot be called twice."),s.done=!0;e.length>0&&e[0].done;){let n=e.shift();setTimeout(n.callback,0)}},callback:t};return e.push(s),s}get _loadTestFont(){return N(this,"_loadTestFont",atob("T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQAABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwAAAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbmFtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAAAADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6AABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAAMQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAAAAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAAAAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQAAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMAAQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAAEAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgcA/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQAAAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAgABAAAAAAAAAAAD6AAAAAAAAA=="))}_prepareFontLoadEvent(t,e){function s(m,b){return m.charCodeAt(b)<<24|m.charCodeAt(b+1)<<16|m.charCodeAt(b+2)<<8|255&m.charCodeAt(b+3)}function i(m,b,y,w){return m.substring(0,b)+w+m.substring(b+y)}let n,r,a=this._document.createElement("canvas");a.width=1,a.height=1;let l=a.getContext("2d"),h=0,c=`lt${Date.now()}${this.loadTestFontId++}`,d=this._loadTestFont;d=i(d,976,c.length,c);let u=1482184792,f=s(d,16);for(n=0,r=c.length-3;n<r;n+=4)f=f-u+s(c,n)|0;n<c.length&&(f=f-u+s(c+"XXX",n)|0),d=i(d,16,4,(function(b){return String.fromCharCode(b>>24&255,b>>16&255,b>>8&255,255&b)})(f));let p=`@font-face {font-family:"${c}";src:${`url(data:font/opentype;base64,${btoa(d)});`}}`;this.insertRule(p);let g=this._document.createElement("div");g.style.visibility="hidden",g.style.width=g.style.height="10px",g.style.position="absolute",g.style.top=g.style.left="0px";for(let m of[t.loadedName,c]){let b=this._document.createElement("span");b.textContent="Hi",b.style.fontFamily=m,g.append(b)}this._document.body.append(g),(function m(b,y){if(++h>30){F("Load test font never loaded."),y();return}l.font="30px "+b,l.fillText(".",0,20),l.getImageData(0,0,1,1).data[3]>0?y():setTimeout(m.bind(null,b,y))})(c,(()=>{g.remove(),e.complete()}))}},Ps=class{constructor(t,{disableFontFace:e=!1,fontExtraProperties:s=!1,inspectFont:i=null}){this.compiledGlyphs=Object.create(null);for(let n in t)this[n]=t[n];this.disableFontFace=e===!0,this.fontExtraProperties=s===!0,this._inspectFont=i}createNativeFontFace(){if(!this.data||this.disableFontFace)return null;let t;if(this.cssFontInfo){let e={weight:this.cssFontInfo.fontWeight};this.cssFontInfo.italicAngle&&(e.style=`oblique ${this.cssFontInfo.italicAngle}deg`),t=new FontFace(this.cssFontInfo.fontFamily,this.data,e)}else t=new FontFace(this.loadedName,this.data,{});return this._inspectFont?.(this),t}createFontFaceRule(){if(!this.data||this.disableFontFace)return null;let t=`url(data:${this.mimetype};base64,${(function(i){return Uint8Array.prototype.toBase64?i.toBase64():btoa(un(i))})(this.data)});`,e;if(this.cssFontInfo){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}}`}else e=`@font-face {font-family:"${this.loadedName}";src:${t}}`;return this._inspectFont?.(this,t),e}getPathGenerator(t,e){if(this.compiledGlyphs[e]!==void 0)return this.compiledGlyphs[e];let s=this.loadedName+"_path_"+e,i;try{i=t.get(s)}catch(r){F(`getPathGenerator - ignoring character: "${r}".`)}let n=new Path2D(i||"");return this.fontExtraProperties||t.delete(s),this.compiledGlyphs[e]=n}},Yi=1,Ki=2,Qi=1,ps=2,Ji=3,Zi=4,tn=5,en=6,ue=7,gs=8;function sn(){}function rt(o){if(o instanceof gt||o instanceof Kt||o instanceof It||o instanceof we||o instanceof jt||o instanceof Xt)return o;switch(o instanceof Error||typeof o=="object"&&o!==null||z('wrapReason: Expected "reason" to be a (possibly cloned) Error.'),o.name){case"AbortException":return new gt(o.message);case"InvalidPDFException":return new Kt(o.message);case"MissingPDFException":return new It(o.message);case"PasswordException":return new we(o.message,o.code);case"UnexpectedResponseException":return new jt(o.message,o.status);case"UnknownErrorException":return new Xt(o.message,o.details)}return new Xt(o.message,o.toString())}var Tt=class{#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.#i(t);return}if(t.callback){let s=t.callbackId,i=this.callbackCapabilities[s];if(!i)throw new Error(`Cannot resolve callback ${s}`);if(delete this.callbackCapabilities[s],t.callback===Yi)i.resolve(t.data);else{if(t.callback!==Ki)throw new Error("Unexpected callback case");i.reject(rt(t.reason))}return}let e=this.actionHandler[t.action];if(!e)throw new Error(`Unknown action from worker: ${t.action}`);if(t.callbackId){let s=this.sourceName,i=t.sourceName,n=this.comObj;Promise.try(e,t.data).then((function(r){n.postMessage({sourceName:s,targetName:i,callback:Yi,callbackId:t.callbackId,data:r})}),(function(r){n.postMessage({sourceName:s,targetName:i,callback:Ki,callbackId:t.callbackId,reason:rt(r)})}))}else t.streamId?this.#s(t):e(t.data)}on(t,e){let 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){let 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){let n=this.streamId++,r=this.sourceName,a=this.targetName,l=this.comObj;return new ReadableStream({start:h=>{let c=Promise.withResolvers();return this.streamControllers[n]={controller:h,startCall:c,pullCall:null,cancelCall:null,isClosed:!1},l.postMessage({sourceName:r,targetName:a,action:t,streamId:n,data:e,desiredSize:h.desiredSize},i),c.promise},pull:h=>{let c=Promise.withResolvers();return this.streamControllers[n].pullCall=c,l.postMessage({sourceName:r,targetName:a,stream:en,streamId:n,desiredSize:h.desiredSize}),c.promise},cancel:h=>{Q(h instanceof Error,"cancel must have a valid reason");let c=Promise.withResolvers();return this.streamControllers[n].cancelCall=c,this.streamControllers[n].isClosed=!0,l.postMessage({sourceName:r,targetName:a,stream:Qi,streamId:n,reason:rt(h)}),c.promise}},s)}#s(t){let e=t.streamId,s=this.sourceName,i=t.sourceName,n=this.comObj,r=this,a=this.actionHandler[t.action],l={enqueue(h,c=1,d){if(this.isCancelled)return;let u=this.desiredSize;this.desiredSize-=c,u>0&&this.desiredSize<=0&&(this.sinkCapability=Promise.withResolvers(),this.ready=this.sinkCapability.promise),n.postMessage({sourceName:s,targetName:i,stream:Zi,streamId:e,chunk:h},d)},close(){this.isCancelled||(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:Ji,streamId:e}),delete r.streamSinks[e])},error(h){Q(h instanceof Error,"error must have a valid reason"),this.isCancelled||(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:tn,streamId:e,reason:rt(h)}))},sinkCapability:Promise.withResolvers(),onPull:null,onCancel:null,isCancelled:!1,desiredSize:t.desiredSize,ready:null};l.sinkCapability.resolve(),l.ready=l.sinkCapability.promise,this.streamSinks[e]=l,Promise.try(a,t.data,l).then((function(){n.postMessage({sourceName:s,targetName:i,stream:gs,streamId:e,success:!0})}),(function(h){n.postMessage({sourceName:s,targetName:i,stream:gs,streamId:e,reason:rt(h)})}))}#i(t){let e=t.streamId,s=this.sourceName,i=t.sourceName,n=this.comObj,r=this.streamControllers[e],a=this.streamSinks[e];switch(t.stream){case gs:t.success?r.startCall.resolve():r.startCall.reject(rt(t.reason));break;case ue:t.success?r.pullCall.resolve():r.pullCall.reject(rt(t.reason));break;case en:if(!a){n.postMessage({sourceName:s,targetName:i,stream:ue,streamId:e,success:!0});break}a.desiredSize<=0&&t.desiredSize>0&&a.sinkCapability.resolve(),a.desiredSize=t.desiredSize,Promise.try(a.onPull||sn).then((function(){n.postMessage({sourceName:s,targetName:i,stream:ue,streamId:e,success:!0})}),(function(h){n.postMessage({sourceName:s,targetName:i,stream:ue,streamId:e,reason:rt(h)})}));break;case Zi:if(Q(r,"enqueue should have stream controller"),r.isClosed)break;r.controller.enqueue(t.chunk);break;case Ji:if(Q(r,"close should have stream controller"),r.isClosed)break;r.isClosed=!0,r.controller.close(),this.#r(r,e);break;case tn:Q(r,"error should have stream controller"),r.controller.error(rt(t.reason)),this.#r(r,e);break;case ps:t.success?r.cancelCall.resolve():r.cancelCall.reject(rt(t.reason)),this.#r(r,e);break;case Qi:if(!a)break;let l=rt(t.reason);Promise.try(a.onCancel||sn,l).then((function(){n.postMessage({sourceName:s,targetName:i,stream:ps,streamId:e,success:!0})}),(function(h){n.postMessage({sourceName:s,targetName:i,stream:ps,streamId:e,reason:rt(h)})})),a.sinkCapability.reject(l),a.isCancelled=!0,delete this.streamSinks[e];break;default:throw new Error("Unexpected stream case")}}async#r(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}},ke=class{#t=!1;constructor({enableHWA:t=!1}){this.#t=t}create(t,e){if(t<=0||e<=0)throw new Error("Invalid canvas size");let 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){z("Abstract method `_createCanvas` called.")}},Me=class{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.");let 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){z("Abstract method `_fetch` called.")}},Te=class extends Me{async _fetch(t){let e=await es(t,this.isCompressed?"arraybuffer":"text");return e instanceof ArrayBuffer?new Uint8Array(e):ts(e)}},Pe=class{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){}},Re=class{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.");let e=`${this.baseUrl}${t}`;return this._fetch(e).catch((s=>{throw new Error(`Unable to load font data at: ${e}`)}))}async _fetch(t){z("Abstract method `_fetch` called.")}},Ie=class extends Re{async _fetch(t){let e=await es(t,"arraybuffer");return new Uint8Array(e)}};et&&F("Please use the `legacy` build in Node.js environments.");async function fn(o){let t=process.getBuiltinModule("fs"),e=await t.promises.readFile(o);return new Uint8Array(e)}var Pt="Fill",Le="Stroke",Yt="Shading";function Rs(o,t){if(!t)return;let e=t[2]-t[0],s=t[3]-t[1],i=new Path2D;i.rect(t[0],t[1],e,s),o.clip(i)}var ee=class{getPattern(){z("Abstract method `getPattern` called.")}},Is=class extends ee{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(let s of this._colorStops)e.addColorStop(s[0],s[1]);return e}getPattern(t,e,s,i){let n;if(i===Le||i===Pt){let r=e.current.getClippedPathBoundingBox(i,U(t))||[0,0,0,0],a=Math.ceil(r[2]-r[0])||1,l=Math.ceil(r[3]-r[1])||1,h=e.cachedCanvases.getCanvas("pattern",a,l),c=h.context;c.clearRect(0,0,c.canvas.width,c.canvas.height),c.beginPath(),c.rect(0,0,c.canvas.width,c.canvas.height),c.translate(-r[0],-r[1]),s=k.transform(s,[1,0,0,1,r[0],r[1]]),c.transform(...e.baseTransform),this.matrix&&c.transform(...this.matrix),Rs(c,this._bbox),c.fillStyle=this._createGradient(c),c.fill(),n=t.createPattern(h.canvas,"no-repeat");let d=new DOMMatrix(s);n.setTransform(d)}else Rs(t,this._bbox),n=this._createGradient(t);return n}};function ms(o,t,e,s,i,n,r,a){let l=t.coords,h=t.colors,c=o.data,d=4*o.width,u;l[e+1]>l[s+1]&&(u=e,e=s,s=u,u=n,n=r,r=u),l[s+1]>l[i+1]&&(u=s,s=i,i=u,u=r,r=a,a=u),l[e+1]>l[s+1]&&(u=e,e=s,s=u,u=n,n=r,r=u);let f=(l[e]+t.offsetX)*t.scaleX,p=(l[e+1]+t.offsetY)*t.scaleY,g=(l[s]+t.offsetX)*t.scaleX,m=(l[s+1]+t.offsetY)*t.scaleY,b=(l[i]+t.offsetX)*t.scaleX,y=(l[i+1]+t.offsetY)*t.scaleY;if(p>=y)return;let w=h[n],A=h[n+1],_=h[n+2],x=h[r],v=h[r+1],C=h[r+2],M=h[a],I=h[a+1],P=h[a+2],O=Math.round(p),G=Math.round(y),$,H,q,R,L,ct,yt,wt;for(let it=O;it<=G;it++){if(it<m){let Y=it<p?0:(p-it)/(p-m);$=f-(f-g)*Y,H=w-(w-x)*Y,q=A-(A-v)*Y,R=_-(_-C)*Y}else{let Y;Y=it>y?1:m===y?0:(m-it)/(m-y),$=g-(g-b)*Y,H=x-(x-M)*Y,q=v-(v-I)*Y,R=C-(C-P)*Y}let J;J=it<p?0:it>y?1:(p-it)/(p-y),L=f-(f-b)*J,ct=w-(w-M)*J,yt=A-(A-I)*J,wt=_-(_-P)*J;let _t=Math.round(Math.min($,L)),lt=Math.round(Math.max($,L)),V=d*it+4*_t;for(let Y=_t;Y<=lt;Y++)J=($-Y)/($-L),J<0?J=0:J>1&&(J=1),c[V++]=H-(H-ct)*J|0,c[V++]=q-(q-yt)*J|0,c[V++]=R-(R-wt)*J|0,c[V++]=255}}function Sr(o,t,e){let s=t.coords,i=t.colors,n,r;switch(t.type){case"lattice":let a=t.verticesPerRow,l=Math.floor(s.length/a)-1,h=a-1;for(n=0;n<l;n++){let c=n*a;for(let d=0;d<h;d++,c++)ms(o,e,s[c],s[c+1],s[c+a],i[c],i[c+1],i[c+a]),ms(o,e,s[c+a+1],s[c+1],s[c+a],i[c+a+1],i[c+1],i[c+a])}break;case"triangles":for(n=0,r=s.length;n<r;n+=3)ms(o,e,s[n],s[n+1],s[n+2],i[n],i[n+1],i[n+2]);break;default:throw new Error("illegal figure")}}var Ls=class extends ee{constructor(t){super(),this._coords=t[2],this._colors=t[3],this._figures=t[4],this._bounds=t[5],this._bbox=t[7],this._background=t[8],this.matrix=null}_createMeshCanvas(t,e,s){let i=Math.floor(this._bounds[0]),n=Math.floor(this._bounds[1]),r=Math.ceil(this._bounds[2])-i,a=Math.ceil(this._bounds[3])-n,l=Math.min(Math.ceil(Math.abs(r*t[0]*1.1)),3e3),h=Math.min(Math.ceil(Math.abs(a*t[1]*1.1)),3e3),c=r/l,d=a/h,u={coords:this._coords,colors:this._colors,offsetX:-i,offsetY:-n,scaleX:1/c,scaleY:1/d},f=l+4,p=h+4,g=s.getCanvas("mesh",f,p),m=g.context,b=m.createImageData(l,h);if(e){let y=b.data;for(let w=0,A=y.length;w<A;w+=4)y[w]=e[0],y[w+1]=e[1],y[w+2]=e[2],y[w+3]=255}for(let y of this._figures)Sr(b,y,u);return m.putImageData(b,2,2),{canvas:g.canvas,offsetX:i-2*c,offsetY:n-2*d,scaleX:c,scaleY:d}}getPattern(t,e,s,i){Rs(t,this._bbox);let n;if(i===Yt)n=k.singularValueDecompose2dScale(U(t));else if(n=k.singularValueDecompose2dScale(e.baseTransform),this.matrix){let a=k.singularValueDecompose2dScale(this.matrix);n=[n[0]*a[0],n[1]*a[1]]}let r=this._createMeshCanvas(n,i===Yt?null:this._background,e.cachedCanvases);return i!==Yt&&(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")}},Ds=class extends ee{getPattern(){return"hotpink"}},Er=1,Cr=2,Fs=class o{static MAX_PATTERN_SIZE=3e3;constructor(t,e,s,i,n){this.operatorList=t[2],this.matrix=t[3],this.bbox=t[4],this.xstep=t[5],this.ystep=t[6],this.paintType=t[7],this.tilingType=t[8],this.color=e,this.ctx=s,this.canvasGraphicsFactory=i,this.baseTransform=n}createPatternCanvas(t){let{bbox:e,operatorList:s,paintType:i,tilingType:n,color:r,canvasGraphicsFactory:a}=this,{xstep:l,ystep:h}=this;l=Math.abs(l),h=Math.abs(h),Ze("TilingType: "+n);let c=e[0],d=e[1],u=e[2],f=e[3],p=u-c,g=f-d,m=k.singularValueDecompose2dScale(this.matrix),b=k.singularValueDecompose2dScale(this.baseTransform),y=m[0]*b[0],w=m[1]*b[1],A=p,_=g,x=!1,v=!1,C=Math.ceil(l*y),M=Math.ceil(h*w);C>=Math.ceil(p*y)?A=l:x=!0,M>=Math.ceil(g*w)?_=h:v=!0;let I=this.getSizeAndScale(A,this.ctx.canvas.width,y),P=this.getSizeAndScale(_,this.ctx.canvas.height,w),O=t.cachedCanvases.getCanvas("pattern",I.size,P.size),G=O.context,$=a.createCanvasGraphics(G);if($.groupLevel=t.groupLevel,this.setFillAndStrokeStyleToContext($,i,r),G.translate(-I.scale*c,-P.scale*d),$.transform(I.scale,0,0,P.scale,0,0),G.save(),this.clipBbox($,c,d,u,f),$.baseTransform=U($.ctx),$.executeOperatorList(s),$.endDrawing(),G.restore(),x||v){let H=O.canvas;x&&(A=l),v&&(_=h);let q=this.getSizeAndScale(A,this.ctx.canvas.width,y),R=this.getSizeAndScale(_,this.ctx.canvas.height,w),L=q.size,ct=R.size,yt=t.cachedCanvases.getCanvas("pattern-workaround",L,ct),wt=yt.context,it=x?Math.floor(p/l):0,J=v?Math.floor(g/h):0;for(let _t=0;_t<=it;_t++)for(let lt=0;lt<=J;lt++)wt.drawImage(H,L*_t,ct*lt,L,ct,0,0,L,ct);return{canvas:yt.canvas,scaleX:q.scale,scaleY:R.scale,offsetX:c,offsetY:d}}return{canvas:O.canvas,scaleX:I.scale,scaleY:P.scale,offsetX:c,offsetY:d}}getSizeAndScale(t,e,s){let i=Math.max(o.MAX_PATTERN_SIZE,e),n=Math.ceil(t*s);return n>=i?n=i:s=n/t,{scale:s,size:n}}clipBbox(t,e,s,i,n){let r=i-e,a=n-s;t.ctx.rect(e,s,r,a),t.current.updateRectMinMax(U(t.ctx),[e,s,i,n]),t.clip(),t.endPath()}setFillAndStrokeStyleToContext(t,e,s){let i=t.ctx,n=t.current;switch(e){case Er:let r=this.ctx;i.fillStyle=r.fillStyle,i.strokeStyle=r.strokeStyle,n.fillColor=r.fillStyle,n.strokeColor=r.strokeStyle;break;case Cr:let a=k.makeHexColor(s[0],s[1],s[2]);i.fillStyle=a,i.strokeStyle=a,n.fillColor=a,n.strokeColor=a;break;default:throw new ws(`Unsupported paint type: ${e}`)}}getPattern(t,e,s,i){let n=s;i!==Yt&&(n=k.transform(n,e.baseTransform),this.matrix&&(n=k.transform(n,this.matrix)));let r=this.createPatternCanvas(e),a=new DOMMatrix(n);a=a.translate(r.offsetX,r.offsetY),a=a.scale(1/r.scaleX,1/r.scaleY);let l=t.createPattern(r.canvas,"repeat");return l.setTransform(a),l}};function kr({src:o,srcPos:t=0,dest:e,width:s,height:i,nonBlackColor:n=4294967295,inverseDecode:r=!1}){let a=Z.isLittleEndian?4278190080:255,[l,h]=r?[n,a]:[a,n],c=s>>3,d=7&s,u=o.length;e=new Uint32Array(e.buffer);let f=0;for(let p=0;p<i;p++){for(let m=t+c;t<m;t++){let b=t<u?o[t]:255;e[f++]=128&b?h:l,e[f++]=64&b?h:l,e[f++]=32&b?h:l,e[f++]=16&b?h:l,e[f++]=8&b?h:l,e[f++]=4&b?h:l,e[f++]=2&b?h:l,e[f++]=1&b?h:l}if(d===0)continue;let g=t<u?o[t++]:255;for(let m=0;m<d;m++)e[f++]=g&1<<7-m?h:l}return{srcPos:t,destPos:f}}var at=16,Ns=class{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(let t in this.cache){let e=this.cache[t];this.canvasFactory.destroy(e),delete this.cache[t]}}};function fe(o,t,e,s,i,n,r,a,l,h){let[c,d,u,f,p,g]=U(o);if(d===0&&u===0){let m=r*c+p,b=Math.round(m),y=a*f+g,w=Math.round(y),A=(r+l)*c+p,_=Math.abs(Math.round(A)-b)||1,x=(a+h)*f+g,v=Math.abs(Math.round(x)-w)||1;return o.setTransform(Math.sign(c),0,0,Math.sign(f),b,w),o.drawImage(t,e,s,i,n,0,0,_,v),o.setTransform(c,d,u,f,p,g),[_,v]}if(c===0&&f===0){let m=a*u+p,b=Math.round(m),y=r*d+g,w=Math.round(y),A=(a+h)*u+p,_=Math.abs(Math.round(A)-b)||1,x=(r+l)*d+g,v=Math.abs(Math.round(x)-w)||1;return o.setTransform(0,Math.sign(d),Math.sign(u),0,b,w),o.drawImage(t,e,s,i,n,0,0,v,_),o.setTransform(c,d,u,f,p,g),[v,_]}return o.drawImage(t,e,s,i,n,r,a,l,h),[Math.hypot(c,d)*l,Math.hypot(u,f)*h]}var De=class{constructor(t,e){this.alphaIsShape=!1,this.fontSize=0,this.fontSizeScale=1,this.textMatrix=cn,this.textMatrixScale=1,this.fontMatrix=ys,this.leading=0,this.x=0,this.y=0,this.lineX=0,this.lineY=0,this.charSpacing=0,this.wordSpacing=0,this.textHScale=1,this.textRenderingMode=me,this.textRise=0,this.fillColor="#000000",this.strokeColor="#000000",this.patternFill=!1,this.patternStroke=!1,this.fillAlpha=1,this.strokeAlpha=1,this.lineWidth=1,this.activeSMask=null,this.transferMaps="none",this.startNewPathAndClipBox([0,0,t,e])}clone(){let t=Object.create(this);return t.clipBox=this.clipBox.slice(),t}setCurrentPoint(t,e){this.x=t,this.y=e}updatePathMinMax(t,e,s){[e,s]=k.applyTransform([e,s],t),this.minX=Math.min(this.minX,e),this.minY=Math.min(this.minY,s),this.maxX=Math.max(this.maxX,e),this.maxY=Math.max(this.maxY,s)}updateRectMinMax(t,e){let s=k.applyTransform(e,t),i=k.applyTransform(e.slice(2),t),n=k.applyTransform([e[0],e[3]],t),r=k.applyTransform([e[2],e[1]],t);this.minX=Math.min(this.minX,s[0],i[0],n[0],r[0]),this.minY=Math.min(this.minY,s[1],i[1],n[1],r[1]),this.maxX=Math.max(this.maxX,s[0],i[0],n[0],r[0]),this.maxY=Math.max(this.maxY,s[1],i[1],n[1],r[1])}updateScalingPathMinMax(t,e){k.scaleMinMax(t,e),this.minX=Math.min(this.minX,e[0]),this.minY=Math.min(this.minY,e[1]),this.maxX=Math.max(this.maxX,e[2]),this.maxY=Math.max(this.maxY,e[3])}updateCurvePathMinMax(t,e,s,i,n,r,a,l,h,c){let d=k.bezierBoundingBox(e,s,i,n,r,a,l,h,c);c||this.updateRectMinMax(t,d)}getPathBoundingBox(t=Pt,e=null){let s=[this.minX,this.minY,this.maxX,this.maxY];if(t===Le){e||z("Stroke bounding box must include transform.");let i=k.singularValueDecompose2dScale(e),n=i[0]*this.lineWidth/2,r=i[1]*this.lineWidth/2;s[0]-=n,s[1]-=r,s[2]+=n,s[3]+=r}return s}updateClipFromPath(){let t=k.intersect(this.clipBox,this.getPathBoundingBox());this.startNewPathAndClipBox(t||[0,0,0,0])}isEmptyClip(){return this.minX===1/0}startNewPathAndClipBox(t){this.clipBox=t,this.minX=1/0,this.minY=1/0,this.maxX=0,this.maxY=0}getClippedPathBoundingBox(t=Pt,e=null){return k.intersect(this.clipBox,this.getPathBoundingBox(t,e))}};function nn(o,t){if(t instanceof ImageData){o.putImageData(t,0,0);return}let e=t.height,s=t.width,i=e%at,n=(e-i)/at,r=i===0?n:n+1,a=o.createImageData(s,at),l,h=0,c=t.data,d=a.data,u,f,p,g;if(t.kind===be.GRAYSCALE_1BPP){let m=c.byteLength,b=new Uint32Array(d.buffer,0,d.byteLength>>2),y=b.length,w=s+7>>3,A=4294967295,_=Z.isLittleEndian?4278190080:255;for(u=0;u<r;u++){for(p=u<n?at:i,l=0,f=0;f<p;f++){let x=m-h,v=0,C=x>w?s:8*x-7,M=-8&C,I=0,P=0;for(;v<M;v+=8)P=c[h++],b[l++]=128&P?A:_,b[l++]=64&P?A:_,b[l++]=32&P?A:_,b[l++]=16&P?A:_,b[l++]=8&P?A:_,b[l++]=4&P?A:_,b[l++]=2&P?A:_,b[l++]=1&P?A:_;for(;v<C;v++)I===0&&(P=c[h++],I=128),b[l++]=P&I?A:_,I>>=1}for(;l<y;)b[l++]=0;o.putImageData(a,0,u*at)}}else if(t.kind===be.RGBA_32BPP){for(f=0,g=s*at*4,u=0;u<n;u++)d.set(c.subarray(h,h+g)),h+=g,o.putImageData(a,0,f),f+=at;u<r&&(g=s*i*4,d.set(c.subarray(h,h+g)),o.putImageData(a,0,f))}else{if(t.kind!==be.RGB_24BPP)throw new Error(`bad image kind: ${t.kind}`);for(p=at,g=s*p,u=0;u<r;u++){for(u>=n&&(p=i,g=s*p),l=0,f=g;f--;)d[l++]=c[h++],d[l++]=c[h++],d[l++]=c[h++],d[l++]=255;o.putImageData(a,0,u*at)}}}function rn(o,t){if(t.bitmap){o.drawImage(t.bitmap,0,0);return}let e=t.height,s=t.width,i=e%at,n=(e-i)/at,r=i===0?n:n+1,a=o.createImageData(s,at),l=0,h=t.data,c=a.data;for(let d=0;d<r;d++){let u=d<n?at:i;({srcPos:l}=kr({src:h,srcPos:l,dest:c,width:s,height:u,nonBlackColor:0})),o.putImageData(a,0,d*at)}}function Gt(o,t){let e=["strokeStyle","fillStyle","fillRule","globalAlpha","lineWidth","lineCap","lineJoin","miterLimit","globalCompositeOperation","font","filter"];for(let s of e)o[s]!==void 0&&(t[s]=o[s]);o.setLineDash!==void 0&&(t.setLineDash(o.getLineDash()),t.lineDashOffset=o.lineDashOffset)}function pe(o){if(o.strokeStyle=o.fillStyle="#000000",o.fillRule="nonzero",o.globalAlpha=1,o.lineWidth=1,o.lineCap="butt",o.lineJoin="miter",o.miterLimit=10,o.globalCompositeOperation="source-over",o.font="10px sans-serif",o.setLineDash!==void 0&&(o.setLineDash([]),o.lineDashOffset=0),!et){let{filter:t}=o;t!=="none"&&t!==""&&(o.filter="none")}}function an(o,t){if(t)return!0;let e=k.singularValueDecompose2dScale(o);e[0]=Math.fround(e[0]),e[1]=Math.fround(e[1]);let s=Math.fround((globalThis.devicePixelRatio||1)*Ct.PDF_TO_CSS_UNITS);return e[0]<=s&&e[1]<=s}var Mr=["butt","round","square"],Tr=["miter","round","bevel"],Pr={},on={},Bt=class o{constructor(t,e,s,i,n,{optionalContentConfig:r,markedContentStack:a=null},l,h){this.ctx=t,this.current=new De(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.processingType3=null,this.baseTransform=null,this.baseTransformStack=[],this.groupLevel=0,this.smaskStack=[],this.smaskCounter=0,this.tempSMask=null,this.suspendedCtx=null,this.contentVisible=!0,this.markedContentStack=a||[],this.optionalContentConfig=r,this.cachedCanvases=new Ns(this.canvasFactory),this.cachedPatterns=new Map,this.annotationCanvasMap=l,this.viewportScale=1,this.outputScaleX=1,this.outputScaleY=1,this.pageColors=h,this._cachedScaleForStroking=[-1,0],this._cachedGetSinglePixelWidth=null,this._cachedBitmapsMap=new Map}getObject(t,e=null){return typeof t=="string"?t.startsWith("g_")?this.commonObjs.get(t):this.objs.get(t):e}beginDrawing({transform:t,viewport:e,transparency:s=!1,background:i=null}){let 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){let l=this.cachedCanvases.getCanvas("transparent",n,r);this.compositeCtx=this.ctx,this.transparentCanvas=l.canvas,this.ctx=l.context,this.ctx.save(),this.ctx.transform(...U(this.compositeCtx))}this.ctx.save(),pe(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=U(this.ctx)}executeOperatorList(t,e,s,i){let n=t.argsArray,r=t.fnArray,a=e||0,l=n.length;if(l===a)return a;let h=l-a>10&&typeof s=="function",c=h?Date.now()+15:0,d=0,u=this.commonObjs,f=this.objs,p;for(;;){if(i!==void 0&&a===i.nextBreakPoint)return i.breakIt(a,s),a;if(p=r[a],p!==ut.dependency)this[p].apply(this,n[a]);else for(let g of n[a]){let m=g.startsWith("g_")?u:f;if(!m.has(g))return m.get(g,s),a}if(a++,a===l)return a;if(h&&++d>10){if(Date.now()>c)return s(),a;d=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(let t of this._cachedBitmapsMap.values()){for(let 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){let t=this.filterFactory.addHCMFilter(this.pageColors.foreground,this.pageColors.background);if(t!=="none"){let e=this.ctx.filter;this.ctx.filter=t,this.ctx.drawImage(this.ctx.canvas,0,0),this.ctx.filter=e}}}_scaleImage(t,e){let s=t.width??t.displayWidth,i=t.height??t.displayHeight,n,r,a=Math.max(Math.hypot(e[0],e[1]),1),l=Math.max(Math.hypot(e[2],e[3]),1),h=s,c=i,d="prescale1";for(;a>2&&h>1||l>2&&c>1;){let u=h,f=c;a>2&&h>1&&(u=h>=16384?Math.floor(h/2)-1||1:Math.ceil(h/2),a/=h/u),l>2&&c>1&&(f=c>=16384?Math.floor(c/2)-1||1:Math.ceil(c)/2,l/=c/f),n=this.cachedCanvases.getCanvas(d,u,f),r=n.context,r.clearRect(0,0,u,f),r.drawImage(t,0,0,h,c,0,0,u,f),t=n.canvas,h=u,c=f,d=d==="prescale1"?"prescale2":"prescale1"}return{img:t,paintWidth:h,paintHeight:c}}_createMaskCanvas(t){let e=this.ctx,{width:s,height:i}=t,n=this.current.fillColor,r=this.current.patternFill,a=U(e),l,h,c,d;if((t.bitmap||t.data)&&t.count>1){let C=t.bitmap||t.data.buffer;h=JSON.stringify(r?a:[a.slice(0,4),n]),l=this._cachedBitmapsMap.get(C),l||(l=new Map,this._cachedBitmapsMap.set(C,l));let M=l.get(h);if(M&&!r)return{canvas:M,offsetX:Math.round(Math.min(a[0],a[2])+a[4]),offsetY:Math.round(Math.min(a[1],a[3])+a[5])};c=M}c||(d=this.cachedCanvases.getCanvas("maskCanvas",s,i),rn(d.context,t));let u=k.transform(a,[1/s,0,0,-1/i,0,0]);u=k.transform(u,[1,0,0,1,0,-i]);let[f,p,g,m]=k.getAxialAlignedBoundingBox([0,0,s,i],u),b=Math.round(g-f)||1,y=Math.round(m-p)||1,w=this.cachedCanvases.getCanvas("fillCanvas",b,y),A=w.context,_=f,x=p;A.translate(-_,-x),A.transform(...u),c||(c=this._scaleImage(d.canvas,pt(A)),c=c.img,l&&r&&l.set(h,c)),A.imageSmoothingEnabled=an(U(A),t.interpolate),fe(A,c,0,0,c.width,c.height,0,0,s,i),A.globalCompositeOperation="source-in";let v=k.transform(pt(A),[1,0,0,1,-_,-x]);return A.fillStyle=r?n.getPattern(e,this,v,Pt):n,A.fillRect(0,0,s,i),l&&!r&&(this.cachedCanvases.delete("fillCanvas"),l.set(h,w.canvas)),{canvas:w.canvas,offsetX:Math.round(_),offsetY:Math.round(x)}}setLineWidth(t){t!==this.current.lineWidth&&(this._cachedScaleForStroking[0]=-1),this.current.lineWidth=t,this.ctx.lineWidth=t}setLineCap(t){this.ctx.lineCap=Mr[t]}setLineJoin(t){this.ctx.lineJoin=Tr[t]}setMiterLimit(t){this.ctx.miterLimit=t}setDash(t,e){let s=this.ctx;s.setLineDash!==void 0&&(s.setLineDash(t),s.lineDashOffset=e)}setRenderingIntent(t){}setFlatness(t){}setGState(t){for(let[e,s]of t)switch(e){case"LW":this.setLineWidth(s);break;case"LC":this.setLineCap(s);break;case"LJ":this.setLineJoin(s);break;case"ML":this.setMiterLimit(s);break;case"D":this.setDash(s[0],s[1]);break;case"RI":this.setRenderingIntent(s);break;case"FL":this.setFlatness(s);break;case"Font":this.setFont(s[0],s[1]);break;case"CA":this.current.strokeAlpha=s;break;case"ca":this.current.fillAlpha=s,this.ctx.globalAlpha=s;break;case"BM":this.ctx.globalCompositeOperation=s;break;case"SMask":this.current.activeSMask=s?this.tempSMask:null,this.tempSMask=null,this.checkSMaskState();break;case"TR":this.ctx.filter=this.current.transferMaps=this.filterFactory.addFilter(s)}}get inSMaskMode(){return!!this.suspendedCtx}checkSMaskState(){let t=this.inSMaskMode;this.current.activeSMask&&!t?this.beginSMaskMode():!this.current.activeSMask&&t&&this.endSMaskMode()}beginSMaskMode(){if(this.inSMaskMode)throw new Error("beginSMaskMode called while already in smask mode");let t=this.ctx.canvas.width,e=this.ctx.canvas.height,s="smaskGroupAt"+this.groupLevel,i=this.cachedCanvases.getCanvas(s,t,e);this.suspendedCtx=this.ctx,this.ctx=i.context;let n=this.ctx;n.setTransform(...U(this.suspendedCtx)),Gt(this.suspendedCtx,n),(function(a,l){if(a._removeMirroring)throw new Error("Context is already forwarding operations.");a.__originalSave=a.save,a.__originalRestore=a.restore,a.__originalRotate=a.rotate,a.__originalScale=a.scale,a.__originalTranslate=a.translate,a.__originalTransform=a.transform,a.__originalSetTransform=a.setTransform,a.__originalResetTransform=a.resetTransform,a.__originalClip=a.clip,a.__originalMoveTo=a.moveTo,a.__originalLineTo=a.lineTo,a.__originalBezierCurveTo=a.bezierCurveTo,a.__originalRect=a.rect,a.__originalClosePath=a.closePath,a.__originalBeginPath=a.beginPath,a._removeMirroring=()=>{a.save=a.__originalSave,a.restore=a.__originalRestore,a.rotate=a.__originalRotate,a.scale=a.__originalScale,a.translate=a.__originalTranslate,a.transform=a.__originalTransform,a.setTransform=a.__originalSetTransform,a.resetTransform=a.__originalResetTransform,a.clip=a.__originalClip,a.moveTo=a.__originalMoveTo,a.lineTo=a.__originalLineTo,a.bezierCurveTo=a.__originalBezierCurveTo,a.rect=a.__originalRect,a.closePath=a.__originalClosePath,a.beginPath=a.__originalBeginPath,delete a._removeMirroring},a.save=function(){l.save(),this.__originalSave()},a.restore=function(){l.restore(),this.__originalRestore()},a.translate=function(c,d){l.translate(c,d),this.__originalTranslate(c,d)},a.scale=function(c,d){l.scale(c,d),this.__originalScale(c,d)},a.transform=function(c,d,u,f,p,g){l.transform(c,d,u,f,p,g),this.__originalTransform(c,d,u,f,p,g)},a.setTransform=function(c,d,u,f,p,g){l.setTransform(c,d,u,f,p,g),this.__originalSetTransform(c,d,u,f,p,g)},a.resetTransform=function(){l.resetTransform(),this.__originalResetTransform()},a.rotate=function(c){l.rotate(c),this.__originalRotate(c)},a.clip=function(c){l.clip(c),this.__originalClip(c)},a.moveTo=function(h,c){l.moveTo(h,c),this.__originalMoveTo(h,c)},a.lineTo=function(h,c){l.lineTo(h,c),this.__originalLineTo(h,c)},a.bezierCurveTo=function(h,c,d,u,f,p){l.bezierCurveTo(h,c,d,u,f,p),this.__originalBezierCurveTo(h,c,d,u,f,p)},a.rect=function(h,c,d,u){l.rect(h,c,d,u),this.__originalRect(h,c,d,u)},a.closePath=function(){l.closePath(),this.__originalClosePath()},a.beginPath=function(){l.beginPath(),this.__originalBeginPath()}})(n,this.suspendedCtx),this.setGState([["BM","source-over"],["ca",1],["CA",1]])}endSMaskMode(){if(!this.inSMaskMode)throw new Error("endSMaskMode called while not in smask mode");this.ctx._removeMirroring(),Gt(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];let 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){let n=i[0],r=i[1],a=i[2]-n,l=i[3]-r;a!==0&&l!==0&&(this.genericComposeSMask(e.context,s,a,l,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,l,h,c,d){let u=t.canvas,f=l-c,p=h-d;if(r){let m=k.makeHexColor(...r);if(f<0||p<0||f+s>u.width||p+i>u.height){let b=this.cachedCanvases.getCanvas("maskExtension",s,i),y=b.context;y.drawImage(u,-f,-p),y.globalCompositeOperation="destination-atop",y.fillStyle=m,y.fillRect(0,0,s,i),y.globalCompositeOperation="source-over",u=b.canvas,f=p=0}else{t.save(),t.globalAlpha=1,t.setTransform(1,0,0,1,0,0);let b=new Path2D;b.rect(f,p,s,i),t.clip(b),t.globalCompositeOperation="destination-atop",t.fillStyle=m,t.fillRect(f,p,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));let g=new Path2D;g.rect(l,h,s,i),e.clip(g),e.globalCompositeOperation="destination-in",e.drawImage(u,f,p,s,i,l,h,s,i),e.restore()}save(){this.inSMaskMode?(Gt(this.ctx,this.suspendedCtx),this.suspendedCtx.save()):this.ctx.save();let t=this.current;this.stateStack.push(t),this.current=t.clone()}restore(){this.stateStack.length===0&&this.inSMaskMode&&this.endSMaskMode(),this.stateStack.length!==0&&(this.current=this.stateStack.pop(),this.inSMaskMode?(this.suspendedCtx.restore(),Gt(this.suspendedCtx,this.ctx)):this.ctx.restore(),this.checkSMaskState(),this.pendingClip=null,this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null)}transform(t,e,s,i,n,r){this.ctx.transform(t,e,s,i,n,r),this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null}constructPath(t,e,s){let i=this.ctx,n=this.current,r,a,l=n.x,h=n.y,c=U(i),d=c[0]===0&&c[3]===0||c[1]===0&&c[2]===0,u=d?s.slice(0):null;for(let f=0,p=0,g=t.length;f<g;f++)switch(0|t[f]){case ut.rectangle:l=e[p++],h=e[p++];let m=e[p++],b=e[p++],y=l+m,w=h+b;i.moveTo(l,h),m===0||b===0?i.lineTo(y,w):(i.lineTo(y,h),i.lineTo(y,w),i.lineTo(l,w)),d||n.updateRectMinMax(c,[l,h,y,w]),i.closePath();break;case ut.moveTo:l=e[p++],h=e[p++],i.moveTo(l,h),d||n.updatePathMinMax(c,l,h);break;case ut.lineTo:l=e[p++],h=e[p++],i.lineTo(l,h),d||n.updatePathMinMax(c,l,h);break;case ut.curveTo:r=l,a=h,l=e[p+4],h=e[p+5],i.bezierCurveTo(e[p],e[p+1],e[p+2],e[p+3],l,h),n.updateCurvePathMinMax(c,r,a,e[p],e[p+1],e[p+2],e[p+3],l,h,u),p+=6;break;case ut.curveTo2:r=l,a=h,i.bezierCurveTo(l,h,e[p],e[p+1],e[p+2],e[p+3]),n.updateCurvePathMinMax(c,r,a,l,h,e[p],e[p+1],e[p+2],e[p+3],u),l=e[p+2],h=e[p+3],p+=4;break;case ut.curveTo3:r=l,a=h,l=e[p+2],h=e[p+3],i.bezierCurveTo(e[p],e[p+1],l,h,l,h),n.updateCurvePathMinMax(c,r,a,e[p],e[p+1],l,h,l,h,u),p+=4;break;case ut.closePath:i.closePath()}d&&n.updateScalingPathMinMax(c,u),n.setCurrentPoint(l,h)}closePath(){this.ctx.closePath()}stroke(t=!0){let e=this.ctx,s=this.current.strokeColor;e.globalAlpha=this.current.strokeAlpha,this.contentVisible&&(typeof s=="object"&&s?.getPattern?(e.save(),e.strokeStyle=s.getPattern(e,this,pt(e),Le),this.rescaleAndStroke(!1),e.restore()):this.rescaleAndStroke(!0)),t&&this.consumePath(this.current.getClippedPathBoundingBox()),e.globalAlpha=this.current.fillAlpha}closeStroke(){this.closePath(),this.stroke()}fill(t=!0){let e=this.ctx,s=this.current.fillColor,i=!1;this.current.patternFill&&(e.save(),e.fillStyle=s.getPattern(e,this,pt(e),Pt),i=!0);let n=this.current.getClippedPathBoundingBox();this.contentVisible&&n!==null&&(this.pendingEOFill?(e.fill("evenodd"),this.pendingEOFill=!1):e.fill()),i&&e.restore(),t&&this.consumePath(n)}eoFill(){this.pendingEOFill=!0,this.fill()}fillStroke(){this.fill(!1),this.stroke(!1),this.consumePath()}eoFillStroke(){this.pendingEOFill=!0,this.fillStroke()}closeFillStroke(){this.closePath(),this.fillStroke()}closeEOFillStroke(){this.pendingEOFill=!0,this.closePath(),this.fillStroke()}endPath(){this.consumePath()}clip(){this.pendingClip=Pr}eoClip(){this.pendingClip=on}beginText(){this.current.textMatrix=cn,this.current.textMatrixScale=1,this.current.x=this.current.lineX=0,this.current.y=this.current.lineY=0}endText(){let t=this.pendingTextPaths,e=this.ctx;if(t===void 0){e.beginPath();return}let s=new Path2D,i=e.getTransform().invertSelf();for(let{transform:n,x:r,y:a,fontSize:l,path:h}of t)s.addPath(h,new DOMMatrix(n).preMultiplySelf(i).translate(r,a).scale(l,-l));e.clip(s),e.beginPath(),delete this.pendingTextPaths}setCharSpacing(t){this.current.charSpacing=t}setWordSpacing(t){this.current.wordSpacing=t}setHScale(t){this.current.textHScale=t/100}setLeading(t){this.current.leading=-t}setFont(t,e){let s=this.commonObjs.get(t),i=this.current;if(!s)throw new Error(`Can't find font for ${t}`);if(i.fontMatrix=s.fontMatrix||ys,i.fontMatrix[0]!==0&&i.fontMatrix[3]!==0||F("Invalid font matrix for font "+t),e<0?(e=-e,i.fontDirection=-1):i.fontDirection=1,this.current.font=s,this.current.fontSize=e,s.isType3Font)return;let n=s.loadedName||"sans-serif",r=s.systemFontInfo?.css||`"${n}", ${s.fallbackName}`,a="normal";s.black?a="900":s.bold&&(a="bold");let l=s.italic?"italic":"normal",h=e;e<16?h=16:e>100&&(h=100),this.current.fontSizeScale=e/h,this.ctx.font=`${l} ${a} ${h}px ${r}`}setTextRenderingMode(t){this.current.textRenderingMode=t}setTextRise(t){this.current.textRise=t}moveText(t,e){this.current.x=this.current.lineX+=t,this.current.y=this.current.lineY+=e}setLeadingMoveText(t,e){this.setLeading(-e),this.moveText(t,e)}setTextMatrix(t,e,s,i,n,r){this.current.textMatrix=[t,e,s,i,n,r],this.current.textMatrixScale=Math.hypot(t,e),this.current.x=this.current.lineX=0,this.current.y=this.current.lineY=0}nextLine(){this.moveText(0,this.current.leading)}#s(t,e,s){let i=new Path2D;return i.addPath(t,new DOMMatrix(s).invertSelf().multiplySelf(e)),i}paintChar(t,e,s,i,n){let r=this.ctx,a=this.current,l=a.font,h=a.textRenderingMode,c=a.fontSize/a.fontSizeScale,d=h&qi,u=!!(h&Wn),f=a.patternFill&&!l.missingFile,p=a.patternStroke&&!l.missingFile,g;if((l.disableFontFace||u||f||p)&&(g=l.getPathGenerator(this.commonObjs,t)),l.disableFontFace||f||p){if(r.save(),r.translate(e,s),r.scale(c,-c),d===me||d===zt)if(i){let m=r.getTransform();r.setTransform(...i),r.fill(this.#s(g,m,i))}else r.fill(g);if(d===ds||d===zt)if(n){let m=r.getTransform();r.setTransform(...n),r.stroke(this.#s(g,m,n))}else r.lineWidth/=c,r.stroke(g);r.restore()}else d!==me&&d!==zt||r.fillText(t,e,s),d!==ds&&d!==zt||r.strokeText(t,e,s);u&&(this.pendingTextPaths||=[]).push({transform:U(r),x:e,y:s,fontSize:c,path:g})}get isFontSubpixelAAEnabled(){let{context:t}=this.cachedCanvases.getCanvas("isFontSubpixelAAEnabled",10,10);t.scale(1.5,1),t.fillText("I",0,10);let e=t.getImageData(0,0,10,10).data,s=!1;for(let i=3;i<e.length;i+=4)if(e[i]>0&&e[i]<255){s=!0;break}return N(this,"isFontSubpixelAAEnabled",s)}showText(t){let e=this.current,s=e.font;if(s.isType3Font)return this.showType3Text(t);let i=e.fontSize;if(i===0)return;let n=this.ctx,r=e.fontSizeScale,a=e.charSpacing,l=e.wordSpacing,h=e.fontDirection,c=e.textHScale*h,d=t.length,u=s.vertical,f=u?1:-1,p=s.defaultVMetrics,g=i*e.fontMatrix[0],m=e.textRenderingMode===me&&!s.disableFontFace&&!e.patternFill;n.save(),n.transform(...e.textMatrix),n.translate(e.x,e.y+e.textRise),h>0?n.scale(c,-1):n.scale(c,1);let b,y;if(e.patternFill){n.save();let v=e.fillColor.getPattern(n,this,pt(n),Pt);b=U(n),n.restore(),n.fillStyle=v}if(e.patternStroke){n.save();let v=e.strokeColor.getPattern(n,this,pt(n),Le);y=U(n),n.restore(),n.strokeStyle=v}let w=e.lineWidth,A=e.textMatrixScale;if(A===0||w===0){let v=e.textRenderingMode&qi;v!==ds&&v!==zt||(w=this.getSinglePixelWidth())}else w/=A;if(r!==1&&(n.scale(r,r),w/=r),n.lineWidth=w,s.isInvalidPDFjsFont){let v=[],C=0;for(let M of t)v.push(M.unicode),C+=M.width;n.fillText(v.join(""),0,0),e.x+=C*g*c,n.restore(),this.compose();return}let _,x=0;for(_=0;_<d;++_){let v=t[_];if(typeof v=="number"){x+=f*v*i/1e3;continue}let C=!1,M=(v.isSpace?l:0)+a,I=v.fontChar,P=v.accent,O,G,$=v.width;if(u){let H=v.vmetric||p,q=-(v.vmetric?H[1]:.5*$)*g,R=H[2]*g;$=H?-H[0]:$,O=q/r,G=(x+R)/r}else O=x/r,G=0;if(s.remeasure&&$>0){let H=1e3*n.measureText(I).width/i*r;if($<H&&this.isFontSubpixelAAEnabled){let q=$/H;C=!0,n.save(),n.scale(q,1),O/=q}else $!==H&&(O+=($-H)/2e3*i/r)}if(this.contentVisible&&(v.isInFont||s.missingFile)){if(m&&!P)n.fillText(I,O,G);else if(this.paintChar(I,O,G,b,y),P){let H=O+i*P.offset.x/r,q=G-i*P.offset.y/r;this.paintChar(P.fontChar,H,q,b,y)}}x+=u?$*g-M*h:$*g+M*h,C&&n.restore()}u?e.y-=x:e.x+=x*c,n.restore(),this.compose()}showType3Text(t){let e=this.ctx,s=this.current,i=s.font,n=s.fontSize,r=s.fontDirection,a=i.vertical?1:-1,l=s.charSpacing,h=s.wordSpacing,c=s.textHScale*r,d=s.fontMatrix||ys,u=t.length,f,p,g,m;if(s.textRenderingMode!==qn&&n!==0){for(this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null,e.save(),e.transform(...s.textMatrix),e.translate(s.x,s.y),e.scale(c,r),f=0;f<u;++f){if(p=t[f],typeof p=="number"){m=a*p*n/1e3,this.ctx.translate(m,0),s.x+=m*c;continue}let b=(p.isSpace?h:0)+l,y=i.charProcOperatorList[p.operatorListId];if(!y){F(`Type3 character "${p.operatorListId}" is not available.`);continue}this.contentVisible&&(this.processingType3=p,this.save(),e.scale(n,n),e.transform(...d),this.executeOperatorList(y),this.restore()),g=k.applyTransform([p.width,0],d)[0]*n+b,e.translate(g,0),s.x+=g*c}e.restore(),this.processingType3=null}}setCharWidth(t,e){}setCharWidthAndBounds(t,e,s,i,n,r){this.ctx.rect(s,i,n-s,r-i),this.ctx.clip(),this.endPath()}getColorN_Pattern(t){let e;if(t[0]==="TilingPattern"){let s=t[1],i=this.baseTransform||U(this.ctx),n={createCanvasGraphics:r=>new o(r,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:this.optionalContentConfig,markedContentStack:this.markedContentStack})};e=new Fs(t,s,this.ctx,n,i)}else e=this._getPattern(t[1],t[2]);return e}setStrokeColorN(){this.current.strokeColor=this.getColorN_Pattern(arguments),this.current.patternStroke=!0}setFillColorN(){this.current.fillColor=this.getColorN_Pattern(arguments),this.current.patternFill=!0}setStrokeRGBColor(t,e,s){this.ctx.strokeStyle=this.current.strokeColor=k.makeHexColor(t,e,s),this.current.patternStroke=!1}setStrokeTransparent(){this.ctx.strokeStyle=this.current.strokeColor="transparent",this.current.patternStroke=!1}setFillRGBColor(t,e,s){this.ctx.fillStyle=this.current.fillColor=k.makeHexColor(t,e,s),this.current.patternFill=!1}setFillTransparent(){this.ctx.fillStyle=this.current.fillColor="transparent",this.current.patternFill=!1}_getPattern(t,e=null){let s;return this.cachedPatterns.has(t)?s=this.cachedPatterns.get(t):(s=(function(n){switch(n[0]){case"RadialAxial":return new Is(n);case"Mesh":return new Ls(n);case"Dummy":return new Ds}throw new Error(`Unknown IR type: ${n[0]}`)})(this.getObject(t)),this.cachedPatterns.set(t,s)),e&&(s.matrix=e),s}shadingFill(t){if(!this.contentVisible)return;let e=this.ctx;this.save();let s=this._getPattern(t);e.fillStyle=s.getPattern(e,this,pt(e),Yt);let i=pt(e);if(i){let{width:n,height:r}=e.canvas,[a,l,h,c]=k.getAxialAlignedBoundingBox([0,0,n,r],i);this.ctx.fillRect(a,l,h-a,c-l)}else this.ctx.fillRect(-1e10,-1e10,2e10,2e10);this.compose(this.current.getClippedPathBoundingBox()),this.restore()}beginInlineImage(){z("Should not call beginInlineImage")}beginImageData(){z("Should not call beginImageData")}paintFormXObjectBegin(t,e){if(this.contentVisible&&(this.save(),this.baseTransformStack.push(this.baseTransform),t&&this.transform(...t),this.baseTransform=U(this.ctx),e)){let s=e[2]-e[0],i=e[3]-e[1];this.ctx.rect(e[0],e[1],s,i),this.current.updateRectMinMax(U(this.ctx),e),this.clip(),this.endPath()}}paintFormXObjectEnd(){this.contentVisible&&(this.restore(),this.baseTransform=this.baseTransformStack.pop())}beginGroup(t){if(!this.contentVisible)return;this.save(),this.inSMaskMode&&(this.endSMaskMode(),this.current.activeSMask=null);let e=this.ctx;t.isolated||Ze("TODO: Support non-isolated groups."),t.knockout&&F("Knockout groups not supported.");let s=U(e);if(t.matrix&&e.transform(...t.matrix),!t.bbox)throw new Error("Bounding box is required.");let i=k.getAxialAlignedBoundingBox(t.bbox,U(e)),n=[0,0,e.canvas.width,e.canvas.height];i=k.intersect(i,n)||[0,0,0,0];let r=Math.floor(i[0]),a=Math.floor(i[1]),l=Math.max(Math.ceil(i[2])-r,1),h=Math.max(Math.ceil(i[3])-a,1);this.current.startNewPathAndClipBox([0,0,l,h]);let c="groupAt"+this.groupLevel;t.smask&&(c+="_smask_"+this.smaskCounter++%2);let d=this.cachedCanvases.getCanvas(c,l,h),u=d.context;u.translate(-r,-a),u.transform(...s),t.smask?this.smaskStack.push({canvas:d.canvas,context:u,offsetX:r,offsetY:a,subtype:t.smask.subtype,backdrop:t.smask.backdrop,transferMap:t.smask.transferMap||null,startTransformInverse:null}):(e.setTransform(1,0,0,1,0,0),e.translate(r,a),e.save()),Gt(e,u),this.ctx=u,this.setGState([["BM","source-over"],["ca",1],["CA",1]]),this.groupStack.push(e),this.groupLevel++}endGroup(t){if(!this.contentVisible)return;this.groupLevel--;let e=this.ctx,s=this.groupStack.pop();if(this.ctx=s,this.ctx.imageSmoothingEnabled=!1,t.smask)this.tempSMask=this.smaskStack.pop(),this.restore();else{this.ctx.restore();let i=U(this.ctx);this.restore(),this.ctx.save(),this.ctx.setTransform(...i);let n=k.getAxialAlignedBoundingBox([0,0,e.canvas.width,e.canvas.height],i);this.ctx.drawImage(e.canvas,0,0),this.ctx.restore(),this.compose(n)}}beginAnnotation(t,e,s,i,n){if(this.#t(),pe(this.ctx),this.ctx.save(),this.save(),this.baseTransform&&this.ctx.setTransform(...this.baseTransform),e){let r=e[2]-e[0],a=e[3]-e[1];if(n&&this.annotationCanvasMap){(s=s.slice())[4]-=e[0],s[5]-=e[1],(e=e.slice())[0]=e[1]=0,e[2]=r,e[3]=a;let[l,h]=k.singularValueDecompose2dScale(U(this.ctx)),{viewportScale:c}=this,d=Math.ceil(r*this.outputScaleX*c),u=Math.ceil(a*this.outputScaleY*c);this.annotationCanvas=this.canvasFactory.create(d,u);let{canvas:f,context:p}=this.annotationCanvas;this.annotationCanvasMap.set(t,f),this.annotationCanvas.savedCtx=this.ctx,this.ctx=p,this.ctx.save(),this.ctx.setTransform(l,0,0,-h,0,a*h),pe(this.ctx)}else pe(this.ctx),this.endPath(),this.ctx.rect(e[0],e[1],r,a),this.ctx.clip(),this.ctx.beginPath()}this.current=new De(this.ctx.canvas.width,this.ctx.canvas.height),this.transform(...s),this.transform(...i)}endAnnotation(){this.annotationCanvas&&(this.ctx.restore(),this.#e(),this.ctx=this.annotationCanvas.savedCtx,delete this.annotationCanvas.savedCtx,delete this.annotationCanvas)}paintImageMaskXObject(t){if(!this.contentVisible)return;let e=t.count;(t=this.getObject(t.data,t)).count=e;let s=this.ctx,i=this.processingType3;if(i&&(i.compiled===void 0&&(i.compiled=(function(l){let{width:h,height:c}=l;if(h>1e3||c>1e3)return null;let d=new Uint8Array([0,2,4,0,1,0,5,4,8,10,0,8,0,2,1,0]),u=h+1,f,p,g,m=new Uint8Array(u*(c+1)),b=h+7&-8,y=new Uint8Array(b*c),w=0;for(let v of l.data){let C=128;for(;C>0;)y[w++]=v&C?0:255,C>>=1}let A=0;for(w=0,y[w]!==0&&(m[0]=1,++A),p=1;p<h;p++)y[w]!==y[w+1]&&(m[p]=y[w]?2:1,++A),w++;for(y[w]!==0&&(m[p]=2,++A),f=1;f<c;f++){w=f*b,g=f*u,y[w-b]!==y[w]&&(m[g]=y[w]?1:8,++A);let v=(y[w]?4:0)+(y[w-b]?8:0);for(p=1;p<h;p++)v=(v>>2)+(y[w+1]?4:0)+(y[w-b+1]?8:0),d[v]&&(m[g+p]=d[v],++A),w++;if(y[w-b]!==y[w]&&(m[g+p]=y[w]?2:4,++A),A>1e3)return null}for(w=b*(c-1),g=f*u,y[w]!==0&&(m[g]=8,++A),p=1;p<h;p++)y[w]!==y[w+1]&&(m[g+p]=y[w]?4:8,++A),w++;if(y[w]!==0&&(m[g+p]=4,++A),A>1e3)return null;let _=new Int32Array([0,u,-1,0,-u,0,0,0,1]),x=new Path2D;for(f=0;A&&f<=c;f++){let v=f*u,C=v+h;for(;v<C&&!m[v];)v++;if(v===C)continue;x.moveTo(v%u,f);let M=v,I=m[v];do{let P=_[I];do v+=P;while(!m[v]);let O=m[v];O!==5&&O!==10?(I=O,m[v]=0):(I=O&51*I>>4,m[v]&=I>>2|I<<2),x.lineTo(v%u,v/u|0),m[v]||--A}while(M!==v);--f}return y=null,m=null,function(v){v.save(),v.scale(1/h,-1/c),v.translate(0,-c),v.fill(x),v.beginPath(),v.restore()}})(t)),i.compiled)){i.compiled(s);return}let n=this._createMaskCanvas(t),r=n.canvas;s.save(),s.setTransform(1,0,0,1,0,0),s.drawImage(r,n.offsetX,n.offsetY),s.restore(),this.compose()}paintImageMaskXObjectRepeat(t,e,s=0,i=0,n,r){if(!this.contentVisible)return;t=this.getObject(t.data,t);let a=this.ctx;a.save();let l=U(a);a.transform(e,s,i,n,0,0);let h=this._createMaskCanvas(t);a.setTransform(1,0,0,1,h.offsetX-l[4],h.offsetY-l[5]);for(let c=0,d=r.length;c<d;c+=2){let u=k.transform(l,[e,s,i,n,r[c],r[c+1]]),[f,p]=k.applyTransform([0,0],u);a.drawImage(h.canvas,f,p)}a.restore(),this.compose()}paintImageMaskXObjectGroup(t){if(!this.contentVisible)return;let e=this.ctx,s=this.current.fillColor,i=this.current.patternFill;for(let n of t){let{data:r,width:a,height:l,transform:h}=n,c=this.cachedCanvases.getCanvas("maskCanvas",a,l),d=c.context;d.save(),rn(d,this.getObject(r,n)),d.globalCompositeOperation="source-in",d.fillStyle=i?s.getPattern(d,this,pt(e),Pt):s,d.fillRect(0,0,a,l),d.restore(),e.save(),e.transform(...h),e.scale(1,-1),fe(e,c.canvas,0,0,a,l,0,-1,1,1),e.restore()}this.compose()}paintImageXObject(t){if(!this.contentVisible)return;let e=this.getObject(t);e?this.paintInlineImageXObject(e):F("Dependent image isn't ready yet")}paintImageXObjectRepeat(t,e,s,i){if(!this.contentVisible)return;let n=this.getObject(t);if(!n){F("Dependent image isn't ready yet");return}let r=n.width,a=n.height,l=[];for(let h=0,c=i.length;h<c;h+=2)l.push({transform:[e,0,0,s,i[h],i[h+1]],x:0,y:0,w:r,h:a});this.paintInlineImageXObjectGroup(n,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;let{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){if(!this.contentVisible)return;let e=t.width,s=t.height,i=this.ctx;if(this.save(),!et){let{filter:a}=i;a!=="none"&&a!==""&&(i.filter="none")}i.scale(1/e,-1/s);let n;if(t.bitmap)n=this.applyTransferMapsToBitmap(t);else if(typeof HTMLElement=="function"&&t instanceof HTMLElement||!t.data)n=t;else{let a=this.cachedCanvases.getCanvas("inlineImage",e,s).context;nn(a,t),n=this.applyTransferMapsToCanvas(a)}let r=this._scaleImage(n,pt(i));i.imageSmoothingEnabled=an(U(i),t.interpolate),fe(i,r.img,0,0,r.paintWidth,r.paintHeight,0,-s,e,s),this.compose(),this.restore()}paintInlineImageXObjectGroup(t,e){if(!this.contentVisible)return;let s=this.ctx,i;if(t.bitmap)i=t.bitmap;else{let n=t.width,r=t.height,a=this.cachedCanvases.getCanvas("inlineImage",n,r).context;nn(a,t),i=this.applyTransferMapsToCanvas(a)}for(let n of e)s.save(),s.transform(...n.transform),s.scale(1,-1),fe(s,i,n.x,n.y,n.w,n.h,0,-1,1,1),s.restore();this.compose()}paintSolidColorImageMask(){this.contentVisible&&(this.ctx.fillRect(0,0,1,1),this.compose())}markPoint(t){}markPointProps(t,e){}beginMarkedContent(t){this.markedContentStack.push({visible:!0})}beginMarkedContentProps(t,e){t==="OC"?this.markedContentStack.push({visible:this.optionalContentConfig.isVisible(e)}):this.markedContentStack.push({visible:!0}),this.contentVisible=this.isContentVisible()}endMarkedContent(){this.markedContentStack.pop(),this.contentVisible=this.isContentVisible()}beginCompat(){}endCompat(){}consumePath(t){let e=this.current.isEmptyClip();this.pendingClip&&this.current.updateClipFromPath(),this.pendingClip||this.compose(t);let s=this.ctx;this.pendingClip&&(e||(this.pendingClip===on?s.clip("evenodd"):s.clip()),this.pendingClip=null),this.current.startNewPathAndClipBox(this.current.clipBox),s.beginPath()}getSinglePixelWidth(){if(!this._cachedGetSinglePixelWidth){let t=U(this.ctx);if(t[1]===0&&t[2]===0)this._cachedGetSinglePixelWidth=1/Math.min(Math.abs(t[0]),Math.abs(t[3]));else{let 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){let{lineWidth:t}=this.current,{a:e,b:s,c:i,d:n}=this.ctx.getTransform(),r,a;if(s===0&&i===0){let l=Math.abs(e),h=Math.abs(n);if(l===h)if(t===0)r=a=1/l;else{let c=l*t;r=a=c<1?1/c:1}else if(t===0)r=1/l,a=1/h;else{let c=l*t,d=h*t;r=c<1?1/c:1,a=d<1?1/d:1}}else{let l=Math.abs(e*n-s*i),h=Math.hypot(e,s),c=Math.hypot(i,n);if(t===0)r=c/l,a=h/l;else{let d=t*l;r=c>d?c/d:1,a=h>d?h/d:1}}this._cachedScaleForStroking[0]=r,this._cachedScaleForStroking[1]=a}return this._cachedScaleForStroking}rescaleAndStroke(t){let{ctx:e}=this,{lineWidth:s}=this.current,[i,n]=this.getScaleForStroking();if(e.lineWidth=s||1,i===1&&n===1){e.stroke();return}let r=e.getLineDash();if(t&&e.save(),e.scale(i,n),r.length>0){let a=Math.max(i,n);e.setLineDash(r.map((l=>l/a))),e.lineDashOffset/=a}e.stroke(),t&&e.restore()}isContentVisible(){for(let t=this.markedContentStack.length-1;t>=0;t--)if(!this.markedContentStack[t].visible)return!1;return!0}};for(let o in ut)Bt.prototype[o]!==void 0&&(Bt.prototype[ut[o]]=Bt.prototype[o]);var Rt=class{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}},Os=class{#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}getAll(){return Ni(this.#t)}has(t){return this.#t.has(t)}},$t=Symbol("INTERNAL"),$s=class{#t=!1;#e=!1;#s=!1;#i=!0;constructor(t,{name:e,intent:s,usage:i,rbGroups:n}){this.#t=!!(t&Fi),this.#e=!!(t&ye),this.name=e,this.intent=s,this.usage=i,this.rbGroups=n}get visible(){if(this.#s)return this.#i;if(!this.#i)return!1;let{print:t,view:e}=this.usage;return this.#t?e?.viewState!=="OFF":!this.#e||t?.printState!=="OFF"}_setVisible(t,e,s=!1){t!==$t&&z("Internal method `_setVisible` called."),this.#s=s,this.#i=e}},Bs=class{#t=null;#e=new Map;#s=null;#i=null;constructor(t,e=Fi){if(this.renderingIntent=e,this.name=null,this.creator=null,t!==null){this.name=t.name,this.creator=t.creator,this.#i=t.order;for(let s of t.groups)this.#e.set(s.id,new $s(e,s));if(t.baseState==="OFF")for(let s of this.#e.values())s._setVisible($t,!1);for(let s of t.on)this.#e.get(s)._setVisible($t,!0);for(let s of t.off)this.#e.get(s)._setVisible($t,!1);this.#s=this.getHash()}}#r(t){let e=t.length;if(e<2)return!0;let s=t[0];for(let i=1;i<e;i++){let n=t[i],r;if(Array.isArray(n))r=this.#r(n);else{if(!this.#e.has(n))return F(`Optional content group not found: ${n}`),!0;r=this.#e.get(n).visible}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 Ze("Optional content group not defined."),!0;if(t.type==="OCG")return this.#e.has(t.id)?this.#e.get(t.id).visible:(F(`Optional content group not found: ${t.id}`),!0);if(t.type==="OCMD"){if(t.expression)return this.#r(t.expression);if(!t.policy||t.policy==="AnyOn"){for(let e of t.ids){if(!this.#e.has(e))return F(`Optional content group not found: ${e}`),!0;if(this.#e.get(e).visible)return!0}return!1}if(t.policy==="AllOn"){for(let e of t.ids){if(!this.#e.has(e))return F(`Optional content group not found: ${e}`),!0;if(!this.#e.get(e).visible)return!1}return!0}if(t.policy==="AnyOff"){for(let e of t.ids){if(!this.#e.has(e))return F(`Optional content group not found: ${e}`),!0;if(!this.#e.get(e).visible)return!0}return!1}if(t.policy==="AllOff"){for(let e of t.ids){if(!this.#e.has(e))return F(`Optional content group not found: ${e}`),!0;if(this.#e.get(e).visible)return!1}return!0}return F(`Unknown optional content policy ${t.policy}.`),!0}return F(`Unknown group type ${t.type}.`),!0}setVisibility(t,e=!0,s=!0){let i=this.#e.get(t);if(i){if(s&&e&&i.rbGroups.length)for(let n of i.rbGroups)for(let r of n)r!==t&&this.#e.get(r)?._setVisible($t,!1,!0);i._setVisible($t,!!e,!0),this.#t=null}else F(`Optional content group not found: ${t}`)}setOCGState({state:t,preserveRB:e}){let s;for(let i of t){switch(i){case"ON":case"OFF":case"Toggle":s=i;continue}let 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)}}this.#t=null}get hasInitialVisibility(){return this.#s===null||this.getHash()===this.#s}getOrder(){return this.#e.size?this.#i?this.#i.slice():[...this.#e.keys()]:null}getGroups(){return this.#e.size>0?Ni(this.#e):null}getGroup(t){return this.#e.get(t)||null}getHash(){if(this.#t!==null)return this.#t;let t=new Ee;for(let[e,s]of this.#e)t.update(`${e}:${s.visible}`);return this.#t=t.hexdigest()}},Hs=class{constructor(t,{disableRange:e=!1,disableStream:s=!1}){Q(t,'PDFDataTransportStream - missing required "pdfDataRangeTransport" argument.');let{length:i,initialData:n,progressiveDone:r,contentDispositionFilename:a}=t;if(this._queuedChunks=[],this._progressiveDone=r,this._contentDispositionFilename=a,n?.length>0){let l=n instanceof Uint8Array&&n.byteLength===n.buffer.byteLength?n.buffer:new Uint8Array(n).buffer;this._queuedChunks.push(l)}this._pdfDataRangeTransport=t,this._isStreamingSupported=!s,this._isRangeSupported=!e,this._contentLength=i,this._fullRequestReader=null,this._rangeReaders=[],t.addRangeListener(((l,h)=>{this._onReceiveData({begin:l,chunk:h})})),t.addProgressListener(((l,h)=>{this._onProgress({loaded:l,total:h})})),t.addProgressiveReadListener((l=>{this._onReceiveData({chunk:l})})),t.addProgressiveDoneListener((()=>{this._onProgressiveDone()})),t.transportReady()}_onReceiveData({begin:t,chunk:e}){let s=e instanceof Uint8Array&&e.byteLength===e.buffer.byteLength?e.buffer:new Uint8Array(e).buffer;t===void 0?this._fullRequestReader?this._fullRequestReader._enqueue(s):this._queuedChunks.push(s):Q(this._rangeReaders.some((function(i){return i._begin!==t?!1:(i._enqueue(s),!0)})),"_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){let e=this._rangeReaders.indexOf(t);e>=0&&this._rangeReaders.splice(e,1)}getFullReader(){Q(!this._fullRequestReader,"PDFDataTransportStream.getFullReader can only be called once.");let t=this._queuedChunks;return this._queuedChunks=null,new js(this,t,this._progressiveDone,this._contentDispositionFilename)}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;let s=new Vs(this,t,e);return this._pdfDataRangeTransport.requestDataRange(t,e),this._rangeReaders.push(s),s}cancelAllRequests(t){this._fullRequestReader?.cancel(t);for(let e of this._rangeReaders.slice(0))e.cancel(t);this._pdfDataRangeTransport.abort()}},js=class{constructor(t,e,s=!1,i=null){this._stream=t,this._done=s||!1,this._filename=$i(i)?i:null,this._queuedChunks=e||[],this._loaded=0;for(let 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};let t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0;for(let e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0}progressiveDone(){this._done||(this._done=!0)}},Vs=class{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(let e of this._requests)e.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){let e=this._queuedChunk;return this._queuedChunk=null,{value:e,done:!1}}if(this._done)return{value:void 0,done:!0};let t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0;for(let e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0,this._stream._removeRangeReader(this)}};function pn(o,t){let e=new Headers;if(!o||!t||typeof t!="object")return e;for(let s in t){let i=t[s];i!==void 0&&e.append(s,i)}return e}function is(o){try{return new URL(o).origin}catch{}return null}function gn({responseHeaders:o,isHttp:t,rangeChunkSize:e,disableRange:s}){let i={allowRangeRequests:!1,suggestedLength:void 0},n=parseInt(o.get("Content-Length"),10);return!Number.isInteger(n)||(i.suggestedLength=n,n<=2*e)||s||!t||o.get("Accept-Ranges")!=="bytes"||(o.get("Content-Encoding")||"identity")!=="identity"||(i.allowRangeRequests=!0),i}function mn(o){let t=o.get("Content-Disposition");if(t){let e=(function(i){let n=!0,r=a("filename\\*","i").exec(i);if(r){r=r[1];let f=c(r);return f=unescape(f),f=d(f),f=u(f),h(f)}if(r=(function(p){let g=[],m,b=a("filename\\*((?!0\\d)\\d+)(\\*?)","ig");for(;(m=b.exec(p))!==null;){let[,w,A,_]=m;if(w=parseInt(w,10),w in g){if(w===0)break}else g[w]=[A,_]}let y=[];for(let w=0;w<g.length&&w in g;++w){let[A,_]=g[w];_=c(_),A&&(_=unescape(_),w===0&&(_=d(_))),y.push(_)}return y.join("")})(i),r)return h(u(r));if(r=a("filename","i").exec(i),r){r=r[1];let f=c(r);return f=u(f),h(f)}function a(f,p){return new RegExp("(?:^|;)\\s*"+f+'\\s*=\\s*([^";\\s][^;\\s]*|"(?:[^"\\\\]|\\\\"?)+"?)',p)}function l(f,p){if(f){if(!/^[\x00-\xFF]+$/.test(p))return p;try{let g=new TextDecoder(f,{fatal:!0}),m=ts(p);p=g.decode(m),n=!1}catch{}}return p}function h(f){return n&&/[\x80-\xff]/.test(f)&&(f=l("utf-8",f),n&&(f=l("iso-8859-1",f))),f}function c(f){if(f.startsWith('"')){let p=f.slice(1).split('\\"');for(let g=0;g<p.length;++g){let m=p[g].indexOf('"');m!==-1&&(p[g]=p[g].slice(0,m),p.length=g+1),p[g]=p[g].replaceAll(/\\(.)/g,"$1")}f=p.join('"')}return f}function d(f){let p=f.indexOf("'");return p===-1?f:l(f.slice(0,p),f.slice(p+1).replace(/^[^']*'/,""))}function u(f){return!f.startsWith("=?")||/[\x00-\x19\x80-\xff]/.test(f)?f:f.replaceAll(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g,(function(p,g,m,b){if(m==="q"||m==="Q")return l(g,b=(b=b.replaceAll("_"," ")).replaceAll(/=([0-9a-fA-F]{2})/g,(function(y,w){return String.fromCharCode(parseInt(w,16))})));try{b=atob(b)}catch{}return l(g,b)}))}return""})(t);if(e.includes("%"))try{e=decodeURIComponent(e)}catch{}if($i(e))return e}return null}function ns(o,t){return o===404||o===0&&t.startsWith("file:")?new It('Missing PDF "'+t+'".'):new jt(`Unexpected server response (${o}) while retrieving PDF "${t}".`,o)}function bn(o){return o===200||o===206}function yn(o,t,e){return{method:"GET",headers:o,signal:e.signal,mode:"cors",credentials:t?"include":"same-origin",redirect:"follow"}}function wn(o){return o instanceof Uint8Array?o.buffer:o instanceof ArrayBuffer?o:(F(`getArrayBuffer - unexpected data format: ${o}`),new Uint8Array(o).buffer)}var Fe=class{_responseOrigin=null;constructor(t){this.source=t,this.isHttp=/^https?:/i.test(t.url),this.headers=pn(this.isHttp,t.httpHeaders),this._fullRequestReader=null,this._rangeRequestReaders=[]}get _progressiveDataLength(){return this._fullRequestReader?._loaded??0}getFullReader(){return Q(!this._fullRequestReader,"PDFFetchStream.getFullReader can only be called once."),this._fullRequestReader=new zs(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;let s=new Gs(this,t,e);return this._rangeRequestReaders.push(s),s}cancelAllRequests(t){this._fullRequestReader?.cancel(t);for(let e of this._rangeRequestReaders.slice(0))e.cancel(t)}},zs=class{constructor(t){this._stream=t,this._reader=null,this._loaded=0,this._filename=null;let 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;let s=new Headers(t.headers),i=e.url;fetch(i,yn(s,this._withCredentials,this._abortController)).then((n=>{if(t._responseOrigin=is(n.url),!bn(n.status))throw ns(n.status,i);this._reader=n.body.getReader(),this._headersCapability.resolve();let r=n.headers,{allowRangeRequests:a,suggestedLength:l}=gn({responseHeaders:r,isHttp:t.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});this._isRangeSupported=a,this._contentLength=l||this._contentLength,this._filename=mn(r),!this._isStreamingSupported&&this._isRangeSupported&&this.cancel(new gt("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;let{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:wn(t),done:!1})}cancel(t){this._reader?.cancel(t),this._abortController.abort()}},Gs=class{constructor(t,e,s){this._stream=t,this._reader=null,this._loaded=0;let i=t.source;this._withCredentials=i.withCredentials||!1,this._readCapability=Promise.withResolvers(),this._isStreamingSupported=!i.disableStream,this._abortController=new AbortController;let n=new Headers(t.headers);n.append("Range",`bytes=${e}-${s-1}`);let r=i.url;fetch(r,yn(n,this._withCredentials,this._abortController)).then((a=>{let l=is(a.url);if(l!==t._responseOrigin)throw new Error(`Expected range response-origin "${l}" to match "${t._responseOrigin}".`);if(!bn(a.status))throw ns(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;let{value:t,done:e}=await this._reader.read();return e?{value:t,done:e}:(this._loaded+=t.byteLength,this.onProgress?.({loaded:this._loaded}),{value:wn(t),done:!1})}cancel(t){this._reader?.cancel(t),this._abortController.abort()}},Us=class{_responseOrigin=null;constructor({url:t,httpHeaders:e,withCredentials:s}){this.url=t,this.isHttp=/^https?:/i.test(t),this.headers=pn(this.isHttp,e),this.withCredentials=s||!1,this.currXhrId=0,this.pendingRequests=Object.create(null)}request(t){let e=new XMLHttpRequest,s=this.currXhrId++,i=this.pendingRequests[s]={xhr:e};e.open("GET",this.url),e.withCredentials=this.withCredentials;for(let[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=206):i.expectedStatus=200,e.responseType="arraybuffer",Q(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){let s=this.pendingRequests[t];s&&s.onProgress?.(e)}onStateChange(t,e){let s=this.pendingRequests[t];if(!s)return;let 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}let n=i.status||200;if(!(n===200&&s.expectedStatus===206)&&n!==s.expectedStatus){s.onError(i.status);return}let r=(function(l){let h=l.response;return typeof h!="string"?h:ts(h).buffer})(i);if(n===206){let a=i.getResponseHeader("Content-Range"),l=/bytes (\d+)-(\d+)\/(\d+)/.exec(a);l?s.onDone({begin:parseInt(l[1],10),chunk:r}):(F('Missing or invalid "Content-Range" header.'),s.onError(0))}else r?s.onDone({begin:0,chunk:r}):s.onError(i.status)}getRequestXhr(t){return this.pendingRequests[t].xhr}isPendingRequest(t){return t in this.pendingRequests}abortRequest(t){let e=this.pendingRequests[t].xhr;delete this.pendingRequests[t],e.abort()}},qs=class{constructor(t){this._source=t,this._manager=new Us(t),this._rangeChunkSize=t.rangeChunkSize,this._fullRequestReader=null,this._rangeRequestReaders=[]}_onRangeRequestReaderClosed(t){let e=this._rangeRequestReaders.indexOf(t);e>=0&&this._rangeRequestReaders.splice(e,1)}getFullReader(){return Q(!this._fullRequestReader,"PDFNetworkStream.getFullReader can only be called once."),this._fullRequestReader=new Ws(this._manager,this._source),this._fullRequestReader}getRangeReader(t,e){let s=new Xs(this._manager,t,e);return s.onClosed=this._onRangeRequestReaderClosed.bind(this),this._rangeRequestReaders.push(s),s}cancelAllRequests(t){this._fullRequestReader?.cancel(t);for(let e of this._rangeRequestReaders.slice(0))e.cancel(t)}},Ws=class{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(){let t=this._fullRequestId,e=this._manager.getRequestXhr(t);this._manager._responseOrigin=is(e.responseURL);let s=e.getAllResponseHeaders(),i=new Headers(s?s.trimStart().replace(/[^\S ]+$/,"").split(/[\r\n]+/).map((a=>{let[l,...h]=a.split(": ");return[l,h.join(": ")]})):[]),{allowRangeRequests:n,suggestedLength:r}=gn({responseHeaders:i,isHttp:this._manager.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});n&&(this._isRangeSupported=!0),this._contentLength=r||this._contentLength,this._filename=mn(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(let e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0}}_onError(t){this._storedError=ns(t,this._url),this._headersCapability.reject(this._storedError);for(let 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};let t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0,this._headersCapability.reject(t);for(let 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}},Xs=class{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(){let t=is(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){let e=t.chunk;this._requests.length>0?this._requests.shift().resolve({value:e,done:!1}):this._queuedChunk=e,this._done=!0;for(let s of this._requests)s.resolve({value:void 0,done:!0});this._requests.length=0,this._close()}_onError(t){this._storedError??=ns(t,this._url);for(let 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){let e=this._queuedChunk;return this._queuedChunk=null,{value:e,done:!1}}if(this._done)return{value:void 0,done:!0};let t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0;for(let 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()}},Rr=/^[a-z][a-z0-9\-+.]+:/i,Ys=class{constructor(t){this.source=t,this.url=(function(s){if(Rr.test(s))return new URL(s);let i=process.getBuiltinModule("url");return new URL(i.pathToFileURL(s))})(t.url),Q(this.url.protocol==="file:","PDFNodeStream only supports file:// URLs."),this._fullRequestReader=null,this._rangeRequestReaders=[]}get _progressiveDataLength(){return this._fullRequestReader?._loaded??0}getFullReader(){return Q(!this._fullRequestReader,"PDFNodeStream.getFullReader can only be called once."),this._fullRequestReader=new Ks(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;let s=new Qs(this,t,e);return this._rangeRequestReaders.push(s),s}cancelAllRequests(t){this._fullRequestReader?.cancel(t);for(let e of this._rangeRequestReaders.slice(0))e.cancel(t)}},Ks=class{constructor(t){this._url=t.url,this._done=!1,this._storedError=null,this.onProgress=null;let 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();let 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=new It(`Missing PDF "${this._url}".`)),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;let 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){this._readableStream?this._readableStream.destroy(t):this._error(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 gt("streaming is disabled")),this._storedError&&this._readableStream.destroy(this._storedError)}},Qs=class{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();let i=t.source;this._isStreamingSupported=!i.disableStream;let 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;let 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){this._readableStream?this._readableStream.destroy(t):this._error(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)}},nt=30,se=class o{#t=Promise.withResolvers();#e=null;#s=!1;#i=!!globalThis.FontInspector?.enabled;#r=null;#n=null;#l=0;#o=0;#c=null;#h=null;#u=0;#d=0;#f=Object.create(null);#a=[];#p=null;#m=[];#g=new WeakMap;#b=null;static#A=new Map;static#y=new Map;static#v=new WeakMap;static#x=null;static#E=new Set;constructor({textContentSource:t,container:e,viewport:s}){if(t instanceof ReadableStream)this.#p=t;else{if(typeof t!="object")throw new Error('No "textContentSource" parameter specified.');this.#p=new ReadableStream({start(l){l.enqueue(t),l.close()}})}this.#e=this.#h=e,this.#d=s.scale*(globalThis.devicePixelRatio||1),this.#u=s.rotation,this.#n={div:null,properties:null,ctx:null};let{pageWidth:i,pageHeight:n,pageX:r,pageY:a}=s.rawDims;this.#b=[1,0,0,-1,-r,a+n],this.#o=i,this.#l=n,o.#R(),Lt(e,s),this.#t.promise.finally((()=>{o.#E.delete(this),this.#n=null,this.#f=null})).catch((()=>{}))}static get fontFamilyMap(){let{isWindows:t,isFirefox:e}=Z.platform;return N(this,"fontFamilyMap",new Map([["sans-serif",(t&&e?"Calibri, ":"")+"sans-serif"],["monospace",(t&&e?"Lucida Console, ":"")+"monospace"]]))}render(){let t=()=>{this.#c.read().then((({value:e,done:s})=>{s?this.#t.resolve():(this.#r??=e.lang,Object.assign(this.#f,e.styles),this.#k(e.items),t())}),this.#t.reject)};return this.#c=this.#p.getReader(),o.#E.add(this),t(),this.#t.promise}update({viewport:t,onBefore:e=null}){let s=t.scale*(globalThis.devicePixelRatio||1),i=t.rotation;if(i!==this.#u&&(e?.(),this.#u=i,Lt(this.#h,{rotation:i})),s!==this.#d){e?.(),this.#d=s;let n={div:null,properties:null,ctx:o.#M(this.#r)};for(let r of this.#m)n.properties=this.#g.get(r),n.div=r,this.#_(n)}}cancel(){let t=new gt("TextLayer task cancelled.");this.#c?.cancel(t).catch((()=>{})),this.#c=null,this.#t.reject(t)}get textDivs(){return this.#m}get textContentItemsStr(){return this.#a}#k(t){if(this.#s)return;this.#n.ctx??=o.#M(this.#r);let e=this.#m,s=this.#a;for(let i of t){if(e.length>1e5){F("Ignoring additional textDivs for performance reasons."),this.#s=!0;return}if(i.str!==void 0)s.push(i.str),this.#T(i);else if(i.type==="beginMarkedContentProps"||i.type==="beginMarkedContent"){let n=this.#e;this.#e=document.createElement("span"),this.#e.classList.add("markedContent"),i.id!==null&&this.#e.setAttribute("id",`${i.id}`),n.append(this.#e)}else i.type==="endMarkedContent"&&(this.#e=this.#e.parentNode)}}#T(t){let e=document.createElement("span"),s={angle:0,canvasWidth:0,hasText:t.str!=="",hasEOL:t.hasEOL,fontSize:0};this.#m.push(e);let i=k.transform(this.#b,t.transform),n=Math.atan2(i[1],i[0]),r=this.#f[t.fontName];r.vertical&&(n+=Math.PI/2);let a=this.#i&&r.fontSubstitution||r.fontFamily;a=o.fontFamilyMap.get(a)||a;let l=Math.hypot(i[2],i[3]),h=l*o.#D(a,this.#r),c,d;n===0?(c=i[4],d=i[5]-h):(c=i[4]+h*Math.sin(n),d=i[5]-h*Math.cos(n));let u="calc(var(--scale-factor)*",f=e.style;this.#e===this.#h?(f.left=`${(100*c/this.#o).toFixed(2)}%`,f.top=`${(100*d/this.#l).toFixed(2)}%`):(f.left=`${u}${c.toFixed(2)}px)`,f.top=`${u}${d.toFixed(2)}px)`),f.fontSize=`${u}${(o.#x*l).toFixed(2)}px)`,f.fontFamily=a,s.fontSize=l,e.setAttribute("role","presentation"),e.textContent=t.str,e.dir=t.dir,this.#i&&(e.dataset.fontName=r.fontSubstitutionLoadedName||t.fontName),n!==0&&(s.angle=n*(180/Math.PI));let p=!1;if(t.str.length>1)p=!0;else if(t.str!==" "&&t.transform[0]!==t.transform[3]){let g=Math.abs(t.transform[0]),m=Math.abs(t.transform[3]);g!==m&&Math.max(g,m)/Math.min(g,m)>1.5&&(p=!0)}if(p&&(s.canvasWidth=r.vertical?t.height:t.width),this.#g.set(e,s),this.#n.div=e,this.#n.properties=s,this.#_(this.#n),s.hasText&&this.#e.append(e),s.hasEOL){let g=document.createElement("br");g.setAttribute("role","presentation"),this.#e.append(g)}}#_(t){let{div:e,properties:s,ctx:i}=t,{style:n}=e,r="";if(o.#x>1&&(r=`scale(${1/o.#x})`),s.canvasWidth!==0&&s.hasText){let{fontFamily:a}=n,{canvasWidth:l,fontSize:h}=s;o.#C(i,h*this.#d,a);let{width:c}=i.measureText(e.textContent);c>0&&(r=`scaleX(${l*this.#d/c}) ${r}`)}s.angle!==0&&(r=`rotate(${s.angle}deg) ${r}`),r.length>0&&(n.transform=r)}static cleanup(){if(!(this.#E.size>0)){this.#A.clear();for(let{canvas:t}of this.#y.values())t.remove();this.#y.clear()}}static#M(t=null){let e=this.#y.get(t||="");if(!e){let 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.#v.set(e,{size:0,family:""})}return e}static#C(t,e,s){let i=this.#v.get(t);(e!==i.size||s!==i.family)&&(t.font=`${e}px ${s}`,i.size=e,i.family=s)}static#R(){if(this.#x!==null)return;let 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.#x=t.getBoundingClientRect().height,t.remove()}static#D(t,e){let s=this.#A.get(t);if(s)return s;let i=this.#M(e);i.canvas.width=i.canvas.height=nt,this.#C(i,nt,t);let n=i.measureText(""),r=n.fontBoundingBoxAscent,a=Math.abs(n.fontBoundingBoxDescent);if(r){let c=r/(r+a);return this.#A.set(t,c),i.canvas.width=i.canvas.height=0,c}i.strokeStyle="red",i.clearRect(0,0,nt,nt),i.strokeText("g",0,0);let l=i.getImageData(0,0,nt,nt).data;a=0;for(let c=l.length-1-3;c>=0;c-=4)if(l[c]>0){a=Math.ceil(c/4/nt);break}i.clearRect(0,0,nt,nt),i.strokeText("A",0,nt),l=i.getImageData(0,0,nt,nt).data,r=0;for(let c=0,d=l.length;c<d;c+=4)if(l[c]>0){r=nt-Math.floor(c/4/nt);break}i.canvas.width=i.canvas.height=0;let h=r?r/(r+a):.8;return this.#A.set(t,h),h}},ie=class o{static textContent(t){let e=[],s={items:e,styles:Object.create(null)};return(function i(n){if(!n)return;let r=null,a=n.name;if(a==="#text")r=n.value;else{if(!o.shouldBuildText(a))return;n?.attributes?.textContent?r=n.attributes.textContent:n.value&&(r=n.value)}if(r!==null&&e.push({str:r}),n.children)for(let l of n.children)i(l)})(t),s}static shouldBuildText(t){return!(t==="textarea"||t==="input"||t==="option"||t==="select")}},Ir=65536,Lr=et?class extends ke{_createCanvas(t,e){return process.getBuiltinModule("module").createRequire(import.meta.url)("@napi-rs/canvas").createCanvas(t,e)}}:class extends ke{constructor({ownerDocument:t=globalThis.document,enableHWA:e=!1}){super({enableHWA:e}),this._document=t}_createCanvas(t,e){let s=this._document.createElement("canvas");return s.width=t,s.height=e,s}},Dr=et?class extends Me{async _fetch(t){return fn(t)}}:Te,Fr=et?class extends Pe{}:class extends Pe{#t;#e;#s;#i;#r;#n;#l=0;constructor({docId:t,ownerDocument:e=globalThis.document}){super(),this.#i=t,this.#r=e}get#o(){return this.#e||=new Map}get#c(){return this.#n||=new Map}get#h(){if(!this.#s){let t=this.#r.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;let s=this.#r.createElementNS(At,"svg");s.setAttribute("width",0),s.setAttribute("height",0),this.#s=this.#r.createElementNS(At,"defs"),t.append(s),s.append(this.#s),this.#r.body.append(t)}return this.#s}#u(t){if(t.length===1){let l=t[0],h=new Array(256);for(let d=0;d<256;d++)h[d]=l[d]/255;let c=h.join(",");return[c,c,c]}let[e,s,i]=t,n=new Array(256),r=new Array(256),a=new Array(256);for(let l=0;l<256;l++)n[l]=e[l]/255,r[l]=s[l]/255,a[l]=i[l]/255;return[n.join(","),r.join(","),a.join(",")]}#d(t){if(this.#t===void 0){this.#t="";let e=this.#r.URL;e!==this.#r.baseURI&&(ss(e)?F('#createUrl: ignore "data:"-URL for performance reasons.'):this.#t=e.split("#",1)[0])}return`url(${this.#t}#${t})`}addFilter(t){if(!t)return"none";let e=this.#o.get(t);if(e)return e;let[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;let a=`g_${this.#i}_transfer_map_${this.#l++}`,l=this.#d(a);this.#o.set(t,l),this.#o.set(r,l);let h=this.#p(a);return this.#g(s,i,n,h),l}addHCMFilter(t,e){let s=`${t}-${e}`,i="base",n=this.#c.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.#c.set(i,n)),!t||!e))return n.url;let r=this.#A(t);t=k.makeHexColor(...r);let a=this.#A(e);if(e=k.makeHexColor(...a),this.#h.style.color="",t==="#000000"&&e==="#ffffff"||t===e)return n.url;let l=new Array(256);for(let f=0;f<=255;f++){let p=f/255;l[f]=p<=.03928?p/12.92:((p+.055)/1.055)**2.4}let h=l.join(","),c=`g_${this.#i}_hcm_filter`,d=n.filter=this.#p(c);this.#g(h,h,h,d),this.#a(d);let u=(f,p)=>{let g=r[f]/255,m=a[f]/255,b=new Array(p+1);for(let y=0;y<=p;y++)b[y]=g+y/p*(m-g);return b.join(",")};return this.#g(u(0,5),u(1,5),u(2,5),d),n.url=this.#d(c),n.url}addAlphaFilter(t){let e=this.#o.get(t);if(e)return e;let[s]=this.#u([t]),i=`alpha_${s}`;if(e=this.#o.get(i),e)return this.#o.set(t,e),e;let n=`g_${this.#i}_alpha_map_${this.#l++}`,r=this.#d(n);this.#o.set(t,r),this.#o.set(i,r);let a=this.#p(n);return this.#b(s,a),r}addLuminosityFilter(t){let e,s,i=this.#o.get(t||"luminosity");if(i)return i;if(t?([e]=this.#u([t]),s=`luminosity_${e}`):s="luminosity",i=this.#o.get(s),i)return this.#o.set(t,i),i;let n=`g_${this.#i}_luminosity_map_${this.#l++}`,r=this.#d(n);this.#o.set(t,r),this.#o.set(s,r);let a=this.#p(n);return this.#f(a),t&&this.#b(e,a),r}addHighlightHCMFilter(t,e,s,i,n){let r=`${e}-${s}-${i}-${n}`,a=this.#c.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.#c.set(t,a)),!e||!s))return a.url;let[l,h]=[e,s].map(this.#A.bind(this)),c=Math.round(.2126*l[0]+.7152*l[1]+.0722*l[2]),d=Math.round(.2126*h[0]+.7152*h[1]+.0722*h[2]),[u,f]=[i,n].map(this.#A.bind(this));d<c&&([c,d,u,f]=[d,c,f,u]),this.#h.style.color="";let p=(b,y,w)=>{let A=new Array(256),_=(d-c)/w,x=b/255,v=(y-b)/(255*w),C=0;for(let M=0;M<=w;M++){let I=Math.round(c+M*_),P=x+M*v;for(let O=C;O<=I;O++)A[O]=P;C=I+1}for(let M=C;M<256;M++)A[M]=A[C-1];return A.join(",")},g=`g_${this.#i}_hcm_${t}_filter`,m=a.filter=this.#p(g);return this.#a(m),this.#g(p(u[0],f[0],5),p(u[1],f[1],5),p(u[2],f[2],5),m),a.url=this.#d(g),a.url}destroy(t=!1){(!t||!this.#n?.size)&&(this.#s?.parentNode.parentNode.remove(),this.#s=null,this.#e?.clear(),this.#e=null,this.#n?.clear(),this.#n=null,this.#l=0)}#f(t){let e=this.#r.createElementNS(At,"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)}#a(t){let e=this.#r.createElementNS(At,"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){let e=this.#r.createElementNS(At,"filter");return e.setAttribute("color-interpolation-filters","sRGB"),e.setAttribute("id",t),this.#h.append(e),e}#m(t,e,s){let i=this.#r.createElementNS(At,e);i.setAttribute("type","discrete"),i.setAttribute("tableValues",s),t.append(i)}#g(t,e,s,i){let n=this.#r.createElementNS(At,"feComponentTransfer");i.append(n),this.#m(n,"feFuncR",t),this.#m(n,"feFuncG",e),this.#m(n,"feFuncB",s)}#b(t,e){let s=this.#r.createElementNS(At,"feComponentTransfer");e.append(s),this.#m(s,"feFuncA",t)}#A(t){return this.#h.style.color=t,As(getComputedStyle(this.#h).getPropertyValue("color"))}},Nr=et?class extends Re{async _fetch(t){return fn(t)}}:Ie;function Or(o={}){typeof o=="string"||o instanceof URL?o={url:o}:(o instanceof ArrayBuffer||ArrayBuffer.isView(o))&&(o={data:o});let t=new Js,{docId:e}=t,s=o.url?(function(V){if(V instanceof URL)return V.href;try{return new URL(V,window.location).href}catch{if(et&&typeof V=="string")return V}throw new Error("Invalid PDF url data: either string or URL-object is expected in the url property.")})(o.url):null,i=o.data?(function(V){if(et&&typeof Buffer<"u"&&V instanceof Buffer)throw new Error("Please provide binary data as `Uint8Array`, rather than `Buffer`.");if(V instanceof Uint8Array&&V.byteLength===V.buffer.byteLength)return V;if(typeof V=="string")return ts(V);if(V instanceof ArrayBuffer||ArrayBuffer.isView(V)||typeof V=="object"&&!isNaN(V?.length))return new Uint8Array(V);throw new Error("Invalid PDF binary data: either TypedArray, string, or array-like object is expected in the data property.")})(o.data):null,n=o.httpHeaders||null,r=o.withCredentials===!0,a=o.password??null,l=o.range instanceof Ne?o.range:null,h=Number.isInteger(o.rangeChunkSize)&&o.rangeChunkSize>0?o.rangeChunkSize:Ir,c=o.worker instanceof Ht?o.worker:null,d=o.verbosity,u=typeof o.docBaseUrl!="string"||ss(o.docBaseUrl)?null:o.docBaseUrl,f=typeof o.cMapUrl=="string"?o.cMapUrl:null,p=o.cMapPacked!==!1,g=o.CMapReaderFactory||Dr,m=typeof o.standardFontDataUrl=="string"?o.standardFontDataUrl:null,b=o.StandardFontDataFactory||Nr,y=o.stopAtErrors!==!0,w=Number.isInteger(o.maxImageSize)&&o.maxImageSize>-1?o.maxImageSize:-1,A=o.isEvalSupported!==!1,_=typeof o.isOffscreenCanvasSupported=="boolean"?o.isOffscreenCanvasSupported:!et,x=typeof o.isImageDecoderSupported=="boolean"?o.isImageDecoderSupported:!et&&(Z.platform.isFirefox||!globalThis.chrome),v=Number.isInteger(o.canvasMaxAreaInBytes)?o.canvasMaxAreaInBytes:-1,C=typeof o.disableFontFace=="boolean"?o.disableFontFace:et,M=o.fontExtraProperties===!0,I=o.enableXfa===!0,P=o.ownerDocument||globalThis.document,O=o.disableRange===!0,G=o.disableStream===!0,$=o.disableAutoFetch===!0,H=o.pdfBug===!0,q=o.CanvasFactory||Lr,R=o.FilterFactory||Fr,L=o.enableHWA===!0,ct=l?l.length:o.length??NaN,yt=typeof o.useSystemFonts=="boolean"?o.useSystemFonts:!et&&!C,wt=typeof o.useWorkerFetch=="boolean"?o.useWorkerFetch:g===Te&&b===Ie&&f&&m&&Wt(f,document.baseURI)&&Wt(m,document.baseURI);br(d);let it={canvasFactory:new q({ownerDocument:P,enableHWA:L}),filterFactory:new R({docId:e,ownerDocument:P}),cMapReaderFactory:wt?null:new g({baseUrl:f,isCompressed:p}),standardFontDataFactory:wt?null:new b({baseUrl:m})};if(!c){let lt={verbosity:d,port:Rt.workerPort};c=lt.port?Ht.fromPort(lt):new Ht(lt),t._worker=c}let J={docId:e,apiVersion:"4.10.38",data:i,password:a,disableAutoFetch:$,rangeChunkSize:h,length:ct,docBaseUrl:u,enableXfa:I,evaluatorOptions:{maxImageSize:w,disableFontFace:C,ignoreErrors:y,isEvalSupported:A,isOffscreenCanvasSupported:_,isImageDecoderSupported:x,canvasMaxAreaInBytes:v,fontExtraProperties:M,useSystemFonts:yt,cMapUrl:wt?f:null,standardFontDataUrl:wt?m:null}},_t={disableFontFace:C,fontExtraProperties:M,ownerDocument:P,pdfBug:H,styleElement:null,loadingParams:{disableAutoFetch:$,enableXfa:I}};return c.promise.then((function(){if(t.destroyed)throw new Error("Loading aborted");if(c.destroyed)throw new Error("Worker was destroyed");let lt=c.messageHandler.sendWithPromise("GetDocRequest",J,i?[i.buffer]:null),V;if(l)V=new Hs(l,{disableRange:O,disableStream:G});else if(!i){if(!s)throw new Error("getDocument - no `url` parameter provided.");let Y;if(et)if(Wt(s)){if(typeof fetch>"u"||typeof Response>"u"||!("body"in Response.prototype))throw new Error("getDocument - the Fetch API was disabled in Node.js, see `--no-experimental-fetch`.");Y=Fe}else Y=Ys;else Y=Wt(s)?Fe:qs;V=new Y({url:s,length:ct,httpHeaders:n,withCredentials:r,rangeChunkSize:h,disableRange:O,disableStream:G})}return lt.then((Y=>{if(t.destroyed)throw new Error("Loading aborted");if(c.destroyed)throw new Error("Worker was destroyed");let Ui=new Tt(e,Y,c.port),$n=new si(Ui,t,V,_t,it);t._transport=$n,Ui.send("Ready",null)}))})).catch(t._capability.reject),t}function ln(o){return typeof o=="object"&&Number.isInteger(o?.num)&&o.num>=0&&Number.isInteger(o?.gen)&&o.gen>=0}var Js=class o{static#t=0;constructor(){this._capability=Promise.withResolvers(),this._transport=null,this._worker=null,this.docId="d"+o.#t++,this.destroyed=!1,this.onPassword=null,this.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}},Ne=class{constructor(t,e,s=!1,i=null){this.length=t,this.initialData=e,this.progressiveDone=s,this.contentDispositionFilename=i,this._rangeListeners=[],this._progressListeners=[],this._progressiveReadListeners=[],this._progressiveDoneListeners=[],this._readyCapability=Promise.withResolvers()}addRangeListener(t){this._rangeListeners.push(t)}addProgressListener(t){this._progressListeners.push(t)}addProgressiveReadListener(t){this._progressiveReadListeners.push(t)}addProgressiveDoneListener(t){this._progressiveDoneListeners.push(t)}onDataRange(t,e){for(let s of this._rangeListeners)s(t,e)}onDataProgress(t,e){this._readyCapability.promise.then((()=>{for(let s of this._progressListeners)s(t,e)}))}onDataProgressiveRead(t){this._readyCapability.promise.then((()=>{for(let e of this._progressiveReadListeners)e(t)}))}onDataProgressiveDone(){this._readyCapability.promise.then((()=>{for(let t of this._progressiveDoneListeners)t()}))}transportReady(){this._readyCapability.resolve()}requestDataRange(t,e){z("Abstract method PDFDataRangeTransport.requestDataRange")}abort(){}},Zs=class{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 N(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()}getJSActions(){return this._transport.getDocJSActions()}getOutline(){return this._transport.getOutline()}getOptionalContentConfig({intent:t="display"}={}){let{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()}},ti=class{#t=null;#e=!1;constructor(t,e,s,i=!1){this._pageIndex=t,this._pageInfo=e,this._transport=s,this._stats=i?new Ae:null,this._pdfBug=i,this.commonObjs=s.commonObjs,this.objs=new Oe,this._maybeCleanupAfterRender=!1,this._intentStates=new Map,this.destroyed=!1}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 Qt({viewBox:this.view,userUnit:this.userUnit,scale:t,rotation:e,offsetX:s,offsetY:i,dontFlip:n})}getAnnotations({intent:t="display"}={}){let{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 N(this,"isPureXfa",!!this._transport._htmlForXfa)}async getXfa(){return this._transport._htmlForXfa?.children[this._pageIndex]||null}render({canvasContext:t,viewport:e,intent:s="display",annotationMode:i=St.ENABLE,transform:n=null,background:r=null,optionalContentConfigPromise:a=null,annotationCanvasMap:l=null,pageColors:h=null,printAnnotationStorage:c=null,isEditing:d=!1}){this._stats?.time("Overall");let u=this._transport.getRenderingIntent(s,i,c,d),{renderingIntent:f,cacheKey:p}=u;this.#e=!1,this.#i(),a||=this._transport.getOptionalContentConfig(f);let g=this._intentStates.get(p);g||(g=Object.create(null),this._intentStates.set(p,g)),g.streamReaderCancelTimeout&&(clearTimeout(g.streamReaderCancelTimeout),g.streamReaderCancelTimeout=null);let m=!!(f&ye);g.displayReadyCapability||(g.displayReadyCapability=Promise.withResolvers(),g.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},this._stats?.time("Page Request"),this._pumpOperatorList(u));let b=A=>{g.renderTasks.delete(y),(this._maybeCleanupAfterRender||m)&&(this.#e=!0),this.#s(!m),A?(y.capability.reject(A),this._abortOperatorList({intentState:g,reason:A instanceof Error?A:new Error(A)})):y.capability.resolve(),this._stats&&(this._stats.timeEnd("Rendering"),this._stats.timeEnd("Overall"),globalThis.Stats?.enabled&&globalThis.Stats.add(this.pageNumber,this._stats))},y=new ni({callback:b,params:{canvasContext:t,viewport:e,transform:n,background:r},objs:this.objs,commonObjs:this.commonObjs,annotationCanvasMap:l,operatorList:g.operatorList,pageIndex:this._pageIndex,canvasFactory:this._transport.canvasFactory,filterFactory:this._transport.filterFactory,useRequestAnimationFrame:!m,pdfBug:this._pdfBug,pageColors:h});(g.renderTasks||=new Set).add(y);let w=y.task;return Promise.all([g.displayReadyCapability.promise,a]).then((([A,_])=>{if(this.destroyed)b();else{if(this._stats?.time("Rendering"),!(_.renderingIntent&f))throw new Error("Must use the same `intent`-argument when calling the `PDFPageProxy.render` and `PDFDocumentProxy.getOptionalContentConfig` methods.");y.initializeGraphics({transparency:A,optionalContentConfig:_}),y.operatorListChanged()}})).catch(b),w}getOperatorList({intent:t="display",annotationMode:e=St.ENABLE,printAnnotationStorage:s=null,isEditing:i=!1}={}){let n=this._transport.getRenderingIntent(t,e,s,i,!0),r,a=this._intentStates.get(n.cacheKey);return a||(a=Object.create(null),this._intentStates.set(n.cacheKey,a)),a.opListReadCapability||(r=Object.create(null),r.operatorListChanged=function(){a.operatorList.lastChunk&&(a.opListReadCapability.resolve(a.operatorList),a.renderTasks.delete(r))},a.opListReadCapability=Promise.withResolvers(),(a.renderTasks||=new Set).add(r),a.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},this._stats?.time("Page Request"),this._pumpOperatorList(n)),a.opListReadCapability.promise}streamTextContent({includeMarkedContent:t=!1,disableNormalization:e=!1}={}){return this._transport.messageHandler.sendWithStream("GetTextContent",{pageIndex:this._pageIndex,includeMarkedContent:t===!0,disableNormalization:e===!0},{highWaterMark:100,size:s=>s.items.length})}getTextContent(t={}){if(this._transport._htmlForXfa)return this.getXfa().then((s=>ie.textContent(s)));let e=this.streamTextContent(t);return new Promise((function(s,i){let n=e.getReader(),r={items:[],styles:Object.create(null),lang:null};(function a(){n.read().then((function({value:l,done:h}){h?s(r):(r.lang??=l.lang,Object.assign(r.styles,l.styles),r.items.push(...l.items),a())}),i)})()}))}getStructTree(){return this._transport.getStructTree(this._pageIndex)}_destroy(){this.destroyed=!0;let t=[];for(let e of this._intentStates.values())if(this._abortOperatorList({intentState:e,reason:new Error("Page was destroyed."),force:!0}),!e.opListReadCapability)for(let s of e.renderTasks)t.push(s.completed),s.cancel();return this.objs.clear(),this.#e=!1,this.#i(),Promise.all(t)}cleanup(t=!1){this.#e=!0;let e=this.#s(!1);return t&&e&&(this._stats&&=new Ae),e}#s(t=!1){if(this.#i(),!this.#e||this.destroyed)return!1;if(t)return this.#t=setTimeout((()=>{this.#t=null,this.#s(!1)}),5e3),!1;for(let{renderTasks:e,operatorList:s}of this._intentStates.values())if(e.size>0||!s.lastChunk)return!1;return this._intentStates.clear(),this.objs.clear(),this.#e=!1,!0}#i(){this.#t&&(clearTimeout(this.#t),this.#t=null)}_startRenderPage(t,e){let 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(let s of e.renderTasks)s.operatorListChanged();t.lastChunk&&this.#s(!0)}_pumpOperatorList({renderingIntent:t,cacheKey:e,annotationStorageSerializable:s,modifiedIds:i}){let{map:n,transfer:r}=s,a=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=a;let h=()=>{a.read().then((({value:c,done:d})=>{d?l.streamReader=null:this._transport.destroyed||(this._renderPageChunk(c,l),h())}),(c=>{if(l.streamReader=null,!this._transport.destroyed){if(l.operatorList){l.operatorList.lastChunk=!0;for(let d of l.renderTasks)d.operatorListChanged();this.#s(!0)}if(l.displayReadyCapability)l.displayReadyCapability.reject(c);else{if(!l.opListReadCapability)throw c;l.opListReadCapability.reject(c)}}}))};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 Jt){let i=100;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 gt(e.message)).catch((()=>{})),t.streamReader=null,!this._transport.destroyed){for(let[i,n]of this._intentStates)if(n===t){this._intentStates.delete(i);break}this.cleanup()}}}get stats(){return this._stats}},ei=class{#t=new Map;#e=Promise.resolve();postMessage(t,e){let s={data:structuredClone(t,e?{transfer:e}:null)};this.#e.then((()=>{for(let[i]of this.#t)i.call(this,s)}))}addEventListener(t,e,s=null){let i=null;if(s?.signal instanceof AbortSignal){let{signal:n}=s;if(n.aborted){F("LoopbackPort - cannot use an `aborted` signal.");return}let 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(let[,t]of this.#t)t?.();this.#t.clear()}},Ht=class o{static#t=0;static#e=!1;static#s;static{et&&(this.#e=!0,Rt.workerSrc||="./pdf.worker.mjs"),this._isSameOrigin=(t,e)=>{let s;try{if(s=new URL(t),!s.origin||s.origin==="null")return!1}catch{return!1}let i=new URL(e,s);return s.origin===i.origin},this._createCDNWrapper=t=>{let e=`await import("${t}");`;return URL.createObjectURL(new Blob([e],{type:"text/javascript"}))}}constructor({name:t=null,port:e=null,verbosity:s=yr()}={}){if(this.name=t,this.destroyed=!1,this.verbosity=s,this._readyCapability=Promise.withResolvers(),this._port=null,this._webWorker=null,this._messageHandler=null,e){if(o.#s?.has(e))throw new Error("Cannot use more than one PDFWorker per port.");(o.#s||=new WeakMap).set(e,this),this._initializeFromPort(e)}else this._initialize()}get promise(){return this._readyCapability.promise}#i(){this._readyCapability.resolve(),this._messageHandler.send("configure",{verbosity:this.verbosity})}get port(){return this._port}get messageHandler(){return this._messageHandler}_initializeFromPort(t){this._port=t,this._messageHandler=new Tt("main","worker",t),this._messageHandler.on("ready",(function(){})),this.#i()}_initialize(){if(o.#e||o.#r){this._setupFakeWorker();return}let{workerSrc:t}=o;try{o._isSameOrigin(window.location.href,t)||(t=o._createCDNWrapper(new URL(t,window.location).href));let e=new Worker(t,{type:"module"}),s=new Tt("main","worker",e),i=()=>{n.abort(),s.destroy(),e.terminate(),this.destroyed?this._readyCapability.reject(new Error("Worker was destroyed")):this._setupFakeWorker()},n=new AbortController;e.addEventListener("error",(()=>{this._webWorker||i()}),{signal:n.signal}),s.on("test",(a=>{n.abort(),!this.destroyed&&a?(this._messageHandler=s,this._port=e,this._webWorker=e,this.#i()):i()})),s.on("ready",(a=>{if(n.abort(),this.destroyed)i();else try{r()}catch{this._setupFakeWorker()}}));let r=()=>{let a=new Uint8Array;s.send("test",a,[a.buffer])};r();return}catch{Ze("The worker has been disabled.")}this._setupFakeWorker()}_setupFakeWorker(){o.#e||(F("Setting up fake worker."),o.#e=!0),o._setupFakeWorkerGlobal.then((t=>{if(this.destroyed){this._readyCapability.reject(new Error("Worker was destroyed"));return}let e=new ei;this._port=e;let s="fake"+o.#t++,i=new Tt(s+"_worker",s,e);t.setup(i,e),this._messageHandler=new Tt(s,s+"_worker",e),this.#i()})).catch((t=>{this._readyCapability.reject(new Error(`Setting up fake worker failed: "${t.message}".`))}))}destroy(){this.destroyed=!0,this._webWorker?.terminate(),this._webWorker=null,o.#s?.delete(this._port),this._port=null,this._messageHandler?.destroy(),this._messageHandler=null}static fromPort(t){if(!t?.port)throw new Error("PDFWorker.fromPort - invalid method signature.");let e=this.#s?.get(t.port);if(e){if(e._pendingDestroy)throw new Error("PDFWorker.fromPort - the worker is being destroyed.\nPlease remember to await `PDFDocumentLoadingTask.destroy()`-calls.");return e}return new o(t)}static get workerSrc(){if(Rt.workerSrc)return Rt.workerSrc;throw new Error('No "GlobalWorkerOptions.workerSrc" specified.')}static get#r(){try{return globalThis.pdfjsWorker?.WorkerMessageHandler||null}catch{return null}}static get _setupFakeWorkerGlobal(){return N(this,"_setupFakeWorkerGlobal",(async()=>this.#r?this.#r:(await import(this.workerSrc)).WorkerMessageHandler)())}},si=class{#t=new Map;#e=new Map;#s=new Map;#i=new Map;#r=null;constructor(t,e,s,i,n){this.messageHandler=t,this.loadingTask=e,this.commonObjs=new Oe,this.fontLoader=new Ts({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.destroyed=!1,this.destroyCapability=null,this._networkStream=s,this._fullReader=null,this._lastProgress=null,this.downloadInfoCapability=Promise.withResolvers(),this.setupMessageHandler()}#n(t,e=null){let s=this.#t.get(t);if(s)return s;let i=this.messageHandler.sendWithPromise(t,e);return this.#t.set(t,i),i}get annotationStorage(){return N(this,"annotationStorage",new te)}getRenderingIntent(t,e=St.ENABLE,s=null,i=!1,n=!1){let r=Fi,a=Ms;switch(t){case"any":r=Bn;break;case"display":break;case"print":r=ye;break;default:F(`getRenderingIntent - invalid intent: ${t}`)}let l=r&ye&&s instanceof Ce?s:this.annotationStorage;switch(e){case St.DISABLE:r+=Vn;break;case St.ENABLE:break;case St.ENABLE_FORMS:r+=Hn;break;case St.ENABLE_STORAGE:r+=jn,a=l.serializable;break;default:F(`getRenderingIntent - invalid annotationMode: ${e}`)}i&&(r+=zn),n&&(r+=Gn);let{ids:h,hash:c}=l.modifiedIds;return{renderingIntent:r,cacheKey:[r,a.hash,c].join("_"),annotationStorageSerializable:a,modifiedIds:h}}destroy(){if(this.destroyCapability)return this.destroyCapability.promise;this.destroyed=!0,this.destroyCapability=Promise.withResolvers(),this.#r?.reject(new Error("Worker was destroyed during onPassword callback"));let t=[];for(let s of this.#e.values())t.push(s._destroy());this.#e.clear(),this.#s.clear(),this.#i.clear(),this.hasOwnProperty("annotationStorage")&&this.annotationStorage.resetModified();let 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(),se.cleanup(),this._networkStream?.cancelAllRequests(new gt("Worker was terminated.")),this.messageHandler?.destroy(),this.messageHandler=null,this.destroyCapability.resolve()}),this.destroyCapability.reject),this.destroyCapability.promise}setupMessageHandler(){let{messageHandler:t,loadingTask:e}=this;t.on("GetReader",((s,i)=>{Q(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}){r?i.close():(Q(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;let{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)=>{Q(this._networkStream,"GetRangeReader - no `IPDFStream` instance available.");let n=this._networkStream.getRangeReader(s.begin,s.end);n?(i.onPull=()=>{n.read().then((function({value:r,done:a}){a?i.close():(Q(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}))}):i.close()})),t.on("GetDoc",(({pdfInfo:s})=>{this._numPages=s.numPages,this._htmlForXfa=s.htmlForXfa,delete s.htmlForXfa,e._capability.resolve(new Zs(s,this))})),t.on("DocException",(s=>{e._capability.reject(rt(s))})),t.on("PasswordRequest",(s=>{this.#r=Promise.withResolvers();try{if(!e.onPassword)throw rt(s);let i=n=>{n instanceof Error?this.#r.reject(n):this.#r.resolve({password:n})};e.onPassword(i,s.code)}catch(i){this.#r.reject(i)}return this.#r.promise})),t.on("DataLoaded",(s=>{e.onProgress?.({loaded:s.length,total:s.length}),this.downloadInfoCapability.resolve(s)})),t.on("StartRenderPage",(s=>{this.destroyed||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":let{disableFontFace:r,fontExtraProperties:a,pdfBug:l}=this._params;if("error"in n){let u=n.error;F(`Error during font loading: ${u}`),this.commonObjs.resolve(s,u);break}let h=l&&globalThis.FontInspector?.enabled?(u,f)=>globalThis.FontInspector.fontAdded(u,f):null,c=new Ps(n,{disableFontFace:r,fontExtraProperties:a,inspectFont:h});this.fontLoader.bind(c).catch((()=>t.sendWithPromise("FontFallback",{id:s}))).finally((()=>{!a&&c.data&&(c.data=null),this.commonObjs.resolve(s,c)}));break;case"CopyLocalImage":let{imageRef:d}=n;Q(d,"The imageRef must be defined.");for(let u of this.#e.values())for(let[,f]of u.objs)if(f?.ref===d)return f.dataLen?(this.commonObjs.resolve(s,structuredClone(f)),f.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;let a=this.#e.get(i);if(!a.objs.has(s))if(a._intentStates.size!==0)switch(n){case"Image":a.objs.resolve(s,r),r?.dataLen>1e7&&(a._maybeCleanupAfterRender=!0);break;case"Pattern":a.objs.resolve(s,r);break;default:throw new Error(`Got unknown object type ${n}`)}else r?.bitmap?.close()})),t.on("DocProgress",(s=>{this.destroyed||e.onProgress?.({loaded:s.loaded,total:s.total})})),t.on("FetchBuiltInCMap",(async s=>{if(this.destroyed)throw new Error("Worker was destroyed.");if(!this.cMapReaderFactory)throw new Error("CMapReaderFactory not initialized, see the `useWorkerFetch` parameter.");return this.cMapReaderFactory.fetch(s)})),t.on("FetchStandardFontData",(async s=>{if(this.destroyed)throw new Error("Worker was destroyed.");if(!this.standardFontDataFactory)throw new Error("StandardFontDataFactory not initialized, see the `useWorkerFetch` parameter.");return this.standardFontDataFactory.fetch(s)}))}getData(){return this.messageHandler.sendWithPromise("GetData",null)}saveDocument(){this.annotationStorage.size<=0&&F("saveDocument called while `annotationStorage` is empty, please use the getData-method instead.");let{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."));let e=t-1,s=this.#s.get(e);if(s)return s;let i=this.messageHandler.sendWithPromise("GetPage",{pageIndex:e}).then((n=>{if(this.destroyed)throw new Error("Transport destroyed");n.refStr&&this.#i.set(n.refStr,t);let r=new ti(e,n,this,this._params.pdfBug);return this.#e.set(e,r),r}));return this.#s.set(e,i),i}getPageIndex(t){return ln(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)}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 Bs(e,t)))}getPermissions(){return this.messageHandler.sendWithPromise("GetPermissions",null)}getMetadata(){let t="GetMetadata",e=this.#t.get(t);if(e)return e;let s=this.messageHandler.sendWithPromise(t,null).then((i=>({info:i[0],metadata:i[1]?new Os(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(let 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),se.cleanup()}}cachedPageNumber(t){if(!ln(t))return null;let e=t.gen===0?`${t.num}R`:`${t.num}R${t.gen}`;return this.#i.get(e)??null}},Ut=Symbol("INITIAL_DATA"),Oe=class{#t=Object.create(null);#e(t){return this.#t[t]||={...Promise.withResolvers(),data:Ut}}get(t,e=null){if(e){let i=this.#e(t);return i.promise.then((()=>e(i.data))),null}let s=this.#t[t];if(!s||s.data===Ut)throw new Error(`Requesting object that isn't resolved yet ${t}.`);return s.data}has(t){let e=this.#t[t];return!!e&&e.data!==Ut}delete(t){let e=this.#t[t];return!e||e.data===Ut?!1:(delete this.#t[t],!0)}resolve(t,e=null){let s=this.#e(t);s.data=e,s.resolve()}clear(){for(let t in this.#t){let{data:e}=this.#t[t];e?.bitmap?.close()}this.#t=Object.create(null)}*[Symbol.iterator](){for(let t in this.#t){let{data:e}=this.#t[t];e!==Ut&&(yield[t,e])}}},ii=class{#t=null;constructor(t){this.#t=t,this.onContinue=null}get promise(){return this.#t.capability.promise}cancel(t=0){this.#t.cancel(null,t)}get separateAnnots(){let{separateAnnots:t}=this.#t.operatorList;if(!t)return!1;let{annotationCanvasMap:e}=this.#t;return t.form||t.canvas&&e?.size>0}},ni=class o{#t=null;static#e=new WeakSet;constructor({callback:t,params:e,objs:s,commonObjs:i,annotationCanvasMap:n,operatorList:r,pageIndex:a,canvasFactory:l,filterFactory:h,useRequestAnimationFrame:c=!1,pdfBug:d=!1,pageColors:u=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=l,this.filterFactory=h,this._pdfBug=d,this.pageColors=u,this.running=!1,this.graphicsReadyCallback=null,this.graphicsReady=!1,this._useRequestAnimationFrame=c===!0&&typeof window<"u",this.cancelled=!1,this.capability=Promise.withResolvers(),this.task=new ii(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.canvasContext.canvas}get completed(){return this.capability.promise.catch((function(){}))}initializeGraphics({transparency:t=!1,optionalContentConfig:e}){if(this.cancelled)return;if(this._canvas){if(o.#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.");o.#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());let{canvasContext:s,viewport:i,transform:n,background:r}=this.params;this.gfx=new Bt(s,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:e},this.annotationCanvasMap,this.pageColors),this.gfx.beginDrawing({transform:n,viewport:i,transparency:t,background:r}),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),o.#e.delete(this._canvas),this.callback(t||new Jt(`Rendering cancelled, page ${this._pageIndex+1}`,e))}operatorListChanged(){this.graphicsReady?(this.stepper?.updateOperatorList(this.operatorList),this.running||this._continue()):this.graphicsReadyCallback||=this._continueBound}_continue(){this.running=!0,this.cancelled||(this.task.onContinue?this.task.onContinue(this._scheduleNextBound):this._scheduleNext())}_scheduleNext(){this._useRequestAnimationFrame?this.#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.operatorListIdx===this.operatorList.argsArray.length&&(this.running=!1,this.operatorList.lastChunk&&(this.gfx.endDrawing(),o.#e.delete(this._canvas),this.callback())))}},$r="4.10.38",Br="f9bea397f";function hn(o){return Math.floor(255*Math.max(0,Math.min(1,o))).toString(16).padStart(2,"0")}function qt(o){return Math.max(0,Math.min(255,255*o))}var $e=class{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=qt(t),t,t]}static G_HTML([t]){let e=hn(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(qt)}static RGB_HTML(t){return`#${t.map(hn).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[qt(1-Math.min(1,t+i)),qt(1-Math.min(1,s+i)),qt(1-Math.min(1,e+i))]}static CMYK_HTML(t){let e=this.CMYK_RGB(t).slice(1);return this.RGB_HTML(e)}static RGB_CMYK([t,e,s]){let i=1-t,n=1-e,r=1-s;return["CMYK",i,n,r,Math.min(i,n,r)]}},ri=class{create(t,e,s=!1){if(t<=0||e<=0)throw new Error("Invalid SVG dimensions");let 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){z("Abstract method `_createSVG` called.")}},ne=class extends ri{_createSVG(t){return document.createElementNS(At,t)}},Be=class{static setupStorage(t,e,s,i,n){let 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(let 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=>{let l=a.target.options,h=l.selectedIndex===-1?"":l[l.selectedIndex].value;i.setValue(e,{value:h})}))}}static setAttributes({html:t,element:e,storage:s=null,intent:i,linkService:n}){let{attributes:r}=e,a=t instanceof HTMLAnchorElement;r.type==="radio"&&(r.name=`${r.name}-${i}`);for(let[l,h]of Object.entries(r))if(h!=null)switch(l){case"class":h.length&&t.setAttribute(l,h.join(" "));break;case"dataId":break;case"id":t.setAttribute("data-element-id",h);break;case"style":Object.assign(t.style,h);break;case"textContent":t.textContent=h;break;default:(!a||l!=="href"&&l!=="newWindow")&&t.setAttribute(l,h)}a&&n.addLinkAttributes(t,r.href,r.newWindow),s&&r.dataId&&this.setupStorage(t,r.dataId,e,s)}static render(t){let 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});let a=n!=="richText",l=t.div;if(l.append(r),t.viewport){let d=`matrix(${t.viewport.transform.join(",")})`;l.style.transform=d}a&&l.setAttribute("class","xfaLayer xfaFont");let h=[];if(i.children.length===0){if(i.value){let d=document.createTextNode(i.value);r.append(d),a&&ie.shouldBuildText(i.name)&&h.push(d)}return{textDivs:h}}let c=[[i,-1,r]];for(;c.length>0;){let[d,u,f]=c.at(-1);if(u+1===d.children.length){c.pop();continue}let p=d.children[++c.at(-1)[1]];if(p===null)continue;let{name:g}=p;if(g==="#text"){let b=document.createTextNode(p.value);h.push(b),f.append(b);continue}let m=p?.attributes?.xmlns?document.createElementNS(p.attributes.xmlns,g):document.createElement(g);if(f.append(m),p.attributes&&this.setAttributes({html:m,element:p,storage:e,intent:n,linkService:s}),p.children?.length>0)c.push([p,-1,m]);else if(p.value){let b=document.createTextNode(p.value);a&&ie.shouldBuildText(g)&&h.push(b),m.append(b)}}for(let d of l.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea"))d.setAttribute("readOnly",!0);return{textDivs:h}}static update(t){let e=`matrix(${t.viewport.transform.join(",")})`;t.div.style.transform=e,t.div.hidden=!1}},he=1e3,Nt=new WeakSet;function Et(o){return{width:o[2]-o[0],height:o[3]-o[1]}}var ai=class{static create(t){switch(t.data.annotationType){case Yn:return new He(t);case Xn:return new oi(t);case cr:switch(t.data.fieldType){case"Tx":return new li(t);case"Btn":return t.data.radioButton?new je(t):t.data.checkBox?new ci(t):new di(t);case"Ch":return new ui(t);case"Sig":return new hi(t)}return new vt(t);case dn:return new re(t);case Kn:return new Ve(t);case Qn:return new pi(t);case Jn:return new gi(t);case Zn:return new mi(t);case er:return new ze(t);case or:return new yi(t);case lr:return new ae(t);case tr:return new bi(t);case sr:return new Ge(t);case ir:return new wi(t);case nr:return new Ai(t);case rr:return new vi(t);case ar:return new Ue(t);case hr:return new _i(t);default:return new K(t)}}},K=class o{#t=null;#e=!1;#s=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.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({titleObj:t,contentsObj:e,richText:s}){return!!(t?.str||e?.str||s?.str)}get _isEditable(){return this.data.isEditable}get hasPopupData(){return o._hasPopupData(this.data)}updateEdited(t){if(!this.container)return;this.#t||={rect:this.data.rect.slice(0)};let{rect:e}=t;e&&this.#i(e),this.#s?.popup.updateEdited(t)}resetEdited(){this.#t&&(this.#i(this.#t.rect),this.#s?.popup.resetEdited(),this.#t=null)}#i(t){let{container:{style:e},data:{rect:s,rotation:i},parent:{viewport:{rawDims:{pageWidth:n,pageHeight:r,pageX:a,pageY:l}}}}=this;s?.splice(0,4,...t);let{width:h,height:c}=Et(t);e.left=100*(t[0]-a)/n+"%",e.top=100*(r-t[3]+l)/r+"%",i===0?(e.width=100*h/n+"%",e.height=100*c/r+"%"):this.setRotation(i)}_createContainer(t){let{data:e,parent:{page:s,viewport:i}}=this,n=document.createElement("section");n.setAttribute("data-annotation-id",e.id),this instanceof vt||(n.tabIndex=he);let{style:r}=n;if(r.zIndex=this.parent.zIndex++,e.alternativeText&&(n.title=e.alternativeText),e.noRotate&&n.classList.add("norotate"),!e.rect||this instanceof re){let{rotation:g}=e;return e.hasOwnCanvas||g===0||this.setRotation(g,n),n}let{width:a,height:l}=Et(e.rect);if(!t&&e.borderStyle.width>0){r.borderWidth=`${e.borderStyle.width}px`;let g=e.borderStyle.horizontalCornerRadius,m=e.borderStyle.verticalCornerRadius;if(g>0||m>0){let y=`calc(${g}px * var(--scale-factor)) / calc(${m}px * var(--scale-factor))`;r.borderRadius=y}else if(this instanceof je){let y=`calc(${a}px * var(--scale-factor)) / calc(${l}px * var(--scale-factor))`;r.borderRadius=y}switch(e.borderStyle.style){case dr:r.borderStyle="solid";break;case ur:r.borderStyle="dashed";break;case fr:F("Unimplemented border style: beveled");break;case pr:F("Unimplemented border style: inset");break;case gr:r.borderBottomStyle="solid"}let b=e.borderColor||null;b?(this.#e=!0,r.borderColor=k.makeHexColor(0|b[0],0|b[1],0|b[2])):r.borderWidth=0}let h=k.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:c,pageHeight:d,pageX:u,pageY:f}=i.rawDims;r.left=100*(h[0]-u)/c+"%",r.top=100*(h[1]-f)/d+"%";let{rotation:p}=e;return e.hasOwnCanvas||p===0?(r.width=100*a/c+"%",r.height=100*l/d+"%"):this.setRotation(p,n),n}setRotation(t,e=this.container){if(!this.data.rect)return;let{pageWidth:s,pageHeight:i}=this.parent.viewport.rawDims,{width:n,height:r}=Et(this.data.rect),a,l;t%180==0?(a=100*n/s,l=100*r/i):(a=100*r/s,l=100*n/i),e.style.width=`${a}%`,e.style.height=`${l}%`,e.setAttribute("data-main-rotation",(360-t)%360)}get _commonActions(){let t=(e,s,i)=>{let n=i.detail[e],r=n[0],a=n.slice(1);i.target.style[s]=$e[`${r}_HTML`](a),this.annotationStorage.setValue(this.data.id,{[s]:$e[`${r}_rgb`](a)})};return N(this,"_commonActions",{display:e=>{let{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=>{let{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=>{let s=e.detail.rotation;this.setRotation(s),this.annotationStorage.setValue(this.data.id,{rotation:s})}})}_dispatchEventFromSandbox(t,e){let s=this._commonActions;for(let i of Object.keys(e.detail))(t[i]||s[i])?.(e)}_setDefaultPropertiesFromJS(t){if(!this.enableScripting)return;let e=this.annotationStorage.getRawValue(this.data.id);if(!e)return;let s=this._commonActions;for(let[i,n]of Object.entries(e)){let r=s[i];r&&(r({detail:{[i]:n},target:t}),delete e[i])}}_createQuadrilaterals(){if(!this.container)return;let{quadPoints:t}=this.data;if(!t)return;let[e,s,i,n]=this.data.rect.map((g=>Math.fround(g)));if(t.length===8){let[g,m,b,y]=t.subarray(2,6);if(i===g&&n===m&&e===b&&s===y)return}let{style:r}=this.container,a;if(this.#e){let{borderColor:g,borderWidth:m}=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="${g}" stroke-width="${m}">`],this.container.classList.add("hasBorder")}let l=i-e,h=n-s,{svgFactory:c}=this,d=c.createElement("svg");d.classList.add("quadrilateralsContainer"),d.setAttribute("width",0),d.setAttribute("height",0);let u=c.createElement("defs");d.append(u);let f=c.createElement("clipPath"),p=`clippath_${this.data.id}`;f.setAttribute("id",p),f.setAttribute("clipPathUnits","objectBoundingBox"),u.append(f);for(let g=2,m=t.length;g<m;g+=8){let b=t[g],y=t[g+1],w=t[g+2],A=t[g+3],_=c.createElement("rect"),x=(w-e)/l,v=(n-y)/h,C=(b-w)/l,M=(y-A)/h;_.setAttribute("x",x),_.setAttribute("y",v),_.setAttribute("width",C),_.setAttribute("height",M),f.append(_),a?.push(`<rect vector-effect="non-scaling-stroke" x="${x}" y="${v}" width="${C}" height="${M}"/>`)}this.#e&&(a.push("</g></svg>')"),r.backgroundImage=a.join("")),this.container.append(d),this.container.style.clipPath=`url(#${p})`}_createPopup(){let{data:t}=this,e=this.#s=new re({data:{color:t.color,titleObj:t.titleObj,modificationDate:t.modificationDate,contentsObj:t.contentsObj,richText:t.richText,parentRect:t.rect,borderStyle:0,id:`popup_${t.id}`,rotation:t.rotation},parent:this.parent,elements:[this]});this.parent.div.append(e.render())}render(){z("Abstract method `AnnotationElement.render` called")}_getElementsByName(t,e=null){let s=[];if(this._fieldObjects){let i=this._fieldObjects[t];if(i)for(let{page:n,id:r,exportValues:a}of i){if(n===-1||r===e)continue;let l=typeof a=="string"?a:null,h=document.querySelector(`[data-element-id="${r}"]`);!h||Nt.has(h)?s.push({id:r,exportValue:l,domElement:h}):F(`_getElementsByName - element not allowed: ${r}`)}return s}for(let i of document.getElementsByName(t)){let{exportValue:n}=i,r=i.getAttribute("data-element-id");r!==e&&Nt.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(){let t=this.getElementsToTriggerPopup();if(Array.isArray(t))for(let e of t)e.classList.add("highlightArea");else t.classList.add("highlightArea")}_editOnDoubleClick(){if(!this._isEditable)return;let{annotationEditorType:t,data:{id:e}}=this;this.container.addEventListener("dblclick",(()=>{this.linkService.eventBus?.dispatch("switchannotationeditormode",{source:this,mode:t,editId:e})}))}},He=class extends K{constructor(t,e=null){super(t,{isRenderable:!0,ignoreBorder:!!e?.ignoreBorder,createQuadrilaterals:!0}),this.isTooltipOnly=t.data.isTooltipOnly}render(){let{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),i=!0):t.attachment?(this.#e(s,t.attachment,t.attachmentDest),i=!0):t.setOCGState?(this.#s(s,t.setOCGState),i=!0):t.dest?(this._bindLink(s,t.dest),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){t.href=this.linkService.getDestinationHash(e),t.onclick=()=>(e&&this.linkService.goToDestination(e),!1),(e||e==="")&&this.#t()}_bindNamedAction(t,e){t.href=this.linkService.getAnchorUrl(""),t.onclick=()=>(this.linkService.executeNamedAction(e),!1),this.#t()}#e(t,e,s=null){t.href=this.linkService.getAnchorUrl(""),e.description&&(t.title=e.description),t.onclick=()=>(this.downloadManager?.openOrDownloadData(e.content,e.filename,s),!1),this.#t()}#s(t,e){t.href=this.linkService.getAnchorUrl(""),t.onclick=()=>(this.linkService.executeSetOCGState(e),!1),this.#t()}_bindJSAction(t,e){t.href=this.linkService.getAnchorUrl("");let s=new Map([["Action","onclick"],["Mouse Up","onmouseup"],["Mouse Down","onmousedown"]]);for(let i of Object.keys(e.actions)){let n=s.get(i);n&&(t[n]=()=>(this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e.id,name:i}}),!1))}t.onclick||(t.onclick=()=>!1),this.#t()}_bindResetFormAction(t,e){let s=t.onclick;s||(t.href=this.linkService.getAnchorUrl("")),this.#t(),this._fieldObjects?t.onclick=()=>{s?.();let{fields:i,refs:n,include:r}=e,a=[];if(i.length!==0||n.length!==0){let c=new Set(n);for(let d of i){let u=this._fieldObjects[d]||[];for(let{id:f}of u)c.add(f)}for(let d of Object.values(this._fieldObjects))for(let u of d)c.has(u.id)===r&&a.push(u)}else for(let c of Object.values(this._fieldObjects))a.push(...c);let l=this.annotationStorage,h=[];for(let c of a){let{id:d}=c;switch(h.push(d),c.type){case"text":{let f=c.defaultValue||"";l.setValue(d,{value:f});break}case"checkbox":case"radiobutton":{let f=c.defaultValue===c.exportValues;l.setValue(d,{value:f});break}case"combobox":case"listbox":{let f=c.defaultValue||"";l.setValue(d,{value:f});break}default:continue}let u=document.querySelector(`[data-element-id="${d}"]`);u&&(Nt.has(u)?u.dispatchEvent(new Event("resetform")):F(`_bindResetFormAction - element not allowed: ${d}`))}return this.enableScripting&&this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:"app",ids:h,name:"ResetForm"}}),!1}:(F('_bindResetFormAction - "resetForm" action not supported, ensure that the `fieldObjects` parameter is provided.'),s||(t.onclick=()=>!1))}},oi=class extends K{constructor(t){super(t,{isRenderable:!0})}render(){this.container.classList.add("textAnnotation");let 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}},vt=class extends K{render(){return this.container}showElementAndHideCanvas(t){this.data.hasOwnCanvas&&(t.previousSibling?.nodeName==="CANVAS"&&(t.previousSibling.hidden=!0),t.hidden=!1)}_getKeyModifier(t){return Z.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(let[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?r!=="Blur"||this.data.actions?.Focus||this._setEventListener(t,e,"focus","Focus",null):this._setEventListener(t,e,"blur","Blur",null))}_setBackgroundColor(t){let e=this.data.backgroundColor||null;t.style.backgroundColor=e===null?"transparent":k.makeHexColor(e[0],e[1],e[2])}_setTextStyle(t){let e=["left","center","right"],{fontColor:s}=this.data.defaultAppearanceData,i=this.data.defaultAppearanceData.fontSize||9,n=t.style,r,a=l=>Math.round(10*l)/10;if(this.data.multiLine){let l=Math.abs(this.data.rect[3]-this.data.rect[1]-2),h=l/(Math.round(l/(cs*i))||1);r=Math.min(i,a(h/cs))}else{let l=Math.abs(this.data.rect[3]-this.data.rect[1]-2);r=Math.min(i,a(l/cs))}n.fontSize=`calc(${r}px * var(--scale-factor))`,n.color=k.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)}},li=class extends vt{constructor(t){super(t,{isRenderable:t.renderForms||t.data.hasOwnCanvas||!t.data.hasAppearance&&!!t.data.fieldValue})}setPropertyOnSiblings(t,e,s,i){let n=this.annotationStorage;for(let r of this._getElementsByName(t.name,t.id))r.domElement&&(r.domElement[e]=s),n.setValue(r.id,{[i]:s})}render(){let t=this.annotationStorage,e=this.data.id;this.container.classList.add("textWidgetAnnotation");let s=null;if(this.renderForms){let i=t.getValue(e,{value:this.data.fieldValue}),n=i.value||"",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
|
+
`)||null;a&&this.data.comb&&(a=a.replaceAll(/\s+/g,""));let l={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="text",s.setAttribute("value",a??n),this.data.doNotScroll&&(s.style.overflowX="hidden")),this.data.hasOwnCanvas&&(s.hidden=!0),Nt.add(s),s.setAttribute("data-element-id",e),s.disabled=this.data.readOnly,s.name=this.data.fieldName,s.tabIndex=he,this._setRequired(s,this.data.required),r&&(s.maxLength=r),s.addEventListener("input",(c=>{t.setValue(e,{value:c.target.value}),this.setPropertyOnSiblings(s,"value",c.target.value,"value"),l.formattedValue=null})),s.addEventListener("resetform",(c=>{let d=this.data.defaultFieldValue??"";s.value=l.userValue=d,l.formattedValue=null}));let h=c=>{let{formattedValue:d}=l;d!=null&&(c.target.value=d),c.target.scrollLeft=0};if(this.enableScripting&&this.hasJSActions){s.addEventListener("focus",(d=>{if(l.focused)return;let{target:u}=d;l.userValue&&(u.value=l.userValue),l.lastCommittedValue=u.value,l.commitKey=1,this.data.actions?.Focus||(l.focused=!0)})),s.addEventListener("updatefromsandbox",(d=>{this.showElementAndHideCanvas(d.target);let u={value(f){l.userValue=f.detail.value??"",t.setValue(e,{value:l.userValue.toString()}),f.target.value=l.userValue},formattedValue(f){let{formattedValue:p}=f.detail;l.formattedValue=p,p!=null&&f.target!==document.activeElement&&(f.target.value=p),t.setValue(e,{formattedValue:p})},selRange(f){f.target.setSelectionRange(...f.detail.selRange)},charLimit:f=>{let{charLimit:p}=f.detail,{target:g}=f;if(p===0){g.removeAttribute("maxLength");return}g.setAttribute("maxLength",p);let m=l.userValue;m&&!(m.length<=p)&&(m=m.slice(0,p),g.value=l.userValue=m,t.setValue(e,{value:m}),this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:m,willCommit:!0,commitKey:1,selStart:g.selectionStart,selEnd:g.selectionEnd}}))}};this._dispatchEventFromSandbox(u,d)})),s.addEventListener("keydown",(d=>{l.commitKey=1;let u=-1;if(d.key==="Escape"?u=0:d.key!=="Enter"||this.data.multiLine?d.key==="Tab"&&(l.commitKey=3):u=2,u===-1)return;let{value:f}=d.target;l.lastCommittedValue!==f&&(l.lastCommittedValue=f,l.userValue=f,this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:f,willCommit:!0,commitKey:u,selStart:d.target.selectionStart,selEnd:d.target.selectionEnd}}))}));let c=h;h=null,s.addEventListener("blur",(d=>{if(!l.focused||!d.relatedTarget)return;this.data.actions?.Blur||(l.focused=!1);let{value:u}=d.target;l.userValue=u,l.lastCommittedValue!==u&&this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:u,willCommit:!0,commitKey:l.commitKey,selStart:d.target.selectionStart,selEnd:d.target.selectionEnd}}),c(d)})),this.data.actions?.Keystroke&&s.addEventListener("beforeinput",(d=>{l.lastCommittedValue=null;let{data:u,target:f}=d,{value:p,selectionStart:g,selectionEnd:m}=f,b=g,y=m;switch(d.inputType){case"deleteWordBackward":{let w=p.substring(0,g).match(/\w*[^\w]*$/);w&&(b-=w[0].length);break}case"deleteWordForward":{let w=p.substring(g).match(/^[^\w]*\w*/);w&&(y+=w[0].length);break}case"deleteContentBackward":g===m&&(b-=1);break;case"deleteContentForward":g===m&&(y+=1)}d.preventDefault(),this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:p,change:u||"",willCommit:!1,selStart:b,selEnd:y}})})),this._setEventListeners(s,l,[["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],(d=>d.target.value))}if(h&&s.addEventListener("blur",h),this.data.comb){let c=(this.data.rect[2]-this.data.rect[0])/r;s.classList.add("comb"),s.style.letterSpacing=`calc(${c}px * var(--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}},hi=class extends vt{constructor(t){super(t,{isRenderable:!!t.data.hasOwnCanvas})}},ci=class extends vt{constructor(t){super(t,{isRenderable:t.renderForms})}render(){let t=this.annotationStorage,e=this.data,s=e.id,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");let n=document.createElement("input");return Nt.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=he,n.addEventListener("change",(r=>{let{name:a,checked:l}=r.target;for(let h of this._getElementsByName(a,s)){let c=l&&h.exportValue===e.exportValue;h.domElement&&(h.domElement.checked=c),t.setValue(h.id,{value:c})}t.setValue(s,{value:l})})),n.addEventListener("resetform",(r=>{let a=e.defaultFieldValue||"Off";r.target.checked=a===e.exportValue})),this.enableScripting&&this.hasJSActions&&(n.addEventListener("updatefromsandbox",(r=>{let a={value(l){l.target.checked=l.detail.value!=="Off",t.setValue(s,{value:l.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}},je=class extends vt{constructor(t){super(t,{isRenderable:t.renderForms})}render(){this.container.classList.add("buttonWidgetAnnotation","radioButton");let t=this.annotationStorage,e=this.data,s=e.id,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(let r of this._getElementsByName(e.fieldName,s))t.setValue(r.id,{value:!1});let n=document.createElement("input");if(Nt.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=he,n.addEventListener("change",(r=>{let{name:a,checked:l}=r.target;for(let h of this._getElementsByName(a,s))t.setValue(h.id,{value:!1});t.setValue(s,{value:l})})),n.addEventListener("resetform",(r=>{let a=e.defaultFieldValue;r.target.checked=a!=null&&a===e.buttonValue})),this.enableScripting&&this.hasJSActions){let r=e.buttonValue;n.addEventListener("updatefromsandbox",(a=>{let l={value:h=>{let c=r===h.detail.value;for(let d of this._getElementsByName(h.target.name)){let u=c&&d.id===s;d.domElement&&(d.domElement.checked=u),t.setValue(d.id,{value:u})}}};this._dispatchEventFromSandbox(l,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}},di=class extends He{constructor(t){super(t,{ignoreBorder:t.data.hasAppearance})}render(){let t=super.render();t.classList.add("buttonWidgetAnnotation","pushButton");let e=t.lastChild;return this.enableScripting&&this.hasJSActions&&e&&(this._setDefaultPropertiesFromJS(e),e.addEventListener("updatefromsandbox",(s=>{this._dispatchEventFromSandbox({},s)}))),t}},ui=class extends vt{constructor(t){super(t,{isRenderable:t.renderForms})}render(){this.container.classList.add("choiceWidgetAnnotation");let t=this.annotationStorage,e=this.data.id,s=t.getValue(e,{value:this.data.fieldValue}),i=document.createElement("select");Nt.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=he;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",(c=>{let d=this.data.defaultFieldValue;for(let u of i.options)u.selected=u.value===d}));for(let c of this.data.options){let d=document.createElement("option");d.textContent=c.displayValue,d.value=c.exportValue,s.value.includes(c.exportValue)&&(d.setAttribute("selected",!0),n=!1),i.append(d)}let r=null;if(n){let c=document.createElement("option");c.value=" ",c.setAttribute("hidden",!0),c.setAttribute("selected",!0),i.prepend(c),r=()=>{c.remove(),i.removeEventListener("input",r),r=null},i.addEventListener("input",r)}let a=c=>{let d=c?"value":"textContent",{options:u,multiple:f}=i;return f?Array.prototype.filter.call(u,(p=>p.selected)).map((p=>p[d])):u.selectedIndex===-1?null:u[u.selectedIndex][d]},l=a(!1),h=c=>{let d=c.target.options;return Array.prototype.map.call(d,(u=>({displayValue:u.textContent,exportValue:u.value})))};return this.enableScripting&&this.hasJSActions?(i.addEventListener("updatefromsandbox",(c=>{let d={value(u){r?.();let f=u.detail.value,p=new Set(Array.isArray(f)?f:[f]);for(let g of i.options)g.selected=p.has(g.value);t.setValue(e,{value:a(!0)}),l=a(!1)},multipleSelection(u){i.multiple=!0},remove(u){let f=i.options,p=u.detail.remove;f[p].selected=!1,i.remove(p),f.length>0&&Array.prototype.findIndex.call(f,(g=>g.selected))===-1&&(f[0].selected=!0),t.setValue(e,{value:a(!0),items:h(u)}),l=a(!1)},clear(u){for(;i.length!==0;)i.remove(0);t.setValue(e,{value:null,items:[]}),l=a(!1)},insert(u){let{index:f,displayValue:p,exportValue:g}=u.detail.insert,m=i.children[f],b=document.createElement("option");b.textContent=p,b.value=g,m?m.before(b):i.append(b),t.setValue(e,{value:a(!0),items:h(u)}),l=a(!1)},items(u){let{items:f}=u.detail;for(;i.length!==0;)i.remove(0);for(let p of f){let{displayValue:g,exportValue:m}=p,b=document.createElement("option");b.textContent=g,b.value=m,i.append(b)}i.options.length>0&&(i.options[0].selected=!0),t.setValue(e,{value:a(!0),items:h(u)}),l=a(!1)},indices(u){let f=new Set(u.detail.indices);for(let p of u.target.options)p.selected=f.has(p.index);t.setValue(e,{value:a(!0)}),l=a(!1)},editable(u){u.target.disabled=!u.detail.editable}};this._dispatchEventFromSandbox(d,c)})),i.addEventListener("input",(c=>{let d=a(!0),u=a(!1);t.setValue(e,{value:d}),c.preventDefault(),this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:l,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"]],(c=>c.target.value))):i.addEventListener("input",(function(c){t.setValue(e,{value:a(!0)})})),this.data.combo&&this._setTextStyle(i),this._setBackgroundColor(i),this._setDefaultPropertiesFromJS(i),this.container.append(i),this.container}},re=class extends K{constructor(t){let{data:e,elements:s}=t;super(t,{isRenderable:K._hasPopupData(e)}),this.elements=s,this.popup=null}render(){this.container.classList.add("popupAnnotation");let t=this.popup=new fi({container:this.container,color:this.data.color,titleObj:this.data.titleObj,modificationDate:this.data.modificationDate,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}),e=[];for(let s of this.elements)s.popup=t,s.container.ariaHasPopup="dialog",e.push(s.data.id),s.addHighlightArea();return this.container.setAttribute("aria-controls",e.map((s=>`${Oi}${s}`)).join(",")),this.container}},fi=class{#t=this.#k.bind(this);#e=this.#C.bind(this);#s=this.#M.bind(this);#i=this.#_.bind(this);#r=null;#n=null;#l=null;#o=null;#c=null;#h=null;#u=null;#d=!1;#f=null;#a=null;#p=null;#m=null;#g=null;#b=null;#A=!1;constructor({container:t,color:e,elements:s,titleObj:i,modificationDate:n,contentsObj:r,richText:a,parent:l,rect:h,parentRect:c,open:d}){this.#n=t,this.#g=i,this.#l=r,this.#m=a,this.#h=l,this.#r=e,this.#p=h,this.#u=c,this.#c=s,this.#o=ve.toDateObject(n),this.trigger=s.flatMap((u=>u.getElementsToTriggerPopup()));for(let u of this.trigger)u.addEventListener("click",this.#i),u.addEventListener("mouseenter",this.#s),u.addEventListener("mouseleave",this.#e),u.classList.add("popupTriggerArea");for(let u of s)u.container?.addEventListener("keydown",this.#t);this.#n.hidden=!0,d&&this.#_()}render(){if(this.#f)return;let t=this.#f=document.createElement("div");if(t.className="popup",this.#r){let n=t.style.outlineColor=k.makeHexColor(...this.#r);CSS.supports("background-color","color-mix(in srgb, red 30%, white)")?t.style.backgroundColor=`color-mix(in srgb, ${n} 30%, white)`:t.style.backgroundColor=k.makeHexColor(...this.#r.map((a=>Math.floor(.7*(255-a)+a))))}let e=document.createElement("span");e.className="header";let s=document.createElement("h1");if(e.append(s),{dir:s.dir,str:s.textContent}=this.#g,t.append(e),this.#o){let n=document.createElement("span");n.classList.add("popupDate"),n.setAttribute("data-l10n-id","pdfjs-annotation-date-time-string"),n.setAttribute("data-l10n-args",JSON.stringify({dateObj:this.#o.valueOf()})),e.append(n)}let i=this.#y;if(i)Be.render({xfaHtml:i,intent:"richText",div:t}),t.lastChild.classList.add("richText","popupContent");else{let n=this._formatContents(this.#l);t.append(n)}this.#n.append(t)}get#y(){let t=this.#m,e=this.#l;return!t?.str||e?.str&&e.str!==t.str?null:this.#m.html||null}get#v(){return this.#y?.attributes?.style?.fontSize||0}get#x(){return this.#y?.attributes?.style?.color||null}#E(t){let e=[],s={str:t,html:{name:"div",attributes:{dir:"auto"},children:[{name:"p",children:e}]}},i={style:{color:this.#x,fontSize:this.#v?`calc(${this.#v}px * var(--scale-factor))`:""}};for(let n of t.split(`
|
|
4
|
+
`))e.push({name:"span",value:n,attributes:i});return s}_formatContents({str:t,dir:e}){let s=document.createElement("p");s.classList.add("popupContent"),s.dir=e;let i=t.split(/(?:\r\n?|\n)/);for(let n=0,r=i.length;n<r;++n){let a=i[n];s.append(document.createTextNode(a)),n<r-1&&s.append(document.createElement("br"))}return s}#k(t){t.altKey||t.shiftKey||t.ctrlKey||t.metaKey||(t.key==="Enter"||t.key==="Escape"&&this.#d)&&this.#_()}updateEdited({rect:t,popupContent:e}){this.#b||={contentsObj:this.#l,richText:this.#m},t&&(this.#a=null),e&&(this.#m=this.#E(e),this.#l=null),this.#f?.remove(),this.#f=null}resetEdited(){this.#b&&({contentsObj:this.#l,richText:this.#m}=this.#b,this.#b=null,this.#f?.remove(),this.#f=null,this.#a=null)}#T(){if(this.#a!==null)return;let{page:{view:t},viewport:{rawDims:{pageWidth:e,pageHeight:s,pageX:i,pageY:n}}}=this.#h,r=!!this.#u,a=r?this.#u:this.#p;for(let f of this.#c)if(!a||k.intersect(f.data.rect,a)!==null){a=f.data.rect,r=!0;break}let l=k.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,c=l[0]+h,d=l[1];this.#a=[100*(c-i)/e,100*(d-n)/s];let{style:u}=this.#n;u.left=`${this.#a[0]}%`,u.top=`${this.#a[1]}%`}#_(){this.#d=!this.#d,this.#d?(this.#M(),this.#n.addEventListener("click",this.#i),this.#n.addEventListener("keydown",this.#t)):(this.#C(),this.#n.removeEventListener("click",this.#i),this.#n.removeEventListener("keydown",this.#t))}#M(){this.#f||this.render(),this.isVisible?this.#d&&this.#n.classList.add("focused"):(this.#T(),this.#n.hidden=!1,this.#n.style.zIndex=parseInt(this.#n.style.zIndex)+1e3)}#C(){this.#n.classList.remove("focused"),!this.#d&&this.isVisible&&(this.#n.hidden=!0,this.#n.style.zIndex=parseInt(this.#n.style.zIndex)-1e3)}forceHide(){this.#A=this.isVisible,this.#A&&(this.#n.hidden=!0)}maybeShow(){this.#A&&(this.#f||this.#M(),this.#A=!1,this.#n.hidden=!1)}get isVisible(){return this.#n.hidden===!1}},Ve=class extends K{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.textContent=t.data.textContent,this.textPosition=t.data.textPosition,this.annotationEditorType=D.FREETEXT}render(){if(this.container.classList.add("freeTextAnnotation"),this.textContent){let t=document.createElement("div");t.classList.add("annotationTextContent"),t.setAttribute("role","comment");for(let e of this.textContent){let 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}},pi=class extends K{#t=null;constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){this.container.classList.add("lineAnnotation");let t=this.data,{width:e,height:s}=Et(t.rect),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")}},gi=class extends K{#t=null;constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){this.container.classList.add("squareAnnotation");let t=this.data,{width:e,height:s}=Et(t.rect),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")}},mi=class extends K{#t=null;constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){this.container.classList.add("circleAnnotation");let t=this.data,{width:e,height:s}=Et(t.rect),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")}},ze=class extends K{#t=null;constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.containerClassName="polylineAnnotation",this.svgElementName="svg:polyline"}render(){this.container.classList.add(this.containerClassName);let{data:{rect:t,vertices:e,borderStyle:s,popupRef:i}}=this;if(!e)return this.container;let{width:n,height:r}=Et(t),a=this.svgFactory.create(n,r,!0),l=[];for(let c=0,d=e.length;c<d;c+=2){let u=e[c]-t[0],f=t[3]-e[c+1];l.push(`${u},${f}`)}l=l.join(" ");let h=this.#t=this.svgFactory.createElement(this.svgElementName);return h.setAttribute("points",l),h.setAttribute("stroke-width",s.width||1),h.setAttribute("stroke","transparent"),h.setAttribute("fill","transparent"),a.append(h),this.container.append(a),!i&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return this.#t}addHighlightArea(){this.container.classList.add("highlightArea")}},bi=class extends ze{constructor(t){super(t),this.containerClassName="polygonAnnotation",this.svgElementName="svg:polygon"}},yi=class extends K{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){return this.container.classList.add("caretAnnotation"),!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container}},ae=class extends K{#t=null;#e=[];constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.containerClassName="inkAnnotation",this.svgElementName="svg:polyline",this.annotationEditorType=this.data.it==="InkHighlight"?D.HIGHLIGHT:D.INK}#s(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);let{data:{rect:t,rotation:e,inkLists:s,borderStyle:i,popupRef:n}}=this,{transform:r,width:a,height:l}=this.#s(e,t),h=this.svgFactory.create(a,l,!0),c=this.#t=this.svgFactory.createElement("svg:g");h.append(c),c.setAttribute("stroke-width",i.width||1),c.setAttribute("stroke-linecap","round"),c.setAttribute("stroke-linejoin","round"),c.setAttribute("stroke-miterlimit",10),c.setAttribute("stroke","transparent"),c.setAttribute("fill","transparent"),c.setAttribute("transform",r);for(let d=0,u=s.length;d<u;d++){let f=this.svgFactory.createElement(this.svgElementName);this.#e.push(f),f.setAttribute("points",s[d].join(",")),c.append(f)}return!n&&this.hasPopupData&&this._createPopup(),this.container.append(h),this._editOnDoubleClick(),this.container}updateEdited(t){super.updateEdited(t);let{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){let{transform:r,width:a,height:l}=this.#s(this.data.rotation,i);n.parentElement.setAttribute("viewBox",`0 0 ${a} ${l}`),n.setAttribute("transform",r)}}getElementsToTriggerPopup(){return this.#e}addHighlightArea(){this.container.classList.add("highlightArea")}},Ge=class extends K{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0}),this.annotationEditorType=D.HIGHLIGHT}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("highlightAnnotation"),this._editOnDoubleClick(),this.container}},wi=class extends K{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("underlineAnnotation"),this.container}},Ai=class extends K{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("squigglyAnnotation"),this.container}},vi=class extends K{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("strikeoutAnnotation"),this.container}},Ue=class extends K{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.annotationEditorType=D.STAMP}render(){return this.container.classList.add("stampAnnotation"),this.container.setAttribute("role","img"),!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this._editOnDoubleClick(),this.container}},_i=class extends K{#t=null;constructor(t){super(t,{isRenderable:!0});let{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");let{container:t,data:e}=this,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(100*e.fillAlpha)}%);`)),s.addEventListener("dblclick",this.#e.bind(this)),this.#t=s;let{isMac:i}=Z.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)}},xi=class{#t=null;#e=null;#s=new Map;#i=null;constructor({div:t,accessibilityManager:e,annotationCanvasMap:s,annotationEditorUIManager:i,page:n,viewport:r,structTreeLayer:a}){this.div=t,this.#t=e,this.#e=s,this.#i=a||null,this.page=n,this.viewport=r,this.zIndex=0,this._annotationEditorUIManager=i}hasEditableAnnotations(){return this.#s.size>0}async#r(t,e){let s=t.firstChild||t,i=s.id=`${Oi}${e}`,n=await this.#i?.getAriaAttributes(i);if(n)for(let[r,a]of n)s.setAttribute(r,a);this.div.append(t),this.#t?.moveElementInDOM(this.div,t,s,!1)}async render(t){let{annotations:e}=t,s=this.div;Lt(s,this.viewport);let i=new Map,n={data:null,layer:s,linkService:t.linkService,downloadManager:t.downloadManager,imageResourcesPath:t.imageResourcesPath||"",renderForms:t.renderForms!==!1,svgFactory:new ne,annotationStorage:t.annotationStorage||new te,enableScripting:t.enableScripting===!0,hasJSActions:t.hasJSActions,fieldObjects:t.fieldObjects,parent:this,elements:null};for(let r of e){if(r.noHTML)continue;let a=r.annotationType===dn;if(a){let c=i.get(r.id);if(!c)continue;n.elements=c}else{let{width:c,height:d}=Et(r.rect);if(c<=0||d<=0)continue}n.data=r;let l=ai.create(n);if(!l.isRenderable)continue;if(!a&&r.popupRef){let c=i.get(r.popupRef);c?c.push(l):i.set(r.popupRef,[l])}let h=l.render();r.hidden&&(h.style.visibility="hidden"),await this.#r(h,r.id),l._isEditable&&(this.#s.set(l.data.id,l),this._annotationEditorUIManager?.renderAnnotationElement(l))}this.#n()}update({viewport:t}){let e=this.div;this.viewport=t,Lt(e,{rotation:t.rotation}),this.#n(),e.hidden=!1}#n(){if(!this.#e)return;let t=this.div;for(let[e,s]of this.#e){let i=t.querySelector(`[data-annotation-id="${e}"]`);if(!i)continue;s.className="annotationContent";let{firstChild:n}=i;n?n.nodeName==="CANVAS"?n.replaceWith(s):n.classList.contains("annotationContent")?n.after(s):n.before(s):i.append(s)}this.#e.clear()}getEditableAnnotations(){return Array.from(this.#s.values())}getEditableAnnotation(t){return this.#s.get(t)}},ge=/\r\n?|\n/g,Si=class o extends W{#t;#e="";#s=`${this.id}-editor`;#i=null;#r;static _freeTextDefaultContent="";static _internalPadding=0;static _defaultColor=null;static _defaultFontSize=10;static get _keyboardManager(){let t=o.prototype,e=n=>n.isEmpty(),s=Ft.TRANSLATE_SMALL,i=Ft.TRANSLATE_BIG;return N(this,"_keyboardManager",new Dt([[["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=D.FREETEXT;constructor(t){super({...t,name:"freeTextEditor"}),this.#t=t.color||o._defaultColor||W._defaultLineColor,this.#r=t.fontSize||o._defaultFontSize}static initialize(t,e){W.initialize(t,e);let s=getComputedStyle(document.documentElement);this._internalPadding=parseFloat(s.getPropertyValue("--freetext-padding"))}static updateDefaultParams(t,e){switch(t){case B.FREETEXT_SIZE:o._defaultFontSize=e;break;case B.FREETEXT_COLOR:o._defaultColor=e}}updateParams(t,e){switch(t){case B.FREETEXT_SIZE:this.#n(e);break;case B.FREETEXT_COLOR:this.#l(e)}}static get defaultPropertiesToUpdate(){return[[B.FREETEXT_SIZE,o._defaultFontSize],[B.FREETEXT_COLOR,o._defaultColor||W._defaultLineColor]]}get propertiesToUpdate(){return[[B.FREETEXT_SIZE,this.#r],[B.FREETEXT_COLOR,this.#t]]}#n(t){let e=i=>{this.editorDiv.style.fontSize=`calc(${i}px * var(--scale-factor))`,this.translate(0,-(i-this.#r)*this.parentScale),this.#r=i,this.#c()},s=this.#r;this.addCommands({cmd:e.bind(this,t),undo:e.bind(this,s),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:B.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})}#l(t){let e=i=>{this.#t=this.editorDiv.style.color=i},s=this.#t;this.addCommands({cmd:e.bind(this,t),undo:e.bind(this,s),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:B.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})}_translateEmpty(t,e){this._uiManager.translateSelectedEditors(t,e,!0)}getInitialTranslation(){let t=this.parentScale;return[-o._internalPadding*t,-(o._internalPadding+this.#r)*t]}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.isAttachedToDOM||this.parent.add(this)))}enableEditMode(){if(this.isInEditMode())return;this.parent.setEditingState(!1),this.parent.updateToolbar(D.FREETEXT),super.enableEditMode(),this.overlayDiv.classList.remove("enabled"),this.editorDiv.contentEditable=!0,this._isDraggable=!1,this.div.removeAttribute("aria-activedescendant"),this.#i=new AbortController;let t=this._uiManager.combinedSignal(this.#i);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})}disableEditMode(){this.isInEditMode()&&(this.parent.setEditingState(!0),super.disableEditMode(),this.overlayDiv.classList.add("enabled"),this.editorDiv.contentEditable=!1,this.div.setAttribute("aria-activedescendant",this.#s),this._isDraggable=!0,this.#i?.abort(),this.#i=null,this.div.focus({preventScroll:!0}),this.isEditing=!1,this.parent.div.classList.add("freetextEditing"))}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()}#o(){let t=[];this.editorDiv.normalize();let e=null;for(let s of this.editorDiv.childNodes)(e?.nodeType!==Node.TEXT_NODE||s.nodeName!=="BR")&&(t.push(o.#h(s)),e=s);return t.join(`
|
|
5
|
+
`)}#c(){let[t,e]=this.parentDimensions,s;if(this.isAttachedToDOM)s=this.div.getBoundingClientRect();else{let{currentLayer:i,div:n}=this,r=n.style.display,a=n.classList.contains("hidden");n.classList.remove("hidden"),n.style.display="hidden",i.div.append(this.div),s=n.getBoundingClientRect(),n.remove(),n.style.display=r,n.classList.toggle("hidden",a)}this.rotation%180==this.parentRotation%180?(this.width=s.width/t,this.height=s.height/e):(this.width=s.height/t,this.height=s.width/e),this.fixAndSetPosition()}commit(){if(!this.isInEditMode())return;super.commit(),this.disableEditMode();let t=this.#e,e=this.#e=this.#o().trimEnd();if(t===e)return;let s=i=>{this.#e=i,i?(this.#u(),this._uiManager.rebuild(this),this.#c()):this.remove()};this.addCommands({cmd:()=>{s(e)},undo:()=>{s(t)},mustExec:!1}),this.#c()}shouldGetKeyboardEvents(){return this.isInEditMode()}enterInEditMode(){this.enableEditMode(),this.editorDiv.focus()}dblclick(t){this.enterInEditMode()}keydown(t){t.target===this.div&&t.key==="Enter"&&(this.enterInEditMode(),t.preventDefault())}editorDivKeydown(t){o._keyboardManager.exec(this,t)}editorDivFocus(t){this.isEditing=!0}editorDivBlur(t){this.isEditing=!1}editorDivInput(t){this.parent.div.classList.toggle("freetextEditing",this.isEmpty())}disableEditing(){this.editorDiv.setAttribute("role","comment"),this.editorDiv.removeAttribute("aria-multiline")}enableEditing(){this.editorDiv.setAttribute("role","textbox"),this.editorDiv.setAttribute("aria-multiline",!0)}render(){if(this.div)return this.div;let t,e;this.width&&(t=this.x,e=this.y),super.render(),this.editorDiv=document.createElement("div"),this.editorDiv.className="internal",this.editorDiv.setAttribute("id",this.#s),this.editorDiv.setAttribute("data-l10n-id","pdfjs-free-text2"),this.editorDiv.setAttribute("data-l10n-attrs","default-content"),this.enableEditing(),this.editorDiv.contentEditable=!0;let{style:s}=this.editorDiv;if(s.fontSize=`calc(${this.#r}px * var(--scale-factor))`,s.color=this.#t,this.div.append(this.editorDiv),this.overlayDiv=document.createElement("div"),this.overlayDiv.classList.add("overlay","enabled"),this.div.append(this.overlayDiv),_e(this,this.div,["dblclick","keydown"]),this.width){let[i,n]=this.parentDimensions;if(this.annotationElementId){let{position:r}=this._initialData,[a,l]=this.getInitialTranslation();[a,l]=this.pageTranslationToScreen(a,l);let[h,c]=this.pageDimensions,[d,u]=this.pageTranslation,f,p;switch(this.rotation){case 0:f=t+(r[0]-d)/h,p=e+this.height-(r[1]-u)/c;break;case 90:f=t+(r[0]-d)/h,p=e-(r[1]-u)/c,[a,l]=[l,-a];break;case 180:f=t-this.width+(r[0]-d)/h,p=e-(r[1]-u)/c,[a,l]=[-a,-l];break;case 270:f=t+(r[0]-d-this.height*c)/h,p=e+(r[1]-u-this.width*h)/c,[a,l]=[-l,a]}this.setAt(f*i,p*n,a,l)}else this.setAt(t*i,e*n,this.width*i,this.height*n);this.#u(),this._isDraggable=!0,this.editorDiv.contentEditable=!1}else this._isDraggable=!1,this.editorDiv.contentEditable=!0;return this.div}static#h(t){return(t.nodeType===Node.TEXT_NODE?t.nodeValue:t.innerText).replaceAll(ge,"")}editorDivPaste(t){let e=t.clipboardData||window.clipboardData,{types:s}=e;if(s.length===1&&s[0]==="text/plain")return;t.preventDefault();let i=o.#f(e.getData("text")||"").replaceAll(ge,`
|
|
6
6
|
`);if(!i)return;let n=window.getSelection();if(!n.rangeCount)return;this.editorDiv.normalize(),n.deleteFromDocument();let r=n.getRangeAt(0);if(!i.includes(`
|
|
7
|
-
`)){r.insertNode(document.createTextNode(i)),this.editorDiv.normalize(),n.collapseToStart();return}let{startContainer:a,startOffset:
|
|
8
|
-
`)}${i}${
|
|
9
|
-
`)}`,this.#u();let d=new Range,u=h.reduce(((p
|
|
10
|
-
`)){let e=document.createElement("div");e.append(t?document.createTextNode(t):document.createElement("br")),this.editorDiv.append(e)}}#d(){return this.#e.replaceAll("\xA0"," ")}static#
|
|
11
|
-
`),position:
|
|
12
|
-
`)){let r=document.createElement("div");r.append(n?document.createTextNode(n):document.createElement("br")),e.append(r)}let i=c._internalPadding*this.parentScale;return t.updateEdited({rect:this.getRect(i,i),popupContent:this.#e}),e}resetAnnotationElement(t){super.resetAnnotationElement(t),t.resetEdited()}},S=class{static PRECISION=1e-4;toSVGPath(){z("Abstract method `toSVGPath` must be implemented.")}get box(){z("Abstract getter `box` must be implemented.")}serialize(t,e){z("Abstract method `serialize` must be implemented.")}static _rescale(t,e,s,i,n,r){r||=new Float32Array(t.length);for(let a=0,o=t.length;a<o;a+=2)r[a]=e+t[a]*i,r[a+1]=s+t[a+1]*n;return r}static _rescaleAndSwap(t,e,s,i,n,r){r||=new Float32Array(t.length);for(let a=0,o=t.length;a<o;a+=2)r[a]=e+t[a+1]*i,r[a+1]=s+t[a]*n;return r}static _translate(t,e,s,i){i||=new Float32Array(t.length);for(let n=0,r=t.length;n<r;n+=2)i[n]=e+t[n],i[n+1]=s+t[n+1];return i}static svgRound(t){return Math.round(1e4*t)}static _normalizePoint(t,e,s,i,n){switch(n){case 90:return[1-e/s,t/i];case 180:return[1-t/s,1-e/i];case 270:return[e/s,1-t/i];default:return[t/s,e/i]}}static _normalizePagePoint(t,e,s){switch(s){case 90:return[1-e,t];case 180:return[1-t,1-e];case 270:return[e,1-t];default:return[t,e]}}static createBezierPoints(t,e,s,i,n,r){return[(t+5*s)/6,(e+5*i)/6,(5*s+n)/6,(5*i+r)/6,(s+n)/2,(i+r)/2]}},De=class c{#t;#e=[];#s;#i;#r=[];#n=new Float32Array(18);#h;#o;#c;#l;#u;#d;#p=[];static#a=8;static#g=2;static#m=c.#a+c.#g;constructor({x:t,y:e},s,i,n,r,a=0){this.#t=s,this.#d=n*i,this.#i=r,this.#n.set([NaN,NaN,NaN,NaN,t,e],6),this.#s=a,this.#l=c.#a*i,this.#c=c.#m*i,this.#u=i,this.#p.push(t,e)}isEmpty(){return isNaN(this.#n[8])}#f(){let t=this.#n.subarray(4,6),e=this.#n.subarray(16,18),[s,i,n,r]=this.#t;return[(this.#h+(t[0]-e[0])/2-s)/n,(this.#o+(t[1]-e[1])/2-i)/r,(this.#h+(e[0]-t[0])/2-s)/n,(this.#o+(e[1]-t[1])/2-i)/r]}add({x:t,y:e}){this.#h=t,this.#o=e;let[s,i,n,r]=this.#t,[a,o,h,l]=this.#n.subarray(8,12),d=t-h,u=e-l,p=Math.hypot(d,u);if(p<this.#c)return!1;let g=p-this.#l,f=g/p,m=f*d,b=f*u,v=a,A=o;a=h,o=l,h+=m,l+=b,this.#p?.push(t,e);let y=m/g,w=-b/g*this.#d,x=y*this.#d;return this.#n.set(this.#n.subarray(2,8),0),this.#n.set([h+w,l+x],4),this.#n.set(this.#n.subarray(14,18),12),this.#n.set([h-w,l-x],16),isNaN(this.#n[6])?(this.#r.length===0&&(this.#n.set([a+w,o+x],2),this.#r.push(NaN,NaN,NaN,NaN,(a+w-s)/n,(o+x-i)/r),this.#n.set([a-w,o-x],14),this.#e.push(NaN,NaN,NaN,NaN,(a-w-s)/n,(o-x-i)/r)),this.#n.set([v,A,a,o,h,l],6),!this.isEmpty()):(this.#n.set([v,A,a,o,h,l],6),Math.abs(Math.atan2(A-o,v-a)-Math.atan2(b,m))<Math.PI/2?([a,o,h,l]=this.#n.subarray(2,6),this.#r.push(NaN,NaN,NaN,NaN,((a+h)/2-s)/n,((o+l)/2-i)/r),[a,o,v,A]=this.#n.subarray(14,18),this.#e.push(NaN,NaN,NaN,NaN,((v+a)/2-s)/n,((A+o)/2-i)/r),!0):([v,A,a,o,h,l]=this.#n.subarray(0,6),this.#r.push(((v+5*a)/6-s)/n,((A+5*o)/6-i)/r,((5*a+h)/6-s)/n,((5*o+l)/6-i)/r,((a+h)/2-s)/n,((o+l)/2-i)/r),[h,l,a,o,v,A]=this.#n.subarray(12,18),this.#e.push(((v+5*a)/6-s)/n,((A+5*o)/6-i)/r,((5*a+h)/6-s)/n,((5*o+l)/6-i)/r,((a+h)/2-s)/n,((o+l)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";let t=this.#r,e=this.#e;if(isNaN(this.#n[6])&&!this.isEmpty())return this.#b();let s=[];s.push(`M${t[4]} ${t[5]}`);for(let i=6;i<t.length;i+=6)isNaN(t[i])?s.push(`L${t[i+4]} ${t[i+5]}`):s.push(`C${t[i]} ${t[i+1]} ${t[i+2]} ${t[i+3]} ${t[i+4]} ${t[i+5]}`);this.#v(s);for(let i=e.length-6;i>=6;i-=6)isNaN(e[i])?s.push(`L${e[i+4]} ${e[i+5]}`):s.push(`C${e[i]} ${e[i+1]} ${e[i+2]} ${e[i+3]} ${e[i+4]} ${e[i+5]}`);return this.#w(s),s.join(" ")}#b(){let[t,e,s,i]=this.#t,[n,r,a,o]=this.#f();return`M${(this.#n[2]-t)/s} ${(this.#n[3]-e)/i} L${(this.#n[4]-t)/s} ${(this.#n[5]-e)/i} L${n} ${r} L${a} ${o} L${(this.#n[16]-t)/s} ${(this.#n[17]-e)/i} L${(this.#n[14]-t)/s} ${(this.#n[15]-e)/i} Z`}#w(t){let e=this.#e;t.push(`L${e[4]} ${e[5]} Z`)}#v(t){let[e,s,i,n]=this.#t,r=this.#n.subarray(4,6),a=this.#n.subarray(16,18),[o,h,l,d]=this.#f();t.push(`L${(r[0]-e)/i} ${(r[1]-s)/n} L${o} ${h} L${l} ${d} L${(a[0]-e)/i} ${(a[1]-s)/n}`)}newFreeDrawOutline(t,e,s,i,n,r){return new Fe(t,e,s,i,n,r)}getOutlines(){let t=this.#r,e=this.#e,s=this.#n,[i,n,r,a]=this.#t,o=new Float32Array((this.#p?.length??0)+2);for(let d=0,u=o.length-2;d<u;d+=2)o[d]=(this.#p[d]-i)/r,o[d+1]=(this.#p[d+1]-n)/a;if(o[o.length-2]=(this.#h-i)/r,o[o.length-1]=(this.#o-n)/a,isNaN(s[6])&&!this.isEmpty())return this.#y(o);let h=new Float32Array(this.#r.length+24+this.#e.length),l=t.length;for(let d=0;d<l;d+=2)isNaN(t[d])?h[d]=h[d+1]=NaN:(h[d]=t[d],h[d+1]=t[d+1]);l=this.#E(h,l);for(let d=e.length-6;d>=6;d-=6)for(let u=0;u<6;u+=2)isNaN(e[d+u])?(h[l]=h[l+1]=NaN,l+=2):(h[l]=e[d+u],h[l+1]=e[d+u+1],l+=2);return this.#x(h,l),this.newFreeDrawOutline(h,o,this.#t,this.#u,this.#s,this.#i)}#y(t){let e=this.#n,[s,i,n,r]=this.#t,[a,o,h,l]=this.#f(),d=new Float32Array(36);return d.set([NaN,NaN,NaN,NaN,(e[2]-s)/n,(e[3]-i)/r,NaN,NaN,NaN,NaN,(e[4]-s)/n,(e[5]-i)/r,NaN,NaN,NaN,NaN,a,o,NaN,NaN,NaN,NaN,h,l,NaN,NaN,NaN,NaN,(e[16]-s)/n,(e[17]-i)/r,NaN,NaN,NaN,NaN,(e[14]-s)/n,(e[15]-i)/r],0),this.newFreeDrawOutline(d,t,this.#t,this.#u,this.#s,this.#i)}#x(t,e){let s=this.#e;return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+6}#E(t,e){let s=this.#n.subarray(4,6),i=this.#n.subarray(16,18),[n,r,a,o]=this.#t,[h,l,d,u]=this.#f();return t.set([NaN,NaN,NaN,NaN,(s[0]-n)/a,(s[1]-r)/o,NaN,NaN,NaN,NaN,h,l,NaN,NaN,NaN,NaN,d,u,NaN,NaN,NaN,NaN,(i[0]-n)/a,(i[1]-r)/o],e),e+24}},Fe=class extends S{#t;#e=new Float32Array(4);#s;#i;#r;#n;#h;constructor(t,e,s,i,n,r){super(),this.#h=t,this.#r=e,this.#t=s,this.#n=i,this.#s=n,this.#i=r,this.lastPoint=[NaN,NaN],this.#o(r);let[a,o,h,l]=this.#e;for(let d=0,u=t.length;d<u;d+=2)t[d]=(t[d]-a)/h,t[d+1]=(t[d+1]-o)/l;for(let d=0,u=e.length;d<u;d+=2)e[d]=(e[d]-a)/h,e[d+1]=(e[d+1]-o)/l}toSVGPath(){let t=[`M${this.#h[4]} ${this.#h[5]}`];for(let e=6,s=this.#h.length;e<s;e+=6)isNaN(this.#h[e])?t.push(`L${this.#h[e+4]} ${this.#h[e+5]}`):t.push(`C${this.#h[e]} ${this.#h[e+1]} ${this.#h[e+2]} ${this.#h[e+3]} ${this.#h[e+4]} ${this.#h[e+5]}`);return t.push("Z"),t.join(" ")}serialize([t,e,s,i],n){let r=s-t,a=i-e,o,h;switch(n){case 0:o=S._rescale(this.#h,t,i,r,-a),h=S._rescale(this.#r,t,i,r,-a);break;case 90:o=S._rescaleAndSwap(this.#h,t,e,r,a),h=S._rescaleAndSwap(this.#r,t,e,r,a);break;case 180:o=S._rescale(this.#h,s,e,-r,a),h=S._rescale(this.#r,s,e,-r,a);break;case 270:o=S._rescaleAndSwap(this.#h,s,i,-r,-a),h=S._rescaleAndSwap(this.#r,s,i,-r,-a)}return{outline:Array.from(o),points:[Array.from(h)]}}#o(t){let e=this.#h,s=e[4],i=e[5],n=s,r=i,a=s,o=i,h=s,l=i,d=t?Math.max:Math.min;for(let p=6,g=e.length;p<g;p+=6){if(isNaN(e[p]))n=Math.min(n,e[p+4]),r=Math.min(r,e[p+5]),a=Math.max(a,e[p+4]),o=Math.max(o,e[p+5]),l<e[p+5]?(h=e[p+4],l=e[p+5]):l===e[p+5]&&(h=d(h,e[p+4]));else{let f=C.bezierBoundingBox(s,i,...e.slice(p,p+6));n=Math.min(n,f[0]),r=Math.min(r,f[1]),a=Math.max(a,f[2]),o=Math.max(o,f[3]),l<f[3]?(h=f[2],l=f[3]):l===f[3]&&(h=d(h,f[2]))}s=e[p+4],i=e[p+5]}let u=this.#e;u[0]=n-this.#s,u[1]=r-this.#s,u[2]=a-n+2*this.#s,u[3]=o-r+2*this.#s,this.lastPoint=[h,l]}get box(){return this.#e}newOutliner(t,e,s,i,n,r=0){return new De(t,e,s,i,n,r)}getNewOutline(t,e){let[s,i,n,r]=this.#e,[a,o,h,l]=this.#t,d=n*h,u=r*l,p=s*h+a,g=i*l+o,f=this.newOutliner({x:this.#r[0]*d+p,y:this.#r[1]*u+g},this.#t,this.#n,t,this.#i,e??this.#s);for(let m=2;m<this.#r.length;m+=2)f.add({x:this.#r[m]*d+p,y:this.#r[m+1]*u+g});return f.getOutlines()}},Qt=class{#t;#e;#s=[];#i=[];constructor(t,e=0,s=0,i=!0){let n=1/0,r=-1/0,a=1/0,o=-1/0,h=10**-4;for(let{x:m,y:b,width:v,height:A}of t){let y=Math.floor((m-e)/h)*h,w=Math.ceil((m+v+e)/h)*h,x=Math.floor((b-e)/h)*h,_=Math.ceil((b+A+e)/h)*h,E=[y,x,_,!0],M=[w,x,_,!1];this.#s.push(E,M),n=Math.min(n,y),r=Math.max(r,w),a=Math.min(a,x),o=Math.max(o,_)}let l=r-n+2*s,d=o-a+2*s,u=n-s,p=a-s,g=this.#s.at(i?-1:-2),f=[g[0],g[2]];for(let m of this.#s){let[b,v,A]=m;m[0]=(b-u)/l,m[1]=(v-p)/d,m[2]=(A-p)/d}this.#t=new Float32Array([u,p,l,d]),this.#e=f}getOutlines(){this.#s.sort(((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]));let t=[];for(let e of this.#s)e[3]?(t.push(...this.#c(e)),this.#h(e)):(this.#o(e),t.push(...this.#c(e)));return this.#r(t)}#r(t){let e=[],s=new Set;for(let r of t){let[a,o,h]=r;e.push([a,o,r],[a,h,r])}e.sort(((r,a)=>r[1]-a[1]||r[0]-a[0]));for(let r=0,a=e.length;r<a;r+=2){let o=e[r][2],h=e[r+1][2];o.push(h),h.push(o),s.add(o),s.add(h)}let i=[],n;for(;s.size>0;){let r=s.values().next().value,[a,o,h,l,d]=r;s.delete(r);let u=a,p=o;for(n=[a,h],i.push(n);;){let g;if(s.has(l))g=l;else{if(!s.has(d))break;g=d}s.delete(g),[a,o,h,l,d]=g,u!==a&&(n.push(u,p,a,p===o?o:h),u=a),p=p===o?h:o}n.push(u,p)}return new li(i,this.#t,this.#e)}#n(t){let e=this.#i,s=0,i=e.length-1;for(;s<=i;){let n=s+i>>1,r=e[n][0];if(r===t)return n;r<t?s=n+1:i=n-1}return i+1}#h([,t,e]){let s=this.#n(t);this.#i.splice(s,0,[t,e])}#o([,t,e]){let s=this.#n(t);for(let i=s;i<this.#i.length;i++){let[n,r]=this.#i[i];if(n!==t)break;if(n===t&&r===e){this.#i.splice(i,1);return}}for(let i=s-1;i>=0;i--){let[n,r]=this.#i[i];if(n!==t)break;if(n===t&&r===e){this.#i.splice(i,1);return}}}#c(t){let[e,s,i]=t,n=[[e,s,i]],r=this.#n(i);for(let a=0;a<r;a++){let[o,h]=this.#i[a];for(let l=0,d=n.length;l<d;l++){let[,u,p]=n[l];if(!(h<=u||p<=o))if(u>=o)if(p>h)n[l][1]=h;else{if(d===1)return[];n.splice(l,1),l--,d--}else n[l][2]=o,p>h&&n.push([e,h,p])}}return n}},li=class extends S{#t;#e;constructor(t,e,s){super(),this.#e=t,this.#t=e,this.lastPoint=s}toSVGPath(){let t=[];for(let e of this.#e){let[s,i]=e;t.push(`M${s} ${i}`);for(let n=2;n<e.length;n+=2){let r=e[n],a=e[n+1];r===s?(t.push(`V${a}`),i=a):a===i&&(t.push(`H${r}`),s=r)}t.push("Z")}return t.join(" ")}serialize([t,e,s,i],n){let r=[],a=s-t,o=i-e;for(let h of this.#e){let l=new Array(h.length);for(let d=0;d<h.length;d+=2)l[d]=t+h[d]*a,l[d+1]=i-h[d+1]*o;r.push(l)}return r}get box(){return this.#t}get classNamesForOutlining(){return["highlightOutline"]}},Jt=class extends De{newFreeDrawOutline(t,e,s,i,n,r){return new ci(t,e,s,i,n,r)}},ci=class extends Fe{newOutliner(t,e,s,i,n,r=0){return new Jt(t,e,s,i,n,r)}},Ne=class c{#t=null;#e=null;#s;#i=null;#r=!1;#n=!1;#h=null;#o;#c=null;#l=null;#u;static#d=null;static get _keyboardManager(){return N(this,"_keyboardManager",new Ct([[["Escape","mac+Escape"],c.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],c.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],c.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],c.prototype._moveToPrevious],[["Home","mac+Home"],c.prototype._moveToBeginning],[["End","mac+End"],c.prototype._moveToEnd]]))}constructor({editor:t=null,uiManager:e=null}){t?(this.#n=!1,this.#u=B.HIGHLIGHT_COLOR,this.#h=t):(this.#n=!0,this.#u=B.HIGHLIGHT_DEFAULT_COLOR),this.#l=t?._uiManager||e,this.#o=this.#l._eventBus,this.#s=t?.color||this.#l?.highlightColors.values().next().value||"#FFFF98",c.#d||=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(){let t=this.#t=document.createElement("button");t.className="colorPicker",t.tabIndex="0",t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-button"),t.setAttribute("aria-haspopup",!0);let e=this.#l._signal;t.addEventListener("click",this.#m.bind(this),{signal:e}),t.addEventListener("keydown",this.#g.bind(this),{signal:e});let s=this.#e=document.createElement("span");return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=this.#s,t.append(s),t}renderMainDropdown(){let t=this.#i=this.#p();return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}#p(){let t=document.createElement("div"),e=this.#l._signal;t.addEventListener("contextmenu",ot,{signal:e}),t.className="dropdown",t.role="listbox",t.setAttribute("aria-multiselectable",!1),t.setAttribute("aria-orientation","vertical"),t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown");for(let[s,i]of this.#l.highlightColors){let n=document.createElement("button");n.tabIndex="0",n.role="option",n.setAttribute("data-color",i),n.title=s,n.setAttribute("data-l10n-id",c.#d[s]);let r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===this.#s),n.addEventListener("click",this.#a.bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",this.#g.bind(this),{signal:e}),t}#a(t,e){e.stopPropagation(),this.#o.dispatch("switchannotationeditorparams",{source:this,type:this.#u,value:t})}_colorSelectFromKeyboard(t){if(t.target===this.#t){this.#m(t);return}let e=t.target.getAttribute("data-color");e&&this.#a(e,t)}_moveToNext(t){this.#b?t.target!==this.#t?t.target.nextSibling?.focus():this.#i.firstChild?.focus():this.#m(t)}_moveToPrevious(t){t.target!==this.#i?.firstChild&&t.target!==this.#t?(this.#b||this.#m(t),t.target.previousSibling?.focus()):this.#b&&this._hideDropdownFromKeyboard()}_moveToBeginning(t){this.#b?this.#i.firstChild?.focus():this.#m(t)}_moveToEnd(t){this.#b?this.#i.lastChild?.focus():this.#m(t)}#g(t){c._keyboardManager.exec(this,t)}#m(t){if(this.#b){this.hideDropdown();return}if(this.#r=t.detail===0,this.#c||(this.#c=new AbortController,window.addEventListener("pointerdown",this.#f.bind(this),{signal:this.#l.combinedSignal(this.#c)})),this.#i){this.#i.classList.remove("hidden");return}let e=this.#i=this.#p();this.#t.append(e)}#f(t){this.#i?.contains(t.target)||this.hideDropdown()}hideDropdown(){this.#i?.classList.add("hidden"),this.#c?.abort(),this.#c=null}get#b(){return this.#i&&!this.#i.classList.contains("hidden")}_hideDropdownFromKeyboard(){this.#n||(this.#b?(this.hideDropdown(),this.#t.focus({preventScroll:!0,focusVisible:this.#r})):this.#h?.unselect())}updateColor(t){if(this.#e&&(this.#e.style.backgroundColor=t),!this.#i)return;let e=this.#l.highlightColors.values();for(let s of this.#i.children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){this.#t?.remove(),this.#t=null,this.#e=null,this.#i?.remove(),this.#i=null}},Oe=class c extends U{#t=null;#e=0;#s;#i=null;#r=null;#n=null;#h=null;#o=0;#c=null;#l=null;#u=null;#d=!1;#p=null;#a;#g=null;#m="";#f;#b="";static _defaultColor=null;static _defaultOpacity=1;static _defaultThickness=12;static _type="highlight";static _editorType=L.HIGHLIGHT;static _freeHighlightId=-1;static _freeHighlight=null;static _freeHighlightClipId="";static get _keyboardManager(){let t=c.prototype;return N(this,"_keyboardManager",new Ct([[["ArrowLeft","mac+ArrowLeft"],t._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],t._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],t._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],t._moveCaret,{args:[3]}]]))}constructor(t){super({...t,name:"highlightEditor"}),this.color=t.color||c._defaultColor,this.#f=t.thickness||c._defaultThickness,this.#a=t.opacity||c._defaultOpacity,this.#s=t.boxes||null,this.#b=t.methodOfCreation||"",this.#m=t.text||"",this._isDraggable=!1,t.highlightId>-1?(this.#d=!0,this.#v(t),this.#T()):this.#s&&(this.#t=t.anchorNode,this.#e=t.anchorOffset,this.#h=t.focusNode,this.#o=t.focusOffset,this.#w(),this.#T(),this.rotate(this.rotation))}get telemetryInitialData(){return{action:"added",type:this.#d?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:this.#f,methodOfCreation:this.#b}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.highlightColorNames.get(this.color)}}static computeTelemetryFinalData(t){return{numberOfColors:t.get("color").size}}#w(){let t=new Qt(this.#s,.001);this.#l=t.getOutlines(),[this.x,this.y,this.width,this.height]=this.#l.box;let e=new Qt(this.#s,.0025,.001,this._uiManager.direction==="ltr");this.#n=e.getOutlines();let{lastPoint:s}=this.#n;this.#p=[(s[0]-this.x)/this.width,(s[1]-this.y)/this.height]}#v({highlightOutlines:t,highlightId:e,clipPathId:s}){if(this.#l=t,this.#n=t.getNewOutline(this.#f/2+1.5,.0025),e>=0)this.#u=e,this.#i=s,this.parent.drawLayer.finalizeDraw(e,{bbox:t.box,path:{d:t.toSVGPath()}}),this.#g=this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:this.#n.box,path:{d:this.#n.toSVGPath()}},!0);else if(this.parent){let h=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(this.#u,{bbox:c.#_(this.#l.box,(h-this.rotation+360)%360),path:{d:t.toSVGPath()}}),this.parent.drawLayer.updateProperties(this.#g,{bbox:c.#_(this.#n.box,h),path:{d:this.#n.toSVGPath()}})}let[i,n,r,a]=t.box;switch(this.rotation){case 0:this.x=i,this.y=n,this.width=r,this.height=a;break;case 90:{let[h,l]=this.parentDimensions;this.x=n,this.y=1-i,this.width=r*l/h,this.height=a*h/l;break}case 180:this.x=1-i,this.y=1-n,this.width=r,this.height=a;break;case 270:{let[h,l]=this.parentDimensions;this.x=1-n,this.y=i,this.width=r*l/h,this.height=a*h/l;break}}let{lastPoint:o}=this.#n;this.#p=[(o[0]-i)/r,(o[1]-n)/a]}static initialize(t,e){U.initialize(t,e),c._defaultColor||=e.highlightColors?.values().next().value||"#fff066"}static updateDefaultParams(t,e){switch(t){case B.HIGHLIGHT_DEFAULT_COLOR:c._defaultColor=e;break;case B.HIGHLIGHT_THICKNESS:c._defaultThickness=e}}translateInPage(t,e){}get toolbarPosition(){return this.#p}updateParams(t,e){switch(t){case B.HIGHLIGHT_COLOR:this.#y(e);break;case B.HIGHLIGHT_THICKNESS:this.#x(e)}}static get defaultPropertiesToUpdate(){return[[B.HIGHLIGHT_DEFAULT_COLOR,c._defaultColor],[B.HIGHLIGHT_THICKNESS,c._defaultThickness]]}get propertiesToUpdate(){return[[B.HIGHLIGHT_COLOR,this.color||c._defaultColor],[B.HIGHLIGHT_THICKNESS,this.#f||c._defaultThickness],[B.HIGHLIGHT_FREE,this.#d]]}#y(t){let e=(n,r)=>{this.color=n,this.#a=r,this.parent?.drawLayer.updateProperties(this.#u,{root:{fill:n,"fill-opacity":r}}),this.#r?.updateColor(n)},s=this.color,i=this.#a;this.addCommands({cmd:e.bind(this,t,c._defaultOpacity),undo:e.bind(this,s,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:B.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(t)},!0)}#x(t){let e=this.#f,s=i=>{this.#f=i,this.#E(i)};this.addCommands({cmd:s.bind(this,t),undo:s.bind(this,e),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:B.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:t},!0)}async addEditToolbar(){let t=await super.addEditToolbar();return t?(this._uiManager.highlightColors&&(this.#r=new Ne({editor:this}),t.addColorPicker(this.#r)),t):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(this.#P())}getBaseTranslation(){return[0,0]}getRect(t,e){return super.getRect(t,e,this.#P())}onceAdded(t){this.annotationElementId||this.parent.addUndoableEditor(this),t&&this.div.focus()}remove(){this.#M(),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.#T(),this.isAttachedToDOM||this.parent.add(this)))}setParent(t){let e=!1;this.parent&&!t?this.#M():t&&(this.#T(t),e=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(t),this.show(this._isVisible),e&&this.select()}#E(t){if(!this.#d)return;this.#v({highlightOutlines:this.#l.getNewOutline(t/2)}),this.fixAndSetPosition();let[e,s]=this.parentDimensions;this.setDims(this.width*e,this.height*s)}#M(){this.#u!==null&&this.parent&&(this.parent.drawLayer.remove(this.#u),this.#u=null,this.parent.drawLayer.remove(this.#g),this.#g=null)}#T(t=this.parent){this.#u===null&&({id:this.#u,clipPathId:this.#i}=t.drawLayer.draw({bbox:this.#l.box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":this.#a},rootClass:{highlight:!0,free:this.#d},path:{d:this.#l.toSVGPath()}},!1,!0),this.#g=t.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:this.#d},bbox:this.#n.box,path:{d:this.#n.toSVGPath()}},this.#d),this.#c&&(this.#c.style.clipPath=this.#i))}static#_([t,e,s,i],n){switch(n){case 90:return[1-e-i,t,i,s];case 180:return[1-t-s,1-e-i,s,i];case 270:return[e,1-t-s,i,s]}return[t,e,s,i]}rotate(t){let{drawLayer:e}=this.parent,s;this.#d?(t=(t-this.rotation+360)%360,s=c.#_(this.#l.box,t)):s=c.#_([this.x,this.y,this.width,this.height],t),e.updateProperties(this.#u,{bbox:s,root:{"data-main-rotation":t}}),e.updateProperties(this.#g,{bbox:c.#_(this.#n.box,t),root:{"data-main-rotation":t}})}render(){if(this.div)return this.div;let t=super.render();this.#m&&(t.setAttribute("aria-label",this.#m),t.setAttribute("role","mark")),this.#d?t.classList.add("free"):this.div.addEventListener("keydown",this.#k.bind(this),{signal:this._uiManager._signal});let e=this.#c=document.createElement("div");t.append(e),e.setAttribute("aria-hidden","true"),e.className="internal",e.style.clipPath=this.#i;let[s,i]=this.parentDimensions;return this.setDims(this.width*s,this.height*i),ce(this,this.#c,["pointerover","pointerleave"]),this.enableEditing(),t}pointerover(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#g,{rootClass:{hovered:!0}})}pointerleave(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#g,{rootClass:{hovered:!1}})}#k(t){c._keyboardManager.exec(this,t)}_moveCaret(t){switch(this.parent.unselect(this),t){case 0:case 2:this.#C(!0);break;case 1:case 3:this.#C(!1)}}#C(t){if(!this.#t)return;let e=window.getSelection();t?e.setPosition(this.#t,this.#e):e.setPosition(this.#h,this.#o)}select(){super.select(),this.#g&&this.parent?.drawLayer.updateProperties(this.#g,{rootClass:{hovered:!1,selected:!0}})}unselect(){super.unselect(),this.#g&&(this.parent?.drawLayer.updateProperties(this.#g,{rootClass:{selected:!1}}),this.#d||this.#C(!1))}get _mustFixPosition(){return!this.#d}show(t=this._isVisible){super.show(t),this.parent&&(this.parent.drawLayer.updateProperties(this.#u,{rootClass:{hidden:!t}}),this.parent.drawLayer.updateProperties(this.#g,{rootClass:{hidden:!t}}))}#P(){return this.#d?this.rotation:0}#D(){if(this.#d)return null;let[t,e]=this.pageDimensions,[s,i]=this.pageTranslation,n=this.#s,r=new Float32Array(8*n.length),a=0;for(let{x:o,y:h,width:l,height:d}of n){let u=o*t+s,p=(1-h)*e+i;r[a]=r[a+4]=u,r[a+1]=r[a+3]=p,r[a+2]=r[a+6]=u+l*t,r[a+5]=r[a+7]=p-d*e,a+=8}return r}#N(t){return this.#l.serialize(t,this.#P())}static startHighlighting(t,e,{target:s,x:i,y:n}){let{x:r,y:a,width:o,height:h}=s.getBoundingClientRect(),l=new AbortController,d=t.combinedSignal(l),u=p=>{l.abort(),this.#A(t,p)};window.addEventListener("blur",u,{signal:d}),window.addEventListener("pointerup",u,{signal:d}),window.addEventListener("pointerdown",it,{capture:!0,passive:!1,signal:d}),window.addEventListener("contextmenu",ot,{signal:d}),s.addEventListener("pointermove",this.#S.bind(this,t),{signal:d}),this._freeHighlight=new Jt({x:i,y:n},[r,a,o,h],t.scale,this._defaultThickness/2,e,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=t.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0)}static#S(t,e){this._freeHighlight.add(e)&&t.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})}static#A(t,e){this._freeHighlight.isEmpty()?t.drawLayer.remove(this._freeHighlightId):t.createAndAddNewEditor(e,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:"main_toolbar"}),this._freeHighlightId=-1,this._freeHighlight=null,this._freeHighlightClipId=""}static async deserialize(t,e,s){let i=null;if(t instanceof Ie){let{data:{quadPoints:g,rect:f,rotation:m,id:b,color:v,opacity:A,popupRef:y},parent:{page:{pageNumber:w}}}=t;i=t={annotationType:L.HIGHLIGHT,color:Array.from(v),opacity:A,quadPoints:g,boxes:null,pageIndex:w-1,rect:f.slice(0),rotation:m,id:b,deleted:!1,popupRef:y}}else if(t instanceof Kt){let{data:{inkLists:g,rect:f,rotation:m,id:b,color:v,borderStyle:{rawWidth:A},popupRef:y},parent:{page:{pageNumber:w}}}=t;i=t={annotationType:L.HIGHLIGHT,color:Array.from(v),thickness:A,inkLists:g,boxes:null,pageIndex:w-1,rect:f.slice(0),rotation:m,id:b,deleted:!1,popupRef:y}}let{color:n,quadPoints:r,inkLists:a,opacity:o}=t,h=await super.deserialize(t,e,s);h.color=C.makeHexColor(...n),h.#a=o||1,a&&(h.#f=t.thickness),h.annotationElementId=t.id||null,h._initialData=i;let[l,d]=h.pageDimensions,[u,p]=h.pageTranslation;if(r){let g=h.#s=[];for(let f=0;f<r.length;f+=8)g.push({x:(r[f]-u)/l,y:1-(r[f+1]-p)/d,width:(r[f+2]-r[f])/l,height:(r[f+1]-r[f+5])/d});h.#w(),h.#T(),h.rotate(h.rotation)}else if(a){h.#d=!0;let g=a[0],f={x:g[0]-u,y:d-(g[1]-p)},m=new Jt(f,[0,0,l,d],1,h.#f/2,!0,.001);for(let A=0,y=g.length;A<y;A+=2)f.x=g[A]-u,f.y=d-(g[A+1]-p),m.add(f);let{id:b,clipPathId:v}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:h.color,"fill-opacity":h._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:m.toSVGPath()}},!0,!0);h.#v({highlightOutlines:m.getOutlines(),highlightId:b,clipPathId:v}),h.#T()}return h}serialize(t=!1){if(this.isEmpty()||t)return null;if(this.deleted)return this.serializeDeleted();let e=this.getRect(0,0),s=U._colorManager.convert(this.color),i={annotationType:L.HIGHLIGHT,color:s,opacity:this.#a,thickness:this.#f,quadPoints:this.#D(),outlines:this.#N(e),pageIndex:this.pageIndex,rect:e,rotation:this.#P(),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!this.#L(i)?null:(i.id=this.annotationElementId,i)}#L(t){let{color:e}=this._initialData;return t.color.some(((s,i)=>s!==e[i]))}renderAnnotationElement(t){return t.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}},di=class{#t=Object.create(null);updateProperty(t,e){this[t]=e,this.updateSVGProperty(t,e)}updateProperties(t){if(t)for(let[e,s]of Object.entries(t))this.updateProperty(e,s)}updateSVGProperty(t,e){this.#t[t]=e}toSVGProperties(){let t=this.#t;return this.#t=Object.create(null),{root:t}}reset(){this.#t=Object.create(null)}updateAll(t=this){this.updateProperties(t)}clone(){z("Not implemented")}},ui=class c extends U{#t=null;#e;_drawId=null;static _currentDrawId=-1;static _currentParent=null;static#s=null;static#i=null;static#r=null;static#n=NaN;static#h=null;static#o=null;static#c=NaN;static _INNER_MARGIN=3;constructor(t){super(t),this.#e=t.mustBeCommitted||!1,t.drawOutlines&&(this.#l(t),this.#p())}#l({drawOutlines:t,drawId:e,drawingOptions:s}){this.#t=t,this._drawingOptions||=s,e>=0?(this._drawId=e,this.parent.drawLayer.finalizeDraw(e,t.defaultProperties)):this._drawId=this.#u(t,this.parent),this.#m(t.box)}#u(t,e){let{id:s}=e.drawLayer.draw(c._mergeSVGProperties(this._drawingOptions.toSVGProperties(),t.defaultSVGProperties),!1,!1);return s}static _mergeSVGProperties(t,e){let s=new Set(Object.keys(t));for(let[i,n]of Object.entries(e))s.has(i)?Object.assign(t[i],n):t[i]=n;return t}static getDefaultDrawingOptions(t){z("Not implemented")}static get typesMap(){z("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(t,e){let s=this.typesMap.get(t);s&&this._defaultDrawingOptions.updateProperty(s,e),this._currentParent&&(c.#s.updateProperty(s,e),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(t,e){let s=this.constructor.typesMap.get(t);s&&this._updateProperty(t,s,e)}static get defaultPropertiesToUpdate(){let t=[],e=this._defaultDrawingOptions;for(let[s,i]of this.typesMap)t.push([s,e[i]]);return t}get propertiesToUpdate(){let t=[],{_drawingOptions:e}=this;for(let[s,i]of this.constructor.typesMap)t.push([s,e[i]]);return t}_updateProperty(t,e,s){let i=this._drawingOptions,n=i[e],r=a=>{i.updateProperty(e,a);let o=this.#t.updateProperty(e,a);o&&this.#m(o),this.parent?.drawLayer.updateProperties(this._drawId,i.toSVGProperties())};this.addCommands({cmd:r.bind(this,s),undo:r.bind(this,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:t,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){this.parent?.drawLayer.updateProperties(this._drawId,c._mergeSVGProperties(this.#t.getPathResizingSVGProperties(this.#g()),{bbox:this.#f()}))}_onResized(){this.parent?.drawLayer.updateProperties(this._drawId,c._mergeSVGProperties(this.#t.getPathResizedSVGProperties(this.#g()),{bbox:this.#f()}))}_onTranslating(t,e){this.parent?.drawLayer.updateProperties(this._drawId,{bbox:this.#f(t,e)})}_onTranslated(){this.parent?.drawLayer.updateProperties(this._drawId,c._mergeSVGProperties(this.#t.getPathTranslatedSVGProperties(this.#g(),this.parentDimensions),{bbox:this.#f()}))}_onStartDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}commit(){super.commit(),this.disableEditMode(),this.disableEditing()}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(t){this.annotationElementId||this.parent.addUndoableEditor(this),this._isDraggable=!0,this.#e&&(this.#e=!1,this.commit(),this.parent.setSelected(this),t&&this.isOnScreen&&this.div.focus())}remove(){this.#d(),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.#p(),this.#m(this.#t.box),this.isAttachedToDOM||this.parent.add(this)))}setParent(t){let e=!1;this.parent&&!t?(this._uiManager.removeShouldRescale(this),this.#d()):t&&(this._uiManager.addShouldRescale(this),this.#p(t),e=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(t),e&&this.select()}#d(){this._drawId!==null&&this.parent&&(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())}#p(t=this.parent){(this._drawId===null||this.parent!==t)&&(this._drawId===null?(this._drawingOptions.updateAll(),this._drawId=this.#u(this.#t,t)):this.parent.drawLayer.updateParent(this._drawId,t.drawLayer))}#a([t,e,s,i]){let{parentDimensions:[n,r],rotation:a}=this;switch(a){case 90:return[e,1-t,s*(r/n),i*(n/r)];case 180:return[1-t,1-e,s,i];case 270:return[1-e,t,s*(r/n),i*(n/r)];default:return[t,e,s,i]}}#g(){let{x:t,y:e,width:s,height:i,parentDimensions:[n,r],rotation:a}=this;switch(a){case 90:return[1-e,t,s*(n/r),i*(r/n)];case 180:return[1-t,1-e,s,i];case 270:return[e,1-t,s*(n/r),i*(r/n)];default:return[t,e,s,i]}}#m(t){if([this.x,this.y,this.width,this.height]=this.#a(t),this.div){this.fixAndSetPosition();let[e,s]=this.parentDimensions;this.setDims(this.width*e,this.height*s)}this._onResized()}#f(){let{x:t,y:e,width:s,height:i,rotation:n,parentRotation:r,parentDimensions:[a,o]}=this;switch((4*n+r)/90){case 1:return[1-e-i,t,i,s];case 2:return[1-t-s,1-e-i,s,i];case 3:return[e,1-t-s,i,s];case 4:return[t,e-s*(a/o),i*(o/a),s*(a/o)];case 5:return[1-e,t,s*(a/o),i*(o/a)];case 6:return[1-t-i*(o/a),1-e,i*(o/a),s*(a/o)];case 7:return[e-s*(a/o),1-t-i*(o/a),s*(a/o),i*(o/a)];case 8:return[t-s,e-i,s,i];case 9:return[1-e,t-s,i,s];case 10:return[1-t,1-e,s,i];case 11:return[e-i,1-t,i,s];case 12:return[t-i*(o/a),e,i*(o/a),s*(a/o)];case 13:return[1-e-s*(a/o),t-i*(o/a),s*(a/o),i*(o/a)];case 14:return[1-t,1-e-s*(a/o),i*(o/a),s*(a/o)];case 15:return[e,1-t,s*(a/o),i*(o/a)];default:return[t,e,s,i]}}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,c._mergeSVGProperties({bbox:this.#f()},this.#t.updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&this.#m(this.#t.updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;let t=super.render();t.classList.add("draw");let e=document.createElement("div");t.append(e),e.setAttribute("aria-hidden","true"),e.className="internal";let[s,i]=this.parentDimensions;return this.setDims(this.width*s,this.height*i),this._uiManager.addShouldRescale(this),this.disableEditing(),t}static createDrawerInstance(t,e,s,i,n){z("Not implemented")}static startDrawing(t,e,s,i){let{target:n,offsetX:r,offsetY:a,pointerId:o,pointerType:h}=i;if(c.#h&&c.#h!==h)return;let{viewport:{rotation:l}}=t,{width:d,height:u}=n.getBoundingClientRect(),p=c.#i=new AbortController,g=t.combinedSignal(p);c.#n||=o,c.#h??=h,window.addEventListener("pointerup",(f=>{c.#n===f.pointerId?this._endDraw(f):c.#o?.delete(f.pointerId)}),{signal:g}),window.addEventListener("pointercancel",(f=>{c.#n===f.pointerId?this._currentParent.endDrawingSession():c.#o?.delete(f.pointerId)}),{signal:g}),window.addEventListener("pointerdown",(f=>{c.#h===f.pointerType&&((c.#o||=new Set).add(f.pointerId),c.#s.isCancellable()&&(c.#s.removeLastElement(),c.#s.isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))}),{capture:!0,passive:!1,signal:g}),window.addEventListener("contextmenu",ot,{signal:g}),n.addEventListener("pointermove",this._drawMove.bind(this),{signal:g}),n.addEventListener("touchmove",(f=>{f.timeStamp===c.#c&&it(f)}),{signal:g}),t.toggleDrawing(),e._editorUndoBar?.hide(),c.#s?t.drawLayer.updateProperties(this._currentDrawId,c.#s.startNew(r,a,d,u,l)):(e.updateUIForDefaultProperties(this),c.#s=this.createDrawerInstance(r,a,d,u,l),c.#r=this.getDefaultDrawingOptions(),this._currentParent=t,{id:this._currentDrawId}=t.drawLayer.draw(this._mergeSVGProperties(c.#r.toSVGProperties(),c.#s.defaultSVGProperties),!0,!1))}static _drawMove(t){if(c.#c=-1,!c.#s)return;let{offsetX:e,offsetY:s,pointerId:i}=t;c.#n===i&&(c.#o?.size>=1?this._endDraw(t):(this._currentParent.drawLayer.updateProperties(this._currentDrawId,c.#s.add(e,s)),c.#c=t.timeStamp,it(t)))}static _cleanup(t){t&&(this._currentDrawId=-1,this._currentParent=null,c.#s=null,c.#r=null,c.#h=null,c.#c=NaN),c.#i&&(c.#i.abort(),c.#i=null,c.#n=NaN,c.#o=null)}static _endDraw(t){let e=this._currentParent;if(e)if(e.toggleDrawing(!0),this._cleanup(!1),t&&e.drawLayer.updateProperties(this._currentDrawId,c.#s.end(t.offsetX,t.offsetY)),this.supportMultipleDrawings){let s=c.#s,i=this._currentDrawId,n=s.getLastElement();e.addCommands({cmd:()=>{e.drawLayer.updateProperties(i,s.setLastElement(n))},undo:()=>{e.drawLayer.updateProperties(i,s.removeLastElement())},mustExec:!1,type:B.DRAW_STEP})}else this.endDrawing(!1)}static endDrawing(t){let e=this._currentParent;if(!e)return null;if(e.toggleDrawing(!0),e.cleanUndoStack(B.DRAW_STEP),!c.#s.isEmpty()){let{pageDimensions:[s,i],scale:n}=e,r=e.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:c.#s.getOutlines(s*n,i*n,n,this._INNER_MARGIN),drawingOptions:c.#r,mustBeCommitted:!t});return this._cleanup(!0),r}return e.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(t){}static deserializeDraw(t,e,s,i,n,r){z("Not implemented")}static async deserialize(t,e,s){let{rawDims:{pageWidth:i,pageHeight:n,pageX:r,pageY:a}}=e.viewport,o=this.deserializeDraw(r,a,i,n,this._INNER_MARGIN,t),h=await super.deserialize(t,e,s);return h.createDrawingOptions(t),h.#l({drawOutlines:o}),h.#p(),h.onScaleChanging(),h.rotate(),h}serializeDraw(t){let[e,s]=this.pageTranslation,[i,n]=this.pageDimensions;return this.#t.serialize([e,s,i,n],t)}renderAnnotationElement(t){return t.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}},pi=class{#t=new Float64Array(6);#e;#s;#i;#r;#n;#h="";#o=0;#c=new Be;#l;#u;constructor(t,e,s,i,n,r){this.#l=s,this.#u=i,this.#i=n,this.#r=r,[t,e]=this.#d(t,e);let a=this.#e=[NaN,NaN,NaN,NaN,t,e];this.#n=[t,e],this.#s=[{line:a,points:this.#n}],this.#t.set(a,0)}updateProperty(t,e){t==="stroke-width"&&(this.#r=e)}#d(t,e){return S._normalizePoint(t,e,this.#l,this.#u,this.#i)}isEmpty(){return!this.#s||this.#s.length===0}isCancellable(){return this.#n.length<=10}add(t,e){[t,e]=this.#d(t,e);let[s,i,n,r]=this.#t.subarray(2,6),a=t-n,o=e-r;return Math.hypot(this.#l*a,this.#u*o)<=2?null:(this.#n.push(t,e),isNaN(s)?(this.#t.set([n,r,t,e],2),this.#e.push(NaN,NaN,NaN,NaN,t,e),{path:{d:this.toSVGPath()}}):(isNaN(this.#t[0])&&this.#e.splice(6,6),this.#t.set([s,i,n,r,t,e],0),this.#e.push(...S.createBezierPoints(s,i,n,r,t,e)),{path:{d:this.toSVGPath()}}))}end(t,e){return this.add(t,e)||(this.#n.length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,s,i,n){this.#l=s,this.#u=i,this.#i=n,[t,e]=this.#d(t,e);let r=this.#e=[NaN,NaN,NaN,NaN,t,e];this.#n=[t,e];let a=this.#s.at(-1);return a&&(a.line=new Float32Array(a.line),a.points=new Float32Array(a.points)),this.#s.push({line:r,points:this.#n}),this.#t.set(r,0),this.#o=0,this.toSVGPath(),null}getLastElement(){return this.#s.at(-1)}setLastElement(t){return this.#s?(this.#s.push(t),this.#e=t.line,this.#n=t.points,this.#o=0,{path:{d:this.toSVGPath()}}):this.#c.setLastElement(t)}removeLastElement(){if(!this.#s)return this.#c.removeLastElement();this.#s.pop(),this.#h="";for(let t=0,e=this.#s.length;t<e;t++){let{line:s,points:i}=this.#s[t];this.#e=s,this.#n=i,this.#o=0,this.toSVGPath()}return{path:{d:this.#h}}}toSVGPath(){let t=S.svgRound(this.#e[4]),e=S.svgRound(this.#e[5]);if(this.#n.length===2)return this.#h=`${this.#h} M ${t} ${e} Z`,this.#h;if(this.#n.length<=6){let i=this.#h.lastIndexOf("M");this.#h=`${this.#h.slice(0,i)} M ${t} ${e}`,this.#o=6}if(this.#n.length===4){let i=S.svgRound(this.#e[10]),n=S.svgRound(this.#e[11]);return this.#h=`${this.#h} L ${i} ${n}`,this.#o=12,this.#h}let s=[];this.#o===0&&(s.push(`M ${t} ${e}`),this.#o=6);for(let i=this.#o,n=this.#e.length;i<n;i+=6){let[r,a,o,h,l,d]=this.#e.slice(i,i+6).map(S.svgRound);s.push(`C${r} ${a} ${o} ${h} ${l} ${d}`)}return this.#h+=s.join(" "),this.#o=this.#e.length,this.#h}getOutlines(t,e,s,i){let n=this.#s.at(-1);return n.line=new Float32Array(n.line),n.points=new Float32Array(n.points),this.#c.build(this.#s,t,e,s,this.#i,this.#r,i),this.#t=null,this.#e=null,this.#s=null,this.#h=null,this.#c}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}},Be=class c extends S{#t;#e=0;#s;#i;#r;#n;#h;#o;#c;build(t,e,s,i,n,r,a){this.#r=e,this.#n=s,this.#h=i,this.#o=n,this.#c=r,this.#s=a??0,this.#i=t,this.#d()}setLastElement(t){return this.#i.push(t),{path:{d:this.toSVGPath()}}}removeLastElement(){return this.#i.pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){let t=[];for(let{line:e}of this.#i)if(t.push(`M${S.svgRound(e[4])} ${S.svgRound(e[5])}`),e.length!==6)if(e.length!==12)for(let s=6,i=e.length;s<i;s+=6){let[n,r,a,o,h,l]=e.subarray(s,s+6).map(S.svgRound);t.push(`C${n} ${r} ${a} ${o} ${h} ${l}`)}else t.push(`L${S.svgRound(e[10])} ${S.svgRound(e[11])}`);else t.push("Z");return t.join("")}serialize([t,e,s,i],n){let r=[],a=[],[o,h,l,d]=this.#u(),u,p,g,f,m,b,v,A,y;switch(this.#o){case 0:y=S._rescale,u=t,p=e+i,g=s,f=-i,m=t+o*s,b=e+(1-h-d)*i,v=t+(o+l)*s,A=e+(1-h)*i;break;case 90:y=S._rescaleAndSwap,u=t,p=e,g=s,f=i,m=t+h*s,b=e+o*i,v=t+(h+d)*s,A=e+(o+l)*i;break;case 180:y=S._rescale,u=t+s,p=e,g=-s,f=i,m=t+(1-o-l)*s,b=e+h*i,v=t+(1-o)*s,A=e+(h+d)*i;break;case 270:y=S._rescaleAndSwap,u=t+s,p=e+i,g=-s,f=-i,m=t+(1-h-d)*s,b=e+(1-o-l)*i,v=t+(1-h)*s,A=e+(1-o)*i}for(let{line:w,points:x}of this.#i)r.push(y(w,u,p,g,f,n?new Array(w.length):null)),a.push(y(x,u,p,g,f,n?new Array(x.length):null));return{lines:r,points:a,rect:[m,b,v,A]}}static deserialize(t,e,s,i,n,{paths:{lines:r,points:a},rotation:o,thickness:h}){let l=[],d,u,p,g,f;switch(o){case 0:f=S._rescale,d=-t/s,u=e/i+1,p=1/s,g=-1/i;break;case 90:f=S._rescaleAndSwap,d=-e/i,u=-t/s,p=1/i,g=1/s;break;case 180:f=S._rescale,d=t/s+1,u=-e/i,p=-1/s,g=1/i;break;case 270:f=S._rescaleAndSwap,d=e/i+1,u=t/s+1,p=-1/i,g=-1/s}if(!r){r=[];for(let b of a){let v=b.length;if(v===2){r.push(new Float32Array([NaN,NaN,NaN,NaN,b[0],b[1]]));continue}if(v===4){r.push(new Float32Array([NaN,NaN,NaN,NaN,b[0],b[1],NaN,NaN,NaN,NaN,b[2],b[3]]));continue}let A=new Float32Array(3*(v-2));r.push(A);let[y,w,x,_]=b.subarray(0,4);A.set([NaN,NaN,NaN,NaN,y,w],0);for(let E=4;E<v;E+=2){let M=b[E],T=b[E+1];A.set(S.createBezierPoints(y,w,x,_,M,T),3*(E-2)),[y,w,x,_]=[x,_,M,T]}}}for(let b=0,v=r.length;b<v;b++)l.push({line:f(r[b].map((A=>A??NaN)),d,u,p,g),points:f(a[b].map((A=>A??NaN)),d,u,p,g)});let m=new c;return m.build(l,s,i,1,o,h,n),m}#l(t=this.#c){let e=this.#s+t/2*this.#h;return this.#o%180==0?[e/this.#r,e/this.#n]:[e/this.#n,e/this.#r]}#u(){let[t,e,s,i]=this.#t,[n,r]=this.#l(0);return[t+n,e+r,s-2*n,i-2*r]}#d(){let t=this.#t=new Float32Array([1/0,1/0,-1/0,-1/0]);for(let{line:i}of this.#i){if(i.length<=12){for(let a=4,o=i.length;a<o;a+=6){let[h,l]=i.subarray(a,a+2);t[0]=Math.min(t[0],h),t[1]=Math.min(t[1],l),t[2]=Math.max(t[2],h),t[3]=Math.max(t[3],l)}continue}let n=i[4],r=i[5];for(let a=6,o=i.length;a<o;a+=6){let[h,l,d,u,p,g]=i.subarray(a,a+6);C.bezierBoundingBox(n,r,h,l,d,u,p,g,t),n=p,r=g}}let[e,s]=this.#l();t[0]=Math.min(1,Math.max(0,t[0]-e)),t[1]=Math.min(1,Math.max(0,t[1]-s)),t[2]=Math.min(1,Math.max(0,t[2]+e)),t[3]=Math.min(1,Math.max(0,t[3]+s)),t[2]-=t[0],t[3]-=t[1]}get box(){return this.#t}updateProperty(t,e){return t==="stroke-width"?this.#p(e):null}#p(t){let[e,s]=this.#l();this.#c=t;let[i,n]=this.#l(),[r,a]=[i-e,n-s],o=this.#t;return o[0]-=r,o[1]-=a,o[2]+=2*r,o[3]+=2*a,o}updateParentDimensions([t,e],s){let[i,n]=this.#l();this.#r=t,this.#n=e,this.#h=s;let[r,a]=this.#l(),o=r-i,h=a-n,l=this.#t;return l[0]-=o,l[1]-=h,l[2]+=2*o,l[3]+=2*h,l}updateRotation(t){return this.#e=t,{path:{transform:this.rotationTransform}}}get viewBox(){return this.#t.map(S.svgRound).join(" ")}get defaultProperties(){let[t,e]=this.#t;return{root:{viewBox:this.viewBox},path:{"transform-origin":`${S.svgRound(t)} ${S.svgRound(e)}`}}}get rotationTransform(){let[,,t,e]=this.#t,s=0,i=0,n=0,r=0,a=0,o=0;switch(this.#e){case 90:i=e/t,n=-t/e,a=t;break;case 180:s=-1,r=-1,a=t,o=e;break;case 270:i=-e/t,n=t/e,o=e;break;default:return""}return`matrix(${s} ${i} ${n} ${r} ${S.svgRound(a)} ${S.svgRound(o)})`}getPathResizingSVGProperties([t,e,s,i]){let[n,r]=this.#l(),[a,o,h,l]=this.#t;if(Math.abs(h-n)<=S.PRECISION||Math.abs(l-r)<=S.PRECISION){let f=t+s/2-(a+h/2),m=e+i/2-(o+l/2);return{path:{"transform-origin":`${S.svgRound(t)} ${S.svgRound(e)}`,transform:`${this.rotationTransform} translate(${f} ${m})`}}}let d=(s-2*n)/(h-2*n),u=(i-2*r)/(l-2*r),p=h/s,g=l/i;return{path:{"transform-origin":`${S.svgRound(a)} ${S.svgRound(o)}`,transform:`${this.rotationTransform} scale(${p} ${g}) translate(${S.svgRound(n)} ${S.svgRound(r)}) scale(${d} ${u}) translate(${S.svgRound(-n)} ${S.svgRound(-r)})`}}}getPathResizedSVGProperties([t,e,s,i]){let[n,r]=this.#l(),a=this.#t,[o,h,l,d]=a;if(a[0]=t,a[1]=e,a[2]=s,a[3]=i,Math.abs(l-n)<=S.PRECISION||Math.abs(d-r)<=S.PRECISION){let m=t+s/2-(o+l/2),b=e+i/2-(h+d/2);for(let{line:v,points:A}of this.#i)S._translate(v,m,b,v),S._translate(A,m,b,A);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${S.svgRound(t)} ${S.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}let u=(s-2*n)/(l-2*n),p=(i-2*r)/(d-2*r),g=-u*(o+n)+t+n,f=-p*(h+r)+e+r;if(u!==1||p!==1||g!==0||f!==0)for(let{line:m,points:b}of this.#i)S._rescale(m,g,f,u,p,m),S._rescale(b,g,f,u,p,b);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${S.svgRound(t)} ${S.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([t,e],s){let[i,n]=s,r=this.#t,a=t-r[0],o=e-r[1];if(this.#r===i&&this.#n===n)for(let{line:h,points:l}of this.#i)S._translate(h,a,o,h),S._translate(l,a,o,l);else{let h=this.#r/i,l=this.#n/n;this.#r=i,this.#n=n;for(let{line:d,points:u}of this.#i)S._rescale(d,a,o,h,l,d),S._rescale(u,a,o,h,l,u);r[2]*=h,r[3]*=l}return r[0]=t,r[1]=e,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${S.svgRound(t)} ${S.svgRound(e)}`}}}get defaultSVGProperties(){let t=this.#t;return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${S.svgRound(t[0])} ${S.svgRound(t[1])}`,transform:this.rotationTransform||null},bbox:t}}},gi=class c extends di{#t;constructor(t){super(),this.#t=t,super.updateProperties({fill:"none",stroke:U._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(t,e){t==="stroke-width"&&(e??=this["stroke-width"],e*=this.#t.realScale),super.updateSVGProperty(t,e)}clone(){let t=new c(this.#t);return t.updateAll(this),t}},fi=class c extends ui{static _type="ink";static _editorType=L.INK;static _defaultDrawingOptions=null;constructor(t){super({...t,name:"inkEditor"}),this._willKeepAspectRatio=!0}static initialize(t,e){U.initialize(t,e),this._defaultDrawingOptions=new gi(e.viewParameters)}static getDefaultDrawingOptions(t){let e=this._defaultDrawingOptions.clone();return e.updateProperties(t),e}static get supportMultipleDrawings(){return!0}static get typesMap(){return N(this,"typesMap",new Map([[B.INK_THICKNESS,"stroke-width"],[B.INK_COLOR,"stroke"],[B.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(t,e,s,i,n){return new pi(t,e,s,i,n,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(t,e,s,i,n,r){return Be.deserialize(t,e,s,i,n,r)}static async deserialize(t,e,s){let i=null;if(t instanceof Kt){let{data:{inkLists:r,rect:a,rotation:o,id:h,color:l,opacity:d,borderStyle:{rawWidth:u},popupRef:p},parent:{page:{pageNumber:g}}}=t;i=t={annotationType:L.INK,color:Array.from(l),thickness:u,opacity:d,paths:{points:r},boxes:null,pageIndex:g-1,rect:a.slice(0),rotation:o,id:h,deleted:!1,popupRef:p}}let n=await super.deserialize(t,e,s);return n.annotationElementId=t.id||null,n._initialData=i,n}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();let{_drawId:t,_drawingOptions:e,parent:s}=this;e.updateSVGProperty("stroke-width"),s.drawLayer.updateProperties(t,e.toSVGProperties())}static onScaleChangingWhenDrawing(){let t=this._currentParent;t&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),t.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:t,thickness:e,opacity:s}){this._drawingOptions=c.getDefaultDrawingOptions({stroke:C.makeHexColor(...t),"stroke-width":e,"stroke-opacity":s})}serialize(t=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let{lines:e,points:s,rect:i}=this.serializeDraw(t),{_drawingOptions:{stroke:n,"stroke-opacity":r,"stroke-width":a}}=this,o={annotationType:L.INK,color:U._colorManager.convert(n),opacity:r,thickness:a,paths:{lines:e,points:s},pageIndex:this.pageIndex,rect:i,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return t?o:this.annotationElementId&&!this.#t(o)?null:(o.id=this.annotationElementId,o)}#t(t){let{color:e,thickness:s,opacity:i,pageIndex:n}=this._initialData;return this._hasBeenMoved||this._hasBeenResized||t.color.some(((r,a)=>r!==e[a]))||t.thickness!==s||t.opacity!==i||t.pageIndex!==n}renderAnnotationElement(t){let{points:e,rect:s}=this.serializeDraw(!1);return t.updateEdited({rect:s,thickness:this._drawingOptions["stroke-width"],points:e}),null}},mi=class c extends U{#t=null;#e=null;#s=null;#i=null;#r=null;#n="";#h=null;#o=null;#c=!1;#l=!1;static _type="stamp";static _editorType=L.STAMP;constructor(t){super({...t,name:"stampEditor"}),this.#i=t.bitmapUrl,this.#r=t.bitmapFile}static initialize(t,e){U.initialize(t,e)}static get supportedTypes(){return N(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map((t=>`image/${t}`)))}static get supportedTypesStr(){return N(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(t){return this.supportedTypes.includes(t)}static paste(t,e){e.pasteEditor(L.STAMP,{bitmapFile:t.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){return{type:"stamp",hasAltText:!!this.altTextData?.altText}}static computeTelemetryFinalData(t){let e=t.get("hasAltText");return{hasAltText:e.get(!0)??0,hasNoAltText:e.get(!1)??0}}#u(t,e=!1){t?(this.#t=t.bitmap,e||(this.#e=t.id,this.#c=t.isSvg),t.file&&(this.#n=t.file.name),this.#a()):this.remove()}#d(){if(this.#s=null,this._uiManager.enableWaiting(!1),this.#h)if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#t)this._editToolbar.hide(),this._uiManager.editAltText(this,!0);else{if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#t){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}}async mlGuessAltText(t=null,e=!0){if(this.hasAltTextData())return null;let{mlManager:s}=this._uiManager;if(!s)throw new Error("No ML.");if(!await s.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");let{data:i,width:n,height:r}=t||this.copyCanvas(null,null,!0).imageData,a=await s.guess({name:"altText",request:{data:i,width:n,height:r,channels:i.length/(n*r)}});if(!a)throw new Error("No response from the AI service.");if(a.error)throw new Error("Error from the AI service.");if(a.cancel)return null;if(!a.output)throw new Error("No valid response from the AI service.");let o=a.output;return await this.setGuessedAltText(o),e&&!this.hasAltTextData()&&(this.altTextData={alt:o,decorative:!1}),o}#p(){if(this.#e){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(this.#e).then((s=>this.#u(s,!0))).finally((()=>this.#d()));return}if(this.#i){let s=this.#i;this.#i=null,this._uiManager.enableWaiting(!0),this.#s=this._uiManager.imageManager.getFromUrl(s).then((i=>this.#u(i))).finally((()=>this.#d()));return}if(this.#r){let s=this.#r;this.#r=null,this._uiManager.enableWaiting(!0),this.#s=this._uiManager.imageManager.getFromFile(s).then((i=>this.#u(i))).finally((()=>this.#d()));return}let t=document.createElement("input");t.type="file",t.accept=c.supportedTypesStr;let e=this._uiManager._signal;this.#s=new Promise((s=>{t.addEventListener("change",(async()=>{if(t.files&&t.files.length!==0){this._uiManager.enableWaiting(!0);let i=await this._uiManager.imageManager.getFromFile(t.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),this.#u(i)}else this.remove();s()}),{signal:e}),t.addEventListener("cancel",(()=>{this.remove(),s()}),{signal:e})})).finally((()=>this.#d())),t.click()}remove(){this.#e&&(this.#t=null,this._uiManager.imageManager.deleteId(this.#e),this.#h?.remove(),this.#h=null,this.#o&&(clearTimeout(this.#o),this.#o=null)),super.remove()}rebuild(){this.parent?(super.rebuild(),this.div!==null&&(this.#e&&this.#h===null&&this.#p(),this.isAttachedToDOM||this.parent.add(this))):this.#e&&this.#p()}onceAdded(t){this._isDraggable=!0,t&&this.div.focus()}isEmpty(){return!(this.#s||this.#t||this.#i||this.#r||this.#e)}get isResizable(){return!0}render(){if(this.div)return this.div;let t,e;if(this.width&&(t=this.x,e=this.y),super.render(),this.div.hidden=!0,this.div.setAttribute("role","figure"),this.addAltTextButton(),this.#t?this.#a():this.#p(),this.width&&!this.annotationElementId){let[s,i]=this.parentDimensions;this.setAt(t*s,e*i,this.width*s,this.height*i)}return this._uiManager.addShouldRescale(this),this.div}_onResized(){this.onScaleChanging()}onScaleChanging(){this.parent&&(this.#o!==null&&clearTimeout(this.#o),this.#o=setTimeout((()=>{this.#o=null,this.#m()}),200))}#a(){let{div:t}=this,{width:e,height:s}=this.#t,[i,n]=this.pageDimensions,r=.75;if(this.width)e=this.width*i,s=this.height*n;else if(e>r*i||s>r*n){let l=Math.min(r*i/e,r*n/s);e*=l,s*=l}let[a,o]=this.parentDimensions;this.setDims(e*a/i,s*o/n),this._uiManager.enableWaiting(!1);let h=this.#h=document.createElement("canvas");h.setAttribute("role","img"),this.addContainer(h),this.width=e/i,this.height=s/n,this._initialOptions?.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&!this.annotationElementId||(t.hidden=!1),this.#m(),this.#l||(this.parent.addUndoableEditor(this),this.#l=!0),this._reportTelemetry({action:"inserted_image"}),this.#n&&h.setAttribute("aria-label",this.#n)}copyCanvas(t,e,s=!1){t||(t=224);let{width:i,height:n}=this.#t,r=new Vt,a=this.#t,o=i,h=n,l=null;if(e){if(i>e||n>e){let x=Math.min(e/i,e/n);o=Math.floor(i*x),h=Math.floor(n*x)}l=document.createElement("canvas");let u=l.width=Math.ceil(o*r.sx),p=l.height=Math.ceil(h*r.sy);this.#c||(a=this.#g(u,p));let g=l.getContext("2d");g.filter=this._uiManager.hcmFilter;let f="white",m="#cfcfd8";this._uiManager.hcmFilter!=="none"?m="black":window.matchMedia?.("(prefers-color-scheme: dark)").matches&&(f="#8f8f9d",m="#42414d");let b=15,v=b*r.sx,A=b*r.sy,y=new OffscreenCanvas(2*v,2*A),w=y.getContext("2d");w.fillStyle=f,w.fillRect(0,0,2*v,2*A),w.fillStyle=m,w.fillRect(0,0,v,A),w.fillRect(v,A,v,A),g.fillStyle=g.createPattern(y,"repeat"),g.fillRect(0,0,u,p),g.drawImage(a,0,0,a.width,a.height,0,0,u,p)}let d=null;if(s){let u,p;if(r.symmetric&&a.width<t&&a.height<t)u=a.width,p=a.height;else if(a=this.#t,i>t||n>t){let f=Math.min(t/i,t/n);u=Math.floor(i*f),p=Math.floor(n*f),this.#c||(a=this.#g(u,p))}let g=new OffscreenCanvas(u,p).getContext("2d",{willReadFrequently:!0});g.drawImage(a,0,0,a.width,a.height,0,0,u,p),d={width:u,height:p,data:g.getImageData(0,0,u,p).data}}return{canvas:l,width:o,height:h,imageData:d}}#g(t,e){let{width:s,height:i}=this.#t,n=s,r=i,a=this.#t;for(;n>2*t||r>2*e;){let o=n,h=r;n>2*t&&(n=n>=16384?Math.floor(n/2)-1:Math.ceil(n/2)),r>2*e&&(r=r>=16384?Math.floor(r/2)-1:Math.ceil(r/2));let l=new OffscreenCanvas(n,r);l.getContext("2d").drawImage(a,0,0,o,h,0,0,n,r),a=l.transferToImageBitmap()}return a}#m(){let[t,e]=this.parentDimensions,{width:s,height:i}=this,n=new Vt,r=Math.ceil(s*t*n.sx),a=Math.ceil(i*e*n.sy),o=this.#h;if(!o||o.width===r&&o.height===a)return;o.width=r,o.height=a;let h=this.#c?this.#t:this.#g(r,a),l=o.getContext("2d");l.filter=this._uiManager.hcmFilter,l.drawImage(h,0,0,h.width,h.height,0,0,r,a)}getImageForAltText(){return this.#h}#f(t){if(t){if(this.#c){let s=this._uiManager.imageManager.getSvgUrl(this.#e);if(s)return s}let e=document.createElement("canvas");return{width:e.width,height:e.height}=this.#t,e.getContext("2d").drawImage(this.#t,0,0),e.toDataURL()}if(this.#c){let[e,s]=this.pageDimensions,i=Math.round(this.width*e*At.PDF_TO_CSS_UNITS),n=Math.round(this.height*s*At.PDF_TO_CSS_UNITS),r=new OffscreenCanvas(i,n);return r.getContext("2d").drawImage(this.#t,0,0,this.#t.width,this.#t.height,0,0,i,n),r.transferToImageBitmap()}return structuredClone(this.#t)}static async deserialize(t,e,s){let i=null;if(t instanceof Le){let{data:{rect:g,rotation:f,id:m,structParent:b,popupRef:v},container:A,parent:{page:{pageNumber:y}}}=t,w=A.querySelector("canvas"),x=s.imageManager.getFromCanvas(A.id,w);w.remove();let _=(await e._structTree.getAriaAttributes(`${yi}${m}`))?.get("aria-label")||"";i=t={annotationType:L.STAMP,bitmapId:x.id,bitmap:x.bitmap,pageIndex:y-1,rect:g.slice(0),rotation:f,id:m,deleted:!1,accessibilityData:{decorative:!1,altText:_},isSvg:!1,structParent:b,popupRef:v}}let n=await super.deserialize(t,e,s),{rect:r,bitmap:a,bitmapUrl:o,bitmapId:h,isSvg:l,accessibilityData:d}=t;h&&s.imageManager.isValidId(h)?(n.#e=h,a&&(n.#t=a)):n.#i=o,n.#c=l;let[u,p]=n.pageDimensions;return n.width=(r[2]-r[0])/u,n.height=(r[3]-r[1])/p,n.annotationElementId=t.id||null,d&&(n.altTextData=d),n._initialData=i,n.#l=!!i,n}serialize(t=!1,e=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let s={annotationType:L.STAMP,bitmapId:this.#e,pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:this.#c,structTreeParentId:this._structTreeParentId};if(t)return s.bitmapUrl=this.#f(!0),s.accessibilityData=this.serializeAltText(!0),s;let{decorative:i,altText:n}=this.serializeAltText(!1);if(!i&&n&&(s.accessibilityData={type:"Figure",alt:n}),this.annotationElementId){let a=this.#b(s);if(a.isSame)return null;a.isSameAltText?delete s.accessibilityData:s.accessibilityData.structParent=this._initialData.structParent??-1}if(s.id=this.annotationElementId,e===null)return s;e.stamps||=new Map;let r=this.#c?(s.rect[2]-s.rect[0])*(s.rect[3]-s.rect[1]):null;if(e.stamps.has(this.#e)){if(this.#c){let a=e.stamps.get(this.#e);r>a.area&&(a.area=r,a.serialized.bitmap.close(),a.serialized.bitmap=this.#f(!1))}}else e.stamps.set(this.#e,{area:r,serialized:s}),s.bitmap=this.#f(!1);return s}#b(t){let{pageIndex:e,accessibilityData:{altText:s}}=this._initialData,i=t.pageIndex===e,n=(t.accessibilityData?.alt||"")===s;return{isSame:!this._hasBeenMoved&&!this._hasBeenResized&&i&&n,isSameAltText:n}}renderAnnotationElement(t){return t.updateEdited({rect:this.getRect(0,0)}),null}},bi=class c{#t;#e=!1;#s=null;#i=null;#r=null;#n=new Map;#h=!1;#o=!1;#c=!1;#l=null;#u=null;#d=null;#p=null;#a;static _initialized=!1;static#g=new Map([hi,fi,mi,Oe].map((t=>[t._editorType,t])));constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:a,textLayer:o,viewport:h,l10n:l}){let d=[...c.#g.values()];if(!c._initialized){c._initialized=!0;for(let u of d)u.initialize(l,t)}t.registerEditorTypes(d),this.#a=t,this.pageIndex=e,this.div=s,this.#t=n,this.#s=r,this.viewport=h,this.#d=o,this.drawLayer=a,this._structTree=i,this.#a.addLayer(this)}get isEmpty(){return this.#n.size===0}get isInvisible(){return this.isEmpty&&this.#a.getMode()===L.NONE}updateToolbar(t){this.#a.updateToolbar(t)}updateMode(t=this.#a.getMode()){switch(this.#v(),t){case L.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case L.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case L.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);let{classList:e}=this.div;for(let s of c.#g.values())e.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){return t===this.#d?.div}setEditingState(t){this.#a.setEditingState(t)}addCommands(t){this.#a.addCommands(t)}cleanUndoStack(t){this.#a.cleanUndoStack(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){this.#s?.div.classList.toggle("disabled",!t)}async enable(){this.#c=!0,this.div.tabIndex=0,this.togglePointerEvents(!0);let t=new Set;for(let s of this.#n.values())s.enableEditing(),s.show(!0),s.annotationElementId&&(this.#a.removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!this.#s){this.#c=!1;return}let e=this.#s.getEditableAnnotations();for(let s of e){if(s.hide(),this.#a.isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;let i=await this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}this.#c=!1}disable(){this.#o=!0,this.div.tabIndex=-1,this.togglePointerEvents(!1);let t=new Map,e=new Map;for(let i of this.#n.values())i.disableEditing(),i.annotationElementId&&(i.serialize()===null?(e.set(i.annotationElementId,i),this.getEditableAnnotation(i.annotationElementId)?.show(),i.remove()):t.set(i.annotationElementId,i));if(this.#s){let i=this.#s.getEditableAnnotations();for(let n of i){let{id:r}=n.data;if(this.#a.isDeletedAnnotationElement(r))continue;let a=e.get(r);a?(a.resetAnnotationElement(n),a.show(!1),n.show()):(a=t.get(r),a&&(this.#a.addChangedExistingAnnotation(a),a.renderAnnotationElement(n)&&a.show(!1)),n.show())}}this.#v(),this.isEmpty&&(this.div.hidden=!0);let{classList:s}=this.div;for(let i of c.#g.values())s.remove(`${i._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),this.#o=!1}getEditableAnnotation(t){return this.#s?.getEditableAnnotation(t)||null}setActiveEditor(t){this.#a.getActive()!==t&&this.#a.setActiveEditor(t)}enableTextSelection(){if(this.div.tabIndex=-1,this.#d?.div&&!this.#p){this.#p=new AbortController;let t=this.#a.combinedSignal(this.#p);this.#d.div.addEventListener("pointerdown",this.#m.bind(this),{signal:t}),this.#d.div.classList.add("highlighting")}}disableTextSelection(){this.div.tabIndex=0,this.#d?.div&&this.#p&&(this.#p.abort(),this.#p=null,this.#d.div.classList.remove("highlighting"))}#m(t){this.#a.unselectAll();let{target:e}=t;if(e===this.#d.div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&this.#d.div.contains(e)){let{isMac:s}=K.platform;if(t.button!==0||t.ctrlKey&&s)return;this.#a.showAllEditors("highlight",!0,!0),this.#d.div.classList.add("free"),this.toggleDrawing(),Oe.startHighlighting(this,this.#a.direction==="ltr",{target:this.#d.div,x:t.x,y:t.y}),this.#d.div.addEventListener("pointerup",(()=>{this.#d.div.classList.remove("free"),this.toggleDrawing(!0)}),{once:!0,signal:this.#a._signal}),t.preventDefault()}}enableClick(){if(this.#i)return;this.#i=new AbortController;let t=this.#a.combinedSignal(this.#i);this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t});let e=this.pointerup.bind(this);this.div.addEventListener("pointerup",e,{signal:t}),this.div.addEventListener("pointercancel",e,{signal:t})}disableClick(){this.#i?.abort(),this.#i=null}attach(t){this.#n.set(t.id,t);let{annotationElementId:e}=t;e&&this.#a.isDeletedAnnotationElement(e)&&this.#a.removeDeletedAnnotationElement(t)}detach(t){this.#n.delete(t.id),this.#t?.removePointerInTextLayer(t.contentDiv),!this.#o&&t.annotationElementId&&this.#a.addDeletedAnnotationElement(t)}remove(t){this.detach(t),this.#a.removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){t.parent!==this&&(t.parent&&t.annotationElementId&&(this.#a.addDeletedAnnotationElement(t.annotationElementId),U.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),t.parent?.detach(t),t.setParent(this),t.div&&t.isAttachedToDOM&&(t.div.remove(),this.div.append(t.div)))}add(t){if(t.parent!==this||!t.isAttachedToDOM){if(this.changeParent(t),this.#a.addEditor(t),this.attach(t),!t.isAttachedToDOM){let e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!this.#c),this.#a.addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){if(!t.isAttachedToDOM)return;let{activeElement:e}=document;t.div.contains(e)&&!this.#r&&(t._focusEventsAllowed=!1,this.#r=setTimeout((()=>{this.#r=null,t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",(()=>{t._focusEventsAllowed=!0}),{once:!0,signal:this.#a._signal}),e.focus())}),0)),t._structTreeParentId=this.#t?.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){t.needsToBeRebuilt()?(t.parent||=this,t.rebuild(),t.show()):this.add(t)}addUndoableEditor(t){this.addCommands({cmd:()=>t._uiManager.rebuild(t),undo:()=>{t.remove()},mustExec:!1})}getNextId(){return this.#a.getId()}get#f(){return c.#g.get(this.#a.getMode())}combinedSignal(t){return this.#a.combinedSignal(t)}#b(t){let e=this.#f;return e?new e.prototype.constructor(t):null}canCreateNewEmptyEditor(){return this.#f?.canCreateNewEmptyEditor()}pasteEditor(t,e){this.#a.updateToolbar(t),this.#a.updateMode(t);let{offsetX:s,offsetY:i}=this.#w(),n=this.getNextId(),r=this.#b({parent:this,id:n,x:s,y:i,uiManager:this.#a,isCentered:!0,...e});r&&this.add(r)}async deserialize(t){return await c.#g.get(t.annotationType??t.annotationEditorType)?.deserialize(t,this,this.#a)||null}createAndAddNewEditor(t,e,s={}){let i=this.getNextId(),n=this.#b({parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:this.#a,isCentered:e,...s});return n&&this.add(n),n}#w(){let{x:t,y:e,width:s,height:i}=this.div.getBoundingClientRect(),n=Math.max(0,t),r=Math.max(0,e),a=(n+Math.min(window.innerWidth,t+s))/2-t,o=(r+Math.min(window.innerHeight,e+i))/2-e,[h,l]=this.viewport.rotation%180==0?[a,o]:[o,a];return{offsetX:h,offsetY:l}}addNewEditor(){this.createAndAddNewEditor(this.#w(),!0)}setSelected(t){this.#a.setSelected(t)}toggleSelected(t){this.#a.toggleSelected(t)}unselect(t){this.#a.unselect(t)}pointerup(t){let{isMac:e}=K.platform;!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&this.#h&&(this.#h=!1,this.#f?.isDrawer&&this.#f.supportMultipleDrawings||(this.#e?this.#a.getMode()!==L.STAMP?this.createAndAddNewEditor(t,!1):this.#a.unselectAll():this.#e=!0))}pointerdown(t){if(this.#a.getMode()===L.HIGHLIGHT&&this.enableTextSelection(),this.#h){this.#h=!1;return}let{isMac:e}=K.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;if(this.#h=!0,this.#f?.isDrawer){this.startDrawingSession(t);return}let s=this.#a.getActive();this.#e=!s||s.isEmpty()}startDrawingSession(t){if(this.div.focus(),this.#l){this.#f.startDrawing(this,this.#a,!1,t);return}this.#a.setCurrentDrawingSession(this),this.#l=new AbortController;let e=this.#a.combinedSignal(this.#l);this.div.addEventListener("blur",(({relatedTarget:s})=>{s&&!this.div.contains(s)&&(this.#u=null,this.commitOrRemove())}),{signal:e}),this.#f.startDrawing(this,this.#a,!1,t)}pause(t){if(t){let{activeElement:e}=document;this.div.contains(e)&&(this.#u=e)}else this.#u&&setTimeout((()=>{this.#u?.focus(),this.#u=null}),0)}endDrawingSession(t=!1){return this.#l?(this.#a.setCurrentDrawingSession(null),this.#l.abort(),this.#l=null,this.#u=null,this.#f.endDrawing(t)):null}findNewParent(t,e,s){let i=this.#a.findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}commitOrRemove(){return this.#l?(this.endDrawingSession(),!0):!1}onScaleChanging(){this.#l&&this.#f.onScaleChangingWhenDrawing(this)}destroy(){this.commitOrRemove(),this.#a.getActive()?.parent===this&&(this.#a.commitOrRemove(),this.#a.setActiveEditor(null)),this.#r&&(clearTimeout(this.#r),this.#r=null);for(let t of this.#n.values())this.#t?.removePointerInTextLayer(t.contentDiv),t.setParent(null),t.isAttachedToDOM=!1,t.div.remove();this.div=null,this.#n.clear(),this.#a.removeLayer(this)}#v(){for(let t of this.#n.values())t.isEmpty()&&t.remove()}render({viewport:t}){this.viewport=t,Et(this.div,t);for(let e of this.#a.getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){this.#a.commitOrRemove(),this.#v();let e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,Et(this.div,{rotation:s}),e!==s)for(let i of this.#n.values())i.rotate(s)}get pageDimensions(){let{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return this.#a.viewParameters.realScale}},vi=class c{#t=null;#e=0;#s=new Map;#i=new Map;constructor({pageIndex:t}){this.pageIndex=t}setParent(t){if(this.#t){if(this.#t!==t){if(this.#s.size>0)for(let e of this.#s.values())e.remove(),t.append(e);this.#t=t}}else this.#t=t}static get _svgFactory(){return N(this,"_svgFactory",new Xt)}static#r(t,[e,s,i,n]){let{style:r}=t;r.top=100*s+"%",r.left=100*e+"%",r.width=100*i+"%",r.height=100*n+"%"}#n(){let t=c._svgFactory.create(1,1,!0);return this.#t.append(t),t.setAttribute("aria-hidden",!0),t}#h(t,e){let s=c._svgFactory.createElement("clipPath");t.append(s);let i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");let n=c._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i}#o(t,e){for(let[s,i]of Object.entries(e))i===null?t.removeAttribute(s):t.setAttribute(s,i)}draw(t,e=!1,s=!1){let i=this.#e++,n=this.#n(),r=c._svgFactory.createElement("defs");n.append(r);let a=c._svgFactory.createElement("path");r.append(a);let o=`path_p${this.pageIndex}_${i}`;a.setAttribute("id",o),a.setAttribute("vector-effect","non-scaling-stroke"),e&&this.#i.set(i,a);let h=s?this.#h(r,o):null,l=c._svgFactory.createElement("use");return n.append(l),l.setAttribute("href",`#${o}`),this.updateProperties(n,t),this.#s.set(i,n),{id:i,clipPathId:`url(#${h})`}}drawOutline(t,e){let s=this.#e++,i=this.#n(),n=c._svgFactory.createElement("defs");i.append(n);let r=c._svgFactory.createElement("path");n.append(r);let a=`path_p${this.pageIndex}_${s}`;r.setAttribute("id",a),r.setAttribute("vector-effect","non-scaling-stroke");let o;if(e){let d=c._svgFactory.createElement("mask");n.append(d),o=`mask_p${this.pageIndex}_${s}`,d.setAttribute("id",o),d.setAttribute("maskUnits","objectBoundingBox");let u=c._svgFactory.createElement("rect");d.append(u),u.setAttribute("width","1"),u.setAttribute("height","1"),u.setAttribute("fill","white");let p=c._svgFactory.createElement("use");d.append(p),p.setAttribute("href",`#${a}`),p.setAttribute("stroke","none"),p.setAttribute("fill","black"),p.setAttribute("fill-rule","nonzero"),p.classList.add("mask")}let h=c._svgFactory.createElement("use");i.append(h),h.setAttribute("href",`#${a}`),o&&h.setAttribute("mask",`url(#${o})`);let l=h.cloneNode();return i.append(l),h.classList.add("mainOutline"),l.classList.add("secondaryOutline"),this.updateProperties(i,t),this.#s.set(s,i),s}finalizeDraw(t,e){this.#i.delete(t),this.updateProperties(t,e)}updateProperties(t,e){if(!e)return;let{root:s,bbox:i,rootClass:n,path:r}=e,a=typeof t=="number"?this.#s.get(t):t;if(a){if(s&&this.#o(a,s),i&&c.#r(a,i),n){let{classList:o}=a;for(let[h,l]of Object.entries(n))o.toggle(h,l)}if(r){let o=a.firstChild.firstChild;this.#o(o,r)}}}updateParent(t,e){if(e===this)return;let s=this.#s.get(t);s&&(e.#t.append(s),this.#s.delete(t),e.#s.set(t,s))}remove(t){this.#i.delete(t),this.#t!==null&&(this.#s.get(t).remove(),this.#s.delete(t))}destroy(){this.#t=null;for(let t of this.#s.values())t.remove();this.#s.clear(),this.#i.clear()}};globalThis.pdfjsTestingUtils={HighlightOutliner:Qt};var fr=R.AbortException,mr=R.AnnotationEditorLayer,br=R.AnnotationEditorParamsType,vr=R.AnnotationEditorType,Ar=R.AnnotationEditorUIManager,wr=R.AnnotationLayer,yr=R.AnnotationMode,_r=R.ColorPicker,xr=R.DOMSVGFactory,Sr=R.DrawLayer,Er=R.FeatureTest,Ji=R.GlobalWorkerOptions,Cr=R.ImageKind,Mr=R.InvalidPDFException,kr=R.MissingPDFException,Tr=R.OPS,Rr=R.OutputScale,Zi=R.PDFDataRangeTransport,Pr=R.PDFDateString,Ir=R.PDFWorker,Lr=R.PasswordResponses,Dr=R.PermissionFlag,Fr=R.PixelsPerInch,tn=R.RenderingCancelledException,Nr=R.TextLayer,Or=R.TouchManager,Br=R.UnexpectedResponseException,$r=R.Util,Hr=R.VerbosityLevel,zr=R.XfaLayer,jr=R.build,Vr=R.createValidAbsoluteUrl,Gr=R.fetchData,en=R.getDocument,Ur=R.getFilenameFromUrl,Wr=R.getPdfFilenameFromUrl,qr=R.getXfaPageViewport,Xr=R.isDataScheme,Yr=R.isPdfFile,Kr=R.noContextMenu,Qr=R.normalizeUnicode,Jr=R.setLayerDimensions,Zr=R.shadow,ta=R.stopEvent,ea=R.version;import{E as qe}from"./store-BsSRYN7v.js";var rr="4.2.6-ym.10",ar=window.__YM_PDFJS_BASE__||`https://cdn.jsdelivr.net/npm/@yuuichi/openlist-assets@${rr}/dist/assets/pdfjs/`,xi=ar;Ji.workerSrc=`${xi}pdf.worker.min.mjs`;var ra=1<<20,or=12<<20;function ct(c,t={},e=[]){let s=document.createElement(c);for(let[i,n]of Object.entries(t))i==="class"?s.className=n:i==="style"?Object.assign(s.style,n):i.startsWith("on")&&typeof n=="function"?s.addEventListener(i.slice(2),n):n!=null&&s.setAttribute(i,n);for(let i of[].concat(e))i!=null&&s.appendChild(typeof i=="string"?document.createTextNode(i):i);return s}function hr(){let c=ct("div",{class:"ym-pdfjs-viewer",style:{display:"flex","flex-direction":"column",width:"100%",height:"100%",minHeight:"60vh",background:"var(--chakra-colors-chakra-subtle-bg, #525659)"}}),t=ct("input",{type:"number",min:"1",value:"1",style:{width:"56px","text-align":"center"},"aria-label":"Page number"}),e=ct("span",{},["/ -"]),s=ct("span",{},["100%"]),i=ct("div",{style:{marginLeft:"auto",opacity:".75","font-size":"12px"}},[""]),n=ct("div",{style:{flex:"1",overflow:"auto",position:"relative",display:"flex","justify-content":"center",padding:"12px"}}),r=ct("canvas",{style:{"box-shadow":"0 2px 12px rgba(0,0,0,.4)",background:"#fff"}}),a=ct("div",{style:{display:"flex","align-items":"center",gap:"8px",padding:"6px 10px",background:"var(--chakra-colors-chakra-body-bg, #2d3748)",color:"var(--chakra-colors-chakra-body-text, #e2e8f0)","border-bottom":"1px solid rgba(128,128,128,.3)",position:"sticky",top:"0","z-index":"2"}},[o("\u2039","Previous page",()=>g(h.page-1)),t,e,o("\u203A","Next page",()=>g(h.page+1)),ct("span",{style:{width:"1px",height:"20px",background:"rgba(128,128,128,.4)"}}),o("\u2212","Zoom out",()=>f(h.scale/1.25)),s,o("+","Zoom in",()=>f(h.scale*1.25)),o("Fit","Fit width",()=>m()),i]);function o(w,x,_){return ct("button",{type:"button",title:x,"aria-label":x,onClick:_,style:{minWidth:"32px",height:"28px",padding:"0 8px",cursor:"pointer",border:"1px solid rgba(128,128,128,.4)","border-radius":"6px",background:"transparent",color:"inherit"}},[w])}c.appendChild(a),c.appendChild(n),n.appendChild(r);let h={doc:null,page:1,scale:1.2,numPages:0,renderTask:null,pendingPage:null,fit:!0,bytes:0,destroyed:!1};function l(w){i.textContent=w}function d(w,x){let _=new Map,E=new Zi(x,new Uint8Array(0)),M=async(T,P)=>{let O=`${T}-${P}`;if(_.has(O))return _.get(O);let $=(async()=>{let F;for(let j=0;j<3;j++)try{let V=await fetch(w,{headers:{Range:`bytes=${T}-${P-1}`},credentials:"omit",referrerPolicy:"no-referrer",redirect:"follow"});if(V.status!==206)throw new Error(`Range HTTP ${V.status}`);let k=new Uint8Array(await V.arrayBuffer());h.destroyed||(h.bytes+=k.byteLength,l(`${(h.bytes/1048576).toFixed(1)} MB loaded`)),E.onDataRange(T,k);return}catch(V){F=V,await new Promise(k=>setTimeout(k,300*(j+1)))}throw F})();return _.set(O,$),$.finally(()=>_.delete(O)),$};return E.requestRange=(T,P)=>{M(T,P)},E.requestDataRange=E.requestRange,E}async function u(){try{let w=qe&&qe.raw_url;if(!w){l("No source URL");return}let x=new URL(w,location.href).href;l("Connecting\u2026");let _=Number(qe&&qe.size)||0,E={isEvalSupported:!1,disableAutoFetch:!0,disableStream:!0,cMapUrl:`${xi}cmaps/`,cMapPacked:!0,standardFontDataUrl:`${xi}standard_fonts/`};_>0?E.range=d(x,_):E.url=x;let M=en(E);h.doc=await M.promise,h.numPages=h.doc.numPages,e.textContent=`/ ${h.numPages}`,t.max=String(h.numPages),await p(1)}catch(w){console.error("[ym-pdfjs]",w),l(`Failed to load PDF: ${w&&w.message?w.message:w}`)}}async function p(w,{rebuildScale:x=!1}={}){if(!h.doc)return;w=Math.min(Math.max(1,w|0),h.numPages),h.page=w,t.value=String(w);let _=await h.doc.getPage(w),E=_.getViewport({scale:1});if(h.fit||x){let F=(n.clientWidth-32)/E.width;h.scale=Math.max(.4,Math.min(4,F)),h.fit=!0}let M=Math.min(window.devicePixelRatio||1,2),T=_.getViewport({scale:h.scale*M});if(r.width=Math.floor(T.width),r.height=Math.floor(T.height),r.style.width=`${Math.floor(T.width/M)}px`,r.style.height=`${Math.floor(T.height/M)}px`,s.textContent=`${Math.round(h.scale*100)}%`,h.renderTask)try{h.renderTask.cancel()}catch{}let P=r.getContext("2d"),O=_.render({canvasContext:P,viewport:T});h.renderTask=O;try{l(`Page ${w}/${h.numPages} \xB7 ${(h.bytes/1048576).toFixed(1)} MB loaded`),await O.promise,h.bytes<or&&h.doc.getPage(Math.min(h.numPages,w+1)).catch(()=>{})}catch($){if(!($ instanceof tn))throw $}}function g(w){p(w)}function f(w){h.fit=!1,h.scale=Math.max(.4,Math.min(6,w)),p(h.page)}function m(){h.fit=!0,p(h.page,{rebuildScale:!0})}t.addEventListener("change",()=>g(Number(t.value)||1)),t.addEventListener("keydown",w=>{w.key==="Enter"&&g(Number(t.value)||1)}),n.addEventListener("wheel",w=>{(w.ctrlKey||w.metaKey)&&(w.preventDefault(),f(h.scale*(w.deltaY<0?1.1:1/1.1)))},{passive:!1});let b,v=()=>{clearTimeout(b),b=setTimeout(()=>{h.fit&&p(h.page,{rebuildScale:!0})},150)};window.addEventListener("resize",v);let A=new MutationObserver(()=>{c.isConnected||y()});A.observe(document.body,{childList:!0,subtree:!0});function y(){if(!h.destroyed){h.destroyed=!0,A.disconnect(),window.removeEventListener("resize",v);try{h.renderTask?.cancel()}catch{}h.doc?.destroy().catch(()=>{})}}return u(),c}var aa=hr;export{aa as default};
|
|
7
|
+
`)){r.insertNode(document.createTextNode(i)),this.editorDiv.normalize(),n.collapseToStart();return}let{startContainer:a,startOffset:l}=r,h=[],c=[];if(a.nodeType===Node.TEXT_NODE){let f=a.parentElement;if(c.push(a.nodeValue.slice(l).replaceAll(ge,"")),f!==this.editorDiv){let p=h;for(let g of this.editorDiv.childNodes)g!==f?p.push(o.#h(g)):p=c}h.push(a.nodeValue.slice(0,l).replaceAll(ge,""))}else if(a===this.editorDiv){let f=h,p=0;for(let g of this.editorDiv.childNodes)p++===l&&(f=c),f.push(o.#h(g))}this.#e=`${h.join(`
|
|
8
|
+
`)}${i}${c.join(`
|
|
9
|
+
`)}`,this.#u();let d=new Range,u=h.reduce(((f,p)=>f+p.length),0);for(let{firstChild:f}of this.editorDiv.childNodes)if(f.nodeType===Node.TEXT_NODE){let p=f.nodeValue.length;if(u<=p){d.setStart(f,u),d.setEnd(f,u);break}u-=p}n.removeAllRanges(),n.addRange(d)}#u(){if(this.editorDiv.replaceChildren(),this.#e)for(let t of this.#e.split(`
|
|
10
|
+
`)){let e=document.createElement("div");e.append(t?document.createTextNode(t):document.createElement("br")),this.editorDiv.append(e)}}#d(){return this.#e.replaceAll("\xA0"," ")}static#f(t){return t.replaceAll(" ","\xA0")}get contentDiv(){return this.editorDiv}static async deserialize(t,e,s){let i=null;if(t instanceof Ve){let{data:{defaultAppearanceData:{fontSize:r,fontColor:a},rect:l,rotation:h,id:c,popupRef:d},textContent:u,textPosition:f,parent:{page:{pageNumber:p}}}=t;if(!u||u.length===0)return null;i=t={annotationType:D.FREETEXT,color:Array.from(a),fontSize:r,value:u.join(`
|
|
11
|
+
`),position:f,pageIndex:p-1,rect:l.slice(0),rotation:h,id:c,deleted:!1,popupRef:d}}let n=await super.deserialize(t,e,s);return n.#r=t.fontSize,n.#t=k.makeHexColor(...t.color),n.#e=o.#f(t.value),n.annotationElementId=t.id||null,n._initialData=i,n}serialize(t=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let e=o._internalPadding*this.parentScale,s=this.getRect(e,e),i=W._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:this.#t),n={annotationType:D.FREETEXT,color:i,fontSize:this.#r,value:this.#d(),pageIndex:this.pageIndex,rect:s,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return t?n:this.annotationElementId&&!this.#a(n)?null:(n.id=this.annotationElementId,n)}#a(t){let{value:e,fontSize:s,color:i,pageIndex:n}=this._initialData;return this._hasBeenMoved||t.value!==e||t.fontSize!==s||t.color.some(((r,a)=>r!==i[a]))||t.pageIndex!==n}renderAnnotationElement(t){let e=super.renderAnnotationElement(t);if(this.deleted)return e;let{style:s}=e;s.fontSize=`calc(${this.#r}px * var(--scale-factor))`,s.color=this.#t,e.replaceChildren();for(let n of this.#e.split(`
|
|
12
|
+
`)){let r=document.createElement("div");r.append(n?document.createTextNode(n):document.createElement("br")),e.append(r)}let i=o._internalPadding*this.parentScale;return t.updateEdited({rect:this.getRect(i,i),popupContent:this.#e}),e}resetAnnotationElement(t){super.resetAnnotationElement(t),t.resetEdited()}},E=class{static PRECISION=1e-4;toSVGPath(){z("Abstract method `toSVGPath` must be implemented.")}get box(){z("Abstract getter `box` must be implemented.")}serialize(t,e){z("Abstract method `serialize` must be implemented.")}static _rescale(t,e,s,i,n,r){r||=new Float32Array(t.length);for(let a=0,l=t.length;a<l;a+=2)r[a]=e+t[a]*i,r[a+1]=s+t[a+1]*n;return r}static _rescaleAndSwap(t,e,s,i,n,r){r||=new Float32Array(t.length);for(let a=0,l=t.length;a<l;a+=2)r[a]=e+t[a+1]*i,r[a+1]=s+t[a]*n;return r}static _translate(t,e,s,i){i||=new Float32Array(t.length);for(let n=0,r=t.length;n<r;n+=2)i[n]=e+t[n],i[n+1]=s+t[n+1];return i}static svgRound(t){return Math.round(1e4*t)}static _normalizePoint(t,e,s,i,n){switch(n){case 90:return[1-e/s,t/i];case 180:return[1-t/s,1-e/i];case 270:return[e/s,1-t/i];default:return[t/s,e/i]}}static _normalizePagePoint(t,e,s){switch(s){case 90:return[1-e,t];case 180:return[1-t,1-e];case 270:return[e,1-t];default:return[t,e]}}static createBezierPoints(t,e,s,i,n,r){return[(t+5*s)/6,(e+5*i)/6,(5*s+n)/6,(5*i+r)/6,(s+n)/2,(i+r)/2]}},qe=class o{#t;#e=[];#s;#i;#r=[];#n=new Float32Array(18);#l;#o;#c;#h;#u;#d;#f=[];static#a=8;static#p=2;static#m=o.#a+o.#p;constructor({x:t,y:e},s,i,n,r,a=0){this.#t=s,this.#d=n*i,this.#i=r,this.#n.set([NaN,NaN,NaN,NaN,t,e],6),this.#s=a,this.#h=o.#a*i,this.#c=o.#m*i,this.#u=i,this.#f.push(t,e)}isEmpty(){return isNaN(this.#n[8])}#g(){let t=this.#n.subarray(4,6),e=this.#n.subarray(16,18),[s,i,n,r]=this.#t;return[(this.#l+(t[0]-e[0])/2-s)/n,(this.#o+(t[1]-e[1])/2-i)/r,(this.#l+(e[0]-t[0])/2-s)/n,(this.#o+(e[1]-t[1])/2-i)/r]}add({x:t,y:e}){this.#l=t,this.#o=e;let[s,i,n,r]=this.#t,[a,l,h,c]=this.#n.subarray(8,12),d=t-h,u=e-c,f=Math.hypot(d,u);if(f<this.#c)return!1;let p=f-this.#h,g=p/f,m=g*d,b=g*u,y=a,w=l;a=h,l=c,h+=m,c+=b,this.#f?.push(t,e);let A=m/p,_=-b/p*this.#d,x=A*this.#d;return this.#n.set(this.#n.subarray(2,8),0),this.#n.set([h+_,c+x],4),this.#n.set(this.#n.subarray(14,18),12),this.#n.set([h-_,c-x],16),isNaN(this.#n[6])?(this.#r.length===0&&(this.#n.set([a+_,l+x],2),this.#r.push(NaN,NaN,NaN,NaN,(a+_-s)/n,(l+x-i)/r),this.#n.set([a-_,l-x],14),this.#e.push(NaN,NaN,NaN,NaN,(a-_-s)/n,(l-x-i)/r)),this.#n.set([y,w,a,l,h,c],6),!this.isEmpty()):(this.#n.set([y,w,a,l,h,c],6),Math.abs(Math.atan2(w-l,y-a)-Math.atan2(b,m))<Math.PI/2?([a,l,h,c]=this.#n.subarray(2,6),this.#r.push(NaN,NaN,NaN,NaN,((a+h)/2-s)/n,((l+c)/2-i)/r),[a,l,y,w]=this.#n.subarray(14,18),this.#e.push(NaN,NaN,NaN,NaN,((y+a)/2-s)/n,((w+l)/2-i)/r),!0):([y,w,a,l,h,c]=this.#n.subarray(0,6),this.#r.push(((y+5*a)/6-s)/n,((w+5*l)/6-i)/r,((5*a+h)/6-s)/n,((5*l+c)/6-i)/r,((a+h)/2-s)/n,((l+c)/2-i)/r),[h,c,a,l,y,w]=this.#n.subarray(12,18),this.#e.push(((y+5*a)/6-s)/n,((w+5*l)/6-i)/r,((5*a+h)/6-s)/n,((5*l+c)/6-i)/r,((a+h)/2-s)/n,((l+c)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";let t=this.#r,e=this.#e;if(isNaN(this.#n[6])&&!this.isEmpty())return this.#b();let s=[];s.push(`M${t[4]} ${t[5]}`);for(let i=6;i<t.length;i+=6)isNaN(t[i])?s.push(`L${t[i+4]} ${t[i+5]}`):s.push(`C${t[i]} ${t[i+1]} ${t[i+2]} ${t[i+3]} ${t[i+4]} ${t[i+5]}`);this.#y(s);for(let i=e.length-6;i>=6;i-=6)isNaN(e[i])?s.push(`L${e[i+4]} ${e[i+5]}`):s.push(`C${e[i]} ${e[i+1]} ${e[i+2]} ${e[i+3]} ${e[i+4]} ${e[i+5]}`);return this.#A(s),s.join(" ")}#b(){let[t,e,s,i]=this.#t,[n,r,a,l]=this.#g();return`M${(this.#n[2]-t)/s} ${(this.#n[3]-e)/i} L${(this.#n[4]-t)/s} ${(this.#n[5]-e)/i} L${n} ${r} L${a} ${l} L${(this.#n[16]-t)/s} ${(this.#n[17]-e)/i} L${(this.#n[14]-t)/s} ${(this.#n[15]-e)/i} Z`}#A(t){let e=this.#e;t.push(`L${e[4]} ${e[5]} Z`)}#y(t){let[e,s,i,n]=this.#t,r=this.#n.subarray(4,6),a=this.#n.subarray(16,18),[l,h,c,d]=this.#g();t.push(`L${(r[0]-e)/i} ${(r[1]-s)/n} L${l} ${h} L${c} ${d} L${(a[0]-e)/i} ${(a[1]-s)/n}`)}newFreeDrawOutline(t,e,s,i,n,r){return new We(t,e,s,i,n,r)}getOutlines(){let t=this.#r,e=this.#e,s=this.#n,[i,n,r,a]=this.#t,l=new Float32Array((this.#f?.length??0)+2);for(let d=0,u=l.length-2;d<u;d+=2)l[d]=(this.#f[d]-i)/r,l[d+1]=(this.#f[d+1]-n)/a;if(l[l.length-2]=(this.#l-i)/r,l[l.length-1]=(this.#o-n)/a,isNaN(s[6])&&!this.isEmpty())return this.#v(l);let h=new Float32Array(this.#r.length+24+this.#e.length),c=t.length;for(let d=0;d<c;d+=2)isNaN(t[d])?h[d]=h[d+1]=NaN:(h[d]=t[d],h[d+1]=t[d+1]);c=this.#E(h,c);for(let d=e.length-6;d>=6;d-=6)for(let u=0;u<6;u+=2)isNaN(e[d+u])?(h[c]=h[c+1]=NaN,c+=2):(h[c]=e[d+u],h[c+1]=e[d+u+1],c+=2);return this.#x(h,c),this.newFreeDrawOutline(h,l,this.#t,this.#u,this.#s,this.#i)}#v(t){let e=this.#n,[s,i,n,r]=this.#t,[a,l,h,c]=this.#g(),d=new Float32Array(36);return d.set([NaN,NaN,NaN,NaN,(e[2]-s)/n,(e[3]-i)/r,NaN,NaN,NaN,NaN,(e[4]-s)/n,(e[5]-i)/r,NaN,NaN,NaN,NaN,a,l,NaN,NaN,NaN,NaN,h,c,NaN,NaN,NaN,NaN,(e[16]-s)/n,(e[17]-i)/r,NaN,NaN,NaN,NaN,(e[14]-s)/n,(e[15]-i)/r],0),this.newFreeDrawOutline(d,t,this.#t,this.#u,this.#s,this.#i)}#x(t,e){let s=this.#e;return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+6}#E(t,e){let s=this.#n.subarray(4,6),i=this.#n.subarray(16,18),[n,r,a,l]=this.#t,[h,c,d,u]=this.#g();return t.set([NaN,NaN,NaN,NaN,(s[0]-n)/a,(s[1]-r)/l,NaN,NaN,NaN,NaN,h,c,NaN,NaN,NaN,NaN,d,u,NaN,NaN,NaN,NaN,(i[0]-n)/a,(i[1]-r)/l],e),e+24}},We=class extends E{#t;#e=new Float32Array(4);#s;#i;#r;#n;#l;constructor(t,e,s,i,n,r){super(),this.#l=t,this.#r=e,this.#t=s,this.#n=i,this.#s=n,this.#i=r,this.lastPoint=[NaN,NaN],this.#o(r);let[a,l,h,c]=this.#e;for(let d=0,u=t.length;d<u;d+=2)t[d]=(t[d]-a)/h,t[d+1]=(t[d+1]-l)/c;for(let d=0,u=e.length;d<u;d+=2)e[d]=(e[d]-a)/h,e[d+1]=(e[d+1]-l)/c}toSVGPath(){let t=[`M${this.#l[4]} ${this.#l[5]}`];for(let e=6,s=this.#l.length;e<s;e+=6)isNaN(this.#l[e])?t.push(`L${this.#l[e+4]} ${this.#l[e+5]}`):t.push(`C${this.#l[e]} ${this.#l[e+1]} ${this.#l[e+2]} ${this.#l[e+3]} ${this.#l[e+4]} ${this.#l[e+5]}`);return t.push("Z"),t.join(" ")}serialize([t,e,s,i],n){let r=s-t,a=i-e,l,h;switch(n){case 0:l=E._rescale(this.#l,t,i,r,-a),h=E._rescale(this.#r,t,i,r,-a);break;case 90:l=E._rescaleAndSwap(this.#l,t,e,r,a),h=E._rescaleAndSwap(this.#r,t,e,r,a);break;case 180:l=E._rescale(this.#l,s,e,-r,a),h=E._rescale(this.#r,s,e,-r,a);break;case 270:l=E._rescaleAndSwap(this.#l,s,i,-r,-a),h=E._rescaleAndSwap(this.#r,s,i,-r,-a)}return{outline:Array.from(l),points:[Array.from(h)]}}#o(t){let e=this.#l,s=e[4],i=e[5],n=s,r=i,a=s,l=i,h=s,c=i,d=t?Math.max:Math.min;for(let f=6,p=e.length;f<p;f+=6){if(isNaN(e[f]))n=Math.min(n,e[f+4]),r=Math.min(r,e[f+5]),a=Math.max(a,e[f+4]),l=Math.max(l,e[f+5]),c<e[f+5]?(h=e[f+4],c=e[f+5]):c===e[f+5]&&(h=d(h,e[f+4]));else{let g=k.bezierBoundingBox(s,i,...e.slice(f,f+6));n=Math.min(n,g[0]),r=Math.min(r,g[1]),a=Math.max(a,g[2]),l=Math.max(l,g[3]),c<g[3]?(h=g[2],c=g[3]):c===g[3]&&(h=d(h,g[2]))}s=e[f+4],i=e[f+5]}let u=this.#e;u[0]=n-this.#s,u[1]=r-this.#s,u[2]=a-n+2*this.#s,u[3]=l-r+2*this.#s,this.lastPoint=[h,c]}get box(){return this.#e}newOutliner(t,e,s,i,n,r=0){return new qe(t,e,s,i,n,r)}getNewOutline(t,e){let[s,i,n,r]=this.#e,[a,l,h,c]=this.#t,d=n*h,u=r*c,f=s*h+a,p=i*c+l,g=this.newOutliner({x:this.#r[0]*d+f,y:this.#r[1]*u+p},this.#t,this.#n,t,this.#i,e??this.#s);for(let m=2;m<this.#r.length;m+=2)g.add({x:this.#r[m]*d+f,y:this.#r[m+1]*u+p});return g.getOutlines()}},oe=class{#t;#e;#s=[];#i=[];constructor(t,e=0,s=0,i=!0){let n=1/0,r=-1/0,a=1/0,l=-1/0,h=10**-4;for(let{x:m,y:b,width:y,height:w}of t){let A=Math.floor((m-e)/h)*h,_=Math.ceil((m+y+e)/h)*h,x=Math.floor((b-e)/h)*h,v=Math.ceil((b+w+e)/h)*h,C=[A,x,v,!0],M=[_,x,v,!1];this.#s.push(C,M),n=Math.min(n,A),r=Math.max(r,_),a=Math.min(a,x),l=Math.max(l,v)}let c=r-n+2*s,d=l-a+2*s,u=n-s,f=a-s,p=this.#s.at(i?-1:-2),g=[p[0],p[2]];for(let m of this.#s){let[b,y,w]=m;m[0]=(b-u)/c,m[1]=(y-f)/d,m[2]=(w-f)/d}this.#t=new Float32Array([u,f,c,d]),this.#e=g}getOutlines(){this.#s.sort(((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]));let t=[];for(let e of this.#s)e[3]?(t.push(...this.#c(e)),this.#l(e)):(this.#o(e),t.push(...this.#c(e)));return this.#r(t)}#r(t){let e=[],s=new Set;for(let r of t){let[a,l,h]=r;e.push([a,l,r],[a,h,r])}e.sort(((r,a)=>r[1]-a[1]||r[0]-a[0]));for(let r=0,a=e.length;r<a;r+=2){let l=e[r][2],h=e[r+1][2];l.push(h),h.push(l),s.add(l),s.add(h)}let i=[],n;for(;s.size>0;){let r=s.values().next().value,[a,l,h,c,d]=r;s.delete(r);let u=a,f=l;for(n=[a,h],i.push(n);;){let p;if(s.has(c))p=c;else{if(!s.has(d))break;p=d}s.delete(p),[a,l,h,c,d]=p,u!==a&&(n.push(u,f,a,f===l?l:h),u=a),f=f===l?h:l}n.push(u,f)}return new Ei(i,this.#t,this.#e)}#n(t){let e=this.#i,s=0,i=e.length-1;for(;s<=i;){let n=s+i>>1,r=e[n][0];if(r===t)return n;r<t?s=n+1:i=n-1}return i+1}#l([,t,e]){let s=this.#n(t);this.#i.splice(s,0,[t,e])}#o([,t,e]){let s=this.#n(t);for(let i=s;i<this.#i.length;i++){let[n,r]=this.#i[i];if(n!==t)break;if(n===t&&r===e){this.#i.splice(i,1);return}}for(let i=s-1;i>=0;i--){let[n,r]=this.#i[i];if(n!==t)break;if(n===t&&r===e){this.#i.splice(i,1);return}}}#c(t){let[e,s,i]=t,n=[[e,s,i]],r=this.#n(i);for(let a=0;a<r;a++){let[l,h]=this.#i[a];for(let c=0,d=n.length;c<d;c++){let[,u,f]=n[c];if(!(h<=u||f<=l))if(u>=l)if(f>h)n[c][1]=h;else{if(d===1)return[];n.splice(c,1),c--,d--}else n[c][2]=l,f>h&&n.push([e,h,f])}}return n}},Ei=class extends E{#t;#e;constructor(t,e,s){super(),this.#e=t,this.#t=e,this.lastPoint=s}toSVGPath(){let t=[];for(let e of this.#e){let[s,i]=e;t.push(`M${s} ${i}`);for(let n=2;n<e.length;n+=2){let r=e[n],a=e[n+1];r===s?(t.push(`V${a}`),i=a):a===i&&(t.push(`H${r}`),s=r)}t.push("Z")}return t.join(" ")}serialize([t,e,s,i],n){let r=[],a=s-t,l=i-e;for(let h of this.#e){let c=new Array(h.length);for(let d=0;d<h.length;d+=2)c[d]=t+h[d]*a,c[d+1]=i-h[d+1]*l;r.push(c)}return r}get box(){return this.#t}get classNamesForOutlining(){return["highlightOutline"]}},le=class extends qe{newFreeDrawOutline(t,e,s,i,n,r){return new Ci(t,e,s,i,n,r)}},Ci=class extends We{newOutliner(t,e,s,i,n,r=0){return new le(t,e,s,i,n,r)}},Xe=class o{#t=null;#e=null;#s;#i=null;#r=!1;#n=!1;#l=null;#o;#c=null;#h=null;#u;static#d=null;static get _keyboardManager(){return N(this,"_keyboardManager",new Dt([[["Escape","mac+Escape"],o.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],o.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],o.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],o.prototype._moveToPrevious],[["Home","mac+Home"],o.prototype._moveToBeginning],[["End","mac+End"],o.prototype._moveToEnd]]))}constructor({editor:t=null,uiManager:e=null}){t?(this.#n=!1,this.#u=B.HIGHLIGHT_COLOR,this.#l=t):(this.#n=!0,this.#u=B.HIGHLIGHT_DEFAULT_COLOR),this.#h=t?._uiManager||e,this.#o=this.#h._eventBus,this.#s=t?.color||this.#h?.highlightColors.values().next().value||"#FFFF98",o.#d||=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(){let t=this.#t=document.createElement("button");t.className="colorPicker",t.tabIndex="0",t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-button"),t.setAttribute("aria-haspopup",!0);let e=this.#h._signal;t.addEventListener("click",this.#m.bind(this),{signal:e}),t.addEventListener("keydown",this.#p.bind(this),{signal:e});let s=this.#e=document.createElement("span");return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=this.#s,t.append(s),t}renderMainDropdown(){let t=this.#i=this.#f();return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}#f(){let t=document.createElement("div"),e=this.#h._signal;t.addEventListener("contextmenu",ft,{signal:e}),t.className="dropdown",t.role="listbox",t.setAttribute("aria-multiselectable",!1),t.setAttribute("aria-orientation","vertical"),t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown");for(let[s,i]of this.#h.highlightColors){let n=document.createElement("button");n.tabIndex="0",n.role="option",n.setAttribute("data-color",i),n.title=s,n.setAttribute("data-l10n-id",o.#d[s]);let r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===this.#s),n.addEventListener("click",this.#a.bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",this.#p.bind(this),{signal:e}),t}#a(t,e){e.stopPropagation(),this.#o.dispatch("switchannotationeditorparams",{source:this,type:this.#u,value:t})}_colorSelectFromKeyboard(t){if(t.target===this.#t){this.#m(t);return}let e=t.target.getAttribute("data-color");e&&this.#a(e,t)}_moveToNext(t){this.#b?t.target!==this.#t?t.target.nextSibling?.focus():this.#i.firstChild?.focus():this.#m(t)}_moveToPrevious(t){t.target!==this.#i?.firstChild&&t.target!==this.#t?(this.#b||this.#m(t),t.target.previousSibling?.focus()):this.#b&&this._hideDropdownFromKeyboard()}_moveToBeginning(t){this.#b?this.#i.firstChild?.focus():this.#m(t)}_moveToEnd(t){this.#b?this.#i.lastChild?.focus():this.#m(t)}#p(t){o._keyboardManager.exec(this,t)}#m(t){if(this.#b){this.hideDropdown();return}if(this.#r=t.detail===0,this.#c||(this.#c=new AbortController,window.addEventListener("pointerdown",this.#g.bind(this),{signal:this.#h.combinedSignal(this.#c)})),this.#i){this.#i.classList.remove("hidden");return}let e=this.#i=this.#f();this.#t.append(e)}#g(t){this.#i?.contains(t.target)||this.hideDropdown()}hideDropdown(){this.#i?.classList.add("hidden"),this.#c?.abort(),this.#c=null}get#b(){return this.#i&&!this.#i.classList.contains("hidden")}_hideDropdownFromKeyboard(){this.#n||(this.#b?(this.hideDropdown(),this.#t.focus({preventScroll:!0,focusVisible:this.#r})):this.#l?.unselect())}updateColor(t){if(this.#e&&(this.#e.style.backgroundColor=t),!this.#i)return;let e=this.#h.highlightColors.values();for(let s of this.#i.children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){this.#t?.remove(),this.#t=null,this.#e=null,this.#i?.remove(),this.#i=null}},Ye=class o extends W{#t=null;#e=0;#s;#i=null;#r=null;#n=null;#l=null;#o=0;#c=null;#h=null;#u=null;#d=!1;#f=null;#a;#p=null;#m="";#g;#b="";static _defaultColor=null;static _defaultOpacity=1;static _defaultThickness=12;static _type="highlight";static _editorType=D.HIGHLIGHT;static _freeHighlightId=-1;static _freeHighlight=null;static _freeHighlightClipId="";static get _keyboardManager(){let t=o.prototype;return N(this,"_keyboardManager",new Dt([[["ArrowLeft","mac+ArrowLeft"],t._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],t._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],t._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],t._moveCaret,{args:[3]}]]))}constructor(t){super({...t,name:"highlightEditor"}),this.color=t.color||o._defaultColor,this.#g=t.thickness||o._defaultThickness,this.#a=t.opacity||o._defaultOpacity,this.#s=t.boxes||null,this.#b=t.methodOfCreation||"",this.#m=t.text||"",this._isDraggable=!1,t.highlightId>-1?(this.#d=!0,this.#y(t),this.#T()):this.#s&&(this.#t=t.anchorNode,this.#e=t.anchorOffset,this.#l=t.focusNode,this.#o=t.focusOffset,this.#A(),this.#T(),this.rotate(this.rotation))}get telemetryInitialData(){return{action:"added",type:this.#d?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:this.#g,methodOfCreation:this.#b}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.highlightColorNames.get(this.color)}}static computeTelemetryFinalData(t){return{numberOfColors:t.get("color").size}}#A(){let t=new oe(this.#s,.001);this.#h=t.getOutlines(),[this.x,this.y,this.width,this.height]=this.#h.box;let e=new oe(this.#s,.0025,.001,this._uiManager.direction==="ltr");this.#n=e.getOutlines();let{lastPoint:s}=this.#n;this.#f=[(s[0]-this.x)/this.width,(s[1]-this.y)/this.height]}#y({highlightOutlines:t,highlightId:e,clipPathId:s}){if(this.#h=t,this.#n=t.getNewOutline(this.#g/2+1.5,.0025),e>=0)this.#u=e,this.#i=s,this.parent.drawLayer.finalizeDraw(e,{bbox:t.box,path:{d:t.toSVGPath()}}),this.#p=this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:this.#n.box,path:{d:this.#n.toSVGPath()}},!0);else if(this.parent){let h=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(this.#u,{bbox:o.#_(this.#h.box,(h-this.rotation+360)%360),path:{d:t.toSVGPath()}}),this.parent.drawLayer.updateProperties(this.#p,{bbox:o.#_(this.#n.box,h),path:{d:this.#n.toSVGPath()}})}let[i,n,r,a]=t.box;switch(this.rotation){case 0:this.x=i,this.y=n,this.width=r,this.height=a;break;case 90:{let[h,c]=this.parentDimensions;this.x=n,this.y=1-i,this.width=r*c/h,this.height=a*h/c;break}case 180:this.x=1-i,this.y=1-n,this.width=r,this.height=a;break;case 270:{let[h,c]=this.parentDimensions;this.x=1-n,this.y=i,this.width=r*c/h,this.height=a*h/c;break}}let{lastPoint:l}=this.#n;this.#f=[(l[0]-i)/r,(l[1]-n)/a]}static initialize(t,e){W.initialize(t,e),o._defaultColor||=e.highlightColors?.values().next().value||"#fff066"}static updateDefaultParams(t,e){switch(t){case B.HIGHLIGHT_DEFAULT_COLOR:o._defaultColor=e;break;case B.HIGHLIGHT_THICKNESS:o._defaultThickness=e}}translateInPage(t,e){}get toolbarPosition(){return this.#f}updateParams(t,e){switch(t){case B.HIGHLIGHT_COLOR:this.#v(e);break;case B.HIGHLIGHT_THICKNESS:this.#x(e)}}static get defaultPropertiesToUpdate(){return[[B.HIGHLIGHT_DEFAULT_COLOR,o._defaultColor],[B.HIGHLIGHT_THICKNESS,o._defaultThickness]]}get propertiesToUpdate(){return[[B.HIGHLIGHT_COLOR,this.color||o._defaultColor],[B.HIGHLIGHT_THICKNESS,this.#g||o._defaultThickness],[B.HIGHLIGHT_FREE,this.#d]]}#v(t){let e=(n,r)=>{this.color=n,this.#a=r,this.parent?.drawLayer.updateProperties(this.#u,{root:{fill:n,"fill-opacity":r}}),this.#r?.updateColor(n)},s=this.color,i=this.#a;this.addCommands({cmd:e.bind(this,t,o._defaultOpacity),undo:e.bind(this,s,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:B.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(t)},!0)}#x(t){let e=this.#g,s=i=>{this.#g=i,this.#E(i)};this.addCommands({cmd:s.bind(this,t),undo:s.bind(this,e),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:B.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:t},!0)}async addEditToolbar(){let t=await super.addEditToolbar();return t?(this._uiManager.highlightColors&&(this.#r=new Xe({editor:this}),t.addColorPicker(this.#r)),t):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(this.#R())}getBaseTranslation(){return[0,0]}getRect(t,e){return super.getRect(t,e,this.#R())}onceAdded(t){this.annotationElementId||this.parent.addUndoableEditor(this),t&&this.div.focus()}remove(){this.#k(),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.#T(),this.isAttachedToDOM||this.parent.add(this)))}setParent(t){let e=!1;this.parent&&!t?this.#k():t&&(this.#T(t),e=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(t),this.show(this._isVisible),e&&this.select()}#E(t){if(!this.#d)return;this.#y({highlightOutlines:this.#h.getNewOutline(t/2)}),this.fixAndSetPosition();let[e,s]=this.parentDimensions;this.setDims(this.width*e,this.height*s)}#k(){this.#u!==null&&this.parent&&(this.parent.drawLayer.remove(this.#u),this.#u=null,this.parent.drawLayer.remove(this.#p),this.#p=null)}#T(t=this.parent){this.#u===null&&({id:this.#u,clipPathId:this.#i}=t.drawLayer.draw({bbox:this.#h.box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":this.#a},rootClass:{highlight:!0,free:this.#d},path:{d:this.#h.toSVGPath()}},!1,!0),this.#p=t.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:this.#d},bbox:this.#n.box,path:{d:this.#n.toSVGPath()}},this.#d),this.#c&&(this.#c.style.clipPath=this.#i))}static#_([t,e,s,i],n){switch(n){case 90:return[1-e-i,t,i,s];case 180:return[1-t-s,1-e-i,s,i];case 270:return[e,1-t-s,i,s]}return[t,e,s,i]}rotate(t){let{drawLayer:e}=this.parent,s;this.#d?(t=(t-this.rotation+360)%360,s=o.#_(this.#h.box,t)):s=o.#_([this.x,this.y,this.width,this.height],t),e.updateProperties(this.#u,{bbox:s,root:{"data-main-rotation":t}}),e.updateProperties(this.#p,{bbox:o.#_(this.#n.box,t),root:{"data-main-rotation":t}})}render(){if(this.div)return this.div;let t=super.render();this.#m&&(t.setAttribute("aria-label",this.#m),t.setAttribute("role","mark")),this.#d?t.classList.add("free"):this.div.addEventListener("keydown",this.#M.bind(this),{signal:this._uiManager._signal});let e=this.#c=document.createElement("div");t.append(e),e.setAttribute("aria-hidden","true"),e.className="internal",e.style.clipPath=this.#i;let[s,i]=this.parentDimensions;return this.setDims(this.width*s,this.height*i),_e(this,this.#c,["pointerover","pointerleave"]),this.enableEditing(),t}pointerover(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#p,{rootClass:{hovered:!0}})}pointerleave(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#p,{rootClass:{hovered:!1}})}#M(t){o._keyboardManager.exec(this,t)}_moveCaret(t){switch(this.parent.unselect(this),t){case 0:case 2:this.#C(!0);break;case 1:case 3:this.#C(!1)}}#C(t){if(!this.#t)return;let e=window.getSelection();t?e.setPosition(this.#t,this.#e):e.setPosition(this.#l,this.#o)}select(){super.select(),this.#p&&this.parent?.drawLayer.updateProperties(this.#p,{rootClass:{hovered:!1,selected:!0}})}unselect(){super.unselect(),this.#p&&(this.parent?.drawLayer.updateProperties(this.#p,{rootClass:{selected:!1}}),this.#d||this.#C(!1))}get _mustFixPosition(){return!this.#d}show(t=this._isVisible){super.show(t),this.parent&&(this.parent.drawLayer.updateProperties(this.#u,{rootClass:{hidden:!t}}),this.parent.drawLayer.updateProperties(this.#p,{rootClass:{hidden:!t}}))}#R(){return this.#d?this.rotation:0}#D(){if(this.#d)return null;let[t,e]=this.pageDimensions,[s,i]=this.pageTranslation,n=this.#s,r=new Float32Array(8*n.length),a=0;for(let{x:l,y:h,width:c,height:d}of n){let u=l*t+s,f=(1-h)*e+i;r[a]=r[a+4]=u,r[a+1]=r[a+3]=f,r[a+2]=r[a+6]=u+c*t,r[a+5]=r[a+7]=f-d*e,a+=8}return r}#N(t){return this.#h.serialize(t,this.#R())}static startHighlighting(t,e,{target:s,x:i,y:n}){let{x:r,y:a,width:l,height:h}=s.getBoundingClientRect(),c=new AbortController,d=t.combinedSignal(c),u=f=>{c.abort(),this.#w(t,f)};window.addEventListener("blur",u,{signal:d}),window.addEventListener("pointerup",u,{signal:d}),window.addEventListener("pointerdown",ht,{capture:!0,passive:!1,signal:d}),window.addEventListener("contextmenu",ft,{signal:d}),s.addEventListener("pointermove",this.#S.bind(this,t),{signal:d}),this._freeHighlight=new le({x:i,y:n},[r,a,l,h],t.scale,this._defaultThickness/2,e,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=t.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0)}static#S(t,e){this._freeHighlight.add(e)&&t.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})}static#w(t,e){this._freeHighlight.isEmpty()?t.drawLayer.remove(this._freeHighlightId):t.createAndAddNewEditor(e,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:"main_toolbar"}),this._freeHighlightId=-1,this._freeHighlight=null,this._freeHighlightClipId=""}static async deserialize(t,e,s){let i=null;if(t instanceof Ge){let{data:{quadPoints:p,rect:g,rotation:m,id:b,color:y,opacity:w,popupRef:A},parent:{page:{pageNumber:_}}}=t;i=t={annotationType:D.HIGHLIGHT,color:Array.from(y),opacity:w,quadPoints:p,boxes:null,pageIndex:_-1,rect:g.slice(0),rotation:m,id:b,deleted:!1,popupRef:A}}else if(t instanceof ae){let{data:{inkLists:p,rect:g,rotation:m,id:b,color:y,borderStyle:{rawWidth:w},popupRef:A},parent:{page:{pageNumber:_}}}=t;i=t={annotationType:D.HIGHLIGHT,color:Array.from(y),thickness:w,inkLists:p,boxes:null,pageIndex:_-1,rect:g.slice(0),rotation:m,id:b,deleted:!1,popupRef:A}}let{color:n,quadPoints:r,inkLists:a,opacity:l}=t,h=await super.deserialize(t,e,s);h.color=k.makeHexColor(...n),h.#a=l||1,a&&(h.#g=t.thickness),h.annotationElementId=t.id||null,h._initialData=i;let[c,d]=h.pageDimensions,[u,f]=h.pageTranslation;if(r){let p=h.#s=[];for(let g=0;g<r.length;g+=8)p.push({x:(r[g]-u)/c,y:1-(r[g+1]-f)/d,width:(r[g+2]-r[g])/c,height:(r[g+1]-r[g+5])/d});h.#A(),h.#T(),h.rotate(h.rotation)}else if(a){h.#d=!0;let p=a[0],g={x:p[0]-u,y:d-(p[1]-f)},m=new le(g,[0,0,c,d],1,h.#g/2,!0,.001);for(let w=0,A=p.length;w<A;w+=2)g.x=p[w]-u,g.y=d-(p[w+1]-f),m.add(g);let{id:b,clipPathId:y}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:h.color,"fill-opacity":h._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:m.toSVGPath()}},!0,!0);h.#y({highlightOutlines:m.getOutlines(),highlightId:b,clipPathId:y}),h.#T()}return h}serialize(t=!1){if(this.isEmpty()||t)return null;if(this.deleted)return this.serializeDeleted();let e=this.getRect(0,0),s=W._colorManager.convert(this.color),i={annotationType:D.HIGHLIGHT,color:s,opacity:this.#a,thickness:this.#g,quadPoints:this.#D(),outlines:this.#N(e),pageIndex:this.pageIndex,rect:e,rotation:this.#R(),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!this.#L(i)?null:(i.id=this.annotationElementId,i)}#L(t){let{color:e}=this._initialData;return t.color.some(((s,i)=>s!==e[i]))}renderAnnotationElement(t){return t.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}},ki=class{#t=Object.create(null);updateProperty(t,e){this[t]=e,this.updateSVGProperty(t,e)}updateProperties(t){if(t)for(let[e,s]of Object.entries(t))this.updateProperty(e,s)}updateSVGProperty(t,e){this.#t[t]=e}toSVGProperties(){let t=this.#t;return this.#t=Object.create(null),{root:t}}reset(){this.#t=Object.create(null)}updateAll(t=this){this.updateProperties(t)}clone(){z("Not implemented")}},Mi=class o extends W{#t=null;#e;_drawId=null;static _currentDrawId=-1;static _currentParent=null;static#s=null;static#i=null;static#r=null;static#n=NaN;static#l=null;static#o=null;static#c=NaN;static _INNER_MARGIN=3;constructor(t){super(t),this.#e=t.mustBeCommitted||!1,t.drawOutlines&&(this.#h(t),this.#f())}#h({drawOutlines:t,drawId:e,drawingOptions:s}){this.#t=t,this._drawingOptions||=s,e>=0?(this._drawId=e,this.parent.drawLayer.finalizeDraw(e,t.defaultProperties)):this._drawId=this.#u(t,this.parent),this.#m(t.box)}#u(t,e){let{id:s}=e.drawLayer.draw(o._mergeSVGProperties(this._drawingOptions.toSVGProperties(),t.defaultSVGProperties),!1,!1);return s}static _mergeSVGProperties(t,e){let s=new Set(Object.keys(t));for(let[i,n]of Object.entries(e))s.has(i)?Object.assign(t[i],n):t[i]=n;return t}static getDefaultDrawingOptions(t){z("Not implemented")}static get typesMap(){z("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(t,e){let s=this.typesMap.get(t);s&&this._defaultDrawingOptions.updateProperty(s,e),this._currentParent&&(o.#s.updateProperty(s,e),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(t,e){let s=this.constructor.typesMap.get(t);s&&this._updateProperty(t,s,e)}static get defaultPropertiesToUpdate(){let t=[],e=this._defaultDrawingOptions;for(let[s,i]of this.typesMap)t.push([s,e[i]]);return t}get propertiesToUpdate(){let t=[],{_drawingOptions:e}=this;for(let[s,i]of this.constructor.typesMap)t.push([s,e[i]]);return t}_updateProperty(t,e,s){let i=this._drawingOptions,n=i[e],r=a=>{i.updateProperty(e,a);let l=this.#t.updateProperty(e,a);l&&this.#m(l),this.parent?.drawLayer.updateProperties(this._drawId,i.toSVGProperties())};this.addCommands({cmd:r.bind(this,s),undo:r.bind(this,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:t,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){this.parent?.drawLayer.updateProperties(this._drawId,o._mergeSVGProperties(this.#t.getPathResizingSVGProperties(this.#p()),{bbox:this.#g()}))}_onResized(){this.parent?.drawLayer.updateProperties(this._drawId,o._mergeSVGProperties(this.#t.getPathResizedSVGProperties(this.#p()),{bbox:this.#g()}))}_onTranslating(t,e){this.parent?.drawLayer.updateProperties(this._drawId,{bbox:this.#g(t,e)})}_onTranslated(){this.parent?.drawLayer.updateProperties(this._drawId,o._mergeSVGProperties(this.#t.getPathTranslatedSVGProperties(this.#p(),this.parentDimensions),{bbox:this.#g()}))}_onStartDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}commit(){super.commit(),this.disableEditMode(),this.disableEditing()}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(t){this.annotationElementId||this.parent.addUndoableEditor(this),this._isDraggable=!0,this.#e&&(this.#e=!1,this.commit(),this.parent.setSelected(this),t&&this.isOnScreen&&this.div.focus())}remove(){this.#d(),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.#f(),this.#m(this.#t.box),this.isAttachedToDOM||this.parent.add(this)))}setParent(t){let e=!1;this.parent&&!t?(this._uiManager.removeShouldRescale(this),this.#d()):t&&(this._uiManager.addShouldRescale(this),this.#f(t),e=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(t),e&&this.select()}#d(){this._drawId!==null&&this.parent&&(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())}#f(t=this.parent){(this._drawId===null||this.parent!==t)&&(this._drawId===null?(this._drawingOptions.updateAll(),this._drawId=this.#u(this.#t,t)):this.parent.drawLayer.updateParent(this._drawId,t.drawLayer))}#a([t,e,s,i]){let{parentDimensions:[n,r],rotation:a}=this;switch(a){case 90:return[e,1-t,s*(r/n),i*(n/r)];case 180:return[1-t,1-e,s,i];case 270:return[1-e,t,s*(r/n),i*(n/r)];default:return[t,e,s,i]}}#p(){let{x:t,y:e,width:s,height:i,parentDimensions:[n,r],rotation:a}=this;switch(a){case 90:return[1-e,t,s*(n/r),i*(r/n)];case 180:return[1-t,1-e,s,i];case 270:return[e,1-t,s*(n/r),i*(r/n)];default:return[t,e,s,i]}}#m(t){if([this.x,this.y,this.width,this.height]=this.#a(t),this.div){this.fixAndSetPosition();let[e,s]=this.parentDimensions;this.setDims(this.width*e,this.height*s)}this._onResized()}#g(){let{x:t,y:e,width:s,height:i,rotation:n,parentRotation:r,parentDimensions:[a,l]}=this;switch((4*n+r)/90){case 1:return[1-e-i,t,i,s];case 2:return[1-t-s,1-e-i,s,i];case 3:return[e,1-t-s,i,s];case 4:return[t,e-s*(a/l),i*(l/a),s*(a/l)];case 5:return[1-e,t,s*(a/l),i*(l/a)];case 6:return[1-t-i*(l/a),1-e,i*(l/a),s*(a/l)];case 7:return[e-s*(a/l),1-t-i*(l/a),s*(a/l),i*(l/a)];case 8:return[t-s,e-i,s,i];case 9:return[1-e,t-s,i,s];case 10:return[1-t,1-e,s,i];case 11:return[e-i,1-t,i,s];case 12:return[t-i*(l/a),e,i*(l/a),s*(a/l)];case 13:return[1-e-s*(a/l),t-i*(l/a),s*(a/l),i*(l/a)];case 14:return[1-t,1-e-s*(a/l),i*(l/a),s*(a/l)];case 15:return[e,1-t,s*(a/l),i*(l/a)];default:return[t,e,s,i]}}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,o._mergeSVGProperties({bbox:this.#g()},this.#t.updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&this.#m(this.#t.updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;let t=super.render();t.classList.add("draw");let e=document.createElement("div");t.append(e),e.setAttribute("aria-hidden","true"),e.className="internal";let[s,i]=this.parentDimensions;return this.setDims(this.width*s,this.height*i),this._uiManager.addShouldRescale(this),this.disableEditing(),t}static createDrawerInstance(t,e,s,i,n){z("Not implemented")}static startDrawing(t,e,s,i){let{target:n,offsetX:r,offsetY:a,pointerId:l,pointerType:h}=i;if(o.#l&&o.#l!==h)return;let{viewport:{rotation:c}}=t,{width:d,height:u}=n.getBoundingClientRect(),f=o.#i=new AbortController,p=t.combinedSignal(f);o.#n||=l,o.#l??=h,window.addEventListener("pointerup",(g=>{o.#n===g.pointerId?this._endDraw(g):o.#o?.delete(g.pointerId)}),{signal:p}),window.addEventListener("pointercancel",(g=>{o.#n===g.pointerId?this._currentParent.endDrawingSession():o.#o?.delete(g.pointerId)}),{signal:p}),window.addEventListener("pointerdown",(g=>{o.#l===g.pointerType&&((o.#o||=new Set).add(g.pointerId),o.#s.isCancellable()&&(o.#s.removeLastElement(),o.#s.isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))}),{capture:!0,passive:!1,signal:p}),window.addEventListener("contextmenu",ft,{signal:p}),n.addEventListener("pointermove",this._drawMove.bind(this),{signal:p}),n.addEventListener("touchmove",(g=>{g.timeStamp===o.#c&&ht(g)}),{signal:p}),t.toggleDrawing(),e._editorUndoBar?.hide(),o.#s?t.drawLayer.updateProperties(this._currentDrawId,o.#s.startNew(r,a,d,u,c)):(e.updateUIForDefaultProperties(this),o.#s=this.createDrawerInstance(r,a,d,u,c),o.#r=this.getDefaultDrawingOptions(),this._currentParent=t,{id:this._currentDrawId}=t.drawLayer.draw(this._mergeSVGProperties(o.#r.toSVGProperties(),o.#s.defaultSVGProperties),!0,!1))}static _drawMove(t){if(o.#c=-1,!o.#s)return;let{offsetX:e,offsetY:s,pointerId:i}=t;o.#n===i&&(o.#o?.size>=1?this._endDraw(t):(this._currentParent.drawLayer.updateProperties(this._currentDrawId,o.#s.add(e,s)),o.#c=t.timeStamp,ht(t)))}static _cleanup(t){t&&(this._currentDrawId=-1,this._currentParent=null,o.#s=null,o.#r=null,o.#l=null,o.#c=NaN),o.#i&&(o.#i.abort(),o.#i=null,o.#n=NaN,o.#o=null)}static _endDraw(t){let e=this._currentParent;if(e)if(e.toggleDrawing(!0),this._cleanup(!1),t&&e.drawLayer.updateProperties(this._currentDrawId,o.#s.end(t.offsetX,t.offsetY)),this.supportMultipleDrawings){let s=o.#s,i=this._currentDrawId,n=s.getLastElement();e.addCommands({cmd:()=>{e.drawLayer.updateProperties(i,s.setLastElement(n))},undo:()=>{e.drawLayer.updateProperties(i,s.removeLastElement())},mustExec:!1,type:B.DRAW_STEP})}else this.endDrawing(!1)}static endDrawing(t){let e=this._currentParent;if(!e)return null;if(e.toggleDrawing(!0),e.cleanUndoStack(B.DRAW_STEP),!o.#s.isEmpty()){let{pageDimensions:[s,i],scale:n}=e,r=e.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:o.#s.getOutlines(s*n,i*n,n,this._INNER_MARGIN),drawingOptions:o.#r,mustBeCommitted:!t});return this._cleanup(!0),r}return e.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(t){}static deserializeDraw(t,e,s,i,n,r){z("Not implemented")}static async deserialize(t,e,s){let{rawDims:{pageWidth:i,pageHeight:n,pageX:r,pageY:a}}=e.viewport,l=this.deserializeDraw(r,a,i,n,this._INNER_MARGIN,t),h=await super.deserialize(t,e,s);return h.createDrawingOptions(t),h.#h({drawOutlines:l}),h.#f(),h.onScaleChanging(),h.rotate(),h}serializeDraw(t){let[e,s]=this.pageTranslation,[i,n]=this.pageDimensions;return this.#t.serialize([e,s,i,n],t)}renderAnnotationElement(t){return t.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}},Ti=class{#t=new Float64Array(6);#e;#s;#i;#r;#n;#l="";#o=0;#c=new Ke;#h;#u;constructor(t,e,s,i,n,r){this.#h=s,this.#u=i,this.#i=n,this.#r=r,[t,e]=this.#d(t,e);let a=this.#e=[NaN,NaN,NaN,NaN,t,e];this.#n=[t,e],this.#s=[{line:a,points:this.#n}],this.#t.set(a,0)}updateProperty(t,e){t==="stroke-width"&&(this.#r=e)}#d(t,e){return E._normalizePoint(t,e,this.#h,this.#u,this.#i)}isEmpty(){return!this.#s||this.#s.length===0}isCancellable(){return this.#n.length<=10}add(t,e){[t,e]=this.#d(t,e);let[s,i,n,r]=this.#t.subarray(2,6),a=t-n,l=e-r;return Math.hypot(this.#h*a,this.#u*l)<=2?null:(this.#n.push(t,e),isNaN(s)?(this.#t.set([n,r,t,e],2),this.#e.push(NaN,NaN,NaN,NaN,t,e),{path:{d:this.toSVGPath()}}):(isNaN(this.#t[0])&&this.#e.splice(6,6),this.#t.set([s,i,n,r,t,e],0),this.#e.push(...E.createBezierPoints(s,i,n,r,t,e)),{path:{d:this.toSVGPath()}}))}end(t,e){return this.add(t,e)||(this.#n.length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,s,i,n){this.#h=s,this.#u=i,this.#i=n,[t,e]=this.#d(t,e);let r=this.#e=[NaN,NaN,NaN,NaN,t,e];this.#n=[t,e];let a=this.#s.at(-1);return a&&(a.line=new Float32Array(a.line),a.points=new Float32Array(a.points)),this.#s.push({line:r,points:this.#n}),this.#t.set(r,0),this.#o=0,this.toSVGPath(),null}getLastElement(){return this.#s.at(-1)}setLastElement(t){return this.#s?(this.#s.push(t),this.#e=t.line,this.#n=t.points,this.#o=0,{path:{d:this.toSVGPath()}}):this.#c.setLastElement(t)}removeLastElement(){if(!this.#s)return this.#c.removeLastElement();this.#s.pop(),this.#l="";for(let t=0,e=this.#s.length;t<e;t++){let{line:s,points:i}=this.#s[t];this.#e=s,this.#n=i,this.#o=0,this.toSVGPath()}return{path:{d:this.#l}}}toSVGPath(){let t=E.svgRound(this.#e[4]),e=E.svgRound(this.#e[5]);if(this.#n.length===2)return this.#l=`${this.#l} M ${t} ${e} Z`,this.#l;if(this.#n.length<=6){let i=this.#l.lastIndexOf("M");this.#l=`${this.#l.slice(0,i)} M ${t} ${e}`,this.#o=6}if(this.#n.length===4){let i=E.svgRound(this.#e[10]),n=E.svgRound(this.#e[11]);return this.#l=`${this.#l} L ${i} ${n}`,this.#o=12,this.#l}let s=[];this.#o===0&&(s.push(`M ${t} ${e}`),this.#o=6);for(let i=this.#o,n=this.#e.length;i<n;i+=6){let[r,a,l,h,c,d]=this.#e.slice(i,i+6).map(E.svgRound);s.push(`C${r} ${a} ${l} ${h} ${c} ${d}`)}return this.#l+=s.join(" "),this.#o=this.#e.length,this.#l}getOutlines(t,e,s,i){let n=this.#s.at(-1);return n.line=new Float32Array(n.line),n.points=new Float32Array(n.points),this.#c.build(this.#s,t,e,s,this.#i,this.#r,i),this.#t=null,this.#e=null,this.#s=null,this.#l=null,this.#c}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}},Ke=class o extends E{#t;#e=0;#s;#i;#r;#n;#l;#o;#c;build(t,e,s,i,n,r,a){this.#r=e,this.#n=s,this.#l=i,this.#o=n,this.#c=r,this.#s=a??0,this.#i=t,this.#d()}setLastElement(t){return this.#i.push(t),{path:{d:this.toSVGPath()}}}removeLastElement(){return this.#i.pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){let t=[];for(let{line:e}of this.#i)if(t.push(`M${E.svgRound(e[4])} ${E.svgRound(e[5])}`),e.length!==6)if(e.length!==12)for(let s=6,i=e.length;s<i;s+=6){let[n,r,a,l,h,c]=e.subarray(s,s+6).map(E.svgRound);t.push(`C${n} ${r} ${a} ${l} ${h} ${c}`)}else t.push(`L${E.svgRound(e[10])} ${E.svgRound(e[11])}`);else t.push("Z");return t.join("")}serialize([t,e,s,i],n){let r=[],a=[],[l,h,c,d]=this.#u(),u,f,p,g,m,b,y,w,A;switch(this.#o){case 0:A=E._rescale,u=t,f=e+i,p=s,g=-i,m=t+l*s,b=e+(1-h-d)*i,y=t+(l+c)*s,w=e+(1-h)*i;break;case 90:A=E._rescaleAndSwap,u=t,f=e,p=s,g=i,m=t+h*s,b=e+l*i,y=t+(h+d)*s,w=e+(l+c)*i;break;case 180:A=E._rescale,u=t+s,f=e,p=-s,g=i,m=t+(1-l-c)*s,b=e+h*i,y=t+(1-l)*s,w=e+(h+d)*i;break;case 270:A=E._rescaleAndSwap,u=t+s,f=e+i,p=-s,g=-i,m=t+(1-h-d)*s,b=e+(1-l-c)*i,y=t+(1-h)*s,w=e+(1-l)*i}for(let{line:_,points:x}of this.#i)r.push(A(_,u,f,p,g,n?new Array(_.length):null)),a.push(A(x,u,f,p,g,n?new Array(x.length):null));return{lines:r,points:a,rect:[m,b,y,w]}}static deserialize(t,e,s,i,n,{paths:{lines:r,points:a},rotation:l,thickness:h}){let c=[],d,u,f,p,g;switch(l){case 0:g=E._rescale,d=-t/s,u=e/i+1,f=1/s,p=-1/i;break;case 90:g=E._rescaleAndSwap,d=-e/i,u=-t/s,f=1/i,p=1/s;break;case 180:g=E._rescale,d=t/s+1,u=-e/i,f=-1/s,p=1/i;break;case 270:g=E._rescaleAndSwap,d=e/i+1,u=t/s+1,f=-1/i,p=-1/s}if(!r){r=[];for(let b of a){let y=b.length;if(y===2){r.push(new Float32Array([NaN,NaN,NaN,NaN,b[0],b[1]]));continue}if(y===4){r.push(new Float32Array([NaN,NaN,NaN,NaN,b[0],b[1],NaN,NaN,NaN,NaN,b[2],b[3]]));continue}let w=new Float32Array(3*(y-2));r.push(w);let[A,_,x,v]=b.subarray(0,4);w.set([NaN,NaN,NaN,NaN,A,_],0);for(let C=4;C<y;C+=2){let M=b[C],I=b[C+1];w.set(E.createBezierPoints(A,_,x,v,M,I),3*(C-2)),[A,_,x,v]=[x,v,M,I]}}}for(let b=0,y=r.length;b<y;b++)c.push({line:g(r[b].map((w=>w??NaN)),d,u,f,p),points:g(a[b].map((w=>w??NaN)),d,u,f,p)});let m=new o;return m.build(c,s,i,1,l,h,n),m}#h(t=this.#c){let e=this.#s+t/2*this.#l;return this.#o%180==0?[e/this.#r,e/this.#n]:[e/this.#n,e/this.#r]}#u(){let[t,e,s,i]=this.#t,[n,r]=this.#h(0);return[t+n,e+r,s-2*n,i-2*r]}#d(){let t=this.#t=new Float32Array([1/0,1/0,-1/0,-1/0]);for(let{line:i}of this.#i){if(i.length<=12){for(let a=4,l=i.length;a<l;a+=6){let[h,c]=i.subarray(a,a+2);t[0]=Math.min(t[0],h),t[1]=Math.min(t[1],c),t[2]=Math.max(t[2],h),t[3]=Math.max(t[3],c)}continue}let n=i[4],r=i[5];for(let a=6,l=i.length;a<l;a+=6){let[h,c,d,u,f,p]=i.subarray(a,a+6);k.bezierBoundingBox(n,r,h,c,d,u,f,p,t),n=f,r=p}}let[e,s]=this.#h();t[0]=Math.min(1,Math.max(0,t[0]-e)),t[1]=Math.min(1,Math.max(0,t[1]-s)),t[2]=Math.min(1,Math.max(0,t[2]+e)),t[3]=Math.min(1,Math.max(0,t[3]+s)),t[2]-=t[0],t[3]-=t[1]}get box(){return this.#t}updateProperty(t,e){return t==="stroke-width"?this.#f(e):null}#f(t){let[e,s]=this.#h();this.#c=t;let[i,n]=this.#h(),[r,a]=[i-e,n-s],l=this.#t;return l[0]-=r,l[1]-=a,l[2]+=2*r,l[3]+=2*a,l}updateParentDimensions([t,e],s){let[i,n]=this.#h();this.#r=t,this.#n=e,this.#l=s;let[r,a]=this.#h(),l=r-i,h=a-n,c=this.#t;return c[0]-=l,c[1]-=h,c[2]+=2*l,c[3]+=2*h,c}updateRotation(t){return this.#e=t,{path:{transform:this.rotationTransform}}}get viewBox(){return this.#t.map(E.svgRound).join(" ")}get defaultProperties(){let[t,e]=this.#t;return{root:{viewBox:this.viewBox},path:{"transform-origin":`${E.svgRound(t)} ${E.svgRound(e)}`}}}get rotationTransform(){let[,,t,e]=this.#t,s=0,i=0,n=0,r=0,a=0,l=0;switch(this.#e){case 90:i=e/t,n=-t/e,a=t;break;case 180:s=-1,r=-1,a=t,l=e;break;case 270:i=-e/t,n=t/e,l=e;break;default:return""}return`matrix(${s} ${i} ${n} ${r} ${E.svgRound(a)} ${E.svgRound(l)})`}getPathResizingSVGProperties([t,e,s,i]){let[n,r]=this.#h(),[a,l,h,c]=this.#t;if(Math.abs(h-n)<=E.PRECISION||Math.abs(c-r)<=E.PRECISION){let g=t+s/2-(a+h/2),m=e+i/2-(l+c/2);return{path:{"transform-origin":`${E.svgRound(t)} ${E.svgRound(e)}`,transform:`${this.rotationTransform} translate(${g} ${m})`}}}let d=(s-2*n)/(h-2*n),u=(i-2*r)/(c-2*r),f=h/s,p=c/i;return{path:{"transform-origin":`${E.svgRound(a)} ${E.svgRound(l)}`,transform:`${this.rotationTransform} scale(${f} ${p}) translate(${E.svgRound(n)} ${E.svgRound(r)}) scale(${d} ${u}) translate(${E.svgRound(-n)} ${E.svgRound(-r)})`}}}getPathResizedSVGProperties([t,e,s,i]){let[n,r]=this.#h(),a=this.#t,[l,h,c,d]=a;if(a[0]=t,a[1]=e,a[2]=s,a[3]=i,Math.abs(c-n)<=E.PRECISION||Math.abs(d-r)<=E.PRECISION){let m=t+s/2-(l+c/2),b=e+i/2-(h+d/2);for(let{line:y,points:w}of this.#i)E._translate(y,m,b,y),E._translate(w,m,b,w);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${E.svgRound(t)} ${E.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}let u=(s-2*n)/(c-2*n),f=(i-2*r)/(d-2*r),p=-u*(l+n)+t+n,g=-f*(h+r)+e+r;if(u!==1||f!==1||p!==0||g!==0)for(let{line:m,points:b}of this.#i)E._rescale(m,p,g,u,f,m),E._rescale(b,p,g,u,f,b);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${E.svgRound(t)} ${E.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([t,e],s){let[i,n]=s,r=this.#t,a=t-r[0],l=e-r[1];if(this.#r===i&&this.#n===n)for(let{line:h,points:c}of this.#i)E._translate(h,a,l,h),E._translate(c,a,l,c);else{let h=this.#r/i,c=this.#n/n;this.#r=i,this.#n=n;for(let{line:d,points:u}of this.#i)E._rescale(d,a,l,h,c,d),E._rescale(u,a,l,h,c,u);r[2]*=h,r[3]*=c}return r[0]=t,r[1]=e,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${E.svgRound(t)} ${E.svgRound(e)}`}}}get defaultSVGProperties(){let t=this.#t;return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${E.svgRound(t[0])} ${E.svgRound(t[1])}`,transform:this.rotationTransform||null},bbox:t}}},Pi=class o extends ki{#t;constructor(t){super(),this.#t=t,super.updateProperties({fill:"none",stroke:W._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(t,e){t==="stroke-width"&&(e??=this["stroke-width"],e*=this.#t.realScale),super.updateSVGProperty(t,e)}clone(){let t=new o(this.#t);return t.updateAll(this),t}},Ri=class o extends Mi{static _type="ink";static _editorType=D.INK;static _defaultDrawingOptions=null;constructor(t){super({...t,name:"inkEditor"}),this._willKeepAspectRatio=!0}static initialize(t,e){W.initialize(t,e),this._defaultDrawingOptions=new Pi(e.viewParameters)}static getDefaultDrawingOptions(t){let e=this._defaultDrawingOptions.clone();return e.updateProperties(t),e}static get supportMultipleDrawings(){return!0}static get typesMap(){return N(this,"typesMap",new Map([[B.INK_THICKNESS,"stroke-width"],[B.INK_COLOR,"stroke"],[B.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(t,e,s,i,n){return new Ti(t,e,s,i,n,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(t,e,s,i,n,r){return Ke.deserialize(t,e,s,i,n,r)}static async deserialize(t,e,s){let i=null;if(t instanceof ae){let{data:{inkLists:r,rect:a,rotation:l,id:h,color:c,opacity:d,borderStyle:{rawWidth:u},popupRef:f},parent:{page:{pageNumber:p}}}=t;i=t={annotationType:D.INK,color:Array.from(c),thickness:u,opacity:d,paths:{points:r},boxes:null,pageIndex:p-1,rect:a.slice(0),rotation:l,id:h,deleted:!1,popupRef:f}}let n=await super.deserialize(t,e,s);return n.annotationElementId=t.id||null,n._initialData=i,n}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();let{_drawId:t,_drawingOptions:e,parent:s}=this;e.updateSVGProperty("stroke-width"),s.drawLayer.updateProperties(t,e.toSVGProperties())}static onScaleChangingWhenDrawing(){let t=this._currentParent;t&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),t.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:t,thickness:e,opacity:s}){this._drawingOptions=o.getDefaultDrawingOptions({stroke:k.makeHexColor(...t),"stroke-width":e,"stroke-opacity":s})}serialize(t=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let{lines:e,points:s,rect:i}=this.serializeDraw(t),{_drawingOptions:{stroke:n,"stroke-opacity":r,"stroke-width":a}}=this,l={annotationType:D.INK,color:W._colorManager.convert(n),opacity:r,thickness:a,paths:{lines:e,points:s},pageIndex:this.pageIndex,rect:i,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return t?l:this.annotationElementId&&!this.#t(l)?null:(l.id=this.annotationElementId,l)}#t(t){let{color:e,thickness:s,opacity:i,pageIndex:n}=this._initialData;return this._hasBeenMoved||this._hasBeenResized||t.color.some(((r,a)=>r!==e[a]))||t.thickness!==s||t.opacity!==i||t.pageIndex!==n}renderAnnotationElement(t){let{points:e,rect:s}=this.serializeDraw(!1);return t.updateEdited({rect:s,thickness:this._drawingOptions["stroke-width"],points:e}),null}},Ii=class o extends W{#t=null;#e=null;#s=null;#i=null;#r=null;#n="";#l=null;#o=null;#c=!1;#h=!1;static _type="stamp";static _editorType=D.STAMP;constructor(t){super({...t,name:"stampEditor"}),this.#i=t.bitmapUrl,this.#r=t.bitmapFile}static initialize(t,e){W.initialize(t,e)}static get supportedTypes(){return N(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map((t=>`image/${t}`)))}static get supportedTypesStr(){return N(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(t){return this.supportedTypes.includes(t)}static paste(t,e){e.pasteEditor(D.STAMP,{bitmapFile:t.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){return{type:"stamp",hasAltText:!!this.altTextData?.altText}}static computeTelemetryFinalData(t){let e=t.get("hasAltText");return{hasAltText:e.get(!0)??0,hasNoAltText:e.get(!1)??0}}#u(t,e=!1){t?(this.#t=t.bitmap,e||(this.#e=t.id,this.#c=t.isSvg),t.file&&(this.#n=t.file.name),this.#a()):this.remove()}#d(){if(this.#s=null,this._uiManager.enableWaiting(!1),this.#l)if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#t)this._editToolbar.hide(),this._uiManager.editAltText(this,!0);else{if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#t){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}}async mlGuessAltText(t=null,e=!0){if(this.hasAltTextData())return null;let{mlManager:s}=this._uiManager;if(!s)throw new Error("No ML.");if(!await s.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");let{data:i,width:n,height:r}=t||this.copyCanvas(null,null,!0).imageData,a=await s.guess({name:"altText",request:{data:i,width:n,height:r,channels:i.length/(n*r)}});if(!a)throw new Error("No response from the AI service.");if(a.error)throw new Error("Error from the AI service.");if(a.cancel)return null;if(!a.output)throw new Error("No valid response from the AI service.");let l=a.output;return await this.setGuessedAltText(l),e&&!this.hasAltTextData()&&(this.altTextData={alt:l,decorative:!1}),l}#f(){if(this.#e){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(this.#e).then((s=>this.#u(s,!0))).finally((()=>this.#d()));return}if(this.#i){let s=this.#i;this.#i=null,this._uiManager.enableWaiting(!0),this.#s=this._uiManager.imageManager.getFromUrl(s).then((i=>this.#u(i))).finally((()=>this.#d()));return}if(this.#r){let s=this.#r;this.#r=null,this._uiManager.enableWaiting(!0),this.#s=this._uiManager.imageManager.getFromFile(s).then((i=>this.#u(i))).finally((()=>this.#d()));return}let t=document.createElement("input");t.type="file",t.accept=o.supportedTypesStr;let e=this._uiManager._signal;this.#s=new Promise((s=>{t.addEventListener("change",(async()=>{if(t.files&&t.files.length!==0){this._uiManager.enableWaiting(!0);let i=await this._uiManager.imageManager.getFromFile(t.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),this.#u(i)}else this.remove();s()}),{signal:e}),t.addEventListener("cancel",(()=>{this.remove(),s()}),{signal:e})})).finally((()=>this.#d())),t.click()}remove(){this.#e&&(this.#t=null,this._uiManager.imageManager.deleteId(this.#e),this.#l?.remove(),this.#l=null,this.#o&&(clearTimeout(this.#o),this.#o=null)),super.remove()}rebuild(){this.parent?(super.rebuild(),this.div!==null&&(this.#e&&this.#l===null&&this.#f(),this.isAttachedToDOM||this.parent.add(this))):this.#e&&this.#f()}onceAdded(t){this._isDraggable=!0,t&&this.div.focus()}isEmpty(){return!(this.#s||this.#t||this.#i||this.#r||this.#e)}get isResizable(){return!0}render(){if(this.div)return this.div;let t,e;if(this.width&&(t=this.x,e=this.y),super.render(),this.div.hidden=!0,this.div.setAttribute("role","figure"),this.addAltTextButton(),this.#t?this.#a():this.#f(),this.width&&!this.annotationElementId){let[s,i]=this.parentDimensions;this.setAt(t*s,e*i,this.width*s,this.height*i)}return this._uiManager.addShouldRescale(this),this.div}_onResized(){this.onScaleChanging()}onScaleChanging(){this.parent&&(this.#o!==null&&clearTimeout(this.#o),this.#o=setTimeout((()=>{this.#o=null,this.#m()}),200))}#a(){let{div:t}=this,{width:e,height:s}=this.#t,[i,n]=this.pageDimensions,r=.75;if(this.width)e=this.width*i,s=this.height*n;else if(e>r*i||s>r*n){let c=Math.min(r*i/e,r*n/s);e*=c,s*=c}let[a,l]=this.parentDimensions;this.setDims(e*a/i,s*l/n),this._uiManager.enableWaiting(!1);let h=this.#l=document.createElement("canvas");h.setAttribute("role","img"),this.addContainer(h),this.width=e/i,this.height=s/n,this._initialOptions?.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&!this.annotationElementId||(t.hidden=!1),this.#m(),this.#h||(this.parent.addUndoableEditor(this),this.#h=!0),this._reportTelemetry({action:"inserted_image"}),this.#n&&h.setAttribute("aria-label",this.#n)}copyCanvas(t,e,s=!1){t||(t=224);let{width:i,height:n}=this.#t,r=new Zt,a=this.#t,l=i,h=n,c=null;if(e){if(i>e||n>e){let x=Math.min(e/i,e/n);l=Math.floor(i*x),h=Math.floor(n*x)}c=document.createElement("canvas");let u=c.width=Math.ceil(l*r.sx),f=c.height=Math.ceil(h*r.sy);this.#c||(a=this.#p(u,f));let p=c.getContext("2d");p.filter=this._uiManager.hcmFilter;let g="white",m="#cfcfd8";this._uiManager.hcmFilter!=="none"?m="black":window.matchMedia?.("(prefers-color-scheme: dark)").matches&&(g="#8f8f9d",m="#42414d");let b=15,y=b*r.sx,w=b*r.sy,A=new OffscreenCanvas(2*y,2*w),_=A.getContext("2d");_.fillStyle=g,_.fillRect(0,0,2*y,2*w),_.fillStyle=m,_.fillRect(0,0,y,w),_.fillRect(y,w,y,w),p.fillStyle=p.createPattern(A,"repeat"),p.fillRect(0,0,u,f),p.drawImage(a,0,0,a.width,a.height,0,0,u,f)}let d=null;if(s){let u,f;if(r.symmetric&&a.width<t&&a.height<t)u=a.width,f=a.height;else if(a=this.#t,i>t||n>t){let g=Math.min(t/i,t/n);u=Math.floor(i*g),f=Math.floor(n*g),this.#c||(a=this.#p(u,f))}let p=new OffscreenCanvas(u,f).getContext("2d",{willReadFrequently:!0});p.drawImage(a,0,0,a.width,a.height,0,0,u,f),d={width:u,height:f,data:p.getImageData(0,0,u,f).data}}return{canvas:c,width:l,height:h,imageData:d}}#p(t,e){let{width:s,height:i}=this.#t,n=s,r=i,a=this.#t;for(;n>2*t||r>2*e;){let l=n,h=r;n>2*t&&(n=n>=16384?Math.floor(n/2)-1:Math.ceil(n/2)),r>2*e&&(r=r>=16384?Math.floor(r/2)-1:Math.ceil(r/2));let c=new OffscreenCanvas(n,r);c.getContext("2d").drawImage(a,0,0,l,h,0,0,n,r),a=c.transferToImageBitmap()}return a}#m(){let[t,e]=this.parentDimensions,{width:s,height:i}=this,n=new Zt,r=Math.ceil(s*t*n.sx),a=Math.ceil(i*e*n.sy),l=this.#l;if(!l||l.width===r&&l.height===a)return;l.width=r,l.height=a;let h=this.#c?this.#t:this.#p(r,a),c=l.getContext("2d");c.filter=this._uiManager.hcmFilter,c.drawImage(h,0,0,h.width,h.height,0,0,r,a)}getImageForAltText(){return this.#l}#g(t){if(t){if(this.#c){let s=this._uiManager.imageManager.getSvgUrl(this.#e);if(s)return s}let e=document.createElement("canvas");return{width:e.width,height:e.height}=this.#t,e.getContext("2d").drawImage(this.#t,0,0),e.toDataURL()}if(this.#c){let[e,s]=this.pageDimensions,i=Math.round(this.width*e*Ct.PDF_TO_CSS_UNITS),n=Math.round(this.height*s*Ct.PDF_TO_CSS_UNITS),r=new OffscreenCanvas(i,n);return r.getContext("2d").drawImage(this.#t,0,0,this.#t.width,this.#t.height,0,0,i,n),r.transferToImageBitmap()}return structuredClone(this.#t)}static async deserialize(t,e,s){let i=null;if(t instanceof Ue){let{data:{rect:p,rotation:g,id:m,structParent:b,popupRef:y},container:w,parent:{page:{pageNumber:A}}}=t,_=w.querySelector("canvas"),x=s.imageManager.getFromCanvas(w.id,_);_.remove();let v=(await e._structTree.getAriaAttributes(`${Oi}${m}`))?.get("aria-label")||"";i=t={annotationType:D.STAMP,bitmapId:x.id,bitmap:x.bitmap,pageIndex:A-1,rect:p.slice(0),rotation:g,id:m,deleted:!1,accessibilityData:{decorative:!1,altText:v},isSvg:!1,structParent:b,popupRef:y}}let n=await super.deserialize(t,e,s),{rect:r,bitmap:a,bitmapUrl:l,bitmapId:h,isSvg:c,accessibilityData:d}=t;h&&s.imageManager.isValidId(h)?(n.#e=h,a&&(n.#t=a)):n.#i=l,n.#c=c;let[u,f]=n.pageDimensions;return n.width=(r[2]-r[0])/u,n.height=(r[3]-r[1])/f,n.annotationElementId=t.id||null,d&&(n.altTextData=d),n._initialData=i,n.#h=!!i,n}serialize(t=!1,e=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();let s={annotationType:D.STAMP,bitmapId:this.#e,pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:this.#c,structTreeParentId:this._structTreeParentId};if(t)return s.bitmapUrl=this.#g(!0),s.accessibilityData=this.serializeAltText(!0),s;let{decorative:i,altText:n}=this.serializeAltText(!1);if(!i&&n&&(s.accessibilityData={type:"Figure",alt:n}),this.annotationElementId){let a=this.#b(s);if(a.isSame)return null;a.isSameAltText?delete s.accessibilityData:s.accessibilityData.structParent=this._initialData.structParent??-1}if(s.id=this.annotationElementId,e===null)return s;e.stamps||=new Map;let r=this.#c?(s.rect[2]-s.rect[0])*(s.rect[3]-s.rect[1]):null;if(e.stamps.has(this.#e)){if(this.#c){let a=e.stamps.get(this.#e);r>a.area&&(a.area=r,a.serialized.bitmap.close(),a.serialized.bitmap=this.#g(!1))}}else e.stamps.set(this.#e,{area:r,serialized:s}),s.bitmap=this.#g(!1);return s}#b(t){let{pageIndex:e,accessibilityData:{altText:s}}=this._initialData,i=t.pageIndex===e,n=(t.accessibilityData?.alt||"")===s;return{isSame:!this._hasBeenMoved&&!this._hasBeenResized&&i&&n,isSameAltText:n}}renderAnnotationElement(t){return t.updateEdited({rect:this.getRect(0,0)}),null}},Li=class o{#t;#e=!1;#s=null;#i=null;#r=null;#n=new Map;#l=!1;#o=!1;#c=!1;#h=null;#u=null;#d=null;#f=null;#a;static _initialized=!1;static#p=new Map([Si,Ri,Ii,Ye].map((t=>[t._editorType,t])));constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:a,textLayer:l,viewport:h,l10n:c}){let d=[...o.#p.values()];if(!o._initialized){o._initialized=!0;for(let u of d)u.initialize(c,t)}t.registerEditorTypes(d),this.#a=t,this.pageIndex=e,this.div=s,this.#t=n,this.#s=r,this.viewport=h,this.#d=l,this.drawLayer=a,this._structTree=i,this.#a.addLayer(this)}get isEmpty(){return this.#n.size===0}get isInvisible(){return this.isEmpty&&this.#a.getMode()===D.NONE}updateToolbar(t){this.#a.updateToolbar(t)}updateMode(t=this.#a.getMode()){switch(this.#y(),t){case D.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case D.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case D.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);let{classList:e}=this.div;for(let s of o.#p.values())e.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){return t===this.#d?.div}setEditingState(t){this.#a.setEditingState(t)}addCommands(t){this.#a.addCommands(t)}cleanUndoStack(t){this.#a.cleanUndoStack(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){this.#s?.div.classList.toggle("disabled",!t)}async enable(){this.#c=!0,this.div.tabIndex=0,this.togglePointerEvents(!0);let t=new Set;for(let s of this.#n.values())s.enableEditing(),s.show(!0),s.annotationElementId&&(this.#a.removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!this.#s){this.#c=!1;return}let e=this.#s.getEditableAnnotations();for(let s of e){if(s.hide(),this.#a.isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;let i=await this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}this.#c=!1}disable(){this.#o=!0,this.div.tabIndex=-1,this.togglePointerEvents(!1);let t=new Map,e=new Map;for(let i of this.#n.values())i.disableEditing(),i.annotationElementId&&(i.serialize()===null?(e.set(i.annotationElementId,i),this.getEditableAnnotation(i.annotationElementId)?.show(),i.remove()):t.set(i.annotationElementId,i));if(this.#s){let i=this.#s.getEditableAnnotations();for(let n of i){let{id:r}=n.data;if(this.#a.isDeletedAnnotationElement(r))continue;let a=e.get(r);a?(a.resetAnnotationElement(n),a.show(!1),n.show()):(a=t.get(r),a&&(this.#a.addChangedExistingAnnotation(a),a.renderAnnotationElement(n)&&a.show(!1)),n.show())}}this.#y(),this.isEmpty&&(this.div.hidden=!0);let{classList:s}=this.div;for(let i of o.#p.values())s.remove(`${i._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),this.#o=!1}getEditableAnnotation(t){return this.#s?.getEditableAnnotation(t)||null}setActiveEditor(t){this.#a.getActive()!==t&&this.#a.setActiveEditor(t)}enableTextSelection(){if(this.div.tabIndex=-1,this.#d?.div&&!this.#f){this.#f=new AbortController;let t=this.#a.combinedSignal(this.#f);this.#d.div.addEventListener("pointerdown",this.#m.bind(this),{signal:t}),this.#d.div.classList.add("highlighting")}}disableTextSelection(){this.div.tabIndex=0,this.#d?.div&&this.#f&&(this.#f.abort(),this.#f=null,this.#d.div.classList.remove("highlighting"))}#m(t){this.#a.unselectAll();let{target:e}=t;if(e===this.#d.div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&this.#d.div.contains(e)){let{isMac:s}=Z.platform;if(t.button!==0||t.ctrlKey&&s)return;this.#a.showAllEditors("highlight",!0,!0),this.#d.div.classList.add("free"),this.toggleDrawing(),Ye.startHighlighting(this,this.#a.direction==="ltr",{target:this.#d.div,x:t.x,y:t.y}),this.#d.div.addEventListener("pointerup",(()=>{this.#d.div.classList.remove("free"),this.toggleDrawing(!0)}),{once:!0,signal:this.#a._signal}),t.preventDefault()}}enableClick(){if(this.#i)return;this.#i=new AbortController;let t=this.#a.combinedSignal(this.#i);this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t});let e=this.pointerup.bind(this);this.div.addEventListener("pointerup",e,{signal:t}),this.div.addEventListener("pointercancel",e,{signal:t})}disableClick(){this.#i?.abort(),this.#i=null}attach(t){this.#n.set(t.id,t);let{annotationElementId:e}=t;e&&this.#a.isDeletedAnnotationElement(e)&&this.#a.removeDeletedAnnotationElement(t)}detach(t){this.#n.delete(t.id),this.#t?.removePointerInTextLayer(t.contentDiv),!this.#o&&t.annotationElementId&&this.#a.addDeletedAnnotationElement(t)}remove(t){this.detach(t),this.#a.removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){t.parent!==this&&(t.parent&&t.annotationElementId&&(this.#a.addDeletedAnnotationElement(t.annotationElementId),W.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),t.parent?.detach(t),t.setParent(this),t.div&&t.isAttachedToDOM&&(t.div.remove(),this.div.append(t.div)))}add(t){if(t.parent!==this||!t.isAttachedToDOM){if(this.changeParent(t),this.#a.addEditor(t),this.attach(t),!t.isAttachedToDOM){let e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!this.#c),this.#a.addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){if(!t.isAttachedToDOM)return;let{activeElement:e}=document;t.div.contains(e)&&!this.#r&&(t._focusEventsAllowed=!1,this.#r=setTimeout((()=>{this.#r=null,t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",(()=>{t._focusEventsAllowed=!0}),{once:!0,signal:this.#a._signal}),e.focus())}),0)),t._structTreeParentId=this.#t?.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){t.needsToBeRebuilt()?(t.parent||=this,t.rebuild(),t.show()):this.add(t)}addUndoableEditor(t){this.addCommands({cmd:()=>t._uiManager.rebuild(t),undo:()=>{t.remove()},mustExec:!1})}getNextId(){return this.#a.getId()}get#g(){return o.#p.get(this.#a.getMode())}combinedSignal(t){return this.#a.combinedSignal(t)}#b(t){let e=this.#g;return e?new e.prototype.constructor(t):null}canCreateNewEmptyEditor(){return this.#g?.canCreateNewEmptyEditor()}pasteEditor(t,e){this.#a.updateToolbar(t),this.#a.updateMode(t);let{offsetX:s,offsetY:i}=this.#A(),n=this.getNextId(),r=this.#b({parent:this,id:n,x:s,y:i,uiManager:this.#a,isCentered:!0,...e});r&&this.add(r)}async deserialize(t){return await o.#p.get(t.annotationType??t.annotationEditorType)?.deserialize(t,this,this.#a)||null}createAndAddNewEditor(t,e,s={}){let i=this.getNextId(),n=this.#b({parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:this.#a,isCentered:e,...s});return n&&this.add(n),n}#A(){let{x:t,y:e,width:s,height:i}=this.div.getBoundingClientRect(),n=Math.max(0,t),r=Math.max(0,e),a=(n+Math.min(window.innerWidth,t+s))/2-t,l=(r+Math.min(window.innerHeight,e+i))/2-e,[h,c]=this.viewport.rotation%180==0?[a,l]:[l,a];return{offsetX:h,offsetY:c}}addNewEditor(){this.createAndAddNewEditor(this.#A(),!0)}setSelected(t){this.#a.setSelected(t)}toggleSelected(t){this.#a.toggleSelected(t)}unselect(t){this.#a.unselect(t)}pointerup(t){let{isMac:e}=Z.platform;!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&this.#l&&(this.#l=!1,this.#g?.isDrawer&&this.#g.supportMultipleDrawings||(this.#e?this.#a.getMode()!==D.STAMP?this.createAndAddNewEditor(t,!1):this.#a.unselectAll():this.#e=!0))}pointerdown(t){if(this.#a.getMode()===D.HIGHLIGHT&&this.enableTextSelection(),this.#l){this.#l=!1;return}let{isMac:e}=Z.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;if(this.#l=!0,this.#g?.isDrawer){this.startDrawingSession(t);return}let s=this.#a.getActive();this.#e=!s||s.isEmpty()}startDrawingSession(t){if(this.div.focus(),this.#h){this.#g.startDrawing(this,this.#a,!1,t);return}this.#a.setCurrentDrawingSession(this),this.#h=new AbortController;let e=this.#a.combinedSignal(this.#h);this.div.addEventListener("blur",(({relatedTarget:s})=>{s&&!this.div.contains(s)&&(this.#u=null,this.commitOrRemove())}),{signal:e}),this.#g.startDrawing(this,this.#a,!1,t)}pause(t){if(t){let{activeElement:e}=document;this.div.contains(e)&&(this.#u=e)}else this.#u&&setTimeout((()=>{this.#u?.focus(),this.#u=null}),0)}endDrawingSession(t=!1){return this.#h?(this.#a.setCurrentDrawingSession(null),this.#h.abort(),this.#h=null,this.#u=null,this.#g.endDrawing(t)):null}findNewParent(t,e,s){let i=this.#a.findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}commitOrRemove(){return this.#h?(this.endDrawingSession(),!0):!1}onScaleChanging(){this.#h&&this.#g.onScaleChangingWhenDrawing(this)}destroy(){this.commitOrRemove(),this.#a.getActive()?.parent===this&&(this.#a.commitOrRemove(),this.#a.setActiveEditor(null)),this.#r&&(clearTimeout(this.#r),this.#r=null);for(let t of this.#n.values())this.#t?.removePointerInTextLayer(t.contentDiv),t.setParent(null),t.isAttachedToDOM=!1,t.div.remove();this.div=null,this.#n.clear(),this.#a.removeLayer(this)}#y(){for(let t of this.#n.values())t.isEmpty()&&t.remove()}render({viewport:t}){this.viewport=t,Lt(this.div,t);for(let e of this.#a.getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){this.#a.commitOrRemove(),this.#y();let e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,Lt(this.div,{rotation:s}),e!==s)for(let i of this.#n.values())i.rotate(s)}get pageDimensions(){let{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return this.#a.viewParameters.realScale}},Di=class o{#t=null;#e=0;#s=new Map;#i=new Map;constructor({pageIndex:t}){this.pageIndex=t}setParent(t){if(this.#t){if(this.#t!==t){if(this.#s.size>0)for(let e of this.#s.values())e.remove(),t.append(e);this.#t=t}}else this.#t=t}static get _svgFactory(){return N(this,"_svgFactory",new ne)}static#r(t,[e,s,i,n]){let{style:r}=t;r.top=100*s+"%",r.left=100*e+"%",r.width=100*i+"%",r.height=100*n+"%"}#n(){let t=o._svgFactory.create(1,1,!0);return this.#t.append(t),t.setAttribute("aria-hidden",!0),t}#l(t,e){let s=o._svgFactory.createElement("clipPath");t.append(s);let i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");let n=o._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i}#o(t,e){for(let[s,i]of Object.entries(e))i===null?t.removeAttribute(s):t.setAttribute(s,i)}draw(t,e=!1,s=!1){let i=this.#e++,n=this.#n(),r=o._svgFactory.createElement("defs");n.append(r);let a=o._svgFactory.createElement("path");r.append(a);let l=`path_p${this.pageIndex}_${i}`;a.setAttribute("id",l),a.setAttribute("vector-effect","non-scaling-stroke"),e&&this.#i.set(i,a);let h=s?this.#l(r,l):null,c=o._svgFactory.createElement("use");return n.append(c),c.setAttribute("href",`#${l}`),this.updateProperties(n,t),this.#s.set(i,n),{id:i,clipPathId:`url(#${h})`}}drawOutline(t,e){let s=this.#e++,i=this.#n(),n=o._svgFactory.createElement("defs");i.append(n);let r=o._svgFactory.createElement("path");n.append(r);let a=`path_p${this.pageIndex}_${s}`;r.setAttribute("id",a),r.setAttribute("vector-effect","non-scaling-stroke");let l;if(e){let d=o._svgFactory.createElement("mask");n.append(d),l=`mask_p${this.pageIndex}_${s}`,d.setAttribute("id",l),d.setAttribute("maskUnits","objectBoundingBox");let u=o._svgFactory.createElement("rect");d.append(u),u.setAttribute("width","1"),u.setAttribute("height","1"),u.setAttribute("fill","white");let f=o._svgFactory.createElement("use");d.append(f),f.setAttribute("href",`#${a}`),f.setAttribute("stroke","none"),f.setAttribute("fill","black"),f.setAttribute("fill-rule","nonzero"),f.classList.add("mask")}let h=o._svgFactory.createElement("use");i.append(h),h.setAttribute("href",`#${a}`),l&&h.setAttribute("mask",`url(#${l})`);let c=h.cloneNode();return i.append(c),h.classList.add("mainOutline"),c.classList.add("secondaryOutline"),this.updateProperties(i,t),this.#s.set(s,i),s}finalizeDraw(t,e){this.#i.delete(t),this.updateProperties(t,e)}updateProperties(t,e){if(!e)return;let{root:s,bbox:i,rootClass:n,path:r}=e,a=typeof t=="number"?this.#s.get(t):t;if(a){if(s&&this.#o(a,s),i&&o.#r(a,i),n){let{classList:l}=a;for(let[h,c]of Object.entries(n))l.toggle(h,c)}if(r){let l=a.firstChild.firstChild;this.#o(l,r)}}}updateParent(t,e){if(e===this)return;let s=this.#s.get(t);s&&(e.#t.append(s),this.#s.delete(t),e.#s.set(t,s))}remove(t){this.#i.delete(t),this.#t!==null&&(this.#s.get(t).remove(),this.#s.delete(t))}destroy(){this.#t=null;for(let t of this.#s.values())t.remove();this.#s.clear(),this.#i.clear()}};globalThis.pdfjsTestingUtils={HighlightOutliner:oe};var da=T.AbortException,ua=T.AnnotationEditorLayer,fa=T.AnnotationEditorParamsType,pa=T.AnnotationEditorType,ga=T.AnnotationEditorUIManager,ma=T.AnnotationLayer,ba=T.AnnotationMode,ya=T.ColorPicker,wa=T.DOMSVGFactory,Aa=T.DrawLayer,va=T.FeatureTest,An=T.GlobalWorkerOptions,_a=T.ImageKind,xa=T.InvalidPDFException,Sa=T.MissingPDFException,Ea=T.OPS,Ca=T.OutputScale,vn=T.PDFDataRangeTransport,ka=T.PDFDateString,Ma=T.PDFWorker,Ta=T.PasswordResponses,Pa=T.PermissionFlag,Ra=T.PixelsPerInch,_n=T.RenderingCancelledException,Ia=T.TextLayer,La=T.TouchManager,Da=T.UnexpectedResponseException,Fa=T.Util,Na=T.VerbosityLevel,Oa=T.XfaLayer,$a=T.build,Ba=T.createValidAbsoluteUrl,Ha=T.fetchData,xn=T.getDocument,ja=T.getFilenameFromUrl,Va=T.getPdfFilenameFromUrl,za=T.getXfaPageViewport,Ga=T.isDataScheme,Ua=T.isPdfFile,qa=T.noContextMenu,Wa=T.normalizeUnicode,Xa=T.setLayerDimensions,Ya=T.shadow,Ka=T.stopEvent,Qa=T.version;import{E as hs}from"./store-BsSRYN7v.js";var ot={context:void 0,registry:void 0,effects:void 0,done:!1,getContextId(){return Sn(this.context.count)},getNextContextId(){return Sn(this.context.count++)}};function Sn(o){let t=String(o),e=t.length-1;return ot.context.id+(e?String.fromCharCode(96+e):"")+t}function Hr(o){ot.context=o}var jr=!1,Vr=(o,t)=>o===t;var En={equals:Vr},Cn=null,Pn=Dn,mt=1,ce=2,zr={owned:null,cleanups:null,context:null,owner:null};var j=null,S=null,Hi=null,Vt=null,X=null,tt=null,st=null,as=0;function ji(o,t){t=t?Object.assign({},En,t):En;let e={value:o,observers:null,observerSlots:null,comparator:t.equals||void 0},s=i=>(typeof i=="function"&&(S&&S.running&&S.sources.has(e)?i=i(e.tValue):i=i(e.value)),Ln(e,i));return[qr.bind(e),s]}function Rn(o,t,e){Pn=Kr;let s=Wr(o,t,!1,mt),i=Bi&&Ur(Bi);i&&(s.suspense=i),(!e||!e.render)&&(s.user=!0),st?st.push(s):Vi(s)}function os(o){if(!Vt&&X===null)return o();let t=X;X=null;try{return Vt?Vt.untrack(o):o()}finally{X=t}}function In(o){Rn(()=>os(o))}function ls(o){return j===null||(j.cleanups===null?j.cleanups=[o]:j.cleanups.push(o)),o}function Gr(o){if(S&&S.running)return o(),S.done;let t=X,e=j;return Promise.resolve().then(()=>{X=t,j=e;let s;return(Hi||Bi)&&(s=S||(S={sources:new Set,effects:[],promises:new Set,disposed:new Set,queue:new Set,running:!0}),s.done||(s.done=new Promise(i=>s.resolve=i)),s.running=!0),Mt(o,!1),X=j=null,s?s.done:void 0})}var[Za,kn]=ji(!1);function Ur(o){let t;return j&&j.context&&(t=j.context[o.id])!==void 0?t:o.defaultValue}var Bi;function qr(){let o=S&&S.running;if(this.sources&&(o?this.tState:this.state))if((o?this.tState:this.state)===mt)Vi(this);else{let t=tt;tt=null,Mt(()=>rs(this),!1),tt=t}if(X){let t=this.observers;if(!t||t[t.length-1]!==X){let e=t?t.length:0;X.sources?(X.sources.push(this),X.sourceSlots.push(e)):(X.sources=[this],X.sourceSlots=[e]),t?(t.push(X),this.observerSlots.push(X.sources.length-1)):(this.observers=[X],this.observerSlots=[X.sources.length-1])}}return o&&S.sources.has(this)?this.tValue:this.value}function Ln(o,t,e){let s=S&&S.running&&S.sources.has(o)?o.tValue:o.value;if(!o.comparator||!o.comparator(s,t)){if(S){let i=S.running;(i||!e&&S.sources.has(o))&&(S.sources.add(o),o.tValue=t),i||(o.value=t)}else o.value=t;o.observers&&o.observers.length&&Mt(()=>{for(let i=0;i<o.observers.length;i+=1){let n=o.observers[i],r=S&&S.running;r&&S.disposed.has(n)||((r?!n.tState:!n.state)&&(n.pure?tt.push(n):st.push(n),n.observers&&Fn(n)),r?n.tState=mt:n.state=mt)}if(tt.length>1e6)throw tt=[],new Error},!1)}return t}function Vi(o){if(!o.fn)return;Ot(o);let t=as;Mn(o,S&&S.running&&S.sources.has(o)?o.tValue:o.value,t),S&&!S.running&&S.sources.has(o)&&queueMicrotask(()=>{Mt(()=>{S&&(S.running=!0),X=j=o,Mn(o,o.tValue,t),X=j=null},!1)})}function Mn(o,t,e){let s,i=j,n=X;X=j=o;try{s=o.fn(t)}catch(r){return o.pure&&(S&&S.running?(o.tState=mt,o.tOwned&&o.tOwned.forEach(Ot),o.tOwned=void 0):(o.state=mt,o.owned&&o.owned.forEach(Ot),o.owned=null)),o.updatedAt=e+1,zi(r)}finally{X=n,j=i}(!o.updatedAt||o.updatedAt<=e)&&(o.updatedAt!=null&&"observers"in o?Ln(o,s,!0):S&&S.running&&o.pure?(S.sources.has(o)||(o.value=s),S.sources.add(o),o.tValue=s):o.value=s,o.updatedAt=e)}function Wr(o,t,e,s=mt,i){let n={fn:o,state:s,updatedAt:null,owned:null,sources:null,sourceSlots:null,cleanups:null,value:t,owner:j,context:j?j.context:null,pure:e};if(S&&S.running&&(n.state=0,n.tState=s),j===null||j!==zr&&(S&&S.running&&j.pure?j.tOwned?j.tOwned.push(n):j.tOwned=[n]:j.owned?j.owned.push(n):j.owned=[n]),Vt&&n.fn){let r=n.fn,[a,l]=ji(void 0,{equals:!1}),h=Vt.factory(r,l);ls(()=>h.dispose());let c,d=()=>Gr(l).then(()=>{c&&(c.dispose(),c=void 0)});n.fn=u=>(a(),S&&S.running?(c||(c=Vt.factory(r,d)),c.track(u)):h.track(u))}return n}function de(o){let t=S&&S.running;if((t?o.tState:o.state)===0)return;if((t?o.tState:o.state)===ce)return rs(o);if(o.suspense&&os(o.suspense.inFallback))return o.suspense.effects.push(o);let e=[o];for(;(o=o.owner)&&(!o.updatedAt||o.updatedAt<as);){if(t&&S.disposed.has(o))return;(t?o.tState:o.state)&&e.push(o)}for(let s=e.length-1;s>=0;s--){if(o=e[s],t){let i=o,n=e[s+1];for(;(i=i.owner)&&i!==n;)if(S.disposed.has(i))return}if((t?o.tState:o.state)===mt)Vi(o);else if((t?o.tState:o.state)===ce){let i=tt;tt=null,Mt(()=>rs(o,e[0]),!1),tt=i}}}function Mt(o,t){if(tt)return o();let e=!1;t||(tt=[]),st?e=!0:st=[],as++;try{let s=o();return Xr(e),s}catch(s){e||(st=null),tt=null,zi(s)}}function Xr(o){if(tt&&(Hi&&S&&S.running?Yr(tt):Dn(tt),tt=null),o)return;let t;if(S){if(!S.promises.size&&!S.queue.size){let s=S.sources,i=S.disposed;st.push.apply(st,S.effects),t=S.resolve;for(let n of st)"tState"in n&&(n.state=n.tState),delete n.tState;S=null,Mt(()=>{for(let n of i)Ot(n);for(let n of s){if(n.value=n.tValue,n.owned)for(let r=0,a=n.owned.length;r<a;r++)Ot(n.owned[r]);n.tOwned&&(n.owned=n.tOwned),delete n.tValue,delete n.tOwned,n.tState=0}kn(!1)},!1)}else if(S.running){S.running=!1,S.effects.push.apply(S.effects,st),st=null,kn(!0);return}}let e=st;st=null,e.length&&Mt(()=>Pn(e),!1),t&&t()}function Dn(o){for(let t=0;t<o.length;t++)de(o[t])}function Yr(o){for(let t=0;t<o.length;t++){let e=o[t],s=S.queue;s.has(e)||(s.add(e),Hi(()=>{s.delete(e),Mt(()=>{S.running=!0,de(e)},!1),S&&(S.running=!1)}))}}function Kr(o){let t,e=0;for(t=0;t<o.length;t++){let s=o[t];s.user?o[e++]=s:de(s)}if(ot.context){if(ot.count){ot.effects||(ot.effects=[]),ot.effects.push(...o.slice(0,e));return}Hr()}for(ot.effects&&(ot.done||!ot.count)&&(o=[...ot.effects,...o],e+=ot.effects.length,delete ot.effects),t=0;t<e;t++)de(o[t])}function rs(o,t){let e=S&&S.running;e?o.tState=0:o.state=0;for(let s=0;s<o.sources.length;s+=1){let i=o.sources[s];if(i.sources){let n=e?i.tState:i.state;n===mt?i!==t&&(!i.updatedAt||i.updatedAt<as)&&de(i):n===ce&&rs(i,t)}}}function Fn(o){let t=S&&S.running;for(let e=0;e<o.observers.length;e+=1){let s=o.observers[e];(t?!s.tState:!s.state)&&(t?s.tState=ce:s.state=ce,s.pure?tt.push(s):st.push(s),s.observers&&Fn(s))}}function Ot(o){let t;if(o.sources)for(;o.sources.length;){let e=o.sources.pop(),s=o.sourceSlots.pop(),i=e.observers;if(i&&i.length){let n=i.pop(),r=e.observerSlots.pop();s<i.length&&(n.sourceSlots[r]=s,i[s]=n,e.observerSlots[s]=r)}}if(o.tOwned){for(t=o.tOwned.length-1;t>=0;t--)Ot(o.tOwned[t]);delete o.tOwned}if(S&&S.running&&o.pure)Nn(o,!0);else if(o.owned){for(t=o.owned.length-1;t>=0;t--)Ot(o.owned[t]);o.owned=null}if(o.cleanups){for(t=o.cleanups.length-1;t>=0;t--)o.cleanups[t]();o.cleanups=null}S&&S.running?o.tState=0:o.state=0}function Nn(o,t){if(t||(o.tState=0,S.disposed.add(o)),o.owned)for(let e=0;e<o.owned.length;e++)Nn(o.owned[e])}function Qr(o){return o instanceof Error?o:new Error(typeof o=="string"?o:"Unknown error",{cause:o})}function Tn(o,t,e){try{for(let s of t)s(o)}catch(s){zi(s,e&&e.owner||null)}}function zi(o,t=j){let e=Cn&&t&&t.context&&t.context[Cn],s=Qr(o);if(!e)throw s;st?st.push({fn(){Tn(s,e,t)},state:mt}):Tn(s,e,t)}var Jr=["allowfullscreen","async","alpha","autofocus","autoplay","checked","controls","default","disabled","formnovalidate","hidden","indeterminate","inert","ismap","loop","multiple","muted","nomodule","novalidate","open","playsinline","readonly","required","reversed","seamless","selected","adauctionheaders","browsingtopics","credentialless","defaultchecked","defaultmuted","defaultselected","defer","disablepictureinpicture","disableremoteplayback","preservespitch","shadowrootclonable","shadowrootcustomelementregistry","shadowrootdelegatesfocus","shadowrootserializable","sharedstoragewritable"],ho=new Set(["className","value","readOnly","noValidate","formNoValidate","isMap","noModule","playsInline","adAuctionHeaders","allowFullscreen","browsingTopics","defaultChecked","defaultMuted","defaultSelected","disablePictureInPicture","disableRemotePlayback","preservesPitch","shadowRootClonable","shadowRootCustomElementRegistry","shadowRootDelegatesFocus","shadowRootSerializable","sharedStorageWritable",...Jr]);function On(o,t,e,s){let i,n=()=>{let a=s?document.createElementNS("http://www.w3.org/1998/Math/MathML","template"):document.createElement("template");return a.innerHTML=o,e?a.content.firstChild.firstChild:s?a.firstChild:a.content.firstChild},r=t?()=>os(()=>document.importNode(i||(i=n()),!0)):()=>(i||(i=n())).cloneNode(!0);return r.cloneNode=r,r}var Zr="4.2.6-ym.11",ta=window.__YM_PDFJS_BASE__||`https://cdn.jsdelivr.net/npm/@yuuichi/openlist-assets@${Zr}/dist/assets/pdfjs/`,Gi=ta;An.workerSrc=`${Gi}pdf.worker.min.mjs`;var mo=1<<20,ea=12<<20;function bt(o,t={},e=[]){let s=document.createElement(o);for(let[i,n]of Object.entries(t))i==="class"?s.className=n:i==="style"?Object.assign(s.style,n):i.startsWith("on")&&typeof n=="function"?s.addEventListener(i.slice(2),n):n!=null&&s.setAttribute(i,n);for(let i of[].concat(e))i!=null&&s.appendChild(typeof i=="string"?document.createTextNode(i):i);return s}function sa(){let o=bt("div",{class:"ym-pdfjs-viewer",style:{display:"flex","flex-direction":"column",width:"100%",height:"100%",minHeight:"60vh",background:"var(--chakra-colors-chakra-subtle-bg, #525659)"}}),t=bt("input",{type:"number",min:"1",value:"1",style:{width:"56px","text-align":"center"},"aria-label":"Page number"}),e=bt("span",{},["/ -"]),s=bt("span",{},["100%"]),i=bt("div",{style:{marginLeft:"auto",opacity:".75","font-size":"12px"}},[""]),n=bt("div",{style:{flex:"1",overflow:"auto",position:"relative",display:"flex","justify-content":"center",padding:"12px"}}),r=bt("canvas",{style:{"box-shadow":"0 2px 12px rgba(0,0,0,.4)",background:"#fff"}}),a=bt("div",{style:{display:"flex","align-items":"center",gap:"8px",padding:"6px 10px",background:"var(--chakra-colors-chakra-body-bg, #2d3748)",color:"var(--chakra-colors-chakra-body-text, #e2e8f0)","border-bottom":"1px solid rgba(128,128,128,.3)",position:"sticky",top:"0","z-index":"2"}},[l("\u2039","Previous page",()=>p(h.page-1)),t,e,l("\u203A","Next page",()=>p(h.page+1)),bt("span",{style:{width:"1px",height:"20px",background:"rgba(128,128,128,.4)"}}),l("\u2212","Zoom out",()=>g(h.scale/1.25)),s,l("+","Zoom in",()=>g(h.scale*1.25)),l("Fit","Fit width",()=>m()),i]);function l(A,_,x){return bt("button",{type:"button",title:_,"aria-label":_,onClick:x,style:{minWidth:"32px",height:"28px",padding:"0 8px",cursor:"pointer",border:"1px solid rgba(128,128,128,.4)","border-radius":"6px",background:"transparent",color:"inherit"}},[A])}o.appendChild(a),o.appendChild(n),n.appendChild(r);let h={doc:null,page:1,scale:1.2,numPages:0,renderTask:null,pendingPage:null,fit:!0,bytes:0,destroyed:!1};function c(A){i.textContent=A}function d(A,_){let x=new Map,v=new vn(_,new Uint8Array(0)),C=async(M,I)=>{let P=`${M}-${I}`;if(x.has(P))return x.get(P);let O=(async()=>{let G;for(let $=0;$<3;$++)try{let H=await fetch(A,{headers:{Range:`bytes=${M}-${I-1}`},credentials:"omit",referrerPolicy:"no-referrer",redirect:"follow"});if(H.status!==206)throw new Error(`Range HTTP ${H.status}`);let q=new Uint8Array(await H.arrayBuffer());h.destroyed||(h.bytes+=q.byteLength,c(`${(h.bytes/1048576).toFixed(1)} MB loaded`)),v.onDataRange(M,q);return}catch(H){G=H,await new Promise(q=>setTimeout(q,300*($+1)))}throw G})();return x.set(P,O),O.finally(()=>x.delete(P)),O};return v.requestRange=(M,I)=>{C(M,I)},v.requestDataRange=v.requestRange,v}async function u(){try{let A=hs&&hs.raw_url;if(!A){c("No source URL");return}let _=new URL(A,location.href).href;c("Connecting\u2026");let x=Number(hs&&hs.size)||0,v={isEvalSupported:!1,disableAutoFetch:!0,disableStream:!0,cMapUrl:`${Gi}cmaps/`,cMapPacked:!0,standardFontDataUrl:`${Gi}standard_fonts/`};x>0?v.range=d(_,x):v.url=_;let C=xn(v);h.doc=await C.promise,h.numPages=h.doc.numPages,e.textContent=`/ ${h.numPages}`,t.max=String(h.numPages),await f(1)}catch(A){console.error("[ym-pdfjs]",A),c(`Failed to load PDF: ${A&&A.message?A.message:A}`)}}async function f(A,{rebuildScale:_=!1}={}){if(!h.doc)return;A=Math.min(Math.max(1,A|0),h.numPages),h.page=A,t.value=String(A);let x=await h.doc.getPage(A),v=x.getViewport({scale:1});if(h.fit||_){let G=(n.clientWidth-32)/v.width;h.scale=Math.max(.4,Math.min(4,G)),h.fit=!0}let C=Math.min(window.devicePixelRatio||1,2),M=x.getViewport({scale:h.scale*C});if(r.width=Math.floor(M.width),r.height=Math.floor(M.height),r.style.width=`${Math.floor(M.width/C)}px`,r.style.height=`${Math.floor(M.height/C)}px`,s.textContent=`${Math.round(h.scale*100)}%`,h.renderTask)try{h.renderTask.cancel()}catch{}let I=r.getContext("2d"),P=x.render({canvasContext:I,viewport:M});h.renderTask=P;try{c(`Page ${A}/${h.numPages} \xB7 ${(h.bytes/1048576).toFixed(1)} MB loaded`),await P.promise,h.bytes<ea&&h.doc.getPage(Math.min(h.numPages,A+1)).catch(()=>{})}catch(O){if(!(O instanceof _n))throw O}}function p(A){f(A)}function g(A){h.fit=!1,h.scale=Math.max(.4,Math.min(6,A)),f(h.page)}function m(){h.fit=!0,f(h.page,{rebuildScale:!0})}t.addEventListener("change",()=>p(Number(t.value)||1)),t.addEventListener("keydown",A=>{A.key==="Enter"&&p(Number(t.value)||1)}),n.addEventListener("wheel",A=>{(A.ctrlKey||A.metaKey)&&(A.preventDefault(),g(h.scale*(A.deltaY<0?1.1:1/1.1)))},{passive:!1});let b,y=()=>{clearTimeout(b),b=setTimeout(()=>{h.fit&&f(h.page,{rebuildScale:!0})},150)};window.addEventListener("resize",y);function w(){if(!h.destroyed){h.destroyed=!0,window.removeEventListener("resize",y);try{h.renderTask?.cancel()}catch{}h.doc?.destroy().catch(()=>{})}}return u(),{root:o,destroy:w}}var ia=On('<div style="width:100%;height:100%;min-height:60vh"></div>');function na(){let o=ia(),t=null;return In(()=>{t=sa(),o.appendChild(t.root)}),ls(()=>t?.destroy()),o}var bo=na;export{bo as default};
|