@fundly.ai/payment-sdk 1.3.0-beta.3 → 1.4.0-beta.1
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/components/fundlyPayDrawer.d.ts.map +1 -1
- package/dist/embed.js +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/embed.js
CHANGED
|
@@ -669,7 +669,7 @@ Thank you for your payment!`;await Lt.shareByteImage(M,Y,`Transaction_${j}`)}cat
|
|
|
669
669
|
`)}`,this.#o();const w=new Range;let b=Math.sumPrecise(f.map(E=>E.length));for(const{firstChild:E}of this.editorDiv.childNodes)if(E.nodeType===Node.TEXT_NODE){const M=E.nodeValue.length;if(b<=M){w.setStart(E,b),w.setEnd(E,b);break}b-=M}a.removeAllRanges(),a.addRange(w)}#o(){if(this.editorDiv.replaceChildren(),!!this.#e)for(const e of this.#e.split(`
|
|
670
670
|
`)){const t=document.createElement("div");t.append(e?document.createTextNode(e):document.createElement("br")),this.editorDiv.append(t)}}#d(){return this.#e.replaceAll(" "," ")}static#u(e){return e.replaceAll(" "," ")}get contentDiv(){return this.editorDiv}getPDFRect(){const e=gn._internalPadding*this.parentScale;return this.getRect(e,e)}static async deserialize(e,t,n){let s=null;if(e instanceof Op){const{data:{defaultAppearanceData:{fontSize:o,fontColor:c},rect:d,rotation:f,id:g,popupRef:w,richText:b,contentsObj:E,creationDate:M,modificationDate:S},textContent:j,textPosition:F,parent:{page:{pageNumber:z}}}=e;if(!j||j.length===0)return null;s=e={annotationType:st.FREETEXT,color:Array.from(c),fontSize:o,value:j.join(`
|
|
671
671
|
`),position:F,pageIndex:z-1,rect:d.slice(0),rotation:f,annotationElementId:g,id:g,deleted:!1,popupRef:w,comment:E?.str||null,richText:b,creationDate:M,modificationDate:S}}const a=await super.deserialize(e,t,n);return a.#n=e.fontSize,a.color=be.makeHexColor(...e.color),a.#e=gn.#u(e.value),a._initialData=s,e.comment&&a.setCommentData(e),a}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const t=Ue._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:this.color),n=Object.assign(super.serialize(e),{color:t,fontSize:this.#n,value:this.#d()});return this.addComment(n),e?(n.isCopy=!0,n):this.annotationElementId&&!this.#h(n)?null:(n.id=this.annotationElementId,n)}#h(e){const{value:t,fontSize:n,color:s,pageIndex:a}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||e.value!==t||e.fontSize!==n||e.color.some((o,c)=>o!==s[c])||e.pageIndex!==a}renderAnnotationElement(e){const t=super.renderAnnotationElement(e);if(!t)return null;const{style:n}=t;n.fontSize=`calc(${this.#n}px * var(--total-scale-factor))`,n.color=this.color,t.replaceChildren();for(const s of this.#e.split(`
|
|
672
|
-
`)){const a=document.createElement("div");a.append(s?document.createTextNode(s):document.createElement("br")),t.append(a)}return e.updateEdited({rect:this.getPDFRect(),popup:this._uiManager.hasCommentManager()||this.hasEditedComment?this.comment:{text:this.#e}}),t}resetAnnotationElement(e){super.resetAnnotationElement(e),e.resetEdited()}}class Be{static PRECISION=1e-4;toSVGPath(){a2("Abstract method `toSVGPath` must be implemented.")}get box(){a2("Abstract getter `box` must be implemented.")}serialize(e,t){a2("Abstract method `serialize` must be implemented.")}static _rescale(e,t,n,s,a,o){o||=new Float32Array(e.length);for(let c=0,d=e.length;c<d;c+=2)o[c]=t+e[c]*s,o[c+1]=n+e[c+1]*a;return o}static _rescaleAndSwap(e,t,n,s,a,o){o||=new Float32Array(e.length);for(let c=0,d=e.length;c<d;c+=2)o[c]=t+e[c+1]*s,o[c+1]=n+e[c]*a;return o}static _translate(e,t,n,s){s||=new Float32Array(e.length);for(let a=0,o=e.length;a<o;a+=2)s[a]=t+e[a],s[a+1]=n+e[a+1];return s}static svgRound(e){return Math.round(e*1e4)}static _normalizePoint(e,t,n,s,a){switch(a){case 90:return[1-t/n,e/s];case 180:return[1-e/n,1-t/s];case 270:return[t/n,1-e/s];default:return[e/n,t/s]}}static _normalizePagePoint(e,t,n){switch(n){case 90:return[1-t,e];case 180:return[1-e,1-t];case 270:return[t,1-e];default:return[e,t]}}static createBezierPoints(e,t,n,s,a,o){return[(e+5*n)/6,(t+5*s)/6,(5*n+a)/6,(5*s+o)/6,(n+a)/2,(s+o)/2]}}class X0{#e;#t=[];#i;#n;#A=[];#s=new Float32Array(18);#r;#a;#l;#o;#d;#u;#h=[];static#g=8;static#f=2;static#c=X0.#g+X0.#f;constructor({x:e,y:t},n,s,a,o,c=0){this.#e=n,this.#u=a*s,this.#n=o,this.#s.set([NaN,NaN,NaN,NaN,e,t],6),this.#i=c,this.#o=X0.#g*s,this.#l=X0.#c*s,this.#d=s,this.#h.push(e,t)}isEmpty(){return isNaN(this.#s[8])}#p(){const e=this.#s.subarray(4,6),t=this.#s.subarray(16,18),[n,s,a,o]=this.#e;return[(this.#r+(e[0]-t[0])/2-n)/a,(this.#a+(e[1]-t[1])/2-s)/o,(this.#r+(t[0]-e[0])/2-n)/a,(this.#a+(t[1]-e[1])/2-s)/o]}add({x:e,y:t}){this.#r=e,this.#a=t;const[n,s,a,o]=this.#e;let[c,d,f,g]=this.#s.subarray(8,12);const w=e-f,b=t-g,E=Math.hypot(w,b);if(E<this.#l)return!1;const M=E-this.#o,S=M/E,j=S*w,F=S*b;let z=c,J=d;c=f,d=g,f+=j,g+=F,this.#h?.push(e,t);const Y=-F/M,H=j/M,W=Y*this.#u,_=H*this.#u;return this.#s.set(this.#s.subarray(2,8),0),this.#s.set([f+W,g+_],4),this.#s.set(this.#s.subarray(14,18),12),this.#s.set([f-W,g-_],16),isNaN(this.#s[6])?(this.#A.length===0&&(this.#s.set([c+W,d+_],2),this.#A.push(NaN,NaN,NaN,NaN,(c+W-n)/a,(d+_-s)/o),this.#s.set([c-W,d-_],14),this.#t.push(NaN,NaN,NaN,NaN,(c-W-n)/a,(d-_-s)/o)),this.#s.set([z,J,c,d,f,g],6),!this.isEmpty()):(this.#s.set([z,J,c,d,f,g],6),Math.abs(Math.atan2(J-d,z-c)-Math.atan2(F,j))<Math.PI/2?([c,d,f,g]=this.#s.subarray(2,6),this.#A.push(NaN,NaN,NaN,NaN,((c+f)/2-n)/a,((d+g)/2-s)/o),[c,d,z,J]=this.#s.subarray(14,18),this.#t.push(NaN,NaN,NaN,NaN,((z+c)/2-n)/a,((J+d)/2-s)/o),!0):([z,J,c,d,f,g]=this.#s.subarray(0,6),this.#A.push(((z+5*c)/6-n)/a,((J+5*d)/6-s)/o,((5*c+f)/6-n)/a,((5*d+g)/6-s)/o,((c+f)/2-n)/a,((d+g)/2-s)/o),[f,g,c,d,z,J]=this.#s.subarray(12,18),this.#t.push(((z+5*c)/6-n)/a,((J+5*d)/6-s)/o,((5*c+f)/6-n)/a,((5*d+g)/6-s)/o,((c+f)/2-n)/a,((d+g)/2-s)/o),!0))}toSVGPath(){if(this.isEmpty())return"";const e=this.#A,t=this.#t;if(isNaN(this.#s[6])&&!this.isEmpty())return this.#m();const n=[];n.push(`M${e[4]} ${e[5]}`);for(let s=6;s<e.length;s+=6)isNaN(e[s])?n.push(`L${e[s+4]} ${e[s+5]}`):n.push(`C${e[s]} ${e[s+1]} ${e[s+2]} ${e[s+3]} ${e[s+4]} ${e[s+5]}`);this.#w(n);for(let s=t.length-6;s>=6;s-=6)isNaN(t[s])?n.push(`L${t[s+4]} ${t[s+5]}`):n.push(`C${t[s]} ${t[s+1]} ${t[s+2]} ${t[s+3]} ${t[s+4]} ${t[s+5]}`);return this.#v(n),n.join(" ")}#m(){const[e,t,n,s]=this.#e,[a,o,c,d]=this.#p();return`M${(this.#s[2]-e)/n} ${(this.#s[3]-t)/s} L${(this.#s[4]-e)/n} ${(this.#s[5]-t)/s} L${a} ${o} L${c} ${d} L${(this.#s[16]-e)/n} ${(this.#s[17]-t)/s} L${(this.#s[14]-e)/n} ${(this.#s[15]-t)/s} Z`}#v(e){const t=this.#t;e.push(`L${t[4]} ${t[5]} Z`)}#w(e){const[t,n,s,a]=this.#e,o=this.#s.subarray(4,6),c=this.#s.subarray(16,18),[d,f,g,w]=this.#p();e.push(`L${(o[0]-t)/s} ${(o[1]-n)/a} L${d} ${f} L${g} ${w} L${(c[0]-t)/s} ${(c[1]-n)/a}`)}newFreeDrawOutline(e,t,n,s,a,o){return new Hp(e,t,n,s,a,o)}getOutlines(){const e=this.#A,t=this.#t,n=this.#s,[s,a,o,c]=this.#e,d=new Float32Array((this.#h?.length??0)+2);for(let w=0,b=d.length-2;w<b;w+=2)d[w]=(this.#h[w]-s)/o,d[w+1]=(this.#h[w+1]-a)/c;if(d[d.length-2]=(this.#r-s)/o,d[d.length-1]=(this.#a-a)/c,isNaN(n[6])&&!this.isEmpty())return this.#I(d);const f=new Float32Array(this.#A.length+24+this.#t.length);let g=e.length;for(let w=0;w<g;w+=2){if(isNaN(e[w])){f[w]=f[w+1]=NaN;continue}f[w]=e[w],f[w+1]=e[w+1]}g=this.#C(f,g);for(let w=t.length-6;w>=6;w-=6)for(let b=0;b<6;b+=2){if(isNaN(t[w+b])){f[g]=f[g+1]=NaN,g+=2;continue}f[g]=t[w+b],f[g+1]=t[w+b+1],g+=2}return this.#B(f,g),this.newFreeDrawOutline(f,d,this.#e,this.#d,this.#i,this.#n)}#I(e){const t=this.#s,[n,s,a,o]=this.#e,[c,d,f,g]=this.#p(),w=new Float32Array(36);return w.set([NaN,NaN,NaN,NaN,(t[2]-n)/a,(t[3]-s)/o,NaN,NaN,NaN,NaN,(t[4]-n)/a,(t[5]-s)/o,NaN,NaN,NaN,NaN,c,d,NaN,NaN,NaN,NaN,f,g,NaN,NaN,NaN,NaN,(t[16]-n)/a,(t[17]-s)/o,NaN,NaN,NaN,NaN,(t[14]-n)/a,(t[15]-s)/o],0),this.newFreeDrawOutline(w,e,this.#e,this.#d,this.#i,this.#n)}#B(e,t){const n=this.#t;return e.set([NaN,NaN,NaN,NaN,n[4],n[5]],t),t+=6}#C(e,t){const n=this.#s.subarray(4,6),s=this.#s.subarray(16,18),[a,o,c,d]=this.#e,[f,g,w,b]=this.#p();return e.set([NaN,NaN,NaN,NaN,(n[0]-a)/c,(n[1]-o)/d,NaN,NaN,NaN,NaN,f,g,NaN,NaN,NaN,NaN,w,b,NaN,NaN,NaN,NaN,(s[0]-a)/c,(s[1]-o)/d],t),t+=24}}class Hp extends Be{#e;#t=new Float32Array(4);#i;#n;#A;#s;#r;constructor(e,t,n,s,a,o){super(),this.#r=e,this.#A=t,this.#e=n,this.#s=s,this.#i=a,this.#n=o,this.firstPoint=[NaN,NaN],this.lastPoint=[NaN,NaN],this.#a(o);const[c,d,f,g]=this.#t;for(let w=0,b=e.length;w<b;w+=2)e[w]=(e[w]-c)/f,e[w+1]=(e[w+1]-d)/g;for(let w=0,b=t.length;w<b;w+=2)t[w]=(t[w]-c)/f,t[w+1]=(t[w+1]-d)/g}toSVGPath(){const e=[`M${this.#r[4]} ${this.#r[5]}`];for(let t=6,n=this.#r.length;t<n;t+=6){if(isNaN(this.#r[t])){e.push(`L${this.#r[t+4]} ${this.#r[t+5]}`);continue}e.push(`C${this.#r[t]} ${this.#r[t+1]} ${this.#r[t+2]} ${this.#r[t+3]} ${this.#r[t+4]} ${this.#r[t+5]}`)}return e.push("Z"),e.join(" ")}serialize([e,t,n,s],a){const o=n-e,c=s-t;let d,f;switch(a){case 0:d=Be._rescale(this.#r,e,s,o,-c),f=Be._rescale(this.#A,e,s,o,-c);break;case 90:d=Be._rescaleAndSwap(this.#r,e,t,o,c),f=Be._rescaleAndSwap(this.#A,e,t,o,c);break;case 180:d=Be._rescale(this.#r,n,t,-o,c),f=Be._rescale(this.#A,n,t,-o,c);break;case 270:d=Be._rescaleAndSwap(this.#r,n,s,-o,-c),f=Be._rescaleAndSwap(this.#A,n,s,-o,-c);break}return{outline:Array.from(d),points:[Array.from(f)]}}#a(e){const t=this.#r;let n=t[4],s=t[5];const a=[n,s,n,s];let o=n,c=s,d=n,f=s;const g=e?Math.max:Math.min,w=new Float32Array(4);for(let E=6,M=t.length;E<M;E+=6){const S=t[E+4],j=t[E+5];isNaN(t[E])?(be.pointBoundingBox(S,j,a),c>j?(o=S,c=j):c===j&&(o=g(o,S)),f<j?(d=S,f=j):f===j&&(d=g(d,S))):(w[0]=w[1]=1/0,w[2]=w[3]=-1/0,be.bezierBoundingBox(n,s,...t.slice(E,E+6),w),be.rectBoundingBox(w[0],w[1],w[2],w[3],a),c>w[1]?(o=w[0],c=w[1]):c===w[1]&&(o=g(o,w[0])),f<w[3]?(d=w[2],f=w[3]):f===w[3]&&(d=g(d,w[2]))),n=S,s=j}const b=this.#t;b[0]=a[0]-this.#i,b[1]=a[1]-this.#i,b[2]=a[2]-a[0]+2*this.#i,b[3]=a[3]-a[1]+2*this.#i,this.firstPoint=[o,c],this.lastPoint=[d,f]}get box(){return this.#t}newOutliner(e,t,n,s,a,o=0){return new X0(e,t,n,s,a,o)}getNewOutline(e,t){const[n,s,a,o]=this.#t,[c,d,f,g]=this.#e,w=a*f,b=o*g,E=n*f+c,M=s*g+d,S=this.newOutliner({x:this.#A[0]*w+E,y:this.#A[1]*b+M},this.#e,this.#s,e,this.#n,t??this.#i);for(let j=2;j<this.#A.length;j+=2)S.add({x:this.#A[j]*w+E,y:this.#A[j+1]*b+M});return S.getOutlines()}}class Rh{#e;#t;#i;#n=[];#A=[];constructor(e,t=0,n=0,s=!0){const a=[1/0,1/0,-1/0,-1/0],o=10**-4;for(const{x:S,y:j,width:F,height:z}of e){const J=Math.floor((S-t)/o)*o,Y=Math.ceil((S+F+t)/o)*o,H=Math.floor((j-t)/o)*o,W=Math.ceil((j+z+t)/o)*o,_=[J,H,W,!0],l1=[Y,H,W,!1];this.#n.push(_,l1),be.rectBoundingBox(J,H,Y,W,a)}const c=a[2]-a[0]+2*n,d=a[3]-a[1]+2*n,f=a[0]-n,g=a[1]-n;let w=s?-1/0:1/0,b=1/0;const E=this.#n.at(s?-1:-2),M=[E[0],E[2]];for(const S of this.#n){const[j,F,z,J]=S;!J&&s?F<b?(b=F,w=j):F===b&&(w=Math.max(w,j)):J&&!s&&(F<b?(b=F,w=j):F===b&&(w=Math.min(w,j))),S[0]=(j-f)/c,S[1]=(F-g)/d,S[2]=(z-g)/d}this.#e=new Float32Array([f,g,c,d]),this.#t=[w,b],this.#i=M}getOutlines(){this.#n.sort((t,n)=>t[0]-n[0]||t[1]-n[1]||t[2]-n[2]);const e=[];for(const t of this.#n)t[3]?(e.push(...this.#o(t)),this.#a(t)):(this.#l(t),e.push(...this.#o(t)));return this.#s(e)}#s(e){const t=[],n=new Set;for(const o of e){const[c,d,f]=o;t.push([c,d,o],[c,f,o])}t.sort((o,c)=>o[1]-c[1]||o[0]-c[0]);for(let o=0,c=t.length;o<c;o+=2){const d=t[o][2],f=t[o+1][2];d.push(f),f.push(d),n.add(d),n.add(f)}const s=[];let a;for(;n.size>0;){const o=n.values().next().value;let[c,d,f,g,w]=o;n.delete(o);let b=c,E=d;for(a=[c,f],s.push(a);;){let M;if(n.has(g))M=g;else if(n.has(w))M=w;else break;n.delete(M),[c,d,f,g,w]=M,b!==c&&(a.push(b,E,c,E===d?d:f),b=c),E=E===d?f:d}a.push(b,E)}return new nv(s,this.#e,this.#t,this.#i)}#r(e){const t=this.#A;let n=0,s=t.length-1;for(;n<=s;){const a=n+s>>1,o=t[a][0];if(o===e)return a;o<e?n=a+1:s=a-1}return s+1}#a([,e,t]){const n=this.#r(e);this.#A.splice(n,0,[e,t])}#l([,e,t]){const n=this.#r(e);for(let s=n;s<this.#A.length;s++){const[a,o]=this.#A[s];if(a!==e)break;if(a===e&&o===t){this.#A.splice(s,1);return}}for(let s=n-1;s>=0;s--){const[a,o]=this.#A[s];if(a!==e)break;if(a===e&&o===t){this.#A.splice(s,1);return}}}#o(e){const[t,n,s]=e,a=[[t,n,s]],o=this.#r(s);for(let c=0;c<o;c++){const[d,f]=this.#A[c];for(let g=0,w=a.length;g<w;g++){const[,b,E]=a[g];if(!(f<=b||E<=d)){if(b>=d){if(E>f)a[g][1]=f;else{if(w===1)return[];a.splice(g,1),g--,w--}continue}a[g][2]=d,E>f&&a.push([t,f,E])}}}return a}}class nv extends Be{#e;#t;constructor(e,t,n,s){super(),this.#t=e,this.#e=t,this.firstPoint=n,this.lastPoint=s}toSVGPath(){const e=[];for(const t of this.#t){let[n,s]=t;e.push(`M${n} ${s}`);for(let a=2;a<t.length;a+=2){const o=t[a],c=t[a+1];o===n?(e.push(`V${c}`),s=c):c===s&&(e.push(`H${o}`),n=o)}e.push("Z")}return e.join(" ")}serialize([e,t,n,s],a){const o=[],c=n-e,d=s-t;for(const f of this.#t){const g=new Array(f.length);for(let w=0;w<f.length;w+=2)g[w]=e+f[w]*c,g[w+1]=s-f[w+1]*d;o.push(g)}return o}get box(){return this.#e}get classNamesForOutlining(){return["highlightOutline"]}}class Hh extends X0{newFreeDrawOutline(e,t,n,s,a,o){return new iv(e,t,n,s,a,o)}}class iv extends Hp{newOutliner(e,t,n,s,a,o=0){return new Hh(e,t,n,s,a,o)}}class z2 extends Ue{#e=null;#t=0;#i;#n=null;#A=null;#s=null;#r=null;#a=0;#l=null;#o=null;#d=null;#u=!1;#h=null;#g=null;#f=null;#c="";#p;#m="";static _defaultColor=null;static _defaultOpacity=1;static _defaultThickness=12;static _type="highlight";static _editorType=st.HIGHLIGHT;static _freeHighlightId=-1;static _freeHighlight=null;static _freeHighlightClipId="";static get _keyboardManager(){const e=z2.prototype;return ut(this,"_keyboardManager",new Ko([[["ArrowLeft","mac+ArrowLeft"],e._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],e._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],e._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],e._moveCaret,{args:[3]}]]))}constructor(e){super({...e,name:"highlightEditor"}),this.color=e.color||z2._defaultColor,this.#p=e.thickness||z2._defaultThickness,this.opacity=e.opacity||z2._defaultOpacity,this.#i=e.boxes||null,this.#m=e.methodOfCreation||"",this.#c=e.text||"",this._isDraggable=!1,this.defaultL10nId="pdfjs-editor-highlight-editor",e.highlightId>-1?(this.#u=!0,this.#w(e),this.#b()):this.#i&&(this.#e=e.anchorNode,this.#t=e.anchorOffset,this.#r=e.focusNode,this.#a=e.focusOffset,this.#v(),this.#b(),this.rotate(this.rotation)),this.annotationElementId||this._uiManager.a11yAlert("pdfjs-editor-highlight-added-alert")}get telemetryInitialData(){return{action:"added",type:this.#u?"free_highlight":"highlight",color:this._uiManager.getNonHCMColorName(this.color),thickness:this.#p,methodOfCreation:this.#m}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.getNonHCMColorName(this.color)}}static computeTelemetryFinalData(e){return{numberOfColors:e.get("color").size}}#v(){const e=new Rh(this.#i,.001);this.#o=e.getOutlines(),[this.x,this.y,this.width,this.height]=this.#o.box;const t=new Rh(this.#i,.0025,.001,this._uiManager.direction==="ltr");this.#s=t.getOutlines();const{firstPoint:n}=this.#o;this.#h=[(n[0]-this.x)/this.width,(n[1]-this.y)/this.height];const{lastPoint:s}=this.#s;this.#g=[(s[0]-this.x)/this.width,(s[1]-this.y)/this.height]}#w({highlightOutlines:e,highlightId:t,clipPathId:n}){this.#o=e;const s=1.5;if(this.#s=e.getNewOutline(this.#p/2+s,.0025),t>=0)this.#d=t,this.#n=n,this.parent.drawLayer.finalizeDraw(t,{bbox:e.box,path:{d:e.toSVGPath()}}),this.#f=this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:this.#s.box,path:{d:this.#s.toSVGPath()}},!0);else if(this.parent){const w=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(this.#d,{bbox:z2.#x(this.#o.box,(w-this.rotation+360)%360),path:{d:e.toSVGPath()}}),this.parent.drawLayer.updateProperties(this.#f,{bbox:z2.#x(this.#s.box,w),path:{d:this.#s.toSVGPath()}})}const[a,o,c,d]=e.box;switch(this.rotation){case 0:this.x=a,this.y=o,this.width=c,this.height=d;break;case 90:{const[w,b]=this.parentDimensions;this.x=o,this.y=1-a,this.width=c*b/w,this.height=d*w/b;break}case 180:this.x=1-a,this.y=1-o,this.width=c,this.height=d;break;case 270:{const[w,b]=this.parentDimensions;this.x=1-o,this.y=a,this.width=c*b/w,this.height=d*w/b;break}}const{firstPoint:f}=e;this.#h=[(f[0]-a)/c,(f[1]-o)/d];const{lastPoint:g}=this.#s;this.#g=[(g[0]-a)/c,(g[1]-o)/d]}static initialize(e,t){Ue.initialize(e,t),z2._defaultColor||=t.highlightColors?.values().next().value||"#fff066"}static updateDefaultParams(e,t){switch(e){case yt.HIGHLIGHT_COLOR:z2._defaultColor=t;break;case yt.HIGHLIGHT_THICKNESS:z2._defaultThickness=t;break}}translateInPage(e,t){}get toolbarPosition(){return this.#g}get commentButtonPosition(){return this.#h}updateParams(e,t){switch(e){case yt.HIGHLIGHT_COLOR:this.#I(t);break;case yt.HIGHLIGHT_THICKNESS:this.#B(t);break}}static get defaultPropertiesToUpdate(){return[[yt.HIGHLIGHT_COLOR,z2._defaultColor],[yt.HIGHLIGHT_THICKNESS,z2._defaultThickness]]}get propertiesToUpdate(){return[[yt.HIGHLIGHT_COLOR,this.color||z2._defaultColor],[yt.HIGHLIGHT_THICKNESS,this.#p||z2._defaultThickness],[yt.HIGHLIGHT_FREE,this.#u]]}onUpdatedColor(){this.parent?.drawLayer.updateProperties(this.#d,{root:{fill:this.color,"fill-opacity":this.opacity}}),this.#A?.updateColor(this.color),super.onUpdatedColor()}#I(e){const t=(a,o)=>{this.color=a,this.opacity=o,this.onUpdatedColor()},n=this.color,s=this.opacity;this.addCommands({cmd:t.bind(this,e,z2._defaultOpacity),undo:t.bind(this,n,s),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:yt.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.getNonHCMColorName(e)},!0)}#B(e){const t=this.#p,n=s=>{this.#p=s,this.#C(s)};this.addCommands({cmd:n.bind(this,e),undo:n.bind(this,t),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:yt.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)}get toolbarButtons(){return this._uiManager.highlightColors?[["colorPicker",this.#A=new zi({editor:this})]]:super.toolbarButtons}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(this.#L())}getBaseTranslation(){return[0,0]}getRect(e,t){return super.getRect(e,t,this.#L())}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),e&&this.div.focus()}remove(){this.#S(),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.#b(),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){let t=!1;this.parent&&!e?this.#S():e&&(this.#b(e),t=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(e),this.show(this._isVisible),t&&this.select()}#C(e){this.#u&&(this.#w({highlightOutlines:this.#o.getNewOutline(e/2)}),this.fixAndSetPosition(),this.setDims(this.width,this.height))}#S(){this.#d===null||!this.parent||(this.parent.drawLayer.remove(this.#d),this.#d=null,this.parent.drawLayer.remove(this.#f),this.#f=null)}#b(e=this.parent){this.#d===null&&({id:this.#d,clipPathId:this.#n}=e.drawLayer.draw({bbox:this.#o.box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":this.opacity},rootClass:{highlight:!0,free:this.#u},path:{d:this.#o.toSVGPath()}},!1,!0),this.#f=e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:this.#u},bbox:this.#s.box,path:{d:this.#s.toSVGPath()}},this.#u),this.#l&&(this.#l.style.clipPath=this.#n))}static#x([e,t,n,s],a){switch(a){case 90:return[1-t-s,e,s,n];case 180:return[1-e-n,1-t-s,n,s];case 270:return[t,1-e-n,s,n]}return[e,t,n,s]}rotate(e){const{drawLayer:t}=this.parent;let n;this.#u?(e=(e-this.rotation+360)%360,n=z2.#x(this.#o.box,e)):n=z2.#x([this.x,this.y,this.width,this.height],e),t.updateProperties(this.#d,{bbox:n,root:{"data-main-rotation":e}}),t.updateProperties(this.#f,{bbox:z2.#x(this.#s.box,e),root:{"data-main-rotation":e}})}render(){if(this.div)return this.div;const e=super.render();this.#c&&(e.setAttribute("aria-label",this.#c),e.setAttribute("role","mark")),this.#u?e.classList.add("free"):this.div.addEventListener("keydown",this.#D.bind(this),{signal:this._uiManager._signal});const t=this.#l=document.createElement("div");return e.append(t),t.setAttribute("aria-hidden","true"),t.className="internal",t.style.clipPath=this.#n,this.setDims(this.width,this.height),$6(this,this.#l,["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#f,{rootClass:{hovered:!0}})}pointerleave(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#f,{rootClass:{hovered:!1}})}#D(e){z2._keyboardManager.exec(this,e)}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:this.#M(!0);break;case 1:case 3:this.#M(!1);break}}#M(e){if(!this.#e)return;const t=window.getSelection();e?t.setPosition(this.#e,this.#t):t.setPosition(this.#r,this.#a)}select(){super.select(),this.#f&&this.parent?.drawLayer.updateProperties(this.#f,{rootClass:{hovered:!1,selected:!0}})}unselect(){super.unselect(),this.#f&&(this.parent?.drawLayer.updateProperties(this.#f,{rootClass:{selected:!1}}),this.#u||this.#M(!1))}get _mustFixPosition(){return!this.#u}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.updateProperties(this.#d,{rootClass:{hidden:!e}}),this.parent.drawLayer.updateProperties(this.#f,{rootClass:{hidden:!e}}))}#L(){return this.#u?this.rotation:0}#O(){if(this.#u)return null;const[e,t]=this.pageDimensions,[n,s]=this.pageTranslation,a=this.#i,o=new Float32Array(a.length*8);let c=0;for(const{x:d,y:f,width:g,height:w}of a){const b=d*e+n,E=(1-f)*t+s;o[c]=o[c+4]=b,o[c+1]=o[c+3]=E,o[c+2]=o[c+6]=b+g*e,o[c+5]=o[c+7]=E-w*t,c+=8}return o}#N(e){return this.#o.serialize(e,this.#L())}static startHighlighting(e,t,{target:n,x:s,y:a}){const{x:o,y:c,width:d,height:f}=n.getBoundingClientRect(),g=new AbortController,w=e.combinedSignal(g),b=E=>{g.abort(),this.#k(e,E)};window.addEventListener("blur",b,{signal:w}),window.addEventListener("pointerup",b,{signal:w}),window.addEventListener("pointerdown",B2,{capture:!0,passive:!1,signal:w}),window.addEventListener("contextmenu",Ri,{signal:w}),n.addEventListener("pointermove",this.#j.bind(this,e),{signal:w}),this._freeHighlight=new Hh({x:s,y:a},[o,c,d,f],e.scale,this._defaultThickness/2,t,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.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#j(e,t){this._freeHighlight.add(t)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})}static#k(e,t){this._freeHighlight.isEmpty()?e.drawLayer.remove(this._freeHighlightId):e.createAndAddNewEditor(t,!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(e,t,n){let s=null;if(e instanceof Pp){const{data:{quadPoints:M,rect:S,rotation:j,id:F,color:z,opacity:J,popupRef:Y,richText:H,contentsObj:W,creationDate:_,modificationDate:l1},parent:{page:{pageNumber:r1}}}=e;s=e={annotationType:st.HIGHLIGHT,color:Array.from(z),opacity:J,quadPoints:M,boxes:null,pageIndex:r1-1,rect:S.slice(0),rotation:j,annotationElementId:F,id:F,deleted:!1,popupRef:Y,richText:H,comment:W?.str||null,creationDate:_,modificationDate:l1}}else if(e instanceof kh){const{data:{inkLists:M,rect:S,rotation:j,id:F,color:z,borderStyle:{rawWidth:J},popupRef:Y,richText:H,contentsObj:W,creationDate:_,modificationDate:l1},parent:{page:{pageNumber:r1}}}=e;s=e={annotationType:st.HIGHLIGHT,color:Array.from(z),thickness:J,inkLists:M,boxes:null,pageIndex:r1-1,rect:S.slice(0),rotation:j,annotationElementId:F,id:F,deleted:!1,popupRef:Y,richText:H,comment:W?.str||null,creationDate:_,modificationDate:l1}}const{color:a,quadPoints:o,inkLists:c,opacity:d}=e,f=await super.deserialize(e,t,n);f.color=be.makeHexColor(...a),f.opacity=d||1,c&&(f.#p=e.thickness),f._initialData=s,e.comment&&f.setCommentData(e);const[g,w]=f.pageDimensions,[b,E]=f.pageTranslation;if(o){const M=f.#i=[];for(let S=0;S<o.length;S+=8)M.push({x:(o[S]-b)/g,y:1-(o[S+1]-E)/w,width:(o[S+2]-o[S])/g,height:(o[S+1]-o[S+5])/w});f.#v(),f.#b(),f.rotate(f.rotation)}else if(c){f.#u=!0;const M=c[0],S={x:M[0]-b,y:w-(M[1]-E)},j=new Hh(S,[0,0,g,w],1,f.#p/2,!0,.001);for(let J=0,Y=M.length;J<Y;J+=2)S.x=M[J]-b,S.y=w-(M[J+1]-E),j.add(S);const{id:F,clipPathId:z}=t.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:f.color,"fill-opacity":f._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:j.toSVGPath()}},!0,!0);f.#w({highlightOutlines:j.getOutlines(),highlightId:F,clipPathId:z}),f.#b(),f.rotate(f.parentRotation)}return f}serialize(e=!1){if(this.isEmpty()||e)return null;if(this.deleted)return this.serializeDeleted();const t=Ue._colorManager.convert(this._uiManager.getNonHCMColor(this.color)),n=super.serialize(e);return Object.assign(n,{color:t,opacity:this.opacity,thickness:this.#p,quadPoints:this.#O(),outlines:this.#N(n.rect)}),this.addComment(n),this.annotationElementId&&!this.#Q(n)?null:(n.id=this.annotationElementId,n)}#Q(e){const{color:t}=this._initialData;return this.hasEditedComment||e.color.some((n,s)=>n!==t[s])}renderAnnotationElement(e){return this.deleted?(e.hide(),null):(e.updateEdited({rect:this.getPDFRect(),popup:this.comment}),null)}static canCreateNewEmptyEditor(){return!1}}class zp{#e=Object.create(null);updateProperty(e,t){this[e]=t,this.updateSVGProperty(e,t)}updateProperties(e){if(e)for(const[t,n]of Object.entries(e))t.startsWith("_")||this.updateProperty(t,n)}updateSVGProperty(e,t){this.#e[e]=t}toSVGProperties(){const e=this.#e;return this.#e=Object.create(null),{root:e}}reset(){this.#e=Object.create(null)}updateAll(e=this){this.updateProperties(e)}clone(){a2("Not implemented")}}class He extends Ue{#e=null;#t;_colorPicker=null;_drawId=null;static _currentDrawId=-1;static _currentParent=null;static#i=null;static#n=null;static#A=null;static#s=NaN;static#r=null;static#a=null;static#l=NaN;static _INNER_MARGIN=3;constructor(e){super(e),this.#t=e.mustBeCommitted||!1,this._addOutlines(e)}onUpdatedColor(){this._colorPicker?.update(this.color),super.onUpdatedColor()}_addOutlines(e){e.drawOutlines&&(this.#o(e),this.#h())}#o({drawOutlines:e,drawId:t,drawingOptions:n}){this.#e=e,this._drawingOptions||=n,this.annotationElementId||this._uiManager.a11yAlert(`pdfjs-editor-${this.editorType}-added-alert`),t>=0?(this._drawId=t,this.parent.drawLayer.finalizeDraw(t,e.defaultProperties)):this._drawId=this.#d(e,this.parent),this.#c(e.box)}#d(e,t){const{id:n}=t.drawLayer.draw(He._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return n}static _mergeSVGProperties(e,t){const n=new Set(Object.keys(e));for(const[s,a]of Object.entries(t))n.has(s)?Object.assign(e[s],a):e[s]=a;return e}static getDefaultDrawingOptions(e){a2("Not implemented")}static get typesMap(){a2("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(e,t){const n=this.typesMap.get(e);n&&this._defaultDrawingOptions.updateProperty(n,t),this._currentParent&&(He.#i.updateProperty(n,t),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(e,t){const n=this.constructor.typesMap.get(e);n&&this._updateProperty(e,n,t)}static get defaultPropertiesToUpdate(){const e=[],t=this._defaultDrawingOptions;for(const[n,s]of this.typesMap)e.push([n,t[s]]);return e}get propertiesToUpdate(){const e=[],{_drawingOptions:t}=this;for(const[n,s]of this.constructor.typesMap)e.push([n,t[s]]);return e}_updateProperty(e,t,n){const s=this._drawingOptions,a=s[t],o=c=>{s.updateProperty(t,c);const d=this.#e.updateProperty(t,c);d&&this.#c(d),this.parent?.drawLayer.updateProperties(this._drawId,s.toSVGProperties()),e===this.colorType&&this.onUpdatedColor()};this.addCommands({cmd:o.bind(this,n),undo:o.bind(this,a),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:e,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){this.parent?.drawLayer.updateProperties(this._drawId,He._mergeSVGProperties(this.#e.getPathResizingSVGProperties(this.#f()),{bbox:this.#p()}))}_onResized(){this.parent?.drawLayer.updateProperties(this._drawId,He._mergeSVGProperties(this.#e.getPathResizedSVGProperties(this.#f()),{bbox:this.#p()}))}_onTranslating(e,t){this.parent?.drawLayer.updateProperties(this._drawId,{bbox:this.#p()})}_onTranslated(){this.parent?.drawLayer.updateProperties(this._drawId,He._mergeSVGProperties(this.#e.getPathTranslatedSVGProperties(this.#f(),this.parentDimensions),{bbox:this.#p()}))}_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(e){this.annotationElementId||this.parent.addUndoableEditor(this),this._isDraggable=!0,this.#t&&(this.#t=!1,this.commit(),this.parent.setSelected(this),e&&this.isOnScreen&&this.div.focus())}remove(){this.#u(),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.#h(),this.#c(this.#e.box),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){let t=!1;this.parent&&!e?(this._uiManager.removeShouldRescale(this),this.#u()):e&&(this._uiManager.addShouldRescale(this),this.#h(e),t=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(e),t&&this.select()}#u(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())}#h(e=this.parent){if(!(this._drawId!==null&&this.parent===e)){if(this._drawId!==null){this.parent.drawLayer.updateParent(this._drawId,e.drawLayer);return}this._drawingOptions.updateAll(),this._drawId=this.#d(this.#e,e)}}#g([e,t,n,s]){const{parentDimensions:[a,o],rotation:c}=this;switch(c){case 90:return[t,1-e,n*(o/a),s*(a/o)];case 180:return[1-e,1-t,n,s];case 270:return[1-t,e,n*(o/a),s*(a/o)];default:return[e,t,n,s]}}#f(){const{x:e,y:t,width:n,height:s,parentDimensions:[a,o],rotation:c}=this;switch(c){case 90:return[1-t,e,n*(a/o),s*(o/a)];case 180:return[1-e,1-t,n,s];case 270:return[t,1-e,n*(a/o),s*(o/a)];default:return[e,t,n,s]}}#c(e){[this.x,this.y,this.width,this.height]=this.#g(e),this.div&&(this.fixAndSetPosition(),this.setDims()),this._onResized()}#p(){const{x:e,y:t,width:n,height:s,rotation:a,parentRotation:o,parentDimensions:[c,d]}=this;switch((a*4+o)/90){case 1:return[1-t-s,e,s,n];case 2:return[1-e-n,1-t-s,n,s];case 3:return[t,1-e-n,s,n];case 4:return[e,t-n*(c/d),s*(d/c),n*(c/d)];case 5:return[1-t,e,n*(c/d),s*(d/c)];case 6:return[1-e-s*(d/c),1-t,s*(d/c),n*(c/d)];case 7:return[t-n*(c/d),1-e-s*(d/c),n*(c/d),s*(d/c)];case 8:return[e-n,t-s,n,s];case 9:return[1-t,e-n,s,n];case 10:return[1-e,1-t,n,s];case 11:return[t-s,1-e,s,n];case 12:return[e-s*(d/c),t,s*(d/c),n*(c/d)];case 13:return[1-t-n*(c/d),e-s*(d/c),n*(c/d),s*(d/c)];case 14:return[1-e,1-t-n*(c/d),s*(d/c),n*(c/d)];case 15:return[t,1-e,n*(c/d),s*(d/c)];default:return[e,t,n,s]}}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,He._mergeSVGProperties({bbox:this.#p()},this.#e.updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&this.#c(this.#e.updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;let e,t;this._isCopy&&(e=this.x,t=this.y);const n=super.render();n.classList.add("draw");const s=document.createElement("div");return n.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",this.setDims(),this._uiManager.addShouldRescale(this),this.disableEditing(),this._isCopy&&this._moveAfterPaste(e,t),n}static createDrawerInstance(e,t,n,s,a){a2("Not implemented")}static startDrawing(e,t,n,s){const{target:a,offsetX:o,offsetY:c,pointerId:d,pointerType:f}=s;if(He.#r&&He.#r!==f)return;const{viewport:{rotation:g}}=e,{width:w,height:b}=a.getBoundingClientRect(),E=He.#n=new AbortController,M=e.combinedSignal(E);if(He.#s||=d,He.#r??=f,window.addEventListener("pointerup",S=>{He.#s===S.pointerId?this._endDraw(S):He.#a?.delete(S.pointerId)},{signal:M}),window.addEventListener("pointercancel",S=>{He.#s===S.pointerId?this._currentParent.endDrawingSession():He.#a?.delete(S.pointerId)},{signal:M}),window.addEventListener("pointerdown",S=>{He.#r===S.pointerType&&((He.#a||=new Set).add(S.pointerId),He.#i.isCancellable()&&(He.#i.removeLastElement(),He.#i.isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:M}),window.addEventListener("contextmenu",Ri,{signal:M}),a.addEventListener("pointermove",this._drawMove.bind(this),{signal:M}),a.addEventListener("touchmove",S=>{S.timeStamp===He.#l&&B2(S)},{signal:M}),e.toggleDrawing(),t._editorUndoBar?.hide(),He.#i){e.drawLayer.updateProperties(this._currentDrawId,He.#i.startNew(o,c,w,b,g));return}t.updateUIForDefaultProperties(this),He.#i=this.createDrawerInstance(o,c,w,b,g),He.#A=this.getDefaultDrawingOptions(),this._currentParent=e,{id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties(He.#A.toSVGProperties(),He.#i.defaultSVGProperties),!0,!1)}static _drawMove(e){if(He.#l=-1,!He.#i)return;const{offsetX:t,offsetY:n,pointerId:s}=e;if(He.#s===s){if(He.#a?.size>=1){this._endDraw(e);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,He.#i.add(t,n)),He.#l=e.timeStamp,B2(e)}}static _cleanup(e){e&&(this._currentDrawId=-1,this._currentParent=null,He.#i=null,He.#A=null,He.#r=null,He.#l=NaN),He.#n&&(He.#n.abort(),He.#n=null,He.#s=NaN,He.#a=null)}static _endDraw(e){const t=this._currentParent;if(t){if(t.toggleDrawing(!0),this._cleanup(!1),e?.target===t.div&&t.drawLayer.updateProperties(this._currentDrawId,He.#i.end(e.offsetX,e.offsetY)),this.supportMultipleDrawings){const n=He.#i,s=this._currentDrawId,a=n.getLastElement();t.addCommands({cmd:()=>{t.drawLayer.updateProperties(s,n.setLastElement(a))},undo:()=>{t.drawLayer.updateProperties(s,n.removeLastElement())},mustExec:!1,type:yt.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(e){const t=this._currentParent;if(!t)return null;if(t.toggleDrawing(!0),t.cleanUndoStack(yt.DRAW_STEP),!He.#i.isEmpty()){const{pageDimensions:[n,s],scale:a}=t,o=t.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:He.#i.getOutlines(n*a,s*a,a,this._INNER_MARGIN),drawingOptions:He.#A,mustBeCommitted:!e});return this._cleanup(!0),o}return t.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(e){}static deserializeDraw(e,t,n,s,a,o){a2("Not implemented")}static async deserialize(e,t,n){const{rawDims:{pageWidth:s,pageHeight:a,pageX:o,pageY:c}}=t.viewport,d=this.deserializeDraw(o,c,s,a,this._INNER_MARGIN,e),f=await super.deserialize(e,t,n);return f.createDrawingOptions(e),f.#o({drawOutlines:d}),f.#h(),f.onScaleChanging(),f.rotate(),f}serializeDraw(e){const[t,n]=this.pageTranslation,[s,a]=this.pageDimensions;return this.#e.serialize([t,n,s,a],e)}renderAnnotationElement(e){return e.updateEdited({rect:this.getPDFRect()}),null}static canCreateNewEmptyEditor(){return!1}}class sv{#e=new Float64Array(6);#t;#i;#n;#A;#s;#r="";#a=0;#l=new tl;#o;#d;constructor(e,t,n,s,a,o){this.#o=n,this.#d=s,this.#n=a,this.#A=o,[e,t]=this.#u(e,t);const c=this.#t=[NaN,NaN,NaN,NaN,e,t];this.#s=[e,t],this.#i=[{line:c,points:this.#s}],this.#e.set(c,0)}updateProperty(e,t){e==="stroke-width"&&(this.#A=t)}#u(e,t){return Be._normalizePoint(e,t,this.#o,this.#d,this.#n)}isEmpty(){return!this.#i||this.#i.length===0}isCancellable(){return this.#s.length<=10}add(e,t){[e,t]=this.#u(e,t);const[n,s,a,o]=this.#e.subarray(2,6),c=e-a,d=t-o;return Math.hypot(this.#o*c,this.#d*d)<=2?null:(this.#s.push(e,t),isNaN(n)?(this.#e.set([a,o,e,t],2),this.#t.push(NaN,NaN,NaN,NaN,e,t),{path:{d:this.toSVGPath()}}):(isNaN(this.#e[0])&&this.#t.splice(6,6),this.#e.set([n,s,a,o,e,t],0),this.#t.push(...Be.createBezierPoints(n,s,a,o,e,t)),{path:{d:this.toSVGPath()}}))}end(e,t){const n=this.add(e,t);return n||(this.#s.length===2?{path:{d:this.toSVGPath()}}:null)}startNew(e,t,n,s,a){this.#o=n,this.#d=s,this.#n=a,[e,t]=this.#u(e,t);const o=this.#t=[NaN,NaN,NaN,NaN,e,t];this.#s=[e,t];const c=this.#i.at(-1);return c&&(c.line=new Float32Array(c.line),c.points=new Float32Array(c.points)),this.#i.push({line:o,points:this.#s}),this.#e.set(o,0),this.#a=0,this.toSVGPath(),null}getLastElement(){return this.#i.at(-1)}setLastElement(e){return this.#i?(this.#i.push(e),this.#t=e.line,this.#s=e.points,this.#a=0,{path:{d:this.toSVGPath()}}):this.#l.setLastElement(e)}removeLastElement(){if(!this.#i)return this.#l.removeLastElement();this.#i.pop(),this.#r="";for(let e=0,t=this.#i.length;e<t;e++){const{line:n,points:s}=this.#i[e];this.#t=n,this.#s=s,this.#a=0,this.toSVGPath()}return{path:{d:this.#r}}}toSVGPath(){const e=Be.svgRound(this.#t[4]),t=Be.svgRound(this.#t[5]);if(this.#s.length===2)return this.#r=`${this.#r} M ${e} ${t} Z`,this.#r;if(this.#s.length<=6){const s=this.#r.lastIndexOf("M");this.#r=`${this.#r.slice(0,s)} M ${e} ${t}`,this.#a=6}if(this.#s.length===4){const s=Be.svgRound(this.#t[10]),a=Be.svgRound(this.#t[11]);return this.#r=`${this.#r} L ${s} ${a}`,this.#a=12,this.#r}const n=[];this.#a===0&&(n.push(`M ${e} ${t}`),this.#a=6);for(let s=this.#a,a=this.#t.length;s<a;s+=6){const[o,c,d,f,g,w]=this.#t.slice(s,s+6).map(Be.svgRound);n.push(`C${o} ${c} ${d} ${f} ${g} ${w}`)}return this.#r+=n.join(" "),this.#a=this.#t.length,this.#r}getOutlines(e,t,n,s){const a=this.#i.at(-1);return a.line=new Float32Array(a.line),a.points=new Float32Array(a.points),this.#l.build(this.#i,e,t,n,this.#n,this.#A,s),this.#e=null,this.#t=null,this.#i=null,this.#r=null,this.#l}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}class tl extends Be{#e;#t=0;#i;#n;#A;#s;#r;#a;#l;build(e,t,n,s,a,o,c){this.#A=t,this.#s=n,this.#r=s,this.#a=a,this.#l=o,this.#i=c??0,this.#n=e,this.#u()}get thickness(){return this.#l}setLastElement(e){return this.#n.push(e),{path:{d:this.toSVGPath()}}}removeLastElement(){return this.#n.pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const e=[];for(const{line:t}of this.#n){if(e.push(`M${Be.svgRound(t[4])} ${Be.svgRound(t[5])}`),t.length===6){e.push("Z");continue}if(t.length===12&&isNaN(t[6])){e.push(`L${Be.svgRound(t[10])} ${Be.svgRound(t[11])}`);continue}for(let n=6,s=t.length;n<s;n+=6){const[a,o,c,d,f,g]=t.subarray(n,n+6).map(Be.svgRound);e.push(`C${a} ${o} ${c} ${d} ${f} ${g}`)}}return e.join("")}serialize([e,t,n,s],a){const o=[],c=[],[d,f,g,w]=this.#d();let b,E,M,S,j,F,z,J,Y;switch(this.#a){case 0:Y=Be._rescale,b=e,E=t+s,M=n,S=-s,j=e+d*n,F=t+(1-f-w)*s,z=e+(d+g)*n,J=t+(1-f)*s;break;case 90:Y=Be._rescaleAndSwap,b=e,E=t,M=n,S=s,j=e+f*n,F=t+d*s,z=e+(f+w)*n,J=t+(d+g)*s;break;case 180:Y=Be._rescale,b=e+n,E=t,M=-n,S=s,j=e+(1-d-g)*n,F=t+f*s,z=e+(1-d)*n,J=t+(f+w)*s;break;case 270:Y=Be._rescaleAndSwap,b=e+n,E=t+s,M=-n,S=-s,j=e+(1-f-w)*n,F=t+(1-d-g)*s,z=e+(1-f)*n,J=t+(1-d)*s;break}for(const{line:H,points:W}of this.#n)o.push(Y(H,b,E,M,S,a?new Array(H.length):null)),c.push(Y(W,b,E,M,S,a?new Array(W.length):null));return{lines:o,points:c,rect:[j,F,z,J]}}static deserialize(e,t,n,s,a,{paths:{lines:o,points:c},rotation:d,thickness:f}){const g=[];let w,b,E,M,S;switch(d){case 0:S=Be._rescale,w=-e/n,b=t/s+1,E=1/n,M=-1/s;break;case 90:S=Be._rescaleAndSwap,w=-t/s,b=-e/n,E=1/s,M=1/n;break;case 180:S=Be._rescale,w=e/n+1,b=-t/s,E=-1/n,M=1/s;break;case 270:S=Be._rescaleAndSwap,w=t/s+1,b=e/n+1,E=-1/s,M=-1/n;break}if(!o){o=[];for(const F of c){const z=F.length;if(z===2){o.push(new Float32Array([NaN,NaN,NaN,NaN,F[0],F[1]]));continue}if(z===4){o.push(new Float32Array([NaN,NaN,NaN,NaN,F[0],F[1],NaN,NaN,NaN,NaN,F[2],F[3]]));continue}const J=new Float32Array(3*(z-2));o.push(J);let[Y,H,W,_]=F.subarray(0,4);J.set([NaN,NaN,NaN,NaN,Y,H],0);for(let l1=4;l1<z;l1+=2){const r1=F[l1],f1=F[l1+1];J.set(Be.createBezierPoints(Y,H,W,_,r1,f1),(l1-2)*3),[Y,H,W,_]=[W,_,r1,f1]}}}for(let F=0,z=o.length;F<z;F++)g.push({line:S(o[F].map(J=>J??NaN),w,b,E,M),points:S(c[F].map(J=>J??NaN),w,b,E,M)});const j=new this.prototype.constructor;return j.build(g,n,s,1,d,f,a),j}#o(e=this.#l){const t=this.#i+e/2*this.#r;return this.#a%180===0?[t/this.#A,t/this.#s]:[t/this.#s,t/this.#A]}#d(){const[e,t,n,s]=this.#e,[a,o]=this.#o(0);return[e+a,t+o,n-2*a,s-2*o]}#u(){const e=this.#e=new Float32Array([1/0,1/0,-1/0,-1/0]);for(const{line:s}of this.#n){if(s.length<=12){for(let c=4,d=s.length;c<d;c+=6)be.pointBoundingBox(s[c],s[c+1],e);continue}let a=s[4],o=s[5];for(let c=6,d=s.length;c<d;c+=6){const[f,g,w,b,E,M]=s.subarray(c,c+6);be.bezierBoundingBox(a,o,f,g,w,b,E,M,e),a=E,o=M}}const[t,n]=this.#o();e[0]=Rn(e[0]-t,0,1),e[1]=Rn(e[1]-n,0,1),e[2]=Rn(e[2]+t,0,1),e[3]=Rn(e[3]+n,0,1),e[2]-=e[0],e[3]-=e[1]}get box(){return this.#e}updateProperty(e,t){return e==="stroke-width"?this.#h(t):null}#h(e){const[t,n]=this.#o();this.#l=e;const[s,a]=this.#o(),[o,c]=[s-t,a-n],d=this.#e;return d[0]-=o,d[1]-=c,d[2]+=2*o,d[3]+=2*c,d}updateParentDimensions([e,t],n){const[s,a]=this.#o();this.#A=e,this.#s=t,this.#r=n;const[o,c]=this.#o(),d=o-s,f=c-a,g=this.#e;return g[0]-=d,g[1]-=f,g[2]+=2*d,g[3]+=2*f,g}updateRotation(e){return this.#t=e,{path:{transform:this.rotationTransform}}}get viewBox(){return this.#e.map(Be.svgRound).join(" ")}get defaultProperties(){const[e,t]=this.#e;return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Be.svgRound(e)} ${Be.svgRound(t)}`}}}get rotationTransform(){const[,,e,t]=this.#e;let n=0,s=0,a=0,o=0,c=0,d=0;switch(this.#t){case 90:s=t/e,a=-e/t,c=e;break;case 180:n=-1,o=-1,c=e,d=t;break;case 270:s=-t/e,a=e/t,d=t;break;default:return""}return`matrix(${n} ${s} ${a} ${o} ${Be.svgRound(c)} ${Be.svgRound(d)})`}getPathResizingSVGProperties([e,t,n,s]){const[a,o]=this.#o(),[c,d,f,g]=this.#e;if(Math.abs(f-a)<=Be.PRECISION||Math.abs(g-o)<=Be.PRECISION){const S=e+n/2-(c+f/2),j=t+s/2-(d+g/2);return{path:{"transform-origin":`${Be.svgRound(e)} ${Be.svgRound(t)}`,transform:`${this.rotationTransform} translate(${S} ${j})`}}}const w=(n-2*a)/(f-2*a),b=(s-2*o)/(g-2*o),E=f/n,M=g/s;return{path:{"transform-origin":`${Be.svgRound(c)} ${Be.svgRound(d)}`,transform:`${this.rotationTransform} scale(${E} ${M}) translate(${Be.svgRound(a)} ${Be.svgRound(o)}) scale(${w} ${b}) translate(${Be.svgRound(-a)} ${Be.svgRound(-o)})`}}}getPathResizedSVGProperties([e,t,n,s]){const[a,o]=this.#o(),c=this.#e,[d,f,g,w]=c;if(c[0]=e,c[1]=t,c[2]=n,c[3]=s,Math.abs(g-a)<=Be.PRECISION||Math.abs(w-o)<=Be.PRECISION){const j=e+n/2-(d+g/2),F=t+s/2-(f+w/2);for(const{line:z,points:J}of this.#n)Be._translate(z,j,F,z),Be._translate(J,j,F,J);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Be.svgRound(e)} ${Be.svgRound(t)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const b=(n-2*a)/(g-2*a),E=(s-2*o)/(w-2*o),M=-b*(d+a)+e+a,S=-E*(f+o)+t+o;if(b!==1||E!==1||M!==0||S!==0)for(const{line:j,points:F}of this.#n)Be._rescale(j,M,S,b,E,j),Be._rescale(F,M,S,b,E,F);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Be.svgRound(e)} ${Be.svgRound(t)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,t],n){const[s,a]=n,o=this.#e,c=e-o[0],d=t-o[1];if(this.#A===s&&this.#s===a)for(const{line:f,points:g}of this.#n)Be._translate(f,c,d,f),Be._translate(g,c,d,g);else{const f=this.#A/s,g=this.#s/a;this.#A=s,this.#s=a;for(const{line:w,points:b}of this.#n)Be._rescale(w,c,d,f,g,w),Be._rescale(b,c,d,f,g,b);o[2]*=f,o[3]*=g}return o[0]=e,o[1]=t,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${Be.svgRound(e)} ${Be.svgRound(t)}`}}}get defaultSVGProperties(){const e=this.#e;return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${Be.svgRound(e[0])} ${Be.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}}class wu extends zp{constructor(e){super(),this._viewParameters=e,super.updateProperties({fill:"none",stroke:Ue._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(e,t){e==="stroke-width"&&(t??=this["stroke-width"],t*=this._viewParameters.realScale),super.updateSVGProperty(e,t)}clone(){const e=new wu(this._viewParameters);return e.updateAll(this),e}}class zh extends He{static _type="ink";static _editorType=st.INK;static _defaultDrawingOptions=null;constructor(e){super({...e,name:"inkEditor"}),this._willKeepAspectRatio=!0,this.defaultL10nId="pdfjs-editor-ink-editor"}static initialize(e,t){Ue.initialize(e,t),this._defaultDrawingOptions=new wu(t.viewParameters)}static getDefaultDrawingOptions(e){const t=this._defaultDrawingOptions.clone();return t.updateProperties(e),t}static get supportMultipleDrawings(){return!0}static get typesMap(){return ut(this,"typesMap",new Map([[yt.INK_THICKNESS,"stroke-width"],[yt.INK_COLOR,"stroke"],[yt.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(e,t,n,s,a){return new sv(e,t,n,s,a,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(e,t,n,s,a,o){return tl.deserialize(e,t,n,s,a,o)}static async deserialize(e,t,n){let s=null;if(e instanceof kh){const{data:{inkLists:o,rect:c,rotation:d,id:f,color:g,opacity:w,borderStyle:{rawWidth:b},popupRef:E,richText:M,contentsObj:S,creationDate:j,modificationDate:F},parent:{page:{pageNumber:z}}}=e;s=e={annotationType:st.INK,color:Array.from(g),thickness:b,opacity:w,paths:{points:o},boxes:null,pageIndex:z-1,rect:c.slice(0),rotation:d,annotationElementId:f,id:f,deleted:!1,popupRef:E,richText:M,comment:S?.str||null,creationDate:j,modificationDate:F}}const a=await super.deserialize(e,t,n);return a._initialData=s,e.comment&&a.setCommentData(e),a}get toolbarButtons(){return this._colorPicker||=new _o(this),[["colorPicker",this._colorPicker]]}get colorType(){return yt.INK_COLOR}get color(){return this._drawingOptions.stroke}get opacity(){return this._drawingOptions["stroke-opacity"]}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();const{_drawId:e,_drawingOptions:t,parent:n}=this;t.updateSVGProperty("stroke-width"),n.drawLayer.updateProperties(e,t.toSVGProperties())}static onScaleChangingWhenDrawing(){const e=this._currentParent;e&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),e.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:e,thickness:t,opacity:n}){this._drawingOptions=zh.getDefaultDrawingOptions({stroke:be.makeHexColor(...e),"stroke-width":t,"stroke-opacity":n})}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:t,points:n}=this.serializeDraw(e),{_drawingOptions:{stroke:s,"stroke-opacity":a,"stroke-width":o}}=this,c=Object.assign(super.serialize(e),{color:Ue._colorManager.convert(s),opacity:a,thickness:o,paths:{lines:t,points:n}});return this.addComment(c),e?(c.isCopy=!0,c):this.annotationElementId&&!this.#e(c)?null:(c.id=this.annotationElementId,c)}#e(e){const{color:t,thickness:n,opacity:s,pageIndex:a}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized||e.color.some((o,c)=>o!==t[c])||e.thickness!==n||e.opacity!==s||e.pageIndex!==a}renderAnnotationElement(e){if(this.deleted)return e.hide(),null;const{points:t,rect:n}=this.serializeDraw(!1);return e.updateEdited({rect:n,thickness:this._drawingOptions["stroke-width"],points:t,popup:this.comment}),null}}class Gh extends tl{toSVGPath(){let e=super.toSVGPath();return e.endsWith("Z")||(e+="Z"),e}}const vu=8,nl=3;class J0{static#e={maxDim:512,sigmaSFactor:.02,sigmaR:25,kernelSize:16};static#t(e,t,n,s){return n-=e,s-=t,n===0?s>0?0:4:n===1?s+6:2-s}static#i=new Int32Array([0,1,-1,1,-1,0,-1,-1,0,-1,1,-1,1,0,1,1]);static#n(e,t,n,s,a,o,c){const d=this.#t(n,s,a,o);for(let f=0;f<8;f++){const g=(-f+d-c+16)%8,w=this.#i[2*g],b=this.#i[2*g+1];if(e[(n+w)*t+(s+b)]!==0)return g}return-1}static#A(e,t,n,s,a,o,c){const d=this.#t(n,s,a,o);for(let f=0;f<8;f++){const g=(f+d+c+16)%8,w=this.#i[2*g],b=this.#i[2*g+1];if(e[(n+w)*t+(s+b)]!==0)return g}return-1}static#s(e,t,n,s){const a=e.length,o=new Int32Array(a);for(let g=0;g<a;g++)o[g]=e[g]<=s?1:0;for(let g=1;g<n-1;g++)o[g*t]=o[g*t+t-1]=0;for(let g=0;g<t;g++)o[g]=o[t*n-1-g]=0;let c=1,d;const f=[];for(let g=1;g<n-1;g++){d=1;for(let w=1;w<t-1;w++){const b=g*t+w,E=o[b];if(E===0)continue;let M=g,S=w;if(E===1&&o[b-1]===0)c+=1,S-=1;else if(E>=1&&o[b+1]===0)c+=1,S+=1,E>1&&(d=E);else{E!==1&&(d=Math.abs(E));continue}const j=[w,g],F=S===w+1,z={isHole:F,points:j,id:c,parent:0};f.push(z);let J;for(const p1 of f)if(p1.id===d){J=p1;break}J?J.isHole?z.parent=F?J.parent:d:z.parent=F?d:J.parent:z.parent=F?d:0;const Y=this.#n(o,t,g,w,M,S,0);if(Y===-1){o[b]=-c,o[b]!==1&&(d=Math.abs(o[b]));continue}let H=this.#i[2*Y],W=this.#i[2*Y+1];const _=g+H,l1=w+W;M=_,S=l1;let r1=g,f1=w;for(;;){const p1=this.#A(o,t,r1,f1,M,S,1);H=this.#i[2*p1],W=this.#i[2*p1+1];const b1=r1+H,N1=f1+W;j.push(N1,b1);const B1=r1*t+f1;if(o[B1+1]===0?o[B1]=-c:o[B1]===1&&(o[B1]=c),b1===g&&N1===w&&r1===_&&f1===l1){o[b]!==1&&(d=Math.abs(o[b]));break}else M=r1,S=f1,r1=b1,f1=N1}}}return f}static#r(e,t,n,s){if(n-t<=4){for(let _=t;_<n-2;_+=2)s.push(e[_],e[_+1]);return}const a=e[t],o=e[t+1],c=e[n-4]-a,d=e[n-3]-o,f=Math.hypot(c,d),g=c/f,w=d/f,b=g*o-w*a,E=d/c,M=1/f,S=Math.atan(E),j=Math.cos(S),F=Math.sin(S),z=M*(Math.abs(j)+Math.abs(F)),J=M*(1-z+z**2),Y=Math.max(Math.atan(Math.abs(F+j)*J),Math.atan(Math.abs(F-j)*J));let H=0,W=t;for(let _=t+2;_<n-2;_+=2){const l1=Math.abs(b-g*e[_+1]+w*e[_]);l1>H&&(W=_,H=l1)}H>(f*Y)**2?(this.#r(e,t,W+2,s),this.#r(e,W,n,s)):s.push(a,o)}static#a(e){const t=[],n=e.length;return this.#r(e,0,n,t),t.push(e[n-2],e[n-1]),t.length<=4?null:t}static#l(e,t,n,s,a,o){const c=new Float32Array(o**2),d=-2*s**2,f=o>>1;for(let S=0;S<o;S++){const j=(S-f)**2;for(let F=0;F<o;F++)c[S*o+F]=Math.exp((j+(F-f)**2)/d)}const g=new Float32Array(256),w=-2*a**2;for(let S=0;S<256;S++)g[S]=Math.exp(S**2/w);const b=e.length,E=new Uint8Array(b),M=new Uint32Array(256);for(let S=0;S<n;S++)for(let j=0;j<t;j++){const F=S*t+j,z=e[F];let J=0,Y=0;for(let W=0;W<o;W++){const _=S+W-f;if(!(_<0||_>=n))for(let l1=0;l1<o;l1++){const r1=j+l1-f;if(r1<0||r1>=t)continue;const f1=e[_*t+r1],p1=c[W*o+l1]*g[Math.abs(f1-z)];J+=f1*p1,Y+=p1}}const H=E[F]=Math.round(J/Y);M[H]++}return[E,M]}static#o(e){const t=new Uint32Array(256);for(const n of e)t[n]++;return t}static#d(e){const t=e.length,n=new Uint8ClampedArray(t>>2);let s=-1/0,a=1/0;for(let c=0,d=n.length;c<d;c++){const f=n[c]=e[c<<2];s=Math.max(s,f),a=Math.min(a,f)}const o=255/(s-a);for(let c=0,d=n.length;c<d;c++)n[c]=(n[c]-a)*o;return n}static#u(e){let t,n=-1/0,s=-1/0;const a=e.findIndex(d=>d!==0);let o=a,c=a;for(t=a;t<256;t++){const d=e[t];d>n&&(t-o>s&&(s=t-o,c=t-1),n=d,o=t)}for(t=c-1;t>=0&&!(e[t]>e[t+1]);t--);return t}static#h(e){const t=e,{width:n,height:s}=e,{maxDim:a}=this.#e;let o=n,c=s;if(n>a||s>a){let b=n,E=s,M=Math.log2(Math.max(n,s)/a);const S=Math.floor(M);M=M===S?S-1:S;for(let F=0;F<M;F++){o=Math.ceil(b/2),c=Math.ceil(E/2);const z=new OffscreenCanvas(o,c);z.getContext("2d").drawImage(e,0,0,b,E,0,0,o,c),b=o,E=c,e!==t&&e.close(),e=z.transferToImageBitmap()}const j=Math.min(a/o,a/c);o=Math.round(o*j),c=Math.round(c*j)}const f=new OffscreenCanvas(o,c).getContext("2d",{willReadFrequently:!0});f.fillStyle="white",f.fillRect(0,0,o,c),f.filter="grayscale(1)",f.drawImage(e,0,0,e.width,e.height,0,0,o,c);const g=f.getImageData(0,0,o,c).data;return[this.#d(g),o,c]}static extractContoursFromText(e,{fontFamily:t,fontStyle:n,fontWeight:s},a,o,c,d){let f=new OffscreenCanvas(1,1),g=f.getContext("2d",{alpha:!1});const w=200,b=g.font=`${n} ${s} ${w}px ${t}`,{actualBoundingBoxLeft:E,actualBoundingBoxRight:M,actualBoundingBoxAscent:S,actualBoundingBoxDescent:j,fontBoundingBoxAscent:F,fontBoundingBoxDescent:z,width:J}=g.measureText(e),Y=1.5,H=Math.ceil(Math.max(Math.abs(E)+Math.abs(M)||0,J)*Y),W=Math.ceil(Math.max(Math.abs(S)+Math.abs(j)||w,Math.abs(F)+Math.abs(z)||w)*Y);f=new OffscreenCanvas(H,W),g=f.getContext("2d",{alpha:!0,willReadFrequently:!0}),g.font=b,g.filter="grayscale(1)",g.fillStyle="white",g.fillRect(0,0,H,W),g.fillStyle="black",g.fillText(e,H*(Y-1)/2,W*(3-Y)/2);const _=this.#d(g.getImageData(0,0,H,W).data),l1=this.#o(_),r1=this.#u(l1),f1=this.#s(_,H,W,r1);return this.processDrawnLines({lines:{curves:f1,width:H,height:W},pageWidth:a,pageHeight:o,rotation:c,innerMargin:d,mustSmooth:!0,areContours:!0})}static process(e,t,n,s,a){const[o,c,d]=this.#h(e),[f,g]=this.#l(o,c,d,Math.hypot(c,d)*this.#e.sigmaSFactor,this.#e.sigmaR,this.#e.kernelSize),w=this.#u(g),b=this.#s(f,c,d,w);return this.processDrawnLines({lines:{curves:b,width:c,height:d},pageWidth:t,pageHeight:n,rotation:s,innerMargin:a,mustSmooth:!0,areContours:!0})}static processDrawnLines({lines:e,pageWidth:t,pageHeight:n,rotation:s,innerMargin:a,mustSmooth:o,areContours:c}){s%180!==0&&([t,n]=[n,t]);const{curves:d,width:f,height:g}=e,w=e.thickness??0,b=[],E=Math.min(t/f,n/g),M=E/t,S=E/n,j=[];for(const{points:z}of d){const J=o?this.#a(z):z;if(!J)continue;j.push(J);const Y=J.length,H=new Float32Array(Y),W=new Float32Array(3*(Y===2?2:Y-2));if(b.push({line:W,points:H}),Y===2){H[0]=J[0]*M,H[1]=J[1]*S,W.set([NaN,NaN,NaN,NaN,H[0],H[1]],0);continue}let[_,l1,r1,f1]=J;_*=M,l1*=S,r1*=M,f1*=S,H.set([_,l1,r1,f1],0),W.set([NaN,NaN,NaN,NaN,_,l1],0);for(let p1=4;p1<Y;p1+=2){const b1=H[p1]=J[p1]*M,N1=H[p1+1]=J[p1+1]*S;W.set(Be.createBezierPoints(_,l1,r1,f1,b1,N1),(p1-2)*3),[_,l1,r1,f1]=[r1,f1,b1,N1]}}if(b.length===0)return null;const F=c?new Gh:new tl;return F.build(b,t,n,1,s,c?0:w,a),{outline:F,newCurves:j,areContours:c,thickness:w,width:f,height:g}}static async compressSignature({outlines:e,areContours:t,thickness:n,width:s,height:a}){let o=1/0,c=-1/0,d=0;for(const J of e){d+=J.length;for(let Y=2,H=J.length;Y<H;Y++){const W=J[Y]-J[Y-2];o=Math.min(o,W),c=Math.max(c,W)}}let f;o>=-128&&c<=127?f=Int8Array:o>=-32768&&c<=32767?f=Int16Array:f=Int32Array;const g=e.length,w=vu+nl*g,b=new Uint32Array(w);let E=0;b[E++]=w*Uint32Array.BYTES_PER_ELEMENT+(d-2*g)*f.BYTES_PER_ELEMENT,b[E++]=0,b[E++]=s,b[E++]=a,b[E++]=t?0:1,b[E++]=Math.max(0,Math.floor(n??0)),b[E++]=g,b[E++]=f.BYTES_PER_ELEMENT;for(const J of e)b[E++]=J.length-2,b[E++]=J[0],b[E++]=J[1];const M=new CompressionStream("deflate-raw"),S=M.writable.getWriter();await S.ready,S.write(b);const j=f.prototype.constructor;for(const J of e){const Y=new j(J.length-2);for(let H=2,W=J.length;H<W;H++)Y[H-2]=J[H]-J[H-2];S.write(Y)}S.close();const F=await new Response(M.readable).arrayBuffer(),z=new Uint8Array(F);return H6(z)}static async decompressSignature(e){try{const t=L8(e),{readable:n,writable:s}=new DecompressionStream("deflate-raw"),a=s.getWriter();await a.ready,a.write(t).then(async()=>{await a.ready,await a.close()}).catch(()=>{});let o=null,c=0;for await(const J of n)o||=new Uint8Array(new Uint32Array(J.buffer,0,4)[0]),o.set(J,c),c+=J.length;const d=new Uint32Array(o.buffer,0,o.length>>2),f=d[1];if(f!==0)throw new Error(`Invalid version: ${f}`);const g=d[2],w=d[3],b=d[4]===0,E=d[5],M=d[6],S=d[7],j=[],F=(vu+nl*M)*Uint32Array.BYTES_PER_ELEMENT;let z;switch(S){case Int8Array.BYTES_PER_ELEMENT:z=new Int8Array(o.buffer,F);break;case Int16Array.BYTES_PER_ELEMENT:z=new Int16Array(o.buffer,F);break;case Int32Array.BYTES_PER_ELEMENT:z=new Int32Array(o.buffer,F);break}c=0;for(let J=0;J<M;J++){const Y=d[nl*J+vu],H=new Float32Array(Y+2);j.push(H);for(let W=0;W<nl-1;W++)H[W]=d[nl*J+vu+W+1];for(let W=0;W<Y;W++)H[W+2]=H[W]+z[c++]}return{areContours:b,thickness:E,outlines:j,width:g,height:w}}catch(t){return rt(`decompressSignature: ${t}`),null}}}class Yh extends zp{constructor(){super(),super.updateProperties({fill:Ue._defaultLineColor,"stroke-width":0})}clone(){const e=new Yh;return e.updateAll(this),e}}class Kh extends wu{constructor(e){super(e),super.updateProperties({stroke:Ue._defaultLineColor,"stroke-width":1})}clone(){const e=new Kh(this._viewParameters);return e.updateAll(this),e}}class h3 extends He{#e=!1;#t=null;#i=null;#n=null;static _type="signature";static _editorType=st.SIGNATURE;static _defaultDrawingOptions=null;constructor(e){super({...e,mustBeCommitted:!0,name:"signatureEditor"}),this._willKeepAspectRatio=!0,this.#i=e.signatureData||null,this.#t=null,this.defaultL10nId="pdfjs-editor-signature-editor1"}static initialize(e,t){Ue.initialize(e,t),this._defaultDrawingOptions=new Yh,this._defaultDrawnSignatureOptions=new Kh(t.viewParameters)}static getDefaultDrawingOptions(e){const t=this._defaultDrawingOptions.clone();return t.updateProperties(e),t}static get supportMultipleDrawings(){return!1}static get typesMap(){return ut(this,"typesMap",new Map)}static get isDrawer(){return!1}get telemetryFinalData(){return{type:"signature",hasDescription:!!this.#t}}static computeTelemetryFinalData(e){const t=e.get("hasDescription");return{hasAltText:t.get(!0)??0,hasNoAltText:t.get(!1)??0}}get isResizable(){return!0}onScaleChanging(){this._drawId!==null&&super.onScaleChanging()}render(){if(this.div)return this.div;let e,t;const{_isCopy:n}=this;if(n&&(this._isCopy=!1,e=this.x,t=this.y),super.render(),this._drawId===null)if(this.#i){const{lines:s,mustSmooth:a,areContours:o,description:c,uuid:d,heightInPage:f}=this.#i,{rawDims:{pageWidth:g,pageHeight:w},rotation:b}=this.parent.viewport,E=J0.processDrawnLines({lines:s,pageWidth:g,pageHeight:w,rotation:b,innerMargin:h3._INNER_MARGIN,mustSmooth:a,areContours:o});this.addSignature(E,f,c,d)}else this.div.setAttribute("data-l10n-args",JSON.stringify({description:""})),this.div.hidden=!0,this._uiManager.getSignature(this);else this.div.setAttribute("data-l10n-args",JSON.stringify({description:this.#t||""}));return n&&(this._isCopy=!0,this._moveAfterPaste(e,t)),this.div}setUuid(e){this.#n=e,this.addEditToolbar()}getUuid(){return this.#n}get description(){return this.#t}set description(e){this.#t=e,this.div&&(this.div.setAttribute("data-l10n-args",JSON.stringify({description:e})),super.addEditToolbar().then(t=>{t?.updateEditSignatureButton(e)}))}getSignaturePreview(){const{newCurves:e,areContours:t,thickness:n,width:s,height:a}=this.#i,o=Math.max(s,a),c=J0.processDrawnLines({lines:{curves:e.map(d=>({points:d})),thickness:n,width:s,height:a},pageWidth:o,pageHeight:o,rotation:0,innerMargin:0,mustSmooth:!1,areContours:t});return{areContours:t,outline:c.outline}}get toolbarButtons(){return this._uiManager.signatureManager?[["editSignature",this._uiManager.signatureManager]]:super.toolbarButtons}addSignature(e,t,n,s){const{x:a,y:o}=this,{outline:c}=this.#i=e;this.#e=c instanceof Gh,this.description=n;let d;this.#e?d=h3.getDefaultDrawingOptions():(d=h3._defaultDrawnSignatureOptions.clone(),d.updateProperties({"stroke-width":c.thickness})),this._addOutlines({drawOutlines:c,drawingOptions:d});const[,f]=this.pageDimensions;let g=t/f;g=g>=1?.5:g,this.width*=g/this.height,this.width>=1&&(g*=.9/this.width,this.width=.9),this.height=g,this.setDims(),this.x=a,this.y=o,this.center(),this._onResized(),this.onScaleChanging(),this.rotate(),this._uiManager.addToAnnotationStorage(this),this.setUuid(s),this._reportTelemetry({action:"pdfjs.signature.inserted",data:{hasBeenSaved:!!s,hasDescription:!!n}}),this.div.hidden=!1}getFromImage(e){const{rawDims:{pageWidth:t,pageHeight:n},rotation:s}=this.parent.viewport;return J0.process(e,t,n,s,h3._INNER_MARGIN)}getFromText(e,t){const{rawDims:{pageWidth:n,pageHeight:s},rotation:a}=this.parent.viewport;return J0.extractContoursFromText(e,t,n,s,a,h3._INNER_MARGIN)}getDrawnSignature(e){const{rawDims:{pageWidth:t,pageHeight:n},rotation:s}=this.parent.viewport;return J0.processDrawnLines({lines:e,pageWidth:t,pageHeight:n,rotation:s,innerMargin:h3._INNER_MARGIN,mustSmooth:!1,areContours:!1})}createDrawingOptions({areContours:e,thickness:t}){e?this._drawingOptions=h3.getDefaultDrawingOptions():(this._drawingOptions=h3._defaultDrawnSignatureOptions.clone(),this._drawingOptions.updateProperties({"stroke-width":t}))}serialize(e=!1){if(this.isEmpty())return null;const{lines:t,points:n}=this.serializeDraw(e),{_drawingOptions:{"stroke-width":s}}=this,a=Object.assign(super.serialize(e),{isSignature:!0,areContours:this.#e,color:[0,0,0],thickness:this.#e?0:s});return this.addComment(a),e?(a.paths={lines:t,points:n},a.uuid=this.#n,a.isCopy=!0):a.lines=t,this.#t&&(a.accessibilityData={type:"Figure",alt:this.#t}),a}static deserializeDraw(e,t,n,s,a,o){return o.areContours?Gh.deserialize(e,t,n,s,a,o):tl.deserialize(e,t,n,s,a,o)}static async deserialize(e,t,n){const s=await super.deserialize(e,t,n);return s.#e=e.areContours,s.description=e.accessibilityData?.alt||"",s.#n=e.uuid,s}}class rv extends Ue{#e=null;#t=null;#i=null;#n=null;#A=null;#s="";#r=null;#a=!1;#l=null;#o=!1;#d=!1;static _type="stamp";static _editorType=st.STAMP;constructor(e){super({...e,name:"stampEditor"}),this.#n=e.bitmapUrl,this.#A=e.bitmapFile,this.defaultL10nId="pdfjs-editor-stamp-editor"}static initialize(e,t){Ue.initialize(e,t)}static isHandlingMimeForPasting(e){return au.includes(e)}static paste(e,t){t.pasteEditor({mode:st.STAMP},{bitmapFile:e.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){return{type:"stamp",hasAltText:!!this.altTextData?.altText}}static computeTelemetryFinalData(e){const t=e.get("hasAltText");return{hasAltText:t.get(!0)??0,hasNoAltText:t.get(!1)??0}}#u(e,t=!1){if(!e){this.remove();return}this.#e=e.bitmap,t||(this.#t=e.id,this.#o=e.isSvg),e.file&&(this.#s=e.file.name),this.#f()}#h(){if(this.#i=null,this._uiManager.enableWaiting(!1),!!this.#r){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#e){this.addEditToolbar().then(()=>{this._editToolbar.hide(),this._uiManager.editAltText(this,!0)});return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#e){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(e=null,t=!0){if(this.hasAltTextData())return null;const{mlManager:n}=this._uiManager;if(!n)throw new Error("No ML.");if(!await n.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:s,width:a,height:o}=e||this.copyCanvas(null,null,!0).imageData,c=await n.guess({name:"altText",request:{data:s,width:a,height:o,channels:s.length/(a*o)}});if(!c)throw new Error("No response from the AI service.");if(c.error)throw new Error("Error from the AI service.");if(c.cancel)return null;if(!c.output)throw new Error("No valid response from the AI service.");const d=c.output;return await this.setGuessedAltText(d),t&&!this.hasAltTextData()&&(this.altTextData={alt:d,decorative:!1}),d}#g(){if(this.#t){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(this.#t).then(n=>this.#u(n,!0)).finally(()=>this.#h());return}if(this.#n){const n=this.#n;this.#n=null,this._uiManager.enableWaiting(!0),this.#i=this._uiManager.imageManager.getFromUrl(n).then(s=>this.#u(s)).finally(()=>this.#h());return}if(this.#A){const n=this.#A;this.#A=null,this._uiManager.enableWaiting(!0),this.#i=this._uiManager.imageManager.getFromFile(n).then(s=>this.#u(s)).finally(()=>this.#h());return}const e=document.createElement("input");e.type="file",e.accept=au.join(",");const t=this._uiManager._signal;this.#i=new Promise(n=>{e.addEventListener("change",async()=>{if(!e.files||e.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const s=await this._uiManager.imageManager.getFromFile(e.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),this.#u(s)}n()},{signal:t}),e.addEventListener("cancel",()=>{this.remove(),n()},{signal:t})}).finally(()=>this.#h()),e.click()}remove(){this.#t&&(this.#e=null,this._uiManager.imageManager.deleteId(this.#t),this.#r?.remove(),this.#r=null,this.#l&&(clearTimeout(this.#l),this.#l=null)),super.remove()}rebuild(){if(!this.parent){this.#t&&this.#g();return}super.rebuild(),this.div!==null&&(this.#t&&this.#r===null&&this.#g(),this.isAttachedToDOM||this.parent.add(this))}onceAdded(e){this._isDraggable=!0,e&&this.div.focus()}isEmpty(){return!(this.#i||this.#e||this.#n||this.#A||this.#t||this.#a)}get toolbarButtons(){return[["altText",this.createAltText()]]}get isResizable(){return!0}render(){if(this.div)return this.div;let e,t;return this._isCopy&&(e=this.x,t=this.y),super.render(),this.div.hidden=!0,this.createAltText(),this.#a||(this.#e?this.#f():this.#g()),this._isCopy&&this._moveAfterPaste(e,t),this._uiManager.addShouldRescale(this),this.div}setCanvas(e,t){const{id:n,bitmap:s}=this._uiManager.imageManager.getFromCanvas(e,t);t.remove(),n&&this._uiManager.imageManager.isValidId(n)&&(this.#t=n,s&&(this.#e=s),this.#a=!1,this.#f())}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;this.#l!==null&&clearTimeout(this.#l);const e=200;this.#l=setTimeout(()=>{this.#l=null,this.#p()},e)}#f(){const{div:e}=this;let{width:t,height:n}=this.#e;const[s,a]=this.pageDimensions,o=.75;if(this.width)t=this.width*s,n=this.height*a;else if(t>o*s||n>o*a){const d=Math.min(o*s/t,o*a/n);t*=d,n*=d}this._uiManager.enableWaiting(!1);const c=this.#r=document.createElement("canvas");c.setAttribute("role","img"),this.addContainer(c),this.width=t/s,this.height=n/a,this.setDims(),this._initialOptions?.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(e.hidden=!1),this.#p(),this.#d||(this.parent.addUndoableEditor(this),this.#d=!0),this._reportTelemetry({action:"inserted_image"}),this.#s&&this.div.setAttribute("aria-description",this.#s),this.annotationElementId||this._uiManager.a11yAlert("pdfjs-editor-stamp-added-alert")}copyCanvas(e,t,n=!1){e||(e=224);const{width:s,height:a}=this.#e,o=new Fs;let c=this.#e,d=s,f=a,g=null;if(t){if(s>t||a>t){const W=Math.min(t/s,t/a);d=Math.floor(s*W),f=Math.floor(a*W)}g=document.createElement("canvas");const b=g.width=Math.ceil(d*o.sx),E=g.height=Math.ceil(f*o.sy);this.#o||(c=this.#c(b,E));const M=g.getContext("2d");M.filter=this._uiManager.hcmFilter;let S="white",j="#cfcfd8";this._uiManager.hcmFilter!=="none"?j="black":N8.isDarkMode&&(S="#8f8f9d",j="#42414d");const F=15,z=F*o.sx,J=F*o.sy,Y=new OffscreenCanvas(z*2,J*2),H=Y.getContext("2d");H.fillStyle=S,H.fillRect(0,0,z*2,J*2),H.fillStyle=j,H.fillRect(0,0,z,J),H.fillRect(z,J,z,J),M.fillStyle=M.createPattern(Y,"repeat"),M.fillRect(0,0,b,E),M.drawImage(c,0,0,c.width,c.height,0,0,b,E)}let w=null;if(n){let b,E;if(o.symmetric&&c.width<e&&c.height<e)b=c.width,E=c.height;else if(c=this.#e,s>e||a>e){const j=Math.min(e/s,e/a);b=Math.floor(s*j),E=Math.floor(a*j),this.#o||(c=this.#c(b,E))}const S=new OffscreenCanvas(b,E).getContext("2d",{willReadFrequently:!0});S.drawImage(c,0,0,c.width,c.height,0,0,b,E),w={width:b,height:E,data:S.getImageData(0,0,b,E).data}}return{canvas:g,width:d,height:f,imageData:w}}#c(e,t){const{width:n,height:s}=this.#e;let a=n,o=s,c=this.#e;for(;a>2*e||o>2*t;){const d=a,f=o;a>2*e&&(a=a>=16384?Math.floor(a/2)-1:Math.ceil(a/2)),o>2*t&&(o=o>=16384?Math.floor(o/2)-1:Math.ceil(o/2));const g=new OffscreenCanvas(a,o);g.getContext("2d").drawImage(c,0,0,d,f,0,0,a,o),c=g.transferToImageBitmap()}return c}#p(){const[e,t]=this.parentDimensions,{width:n,height:s}=this,a=new Fs,o=Math.ceil(n*e*a.sx),c=Math.ceil(s*t*a.sy),d=this.#r;if(!d||d.width===o&&d.height===c)return;d.width=o,d.height=c;const f=this.#o?this.#e:this.#c(o,c),g=d.getContext("2d");g.filter=this._uiManager.hcmFilter,g.drawImage(f,0,0,f.width,f.height,0,0,o,c)}#m(e){if(e){if(this.#o){const s=this._uiManager.imageManager.getSvgUrl(this.#t);if(s)return s}const t=document.createElement("canvas");return{width:t.width,height:t.height}=this.#e,t.getContext("2d").drawImage(this.#e,0,0),t.toDataURL()}if(this.#o){const[t,n]=this.pageDimensions,s=Math.round(this.width*t*G0.PDF_TO_CSS_UNITS),a=Math.round(this.height*n*G0.PDF_TO_CSS_UNITS),o=new OffscreenCanvas(s,a);return o.getContext("2d").drawImage(this.#e,0,0,this.#e.width,this.#e.height,0,0,s,a),o.transferToImageBitmap()}return structuredClone(this.#e)}static async deserialize(e,t,n){let s=null,a=!1;if(e instanceof Rp){const{data:{rect:S,rotation:j,id:F,structParent:z,popupRef:J,richText:Y,contentsObj:H,creationDate:W,modificationDate:_},container:l1,parent:{page:{pageNumber:r1}},canvas:f1}=e;let p1,b1;f1?(delete e.canvas,{id:p1,bitmap:b1}=n.imageManager.getFromCanvas(l1.id,f1),f1.remove()):(a=!0,e._hasNoCanvas=!0);const N1=(await t._structTree.getAriaAttributes(`${fh}${F}`))?.get("aria-label")||"";s=e={annotationType:st.STAMP,bitmapId:p1,bitmap:b1,pageIndex:r1-1,rect:S.slice(0),rotation:j,annotationElementId:F,id:F,deleted:!1,accessibilityData:{decorative:!1,altText:N1},isSvg:!1,structParent:z,popupRef:J,richText:Y,comment:H?.str||null,creationDate:W,modificationDate:_}}const o=await super.deserialize(e,t,n),{rect:c,bitmap:d,bitmapUrl:f,bitmapId:g,isSvg:w,accessibilityData:b}=e;a?(n.addMissingCanvas(e.id,o),o.#a=!0):g&&n.imageManager.isValidId(g)?(o.#t=g,d&&(o.#e=d)):o.#n=f,o.#o=w;const[E,M]=o.pageDimensions;return o.width=(c[2]-c[0])/E,o.height=(c[3]-c[1])/M,b&&(o.altTextData=b),o._initialData=s,e.comment&&o.setCommentData(e),o.#d=!!s,o}serialize(e=!1,t=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const n=Object.assign(super.serialize(e),{bitmapId:this.#t,isSvg:this.#o});if(this.addComment(n),e)return n.bitmapUrl=this.#m(!0),n.accessibilityData=this.serializeAltText(!0),n.isCopy=!0,n;const{decorative:s,altText:a}=this.serializeAltText(!1);if(!s&&a&&(n.accessibilityData={type:"Figure",alt:a}),this.annotationElementId){const c=this.#v(n);return c.isSame?null:(c.isSameAltText?delete n.accessibilityData:n.accessibilityData.structParent=this._initialData.structParent??-1,n.id=this.annotationElementId,delete n.bitmapId,n)}if(t===null)return n;t.stamps||=new Map;const o=this.#o?(n.rect[2]-n.rect[0])*(n.rect[3]-n.rect[1]):null;if(!t.stamps.has(this.#t))t.stamps.set(this.#t,{area:o,serialized:n}),n.bitmap=this.#m(!1);else if(this.#o){const c=t.stamps.get(this.#t);o>c.area&&(c.area=o,c.serialized.bitmap.close(),c.serialized.bitmap=this.#m(!1))}return n}#v(e){const{pageIndex:t,accessibilityData:{altText:n}}=this._initialData,s=e.pageIndex===t,a=(e.accessibilityData?.alt||"")===n;return{isSame:!this.hasEditedComment&&!this._hasBeenMoved&&!this._hasBeenResized&&s&&a,isSameAltText:a}}renderAnnotationElement(e){return this.deleted?(e.hide(),null):(e.updateEdited({rect:this.getPDFRect(),popup:this.comment}),null)}}class f3{#e;#t=!1;#i=null;#n=null;#A=null;#s=new Map;#r=!1;#a=!1;#l=!1;#o=null;#d=null;#u=null;#h=null;#g=null;#f=-1;#c;static _initialized=!1;static#p=new Map([gn,zh,rv,z2,h3].map(e=>[e._editorType,e]));constructor({uiManager:e,pageIndex:t,div:n,structTreeLayer:s,accessibilityManager:a,annotationLayer:o,drawLayer:c,textLayer:d,viewport:f,l10n:g}){const w=[...f3.#p.values()];if(!f3._initialized){f3._initialized=!0;for(const b of w)b.initialize(g,e)}e.registerEditorTypes(w),this.#c=e,this.pageIndex=t,this.div=n,this.#e=a,this.#i=o,this.viewport=f,this.#u=d,this.drawLayer=c,this._structTree=s,this.#c.addLayer(this)}get isEmpty(){return this.#s.size===0}get isInvisible(){return this.isEmpty&&this.#c.getMode()===st.NONE}updateToolbar(e){this.#c.updateToolbar(e)}updateMode(e=this.#c.getMode()){switch(this.#C(),e){case st.NONE:this.div.classList.toggle("nonEditing",!0),this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case st.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case st.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);const{classList:t}=this.div;if(t.toggle("nonEditing",!1),e===st.POPUP)t.toggle("commentEditing",!0);else{t.toggle("commentEditing",!1);for(const n of f3.#p.values())t.toggle(`${n._type}Editing`,e===n._editorType)}this.div.hidden=!1}hasTextLayer(e){return e===this.#u?.div}setEditingState(e){this.#c.setEditingState(e)}addCommands(e){this.#c.addCommands(e)}cleanUndoStack(e){this.#c.cleanUndoStack(e)}toggleDrawing(e=!1){this.div.classList.toggle("drawing",!e)}togglePointerEvents(e=!1){this.div.classList.toggle("disabled",!e)}toggleAnnotationLayerPointerEvents(e=!1){this.#i?.div.classList.toggle("disabled",!e)}get#m(){return this.#s.size!==0?this.#s.values():this.#c.getEditors(this.pageIndex)}async enable(){this.#l=!0,this.div.tabIndex=0,this.togglePointerEvents(!0),this.div.classList.toggle("nonEditing",!1),this.#g?.abort(),this.#g=null;const e=new Set;for(const n of this.#m)n.enableEditing(),n.show(!0),n.annotationElementId&&(this.#c.removeChangedExistingAnnotation(n),e.add(n.annotationElementId));const t=this.#i;if(t)for(const n of t.getEditableAnnotations()){if(n.hide(),this.#c.isDeletedAnnotationElement(n.data.id)||e.has(n.data.id))continue;const s=await this.deserialize(n);s&&(this.addOrRebuild(s),s.enableEditing())}this.#l=!1,this.#c._eventBus.dispatch("editorsrendered",{source:this,pageNumber:this.pageIndex+1})}disable(){if(this.#a=!0,this.div.tabIndex=-1,this.togglePointerEvents(!1),this.div.classList.toggle("nonEditing",!0),this.#u&&!this.#g){this.#g=new AbortController;const n=this.#c.combinedSignal(this.#g);this.#u.div.addEventListener("pointerdown",s=>{const{clientX:o,clientY:c,timeStamp:d}=s,f=this.#f;if(d-f>500){this.#f=d;return}this.#f=-1;const{classList:g}=this.div;g.toggle("getElements",!0);const w=document.elementsFromPoint(o,c);if(g.toggle("getElements",!1),!this.div.contains(w[0]))return;let b;const E=new RegExp(`^${Qo}[0-9]+$`);for(const S of w)if(E.test(S.id)){b=S.id;break}if(!b)return;const M=this.#s.get(b);M?.annotationElementId===null&&(s.stopPropagation(),s.preventDefault(),M.dblclick(s))},{signal:n,capture:!0})}const e=this.#i;if(e){const n=new Map,s=new Map;for(const o of this.#m){if(o.disableEditing(),!o.annotationElementId){o.updateFakeAnnotationElement(e);continue}if(o.serialize()!==null){n.set(o.annotationElementId,o);continue}else s.set(o.annotationElementId,o);this.getEditableAnnotation(o.annotationElementId)?.show(),o.remove()}const a=e.getEditableAnnotations();for(const o of a){const{id:c}=o.data;if(this.#c.isDeletedAnnotationElement(c)){o.updateEdited({deleted:!0});continue}let d=s.get(c);if(d){d.resetAnnotationElement(o),d.show(!1),o.show();continue}d=n.get(c),d&&(this.#c.addChangedExistingAnnotation(d),d.renderAnnotationElement(o)&&d.show(!1)),o.show()}}this.#C(),this.isEmpty&&(this.div.hidden=!0);const{classList:t}=this.div;for(const n of f3.#p.values())t.remove(`${n._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),this.#a=!1}getEditableAnnotation(e){return this.#i?.getEditableAnnotation(e)||null}setActiveEditor(e){this.#c.getActive()!==e&&this.#c.setActiveEditor(e)}enableTextSelection(){if(this.div.tabIndex=-1,this.#u?.div&&!this.#h){this.#h=new AbortController;const e=this.#c.combinedSignal(this.#h);this.#u.div.addEventListener("pointerdown",this.#v.bind(this),{signal:e}),this.#u.div.classList.add("highlighting")}}disableTextSelection(){this.div.tabIndex=0,this.#u?.div&&this.#h&&(this.#h.abort(),this.#h=null,this.#u.div.classList.remove("highlighting"))}#v(e){this.#c.unselectAll();const{target:t}=e;if(t===this.#u.div||(t.getAttribute("role")==="img"||t.classList.contains("endOfContent"))&&this.#u.div.contains(t)){const{isMac:n}=pn.platform;if(e.button!==0||e.ctrlKey&&n)return;this.#c.showAllEditors("highlight",!0,!0),this.#u.div.classList.add("free"),this.toggleDrawing(),z2.startHighlighting(this,this.#c.direction==="ltr",{target:this.#u.div,x:e.x,y:e.y}),this.#u.div.addEventListener("pointerup",()=>{this.#u.div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:this.#c._signal}),e.preventDefault()}}enableClick(){if(this.#n)return;this.#n=new AbortController;const e=this.#c.combinedSignal(this.#n);this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:e});const t=this.pointerup.bind(this);this.div.addEventListener("pointerup",t,{signal:e}),this.div.addEventListener("pointercancel",t,{signal:e})}disableClick(){this.#n?.abort(),this.#n=null}attach(e){this.#s.set(e.id,e);const{annotationElementId:t}=e;t&&this.#c.isDeletedAnnotationElement(t)&&this.#c.removeDeletedAnnotationElement(e)}detach(e){this.#s.delete(e.id),this.#e?.removePointerInTextLayer(e.contentDiv),!this.#a&&e.annotationElementId&&this.#c.addDeletedAnnotationElement(e)}remove(e){this.detach(e),this.#c.removeEditor(e),e.div.remove(),e.isAttachedToDOM=!1}changeParent(e){e.parent!==this&&(e.parent&&e.annotationElementId&&(this.#c.addDeletedAnnotationElement(e.annotationElementId),Ue.deleteAnnotationElement(e),e.annotationElementId=null),this.attach(e),e.parent?.detach(e),e.setParent(this),e.div&&e.isAttachedToDOM&&(e.div.remove(),this.div.append(e.div)))}add(e){if(!(e.parent===this&&e.isAttachedToDOM)){if(this.changeParent(e),this.#c.addEditor(e),this.attach(e),!e.isAttachedToDOM){const t=e.render();this.div.append(t),e.isAttachedToDOM=!0}e.fixAndSetPosition(),e.onceAdded(!this.#l),this.#c.addToAnnotationStorage(e),e._reportTelemetry(e.telemetryInitialData)}}moveEditorInDOM(e){if(!e.isAttachedToDOM)return;const{activeElement:t}=document;e.div.contains(t)&&!this.#A&&(e._focusEventsAllowed=!1,this.#A=setTimeout(()=>{this.#A=null,e.div.contains(document.activeElement)?e._focusEventsAllowed=!0:(e.div.addEventListener("focusin",()=>{e._focusEventsAllowed=!0},{once:!0,signal:this.#c._signal}),t.focus())},0)),e._structTreeParentId=this.#e?.moveElementInDOM(this.div,e.div,e.contentDiv,!0)}addOrRebuild(e){e.needsToBeRebuilt()?(e.parent||=this,e.rebuild(),e.show()):this.add(e)}addUndoableEditor(e){const t=()=>e._uiManager.rebuild(e),n=()=>{e.remove()};this.addCommands({cmd:t,undo:n,mustExec:!1})}getEditorByUID(e){for(const t of this.#s.values())if(t.uid===e)return t;return null}getNextId(){return this.#c.getId()}get#w(){return f3.#p.get(this.#c.getMode())}combinedSignal(e){return this.#c.combinedSignal(e)}#I(e){const t=this.#w;return t?new t.prototype.constructor(e):null}canCreateNewEmptyEditor(){return this.#w?.canCreateNewEmptyEditor()}async pasteEditor(e,t){this.updateToolbar(e),await this.#c.updateMode(e.mode);const{offsetX:n,offsetY:s}=this.#B(),a=this.getNextId(),o=this.#I({parent:this,id:a,x:n,y:s,uiManager:this.#c,isCentered:!0,...t});o&&this.add(o)}async deserialize(e){return await f3.#p.get(e.annotationType??e.annotationEditorType)?.deserialize(e,this,this.#c)||null}createAndAddNewEditor(e,t,n={}){const s=this.getNextId(),a=this.#I({parent:this,id:s,x:e.offsetX,y:e.offsetY,uiManager:this.#c,isCentered:t,...n});return a&&this.add(a),a}get boundingClientRect(){return this.div.getBoundingClientRect()}#B(){const{x:e,y:t,width:n,height:s}=this.boundingClientRect,a=Math.max(0,e),o=Math.max(0,t),c=Math.min(window.innerWidth,e+n),d=Math.min(window.innerHeight,t+s),f=(a+c)/2-e,g=(o+d)/2-t,[w,b]=this.viewport.rotation%180===0?[f,g]:[g,f];return{offsetX:w,offsetY:b}}addNewEditor(e={}){this.createAndAddNewEditor(this.#B(),!0,e)}setSelected(e){this.#c.setSelected(e)}toggleSelected(e){this.#c.toggleSelected(e)}unselect(e){this.#c.unselect(e)}pointerup(e){const{isMac:t}=pn.platform;if(e.button!==0||e.ctrlKey&&t||e.target!==this.div||!this.#r||(this.#r=!1,this.#w?.isDrawer&&this.#w.supportMultipleDrawings))return;if(!this.#t){this.#t=!0;return}const n=this.#c.getMode();if(n===st.STAMP||n===st.SIGNATURE){this.#c.unselectAll();return}this.createAndAddNewEditor(e,!1)}pointerdown(e){if(this.#c.getMode()===st.HIGHLIGHT&&this.enableTextSelection(),this.#r){this.#r=!1;return}const{isMac:t}=pn.platform;if(e.button!==0||e.ctrlKey&&t||e.target!==this.div)return;if(this.#r=!0,this.#w?.isDrawer){this.startDrawingSession(e);return}const n=this.#c.getActive();this.#t=!n||n.isEmpty()}startDrawingSession(e){if(this.div.focus({preventScroll:!0}),this.#o){this.#w.startDrawing(this,this.#c,!1,e);return}this.#c.setCurrentDrawingSession(this),this.#o=new AbortController;const t=this.#c.combinedSignal(this.#o);this.div.addEventListener("blur",({relatedTarget:n})=>{n&&!this.div.contains(n)&&(this.#d=null,this.commitOrRemove())},{signal:t}),this.#w.startDrawing(this,this.#c,!1,e)}pause(e){if(e){const{activeElement:t}=document;this.div.contains(t)&&(this.#d=t);return}this.#d&&setTimeout(()=>{this.#d?.focus(),this.#d=null},0)}endDrawingSession(e=!1){return this.#o?(this.#c.setCurrentDrawingSession(null),this.#o.abort(),this.#o=null,this.#d=null,this.#w.endDrawing(e)):null}findNewParent(e,t,n){const s=this.#c.findParent(t,n);return s===null||s===this?!1:(s.changeParent(e),!0)}commitOrRemove(){return this.#o?(this.endDrawingSession(),!0):!1}onScaleChanging(){this.#o&&this.#w.onScaleChangingWhenDrawing(this)}destroy(){this.commitOrRemove(),this.#c.getActive()?.parent===this&&(this.#c.commitOrRemove(),this.#c.setActiveEditor(null)),this.#A&&(clearTimeout(this.#A),this.#A=null);for(const e of this.#s.values())this.#e?.removePointerInTextLayer(e.contentDiv),e.setParent(null),e.isAttachedToDOM=!1,e.div.remove();this.div=null,this.#s.clear(),this.#c.removeLayer(this)}#C(){for(const e of this.#s.values())e.isEmpty()&&e.remove()}render({viewport:e}){this.viewport=e,Ur(this.div,e);for(const t of this.#c.getEditors(this.pageIndex))this.add(t),t.rebuild();this.updateMode()}update({viewport:e}){this.#c.commitOrRemove(),this.#C();const t=this.viewport.rotation,n=e.rotation;if(this.viewport=e,Ur(this.div,{rotation:n}),t!==n)for(const s of this.#s.values())s.rotate(n)}get pageDimensions(){const{pageWidth:e,pageHeight:t}=this.viewport.rawDims;return[e,t]}get scale(){return this.#c.viewParameters.realScale}}class mn{#e=null;#t=new Map;#i=new Map;static#n=0;constructor({pageIndex:e}){this.pageIndex=e}setParent(e){if(!this.#e){this.#e=e;return}if(this.#e!==e){if(this.#t.size>0)for(const t of this.#t.values())t.remove(),e.append(t);this.#e=e}}static get _svgFactory(){return ut(this,"_svgFactory",new el)}static#A(e,[t,n,s,a]){const{style:o}=e;o.top=`${100*n}%`,o.left=`${100*t}%`,o.width=`${100*s}%`,o.height=`${100*a}%`}#s(){const e=mn._svgFactory.create(1,1,!0);return this.#e.append(e),e.setAttribute("aria-hidden",!0),e}#r(e,t){const n=mn._svgFactory.createElement("clipPath");e.append(n);const s=`clip_${t}`;n.setAttribute("id",s),n.setAttribute("clipPathUnits","objectBoundingBox");const a=mn._svgFactory.createElement("use");return n.append(a),a.setAttribute("href",`#${t}`),a.classList.add("clip"),s}#a(e,t){for(const[n,s]of Object.entries(t))s===null?e.removeAttribute(n):e.setAttribute(n,s)}draw(e,t=!1,n=!1){const s=mn.#n++,a=this.#s(),o=mn._svgFactory.createElement("defs");a.append(o);const c=mn._svgFactory.createElement("path");o.append(c);const d=`path_p${this.pageIndex}_${s}`;c.setAttribute("id",d),c.setAttribute("vector-effect","non-scaling-stroke"),t&&this.#i.set(s,c);const f=n?this.#r(o,d):null,g=mn._svgFactory.createElement("use");return a.append(g),g.setAttribute("href",`#${d}`),this.updateProperties(a,e),this.#t.set(s,a),{id:s,clipPathId:`url(#${f})`}}drawOutline(e,t){const n=mn.#n++,s=this.#s(),a=mn._svgFactory.createElement("defs");s.append(a);const o=mn._svgFactory.createElement("path");a.append(o);const c=`path_p${this.pageIndex}_${n}`;o.setAttribute("id",c),o.setAttribute("vector-effect","non-scaling-stroke");let d;if(t){const w=mn._svgFactory.createElement("mask");a.append(w),d=`mask_p${this.pageIndex}_${n}`,w.setAttribute("id",d),w.setAttribute("maskUnits","objectBoundingBox");const b=mn._svgFactory.createElement("rect");w.append(b),b.setAttribute("width","1"),b.setAttribute("height","1"),b.setAttribute("fill","white");const E=mn._svgFactory.createElement("use");w.append(E),E.setAttribute("href",`#${c}`),E.setAttribute("stroke","none"),E.setAttribute("fill","black"),E.setAttribute("fill-rule","nonzero"),E.classList.add("mask")}const f=mn._svgFactory.createElement("use");s.append(f),f.setAttribute("href",`#${c}`),d&&f.setAttribute("mask",`url(#${d})`);const g=f.cloneNode();return s.append(g),f.classList.add("mainOutline"),g.classList.add("secondaryOutline"),this.updateProperties(s,e),this.#t.set(n,s),n}finalizeDraw(e,t){this.#i.delete(e),this.updateProperties(e,t)}updateProperties(e,t){if(!t)return;const{root:n,bbox:s,rootClass:a,path:o}=t,c=typeof e=="number"?this.#t.get(e):e;if(c){if(n&&this.#a(c,n),s&&mn.#A(c,s),a){const{classList:d}=c;for(const[f,g]of Object.entries(a))d.toggle(f,g)}if(o){const f=c.firstChild.firstChild;this.#a(f,o)}}}updateParent(e,t){if(t===this)return;const n=this.#t.get(e);n&&(t.#e.append(n),this.#t.delete(e),t.#t.set(e,n))}remove(e){this.#i.delete(e),this.#e!==null&&(this.#t.get(e).remove(),this.#t.delete(e))}destroy(){this.#e=null;for(const e of this.#t.values())e.remove();this.#t.clear(),this.#i.clear()}}globalThis._pdfjsTestingUtils={HighlightOutliner:Rh},globalThis.pdfjsLib={AbortException:J3,AnnotationEditorLayer:f3,AnnotationEditorParamsType:yt,AnnotationEditorType:st,AnnotationEditorUIManager:W3,AnnotationLayer:Ph,AnnotationMode:l3,AnnotationType:H2,applyOpacity:J6,build:Np,ColorPicker:zi,createValidAbsoluteUrl:oh,CSSConstants:X6,DOMSVGFactory:el,DrawLayer:mn,FeatureTest:pn,fetchData:ra,findContrastColor:_6,getDocument:Nh,getFilenameFromUrl:z6,getPdfFilenameFromUrl:G6,getRGB:Aa,getUuid:hh,getXfaPageViewport:K6,GlobalWorkerOptions:Or,ImageKind:Uo,InvalidPDFException:iu,isDataScheme:zo,isPdfFile:ru,isValidExplicitDest:ip,MathClamp:Rn,noContextMenu:Ri,normalizeUnicode:R6,OPS:sa,OutputScale:Fs,PasswordResponses:U6,PDFDataRangeTransport:jh,PDFDateString:Au,PDFWorker:ha,PermissionFlag:Q6,PixelsPerInch:G0,RenderingCancelledException:su,renderRichText:mh,ResponseException:ko,setLayerDimensions:Ur,shadow:ut,SignatureExtractor:J0,stopEvent:B2,SupportedImageMimeTypes:au,TextLayer:Zo,TouchManager:Xo,updateUrlHash:lh,Util:be,VerbosityLevel:Oo,version:Qh,XfaLayer:ph};const Av=Object.freeze(Object.defineProperty({__proto__:null,AbortException:J3,AnnotationEditorLayer:f3,AnnotationEditorParamsType:yt,AnnotationEditorType:st,AnnotationEditorUIManager:W3,AnnotationLayer:Ph,AnnotationMode:l3,AnnotationType:H2,CSSConstants:X6,ColorPicker:zi,DOMSVGFactory:el,DrawLayer:mn,FeatureTest:pn,GlobalWorkerOptions:Or,ImageKind:Uo,InvalidPDFException:iu,MathClamp:Rn,OPS:sa,OutputScale:Fs,PDFDataRangeTransport:jh,PDFDateString:Au,PDFWorker:ha,PasswordResponses:U6,PermissionFlag:Q6,PixelsPerInch:G0,RenderingCancelledException:su,ResponseException:ko,SignatureExtractor:J0,SupportedImageMimeTypes:au,TextLayer:Zo,TouchManager:Xo,Util:be,VerbosityLevel:Oo,XfaLayer:ph,applyOpacity:J6,build:Np,createValidAbsoluteUrl:oh,fetchData:ra,findContrastColor:_6,getDocument:Nh,getFilenameFromUrl:z6,getPdfFilenameFromUrl:G6,getRGB:Aa,getUuid:hh,getXfaPageViewport:K6,isDataScheme:zo,isPdfFile:ru,isValidExplicitDest:ip,noContextMenu:Ri,normalizeUnicode:R6,renderRichText:mh,setLayerDimensions:Ur,shadow:ut,stopEvent:B2,updateUrlHash:lh,version:Qh},Symbol.toStringTag,{value:"Module"}));function Gp(A){var e,t,n="";if(typeof A=="string"||typeof A=="number")n+=A;else if(typeof A=="object")if(Array.isArray(A)){var s=A.length;for(e=0;e<s;e++)A[e]&&(t=Gp(A[e]))&&(n&&(n+=" "),n+=t)}else for(t in A)A[t]&&(n&&(n+=" "),n+=t);return n}function Cu(){for(var A,e,t=0,n="",s=arguments.length;t<s;t++)(A=arguments[t])&&(e=Gp(A))&&(n&&(n+=" "),n+=e);return n}var Yp=Object.prototype.hasOwnProperty;function Kp(A,e,t){for(t of A.keys())if(pa(t,e))return t}function pa(A,e){var t,n,s;if(A===e)return!0;if(A&&e&&(t=A.constructor)===e.constructor){if(t===Date)return A.getTime()===e.getTime();if(t===RegExp)return A.toString()===e.toString();if(t===Array){if((n=A.length)===e.length)for(;n--&&pa(A[n],e[n]););return n===-1}if(t===Set){if(A.size!==e.size)return!1;for(n of A)if(s=n,s&&typeof s=="object"&&(s=Kp(e,s),!s)||!e.has(s))return!1;return!0}if(t===Map){if(A.size!==e.size)return!1;for(n of A)if(s=n[0],s&&typeof s=="object"&&(s=Kp(e,s),!s)||!pa(n[1],e.get(s)))return!1;return!0}if(t===ArrayBuffer)A=new Uint8Array(A),e=new Uint8Array(e);else if(t===DataView){if((n=A.byteLength)===e.byteLength)for(;n--&&A.getInt8(n)===e.getInt8(n););return n===-1}if(ArrayBuffer.isView(A)){if((n=A.byteLength)===e.byteLength)for(;n--&&A[n]===e[n];);return n===-1}if(!t||typeof A=="object"){n=0;for(t in A)if(Yp.call(A,t)&&++n&&!Yp.call(e,t)||!(t in e)||!pa(A[t],e[t]))return!1;return Object.keys(e).length===n}}return A!==A&&e!==e}function il(A){let e=!1;return{promise:new Promise((n,s)=>{A.then(a=>!e&&n(a)).catch(a=>!e&&s(a))}),cancel(){e=!0}}}const av=["onCopy","onCut","onPaste"],ov=["onCompositionEnd","onCompositionStart","onCompositionUpdate"],lv=["onFocus","onBlur"],cv=["onInput","onInvalid","onReset","onSubmit"],uv=["onLoad","onError"],dv=["onKeyDown","onKeyPress","onKeyUp"],hv=["onAbort","onCanPlay","onCanPlayThrough","onDurationChange","onEmptied","onEncrypted","onEnded","onError","onLoadedData","onLoadedMetadata","onLoadStart","onPause","onPlay","onPlaying","onProgress","onRateChange","onSeeked","onSeeking","onStalled","onSuspend","onTimeUpdate","onVolumeChange","onWaiting"],fv=["onClick","onContextMenu","onDoubleClick","onMouseDown","onMouseEnter","onMouseLeave","onMouseMove","onMouseOut","onMouseOver","onMouseUp"],pv=["onDrag","onDragEnd","onDragEnter","onDragExit","onDragLeave","onDragOver","onDragStart","onDrop"],gv=["onSelect"],mv=["onTouchCancel","onTouchEnd","onTouchMove","onTouchStart"],wv=["onPointerDown","onPointerMove","onPointerUp","onPointerCancel","onGotPointerCapture","onLostPointerCapture","onPointerEnter","onPointerLeave","onPointerOver","onPointerOut"],vv=["onScroll"],Cv=["onWheel"],yv=["onAnimationStart","onAnimationEnd","onAnimationIteration"],bv=["onTransitionEnd"],Bv=["onToggle"],xv=["onChange"],Iv=[...av,...ov,...lv,...cv,...uv,...dv,...hv,...fv,...pv,...gv,...mv,...wv,...vv,...Cv,...yv,...bv,...xv,...Bv];function Xp(A,e){const t={};for(const n of Iv){const s=A[n];s&&(e?t[n]=(a=>s(a,e(n))):t[n]=s)}return t}var Ev="Invariant failed";function o2(A,e){if(!A)throw new Error(Ev)}var Xh,Jp;function Sv(){if(Jp)return Xh;Jp=1;var A=function(){};return Xh=A,Xh}var Mv=Sv();const Hn=F2(Mv),Vp=G.createContext(null),Lv="noopener noreferrer nofollow";class Dv{constructor(){this.externalLinkEnabled=!0,this.externalLinkRel=void 0,this.externalLinkTarget=void 0,this.isInPresentationMode=!1,this.pdfDocument=void 0,this.pdfViewer=void 0}setDocument(e){this.pdfDocument=e}setViewer(e){this.pdfViewer=e}setExternalLinkRel(e){this.externalLinkRel=e}setExternalLinkTarget(e){this.externalLinkTarget=e}setHash(){}setHistory(){}get pagesCount(){return this.pdfDocument?this.pdfDocument.numPages:0}get page(){return o2(this.pdfViewer),this.pdfViewer.currentPageNumber||0}set page(e){o2(this.pdfViewer),this.pdfViewer.currentPageNumber=e}get rotation(){return 0}set rotation(e){}addLinkAttributes(e,t,n){e.href=t,e.rel=this.externalLinkRel||Lv,e.target=n?"_blank":this.externalLinkTarget||""}goToDestination(e){return new Promise(t=>{o2(this.pdfDocument),o2(e),typeof e=="string"?this.pdfDocument.getDestination(e).then(t):Array.isArray(e)?t(e):e.then(t)}).then(t=>{o2(Array.isArray(t));const n=t[0];new Promise(s=>{o2(this.pdfDocument),n instanceof Object?this.pdfDocument.getPageIndex(n).then(a=>{s(a)}).catch(()=>{o2(!1)}):typeof n=="number"?s(n):o2(!1)}).then(s=>{const a=s+1;o2(this.pdfViewer),o2(a>=1&&a<=this.pagesCount),this.pdfViewer.scrollPageIntoView({dest:t,pageIndex:s,pageNumber:a})})})}goToPage(e){const t=e-1;o2(this.pdfViewer),o2(e>=1&&e<=this.pagesCount),this.pdfViewer.scrollPageIntoView({pageIndex:t,pageNumber:e})}goToXY(){}cachePageRef(){}getDestinationHash(){return"#"}getAnchorUrl(){return"#"}executeNamedAction(){}executeSetOCGState(){}isPageVisible(){return!0}isPageCached(){return!0}navigateTo(e){this.goToDestination(e)}}function ga({children:A,type:e}){return u.jsx("div",{className:`react-pdf__message react-pdf__message--${e}`,children:A})}const Wp={NEED_PASSWORD:1,INCORRECT_PASSWORD:2};function Fv(A,e){switch(e.type){case"RESOLVE":return{value:e.value,error:void 0};case"REJECT":return{value:!1,error:e.error};case"RESET":return{value:void 0,error:void 0};default:return A}}function ma(){return G.useReducer(Fv,{value:void 0,error:void 0})}const yu=typeof window<"u",qp=yu&&window.location.protocol==="file:";function Nv(A){return typeof A<"u"}function V0(A){return Nv(A)&&A!==null}function Tv(A){return typeof A=="string"}function jv(A){return A instanceof ArrayBuffer}function Qv(A){return o2(yu),A instanceof Blob}function Jh(A){return Tv(A)&&/^data:/.test(A)}function Zp(A){o2(Jh(A));const[e="",t=""]=A.split(",");return e.split(";").indexOf("base64")!==-1?atob(t):unescape(t)}function Uv(){return yu&&window.devicePixelRatio||1}const _p="On Chromium based browsers, you can use --allow-file-access-from-files flag for debugging purposes.";function $p(){Hn(!qp,`Loading PDF as base64 strings/URLs may not work on protocols other than HTTP/HTTPS. ${_p}`)}function Ov(){Hn(!qp,`Loading PDF.js worker may not work on protocols other than HTTP/HTTPS. ${_p}`)}function W0(A){A?.cancel&&A.cancel()}function Vh(A,e){return Object.defineProperty(A,"width",{get(){return this.getViewport({scale:e}).width},configurable:!0}),Object.defineProperty(A,"height",{get(){return this.getViewport({scale:e}).height},configurable:!0}),Object.defineProperty(A,"originalWidth",{get(){return this.getViewport({scale:1}).width},configurable:!0}),Object.defineProperty(A,"originalHeight",{get(){return this.getViewport({scale:1}).height},configurable:!0}),A}function e5(A){return A.name==="AbortException"||A.name==="RenderingCancelledException"}function kv(A){return new Promise((e,t)=>{const n=new FileReader;n.onload=()=>{if(!n.result)return t(new Error("Error while reading a file."));e(n.result)},n.onerror=s=>{if(!s.target)return t(new Error("Error while reading a file."));const{error:a}=s.target;if(!a)return t(new Error("Error while reading a file."));switch(a.code){case a.NOT_FOUND_ERR:return t(new Error("Error while reading a file: File not found."));case a.SECURITY_ERR:return t(new Error("Error while reading a file: Security error."));case a.ABORT_ERR:return t(new Error("Error while reading a file: Aborted."));default:return t(new Error("Error while reading a file."))}},n.readAsArrayBuffer(A)})}const{PDFDataRangeTransport:Pv}=Av,Rv=(A,e)=>{switch(e){case Wp.NEED_PASSWORD:{const t=prompt("Enter the password to open this PDF file.");A(t);break}case Wp.INCORRECT_PASSWORD:{const t=prompt("Invalid password. Please try again.");A(t);break}}};function t5(A){return typeof A=="object"&&A!==null&&("data"in A||"range"in A||"url"in A)}const Hv=G.forwardRef(function({children:e,className:t,error:n="Failed to load PDF file.",externalLinkRel:s,externalLinkTarget:a,file:o,inputRef:c,imageResourcesPath:d,loading:f="Loading PDF…",noData:g="No PDF file specified.",onItemClick:w,onLoadError:b,onLoadProgress:E,onLoadSuccess:M,onPassword:S=Rv,onSourceError:j,onSourceSuccess:F,options:z,renderMode:J,rotate:Y,scale:H,...W},_){const[l1,r1]=ma(),{value:f1,error:p1}=l1,[b1,N1]=ma(),{value:B1,error:T1}=b1,$=G.useRef(new Dv),u1=G.useRef([]),x1=G.useRef(void 0),P1=G.useRef(void 0);o&&o!==x1.current&&t5(o)&&(Hn(!pa(o,x1.current),`File prop passed to <Document /> changed, but it's equal to previous one. This might result in unnecessary reloads. Consider memoizing the value passed to "file" prop.`),x1.current=o),z&&z!==P1.current&&(Hn(!pa(z,P1.current),`Options prop passed to <Document /> changed, but it's equal to previous one. This might result in unnecessary reloads. Consider memoizing the value passed to "options" prop.`),P1.current=z);const Z=G.useRef({scrollPageIntoView:ue=>{const{dest:he,pageNumber:C1,pageIndex:R1=C1-1}=ue;if(w){w({dest:he,pageIndex:R1,pageNumber:C1});return}const se=u1.current[R1];if(se){se.scrollIntoView();return}Hn(!1,`An internal link leading to page ${C1} was clicked, but neither <Document> was provided with onItemClick nor it was able to find the page within itself. Either provide onItemClick to <Document> and handle navigating by yourself or ensure that all pages are rendered within <Document>.`)}});G.useImperativeHandle(_,()=>({linkService:$,pages:u1,viewer:Z}),[]);function w1(){F&&F()}function L1(){p1&&(Hn(!1,p1.toString()),j&&j(p1))}function S1(){r1({type:"RESET"})}G.useEffect(S1,[o,r1]);const z1=G.useCallback(async()=>{if(!o)return null;if(typeof o=="string")return Jh(o)?{data:Zp(o)}:($p(),{url:o});if(o instanceof Pv)return{range:o};if(jv(o))return{data:o};if(yu&&Qv(o))return{data:await kv(o)};if(o2(typeof o=="object"),o2(t5(o)),"url"in o&&typeof o.url=="string"){if(Jh(o.url)){const{url:ue,...he}=o;return{data:Zp(ue),...he}}$p()}return o},[o]);G.useEffect(()=>{const ue=il(z1());return ue.promise.then(he=>{r1({type:"RESOLVE",value:he})}).catch(he=>{r1({type:"REJECT",error:he})}),()=>{W0(ue)}},[z1,r1]),G.useEffect(()=>{if(!(typeof f1>"u")){if(f1===!1){L1();return}w1()}},[f1]);function H1(){B1&&(M&&M(B1),u1.current=new Array(B1.numPages),$.current.setDocument(B1))}function G1(){T1&&(Hn(!1,T1.toString()),b&&b(T1))}G.useEffect(function(){N1({type:"RESET"})},[N1,f1]),G.useEffect(function(){if(!f1)return;const he=z?{...f1,...z}:f1,C1=Nh(he);E&&(C1.onProgress=E),S&&(C1.onPassword=S);const R1=C1;return R1.promise.then(se=>{R1.destroyed||N1({type:"RESOLVE",value:se})}).catch(se=>{R1.destroyed||N1({type:"REJECT",error:se})}),()=>{R1.destroy()}},[z,N1,f1]),G.useEffect(()=>{if(!(typeof B1>"u")){if(B1===!1){G1();return}H1()}},[B1]),G.useEffect(function(){$.current.setViewer(Z.current),$.current.setExternalLinkRel(s),$.current.setExternalLinkTarget(a)},[s,a]);const F1=G.useCallback((ue,he)=>{u1.current[ue]=he},[]),K1=G.useCallback(ue=>{delete u1.current[ue]},[]),pe=G.useMemo(()=>({imageResourcesPath:d,linkService:$.current,onItemClick:w,pdf:B1,registerPage:F1,renderMode:J,rotate:Y,scale:H,unregisterPage:K1}),[d,w,B1,F1,J,Y,H,K1]),Ce=G.useMemo(()=>Xp(W,()=>B1),[W,B1]);function ge(){function ue(C1){return!!C1?.pdf}if(!ue(pe))throw new Error("pdf is undefined");const he=typeof e=="function"?e(pe):e;return u.jsx(Vp.Provider,{value:pe,children:he})}function oe(){return o?B1==null?u.jsx(ga,{type:"loading",children:typeof f=="function"?f():f}):B1===!1?u.jsx(ga,{type:"error",children:typeof n=="function"?n():n}):ge():u.jsx(ga,{type:"no-data",children:typeof g=="function"?g():g})}return u.jsx("div",{className:Cu("react-pdf__Document",t),ref:c,...Ce,children:oe()})});function n5(){return G.useContext(Vp)}function i5(){for(var A=[],e=0;e<arguments.length;e++)A[e]=arguments[e];var t=A.filter(Boolean);if(t.length<=1){var n=t[0];return n||null}return function(a){for(var o=0,c=t;o<c.length;o++){var d=c[o];typeof d=="function"?d(a):d&&(d.current=a)}}}const s5=G.createContext(null);function bu(){return G.useContext(s5)}function zv(){const A=n5(),e=bu();o2(e);const t={...A,...e},{filterAnnotations:n,imageResourcesPath:s,linkService:a,onGetAnnotationsError:o,onGetAnnotationsSuccess:c,onRenderAnnotationLayerError:d,onRenderAnnotationLayerSuccess:f,page:g,pdf:w,renderForms:b,rotate:E,scale:M=1}=t;o2(w),o2(g),o2(a);const[S,j]=ma(),{value:F,error:z}=S,J=G.useRef(null);Hn(Number.parseInt(window.getComputedStyle(document.body).getPropertyValue("--react-pdf-annotation-layer"),10)===1,"AnnotationLayer styles not found. Read more: https://github.com/wojtekmaj/react-pdf#support-for-annotations");function Y(){F&&c&&c(F)}function H(){z&&(Hn(!1,z.toString()),o&&o(z))}G.useEffect(function(){j({type:"RESET"})},[j,g]),G.useEffect(function(){if(!g)return;const f1=il(g.getAnnotations()),p1=f1;return f1.promise.then(b1=>{j({type:"RESOLVE",value:b1})}).catch(b1=>{j({type:"REJECT",error:b1})}),()=>{W0(p1)}},[j,g]),G.useEffect(()=>{if(F!==void 0){if(F===!1){H();return}Y()}},[F]);function W(){f&&f()}function _(r1){Hn(!1,`${r1}`),d&&d(r1)}const l1=G.useMemo(()=>g.getViewport({scale:M,rotation:E}),[g,E,M]);return G.useEffect(function(){if(!w||!g||!a||!F)return;const{current:f1}=J;if(!f1)return;const p1=l1.clone({dontFlip:!0}),b1={accessibilityManager:null,annotationCanvasMap:null,annotationEditorUIManager:null,annotationStorage:w.annotationStorage,commentManager:null,div:f1,l10n:null,linkService:a,page:g,structTreeLayer:null,viewport:p1},N1={annotations:n?n({annotations:F}):F,annotationStorage:w.annotationStorage,div:f1,imageResourcesPath:s,linkService:a,page:g,renderForms:b,viewport:p1};f1.innerHTML="";try{new Ph(b1).render(N1),W()}catch(B1){_(B1)}return()=>{}},[F,n,s,a,g,w,b,l1]),u.jsx("div",{className:Cu("react-pdf__Page__annotations","annotationLayer"),ref:J})}const r5={Document:null,DocumentFragment:null,Part:"group",Sect:"group",Div:"group",Aside:"note",NonStruct:"none",P:null,H:"heading",Title:null,FENote:"note",Sub:"group",Lbl:null,Span:null,Em:null,Strong:null,Link:"link",Annot:"note",Form:"form",Ruby:null,RB:null,RT:null,RP:null,Warichu:null,WT:null,WP:null,L:"list",LI:"listitem",LBody:null,Table:"table",TR:"row",TH:"columnheader",TD:"cell",THead:"columnheader",TBody:null,TFoot:null,Caption:null,Figure:"figure",Formula:null,Artifact:null},Gv=/^H(\d+)$/;function Yv(A){return A in r5}function Bu(A){return"children"in A}function A5(A){return Bu(A)?A.children.length===1&&0 in A.children&&"id"in A.children[0]:!1}function Kv(A){const e={};if(Bu(A)){const{role:t}=A,n=t.match(Gv);if(n)e.role="heading",e["aria-level"]=Number(n[1]);else if(Yv(t)){const s=r5[t];s&&(e.role=s)}}return e}function a5(A){const e={};if(Bu(A)){if(A.alt!==void 0&&(e["aria-label"]=A.alt),A.lang!==void 0&&(e.lang=A.lang),A5(A)){const[t]=A.children;if(t){const n=a5(t);return{...e,...n}}}}else"id"in A&&(e["aria-owns"]=A.id);return e}function Xv(A){return A?{...Kv(A),...a5(A)}:null}function o5({className:A,node:e}){const t=G.useMemo(()=>Xv(e),[e]),n=G.useMemo(()=>!Bu(e)||A5(e)?null:e.children.map((s,a)=>u.jsx(o5,{node:s},a)),[e]);return u.jsx("span",{className:A,...t,children:n})}function Jv(){const A=bu();o2(A);const{onGetStructTreeError:e,onGetStructTreeSuccess:t}=A,[n,s]=ma(),{value:a,error:o}=n,{customTextRenderer:c,page:d}=A;function f(){a&&t&&t(a)}function g(){o&&(Hn(!1,o.toString()),e&&e(o))}return G.useEffect(function(){s({type:"RESET"})},[s,d]),G.useEffect(function(){if(c||!d)return;const b=il(d.getStructTree()),E=b;return b.promise.then(M=>{s({type:"RESOLVE",value:M})}).catch(M=>{s({type:"REJECT",error:M})}),()=>W0(E)},[c,d,s]),G.useEffect(()=>{if(a!==void 0){if(a===!1){g();return}f()}},[a]),a?u.jsx(o5,{className:"react-pdf__Page__structTree structTree",node:a}):null}const l5=l3;function Vv(A){const e=bu();o2(e);const t={...e,...A},{_className:n,canvasBackground:s,devicePixelRatio:a=Uv(),onRenderError:o,onRenderSuccess:c,page:d,renderForms:f,renderTextLayer:g,pageColors:w,rotate:b,scale:E}=t,{canvasRef:M}=A;o2(d);const S=G.useRef(null);function j(){d&&c&&c(Vh(d,E))}function F(H){e5(H)||(Hn(!1,H.toString()),o&&o(H))}const z=G.useMemo(()=>d.getViewport({scale:E*a,rotation:b}),[a,d,b,E]),J=G.useMemo(()=>d.getViewport({scale:E,rotation:b}),[d,b,E]);G.useEffect(function(){if(!d)return;d.cleanup();const{current:W}=S;if(!W)return;W.width=z.width,W.height=z.height,W.style.width=`${Math.floor(J.width)}px`,W.style.height=`${Math.floor(J.height)}px`,W.style.visibility="hidden";const _={annotationMode:f?l5.ENABLE_FORMS:l5.ENABLE,canvas:W,canvasContext:W.getContext("2d",{alpha:!1}),pageColors:w,viewport:z};s&&(_.background=s);const l1=d.render(_),r1=l1;return l1.promise.then(()=>{W.style.visibility="",j()}).catch(F),()=>W0(r1)},[s,d,w,f,z,J]);const Y=G.useCallback(()=>{const{current:H}=S;H&&(H.width=0,H.height=0)},[]);return G.useEffect(()=>Y,[Y]),u.jsx("canvas",{className:`${n}__canvas`,dir:"ltr",ref:i5(M,S),style:{display:"block",userSelect:"none"},children:g?u.jsx(Jv,{}):null})}function Wv(A){return"str"in A}const qv=new Set(["base","embed","iframe","link","meta","object","script","style","template"]),Zv=new Set(["action","formaction","href","poster","src","xlink:href"]);function _v(A){let e="";for(const t of A){const n=t.charCodeAt(0);n<=32||n===127||(e+=t.toLowerCase())}return e.startsWith("javascript:")||e.startsWith("vbscript:")}function $v(A){return A.nodeType===Node.ELEMENT_NODE}function c5(A){return $v(A)&&A instanceof HTMLElement}function eC(A){return c5(A)&&qv.has(A.tagName.toLowerCase())}function tC(A){const e=document.createElement(A.tagName.toLowerCase());return Array.from(A.attributes).forEach(t=>{const n=t.name.toLowerCase();n.startsWith("on")||n==="srcdoc"||Zv.has(n)&&_v(t.value)||e.setAttribute(t.name,t.value)}),Array.from(A.childNodes).forEach(t=>{e.append(u5(t))}),e}function u5(A){var e;return c5(A)&&!eC(A)?tC(A):document.createTextNode((e=A.textContent)!==null&&e!==void 0?e:"")}function nC(A,e){const t=document.createElement("template");t.innerHTML=e;const n=document.createDocumentFragment();Array.from(t.content.childNodes).forEach(s=>{n.append(u5(s))}),A.replaceChildren(n)}function iC(){const A=bu();o2(A);const{customTextRenderer:e,onGetTextError:t,onGetTextSuccess:n,onRenderTextLayerError:s,onRenderTextLayerSuccess:a,page:o,pageIndex:c,pageNumber:d,rotate:f,scale:g}=A;o2(o);const[w,b]=ma(),{value:E,error:M}=w,S=G.useRef(null);Hn(Number.parseInt(window.getComputedStyle(document.body).getPropertyValue("--react-pdf-text-layer"),10)===1,"TextLayer styles not found. Read more: https://github.com/wojtekmaj/react-pdf#support-for-text-layer");function j(){E&&n&&n(E)}function F(){M&&(Hn(!1,M.toString()),t&&t(M))}G.useEffect(function(){b({type:"RESET"})},[o,b]),G.useEffect(function(){if(!o)return;const l1=il(o.getTextContent()),r1=l1;return l1.promise.then(f1=>{b({type:"RESOLVE",value:f1})}).catch(f1=>{b({type:"REJECT",error:f1})}),()=>W0(r1)},[o,b]),G.useEffect(()=>{if(E!==void 0){if(E===!1){F();return}j()}},[E]);const z=G.useCallback(()=>{a&&a()},[a]),J=G.useCallback(_=>{e5(_)||(Hn(!1,_.toString()),s&&s(_))},[s]);function Y(){const _=S.current;_&&_.classList.add("selecting")}function H(){const _=S.current;_&&_.classList.remove("selecting")}const W=G.useMemo(()=>o.getViewport({scale:g,rotation:f}),[o,f,g]);return G.useLayoutEffect(function(){if(!o||!E)return;const{current:l1}=S;if(!l1)return;l1.innerHTML="";const r1=o.streamTextContent({includeMarkedContent:!0}),f1={container:l1,textContentSource:r1,viewport:W},p1=new Zo(f1),b1=p1;return p1.render().then(()=>{const N1=document.createElement("div");N1.className="endOfContent",l1.append(N1);const B1=l1.querySelectorAll('[role="presentation"]');if(e){let T1=0;E.items.forEach(($,u1)=>{if(!Wv($))return;const x1=B1[T1];if(!x1)return;const P1=e({pageIndex:c,pageNumber:d,itemIndex:u1,...$});nC(x1,P1),T1+=$.str&&$.hasEOL?2:1})}z()}).catch(J),()=>W0(b1)},[e,J,z,o,c,d,E,W]),u.jsx("div",{className:Cu("react-pdf__Page__textContent","textLayer"),onMouseUp:H,onMouseDown:Y,ref:S})}const d5=1;function sC(A){const t={...n5(),...A},{_className:n="react-pdf__Page",_enableRegisterUnregisterPage:s=!0,canvasBackground:a,canvasRef:o,children:c,className:d,customRenderer:f,customTextRenderer:g,devicePixelRatio:w,error:b="Failed to load the page.",filterAnnotations:E,height:M,inputRef:S,loading:j="Loading page…",noData:F="No page specified.",onGetAnnotationsError:z,onGetAnnotationsSuccess:J,onGetStructTreeError:Y,onGetStructTreeSuccess:H,onGetTextError:W,onGetTextSuccess:_,onLoadError:l1,onLoadSuccess:r1,onRenderAnnotationLayerError:f1,onRenderAnnotationLayerSuccess:p1,onRenderError:b1,onRenderSuccess:N1,onRenderTextLayerError:B1,onRenderTextLayerSuccess:T1,pageColors:$,pageIndex:u1,pageNumber:x1,pdf:P1,registerPage:Z,renderAnnotationLayer:w1=!0,renderForms:L1=!1,renderMode:S1="canvas",renderTextLayer:z1=!0,rotate:H1,scale:G1=d5,unregisterPage:F1,width:K1,...pe}=t,[Ce,ge]=ma(),{value:oe,error:ue}=Ce,he=G.useRef(null);o2(P1);const C1=V0(x1)?x1-1:u1??null,R1=x1??(V0(u1)?u1+1:null),se=H1??(oe?oe.rotate:null),ae=G.useMemo(()=>{if(!oe)return null;let ke=1;const ht=G1??d5;if(K1||M){const at=oe.getViewport({scale:1,rotation:se});K1?ke=K1/at.width:M&&(ke=M/at.height)}return ht*ke},[M,oe,se,G1,K1]);G.useEffect(function(){return()=>{V0(C1)&&s&&F1&&F1(C1)}},[s,P1,C1,F1]);function ne(){if(r1){if(!oe||!ae)return;r1(Vh(oe,ae))}if(s&&Z){if(!V0(C1)||!he.current)return;Z(C1,he.current)}}function Ye(){ue&&(Hn(!1,ue.toString()),l1&&l1(ue))}G.useEffect(function(){ge({type:"RESET"})},[ge,P1,C1]),G.useEffect(function(){if(!P1||!R1)return;const ht=il(P1.getPage(R1)),at=ht;return ht.promise.then(_e=>{ge({type:"RESOLVE",value:_e})}).catch(_e=>{ge({type:"REJECT",error:_e})}),()=>W0(at)},[ge,P1,R1]),G.useEffect(()=>{if(oe!==void 0){if(oe===!1){Ye();return}ne()}},[oe,ae]);const Ne=G.useMemo(()=>V0(C1)&&R1&&V0(se)&&V0(ae)?{_className:n,canvasBackground:a,customTextRenderer:g,devicePixelRatio:w,filterAnnotations:E,onGetAnnotationsError:z,onGetAnnotationsSuccess:J,onGetStructTreeError:Y,onGetStructTreeSuccess:H,onGetTextError:W,onGetTextSuccess:_,onRenderAnnotationLayerError:f1,onRenderAnnotationLayerSuccess:p1,onRenderError:b1,onRenderSuccess:N1,onRenderTextLayerError:B1,onRenderTextLayerSuccess:T1,page:oe,pageColors:$,pageIndex:C1,pageNumber:R1,renderForms:L1,renderTextLayer:z1,rotate:se,scale:ae}:null,[n,a,g,w,E,z,J,Y,H,W,_,f1,p1,b1,N1,B1,T1,oe,$,C1,R1,L1,z1,se,ae]),qe=G.useMemo(()=>Xp(pe,()=>oe&&(ae?Vh(oe,ae):void 0)),[pe,oe,ae]),nt=`${C1}@${ae}/${se}`;function Je(){switch(S1){case"custom":return o2(f),u.jsx(f,{},`${nt}_custom`);case"none":return null;case"canvas":default:return u.jsx(Vv,{canvasRef:o},`${nt}_canvas`)}}function At(){return z1?u.jsx(iC,{},`${nt}_text`):null}function Ze(){return w1?u.jsx(zv,{},`${nt}_annotations`):null}function ce(){function ke(at){return!!at?.page}if(!ke(Ne))throw new Error("page is undefined");const ht=typeof c=="function"?c(Ne):c;return u.jsxs(s5.Provider,{value:Ne,children:[Je(),At(),Ze(),ht]})}function Ke(){return R1?P1===null||oe===void 0||oe===null?u.jsx(ga,{type:"loading",children:typeof j=="function"?j():j}):P1===!1||oe===!1?u.jsx(ga,{type:"error",children:typeof b=="function"?b():b}):ce():u.jsx(ga,{type:"no-data",children:typeof F=="function"?F():F})}return u.jsx("div",{className:Cu(n,d),"data-page-number":R1,ref:i5(S,he),style:{"--scale-round-x":"1px","--scale-round-y":"1px","--scale-factor":"1","--user-unit":`${ae}`,"--total-scale-factor":"calc(var(--scale-factor) * var(--user-unit))",backgroundColor:a||"white",position:"relative",minWidth:"min-content",minHeight:"min-content"},...qe,children:Ke()})}Ov(),Or.workerSrc="pdf.worker.mjs";function dt(A){return Number(A??0).toLocaleString("en-IN",{minimumFractionDigits:2,maximumFractionDigits:2})}Or.workerSrc=`https://unpkg.com/pdfjs-dist@${Qh}/build/pdf.worker.min.mjs`;const rC=({open:A,onClose:e,onPaymentCollected:t,selectedLenderIdx:n=-1,selectedLenderFiCode:s=null,selectedLenderTenureMappings:a=[],selectedLenderRepaymentOption:o=null,selectedLenderDisbursementAccount:c=null})=>{const{tenureMappings:d,payableValue:f,paymentType:g,paymentInvoice:w,invoices:b,chemistId:E,leadId:M,fiCode:S,typeOfApp:j,payerMobileNumber:F,salesmanId:z,distributorIdnum:J,distributorName:Y,drawdownRepaymentOption:H,creditLimitData:W}=ti(),_=a.length>0?a:d,[l1,r1]=G.useState(-1),[f1,p1]=G.useState(n);G.useEffect(()=>{n!==-1&&p1(n)},[n]);const[b1,N1]=G.useState(!1),B1=()=>{e()},T1=s||S,$=T1==="TRILLIONLOAN",u1=new Date;u1.setDate(u1.getDate()+1);const[x1,P1]=G.useState($?new Date:u1),[Z,w1]=G.useState(["","","","","",""]),L1=mi.useRef([]),[S1,z1]=G.useState(0),[H1,G1]=G.useState("idle"),[F1,K1]=G.useState(!1),[pe,Ce]=G.useState(!1),[ge,oe]=G.useState(""),[ue,he]=G.useState(""),[C1,R1]=G.useState(j==="FUNDLY_COLLECT_APP"||j==="FUNDLY_QR_COLLECT_APP"||j==="FUNDLY_QR_WEB"?"Collect":"Pay Now"),[se,ae]=G.useState(!1),[ne,Ye]=G.useState(null),[Ne,qe]=G.useState(null),[nt,Je]=G.useState(!1),[At,Ze]=G.useState(null),[ce,Ke]=G.useState([]),[ke,ht]=G.useState(!1),[at,_e]=G.useState(0),Ve=G.useCallback(le=>{const we=le.getFullYear(),gt=String(le.getMonth()+1).padStart(2,"0"),Ft=String(le.getDate()).padStart(2,"0");return`${we}-${gt}-${Ft}`},[]),Me=G.useCallback(async()=>{if(T1!=="TRILLIONLOAN"){ae(!1);return}ae(!0);try{const le=Pe(),we=s||S||"",gt=o||H||"BULLET",Ft=new URLSearchParams({loanAmount:String(f),businessId:E||"",openedOnDate:Ve(x1||u1),productType:"INSTACASH",tenureMagnitude:String(_[l1]?.tenureValue||""),tenureUnit:String(_[l1]?.tenureUnit||""),fiCode:we,repaymentOption:gt,supplierId:J||""});g==="INVOICE_COLLECT"&&w?.length>0&&Ft.append("invoiceNumber",w.map(S2=>S2.invoiceId).join(","));const ft=`${R0()}/kfs/report?${Ft.toString()}`,Et=await qt.get(ft,{headers:{accept:"application/json",Authorization:`Bearer ${le}`}});Ye(Et.data),qe(Et.data?.documentId??null),Je(!1)}catch(le){console.error("[Fundly Pay] Error fetching KFS:",le),Ye(null),qe(null),Je(!1)}finally{ae(!1)}},[s,S,o,H,f,E,x1,l1,_,J,g,w,Ve]),$1=G.useCallback(async()=>{if(T1==="TRILLIONLOAN")try{const le=Pe(),we=new URLSearchParams({businessId:E||"",intents:"DRAWDOWN_KFS_SIGN",fiCode:T1||""}),gt=`${R0()}/consent?${we.toString()}`,ft=(await qt.get(gt,{headers:{accept:"*/*","Content-Type":"application/json",Authorization:`Bearer ${le}`}})).data;if(Ke(Array.isArray(ft)?ft:[]),ft?.[0]?.consentMessage){let Et=ft[0].consentMessage;Et=Et.replace("{{lenderName}}",T1||""),Et=Et.replace("Drawdown Request Letter",'<span class="kfs-link" style="color:#16558B;text-decoration:underline;cursor:pointer">Drawdown Request Letter</span>'),Et=Et.replace("Sanction Letter",'<span class="kfs-link" style="color:#16558B;text-decoration:underline;cursor:pointer">Sanction Letter</span>'),Et=Et.replace("Key Fact Statement",'<span class="kfs-link" style="color:#16558B;text-decoration:underline;cursor:pointer">Key Fact Statement</span>'),Ze(Et)}}catch(le){console.error("[Fundly Pay] Error fetching consent:",le),Ze(null)}},[E]),xe=G.useCallback(async()=>{try{const le=Pe(),we=`${R0()}/consent`;await qt.post(we,{businessId:E||"",intent:"DRAWDOWN_KFS_SIGN",consents:ce.map(gt=>({consentId:gt.consentId,accepted:!0}))},{headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Bearer ${le}`}})}catch(le){console.error("[Fundly Pay] Error submitting consent:",le)}},[E,ce]),me=G.useCallback(()=>{ne&&ht(!0)},[ne]),$e=mi.useMemo(()=>ne?ne.kfsDocumentBytes?`data:application/pdf;base64,${ne.kfsDocumentBytes}`:ne.kfsDocumentUrl||ne.documentUrl||null:null,[ne]),vt=G.useRef(null);G.useEffect(()=>{const le=vt.current;if(!le)return;const we=gt=>{gt.target.classList.contains("kfs-link")&&me()};return le.addEventListener("click",we),()=>le.removeEventListener("click",we)},[me,At]);const Ut=async()=>{he("");try{F&&Y&&await Lm(F,Y)}catch(le){console.error("Error sending OTP:",le);const we=le,gt=we?.response?.data?.errorMessage||we?.response?.data?.message||we?.message||"Failed to send OTP. Please try again.";he(gt),G1("resend"),z1(0)}},en=async()=>{if(!navigator.onLine){Ce(!0),R1("Submit Again");return}if(Ce(!1),F1)return;if(K1(!0),!x1){console.error("[Fundly Pay] Payment date is required"),K1(!1);return}const le=x1.toISOString(),we=le.split("T")[0],gt=s||S,Ft={paymentMode:"FUNDLY_PAY",paymentDate:le,paymentType:g,distributorCode:J,...Ne&&{documentId:Ne},salesmanId:z,invoiceCount:w?.length||b?.length||0,loanDrawdownRequestDTO:{businessId:E||M,fiCode:gt,requestedAmount:f,scheduledDate:we,tenure:_[l1]?.tenureValue||"",tenureUnit:_[l1]?.tenureUnit?.replace(/s$/i,"")||"",invoiceIds:g==="INVOICE_COLLECT"?w?.map(ft=>ft.invoiceId)??[]:b??[],sourceSystem:j,paymentType:g}};E&&E.trim()!==""?Ft.chemistBusinessId=E:M&&M.trim()!==""&&(Ft.leadId=M),g==="INVOICE_COLLECT"?Ft.paymentInvoice=w:g==="DIRECT_COLLECT"&&(Ft.invoiceIds=b,Ft.paidAmount=f),(j==="FUNDLY_COLLECT_APP"||j==="FUNDLY_QR_COLLECT_APP"||j==="FUNDLY_QR_WEB"||j==="FUNDLY_TRADE")&&(Ft.loanDrawdownRequestDTO.mobileNumber=F,Ft.loanDrawdownRequestDTO.loanInitiateOtp=Z.join("")),F&&(Ft.payerMobileNumber=F),T1==="TRILLIONLOAN"&&xe();try{const ft=await X3(Ft),Et=ft?.data||ft;Et&&!Et.scheduleDate&&(Et.scheduleDate=we),Et&&et?.lastRepaymentDate&&(Et.dueDate=et.lastRepaymentDate),t&&t(Et)}catch(ft){const Et=ft?.response?.data?.errorMessage||ft?.response?.data?.errorDesc||ft?.response?.data?.message||ft?.message||"Payment failed. Please try again.";oe(Et)}finally{K1(!1)}},E2=(le,we)=>{if(!/^[0-9]?$/.test(le))return;const gt=[...Z];gt[we]=le,w1(gt),le&&we<5&&L1.current[we+1]?.focus()},Jt=(le,we)=>{le.key==="Backspace"&&!Z[we]&&we>0&&L1.current[we-1]?.focus()},Qs=()=>{G1("countdown"),z1(30),Ut()};G.useEffect(()=>{if(H1==="countdown"&&S1>0){const le=setInterval(()=>{z1(we=>we-1)},1e3);return()=>clearInterval(le)}else H1==="countdown"&&S1===0&&(G1("resend"),Ut())},[S1,H1]);const Gt=mi.useMemo(()=>{if($&&se)return!0;const le=l1!==-1,we=x1!==null,gt=f1!==-1||!W?.subLimits,Ft=$?nt:!0;if(j==="FUNDLY_COLLECT_APP"||j==="FUNDLY_QR_COLLECT_APP"||j==="FUNDLY_QR_WEB"||j==="FUNDLY_TRADE"){const ft=Z.every(Et=>Et!=="");return!(le&&ft&&we&>&&Ft)}return!(le&&we&>&&Ft)},[l1,f1,Z,j,x1,W,nt,se]),[et,vn]=G.useState(null),[Nn,Bt]=G.useState(!1),tn=async()=>{if(l1===-1)return;const le=_[l1],we=s||S||"",gt=o||H||"BULLET",Ft=c||"SUPPLIER";Bt(!0);try{const ft=await Hm({loanAmount:Number(f),businessId:E||"",openedOnDate:Ve(x1||u1),productType:"INSTACASH",tenureMagnitude:le.tenureValue,tenureUnit:le.tenureUnit,fiCode:we,repaymentOption:gt,disbursementAccount:Ft});vn(ft)}catch(ft){console.error("Error fetching EMI:",ft),vn(null)}finally{Bt(!1)}};return G.useEffect(()=>{let le;return A&&l1!==-1&&f1!==-1&&(le=window.setTimeout(()=>{tn()},1e3)),()=>{clearTimeout(le)}},[l1,f1,x1]),G.useEffect(()=>{if(A){if(r1(0),$)P1(new Date),Je(!1);else{const le=new Date;le.setDate(le.getDate()+1),P1(le)}$1()}},[A,$1]),G.useEffect(()=>{if(!A||T1!=="TRILLIONLOAN")return;const le=window.setTimeout(()=>{Me()},400);return()=>clearTimeout(le)},[l1,x1,Me]),G.useEffect(()=>{const le=()=>{A&&l1!==-1&&(tn(),Me())};return window.addEventListener("online",le),()=>{window.removeEventListener("online",le)}},[A,l1,Me]),u.jsxs(wi,{open:A,onClose:B1,children:[u.jsxs("div",{style:{fontFamily:"Poppins"},className:"fp:w-full fp:px-4 fp:pt-6 fp:mb-12 ",children:[u.jsx("div",{className:"fp:w-full fp:flex fp:items-center fp:justify-end",children:u.jsx("img",{src:de.closingCross,className:"fp:w-4 fp:h-4 fp:cursor-pointer",onClick:()=>N1(!0)})}),ge&&u.jsxs("div",{className:"fp:w-full fp:bg-red-50 fp:border fp:border-red-200 fp:rounded-xl fp:p-3 fp:flex fp:items-start fp:space-x-2 fp:mt-4",children:[u.jsx("svg",{className:"fp:w-5 fp:h-5 fp:text-red-500 fp:flex-shrink-0 fp:mt-0.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),u.jsxs("div",{className:"fp:flex-1",children:[u.jsx("p",{className:"fp:text-[14px] fp:text-red-700 fp:font-medium",children:"Payment Failed"}),u.jsx("p",{className:"fp:text-[12px] fp:text-red-600 fp:mt-1",children:ge})]}),u.jsx("button",{onClick:()=>oe(""),className:"fp:text-red-400 fp:hover:text-red-600",children:u.jsx("svg",{className:"fp:w-4 fp:h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M6 18L18 6M6 6l12 12"})})})]}),u.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:mt-4 fp:space-y-4",children:[u.jsx("div",{children:u.jsx(jo,{value:x1,onChange:le=>P1(le),minDate:$?void 0:u1,label:"Select Payment Date",fullWidth:!0,disabled:$})}),u.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:space-y-2 ",children:[u.jsx("span",{className:"fp:text-[15px] fp:font-medium fp:text-[#222222]",children:"Tenure"}),u.jsx("div",{className:"fp:w-full fp:flex fp:space-x-4 ",children:_&&_.length>0?_.map((le,we)=>u.jsxs("button",{type:"button",className:`fp:py-1 fp:px-6 fp:border-[] fp:rounded-2xl fp:text-[14px] fp:font-medium fp:focus:outline-none fp:transition-colors fp:duration-150 ${l1===we?"fp:border-[#16558B] fp:bg-[#E6F0FA] fp:text-[#16558B]":"fp:border-[#D0D0D0] fp:text-gray-700 fp:bg-white"}`,onClick:()=>{r1(we)},children:[le.tenureValue," ",le.tenureUnit]},we)):u.jsx("span",{className:"fp:py-1 fp:px-6 fp:border-2 fp:rounded-2xl fp:text-[14px] fp:border-[#D0D0D0] fp:text-gray-700 fp:font-medium",children:"No tenure available"})})]}),!$&&u.jsxs("span",{className:"fp:text-[12px] fp:font-medium fp:text-green-600 fp:text-wrap",children:["₹",dt(f)," will be processed via Fundly Credit — a loan will be set up in retailer's account."]}),u.jsxs("div",{className:"fp:text-[12px] fp:w-full fp:border fp:p-4 fp:space-y-3 fp:rounded-2xl fp:flex fp:flex-col fp:border-[#E8EEF3] ",children:[u.jsxs("div",{className:"fp:flex fp:justify-between",children:[u.jsx("label",{className:"fp:text-gray-700",children:"Due date"}),u.jsx("label",{className:"fp:font-medium",children:et?.lastRepaymentDate?ta(et.lastRepaymentDate):"—"})]}),u.jsxs("div",{className:"fp:flex fp:justify-between",children:[u.jsx("label",{className:"fp:text-gray-700",children:"ROI (Annualised)"}),u.jsx("label",{className:"fp:font-medium",children:et?.normalInterestRate!=null?`${et.normalInterestRate}%`:"—"})]}),u.jsxs("div",{className:"fp:flex fp:justify-between",children:[u.jsx("label",{className:"fp:text-gray-700",children:"Interest/₹ 10,000/day"}),u.jsx("label",{className:"fp:font-medium",children:et?.interestPerDay!=null?`₹${et.interestPerDay}`:"—"})]}),u.jsxs("div",{className:"fp:flex fp:justify-between",children:[u.jsx("label",{className:"fp:text-gray-700",children:"Penal Charges"}),u.jsx("label",{className:"fp:font-medium",children:et?.penalInterestRate!=null?`${et.penalInterestRate}% p.a`:"—"})]}),u.jsxs("div",{className:"fp:flex fp:justify-between",children:[u.jsx("label",{className:"fp:text-gray-700",children:"Processing Fee"}),u.jsx("label",{className:"fp:font-medium",children:et?.processingFeeExclGst!=null?`₹${Number(et.processingFeeExclGst).toLocaleString("en-IN")}`:"—"})]}),u.jsxs("div",{className:"fp:flex fp:justify-between",children:[u.jsx("label",{className:"fp:text-gray-700",children:"APR"}),u.jsx("label",{className:"fp:font-medium",children:et?.apr!=null?`${et.apr}%`:"—"})]}),u.jsxs("div",{className:"fp:flex fp:justify-between",children:[u.jsx("label",{className:"fp:text-gray-700",children:"Net Disbursed Amount"}),u.jsx("label",{className:"fp:font-medium",children:et?.creditedAmount!=null?`₹${Number(et.creditedAmount).toLocaleString("en-IN")}`:"—"})]})]}),(j==="FUNDLY_COLLECT_APP"||j==="FUNDLY_QR_COLLECT_APP"||j==="FUNDLY_QR_WEB"||j==="FUNDLY_TRADE")&&u.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:space-y-4 fp:border-2 fp:border-[#E8EEF3] fp:mt-2 fp:rounded-2xl fp:p-3",children:[u.jsx("label",{className:"fp:font-medium fp:text-[15px]",children:"Retailer Verification"}),u.jsxs("div",{className:"fp:w-full fp:flex fp:space-x-2 fp:justify-between",children:[u.jsx("div",{className:"fp:flex fp:border-2 fp:rounded-lg fp:px-1 fp:space-x-2 ",children:Z.map((le,we)=>u.jsx("input",{type:"text",value:le,maxLength:1,placeholder:"●",ref:gt=>{L1.current[we]=gt},onChange:gt=>E2(gt.target.value,we),onKeyDown:gt=>Jt(gt,we),className:"fp:w-7 fp:h-8 fp:text-center fp:text-[16px] fp:outline-none"},we))}),u.jsxs("button",{onClick:Qs,disabled:H1==="countdown",className:`fp:text-white fp:text-[12px] fp:px-7 fp:rounded-lg ${H1==="resend"?"fp:bg-gray-500":"fp:bg-[#16558B]"}`,children:[H1==="idle"&&"Get OTP",H1==="countdown"&&`${S1}s`,H1==="resend"&&"Resend"]})]}),ue?u.jsxs("div",{className:"fp:w-full fp:bg-red-50 fp:border fp:border-red-200 fp:rounded-lg fp:p-2 fp:flex fp:items-start fp:space-x-2",children:[u.jsx("svg",{className:"fp:w-4 fp:h-4 fp:text-red-500 fp:flex-shrink-0 fp:mt-0.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),u.jsx("p",{className:"fp:text-[11px] fp:text-red-700",children:ue})]}):u.jsxs("label",{className:"fp:text-[13px] fp:flex fp:text-center fp:items-center fp:text-[#16558B]",children:[u.jsx("img",{src:de.info,className:"fp:w-4 fp:h-4 fp:mr-1"}),H1==="idle"?"OTP will be sent to the retailer for consent.":"An OTP has been sent to the retailer for consent."]})]}),At&&u.jsx("div",{ref:vt,className:"fp:text-[12px] fp:text-gray-600 fp:leading-relaxed fp:select-none",dangerouslySetInnerHTML:{__html:At}}),$&&u.jsxs("label",{className:"fp:flex fp:items-start fp:space-x-2 fp:cursor-pointer",children:[u.jsx("input",{type:"checkbox",checked:nt,onChange:le=>{const we=le.target.checked;Je(we),we&&me()},className:"fp:mt-0.5 fp:w-4 fp:h-4 fp:flex-shrink-0 fp:accent-[#16558B]"}),u.jsxs("span",{className:"fp:text-[12px] fp:text-gray-700",children:["I agree to the loan terms and accept the"," ",u.jsx("span",{className:"fp:text-[#16558B] fp:underline fp:cursor-pointer",onClick:le=>{le.preventDefault(),me()},children:"Key Fact Statement (KFS)"})]})]}),pe&&u.jsx("span",{className:"fp:text-red-500 fp:text-[12px] fp:mt-1",children:"We couldn't process your payment due to a network error. Please retry."}),u.jsx("button",{className:`fp:w-full fp:h-12 fp:mt-4 fp:rounded-lg fp:text-[16px] fp:flex fp:items-center fp:justify-center
|
|
672
|
+
`)){const a=document.createElement("div");a.append(s?document.createTextNode(s):document.createElement("br")),t.append(a)}return e.updateEdited({rect:this.getPDFRect(),popup:this._uiManager.hasCommentManager()||this.hasEditedComment?this.comment:{text:this.#e}}),t}resetAnnotationElement(e){super.resetAnnotationElement(e),e.resetEdited()}}class Be{static PRECISION=1e-4;toSVGPath(){a2("Abstract method `toSVGPath` must be implemented.")}get box(){a2("Abstract getter `box` must be implemented.")}serialize(e,t){a2("Abstract method `serialize` must be implemented.")}static _rescale(e,t,n,s,a,o){o||=new Float32Array(e.length);for(let c=0,d=e.length;c<d;c+=2)o[c]=t+e[c]*s,o[c+1]=n+e[c+1]*a;return o}static _rescaleAndSwap(e,t,n,s,a,o){o||=new Float32Array(e.length);for(let c=0,d=e.length;c<d;c+=2)o[c]=t+e[c+1]*s,o[c+1]=n+e[c]*a;return o}static _translate(e,t,n,s){s||=new Float32Array(e.length);for(let a=0,o=e.length;a<o;a+=2)s[a]=t+e[a],s[a+1]=n+e[a+1];return s}static svgRound(e){return Math.round(e*1e4)}static _normalizePoint(e,t,n,s,a){switch(a){case 90:return[1-t/n,e/s];case 180:return[1-e/n,1-t/s];case 270:return[t/n,1-e/s];default:return[e/n,t/s]}}static _normalizePagePoint(e,t,n){switch(n){case 90:return[1-t,e];case 180:return[1-e,1-t];case 270:return[t,1-e];default:return[e,t]}}static createBezierPoints(e,t,n,s,a,o){return[(e+5*n)/6,(t+5*s)/6,(5*n+a)/6,(5*s+o)/6,(n+a)/2,(s+o)/2]}}class X0{#e;#t=[];#i;#n;#A=[];#s=new Float32Array(18);#r;#a;#l;#o;#d;#u;#h=[];static#g=8;static#f=2;static#c=X0.#g+X0.#f;constructor({x:e,y:t},n,s,a,o,c=0){this.#e=n,this.#u=a*s,this.#n=o,this.#s.set([NaN,NaN,NaN,NaN,e,t],6),this.#i=c,this.#o=X0.#g*s,this.#l=X0.#c*s,this.#d=s,this.#h.push(e,t)}isEmpty(){return isNaN(this.#s[8])}#p(){const e=this.#s.subarray(4,6),t=this.#s.subarray(16,18),[n,s,a,o]=this.#e;return[(this.#r+(e[0]-t[0])/2-n)/a,(this.#a+(e[1]-t[1])/2-s)/o,(this.#r+(t[0]-e[0])/2-n)/a,(this.#a+(t[1]-e[1])/2-s)/o]}add({x:e,y:t}){this.#r=e,this.#a=t;const[n,s,a,o]=this.#e;let[c,d,f,g]=this.#s.subarray(8,12);const w=e-f,b=t-g,E=Math.hypot(w,b);if(E<this.#l)return!1;const M=E-this.#o,S=M/E,j=S*w,F=S*b;let z=c,J=d;c=f,d=g,f+=j,g+=F,this.#h?.push(e,t);const Y=-F/M,H=j/M,W=Y*this.#u,_=H*this.#u;return this.#s.set(this.#s.subarray(2,8),0),this.#s.set([f+W,g+_],4),this.#s.set(this.#s.subarray(14,18),12),this.#s.set([f-W,g-_],16),isNaN(this.#s[6])?(this.#A.length===0&&(this.#s.set([c+W,d+_],2),this.#A.push(NaN,NaN,NaN,NaN,(c+W-n)/a,(d+_-s)/o),this.#s.set([c-W,d-_],14),this.#t.push(NaN,NaN,NaN,NaN,(c-W-n)/a,(d-_-s)/o)),this.#s.set([z,J,c,d,f,g],6),!this.isEmpty()):(this.#s.set([z,J,c,d,f,g],6),Math.abs(Math.atan2(J-d,z-c)-Math.atan2(F,j))<Math.PI/2?([c,d,f,g]=this.#s.subarray(2,6),this.#A.push(NaN,NaN,NaN,NaN,((c+f)/2-n)/a,((d+g)/2-s)/o),[c,d,z,J]=this.#s.subarray(14,18),this.#t.push(NaN,NaN,NaN,NaN,((z+c)/2-n)/a,((J+d)/2-s)/o),!0):([z,J,c,d,f,g]=this.#s.subarray(0,6),this.#A.push(((z+5*c)/6-n)/a,((J+5*d)/6-s)/o,((5*c+f)/6-n)/a,((5*d+g)/6-s)/o,((c+f)/2-n)/a,((d+g)/2-s)/o),[f,g,c,d,z,J]=this.#s.subarray(12,18),this.#t.push(((z+5*c)/6-n)/a,((J+5*d)/6-s)/o,((5*c+f)/6-n)/a,((5*d+g)/6-s)/o,((c+f)/2-n)/a,((d+g)/2-s)/o),!0))}toSVGPath(){if(this.isEmpty())return"";const e=this.#A,t=this.#t;if(isNaN(this.#s[6])&&!this.isEmpty())return this.#m();const n=[];n.push(`M${e[4]} ${e[5]}`);for(let s=6;s<e.length;s+=6)isNaN(e[s])?n.push(`L${e[s+4]} ${e[s+5]}`):n.push(`C${e[s]} ${e[s+1]} ${e[s+2]} ${e[s+3]} ${e[s+4]} ${e[s+5]}`);this.#w(n);for(let s=t.length-6;s>=6;s-=6)isNaN(t[s])?n.push(`L${t[s+4]} ${t[s+5]}`):n.push(`C${t[s]} ${t[s+1]} ${t[s+2]} ${t[s+3]} ${t[s+4]} ${t[s+5]}`);return this.#v(n),n.join(" ")}#m(){const[e,t,n,s]=this.#e,[a,o,c,d]=this.#p();return`M${(this.#s[2]-e)/n} ${(this.#s[3]-t)/s} L${(this.#s[4]-e)/n} ${(this.#s[5]-t)/s} L${a} ${o} L${c} ${d} L${(this.#s[16]-e)/n} ${(this.#s[17]-t)/s} L${(this.#s[14]-e)/n} ${(this.#s[15]-t)/s} Z`}#v(e){const t=this.#t;e.push(`L${t[4]} ${t[5]} Z`)}#w(e){const[t,n,s,a]=this.#e,o=this.#s.subarray(4,6),c=this.#s.subarray(16,18),[d,f,g,w]=this.#p();e.push(`L${(o[0]-t)/s} ${(o[1]-n)/a} L${d} ${f} L${g} ${w} L${(c[0]-t)/s} ${(c[1]-n)/a}`)}newFreeDrawOutline(e,t,n,s,a,o){return new Hp(e,t,n,s,a,o)}getOutlines(){const e=this.#A,t=this.#t,n=this.#s,[s,a,o,c]=this.#e,d=new Float32Array((this.#h?.length??0)+2);for(let w=0,b=d.length-2;w<b;w+=2)d[w]=(this.#h[w]-s)/o,d[w+1]=(this.#h[w+1]-a)/c;if(d[d.length-2]=(this.#r-s)/o,d[d.length-1]=(this.#a-a)/c,isNaN(n[6])&&!this.isEmpty())return this.#I(d);const f=new Float32Array(this.#A.length+24+this.#t.length);let g=e.length;for(let w=0;w<g;w+=2){if(isNaN(e[w])){f[w]=f[w+1]=NaN;continue}f[w]=e[w],f[w+1]=e[w+1]}g=this.#C(f,g);for(let w=t.length-6;w>=6;w-=6)for(let b=0;b<6;b+=2){if(isNaN(t[w+b])){f[g]=f[g+1]=NaN,g+=2;continue}f[g]=t[w+b],f[g+1]=t[w+b+1],g+=2}return this.#B(f,g),this.newFreeDrawOutline(f,d,this.#e,this.#d,this.#i,this.#n)}#I(e){const t=this.#s,[n,s,a,o]=this.#e,[c,d,f,g]=this.#p(),w=new Float32Array(36);return w.set([NaN,NaN,NaN,NaN,(t[2]-n)/a,(t[3]-s)/o,NaN,NaN,NaN,NaN,(t[4]-n)/a,(t[5]-s)/o,NaN,NaN,NaN,NaN,c,d,NaN,NaN,NaN,NaN,f,g,NaN,NaN,NaN,NaN,(t[16]-n)/a,(t[17]-s)/o,NaN,NaN,NaN,NaN,(t[14]-n)/a,(t[15]-s)/o],0),this.newFreeDrawOutline(w,e,this.#e,this.#d,this.#i,this.#n)}#B(e,t){const n=this.#t;return e.set([NaN,NaN,NaN,NaN,n[4],n[5]],t),t+=6}#C(e,t){const n=this.#s.subarray(4,6),s=this.#s.subarray(16,18),[a,o,c,d]=this.#e,[f,g,w,b]=this.#p();return e.set([NaN,NaN,NaN,NaN,(n[0]-a)/c,(n[1]-o)/d,NaN,NaN,NaN,NaN,f,g,NaN,NaN,NaN,NaN,w,b,NaN,NaN,NaN,NaN,(s[0]-a)/c,(s[1]-o)/d],t),t+=24}}class Hp extends Be{#e;#t=new Float32Array(4);#i;#n;#A;#s;#r;constructor(e,t,n,s,a,o){super(),this.#r=e,this.#A=t,this.#e=n,this.#s=s,this.#i=a,this.#n=o,this.firstPoint=[NaN,NaN],this.lastPoint=[NaN,NaN],this.#a(o);const[c,d,f,g]=this.#t;for(let w=0,b=e.length;w<b;w+=2)e[w]=(e[w]-c)/f,e[w+1]=(e[w+1]-d)/g;for(let w=0,b=t.length;w<b;w+=2)t[w]=(t[w]-c)/f,t[w+1]=(t[w+1]-d)/g}toSVGPath(){const e=[`M${this.#r[4]} ${this.#r[5]}`];for(let t=6,n=this.#r.length;t<n;t+=6){if(isNaN(this.#r[t])){e.push(`L${this.#r[t+4]} ${this.#r[t+5]}`);continue}e.push(`C${this.#r[t]} ${this.#r[t+1]} ${this.#r[t+2]} ${this.#r[t+3]} ${this.#r[t+4]} ${this.#r[t+5]}`)}return e.push("Z"),e.join(" ")}serialize([e,t,n,s],a){const o=n-e,c=s-t;let d,f;switch(a){case 0:d=Be._rescale(this.#r,e,s,o,-c),f=Be._rescale(this.#A,e,s,o,-c);break;case 90:d=Be._rescaleAndSwap(this.#r,e,t,o,c),f=Be._rescaleAndSwap(this.#A,e,t,o,c);break;case 180:d=Be._rescale(this.#r,n,t,-o,c),f=Be._rescale(this.#A,n,t,-o,c);break;case 270:d=Be._rescaleAndSwap(this.#r,n,s,-o,-c),f=Be._rescaleAndSwap(this.#A,n,s,-o,-c);break}return{outline:Array.from(d),points:[Array.from(f)]}}#a(e){const t=this.#r;let n=t[4],s=t[5];const a=[n,s,n,s];let o=n,c=s,d=n,f=s;const g=e?Math.max:Math.min,w=new Float32Array(4);for(let E=6,M=t.length;E<M;E+=6){const S=t[E+4],j=t[E+5];isNaN(t[E])?(be.pointBoundingBox(S,j,a),c>j?(o=S,c=j):c===j&&(o=g(o,S)),f<j?(d=S,f=j):f===j&&(d=g(d,S))):(w[0]=w[1]=1/0,w[2]=w[3]=-1/0,be.bezierBoundingBox(n,s,...t.slice(E,E+6),w),be.rectBoundingBox(w[0],w[1],w[2],w[3],a),c>w[1]?(o=w[0],c=w[1]):c===w[1]&&(o=g(o,w[0])),f<w[3]?(d=w[2],f=w[3]):f===w[3]&&(d=g(d,w[2]))),n=S,s=j}const b=this.#t;b[0]=a[0]-this.#i,b[1]=a[1]-this.#i,b[2]=a[2]-a[0]+2*this.#i,b[3]=a[3]-a[1]+2*this.#i,this.firstPoint=[o,c],this.lastPoint=[d,f]}get box(){return this.#t}newOutliner(e,t,n,s,a,o=0){return new X0(e,t,n,s,a,o)}getNewOutline(e,t){const[n,s,a,o]=this.#t,[c,d,f,g]=this.#e,w=a*f,b=o*g,E=n*f+c,M=s*g+d,S=this.newOutliner({x:this.#A[0]*w+E,y:this.#A[1]*b+M},this.#e,this.#s,e,this.#n,t??this.#i);for(let j=2;j<this.#A.length;j+=2)S.add({x:this.#A[j]*w+E,y:this.#A[j+1]*b+M});return S.getOutlines()}}class Rh{#e;#t;#i;#n=[];#A=[];constructor(e,t=0,n=0,s=!0){const a=[1/0,1/0,-1/0,-1/0],o=10**-4;for(const{x:S,y:j,width:F,height:z}of e){const J=Math.floor((S-t)/o)*o,Y=Math.ceil((S+F+t)/o)*o,H=Math.floor((j-t)/o)*o,W=Math.ceil((j+z+t)/o)*o,_=[J,H,W,!0],l1=[Y,H,W,!1];this.#n.push(_,l1),be.rectBoundingBox(J,H,Y,W,a)}const c=a[2]-a[0]+2*n,d=a[3]-a[1]+2*n,f=a[0]-n,g=a[1]-n;let w=s?-1/0:1/0,b=1/0;const E=this.#n.at(s?-1:-2),M=[E[0],E[2]];for(const S of this.#n){const[j,F,z,J]=S;!J&&s?F<b?(b=F,w=j):F===b&&(w=Math.max(w,j)):J&&!s&&(F<b?(b=F,w=j):F===b&&(w=Math.min(w,j))),S[0]=(j-f)/c,S[1]=(F-g)/d,S[2]=(z-g)/d}this.#e=new Float32Array([f,g,c,d]),this.#t=[w,b],this.#i=M}getOutlines(){this.#n.sort((t,n)=>t[0]-n[0]||t[1]-n[1]||t[2]-n[2]);const e=[];for(const t of this.#n)t[3]?(e.push(...this.#o(t)),this.#a(t)):(this.#l(t),e.push(...this.#o(t)));return this.#s(e)}#s(e){const t=[],n=new Set;for(const o of e){const[c,d,f]=o;t.push([c,d,o],[c,f,o])}t.sort((o,c)=>o[1]-c[1]||o[0]-c[0]);for(let o=0,c=t.length;o<c;o+=2){const d=t[o][2],f=t[o+1][2];d.push(f),f.push(d),n.add(d),n.add(f)}const s=[];let a;for(;n.size>0;){const o=n.values().next().value;let[c,d,f,g,w]=o;n.delete(o);let b=c,E=d;for(a=[c,f],s.push(a);;){let M;if(n.has(g))M=g;else if(n.has(w))M=w;else break;n.delete(M),[c,d,f,g,w]=M,b!==c&&(a.push(b,E,c,E===d?d:f),b=c),E=E===d?f:d}a.push(b,E)}return new nv(s,this.#e,this.#t,this.#i)}#r(e){const t=this.#A;let n=0,s=t.length-1;for(;n<=s;){const a=n+s>>1,o=t[a][0];if(o===e)return a;o<e?n=a+1:s=a-1}return s+1}#a([,e,t]){const n=this.#r(e);this.#A.splice(n,0,[e,t])}#l([,e,t]){const n=this.#r(e);for(let s=n;s<this.#A.length;s++){const[a,o]=this.#A[s];if(a!==e)break;if(a===e&&o===t){this.#A.splice(s,1);return}}for(let s=n-1;s>=0;s--){const[a,o]=this.#A[s];if(a!==e)break;if(a===e&&o===t){this.#A.splice(s,1);return}}}#o(e){const[t,n,s]=e,a=[[t,n,s]],o=this.#r(s);for(let c=0;c<o;c++){const[d,f]=this.#A[c];for(let g=0,w=a.length;g<w;g++){const[,b,E]=a[g];if(!(f<=b||E<=d)){if(b>=d){if(E>f)a[g][1]=f;else{if(w===1)return[];a.splice(g,1),g--,w--}continue}a[g][2]=d,E>f&&a.push([t,f,E])}}}return a}}class nv extends Be{#e;#t;constructor(e,t,n,s){super(),this.#t=e,this.#e=t,this.firstPoint=n,this.lastPoint=s}toSVGPath(){const e=[];for(const t of this.#t){let[n,s]=t;e.push(`M${n} ${s}`);for(let a=2;a<t.length;a+=2){const o=t[a],c=t[a+1];o===n?(e.push(`V${c}`),s=c):c===s&&(e.push(`H${o}`),n=o)}e.push("Z")}return e.join(" ")}serialize([e,t,n,s],a){const o=[],c=n-e,d=s-t;for(const f of this.#t){const g=new Array(f.length);for(let w=0;w<f.length;w+=2)g[w]=e+f[w]*c,g[w+1]=s-f[w+1]*d;o.push(g)}return o}get box(){return this.#e}get classNamesForOutlining(){return["highlightOutline"]}}class Hh extends X0{newFreeDrawOutline(e,t,n,s,a,o){return new iv(e,t,n,s,a,o)}}class iv extends Hp{newOutliner(e,t,n,s,a,o=0){return new Hh(e,t,n,s,a,o)}}class z2 extends Ue{#e=null;#t=0;#i;#n=null;#A=null;#s=null;#r=null;#a=0;#l=null;#o=null;#d=null;#u=!1;#h=null;#g=null;#f=null;#c="";#p;#m="";static _defaultColor=null;static _defaultOpacity=1;static _defaultThickness=12;static _type="highlight";static _editorType=st.HIGHLIGHT;static _freeHighlightId=-1;static _freeHighlight=null;static _freeHighlightClipId="";static get _keyboardManager(){const e=z2.prototype;return ut(this,"_keyboardManager",new Ko([[["ArrowLeft","mac+ArrowLeft"],e._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],e._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],e._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],e._moveCaret,{args:[3]}]]))}constructor(e){super({...e,name:"highlightEditor"}),this.color=e.color||z2._defaultColor,this.#p=e.thickness||z2._defaultThickness,this.opacity=e.opacity||z2._defaultOpacity,this.#i=e.boxes||null,this.#m=e.methodOfCreation||"",this.#c=e.text||"",this._isDraggable=!1,this.defaultL10nId="pdfjs-editor-highlight-editor",e.highlightId>-1?(this.#u=!0,this.#w(e),this.#b()):this.#i&&(this.#e=e.anchorNode,this.#t=e.anchorOffset,this.#r=e.focusNode,this.#a=e.focusOffset,this.#v(),this.#b(),this.rotate(this.rotation)),this.annotationElementId||this._uiManager.a11yAlert("pdfjs-editor-highlight-added-alert")}get telemetryInitialData(){return{action:"added",type:this.#u?"free_highlight":"highlight",color:this._uiManager.getNonHCMColorName(this.color),thickness:this.#p,methodOfCreation:this.#m}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.getNonHCMColorName(this.color)}}static computeTelemetryFinalData(e){return{numberOfColors:e.get("color").size}}#v(){const e=new Rh(this.#i,.001);this.#o=e.getOutlines(),[this.x,this.y,this.width,this.height]=this.#o.box;const t=new Rh(this.#i,.0025,.001,this._uiManager.direction==="ltr");this.#s=t.getOutlines();const{firstPoint:n}=this.#o;this.#h=[(n[0]-this.x)/this.width,(n[1]-this.y)/this.height];const{lastPoint:s}=this.#s;this.#g=[(s[0]-this.x)/this.width,(s[1]-this.y)/this.height]}#w({highlightOutlines:e,highlightId:t,clipPathId:n}){this.#o=e;const s=1.5;if(this.#s=e.getNewOutline(this.#p/2+s,.0025),t>=0)this.#d=t,this.#n=n,this.parent.drawLayer.finalizeDraw(t,{bbox:e.box,path:{d:e.toSVGPath()}}),this.#f=this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:this.#s.box,path:{d:this.#s.toSVGPath()}},!0);else if(this.parent){const w=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(this.#d,{bbox:z2.#x(this.#o.box,(w-this.rotation+360)%360),path:{d:e.toSVGPath()}}),this.parent.drawLayer.updateProperties(this.#f,{bbox:z2.#x(this.#s.box,w),path:{d:this.#s.toSVGPath()}})}const[a,o,c,d]=e.box;switch(this.rotation){case 0:this.x=a,this.y=o,this.width=c,this.height=d;break;case 90:{const[w,b]=this.parentDimensions;this.x=o,this.y=1-a,this.width=c*b/w,this.height=d*w/b;break}case 180:this.x=1-a,this.y=1-o,this.width=c,this.height=d;break;case 270:{const[w,b]=this.parentDimensions;this.x=1-o,this.y=a,this.width=c*b/w,this.height=d*w/b;break}}const{firstPoint:f}=e;this.#h=[(f[0]-a)/c,(f[1]-o)/d];const{lastPoint:g}=this.#s;this.#g=[(g[0]-a)/c,(g[1]-o)/d]}static initialize(e,t){Ue.initialize(e,t),z2._defaultColor||=t.highlightColors?.values().next().value||"#fff066"}static updateDefaultParams(e,t){switch(e){case yt.HIGHLIGHT_COLOR:z2._defaultColor=t;break;case yt.HIGHLIGHT_THICKNESS:z2._defaultThickness=t;break}}translateInPage(e,t){}get toolbarPosition(){return this.#g}get commentButtonPosition(){return this.#h}updateParams(e,t){switch(e){case yt.HIGHLIGHT_COLOR:this.#I(t);break;case yt.HIGHLIGHT_THICKNESS:this.#B(t);break}}static get defaultPropertiesToUpdate(){return[[yt.HIGHLIGHT_COLOR,z2._defaultColor],[yt.HIGHLIGHT_THICKNESS,z2._defaultThickness]]}get propertiesToUpdate(){return[[yt.HIGHLIGHT_COLOR,this.color||z2._defaultColor],[yt.HIGHLIGHT_THICKNESS,this.#p||z2._defaultThickness],[yt.HIGHLIGHT_FREE,this.#u]]}onUpdatedColor(){this.parent?.drawLayer.updateProperties(this.#d,{root:{fill:this.color,"fill-opacity":this.opacity}}),this.#A?.updateColor(this.color),super.onUpdatedColor()}#I(e){const t=(a,o)=>{this.color=a,this.opacity=o,this.onUpdatedColor()},n=this.color,s=this.opacity;this.addCommands({cmd:t.bind(this,e,z2._defaultOpacity),undo:t.bind(this,n,s),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:yt.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.getNonHCMColorName(e)},!0)}#B(e){const t=this.#p,n=s=>{this.#p=s,this.#C(s)};this.addCommands({cmd:n.bind(this,e),undo:n.bind(this,t),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:yt.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)}get toolbarButtons(){return this._uiManager.highlightColors?[["colorPicker",this.#A=new zi({editor:this})]]:super.toolbarButtons}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(this.#L())}getBaseTranslation(){return[0,0]}getRect(e,t){return super.getRect(e,t,this.#L())}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),e&&this.div.focus()}remove(){this.#S(),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.#b(),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){let t=!1;this.parent&&!e?this.#S():e&&(this.#b(e),t=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(e),this.show(this._isVisible),t&&this.select()}#C(e){this.#u&&(this.#w({highlightOutlines:this.#o.getNewOutline(e/2)}),this.fixAndSetPosition(),this.setDims(this.width,this.height))}#S(){this.#d===null||!this.parent||(this.parent.drawLayer.remove(this.#d),this.#d=null,this.parent.drawLayer.remove(this.#f),this.#f=null)}#b(e=this.parent){this.#d===null&&({id:this.#d,clipPathId:this.#n}=e.drawLayer.draw({bbox:this.#o.box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":this.opacity},rootClass:{highlight:!0,free:this.#u},path:{d:this.#o.toSVGPath()}},!1,!0),this.#f=e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:this.#u},bbox:this.#s.box,path:{d:this.#s.toSVGPath()}},this.#u),this.#l&&(this.#l.style.clipPath=this.#n))}static#x([e,t,n,s],a){switch(a){case 90:return[1-t-s,e,s,n];case 180:return[1-e-n,1-t-s,n,s];case 270:return[t,1-e-n,s,n]}return[e,t,n,s]}rotate(e){const{drawLayer:t}=this.parent;let n;this.#u?(e=(e-this.rotation+360)%360,n=z2.#x(this.#o.box,e)):n=z2.#x([this.x,this.y,this.width,this.height],e),t.updateProperties(this.#d,{bbox:n,root:{"data-main-rotation":e}}),t.updateProperties(this.#f,{bbox:z2.#x(this.#s.box,e),root:{"data-main-rotation":e}})}render(){if(this.div)return this.div;const e=super.render();this.#c&&(e.setAttribute("aria-label",this.#c),e.setAttribute("role","mark")),this.#u?e.classList.add("free"):this.div.addEventListener("keydown",this.#D.bind(this),{signal:this._uiManager._signal});const t=this.#l=document.createElement("div");return e.append(t),t.setAttribute("aria-hidden","true"),t.className="internal",t.style.clipPath=this.#n,this.setDims(this.width,this.height),$6(this,this.#l,["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#f,{rootClass:{hovered:!0}})}pointerleave(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#f,{rootClass:{hovered:!1}})}#D(e){z2._keyboardManager.exec(this,e)}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:this.#M(!0);break;case 1:case 3:this.#M(!1);break}}#M(e){if(!this.#e)return;const t=window.getSelection();e?t.setPosition(this.#e,this.#t):t.setPosition(this.#r,this.#a)}select(){super.select(),this.#f&&this.parent?.drawLayer.updateProperties(this.#f,{rootClass:{hovered:!1,selected:!0}})}unselect(){super.unselect(),this.#f&&(this.parent?.drawLayer.updateProperties(this.#f,{rootClass:{selected:!1}}),this.#u||this.#M(!1))}get _mustFixPosition(){return!this.#u}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.updateProperties(this.#d,{rootClass:{hidden:!e}}),this.parent.drawLayer.updateProperties(this.#f,{rootClass:{hidden:!e}}))}#L(){return this.#u?this.rotation:0}#O(){if(this.#u)return null;const[e,t]=this.pageDimensions,[n,s]=this.pageTranslation,a=this.#i,o=new Float32Array(a.length*8);let c=0;for(const{x:d,y:f,width:g,height:w}of a){const b=d*e+n,E=(1-f)*t+s;o[c]=o[c+4]=b,o[c+1]=o[c+3]=E,o[c+2]=o[c+6]=b+g*e,o[c+5]=o[c+7]=E-w*t,c+=8}return o}#N(e){return this.#o.serialize(e,this.#L())}static startHighlighting(e,t,{target:n,x:s,y:a}){const{x:o,y:c,width:d,height:f}=n.getBoundingClientRect(),g=new AbortController,w=e.combinedSignal(g),b=E=>{g.abort(),this.#k(e,E)};window.addEventListener("blur",b,{signal:w}),window.addEventListener("pointerup",b,{signal:w}),window.addEventListener("pointerdown",B2,{capture:!0,passive:!1,signal:w}),window.addEventListener("contextmenu",Ri,{signal:w}),n.addEventListener("pointermove",this.#j.bind(this,e),{signal:w}),this._freeHighlight=new Hh({x:s,y:a},[o,c,d,f],e.scale,this._defaultThickness/2,t,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.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#j(e,t){this._freeHighlight.add(t)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})}static#k(e,t){this._freeHighlight.isEmpty()?e.drawLayer.remove(this._freeHighlightId):e.createAndAddNewEditor(t,!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(e,t,n){let s=null;if(e instanceof Pp){const{data:{quadPoints:M,rect:S,rotation:j,id:F,color:z,opacity:J,popupRef:Y,richText:H,contentsObj:W,creationDate:_,modificationDate:l1},parent:{page:{pageNumber:r1}}}=e;s=e={annotationType:st.HIGHLIGHT,color:Array.from(z),opacity:J,quadPoints:M,boxes:null,pageIndex:r1-1,rect:S.slice(0),rotation:j,annotationElementId:F,id:F,deleted:!1,popupRef:Y,richText:H,comment:W?.str||null,creationDate:_,modificationDate:l1}}else if(e instanceof kh){const{data:{inkLists:M,rect:S,rotation:j,id:F,color:z,borderStyle:{rawWidth:J},popupRef:Y,richText:H,contentsObj:W,creationDate:_,modificationDate:l1},parent:{page:{pageNumber:r1}}}=e;s=e={annotationType:st.HIGHLIGHT,color:Array.from(z),thickness:J,inkLists:M,boxes:null,pageIndex:r1-1,rect:S.slice(0),rotation:j,annotationElementId:F,id:F,deleted:!1,popupRef:Y,richText:H,comment:W?.str||null,creationDate:_,modificationDate:l1}}const{color:a,quadPoints:o,inkLists:c,opacity:d}=e,f=await super.deserialize(e,t,n);f.color=be.makeHexColor(...a),f.opacity=d||1,c&&(f.#p=e.thickness),f._initialData=s,e.comment&&f.setCommentData(e);const[g,w]=f.pageDimensions,[b,E]=f.pageTranslation;if(o){const M=f.#i=[];for(let S=0;S<o.length;S+=8)M.push({x:(o[S]-b)/g,y:1-(o[S+1]-E)/w,width:(o[S+2]-o[S])/g,height:(o[S+1]-o[S+5])/w});f.#v(),f.#b(),f.rotate(f.rotation)}else if(c){f.#u=!0;const M=c[0],S={x:M[0]-b,y:w-(M[1]-E)},j=new Hh(S,[0,0,g,w],1,f.#p/2,!0,.001);for(let J=0,Y=M.length;J<Y;J+=2)S.x=M[J]-b,S.y=w-(M[J+1]-E),j.add(S);const{id:F,clipPathId:z}=t.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:f.color,"fill-opacity":f._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:j.toSVGPath()}},!0,!0);f.#w({highlightOutlines:j.getOutlines(),highlightId:F,clipPathId:z}),f.#b(),f.rotate(f.parentRotation)}return f}serialize(e=!1){if(this.isEmpty()||e)return null;if(this.deleted)return this.serializeDeleted();const t=Ue._colorManager.convert(this._uiManager.getNonHCMColor(this.color)),n=super.serialize(e);return Object.assign(n,{color:t,opacity:this.opacity,thickness:this.#p,quadPoints:this.#O(),outlines:this.#N(n.rect)}),this.addComment(n),this.annotationElementId&&!this.#Q(n)?null:(n.id=this.annotationElementId,n)}#Q(e){const{color:t}=this._initialData;return this.hasEditedComment||e.color.some((n,s)=>n!==t[s])}renderAnnotationElement(e){return this.deleted?(e.hide(),null):(e.updateEdited({rect:this.getPDFRect(),popup:this.comment}),null)}static canCreateNewEmptyEditor(){return!1}}class zp{#e=Object.create(null);updateProperty(e,t){this[e]=t,this.updateSVGProperty(e,t)}updateProperties(e){if(e)for(const[t,n]of Object.entries(e))t.startsWith("_")||this.updateProperty(t,n)}updateSVGProperty(e,t){this.#e[e]=t}toSVGProperties(){const e=this.#e;return this.#e=Object.create(null),{root:e}}reset(){this.#e=Object.create(null)}updateAll(e=this){this.updateProperties(e)}clone(){a2("Not implemented")}}class He extends Ue{#e=null;#t;_colorPicker=null;_drawId=null;static _currentDrawId=-1;static _currentParent=null;static#i=null;static#n=null;static#A=null;static#s=NaN;static#r=null;static#a=null;static#l=NaN;static _INNER_MARGIN=3;constructor(e){super(e),this.#t=e.mustBeCommitted||!1,this._addOutlines(e)}onUpdatedColor(){this._colorPicker?.update(this.color),super.onUpdatedColor()}_addOutlines(e){e.drawOutlines&&(this.#o(e),this.#h())}#o({drawOutlines:e,drawId:t,drawingOptions:n}){this.#e=e,this._drawingOptions||=n,this.annotationElementId||this._uiManager.a11yAlert(`pdfjs-editor-${this.editorType}-added-alert`),t>=0?(this._drawId=t,this.parent.drawLayer.finalizeDraw(t,e.defaultProperties)):this._drawId=this.#d(e,this.parent),this.#c(e.box)}#d(e,t){const{id:n}=t.drawLayer.draw(He._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return n}static _mergeSVGProperties(e,t){const n=new Set(Object.keys(e));for(const[s,a]of Object.entries(t))n.has(s)?Object.assign(e[s],a):e[s]=a;return e}static getDefaultDrawingOptions(e){a2("Not implemented")}static get typesMap(){a2("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(e,t){const n=this.typesMap.get(e);n&&this._defaultDrawingOptions.updateProperty(n,t),this._currentParent&&(He.#i.updateProperty(n,t),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(e,t){const n=this.constructor.typesMap.get(e);n&&this._updateProperty(e,n,t)}static get defaultPropertiesToUpdate(){const e=[],t=this._defaultDrawingOptions;for(const[n,s]of this.typesMap)e.push([n,t[s]]);return e}get propertiesToUpdate(){const e=[],{_drawingOptions:t}=this;for(const[n,s]of this.constructor.typesMap)e.push([n,t[s]]);return e}_updateProperty(e,t,n){const s=this._drawingOptions,a=s[t],o=c=>{s.updateProperty(t,c);const d=this.#e.updateProperty(t,c);d&&this.#c(d),this.parent?.drawLayer.updateProperties(this._drawId,s.toSVGProperties()),e===this.colorType&&this.onUpdatedColor()};this.addCommands({cmd:o.bind(this,n),undo:o.bind(this,a),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:e,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){this.parent?.drawLayer.updateProperties(this._drawId,He._mergeSVGProperties(this.#e.getPathResizingSVGProperties(this.#f()),{bbox:this.#p()}))}_onResized(){this.parent?.drawLayer.updateProperties(this._drawId,He._mergeSVGProperties(this.#e.getPathResizedSVGProperties(this.#f()),{bbox:this.#p()}))}_onTranslating(e,t){this.parent?.drawLayer.updateProperties(this._drawId,{bbox:this.#p()})}_onTranslated(){this.parent?.drawLayer.updateProperties(this._drawId,He._mergeSVGProperties(this.#e.getPathTranslatedSVGProperties(this.#f(),this.parentDimensions),{bbox:this.#p()}))}_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(e){this.annotationElementId||this.parent.addUndoableEditor(this),this._isDraggable=!0,this.#t&&(this.#t=!1,this.commit(),this.parent.setSelected(this),e&&this.isOnScreen&&this.div.focus())}remove(){this.#u(),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.#h(),this.#c(this.#e.box),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){let t=!1;this.parent&&!e?(this._uiManager.removeShouldRescale(this),this.#u()):e&&(this._uiManager.addShouldRescale(this),this.#h(e),t=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(e),t&&this.select()}#u(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())}#h(e=this.parent){if(!(this._drawId!==null&&this.parent===e)){if(this._drawId!==null){this.parent.drawLayer.updateParent(this._drawId,e.drawLayer);return}this._drawingOptions.updateAll(),this._drawId=this.#d(this.#e,e)}}#g([e,t,n,s]){const{parentDimensions:[a,o],rotation:c}=this;switch(c){case 90:return[t,1-e,n*(o/a),s*(a/o)];case 180:return[1-e,1-t,n,s];case 270:return[1-t,e,n*(o/a),s*(a/o)];default:return[e,t,n,s]}}#f(){const{x:e,y:t,width:n,height:s,parentDimensions:[a,o],rotation:c}=this;switch(c){case 90:return[1-t,e,n*(a/o),s*(o/a)];case 180:return[1-e,1-t,n,s];case 270:return[t,1-e,n*(a/o),s*(o/a)];default:return[e,t,n,s]}}#c(e){[this.x,this.y,this.width,this.height]=this.#g(e),this.div&&(this.fixAndSetPosition(),this.setDims()),this._onResized()}#p(){const{x:e,y:t,width:n,height:s,rotation:a,parentRotation:o,parentDimensions:[c,d]}=this;switch((a*4+o)/90){case 1:return[1-t-s,e,s,n];case 2:return[1-e-n,1-t-s,n,s];case 3:return[t,1-e-n,s,n];case 4:return[e,t-n*(c/d),s*(d/c),n*(c/d)];case 5:return[1-t,e,n*(c/d),s*(d/c)];case 6:return[1-e-s*(d/c),1-t,s*(d/c),n*(c/d)];case 7:return[t-n*(c/d),1-e-s*(d/c),n*(c/d),s*(d/c)];case 8:return[e-n,t-s,n,s];case 9:return[1-t,e-n,s,n];case 10:return[1-e,1-t,n,s];case 11:return[t-s,1-e,s,n];case 12:return[e-s*(d/c),t,s*(d/c),n*(c/d)];case 13:return[1-t-n*(c/d),e-s*(d/c),n*(c/d),s*(d/c)];case 14:return[1-e,1-t-n*(c/d),s*(d/c),n*(c/d)];case 15:return[t,1-e,n*(c/d),s*(d/c)];default:return[e,t,n,s]}}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,He._mergeSVGProperties({bbox:this.#p()},this.#e.updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&this.#c(this.#e.updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;let e,t;this._isCopy&&(e=this.x,t=this.y);const n=super.render();n.classList.add("draw");const s=document.createElement("div");return n.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",this.setDims(),this._uiManager.addShouldRescale(this),this.disableEditing(),this._isCopy&&this._moveAfterPaste(e,t),n}static createDrawerInstance(e,t,n,s,a){a2("Not implemented")}static startDrawing(e,t,n,s){const{target:a,offsetX:o,offsetY:c,pointerId:d,pointerType:f}=s;if(He.#r&&He.#r!==f)return;const{viewport:{rotation:g}}=e,{width:w,height:b}=a.getBoundingClientRect(),E=He.#n=new AbortController,M=e.combinedSignal(E);if(He.#s||=d,He.#r??=f,window.addEventListener("pointerup",S=>{He.#s===S.pointerId?this._endDraw(S):He.#a?.delete(S.pointerId)},{signal:M}),window.addEventListener("pointercancel",S=>{He.#s===S.pointerId?this._currentParent.endDrawingSession():He.#a?.delete(S.pointerId)},{signal:M}),window.addEventListener("pointerdown",S=>{He.#r===S.pointerType&&((He.#a||=new Set).add(S.pointerId),He.#i.isCancellable()&&(He.#i.removeLastElement(),He.#i.isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:M}),window.addEventListener("contextmenu",Ri,{signal:M}),a.addEventListener("pointermove",this._drawMove.bind(this),{signal:M}),a.addEventListener("touchmove",S=>{S.timeStamp===He.#l&&B2(S)},{signal:M}),e.toggleDrawing(),t._editorUndoBar?.hide(),He.#i){e.drawLayer.updateProperties(this._currentDrawId,He.#i.startNew(o,c,w,b,g));return}t.updateUIForDefaultProperties(this),He.#i=this.createDrawerInstance(o,c,w,b,g),He.#A=this.getDefaultDrawingOptions(),this._currentParent=e,{id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties(He.#A.toSVGProperties(),He.#i.defaultSVGProperties),!0,!1)}static _drawMove(e){if(He.#l=-1,!He.#i)return;const{offsetX:t,offsetY:n,pointerId:s}=e;if(He.#s===s){if(He.#a?.size>=1){this._endDraw(e);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,He.#i.add(t,n)),He.#l=e.timeStamp,B2(e)}}static _cleanup(e){e&&(this._currentDrawId=-1,this._currentParent=null,He.#i=null,He.#A=null,He.#r=null,He.#l=NaN),He.#n&&(He.#n.abort(),He.#n=null,He.#s=NaN,He.#a=null)}static _endDraw(e){const t=this._currentParent;if(t){if(t.toggleDrawing(!0),this._cleanup(!1),e?.target===t.div&&t.drawLayer.updateProperties(this._currentDrawId,He.#i.end(e.offsetX,e.offsetY)),this.supportMultipleDrawings){const n=He.#i,s=this._currentDrawId,a=n.getLastElement();t.addCommands({cmd:()=>{t.drawLayer.updateProperties(s,n.setLastElement(a))},undo:()=>{t.drawLayer.updateProperties(s,n.removeLastElement())},mustExec:!1,type:yt.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(e){const t=this._currentParent;if(!t)return null;if(t.toggleDrawing(!0),t.cleanUndoStack(yt.DRAW_STEP),!He.#i.isEmpty()){const{pageDimensions:[n,s],scale:a}=t,o=t.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:He.#i.getOutlines(n*a,s*a,a,this._INNER_MARGIN),drawingOptions:He.#A,mustBeCommitted:!e});return this._cleanup(!0),o}return t.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(e){}static deserializeDraw(e,t,n,s,a,o){a2("Not implemented")}static async deserialize(e,t,n){const{rawDims:{pageWidth:s,pageHeight:a,pageX:o,pageY:c}}=t.viewport,d=this.deserializeDraw(o,c,s,a,this._INNER_MARGIN,e),f=await super.deserialize(e,t,n);return f.createDrawingOptions(e),f.#o({drawOutlines:d}),f.#h(),f.onScaleChanging(),f.rotate(),f}serializeDraw(e){const[t,n]=this.pageTranslation,[s,a]=this.pageDimensions;return this.#e.serialize([t,n,s,a],e)}renderAnnotationElement(e){return e.updateEdited({rect:this.getPDFRect()}),null}static canCreateNewEmptyEditor(){return!1}}class sv{#e=new Float64Array(6);#t;#i;#n;#A;#s;#r="";#a=0;#l=new tl;#o;#d;constructor(e,t,n,s,a,o){this.#o=n,this.#d=s,this.#n=a,this.#A=o,[e,t]=this.#u(e,t);const c=this.#t=[NaN,NaN,NaN,NaN,e,t];this.#s=[e,t],this.#i=[{line:c,points:this.#s}],this.#e.set(c,0)}updateProperty(e,t){e==="stroke-width"&&(this.#A=t)}#u(e,t){return Be._normalizePoint(e,t,this.#o,this.#d,this.#n)}isEmpty(){return!this.#i||this.#i.length===0}isCancellable(){return this.#s.length<=10}add(e,t){[e,t]=this.#u(e,t);const[n,s,a,o]=this.#e.subarray(2,6),c=e-a,d=t-o;return Math.hypot(this.#o*c,this.#d*d)<=2?null:(this.#s.push(e,t),isNaN(n)?(this.#e.set([a,o,e,t],2),this.#t.push(NaN,NaN,NaN,NaN,e,t),{path:{d:this.toSVGPath()}}):(isNaN(this.#e[0])&&this.#t.splice(6,6),this.#e.set([n,s,a,o,e,t],0),this.#t.push(...Be.createBezierPoints(n,s,a,o,e,t)),{path:{d:this.toSVGPath()}}))}end(e,t){const n=this.add(e,t);return n||(this.#s.length===2?{path:{d:this.toSVGPath()}}:null)}startNew(e,t,n,s,a){this.#o=n,this.#d=s,this.#n=a,[e,t]=this.#u(e,t);const o=this.#t=[NaN,NaN,NaN,NaN,e,t];this.#s=[e,t];const c=this.#i.at(-1);return c&&(c.line=new Float32Array(c.line),c.points=new Float32Array(c.points)),this.#i.push({line:o,points:this.#s}),this.#e.set(o,0),this.#a=0,this.toSVGPath(),null}getLastElement(){return this.#i.at(-1)}setLastElement(e){return this.#i?(this.#i.push(e),this.#t=e.line,this.#s=e.points,this.#a=0,{path:{d:this.toSVGPath()}}):this.#l.setLastElement(e)}removeLastElement(){if(!this.#i)return this.#l.removeLastElement();this.#i.pop(),this.#r="";for(let e=0,t=this.#i.length;e<t;e++){const{line:n,points:s}=this.#i[e];this.#t=n,this.#s=s,this.#a=0,this.toSVGPath()}return{path:{d:this.#r}}}toSVGPath(){const e=Be.svgRound(this.#t[4]),t=Be.svgRound(this.#t[5]);if(this.#s.length===2)return this.#r=`${this.#r} M ${e} ${t} Z`,this.#r;if(this.#s.length<=6){const s=this.#r.lastIndexOf("M");this.#r=`${this.#r.slice(0,s)} M ${e} ${t}`,this.#a=6}if(this.#s.length===4){const s=Be.svgRound(this.#t[10]),a=Be.svgRound(this.#t[11]);return this.#r=`${this.#r} L ${s} ${a}`,this.#a=12,this.#r}const n=[];this.#a===0&&(n.push(`M ${e} ${t}`),this.#a=6);for(let s=this.#a,a=this.#t.length;s<a;s+=6){const[o,c,d,f,g,w]=this.#t.slice(s,s+6).map(Be.svgRound);n.push(`C${o} ${c} ${d} ${f} ${g} ${w}`)}return this.#r+=n.join(" "),this.#a=this.#t.length,this.#r}getOutlines(e,t,n,s){const a=this.#i.at(-1);return a.line=new Float32Array(a.line),a.points=new Float32Array(a.points),this.#l.build(this.#i,e,t,n,this.#n,this.#A,s),this.#e=null,this.#t=null,this.#i=null,this.#r=null,this.#l}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}class tl extends Be{#e;#t=0;#i;#n;#A;#s;#r;#a;#l;build(e,t,n,s,a,o,c){this.#A=t,this.#s=n,this.#r=s,this.#a=a,this.#l=o,this.#i=c??0,this.#n=e,this.#u()}get thickness(){return this.#l}setLastElement(e){return this.#n.push(e),{path:{d:this.toSVGPath()}}}removeLastElement(){return this.#n.pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const e=[];for(const{line:t}of this.#n){if(e.push(`M${Be.svgRound(t[4])} ${Be.svgRound(t[5])}`),t.length===6){e.push("Z");continue}if(t.length===12&&isNaN(t[6])){e.push(`L${Be.svgRound(t[10])} ${Be.svgRound(t[11])}`);continue}for(let n=6,s=t.length;n<s;n+=6){const[a,o,c,d,f,g]=t.subarray(n,n+6).map(Be.svgRound);e.push(`C${a} ${o} ${c} ${d} ${f} ${g}`)}}return e.join("")}serialize([e,t,n,s],a){const o=[],c=[],[d,f,g,w]=this.#d();let b,E,M,S,j,F,z,J,Y;switch(this.#a){case 0:Y=Be._rescale,b=e,E=t+s,M=n,S=-s,j=e+d*n,F=t+(1-f-w)*s,z=e+(d+g)*n,J=t+(1-f)*s;break;case 90:Y=Be._rescaleAndSwap,b=e,E=t,M=n,S=s,j=e+f*n,F=t+d*s,z=e+(f+w)*n,J=t+(d+g)*s;break;case 180:Y=Be._rescale,b=e+n,E=t,M=-n,S=s,j=e+(1-d-g)*n,F=t+f*s,z=e+(1-d)*n,J=t+(f+w)*s;break;case 270:Y=Be._rescaleAndSwap,b=e+n,E=t+s,M=-n,S=-s,j=e+(1-f-w)*n,F=t+(1-d-g)*s,z=e+(1-f)*n,J=t+(1-d)*s;break}for(const{line:H,points:W}of this.#n)o.push(Y(H,b,E,M,S,a?new Array(H.length):null)),c.push(Y(W,b,E,M,S,a?new Array(W.length):null));return{lines:o,points:c,rect:[j,F,z,J]}}static deserialize(e,t,n,s,a,{paths:{lines:o,points:c},rotation:d,thickness:f}){const g=[];let w,b,E,M,S;switch(d){case 0:S=Be._rescale,w=-e/n,b=t/s+1,E=1/n,M=-1/s;break;case 90:S=Be._rescaleAndSwap,w=-t/s,b=-e/n,E=1/s,M=1/n;break;case 180:S=Be._rescale,w=e/n+1,b=-t/s,E=-1/n,M=1/s;break;case 270:S=Be._rescaleAndSwap,w=t/s+1,b=e/n+1,E=-1/s,M=-1/n;break}if(!o){o=[];for(const F of c){const z=F.length;if(z===2){o.push(new Float32Array([NaN,NaN,NaN,NaN,F[0],F[1]]));continue}if(z===4){o.push(new Float32Array([NaN,NaN,NaN,NaN,F[0],F[1],NaN,NaN,NaN,NaN,F[2],F[3]]));continue}const J=new Float32Array(3*(z-2));o.push(J);let[Y,H,W,_]=F.subarray(0,4);J.set([NaN,NaN,NaN,NaN,Y,H],0);for(let l1=4;l1<z;l1+=2){const r1=F[l1],f1=F[l1+1];J.set(Be.createBezierPoints(Y,H,W,_,r1,f1),(l1-2)*3),[Y,H,W,_]=[W,_,r1,f1]}}}for(let F=0,z=o.length;F<z;F++)g.push({line:S(o[F].map(J=>J??NaN),w,b,E,M),points:S(c[F].map(J=>J??NaN),w,b,E,M)});const j=new this.prototype.constructor;return j.build(g,n,s,1,d,f,a),j}#o(e=this.#l){const t=this.#i+e/2*this.#r;return this.#a%180===0?[t/this.#A,t/this.#s]:[t/this.#s,t/this.#A]}#d(){const[e,t,n,s]=this.#e,[a,o]=this.#o(0);return[e+a,t+o,n-2*a,s-2*o]}#u(){const e=this.#e=new Float32Array([1/0,1/0,-1/0,-1/0]);for(const{line:s}of this.#n){if(s.length<=12){for(let c=4,d=s.length;c<d;c+=6)be.pointBoundingBox(s[c],s[c+1],e);continue}let a=s[4],o=s[5];for(let c=6,d=s.length;c<d;c+=6){const[f,g,w,b,E,M]=s.subarray(c,c+6);be.bezierBoundingBox(a,o,f,g,w,b,E,M,e),a=E,o=M}}const[t,n]=this.#o();e[0]=Rn(e[0]-t,0,1),e[1]=Rn(e[1]-n,0,1),e[2]=Rn(e[2]+t,0,1),e[3]=Rn(e[3]+n,0,1),e[2]-=e[0],e[3]-=e[1]}get box(){return this.#e}updateProperty(e,t){return e==="stroke-width"?this.#h(t):null}#h(e){const[t,n]=this.#o();this.#l=e;const[s,a]=this.#o(),[o,c]=[s-t,a-n],d=this.#e;return d[0]-=o,d[1]-=c,d[2]+=2*o,d[3]+=2*c,d}updateParentDimensions([e,t],n){const[s,a]=this.#o();this.#A=e,this.#s=t,this.#r=n;const[o,c]=this.#o(),d=o-s,f=c-a,g=this.#e;return g[0]-=d,g[1]-=f,g[2]+=2*d,g[3]+=2*f,g}updateRotation(e){return this.#t=e,{path:{transform:this.rotationTransform}}}get viewBox(){return this.#e.map(Be.svgRound).join(" ")}get defaultProperties(){const[e,t]=this.#e;return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Be.svgRound(e)} ${Be.svgRound(t)}`}}}get rotationTransform(){const[,,e,t]=this.#e;let n=0,s=0,a=0,o=0,c=0,d=0;switch(this.#t){case 90:s=t/e,a=-e/t,c=e;break;case 180:n=-1,o=-1,c=e,d=t;break;case 270:s=-t/e,a=e/t,d=t;break;default:return""}return`matrix(${n} ${s} ${a} ${o} ${Be.svgRound(c)} ${Be.svgRound(d)})`}getPathResizingSVGProperties([e,t,n,s]){const[a,o]=this.#o(),[c,d,f,g]=this.#e;if(Math.abs(f-a)<=Be.PRECISION||Math.abs(g-o)<=Be.PRECISION){const S=e+n/2-(c+f/2),j=t+s/2-(d+g/2);return{path:{"transform-origin":`${Be.svgRound(e)} ${Be.svgRound(t)}`,transform:`${this.rotationTransform} translate(${S} ${j})`}}}const w=(n-2*a)/(f-2*a),b=(s-2*o)/(g-2*o),E=f/n,M=g/s;return{path:{"transform-origin":`${Be.svgRound(c)} ${Be.svgRound(d)}`,transform:`${this.rotationTransform} scale(${E} ${M}) translate(${Be.svgRound(a)} ${Be.svgRound(o)}) scale(${w} ${b}) translate(${Be.svgRound(-a)} ${Be.svgRound(-o)})`}}}getPathResizedSVGProperties([e,t,n,s]){const[a,o]=this.#o(),c=this.#e,[d,f,g,w]=c;if(c[0]=e,c[1]=t,c[2]=n,c[3]=s,Math.abs(g-a)<=Be.PRECISION||Math.abs(w-o)<=Be.PRECISION){const j=e+n/2-(d+g/2),F=t+s/2-(f+w/2);for(const{line:z,points:J}of this.#n)Be._translate(z,j,F,z),Be._translate(J,j,F,J);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Be.svgRound(e)} ${Be.svgRound(t)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const b=(n-2*a)/(g-2*a),E=(s-2*o)/(w-2*o),M=-b*(d+a)+e+a,S=-E*(f+o)+t+o;if(b!==1||E!==1||M!==0||S!==0)for(const{line:j,points:F}of this.#n)Be._rescale(j,M,S,b,E,j),Be._rescale(F,M,S,b,E,F);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Be.svgRound(e)} ${Be.svgRound(t)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,t],n){const[s,a]=n,o=this.#e,c=e-o[0],d=t-o[1];if(this.#A===s&&this.#s===a)for(const{line:f,points:g}of this.#n)Be._translate(f,c,d,f),Be._translate(g,c,d,g);else{const f=this.#A/s,g=this.#s/a;this.#A=s,this.#s=a;for(const{line:w,points:b}of this.#n)Be._rescale(w,c,d,f,g,w),Be._rescale(b,c,d,f,g,b);o[2]*=f,o[3]*=g}return o[0]=e,o[1]=t,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${Be.svgRound(e)} ${Be.svgRound(t)}`}}}get defaultSVGProperties(){const e=this.#e;return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${Be.svgRound(e[0])} ${Be.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}}class wu extends zp{constructor(e){super(),this._viewParameters=e,super.updateProperties({fill:"none",stroke:Ue._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(e,t){e==="stroke-width"&&(t??=this["stroke-width"],t*=this._viewParameters.realScale),super.updateSVGProperty(e,t)}clone(){const e=new wu(this._viewParameters);return e.updateAll(this),e}}class zh extends He{static _type="ink";static _editorType=st.INK;static _defaultDrawingOptions=null;constructor(e){super({...e,name:"inkEditor"}),this._willKeepAspectRatio=!0,this.defaultL10nId="pdfjs-editor-ink-editor"}static initialize(e,t){Ue.initialize(e,t),this._defaultDrawingOptions=new wu(t.viewParameters)}static getDefaultDrawingOptions(e){const t=this._defaultDrawingOptions.clone();return t.updateProperties(e),t}static get supportMultipleDrawings(){return!0}static get typesMap(){return ut(this,"typesMap",new Map([[yt.INK_THICKNESS,"stroke-width"],[yt.INK_COLOR,"stroke"],[yt.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(e,t,n,s,a){return new sv(e,t,n,s,a,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(e,t,n,s,a,o){return tl.deserialize(e,t,n,s,a,o)}static async deserialize(e,t,n){let s=null;if(e instanceof kh){const{data:{inkLists:o,rect:c,rotation:d,id:f,color:g,opacity:w,borderStyle:{rawWidth:b},popupRef:E,richText:M,contentsObj:S,creationDate:j,modificationDate:F},parent:{page:{pageNumber:z}}}=e;s=e={annotationType:st.INK,color:Array.from(g),thickness:b,opacity:w,paths:{points:o},boxes:null,pageIndex:z-1,rect:c.slice(0),rotation:d,annotationElementId:f,id:f,deleted:!1,popupRef:E,richText:M,comment:S?.str||null,creationDate:j,modificationDate:F}}const a=await super.deserialize(e,t,n);return a._initialData=s,e.comment&&a.setCommentData(e),a}get toolbarButtons(){return this._colorPicker||=new _o(this),[["colorPicker",this._colorPicker]]}get colorType(){return yt.INK_COLOR}get color(){return this._drawingOptions.stroke}get opacity(){return this._drawingOptions["stroke-opacity"]}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();const{_drawId:e,_drawingOptions:t,parent:n}=this;t.updateSVGProperty("stroke-width"),n.drawLayer.updateProperties(e,t.toSVGProperties())}static onScaleChangingWhenDrawing(){const e=this._currentParent;e&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),e.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:e,thickness:t,opacity:n}){this._drawingOptions=zh.getDefaultDrawingOptions({stroke:be.makeHexColor(...e),"stroke-width":t,"stroke-opacity":n})}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:t,points:n}=this.serializeDraw(e),{_drawingOptions:{stroke:s,"stroke-opacity":a,"stroke-width":o}}=this,c=Object.assign(super.serialize(e),{color:Ue._colorManager.convert(s),opacity:a,thickness:o,paths:{lines:t,points:n}});return this.addComment(c),e?(c.isCopy=!0,c):this.annotationElementId&&!this.#e(c)?null:(c.id=this.annotationElementId,c)}#e(e){const{color:t,thickness:n,opacity:s,pageIndex:a}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized||e.color.some((o,c)=>o!==t[c])||e.thickness!==n||e.opacity!==s||e.pageIndex!==a}renderAnnotationElement(e){if(this.deleted)return e.hide(),null;const{points:t,rect:n}=this.serializeDraw(!1);return e.updateEdited({rect:n,thickness:this._drawingOptions["stroke-width"],points:t,popup:this.comment}),null}}class Gh extends tl{toSVGPath(){let e=super.toSVGPath();return e.endsWith("Z")||(e+="Z"),e}}const vu=8,nl=3;class J0{static#e={maxDim:512,sigmaSFactor:.02,sigmaR:25,kernelSize:16};static#t(e,t,n,s){return n-=e,s-=t,n===0?s>0?0:4:n===1?s+6:2-s}static#i=new Int32Array([0,1,-1,1,-1,0,-1,-1,0,-1,1,-1,1,0,1,1]);static#n(e,t,n,s,a,o,c){const d=this.#t(n,s,a,o);for(let f=0;f<8;f++){const g=(-f+d-c+16)%8,w=this.#i[2*g],b=this.#i[2*g+1];if(e[(n+w)*t+(s+b)]!==0)return g}return-1}static#A(e,t,n,s,a,o,c){const d=this.#t(n,s,a,o);for(let f=0;f<8;f++){const g=(f+d+c+16)%8,w=this.#i[2*g],b=this.#i[2*g+1];if(e[(n+w)*t+(s+b)]!==0)return g}return-1}static#s(e,t,n,s){const a=e.length,o=new Int32Array(a);for(let g=0;g<a;g++)o[g]=e[g]<=s?1:0;for(let g=1;g<n-1;g++)o[g*t]=o[g*t+t-1]=0;for(let g=0;g<t;g++)o[g]=o[t*n-1-g]=0;let c=1,d;const f=[];for(let g=1;g<n-1;g++){d=1;for(let w=1;w<t-1;w++){const b=g*t+w,E=o[b];if(E===0)continue;let M=g,S=w;if(E===1&&o[b-1]===0)c+=1,S-=1;else if(E>=1&&o[b+1]===0)c+=1,S+=1,E>1&&(d=E);else{E!==1&&(d=Math.abs(E));continue}const j=[w,g],F=S===w+1,z={isHole:F,points:j,id:c,parent:0};f.push(z);let J;for(const p1 of f)if(p1.id===d){J=p1;break}J?J.isHole?z.parent=F?J.parent:d:z.parent=F?d:J.parent:z.parent=F?d:0;const Y=this.#n(o,t,g,w,M,S,0);if(Y===-1){o[b]=-c,o[b]!==1&&(d=Math.abs(o[b]));continue}let H=this.#i[2*Y],W=this.#i[2*Y+1];const _=g+H,l1=w+W;M=_,S=l1;let r1=g,f1=w;for(;;){const p1=this.#A(o,t,r1,f1,M,S,1);H=this.#i[2*p1],W=this.#i[2*p1+1];const b1=r1+H,N1=f1+W;j.push(N1,b1);const B1=r1*t+f1;if(o[B1+1]===0?o[B1]=-c:o[B1]===1&&(o[B1]=c),b1===g&&N1===w&&r1===_&&f1===l1){o[b]!==1&&(d=Math.abs(o[b]));break}else M=r1,S=f1,r1=b1,f1=N1}}}return f}static#r(e,t,n,s){if(n-t<=4){for(let _=t;_<n-2;_+=2)s.push(e[_],e[_+1]);return}const a=e[t],o=e[t+1],c=e[n-4]-a,d=e[n-3]-o,f=Math.hypot(c,d),g=c/f,w=d/f,b=g*o-w*a,E=d/c,M=1/f,S=Math.atan(E),j=Math.cos(S),F=Math.sin(S),z=M*(Math.abs(j)+Math.abs(F)),J=M*(1-z+z**2),Y=Math.max(Math.atan(Math.abs(F+j)*J),Math.atan(Math.abs(F-j)*J));let H=0,W=t;for(let _=t+2;_<n-2;_+=2){const l1=Math.abs(b-g*e[_+1]+w*e[_]);l1>H&&(W=_,H=l1)}H>(f*Y)**2?(this.#r(e,t,W+2,s),this.#r(e,W,n,s)):s.push(a,o)}static#a(e){const t=[],n=e.length;return this.#r(e,0,n,t),t.push(e[n-2],e[n-1]),t.length<=4?null:t}static#l(e,t,n,s,a,o){const c=new Float32Array(o**2),d=-2*s**2,f=o>>1;for(let S=0;S<o;S++){const j=(S-f)**2;for(let F=0;F<o;F++)c[S*o+F]=Math.exp((j+(F-f)**2)/d)}const g=new Float32Array(256),w=-2*a**2;for(let S=0;S<256;S++)g[S]=Math.exp(S**2/w);const b=e.length,E=new Uint8Array(b),M=new Uint32Array(256);for(let S=0;S<n;S++)for(let j=0;j<t;j++){const F=S*t+j,z=e[F];let J=0,Y=0;for(let W=0;W<o;W++){const _=S+W-f;if(!(_<0||_>=n))for(let l1=0;l1<o;l1++){const r1=j+l1-f;if(r1<0||r1>=t)continue;const f1=e[_*t+r1],p1=c[W*o+l1]*g[Math.abs(f1-z)];J+=f1*p1,Y+=p1}}const H=E[F]=Math.round(J/Y);M[H]++}return[E,M]}static#o(e){const t=new Uint32Array(256);for(const n of e)t[n]++;return t}static#d(e){const t=e.length,n=new Uint8ClampedArray(t>>2);let s=-1/0,a=1/0;for(let c=0,d=n.length;c<d;c++){const f=n[c]=e[c<<2];s=Math.max(s,f),a=Math.min(a,f)}const o=255/(s-a);for(let c=0,d=n.length;c<d;c++)n[c]=(n[c]-a)*o;return n}static#u(e){let t,n=-1/0,s=-1/0;const a=e.findIndex(d=>d!==0);let o=a,c=a;for(t=a;t<256;t++){const d=e[t];d>n&&(t-o>s&&(s=t-o,c=t-1),n=d,o=t)}for(t=c-1;t>=0&&!(e[t]>e[t+1]);t--);return t}static#h(e){const t=e,{width:n,height:s}=e,{maxDim:a}=this.#e;let o=n,c=s;if(n>a||s>a){let b=n,E=s,M=Math.log2(Math.max(n,s)/a);const S=Math.floor(M);M=M===S?S-1:S;for(let F=0;F<M;F++){o=Math.ceil(b/2),c=Math.ceil(E/2);const z=new OffscreenCanvas(o,c);z.getContext("2d").drawImage(e,0,0,b,E,0,0,o,c),b=o,E=c,e!==t&&e.close(),e=z.transferToImageBitmap()}const j=Math.min(a/o,a/c);o=Math.round(o*j),c=Math.round(c*j)}const f=new OffscreenCanvas(o,c).getContext("2d",{willReadFrequently:!0});f.fillStyle="white",f.fillRect(0,0,o,c),f.filter="grayscale(1)",f.drawImage(e,0,0,e.width,e.height,0,0,o,c);const g=f.getImageData(0,0,o,c).data;return[this.#d(g),o,c]}static extractContoursFromText(e,{fontFamily:t,fontStyle:n,fontWeight:s},a,o,c,d){let f=new OffscreenCanvas(1,1),g=f.getContext("2d",{alpha:!1});const w=200,b=g.font=`${n} ${s} ${w}px ${t}`,{actualBoundingBoxLeft:E,actualBoundingBoxRight:M,actualBoundingBoxAscent:S,actualBoundingBoxDescent:j,fontBoundingBoxAscent:F,fontBoundingBoxDescent:z,width:J}=g.measureText(e),Y=1.5,H=Math.ceil(Math.max(Math.abs(E)+Math.abs(M)||0,J)*Y),W=Math.ceil(Math.max(Math.abs(S)+Math.abs(j)||w,Math.abs(F)+Math.abs(z)||w)*Y);f=new OffscreenCanvas(H,W),g=f.getContext("2d",{alpha:!0,willReadFrequently:!0}),g.font=b,g.filter="grayscale(1)",g.fillStyle="white",g.fillRect(0,0,H,W),g.fillStyle="black",g.fillText(e,H*(Y-1)/2,W*(3-Y)/2);const _=this.#d(g.getImageData(0,0,H,W).data),l1=this.#o(_),r1=this.#u(l1),f1=this.#s(_,H,W,r1);return this.processDrawnLines({lines:{curves:f1,width:H,height:W},pageWidth:a,pageHeight:o,rotation:c,innerMargin:d,mustSmooth:!0,areContours:!0})}static process(e,t,n,s,a){const[o,c,d]=this.#h(e),[f,g]=this.#l(o,c,d,Math.hypot(c,d)*this.#e.sigmaSFactor,this.#e.sigmaR,this.#e.kernelSize),w=this.#u(g),b=this.#s(f,c,d,w);return this.processDrawnLines({lines:{curves:b,width:c,height:d},pageWidth:t,pageHeight:n,rotation:s,innerMargin:a,mustSmooth:!0,areContours:!0})}static processDrawnLines({lines:e,pageWidth:t,pageHeight:n,rotation:s,innerMargin:a,mustSmooth:o,areContours:c}){s%180!==0&&([t,n]=[n,t]);const{curves:d,width:f,height:g}=e,w=e.thickness??0,b=[],E=Math.min(t/f,n/g),M=E/t,S=E/n,j=[];for(const{points:z}of d){const J=o?this.#a(z):z;if(!J)continue;j.push(J);const Y=J.length,H=new Float32Array(Y),W=new Float32Array(3*(Y===2?2:Y-2));if(b.push({line:W,points:H}),Y===2){H[0]=J[0]*M,H[1]=J[1]*S,W.set([NaN,NaN,NaN,NaN,H[0],H[1]],0);continue}let[_,l1,r1,f1]=J;_*=M,l1*=S,r1*=M,f1*=S,H.set([_,l1,r1,f1],0),W.set([NaN,NaN,NaN,NaN,_,l1],0);for(let p1=4;p1<Y;p1+=2){const b1=H[p1]=J[p1]*M,N1=H[p1+1]=J[p1+1]*S;W.set(Be.createBezierPoints(_,l1,r1,f1,b1,N1),(p1-2)*3),[_,l1,r1,f1]=[r1,f1,b1,N1]}}if(b.length===0)return null;const F=c?new Gh:new tl;return F.build(b,t,n,1,s,c?0:w,a),{outline:F,newCurves:j,areContours:c,thickness:w,width:f,height:g}}static async compressSignature({outlines:e,areContours:t,thickness:n,width:s,height:a}){let o=1/0,c=-1/0,d=0;for(const J of e){d+=J.length;for(let Y=2,H=J.length;Y<H;Y++){const W=J[Y]-J[Y-2];o=Math.min(o,W),c=Math.max(c,W)}}let f;o>=-128&&c<=127?f=Int8Array:o>=-32768&&c<=32767?f=Int16Array:f=Int32Array;const g=e.length,w=vu+nl*g,b=new Uint32Array(w);let E=0;b[E++]=w*Uint32Array.BYTES_PER_ELEMENT+(d-2*g)*f.BYTES_PER_ELEMENT,b[E++]=0,b[E++]=s,b[E++]=a,b[E++]=t?0:1,b[E++]=Math.max(0,Math.floor(n??0)),b[E++]=g,b[E++]=f.BYTES_PER_ELEMENT;for(const J of e)b[E++]=J.length-2,b[E++]=J[0],b[E++]=J[1];const M=new CompressionStream("deflate-raw"),S=M.writable.getWriter();await S.ready,S.write(b);const j=f.prototype.constructor;for(const J of e){const Y=new j(J.length-2);for(let H=2,W=J.length;H<W;H++)Y[H-2]=J[H]-J[H-2];S.write(Y)}S.close();const F=await new Response(M.readable).arrayBuffer(),z=new Uint8Array(F);return H6(z)}static async decompressSignature(e){try{const t=L8(e),{readable:n,writable:s}=new DecompressionStream("deflate-raw"),a=s.getWriter();await a.ready,a.write(t).then(async()=>{await a.ready,await a.close()}).catch(()=>{});let o=null,c=0;for await(const J of n)o||=new Uint8Array(new Uint32Array(J.buffer,0,4)[0]),o.set(J,c),c+=J.length;const d=new Uint32Array(o.buffer,0,o.length>>2),f=d[1];if(f!==0)throw new Error(`Invalid version: ${f}`);const g=d[2],w=d[3],b=d[4]===0,E=d[5],M=d[6],S=d[7],j=[],F=(vu+nl*M)*Uint32Array.BYTES_PER_ELEMENT;let z;switch(S){case Int8Array.BYTES_PER_ELEMENT:z=new Int8Array(o.buffer,F);break;case Int16Array.BYTES_PER_ELEMENT:z=new Int16Array(o.buffer,F);break;case Int32Array.BYTES_PER_ELEMENT:z=new Int32Array(o.buffer,F);break}c=0;for(let J=0;J<M;J++){const Y=d[nl*J+vu],H=new Float32Array(Y+2);j.push(H);for(let W=0;W<nl-1;W++)H[W]=d[nl*J+vu+W+1];for(let W=0;W<Y;W++)H[W+2]=H[W]+z[c++]}return{areContours:b,thickness:E,outlines:j,width:g,height:w}}catch(t){return rt(`decompressSignature: ${t}`),null}}}class Yh extends zp{constructor(){super(),super.updateProperties({fill:Ue._defaultLineColor,"stroke-width":0})}clone(){const e=new Yh;return e.updateAll(this),e}}class Kh extends wu{constructor(e){super(e),super.updateProperties({stroke:Ue._defaultLineColor,"stroke-width":1})}clone(){const e=new Kh(this._viewParameters);return e.updateAll(this),e}}class h3 extends He{#e=!1;#t=null;#i=null;#n=null;static _type="signature";static _editorType=st.SIGNATURE;static _defaultDrawingOptions=null;constructor(e){super({...e,mustBeCommitted:!0,name:"signatureEditor"}),this._willKeepAspectRatio=!0,this.#i=e.signatureData||null,this.#t=null,this.defaultL10nId="pdfjs-editor-signature-editor1"}static initialize(e,t){Ue.initialize(e,t),this._defaultDrawingOptions=new Yh,this._defaultDrawnSignatureOptions=new Kh(t.viewParameters)}static getDefaultDrawingOptions(e){const t=this._defaultDrawingOptions.clone();return t.updateProperties(e),t}static get supportMultipleDrawings(){return!1}static get typesMap(){return ut(this,"typesMap",new Map)}static get isDrawer(){return!1}get telemetryFinalData(){return{type:"signature",hasDescription:!!this.#t}}static computeTelemetryFinalData(e){const t=e.get("hasDescription");return{hasAltText:t.get(!0)??0,hasNoAltText:t.get(!1)??0}}get isResizable(){return!0}onScaleChanging(){this._drawId!==null&&super.onScaleChanging()}render(){if(this.div)return this.div;let e,t;const{_isCopy:n}=this;if(n&&(this._isCopy=!1,e=this.x,t=this.y),super.render(),this._drawId===null)if(this.#i){const{lines:s,mustSmooth:a,areContours:o,description:c,uuid:d,heightInPage:f}=this.#i,{rawDims:{pageWidth:g,pageHeight:w},rotation:b}=this.parent.viewport,E=J0.processDrawnLines({lines:s,pageWidth:g,pageHeight:w,rotation:b,innerMargin:h3._INNER_MARGIN,mustSmooth:a,areContours:o});this.addSignature(E,f,c,d)}else this.div.setAttribute("data-l10n-args",JSON.stringify({description:""})),this.div.hidden=!0,this._uiManager.getSignature(this);else this.div.setAttribute("data-l10n-args",JSON.stringify({description:this.#t||""}));return n&&(this._isCopy=!0,this._moveAfterPaste(e,t)),this.div}setUuid(e){this.#n=e,this.addEditToolbar()}getUuid(){return this.#n}get description(){return this.#t}set description(e){this.#t=e,this.div&&(this.div.setAttribute("data-l10n-args",JSON.stringify({description:e})),super.addEditToolbar().then(t=>{t?.updateEditSignatureButton(e)}))}getSignaturePreview(){const{newCurves:e,areContours:t,thickness:n,width:s,height:a}=this.#i,o=Math.max(s,a),c=J0.processDrawnLines({lines:{curves:e.map(d=>({points:d})),thickness:n,width:s,height:a},pageWidth:o,pageHeight:o,rotation:0,innerMargin:0,mustSmooth:!1,areContours:t});return{areContours:t,outline:c.outline}}get toolbarButtons(){return this._uiManager.signatureManager?[["editSignature",this._uiManager.signatureManager]]:super.toolbarButtons}addSignature(e,t,n,s){const{x:a,y:o}=this,{outline:c}=this.#i=e;this.#e=c instanceof Gh,this.description=n;let d;this.#e?d=h3.getDefaultDrawingOptions():(d=h3._defaultDrawnSignatureOptions.clone(),d.updateProperties({"stroke-width":c.thickness})),this._addOutlines({drawOutlines:c,drawingOptions:d});const[,f]=this.pageDimensions;let g=t/f;g=g>=1?.5:g,this.width*=g/this.height,this.width>=1&&(g*=.9/this.width,this.width=.9),this.height=g,this.setDims(),this.x=a,this.y=o,this.center(),this._onResized(),this.onScaleChanging(),this.rotate(),this._uiManager.addToAnnotationStorage(this),this.setUuid(s),this._reportTelemetry({action:"pdfjs.signature.inserted",data:{hasBeenSaved:!!s,hasDescription:!!n}}),this.div.hidden=!1}getFromImage(e){const{rawDims:{pageWidth:t,pageHeight:n},rotation:s}=this.parent.viewport;return J0.process(e,t,n,s,h3._INNER_MARGIN)}getFromText(e,t){const{rawDims:{pageWidth:n,pageHeight:s},rotation:a}=this.parent.viewport;return J0.extractContoursFromText(e,t,n,s,a,h3._INNER_MARGIN)}getDrawnSignature(e){const{rawDims:{pageWidth:t,pageHeight:n},rotation:s}=this.parent.viewport;return J0.processDrawnLines({lines:e,pageWidth:t,pageHeight:n,rotation:s,innerMargin:h3._INNER_MARGIN,mustSmooth:!1,areContours:!1})}createDrawingOptions({areContours:e,thickness:t}){e?this._drawingOptions=h3.getDefaultDrawingOptions():(this._drawingOptions=h3._defaultDrawnSignatureOptions.clone(),this._drawingOptions.updateProperties({"stroke-width":t}))}serialize(e=!1){if(this.isEmpty())return null;const{lines:t,points:n}=this.serializeDraw(e),{_drawingOptions:{"stroke-width":s}}=this,a=Object.assign(super.serialize(e),{isSignature:!0,areContours:this.#e,color:[0,0,0],thickness:this.#e?0:s});return this.addComment(a),e?(a.paths={lines:t,points:n},a.uuid=this.#n,a.isCopy=!0):a.lines=t,this.#t&&(a.accessibilityData={type:"Figure",alt:this.#t}),a}static deserializeDraw(e,t,n,s,a,o){return o.areContours?Gh.deserialize(e,t,n,s,a,o):tl.deserialize(e,t,n,s,a,o)}static async deserialize(e,t,n){const s=await super.deserialize(e,t,n);return s.#e=e.areContours,s.description=e.accessibilityData?.alt||"",s.#n=e.uuid,s}}class rv extends Ue{#e=null;#t=null;#i=null;#n=null;#A=null;#s="";#r=null;#a=!1;#l=null;#o=!1;#d=!1;static _type="stamp";static _editorType=st.STAMP;constructor(e){super({...e,name:"stampEditor"}),this.#n=e.bitmapUrl,this.#A=e.bitmapFile,this.defaultL10nId="pdfjs-editor-stamp-editor"}static initialize(e,t){Ue.initialize(e,t)}static isHandlingMimeForPasting(e){return au.includes(e)}static paste(e,t){t.pasteEditor({mode:st.STAMP},{bitmapFile:e.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){return{type:"stamp",hasAltText:!!this.altTextData?.altText}}static computeTelemetryFinalData(e){const t=e.get("hasAltText");return{hasAltText:t.get(!0)??0,hasNoAltText:t.get(!1)??0}}#u(e,t=!1){if(!e){this.remove();return}this.#e=e.bitmap,t||(this.#t=e.id,this.#o=e.isSvg),e.file&&(this.#s=e.file.name),this.#f()}#h(){if(this.#i=null,this._uiManager.enableWaiting(!1),!!this.#r){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#e){this.addEditToolbar().then(()=>{this._editToolbar.hide(),this._uiManager.editAltText(this,!0)});return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#e){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(e=null,t=!0){if(this.hasAltTextData())return null;const{mlManager:n}=this._uiManager;if(!n)throw new Error("No ML.");if(!await n.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:s,width:a,height:o}=e||this.copyCanvas(null,null,!0).imageData,c=await n.guess({name:"altText",request:{data:s,width:a,height:o,channels:s.length/(a*o)}});if(!c)throw new Error("No response from the AI service.");if(c.error)throw new Error("Error from the AI service.");if(c.cancel)return null;if(!c.output)throw new Error("No valid response from the AI service.");const d=c.output;return await this.setGuessedAltText(d),t&&!this.hasAltTextData()&&(this.altTextData={alt:d,decorative:!1}),d}#g(){if(this.#t){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(this.#t).then(n=>this.#u(n,!0)).finally(()=>this.#h());return}if(this.#n){const n=this.#n;this.#n=null,this._uiManager.enableWaiting(!0),this.#i=this._uiManager.imageManager.getFromUrl(n).then(s=>this.#u(s)).finally(()=>this.#h());return}if(this.#A){const n=this.#A;this.#A=null,this._uiManager.enableWaiting(!0),this.#i=this._uiManager.imageManager.getFromFile(n).then(s=>this.#u(s)).finally(()=>this.#h());return}const e=document.createElement("input");e.type="file",e.accept=au.join(",");const t=this._uiManager._signal;this.#i=new Promise(n=>{e.addEventListener("change",async()=>{if(!e.files||e.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const s=await this._uiManager.imageManager.getFromFile(e.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),this.#u(s)}n()},{signal:t}),e.addEventListener("cancel",()=>{this.remove(),n()},{signal:t})}).finally(()=>this.#h()),e.click()}remove(){this.#t&&(this.#e=null,this._uiManager.imageManager.deleteId(this.#t),this.#r?.remove(),this.#r=null,this.#l&&(clearTimeout(this.#l),this.#l=null)),super.remove()}rebuild(){if(!this.parent){this.#t&&this.#g();return}super.rebuild(),this.div!==null&&(this.#t&&this.#r===null&&this.#g(),this.isAttachedToDOM||this.parent.add(this))}onceAdded(e){this._isDraggable=!0,e&&this.div.focus()}isEmpty(){return!(this.#i||this.#e||this.#n||this.#A||this.#t||this.#a)}get toolbarButtons(){return[["altText",this.createAltText()]]}get isResizable(){return!0}render(){if(this.div)return this.div;let e,t;return this._isCopy&&(e=this.x,t=this.y),super.render(),this.div.hidden=!0,this.createAltText(),this.#a||(this.#e?this.#f():this.#g()),this._isCopy&&this._moveAfterPaste(e,t),this._uiManager.addShouldRescale(this),this.div}setCanvas(e,t){const{id:n,bitmap:s}=this._uiManager.imageManager.getFromCanvas(e,t);t.remove(),n&&this._uiManager.imageManager.isValidId(n)&&(this.#t=n,s&&(this.#e=s),this.#a=!1,this.#f())}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;this.#l!==null&&clearTimeout(this.#l);const e=200;this.#l=setTimeout(()=>{this.#l=null,this.#p()},e)}#f(){const{div:e}=this;let{width:t,height:n}=this.#e;const[s,a]=this.pageDimensions,o=.75;if(this.width)t=this.width*s,n=this.height*a;else if(t>o*s||n>o*a){const d=Math.min(o*s/t,o*a/n);t*=d,n*=d}this._uiManager.enableWaiting(!1);const c=this.#r=document.createElement("canvas");c.setAttribute("role","img"),this.addContainer(c),this.width=t/s,this.height=n/a,this.setDims(),this._initialOptions?.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(e.hidden=!1),this.#p(),this.#d||(this.parent.addUndoableEditor(this),this.#d=!0),this._reportTelemetry({action:"inserted_image"}),this.#s&&this.div.setAttribute("aria-description",this.#s),this.annotationElementId||this._uiManager.a11yAlert("pdfjs-editor-stamp-added-alert")}copyCanvas(e,t,n=!1){e||(e=224);const{width:s,height:a}=this.#e,o=new Fs;let c=this.#e,d=s,f=a,g=null;if(t){if(s>t||a>t){const W=Math.min(t/s,t/a);d=Math.floor(s*W),f=Math.floor(a*W)}g=document.createElement("canvas");const b=g.width=Math.ceil(d*o.sx),E=g.height=Math.ceil(f*o.sy);this.#o||(c=this.#c(b,E));const M=g.getContext("2d");M.filter=this._uiManager.hcmFilter;let S="white",j="#cfcfd8";this._uiManager.hcmFilter!=="none"?j="black":N8.isDarkMode&&(S="#8f8f9d",j="#42414d");const F=15,z=F*o.sx,J=F*o.sy,Y=new OffscreenCanvas(z*2,J*2),H=Y.getContext("2d");H.fillStyle=S,H.fillRect(0,0,z*2,J*2),H.fillStyle=j,H.fillRect(0,0,z,J),H.fillRect(z,J,z,J),M.fillStyle=M.createPattern(Y,"repeat"),M.fillRect(0,0,b,E),M.drawImage(c,0,0,c.width,c.height,0,0,b,E)}let w=null;if(n){let b,E;if(o.symmetric&&c.width<e&&c.height<e)b=c.width,E=c.height;else if(c=this.#e,s>e||a>e){const j=Math.min(e/s,e/a);b=Math.floor(s*j),E=Math.floor(a*j),this.#o||(c=this.#c(b,E))}const S=new OffscreenCanvas(b,E).getContext("2d",{willReadFrequently:!0});S.drawImage(c,0,0,c.width,c.height,0,0,b,E),w={width:b,height:E,data:S.getImageData(0,0,b,E).data}}return{canvas:g,width:d,height:f,imageData:w}}#c(e,t){const{width:n,height:s}=this.#e;let a=n,o=s,c=this.#e;for(;a>2*e||o>2*t;){const d=a,f=o;a>2*e&&(a=a>=16384?Math.floor(a/2)-1:Math.ceil(a/2)),o>2*t&&(o=o>=16384?Math.floor(o/2)-1:Math.ceil(o/2));const g=new OffscreenCanvas(a,o);g.getContext("2d").drawImage(c,0,0,d,f,0,0,a,o),c=g.transferToImageBitmap()}return c}#p(){const[e,t]=this.parentDimensions,{width:n,height:s}=this,a=new Fs,o=Math.ceil(n*e*a.sx),c=Math.ceil(s*t*a.sy),d=this.#r;if(!d||d.width===o&&d.height===c)return;d.width=o,d.height=c;const f=this.#o?this.#e:this.#c(o,c),g=d.getContext("2d");g.filter=this._uiManager.hcmFilter,g.drawImage(f,0,0,f.width,f.height,0,0,o,c)}#m(e){if(e){if(this.#o){const s=this._uiManager.imageManager.getSvgUrl(this.#t);if(s)return s}const t=document.createElement("canvas");return{width:t.width,height:t.height}=this.#e,t.getContext("2d").drawImage(this.#e,0,0),t.toDataURL()}if(this.#o){const[t,n]=this.pageDimensions,s=Math.round(this.width*t*G0.PDF_TO_CSS_UNITS),a=Math.round(this.height*n*G0.PDF_TO_CSS_UNITS),o=new OffscreenCanvas(s,a);return o.getContext("2d").drawImage(this.#e,0,0,this.#e.width,this.#e.height,0,0,s,a),o.transferToImageBitmap()}return structuredClone(this.#e)}static async deserialize(e,t,n){let s=null,a=!1;if(e instanceof Rp){const{data:{rect:S,rotation:j,id:F,structParent:z,popupRef:J,richText:Y,contentsObj:H,creationDate:W,modificationDate:_},container:l1,parent:{page:{pageNumber:r1}},canvas:f1}=e;let p1,b1;f1?(delete e.canvas,{id:p1,bitmap:b1}=n.imageManager.getFromCanvas(l1.id,f1),f1.remove()):(a=!0,e._hasNoCanvas=!0);const N1=(await t._structTree.getAriaAttributes(`${fh}${F}`))?.get("aria-label")||"";s=e={annotationType:st.STAMP,bitmapId:p1,bitmap:b1,pageIndex:r1-1,rect:S.slice(0),rotation:j,annotationElementId:F,id:F,deleted:!1,accessibilityData:{decorative:!1,altText:N1},isSvg:!1,structParent:z,popupRef:J,richText:Y,comment:H?.str||null,creationDate:W,modificationDate:_}}const o=await super.deserialize(e,t,n),{rect:c,bitmap:d,bitmapUrl:f,bitmapId:g,isSvg:w,accessibilityData:b}=e;a?(n.addMissingCanvas(e.id,o),o.#a=!0):g&&n.imageManager.isValidId(g)?(o.#t=g,d&&(o.#e=d)):o.#n=f,o.#o=w;const[E,M]=o.pageDimensions;return o.width=(c[2]-c[0])/E,o.height=(c[3]-c[1])/M,b&&(o.altTextData=b),o._initialData=s,e.comment&&o.setCommentData(e),o.#d=!!s,o}serialize(e=!1,t=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const n=Object.assign(super.serialize(e),{bitmapId:this.#t,isSvg:this.#o});if(this.addComment(n),e)return n.bitmapUrl=this.#m(!0),n.accessibilityData=this.serializeAltText(!0),n.isCopy=!0,n;const{decorative:s,altText:a}=this.serializeAltText(!1);if(!s&&a&&(n.accessibilityData={type:"Figure",alt:a}),this.annotationElementId){const c=this.#v(n);return c.isSame?null:(c.isSameAltText?delete n.accessibilityData:n.accessibilityData.structParent=this._initialData.structParent??-1,n.id=this.annotationElementId,delete n.bitmapId,n)}if(t===null)return n;t.stamps||=new Map;const o=this.#o?(n.rect[2]-n.rect[0])*(n.rect[3]-n.rect[1]):null;if(!t.stamps.has(this.#t))t.stamps.set(this.#t,{area:o,serialized:n}),n.bitmap=this.#m(!1);else if(this.#o){const c=t.stamps.get(this.#t);o>c.area&&(c.area=o,c.serialized.bitmap.close(),c.serialized.bitmap=this.#m(!1))}return n}#v(e){const{pageIndex:t,accessibilityData:{altText:n}}=this._initialData,s=e.pageIndex===t,a=(e.accessibilityData?.alt||"")===n;return{isSame:!this.hasEditedComment&&!this._hasBeenMoved&&!this._hasBeenResized&&s&&a,isSameAltText:a}}renderAnnotationElement(e){return this.deleted?(e.hide(),null):(e.updateEdited({rect:this.getPDFRect(),popup:this.comment}),null)}}class f3{#e;#t=!1;#i=null;#n=null;#A=null;#s=new Map;#r=!1;#a=!1;#l=!1;#o=null;#d=null;#u=null;#h=null;#g=null;#f=-1;#c;static _initialized=!1;static#p=new Map([gn,zh,rv,z2,h3].map(e=>[e._editorType,e]));constructor({uiManager:e,pageIndex:t,div:n,structTreeLayer:s,accessibilityManager:a,annotationLayer:o,drawLayer:c,textLayer:d,viewport:f,l10n:g}){const w=[...f3.#p.values()];if(!f3._initialized){f3._initialized=!0;for(const b of w)b.initialize(g,e)}e.registerEditorTypes(w),this.#c=e,this.pageIndex=t,this.div=n,this.#e=a,this.#i=o,this.viewport=f,this.#u=d,this.drawLayer=c,this._structTree=s,this.#c.addLayer(this)}get isEmpty(){return this.#s.size===0}get isInvisible(){return this.isEmpty&&this.#c.getMode()===st.NONE}updateToolbar(e){this.#c.updateToolbar(e)}updateMode(e=this.#c.getMode()){switch(this.#C(),e){case st.NONE:this.div.classList.toggle("nonEditing",!0),this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case st.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case st.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);const{classList:t}=this.div;if(t.toggle("nonEditing",!1),e===st.POPUP)t.toggle("commentEditing",!0);else{t.toggle("commentEditing",!1);for(const n of f3.#p.values())t.toggle(`${n._type}Editing`,e===n._editorType)}this.div.hidden=!1}hasTextLayer(e){return e===this.#u?.div}setEditingState(e){this.#c.setEditingState(e)}addCommands(e){this.#c.addCommands(e)}cleanUndoStack(e){this.#c.cleanUndoStack(e)}toggleDrawing(e=!1){this.div.classList.toggle("drawing",!e)}togglePointerEvents(e=!1){this.div.classList.toggle("disabled",!e)}toggleAnnotationLayerPointerEvents(e=!1){this.#i?.div.classList.toggle("disabled",!e)}get#m(){return this.#s.size!==0?this.#s.values():this.#c.getEditors(this.pageIndex)}async enable(){this.#l=!0,this.div.tabIndex=0,this.togglePointerEvents(!0),this.div.classList.toggle("nonEditing",!1),this.#g?.abort(),this.#g=null;const e=new Set;for(const n of this.#m)n.enableEditing(),n.show(!0),n.annotationElementId&&(this.#c.removeChangedExistingAnnotation(n),e.add(n.annotationElementId));const t=this.#i;if(t)for(const n of t.getEditableAnnotations()){if(n.hide(),this.#c.isDeletedAnnotationElement(n.data.id)||e.has(n.data.id))continue;const s=await this.deserialize(n);s&&(this.addOrRebuild(s),s.enableEditing())}this.#l=!1,this.#c._eventBus.dispatch("editorsrendered",{source:this,pageNumber:this.pageIndex+1})}disable(){if(this.#a=!0,this.div.tabIndex=-1,this.togglePointerEvents(!1),this.div.classList.toggle("nonEditing",!0),this.#u&&!this.#g){this.#g=new AbortController;const n=this.#c.combinedSignal(this.#g);this.#u.div.addEventListener("pointerdown",s=>{const{clientX:o,clientY:c,timeStamp:d}=s,f=this.#f;if(d-f>500){this.#f=d;return}this.#f=-1;const{classList:g}=this.div;g.toggle("getElements",!0);const w=document.elementsFromPoint(o,c);if(g.toggle("getElements",!1),!this.div.contains(w[0]))return;let b;const E=new RegExp(`^${Qo}[0-9]+$`);for(const S of w)if(E.test(S.id)){b=S.id;break}if(!b)return;const M=this.#s.get(b);M?.annotationElementId===null&&(s.stopPropagation(),s.preventDefault(),M.dblclick(s))},{signal:n,capture:!0})}const e=this.#i;if(e){const n=new Map,s=new Map;for(const o of this.#m){if(o.disableEditing(),!o.annotationElementId){o.updateFakeAnnotationElement(e);continue}if(o.serialize()!==null){n.set(o.annotationElementId,o);continue}else s.set(o.annotationElementId,o);this.getEditableAnnotation(o.annotationElementId)?.show(),o.remove()}const a=e.getEditableAnnotations();for(const o of a){const{id:c}=o.data;if(this.#c.isDeletedAnnotationElement(c)){o.updateEdited({deleted:!0});continue}let d=s.get(c);if(d){d.resetAnnotationElement(o),d.show(!1),o.show();continue}d=n.get(c),d&&(this.#c.addChangedExistingAnnotation(d),d.renderAnnotationElement(o)&&d.show(!1)),o.show()}}this.#C(),this.isEmpty&&(this.div.hidden=!0);const{classList:t}=this.div;for(const n of f3.#p.values())t.remove(`${n._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),this.#a=!1}getEditableAnnotation(e){return this.#i?.getEditableAnnotation(e)||null}setActiveEditor(e){this.#c.getActive()!==e&&this.#c.setActiveEditor(e)}enableTextSelection(){if(this.div.tabIndex=-1,this.#u?.div&&!this.#h){this.#h=new AbortController;const e=this.#c.combinedSignal(this.#h);this.#u.div.addEventListener("pointerdown",this.#v.bind(this),{signal:e}),this.#u.div.classList.add("highlighting")}}disableTextSelection(){this.div.tabIndex=0,this.#u?.div&&this.#h&&(this.#h.abort(),this.#h=null,this.#u.div.classList.remove("highlighting"))}#v(e){this.#c.unselectAll();const{target:t}=e;if(t===this.#u.div||(t.getAttribute("role")==="img"||t.classList.contains("endOfContent"))&&this.#u.div.contains(t)){const{isMac:n}=pn.platform;if(e.button!==0||e.ctrlKey&&n)return;this.#c.showAllEditors("highlight",!0,!0),this.#u.div.classList.add("free"),this.toggleDrawing(),z2.startHighlighting(this,this.#c.direction==="ltr",{target:this.#u.div,x:e.x,y:e.y}),this.#u.div.addEventListener("pointerup",()=>{this.#u.div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:this.#c._signal}),e.preventDefault()}}enableClick(){if(this.#n)return;this.#n=new AbortController;const e=this.#c.combinedSignal(this.#n);this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:e});const t=this.pointerup.bind(this);this.div.addEventListener("pointerup",t,{signal:e}),this.div.addEventListener("pointercancel",t,{signal:e})}disableClick(){this.#n?.abort(),this.#n=null}attach(e){this.#s.set(e.id,e);const{annotationElementId:t}=e;t&&this.#c.isDeletedAnnotationElement(t)&&this.#c.removeDeletedAnnotationElement(e)}detach(e){this.#s.delete(e.id),this.#e?.removePointerInTextLayer(e.contentDiv),!this.#a&&e.annotationElementId&&this.#c.addDeletedAnnotationElement(e)}remove(e){this.detach(e),this.#c.removeEditor(e),e.div.remove(),e.isAttachedToDOM=!1}changeParent(e){e.parent!==this&&(e.parent&&e.annotationElementId&&(this.#c.addDeletedAnnotationElement(e.annotationElementId),Ue.deleteAnnotationElement(e),e.annotationElementId=null),this.attach(e),e.parent?.detach(e),e.setParent(this),e.div&&e.isAttachedToDOM&&(e.div.remove(),this.div.append(e.div)))}add(e){if(!(e.parent===this&&e.isAttachedToDOM)){if(this.changeParent(e),this.#c.addEditor(e),this.attach(e),!e.isAttachedToDOM){const t=e.render();this.div.append(t),e.isAttachedToDOM=!0}e.fixAndSetPosition(),e.onceAdded(!this.#l),this.#c.addToAnnotationStorage(e),e._reportTelemetry(e.telemetryInitialData)}}moveEditorInDOM(e){if(!e.isAttachedToDOM)return;const{activeElement:t}=document;e.div.contains(t)&&!this.#A&&(e._focusEventsAllowed=!1,this.#A=setTimeout(()=>{this.#A=null,e.div.contains(document.activeElement)?e._focusEventsAllowed=!0:(e.div.addEventListener("focusin",()=>{e._focusEventsAllowed=!0},{once:!0,signal:this.#c._signal}),t.focus())},0)),e._structTreeParentId=this.#e?.moveElementInDOM(this.div,e.div,e.contentDiv,!0)}addOrRebuild(e){e.needsToBeRebuilt()?(e.parent||=this,e.rebuild(),e.show()):this.add(e)}addUndoableEditor(e){const t=()=>e._uiManager.rebuild(e),n=()=>{e.remove()};this.addCommands({cmd:t,undo:n,mustExec:!1})}getEditorByUID(e){for(const t of this.#s.values())if(t.uid===e)return t;return null}getNextId(){return this.#c.getId()}get#w(){return f3.#p.get(this.#c.getMode())}combinedSignal(e){return this.#c.combinedSignal(e)}#I(e){const t=this.#w;return t?new t.prototype.constructor(e):null}canCreateNewEmptyEditor(){return this.#w?.canCreateNewEmptyEditor()}async pasteEditor(e,t){this.updateToolbar(e),await this.#c.updateMode(e.mode);const{offsetX:n,offsetY:s}=this.#B(),a=this.getNextId(),o=this.#I({parent:this,id:a,x:n,y:s,uiManager:this.#c,isCentered:!0,...t});o&&this.add(o)}async deserialize(e){return await f3.#p.get(e.annotationType??e.annotationEditorType)?.deserialize(e,this,this.#c)||null}createAndAddNewEditor(e,t,n={}){const s=this.getNextId(),a=this.#I({parent:this,id:s,x:e.offsetX,y:e.offsetY,uiManager:this.#c,isCentered:t,...n});return a&&this.add(a),a}get boundingClientRect(){return this.div.getBoundingClientRect()}#B(){const{x:e,y:t,width:n,height:s}=this.boundingClientRect,a=Math.max(0,e),o=Math.max(0,t),c=Math.min(window.innerWidth,e+n),d=Math.min(window.innerHeight,t+s),f=(a+c)/2-e,g=(o+d)/2-t,[w,b]=this.viewport.rotation%180===0?[f,g]:[g,f];return{offsetX:w,offsetY:b}}addNewEditor(e={}){this.createAndAddNewEditor(this.#B(),!0,e)}setSelected(e){this.#c.setSelected(e)}toggleSelected(e){this.#c.toggleSelected(e)}unselect(e){this.#c.unselect(e)}pointerup(e){const{isMac:t}=pn.platform;if(e.button!==0||e.ctrlKey&&t||e.target!==this.div||!this.#r||(this.#r=!1,this.#w?.isDrawer&&this.#w.supportMultipleDrawings))return;if(!this.#t){this.#t=!0;return}const n=this.#c.getMode();if(n===st.STAMP||n===st.SIGNATURE){this.#c.unselectAll();return}this.createAndAddNewEditor(e,!1)}pointerdown(e){if(this.#c.getMode()===st.HIGHLIGHT&&this.enableTextSelection(),this.#r){this.#r=!1;return}const{isMac:t}=pn.platform;if(e.button!==0||e.ctrlKey&&t||e.target!==this.div)return;if(this.#r=!0,this.#w?.isDrawer){this.startDrawingSession(e);return}const n=this.#c.getActive();this.#t=!n||n.isEmpty()}startDrawingSession(e){if(this.div.focus({preventScroll:!0}),this.#o){this.#w.startDrawing(this,this.#c,!1,e);return}this.#c.setCurrentDrawingSession(this),this.#o=new AbortController;const t=this.#c.combinedSignal(this.#o);this.div.addEventListener("blur",({relatedTarget:n})=>{n&&!this.div.contains(n)&&(this.#d=null,this.commitOrRemove())},{signal:t}),this.#w.startDrawing(this,this.#c,!1,e)}pause(e){if(e){const{activeElement:t}=document;this.div.contains(t)&&(this.#d=t);return}this.#d&&setTimeout(()=>{this.#d?.focus(),this.#d=null},0)}endDrawingSession(e=!1){return this.#o?(this.#c.setCurrentDrawingSession(null),this.#o.abort(),this.#o=null,this.#d=null,this.#w.endDrawing(e)):null}findNewParent(e,t,n){const s=this.#c.findParent(t,n);return s===null||s===this?!1:(s.changeParent(e),!0)}commitOrRemove(){return this.#o?(this.endDrawingSession(),!0):!1}onScaleChanging(){this.#o&&this.#w.onScaleChangingWhenDrawing(this)}destroy(){this.commitOrRemove(),this.#c.getActive()?.parent===this&&(this.#c.commitOrRemove(),this.#c.setActiveEditor(null)),this.#A&&(clearTimeout(this.#A),this.#A=null);for(const e of this.#s.values())this.#e?.removePointerInTextLayer(e.contentDiv),e.setParent(null),e.isAttachedToDOM=!1,e.div.remove();this.div=null,this.#s.clear(),this.#c.removeLayer(this)}#C(){for(const e of this.#s.values())e.isEmpty()&&e.remove()}render({viewport:e}){this.viewport=e,Ur(this.div,e);for(const t of this.#c.getEditors(this.pageIndex))this.add(t),t.rebuild();this.updateMode()}update({viewport:e}){this.#c.commitOrRemove(),this.#C();const t=this.viewport.rotation,n=e.rotation;if(this.viewport=e,Ur(this.div,{rotation:n}),t!==n)for(const s of this.#s.values())s.rotate(n)}get pageDimensions(){const{pageWidth:e,pageHeight:t}=this.viewport.rawDims;return[e,t]}get scale(){return this.#c.viewParameters.realScale}}class mn{#e=null;#t=new Map;#i=new Map;static#n=0;constructor({pageIndex:e}){this.pageIndex=e}setParent(e){if(!this.#e){this.#e=e;return}if(this.#e!==e){if(this.#t.size>0)for(const t of this.#t.values())t.remove(),e.append(t);this.#e=e}}static get _svgFactory(){return ut(this,"_svgFactory",new el)}static#A(e,[t,n,s,a]){const{style:o}=e;o.top=`${100*n}%`,o.left=`${100*t}%`,o.width=`${100*s}%`,o.height=`${100*a}%`}#s(){const e=mn._svgFactory.create(1,1,!0);return this.#e.append(e),e.setAttribute("aria-hidden",!0),e}#r(e,t){const n=mn._svgFactory.createElement("clipPath");e.append(n);const s=`clip_${t}`;n.setAttribute("id",s),n.setAttribute("clipPathUnits","objectBoundingBox");const a=mn._svgFactory.createElement("use");return n.append(a),a.setAttribute("href",`#${t}`),a.classList.add("clip"),s}#a(e,t){for(const[n,s]of Object.entries(t))s===null?e.removeAttribute(n):e.setAttribute(n,s)}draw(e,t=!1,n=!1){const s=mn.#n++,a=this.#s(),o=mn._svgFactory.createElement("defs");a.append(o);const c=mn._svgFactory.createElement("path");o.append(c);const d=`path_p${this.pageIndex}_${s}`;c.setAttribute("id",d),c.setAttribute("vector-effect","non-scaling-stroke"),t&&this.#i.set(s,c);const f=n?this.#r(o,d):null,g=mn._svgFactory.createElement("use");return a.append(g),g.setAttribute("href",`#${d}`),this.updateProperties(a,e),this.#t.set(s,a),{id:s,clipPathId:`url(#${f})`}}drawOutline(e,t){const n=mn.#n++,s=this.#s(),a=mn._svgFactory.createElement("defs");s.append(a);const o=mn._svgFactory.createElement("path");a.append(o);const c=`path_p${this.pageIndex}_${n}`;o.setAttribute("id",c),o.setAttribute("vector-effect","non-scaling-stroke");let d;if(t){const w=mn._svgFactory.createElement("mask");a.append(w),d=`mask_p${this.pageIndex}_${n}`,w.setAttribute("id",d),w.setAttribute("maskUnits","objectBoundingBox");const b=mn._svgFactory.createElement("rect");w.append(b),b.setAttribute("width","1"),b.setAttribute("height","1"),b.setAttribute("fill","white");const E=mn._svgFactory.createElement("use");w.append(E),E.setAttribute("href",`#${c}`),E.setAttribute("stroke","none"),E.setAttribute("fill","black"),E.setAttribute("fill-rule","nonzero"),E.classList.add("mask")}const f=mn._svgFactory.createElement("use");s.append(f),f.setAttribute("href",`#${c}`),d&&f.setAttribute("mask",`url(#${d})`);const g=f.cloneNode();return s.append(g),f.classList.add("mainOutline"),g.classList.add("secondaryOutline"),this.updateProperties(s,e),this.#t.set(n,s),n}finalizeDraw(e,t){this.#i.delete(e),this.updateProperties(e,t)}updateProperties(e,t){if(!t)return;const{root:n,bbox:s,rootClass:a,path:o}=t,c=typeof e=="number"?this.#t.get(e):e;if(c){if(n&&this.#a(c,n),s&&mn.#A(c,s),a){const{classList:d}=c;for(const[f,g]of Object.entries(a))d.toggle(f,g)}if(o){const f=c.firstChild.firstChild;this.#a(f,o)}}}updateParent(e,t){if(t===this)return;const n=this.#t.get(e);n&&(t.#e.append(n),this.#t.delete(e),t.#t.set(e,n))}remove(e){this.#i.delete(e),this.#e!==null&&(this.#t.get(e).remove(),this.#t.delete(e))}destroy(){this.#e=null;for(const e of this.#t.values())e.remove();this.#t.clear(),this.#i.clear()}}globalThis._pdfjsTestingUtils={HighlightOutliner:Rh},globalThis.pdfjsLib={AbortException:J3,AnnotationEditorLayer:f3,AnnotationEditorParamsType:yt,AnnotationEditorType:st,AnnotationEditorUIManager:W3,AnnotationLayer:Ph,AnnotationMode:l3,AnnotationType:H2,applyOpacity:J6,build:Np,ColorPicker:zi,createValidAbsoluteUrl:oh,CSSConstants:X6,DOMSVGFactory:el,DrawLayer:mn,FeatureTest:pn,fetchData:ra,findContrastColor:_6,getDocument:Nh,getFilenameFromUrl:z6,getPdfFilenameFromUrl:G6,getRGB:Aa,getUuid:hh,getXfaPageViewport:K6,GlobalWorkerOptions:Or,ImageKind:Uo,InvalidPDFException:iu,isDataScheme:zo,isPdfFile:ru,isValidExplicitDest:ip,MathClamp:Rn,noContextMenu:Ri,normalizeUnicode:R6,OPS:sa,OutputScale:Fs,PasswordResponses:U6,PDFDataRangeTransport:jh,PDFDateString:Au,PDFWorker:ha,PermissionFlag:Q6,PixelsPerInch:G0,RenderingCancelledException:su,renderRichText:mh,ResponseException:ko,setLayerDimensions:Ur,shadow:ut,SignatureExtractor:J0,stopEvent:B2,SupportedImageMimeTypes:au,TextLayer:Zo,TouchManager:Xo,updateUrlHash:lh,Util:be,VerbosityLevel:Oo,version:Qh,XfaLayer:ph};const Av=Object.freeze(Object.defineProperty({__proto__:null,AbortException:J3,AnnotationEditorLayer:f3,AnnotationEditorParamsType:yt,AnnotationEditorType:st,AnnotationEditorUIManager:W3,AnnotationLayer:Ph,AnnotationMode:l3,AnnotationType:H2,CSSConstants:X6,ColorPicker:zi,DOMSVGFactory:el,DrawLayer:mn,FeatureTest:pn,GlobalWorkerOptions:Or,ImageKind:Uo,InvalidPDFException:iu,MathClamp:Rn,OPS:sa,OutputScale:Fs,PDFDataRangeTransport:jh,PDFDateString:Au,PDFWorker:ha,PasswordResponses:U6,PermissionFlag:Q6,PixelsPerInch:G0,RenderingCancelledException:su,ResponseException:ko,SignatureExtractor:J0,SupportedImageMimeTypes:au,TextLayer:Zo,TouchManager:Xo,Util:be,VerbosityLevel:Oo,XfaLayer:ph,applyOpacity:J6,build:Np,createValidAbsoluteUrl:oh,fetchData:ra,findContrastColor:_6,getDocument:Nh,getFilenameFromUrl:z6,getPdfFilenameFromUrl:G6,getRGB:Aa,getUuid:hh,getXfaPageViewport:K6,isDataScheme:zo,isPdfFile:ru,isValidExplicitDest:ip,noContextMenu:Ri,normalizeUnicode:R6,renderRichText:mh,setLayerDimensions:Ur,shadow:ut,stopEvent:B2,updateUrlHash:lh,version:Qh},Symbol.toStringTag,{value:"Module"}));function Gp(A){var e,t,n="";if(typeof A=="string"||typeof A=="number")n+=A;else if(typeof A=="object")if(Array.isArray(A)){var s=A.length;for(e=0;e<s;e++)A[e]&&(t=Gp(A[e]))&&(n&&(n+=" "),n+=t)}else for(t in A)A[t]&&(n&&(n+=" "),n+=t);return n}function Cu(){for(var A,e,t=0,n="",s=arguments.length;t<s;t++)(A=arguments[t])&&(e=Gp(A))&&(n&&(n+=" "),n+=e);return n}var Yp=Object.prototype.hasOwnProperty;function Kp(A,e,t){for(t of A.keys())if(pa(t,e))return t}function pa(A,e){var t,n,s;if(A===e)return!0;if(A&&e&&(t=A.constructor)===e.constructor){if(t===Date)return A.getTime()===e.getTime();if(t===RegExp)return A.toString()===e.toString();if(t===Array){if((n=A.length)===e.length)for(;n--&&pa(A[n],e[n]););return n===-1}if(t===Set){if(A.size!==e.size)return!1;for(n of A)if(s=n,s&&typeof s=="object"&&(s=Kp(e,s),!s)||!e.has(s))return!1;return!0}if(t===Map){if(A.size!==e.size)return!1;for(n of A)if(s=n[0],s&&typeof s=="object"&&(s=Kp(e,s),!s)||!pa(n[1],e.get(s)))return!1;return!0}if(t===ArrayBuffer)A=new Uint8Array(A),e=new Uint8Array(e);else if(t===DataView){if((n=A.byteLength)===e.byteLength)for(;n--&&A.getInt8(n)===e.getInt8(n););return n===-1}if(ArrayBuffer.isView(A)){if((n=A.byteLength)===e.byteLength)for(;n--&&A[n]===e[n];);return n===-1}if(!t||typeof A=="object"){n=0;for(t in A)if(Yp.call(A,t)&&++n&&!Yp.call(e,t)||!(t in e)||!pa(A[t],e[t]))return!1;return Object.keys(e).length===n}}return A!==A&&e!==e}function il(A){let e=!1;return{promise:new Promise((n,s)=>{A.then(a=>!e&&n(a)).catch(a=>!e&&s(a))}),cancel(){e=!0}}}const av=["onCopy","onCut","onPaste"],ov=["onCompositionEnd","onCompositionStart","onCompositionUpdate"],lv=["onFocus","onBlur"],cv=["onInput","onInvalid","onReset","onSubmit"],uv=["onLoad","onError"],dv=["onKeyDown","onKeyPress","onKeyUp"],hv=["onAbort","onCanPlay","onCanPlayThrough","onDurationChange","onEmptied","onEncrypted","onEnded","onError","onLoadedData","onLoadedMetadata","onLoadStart","onPause","onPlay","onPlaying","onProgress","onRateChange","onSeeked","onSeeking","onStalled","onSuspend","onTimeUpdate","onVolumeChange","onWaiting"],fv=["onClick","onContextMenu","onDoubleClick","onMouseDown","onMouseEnter","onMouseLeave","onMouseMove","onMouseOut","onMouseOver","onMouseUp"],pv=["onDrag","onDragEnd","onDragEnter","onDragExit","onDragLeave","onDragOver","onDragStart","onDrop"],gv=["onSelect"],mv=["onTouchCancel","onTouchEnd","onTouchMove","onTouchStart"],wv=["onPointerDown","onPointerMove","onPointerUp","onPointerCancel","onGotPointerCapture","onLostPointerCapture","onPointerEnter","onPointerLeave","onPointerOver","onPointerOut"],vv=["onScroll"],Cv=["onWheel"],yv=["onAnimationStart","onAnimationEnd","onAnimationIteration"],bv=["onTransitionEnd"],Bv=["onToggle"],xv=["onChange"],Iv=[...av,...ov,...lv,...cv,...uv,...dv,...hv,...fv,...pv,...gv,...mv,...wv,...vv,...Cv,...yv,...bv,...xv,...Bv];function Xp(A,e){const t={};for(const n of Iv){const s=A[n];s&&(e?t[n]=(a=>s(a,e(n))):t[n]=s)}return t}var Ev="Invariant failed";function o2(A,e){if(!A)throw new Error(Ev)}var Xh,Jp;function Sv(){if(Jp)return Xh;Jp=1;var A=function(){};return Xh=A,Xh}var Mv=Sv();const Hn=F2(Mv),Vp=G.createContext(null),Lv="noopener noreferrer nofollow";class Dv{constructor(){this.externalLinkEnabled=!0,this.externalLinkRel=void 0,this.externalLinkTarget=void 0,this.isInPresentationMode=!1,this.pdfDocument=void 0,this.pdfViewer=void 0}setDocument(e){this.pdfDocument=e}setViewer(e){this.pdfViewer=e}setExternalLinkRel(e){this.externalLinkRel=e}setExternalLinkTarget(e){this.externalLinkTarget=e}setHash(){}setHistory(){}get pagesCount(){return this.pdfDocument?this.pdfDocument.numPages:0}get page(){return o2(this.pdfViewer),this.pdfViewer.currentPageNumber||0}set page(e){o2(this.pdfViewer),this.pdfViewer.currentPageNumber=e}get rotation(){return 0}set rotation(e){}addLinkAttributes(e,t,n){e.href=t,e.rel=this.externalLinkRel||Lv,e.target=n?"_blank":this.externalLinkTarget||""}goToDestination(e){return new Promise(t=>{o2(this.pdfDocument),o2(e),typeof e=="string"?this.pdfDocument.getDestination(e).then(t):Array.isArray(e)?t(e):e.then(t)}).then(t=>{o2(Array.isArray(t));const n=t[0];new Promise(s=>{o2(this.pdfDocument),n instanceof Object?this.pdfDocument.getPageIndex(n).then(a=>{s(a)}).catch(()=>{o2(!1)}):typeof n=="number"?s(n):o2(!1)}).then(s=>{const a=s+1;o2(this.pdfViewer),o2(a>=1&&a<=this.pagesCount),this.pdfViewer.scrollPageIntoView({dest:t,pageIndex:s,pageNumber:a})})})}goToPage(e){const t=e-1;o2(this.pdfViewer),o2(e>=1&&e<=this.pagesCount),this.pdfViewer.scrollPageIntoView({pageIndex:t,pageNumber:e})}goToXY(){}cachePageRef(){}getDestinationHash(){return"#"}getAnchorUrl(){return"#"}executeNamedAction(){}executeSetOCGState(){}isPageVisible(){return!0}isPageCached(){return!0}navigateTo(e){this.goToDestination(e)}}function ga({children:A,type:e}){return u.jsx("div",{className:`react-pdf__message react-pdf__message--${e}`,children:A})}const Wp={NEED_PASSWORD:1,INCORRECT_PASSWORD:2};function Fv(A,e){switch(e.type){case"RESOLVE":return{value:e.value,error:void 0};case"REJECT":return{value:!1,error:e.error};case"RESET":return{value:void 0,error:void 0};default:return A}}function ma(){return G.useReducer(Fv,{value:void 0,error:void 0})}const yu=typeof window<"u",qp=yu&&window.location.protocol==="file:";function Nv(A){return typeof A<"u"}function V0(A){return Nv(A)&&A!==null}function Tv(A){return typeof A=="string"}function jv(A){return A instanceof ArrayBuffer}function Qv(A){return o2(yu),A instanceof Blob}function Jh(A){return Tv(A)&&/^data:/.test(A)}function Zp(A){o2(Jh(A));const[e="",t=""]=A.split(",");return e.split(";").indexOf("base64")!==-1?atob(t):unescape(t)}function Uv(){return yu&&window.devicePixelRatio||1}const _p="On Chromium based browsers, you can use --allow-file-access-from-files flag for debugging purposes.";function $p(){Hn(!qp,`Loading PDF as base64 strings/URLs may not work on protocols other than HTTP/HTTPS. ${_p}`)}function Ov(){Hn(!qp,`Loading PDF.js worker may not work on protocols other than HTTP/HTTPS. ${_p}`)}function W0(A){A?.cancel&&A.cancel()}function Vh(A,e){return Object.defineProperty(A,"width",{get(){return this.getViewport({scale:e}).width},configurable:!0}),Object.defineProperty(A,"height",{get(){return this.getViewport({scale:e}).height},configurable:!0}),Object.defineProperty(A,"originalWidth",{get(){return this.getViewport({scale:1}).width},configurable:!0}),Object.defineProperty(A,"originalHeight",{get(){return this.getViewport({scale:1}).height},configurable:!0}),A}function e5(A){return A.name==="AbortException"||A.name==="RenderingCancelledException"}function kv(A){return new Promise((e,t)=>{const n=new FileReader;n.onload=()=>{if(!n.result)return t(new Error("Error while reading a file."));e(n.result)},n.onerror=s=>{if(!s.target)return t(new Error("Error while reading a file."));const{error:a}=s.target;if(!a)return t(new Error("Error while reading a file."));switch(a.code){case a.NOT_FOUND_ERR:return t(new Error("Error while reading a file: File not found."));case a.SECURITY_ERR:return t(new Error("Error while reading a file: Security error."));case a.ABORT_ERR:return t(new Error("Error while reading a file: Aborted."));default:return t(new Error("Error while reading a file."))}},n.readAsArrayBuffer(A)})}const{PDFDataRangeTransport:Pv}=Av,Rv=(A,e)=>{switch(e){case Wp.NEED_PASSWORD:{const t=prompt("Enter the password to open this PDF file.");A(t);break}case Wp.INCORRECT_PASSWORD:{const t=prompt("Invalid password. Please try again.");A(t);break}}};function t5(A){return typeof A=="object"&&A!==null&&("data"in A||"range"in A||"url"in A)}const Hv=G.forwardRef(function({children:e,className:t,error:n="Failed to load PDF file.",externalLinkRel:s,externalLinkTarget:a,file:o,inputRef:c,imageResourcesPath:d,loading:f="Loading PDF…",noData:g="No PDF file specified.",onItemClick:w,onLoadError:b,onLoadProgress:E,onLoadSuccess:M,onPassword:S=Rv,onSourceError:j,onSourceSuccess:F,options:z,renderMode:J,rotate:Y,scale:H,...W},_){const[l1,r1]=ma(),{value:f1,error:p1}=l1,[b1,N1]=ma(),{value:B1,error:T1}=b1,$=G.useRef(new Dv),u1=G.useRef([]),x1=G.useRef(void 0),P1=G.useRef(void 0);o&&o!==x1.current&&t5(o)&&(Hn(!pa(o,x1.current),`File prop passed to <Document /> changed, but it's equal to previous one. This might result in unnecessary reloads. Consider memoizing the value passed to "file" prop.`),x1.current=o),z&&z!==P1.current&&(Hn(!pa(z,P1.current),`Options prop passed to <Document /> changed, but it's equal to previous one. This might result in unnecessary reloads. Consider memoizing the value passed to "options" prop.`),P1.current=z);const Z=G.useRef({scrollPageIntoView:ue=>{const{dest:he,pageNumber:C1,pageIndex:R1=C1-1}=ue;if(w){w({dest:he,pageIndex:R1,pageNumber:C1});return}const se=u1.current[R1];if(se){se.scrollIntoView();return}Hn(!1,`An internal link leading to page ${C1} was clicked, but neither <Document> was provided with onItemClick nor it was able to find the page within itself. Either provide onItemClick to <Document> and handle navigating by yourself or ensure that all pages are rendered within <Document>.`)}});G.useImperativeHandle(_,()=>({linkService:$,pages:u1,viewer:Z}),[]);function w1(){F&&F()}function L1(){p1&&(Hn(!1,p1.toString()),j&&j(p1))}function S1(){r1({type:"RESET"})}G.useEffect(S1,[o,r1]);const z1=G.useCallback(async()=>{if(!o)return null;if(typeof o=="string")return Jh(o)?{data:Zp(o)}:($p(),{url:o});if(o instanceof Pv)return{range:o};if(jv(o))return{data:o};if(yu&&Qv(o))return{data:await kv(o)};if(o2(typeof o=="object"),o2(t5(o)),"url"in o&&typeof o.url=="string"){if(Jh(o.url)){const{url:ue,...he}=o;return{data:Zp(ue),...he}}$p()}return o},[o]);G.useEffect(()=>{const ue=il(z1());return ue.promise.then(he=>{r1({type:"RESOLVE",value:he})}).catch(he=>{r1({type:"REJECT",error:he})}),()=>{W0(ue)}},[z1,r1]),G.useEffect(()=>{if(!(typeof f1>"u")){if(f1===!1){L1();return}w1()}},[f1]);function H1(){B1&&(M&&M(B1),u1.current=new Array(B1.numPages),$.current.setDocument(B1))}function G1(){T1&&(Hn(!1,T1.toString()),b&&b(T1))}G.useEffect(function(){N1({type:"RESET"})},[N1,f1]),G.useEffect(function(){if(!f1)return;const he=z?{...f1,...z}:f1,C1=Nh(he);E&&(C1.onProgress=E),S&&(C1.onPassword=S);const R1=C1;return R1.promise.then(se=>{R1.destroyed||N1({type:"RESOLVE",value:se})}).catch(se=>{R1.destroyed||N1({type:"REJECT",error:se})}),()=>{R1.destroy()}},[z,N1,f1]),G.useEffect(()=>{if(!(typeof B1>"u")){if(B1===!1){G1();return}H1()}},[B1]),G.useEffect(function(){$.current.setViewer(Z.current),$.current.setExternalLinkRel(s),$.current.setExternalLinkTarget(a)},[s,a]);const F1=G.useCallback((ue,he)=>{u1.current[ue]=he},[]),K1=G.useCallback(ue=>{delete u1.current[ue]},[]),pe=G.useMemo(()=>({imageResourcesPath:d,linkService:$.current,onItemClick:w,pdf:B1,registerPage:F1,renderMode:J,rotate:Y,scale:H,unregisterPage:K1}),[d,w,B1,F1,J,Y,H,K1]),Ce=G.useMemo(()=>Xp(W,()=>B1),[W,B1]);function ge(){function ue(C1){return!!C1?.pdf}if(!ue(pe))throw new Error("pdf is undefined");const he=typeof e=="function"?e(pe):e;return u.jsx(Vp.Provider,{value:pe,children:he})}function oe(){return o?B1==null?u.jsx(ga,{type:"loading",children:typeof f=="function"?f():f}):B1===!1?u.jsx(ga,{type:"error",children:typeof n=="function"?n():n}):ge():u.jsx(ga,{type:"no-data",children:typeof g=="function"?g():g})}return u.jsx("div",{className:Cu("react-pdf__Document",t),ref:c,...Ce,children:oe()})});function n5(){return G.useContext(Vp)}function i5(){for(var A=[],e=0;e<arguments.length;e++)A[e]=arguments[e];var t=A.filter(Boolean);if(t.length<=1){var n=t[0];return n||null}return function(a){for(var o=0,c=t;o<c.length;o++){var d=c[o];typeof d=="function"?d(a):d&&(d.current=a)}}}const s5=G.createContext(null);function bu(){return G.useContext(s5)}function zv(){const A=n5(),e=bu();o2(e);const t={...A,...e},{filterAnnotations:n,imageResourcesPath:s,linkService:a,onGetAnnotationsError:o,onGetAnnotationsSuccess:c,onRenderAnnotationLayerError:d,onRenderAnnotationLayerSuccess:f,page:g,pdf:w,renderForms:b,rotate:E,scale:M=1}=t;o2(w),o2(g),o2(a);const[S,j]=ma(),{value:F,error:z}=S,J=G.useRef(null);Hn(Number.parseInt(window.getComputedStyle(document.body).getPropertyValue("--react-pdf-annotation-layer"),10)===1,"AnnotationLayer styles not found. Read more: https://github.com/wojtekmaj/react-pdf#support-for-annotations");function Y(){F&&c&&c(F)}function H(){z&&(Hn(!1,z.toString()),o&&o(z))}G.useEffect(function(){j({type:"RESET"})},[j,g]),G.useEffect(function(){if(!g)return;const f1=il(g.getAnnotations()),p1=f1;return f1.promise.then(b1=>{j({type:"RESOLVE",value:b1})}).catch(b1=>{j({type:"REJECT",error:b1})}),()=>{W0(p1)}},[j,g]),G.useEffect(()=>{if(F!==void 0){if(F===!1){H();return}Y()}},[F]);function W(){f&&f()}function _(r1){Hn(!1,`${r1}`),d&&d(r1)}const l1=G.useMemo(()=>g.getViewport({scale:M,rotation:E}),[g,E,M]);return G.useEffect(function(){if(!w||!g||!a||!F)return;const{current:f1}=J;if(!f1)return;const p1=l1.clone({dontFlip:!0}),b1={accessibilityManager:null,annotationCanvasMap:null,annotationEditorUIManager:null,annotationStorage:w.annotationStorage,commentManager:null,div:f1,l10n:null,linkService:a,page:g,structTreeLayer:null,viewport:p1},N1={annotations:n?n({annotations:F}):F,annotationStorage:w.annotationStorage,div:f1,imageResourcesPath:s,linkService:a,page:g,renderForms:b,viewport:p1};f1.innerHTML="";try{new Ph(b1).render(N1),W()}catch(B1){_(B1)}return()=>{}},[F,n,s,a,g,w,b,l1]),u.jsx("div",{className:Cu("react-pdf__Page__annotations","annotationLayer"),ref:J})}const r5={Document:null,DocumentFragment:null,Part:"group",Sect:"group",Div:"group",Aside:"note",NonStruct:"none",P:null,H:"heading",Title:null,FENote:"note",Sub:"group",Lbl:null,Span:null,Em:null,Strong:null,Link:"link",Annot:"note",Form:"form",Ruby:null,RB:null,RT:null,RP:null,Warichu:null,WT:null,WP:null,L:"list",LI:"listitem",LBody:null,Table:"table",TR:"row",TH:"columnheader",TD:"cell",THead:"columnheader",TBody:null,TFoot:null,Caption:null,Figure:"figure",Formula:null,Artifact:null},Gv=/^H(\d+)$/;function Yv(A){return A in r5}function Bu(A){return"children"in A}function A5(A){return Bu(A)?A.children.length===1&&0 in A.children&&"id"in A.children[0]:!1}function Kv(A){const e={};if(Bu(A)){const{role:t}=A,n=t.match(Gv);if(n)e.role="heading",e["aria-level"]=Number(n[1]);else if(Yv(t)){const s=r5[t];s&&(e.role=s)}}return e}function a5(A){const e={};if(Bu(A)){if(A.alt!==void 0&&(e["aria-label"]=A.alt),A.lang!==void 0&&(e.lang=A.lang),A5(A)){const[t]=A.children;if(t){const n=a5(t);return{...e,...n}}}}else"id"in A&&(e["aria-owns"]=A.id);return e}function Xv(A){return A?{...Kv(A),...a5(A)}:null}function o5({className:A,node:e}){const t=G.useMemo(()=>Xv(e),[e]),n=G.useMemo(()=>!Bu(e)||A5(e)?null:e.children.map((s,a)=>u.jsx(o5,{node:s},a)),[e]);return u.jsx("span",{className:A,...t,children:n})}function Jv(){const A=bu();o2(A);const{onGetStructTreeError:e,onGetStructTreeSuccess:t}=A,[n,s]=ma(),{value:a,error:o}=n,{customTextRenderer:c,page:d}=A;function f(){a&&t&&t(a)}function g(){o&&(Hn(!1,o.toString()),e&&e(o))}return G.useEffect(function(){s({type:"RESET"})},[s,d]),G.useEffect(function(){if(c||!d)return;const b=il(d.getStructTree()),E=b;return b.promise.then(M=>{s({type:"RESOLVE",value:M})}).catch(M=>{s({type:"REJECT",error:M})}),()=>W0(E)},[c,d,s]),G.useEffect(()=>{if(a!==void 0){if(a===!1){g();return}f()}},[a]),a?u.jsx(o5,{className:"react-pdf__Page__structTree structTree",node:a}):null}const l5=l3;function Vv(A){const e=bu();o2(e);const t={...e,...A},{_className:n,canvasBackground:s,devicePixelRatio:a=Uv(),onRenderError:o,onRenderSuccess:c,page:d,renderForms:f,renderTextLayer:g,pageColors:w,rotate:b,scale:E}=t,{canvasRef:M}=A;o2(d);const S=G.useRef(null);function j(){d&&c&&c(Vh(d,E))}function F(H){e5(H)||(Hn(!1,H.toString()),o&&o(H))}const z=G.useMemo(()=>d.getViewport({scale:E*a,rotation:b}),[a,d,b,E]),J=G.useMemo(()=>d.getViewport({scale:E,rotation:b}),[d,b,E]);G.useEffect(function(){if(!d)return;d.cleanup();const{current:W}=S;if(!W)return;W.width=z.width,W.height=z.height,W.style.width=`${Math.floor(J.width)}px`,W.style.height=`${Math.floor(J.height)}px`,W.style.visibility="hidden";const _={annotationMode:f?l5.ENABLE_FORMS:l5.ENABLE,canvas:W,canvasContext:W.getContext("2d",{alpha:!1}),pageColors:w,viewport:z};s&&(_.background=s);const l1=d.render(_),r1=l1;return l1.promise.then(()=>{W.style.visibility="",j()}).catch(F),()=>W0(r1)},[s,d,w,f,z,J]);const Y=G.useCallback(()=>{const{current:H}=S;H&&(H.width=0,H.height=0)},[]);return G.useEffect(()=>Y,[Y]),u.jsx("canvas",{className:`${n}__canvas`,dir:"ltr",ref:i5(M,S),style:{display:"block",userSelect:"none"},children:g?u.jsx(Jv,{}):null})}function Wv(A){return"str"in A}const qv=new Set(["base","embed","iframe","link","meta","object","script","style","template"]),Zv=new Set(["action","formaction","href","poster","src","xlink:href"]);function _v(A){let e="";for(const t of A){const n=t.charCodeAt(0);n<=32||n===127||(e+=t.toLowerCase())}return e.startsWith("javascript:")||e.startsWith("vbscript:")}function $v(A){return A.nodeType===Node.ELEMENT_NODE}function c5(A){return $v(A)&&A instanceof HTMLElement}function eC(A){return c5(A)&&qv.has(A.tagName.toLowerCase())}function tC(A){const e=document.createElement(A.tagName.toLowerCase());return Array.from(A.attributes).forEach(t=>{const n=t.name.toLowerCase();n.startsWith("on")||n==="srcdoc"||Zv.has(n)&&_v(t.value)||e.setAttribute(t.name,t.value)}),Array.from(A.childNodes).forEach(t=>{e.append(u5(t))}),e}function u5(A){var e;return c5(A)&&!eC(A)?tC(A):document.createTextNode((e=A.textContent)!==null&&e!==void 0?e:"")}function nC(A,e){const t=document.createElement("template");t.innerHTML=e;const n=document.createDocumentFragment();Array.from(t.content.childNodes).forEach(s=>{n.append(u5(s))}),A.replaceChildren(n)}function iC(){const A=bu();o2(A);const{customTextRenderer:e,onGetTextError:t,onGetTextSuccess:n,onRenderTextLayerError:s,onRenderTextLayerSuccess:a,page:o,pageIndex:c,pageNumber:d,rotate:f,scale:g}=A;o2(o);const[w,b]=ma(),{value:E,error:M}=w,S=G.useRef(null);Hn(Number.parseInt(window.getComputedStyle(document.body).getPropertyValue("--react-pdf-text-layer"),10)===1,"TextLayer styles not found. Read more: https://github.com/wojtekmaj/react-pdf#support-for-text-layer");function j(){E&&n&&n(E)}function F(){M&&(Hn(!1,M.toString()),t&&t(M))}G.useEffect(function(){b({type:"RESET"})},[o,b]),G.useEffect(function(){if(!o)return;const l1=il(o.getTextContent()),r1=l1;return l1.promise.then(f1=>{b({type:"RESOLVE",value:f1})}).catch(f1=>{b({type:"REJECT",error:f1})}),()=>W0(r1)},[o,b]),G.useEffect(()=>{if(E!==void 0){if(E===!1){F();return}j()}},[E]);const z=G.useCallback(()=>{a&&a()},[a]),J=G.useCallback(_=>{e5(_)||(Hn(!1,_.toString()),s&&s(_))},[s]);function Y(){const _=S.current;_&&_.classList.add("selecting")}function H(){const _=S.current;_&&_.classList.remove("selecting")}const W=G.useMemo(()=>o.getViewport({scale:g,rotation:f}),[o,f,g]);return G.useLayoutEffect(function(){if(!o||!E)return;const{current:l1}=S;if(!l1)return;l1.innerHTML="";const r1=o.streamTextContent({includeMarkedContent:!0}),f1={container:l1,textContentSource:r1,viewport:W},p1=new Zo(f1),b1=p1;return p1.render().then(()=>{const N1=document.createElement("div");N1.className="endOfContent",l1.append(N1);const B1=l1.querySelectorAll('[role="presentation"]');if(e){let T1=0;E.items.forEach(($,u1)=>{if(!Wv($))return;const x1=B1[T1];if(!x1)return;const P1=e({pageIndex:c,pageNumber:d,itemIndex:u1,...$});nC(x1,P1),T1+=$.str&&$.hasEOL?2:1})}z()}).catch(J),()=>W0(b1)},[e,J,z,o,c,d,E,W]),u.jsx("div",{className:Cu("react-pdf__Page__textContent","textLayer"),onMouseUp:H,onMouseDown:Y,ref:S})}const d5=1;function sC(A){const t={...n5(),...A},{_className:n="react-pdf__Page",_enableRegisterUnregisterPage:s=!0,canvasBackground:a,canvasRef:o,children:c,className:d,customRenderer:f,customTextRenderer:g,devicePixelRatio:w,error:b="Failed to load the page.",filterAnnotations:E,height:M,inputRef:S,loading:j="Loading page…",noData:F="No page specified.",onGetAnnotationsError:z,onGetAnnotationsSuccess:J,onGetStructTreeError:Y,onGetStructTreeSuccess:H,onGetTextError:W,onGetTextSuccess:_,onLoadError:l1,onLoadSuccess:r1,onRenderAnnotationLayerError:f1,onRenderAnnotationLayerSuccess:p1,onRenderError:b1,onRenderSuccess:N1,onRenderTextLayerError:B1,onRenderTextLayerSuccess:T1,pageColors:$,pageIndex:u1,pageNumber:x1,pdf:P1,registerPage:Z,renderAnnotationLayer:w1=!0,renderForms:L1=!1,renderMode:S1="canvas",renderTextLayer:z1=!0,rotate:H1,scale:G1=d5,unregisterPage:F1,width:K1,...pe}=t,[Ce,ge]=ma(),{value:oe,error:ue}=Ce,he=G.useRef(null);o2(P1);const C1=V0(x1)?x1-1:u1??null,R1=x1??(V0(u1)?u1+1:null),se=H1??(oe?oe.rotate:null),ae=G.useMemo(()=>{if(!oe)return null;let ke=1;const ht=G1??d5;if(K1||M){const at=oe.getViewport({scale:1,rotation:se});K1?ke=K1/at.width:M&&(ke=M/at.height)}return ht*ke},[M,oe,se,G1,K1]);G.useEffect(function(){return()=>{V0(C1)&&s&&F1&&F1(C1)}},[s,P1,C1,F1]);function ne(){if(r1){if(!oe||!ae)return;r1(Vh(oe,ae))}if(s&&Z){if(!V0(C1)||!he.current)return;Z(C1,he.current)}}function Ye(){ue&&(Hn(!1,ue.toString()),l1&&l1(ue))}G.useEffect(function(){ge({type:"RESET"})},[ge,P1,C1]),G.useEffect(function(){if(!P1||!R1)return;const ht=il(P1.getPage(R1)),at=ht;return ht.promise.then(_e=>{ge({type:"RESOLVE",value:_e})}).catch(_e=>{ge({type:"REJECT",error:_e})}),()=>W0(at)},[ge,P1,R1]),G.useEffect(()=>{if(oe!==void 0){if(oe===!1){Ye();return}ne()}},[oe,ae]);const Ne=G.useMemo(()=>V0(C1)&&R1&&V0(se)&&V0(ae)?{_className:n,canvasBackground:a,customTextRenderer:g,devicePixelRatio:w,filterAnnotations:E,onGetAnnotationsError:z,onGetAnnotationsSuccess:J,onGetStructTreeError:Y,onGetStructTreeSuccess:H,onGetTextError:W,onGetTextSuccess:_,onRenderAnnotationLayerError:f1,onRenderAnnotationLayerSuccess:p1,onRenderError:b1,onRenderSuccess:N1,onRenderTextLayerError:B1,onRenderTextLayerSuccess:T1,page:oe,pageColors:$,pageIndex:C1,pageNumber:R1,renderForms:L1,renderTextLayer:z1,rotate:se,scale:ae}:null,[n,a,g,w,E,z,J,Y,H,W,_,f1,p1,b1,N1,B1,T1,oe,$,C1,R1,L1,z1,se,ae]),qe=G.useMemo(()=>Xp(pe,()=>oe&&(ae?Vh(oe,ae):void 0)),[pe,oe,ae]),nt=`${C1}@${ae}/${se}`;function Je(){switch(S1){case"custom":return o2(f),u.jsx(f,{},`${nt}_custom`);case"none":return null;case"canvas":default:return u.jsx(Vv,{canvasRef:o},`${nt}_canvas`)}}function At(){return z1?u.jsx(iC,{},`${nt}_text`):null}function Ze(){return w1?u.jsx(zv,{},`${nt}_annotations`):null}function ce(){function ke(at){return!!at?.page}if(!ke(Ne))throw new Error("page is undefined");const ht=typeof c=="function"?c(Ne):c;return u.jsxs(s5.Provider,{value:Ne,children:[Je(),At(),Ze(),ht]})}function Ke(){return R1?P1===null||oe===void 0||oe===null?u.jsx(ga,{type:"loading",children:typeof j=="function"?j():j}):P1===!1||oe===!1?u.jsx(ga,{type:"error",children:typeof b=="function"?b():b}):ce():u.jsx(ga,{type:"no-data",children:typeof F=="function"?F():F})}return u.jsx("div",{className:Cu(n,d),"data-page-number":R1,ref:i5(S,he),style:{"--scale-round-x":"1px","--scale-round-y":"1px","--scale-factor":"1","--user-unit":`${ae}`,"--total-scale-factor":"calc(var(--scale-factor) * var(--user-unit))",backgroundColor:a||"white",position:"relative",minWidth:"min-content",minHeight:"min-content"},...qe,children:Ke()})}Ov(),Or.workerSrc="pdf.worker.mjs";function dt(A){return Number(A??0).toLocaleString("en-IN",{minimumFractionDigits:2,maximumFractionDigits:2})}Or.workerSrc=`https://unpkg.com/pdfjs-dist@${Qh}/build/pdf.worker.min.mjs`;const rC=({open:A,onClose:e,onPaymentCollected:t,selectedLenderIdx:n=-1,selectedLenderFiCode:s=null,selectedLenderTenureMappings:a=[],selectedLenderRepaymentOption:o=null,selectedLenderDisbursementAccount:c=null})=>{const{tenureMappings:d,payableValue:f,paymentType:g,paymentInvoice:w,invoices:b,chemistId:E,leadId:M,fiCode:S,typeOfApp:j,payerMobileNumber:F,salesmanId:z,distributorIdnum:J,distributorName:Y,drawdownRepaymentOption:H,creditLimitData:W}=ti(),_=a.length>0?a:d,[l1,r1]=G.useState(-1),[f1,p1]=G.useState(n);G.useEffect(()=>{n!==-1&&p1(n)},[n]);const[b1,N1]=G.useState(!1),B1=()=>{e()},T1=s||S,$=T1==="TRILLIONLOAN",u1=new Date;u1.setDate(u1.getDate()+1);const[x1,P1]=G.useState($?new Date:u1),[Z,w1]=G.useState(["","","","","",""]),L1=mi.useRef([]),[S1,z1]=G.useState(0),[H1,G1]=G.useState("idle"),[F1,K1]=G.useState(!1),[pe,Ce]=G.useState(!1),[ge,oe]=G.useState(""),[ue,he]=G.useState(""),[C1,R1]=G.useState(j==="FUNDLY_COLLECT_APP"||j==="FUNDLY_QR_COLLECT_APP"||j==="FUNDLY_QR_WEB"?"Collect":"Pay Now"),[se,ae]=G.useState(!1),[ne,Ye]=G.useState(null),[Ne,qe]=G.useState(null),[nt,Je]=G.useState(!1),[At,Ze]=G.useState(null),[ce,Ke]=G.useState([]),[ke,ht]=G.useState(!1),[at,_e]=G.useState(0),Ve=G.useCallback(le=>{const we=le.getFullYear(),gt=String(le.getMonth()+1).padStart(2,"0"),Ft=String(le.getDate()).padStart(2,"0");return`${we}-${gt}-${Ft}`},[]),Me=G.useCallback(async()=>{if(T1!=="TRILLIONLOAN"){ae(!1);return}ae(!0);try{const le=Pe(),we=s||S||"",gt=o||H||"BULLET",Ft=new URLSearchParams({loanAmount:String(f),businessId:E||"",openedOnDate:Ve(x1||u1),productType:"INSTACASH",tenureMagnitude:String(_[l1]?.tenureValue||""),tenureUnit:String(_[l1]?.tenureUnit||""),fiCode:we,repaymentOption:gt,supplierId:J||""});g==="INVOICE_COLLECT"&&w?.length>0&&Ft.append("invoiceNumber",w.map(S2=>S2.invoiceId).join(","));const ft=`${R0()}/kfs/report?${Ft.toString()}`,Et=await qt.get(ft,{headers:{accept:"application/json",Authorization:`Bearer ${le}`}});Ye(Et.data),qe(Et.data?.documentId??null),Je(!1)}catch(le){console.error("[Fundly Pay] Error fetching KFS:",le),Ye(null),qe(null),Je(!1)}finally{ae(!1)}},[s,S,o,H,f,E,x1,l1,_,J,g,w,Ve]),$1=G.useCallback(async()=>{if(T1==="TRILLIONLOAN")try{const le=Pe(),we=new URLSearchParams({businessId:E||"",intents:"DRAWDOWN_KFS_SIGN",fiCode:T1||""}),gt=`${R0()}/consent?${we.toString()}`,ft=(await qt.get(gt,{headers:{accept:"*/*","Content-Type":"application/json",Authorization:`Bearer ${le}`}})).data;if(Ke(Array.isArray(ft)?ft:[]),ft?.[0]?.consentMessage){let Et=ft[0].consentMessage;Et=Et.replace("{{lenderName}}",T1||""),Et=Et.replace("Drawdown Request Letter",'<span class="kfs-link" style="color:#16558B;text-decoration:underline;cursor:pointer">Drawdown Request Letter</span>'),Et=Et.replace("Sanction Letter",'<span class="kfs-link" style="color:#16558B;text-decoration:underline;cursor:pointer">Sanction Letter</span>'),Et=Et.replace("Key Fact Statement",'<span class="kfs-link" style="color:#16558B;text-decoration:underline;cursor:pointer">Key Fact Statement</span>'),Ze(Et)}}catch(le){console.error("[Fundly Pay] Error fetching consent:",le),Ze(null)}},[E]),xe=G.useCallback(async()=>{try{const le=Pe(),we=`${R0()}/consent`;await qt.post(we,{businessId:E||"",intent:"DRAWDOWN_KFS_SIGN",consents:ce.map(gt=>({consentId:gt.consentId,accepted:!0}))},{headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Bearer ${le}`}})}catch(le){console.error("[Fundly Pay] Error submitting consent:",le)}},[E,ce]),me=G.useCallback(()=>{ne&&ht(!0)},[ne]),$e=mi.useMemo(()=>ne?ne.kfsDocumentBytes?`data:application/pdf;base64,${ne.kfsDocumentBytes}`:ne.kfsDocumentUrl||ne.documentUrl||null:null,[ne]),vt=G.useRef(null);G.useEffect(()=>{const le=vt.current;if(!le)return;const we=gt=>{gt.target.classList.contains("kfs-link")&&me()};return le.addEventListener("click",we),()=>le.removeEventListener("click",we)},[me,At]);const Ut=async()=>{he("");try{F&&Y&&await Lm(F,Y)}catch(le){console.error("Error sending OTP:",le);const we=le,gt=we?.response?.data?.errorMessage||we?.response?.data?.message||we?.message||"Failed to send OTP. Please try again.";he(gt),G1("resend"),z1(0)}},en=async()=>{if(!navigator.onLine){Ce(!0),R1("Submit Again");return}if(Ce(!1),F1)return;if(K1(!0),!x1){console.error("[Fundly Pay] Payment date is required"),K1(!1);return}const le=x1.toISOString(),we=le.split("T")[0],gt=s||S,Ft={paymentMode:"FUNDLY_PAY",paymentDate:le,paymentType:g,distributorCode:J,...Ne&&{documentId:Ne},salesmanId:z,invoiceCount:w?.length||b?.length||0,loanDrawdownRequestDTO:{businessId:E||M,fiCode:gt,requestedAmount:f,scheduledDate:we,tenure:_[l1]?.tenureValue||"",tenureUnit:_[l1]?.tenureUnit?.replace(/s$/i,"")||"",invoiceIds:j==="FUNDLY_MART"||j==="FUNDLY_TRADE"?[]:g==="INVOICE_COLLECT"?w?.map(ft=>ft.invoiceId)??[]:b??[],sourceSystem:j,paymentType:g}};E&&E.trim()!==""?Ft.chemistBusinessId=E:M&&M.trim()!==""&&(Ft.leadId=M),g==="INVOICE_COLLECT"?Ft.paymentInvoice=w:g==="DIRECT_COLLECT"&&(Ft.invoiceIds=b,Ft.paidAmount=f),(j==="FUNDLY_COLLECT_APP"||j==="FUNDLY_QR_COLLECT_APP"||j==="FUNDLY_QR_WEB"||j==="FUNDLY_TRADE")&&(Ft.loanDrawdownRequestDTO.mobileNumber=F,Ft.loanDrawdownRequestDTO.loanInitiateOtp=Z.join("")),F&&(Ft.payerMobileNumber=F),T1==="TRILLIONLOAN"&&xe();try{const ft=await X3(Ft),Et=ft?.data||ft;Et&&!Et.scheduleDate&&(Et.scheduleDate=we),Et&&et?.lastRepaymentDate&&(Et.dueDate=et.lastRepaymentDate),t&&t(Et)}catch(ft){const Et=ft?.response?.data?.errorMessage||ft?.response?.data?.errorDesc||ft?.response?.data?.message||ft?.message||"Payment failed. Please try again.";oe(Et)}finally{K1(!1)}},E2=(le,we)=>{if(!/^[0-9]?$/.test(le))return;const gt=[...Z];gt[we]=le,w1(gt),le&&we<5&&L1.current[we+1]?.focus()},Jt=(le,we)=>{le.key==="Backspace"&&!Z[we]&&we>0&&L1.current[we-1]?.focus()},Qs=()=>{G1("countdown"),z1(30),Ut()};G.useEffect(()=>{if(H1==="countdown"&&S1>0){const le=setInterval(()=>{z1(we=>we-1)},1e3);return()=>clearInterval(le)}else H1==="countdown"&&S1===0&&(G1("resend"),Ut())},[S1,H1]);const Gt=mi.useMemo(()=>{if($&&se)return!0;const le=l1!==-1,we=x1!==null,gt=f1!==-1||!W?.subLimits,Ft=$?nt:!0;if(j==="FUNDLY_COLLECT_APP"||j==="FUNDLY_QR_COLLECT_APP"||j==="FUNDLY_QR_WEB"||j==="FUNDLY_TRADE"){const ft=Z.every(Et=>Et!=="");return!(le&&ft&&we&>&&Ft)}return!(le&&we&>&&Ft)},[l1,f1,Z,j,x1,W,nt,se]),[et,vn]=G.useState(null),[Nn,Bt]=G.useState(!1),tn=async()=>{if(l1===-1)return;const le=_[l1],we=s||S||"",gt=o||H||"BULLET",Ft=c||"SUPPLIER";Bt(!0);try{const ft=await Hm({loanAmount:Number(f),businessId:E||"",openedOnDate:Ve(x1||u1),productType:"INSTACASH",tenureMagnitude:le.tenureValue,tenureUnit:le.tenureUnit,fiCode:we,repaymentOption:gt,disbursementAccount:Ft});vn(ft)}catch(ft){console.error("Error fetching EMI:",ft),vn(null)}finally{Bt(!1)}};return G.useEffect(()=>{let le;return A&&l1!==-1&&f1!==-1&&(le=window.setTimeout(()=>{tn()},1e3)),()=>{clearTimeout(le)}},[l1,f1,x1]),G.useEffect(()=>{if(A){if(r1(0),$)P1(new Date),Je(!1);else{const le=new Date;le.setDate(le.getDate()+1),P1(le)}$1()}},[A,$1]),G.useEffect(()=>{if(!A||T1!=="TRILLIONLOAN")return;const le=window.setTimeout(()=>{Me()},400);return()=>clearTimeout(le)},[l1,x1,Me]),G.useEffect(()=>{const le=()=>{A&&l1!==-1&&(tn(),Me())};return window.addEventListener("online",le),()=>{window.removeEventListener("online",le)}},[A,l1,Me]),u.jsxs(wi,{open:A,onClose:B1,children:[u.jsxs("div",{style:{fontFamily:"Poppins"},className:"fp:w-full fp:px-4 fp:pt-6 fp:mb-12 ",children:[u.jsx("div",{className:"fp:w-full fp:flex fp:items-center fp:justify-end",children:u.jsx("img",{src:de.closingCross,className:"fp:w-4 fp:h-4 fp:cursor-pointer",onClick:()=>N1(!0)})}),ge&&u.jsxs("div",{className:"fp:w-full fp:bg-red-50 fp:border fp:border-red-200 fp:rounded-xl fp:p-3 fp:flex fp:items-start fp:space-x-2 fp:mt-4",children:[u.jsx("svg",{className:"fp:w-5 fp:h-5 fp:text-red-500 fp:flex-shrink-0 fp:mt-0.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),u.jsxs("div",{className:"fp:flex-1",children:[u.jsx("p",{className:"fp:text-[14px] fp:text-red-700 fp:font-medium",children:"Payment Failed"}),u.jsx("p",{className:"fp:text-[12px] fp:text-red-600 fp:mt-1",children:ge})]}),u.jsx("button",{onClick:()=>oe(""),className:"fp:text-red-400 fp:hover:text-red-600",children:u.jsx("svg",{className:"fp:w-4 fp:h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M6 18L18 6M6 6l12 12"})})})]}),u.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:mt-4 fp:space-y-4",children:[u.jsx("div",{children:u.jsx(jo,{value:x1,onChange:le=>P1(le),minDate:$?void 0:u1,label:"Select Payment Date",fullWidth:!0,disabled:$})}),u.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:space-y-2 ",children:[u.jsx("span",{className:"fp:text-[15px] fp:font-medium fp:text-[#222222]",children:"Tenure"}),u.jsx("div",{className:"fp:w-full fp:flex fp:space-x-4 ",children:_&&_.length>0?_.map((le,we)=>u.jsxs("button",{type:"button",className:`fp:py-1 fp:px-6 fp:border-[] fp:rounded-2xl fp:text-[14px] fp:font-medium fp:focus:outline-none fp:transition-colors fp:duration-150 ${l1===we?"fp:border-[#16558B] fp:bg-[#E6F0FA] fp:text-[#16558B]":"fp:border-[#D0D0D0] fp:text-gray-700 fp:bg-white"}`,onClick:()=>{r1(we)},children:[le.tenureValue," ",le.tenureUnit]},we)):u.jsx("span",{className:"fp:py-1 fp:px-6 fp:border-2 fp:rounded-2xl fp:text-[14px] fp:border-[#D0D0D0] fp:text-gray-700 fp:font-medium",children:"No tenure available"})})]}),!$&&u.jsxs("span",{className:"fp:text-[12px] fp:font-medium fp:text-green-600 fp:text-wrap",children:["₹",dt(f)," will be processed via Fundly Credit — a loan will be set up in retailer's account."]}),u.jsxs("div",{className:"fp:text-[12px] fp:w-full fp:border fp:p-4 fp:space-y-3 fp:rounded-2xl fp:flex fp:flex-col fp:border-[#E8EEF3] ",children:[u.jsxs("div",{className:"fp:flex fp:justify-between",children:[u.jsx("label",{className:"fp:text-gray-700",children:"Due date"}),u.jsx("label",{className:"fp:font-medium",children:et?.lastRepaymentDate?ta(et.lastRepaymentDate):"—"})]}),u.jsxs("div",{className:"fp:flex fp:justify-between",children:[u.jsx("label",{className:"fp:text-gray-700",children:"ROI (Annualised)"}),u.jsx("label",{className:"fp:font-medium",children:et?.normalInterestRate!=null?`${et.normalInterestRate}%`:"—"})]}),u.jsxs("div",{className:"fp:flex fp:justify-between",children:[u.jsx("label",{className:"fp:text-gray-700",children:"Interest/₹ 10,000/day"}),u.jsx("label",{className:"fp:font-medium",children:et?.interestPerDay!=null?`₹${et.interestPerDay}`:"—"})]}),u.jsxs("div",{className:"fp:flex fp:justify-between",children:[u.jsx("label",{className:"fp:text-gray-700",children:"Penal Charges"}),u.jsx("label",{className:"fp:font-medium",children:et?.penalInterestRate!=null?`${et.penalInterestRate}% p.a`:"—"})]}),u.jsxs("div",{className:"fp:flex fp:justify-between",children:[u.jsx("label",{className:"fp:text-gray-700",children:"Processing Fee"}),u.jsx("label",{className:"fp:font-medium",children:et?.processingFeeExclGst!=null?`₹${Number(et.processingFeeExclGst).toLocaleString("en-IN")}`:"—"})]}),u.jsxs("div",{className:"fp:flex fp:justify-between",children:[u.jsx("label",{className:"fp:text-gray-700",children:"APR"}),u.jsx("label",{className:"fp:font-medium",children:et?.apr!=null?`${et.apr}%`:"—"})]}),u.jsxs("div",{className:"fp:flex fp:justify-between",children:[u.jsx("label",{className:"fp:text-gray-700",children:"Net Disbursed Amount"}),u.jsx("label",{className:"fp:font-medium",children:et?.creditedAmount!=null?`₹${Number(et.creditedAmount).toLocaleString("en-IN")}`:"—"})]})]}),(j==="FUNDLY_COLLECT_APP"||j==="FUNDLY_QR_COLLECT_APP"||j==="FUNDLY_QR_WEB"||j==="FUNDLY_TRADE")&&u.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:space-y-4 fp:border-2 fp:border-[#E8EEF3] fp:mt-2 fp:rounded-2xl fp:p-3",children:[u.jsx("label",{className:"fp:font-medium fp:text-[15px]",children:"Retailer Verification"}),u.jsxs("div",{className:"fp:w-full fp:flex fp:space-x-2 fp:justify-between",children:[u.jsx("div",{className:"fp:flex fp:border-2 fp:rounded-lg fp:px-1 fp:space-x-2 ",children:Z.map((le,we)=>u.jsx("input",{type:"text",value:le,maxLength:1,placeholder:"●",ref:gt=>{L1.current[we]=gt},onChange:gt=>E2(gt.target.value,we),onKeyDown:gt=>Jt(gt,we),className:"fp:w-7 fp:h-8 fp:text-center fp:text-[16px] fp:outline-none"},we))}),u.jsxs("button",{onClick:Qs,disabled:H1==="countdown",className:`fp:text-white fp:text-[12px] fp:px-7 fp:rounded-lg ${H1==="resend"?"fp:bg-gray-500":"fp:bg-[#16558B]"}`,children:[H1==="idle"&&"Get OTP",H1==="countdown"&&`${S1}s`,H1==="resend"&&"Resend"]})]}),ue?u.jsxs("div",{className:"fp:w-full fp:bg-red-50 fp:border fp:border-red-200 fp:rounded-lg fp:p-2 fp:flex fp:items-start fp:space-x-2",children:[u.jsx("svg",{className:"fp:w-4 fp:h-4 fp:text-red-500 fp:flex-shrink-0 fp:mt-0.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),u.jsx("p",{className:"fp:text-[11px] fp:text-red-700",children:ue})]}):u.jsxs("label",{className:"fp:text-[13px] fp:flex fp:text-center fp:items-center fp:text-[#16558B]",children:[u.jsx("img",{src:de.info,className:"fp:w-4 fp:h-4 fp:mr-1"}),H1==="idle"?"OTP will be sent to the retailer for consent.":"An OTP has been sent to the retailer for consent."]})]}),At&&u.jsx("div",{ref:vt,className:"fp:text-[12px] fp:text-gray-600 fp:leading-relaxed fp:select-none",dangerouslySetInnerHTML:{__html:At}}),$&&u.jsxs("label",{className:"fp:flex fp:items-start fp:space-x-2 fp:cursor-pointer",children:[u.jsx("input",{type:"checkbox",checked:nt,onChange:le=>{const we=le.target.checked;Je(we),we&&me()},className:"fp:mt-0.5 fp:w-4 fp:h-4 fp:flex-shrink-0 fp:accent-[#16558B]"}),u.jsxs("span",{className:"fp:text-[12px] fp:text-gray-700",children:["I agree to the loan terms and accept the"," ",u.jsx("span",{className:"fp:text-[#16558B] fp:underline fp:cursor-pointer",onClick:le=>{le.preventDefault(),me()},children:"Key Fact Statement (KFS)"})]})]}),pe&&u.jsx("span",{className:"fp:text-red-500 fp:text-[12px] fp:mt-1",children:"We couldn't process your payment due to a network error. Please retry."}),u.jsx("button",{className:`fp:w-full fp:h-12 fp:mt-4 fp:rounded-lg fp:text-[16px] fp:flex fp:items-center fp:justify-center
|
|
673
673
|
${Gt||F1?"fp:bg-gray-400 fp:text-white fp:cursor-not-allowed":"fp:bg-[#16558B] fp:text-white"}`,onClick:()=>{!Gt&&!F1&&en()},disabled:Gt||F1,children:F1?"Processing...":C1})]})]}),ke&&$e&&v8.createPortal(u.jsx("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,zIndex:99999,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.6)"},onClick:()=>ht(!1),children:u.jsxs("div",{style:{backgroundColor:"#fff",borderRadius:window.innerWidth<=480?0:"16px",display:"flex",flexDirection:"column",width:window.innerWidth<=480?"100%":"70%",height:window.innerWidth<=480?"100%":"80%",maxWidth:"700px",overflow:"hidden",boxShadow:window.innerWidth<=480?"none":"0 8px 32px rgba(0,0,0,0.2)"},onClick:le=>le.stopPropagation(),children:[u.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",borderBottom:"1px solid #E8EEF3",fontFamily:"Poppins",flexShrink:0},children:[u.jsx("span",{style:{fontSize:"16px",fontWeight:600,color:"#222",fontFamily:"Poppins"},children:"Key Fact Statement"}),u.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[u.jsx("button",{onClick:()=>Lt.shareByteImage($e||"","KFS Document","KFS_Document"),style:{padding:"4px",display:"flex",alignItems:"center",justifyContent:"center",background:"none",border:"none",cursor:"pointer"},children:u.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"#16558B",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:[u.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),u.jsx("polyline",{points:"7 10 12 15 17 10"}),u.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})}),u.jsx("button",{onClick:()=>ht(!1),style:{padding:"4px",background:"none",border:"none",cursor:"pointer"},children:u.jsx("img",{src:de.closingCross,style:{width:"20px",height:"20px"}})})]})]}),u.jsx("div",{style:{flex:1,overflowY:"auto",display:"flex",flexDirection:"column",alignItems:"center",backgroundColor:"#f5f5f5"},children:u.jsx(Hv,{file:$e,onLoadSuccess:({numPages:le})=>_e(le),loading:u.jsx("div",{style:{padding:"20px",color:"#666",fontFamily:"Poppins"},children:"Loading..."}),error:u.jsx("div",{style:{padding:"20px",color:"red",fontFamily:"Poppins"},children:"Failed to load PDF."}),children:Array.from({length:at},(le,we)=>u.jsx("div",{style:{marginBottom:"8px"},children:u.jsx(sC,{pageNumber:we+1,width:typeof window<"u"?Math.min(window.innerWidth,500)-16:350,renderTextLayer:!1,renderAnnotationLayer:!1})},we+1))})})]})}),document.body),u.jsxs(vi,{open:b1,onClose:()=>N1(!1),children:[u.jsx(Ci,{children:u.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:justify-center fp:items-center",children:[u.jsx("img",{src:de.Gateway,className:"fp:w-15 fp:h-15"}),u.jsx("span",{style:{fontFamily:"Poppins"},className:"fp:text-[16px] fp:mt-3 fp:text-wrap fp:font-semibold fp:text-center fp:text-[#222222]",children:"Payment has not been completed. Do you still want to close?"})]})}),u.jsx(ns,{children:u.jsxs("div",{className:"fp:w-full fp:flex fp:justify-between fp:px-3 fp:mb-3 fp:gap-3",children:[u.jsx("button",{style:{fontFamily:"Poppins"},className:"fp:flex-1 fp:h-[48px] fp:text-[18px] fp:border-2 fp:border-gray-300 fp:text-gray-400 fp:rounded-xl",onClick:()=>{N1(!1),B1()},children:"Exit"}),u.jsx("button",{style:{fontFamily:"Poppins"},className:"fp:flex-1 fp:h-[48px] fp:text-[18px] fp:bg-[#16558B] fp:text-white fp:rounded-xl",onClick:()=>N1(!1),children:"Continue"})]})})]})]})},AC=({open:A,onClose:e})=>{const{distributorName:t,chemistName:n,paymentType:s,paymentInvoice:a,invoices:o,payableValue:c,salesmanId:d,salesmanPhoneNumber:f,distributorIdnum:g,chemistId:w,leadId:b,payerMobileNumber:E}=ti(),M=()=>{e()},[S,j]=G.useState(""),[F,z]=G.useState(!1),[J,Y]=G.useState(""),[H,W]=G.useState(!1),[_,l1]=G.useState(5),[r1,f1]=G.useState(""),p1=G.useRef(null),b1=G.useRef(null);G.useEffect(()=>{A||(j(""),Y(""),W(!1),l1(5),p1.current&&clearTimeout(p1.current),b1.current&&clearInterval(b1.current))},[A]);const N1=()=>{l1(5),p1.current&&clearTimeout(p1.current),b1.current&&clearInterval(b1.current);let P1=5;b1.current=setInterval(()=>{P1--,l1(P1),P1<=0&&b1.current&&clearInterval(b1.current)},1e3),p1.current=setTimeout(async()=>{await Lt.navigateHome()},5e3)},B1=async()=>{W(!0),Y("");const P1={paymentMode:"PAYMENT_LINK",paymentDate:new Date().toISOString(),paymentType:s,paidAmount:c,distributorCode:g,salesmanId:d,salesmanPhoneNumber:f?.trim()||void 0,invoiceCount:a?.length||o?.length||0,chemistName:n||void 0,distributorName:t||void 0,mobileNumber:E||void 0};w&&w.trim()!==""?P1.chemistBusinessId=w:b&&b.trim()!==""&&(P1.leadId=b),s==="INVOICE_COLLECT"?P1.paymentInvoice=a:s==="DIRECT_COLLECT"&&(P1.invoiceIds=o),E&&(P1.payerMobileNumber=E);try{const Z=await X3(P1),w1=Z.data||Z;f1(w1.chemistCode||""),w1?.link?(j(w1.link),Y("")):(j(""),Y("Failed to generate payment link. Please try again."),N1())}catch(Z){j("");const w1=Z?.response?.data?.errorResponse?.errorMessage||Z?.response?.data?.errorMessage||Z?.response?.data?.errorResponse?.errorDesc||Z?.response?.data?.errorDesc||Z?.response?.data?.message||Z?.message||"Failed to generate payment link. Please try again.";Y(w1),N1()}finally{W(!1)}},[T1,$]=G.useState(!1),u1=async()=>{if(S)try{await navigator.clipboard.writeText(S),$(!0),setTimeout(()=>$(!1),1500)}catch{}},x1=async()=>{if(S){const P1=`Complete your payment:
|
|
674
674
|
|
|
675
675
|
Amount: ₹${Number(c).toLocaleString("en-IN")}
|