@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/index.js
CHANGED
|
@@ -616,7 +616,7 @@ Thank you for your payment!`;await kt.shareByteImage(I,F,`Transaction_${j}`)}cat
|
|
|
616
616
|
`)}`,this.#l();const g=new Range;let w=Math.sumPrecise(u.map(b=>b.length));for(const{firstChild:b}of this.editorDiv.childNodes)if(b.nodeType===Node.TEXT_NODE){const I=b.nodeValue.length;if(w<=I){g.setStart(b,w),g.setEnd(b,w);break}w-=I}n.removeAllRanges(),n.addRange(g)}#l(){if(this.editorDiv.replaceChildren(),!!this.#e)for(const e of this.#e.split(`
|
|
617
617
|
`)){const t=document.createElement("div");t.append(e?document.createTextNode(e):document.createElement("br")),this.editorDiv.append(t)}}#f(){return this.#e.replaceAll(" "," ")}static#h(e){return e.replaceAll(" "," ")}get contentDiv(){return this.editorDiv}getPDFRect(){const e=ws._internalPadding*this.parentScale;return this.getRect(e,e)}static async deserialize(e,t,s){let i=null;if(e instanceof Bu){const{data:{defaultAppearanceData:{fontSize:o,fontColor:a},rect:d,rotation:u,id:m,popupRef:g,richText:w,contentsObj:b,creationDate:I,modificationDate:y},textContent:j,textPosition:L,parent:{page:{pageNumber:O}}}=e;if(!j||j.length===0)return null;i=e={annotationType:at.FREETEXT,color:Array.from(a),fontSize:o,value:j.join(`
|
|
618
618
|
`),position:L,pageIndex:O-1,rect:d.slice(0),rotation:u,annotationElementId:m,id:m,deleted:!1,popupRef:g,comment:b?.str||null,richText:w,creationDate:I,modificationDate:y}}const n=await super.deserialize(e,t,s);return n.#s=e.fontSize,n.color=He.makeHexColor(...e.color),n.#e=ws.#h(e.value),n._initialData=i,e.comment&&n.setCommentData(e),n}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const t=_e._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:this.color),s=Object.assign(super.serialize(e),{color:t,fontSize:this.#s,value:this.#f()});return this.addComment(s),e?(s.isCopy=!0,s):this.annotationElementId&&!this.#u(s)?null:(s.id=this.annotationElementId,s)}#u(e){const{value:t,fontSize:s,color:i,pageIndex:n}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||e.value!==t||e.fontSize!==s||e.color.some((o,a)=>o!==i[a])||e.pageIndex!==n}renderAnnotationElement(e){const t=super.renderAnnotationElement(e);if(!t)return null;const{style:s}=t;s.fontSize=`calc(${this.#s}px * var(--total-scale-factor))`,s.color=this.color,t.replaceChildren();for(const i of this.#e.split(`
|
|
619
|
-
`)){const n=document.createElement("div");n.append(i?document.createTextNode(i):document.createElement("br")),t.append(n)}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 Ue{static PRECISION=1e-4;toSVGPath(){Jt("Abstract method `toSVGPath` must be implemented.")}get box(){Jt("Abstract getter `box` must be implemented.")}serialize(e,t){Jt("Abstract method `serialize` must be implemented.")}static _rescale(e,t,s,i,n,o){o||=new Float32Array(e.length);for(let a=0,d=e.length;a<d;a+=2)o[a]=t+e[a]*i,o[a+1]=s+e[a+1]*n;return o}static _rescaleAndSwap(e,t,s,i,n,o){o||=new Float32Array(e.length);for(let a=0,d=e.length;a<d;a+=2)o[a]=t+e[a+1]*i,o[a+1]=s+e[a]*n;return o}static _translate(e,t,s,i){i||=new Float32Array(e.length);for(let n=0,o=e.length;n<o;n+=2)i[n]=t+e[n],i[n+1]=s+e[n+1];return i}static svgRound(e){return Math.round(e*1e4)}static _normalizePoint(e,t,s,i,n){switch(n){case 90:return[1-t/s,e/i];case 180:return[1-e/s,1-t/i];case 270:return[t/s,1-e/i];default:return[e/s,t/i]}}static _normalizePagePoint(e,t,s){switch(s){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,s,i,n,o){return[(e+5*s)/6,(t+5*i)/6,(5*s+n)/6,(5*i+o)/6,(s+n)/2,(i+o)/2]}}class Hn{#e;#t=[];#i;#s;#o=[];#n=new Float32Array(18);#r;#a;#c;#l;#f;#h;#u=[];static#g=8;static#p=2;static#d=Hn.#g+Hn.#p;constructor({x:e,y:t},s,i,n,o,a=0){this.#e=s,this.#h=n*i,this.#s=o,this.#n.set([NaN,NaN,NaN,NaN,e,t],6),this.#i=a,this.#l=Hn.#g*i,this.#c=Hn.#d*i,this.#f=i,this.#u.push(e,t)}isEmpty(){return isNaN(this.#n[8])}#m(){const e=this.#n.subarray(4,6),t=this.#n.subarray(16,18),[s,i,n,o]=this.#e;return[(this.#r+(e[0]-t[0])/2-s)/n,(this.#a+(e[1]-t[1])/2-i)/o,(this.#r+(t[0]-e[0])/2-s)/n,(this.#a+(t[1]-e[1])/2-i)/o]}add({x:e,y:t}){this.#r=e,this.#a=t;const[s,i,n,o]=this.#e;let[a,d,u,m]=this.#n.subarray(8,12);const g=e-u,w=t-m,b=Math.hypot(g,w);if(b<this.#c)return!1;const I=b-this.#l,y=I/b,j=y*g,L=y*w;let O=a,R=d;a=u,d=m,u+=j,m+=L,this.#u?.push(e,t);const F=-L/I,U=j/I,V=F*this.#h,Q=U*this.#h;return this.#n.set(this.#n.subarray(2,8),0),this.#n.set([u+V,m+Q],4),this.#n.set(this.#n.subarray(14,18),12),this.#n.set([u-V,m-Q],16),isNaN(this.#n[6])?(this.#o.length===0&&(this.#n.set([a+V,d+Q],2),this.#o.push(NaN,NaN,NaN,NaN,(a+V-s)/n,(d+Q-i)/o),this.#n.set([a-V,d-Q],14),this.#t.push(NaN,NaN,NaN,NaN,(a-V-s)/n,(d-Q-i)/o)),this.#n.set([O,R,a,d,u,m],6),!this.isEmpty()):(this.#n.set([O,R,a,d,u,m],6),Math.abs(Math.atan2(R-d,O-a)-Math.atan2(L,j))<Math.PI/2?([a,d,u,m]=this.#n.subarray(2,6),this.#o.push(NaN,NaN,NaN,NaN,((a+u)/2-s)/n,((d+m)/2-i)/o),[a,d,O,R]=this.#n.subarray(14,18),this.#t.push(NaN,NaN,NaN,NaN,((O+a)/2-s)/n,((R+d)/2-i)/o),!0):([O,R,a,d,u,m]=this.#n.subarray(0,6),this.#o.push(((O+5*a)/6-s)/n,((R+5*d)/6-i)/o,((5*a+u)/6-s)/n,((5*d+m)/6-i)/o,((a+u)/2-s)/n,((d+m)/2-i)/o),[u,m,a,d,O,R]=this.#n.subarray(12,18),this.#t.push(((O+5*a)/6-s)/n,((R+5*d)/6-i)/o,((5*a+u)/6-s)/n,((5*d+m)/6-i)/o,((a+u)/2-s)/n,((d+m)/2-i)/o),!0))}toSVGPath(){if(this.isEmpty())return"";const e=this.#o,t=this.#t;if(isNaN(this.#n[6])&&!this.isEmpty())return this.#A();const s=[];s.push(`M${e[4]} ${e[5]}`);for(let i=6;i<e.length;i+=6)isNaN(e[i])?s.push(`L${e[i+4]} ${e[i+5]}`):s.push(`C${e[i]} ${e[i+1]} ${e[i+2]} ${e[i+3]} ${e[i+4]} ${e[i+5]}`);this.#x(s);for(let i=t.length-6;i>=6;i-=6)isNaN(t[i])?s.push(`L${t[i+4]} ${t[i+5]}`):s.push(`C${t[i]} ${t[i+1]} ${t[i+2]} ${t[i+3]} ${t[i+4]} ${t[i+5]}`);return this.#w(s),s.join(" ")}#A(){const[e,t,s,i]=this.#e,[n,o,a,d]=this.#m();return`M${(this.#n[2]-e)/s} ${(this.#n[3]-t)/i} L${(this.#n[4]-e)/s} ${(this.#n[5]-t)/i} L${n} ${o} L${a} ${d} L${(this.#n[16]-e)/s} ${(this.#n[17]-t)/i} L${(this.#n[14]-e)/s} ${(this.#n[15]-t)/i} Z`}#w(e){const t=this.#t;e.push(`L${t[4]} ${t[5]} Z`)}#x(e){const[t,s,i,n]=this.#e,o=this.#n.subarray(4,6),a=this.#n.subarray(16,18),[d,u,m,g]=this.#m();e.push(`L${(o[0]-t)/i} ${(o[1]-s)/n} L${d} ${u} L${m} ${g} L${(a[0]-t)/i} ${(a[1]-s)/n}`)}newFreeDrawOutline(e,t,s,i,n,o){return new zu(e,t,s,i,n,o)}getOutlines(){const e=this.#o,t=this.#t,s=this.#n,[i,n,o,a]=this.#e,d=new Float32Array((this.#u?.length??0)+2);for(let g=0,w=d.length-2;g<w;g+=2)d[g]=(this.#u[g]-i)/o,d[g+1]=(this.#u[g+1]-n)/a;if(d[d.length-2]=(this.#r-i)/o,d[d.length-1]=(this.#a-n)/a,isNaN(s[6])&&!this.isEmpty())return this.#E(d);const u=new Float32Array(this.#o.length+24+this.#t.length);let m=e.length;for(let g=0;g<m;g+=2){if(isNaN(e[g])){u[g]=u[g+1]=NaN;continue}u[g]=e[g],u[g+1]=e[g+1]}m=this.#b(u,m);for(let g=t.length-6;g>=6;g-=6)for(let w=0;w<6;w+=2){if(isNaN(t[g+w])){u[m]=u[m+1]=NaN,m+=2;continue}u[m]=t[g+w],u[m+1]=t[g+w+1],m+=2}return this.#v(u,m),this.newFreeDrawOutline(u,d,this.#e,this.#f,this.#i,this.#s)}#E(e){const t=this.#n,[s,i,n,o]=this.#e,[a,d,u,m]=this.#m(),g=new Float32Array(36);return g.set([NaN,NaN,NaN,NaN,(t[2]-s)/n,(t[3]-i)/o,NaN,NaN,NaN,NaN,(t[4]-s)/n,(t[5]-i)/o,NaN,NaN,NaN,NaN,a,d,NaN,NaN,NaN,NaN,u,m,NaN,NaN,NaN,NaN,(t[16]-s)/n,(t[17]-i)/o,NaN,NaN,NaN,NaN,(t[14]-s)/n,(t[15]-i)/o],0),this.newFreeDrawOutline(g,e,this.#e,this.#f,this.#i,this.#s)}#v(e,t){const s=this.#t;return e.set([NaN,NaN,NaN,NaN,s[4],s[5]],t),t+=6}#b(e,t){const s=this.#n.subarray(4,6),i=this.#n.subarray(16,18),[n,o,a,d]=this.#e,[u,m,g,w]=this.#m();return e.set([NaN,NaN,NaN,NaN,(s[0]-n)/a,(s[1]-o)/d,NaN,NaN,NaN,NaN,u,m,NaN,NaN,NaN,NaN,g,w,NaN,NaN,NaN,NaN,(i[0]-n)/a,(i[1]-o)/d],t),t+=24}}class zu extends Ue{#e;#t=new Float32Array(4);#i;#s;#o;#n;#r;constructor(e,t,s,i,n,o){super(),this.#r=e,this.#o=t,this.#e=s,this.#n=i,this.#i=n,this.#s=o,this.firstPoint=[NaN,NaN],this.lastPoint=[NaN,NaN],this.#a(o);const[a,d,u,m]=this.#t;for(let g=0,w=e.length;g<w;g+=2)e[g]=(e[g]-a)/u,e[g+1]=(e[g+1]-d)/m;for(let g=0,w=t.length;g<w;g+=2)t[g]=(t[g]-a)/u,t[g+1]=(t[g+1]-d)/m}toSVGPath(){const e=[`M${this.#r[4]} ${this.#r[5]}`];for(let t=6,s=this.#r.length;t<s;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,s,i],n){const o=s-e,a=i-t;let d,u;switch(n){case 0:d=Ue._rescale(this.#r,e,i,o,-a),u=Ue._rescale(this.#o,e,i,o,-a);break;case 90:d=Ue._rescaleAndSwap(this.#r,e,t,o,a),u=Ue._rescaleAndSwap(this.#o,e,t,o,a);break;case 180:d=Ue._rescale(this.#r,s,t,-o,a),u=Ue._rescale(this.#o,s,t,-o,a);break;case 270:d=Ue._rescaleAndSwap(this.#r,s,i,-o,-a),u=Ue._rescaleAndSwap(this.#o,s,i,-o,-a);break}return{outline:Array.from(d),points:[Array.from(u)]}}#a(e){const t=this.#r;let s=t[4],i=t[5];const n=[s,i,s,i];let o=s,a=i,d=s,u=i;const m=e?Math.max:Math.min,g=new Float32Array(4);for(let b=6,I=t.length;b<I;b+=6){const y=t[b+4],j=t[b+5];isNaN(t[b])?(He.pointBoundingBox(y,j,n),a>j?(o=y,a=j):a===j&&(o=m(o,y)),u<j?(d=y,u=j):u===j&&(d=m(d,y))):(g[0]=g[1]=1/0,g[2]=g[3]=-1/0,He.bezierBoundingBox(s,i,...t.slice(b,b+6),g),He.rectBoundingBox(g[0],g[1],g[2],g[3],n),a>g[1]?(o=g[0],a=g[1]):a===g[1]&&(o=m(o,g[0])),u<g[3]?(d=g[2],u=g[3]):u===g[3]&&(d=m(d,g[2]))),s=y,i=j}const w=this.#t;w[0]=n[0]-this.#i,w[1]=n[1]-this.#i,w[2]=n[2]-n[0]+2*this.#i,w[3]=n[3]-n[1]+2*this.#i,this.firstPoint=[o,a],this.lastPoint=[d,u]}get box(){return this.#t}newOutliner(e,t,s,i,n,o=0){return new Hn(e,t,s,i,n,o)}getNewOutline(e,t){const[s,i,n,o]=this.#t,[a,d,u,m]=this.#e,g=n*u,w=o*m,b=s*u+a,I=i*m+d,y=this.newOutliner({x:this.#o[0]*g+b,y:this.#o[1]*w+I},this.#e,this.#n,e,this.#s,t??this.#i);for(let j=2;j<this.#o.length;j+=2)y.add({x:this.#o[j]*g+b,y:this.#o[j+1]*w+I});return y.getOutlines()}}class Ic{#e;#t;#i;#s=[];#o=[];constructor(e,t=0,s=0,i=!0){const n=[1/0,1/0,-1/0,-1/0],o=10**-4;for(const{x:y,y:j,width:L,height:O}of e){const R=Math.floor((y-t)/o)*o,F=Math.ceil((y+L+t)/o)*o,U=Math.floor((j-t)/o)*o,V=Math.ceil((j+O+t)/o)*o,Q=[R,U,V,!0],K=[F,U,V,!1];this.#s.push(Q,K),He.rectBoundingBox(R,U,F,V,n)}const a=n[2]-n[0]+2*s,d=n[3]-n[1]+2*s,u=n[0]-s,m=n[1]-s;let g=i?-1/0:1/0,w=1/0;const b=this.#s.at(i?-1:-2),I=[b[0],b[2]];for(const y of this.#s){const[j,L,O,R]=y;!R&&i?L<w?(w=L,g=j):L===w&&(g=Math.max(g,j)):R&&!i&&(L<w?(w=L,g=j):L===w&&(g=Math.min(g,j))),y[0]=(j-u)/a,y[1]=(L-m)/d,y[2]=(O-m)/d}this.#e=new Float32Array([u,m,a,d]),this.#t=[g,w],this.#i=I}getOutlines(){this.#s.sort((t,s)=>t[0]-s[0]||t[1]-s[1]||t[2]-s[2]);const e=[];for(const t of this.#s)t[3]?(e.push(...this.#l(t)),this.#a(t)):(this.#c(t),e.push(...this.#l(t)));return this.#n(e)}#n(e){const t=[],s=new Set;for(const o of e){const[a,d,u]=o;t.push([a,d,o],[a,u,o])}t.sort((o,a)=>o[1]-a[1]||o[0]-a[0]);for(let o=0,a=t.length;o<a;o+=2){const d=t[o][2],u=t[o+1][2];d.push(u),u.push(d),s.add(d),s.add(u)}const i=[];let n;for(;s.size>0;){const o=s.values().next().value;let[a,d,u,m,g]=o;s.delete(o);let w=a,b=d;for(n=[a,u],i.push(n);;){let I;if(s.has(m))I=m;else if(s.has(g))I=g;else break;s.delete(I),[a,d,u,m,g]=I,w!==a&&(n.push(w,b,a,b===d?d:u),w=a),b=b===d?u:d}n.push(w,b)}return new D2(i,this.#e,this.#t,this.#i)}#r(e){const t=this.#o;let s=0,i=t.length-1;for(;s<=i;){const n=s+i>>1,o=t[n][0];if(o===e)return n;o<e?s=n+1:i=n-1}return i+1}#a([,e,t]){const s=this.#r(e);this.#o.splice(s,0,[e,t])}#c([,e,t]){const s=this.#r(e);for(let i=s;i<this.#o.length;i++){const[n,o]=this.#o[i];if(n!==e)break;if(n===e&&o===t){this.#o.splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,o]=this.#o[i];if(n!==e)break;if(n===e&&o===t){this.#o.splice(i,1);return}}}#l(e){const[t,s,i]=e,n=[[t,s,i]],o=this.#r(i);for(let a=0;a<o;a++){const[d,u]=this.#o[a];for(let m=0,g=n.length;m<g;m++){const[,w,b]=n[m];if(!(u<=w||b<=d)){if(w>=d){if(b>u)n[m][1]=u;else{if(g===1)return[];n.splice(m,1),m--,g--}continue}n[m][2]=d,b>u&&n.push([t,u,b])}}}return n}}class D2 extends Ue{#e;#t;constructor(e,t,s,i){super(),this.#t=e,this.#e=t,this.firstPoint=s,this.lastPoint=i}toSVGPath(){const e=[];for(const t of this.#t){let[s,i]=t;e.push(`M${s} ${i}`);for(let n=2;n<t.length;n+=2){const o=t[n],a=t[n+1];o===s?(e.push(`V${a}`),i=a):a===i&&(e.push(`H${o}`),s=o)}e.push("Z")}return e.join(" ")}serialize([e,t,s,i],n){const o=[],a=s-e,d=i-t;for(const u of this.#t){const m=new Array(u.length);for(let g=0;g<u.length;g+=2)m[g]=e+u[g]*a,m[g+1]=i-u[g+1]*d;o.push(m)}return o}get box(){return this.#e}get classNamesForOutlining(){return["highlightOutline"]}}class Ec extends Hn{newFreeDrawOutline(e,t,s,i,n,o){return new L2(e,t,s,i,n,o)}}class L2 extends zu{newOutliner(e,t,s,i,n,o=0){return new Ec(e,t,s,i,n,o)}}class ds extends _e{#e=null;#t=0;#i;#s=null;#o=null;#n=null;#r=null;#a=0;#c=null;#l=null;#f=null;#h=!1;#u=null;#g=null;#p=null;#d="";#m;#A="";static _defaultColor=null;static _defaultOpacity=1;static _defaultThickness=12;static _type="highlight";static _editorType=at.HIGHLIGHT;static _freeHighlightId=-1;static _freeHighlight=null;static _freeHighlightClipId="";static get _keyboardManager(){const e=ds.prototype;return mt(this,"_keyboardManager",new Oo([[["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||ds._defaultColor,this.#m=e.thickness||ds._defaultThickness,this.opacity=e.opacity||ds._defaultOpacity,this.#i=e.boxes||null,this.#A=e.methodOfCreation||"",this.#d=e.text||"",this._isDraggable=!1,this.defaultL10nId="pdfjs-editor-highlight-editor",e.highlightId>-1?(this.#h=!0,this.#x(e),this.#C()):this.#i&&(this.#e=e.anchorNode,this.#t=e.anchorOffset,this.#r=e.focusNode,this.#a=e.focusOffset,this.#w(),this.#C(),this.rotate(this.rotation)),this.annotationElementId||this._uiManager.a11yAlert("pdfjs-editor-highlight-added-alert")}get telemetryInitialData(){return{action:"added",type:this.#h?"free_highlight":"highlight",color:this._uiManager.getNonHCMColorName(this.color),thickness:this.#m,methodOfCreation:this.#A}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.getNonHCMColorName(this.color)}}static computeTelemetryFinalData(e){return{numberOfColors:e.get("color").size}}#w(){const e=new Ic(this.#i,.001);this.#l=e.getOutlines(),[this.x,this.y,this.width,this.height]=this.#l.box;const t=new Ic(this.#i,.0025,.001,this._uiManager.direction==="ltr");this.#n=t.getOutlines();const{firstPoint:s}=this.#l;this.#u=[(s[0]-this.x)/this.width,(s[1]-this.y)/this.height];const{lastPoint:i}=this.#n;this.#g=[(i[0]-this.x)/this.width,(i[1]-this.y)/this.height]}#x({highlightOutlines:e,highlightId:t,clipPathId:s}){this.#l=e;const i=1.5;if(this.#n=e.getNewOutline(this.#m/2+i,.0025),t>=0)this.#f=t,this.#s=s,this.parent.drawLayer.finalizeDraw(t,{bbox:e.box,path:{d:e.toSVGPath()}}),this.#p=this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:this.#n.box,path:{d:this.#n.toSVGPath()}},!0);else if(this.parent){const g=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(this.#f,{bbox:ds.#I(this.#l.box,(g-this.rotation+360)%360),path:{d:e.toSVGPath()}}),this.parent.drawLayer.updateProperties(this.#p,{bbox:ds.#I(this.#n.box,g),path:{d:this.#n.toSVGPath()}})}const[n,o,a,d]=e.box;switch(this.rotation){case 0:this.x=n,this.y=o,this.width=a,this.height=d;break;case 90:{const[g,w]=this.parentDimensions;this.x=o,this.y=1-n,this.width=a*w/g,this.height=d*g/w;break}case 180:this.x=1-n,this.y=1-o,this.width=a,this.height=d;break;case 270:{const[g,w]=this.parentDimensions;this.x=1-o,this.y=n,this.width=a*w/g,this.height=d*g/w;break}}const{firstPoint:u}=e;this.#u=[(u[0]-n)/a,(u[1]-o)/d];const{lastPoint:m}=this.#n;this.#g=[(m[0]-n)/a,(m[1]-o)/d]}static initialize(e,t){_e.initialize(e,t),ds._defaultColor||=t.highlightColors?.values().next().value||"#fff066"}static updateDefaultParams(e,t){switch(e){case Mt.HIGHLIGHT_COLOR:ds._defaultColor=t;break;case Mt.HIGHLIGHT_THICKNESS:ds._defaultThickness=t;break}}translateInPage(e,t){}get toolbarPosition(){return this.#g}get commentButtonPosition(){return this.#u}updateParams(e,t){switch(e){case Mt.HIGHLIGHT_COLOR:this.#E(t);break;case Mt.HIGHLIGHT_THICKNESS:this.#v(t);break}}static get defaultPropertiesToUpdate(){return[[Mt.HIGHLIGHT_COLOR,ds._defaultColor],[Mt.HIGHLIGHT_THICKNESS,ds._defaultThickness]]}get propertiesToUpdate(){return[[Mt.HIGHLIGHT_COLOR,this.color||ds._defaultColor],[Mt.HIGHLIGHT_THICKNESS,this.#m||ds._defaultThickness],[Mt.HIGHLIGHT_FREE,this.#h]]}onUpdatedColor(){this.parent?.drawLayer.updateProperties(this.#f,{root:{fill:this.color,"fill-opacity":this.opacity}}),this.#o?.updateColor(this.color),super.onUpdatedColor()}#E(e){const t=(n,o)=>{this.color=n,this.opacity=o,this.onUpdatedColor()},s=this.color,i=this.opacity;this.addCommands({cmd:t.bind(this,e,ds._defaultOpacity),undo:t.bind(this,s,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Mt.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.getNonHCMColorName(e)},!0)}#v(e){const t=this.#m,s=i=>{this.#m=i,this.#b(i)};this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,t),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Mt.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)}get toolbarButtons(){return this._uiManager.highlightColors?[["colorPicker",this.#o=new si({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.#D())}getBaseTranslation(){return[0,0]}getRect(e,t){return super.getRect(e,t,this.#D())}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.#C(),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){let t=!1;this.parent&&!e?this.#S():e&&(this.#C(e),t=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(e),this.show(this._isVisible),t&&this.select()}#b(e){this.#h&&(this.#x({highlightOutlines:this.#l.getNewOutline(e/2)}),this.fixAndSetPosition(),this.setDims(this.width,this.height))}#S(){this.#f===null||!this.parent||(this.parent.drawLayer.remove(this.#f),this.#f=null,this.parent.drawLayer.remove(this.#p),this.#p=null)}#C(e=this.parent){this.#f===null&&({id:this.#f,clipPathId:this.#s}=e.drawLayer.draw({bbox:this.#l.box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":this.opacity},rootClass:{highlight:!0,free:this.#h},path:{d:this.#l.toSVGPath()}},!1,!0),this.#p=e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:this.#h},bbox:this.#n.box,path:{d:this.#n.toSVGPath()}},this.#h),this.#c&&(this.#c.style.clipPath=this.#s))}static#I([e,t,s,i],n){switch(n){case 90:return[1-t-i,e,i,s];case 180:return[1-e-s,1-t-i,s,i];case 270:return[t,1-e-s,i,s]}return[e,t,s,i]}rotate(e){const{drawLayer:t}=this.parent;let s;this.#h?(e=(e-this.rotation+360)%360,s=ds.#I(this.#l.box,e)):s=ds.#I([this.x,this.y,this.width,this.height],e),t.updateProperties(this.#f,{bbox:s,root:{"data-main-rotation":e}}),t.updateProperties(this.#p,{bbox:ds.#I(this.#n.box,e),root:{"data-main-rotation":e}})}render(){if(this.div)return this.div;const e=super.render();this.#d&&(e.setAttribute("aria-label",this.#d),e.setAttribute("role","mark")),this.#h?e.classList.add("free"):this.div.addEventListener("keydown",this.#L.bind(this),{signal:this._uiManager._signal});const t=this.#c=document.createElement("div");return e.append(t),t.setAttribute("aria-hidden","true"),t.className="internal",t.style.clipPath=this.#s,this.setDims(this.width,this.height),pu(this,this.#c,["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#p,{rootClass:{hovered:!0}})}pointerleave(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#p,{rootClass:{hovered:!1}})}#L(e){ds._keyboardManager.exec(this,e)}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:this.#j(!0);break;case 1:case 3:this.#j(!1);break}}#j(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.#p&&this.parent?.drawLayer.updateProperties(this.#p,{rootClass:{hovered:!1,selected:!0}})}unselect(){super.unselect(),this.#p&&(this.parent?.drawLayer.updateProperties(this.#p,{rootClass:{selected:!1}}),this.#h||this.#j(!1))}get _mustFixPosition(){return!this.#h}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.updateProperties(this.#f,{rootClass:{hidden:!e}}),this.parent.drawLayer.updateProperties(this.#p,{rootClass:{hidden:!e}}))}#D(){return this.#h?this.rotation:0}#F(){if(this.#h)return null;const[e,t]=this.pageDimensions,[s,i]=this.pageTranslation,n=this.#i,o=new Float32Array(n.length*8);let a=0;for(const{x:d,y:u,width:m,height:g}of n){const w=d*e+s,b=(1-u)*t+i;o[a]=o[a+4]=w,o[a+1]=o[a+3]=b,o[a+2]=o[a+6]=w+m*e,o[a+5]=o[a+7]=b-g*t,a+=8}return o}#k(e){return this.#l.serialize(e,this.#D())}static startHighlighting(e,t,{target:s,x:i,y:n}){const{x:o,y:a,width:d,height:u}=s.getBoundingClientRect(),m=new AbortController,g=e.combinedSignal(m),w=b=>{m.abort(),this.#R(e,b)};window.addEventListener("blur",w,{signal:g}),window.addEventListener("pointerup",w,{signal:g}),window.addEventListener("pointerdown",rs,{capture:!0,passive:!1,signal:g}),window.addEventListener("contextmenu",ri,{signal:g}),s.addEventListener("pointermove",this.#B.bind(this,e),{signal:g}),this._freeHighlight=new Ec({x:i,y:n},[o,a,d,u],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#B(e,t){this._freeHighlight.add(t)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})}static#R(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,s){let i=null;if(e instanceof Ou){const{data:{quadPoints:I,rect:y,rotation:j,id:L,color:O,opacity:R,popupRef:F,richText:U,contentsObj:V,creationDate:Q,modificationDate:K},parent:{page:{pageNumber:Z}}}=e;i=e={annotationType:at.HIGHLIGHT,color:Array.from(O),opacity:R,quadPoints:I,boxes:null,pageIndex:Z-1,rect:y.slice(0),rotation:j,annotationElementId:L,id:L,deleted:!1,popupRef:F,richText:U,comment:V?.str||null,creationDate:Q,modificationDate:K}}else if(e instanceof Vc){const{data:{inkLists:I,rect:y,rotation:j,id:L,color:O,borderStyle:{rawWidth:R},popupRef:F,richText:U,contentsObj:V,creationDate:Q,modificationDate:K},parent:{page:{pageNumber:Z}}}=e;i=e={annotationType:at.HIGHLIGHT,color:Array.from(O),thickness:R,inkLists:I,boxes:null,pageIndex:Z-1,rect:y.slice(0),rotation:j,annotationElementId:L,id:L,deleted:!1,popupRef:F,richText:U,comment:V?.str||null,creationDate:Q,modificationDate:K}}const{color:n,quadPoints:o,inkLists:a,opacity:d}=e,u=await super.deserialize(e,t,s);u.color=He.makeHexColor(...n),u.opacity=d||1,a&&(u.#m=e.thickness),u._initialData=i,e.comment&&u.setCommentData(e);const[m,g]=u.pageDimensions,[w,b]=u.pageTranslation;if(o){const I=u.#i=[];for(let y=0;y<o.length;y+=8)I.push({x:(o[y]-w)/m,y:1-(o[y+1]-b)/g,width:(o[y+2]-o[y])/m,height:(o[y+1]-o[y+5])/g});u.#w(),u.#C(),u.rotate(u.rotation)}else if(a){u.#h=!0;const I=a[0],y={x:I[0]-w,y:g-(I[1]-b)},j=new Ec(y,[0,0,m,g],1,u.#m/2,!0,.001);for(let R=0,F=I.length;R<F;R+=2)y.x=I[R]-w,y.y=g-(I[R+1]-b),j.add(y);const{id:L,clipPathId:O}=t.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:u.color,"fill-opacity":u._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:j.toSVGPath()}},!0,!0);u.#x({highlightOutlines:j.getOutlines(),highlightId:L,clipPathId:O}),u.#C(),u.rotate(u.parentRotation)}return u}serialize(e=!1){if(this.isEmpty()||e)return null;if(this.deleted)return this.serializeDeleted();const t=_e._colorManager.convert(this._uiManager.getNonHCMColor(this.color)),s=super.serialize(e);return Object.assign(s,{color:t,opacity:this.opacity,thickness:this.#m,quadPoints:this.#F(),outlines:this.#k(s.rect)}),this.addComment(s),this.annotationElementId&&!this.#P(s)?null:(s.id=this.annotationElementId,s)}#P(e){const{color:t}=this._initialData;return this.hasEditedComment||e.color.some((s,i)=>s!==t[i])}renderAnnotationElement(e){return this.deleted?(e.hide(),null):(e.updateEdited({rect:this.getPDFRect(),popup:this.comment}),null)}static canCreateNewEmptyEditor(){return!1}}class Uu{#e=Object.create(null);updateProperty(e,t){this[e]=t,this.updateSVGProperty(e,t)}updateProperties(e){if(e)for(const[t,s]of Object.entries(e))t.startsWith("_")||this.updateProperty(t,s)}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(){Jt("Not implemented")}}class nt extends _e{#e=null;#t;_colorPicker=null;_drawId=null;static _currentDrawId=-1;static _currentParent=null;static#i=null;static#s=null;static#o=null;static#n=NaN;static#r=null;static#a=null;static#c=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.#l(e),this.#u())}#l({drawOutlines:e,drawId:t,drawingOptions:s}){this.#e=e,this._drawingOptions||=s,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.#f(e,this.parent),this.#d(e.box)}#f(e,t){const{id:s}=t.drawLayer.draw(nt._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return s}static _mergeSVGProperties(e,t){const s=new Set(Object.keys(e));for(const[i,n]of Object.entries(t))s.has(i)?Object.assign(e[i],n):e[i]=n;return e}static getDefaultDrawingOptions(e){Jt("Not implemented")}static get typesMap(){Jt("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(e,t){const s=this.typesMap.get(e);s&&this._defaultDrawingOptions.updateProperty(s,t),this._currentParent&&(nt.#i.updateProperty(s,t),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(e,t){const s=this.constructor.typesMap.get(e);s&&this._updateProperty(e,s,t)}static get defaultPropertiesToUpdate(){const e=[],t=this._defaultDrawingOptions;for(const[s,i]of this.typesMap)e.push([s,t[i]]);return e}get propertiesToUpdate(){const e=[],{_drawingOptions:t}=this;for(const[s,i]of this.constructor.typesMap)e.push([s,t[i]]);return e}_updateProperty(e,t,s){const i=this._drawingOptions,n=i[t],o=a=>{i.updateProperty(t,a);const d=this.#e.updateProperty(t,a);d&&this.#d(d),this.parent?.drawLayer.updateProperties(this._drawId,i.toSVGProperties()),e===this.colorType&&this.onUpdatedColor()};this.addCommands({cmd:o.bind(this,s),undo:o.bind(this,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:e,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){this.parent?.drawLayer.updateProperties(this._drawId,nt._mergeSVGProperties(this.#e.getPathResizingSVGProperties(this.#p()),{bbox:this.#m()}))}_onResized(){this.parent?.drawLayer.updateProperties(this._drawId,nt._mergeSVGProperties(this.#e.getPathResizedSVGProperties(this.#p()),{bbox:this.#m()}))}_onTranslating(e,t){this.parent?.drawLayer.updateProperties(this._drawId,{bbox:this.#m()})}_onTranslated(){this.parent?.drawLayer.updateProperties(this._drawId,nt._mergeSVGProperties(this.#e.getPathTranslatedSVGProperties(this.#p(),this.parentDimensions),{bbox:this.#m()}))}_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.#h(),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.#u(),this.#d(this.#e.box),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){let t=!1;this.parent&&!e?(this._uiManager.removeShouldRescale(this),this.#h()):e&&(this._uiManager.addShouldRescale(this),this.#u(e),t=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(e),t&&this.select()}#h(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())}#u(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.#f(this.#e,e)}}#g([e,t,s,i]){const{parentDimensions:[n,o],rotation:a}=this;switch(a){case 90:return[t,1-e,s*(o/n),i*(n/o)];case 180:return[1-e,1-t,s,i];case 270:return[1-t,e,s*(o/n),i*(n/o)];default:return[e,t,s,i]}}#p(){const{x:e,y:t,width:s,height:i,parentDimensions:[n,o],rotation:a}=this;switch(a){case 90:return[1-t,e,s*(n/o),i*(o/n)];case 180:return[1-e,1-t,s,i];case 270:return[t,1-e,s*(n/o),i*(o/n)];default:return[e,t,s,i]}}#d(e){[this.x,this.y,this.width,this.height]=this.#g(e),this.div&&(this.fixAndSetPosition(),this.setDims()),this._onResized()}#m(){const{x:e,y:t,width:s,height:i,rotation:n,parentRotation:o,parentDimensions:[a,d]}=this;switch((n*4+o)/90){case 1:return[1-t-i,e,i,s];case 2:return[1-e-s,1-t-i,s,i];case 3:return[t,1-e-s,i,s];case 4:return[e,t-s*(a/d),i*(d/a),s*(a/d)];case 5:return[1-t,e,s*(a/d),i*(d/a)];case 6:return[1-e-i*(d/a),1-t,i*(d/a),s*(a/d)];case 7:return[t-s*(a/d),1-e-i*(d/a),s*(a/d),i*(d/a)];case 8:return[e-s,t-i,s,i];case 9:return[1-t,e-s,i,s];case 10:return[1-e,1-t,s,i];case 11:return[t-i,1-e,i,s];case 12:return[e-i*(d/a),t,i*(d/a),s*(a/d)];case 13:return[1-t-s*(a/d),e-i*(d/a),s*(a/d),i*(d/a)];case 14:return[1-e,1-t-s*(a/d),i*(d/a),s*(a/d)];case 15:return[t,1-e,s*(a/d),i*(d/a)];default:return[e,t,s,i]}}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,nt._mergeSVGProperties({bbox:this.#m()},this.#e.updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&this.#d(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 s=super.render();s.classList.add("draw");const i=document.createElement("div");return s.append(i),i.setAttribute("aria-hidden","true"),i.className="internal",this.setDims(),this._uiManager.addShouldRescale(this),this.disableEditing(),this._isCopy&&this._moveAfterPaste(e,t),s}static createDrawerInstance(e,t,s,i,n){Jt("Not implemented")}static startDrawing(e,t,s,i){const{target:n,offsetX:o,offsetY:a,pointerId:d,pointerType:u}=i;if(nt.#r&&nt.#r!==u)return;const{viewport:{rotation:m}}=e,{width:g,height:w}=n.getBoundingClientRect(),b=nt.#s=new AbortController,I=e.combinedSignal(b);if(nt.#n||=d,nt.#r??=u,window.addEventListener("pointerup",y=>{nt.#n===y.pointerId?this._endDraw(y):nt.#a?.delete(y.pointerId)},{signal:I}),window.addEventListener("pointercancel",y=>{nt.#n===y.pointerId?this._currentParent.endDrawingSession():nt.#a?.delete(y.pointerId)},{signal:I}),window.addEventListener("pointerdown",y=>{nt.#r===y.pointerType&&((nt.#a||=new Set).add(y.pointerId),nt.#i.isCancellable()&&(nt.#i.removeLastElement(),nt.#i.isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:I}),window.addEventListener("contextmenu",ri,{signal:I}),n.addEventListener("pointermove",this._drawMove.bind(this),{signal:I}),n.addEventListener("touchmove",y=>{y.timeStamp===nt.#c&&rs(y)},{signal:I}),e.toggleDrawing(),t._editorUndoBar?.hide(),nt.#i){e.drawLayer.updateProperties(this._currentDrawId,nt.#i.startNew(o,a,g,w,m));return}t.updateUIForDefaultProperties(this),nt.#i=this.createDrawerInstance(o,a,g,w,m),nt.#o=this.getDefaultDrawingOptions(),this._currentParent=e,{id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties(nt.#o.toSVGProperties(),nt.#i.defaultSVGProperties),!0,!1)}static _drawMove(e){if(nt.#c=-1,!nt.#i)return;const{offsetX:t,offsetY:s,pointerId:i}=e;if(nt.#n===i){if(nt.#a?.size>=1){this._endDraw(e);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,nt.#i.add(t,s)),nt.#c=e.timeStamp,rs(e)}}static _cleanup(e){e&&(this._currentDrawId=-1,this._currentParent=null,nt.#i=null,nt.#o=null,nt.#r=null,nt.#c=NaN),nt.#s&&(nt.#s.abort(),nt.#s=null,nt.#n=NaN,nt.#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,nt.#i.end(e.offsetX,e.offsetY)),this.supportMultipleDrawings){const s=nt.#i,i=this._currentDrawId,n=s.getLastElement();t.addCommands({cmd:()=>{t.drawLayer.updateProperties(i,s.setLastElement(n))},undo:()=>{t.drawLayer.updateProperties(i,s.removeLastElement())},mustExec:!1,type:Mt.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(e){const t=this._currentParent;if(!t)return null;if(t.toggleDrawing(!0),t.cleanUndoStack(Mt.DRAW_STEP),!nt.#i.isEmpty()){const{pageDimensions:[s,i],scale:n}=t,o=t.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:nt.#i.getOutlines(s*n,i*n,n,this._INNER_MARGIN),drawingOptions:nt.#o,mustBeCommitted:!e});return this._cleanup(!0),o}return t.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(e){}static deserializeDraw(e,t,s,i,n,o){Jt("Not implemented")}static async deserialize(e,t,s){const{rawDims:{pageWidth:i,pageHeight:n,pageX:o,pageY:a}}=t.viewport,d=this.deserializeDraw(o,a,i,n,this._INNER_MARGIN,e),u=await super.deserialize(e,t,s);return u.createDrawingOptions(e),u.#l({drawOutlines:d}),u.#u(),u.onScaleChanging(),u.rotate(),u}serializeDraw(e){const[t,s]=this.pageTranslation,[i,n]=this.pageDimensions;return this.#e.serialize([t,s,i,n],e)}renderAnnotationElement(e){return e.updateEdited({rect:this.getPDFRect()}),null}static canCreateNewEmptyEditor(){return!1}}class N2{#e=new Float64Array(6);#t;#i;#s;#o;#n;#r="";#a=0;#c=new zo;#l;#f;constructor(e,t,s,i,n,o){this.#l=s,this.#f=i,this.#s=n,this.#o=o,[e,t]=this.#h(e,t);const a=this.#t=[NaN,NaN,NaN,NaN,e,t];this.#n=[e,t],this.#i=[{line:a,points:this.#n}],this.#e.set(a,0)}updateProperty(e,t){e==="stroke-width"&&(this.#o=t)}#h(e,t){return Ue._normalizePoint(e,t,this.#l,this.#f,this.#s)}isEmpty(){return!this.#i||this.#i.length===0}isCancellable(){return this.#n.length<=10}add(e,t){[e,t]=this.#h(e,t);const[s,i,n,o]=this.#e.subarray(2,6),a=e-n,d=t-o;return Math.hypot(this.#l*a,this.#f*d)<=2?null:(this.#n.push(e,t),isNaN(s)?(this.#e.set([n,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([s,i,n,o,e,t],0),this.#t.push(...Ue.createBezierPoints(s,i,n,o,e,t)),{path:{d:this.toSVGPath()}}))}end(e,t){const s=this.add(e,t);return s||(this.#n.length===2?{path:{d:this.toSVGPath()}}:null)}startNew(e,t,s,i,n){this.#l=s,this.#f=i,this.#s=n,[e,t]=this.#h(e,t);const o=this.#t=[NaN,NaN,NaN,NaN,e,t];this.#n=[e,t];const a=this.#i.at(-1);return a&&(a.line=new Float32Array(a.line),a.points=new Float32Array(a.points)),this.#i.push({line:o,points:this.#n}),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.#n=e.points,this.#a=0,{path:{d:this.toSVGPath()}}):this.#c.setLastElement(e)}removeLastElement(){if(!this.#i)return this.#c.removeLastElement();this.#i.pop(),this.#r="";for(let e=0,t=this.#i.length;e<t;e++){const{line:s,points:i}=this.#i[e];this.#t=s,this.#n=i,this.#a=0,this.toSVGPath()}return{path:{d:this.#r}}}toSVGPath(){const e=Ue.svgRound(this.#t[4]),t=Ue.svgRound(this.#t[5]);if(this.#n.length===2)return this.#r=`${this.#r} M ${e} ${t} Z`,this.#r;if(this.#n.length<=6){const i=this.#r.lastIndexOf("M");this.#r=`${this.#r.slice(0,i)} M ${e} ${t}`,this.#a=6}if(this.#n.length===4){const i=Ue.svgRound(this.#t[10]),n=Ue.svgRound(this.#t[11]);return this.#r=`${this.#r} L ${i} ${n}`,this.#a=12,this.#r}const s=[];this.#a===0&&(s.push(`M ${e} ${t}`),this.#a=6);for(let i=this.#a,n=this.#t.length;i<n;i+=6){const[o,a,d,u,m,g]=this.#t.slice(i,i+6).map(Ue.svgRound);s.push(`C${o} ${a} ${d} ${u} ${m} ${g}`)}return this.#r+=s.join(" "),this.#a=this.#t.length,this.#r}getOutlines(e,t,s,i){const n=this.#i.at(-1);return n.line=new Float32Array(n.line),n.points=new Float32Array(n.points),this.#c.build(this.#i,e,t,s,this.#s,this.#o,i),this.#e=null,this.#t=null,this.#i=null,this.#r=null,this.#c}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}class zo extends Ue{#e;#t=0;#i;#s;#o;#n;#r;#a;#c;build(e,t,s,i,n,o,a){this.#o=t,this.#n=s,this.#r=i,this.#a=n,this.#c=o,this.#i=a??0,this.#s=e,this.#h()}get thickness(){return this.#c}setLastElement(e){return this.#s.push(e),{path:{d:this.toSVGPath()}}}removeLastElement(){return this.#s.pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const e=[];for(const{line:t}of this.#s){if(e.push(`M${Ue.svgRound(t[4])} ${Ue.svgRound(t[5])}`),t.length===6){e.push("Z");continue}if(t.length===12&&isNaN(t[6])){e.push(`L${Ue.svgRound(t[10])} ${Ue.svgRound(t[11])}`);continue}for(let s=6,i=t.length;s<i;s+=6){const[n,o,a,d,u,m]=t.subarray(s,s+6).map(Ue.svgRound);e.push(`C${n} ${o} ${a} ${d} ${u} ${m}`)}}return e.join("")}serialize([e,t,s,i],n){const o=[],a=[],[d,u,m,g]=this.#f();let w,b,I,y,j,L,O,R,F;switch(this.#a){case 0:F=Ue._rescale,w=e,b=t+i,I=s,y=-i,j=e+d*s,L=t+(1-u-g)*i,O=e+(d+m)*s,R=t+(1-u)*i;break;case 90:F=Ue._rescaleAndSwap,w=e,b=t,I=s,y=i,j=e+u*s,L=t+d*i,O=e+(u+g)*s,R=t+(d+m)*i;break;case 180:F=Ue._rescale,w=e+s,b=t,I=-s,y=i,j=e+(1-d-m)*s,L=t+u*i,O=e+(1-d)*s,R=t+(u+g)*i;break;case 270:F=Ue._rescaleAndSwap,w=e+s,b=t+i,I=-s,y=-i,j=e+(1-u-g)*s,L=t+(1-d-m)*i,O=e+(1-u)*s,R=t+(1-d)*i;break}for(const{line:U,points:V}of this.#s)o.push(F(U,w,b,I,y,n?new Array(U.length):null)),a.push(F(V,w,b,I,y,n?new Array(V.length):null));return{lines:o,points:a,rect:[j,L,O,R]}}static deserialize(e,t,s,i,n,{paths:{lines:o,points:a},rotation:d,thickness:u}){const m=[];let g,w,b,I,y;switch(d){case 0:y=Ue._rescale,g=-e/s,w=t/i+1,b=1/s,I=-1/i;break;case 90:y=Ue._rescaleAndSwap,g=-t/i,w=-e/s,b=1/i,I=1/s;break;case 180:y=Ue._rescale,g=e/s+1,w=-t/i,b=-1/s,I=1/i;break;case 270:y=Ue._rescaleAndSwap,g=t/i+1,w=e/s+1,b=-1/i,I=-1/s;break}if(!o){o=[];for(const L of a){const O=L.length;if(O===2){o.push(new Float32Array([NaN,NaN,NaN,NaN,L[0],L[1]]));continue}if(O===4){o.push(new Float32Array([NaN,NaN,NaN,NaN,L[0],L[1],NaN,NaN,NaN,NaN,L[2],L[3]]));continue}const R=new Float32Array(3*(O-2));o.push(R);let[F,U,V,Q]=L.subarray(0,4);R.set([NaN,NaN,NaN,NaN,F,U],0);for(let K=4;K<O;K+=2){const Z=L[K],$=L[K+1];R.set(Ue.createBezierPoints(F,U,V,Q,Z,$),(K-2)*3),[F,U,V,Q]=[V,Q,Z,$]}}}for(let L=0,O=o.length;L<O;L++)m.push({line:y(o[L].map(R=>R??NaN),g,w,b,I),points:y(a[L].map(R=>R??NaN),g,w,b,I)});const j=new this.prototype.constructor;return j.build(m,s,i,1,d,u,n),j}#l(e=this.#c){const t=this.#i+e/2*this.#r;return this.#a%180===0?[t/this.#o,t/this.#n]:[t/this.#n,t/this.#o]}#f(){const[e,t,s,i]=this.#e,[n,o]=this.#l(0);return[e+n,t+o,s-2*n,i-2*o]}#h(){const e=this.#e=new Float32Array([1/0,1/0,-1/0,-1/0]);for(const{line:i}of this.#s){if(i.length<=12){for(let a=4,d=i.length;a<d;a+=6)He.pointBoundingBox(i[a],i[a+1],e);continue}let n=i[4],o=i[5];for(let a=6,d=i.length;a<d;a+=6){const[u,m,g,w,b,I]=i.subarray(a,a+6);He.bezierBoundingBox(n,o,u,m,g,w,b,I,e),n=b,o=I}}const[t,s]=this.#l();e[0]=js(e[0]-t,0,1),e[1]=js(e[1]-s,0,1),e[2]=js(e[2]+t,0,1),e[3]=js(e[3]+s,0,1),e[2]-=e[0],e[3]-=e[1]}get box(){return this.#e}updateProperty(e,t){return e==="stroke-width"?this.#u(t):null}#u(e){const[t,s]=this.#l();this.#c=e;const[i,n]=this.#l(),[o,a]=[i-t,n-s],d=this.#e;return d[0]-=o,d[1]-=a,d[2]+=2*o,d[3]+=2*a,d}updateParentDimensions([e,t],s){const[i,n]=this.#l();this.#o=e,this.#n=t,this.#r=s;const[o,a]=this.#l(),d=o-i,u=a-n,m=this.#e;return m[0]-=d,m[1]-=u,m[2]+=2*d,m[3]+=2*u,m}updateRotation(e){return this.#t=e,{path:{transform:this.rotationTransform}}}get viewBox(){return this.#e.map(Ue.svgRound).join(" ")}get defaultProperties(){const[e,t]=this.#e;return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Ue.svgRound(e)} ${Ue.svgRound(t)}`}}}get rotationTransform(){const[,,e,t]=this.#e;let s=0,i=0,n=0,o=0,a=0,d=0;switch(this.#t){case 90:i=t/e,n=-e/t,a=e;break;case 180:s=-1,o=-1,a=e,d=t;break;case 270:i=-t/e,n=e/t,d=t;break;default:return""}return`matrix(${s} ${i} ${n} ${o} ${Ue.svgRound(a)} ${Ue.svgRound(d)})`}getPathResizingSVGProperties([e,t,s,i]){const[n,o]=this.#l(),[a,d,u,m]=this.#e;if(Math.abs(u-n)<=Ue.PRECISION||Math.abs(m-o)<=Ue.PRECISION){const y=e+s/2-(a+u/2),j=t+i/2-(d+m/2);return{path:{"transform-origin":`${Ue.svgRound(e)} ${Ue.svgRound(t)}`,transform:`${this.rotationTransform} translate(${y} ${j})`}}}const g=(s-2*n)/(u-2*n),w=(i-2*o)/(m-2*o),b=u/s,I=m/i;return{path:{"transform-origin":`${Ue.svgRound(a)} ${Ue.svgRound(d)}`,transform:`${this.rotationTransform} scale(${b} ${I}) translate(${Ue.svgRound(n)} ${Ue.svgRound(o)}) scale(${g} ${w}) translate(${Ue.svgRound(-n)} ${Ue.svgRound(-o)})`}}}getPathResizedSVGProperties([e,t,s,i]){const[n,o]=this.#l(),a=this.#e,[d,u,m,g]=a;if(a[0]=e,a[1]=t,a[2]=s,a[3]=i,Math.abs(m-n)<=Ue.PRECISION||Math.abs(g-o)<=Ue.PRECISION){const j=e+s/2-(d+m/2),L=t+i/2-(u+g/2);for(const{line:O,points:R}of this.#s)Ue._translate(O,j,L,O),Ue._translate(R,j,L,R);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Ue.svgRound(e)} ${Ue.svgRound(t)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const w=(s-2*n)/(m-2*n),b=(i-2*o)/(g-2*o),I=-w*(d+n)+e+n,y=-b*(u+o)+t+o;if(w!==1||b!==1||I!==0||y!==0)for(const{line:j,points:L}of this.#s)Ue._rescale(j,I,y,w,b,j),Ue._rescale(L,I,y,w,b,L);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Ue.svgRound(e)} ${Ue.svgRound(t)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,t],s){const[i,n]=s,o=this.#e,a=e-o[0],d=t-o[1];if(this.#o===i&&this.#n===n)for(const{line:u,points:m}of this.#s)Ue._translate(u,a,d,u),Ue._translate(m,a,d,m);else{const u=this.#o/i,m=this.#n/n;this.#o=i,this.#n=n;for(const{line:g,points:w}of this.#s)Ue._rescale(g,a,d,u,m,g),Ue._rescale(w,a,d,u,m,w);o[2]*=u,o[3]*=m}return o[0]=e,o[1]=t,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${Ue.svgRound(e)} ${Ue.svgRound(t)}`}}}get defaultSVGProperties(){const e=this.#e;return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${Ue.svgRound(e[0])} ${Ue.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}}class fl extends Uu{constructor(e){super(),this._viewParameters=e,super.updateProperties({fill:"none",stroke:_e._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 fl(this._viewParameters);return e.updateAll(this),e}}class Zc extends nt{static _type="ink";static _editorType=at.INK;static _defaultDrawingOptions=null;constructor(e){super({...e,name:"inkEditor"}),this._willKeepAspectRatio=!0,this.defaultL10nId="pdfjs-editor-ink-editor"}static initialize(e,t){_e.initialize(e,t),this._defaultDrawingOptions=new fl(t.viewParameters)}static getDefaultDrawingOptions(e){const t=this._defaultDrawingOptions.clone();return t.updateProperties(e),t}static get supportMultipleDrawings(){return!0}static get typesMap(){return mt(this,"typesMap",new Map([[Mt.INK_THICKNESS,"stroke-width"],[Mt.INK_COLOR,"stroke"],[Mt.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(e,t,s,i,n){return new N2(e,t,s,i,n,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(e,t,s,i,n,o){return zo.deserialize(e,t,s,i,n,o)}static async deserialize(e,t,s){let i=null;if(e instanceof Vc){const{data:{inkLists:o,rect:a,rotation:d,id:u,color:m,opacity:g,borderStyle:{rawWidth:w},popupRef:b,richText:I,contentsObj:y,creationDate:j,modificationDate:L},parent:{page:{pageNumber:O}}}=e;i=e={annotationType:at.INK,color:Array.from(m),thickness:w,opacity:g,paths:{points:o},boxes:null,pageIndex:O-1,rect:a.slice(0),rotation:d,annotationElementId:u,id:u,deleted:!1,popupRef:b,richText:I,comment:y?.str||null,creationDate:j,modificationDate:L}}const n=await super.deserialize(e,t,s);return n._initialData=i,e.comment&&n.setCommentData(e),n}get toolbarButtons(){return this._colorPicker||=new Do(this),[["colorPicker",this._colorPicker]]}get colorType(){return Mt.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:s}=this;t.updateSVGProperty("stroke-width"),s.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:s}){this._drawingOptions=Zc.getDefaultDrawingOptions({stroke:He.makeHexColor(...e),"stroke-width":t,"stroke-opacity":s})}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:t,points:s}=this.serializeDraw(e),{_drawingOptions:{stroke:i,"stroke-opacity":n,"stroke-width":o}}=this,a=Object.assign(super.serialize(e),{color:_e._colorManager.convert(i),opacity:n,thickness:o,paths:{lines:t,points:s}});return this.addComment(a),e?(a.isCopy=!0,a):this.annotationElementId&&!this.#e(a)?null:(a.id=this.annotationElementId,a)}#e(e){const{color:t,thickness:s,opacity:i,pageIndex:n}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized||e.color.some((o,a)=>o!==t[a])||e.thickness!==s||e.opacity!==i||e.pageIndex!==n}renderAnnotationElement(e){if(this.deleted)return e.hide(),null;const{points:t,rect:s}=this.serializeDraw(!1);return e.updateEdited({rect:s,thickness:this._drawingOptions["stroke-width"],points:t,popup:this.comment}),null}}class Mc extends zo{toSVGPath(){let e=super.toSVGPath();return e.endsWith("Z")||(e+="Z"),e}}const Ja=8,Ao=3;class Un{static#e={maxDim:512,sigmaSFactor:.02,sigmaR:25,kernelSize:16};static#t(e,t,s,i){return s-=e,i-=t,s===0?i>0?0:4:s===1?i+6:2-i}static#i=new Int32Array([0,1,-1,1,-1,0,-1,-1,0,-1,1,-1,1,0,1,1]);static#s(e,t,s,i,n,o,a){const d=this.#t(s,i,n,o);for(let u=0;u<8;u++){const m=(-u+d-a+16)%8,g=this.#i[2*m],w=this.#i[2*m+1];if(e[(s+g)*t+(i+w)]!==0)return m}return-1}static#o(e,t,s,i,n,o,a){const d=this.#t(s,i,n,o);for(let u=0;u<8;u++){const m=(u+d+a+16)%8,g=this.#i[2*m],w=this.#i[2*m+1];if(e[(s+g)*t+(i+w)]!==0)return m}return-1}static#n(e,t,s,i){const n=e.length,o=new Int32Array(n);for(let m=0;m<n;m++)o[m]=e[m]<=i?1:0;for(let m=1;m<s-1;m++)o[m*t]=o[m*t+t-1]=0;for(let m=0;m<t;m++)o[m]=o[t*s-1-m]=0;let a=1,d;const u=[];for(let m=1;m<s-1;m++){d=1;for(let g=1;g<t-1;g++){const w=m*t+g,b=o[w];if(b===0)continue;let I=m,y=g;if(b===1&&o[w-1]===0)a+=1,y-=1;else if(b>=1&&o[w+1]===0)a+=1,y+=1,b>1&&(d=b);else{b!==1&&(d=Math.abs(b));continue}const j=[g,m],L=y===g+1,O={isHole:L,points:j,id:a,parent:0};u.push(O);let R;for(const se of u)if(se.id===d){R=se;break}R?R.isHole?O.parent=L?R.parent:d:O.parent=L?d:R.parent:O.parent=L?d:0;const F=this.#s(o,t,m,g,I,y,0);if(F===-1){o[w]=-a,o[w]!==1&&(d=Math.abs(o[w]));continue}let U=this.#i[2*F],V=this.#i[2*F+1];const Q=m+U,K=g+V;I=Q,y=K;let Z=m,$=g;for(;;){const se=this.#o(o,t,Z,$,I,y,1);U=this.#i[2*se],V=this.#i[2*se+1];const le=Z+U,pe=$+V;j.push(pe,le);const oe=Z*t+$;if(o[oe+1]===0?o[oe]=-a:o[oe]===1&&(o[oe]=a),le===m&&pe===g&&Z===Q&&$===K){o[w]!==1&&(d=Math.abs(o[w]));break}else I=Z,y=$,Z=le,$=pe}}}return u}static#r(e,t,s,i){if(s-t<=4){for(let Q=t;Q<s-2;Q+=2)i.push(e[Q],e[Q+1]);return}const n=e[t],o=e[t+1],a=e[s-4]-n,d=e[s-3]-o,u=Math.hypot(a,d),m=a/u,g=d/u,w=m*o-g*n,b=d/a,I=1/u,y=Math.atan(b),j=Math.cos(y),L=Math.sin(y),O=I*(Math.abs(j)+Math.abs(L)),R=I*(1-O+O**2),F=Math.max(Math.atan(Math.abs(L+j)*R),Math.atan(Math.abs(L-j)*R));let U=0,V=t;for(let Q=t+2;Q<s-2;Q+=2){const K=Math.abs(w-m*e[Q+1]+g*e[Q]);K>U&&(V=Q,U=K)}U>(u*F)**2?(this.#r(e,t,V+2,i),this.#r(e,V,s,i)):i.push(n,o)}static#a(e){const t=[],s=e.length;return this.#r(e,0,s,t),t.push(e[s-2],e[s-1]),t.length<=4?null:t}static#c(e,t,s,i,n,o){const a=new Float32Array(o**2),d=-2*i**2,u=o>>1;for(let y=0;y<o;y++){const j=(y-u)**2;for(let L=0;L<o;L++)a[y*o+L]=Math.exp((j+(L-u)**2)/d)}const m=new Float32Array(256),g=-2*n**2;for(let y=0;y<256;y++)m[y]=Math.exp(y**2/g);const w=e.length,b=new Uint8Array(w),I=new Uint32Array(256);for(let y=0;y<s;y++)for(let j=0;j<t;j++){const L=y*t+j,O=e[L];let R=0,F=0;for(let V=0;V<o;V++){const Q=y+V-u;if(!(Q<0||Q>=s))for(let K=0;K<o;K++){const Z=j+K-u;if(Z<0||Z>=t)continue;const $=e[Q*t+Z],se=a[V*o+K]*m[Math.abs($-O)];R+=$*se,F+=se}}const U=b[L]=Math.round(R/F);I[U]++}return[b,I]}static#l(e){const t=new Uint32Array(256);for(const s of e)t[s]++;return t}static#f(e){const t=e.length,s=new Uint8ClampedArray(t>>2);let i=-1/0,n=1/0;for(let a=0,d=s.length;a<d;a++){const u=s[a]=e[a<<2];i=Math.max(i,u),n=Math.min(n,u)}const o=255/(i-n);for(let a=0,d=s.length;a<d;a++)s[a]=(s[a]-n)*o;return s}static#h(e){let t,s=-1/0,i=-1/0;const n=e.findIndex(d=>d!==0);let o=n,a=n;for(t=n;t<256;t++){const d=e[t];d>s&&(t-o>i&&(i=t-o,a=t-1),s=d,o=t)}for(t=a-1;t>=0&&!(e[t]>e[t+1]);t--);return t}static#u(e){const t=e,{width:s,height:i}=e,{maxDim:n}=this.#e;let o=s,a=i;if(s>n||i>n){let w=s,b=i,I=Math.log2(Math.max(s,i)/n);const y=Math.floor(I);I=I===y?y-1:y;for(let L=0;L<I;L++){o=Math.ceil(w/2),a=Math.ceil(b/2);const O=new OffscreenCanvas(o,a);O.getContext("2d").drawImage(e,0,0,w,b,0,0,o,a),w=o,b=a,e!==t&&e.close(),e=O.transferToImageBitmap()}const j=Math.min(n/o,n/a);o=Math.round(o*j),a=Math.round(a*j)}const u=new OffscreenCanvas(o,a).getContext("2d",{willReadFrequently:!0});u.fillStyle="white",u.fillRect(0,0,o,a),u.filter="grayscale(1)",u.drawImage(e,0,0,e.width,e.height,0,0,o,a);const m=u.getImageData(0,0,o,a).data;return[this.#f(m),o,a]}static extractContoursFromText(e,{fontFamily:t,fontStyle:s,fontWeight:i},n,o,a,d){let u=new OffscreenCanvas(1,1),m=u.getContext("2d",{alpha:!1});const g=200,w=m.font=`${s} ${i} ${g}px ${t}`,{actualBoundingBoxLeft:b,actualBoundingBoxRight:I,actualBoundingBoxAscent:y,actualBoundingBoxDescent:j,fontBoundingBoxAscent:L,fontBoundingBoxDescent:O,width:R}=m.measureText(e),F=1.5,U=Math.ceil(Math.max(Math.abs(b)+Math.abs(I)||0,R)*F),V=Math.ceil(Math.max(Math.abs(y)+Math.abs(j)||g,Math.abs(L)+Math.abs(O)||g)*F);u=new OffscreenCanvas(U,V),m=u.getContext("2d",{alpha:!0,willReadFrequently:!0}),m.font=w,m.filter="grayscale(1)",m.fillStyle="white",m.fillRect(0,0,U,V),m.fillStyle="black",m.fillText(e,U*(F-1)/2,V*(3-F)/2);const Q=this.#f(m.getImageData(0,0,U,V).data),K=this.#l(Q),Z=this.#h(K),$=this.#n(Q,U,V,Z);return this.processDrawnLines({lines:{curves:$,width:U,height:V},pageWidth:n,pageHeight:o,rotation:a,innerMargin:d,mustSmooth:!0,areContours:!0})}static process(e,t,s,i,n){const[o,a,d]=this.#u(e),[u,m]=this.#c(o,a,d,Math.hypot(a,d)*this.#e.sigmaSFactor,this.#e.sigmaR,this.#e.kernelSize),g=this.#h(m),w=this.#n(u,a,d,g);return this.processDrawnLines({lines:{curves:w,width:a,height:d},pageWidth:t,pageHeight:s,rotation:i,innerMargin:n,mustSmooth:!0,areContours:!0})}static processDrawnLines({lines:e,pageWidth:t,pageHeight:s,rotation:i,innerMargin:n,mustSmooth:o,areContours:a}){i%180!==0&&([t,s]=[s,t]);const{curves:d,width:u,height:m}=e,g=e.thickness??0,w=[],b=Math.min(t/u,s/m),I=b/t,y=b/s,j=[];for(const{points:O}of d){const R=o?this.#a(O):O;if(!R)continue;j.push(R);const F=R.length,U=new Float32Array(F),V=new Float32Array(3*(F===2?2:F-2));if(w.push({line:V,points:U}),F===2){U[0]=R[0]*I,U[1]=R[1]*y,V.set([NaN,NaN,NaN,NaN,U[0],U[1]],0);continue}let[Q,K,Z,$]=R;Q*=I,K*=y,Z*=I,$*=y,U.set([Q,K,Z,$],0),V.set([NaN,NaN,NaN,NaN,Q,K],0);for(let se=4;se<F;se+=2){const le=U[se]=R[se]*I,pe=U[se+1]=R[se+1]*y;V.set(Ue.createBezierPoints(Q,K,Z,$,le,pe),(se-2)*3),[Q,K,Z,$]=[Z,$,le,pe]}}if(w.length===0)return null;const L=a?new Mc:new zo;return L.build(w,t,s,1,i,a?0:g,n),{outline:L,newCurves:j,areContours:a,thickness:g,width:u,height:m}}static async compressSignature({outlines:e,areContours:t,thickness:s,width:i,height:n}){let o=1/0,a=-1/0,d=0;for(const R of e){d+=R.length;for(let F=2,U=R.length;F<U;F++){const V=R[F]-R[F-2];o=Math.min(o,V),a=Math.max(a,V)}}let u;o>=-128&&a<=127?u=Int8Array:o>=-32768&&a<=32767?u=Int16Array:u=Int32Array;const m=e.length,g=Ja+Ao*m,w=new Uint32Array(g);let b=0;w[b++]=g*Uint32Array.BYTES_PER_ELEMENT+(d-2*m)*u.BYTES_PER_ELEMENT,w[b++]=0,w[b++]=i,w[b++]=n,w[b++]=t?0:1,w[b++]=Math.max(0,Math.floor(s??0)),w[b++]=m,w[b++]=u.BYTES_PER_ELEMENT;for(const R of e)w[b++]=R.length-2,w[b++]=R[0],w[b++]=R[1];const I=new CompressionStream("deflate-raw"),y=I.writable.getWriter();await y.ready,y.write(w);const j=u.prototype.constructor;for(const R of e){const F=new j(R.length-2);for(let U=2,V=R.length;U<V;U++)F[U-2]=R[U]-R[U-2];y.write(F)}y.close();const L=await new Response(I.readable).arrayBuffer(),O=new Uint8Array(L);return au(O)}static async decompressSignature(e){try{const t=sx(e),{readable:s,writable:i}=new DecompressionStream("deflate-raw"),n=i.getWriter();await n.ready,n.write(t).then(async()=>{await n.ready,await n.close()}).catch(()=>{});let o=null,a=0;for await(const R of s)o||=new Uint8Array(new Uint32Array(R.buffer,0,4)[0]),o.set(R,a),a+=R.length;const d=new Uint32Array(o.buffer,0,o.length>>2),u=d[1];if(u!==0)throw new Error(`Invalid version: ${u}`);const m=d[2],g=d[3],w=d[4]===0,b=d[5],I=d[6],y=d[7],j=[],L=(Ja+Ao*I)*Uint32Array.BYTES_PER_ELEMENT;let O;switch(y){case Int8Array.BYTES_PER_ELEMENT:O=new Int8Array(o.buffer,L);break;case Int16Array.BYTES_PER_ELEMENT:O=new Int16Array(o.buffer,L);break;case Int32Array.BYTES_PER_ELEMENT:O=new Int32Array(o.buffer,L);break}a=0;for(let R=0;R<I;R++){const F=d[Ao*R+Ja],U=new Float32Array(F+2);j.push(U);for(let V=0;V<Ao-1;V++)U[V]=d[Ao*R+Ja+V+1];for(let V=0;V<F;V++)U[V+2]=U[V]+O[a++]}return{areContours:w,thickness:b,outlines:j,width:m,height:g}}catch(t){return lt(`decompressSignature: ${t}`),null}}}class Kc extends Uu{constructor(){super(),super.updateProperties({fill:_e._defaultLineColor,"stroke-width":0})}clone(){const e=new Kc;return e.updateAll(this),e}}class _c extends fl{constructor(e){super(e),super.updateProperties({stroke:_e._defaultLineColor,"stroke-width":1})}clone(){const e=new _c(this._viewParameters);return e.updateAll(this),e}}class Bi extends nt{#e=!1;#t=null;#i=null;#s=null;static _type="signature";static _editorType=at.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){_e.initialize(e,t),this._defaultDrawingOptions=new Kc,this._defaultDrawnSignatureOptions=new _c(t.viewParameters)}static getDefaultDrawingOptions(e){const t=this._defaultDrawingOptions.clone();return t.updateProperties(e),t}static get supportMultipleDrawings(){return!1}static get typesMap(){return mt(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:s}=this;if(s&&(this._isCopy=!1,e=this.x,t=this.y),super.render(),this._drawId===null)if(this.#i){const{lines:i,mustSmooth:n,areContours:o,description:a,uuid:d,heightInPage:u}=this.#i,{rawDims:{pageWidth:m,pageHeight:g},rotation:w}=this.parent.viewport,b=Un.processDrawnLines({lines:i,pageWidth:m,pageHeight:g,rotation:w,innerMargin:Bi._INNER_MARGIN,mustSmooth:n,areContours:o});this.addSignature(b,u,a,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 s&&(this._isCopy=!0,this._moveAfterPaste(e,t)),this.div}setUuid(e){this.#s=e,this.addEditToolbar()}getUuid(){return this.#s}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:s,width:i,height:n}=this.#i,o=Math.max(i,n),a=Un.processDrawnLines({lines:{curves:e.map(d=>({points:d})),thickness:s,width:i,height:n},pageWidth:o,pageHeight:o,rotation:0,innerMargin:0,mustSmooth:!1,areContours:t});return{areContours:t,outline:a.outline}}get toolbarButtons(){return this._uiManager.signatureManager?[["editSignature",this._uiManager.signatureManager]]:super.toolbarButtons}addSignature(e,t,s,i){const{x:n,y:o}=this,{outline:a}=this.#i=e;this.#e=a instanceof Mc,this.description=s;let d;this.#e?d=Bi.getDefaultDrawingOptions():(d=Bi._defaultDrawnSignatureOptions.clone(),d.updateProperties({"stroke-width":a.thickness})),this._addOutlines({drawOutlines:a,drawingOptions:d});const[,u]=this.pageDimensions;let m=t/u;m=m>=1?.5:m,this.width*=m/this.height,this.width>=1&&(m*=.9/this.width,this.width=.9),this.height=m,this.setDims(),this.x=n,this.y=o,this.center(),this._onResized(),this.onScaleChanging(),this.rotate(),this._uiManager.addToAnnotationStorage(this),this.setUuid(i),this._reportTelemetry({action:"pdfjs.signature.inserted",data:{hasBeenSaved:!!i,hasDescription:!!s}}),this.div.hidden=!1}getFromImage(e){const{rawDims:{pageWidth:t,pageHeight:s},rotation:i}=this.parent.viewport;return Un.process(e,t,s,i,Bi._INNER_MARGIN)}getFromText(e,t){const{rawDims:{pageWidth:s,pageHeight:i},rotation:n}=this.parent.viewport;return Un.extractContoursFromText(e,t,s,i,n,Bi._INNER_MARGIN)}getDrawnSignature(e){const{rawDims:{pageWidth:t,pageHeight:s},rotation:i}=this.parent.viewport;return Un.processDrawnLines({lines:e,pageWidth:t,pageHeight:s,rotation:i,innerMargin:Bi._INNER_MARGIN,mustSmooth:!1,areContours:!1})}createDrawingOptions({areContours:e,thickness:t}){e?this._drawingOptions=Bi.getDefaultDrawingOptions():(this._drawingOptions=Bi._defaultDrawnSignatureOptions.clone(),this._drawingOptions.updateProperties({"stroke-width":t}))}serialize(e=!1){if(this.isEmpty())return null;const{lines:t,points:s}=this.serializeDraw(e),{_drawingOptions:{"stroke-width":i}}=this,n=Object.assign(super.serialize(e),{isSignature:!0,areContours:this.#e,color:[0,0,0],thickness:this.#e?0:i});return this.addComment(n),e?(n.paths={lines:t,points:s},n.uuid=this.#s,n.isCopy=!0):n.lines=t,this.#t&&(n.accessibilityData={type:"Figure",alt:this.#t}),n}static deserializeDraw(e,t,s,i,n,o){return o.areContours?Mc.deserialize(e,t,s,i,n,o):zo.deserialize(e,t,s,i,n,o)}static async deserialize(e,t,s){const i=await super.deserialize(e,t,s);return i.#e=e.areContours,i.description=e.accessibilityData?.alt||"",i.#s=e.uuid,i}}class k2 extends _e{#e=null;#t=null;#i=null;#s=null;#o=null;#n="";#r=null;#a=!1;#c=null;#l=!1;#f=!1;static _type="stamp";static _editorType=at.STAMP;constructor(e){super({...e,name:"stampEditor"}),this.#s=e.bitmapUrl,this.#o=e.bitmapFile,this.defaultL10nId="pdfjs-editor-stamp-editor"}static initialize(e,t){_e.initialize(e,t)}static isHandlingMimeForPasting(e){return $a.includes(e)}static paste(e,t){t.pasteEditor({mode:at.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}}#h(e,t=!1){if(!e){this.remove();return}this.#e=e.bitmap,t||(this.#t=e.id,this.#l=e.isSvg),e.file&&(this.#n=e.file.name),this.#p()}#u(){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:s}=this._uiManager;if(!s)throw new Error("No ML.");if(!await s.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:i,width:n,height:o}=e||this.copyCanvas(null,null,!0).imageData,a=await s.guess({name:"altText",request:{data:i,width:n,height:o,channels:i.length/(n*o)}});if(!a)throw new Error("No response from the AI service.");if(a.error)throw new Error("Error from the AI service.");if(a.cancel)return null;if(!a.output)throw new Error("No valid response from the AI service.");const d=a.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(s=>this.#h(s,!0)).finally(()=>this.#u());return}if(this.#s){const s=this.#s;this.#s=null,this._uiManager.enableWaiting(!0),this.#i=this._uiManager.imageManager.getFromUrl(s).then(i=>this.#h(i)).finally(()=>this.#u());return}if(this.#o){const s=this.#o;this.#o=null,this._uiManager.enableWaiting(!0),this.#i=this._uiManager.imageManager.getFromFile(s).then(i=>this.#h(i)).finally(()=>this.#u());return}const e=document.createElement("input");e.type="file",e.accept=$a.join(",");const t=this._uiManager._signal;this.#i=new Promise(s=>{e.addEventListener("change",async()=>{if(!e.files||e.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const i=await this._uiManager.imageManager.getFromFile(e.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),this.#h(i)}s()},{signal:t}),e.addEventListener("cancel",()=>{this.remove(),s()},{signal:t})}).finally(()=>this.#u()),e.click()}remove(){this.#t&&(this.#e=null,this._uiManager.imageManager.deleteId(this.#t),this.#r?.remove(),this.#r=null,this.#c&&(clearTimeout(this.#c),this.#c=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.#s||this.#o||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.#p():this.#g()),this._isCopy&&this._moveAfterPaste(e,t),this._uiManager.addShouldRescale(this),this.div}setCanvas(e,t){const{id:s,bitmap:i}=this._uiManager.imageManager.getFromCanvas(e,t);t.remove(),s&&this._uiManager.imageManager.isValidId(s)&&(this.#t=s,i&&(this.#e=i),this.#a=!1,this.#p())}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;this.#c!==null&&clearTimeout(this.#c);const e=200;this.#c=setTimeout(()=>{this.#c=null,this.#m()},e)}#p(){const{div:e}=this;let{width:t,height:s}=this.#e;const[i,n]=this.pageDimensions,o=.75;if(this.width)t=this.width*i,s=this.height*n;else if(t>o*i||s>o*n){const d=Math.min(o*i/t,o*n/s);t*=d,s*=d}this._uiManager.enableWaiting(!1);const a=this.#r=document.createElement("canvas");a.setAttribute("role","img"),this.addContainer(a),this.width=t/i,this.height=s/n,this.setDims(),this._initialOptions?.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(e.hidden=!1),this.#m(),this.#f||(this.parent.addUndoableEditor(this),this.#f=!0),this._reportTelemetry({action:"inserted_image"}),this.#n&&this.div.setAttribute("aria-description",this.#n),this.annotationElementId||this._uiManager.a11yAlert("pdfjs-editor-stamp-added-alert")}copyCanvas(e,t,s=!1){e||(e=224);const{width:i,height:n}=this.#e,o=new Mi;let a=this.#e,d=i,u=n,m=null;if(t){if(i>t||n>t){const V=Math.min(t/i,t/n);d=Math.floor(i*V),u=Math.floor(n*V)}m=document.createElement("canvas");const w=m.width=Math.ceil(d*o.sx),b=m.height=Math.ceil(u*o.sy);this.#l||(a=this.#d(w,b));const I=m.getContext("2d");I.filter=this._uiManager.hcmFilter;let y="white",j="#cfcfd8";this._uiManager.hcmFilter!=="none"?j="black":rx.isDarkMode&&(y="#8f8f9d",j="#42414d");const L=15,O=L*o.sx,R=L*o.sy,F=new OffscreenCanvas(O*2,R*2),U=F.getContext("2d");U.fillStyle=y,U.fillRect(0,0,O*2,R*2),U.fillStyle=j,U.fillRect(0,0,O,R),U.fillRect(O,R,O,R),I.fillStyle=I.createPattern(F,"repeat"),I.fillRect(0,0,w,b),I.drawImage(a,0,0,a.width,a.height,0,0,w,b)}let g=null;if(s){let w,b;if(o.symmetric&&a.width<e&&a.height<e)w=a.width,b=a.height;else if(a=this.#e,i>e||n>e){const j=Math.min(e/i,e/n);w=Math.floor(i*j),b=Math.floor(n*j),this.#l||(a=this.#d(w,b))}const y=new OffscreenCanvas(w,b).getContext("2d",{willReadFrequently:!0});y.drawImage(a,0,0,a.width,a.height,0,0,w,b),g={width:w,height:b,data:y.getImageData(0,0,w,b).data}}return{canvas:m,width:d,height:u,imageData:g}}#d(e,t){const{width:s,height:i}=this.#e;let n=s,o=i,a=this.#e;for(;n>2*e||o>2*t;){const d=n,u=o;n>2*e&&(n=n>=16384?Math.floor(n/2)-1:Math.ceil(n/2)),o>2*t&&(o=o>=16384?Math.floor(o/2)-1:Math.ceil(o/2));const m=new OffscreenCanvas(n,o);m.getContext("2d").drawImage(a,0,0,d,u,0,0,n,o),a=m.transferToImageBitmap()}return a}#m(){const[e,t]=this.parentDimensions,{width:s,height:i}=this,n=new Mi,o=Math.ceil(s*e*n.sx),a=Math.ceil(i*t*n.sy),d=this.#r;if(!d||d.width===o&&d.height===a)return;d.width=o,d.height=a;const u=this.#l?this.#e:this.#d(o,a),m=d.getContext("2d");m.filter=this._uiManager.hcmFilter,m.drawImage(u,0,0,u.width,u.height,0,0,o,a)}#A(e){if(e){if(this.#l){const i=this._uiManager.imageManager.getSvgUrl(this.#t);if(i)return i}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.#l){const[t,s]=this.pageDimensions,i=Math.round(this.width*t*Xn.PDF_TO_CSS_UNITS),n=Math.round(this.height*s*Xn.PDF_TO_CSS_UNITS),o=new OffscreenCanvas(i,n);return o.getContext("2d").drawImage(this.#e,0,0,this.#e.width,this.#e.height,0,0,i,n),o.transferToImageBitmap()}return structuredClone(this.#e)}static async deserialize(e,t,s){let i=null,n=!1;if(e instanceof Fu){const{data:{rect:y,rotation:j,id:L,structParent:O,popupRef:R,richText:F,contentsObj:U,creationDate:V,modificationDate:Q},container:K,parent:{page:{pageNumber:Z}},canvas:$}=e;let se,le;$?(delete e.canvas,{id:se,bitmap:le}=s.imageManager.getFromCanvas(K.id,$),$.remove()):(n=!0,e._hasNoCanvas=!0);const pe=(await t._structTree.getAriaAttributes(`${Bc}${L}`))?.get("aria-label")||"";i=e={annotationType:at.STAMP,bitmapId:se,bitmap:le,pageIndex:Z-1,rect:y.slice(0),rotation:j,annotationElementId:L,id:L,deleted:!1,accessibilityData:{decorative:!1,altText:pe},isSvg:!1,structParent:O,popupRef:R,richText:F,comment:U?.str||null,creationDate:V,modificationDate:Q}}const o=await super.deserialize(e,t,s),{rect:a,bitmap:d,bitmapUrl:u,bitmapId:m,isSvg:g,accessibilityData:w}=e;n?(s.addMissingCanvas(e.id,o),o.#a=!0):m&&s.imageManager.isValidId(m)?(o.#t=m,d&&(o.#e=d)):o.#s=u,o.#l=g;const[b,I]=o.pageDimensions;return o.width=(a[2]-a[0])/b,o.height=(a[3]-a[1])/I,w&&(o.altTextData=w),o._initialData=i,e.comment&&o.setCommentData(e),o.#f=!!i,o}serialize(e=!1,t=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const s=Object.assign(super.serialize(e),{bitmapId:this.#t,isSvg:this.#l});if(this.addComment(s),e)return s.bitmapUrl=this.#A(!0),s.accessibilityData=this.serializeAltText(!0),s.isCopy=!0,s;const{decorative:i,altText:n}=this.serializeAltText(!1);if(!i&&n&&(s.accessibilityData={type:"Figure",alt:n}),this.annotationElementId){const a=this.#w(s);return a.isSame?null:(a.isSameAltText?delete s.accessibilityData:s.accessibilityData.structParent=this._initialData.structParent??-1,s.id=this.annotationElementId,delete s.bitmapId,s)}if(t===null)return s;t.stamps||=new Map;const o=this.#l?(s.rect[2]-s.rect[0])*(s.rect[3]-s.rect[1]):null;if(!t.stamps.has(this.#t))t.stamps.set(this.#t,{area:o,serialized:s}),s.bitmap=this.#A(!1);else if(this.#l){const a=t.stamps.get(this.#t);o>a.area&&(a.area=o,a.serialized.bitmap.close(),a.serialized.bitmap=this.#A(!1))}return s}#w(e){const{pageIndex:t,accessibilityData:{altText:s}}=this._initialData,i=e.pageIndex===t,n=(e.accessibilityData?.alt||"")===s;return{isSame:!this.hasEditedComment&&!this._hasBeenMoved&&!this._hasBeenResized&&i&&n,isSameAltText:n}}renderAnnotationElement(e){return this.deleted?(e.hide(),null):(e.updateEdited({rect:this.getPDFRect(),popup:this.comment}),null)}}class Oi{#e;#t=!1;#i=null;#s=null;#o=null;#n=new Map;#r=!1;#a=!1;#c=!1;#l=null;#f=null;#h=null;#u=null;#g=null;#p=-1;#d;static _initialized=!1;static#m=new Map([ws,Zc,k2,ds,Bi].map(e=>[e._editorType,e]));constructor({uiManager:e,pageIndex:t,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:o,drawLayer:a,textLayer:d,viewport:u,l10n:m}){const g=[...Oi.#m.values()];if(!Oi._initialized){Oi._initialized=!0;for(const w of g)w.initialize(m,e)}e.registerEditorTypes(g),this.#d=e,this.pageIndex=t,this.div=s,this.#e=n,this.#i=o,this.viewport=u,this.#h=d,this.drawLayer=a,this._structTree=i,this.#d.addLayer(this)}get isEmpty(){return this.#n.size===0}get isInvisible(){return this.isEmpty&&this.#d.getMode()===at.NONE}updateToolbar(e){this.#d.updateToolbar(e)}updateMode(e=this.#d.getMode()){switch(this.#b(),e){case at.NONE:this.div.classList.toggle("nonEditing",!0),this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case at.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case at.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===at.POPUP)t.toggle("commentEditing",!0);else{t.toggle("commentEditing",!1);for(const s of Oi.#m.values())t.toggle(`${s._type}Editing`,e===s._editorType)}this.div.hidden=!1}hasTextLayer(e){return e===this.#h?.div}setEditingState(e){this.#d.setEditingState(e)}addCommands(e){this.#d.addCommands(e)}cleanUndoStack(e){this.#d.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#A(){return this.#n.size!==0?this.#n.values():this.#d.getEditors(this.pageIndex)}async enable(){this.#c=!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 s of this.#A)s.enableEditing(),s.show(!0),s.annotationElementId&&(this.#d.removeChangedExistingAnnotation(s),e.add(s.annotationElementId));const t=this.#i;if(t)for(const s of t.getEditableAnnotations()){if(s.hide(),this.#d.isDeletedAnnotationElement(s.data.id)||e.has(s.data.id))continue;const i=await this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}this.#c=!1,this.#d._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.#h&&!this.#g){this.#g=new AbortController;const s=this.#d.combinedSignal(this.#g);this.#h.div.addEventListener("pointerdown",i=>{const{clientX:o,clientY:a,timeStamp:d}=i,u=this.#p;if(d-u>500){this.#p=d;return}this.#p=-1;const{classList:m}=this.div;m.toggle("getElements",!0);const g=document.elementsFromPoint(o,a);if(m.toggle("getElements",!1),!this.div.contains(g[0]))return;let w;const b=new RegExp(`^${Eo}[0-9]+$`);for(const y of g)if(b.test(y.id)){w=y.id;break}if(!w)return;const I=this.#n.get(w);I?.annotationElementId===null&&(i.stopPropagation(),i.preventDefault(),I.dblclick(i))},{signal:s,capture:!0})}const e=this.#i;if(e){const s=new Map,i=new Map;for(const o of this.#A){if(o.disableEditing(),!o.annotationElementId){o.updateFakeAnnotationElement(e);continue}if(o.serialize()!==null){s.set(o.annotationElementId,o);continue}else i.set(o.annotationElementId,o);this.getEditableAnnotation(o.annotationElementId)?.show(),o.remove()}const n=e.getEditableAnnotations();for(const o of n){const{id:a}=o.data;if(this.#d.isDeletedAnnotationElement(a)){o.updateEdited({deleted:!0});continue}let d=i.get(a);if(d){d.resetAnnotationElement(o),d.show(!1),o.show();continue}d=s.get(a),d&&(this.#d.addChangedExistingAnnotation(d),d.renderAnnotationElement(o)&&d.show(!1)),o.show()}}this.#b(),this.isEmpty&&(this.div.hidden=!0);const{classList:t}=this.div;for(const s of Oi.#m.values())t.remove(`${s._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),this.#a=!1}getEditableAnnotation(e){return this.#i?.getEditableAnnotation(e)||null}setActiveEditor(e){this.#d.getActive()!==e&&this.#d.setActiveEditor(e)}enableTextSelection(){if(this.div.tabIndex=-1,this.#h?.div&&!this.#u){this.#u=new AbortController;const e=this.#d.combinedSignal(this.#u);this.#h.div.addEventListener("pointerdown",this.#w.bind(this),{signal:e}),this.#h.div.classList.add("highlighting")}}disableTextSelection(){this.div.tabIndex=0,this.#h?.div&&this.#u&&(this.#u.abort(),this.#u=null,this.#h.div.classList.remove("highlighting"))}#w(e){this.#d.unselectAll();const{target:t}=e;if(t===this.#h.div||(t.getAttribute("role")==="img"||t.classList.contains("endOfContent"))&&this.#h.div.contains(t)){const{isMac:s}=ys.platform;if(e.button!==0||e.ctrlKey&&s)return;this.#d.showAllEditors("highlight",!0,!0),this.#h.div.classList.add("free"),this.toggleDrawing(),ds.startHighlighting(this,this.#d.direction==="ltr",{target:this.#h.div,x:e.x,y:e.y}),this.#h.div.addEventListener("pointerup",()=>{this.#h.div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:this.#d._signal}),e.preventDefault()}}enableClick(){if(this.#s)return;this.#s=new AbortController;const e=this.#d.combinedSignal(this.#s);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.#s?.abort(),this.#s=null}attach(e){this.#n.set(e.id,e);const{annotationElementId:t}=e;t&&this.#d.isDeletedAnnotationElement(t)&&this.#d.removeDeletedAnnotationElement(e)}detach(e){this.#n.delete(e.id),this.#e?.removePointerInTextLayer(e.contentDiv),!this.#a&&e.annotationElementId&&this.#d.addDeletedAnnotationElement(e)}remove(e){this.detach(e),this.#d.removeEditor(e),e.div.remove(),e.isAttachedToDOM=!1}changeParent(e){e.parent!==this&&(e.parent&&e.annotationElementId&&(this.#d.addDeletedAnnotationElement(e.annotationElementId),_e.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.#d.addEditor(e),this.attach(e),!e.isAttachedToDOM){const t=e.render();this.div.append(t),e.isAttachedToDOM=!0}e.fixAndSetPosition(),e.onceAdded(!this.#c),this.#d.addToAnnotationStorage(e),e._reportTelemetry(e.telemetryInitialData)}}moveEditorInDOM(e){if(!e.isAttachedToDOM)return;const{activeElement:t}=document;e.div.contains(t)&&!this.#o&&(e._focusEventsAllowed=!1,this.#o=setTimeout(()=>{this.#o=null,e.div.contains(document.activeElement)?e._focusEventsAllowed=!0:(e.div.addEventListener("focusin",()=>{e._focusEventsAllowed=!0},{once:!0,signal:this.#d._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),s=()=>{e.remove()};this.addCommands({cmd:t,undo:s,mustExec:!1})}getEditorByUID(e){for(const t of this.#n.values())if(t.uid===e)return t;return null}getNextId(){return this.#d.getId()}get#x(){return Oi.#m.get(this.#d.getMode())}combinedSignal(e){return this.#d.combinedSignal(e)}#E(e){const t=this.#x;return t?new t.prototype.constructor(e):null}canCreateNewEmptyEditor(){return this.#x?.canCreateNewEmptyEditor()}async pasteEditor(e,t){this.updateToolbar(e),await this.#d.updateMode(e.mode);const{offsetX:s,offsetY:i}=this.#v(),n=this.getNextId(),o=this.#E({parent:this,id:n,x:s,y:i,uiManager:this.#d,isCentered:!0,...t});o&&this.add(o)}async deserialize(e){return await Oi.#m.get(e.annotationType??e.annotationEditorType)?.deserialize(e,this,this.#d)||null}createAndAddNewEditor(e,t,s={}){const i=this.getNextId(),n=this.#E({parent:this,id:i,x:e.offsetX,y:e.offsetY,uiManager:this.#d,isCentered:t,...s});return n&&this.add(n),n}get boundingClientRect(){return this.div.getBoundingClientRect()}#v(){const{x:e,y:t,width:s,height:i}=this.boundingClientRect,n=Math.max(0,e),o=Math.max(0,t),a=Math.min(window.innerWidth,e+s),d=Math.min(window.innerHeight,t+i),u=(n+a)/2-e,m=(o+d)/2-t,[g,w]=this.viewport.rotation%180===0?[u,m]:[m,u];return{offsetX:g,offsetY:w}}addNewEditor(e={}){this.createAndAddNewEditor(this.#v(),!0,e)}setSelected(e){this.#d.setSelected(e)}toggleSelected(e){this.#d.toggleSelected(e)}unselect(e){this.#d.unselect(e)}pointerup(e){const{isMac:t}=ys.platform;if(e.button!==0||e.ctrlKey&&t||e.target!==this.div||!this.#r||(this.#r=!1,this.#x?.isDrawer&&this.#x.supportMultipleDrawings))return;if(!this.#t){this.#t=!0;return}const s=this.#d.getMode();if(s===at.STAMP||s===at.SIGNATURE){this.#d.unselectAll();return}this.createAndAddNewEditor(e,!1)}pointerdown(e){if(this.#d.getMode()===at.HIGHLIGHT&&this.enableTextSelection(),this.#r){this.#r=!1;return}const{isMac:t}=ys.platform;if(e.button!==0||e.ctrlKey&&t||e.target!==this.div)return;if(this.#r=!0,this.#x?.isDrawer){this.startDrawingSession(e);return}const s=this.#d.getActive();this.#t=!s||s.isEmpty()}startDrawingSession(e){if(this.div.focus({preventScroll:!0}),this.#l){this.#x.startDrawing(this,this.#d,!1,e);return}this.#d.setCurrentDrawingSession(this),this.#l=new AbortController;const t=this.#d.combinedSignal(this.#l);this.div.addEventListener("blur",({relatedTarget:s})=>{s&&!this.div.contains(s)&&(this.#f=null,this.commitOrRemove())},{signal:t}),this.#x.startDrawing(this,this.#d,!1,e)}pause(e){if(e){const{activeElement:t}=document;this.div.contains(t)&&(this.#f=t);return}this.#f&&setTimeout(()=>{this.#f?.focus(),this.#f=null},0)}endDrawingSession(e=!1){return this.#l?(this.#d.setCurrentDrawingSession(null),this.#l.abort(),this.#l=null,this.#f=null,this.#x.endDrawing(e)):null}findNewParent(e,t,s){const i=this.#d.findParent(t,s);return i===null||i===this?!1:(i.changeParent(e),!0)}commitOrRemove(){return this.#l?(this.endDrawingSession(),!0):!1}onScaleChanging(){this.#l&&this.#x.onScaleChangingWhenDrawing(this)}destroy(){this.commitOrRemove(),this.#d.getActive()?.parent===this&&(this.#d.commitOrRemove(),this.#d.setActiveEditor(null)),this.#o&&(clearTimeout(this.#o),this.#o=null);for(const e of this.#n.values())this.#e?.removePointerInTextLayer(e.contentDiv),e.setParent(null),e.isAttachedToDOM=!1,e.div.remove();this.div=null,this.#n.clear(),this.#d.removeLayer(this)}#b(){for(const e of this.#n.values())e.isEmpty()&&e.remove()}render({viewport:e}){this.viewport=e,pn(this.div,e);for(const t of this.#d.getEditors(this.pageIndex))this.add(t),t.rebuild();this.updateMode()}update({viewport:e}){this.#d.commitOrRemove(),this.#b();const t=this.viewport.rotation,s=e.rotation;if(this.viewport=e,pn(this.div,{rotation:s}),t!==s)for(const i of this.#n.values())i.rotate(s)}get pageDimensions(){const{pageWidth:e,pageHeight:t}=this.viewport.rawDims;return[e,t]}get scale(){return this.#d.viewParameters.realScale}}class bs{#e=null;#t=new Map;#i=new Map;static#s=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 mt(this,"_svgFactory",new Lo)}static#o(e,[t,s,i,n]){const{style:o}=e;o.top=`${100*s}%`,o.left=`${100*t}%`,o.width=`${100*i}%`,o.height=`${100*n}%`}#n(){const e=bs._svgFactory.create(1,1,!0);return this.#e.append(e),e.setAttribute("aria-hidden",!0),e}#r(e,t){const s=bs._svgFactory.createElement("clipPath");e.append(s);const i=`clip_${t}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=bs._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${t}`),n.classList.add("clip"),i}#a(e,t){for(const[s,i]of Object.entries(t))i===null?e.removeAttribute(s):e.setAttribute(s,i)}draw(e,t=!1,s=!1){const i=bs.#s++,n=this.#n(),o=bs._svgFactory.createElement("defs");n.append(o);const a=bs._svgFactory.createElement("path");o.append(a);const d=`path_p${this.pageIndex}_${i}`;a.setAttribute("id",d),a.setAttribute("vector-effect","non-scaling-stroke"),t&&this.#i.set(i,a);const u=s?this.#r(o,d):null,m=bs._svgFactory.createElement("use");return n.append(m),m.setAttribute("href",`#${d}`),this.updateProperties(n,e),this.#t.set(i,n),{id:i,clipPathId:`url(#${u})`}}drawOutline(e,t){const s=bs.#s++,i=this.#n(),n=bs._svgFactory.createElement("defs");i.append(n);const o=bs._svgFactory.createElement("path");n.append(o);const a=`path_p${this.pageIndex}_${s}`;o.setAttribute("id",a),o.setAttribute("vector-effect","non-scaling-stroke");let d;if(t){const g=bs._svgFactory.createElement("mask");n.append(g),d=`mask_p${this.pageIndex}_${s}`,g.setAttribute("id",d),g.setAttribute("maskUnits","objectBoundingBox");const w=bs._svgFactory.createElement("rect");g.append(w),w.setAttribute("width","1"),w.setAttribute("height","1"),w.setAttribute("fill","white");const b=bs._svgFactory.createElement("use");g.append(b),b.setAttribute("href",`#${a}`),b.setAttribute("stroke","none"),b.setAttribute("fill","black"),b.setAttribute("fill-rule","nonzero"),b.classList.add("mask")}const u=bs._svgFactory.createElement("use");i.append(u),u.setAttribute("href",`#${a}`),d&&u.setAttribute("mask",`url(#${d})`);const m=u.cloneNode();return i.append(m),u.classList.add("mainOutline"),m.classList.add("secondaryOutline"),this.updateProperties(i,e),this.#t.set(s,i),s}finalizeDraw(e,t){this.#i.delete(e),this.updateProperties(e,t)}updateProperties(e,t){if(!t)return;const{root:s,bbox:i,rootClass:n,path:o}=t,a=typeof e=="number"?this.#t.get(e):e;if(a){if(s&&this.#a(a,s),i&&bs.#o(a,i),n){const{classList:d}=a;for(const[u,m]of Object.entries(n))d.toggle(u,m)}if(o){const u=a.firstChild.firstChild;this.#a(u,o)}}}updateParent(e,t){if(t===this)return;const s=this.#t.get(e);s&&(t.#e.append(s),this.#t.delete(e),t.#t.set(e,s))}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:Ic};globalThis.pdfjsLib={AbortException:sn,AnnotationEditorLayer:Oi,AnnotationEditorParamsType:Mt,AnnotationEditorType:at,AnnotationEditorUIManager:nn,AnnotationLayer:qc,AnnotationMode:Fi,AnnotationType:cs,applyOpacity:fu,build:ku,ColorPicker:si,createValidAbsoluteUrl:Nc,CSSConstants:hu,DOMSVGFactory:Lo,DrawLayer:bs,FeatureTest:ys,fetchData:Dr,findContrastColor:uu,getDocument:Qc,getFilenameFromUrl:lu,getPdfFilenameFromUrl:cu,getRGB:Lr,getUuid:Tc,getXfaPageViewport:du,GlobalWorkerOptions:un,ImageKind:yo,InvalidPDFException:Ka,isDataScheme:Po,isPdfFile:dl,isValidExplicitDest:Au,MathClamp:js,noContextMenu:ri,normalizeUnicode:ou,OPS:Mr,OutputScale:Mi,PasswordResponses:nu,PDFDataRangeTransport:Jc,PDFDateString:_a,PDFWorker:Sr,PermissionFlag:iu,PixelsPerInch:Xn,RenderingCancelledException:cl,renderRichText:Oc,ResponseException:Mo,setLayerDimensions:pn,shadow:mt,SignatureExtractor:Un,stopEvent:rs,SupportedImageMimeTypes:$a,TextLayer:jo,TouchManager:Fo,updateUrlHash:kc,Util:He,VerbosityLevel:ko,version:Xc,XfaLayer:Pc};const T2=Object.freeze(Object.defineProperty({__proto__:null,AbortException:sn,AnnotationEditorLayer:Oi,AnnotationEditorParamsType:Mt,AnnotationEditorType:at,AnnotationEditorUIManager:nn,AnnotationLayer:qc,AnnotationMode:Fi,AnnotationType:cs,CSSConstants:hu,ColorPicker:si,DOMSVGFactory:Lo,DrawLayer:bs,FeatureTest:ys,GlobalWorkerOptions:un,ImageKind:yo,InvalidPDFException:Ka,MathClamp:js,OPS:Mr,OutputScale:Mi,PDFDataRangeTransport:Jc,PDFDateString:_a,PDFWorker:Sr,PasswordResponses:nu,PermissionFlag:iu,PixelsPerInch:Xn,RenderingCancelledException:cl,ResponseException:Mo,SignatureExtractor:Un,SupportedImageMimeTypes:$a,TextLayer:jo,TouchManager:Fo,Util:He,VerbosityLevel:ko,XfaLayer:Pc,applyOpacity:fu,build:ku,createValidAbsoluteUrl:Nc,fetchData:Dr,findContrastColor:uu,getDocument:Qc,getFilenameFromUrl:lu,getPdfFilenameFromUrl:cu,getRGB:Lr,getUuid:Tc,getXfaPageViewport:du,isDataScheme:Po,isPdfFile:dl,isValidExplicitDest:Au,noContextMenu:ri,normalizeUnicode:ou,renderRichText:Oc,setLayerDimensions:pn,shadow:mt,stopEvent:rs,updateUrlHash:kc,version:Xc},Symbol.toStringTag,{value:"Module"}));function Hu(c){var e,t,s="";if(typeof c=="string"||typeof c=="number")s+=c;else if(typeof c=="object")if(Array.isArray(c)){var i=c.length;for(e=0;e<i;e++)c[e]&&(t=Hu(c[e]))&&(s&&(s+=" "),s+=t)}else for(t in c)c[t]&&(s&&(s+=" "),s+=t);return s}function ul(){for(var c,e,t=0,s="",i=arguments.length;t<i;t++)(c=arguments[t])&&(e=Hu(c))&&(s&&(s+=" "),s+=e);return s}var Lf=Object.prototype.hasOwnProperty;function Nf(c,e,t){for(t of c.keys())if(yr(t,e))return t}function yr(c,e){var t,s,i;if(c===e)return!0;if(c&&e&&(t=c.constructor)===e.constructor){if(t===Date)return c.getTime()===e.getTime();if(t===RegExp)return c.toString()===e.toString();if(t===Array){if((s=c.length)===e.length)for(;s--&&yr(c[s],e[s]););return s===-1}if(t===Set){if(c.size!==e.size)return!1;for(s of c)if(i=s,i&&typeof i=="object"&&(i=Nf(e,i),!i)||!e.has(i))return!1;return!0}if(t===Map){if(c.size!==e.size)return!1;for(s of c)if(i=s[0],i&&typeof i=="object"&&(i=Nf(e,i),!i)||!yr(s[1],e.get(i)))return!1;return!0}if(t===ArrayBuffer)c=new Uint8Array(c),e=new Uint8Array(e);else if(t===DataView){if((s=c.byteLength)===e.byteLength)for(;s--&&c.getInt8(s)===e.getInt8(s););return s===-1}if(ArrayBuffer.isView(c)){if((s=c.byteLength)===e.byteLength)for(;s--&&c[s]===e[s];);return s===-1}if(!t||typeof c=="object"){s=0;for(t in c)if(Lf.call(c,t)&&++s&&!Lf.call(e,t)||!(t in e)||!yr(c[t],e[t]))return!1;return Object.keys(e).length===s}}return c!==c&&e!==e}function Uo(c){let e=!1;return{promise:new Promise((s,i)=>{c.then(n=>!e&&s(n)).catch(n=>!e&&i(n))}),cancel(){e=!0}}}const B2=["onCopy","onCut","onPaste"],P2=["onCompositionEnd","onCompositionStart","onCompositionUpdate"],O2=["onFocus","onBlur"],F2=["onInput","onInvalid","onReset","onSubmit"],R2=["onLoad","onError"],z2=["onKeyDown","onKeyPress","onKeyUp"],U2=["onAbort","onCanPlay","onCanPlayThrough","onDurationChange","onEmptied","onEncrypted","onEnded","onError","onLoadedData","onLoadedMetadata","onLoadStart","onPause","onPlay","onPlaying","onProgress","onRateChange","onSeeked","onSeeking","onStalled","onSuspend","onTimeUpdate","onVolumeChange","onWaiting"],H2=["onClick","onContextMenu","onDoubleClick","onMouseDown","onMouseEnter","onMouseLeave","onMouseMove","onMouseOut","onMouseOver","onMouseUp"],Y2=["onDrag","onDragEnd","onDragEnter","onDragExit","onDragLeave","onDragOver","onDragStart","onDrop"],Q2=["onSelect"],W2=["onTouchCancel","onTouchEnd","onTouchMove","onTouchStart"],J2=["onPointerDown","onPointerMove","onPointerUp","onPointerCancel","onGotPointerCapture","onLostPointerCapture","onPointerEnter","onPointerLeave","onPointerOver","onPointerOut"],X2=["onScroll"],G2=["onWheel"],V2=["onAnimationStart","onAnimationEnd","onAnimationIteration"],q2=["onTransitionEnd"],Z2=["onToggle"],K2=["onChange"],_2=[...B2,...P2,...O2,...F2,...R2,...z2,...U2,...H2,...Y2,...Q2,...W2,...J2,...X2,...G2,...V2,...q2,...K2,...Z2];function Yu(c,e){const t={};for(const s of _2){const i=c[s];i&&(e?t[s]=(n=>i(n,e(s))):t[s]=i)}return t}var $2=process.env.NODE_ENV==="production",uc="Invariant failed";function Wt(c,e){if(!c){if($2)throw new Error(uc);var t=typeof e=="function"?e():e,s=t?"".concat(uc,": ").concat(t):uc;throw new Error(s)}}var pc,kf;function ew(){if(kf)return pc;kf=1;var c=process.env.NODE_ENV!=="production",e=function(){};if(c){var t=function(i,n){var o=arguments.length;n=new Array(o>1?o-1:0);for(var a=1;a<o;a++)n[a-1]=arguments[a];var d=0,u="Warning: "+i.replace(/%s/g,function(){return n[d++]});typeof console<"u"&&console.error(u);try{throw new Error(u)}catch{}};e=function(s,i,n){var o=arguments.length;n=new Array(o>2?o-2:0);for(var a=2;a<o;a++)n[a-2]=arguments[a];if(i===void 0)throw new Error("`warning(condition, format, ...args)` requires a warning message argument");s||t.apply(null,[i].concat(n))}}return pc=e,pc}var tw=ew();const Ds=Wf(tw),Qu=k.createContext(null),sw="noopener noreferrer nofollow";class iw{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 Wt(this.pdfViewer,"PDF viewer is not initialized."),this.pdfViewer.currentPageNumber||0}set page(e){Wt(this.pdfViewer,"PDF viewer is not initialized."),this.pdfViewer.currentPageNumber=e}get rotation(){return 0}set rotation(e){}addLinkAttributes(e,t,s){e.href=t,e.rel=this.externalLinkRel||sw,e.target=s?"_blank":this.externalLinkTarget||""}goToDestination(e){return new Promise(t=>{Wt(this.pdfDocument,"PDF document not loaded."),Wt(e,"Destination is not specified."),typeof e=="string"?this.pdfDocument.getDestination(e).then(t):Array.isArray(e)?t(e):e.then(t)}).then(t=>{Wt(Array.isArray(t),`"${t}" is not a valid destination array.`);const s=t[0];new Promise(i=>{Wt(this.pdfDocument,"PDF document not loaded."),s instanceof Object?this.pdfDocument.getPageIndex(s).then(n=>{i(n)}).catch(()=>{Wt(!1,`"${s}" is not a valid page reference.`)}):typeof s=="number"?i(s):Wt(!1,`"${s}" is not a valid destination reference.`)}).then(i=>{const n=i+1;Wt(this.pdfViewer,"PDF viewer is not initialized."),Wt(n>=1&&n<=this.pagesCount,`"${n}" is not a valid page number.`),this.pdfViewer.scrollPageIntoView({dest:t,pageIndex:i,pageNumber:n})})})}goToPage(e){const t=e-1;Wt(this.pdfViewer,"PDF viewer is not initialized."),Wt(e>=1&&e<=this.pagesCount,`"${e}" is not a valid page number.`),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 Cr({children:c,type:e}){return r.jsx("div",{className:`react-pdf__message react-pdf__message--${e}`,children:c})}const Tf={NEED_PASSWORD:1,INCORRECT_PASSWORD:2};function nw(c,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 c}}function jr(){return k.useReducer(nw,{value:void 0,error:void 0})}const pl=typeof window<"u",Wu=pl&&window.location.protocol==="file:";function rw(c){return typeof c<"u"}function zn(c){return rw(c)&&c!==null}function ow(c){return typeof c=="string"}function aw(c){return c instanceof ArrayBuffer}function lw(c){return Wt(pl,"isBlob can only be used in a browser environment"),c instanceof Blob}function Sc(c){return ow(c)&&/^data:/.test(c)}function Bf(c){Wt(Sc(c),"Invalid data URI.");const[e="",t=""]=c.split(",");return e.split(";").indexOf("base64")!==-1?atob(t):unescape(t)}function cw(){return pl&&window.devicePixelRatio||1}const Ju="On Chromium based browsers, you can use --allow-file-access-from-files flag for debugging purposes.";function Pf(){Ds(!Wu,`Loading PDF as base64 strings/URLs may not work on protocols other than HTTP/HTTPS. ${Ju}`)}function dw(){Ds(!Wu,`Loading PDF.js worker may not work on protocols other than HTTP/HTTPS. ${Ju}`)}function Vn(c){c?.cancel&&c.cancel()}function jc(c,e){return Object.defineProperty(c,"width",{get(){return this.getViewport({scale:e}).width},configurable:!0}),Object.defineProperty(c,"height",{get(){return this.getViewport({scale:e}).height},configurable:!0}),Object.defineProperty(c,"originalWidth",{get(){return this.getViewport({scale:1}).width},configurable:!0}),Object.defineProperty(c,"originalHeight",{get(){return this.getViewport({scale:1}).height},configurable:!0}),c}function Xu(c){return c.name==="AbortException"||c.name==="RenderingCancelledException"}function hw(c){return new Promise((e,t)=>{const s=new FileReader;s.onload=()=>{if(!s.result)return t(new Error("Error while reading a file."));e(s.result)},s.onerror=i=>{if(!i.target)return t(new Error("Error while reading a file."));const{error:n}=i.target;if(!n)return t(new Error("Error while reading a file."));switch(n.code){case n.NOT_FOUND_ERR:return t(new Error("Error while reading a file: File not found."));case n.SECURITY_ERR:return t(new Error("Error while reading a file: Security error."));case n.ABORT_ERR:return t(new Error("Error while reading a file: Aborted."));default:return t(new Error("Error while reading a file."))}},s.readAsArrayBuffer(c)})}const{PDFDataRangeTransport:fw}=T2,uw=(c,e)=>{switch(e){case Tf.NEED_PASSWORD:{const t=prompt("Enter the password to open this PDF file.");c(t);break}case Tf.INCORRECT_PASSWORD:{const t=prompt("Invalid password. Please try again.");c(t);break}}};function Of(c){return typeof c=="object"&&c!==null&&("data"in c||"range"in c||"url"in c)}const pw=k.forwardRef(function({children:e,className:t,error:s="Failed to load PDF file.",externalLinkRel:i,externalLinkTarget:n,file:o,inputRef:a,imageResourcesPath:d,loading:u="Loading PDF…",noData:m="No PDF file specified.",onItemClick:g,onLoadError:w,onLoadProgress:b,onLoadSuccess:I,onPassword:y=uw,onSourceError:j,onSourceSuccess:L,options:O,renderMode:R,rotate:F,scale:U,...V},Q){const[K,Z]=jr(),{value:$,error:se}=K,[le,pe]=jr(),{value:oe,error:he}=le,ne=k.useRef(new iw),re=k.useRef([]),fe=k.useRef(void 0),we=k.useRef(void 0);o&&o!==fe.current&&Of(o)&&(Ds(!yr(o,fe.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.`),fe.current=o),O&&O!==we.current&&(Ds(!yr(O,we.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.`),we.current=O);const xe=k.useRef({scrollPageIntoView:Be=>{const{dest:ze,pageNumber:te,pageIndex:ue=te-1}=Be;if(g){g({dest:ze,pageIndex:ue,pageNumber:te});return}const je=re.current[ue];if(je){je.scrollIntoView();return}Ds(!1,`An internal link leading to page ${te} 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>.`)}});k.useImperativeHandle(Q,()=>({linkService:ne,pages:re,viewer:xe}),[]);function Te(){L&&L()}function Ne(){se&&(Ds(!1,se.toString()),j&&j(se))}function De(){Z({type:"RESET"})}k.useEffect(De,[o,Z]);const Je=k.useCallback(async()=>{if(!o)return null;if(typeof o=="string")return Sc(o)?{data:Bf(o)}:(Pf(),{url:o});if(o instanceof fw)return{range:o};if(aw(o))return{data:o};if(pl&&lw(o))return{data:await hw(o)};if(Wt(typeof o=="object","Invalid parameter in file, need either Uint8Array, string or a parameter object"),Wt(Of(o),"Invalid parameter object: need either .data, .range or .url"),"url"in o&&typeof o.url=="string"){if(Sc(o.url)){const{url:Be,...ze}=o;return{data:Bf(Be),...ze}}Pf()}return o},[o]);k.useEffect(()=>{const Be=Uo(Je());return Be.promise.then(ze=>{Z({type:"RESOLVE",value:ze})}).catch(ze=>{Z({type:"REJECT",error:ze})}),()=>{Vn(Be)}},[Je,Z]),k.useEffect(()=>{if(!(typeof $>"u")){if($===!1){Ne();return}Te()}},[$]);function ke(){oe&&(I&&I(oe),re.current=new Array(oe.numPages),ne.current.setDocument(oe))}function Re(){he&&(Ds(!1,he.toString()),w&&w(he))}k.useEffect(function(){pe({type:"RESET"})},[pe,$]),k.useEffect(function(){if(!$)return;const ze=O?{...$,...O}:$,te=Qc(ze);b&&(te.onProgress=b),y&&(te.onPassword=y);const ue=te;return ue.promise.then(je=>{ue.destroyed||pe({type:"RESOLVE",value:je})}).catch(je=>{ue.destroyed||pe({type:"REJECT",error:je})}),()=>{ue.destroy()}},[O,pe,$]),k.useEffect(()=>{if(!(typeof oe>"u")){if(oe===!1){Re();return}ke()}},[oe]),k.useEffect(function(){ne.current.setViewer(xe.current),ne.current.setExternalLinkRel(i),ne.current.setExternalLinkTarget(n)},[i,n]);const de=k.useCallback((Be,ze)=>{re.current[Be]=ze},[]),Ee=k.useCallback(Be=>{delete re.current[Be]},[]),Ge=k.useMemo(()=>({imageResourcesPath:d,linkService:ne.current,onItemClick:g,pdf:oe,registerPage:de,renderMode:R,rotate:F,scale:U,unregisterPage:Ee}),[d,g,oe,de,R,F,U,Ee]),Ye=k.useMemo(()=>Yu(V,()=>oe),[V,oe]);function Qe(){function Be(te){return!!te?.pdf}if(!Be(Ge))throw new Error("pdf is undefined");const ze=typeof e=="function"?e(Ge):e;return r.jsx(Qu.Provider,{value:Ge,children:ze})}function Se(){return o?oe==null?r.jsx(Cr,{type:"loading",children:typeof u=="function"?u():u}):oe===!1?r.jsx(Cr,{type:"error",children:typeof s=="function"?s():s}):Qe():r.jsx(Cr,{type:"no-data",children:typeof m=="function"?m():m})}return r.jsx("div",{className:ul("react-pdf__Document",t),ref:a,...Ye,children:Se()})});function Gu(){return k.useContext(Qu)}function Vu(){for(var c=[],e=0;e<arguments.length;e++)c[e]=arguments[e];var t=c.filter(Boolean);if(t.length<=1){var s=t[0];return s||null}return function(n){for(var o=0,a=t;o<a.length;o++){var d=a[o];typeof d=="function"?d(n):d&&(d.current=n)}}}const qu=k.createContext(null);function ml(){return k.useContext(qu)}function mw(){const c=Gu(),e=ml();Wt(e,"Unable to find Page context.");const t={...c,...e},{filterAnnotations:s,imageResourcesPath:i,linkService:n,onGetAnnotationsError:o,onGetAnnotationsSuccess:a,onRenderAnnotationLayerError:d,onRenderAnnotationLayerSuccess:u,page:m,pdf:g,renderForms:w,rotate:b,scale:I=1}=t;Wt(g,"Attempted to load page annotations, but no document was specified. Wrap <Page /> in a <Document /> or pass explicit `pdf` prop."),Wt(m,"Attempted to load page annotations, but no page was specified."),Wt(n,"Attempted to load page annotations, but no linkService was specified.");const[y,j]=jr(),{value:L,error:O}=y,R=k.useRef(null);Ds(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 F(){L&&a&&a(L)}function U(){O&&(Ds(!1,O.toString()),o&&o(O))}k.useEffect(function(){j({type:"RESET"})},[j,m]),k.useEffect(function(){if(!m)return;const $=Uo(m.getAnnotations()),se=$;return $.promise.then(le=>{j({type:"RESOLVE",value:le})}).catch(le=>{j({type:"REJECT",error:le})}),()=>{Vn(se)}},[j,m]),k.useEffect(()=>{if(L!==void 0){if(L===!1){U();return}F()}},[L]);function V(){u&&u()}function Q(Z){Ds(!1,`${Z}`),d&&d(Z)}const K=k.useMemo(()=>m.getViewport({scale:I,rotation:b}),[m,b,I]);return k.useEffect(function(){if(!g||!m||!n||!L)return;const{current:$}=R;if(!$)return;const se=K.clone({dontFlip:!0}),le={accessibilityManager:null,annotationCanvasMap:null,annotationEditorUIManager:null,annotationStorage:g.annotationStorage,commentManager:null,div:$,l10n:null,linkService:n,page:m,structTreeLayer:null,viewport:se},pe={annotations:s?s({annotations:L}):L,annotationStorage:g.annotationStorage,div:$,imageResourcesPath:i,linkService:n,page:m,renderForms:w,viewport:se};$.innerHTML="";try{new qc(le).render(pe),V()}catch(oe){Q(oe)}return()=>{}},[L,s,i,n,m,g,w,K]),r.jsx("div",{className:ul("react-pdf__Page__annotations","annotationLayer"),ref:R})}const Zu={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},gw=/^H(\d+)$/;function Aw(c){return c in Zu}function gl(c){return"children"in c}function Ku(c){return gl(c)?c.children.length===1&&0 in c.children&&"id"in c.children[0]:!1}function xw(c){const e={};if(gl(c)){const{role:t}=c,s=t.match(gw);if(s)e.role="heading",e["aria-level"]=Number(s[1]);else if(Aw(t)){const i=Zu[t];i&&(e.role=i)}}return e}function _u(c){const e={};if(gl(c)){if(c.alt!==void 0&&(e["aria-label"]=c.alt),c.lang!==void 0&&(e.lang=c.lang),Ku(c)){const[t]=c.children;if(t){const s=_u(t);return{...e,...s}}}}else"id"in c&&(e["aria-owns"]=c.id);return e}function ww(c){return c?{...xw(c),..._u(c)}:null}function $u({className:c,node:e}){const t=k.useMemo(()=>ww(e),[e]),s=k.useMemo(()=>!gl(e)||Ku(e)?null:e.children.map((i,n)=>r.jsx($u,{node:i},n)),[e]);return r.jsx("span",{className:c,...t,children:s})}function bw(){const c=ml();Wt(c,"Unable to find Page context.");const{onGetStructTreeError:e,onGetStructTreeSuccess:t}=c,[s,i]=jr(),{value:n,error:o}=s,{customTextRenderer:a,page:d}=c;function u(){n&&t&&t(n)}function m(){o&&(Ds(!1,o.toString()),e&&e(o))}return k.useEffect(function(){i({type:"RESET"})},[i,d]),k.useEffect(function(){if(a||!d)return;const w=Uo(d.getStructTree()),b=w;return w.promise.then(I=>{i({type:"RESOLVE",value:I})}).catch(I=>{i({type:"REJECT",error:I})}),()=>Vn(b)},[a,d,i]),k.useEffect(()=>{if(n!==void 0){if(n===!1){m();return}u()}},[n]),n?r.jsx($u,{className:"react-pdf__Page__structTree structTree",node:n}):null}const Ff=Fi;function yw(c){const e=ml();Wt(e,"Unable to find Page context.");const t={...e,...c},{_className:s,canvasBackground:i,devicePixelRatio:n=cw(),onRenderError:o,onRenderSuccess:a,page:d,renderForms:u,renderTextLayer:m,pageColors:g,rotate:w,scale:b}=t,{canvasRef:I}=c;Wt(d,"Attempted to render page canvas, but no page was specified.");const y=k.useRef(null);function j(){d&&a&&a(jc(d,b))}function L(U){Xu(U)||(Ds(!1,U.toString()),o&&o(U))}const O=k.useMemo(()=>d.getViewport({scale:b*n,rotation:w}),[n,d,w,b]),R=k.useMemo(()=>d.getViewport({scale:b,rotation:w}),[d,w,b]);k.useEffect(function(){if(!d)return;d.cleanup();const{current:V}=y;if(!V)return;V.width=O.width,V.height=O.height,V.style.width=`${Math.floor(R.width)}px`,V.style.height=`${Math.floor(R.height)}px`,V.style.visibility="hidden";const Q={annotationMode:u?Ff.ENABLE_FORMS:Ff.ENABLE,canvas:V,canvasContext:V.getContext("2d",{alpha:!1}),pageColors:g,viewport:O};i&&(Q.background=i);const K=d.render(Q),Z=K;return K.promise.then(()=>{V.style.visibility="",j()}).catch(L),()=>Vn(Z)},[i,d,g,u,O,R]);const F=k.useCallback(()=>{const{current:U}=y;U&&(U.width=0,U.height=0)},[]);return k.useEffect(()=>F,[F]),r.jsx("canvas",{className:`${s}__canvas`,dir:"ltr",ref:Vu(I,y),style:{display:"block",userSelect:"none"},children:m?r.jsx(bw,{}):null})}function Cw(c){return"str"in c}const vw=new Set(["base","embed","iframe","link","meta","object","script","style","template"]),Iw=new Set(["action","formaction","href","poster","src","xlink:href"]);function Ew(c){let e="";for(const t of c){const s=t.charCodeAt(0);s<=32||s===127||(e+=t.toLowerCase())}return e.startsWith("javascript:")||e.startsWith("vbscript:")}function Mw(c){return c.nodeType===Node.ELEMENT_NODE}function ep(c){return Mw(c)&&c instanceof HTMLElement}function Sw(c){return ep(c)&&vw.has(c.tagName.toLowerCase())}function jw(c){const e=document.createElement(c.tagName.toLowerCase());return Array.from(c.attributes).forEach(t=>{const s=t.name.toLowerCase();s.startsWith("on")||s==="srcdoc"||Iw.has(s)&&Ew(t.value)||e.setAttribute(t.name,t.value)}),Array.from(c.childNodes).forEach(t=>{e.append(tp(t))}),e}function tp(c){var e;return ep(c)&&!Sw(c)?jw(c):document.createTextNode((e=c.textContent)!==null&&e!==void 0?e:"")}function Dw(c,e){const t=document.createElement("template");t.innerHTML=e;const s=document.createDocumentFragment();Array.from(t.content.childNodes).forEach(i=>{s.append(tp(i))}),c.replaceChildren(s)}function Lw(){const c=ml();Wt(c,"Unable to find Page context.");const{customTextRenderer:e,onGetTextError:t,onGetTextSuccess:s,onRenderTextLayerError:i,onRenderTextLayerSuccess:n,page:o,pageIndex:a,pageNumber:d,rotate:u,scale:m}=c;Wt(o,"Attempted to load page text content, but no page was specified.");const[g,w]=jr(),{value:b,error:I}=g,y=k.useRef(null);Ds(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(){b&&s&&s(b)}function L(){I&&(Ds(!1,I.toString()),t&&t(I))}k.useEffect(function(){w({type:"RESET"})},[o,w]),k.useEffect(function(){if(!o)return;const K=Uo(o.getTextContent()),Z=K;return K.promise.then($=>{w({type:"RESOLVE",value:$})}).catch($=>{w({type:"REJECT",error:$})}),()=>Vn(Z)},[o,w]),k.useEffect(()=>{if(b!==void 0){if(b===!1){L();return}j()}},[b]);const O=k.useCallback(()=>{n&&n()},[n]),R=k.useCallback(Q=>{Xu(Q)||(Ds(!1,Q.toString()),i&&i(Q))},[i]);function F(){const Q=y.current;Q&&Q.classList.add("selecting")}function U(){const Q=y.current;Q&&Q.classList.remove("selecting")}const V=k.useMemo(()=>o.getViewport({scale:m,rotation:u}),[o,u,m]);return k.useLayoutEffect(function(){if(!o||!b)return;const{current:K}=y;if(!K)return;K.innerHTML="";const Z=o.streamTextContent({includeMarkedContent:!0}),$={container:K,textContentSource:Z,viewport:V},se=new jo($),le=se;return se.render().then(()=>{const pe=document.createElement("div");pe.className="endOfContent",K.append(pe);const oe=K.querySelectorAll('[role="presentation"]');if(e){let he=0;b.items.forEach((ne,re)=>{if(!Cw(ne))return;const fe=oe[he];if(!fe)return;const we=e({pageIndex:a,pageNumber:d,itemIndex:re,...ne});Dw(fe,we),he+=ne.str&&ne.hasEOL?2:1})}O()}).catch(R),()=>Vn(le)},[e,R,O,o,a,d,b,V]),r.jsx("div",{className:ul("react-pdf__Page__textContent","textLayer"),onMouseUp:U,onMouseDown:F,ref:y})}const Rf=1;function Nw(c){const t={...Gu(),...c},{_className:s="react-pdf__Page",_enableRegisterUnregisterPage:i=!0,canvasBackground:n,canvasRef:o,children:a,className:d,customRenderer:u,customTextRenderer:m,devicePixelRatio:g,error:w="Failed to load the page.",filterAnnotations:b,height:I,inputRef:y,loading:j="Loading page…",noData:L="No page specified.",onGetAnnotationsError:O,onGetAnnotationsSuccess:R,onGetStructTreeError:F,onGetStructTreeSuccess:U,onGetTextError:V,onGetTextSuccess:Q,onLoadError:K,onLoadSuccess:Z,onRenderAnnotationLayerError:$,onRenderAnnotationLayerSuccess:se,onRenderError:le,onRenderSuccess:pe,onRenderTextLayerError:oe,onRenderTextLayerSuccess:he,pageColors:ne,pageIndex:re,pageNumber:fe,pdf:we,registerPage:xe,renderAnnotationLayer:Te=!0,renderForms:Ne=!1,renderMode:De="canvas",renderTextLayer:Je=!0,rotate:ke,scale:Re=Rf,unregisterPage:de,width:Ee,...Ge}=t,[Ye,Qe]=jr(),{value:Se,error:Be}=Ye,ze=k.useRef(null);Wt(we,"Attempted to load a page, but no document was specified. Wrap <Page /> in a <Document /> or pass explicit `pdf` prop.");const te=zn(fe)?fe-1:re??null,ue=fe??(zn(re)?re+1:null),je=ke??(Se?Se.rotate:null),Pe=k.useMemo(()=>{if(!Se)return null;let It=1;const Lt=Re??Rf;if(Ee||I){const Et=Se.getViewport({scale:1,rotation:je});Ee?It=Ee/Et.width:I&&(It=I/Et.height)}return Lt*It},[I,Se,je,Re,Ee]);k.useEffect(function(){return()=>{zn(te)&&i&&de&&de(te)}},[i,we,te,de]);function Xe(){if(Z){if(!Se||!Pe)return;Z(jc(Se,Pe))}if(i&&xe){if(!zn(te)||!ze.current)return;xe(te,ze.current)}}function ot(){Be&&(Ds(!1,Be.toString()),K&&K(Be))}k.useEffect(function(){Qe({type:"RESET"})},[Qe,we,te]),k.useEffect(function(){if(!we||!ue)return;const Lt=Uo(we.getPage(ue)),Et=Lt;return Lt.promise.then(yt=>{Qe({type:"RESOLVE",value:yt})}).catch(yt=>{Qe({type:"REJECT",error:yt})}),()=>Vn(Et)},[Qe,we,ue]),k.useEffect(()=>{if(Se!==void 0){if(Se===!1){ot();return}Xe()}},[Se,Pe]);const ht=k.useMemo(()=>zn(te)&&ue&&zn(je)&&zn(Pe)?{_className:s,canvasBackground:n,customTextRenderer:m,devicePixelRatio:g,filterAnnotations:b,onGetAnnotationsError:O,onGetAnnotationsSuccess:R,onGetStructTreeError:F,onGetStructTreeSuccess:U,onGetTextError:V,onGetTextSuccess:Q,onRenderAnnotationLayerError:$,onRenderAnnotationLayerSuccess:se,onRenderError:le,onRenderSuccess:pe,onRenderTextLayerError:oe,onRenderTextLayerSuccess:he,page:Se,pageColors:ne,pageIndex:te,pageNumber:ue,renderForms:Ne,renderTextLayer:Je,rotate:je,scale:Pe}:null,[s,n,m,g,b,O,R,F,U,V,Q,$,se,le,pe,oe,he,Se,ne,te,ue,Ne,Je,je,Pe]),gt=k.useMemo(()=>Yu(Ge,()=>Se&&(Pe?jc(Se,Pe):void 0)),[Ge,Se,Pe]),xt=`${te}@${Pe}/${je}`;function ct(){switch(De){case"custom":return Wt(u,'renderMode was set to "custom", but no customRenderer was passed.'),r.jsx(u,{},`${xt}_custom`);case"none":return null;case"canvas":default:return r.jsx(yw,{canvasRef:o},`${xt}_canvas`)}}function wt(){return Je?r.jsx(Lw,{},`${xt}_text`):null}function vt(){return Te?r.jsx(mw,{},`${xt}_annotations`):null}function Oe(){function It(Et){return!!Et?.page}if(!It(ht))throw new Error("page is undefined");const Lt=typeof a=="function"?a(ht):a;return r.jsxs(qu.Provider,{value:ht,children:[ct(),wt(),vt(),Lt]})}function bt(){return ue?we===null||Se===void 0||Se===null?r.jsx(Cr,{type:"loading",children:typeof j=="function"?j():j}):we===!1||Se===!1?r.jsx(Cr,{type:"error",children:typeof w=="function"?w():w}):Oe():r.jsx(Cr,{type:"no-data",children:typeof L=="function"?L():L})}return r.jsx("div",{className:ul(s,d),"data-page-number":ue,ref:Vu(y,ze),style:{"--scale-round-x":"1px","--scale-round-y":"1px","--scale-factor":"1","--user-unit":`${Pe}`,"--total-scale-factor":"calc(var(--scale-factor) * var(--user-unit))",backgroundColor:n||"white",position:"relative",minWidth:"min-content",minHeight:"min-content"},...gt,children:bt()})}dw();un.workerSrc="pdf.worker.mjs";function pt(c){return Number(c??0).toLocaleString("en-IN",{minimumFractionDigits:2,maximumFractionDigits:2})}un.workerSrc=`https://unpkg.com/pdfjs-dist@${Xc}/build/pdf.worker.min.mjs`;const kw=({open:c,onClose:e,onPaymentCollected:t,selectedLenderIdx:s=-1,selectedLenderFiCode:i=null,selectedLenderTenureMappings:n=[],selectedLenderRepaymentOption:o=null,selectedLenderDisbursementAccount:a=null})=>{const{tenureMappings:d,payableValue:u,paymentType:m,paymentInvoice:g,invoices:w,chemistId:b,leadId:I,fiCode:y,typeOfApp:j,payerMobileNumber:L,salesmanId:O,distributorIdnum:R,distributorName:F,drawdownRepaymentOption:U,creditLimitData:V}=zs(),Q=n.length>0?n:d,[K,Z]=k.useState(-1),[$,se]=k.useState(s);k.useEffect(()=>{s!==-1&&se(s)},[s]);const[le,pe]=k.useState(!1),oe=()=>{e()},he=i||y,ne=he==="TRILLIONLOAN",re=new Date;re.setDate(re.getDate()+1);const[fe,we]=k.useState(ne?new Date:re),[xe,Te]=k.useState(["","","","","",""]),Ne=k.useRef([]),[De,Je]=k.useState(0),[ke,Re]=k.useState("idle"),[de,Ee]=k.useState(!1),[Ge,Ye]=k.useState(!1),[Qe,Se]=k.useState(""),[Be,ze]=k.useState(""),[te,ue]=k.useState(j==="FUNDLY_COLLECT_APP"||j==="FUNDLY_QR_COLLECT_APP"||j==="FUNDLY_QR_WEB"?"Collect":"Pay Now"),[je,Pe]=k.useState(!1),[Xe,ot]=k.useState(null),[ht,gt]=k.useState(null),[xt,ct]=k.useState(!1),[wt,vt]=k.useState(null),[Oe,bt]=k.useState([]),[It,Lt]=k.useState(!1),[Et,yt]=k.useState(0),At=k.useCallback(Fe=>{const Ke=Fe.getFullYear(),Bt=String(Fe.getMonth()+1).padStart(2,"0"),Zt=String(Fe.getDate()).padStart(2,"0");return`${Ke}-${Bt}-${Zt}`},[]),et=k.useCallback(async()=>{if(he!=="TRILLIONLOAN"){Pe(!1);return}Pe(!0);try{const Fe=tt(),Ke=i||y||"",Bt=o||U||"BULLET",Zt=new URLSearchParams({loanAmount:String(u),businessId:b||"",openedOnDate:At(fe||re),productType:"INSTACASH",tenureMagnitude:String(Q[K]?.tenureValue||""),tenureUnit:String(Q[K]?.tenureUnit||""),fiCode:Ke,repaymentOption:Bt,supplierId:R||""});m==="INVOICE_COLLECT"&&g?.length>0&&Zt.append("invoiceNumber",g.map(Vs=>Vs.invoiceId).join(","));const Ot=`${Jn()}/kfs/report?${Zt.toString()}`,Ft=await Ut.get(Ot,{headers:{accept:"application/json",Authorization:`Bearer ${Fe}`}});ot(Ft.data),gt(Ft.data?.documentId??null),ct(!1)}catch(Fe){console.error("[Fundly Pay] Error fetching KFS:",Fe),ot(null),gt(null),ct(!1)}finally{Pe(!1)}},[i,y,o,U,u,b,fe,K,Q,R,m,g,At]),Ce=k.useCallback(async()=>{if(he==="TRILLIONLOAN")try{const Fe=tt(),Ke=new URLSearchParams({businessId:b||"",intents:"DRAWDOWN_KFS_SIGN",fiCode:he||""}),Bt=`${Jn()}/consent?${Ke.toString()}`,Ot=(await Ut.get(Bt,{headers:{accept:"*/*","Content-Type":"application/json",Authorization:`Bearer ${Fe}`}})).data;if(bt(Array.isArray(Ot)?Ot:[]),Ot?.[0]?.consentMessage){let Ft=Ot[0].consentMessage;Ft=Ft.replace("{{lenderName}}",he||""),Ft=Ft.replace("Drawdown Request Letter",'<span class="kfs-link" style="color:#16558B;text-decoration:underline;cursor:pointer">Drawdown Request Letter</span>'),Ft=Ft.replace("Sanction Letter",'<span class="kfs-link" style="color:#16558B;text-decoration:underline;cursor:pointer">Sanction Letter</span>'),Ft=Ft.replace("Key Fact Statement",'<span class="kfs-link" style="color:#16558B;text-decoration:underline;cursor:pointer">Key Fact Statement</span>'),vt(Ft)}}catch(Fe){console.error("[Fundly Pay] Error fetching consent:",Fe),vt(null)}},[b]),qe=k.useCallback(async()=>{try{const Fe=tt(),Ke=`${Jn()}/consent`;await Ut.post(Ke,{businessId:b||"",intent:"DRAWDOWN_KFS_SIGN",consents:Oe.map(Bt=>({consentId:Bt.consentId,accepted:!0}))},{headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Bearer ${Fe}`}})}catch(Fe){console.error("[Fundly Pay] Error submitting consent:",Fe)}},[b,Oe]),We=k.useCallback(()=>{Xe&&Lt(!0)},[Xe]),dt=k.useMemo(()=>Xe?Xe.kfsDocumentBytes?`data:application/pdf;base64,${Xe.kfsDocumentBytes}`:Xe.kfsDocumentUrl||Xe.documentUrl||null:null,[Xe]),Nt=k.useRef(null);k.useEffect(()=>{const Fe=Nt.current;if(!Fe)return;const Ke=Bt=>{Bt.target.classList.contains("kfs-link")&&We()};return Fe.addEventListener("click",Ke),()=>Fe.removeEventListener("click",Ke)},[We,wt]);const Qt=async()=>{ze("");try{L&&F&&await IA(L,F)}catch(Fe){console.error("Error sending OTP:",Fe);const Ke=Fe,Bt=Ke?.response?.data?.errorMessage||Ke?.response?.data?.message||Ke?.message||"Failed to send OTP. Please try again.";ze(Bt),Re("resend"),Je(0)}},Si=async()=>{if(!navigator.onLine){Ye(!0),ue("Submit Again");return}if(Ye(!1),de)return;if(Ee(!0),!fe){console.error("[Fundly Pay] Payment date is required"),Ee(!1);return}const Fe=fe.toISOString(),Ke=Fe.split("T")[0],Bt=i||y,Zt={paymentMode:"FUNDLY_PAY",paymentDate:Fe,paymentType:m,distributorCode:R,...ht&&{documentId:ht},salesmanId:O,invoiceCount:g?.length||w?.length||0,loanDrawdownRequestDTO:{businessId:b||I,fiCode:Bt,requestedAmount:u,scheduledDate:Ke,tenure:Q[K]?.tenureValue||"",tenureUnit:Q[K]?.tenureUnit?.replace(/s$/i,"")||"",invoiceIds:m==="INVOICE_COLLECT"?g?.map(Ot=>Ot.invoiceId)??[]:w??[],sourceSystem:j,paymentType:m}};b&&b.trim()!==""?Zt.chemistBusinessId=b:I&&I.trim()!==""&&(Zt.leadId=I),m==="INVOICE_COLLECT"?Zt.paymentInvoice=g:m==="DIRECT_COLLECT"&&(Zt.invoiceIds=w,Zt.paidAmount=u),(j==="FUNDLY_COLLECT_APP"||j==="FUNDLY_QR_COLLECT_APP"||j==="FUNDLY_QR_WEB"||j==="FUNDLY_TRADE")&&(Zt.loanDrawdownRequestDTO.mobileNumber=L,Zt.loanDrawdownRequestDTO.loanInitiateOtp=xe.join("")),L&&(Zt.payerMobileNumber=L),he==="TRILLIONLOAN"&&qe();try{const Ot=await on(Zt),Ft=Ot?.data||Ot;Ft&&!Ft.scheduleDate&&(Ft.scheduleDate=Ke),Ft&&Gt?.lastRepaymentDate&&(Ft.dueDate=Gt.lastRepaymentDate),t&&t(Ft)}catch(Ot){const Ft=Ot?.response?.data?.errorMessage||Ot?.response?.data?.errorDesc||Ot?.response?.data?.message||Ot?.message||"Payment failed. Please try again.";Se(Ft)}finally{Ee(!1)}},Us=(Fe,Ke)=>{if(!/^[0-9]?$/.test(Fe))return;const Bt=[...xe];Bt[Ke]=Fe,Te(Bt),Fe&&Ke<5&&Ne.current[Ke+1]?.focus()},Ls=(Fe,Ke)=>{Fe.key==="Backspace"&&!xe[Ke]&&Ke>0&&Ne.current[Ke-1]?.focus()},Kn=()=>{Re("countdown"),Je(30),Qt()};k.useEffect(()=>{if(ke==="countdown"&&De>0){const Fe=setInterval(()=>{Je(Ke=>Ke-1)},1e3);return()=>clearInterval(Fe)}else ke==="countdown"&&De===0&&(Re("resend"),Qt())},[De,ke]);const Xt=k.useMemo(()=>{if(ne&&je)return!0;const Fe=K!==-1,Ke=fe!==null,Bt=$!==-1||!V?.subLimits,Zt=ne?xt:!0;if(j==="FUNDLY_COLLECT_APP"||j==="FUNDLY_QR_COLLECT_APP"||j==="FUNDLY_QR_WEB"||j==="FUNDLY_TRADE"){const Ot=xe.every(Ft=>Ft!=="");return!(Fe&&Ot&&Ke&&Bt&&Zt)}return!(Fe&&Ke&&Bt&&Zt)},[K,$,xe,j,fe,V,xt,je]),[Gt,fi]=k.useState(null),[ui,Pt]=k.useState(!1),mn=async()=>{if(K===-1)return;const Fe=Q[K],Ke=i||y||"",Bt=o||U||"BULLET",Zt=a||"SUPPLIER";Pt(!0);try{const Ot=await OA({loanAmount:Number(u),businessId:b||"",openedOnDate:At(fe||re),productType:"INSTACASH",tenureMagnitude:Fe.tenureValue,tenureUnit:Fe.tenureUnit,fiCode:Ke,repaymentOption:Bt,disbursementAccount:Zt});fi(Ot)}catch(Ot){console.error("Error fetching EMI:",Ot),fi(null)}finally{Pt(!1)}};return k.useEffect(()=>{let Fe;return c&&K!==-1&&$!==-1&&(Fe=window.setTimeout(()=>{mn()},1e3)),()=>{clearTimeout(Fe)}},[K,$,fe]),k.useEffect(()=>{if(c){if(Z(0),ne)we(new Date),ct(!1);else{const Fe=new Date;Fe.setDate(Fe.getDate()+1),we(Fe)}Ce()}},[c,Ce]),k.useEffect(()=>{if(!c||he!=="TRILLIONLOAN")return;const Fe=window.setTimeout(()=>{et()},400);return()=>clearTimeout(Fe)},[K,fe,et]),k.useEffect(()=>{const Fe=()=>{c&&K!==-1&&(mn(),et())};return window.addEventListener("online",Fe),()=>{window.removeEventListener("online",Fe)}},[c,K,et]),r.jsxs(Gs,{open:c,onClose:oe,children:[r.jsxs("div",{style:{fontFamily:"Poppins"},className:"fp:w-full fp:px-4 fp:pt-6 fp:mb-12 ",children:[r.jsx("div",{className:"fp:w-full fp:flex fp:items-center fp:justify-end",children:r.jsx("img",{src:Le.closingCross,className:"fp:w-4 fp:h-4 fp:cursor-pointer",onClick:()=>pe(!0)})}),Qe&&r.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:[r.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:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),r.jsxs("div",{className:"fp:flex-1",children:[r.jsx("p",{className:"fp:text-[14px] fp:text-red-700 fp:font-medium",children:"Payment Failed"}),r.jsx("p",{className:"fp:text-[12px] fp:text-red-600 fp:mt-1",children:Qe})]}),r.jsx("button",{onClick:()=>Se(""),className:"fp:text-red-400 fp:hover:text-red-600",children:r.jsx("svg",{className:"fp:w-4 fp:h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M6 18L18 6M6 6l12 12"})})})]}),r.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:mt-4 fp:space-y-4",children:[r.jsx("div",{children:r.jsx(Io,{value:fe,onChange:Fe=>we(Fe),minDate:ne?void 0:re,label:"Select Payment Date",fullWidth:!0,disabled:ne})}),r.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:space-y-2 ",children:[r.jsx("span",{className:"fp:text-[15px] fp:font-medium fp:text-[#222222]",children:"Tenure"}),r.jsx("div",{className:"fp:w-full fp:flex fp:space-x-4 ",children:Q&&Q.length>0?Q.map((Fe,Ke)=>r.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 ${K===Ke?"fp:border-[#16558B] fp:bg-[#E6F0FA] fp:text-[#16558B]":"fp:border-[#D0D0D0] fp:text-gray-700 fp:bg-white"}`,onClick:()=>{Z(Ke)},children:[Fe.tenureValue," ",Fe.tenureUnit]},Ke)):r.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"})})]}),!ne&&r.jsxs("span",{className:"fp:text-[12px] fp:font-medium fp:text-green-600 fp:text-wrap",children:["₹",pt(u)," will be processed via Fundly Credit — a loan will be set up in retailer's account."]}),r.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:[r.jsxs("div",{className:"fp:flex fp:justify-between",children:[r.jsx("label",{className:"fp:text-gray-700",children:"Due date"}),r.jsx("label",{className:"fp:font-medium",children:Gt?.lastRepaymentDate?Ir(Gt.lastRepaymentDate):"—"})]}),r.jsxs("div",{className:"fp:flex fp:justify-between",children:[r.jsx("label",{className:"fp:text-gray-700",children:"ROI (Annualised)"}),r.jsx("label",{className:"fp:font-medium",children:Gt?.normalInterestRate!=null?`${Gt.normalInterestRate}%`:"—"})]}),r.jsxs("div",{className:"fp:flex fp:justify-between",children:[r.jsx("label",{className:"fp:text-gray-700",children:"Interest/₹ 10,000/day"}),r.jsx("label",{className:"fp:font-medium",children:Gt?.interestPerDay!=null?`₹${Gt.interestPerDay}`:"—"})]}),r.jsxs("div",{className:"fp:flex fp:justify-between",children:[r.jsx("label",{className:"fp:text-gray-700",children:"Penal Charges"}),r.jsx("label",{className:"fp:font-medium",children:Gt?.penalInterestRate!=null?`${Gt.penalInterestRate}% p.a`:"—"})]}),r.jsxs("div",{className:"fp:flex fp:justify-between",children:[r.jsx("label",{className:"fp:text-gray-700",children:"Processing Fee"}),r.jsx("label",{className:"fp:font-medium",children:Gt?.processingFeeExclGst!=null?`₹${Number(Gt.processingFeeExclGst).toLocaleString("en-IN")}`:"—"})]}),r.jsxs("div",{className:"fp:flex fp:justify-between",children:[r.jsx("label",{className:"fp:text-gray-700",children:"APR"}),r.jsx("label",{className:"fp:font-medium",children:Gt?.apr!=null?`${Gt.apr}%`:"—"})]}),r.jsxs("div",{className:"fp:flex fp:justify-between",children:[r.jsx("label",{className:"fp:text-gray-700",children:"Net Disbursed Amount"}),r.jsx("label",{className:"fp:font-medium",children:Gt?.creditedAmount!=null?`₹${Number(Gt.creditedAmount).toLocaleString("en-IN")}`:"—"})]})]}),(j==="FUNDLY_COLLECT_APP"||j==="FUNDLY_QR_COLLECT_APP"||j==="FUNDLY_QR_WEB"||j==="FUNDLY_TRADE")&&r.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:[r.jsx("label",{className:"fp:font-medium fp:text-[15px]",children:"Retailer Verification"}),r.jsxs("div",{className:"fp:w-full fp:flex fp:space-x-2 fp:justify-between",children:[r.jsx("div",{className:"fp:flex fp:border-2 fp:rounded-lg fp:px-1 fp:space-x-2 ",children:xe.map((Fe,Ke)=>r.jsx("input",{type:"text",value:Fe,maxLength:1,placeholder:"●",ref:Bt=>{Ne.current[Ke]=Bt},onChange:Bt=>Us(Bt.target.value,Ke),onKeyDown:Bt=>Ls(Bt,Ke),className:"fp:w-7 fp:h-8 fp:text-center fp:text-[16px] fp:outline-none"},Ke))}),r.jsxs("button",{onClick:Kn,disabled:ke==="countdown",className:`fp:text-white fp:text-[12px] fp:px-7 fp:rounded-lg ${ke==="resend"?"fp:bg-gray-500":"fp:bg-[#16558B]"}`,children:[ke==="idle"&&"Get OTP",ke==="countdown"&&`${De}s`,ke==="resend"&&"Resend"]})]}),Be?r.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:[r.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:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),r.jsx("p",{className:"fp:text-[11px] fp:text-red-700",children:Be})]}):r.jsxs("label",{className:"fp:text-[13px] fp:flex fp:text-center fp:items-center fp:text-[#16558B]",children:[r.jsx("img",{src:Le.info,className:"fp:w-4 fp:h-4 fp:mr-1"}),ke==="idle"?"OTP will be sent to the retailer for consent.":"An OTP has been sent to the retailer for consent."]})]}),wt&&r.jsx("div",{ref:Nt,className:"fp:text-[12px] fp:text-gray-600 fp:leading-relaxed fp:select-none",dangerouslySetInnerHTML:{__html:wt}}),ne&&r.jsxs("label",{className:"fp:flex fp:items-start fp:space-x-2 fp:cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:xt,onChange:Fe=>{const Ke=Fe.target.checked;ct(Ke),Ke&&We()},className:"fp:mt-0.5 fp:w-4 fp:h-4 fp:flex-shrink-0 fp:accent-[#16558B]"}),r.jsxs("span",{className:"fp:text-[12px] fp:text-gray-700",children:["I agree to the loan terms and accept the"," ",r.jsx("span",{className:"fp:text-[#16558B] fp:underline fp:cursor-pointer",onClick:Fe=>{Fe.preventDefault(),We()},children:"Key Fact Statement (KFS)"})]})]}),Ge&&r.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."}),r.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
|
|
619
|
+
`)){const n=document.createElement("div");n.append(i?document.createTextNode(i):document.createElement("br")),t.append(n)}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 Ue{static PRECISION=1e-4;toSVGPath(){Jt("Abstract method `toSVGPath` must be implemented.")}get box(){Jt("Abstract getter `box` must be implemented.")}serialize(e,t){Jt("Abstract method `serialize` must be implemented.")}static _rescale(e,t,s,i,n,o){o||=new Float32Array(e.length);for(let a=0,d=e.length;a<d;a+=2)o[a]=t+e[a]*i,o[a+1]=s+e[a+1]*n;return o}static _rescaleAndSwap(e,t,s,i,n,o){o||=new Float32Array(e.length);for(let a=0,d=e.length;a<d;a+=2)o[a]=t+e[a+1]*i,o[a+1]=s+e[a]*n;return o}static _translate(e,t,s,i){i||=new Float32Array(e.length);for(let n=0,o=e.length;n<o;n+=2)i[n]=t+e[n],i[n+1]=s+e[n+1];return i}static svgRound(e){return Math.round(e*1e4)}static _normalizePoint(e,t,s,i,n){switch(n){case 90:return[1-t/s,e/i];case 180:return[1-e/s,1-t/i];case 270:return[t/s,1-e/i];default:return[e/s,t/i]}}static _normalizePagePoint(e,t,s){switch(s){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,s,i,n,o){return[(e+5*s)/6,(t+5*i)/6,(5*s+n)/6,(5*i+o)/6,(s+n)/2,(i+o)/2]}}class Hn{#e;#t=[];#i;#s;#o=[];#n=new Float32Array(18);#r;#a;#c;#l;#f;#h;#u=[];static#g=8;static#p=2;static#d=Hn.#g+Hn.#p;constructor({x:e,y:t},s,i,n,o,a=0){this.#e=s,this.#h=n*i,this.#s=o,this.#n.set([NaN,NaN,NaN,NaN,e,t],6),this.#i=a,this.#l=Hn.#g*i,this.#c=Hn.#d*i,this.#f=i,this.#u.push(e,t)}isEmpty(){return isNaN(this.#n[8])}#m(){const e=this.#n.subarray(4,6),t=this.#n.subarray(16,18),[s,i,n,o]=this.#e;return[(this.#r+(e[0]-t[0])/2-s)/n,(this.#a+(e[1]-t[1])/2-i)/o,(this.#r+(t[0]-e[0])/2-s)/n,(this.#a+(t[1]-e[1])/2-i)/o]}add({x:e,y:t}){this.#r=e,this.#a=t;const[s,i,n,o]=this.#e;let[a,d,u,m]=this.#n.subarray(8,12);const g=e-u,w=t-m,b=Math.hypot(g,w);if(b<this.#c)return!1;const I=b-this.#l,y=I/b,j=y*g,L=y*w;let O=a,R=d;a=u,d=m,u+=j,m+=L,this.#u?.push(e,t);const F=-L/I,U=j/I,V=F*this.#h,Q=U*this.#h;return this.#n.set(this.#n.subarray(2,8),0),this.#n.set([u+V,m+Q],4),this.#n.set(this.#n.subarray(14,18),12),this.#n.set([u-V,m-Q],16),isNaN(this.#n[6])?(this.#o.length===0&&(this.#n.set([a+V,d+Q],2),this.#o.push(NaN,NaN,NaN,NaN,(a+V-s)/n,(d+Q-i)/o),this.#n.set([a-V,d-Q],14),this.#t.push(NaN,NaN,NaN,NaN,(a-V-s)/n,(d-Q-i)/o)),this.#n.set([O,R,a,d,u,m],6),!this.isEmpty()):(this.#n.set([O,R,a,d,u,m],6),Math.abs(Math.atan2(R-d,O-a)-Math.atan2(L,j))<Math.PI/2?([a,d,u,m]=this.#n.subarray(2,6),this.#o.push(NaN,NaN,NaN,NaN,((a+u)/2-s)/n,((d+m)/2-i)/o),[a,d,O,R]=this.#n.subarray(14,18),this.#t.push(NaN,NaN,NaN,NaN,((O+a)/2-s)/n,((R+d)/2-i)/o),!0):([O,R,a,d,u,m]=this.#n.subarray(0,6),this.#o.push(((O+5*a)/6-s)/n,((R+5*d)/6-i)/o,((5*a+u)/6-s)/n,((5*d+m)/6-i)/o,((a+u)/2-s)/n,((d+m)/2-i)/o),[u,m,a,d,O,R]=this.#n.subarray(12,18),this.#t.push(((O+5*a)/6-s)/n,((R+5*d)/6-i)/o,((5*a+u)/6-s)/n,((5*d+m)/6-i)/o,((a+u)/2-s)/n,((d+m)/2-i)/o),!0))}toSVGPath(){if(this.isEmpty())return"";const e=this.#o,t=this.#t;if(isNaN(this.#n[6])&&!this.isEmpty())return this.#A();const s=[];s.push(`M${e[4]} ${e[5]}`);for(let i=6;i<e.length;i+=6)isNaN(e[i])?s.push(`L${e[i+4]} ${e[i+5]}`):s.push(`C${e[i]} ${e[i+1]} ${e[i+2]} ${e[i+3]} ${e[i+4]} ${e[i+5]}`);this.#x(s);for(let i=t.length-6;i>=6;i-=6)isNaN(t[i])?s.push(`L${t[i+4]} ${t[i+5]}`):s.push(`C${t[i]} ${t[i+1]} ${t[i+2]} ${t[i+3]} ${t[i+4]} ${t[i+5]}`);return this.#w(s),s.join(" ")}#A(){const[e,t,s,i]=this.#e,[n,o,a,d]=this.#m();return`M${(this.#n[2]-e)/s} ${(this.#n[3]-t)/i} L${(this.#n[4]-e)/s} ${(this.#n[5]-t)/i} L${n} ${o} L${a} ${d} L${(this.#n[16]-e)/s} ${(this.#n[17]-t)/i} L${(this.#n[14]-e)/s} ${(this.#n[15]-t)/i} Z`}#w(e){const t=this.#t;e.push(`L${t[4]} ${t[5]} Z`)}#x(e){const[t,s,i,n]=this.#e,o=this.#n.subarray(4,6),a=this.#n.subarray(16,18),[d,u,m,g]=this.#m();e.push(`L${(o[0]-t)/i} ${(o[1]-s)/n} L${d} ${u} L${m} ${g} L${(a[0]-t)/i} ${(a[1]-s)/n}`)}newFreeDrawOutline(e,t,s,i,n,o){return new zu(e,t,s,i,n,o)}getOutlines(){const e=this.#o,t=this.#t,s=this.#n,[i,n,o,a]=this.#e,d=new Float32Array((this.#u?.length??0)+2);for(let g=0,w=d.length-2;g<w;g+=2)d[g]=(this.#u[g]-i)/o,d[g+1]=(this.#u[g+1]-n)/a;if(d[d.length-2]=(this.#r-i)/o,d[d.length-1]=(this.#a-n)/a,isNaN(s[6])&&!this.isEmpty())return this.#E(d);const u=new Float32Array(this.#o.length+24+this.#t.length);let m=e.length;for(let g=0;g<m;g+=2){if(isNaN(e[g])){u[g]=u[g+1]=NaN;continue}u[g]=e[g],u[g+1]=e[g+1]}m=this.#b(u,m);for(let g=t.length-6;g>=6;g-=6)for(let w=0;w<6;w+=2){if(isNaN(t[g+w])){u[m]=u[m+1]=NaN,m+=2;continue}u[m]=t[g+w],u[m+1]=t[g+w+1],m+=2}return this.#v(u,m),this.newFreeDrawOutline(u,d,this.#e,this.#f,this.#i,this.#s)}#E(e){const t=this.#n,[s,i,n,o]=this.#e,[a,d,u,m]=this.#m(),g=new Float32Array(36);return g.set([NaN,NaN,NaN,NaN,(t[2]-s)/n,(t[3]-i)/o,NaN,NaN,NaN,NaN,(t[4]-s)/n,(t[5]-i)/o,NaN,NaN,NaN,NaN,a,d,NaN,NaN,NaN,NaN,u,m,NaN,NaN,NaN,NaN,(t[16]-s)/n,(t[17]-i)/o,NaN,NaN,NaN,NaN,(t[14]-s)/n,(t[15]-i)/o],0),this.newFreeDrawOutline(g,e,this.#e,this.#f,this.#i,this.#s)}#v(e,t){const s=this.#t;return e.set([NaN,NaN,NaN,NaN,s[4],s[5]],t),t+=6}#b(e,t){const s=this.#n.subarray(4,6),i=this.#n.subarray(16,18),[n,o,a,d]=this.#e,[u,m,g,w]=this.#m();return e.set([NaN,NaN,NaN,NaN,(s[0]-n)/a,(s[1]-o)/d,NaN,NaN,NaN,NaN,u,m,NaN,NaN,NaN,NaN,g,w,NaN,NaN,NaN,NaN,(i[0]-n)/a,(i[1]-o)/d],t),t+=24}}class zu extends Ue{#e;#t=new Float32Array(4);#i;#s;#o;#n;#r;constructor(e,t,s,i,n,o){super(),this.#r=e,this.#o=t,this.#e=s,this.#n=i,this.#i=n,this.#s=o,this.firstPoint=[NaN,NaN],this.lastPoint=[NaN,NaN],this.#a(o);const[a,d,u,m]=this.#t;for(let g=0,w=e.length;g<w;g+=2)e[g]=(e[g]-a)/u,e[g+1]=(e[g+1]-d)/m;for(let g=0,w=t.length;g<w;g+=2)t[g]=(t[g]-a)/u,t[g+1]=(t[g+1]-d)/m}toSVGPath(){const e=[`M${this.#r[4]} ${this.#r[5]}`];for(let t=6,s=this.#r.length;t<s;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,s,i],n){const o=s-e,a=i-t;let d,u;switch(n){case 0:d=Ue._rescale(this.#r,e,i,o,-a),u=Ue._rescale(this.#o,e,i,o,-a);break;case 90:d=Ue._rescaleAndSwap(this.#r,e,t,o,a),u=Ue._rescaleAndSwap(this.#o,e,t,o,a);break;case 180:d=Ue._rescale(this.#r,s,t,-o,a),u=Ue._rescale(this.#o,s,t,-o,a);break;case 270:d=Ue._rescaleAndSwap(this.#r,s,i,-o,-a),u=Ue._rescaleAndSwap(this.#o,s,i,-o,-a);break}return{outline:Array.from(d),points:[Array.from(u)]}}#a(e){const t=this.#r;let s=t[4],i=t[5];const n=[s,i,s,i];let o=s,a=i,d=s,u=i;const m=e?Math.max:Math.min,g=new Float32Array(4);for(let b=6,I=t.length;b<I;b+=6){const y=t[b+4],j=t[b+5];isNaN(t[b])?(He.pointBoundingBox(y,j,n),a>j?(o=y,a=j):a===j&&(o=m(o,y)),u<j?(d=y,u=j):u===j&&(d=m(d,y))):(g[0]=g[1]=1/0,g[2]=g[3]=-1/0,He.bezierBoundingBox(s,i,...t.slice(b,b+6),g),He.rectBoundingBox(g[0],g[1],g[2],g[3],n),a>g[1]?(o=g[0],a=g[1]):a===g[1]&&(o=m(o,g[0])),u<g[3]?(d=g[2],u=g[3]):u===g[3]&&(d=m(d,g[2]))),s=y,i=j}const w=this.#t;w[0]=n[0]-this.#i,w[1]=n[1]-this.#i,w[2]=n[2]-n[0]+2*this.#i,w[3]=n[3]-n[1]+2*this.#i,this.firstPoint=[o,a],this.lastPoint=[d,u]}get box(){return this.#t}newOutliner(e,t,s,i,n,o=0){return new Hn(e,t,s,i,n,o)}getNewOutline(e,t){const[s,i,n,o]=this.#t,[a,d,u,m]=this.#e,g=n*u,w=o*m,b=s*u+a,I=i*m+d,y=this.newOutliner({x:this.#o[0]*g+b,y:this.#o[1]*w+I},this.#e,this.#n,e,this.#s,t??this.#i);for(let j=2;j<this.#o.length;j+=2)y.add({x:this.#o[j]*g+b,y:this.#o[j+1]*w+I});return y.getOutlines()}}class Ic{#e;#t;#i;#s=[];#o=[];constructor(e,t=0,s=0,i=!0){const n=[1/0,1/0,-1/0,-1/0],o=10**-4;for(const{x:y,y:j,width:L,height:O}of e){const R=Math.floor((y-t)/o)*o,F=Math.ceil((y+L+t)/o)*o,U=Math.floor((j-t)/o)*o,V=Math.ceil((j+O+t)/o)*o,Q=[R,U,V,!0],K=[F,U,V,!1];this.#s.push(Q,K),He.rectBoundingBox(R,U,F,V,n)}const a=n[2]-n[0]+2*s,d=n[3]-n[1]+2*s,u=n[0]-s,m=n[1]-s;let g=i?-1/0:1/0,w=1/0;const b=this.#s.at(i?-1:-2),I=[b[0],b[2]];for(const y of this.#s){const[j,L,O,R]=y;!R&&i?L<w?(w=L,g=j):L===w&&(g=Math.max(g,j)):R&&!i&&(L<w?(w=L,g=j):L===w&&(g=Math.min(g,j))),y[0]=(j-u)/a,y[1]=(L-m)/d,y[2]=(O-m)/d}this.#e=new Float32Array([u,m,a,d]),this.#t=[g,w],this.#i=I}getOutlines(){this.#s.sort((t,s)=>t[0]-s[0]||t[1]-s[1]||t[2]-s[2]);const e=[];for(const t of this.#s)t[3]?(e.push(...this.#l(t)),this.#a(t)):(this.#c(t),e.push(...this.#l(t)));return this.#n(e)}#n(e){const t=[],s=new Set;for(const o of e){const[a,d,u]=o;t.push([a,d,o],[a,u,o])}t.sort((o,a)=>o[1]-a[1]||o[0]-a[0]);for(let o=0,a=t.length;o<a;o+=2){const d=t[o][2],u=t[o+1][2];d.push(u),u.push(d),s.add(d),s.add(u)}const i=[];let n;for(;s.size>0;){const o=s.values().next().value;let[a,d,u,m,g]=o;s.delete(o);let w=a,b=d;for(n=[a,u],i.push(n);;){let I;if(s.has(m))I=m;else if(s.has(g))I=g;else break;s.delete(I),[a,d,u,m,g]=I,w!==a&&(n.push(w,b,a,b===d?d:u),w=a),b=b===d?u:d}n.push(w,b)}return new D2(i,this.#e,this.#t,this.#i)}#r(e){const t=this.#o;let s=0,i=t.length-1;for(;s<=i;){const n=s+i>>1,o=t[n][0];if(o===e)return n;o<e?s=n+1:i=n-1}return i+1}#a([,e,t]){const s=this.#r(e);this.#o.splice(s,0,[e,t])}#c([,e,t]){const s=this.#r(e);for(let i=s;i<this.#o.length;i++){const[n,o]=this.#o[i];if(n!==e)break;if(n===e&&o===t){this.#o.splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,o]=this.#o[i];if(n!==e)break;if(n===e&&o===t){this.#o.splice(i,1);return}}}#l(e){const[t,s,i]=e,n=[[t,s,i]],o=this.#r(i);for(let a=0;a<o;a++){const[d,u]=this.#o[a];for(let m=0,g=n.length;m<g;m++){const[,w,b]=n[m];if(!(u<=w||b<=d)){if(w>=d){if(b>u)n[m][1]=u;else{if(g===1)return[];n.splice(m,1),m--,g--}continue}n[m][2]=d,b>u&&n.push([t,u,b])}}}return n}}class D2 extends Ue{#e;#t;constructor(e,t,s,i){super(),this.#t=e,this.#e=t,this.firstPoint=s,this.lastPoint=i}toSVGPath(){const e=[];for(const t of this.#t){let[s,i]=t;e.push(`M${s} ${i}`);for(let n=2;n<t.length;n+=2){const o=t[n],a=t[n+1];o===s?(e.push(`V${a}`),i=a):a===i&&(e.push(`H${o}`),s=o)}e.push("Z")}return e.join(" ")}serialize([e,t,s,i],n){const o=[],a=s-e,d=i-t;for(const u of this.#t){const m=new Array(u.length);for(let g=0;g<u.length;g+=2)m[g]=e+u[g]*a,m[g+1]=i-u[g+1]*d;o.push(m)}return o}get box(){return this.#e}get classNamesForOutlining(){return["highlightOutline"]}}class Ec extends Hn{newFreeDrawOutline(e,t,s,i,n,o){return new L2(e,t,s,i,n,o)}}class L2 extends zu{newOutliner(e,t,s,i,n,o=0){return new Ec(e,t,s,i,n,o)}}class ds extends _e{#e=null;#t=0;#i;#s=null;#o=null;#n=null;#r=null;#a=0;#c=null;#l=null;#f=null;#h=!1;#u=null;#g=null;#p=null;#d="";#m;#A="";static _defaultColor=null;static _defaultOpacity=1;static _defaultThickness=12;static _type="highlight";static _editorType=at.HIGHLIGHT;static _freeHighlightId=-1;static _freeHighlight=null;static _freeHighlightClipId="";static get _keyboardManager(){const e=ds.prototype;return mt(this,"_keyboardManager",new Oo([[["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||ds._defaultColor,this.#m=e.thickness||ds._defaultThickness,this.opacity=e.opacity||ds._defaultOpacity,this.#i=e.boxes||null,this.#A=e.methodOfCreation||"",this.#d=e.text||"",this._isDraggable=!1,this.defaultL10nId="pdfjs-editor-highlight-editor",e.highlightId>-1?(this.#h=!0,this.#x(e),this.#C()):this.#i&&(this.#e=e.anchorNode,this.#t=e.anchorOffset,this.#r=e.focusNode,this.#a=e.focusOffset,this.#w(),this.#C(),this.rotate(this.rotation)),this.annotationElementId||this._uiManager.a11yAlert("pdfjs-editor-highlight-added-alert")}get telemetryInitialData(){return{action:"added",type:this.#h?"free_highlight":"highlight",color:this._uiManager.getNonHCMColorName(this.color),thickness:this.#m,methodOfCreation:this.#A}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.getNonHCMColorName(this.color)}}static computeTelemetryFinalData(e){return{numberOfColors:e.get("color").size}}#w(){const e=new Ic(this.#i,.001);this.#l=e.getOutlines(),[this.x,this.y,this.width,this.height]=this.#l.box;const t=new Ic(this.#i,.0025,.001,this._uiManager.direction==="ltr");this.#n=t.getOutlines();const{firstPoint:s}=this.#l;this.#u=[(s[0]-this.x)/this.width,(s[1]-this.y)/this.height];const{lastPoint:i}=this.#n;this.#g=[(i[0]-this.x)/this.width,(i[1]-this.y)/this.height]}#x({highlightOutlines:e,highlightId:t,clipPathId:s}){this.#l=e;const i=1.5;if(this.#n=e.getNewOutline(this.#m/2+i,.0025),t>=0)this.#f=t,this.#s=s,this.parent.drawLayer.finalizeDraw(t,{bbox:e.box,path:{d:e.toSVGPath()}}),this.#p=this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:this.#n.box,path:{d:this.#n.toSVGPath()}},!0);else if(this.parent){const g=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(this.#f,{bbox:ds.#I(this.#l.box,(g-this.rotation+360)%360),path:{d:e.toSVGPath()}}),this.parent.drawLayer.updateProperties(this.#p,{bbox:ds.#I(this.#n.box,g),path:{d:this.#n.toSVGPath()}})}const[n,o,a,d]=e.box;switch(this.rotation){case 0:this.x=n,this.y=o,this.width=a,this.height=d;break;case 90:{const[g,w]=this.parentDimensions;this.x=o,this.y=1-n,this.width=a*w/g,this.height=d*g/w;break}case 180:this.x=1-n,this.y=1-o,this.width=a,this.height=d;break;case 270:{const[g,w]=this.parentDimensions;this.x=1-o,this.y=n,this.width=a*w/g,this.height=d*g/w;break}}const{firstPoint:u}=e;this.#u=[(u[0]-n)/a,(u[1]-o)/d];const{lastPoint:m}=this.#n;this.#g=[(m[0]-n)/a,(m[1]-o)/d]}static initialize(e,t){_e.initialize(e,t),ds._defaultColor||=t.highlightColors?.values().next().value||"#fff066"}static updateDefaultParams(e,t){switch(e){case Mt.HIGHLIGHT_COLOR:ds._defaultColor=t;break;case Mt.HIGHLIGHT_THICKNESS:ds._defaultThickness=t;break}}translateInPage(e,t){}get toolbarPosition(){return this.#g}get commentButtonPosition(){return this.#u}updateParams(e,t){switch(e){case Mt.HIGHLIGHT_COLOR:this.#E(t);break;case Mt.HIGHLIGHT_THICKNESS:this.#v(t);break}}static get defaultPropertiesToUpdate(){return[[Mt.HIGHLIGHT_COLOR,ds._defaultColor],[Mt.HIGHLIGHT_THICKNESS,ds._defaultThickness]]}get propertiesToUpdate(){return[[Mt.HIGHLIGHT_COLOR,this.color||ds._defaultColor],[Mt.HIGHLIGHT_THICKNESS,this.#m||ds._defaultThickness],[Mt.HIGHLIGHT_FREE,this.#h]]}onUpdatedColor(){this.parent?.drawLayer.updateProperties(this.#f,{root:{fill:this.color,"fill-opacity":this.opacity}}),this.#o?.updateColor(this.color),super.onUpdatedColor()}#E(e){const t=(n,o)=>{this.color=n,this.opacity=o,this.onUpdatedColor()},s=this.color,i=this.opacity;this.addCommands({cmd:t.bind(this,e,ds._defaultOpacity),undo:t.bind(this,s,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Mt.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.getNonHCMColorName(e)},!0)}#v(e){const t=this.#m,s=i=>{this.#m=i,this.#b(i)};this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,t),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Mt.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)}get toolbarButtons(){return this._uiManager.highlightColors?[["colorPicker",this.#o=new si({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.#D())}getBaseTranslation(){return[0,0]}getRect(e,t){return super.getRect(e,t,this.#D())}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.#C(),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){let t=!1;this.parent&&!e?this.#S():e&&(this.#C(e),t=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(e),this.show(this._isVisible),t&&this.select()}#b(e){this.#h&&(this.#x({highlightOutlines:this.#l.getNewOutline(e/2)}),this.fixAndSetPosition(),this.setDims(this.width,this.height))}#S(){this.#f===null||!this.parent||(this.parent.drawLayer.remove(this.#f),this.#f=null,this.parent.drawLayer.remove(this.#p),this.#p=null)}#C(e=this.parent){this.#f===null&&({id:this.#f,clipPathId:this.#s}=e.drawLayer.draw({bbox:this.#l.box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":this.opacity},rootClass:{highlight:!0,free:this.#h},path:{d:this.#l.toSVGPath()}},!1,!0),this.#p=e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:this.#h},bbox:this.#n.box,path:{d:this.#n.toSVGPath()}},this.#h),this.#c&&(this.#c.style.clipPath=this.#s))}static#I([e,t,s,i],n){switch(n){case 90:return[1-t-i,e,i,s];case 180:return[1-e-s,1-t-i,s,i];case 270:return[t,1-e-s,i,s]}return[e,t,s,i]}rotate(e){const{drawLayer:t}=this.parent;let s;this.#h?(e=(e-this.rotation+360)%360,s=ds.#I(this.#l.box,e)):s=ds.#I([this.x,this.y,this.width,this.height],e),t.updateProperties(this.#f,{bbox:s,root:{"data-main-rotation":e}}),t.updateProperties(this.#p,{bbox:ds.#I(this.#n.box,e),root:{"data-main-rotation":e}})}render(){if(this.div)return this.div;const e=super.render();this.#d&&(e.setAttribute("aria-label",this.#d),e.setAttribute("role","mark")),this.#h?e.classList.add("free"):this.div.addEventListener("keydown",this.#L.bind(this),{signal:this._uiManager._signal});const t=this.#c=document.createElement("div");return e.append(t),t.setAttribute("aria-hidden","true"),t.className="internal",t.style.clipPath=this.#s,this.setDims(this.width,this.height),pu(this,this.#c,["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#p,{rootClass:{hovered:!0}})}pointerleave(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#p,{rootClass:{hovered:!1}})}#L(e){ds._keyboardManager.exec(this,e)}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:this.#j(!0);break;case 1:case 3:this.#j(!1);break}}#j(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.#p&&this.parent?.drawLayer.updateProperties(this.#p,{rootClass:{hovered:!1,selected:!0}})}unselect(){super.unselect(),this.#p&&(this.parent?.drawLayer.updateProperties(this.#p,{rootClass:{selected:!1}}),this.#h||this.#j(!1))}get _mustFixPosition(){return!this.#h}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.updateProperties(this.#f,{rootClass:{hidden:!e}}),this.parent.drawLayer.updateProperties(this.#p,{rootClass:{hidden:!e}}))}#D(){return this.#h?this.rotation:0}#F(){if(this.#h)return null;const[e,t]=this.pageDimensions,[s,i]=this.pageTranslation,n=this.#i,o=new Float32Array(n.length*8);let a=0;for(const{x:d,y:u,width:m,height:g}of n){const w=d*e+s,b=(1-u)*t+i;o[a]=o[a+4]=w,o[a+1]=o[a+3]=b,o[a+2]=o[a+6]=w+m*e,o[a+5]=o[a+7]=b-g*t,a+=8}return o}#k(e){return this.#l.serialize(e,this.#D())}static startHighlighting(e,t,{target:s,x:i,y:n}){const{x:o,y:a,width:d,height:u}=s.getBoundingClientRect(),m=new AbortController,g=e.combinedSignal(m),w=b=>{m.abort(),this.#R(e,b)};window.addEventListener("blur",w,{signal:g}),window.addEventListener("pointerup",w,{signal:g}),window.addEventListener("pointerdown",rs,{capture:!0,passive:!1,signal:g}),window.addEventListener("contextmenu",ri,{signal:g}),s.addEventListener("pointermove",this.#B.bind(this,e),{signal:g}),this._freeHighlight=new Ec({x:i,y:n},[o,a,d,u],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#B(e,t){this._freeHighlight.add(t)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})}static#R(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,s){let i=null;if(e instanceof Ou){const{data:{quadPoints:I,rect:y,rotation:j,id:L,color:O,opacity:R,popupRef:F,richText:U,contentsObj:V,creationDate:Q,modificationDate:K},parent:{page:{pageNumber:Z}}}=e;i=e={annotationType:at.HIGHLIGHT,color:Array.from(O),opacity:R,quadPoints:I,boxes:null,pageIndex:Z-1,rect:y.slice(0),rotation:j,annotationElementId:L,id:L,deleted:!1,popupRef:F,richText:U,comment:V?.str||null,creationDate:Q,modificationDate:K}}else if(e instanceof Vc){const{data:{inkLists:I,rect:y,rotation:j,id:L,color:O,borderStyle:{rawWidth:R},popupRef:F,richText:U,contentsObj:V,creationDate:Q,modificationDate:K},parent:{page:{pageNumber:Z}}}=e;i=e={annotationType:at.HIGHLIGHT,color:Array.from(O),thickness:R,inkLists:I,boxes:null,pageIndex:Z-1,rect:y.slice(0),rotation:j,annotationElementId:L,id:L,deleted:!1,popupRef:F,richText:U,comment:V?.str||null,creationDate:Q,modificationDate:K}}const{color:n,quadPoints:o,inkLists:a,opacity:d}=e,u=await super.deserialize(e,t,s);u.color=He.makeHexColor(...n),u.opacity=d||1,a&&(u.#m=e.thickness),u._initialData=i,e.comment&&u.setCommentData(e);const[m,g]=u.pageDimensions,[w,b]=u.pageTranslation;if(o){const I=u.#i=[];for(let y=0;y<o.length;y+=8)I.push({x:(o[y]-w)/m,y:1-(o[y+1]-b)/g,width:(o[y+2]-o[y])/m,height:(o[y+1]-o[y+5])/g});u.#w(),u.#C(),u.rotate(u.rotation)}else if(a){u.#h=!0;const I=a[0],y={x:I[0]-w,y:g-(I[1]-b)},j=new Ec(y,[0,0,m,g],1,u.#m/2,!0,.001);for(let R=0,F=I.length;R<F;R+=2)y.x=I[R]-w,y.y=g-(I[R+1]-b),j.add(y);const{id:L,clipPathId:O}=t.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:u.color,"fill-opacity":u._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:j.toSVGPath()}},!0,!0);u.#x({highlightOutlines:j.getOutlines(),highlightId:L,clipPathId:O}),u.#C(),u.rotate(u.parentRotation)}return u}serialize(e=!1){if(this.isEmpty()||e)return null;if(this.deleted)return this.serializeDeleted();const t=_e._colorManager.convert(this._uiManager.getNonHCMColor(this.color)),s=super.serialize(e);return Object.assign(s,{color:t,opacity:this.opacity,thickness:this.#m,quadPoints:this.#F(),outlines:this.#k(s.rect)}),this.addComment(s),this.annotationElementId&&!this.#P(s)?null:(s.id=this.annotationElementId,s)}#P(e){const{color:t}=this._initialData;return this.hasEditedComment||e.color.some((s,i)=>s!==t[i])}renderAnnotationElement(e){return this.deleted?(e.hide(),null):(e.updateEdited({rect:this.getPDFRect(),popup:this.comment}),null)}static canCreateNewEmptyEditor(){return!1}}class Uu{#e=Object.create(null);updateProperty(e,t){this[e]=t,this.updateSVGProperty(e,t)}updateProperties(e){if(e)for(const[t,s]of Object.entries(e))t.startsWith("_")||this.updateProperty(t,s)}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(){Jt("Not implemented")}}class nt extends _e{#e=null;#t;_colorPicker=null;_drawId=null;static _currentDrawId=-1;static _currentParent=null;static#i=null;static#s=null;static#o=null;static#n=NaN;static#r=null;static#a=null;static#c=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.#l(e),this.#u())}#l({drawOutlines:e,drawId:t,drawingOptions:s}){this.#e=e,this._drawingOptions||=s,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.#f(e,this.parent),this.#d(e.box)}#f(e,t){const{id:s}=t.drawLayer.draw(nt._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return s}static _mergeSVGProperties(e,t){const s=new Set(Object.keys(e));for(const[i,n]of Object.entries(t))s.has(i)?Object.assign(e[i],n):e[i]=n;return e}static getDefaultDrawingOptions(e){Jt("Not implemented")}static get typesMap(){Jt("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(e,t){const s=this.typesMap.get(e);s&&this._defaultDrawingOptions.updateProperty(s,t),this._currentParent&&(nt.#i.updateProperty(s,t),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(e,t){const s=this.constructor.typesMap.get(e);s&&this._updateProperty(e,s,t)}static get defaultPropertiesToUpdate(){const e=[],t=this._defaultDrawingOptions;for(const[s,i]of this.typesMap)e.push([s,t[i]]);return e}get propertiesToUpdate(){const e=[],{_drawingOptions:t}=this;for(const[s,i]of this.constructor.typesMap)e.push([s,t[i]]);return e}_updateProperty(e,t,s){const i=this._drawingOptions,n=i[t],o=a=>{i.updateProperty(t,a);const d=this.#e.updateProperty(t,a);d&&this.#d(d),this.parent?.drawLayer.updateProperties(this._drawId,i.toSVGProperties()),e===this.colorType&&this.onUpdatedColor()};this.addCommands({cmd:o.bind(this,s),undo:o.bind(this,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:e,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){this.parent?.drawLayer.updateProperties(this._drawId,nt._mergeSVGProperties(this.#e.getPathResizingSVGProperties(this.#p()),{bbox:this.#m()}))}_onResized(){this.parent?.drawLayer.updateProperties(this._drawId,nt._mergeSVGProperties(this.#e.getPathResizedSVGProperties(this.#p()),{bbox:this.#m()}))}_onTranslating(e,t){this.parent?.drawLayer.updateProperties(this._drawId,{bbox:this.#m()})}_onTranslated(){this.parent?.drawLayer.updateProperties(this._drawId,nt._mergeSVGProperties(this.#e.getPathTranslatedSVGProperties(this.#p(),this.parentDimensions),{bbox:this.#m()}))}_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.#h(),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.#u(),this.#d(this.#e.box),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){let t=!1;this.parent&&!e?(this._uiManager.removeShouldRescale(this),this.#h()):e&&(this._uiManager.addShouldRescale(this),this.#u(e),t=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(e),t&&this.select()}#h(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())}#u(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.#f(this.#e,e)}}#g([e,t,s,i]){const{parentDimensions:[n,o],rotation:a}=this;switch(a){case 90:return[t,1-e,s*(o/n),i*(n/o)];case 180:return[1-e,1-t,s,i];case 270:return[1-t,e,s*(o/n),i*(n/o)];default:return[e,t,s,i]}}#p(){const{x:e,y:t,width:s,height:i,parentDimensions:[n,o],rotation:a}=this;switch(a){case 90:return[1-t,e,s*(n/o),i*(o/n)];case 180:return[1-e,1-t,s,i];case 270:return[t,1-e,s*(n/o),i*(o/n)];default:return[e,t,s,i]}}#d(e){[this.x,this.y,this.width,this.height]=this.#g(e),this.div&&(this.fixAndSetPosition(),this.setDims()),this._onResized()}#m(){const{x:e,y:t,width:s,height:i,rotation:n,parentRotation:o,parentDimensions:[a,d]}=this;switch((n*4+o)/90){case 1:return[1-t-i,e,i,s];case 2:return[1-e-s,1-t-i,s,i];case 3:return[t,1-e-s,i,s];case 4:return[e,t-s*(a/d),i*(d/a),s*(a/d)];case 5:return[1-t,e,s*(a/d),i*(d/a)];case 6:return[1-e-i*(d/a),1-t,i*(d/a),s*(a/d)];case 7:return[t-s*(a/d),1-e-i*(d/a),s*(a/d),i*(d/a)];case 8:return[e-s,t-i,s,i];case 9:return[1-t,e-s,i,s];case 10:return[1-e,1-t,s,i];case 11:return[t-i,1-e,i,s];case 12:return[e-i*(d/a),t,i*(d/a),s*(a/d)];case 13:return[1-t-s*(a/d),e-i*(d/a),s*(a/d),i*(d/a)];case 14:return[1-e,1-t-s*(a/d),i*(d/a),s*(a/d)];case 15:return[t,1-e,s*(a/d),i*(d/a)];default:return[e,t,s,i]}}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,nt._mergeSVGProperties({bbox:this.#m()},this.#e.updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&this.#d(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 s=super.render();s.classList.add("draw");const i=document.createElement("div");return s.append(i),i.setAttribute("aria-hidden","true"),i.className="internal",this.setDims(),this._uiManager.addShouldRescale(this),this.disableEditing(),this._isCopy&&this._moveAfterPaste(e,t),s}static createDrawerInstance(e,t,s,i,n){Jt("Not implemented")}static startDrawing(e,t,s,i){const{target:n,offsetX:o,offsetY:a,pointerId:d,pointerType:u}=i;if(nt.#r&&nt.#r!==u)return;const{viewport:{rotation:m}}=e,{width:g,height:w}=n.getBoundingClientRect(),b=nt.#s=new AbortController,I=e.combinedSignal(b);if(nt.#n||=d,nt.#r??=u,window.addEventListener("pointerup",y=>{nt.#n===y.pointerId?this._endDraw(y):nt.#a?.delete(y.pointerId)},{signal:I}),window.addEventListener("pointercancel",y=>{nt.#n===y.pointerId?this._currentParent.endDrawingSession():nt.#a?.delete(y.pointerId)},{signal:I}),window.addEventListener("pointerdown",y=>{nt.#r===y.pointerType&&((nt.#a||=new Set).add(y.pointerId),nt.#i.isCancellable()&&(nt.#i.removeLastElement(),nt.#i.isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:I}),window.addEventListener("contextmenu",ri,{signal:I}),n.addEventListener("pointermove",this._drawMove.bind(this),{signal:I}),n.addEventListener("touchmove",y=>{y.timeStamp===nt.#c&&rs(y)},{signal:I}),e.toggleDrawing(),t._editorUndoBar?.hide(),nt.#i){e.drawLayer.updateProperties(this._currentDrawId,nt.#i.startNew(o,a,g,w,m));return}t.updateUIForDefaultProperties(this),nt.#i=this.createDrawerInstance(o,a,g,w,m),nt.#o=this.getDefaultDrawingOptions(),this._currentParent=e,{id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties(nt.#o.toSVGProperties(),nt.#i.defaultSVGProperties),!0,!1)}static _drawMove(e){if(nt.#c=-1,!nt.#i)return;const{offsetX:t,offsetY:s,pointerId:i}=e;if(nt.#n===i){if(nt.#a?.size>=1){this._endDraw(e);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,nt.#i.add(t,s)),nt.#c=e.timeStamp,rs(e)}}static _cleanup(e){e&&(this._currentDrawId=-1,this._currentParent=null,nt.#i=null,nt.#o=null,nt.#r=null,nt.#c=NaN),nt.#s&&(nt.#s.abort(),nt.#s=null,nt.#n=NaN,nt.#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,nt.#i.end(e.offsetX,e.offsetY)),this.supportMultipleDrawings){const s=nt.#i,i=this._currentDrawId,n=s.getLastElement();t.addCommands({cmd:()=>{t.drawLayer.updateProperties(i,s.setLastElement(n))},undo:()=>{t.drawLayer.updateProperties(i,s.removeLastElement())},mustExec:!1,type:Mt.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(e){const t=this._currentParent;if(!t)return null;if(t.toggleDrawing(!0),t.cleanUndoStack(Mt.DRAW_STEP),!nt.#i.isEmpty()){const{pageDimensions:[s,i],scale:n}=t,o=t.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:nt.#i.getOutlines(s*n,i*n,n,this._INNER_MARGIN),drawingOptions:nt.#o,mustBeCommitted:!e});return this._cleanup(!0),o}return t.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(e){}static deserializeDraw(e,t,s,i,n,o){Jt("Not implemented")}static async deserialize(e,t,s){const{rawDims:{pageWidth:i,pageHeight:n,pageX:o,pageY:a}}=t.viewport,d=this.deserializeDraw(o,a,i,n,this._INNER_MARGIN,e),u=await super.deserialize(e,t,s);return u.createDrawingOptions(e),u.#l({drawOutlines:d}),u.#u(),u.onScaleChanging(),u.rotate(),u}serializeDraw(e){const[t,s]=this.pageTranslation,[i,n]=this.pageDimensions;return this.#e.serialize([t,s,i,n],e)}renderAnnotationElement(e){return e.updateEdited({rect:this.getPDFRect()}),null}static canCreateNewEmptyEditor(){return!1}}class N2{#e=new Float64Array(6);#t;#i;#s;#o;#n;#r="";#a=0;#c=new zo;#l;#f;constructor(e,t,s,i,n,o){this.#l=s,this.#f=i,this.#s=n,this.#o=o,[e,t]=this.#h(e,t);const a=this.#t=[NaN,NaN,NaN,NaN,e,t];this.#n=[e,t],this.#i=[{line:a,points:this.#n}],this.#e.set(a,0)}updateProperty(e,t){e==="stroke-width"&&(this.#o=t)}#h(e,t){return Ue._normalizePoint(e,t,this.#l,this.#f,this.#s)}isEmpty(){return!this.#i||this.#i.length===0}isCancellable(){return this.#n.length<=10}add(e,t){[e,t]=this.#h(e,t);const[s,i,n,o]=this.#e.subarray(2,6),a=e-n,d=t-o;return Math.hypot(this.#l*a,this.#f*d)<=2?null:(this.#n.push(e,t),isNaN(s)?(this.#e.set([n,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([s,i,n,o,e,t],0),this.#t.push(...Ue.createBezierPoints(s,i,n,o,e,t)),{path:{d:this.toSVGPath()}}))}end(e,t){const s=this.add(e,t);return s||(this.#n.length===2?{path:{d:this.toSVGPath()}}:null)}startNew(e,t,s,i,n){this.#l=s,this.#f=i,this.#s=n,[e,t]=this.#h(e,t);const o=this.#t=[NaN,NaN,NaN,NaN,e,t];this.#n=[e,t];const a=this.#i.at(-1);return a&&(a.line=new Float32Array(a.line),a.points=new Float32Array(a.points)),this.#i.push({line:o,points:this.#n}),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.#n=e.points,this.#a=0,{path:{d:this.toSVGPath()}}):this.#c.setLastElement(e)}removeLastElement(){if(!this.#i)return this.#c.removeLastElement();this.#i.pop(),this.#r="";for(let e=0,t=this.#i.length;e<t;e++){const{line:s,points:i}=this.#i[e];this.#t=s,this.#n=i,this.#a=0,this.toSVGPath()}return{path:{d:this.#r}}}toSVGPath(){const e=Ue.svgRound(this.#t[4]),t=Ue.svgRound(this.#t[5]);if(this.#n.length===2)return this.#r=`${this.#r} M ${e} ${t} Z`,this.#r;if(this.#n.length<=6){const i=this.#r.lastIndexOf("M");this.#r=`${this.#r.slice(0,i)} M ${e} ${t}`,this.#a=6}if(this.#n.length===4){const i=Ue.svgRound(this.#t[10]),n=Ue.svgRound(this.#t[11]);return this.#r=`${this.#r} L ${i} ${n}`,this.#a=12,this.#r}const s=[];this.#a===0&&(s.push(`M ${e} ${t}`),this.#a=6);for(let i=this.#a,n=this.#t.length;i<n;i+=6){const[o,a,d,u,m,g]=this.#t.slice(i,i+6).map(Ue.svgRound);s.push(`C${o} ${a} ${d} ${u} ${m} ${g}`)}return this.#r+=s.join(" "),this.#a=this.#t.length,this.#r}getOutlines(e,t,s,i){const n=this.#i.at(-1);return n.line=new Float32Array(n.line),n.points=new Float32Array(n.points),this.#c.build(this.#i,e,t,s,this.#s,this.#o,i),this.#e=null,this.#t=null,this.#i=null,this.#r=null,this.#c}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}class zo extends Ue{#e;#t=0;#i;#s;#o;#n;#r;#a;#c;build(e,t,s,i,n,o,a){this.#o=t,this.#n=s,this.#r=i,this.#a=n,this.#c=o,this.#i=a??0,this.#s=e,this.#h()}get thickness(){return this.#c}setLastElement(e){return this.#s.push(e),{path:{d:this.toSVGPath()}}}removeLastElement(){return this.#s.pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const e=[];for(const{line:t}of this.#s){if(e.push(`M${Ue.svgRound(t[4])} ${Ue.svgRound(t[5])}`),t.length===6){e.push("Z");continue}if(t.length===12&&isNaN(t[6])){e.push(`L${Ue.svgRound(t[10])} ${Ue.svgRound(t[11])}`);continue}for(let s=6,i=t.length;s<i;s+=6){const[n,o,a,d,u,m]=t.subarray(s,s+6).map(Ue.svgRound);e.push(`C${n} ${o} ${a} ${d} ${u} ${m}`)}}return e.join("")}serialize([e,t,s,i],n){const o=[],a=[],[d,u,m,g]=this.#f();let w,b,I,y,j,L,O,R,F;switch(this.#a){case 0:F=Ue._rescale,w=e,b=t+i,I=s,y=-i,j=e+d*s,L=t+(1-u-g)*i,O=e+(d+m)*s,R=t+(1-u)*i;break;case 90:F=Ue._rescaleAndSwap,w=e,b=t,I=s,y=i,j=e+u*s,L=t+d*i,O=e+(u+g)*s,R=t+(d+m)*i;break;case 180:F=Ue._rescale,w=e+s,b=t,I=-s,y=i,j=e+(1-d-m)*s,L=t+u*i,O=e+(1-d)*s,R=t+(u+g)*i;break;case 270:F=Ue._rescaleAndSwap,w=e+s,b=t+i,I=-s,y=-i,j=e+(1-u-g)*s,L=t+(1-d-m)*i,O=e+(1-u)*s,R=t+(1-d)*i;break}for(const{line:U,points:V}of this.#s)o.push(F(U,w,b,I,y,n?new Array(U.length):null)),a.push(F(V,w,b,I,y,n?new Array(V.length):null));return{lines:o,points:a,rect:[j,L,O,R]}}static deserialize(e,t,s,i,n,{paths:{lines:o,points:a},rotation:d,thickness:u}){const m=[];let g,w,b,I,y;switch(d){case 0:y=Ue._rescale,g=-e/s,w=t/i+1,b=1/s,I=-1/i;break;case 90:y=Ue._rescaleAndSwap,g=-t/i,w=-e/s,b=1/i,I=1/s;break;case 180:y=Ue._rescale,g=e/s+1,w=-t/i,b=-1/s,I=1/i;break;case 270:y=Ue._rescaleAndSwap,g=t/i+1,w=e/s+1,b=-1/i,I=-1/s;break}if(!o){o=[];for(const L of a){const O=L.length;if(O===2){o.push(new Float32Array([NaN,NaN,NaN,NaN,L[0],L[1]]));continue}if(O===4){o.push(new Float32Array([NaN,NaN,NaN,NaN,L[0],L[1],NaN,NaN,NaN,NaN,L[2],L[3]]));continue}const R=new Float32Array(3*(O-2));o.push(R);let[F,U,V,Q]=L.subarray(0,4);R.set([NaN,NaN,NaN,NaN,F,U],0);for(let K=4;K<O;K+=2){const Z=L[K],$=L[K+1];R.set(Ue.createBezierPoints(F,U,V,Q,Z,$),(K-2)*3),[F,U,V,Q]=[V,Q,Z,$]}}}for(let L=0,O=o.length;L<O;L++)m.push({line:y(o[L].map(R=>R??NaN),g,w,b,I),points:y(a[L].map(R=>R??NaN),g,w,b,I)});const j=new this.prototype.constructor;return j.build(m,s,i,1,d,u,n),j}#l(e=this.#c){const t=this.#i+e/2*this.#r;return this.#a%180===0?[t/this.#o,t/this.#n]:[t/this.#n,t/this.#o]}#f(){const[e,t,s,i]=this.#e,[n,o]=this.#l(0);return[e+n,t+o,s-2*n,i-2*o]}#h(){const e=this.#e=new Float32Array([1/0,1/0,-1/0,-1/0]);for(const{line:i}of this.#s){if(i.length<=12){for(let a=4,d=i.length;a<d;a+=6)He.pointBoundingBox(i[a],i[a+1],e);continue}let n=i[4],o=i[5];for(let a=6,d=i.length;a<d;a+=6){const[u,m,g,w,b,I]=i.subarray(a,a+6);He.bezierBoundingBox(n,o,u,m,g,w,b,I,e),n=b,o=I}}const[t,s]=this.#l();e[0]=js(e[0]-t,0,1),e[1]=js(e[1]-s,0,1),e[2]=js(e[2]+t,0,1),e[3]=js(e[3]+s,0,1),e[2]-=e[0],e[3]-=e[1]}get box(){return this.#e}updateProperty(e,t){return e==="stroke-width"?this.#u(t):null}#u(e){const[t,s]=this.#l();this.#c=e;const[i,n]=this.#l(),[o,a]=[i-t,n-s],d=this.#e;return d[0]-=o,d[1]-=a,d[2]+=2*o,d[3]+=2*a,d}updateParentDimensions([e,t],s){const[i,n]=this.#l();this.#o=e,this.#n=t,this.#r=s;const[o,a]=this.#l(),d=o-i,u=a-n,m=this.#e;return m[0]-=d,m[1]-=u,m[2]+=2*d,m[3]+=2*u,m}updateRotation(e){return this.#t=e,{path:{transform:this.rotationTransform}}}get viewBox(){return this.#e.map(Ue.svgRound).join(" ")}get defaultProperties(){const[e,t]=this.#e;return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Ue.svgRound(e)} ${Ue.svgRound(t)}`}}}get rotationTransform(){const[,,e,t]=this.#e;let s=0,i=0,n=0,o=0,a=0,d=0;switch(this.#t){case 90:i=t/e,n=-e/t,a=e;break;case 180:s=-1,o=-1,a=e,d=t;break;case 270:i=-t/e,n=e/t,d=t;break;default:return""}return`matrix(${s} ${i} ${n} ${o} ${Ue.svgRound(a)} ${Ue.svgRound(d)})`}getPathResizingSVGProperties([e,t,s,i]){const[n,o]=this.#l(),[a,d,u,m]=this.#e;if(Math.abs(u-n)<=Ue.PRECISION||Math.abs(m-o)<=Ue.PRECISION){const y=e+s/2-(a+u/2),j=t+i/2-(d+m/2);return{path:{"transform-origin":`${Ue.svgRound(e)} ${Ue.svgRound(t)}`,transform:`${this.rotationTransform} translate(${y} ${j})`}}}const g=(s-2*n)/(u-2*n),w=(i-2*o)/(m-2*o),b=u/s,I=m/i;return{path:{"transform-origin":`${Ue.svgRound(a)} ${Ue.svgRound(d)}`,transform:`${this.rotationTransform} scale(${b} ${I}) translate(${Ue.svgRound(n)} ${Ue.svgRound(o)}) scale(${g} ${w}) translate(${Ue.svgRound(-n)} ${Ue.svgRound(-o)})`}}}getPathResizedSVGProperties([e,t,s,i]){const[n,o]=this.#l(),a=this.#e,[d,u,m,g]=a;if(a[0]=e,a[1]=t,a[2]=s,a[3]=i,Math.abs(m-n)<=Ue.PRECISION||Math.abs(g-o)<=Ue.PRECISION){const j=e+s/2-(d+m/2),L=t+i/2-(u+g/2);for(const{line:O,points:R}of this.#s)Ue._translate(O,j,L,O),Ue._translate(R,j,L,R);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Ue.svgRound(e)} ${Ue.svgRound(t)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const w=(s-2*n)/(m-2*n),b=(i-2*o)/(g-2*o),I=-w*(d+n)+e+n,y=-b*(u+o)+t+o;if(w!==1||b!==1||I!==0||y!==0)for(const{line:j,points:L}of this.#s)Ue._rescale(j,I,y,w,b,j),Ue._rescale(L,I,y,w,b,L);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Ue.svgRound(e)} ${Ue.svgRound(t)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,t],s){const[i,n]=s,o=this.#e,a=e-o[0],d=t-o[1];if(this.#o===i&&this.#n===n)for(const{line:u,points:m}of this.#s)Ue._translate(u,a,d,u),Ue._translate(m,a,d,m);else{const u=this.#o/i,m=this.#n/n;this.#o=i,this.#n=n;for(const{line:g,points:w}of this.#s)Ue._rescale(g,a,d,u,m,g),Ue._rescale(w,a,d,u,m,w);o[2]*=u,o[3]*=m}return o[0]=e,o[1]=t,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${Ue.svgRound(e)} ${Ue.svgRound(t)}`}}}get defaultSVGProperties(){const e=this.#e;return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${Ue.svgRound(e[0])} ${Ue.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}}class fl extends Uu{constructor(e){super(),this._viewParameters=e,super.updateProperties({fill:"none",stroke:_e._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 fl(this._viewParameters);return e.updateAll(this),e}}class Zc extends nt{static _type="ink";static _editorType=at.INK;static _defaultDrawingOptions=null;constructor(e){super({...e,name:"inkEditor"}),this._willKeepAspectRatio=!0,this.defaultL10nId="pdfjs-editor-ink-editor"}static initialize(e,t){_e.initialize(e,t),this._defaultDrawingOptions=new fl(t.viewParameters)}static getDefaultDrawingOptions(e){const t=this._defaultDrawingOptions.clone();return t.updateProperties(e),t}static get supportMultipleDrawings(){return!0}static get typesMap(){return mt(this,"typesMap",new Map([[Mt.INK_THICKNESS,"stroke-width"],[Mt.INK_COLOR,"stroke"],[Mt.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(e,t,s,i,n){return new N2(e,t,s,i,n,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(e,t,s,i,n,o){return zo.deserialize(e,t,s,i,n,o)}static async deserialize(e,t,s){let i=null;if(e instanceof Vc){const{data:{inkLists:o,rect:a,rotation:d,id:u,color:m,opacity:g,borderStyle:{rawWidth:w},popupRef:b,richText:I,contentsObj:y,creationDate:j,modificationDate:L},parent:{page:{pageNumber:O}}}=e;i=e={annotationType:at.INK,color:Array.from(m),thickness:w,opacity:g,paths:{points:o},boxes:null,pageIndex:O-1,rect:a.slice(0),rotation:d,annotationElementId:u,id:u,deleted:!1,popupRef:b,richText:I,comment:y?.str||null,creationDate:j,modificationDate:L}}const n=await super.deserialize(e,t,s);return n._initialData=i,e.comment&&n.setCommentData(e),n}get toolbarButtons(){return this._colorPicker||=new Do(this),[["colorPicker",this._colorPicker]]}get colorType(){return Mt.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:s}=this;t.updateSVGProperty("stroke-width"),s.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:s}){this._drawingOptions=Zc.getDefaultDrawingOptions({stroke:He.makeHexColor(...e),"stroke-width":t,"stroke-opacity":s})}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:t,points:s}=this.serializeDraw(e),{_drawingOptions:{stroke:i,"stroke-opacity":n,"stroke-width":o}}=this,a=Object.assign(super.serialize(e),{color:_e._colorManager.convert(i),opacity:n,thickness:o,paths:{lines:t,points:s}});return this.addComment(a),e?(a.isCopy=!0,a):this.annotationElementId&&!this.#e(a)?null:(a.id=this.annotationElementId,a)}#e(e){const{color:t,thickness:s,opacity:i,pageIndex:n}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized||e.color.some((o,a)=>o!==t[a])||e.thickness!==s||e.opacity!==i||e.pageIndex!==n}renderAnnotationElement(e){if(this.deleted)return e.hide(),null;const{points:t,rect:s}=this.serializeDraw(!1);return e.updateEdited({rect:s,thickness:this._drawingOptions["stroke-width"],points:t,popup:this.comment}),null}}class Mc extends zo{toSVGPath(){let e=super.toSVGPath();return e.endsWith("Z")||(e+="Z"),e}}const Ja=8,Ao=3;class Un{static#e={maxDim:512,sigmaSFactor:.02,sigmaR:25,kernelSize:16};static#t(e,t,s,i){return s-=e,i-=t,s===0?i>0?0:4:s===1?i+6:2-i}static#i=new Int32Array([0,1,-1,1,-1,0,-1,-1,0,-1,1,-1,1,0,1,1]);static#s(e,t,s,i,n,o,a){const d=this.#t(s,i,n,o);for(let u=0;u<8;u++){const m=(-u+d-a+16)%8,g=this.#i[2*m],w=this.#i[2*m+1];if(e[(s+g)*t+(i+w)]!==0)return m}return-1}static#o(e,t,s,i,n,o,a){const d=this.#t(s,i,n,o);for(let u=0;u<8;u++){const m=(u+d+a+16)%8,g=this.#i[2*m],w=this.#i[2*m+1];if(e[(s+g)*t+(i+w)]!==0)return m}return-1}static#n(e,t,s,i){const n=e.length,o=new Int32Array(n);for(let m=0;m<n;m++)o[m]=e[m]<=i?1:0;for(let m=1;m<s-1;m++)o[m*t]=o[m*t+t-1]=0;for(let m=0;m<t;m++)o[m]=o[t*s-1-m]=0;let a=1,d;const u=[];for(let m=1;m<s-1;m++){d=1;for(let g=1;g<t-1;g++){const w=m*t+g,b=o[w];if(b===0)continue;let I=m,y=g;if(b===1&&o[w-1]===0)a+=1,y-=1;else if(b>=1&&o[w+1]===0)a+=1,y+=1,b>1&&(d=b);else{b!==1&&(d=Math.abs(b));continue}const j=[g,m],L=y===g+1,O={isHole:L,points:j,id:a,parent:0};u.push(O);let R;for(const se of u)if(se.id===d){R=se;break}R?R.isHole?O.parent=L?R.parent:d:O.parent=L?d:R.parent:O.parent=L?d:0;const F=this.#s(o,t,m,g,I,y,0);if(F===-1){o[w]=-a,o[w]!==1&&(d=Math.abs(o[w]));continue}let U=this.#i[2*F],V=this.#i[2*F+1];const Q=m+U,K=g+V;I=Q,y=K;let Z=m,$=g;for(;;){const se=this.#o(o,t,Z,$,I,y,1);U=this.#i[2*se],V=this.#i[2*se+1];const le=Z+U,pe=$+V;j.push(pe,le);const oe=Z*t+$;if(o[oe+1]===0?o[oe]=-a:o[oe]===1&&(o[oe]=a),le===m&&pe===g&&Z===Q&&$===K){o[w]!==1&&(d=Math.abs(o[w]));break}else I=Z,y=$,Z=le,$=pe}}}return u}static#r(e,t,s,i){if(s-t<=4){for(let Q=t;Q<s-2;Q+=2)i.push(e[Q],e[Q+1]);return}const n=e[t],o=e[t+1],a=e[s-4]-n,d=e[s-3]-o,u=Math.hypot(a,d),m=a/u,g=d/u,w=m*o-g*n,b=d/a,I=1/u,y=Math.atan(b),j=Math.cos(y),L=Math.sin(y),O=I*(Math.abs(j)+Math.abs(L)),R=I*(1-O+O**2),F=Math.max(Math.atan(Math.abs(L+j)*R),Math.atan(Math.abs(L-j)*R));let U=0,V=t;for(let Q=t+2;Q<s-2;Q+=2){const K=Math.abs(w-m*e[Q+1]+g*e[Q]);K>U&&(V=Q,U=K)}U>(u*F)**2?(this.#r(e,t,V+2,i),this.#r(e,V,s,i)):i.push(n,o)}static#a(e){const t=[],s=e.length;return this.#r(e,0,s,t),t.push(e[s-2],e[s-1]),t.length<=4?null:t}static#c(e,t,s,i,n,o){const a=new Float32Array(o**2),d=-2*i**2,u=o>>1;for(let y=0;y<o;y++){const j=(y-u)**2;for(let L=0;L<o;L++)a[y*o+L]=Math.exp((j+(L-u)**2)/d)}const m=new Float32Array(256),g=-2*n**2;for(let y=0;y<256;y++)m[y]=Math.exp(y**2/g);const w=e.length,b=new Uint8Array(w),I=new Uint32Array(256);for(let y=0;y<s;y++)for(let j=0;j<t;j++){const L=y*t+j,O=e[L];let R=0,F=0;for(let V=0;V<o;V++){const Q=y+V-u;if(!(Q<0||Q>=s))for(let K=0;K<o;K++){const Z=j+K-u;if(Z<0||Z>=t)continue;const $=e[Q*t+Z],se=a[V*o+K]*m[Math.abs($-O)];R+=$*se,F+=se}}const U=b[L]=Math.round(R/F);I[U]++}return[b,I]}static#l(e){const t=new Uint32Array(256);for(const s of e)t[s]++;return t}static#f(e){const t=e.length,s=new Uint8ClampedArray(t>>2);let i=-1/0,n=1/0;for(let a=0,d=s.length;a<d;a++){const u=s[a]=e[a<<2];i=Math.max(i,u),n=Math.min(n,u)}const o=255/(i-n);for(let a=0,d=s.length;a<d;a++)s[a]=(s[a]-n)*o;return s}static#h(e){let t,s=-1/0,i=-1/0;const n=e.findIndex(d=>d!==0);let o=n,a=n;for(t=n;t<256;t++){const d=e[t];d>s&&(t-o>i&&(i=t-o,a=t-1),s=d,o=t)}for(t=a-1;t>=0&&!(e[t]>e[t+1]);t--);return t}static#u(e){const t=e,{width:s,height:i}=e,{maxDim:n}=this.#e;let o=s,a=i;if(s>n||i>n){let w=s,b=i,I=Math.log2(Math.max(s,i)/n);const y=Math.floor(I);I=I===y?y-1:y;for(let L=0;L<I;L++){o=Math.ceil(w/2),a=Math.ceil(b/2);const O=new OffscreenCanvas(o,a);O.getContext("2d").drawImage(e,0,0,w,b,0,0,o,a),w=o,b=a,e!==t&&e.close(),e=O.transferToImageBitmap()}const j=Math.min(n/o,n/a);o=Math.round(o*j),a=Math.round(a*j)}const u=new OffscreenCanvas(o,a).getContext("2d",{willReadFrequently:!0});u.fillStyle="white",u.fillRect(0,0,o,a),u.filter="grayscale(1)",u.drawImage(e,0,0,e.width,e.height,0,0,o,a);const m=u.getImageData(0,0,o,a).data;return[this.#f(m),o,a]}static extractContoursFromText(e,{fontFamily:t,fontStyle:s,fontWeight:i},n,o,a,d){let u=new OffscreenCanvas(1,1),m=u.getContext("2d",{alpha:!1});const g=200,w=m.font=`${s} ${i} ${g}px ${t}`,{actualBoundingBoxLeft:b,actualBoundingBoxRight:I,actualBoundingBoxAscent:y,actualBoundingBoxDescent:j,fontBoundingBoxAscent:L,fontBoundingBoxDescent:O,width:R}=m.measureText(e),F=1.5,U=Math.ceil(Math.max(Math.abs(b)+Math.abs(I)||0,R)*F),V=Math.ceil(Math.max(Math.abs(y)+Math.abs(j)||g,Math.abs(L)+Math.abs(O)||g)*F);u=new OffscreenCanvas(U,V),m=u.getContext("2d",{alpha:!0,willReadFrequently:!0}),m.font=w,m.filter="grayscale(1)",m.fillStyle="white",m.fillRect(0,0,U,V),m.fillStyle="black",m.fillText(e,U*(F-1)/2,V*(3-F)/2);const Q=this.#f(m.getImageData(0,0,U,V).data),K=this.#l(Q),Z=this.#h(K),$=this.#n(Q,U,V,Z);return this.processDrawnLines({lines:{curves:$,width:U,height:V},pageWidth:n,pageHeight:o,rotation:a,innerMargin:d,mustSmooth:!0,areContours:!0})}static process(e,t,s,i,n){const[o,a,d]=this.#u(e),[u,m]=this.#c(o,a,d,Math.hypot(a,d)*this.#e.sigmaSFactor,this.#e.sigmaR,this.#e.kernelSize),g=this.#h(m),w=this.#n(u,a,d,g);return this.processDrawnLines({lines:{curves:w,width:a,height:d},pageWidth:t,pageHeight:s,rotation:i,innerMargin:n,mustSmooth:!0,areContours:!0})}static processDrawnLines({lines:e,pageWidth:t,pageHeight:s,rotation:i,innerMargin:n,mustSmooth:o,areContours:a}){i%180!==0&&([t,s]=[s,t]);const{curves:d,width:u,height:m}=e,g=e.thickness??0,w=[],b=Math.min(t/u,s/m),I=b/t,y=b/s,j=[];for(const{points:O}of d){const R=o?this.#a(O):O;if(!R)continue;j.push(R);const F=R.length,U=new Float32Array(F),V=new Float32Array(3*(F===2?2:F-2));if(w.push({line:V,points:U}),F===2){U[0]=R[0]*I,U[1]=R[1]*y,V.set([NaN,NaN,NaN,NaN,U[0],U[1]],0);continue}let[Q,K,Z,$]=R;Q*=I,K*=y,Z*=I,$*=y,U.set([Q,K,Z,$],0),V.set([NaN,NaN,NaN,NaN,Q,K],0);for(let se=4;se<F;se+=2){const le=U[se]=R[se]*I,pe=U[se+1]=R[se+1]*y;V.set(Ue.createBezierPoints(Q,K,Z,$,le,pe),(se-2)*3),[Q,K,Z,$]=[Z,$,le,pe]}}if(w.length===0)return null;const L=a?new Mc:new zo;return L.build(w,t,s,1,i,a?0:g,n),{outline:L,newCurves:j,areContours:a,thickness:g,width:u,height:m}}static async compressSignature({outlines:e,areContours:t,thickness:s,width:i,height:n}){let o=1/0,a=-1/0,d=0;for(const R of e){d+=R.length;for(let F=2,U=R.length;F<U;F++){const V=R[F]-R[F-2];o=Math.min(o,V),a=Math.max(a,V)}}let u;o>=-128&&a<=127?u=Int8Array:o>=-32768&&a<=32767?u=Int16Array:u=Int32Array;const m=e.length,g=Ja+Ao*m,w=new Uint32Array(g);let b=0;w[b++]=g*Uint32Array.BYTES_PER_ELEMENT+(d-2*m)*u.BYTES_PER_ELEMENT,w[b++]=0,w[b++]=i,w[b++]=n,w[b++]=t?0:1,w[b++]=Math.max(0,Math.floor(s??0)),w[b++]=m,w[b++]=u.BYTES_PER_ELEMENT;for(const R of e)w[b++]=R.length-2,w[b++]=R[0],w[b++]=R[1];const I=new CompressionStream("deflate-raw"),y=I.writable.getWriter();await y.ready,y.write(w);const j=u.prototype.constructor;for(const R of e){const F=new j(R.length-2);for(let U=2,V=R.length;U<V;U++)F[U-2]=R[U]-R[U-2];y.write(F)}y.close();const L=await new Response(I.readable).arrayBuffer(),O=new Uint8Array(L);return au(O)}static async decompressSignature(e){try{const t=sx(e),{readable:s,writable:i}=new DecompressionStream("deflate-raw"),n=i.getWriter();await n.ready,n.write(t).then(async()=>{await n.ready,await n.close()}).catch(()=>{});let o=null,a=0;for await(const R of s)o||=new Uint8Array(new Uint32Array(R.buffer,0,4)[0]),o.set(R,a),a+=R.length;const d=new Uint32Array(o.buffer,0,o.length>>2),u=d[1];if(u!==0)throw new Error(`Invalid version: ${u}`);const m=d[2],g=d[3],w=d[4]===0,b=d[5],I=d[6],y=d[7],j=[],L=(Ja+Ao*I)*Uint32Array.BYTES_PER_ELEMENT;let O;switch(y){case Int8Array.BYTES_PER_ELEMENT:O=new Int8Array(o.buffer,L);break;case Int16Array.BYTES_PER_ELEMENT:O=new Int16Array(o.buffer,L);break;case Int32Array.BYTES_PER_ELEMENT:O=new Int32Array(o.buffer,L);break}a=0;for(let R=0;R<I;R++){const F=d[Ao*R+Ja],U=new Float32Array(F+2);j.push(U);for(let V=0;V<Ao-1;V++)U[V]=d[Ao*R+Ja+V+1];for(let V=0;V<F;V++)U[V+2]=U[V]+O[a++]}return{areContours:w,thickness:b,outlines:j,width:m,height:g}}catch(t){return lt(`decompressSignature: ${t}`),null}}}class Kc extends Uu{constructor(){super(),super.updateProperties({fill:_e._defaultLineColor,"stroke-width":0})}clone(){const e=new Kc;return e.updateAll(this),e}}class _c extends fl{constructor(e){super(e),super.updateProperties({stroke:_e._defaultLineColor,"stroke-width":1})}clone(){const e=new _c(this._viewParameters);return e.updateAll(this),e}}class Bi extends nt{#e=!1;#t=null;#i=null;#s=null;static _type="signature";static _editorType=at.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){_e.initialize(e,t),this._defaultDrawingOptions=new Kc,this._defaultDrawnSignatureOptions=new _c(t.viewParameters)}static getDefaultDrawingOptions(e){const t=this._defaultDrawingOptions.clone();return t.updateProperties(e),t}static get supportMultipleDrawings(){return!1}static get typesMap(){return mt(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:s}=this;if(s&&(this._isCopy=!1,e=this.x,t=this.y),super.render(),this._drawId===null)if(this.#i){const{lines:i,mustSmooth:n,areContours:o,description:a,uuid:d,heightInPage:u}=this.#i,{rawDims:{pageWidth:m,pageHeight:g},rotation:w}=this.parent.viewport,b=Un.processDrawnLines({lines:i,pageWidth:m,pageHeight:g,rotation:w,innerMargin:Bi._INNER_MARGIN,mustSmooth:n,areContours:o});this.addSignature(b,u,a,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 s&&(this._isCopy=!0,this._moveAfterPaste(e,t)),this.div}setUuid(e){this.#s=e,this.addEditToolbar()}getUuid(){return this.#s}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:s,width:i,height:n}=this.#i,o=Math.max(i,n),a=Un.processDrawnLines({lines:{curves:e.map(d=>({points:d})),thickness:s,width:i,height:n},pageWidth:o,pageHeight:o,rotation:0,innerMargin:0,mustSmooth:!1,areContours:t});return{areContours:t,outline:a.outline}}get toolbarButtons(){return this._uiManager.signatureManager?[["editSignature",this._uiManager.signatureManager]]:super.toolbarButtons}addSignature(e,t,s,i){const{x:n,y:o}=this,{outline:a}=this.#i=e;this.#e=a instanceof Mc,this.description=s;let d;this.#e?d=Bi.getDefaultDrawingOptions():(d=Bi._defaultDrawnSignatureOptions.clone(),d.updateProperties({"stroke-width":a.thickness})),this._addOutlines({drawOutlines:a,drawingOptions:d});const[,u]=this.pageDimensions;let m=t/u;m=m>=1?.5:m,this.width*=m/this.height,this.width>=1&&(m*=.9/this.width,this.width=.9),this.height=m,this.setDims(),this.x=n,this.y=o,this.center(),this._onResized(),this.onScaleChanging(),this.rotate(),this._uiManager.addToAnnotationStorage(this),this.setUuid(i),this._reportTelemetry({action:"pdfjs.signature.inserted",data:{hasBeenSaved:!!i,hasDescription:!!s}}),this.div.hidden=!1}getFromImage(e){const{rawDims:{pageWidth:t,pageHeight:s},rotation:i}=this.parent.viewport;return Un.process(e,t,s,i,Bi._INNER_MARGIN)}getFromText(e,t){const{rawDims:{pageWidth:s,pageHeight:i},rotation:n}=this.parent.viewport;return Un.extractContoursFromText(e,t,s,i,n,Bi._INNER_MARGIN)}getDrawnSignature(e){const{rawDims:{pageWidth:t,pageHeight:s},rotation:i}=this.parent.viewport;return Un.processDrawnLines({lines:e,pageWidth:t,pageHeight:s,rotation:i,innerMargin:Bi._INNER_MARGIN,mustSmooth:!1,areContours:!1})}createDrawingOptions({areContours:e,thickness:t}){e?this._drawingOptions=Bi.getDefaultDrawingOptions():(this._drawingOptions=Bi._defaultDrawnSignatureOptions.clone(),this._drawingOptions.updateProperties({"stroke-width":t}))}serialize(e=!1){if(this.isEmpty())return null;const{lines:t,points:s}=this.serializeDraw(e),{_drawingOptions:{"stroke-width":i}}=this,n=Object.assign(super.serialize(e),{isSignature:!0,areContours:this.#e,color:[0,0,0],thickness:this.#e?0:i});return this.addComment(n),e?(n.paths={lines:t,points:s},n.uuid=this.#s,n.isCopy=!0):n.lines=t,this.#t&&(n.accessibilityData={type:"Figure",alt:this.#t}),n}static deserializeDraw(e,t,s,i,n,o){return o.areContours?Mc.deserialize(e,t,s,i,n,o):zo.deserialize(e,t,s,i,n,o)}static async deserialize(e,t,s){const i=await super.deserialize(e,t,s);return i.#e=e.areContours,i.description=e.accessibilityData?.alt||"",i.#s=e.uuid,i}}class k2 extends _e{#e=null;#t=null;#i=null;#s=null;#o=null;#n="";#r=null;#a=!1;#c=null;#l=!1;#f=!1;static _type="stamp";static _editorType=at.STAMP;constructor(e){super({...e,name:"stampEditor"}),this.#s=e.bitmapUrl,this.#o=e.bitmapFile,this.defaultL10nId="pdfjs-editor-stamp-editor"}static initialize(e,t){_e.initialize(e,t)}static isHandlingMimeForPasting(e){return $a.includes(e)}static paste(e,t){t.pasteEditor({mode:at.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}}#h(e,t=!1){if(!e){this.remove();return}this.#e=e.bitmap,t||(this.#t=e.id,this.#l=e.isSvg),e.file&&(this.#n=e.file.name),this.#p()}#u(){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:s}=this._uiManager;if(!s)throw new Error("No ML.");if(!await s.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:i,width:n,height:o}=e||this.copyCanvas(null,null,!0).imageData,a=await s.guess({name:"altText",request:{data:i,width:n,height:o,channels:i.length/(n*o)}});if(!a)throw new Error("No response from the AI service.");if(a.error)throw new Error("Error from the AI service.");if(a.cancel)return null;if(!a.output)throw new Error("No valid response from the AI service.");const d=a.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(s=>this.#h(s,!0)).finally(()=>this.#u());return}if(this.#s){const s=this.#s;this.#s=null,this._uiManager.enableWaiting(!0),this.#i=this._uiManager.imageManager.getFromUrl(s).then(i=>this.#h(i)).finally(()=>this.#u());return}if(this.#o){const s=this.#o;this.#o=null,this._uiManager.enableWaiting(!0),this.#i=this._uiManager.imageManager.getFromFile(s).then(i=>this.#h(i)).finally(()=>this.#u());return}const e=document.createElement("input");e.type="file",e.accept=$a.join(",");const t=this._uiManager._signal;this.#i=new Promise(s=>{e.addEventListener("change",async()=>{if(!e.files||e.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const i=await this._uiManager.imageManager.getFromFile(e.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),this.#h(i)}s()},{signal:t}),e.addEventListener("cancel",()=>{this.remove(),s()},{signal:t})}).finally(()=>this.#u()),e.click()}remove(){this.#t&&(this.#e=null,this._uiManager.imageManager.deleteId(this.#t),this.#r?.remove(),this.#r=null,this.#c&&(clearTimeout(this.#c),this.#c=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.#s||this.#o||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.#p():this.#g()),this._isCopy&&this._moveAfterPaste(e,t),this._uiManager.addShouldRescale(this),this.div}setCanvas(e,t){const{id:s,bitmap:i}=this._uiManager.imageManager.getFromCanvas(e,t);t.remove(),s&&this._uiManager.imageManager.isValidId(s)&&(this.#t=s,i&&(this.#e=i),this.#a=!1,this.#p())}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;this.#c!==null&&clearTimeout(this.#c);const e=200;this.#c=setTimeout(()=>{this.#c=null,this.#m()},e)}#p(){const{div:e}=this;let{width:t,height:s}=this.#e;const[i,n]=this.pageDimensions,o=.75;if(this.width)t=this.width*i,s=this.height*n;else if(t>o*i||s>o*n){const d=Math.min(o*i/t,o*n/s);t*=d,s*=d}this._uiManager.enableWaiting(!1);const a=this.#r=document.createElement("canvas");a.setAttribute("role","img"),this.addContainer(a),this.width=t/i,this.height=s/n,this.setDims(),this._initialOptions?.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(e.hidden=!1),this.#m(),this.#f||(this.parent.addUndoableEditor(this),this.#f=!0),this._reportTelemetry({action:"inserted_image"}),this.#n&&this.div.setAttribute("aria-description",this.#n),this.annotationElementId||this._uiManager.a11yAlert("pdfjs-editor-stamp-added-alert")}copyCanvas(e,t,s=!1){e||(e=224);const{width:i,height:n}=this.#e,o=new Mi;let a=this.#e,d=i,u=n,m=null;if(t){if(i>t||n>t){const V=Math.min(t/i,t/n);d=Math.floor(i*V),u=Math.floor(n*V)}m=document.createElement("canvas");const w=m.width=Math.ceil(d*o.sx),b=m.height=Math.ceil(u*o.sy);this.#l||(a=this.#d(w,b));const I=m.getContext("2d");I.filter=this._uiManager.hcmFilter;let y="white",j="#cfcfd8";this._uiManager.hcmFilter!=="none"?j="black":rx.isDarkMode&&(y="#8f8f9d",j="#42414d");const L=15,O=L*o.sx,R=L*o.sy,F=new OffscreenCanvas(O*2,R*2),U=F.getContext("2d");U.fillStyle=y,U.fillRect(0,0,O*2,R*2),U.fillStyle=j,U.fillRect(0,0,O,R),U.fillRect(O,R,O,R),I.fillStyle=I.createPattern(F,"repeat"),I.fillRect(0,0,w,b),I.drawImage(a,0,0,a.width,a.height,0,0,w,b)}let g=null;if(s){let w,b;if(o.symmetric&&a.width<e&&a.height<e)w=a.width,b=a.height;else if(a=this.#e,i>e||n>e){const j=Math.min(e/i,e/n);w=Math.floor(i*j),b=Math.floor(n*j),this.#l||(a=this.#d(w,b))}const y=new OffscreenCanvas(w,b).getContext("2d",{willReadFrequently:!0});y.drawImage(a,0,0,a.width,a.height,0,0,w,b),g={width:w,height:b,data:y.getImageData(0,0,w,b).data}}return{canvas:m,width:d,height:u,imageData:g}}#d(e,t){const{width:s,height:i}=this.#e;let n=s,o=i,a=this.#e;for(;n>2*e||o>2*t;){const d=n,u=o;n>2*e&&(n=n>=16384?Math.floor(n/2)-1:Math.ceil(n/2)),o>2*t&&(o=o>=16384?Math.floor(o/2)-1:Math.ceil(o/2));const m=new OffscreenCanvas(n,o);m.getContext("2d").drawImage(a,0,0,d,u,0,0,n,o),a=m.transferToImageBitmap()}return a}#m(){const[e,t]=this.parentDimensions,{width:s,height:i}=this,n=new Mi,o=Math.ceil(s*e*n.sx),a=Math.ceil(i*t*n.sy),d=this.#r;if(!d||d.width===o&&d.height===a)return;d.width=o,d.height=a;const u=this.#l?this.#e:this.#d(o,a),m=d.getContext("2d");m.filter=this._uiManager.hcmFilter,m.drawImage(u,0,0,u.width,u.height,0,0,o,a)}#A(e){if(e){if(this.#l){const i=this._uiManager.imageManager.getSvgUrl(this.#t);if(i)return i}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.#l){const[t,s]=this.pageDimensions,i=Math.round(this.width*t*Xn.PDF_TO_CSS_UNITS),n=Math.round(this.height*s*Xn.PDF_TO_CSS_UNITS),o=new OffscreenCanvas(i,n);return o.getContext("2d").drawImage(this.#e,0,0,this.#e.width,this.#e.height,0,0,i,n),o.transferToImageBitmap()}return structuredClone(this.#e)}static async deserialize(e,t,s){let i=null,n=!1;if(e instanceof Fu){const{data:{rect:y,rotation:j,id:L,structParent:O,popupRef:R,richText:F,contentsObj:U,creationDate:V,modificationDate:Q},container:K,parent:{page:{pageNumber:Z}},canvas:$}=e;let se,le;$?(delete e.canvas,{id:se,bitmap:le}=s.imageManager.getFromCanvas(K.id,$),$.remove()):(n=!0,e._hasNoCanvas=!0);const pe=(await t._structTree.getAriaAttributes(`${Bc}${L}`))?.get("aria-label")||"";i=e={annotationType:at.STAMP,bitmapId:se,bitmap:le,pageIndex:Z-1,rect:y.slice(0),rotation:j,annotationElementId:L,id:L,deleted:!1,accessibilityData:{decorative:!1,altText:pe},isSvg:!1,structParent:O,popupRef:R,richText:F,comment:U?.str||null,creationDate:V,modificationDate:Q}}const o=await super.deserialize(e,t,s),{rect:a,bitmap:d,bitmapUrl:u,bitmapId:m,isSvg:g,accessibilityData:w}=e;n?(s.addMissingCanvas(e.id,o),o.#a=!0):m&&s.imageManager.isValidId(m)?(o.#t=m,d&&(o.#e=d)):o.#s=u,o.#l=g;const[b,I]=o.pageDimensions;return o.width=(a[2]-a[0])/b,o.height=(a[3]-a[1])/I,w&&(o.altTextData=w),o._initialData=i,e.comment&&o.setCommentData(e),o.#f=!!i,o}serialize(e=!1,t=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const s=Object.assign(super.serialize(e),{bitmapId:this.#t,isSvg:this.#l});if(this.addComment(s),e)return s.bitmapUrl=this.#A(!0),s.accessibilityData=this.serializeAltText(!0),s.isCopy=!0,s;const{decorative:i,altText:n}=this.serializeAltText(!1);if(!i&&n&&(s.accessibilityData={type:"Figure",alt:n}),this.annotationElementId){const a=this.#w(s);return a.isSame?null:(a.isSameAltText?delete s.accessibilityData:s.accessibilityData.structParent=this._initialData.structParent??-1,s.id=this.annotationElementId,delete s.bitmapId,s)}if(t===null)return s;t.stamps||=new Map;const o=this.#l?(s.rect[2]-s.rect[0])*(s.rect[3]-s.rect[1]):null;if(!t.stamps.has(this.#t))t.stamps.set(this.#t,{area:o,serialized:s}),s.bitmap=this.#A(!1);else if(this.#l){const a=t.stamps.get(this.#t);o>a.area&&(a.area=o,a.serialized.bitmap.close(),a.serialized.bitmap=this.#A(!1))}return s}#w(e){const{pageIndex:t,accessibilityData:{altText:s}}=this._initialData,i=e.pageIndex===t,n=(e.accessibilityData?.alt||"")===s;return{isSame:!this.hasEditedComment&&!this._hasBeenMoved&&!this._hasBeenResized&&i&&n,isSameAltText:n}}renderAnnotationElement(e){return this.deleted?(e.hide(),null):(e.updateEdited({rect:this.getPDFRect(),popup:this.comment}),null)}}class Oi{#e;#t=!1;#i=null;#s=null;#o=null;#n=new Map;#r=!1;#a=!1;#c=!1;#l=null;#f=null;#h=null;#u=null;#g=null;#p=-1;#d;static _initialized=!1;static#m=new Map([ws,Zc,k2,ds,Bi].map(e=>[e._editorType,e]));constructor({uiManager:e,pageIndex:t,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:o,drawLayer:a,textLayer:d,viewport:u,l10n:m}){const g=[...Oi.#m.values()];if(!Oi._initialized){Oi._initialized=!0;for(const w of g)w.initialize(m,e)}e.registerEditorTypes(g),this.#d=e,this.pageIndex=t,this.div=s,this.#e=n,this.#i=o,this.viewport=u,this.#h=d,this.drawLayer=a,this._structTree=i,this.#d.addLayer(this)}get isEmpty(){return this.#n.size===0}get isInvisible(){return this.isEmpty&&this.#d.getMode()===at.NONE}updateToolbar(e){this.#d.updateToolbar(e)}updateMode(e=this.#d.getMode()){switch(this.#b(),e){case at.NONE:this.div.classList.toggle("nonEditing",!0),this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case at.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case at.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===at.POPUP)t.toggle("commentEditing",!0);else{t.toggle("commentEditing",!1);for(const s of Oi.#m.values())t.toggle(`${s._type}Editing`,e===s._editorType)}this.div.hidden=!1}hasTextLayer(e){return e===this.#h?.div}setEditingState(e){this.#d.setEditingState(e)}addCommands(e){this.#d.addCommands(e)}cleanUndoStack(e){this.#d.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#A(){return this.#n.size!==0?this.#n.values():this.#d.getEditors(this.pageIndex)}async enable(){this.#c=!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 s of this.#A)s.enableEditing(),s.show(!0),s.annotationElementId&&(this.#d.removeChangedExistingAnnotation(s),e.add(s.annotationElementId));const t=this.#i;if(t)for(const s of t.getEditableAnnotations()){if(s.hide(),this.#d.isDeletedAnnotationElement(s.data.id)||e.has(s.data.id))continue;const i=await this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}this.#c=!1,this.#d._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.#h&&!this.#g){this.#g=new AbortController;const s=this.#d.combinedSignal(this.#g);this.#h.div.addEventListener("pointerdown",i=>{const{clientX:o,clientY:a,timeStamp:d}=i,u=this.#p;if(d-u>500){this.#p=d;return}this.#p=-1;const{classList:m}=this.div;m.toggle("getElements",!0);const g=document.elementsFromPoint(o,a);if(m.toggle("getElements",!1),!this.div.contains(g[0]))return;let w;const b=new RegExp(`^${Eo}[0-9]+$`);for(const y of g)if(b.test(y.id)){w=y.id;break}if(!w)return;const I=this.#n.get(w);I?.annotationElementId===null&&(i.stopPropagation(),i.preventDefault(),I.dblclick(i))},{signal:s,capture:!0})}const e=this.#i;if(e){const s=new Map,i=new Map;for(const o of this.#A){if(o.disableEditing(),!o.annotationElementId){o.updateFakeAnnotationElement(e);continue}if(o.serialize()!==null){s.set(o.annotationElementId,o);continue}else i.set(o.annotationElementId,o);this.getEditableAnnotation(o.annotationElementId)?.show(),o.remove()}const n=e.getEditableAnnotations();for(const o of n){const{id:a}=o.data;if(this.#d.isDeletedAnnotationElement(a)){o.updateEdited({deleted:!0});continue}let d=i.get(a);if(d){d.resetAnnotationElement(o),d.show(!1),o.show();continue}d=s.get(a),d&&(this.#d.addChangedExistingAnnotation(d),d.renderAnnotationElement(o)&&d.show(!1)),o.show()}}this.#b(),this.isEmpty&&(this.div.hidden=!0);const{classList:t}=this.div;for(const s of Oi.#m.values())t.remove(`${s._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),this.#a=!1}getEditableAnnotation(e){return this.#i?.getEditableAnnotation(e)||null}setActiveEditor(e){this.#d.getActive()!==e&&this.#d.setActiveEditor(e)}enableTextSelection(){if(this.div.tabIndex=-1,this.#h?.div&&!this.#u){this.#u=new AbortController;const e=this.#d.combinedSignal(this.#u);this.#h.div.addEventListener("pointerdown",this.#w.bind(this),{signal:e}),this.#h.div.classList.add("highlighting")}}disableTextSelection(){this.div.tabIndex=0,this.#h?.div&&this.#u&&(this.#u.abort(),this.#u=null,this.#h.div.classList.remove("highlighting"))}#w(e){this.#d.unselectAll();const{target:t}=e;if(t===this.#h.div||(t.getAttribute("role")==="img"||t.classList.contains("endOfContent"))&&this.#h.div.contains(t)){const{isMac:s}=ys.platform;if(e.button!==0||e.ctrlKey&&s)return;this.#d.showAllEditors("highlight",!0,!0),this.#h.div.classList.add("free"),this.toggleDrawing(),ds.startHighlighting(this,this.#d.direction==="ltr",{target:this.#h.div,x:e.x,y:e.y}),this.#h.div.addEventListener("pointerup",()=>{this.#h.div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:this.#d._signal}),e.preventDefault()}}enableClick(){if(this.#s)return;this.#s=new AbortController;const e=this.#d.combinedSignal(this.#s);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.#s?.abort(),this.#s=null}attach(e){this.#n.set(e.id,e);const{annotationElementId:t}=e;t&&this.#d.isDeletedAnnotationElement(t)&&this.#d.removeDeletedAnnotationElement(e)}detach(e){this.#n.delete(e.id),this.#e?.removePointerInTextLayer(e.contentDiv),!this.#a&&e.annotationElementId&&this.#d.addDeletedAnnotationElement(e)}remove(e){this.detach(e),this.#d.removeEditor(e),e.div.remove(),e.isAttachedToDOM=!1}changeParent(e){e.parent!==this&&(e.parent&&e.annotationElementId&&(this.#d.addDeletedAnnotationElement(e.annotationElementId),_e.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.#d.addEditor(e),this.attach(e),!e.isAttachedToDOM){const t=e.render();this.div.append(t),e.isAttachedToDOM=!0}e.fixAndSetPosition(),e.onceAdded(!this.#c),this.#d.addToAnnotationStorage(e),e._reportTelemetry(e.telemetryInitialData)}}moveEditorInDOM(e){if(!e.isAttachedToDOM)return;const{activeElement:t}=document;e.div.contains(t)&&!this.#o&&(e._focusEventsAllowed=!1,this.#o=setTimeout(()=>{this.#o=null,e.div.contains(document.activeElement)?e._focusEventsAllowed=!0:(e.div.addEventListener("focusin",()=>{e._focusEventsAllowed=!0},{once:!0,signal:this.#d._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),s=()=>{e.remove()};this.addCommands({cmd:t,undo:s,mustExec:!1})}getEditorByUID(e){for(const t of this.#n.values())if(t.uid===e)return t;return null}getNextId(){return this.#d.getId()}get#x(){return Oi.#m.get(this.#d.getMode())}combinedSignal(e){return this.#d.combinedSignal(e)}#E(e){const t=this.#x;return t?new t.prototype.constructor(e):null}canCreateNewEmptyEditor(){return this.#x?.canCreateNewEmptyEditor()}async pasteEditor(e,t){this.updateToolbar(e),await this.#d.updateMode(e.mode);const{offsetX:s,offsetY:i}=this.#v(),n=this.getNextId(),o=this.#E({parent:this,id:n,x:s,y:i,uiManager:this.#d,isCentered:!0,...t});o&&this.add(o)}async deserialize(e){return await Oi.#m.get(e.annotationType??e.annotationEditorType)?.deserialize(e,this,this.#d)||null}createAndAddNewEditor(e,t,s={}){const i=this.getNextId(),n=this.#E({parent:this,id:i,x:e.offsetX,y:e.offsetY,uiManager:this.#d,isCentered:t,...s});return n&&this.add(n),n}get boundingClientRect(){return this.div.getBoundingClientRect()}#v(){const{x:e,y:t,width:s,height:i}=this.boundingClientRect,n=Math.max(0,e),o=Math.max(0,t),a=Math.min(window.innerWidth,e+s),d=Math.min(window.innerHeight,t+i),u=(n+a)/2-e,m=(o+d)/2-t,[g,w]=this.viewport.rotation%180===0?[u,m]:[m,u];return{offsetX:g,offsetY:w}}addNewEditor(e={}){this.createAndAddNewEditor(this.#v(),!0,e)}setSelected(e){this.#d.setSelected(e)}toggleSelected(e){this.#d.toggleSelected(e)}unselect(e){this.#d.unselect(e)}pointerup(e){const{isMac:t}=ys.platform;if(e.button!==0||e.ctrlKey&&t||e.target!==this.div||!this.#r||(this.#r=!1,this.#x?.isDrawer&&this.#x.supportMultipleDrawings))return;if(!this.#t){this.#t=!0;return}const s=this.#d.getMode();if(s===at.STAMP||s===at.SIGNATURE){this.#d.unselectAll();return}this.createAndAddNewEditor(e,!1)}pointerdown(e){if(this.#d.getMode()===at.HIGHLIGHT&&this.enableTextSelection(),this.#r){this.#r=!1;return}const{isMac:t}=ys.platform;if(e.button!==0||e.ctrlKey&&t||e.target!==this.div)return;if(this.#r=!0,this.#x?.isDrawer){this.startDrawingSession(e);return}const s=this.#d.getActive();this.#t=!s||s.isEmpty()}startDrawingSession(e){if(this.div.focus({preventScroll:!0}),this.#l){this.#x.startDrawing(this,this.#d,!1,e);return}this.#d.setCurrentDrawingSession(this),this.#l=new AbortController;const t=this.#d.combinedSignal(this.#l);this.div.addEventListener("blur",({relatedTarget:s})=>{s&&!this.div.contains(s)&&(this.#f=null,this.commitOrRemove())},{signal:t}),this.#x.startDrawing(this,this.#d,!1,e)}pause(e){if(e){const{activeElement:t}=document;this.div.contains(t)&&(this.#f=t);return}this.#f&&setTimeout(()=>{this.#f?.focus(),this.#f=null},0)}endDrawingSession(e=!1){return this.#l?(this.#d.setCurrentDrawingSession(null),this.#l.abort(),this.#l=null,this.#f=null,this.#x.endDrawing(e)):null}findNewParent(e,t,s){const i=this.#d.findParent(t,s);return i===null||i===this?!1:(i.changeParent(e),!0)}commitOrRemove(){return this.#l?(this.endDrawingSession(),!0):!1}onScaleChanging(){this.#l&&this.#x.onScaleChangingWhenDrawing(this)}destroy(){this.commitOrRemove(),this.#d.getActive()?.parent===this&&(this.#d.commitOrRemove(),this.#d.setActiveEditor(null)),this.#o&&(clearTimeout(this.#o),this.#o=null);for(const e of this.#n.values())this.#e?.removePointerInTextLayer(e.contentDiv),e.setParent(null),e.isAttachedToDOM=!1,e.div.remove();this.div=null,this.#n.clear(),this.#d.removeLayer(this)}#b(){for(const e of this.#n.values())e.isEmpty()&&e.remove()}render({viewport:e}){this.viewport=e,pn(this.div,e);for(const t of this.#d.getEditors(this.pageIndex))this.add(t),t.rebuild();this.updateMode()}update({viewport:e}){this.#d.commitOrRemove(),this.#b();const t=this.viewport.rotation,s=e.rotation;if(this.viewport=e,pn(this.div,{rotation:s}),t!==s)for(const i of this.#n.values())i.rotate(s)}get pageDimensions(){const{pageWidth:e,pageHeight:t}=this.viewport.rawDims;return[e,t]}get scale(){return this.#d.viewParameters.realScale}}class bs{#e=null;#t=new Map;#i=new Map;static#s=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 mt(this,"_svgFactory",new Lo)}static#o(e,[t,s,i,n]){const{style:o}=e;o.top=`${100*s}%`,o.left=`${100*t}%`,o.width=`${100*i}%`,o.height=`${100*n}%`}#n(){const e=bs._svgFactory.create(1,1,!0);return this.#e.append(e),e.setAttribute("aria-hidden",!0),e}#r(e,t){const s=bs._svgFactory.createElement("clipPath");e.append(s);const i=`clip_${t}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=bs._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${t}`),n.classList.add("clip"),i}#a(e,t){for(const[s,i]of Object.entries(t))i===null?e.removeAttribute(s):e.setAttribute(s,i)}draw(e,t=!1,s=!1){const i=bs.#s++,n=this.#n(),o=bs._svgFactory.createElement("defs");n.append(o);const a=bs._svgFactory.createElement("path");o.append(a);const d=`path_p${this.pageIndex}_${i}`;a.setAttribute("id",d),a.setAttribute("vector-effect","non-scaling-stroke"),t&&this.#i.set(i,a);const u=s?this.#r(o,d):null,m=bs._svgFactory.createElement("use");return n.append(m),m.setAttribute("href",`#${d}`),this.updateProperties(n,e),this.#t.set(i,n),{id:i,clipPathId:`url(#${u})`}}drawOutline(e,t){const s=bs.#s++,i=this.#n(),n=bs._svgFactory.createElement("defs");i.append(n);const o=bs._svgFactory.createElement("path");n.append(o);const a=`path_p${this.pageIndex}_${s}`;o.setAttribute("id",a),o.setAttribute("vector-effect","non-scaling-stroke");let d;if(t){const g=bs._svgFactory.createElement("mask");n.append(g),d=`mask_p${this.pageIndex}_${s}`,g.setAttribute("id",d),g.setAttribute("maskUnits","objectBoundingBox");const w=bs._svgFactory.createElement("rect");g.append(w),w.setAttribute("width","1"),w.setAttribute("height","1"),w.setAttribute("fill","white");const b=bs._svgFactory.createElement("use");g.append(b),b.setAttribute("href",`#${a}`),b.setAttribute("stroke","none"),b.setAttribute("fill","black"),b.setAttribute("fill-rule","nonzero"),b.classList.add("mask")}const u=bs._svgFactory.createElement("use");i.append(u),u.setAttribute("href",`#${a}`),d&&u.setAttribute("mask",`url(#${d})`);const m=u.cloneNode();return i.append(m),u.classList.add("mainOutline"),m.classList.add("secondaryOutline"),this.updateProperties(i,e),this.#t.set(s,i),s}finalizeDraw(e,t){this.#i.delete(e),this.updateProperties(e,t)}updateProperties(e,t){if(!t)return;const{root:s,bbox:i,rootClass:n,path:o}=t,a=typeof e=="number"?this.#t.get(e):e;if(a){if(s&&this.#a(a,s),i&&bs.#o(a,i),n){const{classList:d}=a;for(const[u,m]of Object.entries(n))d.toggle(u,m)}if(o){const u=a.firstChild.firstChild;this.#a(u,o)}}}updateParent(e,t){if(t===this)return;const s=this.#t.get(e);s&&(t.#e.append(s),this.#t.delete(e),t.#t.set(e,s))}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:Ic};globalThis.pdfjsLib={AbortException:sn,AnnotationEditorLayer:Oi,AnnotationEditorParamsType:Mt,AnnotationEditorType:at,AnnotationEditorUIManager:nn,AnnotationLayer:qc,AnnotationMode:Fi,AnnotationType:cs,applyOpacity:fu,build:ku,ColorPicker:si,createValidAbsoluteUrl:Nc,CSSConstants:hu,DOMSVGFactory:Lo,DrawLayer:bs,FeatureTest:ys,fetchData:Dr,findContrastColor:uu,getDocument:Qc,getFilenameFromUrl:lu,getPdfFilenameFromUrl:cu,getRGB:Lr,getUuid:Tc,getXfaPageViewport:du,GlobalWorkerOptions:un,ImageKind:yo,InvalidPDFException:Ka,isDataScheme:Po,isPdfFile:dl,isValidExplicitDest:Au,MathClamp:js,noContextMenu:ri,normalizeUnicode:ou,OPS:Mr,OutputScale:Mi,PasswordResponses:nu,PDFDataRangeTransport:Jc,PDFDateString:_a,PDFWorker:Sr,PermissionFlag:iu,PixelsPerInch:Xn,RenderingCancelledException:cl,renderRichText:Oc,ResponseException:Mo,setLayerDimensions:pn,shadow:mt,SignatureExtractor:Un,stopEvent:rs,SupportedImageMimeTypes:$a,TextLayer:jo,TouchManager:Fo,updateUrlHash:kc,Util:He,VerbosityLevel:ko,version:Xc,XfaLayer:Pc};const T2=Object.freeze(Object.defineProperty({__proto__:null,AbortException:sn,AnnotationEditorLayer:Oi,AnnotationEditorParamsType:Mt,AnnotationEditorType:at,AnnotationEditorUIManager:nn,AnnotationLayer:qc,AnnotationMode:Fi,AnnotationType:cs,CSSConstants:hu,ColorPicker:si,DOMSVGFactory:Lo,DrawLayer:bs,FeatureTest:ys,GlobalWorkerOptions:un,ImageKind:yo,InvalidPDFException:Ka,MathClamp:js,OPS:Mr,OutputScale:Mi,PDFDataRangeTransport:Jc,PDFDateString:_a,PDFWorker:Sr,PasswordResponses:nu,PermissionFlag:iu,PixelsPerInch:Xn,RenderingCancelledException:cl,ResponseException:Mo,SignatureExtractor:Un,SupportedImageMimeTypes:$a,TextLayer:jo,TouchManager:Fo,Util:He,VerbosityLevel:ko,XfaLayer:Pc,applyOpacity:fu,build:ku,createValidAbsoluteUrl:Nc,fetchData:Dr,findContrastColor:uu,getDocument:Qc,getFilenameFromUrl:lu,getPdfFilenameFromUrl:cu,getRGB:Lr,getUuid:Tc,getXfaPageViewport:du,isDataScheme:Po,isPdfFile:dl,isValidExplicitDest:Au,noContextMenu:ri,normalizeUnicode:ou,renderRichText:Oc,setLayerDimensions:pn,shadow:mt,stopEvent:rs,updateUrlHash:kc,version:Xc},Symbol.toStringTag,{value:"Module"}));function Hu(c){var e,t,s="";if(typeof c=="string"||typeof c=="number")s+=c;else if(typeof c=="object")if(Array.isArray(c)){var i=c.length;for(e=0;e<i;e++)c[e]&&(t=Hu(c[e]))&&(s&&(s+=" "),s+=t)}else for(t in c)c[t]&&(s&&(s+=" "),s+=t);return s}function ul(){for(var c,e,t=0,s="",i=arguments.length;t<i;t++)(c=arguments[t])&&(e=Hu(c))&&(s&&(s+=" "),s+=e);return s}var Lf=Object.prototype.hasOwnProperty;function Nf(c,e,t){for(t of c.keys())if(yr(t,e))return t}function yr(c,e){var t,s,i;if(c===e)return!0;if(c&&e&&(t=c.constructor)===e.constructor){if(t===Date)return c.getTime()===e.getTime();if(t===RegExp)return c.toString()===e.toString();if(t===Array){if((s=c.length)===e.length)for(;s--&&yr(c[s],e[s]););return s===-1}if(t===Set){if(c.size!==e.size)return!1;for(s of c)if(i=s,i&&typeof i=="object"&&(i=Nf(e,i),!i)||!e.has(i))return!1;return!0}if(t===Map){if(c.size!==e.size)return!1;for(s of c)if(i=s[0],i&&typeof i=="object"&&(i=Nf(e,i),!i)||!yr(s[1],e.get(i)))return!1;return!0}if(t===ArrayBuffer)c=new Uint8Array(c),e=new Uint8Array(e);else if(t===DataView){if((s=c.byteLength)===e.byteLength)for(;s--&&c.getInt8(s)===e.getInt8(s););return s===-1}if(ArrayBuffer.isView(c)){if((s=c.byteLength)===e.byteLength)for(;s--&&c[s]===e[s];);return s===-1}if(!t||typeof c=="object"){s=0;for(t in c)if(Lf.call(c,t)&&++s&&!Lf.call(e,t)||!(t in e)||!yr(c[t],e[t]))return!1;return Object.keys(e).length===s}}return c!==c&&e!==e}function Uo(c){let e=!1;return{promise:new Promise((s,i)=>{c.then(n=>!e&&s(n)).catch(n=>!e&&i(n))}),cancel(){e=!0}}}const B2=["onCopy","onCut","onPaste"],P2=["onCompositionEnd","onCompositionStart","onCompositionUpdate"],O2=["onFocus","onBlur"],F2=["onInput","onInvalid","onReset","onSubmit"],R2=["onLoad","onError"],z2=["onKeyDown","onKeyPress","onKeyUp"],U2=["onAbort","onCanPlay","onCanPlayThrough","onDurationChange","onEmptied","onEncrypted","onEnded","onError","onLoadedData","onLoadedMetadata","onLoadStart","onPause","onPlay","onPlaying","onProgress","onRateChange","onSeeked","onSeeking","onStalled","onSuspend","onTimeUpdate","onVolumeChange","onWaiting"],H2=["onClick","onContextMenu","onDoubleClick","onMouseDown","onMouseEnter","onMouseLeave","onMouseMove","onMouseOut","onMouseOver","onMouseUp"],Y2=["onDrag","onDragEnd","onDragEnter","onDragExit","onDragLeave","onDragOver","onDragStart","onDrop"],Q2=["onSelect"],W2=["onTouchCancel","onTouchEnd","onTouchMove","onTouchStart"],J2=["onPointerDown","onPointerMove","onPointerUp","onPointerCancel","onGotPointerCapture","onLostPointerCapture","onPointerEnter","onPointerLeave","onPointerOver","onPointerOut"],X2=["onScroll"],G2=["onWheel"],V2=["onAnimationStart","onAnimationEnd","onAnimationIteration"],q2=["onTransitionEnd"],Z2=["onToggle"],K2=["onChange"],_2=[...B2,...P2,...O2,...F2,...R2,...z2,...U2,...H2,...Y2,...Q2,...W2,...J2,...X2,...G2,...V2,...q2,...K2,...Z2];function Yu(c,e){const t={};for(const s of _2){const i=c[s];i&&(e?t[s]=(n=>i(n,e(s))):t[s]=i)}return t}var $2=process.env.NODE_ENV==="production",uc="Invariant failed";function Wt(c,e){if(!c){if($2)throw new Error(uc);var t=typeof e=="function"?e():e,s=t?"".concat(uc,": ").concat(t):uc;throw new Error(s)}}var pc,kf;function ew(){if(kf)return pc;kf=1;var c=process.env.NODE_ENV!=="production",e=function(){};if(c){var t=function(i,n){var o=arguments.length;n=new Array(o>1?o-1:0);for(var a=1;a<o;a++)n[a-1]=arguments[a];var d=0,u="Warning: "+i.replace(/%s/g,function(){return n[d++]});typeof console<"u"&&console.error(u);try{throw new Error(u)}catch{}};e=function(s,i,n){var o=arguments.length;n=new Array(o>2?o-2:0);for(var a=2;a<o;a++)n[a-2]=arguments[a];if(i===void 0)throw new Error("`warning(condition, format, ...args)` requires a warning message argument");s||t.apply(null,[i].concat(n))}}return pc=e,pc}var tw=ew();const Ds=Wf(tw),Qu=k.createContext(null),sw="noopener noreferrer nofollow";class iw{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 Wt(this.pdfViewer,"PDF viewer is not initialized."),this.pdfViewer.currentPageNumber||0}set page(e){Wt(this.pdfViewer,"PDF viewer is not initialized."),this.pdfViewer.currentPageNumber=e}get rotation(){return 0}set rotation(e){}addLinkAttributes(e,t,s){e.href=t,e.rel=this.externalLinkRel||sw,e.target=s?"_blank":this.externalLinkTarget||""}goToDestination(e){return new Promise(t=>{Wt(this.pdfDocument,"PDF document not loaded."),Wt(e,"Destination is not specified."),typeof e=="string"?this.pdfDocument.getDestination(e).then(t):Array.isArray(e)?t(e):e.then(t)}).then(t=>{Wt(Array.isArray(t),`"${t}" is not a valid destination array.`);const s=t[0];new Promise(i=>{Wt(this.pdfDocument,"PDF document not loaded."),s instanceof Object?this.pdfDocument.getPageIndex(s).then(n=>{i(n)}).catch(()=>{Wt(!1,`"${s}" is not a valid page reference.`)}):typeof s=="number"?i(s):Wt(!1,`"${s}" is not a valid destination reference.`)}).then(i=>{const n=i+1;Wt(this.pdfViewer,"PDF viewer is not initialized."),Wt(n>=1&&n<=this.pagesCount,`"${n}" is not a valid page number.`),this.pdfViewer.scrollPageIntoView({dest:t,pageIndex:i,pageNumber:n})})})}goToPage(e){const t=e-1;Wt(this.pdfViewer,"PDF viewer is not initialized."),Wt(e>=1&&e<=this.pagesCount,`"${e}" is not a valid page number.`),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 Cr({children:c,type:e}){return r.jsx("div",{className:`react-pdf__message react-pdf__message--${e}`,children:c})}const Tf={NEED_PASSWORD:1,INCORRECT_PASSWORD:2};function nw(c,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 c}}function jr(){return k.useReducer(nw,{value:void 0,error:void 0})}const pl=typeof window<"u",Wu=pl&&window.location.protocol==="file:";function rw(c){return typeof c<"u"}function zn(c){return rw(c)&&c!==null}function ow(c){return typeof c=="string"}function aw(c){return c instanceof ArrayBuffer}function lw(c){return Wt(pl,"isBlob can only be used in a browser environment"),c instanceof Blob}function Sc(c){return ow(c)&&/^data:/.test(c)}function Bf(c){Wt(Sc(c),"Invalid data URI.");const[e="",t=""]=c.split(",");return e.split(";").indexOf("base64")!==-1?atob(t):unescape(t)}function cw(){return pl&&window.devicePixelRatio||1}const Ju="On Chromium based browsers, you can use --allow-file-access-from-files flag for debugging purposes.";function Pf(){Ds(!Wu,`Loading PDF as base64 strings/URLs may not work on protocols other than HTTP/HTTPS. ${Ju}`)}function dw(){Ds(!Wu,`Loading PDF.js worker may not work on protocols other than HTTP/HTTPS. ${Ju}`)}function Vn(c){c?.cancel&&c.cancel()}function jc(c,e){return Object.defineProperty(c,"width",{get(){return this.getViewport({scale:e}).width},configurable:!0}),Object.defineProperty(c,"height",{get(){return this.getViewport({scale:e}).height},configurable:!0}),Object.defineProperty(c,"originalWidth",{get(){return this.getViewport({scale:1}).width},configurable:!0}),Object.defineProperty(c,"originalHeight",{get(){return this.getViewport({scale:1}).height},configurable:!0}),c}function Xu(c){return c.name==="AbortException"||c.name==="RenderingCancelledException"}function hw(c){return new Promise((e,t)=>{const s=new FileReader;s.onload=()=>{if(!s.result)return t(new Error("Error while reading a file."));e(s.result)},s.onerror=i=>{if(!i.target)return t(new Error("Error while reading a file."));const{error:n}=i.target;if(!n)return t(new Error("Error while reading a file."));switch(n.code){case n.NOT_FOUND_ERR:return t(new Error("Error while reading a file: File not found."));case n.SECURITY_ERR:return t(new Error("Error while reading a file: Security error."));case n.ABORT_ERR:return t(new Error("Error while reading a file: Aborted."));default:return t(new Error("Error while reading a file."))}},s.readAsArrayBuffer(c)})}const{PDFDataRangeTransport:fw}=T2,uw=(c,e)=>{switch(e){case Tf.NEED_PASSWORD:{const t=prompt("Enter the password to open this PDF file.");c(t);break}case Tf.INCORRECT_PASSWORD:{const t=prompt("Invalid password. Please try again.");c(t);break}}};function Of(c){return typeof c=="object"&&c!==null&&("data"in c||"range"in c||"url"in c)}const pw=k.forwardRef(function({children:e,className:t,error:s="Failed to load PDF file.",externalLinkRel:i,externalLinkTarget:n,file:o,inputRef:a,imageResourcesPath:d,loading:u="Loading PDF…",noData:m="No PDF file specified.",onItemClick:g,onLoadError:w,onLoadProgress:b,onLoadSuccess:I,onPassword:y=uw,onSourceError:j,onSourceSuccess:L,options:O,renderMode:R,rotate:F,scale:U,...V},Q){const[K,Z]=jr(),{value:$,error:se}=K,[le,pe]=jr(),{value:oe,error:he}=le,ne=k.useRef(new iw),re=k.useRef([]),fe=k.useRef(void 0),we=k.useRef(void 0);o&&o!==fe.current&&Of(o)&&(Ds(!yr(o,fe.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.`),fe.current=o),O&&O!==we.current&&(Ds(!yr(O,we.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.`),we.current=O);const xe=k.useRef({scrollPageIntoView:Be=>{const{dest:ze,pageNumber:te,pageIndex:ue=te-1}=Be;if(g){g({dest:ze,pageIndex:ue,pageNumber:te});return}const je=re.current[ue];if(je){je.scrollIntoView();return}Ds(!1,`An internal link leading to page ${te} 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>.`)}});k.useImperativeHandle(Q,()=>({linkService:ne,pages:re,viewer:xe}),[]);function Te(){L&&L()}function Ne(){se&&(Ds(!1,se.toString()),j&&j(se))}function De(){Z({type:"RESET"})}k.useEffect(De,[o,Z]);const Je=k.useCallback(async()=>{if(!o)return null;if(typeof o=="string")return Sc(o)?{data:Bf(o)}:(Pf(),{url:o});if(o instanceof fw)return{range:o};if(aw(o))return{data:o};if(pl&&lw(o))return{data:await hw(o)};if(Wt(typeof o=="object","Invalid parameter in file, need either Uint8Array, string or a parameter object"),Wt(Of(o),"Invalid parameter object: need either .data, .range or .url"),"url"in o&&typeof o.url=="string"){if(Sc(o.url)){const{url:Be,...ze}=o;return{data:Bf(Be),...ze}}Pf()}return o},[o]);k.useEffect(()=>{const Be=Uo(Je());return Be.promise.then(ze=>{Z({type:"RESOLVE",value:ze})}).catch(ze=>{Z({type:"REJECT",error:ze})}),()=>{Vn(Be)}},[Je,Z]),k.useEffect(()=>{if(!(typeof $>"u")){if($===!1){Ne();return}Te()}},[$]);function ke(){oe&&(I&&I(oe),re.current=new Array(oe.numPages),ne.current.setDocument(oe))}function Re(){he&&(Ds(!1,he.toString()),w&&w(he))}k.useEffect(function(){pe({type:"RESET"})},[pe,$]),k.useEffect(function(){if(!$)return;const ze=O?{...$,...O}:$,te=Qc(ze);b&&(te.onProgress=b),y&&(te.onPassword=y);const ue=te;return ue.promise.then(je=>{ue.destroyed||pe({type:"RESOLVE",value:je})}).catch(je=>{ue.destroyed||pe({type:"REJECT",error:je})}),()=>{ue.destroy()}},[O,pe,$]),k.useEffect(()=>{if(!(typeof oe>"u")){if(oe===!1){Re();return}ke()}},[oe]),k.useEffect(function(){ne.current.setViewer(xe.current),ne.current.setExternalLinkRel(i),ne.current.setExternalLinkTarget(n)},[i,n]);const de=k.useCallback((Be,ze)=>{re.current[Be]=ze},[]),Ee=k.useCallback(Be=>{delete re.current[Be]},[]),Ge=k.useMemo(()=>({imageResourcesPath:d,linkService:ne.current,onItemClick:g,pdf:oe,registerPage:de,renderMode:R,rotate:F,scale:U,unregisterPage:Ee}),[d,g,oe,de,R,F,U,Ee]),Ye=k.useMemo(()=>Yu(V,()=>oe),[V,oe]);function Qe(){function Be(te){return!!te?.pdf}if(!Be(Ge))throw new Error("pdf is undefined");const ze=typeof e=="function"?e(Ge):e;return r.jsx(Qu.Provider,{value:Ge,children:ze})}function Se(){return o?oe==null?r.jsx(Cr,{type:"loading",children:typeof u=="function"?u():u}):oe===!1?r.jsx(Cr,{type:"error",children:typeof s=="function"?s():s}):Qe():r.jsx(Cr,{type:"no-data",children:typeof m=="function"?m():m})}return r.jsx("div",{className:ul("react-pdf__Document",t),ref:a,...Ye,children:Se()})});function Gu(){return k.useContext(Qu)}function Vu(){for(var c=[],e=0;e<arguments.length;e++)c[e]=arguments[e];var t=c.filter(Boolean);if(t.length<=1){var s=t[0];return s||null}return function(n){for(var o=0,a=t;o<a.length;o++){var d=a[o];typeof d=="function"?d(n):d&&(d.current=n)}}}const qu=k.createContext(null);function ml(){return k.useContext(qu)}function mw(){const c=Gu(),e=ml();Wt(e,"Unable to find Page context.");const t={...c,...e},{filterAnnotations:s,imageResourcesPath:i,linkService:n,onGetAnnotationsError:o,onGetAnnotationsSuccess:a,onRenderAnnotationLayerError:d,onRenderAnnotationLayerSuccess:u,page:m,pdf:g,renderForms:w,rotate:b,scale:I=1}=t;Wt(g,"Attempted to load page annotations, but no document was specified. Wrap <Page /> in a <Document /> or pass explicit `pdf` prop."),Wt(m,"Attempted to load page annotations, but no page was specified."),Wt(n,"Attempted to load page annotations, but no linkService was specified.");const[y,j]=jr(),{value:L,error:O}=y,R=k.useRef(null);Ds(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 F(){L&&a&&a(L)}function U(){O&&(Ds(!1,O.toString()),o&&o(O))}k.useEffect(function(){j({type:"RESET"})},[j,m]),k.useEffect(function(){if(!m)return;const $=Uo(m.getAnnotations()),se=$;return $.promise.then(le=>{j({type:"RESOLVE",value:le})}).catch(le=>{j({type:"REJECT",error:le})}),()=>{Vn(se)}},[j,m]),k.useEffect(()=>{if(L!==void 0){if(L===!1){U();return}F()}},[L]);function V(){u&&u()}function Q(Z){Ds(!1,`${Z}`),d&&d(Z)}const K=k.useMemo(()=>m.getViewport({scale:I,rotation:b}),[m,b,I]);return k.useEffect(function(){if(!g||!m||!n||!L)return;const{current:$}=R;if(!$)return;const se=K.clone({dontFlip:!0}),le={accessibilityManager:null,annotationCanvasMap:null,annotationEditorUIManager:null,annotationStorage:g.annotationStorage,commentManager:null,div:$,l10n:null,linkService:n,page:m,structTreeLayer:null,viewport:se},pe={annotations:s?s({annotations:L}):L,annotationStorage:g.annotationStorage,div:$,imageResourcesPath:i,linkService:n,page:m,renderForms:w,viewport:se};$.innerHTML="";try{new qc(le).render(pe),V()}catch(oe){Q(oe)}return()=>{}},[L,s,i,n,m,g,w,K]),r.jsx("div",{className:ul("react-pdf__Page__annotations","annotationLayer"),ref:R})}const Zu={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},gw=/^H(\d+)$/;function Aw(c){return c in Zu}function gl(c){return"children"in c}function Ku(c){return gl(c)?c.children.length===1&&0 in c.children&&"id"in c.children[0]:!1}function xw(c){const e={};if(gl(c)){const{role:t}=c,s=t.match(gw);if(s)e.role="heading",e["aria-level"]=Number(s[1]);else if(Aw(t)){const i=Zu[t];i&&(e.role=i)}}return e}function _u(c){const e={};if(gl(c)){if(c.alt!==void 0&&(e["aria-label"]=c.alt),c.lang!==void 0&&(e.lang=c.lang),Ku(c)){const[t]=c.children;if(t){const s=_u(t);return{...e,...s}}}}else"id"in c&&(e["aria-owns"]=c.id);return e}function ww(c){return c?{...xw(c),..._u(c)}:null}function $u({className:c,node:e}){const t=k.useMemo(()=>ww(e),[e]),s=k.useMemo(()=>!gl(e)||Ku(e)?null:e.children.map((i,n)=>r.jsx($u,{node:i},n)),[e]);return r.jsx("span",{className:c,...t,children:s})}function bw(){const c=ml();Wt(c,"Unable to find Page context.");const{onGetStructTreeError:e,onGetStructTreeSuccess:t}=c,[s,i]=jr(),{value:n,error:o}=s,{customTextRenderer:a,page:d}=c;function u(){n&&t&&t(n)}function m(){o&&(Ds(!1,o.toString()),e&&e(o))}return k.useEffect(function(){i({type:"RESET"})},[i,d]),k.useEffect(function(){if(a||!d)return;const w=Uo(d.getStructTree()),b=w;return w.promise.then(I=>{i({type:"RESOLVE",value:I})}).catch(I=>{i({type:"REJECT",error:I})}),()=>Vn(b)},[a,d,i]),k.useEffect(()=>{if(n!==void 0){if(n===!1){m();return}u()}},[n]),n?r.jsx($u,{className:"react-pdf__Page__structTree structTree",node:n}):null}const Ff=Fi;function yw(c){const e=ml();Wt(e,"Unable to find Page context.");const t={...e,...c},{_className:s,canvasBackground:i,devicePixelRatio:n=cw(),onRenderError:o,onRenderSuccess:a,page:d,renderForms:u,renderTextLayer:m,pageColors:g,rotate:w,scale:b}=t,{canvasRef:I}=c;Wt(d,"Attempted to render page canvas, but no page was specified.");const y=k.useRef(null);function j(){d&&a&&a(jc(d,b))}function L(U){Xu(U)||(Ds(!1,U.toString()),o&&o(U))}const O=k.useMemo(()=>d.getViewport({scale:b*n,rotation:w}),[n,d,w,b]),R=k.useMemo(()=>d.getViewport({scale:b,rotation:w}),[d,w,b]);k.useEffect(function(){if(!d)return;d.cleanup();const{current:V}=y;if(!V)return;V.width=O.width,V.height=O.height,V.style.width=`${Math.floor(R.width)}px`,V.style.height=`${Math.floor(R.height)}px`,V.style.visibility="hidden";const Q={annotationMode:u?Ff.ENABLE_FORMS:Ff.ENABLE,canvas:V,canvasContext:V.getContext("2d",{alpha:!1}),pageColors:g,viewport:O};i&&(Q.background=i);const K=d.render(Q),Z=K;return K.promise.then(()=>{V.style.visibility="",j()}).catch(L),()=>Vn(Z)},[i,d,g,u,O,R]);const F=k.useCallback(()=>{const{current:U}=y;U&&(U.width=0,U.height=0)},[]);return k.useEffect(()=>F,[F]),r.jsx("canvas",{className:`${s}__canvas`,dir:"ltr",ref:Vu(I,y),style:{display:"block",userSelect:"none"},children:m?r.jsx(bw,{}):null})}function Cw(c){return"str"in c}const vw=new Set(["base","embed","iframe","link","meta","object","script","style","template"]),Iw=new Set(["action","formaction","href","poster","src","xlink:href"]);function Ew(c){let e="";for(const t of c){const s=t.charCodeAt(0);s<=32||s===127||(e+=t.toLowerCase())}return e.startsWith("javascript:")||e.startsWith("vbscript:")}function Mw(c){return c.nodeType===Node.ELEMENT_NODE}function ep(c){return Mw(c)&&c instanceof HTMLElement}function Sw(c){return ep(c)&&vw.has(c.tagName.toLowerCase())}function jw(c){const e=document.createElement(c.tagName.toLowerCase());return Array.from(c.attributes).forEach(t=>{const s=t.name.toLowerCase();s.startsWith("on")||s==="srcdoc"||Iw.has(s)&&Ew(t.value)||e.setAttribute(t.name,t.value)}),Array.from(c.childNodes).forEach(t=>{e.append(tp(t))}),e}function tp(c){var e;return ep(c)&&!Sw(c)?jw(c):document.createTextNode((e=c.textContent)!==null&&e!==void 0?e:"")}function Dw(c,e){const t=document.createElement("template");t.innerHTML=e;const s=document.createDocumentFragment();Array.from(t.content.childNodes).forEach(i=>{s.append(tp(i))}),c.replaceChildren(s)}function Lw(){const c=ml();Wt(c,"Unable to find Page context.");const{customTextRenderer:e,onGetTextError:t,onGetTextSuccess:s,onRenderTextLayerError:i,onRenderTextLayerSuccess:n,page:o,pageIndex:a,pageNumber:d,rotate:u,scale:m}=c;Wt(o,"Attempted to load page text content, but no page was specified.");const[g,w]=jr(),{value:b,error:I}=g,y=k.useRef(null);Ds(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(){b&&s&&s(b)}function L(){I&&(Ds(!1,I.toString()),t&&t(I))}k.useEffect(function(){w({type:"RESET"})},[o,w]),k.useEffect(function(){if(!o)return;const K=Uo(o.getTextContent()),Z=K;return K.promise.then($=>{w({type:"RESOLVE",value:$})}).catch($=>{w({type:"REJECT",error:$})}),()=>Vn(Z)},[o,w]),k.useEffect(()=>{if(b!==void 0){if(b===!1){L();return}j()}},[b]);const O=k.useCallback(()=>{n&&n()},[n]),R=k.useCallback(Q=>{Xu(Q)||(Ds(!1,Q.toString()),i&&i(Q))},[i]);function F(){const Q=y.current;Q&&Q.classList.add("selecting")}function U(){const Q=y.current;Q&&Q.classList.remove("selecting")}const V=k.useMemo(()=>o.getViewport({scale:m,rotation:u}),[o,u,m]);return k.useLayoutEffect(function(){if(!o||!b)return;const{current:K}=y;if(!K)return;K.innerHTML="";const Z=o.streamTextContent({includeMarkedContent:!0}),$={container:K,textContentSource:Z,viewport:V},se=new jo($),le=se;return se.render().then(()=>{const pe=document.createElement("div");pe.className="endOfContent",K.append(pe);const oe=K.querySelectorAll('[role="presentation"]');if(e){let he=0;b.items.forEach((ne,re)=>{if(!Cw(ne))return;const fe=oe[he];if(!fe)return;const we=e({pageIndex:a,pageNumber:d,itemIndex:re,...ne});Dw(fe,we),he+=ne.str&&ne.hasEOL?2:1})}O()}).catch(R),()=>Vn(le)},[e,R,O,o,a,d,b,V]),r.jsx("div",{className:ul("react-pdf__Page__textContent","textLayer"),onMouseUp:U,onMouseDown:F,ref:y})}const Rf=1;function Nw(c){const t={...Gu(),...c},{_className:s="react-pdf__Page",_enableRegisterUnregisterPage:i=!0,canvasBackground:n,canvasRef:o,children:a,className:d,customRenderer:u,customTextRenderer:m,devicePixelRatio:g,error:w="Failed to load the page.",filterAnnotations:b,height:I,inputRef:y,loading:j="Loading page…",noData:L="No page specified.",onGetAnnotationsError:O,onGetAnnotationsSuccess:R,onGetStructTreeError:F,onGetStructTreeSuccess:U,onGetTextError:V,onGetTextSuccess:Q,onLoadError:K,onLoadSuccess:Z,onRenderAnnotationLayerError:$,onRenderAnnotationLayerSuccess:se,onRenderError:le,onRenderSuccess:pe,onRenderTextLayerError:oe,onRenderTextLayerSuccess:he,pageColors:ne,pageIndex:re,pageNumber:fe,pdf:we,registerPage:xe,renderAnnotationLayer:Te=!0,renderForms:Ne=!1,renderMode:De="canvas",renderTextLayer:Je=!0,rotate:ke,scale:Re=Rf,unregisterPage:de,width:Ee,...Ge}=t,[Ye,Qe]=jr(),{value:Se,error:Be}=Ye,ze=k.useRef(null);Wt(we,"Attempted to load a page, but no document was specified. Wrap <Page /> in a <Document /> or pass explicit `pdf` prop.");const te=zn(fe)?fe-1:re??null,ue=fe??(zn(re)?re+1:null),je=ke??(Se?Se.rotate:null),Pe=k.useMemo(()=>{if(!Se)return null;let It=1;const Lt=Re??Rf;if(Ee||I){const Et=Se.getViewport({scale:1,rotation:je});Ee?It=Ee/Et.width:I&&(It=I/Et.height)}return Lt*It},[I,Se,je,Re,Ee]);k.useEffect(function(){return()=>{zn(te)&&i&&de&&de(te)}},[i,we,te,de]);function Xe(){if(Z){if(!Se||!Pe)return;Z(jc(Se,Pe))}if(i&&xe){if(!zn(te)||!ze.current)return;xe(te,ze.current)}}function ot(){Be&&(Ds(!1,Be.toString()),K&&K(Be))}k.useEffect(function(){Qe({type:"RESET"})},[Qe,we,te]),k.useEffect(function(){if(!we||!ue)return;const Lt=Uo(we.getPage(ue)),Et=Lt;return Lt.promise.then(yt=>{Qe({type:"RESOLVE",value:yt})}).catch(yt=>{Qe({type:"REJECT",error:yt})}),()=>Vn(Et)},[Qe,we,ue]),k.useEffect(()=>{if(Se!==void 0){if(Se===!1){ot();return}Xe()}},[Se,Pe]);const ht=k.useMemo(()=>zn(te)&&ue&&zn(je)&&zn(Pe)?{_className:s,canvasBackground:n,customTextRenderer:m,devicePixelRatio:g,filterAnnotations:b,onGetAnnotationsError:O,onGetAnnotationsSuccess:R,onGetStructTreeError:F,onGetStructTreeSuccess:U,onGetTextError:V,onGetTextSuccess:Q,onRenderAnnotationLayerError:$,onRenderAnnotationLayerSuccess:se,onRenderError:le,onRenderSuccess:pe,onRenderTextLayerError:oe,onRenderTextLayerSuccess:he,page:Se,pageColors:ne,pageIndex:te,pageNumber:ue,renderForms:Ne,renderTextLayer:Je,rotate:je,scale:Pe}:null,[s,n,m,g,b,O,R,F,U,V,Q,$,se,le,pe,oe,he,Se,ne,te,ue,Ne,Je,je,Pe]),gt=k.useMemo(()=>Yu(Ge,()=>Se&&(Pe?jc(Se,Pe):void 0)),[Ge,Se,Pe]),xt=`${te}@${Pe}/${je}`;function ct(){switch(De){case"custom":return Wt(u,'renderMode was set to "custom", but no customRenderer was passed.'),r.jsx(u,{},`${xt}_custom`);case"none":return null;case"canvas":default:return r.jsx(yw,{canvasRef:o},`${xt}_canvas`)}}function wt(){return Je?r.jsx(Lw,{},`${xt}_text`):null}function vt(){return Te?r.jsx(mw,{},`${xt}_annotations`):null}function Oe(){function It(Et){return!!Et?.page}if(!It(ht))throw new Error("page is undefined");const Lt=typeof a=="function"?a(ht):a;return r.jsxs(qu.Provider,{value:ht,children:[ct(),wt(),vt(),Lt]})}function bt(){return ue?we===null||Se===void 0||Se===null?r.jsx(Cr,{type:"loading",children:typeof j=="function"?j():j}):we===!1||Se===!1?r.jsx(Cr,{type:"error",children:typeof w=="function"?w():w}):Oe():r.jsx(Cr,{type:"no-data",children:typeof L=="function"?L():L})}return r.jsx("div",{className:ul(s,d),"data-page-number":ue,ref:Vu(y,ze),style:{"--scale-round-x":"1px","--scale-round-y":"1px","--scale-factor":"1","--user-unit":`${Pe}`,"--total-scale-factor":"calc(var(--scale-factor) * var(--user-unit))",backgroundColor:n||"white",position:"relative",minWidth:"min-content",minHeight:"min-content"},...gt,children:bt()})}dw();un.workerSrc="pdf.worker.mjs";function pt(c){return Number(c??0).toLocaleString("en-IN",{minimumFractionDigits:2,maximumFractionDigits:2})}un.workerSrc=`https://unpkg.com/pdfjs-dist@${Xc}/build/pdf.worker.min.mjs`;const kw=({open:c,onClose:e,onPaymentCollected:t,selectedLenderIdx:s=-1,selectedLenderFiCode:i=null,selectedLenderTenureMappings:n=[],selectedLenderRepaymentOption:o=null,selectedLenderDisbursementAccount:a=null})=>{const{tenureMappings:d,payableValue:u,paymentType:m,paymentInvoice:g,invoices:w,chemistId:b,leadId:I,fiCode:y,typeOfApp:j,payerMobileNumber:L,salesmanId:O,distributorIdnum:R,distributorName:F,drawdownRepaymentOption:U,creditLimitData:V}=zs(),Q=n.length>0?n:d,[K,Z]=k.useState(-1),[$,se]=k.useState(s);k.useEffect(()=>{s!==-1&&se(s)},[s]);const[le,pe]=k.useState(!1),oe=()=>{e()},he=i||y,ne=he==="TRILLIONLOAN",re=new Date;re.setDate(re.getDate()+1);const[fe,we]=k.useState(ne?new Date:re),[xe,Te]=k.useState(["","","","","",""]),Ne=k.useRef([]),[De,Je]=k.useState(0),[ke,Re]=k.useState("idle"),[de,Ee]=k.useState(!1),[Ge,Ye]=k.useState(!1),[Qe,Se]=k.useState(""),[Be,ze]=k.useState(""),[te,ue]=k.useState(j==="FUNDLY_COLLECT_APP"||j==="FUNDLY_QR_COLLECT_APP"||j==="FUNDLY_QR_WEB"?"Collect":"Pay Now"),[je,Pe]=k.useState(!1),[Xe,ot]=k.useState(null),[ht,gt]=k.useState(null),[xt,ct]=k.useState(!1),[wt,vt]=k.useState(null),[Oe,bt]=k.useState([]),[It,Lt]=k.useState(!1),[Et,yt]=k.useState(0),At=k.useCallback(Fe=>{const Ke=Fe.getFullYear(),Bt=String(Fe.getMonth()+1).padStart(2,"0"),Zt=String(Fe.getDate()).padStart(2,"0");return`${Ke}-${Bt}-${Zt}`},[]),et=k.useCallback(async()=>{if(he!=="TRILLIONLOAN"){Pe(!1);return}Pe(!0);try{const Fe=tt(),Ke=i||y||"",Bt=o||U||"BULLET",Zt=new URLSearchParams({loanAmount:String(u),businessId:b||"",openedOnDate:At(fe||re),productType:"INSTACASH",tenureMagnitude:String(Q[K]?.tenureValue||""),tenureUnit:String(Q[K]?.tenureUnit||""),fiCode:Ke,repaymentOption:Bt,supplierId:R||""});m==="INVOICE_COLLECT"&&g?.length>0&&Zt.append("invoiceNumber",g.map(Vs=>Vs.invoiceId).join(","));const Ot=`${Jn()}/kfs/report?${Zt.toString()}`,Ft=await Ut.get(Ot,{headers:{accept:"application/json",Authorization:`Bearer ${Fe}`}});ot(Ft.data),gt(Ft.data?.documentId??null),ct(!1)}catch(Fe){console.error("[Fundly Pay] Error fetching KFS:",Fe),ot(null),gt(null),ct(!1)}finally{Pe(!1)}},[i,y,o,U,u,b,fe,K,Q,R,m,g,At]),Ce=k.useCallback(async()=>{if(he==="TRILLIONLOAN")try{const Fe=tt(),Ke=new URLSearchParams({businessId:b||"",intents:"DRAWDOWN_KFS_SIGN",fiCode:he||""}),Bt=`${Jn()}/consent?${Ke.toString()}`,Ot=(await Ut.get(Bt,{headers:{accept:"*/*","Content-Type":"application/json",Authorization:`Bearer ${Fe}`}})).data;if(bt(Array.isArray(Ot)?Ot:[]),Ot?.[0]?.consentMessage){let Ft=Ot[0].consentMessage;Ft=Ft.replace("{{lenderName}}",he||""),Ft=Ft.replace("Drawdown Request Letter",'<span class="kfs-link" style="color:#16558B;text-decoration:underline;cursor:pointer">Drawdown Request Letter</span>'),Ft=Ft.replace("Sanction Letter",'<span class="kfs-link" style="color:#16558B;text-decoration:underline;cursor:pointer">Sanction Letter</span>'),Ft=Ft.replace("Key Fact Statement",'<span class="kfs-link" style="color:#16558B;text-decoration:underline;cursor:pointer">Key Fact Statement</span>'),vt(Ft)}}catch(Fe){console.error("[Fundly Pay] Error fetching consent:",Fe),vt(null)}},[b]),qe=k.useCallback(async()=>{try{const Fe=tt(),Ke=`${Jn()}/consent`;await Ut.post(Ke,{businessId:b||"",intent:"DRAWDOWN_KFS_SIGN",consents:Oe.map(Bt=>({consentId:Bt.consentId,accepted:!0}))},{headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Bearer ${Fe}`}})}catch(Fe){console.error("[Fundly Pay] Error submitting consent:",Fe)}},[b,Oe]),We=k.useCallback(()=>{Xe&&Lt(!0)},[Xe]),dt=k.useMemo(()=>Xe?Xe.kfsDocumentBytes?`data:application/pdf;base64,${Xe.kfsDocumentBytes}`:Xe.kfsDocumentUrl||Xe.documentUrl||null:null,[Xe]),Nt=k.useRef(null);k.useEffect(()=>{const Fe=Nt.current;if(!Fe)return;const Ke=Bt=>{Bt.target.classList.contains("kfs-link")&&We()};return Fe.addEventListener("click",Ke),()=>Fe.removeEventListener("click",Ke)},[We,wt]);const Qt=async()=>{ze("");try{L&&F&&await IA(L,F)}catch(Fe){console.error("Error sending OTP:",Fe);const Ke=Fe,Bt=Ke?.response?.data?.errorMessage||Ke?.response?.data?.message||Ke?.message||"Failed to send OTP. Please try again.";ze(Bt),Re("resend"),Je(0)}},Si=async()=>{if(!navigator.onLine){Ye(!0),ue("Submit Again");return}if(Ye(!1),de)return;if(Ee(!0),!fe){console.error("[Fundly Pay] Payment date is required"),Ee(!1);return}const Fe=fe.toISOString(),Ke=Fe.split("T")[0],Bt=i||y,Zt={paymentMode:"FUNDLY_PAY",paymentDate:Fe,paymentType:m,distributorCode:R,...ht&&{documentId:ht},salesmanId:O,invoiceCount:g?.length||w?.length||0,loanDrawdownRequestDTO:{businessId:b||I,fiCode:Bt,requestedAmount:u,scheduledDate:Ke,tenure:Q[K]?.tenureValue||"",tenureUnit:Q[K]?.tenureUnit?.replace(/s$/i,"")||"",invoiceIds:j==="FUNDLY_MART"||j==="FUNDLY_TRADE"?[]:m==="INVOICE_COLLECT"?g?.map(Ot=>Ot.invoiceId)??[]:w??[],sourceSystem:j,paymentType:m}};b&&b.trim()!==""?Zt.chemistBusinessId=b:I&&I.trim()!==""&&(Zt.leadId=I),m==="INVOICE_COLLECT"?Zt.paymentInvoice=g:m==="DIRECT_COLLECT"&&(Zt.invoiceIds=w,Zt.paidAmount=u),(j==="FUNDLY_COLLECT_APP"||j==="FUNDLY_QR_COLLECT_APP"||j==="FUNDLY_QR_WEB"||j==="FUNDLY_TRADE")&&(Zt.loanDrawdownRequestDTO.mobileNumber=L,Zt.loanDrawdownRequestDTO.loanInitiateOtp=xe.join("")),L&&(Zt.payerMobileNumber=L),he==="TRILLIONLOAN"&&qe();try{const Ot=await on(Zt),Ft=Ot?.data||Ot;Ft&&!Ft.scheduleDate&&(Ft.scheduleDate=Ke),Ft&&Gt?.lastRepaymentDate&&(Ft.dueDate=Gt.lastRepaymentDate),t&&t(Ft)}catch(Ot){const Ft=Ot?.response?.data?.errorMessage||Ot?.response?.data?.errorDesc||Ot?.response?.data?.message||Ot?.message||"Payment failed. Please try again.";Se(Ft)}finally{Ee(!1)}},Us=(Fe,Ke)=>{if(!/^[0-9]?$/.test(Fe))return;const Bt=[...xe];Bt[Ke]=Fe,Te(Bt),Fe&&Ke<5&&Ne.current[Ke+1]?.focus()},Ls=(Fe,Ke)=>{Fe.key==="Backspace"&&!xe[Ke]&&Ke>0&&Ne.current[Ke-1]?.focus()},Kn=()=>{Re("countdown"),Je(30),Qt()};k.useEffect(()=>{if(ke==="countdown"&&De>0){const Fe=setInterval(()=>{Je(Ke=>Ke-1)},1e3);return()=>clearInterval(Fe)}else ke==="countdown"&&De===0&&(Re("resend"),Qt())},[De,ke]);const Xt=k.useMemo(()=>{if(ne&&je)return!0;const Fe=K!==-1,Ke=fe!==null,Bt=$!==-1||!V?.subLimits,Zt=ne?xt:!0;if(j==="FUNDLY_COLLECT_APP"||j==="FUNDLY_QR_COLLECT_APP"||j==="FUNDLY_QR_WEB"||j==="FUNDLY_TRADE"){const Ot=xe.every(Ft=>Ft!=="");return!(Fe&&Ot&&Ke&&Bt&&Zt)}return!(Fe&&Ke&&Bt&&Zt)},[K,$,xe,j,fe,V,xt,je]),[Gt,fi]=k.useState(null),[ui,Pt]=k.useState(!1),mn=async()=>{if(K===-1)return;const Fe=Q[K],Ke=i||y||"",Bt=o||U||"BULLET",Zt=a||"SUPPLIER";Pt(!0);try{const Ot=await OA({loanAmount:Number(u),businessId:b||"",openedOnDate:At(fe||re),productType:"INSTACASH",tenureMagnitude:Fe.tenureValue,tenureUnit:Fe.tenureUnit,fiCode:Ke,repaymentOption:Bt,disbursementAccount:Zt});fi(Ot)}catch(Ot){console.error("Error fetching EMI:",Ot),fi(null)}finally{Pt(!1)}};return k.useEffect(()=>{let Fe;return c&&K!==-1&&$!==-1&&(Fe=window.setTimeout(()=>{mn()},1e3)),()=>{clearTimeout(Fe)}},[K,$,fe]),k.useEffect(()=>{if(c){if(Z(0),ne)we(new Date),ct(!1);else{const Fe=new Date;Fe.setDate(Fe.getDate()+1),we(Fe)}Ce()}},[c,Ce]),k.useEffect(()=>{if(!c||he!=="TRILLIONLOAN")return;const Fe=window.setTimeout(()=>{et()},400);return()=>clearTimeout(Fe)},[K,fe,et]),k.useEffect(()=>{const Fe=()=>{c&&K!==-1&&(mn(),et())};return window.addEventListener("online",Fe),()=>{window.removeEventListener("online",Fe)}},[c,K,et]),r.jsxs(Gs,{open:c,onClose:oe,children:[r.jsxs("div",{style:{fontFamily:"Poppins"},className:"fp:w-full fp:px-4 fp:pt-6 fp:mb-12 ",children:[r.jsx("div",{className:"fp:w-full fp:flex fp:items-center fp:justify-end",children:r.jsx("img",{src:Le.closingCross,className:"fp:w-4 fp:h-4 fp:cursor-pointer",onClick:()=>pe(!0)})}),Qe&&r.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:[r.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:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),r.jsxs("div",{className:"fp:flex-1",children:[r.jsx("p",{className:"fp:text-[14px] fp:text-red-700 fp:font-medium",children:"Payment Failed"}),r.jsx("p",{className:"fp:text-[12px] fp:text-red-600 fp:mt-1",children:Qe})]}),r.jsx("button",{onClick:()=>Se(""),className:"fp:text-red-400 fp:hover:text-red-600",children:r.jsx("svg",{className:"fp:w-4 fp:h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M6 18L18 6M6 6l12 12"})})})]}),r.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:mt-4 fp:space-y-4",children:[r.jsx("div",{children:r.jsx(Io,{value:fe,onChange:Fe=>we(Fe),minDate:ne?void 0:re,label:"Select Payment Date",fullWidth:!0,disabled:ne})}),r.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:space-y-2 ",children:[r.jsx("span",{className:"fp:text-[15px] fp:font-medium fp:text-[#222222]",children:"Tenure"}),r.jsx("div",{className:"fp:w-full fp:flex fp:space-x-4 ",children:Q&&Q.length>0?Q.map((Fe,Ke)=>r.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 ${K===Ke?"fp:border-[#16558B] fp:bg-[#E6F0FA] fp:text-[#16558B]":"fp:border-[#D0D0D0] fp:text-gray-700 fp:bg-white"}`,onClick:()=>{Z(Ke)},children:[Fe.tenureValue," ",Fe.tenureUnit]},Ke)):r.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"})})]}),!ne&&r.jsxs("span",{className:"fp:text-[12px] fp:font-medium fp:text-green-600 fp:text-wrap",children:["₹",pt(u)," will be processed via Fundly Credit — a loan will be set up in retailer's account."]}),r.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:[r.jsxs("div",{className:"fp:flex fp:justify-between",children:[r.jsx("label",{className:"fp:text-gray-700",children:"Due date"}),r.jsx("label",{className:"fp:font-medium",children:Gt?.lastRepaymentDate?Ir(Gt.lastRepaymentDate):"—"})]}),r.jsxs("div",{className:"fp:flex fp:justify-between",children:[r.jsx("label",{className:"fp:text-gray-700",children:"ROI (Annualised)"}),r.jsx("label",{className:"fp:font-medium",children:Gt?.normalInterestRate!=null?`${Gt.normalInterestRate}%`:"—"})]}),r.jsxs("div",{className:"fp:flex fp:justify-between",children:[r.jsx("label",{className:"fp:text-gray-700",children:"Interest/₹ 10,000/day"}),r.jsx("label",{className:"fp:font-medium",children:Gt?.interestPerDay!=null?`₹${Gt.interestPerDay}`:"—"})]}),r.jsxs("div",{className:"fp:flex fp:justify-between",children:[r.jsx("label",{className:"fp:text-gray-700",children:"Penal Charges"}),r.jsx("label",{className:"fp:font-medium",children:Gt?.penalInterestRate!=null?`${Gt.penalInterestRate}% p.a`:"—"})]}),r.jsxs("div",{className:"fp:flex fp:justify-between",children:[r.jsx("label",{className:"fp:text-gray-700",children:"Processing Fee"}),r.jsx("label",{className:"fp:font-medium",children:Gt?.processingFeeExclGst!=null?`₹${Number(Gt.processingFeeExclGst).toLocaleString("en-IN")}`:"—"})]}),r.jsxs("div",{className:"fp:flex fp:justify-between",children:[r.jsx("label",{className:"fp:text-gray-700",children:"APR"}),r.jsx("label",{className:"fp:font-medium",children:Gt?.apr!=null?`${Gt.apr}%`:"—"})]}),r.jsxs("div",{className:"fp:flex fp:justify-between",children:[r.jsx("label",{className:"fp:text-gray-700",children:"Net Disbursed Amount"}),r.jsx("label",{className:"fp:font-medium",children:Gt?.creditedAmount!=null?`₹${Number(Gt.creditedAmount).toLocaleString("en-IN")}`:"—"})]})]}),(j==="FUNDLY_COLLECT_APP"||j==="FUNDLY_QR_COLLECT_APP"||j==="FUNDLY_QR_WEB"||j==="FUNDLY_TRADE")&&r.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:[r.jsx("label",{className:"fp:font-medium fp:text-[15px]",children:"Retailer Verification"}),r.jsxs("div",{className:"fp:w-full fp:flex fp:space-x-2 fp:justify-between",children:[r.jsx("div",{className:"fp:flex fp:border-2 fp:rounded-lg fp:px-1 fp:space-x-2 ",children:xe.map((Fe,Ke)=>r.jsx("input",{type:"text",value:Fe,maxLength:1,placeholder:"●",ref:Bt=>{Ne.current[Ke]=Bt},onChange:Bt=>Us(Bt.target.value,Ke),onKeyDown:Bt=>Ls(Bt,Ke),className:"fp:w-7 fp:h-8 fp:text-center fp:text-[16px] fp:outline-none"},Ke))}),r.jsxs("button",{onClick:Kn,disabled:ke==="countdown",className:`fp:text-white fp:text-[12px] fp:px-7 fp:rounded-lg ${ke==="resend"?"fp:bg-gray-500":"fp:bg-[#16558B]"}`,children:[ke==="idle"&&"Get OTP",ke==="countdown"&&`${De}s`,ke==="resend"&&"Resend"]})]}),Be?r.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:[r.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:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),r.jsx("p",{className:"fp:text-[11px] fp:text-red-700",children:Be})]}):r.jsxs("label",{className:"fp:text-[13px] fp:flex fp:text-center fp:items-center fp:text-[#16558B]",children:[r.jsx("img",{src:Le.info,className:"fp:w-4 fp:h-4 fp:mr-1"}),ke==="idle"?"OTP will be sent to the retailer for consent.":"An OTP has been sent to the retailer for consent."]})]}),wt&&r.jsx("div",{ref:Nt,className:"fp:text-[12px] fp:text-gray-600 fp:leading-relaxed fp:select-none",dangerouslySetInnerHTML:{__html:wt}}),ne&&r.jsxs("label",{className:"fp:flex fp:items-start fp:space-x-2 fp:cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:xt,onChange:Fe=>{const Ke=Fe.target.checked;ct(Ke),Ke&&We()},className:"fp:mt-0.5 fp:w-4 fp:h-4 fp:flex-shrink-0 fp:accent-[#16558B]"}),r.jsxs("span",{className:"fp:text-[12px] fp:text-gray-700",children:["I agree to the loan terms and accept the"," ",r.jsx("span",{className:"fp:text-[#16558B] fp:underline fp:cursor-pointer",onClick:Fe=>{Fe.preventDefault(),We()},children:"Key Fact Statement (KFS)"})]})]}),Ge&&r.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."}),r.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
|
|
620
620
|
${Xt||de?"fp:bg-gray-400 fp:text-white fp:cursor-not-allowed":"fp:bg-[#16558B] fp:text-white"}`,onClick:()=>{!Xt&&!de&&Si()},disabled:Xt||de,children:de?"Processing...":te})]})]}),It&&dt&&Bg.createPortal(r.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:()=>Lt(!1),children:r.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:Fe=>Fe.stopPropagation(),children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",borderBottom:"1px solid #E8EEF3",fontFamily:"Poppins",flexShrink:0},children:[r.jsx("span",{style:{fontSize:"16px",fontWeight:600,color:"#222",fontFamily:"Poppins"},children:"Key Fact Statement"}),r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[r.jsx("button",{onClick:()=>kt.shareByteImage(dt||"","KFS Document","KFS_Document"),style:{padding:"4px",display:"flex",alignItems:"center",justifyContent:"center",background:"none",border:"none",cursor:"pointer"},children:r.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:[r.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),r.jsx("polyline",{points:"7 10 12 15 17 10"}),r.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})}),r.jsx("button",{onClick:()=>Lt(!1),style:{padding:"4px",background:"none",border:"none",cursor:"pointer"},children:r.jsx("img",{src:Le.closingCross,style:{width:"20px",height:"20px"}})})]})]}),r.jsx("div",{style:{flex:1,overflowY:"auto",display:"flex",flexDirection:"column",alignItems:"center",backgroundColor:"#f5f5f5"},children:r.jsx(pw,{file:dt,onLoadSuccess:({numPages:Fe})=>yt(Fe),loading:r.jsx("div",{style:{padding:"20px",color:"#666",fontFamily:"Poppins"},children:"Loading..."}),error:r.jsx("div",{style:{padding:"20px",color:"red",fontFamily:"Poppins"},children:"Failed to load PDF."}),children:Array.from({length:Et},(Fe,Ke)=>r.jsx("div",{style:{marginBottom:"8px"},children:r.jsx(Nw,{pageNumber:Ke+1,width:typeof window<"u"?Math.min(window.innerWidth,500)-16:350,renderTextLayer:!1,renderAnnotationLayer:!1})},Ke+1))})})]})}),document.body),r.jsxs(Js,{open:le,onClose:()=>pe(!1),children:[r.jsx(Xs,{children:r.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:justify-center fp:items-center",children:[r.jsx("img",{src:Le.Gateway,className:"fp:w-15 fp:h-15"}),r.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?"})]})}),r.jsx(di,{children:r.jsxs("div",{className:"fp:w-full fp:flex fp:justify-between fp:px-3 fp:mb-3 fp:gap-3",children:[r.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:()=>{pe(!1),oe()},children:"Exit"}),r.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:()=>pe(!1),children:"Continue"})]})})]})]})},Tw=({open:c,onClose:e})=>{const{distributorName:t,chemistName:s,paymentType:i,paymentInvoice:n,invoices:o,payableValue:a,salesmanId:d,salesmanPhoneNumber:u,distributorIdnum:m,chemistId:g,leadId:w,payerMobileNumber:b}=zs(),I=()=>{e()},[y,j]=k.useState(""),[L,O]=k.useState(!1),[R,F]=k.useState(""),[U,V]=k.useState(!1),[Q,K]=k.useState(5),[Z,$]=k.useState(""),se=k.useRef(null),le=k.useRef(null);k.useEffect(()=>{c||(j(""),F(""),V(!1),K(5),se.current&&clearTimeout(se.current),le.current&&clearInterval(le.current))},[c]);const pe=()=>{K(5),se.current&&clearTimeout(se.current),le.current&&clearInterval(le.current);let we=5;le.current=setInterval(()=>{we--,K(we),we<=0&&le.current&&clearInterval(le.current)},1e3),se.current=setTimeout(async()=>{await kt.navigateHome()},5e3)},oe=async()=>{V(!0),F("");const we={paymentMode:"PAYMENT_LINK",paymentDate:new Date().toISOString(),paymentType:i,paidAmount:a,distributorCode:m,salesmanId:d,salesmanPhoneNumber:u?.trim()||void 0,invoiceCount:n?.length||o?.length||0,chemistName:s||void 0,distributorName:t||void 0,mobileNumber:b||void 0};g&&g.trim()!==""?we.chemistBusinessId=g:w&&w.trim()!==""&&(we.leadId=w),i==="INVOICE_COLLECT"?we.paymentInvoice=n:i==="DIRECT_COLLECT"&&(we.invoiceIds=o),b&&(we.payerMobileNumber=b);try{const xe=await on(we),Te=xe.data||xe;$(Te.chemistCode||""),Te?.link?(j(Te.link),F("")):(j(""),F("Failed to generate payment link. Please try again."),pe())}catch(xe){j("");const Te=xe?.response?.data?.errorResponse?.errorMessage||xe?.response?.data?.errorMessage||xe?.response?.data?.errorResponse?.errorDesc||xe?.response?.data?.errorDesc||xe?.response?.data?.message||xe?.message||"Failed to generate payment link. Please try again.";F(Te),pe()}finally{V(!1)}},[he,ne]=k.useState(!1),re=async()=>{if(y)try{await navigator.clipboard.writeText(y),ne(!0),setTimeout(()=>ne(!1),1500)}catch{}},fe=async()=>{if(y){const we=`Complete your payment:
|
|
621
621
|
|
|
622
622
|
Amount: ₹${Number(a).toLocaleString("en-IN")}
|