@mercoa/react 0.0.49-rc3 → 0.0.49-rc4
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/{empty-DuOnCl9f.mjs → empty-BrMR1Zjr.mjs} +2 -2
- package/dist/{empty-DuOnCl9f.mjs.map → empty-BrMR1Zjr.mjs.map} +1 -1
- package/dist/{index-DOZn9bLJ.mjs → index-C_-tXPYo.mjs} +6 -6
- package/dist/{index-DOZn9bLJ.mjs.map → index-C_-tXPYo.mjs.map} +1 -1
- package/dist/{index-AYLetci1.mjs → index-CiL9tBm-.mjs} +3 -3
- package/dist/{index-AYLetci1.mjs.map → index-CiL9tBm-.mjs.map} +1 -1
- package/dist/{index-DysMNBj5.mjs → index-teJ6gsxg.mjs} +4 -4
- package/dist/{index-DysMNBj5.mjs.map → index-teJ6gsxg.mjs.map} +1 -1
- package/dist/index.es.js +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/{url-DGeWpMvf.mjs → url-D2e1NnVe.mjs} +2 -2
- package/dist/{url-DGeWpMvf.mjs.map → url-D2e1NnVe.mjs.map} +1 -1
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -192,7 +192,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
192
192
|
`),position:g,pageIndex:y-1,rect:d.slice(0),rotation:h,id:p,deleted:!1}}const a=super.deserialize(r,n,o);return G(a,Gi,r.fontSize),G(a,Xa,Ze.makeHexColor(...r.color)),G(a,Xi,J(s=Tr,wO,_B).call(s,r.value)),a.annotationElementId=r.id||null,G(a,Og,i),a}serialize(r=!1){if(this.isEmpty())return null;if(this.deleted)return{pageIndex:this.pageIndex,id:this.annotationElementId,deleted:!0};const n=Tr._internalPadding*this.parentScale,o=this.getRect(n,n),i=lr._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:b(this,Xa)),a={annotationType:Vt.FREETEXT,color:i,fontSize:b(this,Gi),value:J(this,MA,TQ).call(this),pageIndex:this.pageIndex,rect:o,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return r?a:this.annotationElementId&&!J(this,SA,CQ).call(this,a)?null:(a.id=this.annotationElementId,a)}renderAnnotationElement(r){const n=super.renderAnnotationElement(r);if(this.deleted)return n;const{style:o}=n;o.fontSize=`calc(${b(this,Gi)}px * var(--scale-factor))`,o.color=b(this,Xa),n.replaceChildren();for(const a of b(this,Xi).split(`
|
|
193
193
|
`)){const s=document.createElement("div");s.append(a?document.createTextNode(a):document.createElement("br")),n.append(s)}const i=Tr._internalPadding*this.parentScale;return r.updateEdited({rect:this.getRect(i,i),popupContent:b(this,Xi)}),n}resetAnnotationElement(r){super.resetAnnotationElement(r),r.resetEdited()}};pO=new WeakMap,mO=new WeakMap,gO=new WeakMap,yO=new WeakMap,bO=new WeakMap,Xa=new WeakMap,Xi=new WeakMap,vO=new WeakMap,Gi=new WeakMap,Og=new WeakMap,OA=new WeakSet,SQ=function(r){const n=i=>{this.editorDiv.style.fontSize=`calc(${i}px * var(--scale-factor))`,this.translate(0,-(i-b(this,Gi))*this.parentScale),G(this,Gi,i),J(this,xg,xD).call(this)},o=b(this,Gi);this.addCommands({cmd:n.bind(this,r),undo:n.bind(this,o),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:mt.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})},xA=new WeakSet,EQ=function(r){const n=i=>{G(this,Xa,this.editorDiv.style.color=i)},o=b(this,Xa);this.addCommands({cmd:n.bind(this,r),undo:n.bind(this,o),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:mt.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})},jA=new WeakSet,PQ=function(){var n;const r=[];this.editorDiv.normalize();for(const o of this.editorDiv.childNodes)r.push(J(n=Tr,jg,jD).call(n,o));return r.join(`
|
|
194
194
|
`)},xg=new WeakSet,xD=function(){const[r,n]=this.parentDimensions;let o;if(this.isAttachedToDOM)o=this.div.getBoundingClientRect();else{const{currentLayer:i,div:a}=this,s=a.style.display,c=a.classList.contains("hidden");a.classList.remove("hidden"),a.style.display="hidden",i.div.append(this.div),o=a.getBoundingClientRect(),a.remove(),a.style.display=s,a.classList.toggle("hidden",c)}this.rotation%180===this.parentRotation%180?(this.width=o.width/r,this.height=o.height/n):(this.width=o.height/r,this.height=o.width/n),this.fixAndSetPosition()},jg=new WeakSet,jD=function(r){return(r.nodeType===Node.TEXT_NODE?r.nodeValue:r.innerText).replaceAll(YT,"")},Mg=new WeakSet,MD=function(){if(this.editorDiv.replaceChildren(),!!b(this,Xi))for(const r of b(this,Xi).split(`
|
|
195
|
-
`)){const n=document.createElement("div");n.append(r?document.createTextNode(r):document.createElement("br")),this.editorDiv.append(n)}},MA=new WeakSet,TQ=function(){return b(this,Xi).replaceAll(" "," ")},wO=new WeakSet,_B=function(r){return r.replaceAll(" "," ")},SA=new WeakSet,CQ=function(r){const{value:n,fontSize:o,color:i,pageIndex:a}=b(this,Og);return this._hasBeenMoved||r.value!==n||r.fontSize!==o||r.color.some((s,c)=>s!==i[c])||r.pageIndex!==a},I(Tr,jg),I(Tr,wO),Je(Tr,"_freeTextDefaultContent",""),Je(Tr,"_internalPadding",0),Je(Tr,"_defaultColor",null),Je(Tr,"_defaultFontSize",10),Je(Tr,"_type","freetext"),Je(Tr,"_editorType",Vt.FREETEXT);let KF=Tr;class HF{constructor(t,r=0,n=0,o=!0){I(this,EA);I(this,Sg);I(this,PA);I(this,TA);I(this,OO);I(this,_O,void 0);I(this,Du,[]);I(this,Ga,[]);let i=1/0,a=-1/0,s=1/0,c=-1/0;const d=10**-4;for(const{x:v,y:O,width:x,height:S}of t){const j=Math.floor((v-r)/d)*d,P=Math.ceil((v+x+r)/d)*d,D=Math.floor((O-r)/d)*d,M=Math.ceil((O+S+r)/d)*d,T=[j,D,M,!0],z=[P,D,M,!1];b(this,Du).push(T,z),i=Math.min(i,j),a=Math.max(a,P),s=Math.min(s,D),c=Math.max(c,M)}const h=a-i+2*n,p=c-s+2*n,m=i-n,g=s-n,y=b(this,Du).at(o?-1:-2),w=[y[0],y[2]];for(const v of b(this,Du)){const[O,x,S]=v;v[0]=(O-m)/h,v[1]=(x-g)/p,v[2]=(S-g)/p}G(this,_O,{x:m,y:g,width:h,height:p,lastPoint:w})}getOutlines(){b(this,Du).sort((r,n)=>r[0]-n[0]||r[1]-n[1]||r[2]-n[2]);const t=[];for(const r of b(this,Du))r[3]?(t.push(...J(this,OO,OB).call(this,r)),J(this,PA,DQ).call(this,r)):(J(this,TA,zQ).call(this,r),t.push(...J(this,OO,OB).call(this,r)));return J(this,EA,AQ).call(this,t)}}_O=new WeakMap,Du=new WeakMap,Ga=new WeakMap,EA=new WeakSet,AQ=function(t){const r=[],n=new Set;for(const a of t){const[s,c,l]=a;r.push([s,c,a],[s,l,a])}r.sort((a,s)=>a[1]-s[1]||a[0]-s[0]);for(let a=0,s=r.length;a<s;a+=2){const c=r[a][2],l=r[a+1][2];c.push(l),l.push(c),n.add(c),n.add(l)}const o=[];let i;for(;n.size>0;){const a=n.values().next().value;let[s,c,l,d,h]=a;n.delete(a);let p=s,m=c;for(i=[s,l],o.push(i);;){let g;if(n.has(d))g=d;else if(n.has(h))g=h;else break;n.delete(g),[s,c,l,d,h]=g,p!==s&&(i.push(p,m,s,m===c?c:l),p=s),m=m===c?l:c}i.push(p,m)}return new i6e(o,b(this,_O))},Sg=new WeakSet,SD=function(t){const r=b(this,Ga);let n=0,o=r.length-1;for(;n<=o;){const i=n+o>>1,a=r[i][0];if(a===t)return i;a<t?n=i+1:o=i-1}return o+1},PA=new WeakSet,DQ=function([,t,r]){const n=J(this,Sg,SD).call(this,t);b(this,Ga).splice(n,0,[t,r])},TA=new WeakSet,zQ=function([,t,r]){const n=J(this,Sg,SD).call(this,t);for(let o=n;o<b(this,Ga).length;o++){const[i,a]=b(this,Ga)[o];if(i!==t)break;if(i===t&&a===r){b(this,Ga).splice(o,1);return}}for(let o=n-1;o>=0;o--){const[i,a]=b(this,Ga)[o];if(i!==t)break;if(i===t&&a===r){b(this,Ga).splice(o,1);return}}},OO=new WeakSet,OB=function(t){const[r,n,o]=t,i=[[r,n,o]],a=J(this,Sg,SD).call(this,o);for(let s=0;s<a;s++){const[c,l]=b(this,Ga)[s];for(let d=0,h=i.length;d<h;d++){const[,p,m]=i[d];if(!(l<=p||m<=c)){if(p>=c){if(m>l)i[d][1]=l;else{if(h===1)return[];i.splice(d,1),d--,h--}continue}i[d][2]=c,m>l&&i.push([r,l,m])}}}return i};class lY{toSVGPath(){throw new Error("Abstract method `toSVGPath` must be implemented.")}get box(){throw new Error("Abstract getter `box` must be implemented.")}serialize(t,r){throw new Error("Abstract method `serialize` must be implemented.")}get free(){return this instanceof kF}}class i6e extends lY{constructor(r,n){super();I(this,xO,void 0);I(this,Eg,void 0);G(this,Eg,r),G(this,xO,n)}toSVGPath(){const r=[];for(const n of b(this,Eg)){let[o,i]=n;r.push(`M${o} ${i}`);for(let a=2;a<n.length;a+=2){const s=n[a],c=n[a+1];s===o?(r.push(`V${c}`),i=c):c===i&&(r.push(`H${s}`),o=s)}r.push("Z")}return r.join(" ")}serialize([r,n,o,i],a){const s=[],c=o-r,l=i-n;for(const d of b(this,Eg)){const h=new Array(d.length);for(let p=0;p<d.length;p+=2)h[p]=r+d[p]*c,h[p+1]=i-d[p+1]*l;s.push(h)}return s}get box(){return b(this,xO)}}xO=new WeakMap,Eg=new WeakMap;const Gc=class Gc{constructor({x:t,y:r},n,o,i,a,s=0){I(this,EO);I(this,Vs,void 0);I(this,Xc,[]);I(this,Pg,void 0);I(this,Tg,void 0);I(this,Ks,[]);I(this,$t,new Float64Array(18));I(this,qf,void 0);I(this,Jf,void 0);I(this,jO,void 0);I(this,MO,void 0);I(this,Cg,void 0);I(this,Ag,void 0);I(this,zu,[]);G(this,Vs,n),G(this,Ag,i*o),G(this,Tg,a),b(this,$t).set([NaN,NaN,NaN,NaN,t,r],6),G(this,Pg,s),G(this,MO,b(Gc,SO)*o),G(this,jO,b(Gc,AA)*o),G(this,Cg,o),b(this,zu).push(t,r)}get free(){return!0}isEmpty(){return isNaN(b(this,$t)[8])}add({x:t,y:r}){var T;G(this,qf,t),G(this,Jf,r);const[n,o,i,a]=b(this,Vs);let[s,c,l,d]=b(this,$t).subarray(8,12);const h=t-l,p=r-d,m=Math.hypot(h,p);if(m<b(this,jO))return!1;const g=m-b(this,MO),y=g/m,w=y*h,v=y*p;let O=s,x=c;s=l,c=d,l+=w,d+=v,(T=b(this,zu))==null||T.push(t,r);const S=-v/g,j=w/g,P=S*b(this,Ag),D=j*b(this,Ag);return b(this,$t).set(b(this,$t).subarray(2,8),0),b(this,$t).set([l+P,d+D],4),b(this,$t).set(b(this,$t).subarray(14,18),12),b(this,$t).set([l-P,d-D],16),isNaN(b(this,$t)[6])?(b(this,Ks).length===0&&(b(this,$t).set([s+P,c+D],2),b(this,Ks).push(NaN,NaN,NaN,NaN,(s+P-n)/i,(c+D-o)/a),b(this,$t).set([s-P,c-D],14),b(this,Xc).push(NaN,NaN,NaN,NaN,(s-P-n)/i,(c-D-o)/a)),b(this,$t).set([O,x,s,c,l,d],6),!this.isEmpty()):(b(this,$t).set([O,x,s,c,l,d],6),Math.abs(Math.atan2(x-c,O-s)-Math.atan2(v,w))<Math.PI/2?([s,c,l,d]=b(this,$t).subarray(2,6),b(this,Ks).push(NaN,NaN,NaN,NaN,((s+l)/2-n)/i,((c+d)/2-o)/a),[s,c,O,x]=b(this,$t).subarray(14,18),b(this,Xc).push(NaN,NaN,NaN,NaN,((O+s)/2-n)/i,((x+c)/2-o)/a),!0):([O,x,s,c,l,d]=b(this,$t).subarray(0,6),b(this,Ks).push(((O+5*s)/6-n)/i,((x+5*c)/6-o)/a,((5*s+l)/6-n)/i,((5*c+d)/6-o)/a,((s+l)/2-n)/i,((c+d)/2-o)/a),[l,d,s,c,O,x]=b(this,$t).subarray(12,18),b(this,Xc).push(((O+5*s)/6-n)/i,((x+5*c)/6-o)/a,((5*s+l)/6-n)/i,((5*c+d)/6-o)/a,((s+l)/2-n)/i,((c+d)/2-o)/a),!0))}toSVGPath(){if(this.isEmpty())return"";const t=b(this,Ks),r=b(this,Xc),n=b(this,$t).subarray(4,6),o=b(this,$t).subarray(16,18),[i,a,s,c]=b(this,Vs),[l,d,h,p]=J(this,EO,xB).call(this);if(isNaN(b(this,$t)[6])&&!this.isEmpty())return`M${(b(this,$t)[2]-i)/s} ${(b(this,$t)[3]-a)/c} L${(b(this,$t)[4]-i)/s} ${(b(this,$t)[5]-a)/c} L${l} ${d} L${h} ${p} L${(b(this,$t)[16]-i)/s} ${(b(this,$t)[17]-a)/c} L${(b(this,$t)[14]-i)/s} ${(b(this,$t)[15]-a)/c} Z`;const m=[];m.push(`M${t[4]} ${t[5]}`);for(let g=6;g<t.length;g+=6)isNaN(t[g])?m.push(`L${t[g+4]} ${t[g+5]}`):m.push(`C${t[g]} ${t[g+1]} ${t[g+2]} ${t[g+3]} ${t[g+4]} ${t[g+5]}`);m.push(`L${(n[0]-i)/s} ${(n[1]-a)/c} L${l} ${d} L${h} ${p} L${(o[0]-i)/s} ${(o[1]-a)/c}`);for(let g=r.length-6;g>=6;g-=6)isNaN(r[g])?m.push(`L${r[g+4]} ${r[g+5]}`):m.push(`C${r[g]} ${r[g+1]} ${r[g+2]} ${r[g+3]} ${r[g+4]} ${r[g+5]}`);return m.push(`L${r[4]} ${r[5]} Z`),m.join(" ")}getOutlines(){var v;const t=b(this,Ks),r=b(this,Xc),n=b(this,$t),o=n.subarray(4,6),i=n.subarray(16,18),[a,s,c,l]=b(this,Vs),d=new Float64Array((((v=b(this,zu))==null?void 0:v.length)??0)+2);for(let O=0,x=d.length-2;O<x;O+=2)d[O]=(b(this,zu)[O]-a)/c,d[O+1]=(b(this,zu)[O+1]-s)/l;d[d.length-2]=(b(this,qf)-a)/c,d[d.length-1]=(b(this,Jf)-s)/l;const[h,p,m,g]=J(this,EO,xB).call(this);if(isNaN(n[6])&&!this.isEmpty()){const O=new Float64Array(36);return O.set([NaN,NaN,NaN,NaN,(n[2]-a)/c,(n[3]-s)/l,NaN,NaN,NaN,NaN,(n[4]-a)/c,(n[5]-s)/l,NaN,NaN,NaN,NaN,h,p,NaN,NaN,NaN,NaN,m,g,NaN,NaN,NaN,NaN,(n[16]-a)/c,(n[17]-s)/l,NaN,NaN,NaN,NaN,(n[14]-a)/c,(n[15]-s)/l],0),new kF(O,d,b(this,Vs),b(this,Cg),b(this,Pg),b(this,Tg))}const y=new Float64Array(b(this,Ks).length+24+b(this,Xc).length);let w=t.length;for(let O=0;O<w;O+=2){if(isNaN(t[O])){y[O]=y[O+1]=NaN;continue}y[O]=t[O],y[O+1]=t[O+1]}y.set([NaN,NaN,NaN,NaN,(o[0]-a)/c,(o[1]-s)/l,NaN,NaN,NaN,NaN,h,p,NaN,NaN,NaN,NaN,m,g,NaN,NaN,NaN,NaN,(i[0]-a)/c,(i[1]-s)/l],w),w+=24;for(let O=r.length-6;O>=6;O-=6)for(let x=0;x<6;x+=2){if(isNaN(r[O+x])){y[w]=y[w+1]=NaN,w+=2;continue}y[w]=r[O+x],y[w+1]=r[O+x+1],w+=2}return y.set([NaN,NaN,NaN,NaN,r[4],r[5]],w),new kF(y,d,b(this,Vs),b(this,Cg),b(this,Pg),b(this,Tg))}};Vs=new WeakMap,Xc=new WeakMap,Pg=new WeakMap,Tg=new WeakMap,Ks=new WeakMap,$t=new WeakMap,qf=new WeakMap,Jf=new WeakMap,jO=new WeakMap,MO=new WeakMap,Cg=new WeakMap,Ag=new WeakMap,zu=new WeakMap,SO=new WeakMap,CA=new WeakMap,AA=new WeakMap,EO=new WeakSet,xB=function(){const t=b(this,$t).subarray(4,6),r=b(this,$t).subarray(16,18),[n,o,i,a]=b(this,Vs);return[(b(this,qf)+(t[0]-r[0])/2-n)/i,(b(this,Jf)+(t[1]-r[1])/2-o)/a,(b(this,qf)+(r[0]-t[0])/2-n)/i,(b(this,Jf)+(r[1]-t[1])/2-o)/a]},I(Gc,SO,8),I(Gc,CA,2),I(Gc,AA,b(Gc,SO)+b(Gc,CA));let qT=Gc;class kF extends lY{constructor(r,n,o,i,a,s){super();I(this,Zf);I(this,eh);I(this,DA);I(this,Dg,void 0);I(this,Qf,null);I(this,Yc,void 0);I(this,PO,void 0);I(this,Yi,void 0);I(this,TO,void 0);I(this,jn,void 0);G(this,jn,r),G(this,Yi,n),G(this,Dg,o),G(this,TO,i),G(this,Yc,a),G(this,PO,s),J(this,DA,UQ).call(this,s);const{x:c,y:l,width:d,height:h}=b(this,Qf);for(let p=0,m=r.length;p<m;p+=2)r[p]=(r[p]-c)/d,r[p+1]=(r[p+1]-l)/h;for(let p=0,m=n.length;p<m;p+=2)n[p]=(n[p]-c)/d,n[p+1]=(n[p+1]-l)/h}toSVGPath(){const r=[`M${b(this,jn)[4]} ${b(this,jn)[5]}`];for(let n=6,o=b(this,jn).length;n<o;n+=6){if(isNaN(b(this,jn)[n])){r.push(`L${b(this,jn)[n+4]} ${b(this,jn)[n+5]}`);continue}r.push(`C${b(this,jn)[n]} ${b(this,jn)[n+1]} ${b(this,jn)[n+2]} ${b(this,jn)[n+3]} ${b(this,jn)[n+4]} ${b(this,jn)[n+5]}`)}return r.push("Z"),r.join(" ")}serialize([r,n,o,i],a){const s=o-r,c=i-n;let l,d;switch(a){case 0:l=J(this,Zf,mx).call(this,b(this,jn),r,i,s,-c),d=J(this,Zf,mx).call(this,b(this,Yi),r,i,s,-c);break;case 90:l=J(this,eh,gx).call(this,b(this,jn),r,n,s,c),d=J(this,eh,gx).call(this,b(this,Yi),r,n,s,c);break;case 180:l=J(this,Zf,mx).call(this,b(this,jn),o,n,-s,c),d=J(this,Zf,mx).call(this,b(this,Yi),o,n,-s,c);break;case 270:l=J(this,eh,gx).call(this,b(this,jn),o,i,-s,-c),d=J(this,eh,gx).call(this,b(this,Yi),o,i,-s,-c);break}return{outline:Array.from(l),points:[Array.from(d)]}}get box(){return b(this,Qf)}getNewOutline(r,n){const{x:o,y:i,width:a,height:s}=b(this,Qf),[c,l,d,h]=b(this,Dg),p=a*d,m=s*h,g=o*d+c,y=i*h+l,w=new qT({x:b(this,Yi)[0]*p+g,y:b(this,Yi)[1]*m+y},b(this,Dg),b(this,TO),r,b(this,PO),n??b(this,Yc));for(let v=2;v<b(this,Yi).length;v+=2)w.add({x:b(this,Yi)[v]*p+g,y:b(this,Yi)[v+1]*m+y});return w.getOutlines()}}Dg=new WeakMap,Qf=new WeakMap,Yc=new WeakMap,PO=new WeakMap,Yi=new WeakMap,TO=new WeakMap,jn=new WeakMap,Zf=new WeakSet,mx=function(r,n,o,i,a){const s=new Float64Array(r.length);for(let c=0,l=r.length;c<l;c+=2)s[c]=n+r[c]*i,s[c+1]=o+r[c+1]*a;return s},eh=new WeakSet,gx=function(r,n,o,i,a){const s=new Float64Array(r.length);for(let c=0,l=r.length;c<l;c+=2)s[c]=n+r[c+1]*i,s[c+1]=o+r[c]*a;return s},DA=new WeakSet,UQ=function(r){const n=b(this,jn);let o=n[4],i=n[5],a=o,s=i,c=o,l=i,d=o,h=i;const p=r?Math.max:Math.min;for(let v=6,O=n.length;v<O;v+=6){if(isNaN(n[v]))a=Math.min(a,n[v+4]),s=Math.min(s,n[v+5]),c=Math.max(c,n[v+4]),l=Math.max(l,n[v+5]),h<n[v+5]?(d=n[v+4],h=n[v+5]):h===n[v+5]&&(d=p(d,n[v+4]));else{const x=Ze.bezierBoundingBox(o,i,...n.slice(v,v+6));a=Math.min(a,x[0]),s=Math.min(s,x[1]),c=Math.max(c,x[2]),l=Math.max(l,x[3]),h<x[3]?(d=x[2],h=x[3]):h===x[3]&&(d=p(d,x[2]))}o=n[v+4],i=n[v+5]}const m=a-b(this,Yc),g=s-b(this,Yc),y=c-a+2*b(this,Yc),w=l-s+2*b(this,Yc);G(this,Qf,{x:m,y:g,width:y,height:w,lastPoint:[d,h]})};const Jc=class Jc{constructor({editor:t=null,uiManager:r=null}){I(this,IO);I(this,NO);I(this,zA);I(this,qc);I(this,UA);I(this,Hs);I(this,CO,J(this,zA,IQ).bind(this));I(this,AO,J(this,UA,NQ).bind(this));I(this,Ya,null);I(this,th,null);I(this,zg,void 0);I(this,kn,null);I(this,DO,!1);I(this,Ug,!1);I(this,zO,null);I(this,UO,void 0);I(this,qa,null);I(this,Ig,void 0);var n;t?(G(this,Ug,!1),G(this,Ig,mt.HIGHLIGHT_COLOR),G(this,zO,t)):(G(this,Ug,!0),G(this,Ig,mt.HIGHLIGHT_DEFAULT_COLOR)),G(this,qa,(t==null?void 0:t._uiManager)||r),G(this,UO,b(this,qa)._eventBus),G(this,zg,(t==null?void 0:t.color)||((n=b(this,qa))==null?void 0:n.highlightColors.values().next().value)||"#FFFF98")}static get _keyboardManager(){return qt(this,"_keyboardManager",new A_([[["Escape","mac+Escape"],Jc.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],Jc.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],Jc.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],Jc.prototype._moveToPrevious],[["Home","mac+Home"],Jc.prototype._moveToBeginning],[["End","mac+End"],Jc.prototype._moveToEnd]]))}renderButton(){const t=G(this,Ya,document.createElement("button"));t.className="colorPicker",t.tabIndex="0",t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-button"),t.setAttribute("aria-haspopup",!0);const r=b(this,qa)._signal;t.addEventListener("click",J(this,qc,_h).bind(this),{signal:r}),t.addEventListener("keydown",b(this,CO),{signal:r});const n=G(this,th,document.createElement("span"));return n.className="swatch",n.setAttribute("aria-hidden",!0),n.style.backgroundColor=b(this,zg),t.append(n),t}renderMainDropdown(){const t=G(this,kn,J(this,IO,jB).call(this));return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}_colorSelectFromKeyboard(t){if(t.target===b(this,Ya)){J(this,qc,_h).call(this,t);return}const r=t.target.getAttribute("data-color");r&&J(this,NO,MB).call(this,r,t)}_moveToNext(t){var r,n;if(!b(this,Hs,ku)){J(this,qc,_h).call(this,t);return}if(t.target===b(this,Ya)){(r=b(this,kn).firstChild)==null||r.focus();return}(n=t.target.nextSibling)==null||n.focus()}_moveToPrevious(t){var r,n;if(t.target===((r=b(this,kn))==null?void 0:r.firstChild)||t.target===b(this,Ya)){b(this,Hs,ku)&&this._hideDropdownFromKeyboard();return}b(this,Hs,ku)||J(this,qc,_h).call(this,t),(n=t.target.previousSibling)==null||n.focus()}_moveToBeginning(t){var r;if(!b(this,Hs,ku)){J(this,qc,_h).call(this,t);return}(r=b(this,kn).firstChild)==null||r.focus()}_moveToEnd(t){var r;if(!b(this,Hs,ku)){J(this,qc,_h).call(this,t);return}(r=b(this,kn).lastChild)==null||r.focus()}hideDropdown(){var t;(t=b(this,kn))==null||t.classList.add("hidden"),window.removeEventListener("pointerdown",b(this,AO))}_hideDropdownFromKeyboard(){var t;if(!b(this,Ug)){if(!b(this,Hs,ku)){(t=b(this,zO))==null||t.unselect();return}this.hideDropdown(),b(this,Ya).focus({preventScroll:!0,focusVisible:b(this,DO)})}}updateColor(t){if(b(this,th)&&(b(this,th).style.backgroundColor=t),!b(this,kn))return;const r=b(this,qa).highlightColors.values();for(const n of b(this,kn).children)n.setAttribute("aria-selected",r.next().value===t)}destroy(){var t,r;(t=b(this,Ya))==null||t.remove(),G(this,Ya,null),G(this,th,null),(r=b(this,kn))==null||r.remove(),G(this,kn,null)}};CO=new WeakMap,AO=new WeakMap,Ya=new WeakMap,th=new WeakMap,zg=new WeakMap,kn=new WeakMap,DO=new WeakMap,Ug=new WeakMap,zO=new WeakMap,UO=new WeakMap,qa=new WeakMap,Ig=new WeakMap,IO=new WeakSet,jB=function(){const t=document.createElement("div"),r=b(this,qa)._signal;t.addEventListener("contextmenu",Oi,{signal:r}),t.className="dropdown",t.role="listbox",t.setAttribute("aria-multiselectable",!1),t.setAttribute("aria-orientation","vertical"),t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown");for(const[n,o]of b(this,qa).highlightColors){const i=document.createElement("button");i.tabIndex="0",i.role="option",i.setAttribute("data-color",o),i.title=n,i.setAttribute("data-l10n-id",`pdfjs-editor-colorpicker-${n}`);const a=document.createElement("span");i.append(a),a.className="swatch",a.style.backgroundColor=o,i.setAttribute("aria-selected",o===b(this,zg)),i.addEventListener("click",J(this,NO,MB).bind(this,o),{signal:r}),t.append(i)}return t.addEventListener("keydown",b(this,CO),{signal:r}),t},NO=new WeakSet,MB=function(t,r){r.stopPropagation(),b(this,UO).dispatch("switchannotationeditorparams",{source:this,type:b(this,Ig),value:t})},zA=new WeakSet,IQ=function(t){Jc._keyboardManager.exec(this,t)},qc=new WeakSet,_h=function(t){if(b(this,Hs,ku)){this.hideDropdown();return}if(G(this,DO,t.detail===0),window.addEventListener("pointerdown",b(this,AO),{signal:b(this,qa)._signal}),b(this,kn)){b(this,kn).classList.remove("hidden");return}const r=G(this,kn,J(this,IO,jB).call(this));b(this,Ya).append(r)},UA=new WeakSet,NQ=function(t){var r;(r=b(this,kn))!=null&&r.contains(t.target)||this.hideDropdown()},Hs=new WeakSet,ku=function(){return b(this,kn)&&!b(this,kn).classList.contains("hidden")};let JT=Jc;const Jt=class Jt extends lr{constructor(r){super({...r,name:"highlightEditor"});I(this,LO);I(this,VO);I(this,NA);I(this,RA);I(this,FA);I(this,KO);I(this,ih);I(this,$A);I(this,Bg);I(this,ah);I(this,BA);I(this,LA);I(this,Ng,null);I(this,RO,0);I(this,Uu,void 0);I(this,rh,null);I(this,Rg,null);I(this,xa,null);I(this,FO,null);I(this,$O,0);I(this,nh,null);I(this,Ja,null);I(this,oi,null);I(this,qi,!1);I(this,IA,J(this,$A,BQ).bind(this));I(this,Fg,null);I(this,oh,void 0);I(this,Wn,null);I(this,$g,"");I(this,ks,void 0);I(this,BO,"");this.color=r.color||Jt._defaultColor,G(this,ks,r.thickness||Jt._defaultThickness),G(this,oh,r.opacity||Jt._defaultOpacity),G(this,Uu,r.boxes||null),G(this,BO,r.methodOfCreation||""),G(this,$g,r.text||""),this._isDraggable=!1,r.highlightId>-1?(G(this,qi,!0),J(this,VO,EB).call(this,r),J(this,ih,yx).call(this)):(G(this,Ng,r.anchorNode),G(this,RO,r.anchorOffset),G(this,FO,r.focusNode),G(this,$O,r.focusOffset),J(this,LO,SB).call(this),J(this,ih,yx).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const r=Jt.prototype;return qt(this,"_keyboardManager",new A_([[["ArrowLeft","mac+ArrowLeft"],r._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],r._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],r._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],r._moveCaret,{args:[3]}]]))}get telemetryInitialData(){return{action:"added",type:b(this,qi)?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:b(this,ks),methodOfCreation:b(this,BO)}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.highlightColorNames.get(this.color)}}static computeTelemetryFinalData(r){return{numberOfColors:r.get("color").size}}static initialize(r,n){var o;lr.initialize(r,n),Jt._defaultColor||(Jt._defaultColor=((o=n.highlightColors)==null?void 0:o.values().next().value)||"#fff066")}static updateDefaultParams(r,n){switch(r){case mt.HIGHLIGHT_DEFAULT_COLOR:Jt._defaultColor=n;break;case mt.HIGHLIGHT_THICKNESS:Jt._defaultThickness=n;break}}translateInPage(r,n){}get toolbarPosition(){return b(this,Fg)}updateParams(r,n){switch(r){case mt.HIGHLIGHT_COLOR:J(this,NA,RQ).call(this,n);break;case mt.HIGHLIGHT_THICKNESS:J(this,RA,FQ).call(this,n);break}}static get defaultPropertiesToUpdate(){return[[mt.HIGHLIGHT_DEFAULT_COLOR,Jt._defaultColor],[mt.HIGHLIGHT_THICKNESS,Jt._defaultThickness]]}get propertiesToUpdate(){return[[mt.HIGHLIGHT_COLOR,this.color||Jt._defaultColor],[mt.HIGHLIGHT_THICKNESS,b(this,ks)||Jt._defaultThickness],[mt.HIGHLIGHT_FREE,b(this,qi)]]}async addEditToolbar(){const r=await super.addEditToolbar();return r?(this._uiManager.highlightColors&&(G(this,Rg,new JT({editor:this})),r.addColorPicker(b(this,Rg))),r):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(J(this,ah,bx).call(this))}getBaseTranslation(){return[0,0]}getRect(r,n){return super.getRect(r,n,J(this,ah,bx).call(this))}onceAdded(){this.parent.addUndoableEditor(this),this.div.focus()}remove(){J(this,KO,PB).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(J(this,ih,yx).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(r){var o;let n=!1;this.parent&&!r?J(this,KO,PB).call(this):r&&(J(this,ih,yx).call(this,r),n=!this.parent&&((o=this.div)==null?void 0:o.classList.contains("selectedEditor"))),super.setParent(r),this.show(this._isVisible),n&&this.select()}rotate(r){var i,a,s;const{drawLayer:n}=this.parent;let o;b(this,qi)?(r=(r-this.rotation+360)%360,o=J(i=Jt,Iu,sy).call(i,b(this,Ja).box,r)):o=J(a=Jt,Iu,sy).call(a,this,r),n.rotate(b(this,oi),r),n.rotate(b(this,Wn),r),n.updateBox(b(this,oi),o),n.updateBox(b(this,Wn),J(s=Jt,Iu,sy).call(s,b(this,xa).box,r))}render(){if(this.div)return this.div;const r=super.render();b(this,$g)&&(r.setAttribute("aria-label",b(this,$g)),r.setAttribute("role","mark")),b(this,qi)?r.classList.add("free"):this.div.addEventListener("keydown",b(this,IA),{signal:this._uiManager._signal});const n=G(this,nh,document.createElement("div"));r.append(n),n.setAttribute("aria-hidden","true"),n.className="internal",n.style.clipPath=b(this,rh);const[o,i]=this.parentDimensions;return this.setDims(this.width*o,this.height*i),BT(this,b(this,nh),["pointerover","pointerleave"]),this.enableEditing(),r}pointerover(){this.parent.drawLayer.addClass(b(this,Wn),"hovered")}pointerleave(){this.parent.drawLayer.removeClass(b(this,Wn),"hovered")}_moveCaret(r){switch(this.parent.unselect(this),r){case 0:case 2:J(this,Bg,ED).call(this,!0);break;case 1:case 3:J(this,Bg,ED).call(this,!1);break}}select(){var r,n;super.select(),b(this,Wn)&&((r=this.parent)==null||r.drawLayer.removeClass(b(this,Wn),"hovered"),(n=this.parent)==null||n.drawLayer.addClass(b(this,Wn),"selected"))}unselect(){var r;super.unselect(),b(this,Wn)&&((r=this.parent)==null||r.drawLayer.removeClass(b(this,Wn),"selected"),b(this,qi)||J(this,Bg,ED).call(this,!1))}get _mustFixPosition(){return!b(this,qi)}show(r=this._isVisible){super.show(r),this.parent&&(this.parent.drawLayer.show(b(this,oi),r),this.parent.drawLayer.show(b(this,Wn),r))}static startHighlighting(r,n,{target:o,x:i,y:a}){const{x:s,y:c,width:l,height:d}=o.getBoundingClientRect(),h=w=>{J(this,VA,KQ).call(this,r,w)},p=r._signal,m={capture:!0,passive:!1,signal:p},g=w=>{w.preventDefault(),w.stopPropagation()},y=w=>{o.removeEventListener("pointermove",h),window.removeEventListener("blur",y),window.removeEventListener("pointerup",y),window.removeEventListener("pointerdown",g,m),window.removeEventListener("contextmenu",Oi),J(this,KA,HQ).call(this,r,w)};window.addEventListener("blur",y,{signal:p}),window.addEventListener("pointerup",y,{signal:p}),window.addEventListener("pointerdown",g,m),window.addEventListener("contextmenu",Oi,{signal:p}),o.addEventListener("pointermove",h,{signal:p}),this._freeHighlight=new qT({x:i,y:a},[s,c,l,d],r.scale,this._defaultThickness/2,n,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=r.drawLayer.highlight(this._freeHighlight,this._defaultColor,this._defaultOpacity,!0)}static deserialize(r,n,o){var y;const i=super.deserialize(r,n,o),{rect:[a,s,c,l],color:d,quadPoints:h}=r;i.color=Ze.makeHexColor(...d),G(i,oh,r.opacity);const[p,m]=i.pageDimensions;i.width=(c-a)/p,i.height=(l-s)/m;const g=G(i,Uu,[]);for(let w=0;w<h.length;w+=8)g.push({x:(h[4]-c)/p,y:(l-(1-h[w+5]))/m,width:(h[w+2]-h[w])/p,height:(h[w+5]-h[w+1])/m});return J(y=i,LO,SB).call(y),i}serialize(r=!1){if(this.isEmpty()||r)return null;const n=this.getRect(0,0),o=lr._colorManager.convert(this.color);return{annotationType:Vt.HIGHLIGHT,color:o,opacity:b(this,oh),thickness:b(this,ks),quadPoints:J(this,BA,LQ).call(this),outlines:J(this,LA,VQ).call(this,n),pageIndex:this.pageIndex,rect:n,rotation:J(this,ah,bx).call(this),structTreeParentId:this._structTreeParentId}}static canCreateNewEmptyEditor(){return!1}};Ng=new WeakMap,RO=new WeakMap,Uu=new WeakMap,rh=new WeakMap,Rg=new WeakMap,xa=new WeakMap,FO=new WeakMap,$O=new WeakMap,nh=new WeakMap,Ja=new WeakMap,oi=new WeakMap,qi=new WeakMap,IA=new WeakMap,Fg=new WeakMap,oh=new WeakMap,Wn=new WeakMap,$g=new WeakMap,ks=new WeakMap,BO=new WeakMap,LO=new WeakSet,SB=function(){const r=new HF(b(this,Uu),.001);G(this,Ja,r.getOutlines()),{x:this.x,y:this.y,width:this.width,height:this.height}=b(this,Ja).box;const n=new HF(b(this,Uu),.0025,.001,this._uiManager.direction==="ltr");G(this,xa,n.getOutlines());const{lastPoint:o}=b(this,xa).box;G(this,Fg,[(o[0]-this.x)/this.width,(o[1]-this.y)/this.height])},VO=new WeakSet,EB=function({highlightOutlines:r,highlightId:n,clipPathId:o}){var h,p;if(G(this,Ja,r),G(this,xa,r.getNewOutline(b(this,ks)/2+1.5,.0025)),n>=0)G(this,oi,n),G(this,rh,o),this.parent.drawLayer.finalizeLine(n,r),G(this,Wn,this.parent.drawLayer.highlightOutline(b(this,xa)));else if(this.parent){const m=this.parent.viewport.rotation;this.parent.drawLayer.updateLine(b(this,oi),r),this.parent.drawLayer.updateBox(b(this,oi),J(h=Jt,Iu,sy).call(h,b(this,Ja).box,(m-this.rotation+360)%360)),this.parent.drawLayer.updateLine(b(this,Wn),b(this,xa)),this.parent.drawLayer.updateBox(b(this,Wn),J(p=Jt,Iu,sy).call(p,b(this,xa).box,m))}const{x:a,y:s,width:c,height:l}=r.box;switch(this.rotation){case 0:this.x=a,this.y=s,this.width=c,this.height=l;break;case 90:{const[m,g]=this.parentDimensions;this.x=s,this.y=1-a,this.width=c*g/m,this.height=l*m/g;break}case 180:this.x=1-a,this.y=1-s,this.width=c,this.height=l;break;case 270:{const[m,g]=this.parentDimensions;this.x=1-s,this.y=a,this.width=c*g/m,this.height=l*m/g;break}}const{lastPoint:d}=b(this,xa).box;G(this,Fg,[(d[0]-a)/c,(d[1]-s)/l])},NA=new WeakSet,RQ=function(r){const n=i=>{var a,s;this.color=i,(a=this.parent)==null||a.drawLayer.changeColor(b(this,oi),i),(s=b(this,Rg))==null||s.updateColor(i)},o=this.color;this.addCommands({cmd:n.bind(this,r),undo:n.bind(this,o),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.highlightColorNames.get(r)},!0)},RA=new WeakSet,FQ=function(r){const n=b(this,ks),o=i=>{G(this,ks,i),J(this,FA,$Q).call(this,i)};this.addCommands({cmd:o.bind(this,r),undo:o.bind(this,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:mt.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:r},!0)},FA=new WeakSet,$Q=function(r){if(!b(this,qi))return;J(this,VO,EB).call(this,{highlightOutlines:b(this,Ja).getNewOutline(r/2)}),this.fixAndSetPosition();const[n,o]=this.parentDimensions;this.setDims(this.width*n,this.height*o)},KO=new WeakSet,PB=function(){b(this,oi)===null||!this.parent||(this.parent.drawLayer.remove(b(this,oi)),G(this,oi,null),this.parent.drawLayer.remove(b(this,Wn)),G(this,Wn,null))},ih=new WeakSet,yx=function(r=this.parent){b(this,oi)===null&&({id:Zi(this,oi)._,clipPathId:Zi(this,rh)._}=r.drawLayer.highlight(b(this,Ja),this.color,b(this,oh)),G(this,Wn,r.drawLayer.highlightOutline(b(this,xa))),b(this,nh)&&(b(this,nh).style.clipPath=b(this,rh)))},Iu=new WeakSet,sy=function({x:r,y:n,width:o,height:i},a){switch(a){case 90:return{x:1-n-i,y:r,width:i,height:o};case 180:return{x:1-r-o,y:1-n-i,width:o,height:i};case 270:return{x:n,y:1-r-o,width:i,height:o}}return{x:r,y:n,width:o,height:i}},$A=new WeakSet,BQ=function(r){Jt._keyboardManager.exec(this,r)},Bg=new WeakSet,ED=function(r){if(!b(this,Ng))return;const n=window.getSelection();r?n.setPosition(b(this,Ng),b(this,RO)):n.setPosition(b(this,FO),b(this,$O))},ah=new WeakSet,bx=function(){return b(this,qi)?this.rotation:0},BA=new WeakSet,LQ=function(){if(b(this,qi))return null;const[r,n]=this.pageDimensions,o=b(this,Uu),i=new Float32Array(o.length*8);let a=0;for(const{x:s,y:c,width:l,height:d}of o){const h=s*r,p=(1-c-d)*n;i[a]=i[a+4]=h,i[a+1]=i[a+3]=p,i[a+2]=i[a+6]=h+l*r,i[a+5]=i[a+7]=p+d*n,a+=8}return i},LA=new WeakSet,VQ=function(r){return b(this,Ja).serialize(r,J(this,ah,bx).call(this))},VA=new WeakSet,KQ=function(r,n){this._freeHighlight.add(n)&&r.drawLayer.updatePath(this._freeHighlightId,this._freeHighlight)},KA=new WeakSet,HQ=function(r,n){this._freeHighlight.isEmpty()?r.drawLayer.removeFreeHighlight(this._freeHighlightId):r.createAndAddNewEditor(n,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:"main_toolbar"}),this._freeHighlightId=-1,this._freeHighlight=null,this._freeHighlightClipId=""},I(Jt,Iu),I(Jt,VA),I(Jt,KA),Je(Jt,"_defaultColor",null),Je(Jt,"_defaultOpacity",1),Je(Jt,"_defaultThickness",12),Je(Jt,"_l10nPromise"),Je(Jt,"_type","highlight"),Je(Jt,"_editorType",Vt.HIGHLIGHT),Je(Jt,"_freeHighlightId",-1),Je(Jt,"_freeHighlight",null),Je(Jt,"_freeHighlightClipId","");let QT=Jt;const Vr=class Vr extends lr{constructor(r){super({...r,name:"inkEditor"});I(this,HA);I(this,kA);I(this,WA);I(this,XA);I(this,XO);I(this,GA);I(this,GO);I(this,YA);I(this,qA);I(this,JA);I(this,QA);I(this,ZA);I(this,el);I(this,YO);I(this,Lg);I(this,Vg);I(this,Ru);I(this,qO);I(this,Kg);I(this,rD);I(this,QO);I(this,Hg);I(this,ph);I(this,sh,0);I(this,ch,0);I(this,HO,this.canvasPointermove.bind(this));I(this,kO,this.canvasPointerleave.bind(this));I(this,WO,this.canvasPointerup.bind(this));I(this,lh,this.canvasPointerdown.bind(this));I(this,Ws,null);I(this,Qc,new Path2D);I(this,ja,!1);I(this,uh,!1);I(this,dh,!1);I(this,Zc,null);I(this,fh,0);I(this,hh,0);I(this,Nu,null);this.color=r.color||null,this.thickness=r.thickness||null,this.opacity=r.opacity||null,this.paths=[],this.bezierPath2D=[],this.allRawPaths=[],this.currentPath=[],this.scaleFactor=1,this.translationX=this.translationY=0,this.x=0,this.y=0,this._willKeepAspectRatio=!0}static initialize(r,n){lr.initialize(r,n)}static updateDefaultParams(r,n){switch(r){case mt.INK_THICKNESS:Vr._defaultThickness=n;break;case mt.INK_COLOR:Vr._defaultColor=n;break;case mt.INK_OPACITY:Vr._defaultOpacity=n/100;break}}updateParams(r,n){switch(r){case mt.INK_THICKNESS:J(this,HA,kQ).call(this,n);break;case mt.INK_COLOR:J(this,kA,WQ).call(this,n);break;case mt.INK_OPACITY:J(this,WA,XQ).call(this,n);break}}static get defaultPropertiesToUpdate(){return[[mt.INK_THICKNESS,Vr._defaultThickness],[mt.INK_COLOR,Vr._defaultColor||lr._defaultLineColor],[mt.INK_OPACITY,Math.round(Vr._defaultOpacity*100)]]}get propertiesToUpdate(){return[[mt.INK_THICKNESS,this.thickness||Vr._defaultThickness],[mt.INK_COLOR,this.color||Vr._defaultColor||lr._defaultLineColor],[mt.INK_OPACITY,Math.round(100*(this.opacity??Vr._defaultOpacity))]]}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.canvas||(J(this,Lg,PD).call(this),J(this,Vg,TD).call(this)),this.isAttachedToDOM||(this.parent.add(this),J(this,Ru,cy).call(this)),J(this,ph,vx).call(this)))}remove(){var r;this.canvas!==null&&(this.isEmpty()||this.commit(),this.canvas.width=this.canvas.height=0,this.canvas.remove(),this.canvas=null,b(this,Ws)&&(clearTimeout(b(this,Ws)),G(this,Ws,null)),(r=b(this,Zc))==null||r.disconnect(),G(this,Zc,null),super.remove())}setParent(r){!this.parent&&r?this._uiManager.removeShouldRescale(this):this.parent&&r===null&&this._uiManager.addShouldRescale(this),super.setParent(r)}onScaleChanging(){const[r,n]=this.parentDimensions,o=this.width*r,i=this.height*n;this.setDimensions(o,i)}enableEditMode(){b(this,ja)||this.canvas===null||(super.enableEditMode(),this._isDraggable=!1,this.canvas.addEventListener("pointerdown",b(this,lh),{signal:this._uiManager._signal}))}disableEditMode(){!this.isInEditMode()||this.canvas===null||(super.disableEditMode(),this._isDraggable=!this.isEmpty(),this.div.classList.remove("editing"),this.canvas.removeEventListener("pointerdown",b(this,lh)))}onceAdded(){this._isDraggable=!this.isEmpty()}isEmpty(){return this.paths.length===0||this.paths.length===1&&this.paths[0].length===0}commit(){b(this,ja)||(super.commit(),this.isEditing=!1,this.disableEditMode(),this.setInForeground(),G(this,ja,!0),this.div.classList.add("disabled"),J(this,ph,vx).call(this,!0),this.select(),this.parent.addInkEditorIfNeeded(!0),this.moveInDOM(),this.div.focus({preventScroll:!0}))}focusin(r){this._focusEventsAllowed&&(super.focusin(r),this.enableEditMode())}canvasPointerdown(r){r.button!==0||!this.isInEditMode()||b(this,ja)||(this.setInForeground(),r.preventDefault(),this.div.contains(document.activeElement)||this.div.focus({preventScroll:!0}),J(this,GA,YQ).call(this,r.offsetX,r.offsetY))}canvasPointermove(r){r.preventDefault(),J(this,GO,CB).call(this,r.offsetX,r.offsetY)}canvasPointerup(r){r.preventDefault(),J(this,YO,AB).call(this,r)}canvasPointerleave(r){J(this,YO,AB).call(this,r)}get isResizable(){return!this.isEmpty()&&b(this,ja)}render(){if(this.div)return this.div;let r,n;this.width&&(r=this.x,n=this.y),super.render(),this.div.setAttribute("data-l10n-id","pdfjs-ink");const[o,i,a,s]=J(this,XA,GQ).call(this);if(this.setAt(o,i,0,0),this.setDims(a,s),J(this,Lg,PD).call(this),this.width){const[c,l]=this.parentDimensions;this.setAspectRatio(this.width*c,this.height*l),this.setAt(r*c,n*l,this.width*c,this.height*l),G(this,dh,!0),J(this,Ru,cy).call(this),this.setDims(this.width*c,this.height*l),J(this,el,Oh).call(this),this.div.classList.add("disabled")}else this.div.classList.add("editing"),this.enableEditMode();return J(this,Vg,TD).call(this),this.div}setDimensions(r,n){const o=Math.round(r),i=Math.round(n);if(b(this,fh)===o&&b(this,hh)===i)return;G(this,fh,o),G(this,hh,i),this.canvas.style.visibility="hidden";const[a,s]=this.parentDimensions;this.width=r/a,this.height=n/s,this.fixAndSetPosition(),b(this,ja)&&J(this,qO,DB).call(this,r,n),J(this,Ru,cy).call(this),J(this,el,Oh).call(this),this.canvas.style.visibility="visible",this.fixDims()}static deserialize(r,n,o){var w,v,O;if(r instanceof sY)return null;const i=super.deserialize(r,n,o);i.thickness=r.thickness,i.color=Ze.makeHexColor(...r.color),i.opacity=r.opacity;const[a,s]=i.pageDimensions,c=i.width*a,l=i.height*s,d=i.parentScale,h=r.thickness/2;G(i,ja,!0),G(i,fh,Math.round(c)),G(i,hh,Math.round(l));const{paths:p,rect:m,rotation:g}=r;for(let{bezier:x}of p){x=J(w=Vr,tD,rZ).call(w,x,m,g);const S=[];i.paths.push(S);let j=d*(x[0]-h),P=d*(x[1]-h);for(let M=2,T=x.length;M<T;M+=6){const z=d*(x[M]-h),A=d*(x[M+1]-h),L=d*(x[M+2]-h),H=d*(x[M+3]-h),X=d*(x[M+4]-h),K=d*(x[M+5]-h);S.push([[j,P],[z,A],[L,H],[X,K]]),j=X,P=K}const D=J(this,eD,tZ).call(this,S);i.bezierPath2D.push(D)}const y=J(v=i,QO,UB).call(v);return G(i,ch,Math.max(lr.MIN_SIZE,y[2]-y[0])),G(i,sh,Math.max(lr.MIN_SIZE,y[3]-y[1])),J(O=i,qO,DB).call(O,c,l),i}serialize(){if(this.isEmpty())return null;const r=this.getRect(0,0),n=lr._colorManager.convert(this.ctx.strokeStyle);return{annotationType:Vt.INK,color:n,thickness:this.thickness,opacity:this.opacity,paths:J(this,rD,nZ).call(this,this.scaleFactor/this.parentScale,this.translationX,this.translationY,r),pageIndex:this.pageIndex,rect:r,rotation:this.rotation,structTreeParentId:this._structTreeParentId}}};sh=new WeakMap,ch=new WeakMap,HO=new WeakMap,kO=new WeakMap,WO=new WeakMap,lh=new WeakMap,Ws=new WeakMap,Qc=new WeakMap,ja=new WeakMap,uh=new WeakMap,dh=new WeakMap,Zc=new WeakMap,fh=new WeakMap,hh=new WeakMap,Nu=new WeakMap,HA=new WeakSet,kQ=function(r){const n=i=>{this.thickness=i,J(this,ph,vx).call(this)},o=this.thickness;this.addCommands({cmd:n.bind(this,r),undo:n.bind(this,o),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:mt.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0})},kA=new WeakSet,WQ=function(r){const n=i=>{this.color=i,J(this,el,Oh).call(this)},o=this.color;this.addCommands({cmd:n.bind(this,r),undo:n.bind(this,o),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:mt.INK_COLOR,overwriteIfSameType:!0,keepUndo:!0})},WA=new WeakSet,XQ=function(r){const n=i=>{this.opacity=i,J(this,el,Oh).call(this)};r/=100;const o=this.opacity;this.addCommands({cmd:n.bind(this,r),undo:n.bind(this,o),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:mt.INK_OPACITY,overwriteIfSameType:!0,keepUndo:!0})},XA=new WeakSet,GQ=function(){const{parentRotation:r,parentDimensions:[n,o]}=this;switch(r){case 90:return[0,o,o,n];case 180:return[n,o,n,o];case 270:return[n,0,o,n];default:return[0,0,n,o]}},XO=new WeakSet,TB=function(){const{ctx:r,color:n,opacity:o,thickness:i,parentScale:a,scaleFactor:s}=this;r.lineWidth=i*a/s,r.lineCap="round",r.lineJoin="round",r.miterLimit=10,r.strokeStyle=`${n}${T4e(o)}`},GA=new WeakSet,YQ=function(r,n){const o=this._uiManager._signal;this.canvas.addEventListener("contextmenu",Oi,{signal:o}),this.canvas.addEventListener("pointerleave",b(this,kO),{signal:o}),this.canvas.addEventListener("pointermove",b(this,HO),{signal:o}),this.canvas.addEventListener("pointerup",b(this,WO),{signal:o}),this.canvas.removeEventListener("pointerdown",b(this,lh)),this.isEditing=!0,b(this,dh)||(G(this,dh,!0),J(this,Ru,cy).call(this),this.thickness||(this.thickness=Vr._defaultThickness),this.color||(this.color=Vr._defaultColor||lr._defaultLineColor),this.opacity??(this.opacity=Vr._defaultOpacity)),this.currentPath.push([r,n]),G(this,uh,!1),J(this,XO,TB).call(this),G(this,Nu,()=>{J(this,JA,QQ).call(this),b(this,Nu)&&window.requestAnimationFrame(b(this,Nu))}),window.requestAnimationFrame(b(this,Nu))},GO=new WeakSet,CB=function(r,n){const[o,i]=this.currentPath.at(-1);if(this.currentPath.length>1&&r===o&&n===i)return;const a=this.currentPath;let s=b(this,Qc);if(a.push([r,n]),G(this,uh,!0),a.length<=2){s.moveTo(...a[0]),s.lineTo(r,n);return}a.length===3&&(G(this,Qc,s=new Path2D),s.moveTo(...a[0])),J(this,QA,ZQ).call(this,s,...a.at(-3),...a.at(-2),r,n)},YA=new WeakSet,qQ=function(){if(this.currentPath.length===0)return;const r=this.currentPath.at(-1);b(this,Qc).lineTo(...r)},qA=new WeakSet,JQ=function(r,n){G(this,Nu,null),r=Math.min(Math.max(r,0),this.canvas.width),n=Math.min(Math.max(n,0),this.canvas.height),J(this,GO,CB).call(this,r,n),J(this,YA,qQ).call(this);let o;if(this.currentPath.length!==1)o=J(this,ZA,eZ).call(this);else{const l=[r,n];o=[[l,l.slice(),l.slice(),l]]}const i=b(this,Qc),a=this.currentPath;this.currentPath=[],G(this,Qc,new Path2D);const s=()=>{this.allRawPaths.push(a),this.paths.push(o),this.bezierPath2D.push(i),this._uiManager.rebuild(this)},c=()=>{this.allRawPaths.pop(),this.paths.pop(),this.bezierPath2D.pop(),this.paths.length===0?this.remove():(this.canvas||(J(this,Lg,PD).call(this),J(this,Vg,TD).call(this)),J(this,ph,vx).call(this))};this.addCommands({cmd:s,undo:c,mustExec:!0})},JA=new WeakSet,QQ=function(){if(!b(this,uh))return;G(this,uh,!1);const r=Math.ceil(this.thickness*this.parentScale),n=this.currentPath.slice(-3),o=n.map(s=>s[0]),i=n.map(s=>s[1]);Math.min(...o)-r,Math.max(...o)+r,Math.min(...i)-r,Math.max(...i)+r;const{ctx:a}=this;a.save(),a.clearRect(0,0,this.canvas.width,this.canvas.height);for(const s of this.bezierPath2D)a.stroke(s);a.stroke(b(this,Qc)),a.restore()},QA=new WeakSet,ZQ=function(r,n,o,i,a,s,c){const l=(n+i)/2,d=(o+a)/2,h=(i+s)/2,p=(a+c)/2;r.bezierCurveTo(l+2*(i-l)/3,d+2*(a-d)/3,h+2*(i-h)/3,p+2*(a-p)/3,h,p)},ZA=new WeakSet,eZ=function(){const r=this.currentPath;if(r.length<=2)return[[r[0],r[0],r.at(-1),r.at(-1)]];const n=[];let o,[i,a]=r[0];for(o=1;o<r.length-2;o++){const[m,g]=r[o],[y,w]=r[o+1],v=(m+y)/2,O=(g+w)/2,x=[i+2*(m-i)/3,a+2*(g-a)/3],S=[v+2*(m-v)/3,O+2*(g-O)/3];n.push([[i,a],x,S,[v,O]]),[i,a]=[v,O]}const[s,c]=r[o],[l,d]=r[o+1],h=[i+2*(s-i)/3,a+2*(c-a)/3],p=[l+2*(s-l)/3,d+2*(c-d)/3];return n.push([[i,a],h,p,[l,d]]),n},el=new WeakSet,Oh=function(){if(this.isEmpty()){J(this,Kg,CD).call(this);return}J(this,XO,TB).call(this);const{canvas:r,ctx:n}=this;n.setTransform(1,0,0,1,0,0),n.clearRect(0,0,r.width,r.height),J(this,Kg,CD).call(this);for(const o of this.bezierPath2D)n.stroke(o)},YO=new WeakSet,AB=function(r){this.canvas.removeEventListener("pointerleave",b(this,kO)),this.canvas.removeEventListener("pointermove",b(this,HO)),this.canvas.removeEventListener("pointerup",b(this,WO)),this.canvas.addEventListener("pointerdown",b(this,lh),{signal:this._uiManager._signal}),b(this,Ws)&&clearTimeout(b(this,Ws)),G(this,Ws,setTimeout(()=>{G(this,Ws,null),this.canvas.removeEventListener("contextmenu",Oi)},10)),J(this,qA,JQ).call(this,r.offsetX,r.offsetY),this.addToAnnotationStorage(),this.setInBackground()},Lg=new WeakSet,PD=function(){this.canvas=document.createElement("canvas"),this.canvas.width=this.canvas.height=0,this.canvas.className="inkEditorCanvas",this.canvas.setAttribute("data-l10n-id","pdfjs-ink-canvas"),this.div.append(this.canvas),this.ctx=this.canvas.getContext("2d")},Vg=new WeakSet,TD=function(){G(this,Zc,new ResizeObserver(r=>{const n=r[0].contentRect;n.width&&n.height&&this.setDimensions(n.width,n.height)})),b(this,Zc).observe(this.div),this._uiManager._signal.addEventListener("abort",()=>{var r;(r=b(this,Zc))==null||r.disconnect(),G(this,Zc,null)},{once:!0})},Ru=new WeakSet,cy=function(){if(!b(this,dh))return;const[r,n]=this.parentDimensions;this.canvas.width=Math.ceil(this.width*r),this.canvas.height=Math.ceil(this.height*n),J(this,Kg,CD).call(this)},qO=new WeakSet,DB=function(r,n){const o=J(this,Hg,AD).call(this),i=(r-o)/b(this,ch),a=(n-o)/b(this,sh);this.scaleFactor=Math.min(i,a)},Kg=new WeakSet,CD=function(){const r=J(this,Hg,AD).call(this)/2;this.ctx.setTransform(this.scaleFactor,0,0,this.scaleFactor,this.translationX*this.scaleFactor+r,this.translationY*this.scaleFactor+r)},eD=new WeakSet,tZ=function(r){const n=new Path2D;for(let o=0,i=r.length;o<i;o++){const[a,s,c,l]=r[o];o===0&&n.moveTo(...a),n.bezierCurveTo(s[0],s[1],c[0],c[1],l[0],l[1])}return n},JO=new WeakSet,zB=function(r,n,o){const[i,a,s,c]=n;switch(o){case 0:for(let l=0,d=r.length;l<d;l+=2)r[l]+=i,r[l+1]=c-r[l+1];break;case 90:for(let l=0,d=r.length;l<d;l+=2){const h=r[l];r[l]=r[l+1]+i,r[l+1]=h+a}break;case 180:for(let l=0,d=r.length;l<d;l+=2)r[l]=s-r[l],r[l+1]+=a;break;case 270:for(let l=0,d=r.length;l<d;l+=2){const h=r[l];r[l]=s-r[l+1],r[l+1]=c-h}break;default:throw new Error("Invalid rotation")}return r},tD=new WeakSet,rZ=function(r,n,o){const[i,a,s,c]=n;switch(o){case 0:for(let l=0,d=r.length;l<d;l+=2)r[l]-=i,r[l+1]=c-r[l+1];break;case 90:for(let l=0,d=r.length;l<d;l+=2){const h=r[l];r[l]=r[l+1]-a,r[l+1]=h-i}break;case 180:for(let l=0,d=r.length;l<d;l+=2)r[l]=s-r[l],r[l+1]-=a;break;case 270:for(let l=0,d=r.length;l<d;l+=2){const h=r[l];r[l]=c-r[l+1],r[l+1]=s-h}break;default:throw new Error("Invalid rotation")}return r},rD=new WeakSet,nZ=function(r,n,o,i){var d,h;const a=[],s=this.thickness/2,c=r*n+s,l=r*o+s;for(const p of this.paths){const m=[],g=[];for(let y=0,w=p.length;y<w;y++){const[v,O,x,S]=p[y];if(v[0]===S[0]&&v[1]===S[1]&&w===1){const H=r*v[0]+c,X=r*v[1]+l;m.push(H,X),g.push(H,X);break}const j=r*v[0]+c,P=r*v[1]+l,D=r*O[0]+c,M=r*O[1]+l,T=r*x[0]+c,z=r*x[1]+l,A=r*S[0]+c,L=r*S[1]+l;y===0&&(m.push(j,P),g.push(j,P)),m.push(D,M,T,z,A,L),g.push(D,M),y===w-1&&g.push(A,L)}a.push({bezier:J(d=Vr,JO,zB).call(d,m,i,this.rotation),points:J(h=Vr,JO,zB).call(h,g,i,this.rotation)})}return a},QO=new WeakSet,UB=function(){let r=1/0,n=-1/0,o=1/0,i=-1/0;for(const a of this.paths)for(const[s,c,l,d]of a){const h=Ze.bezierBoundingBox(...s,...c,...l,...d);r=Math.min(r,h[0]),o=Math.min(o,h[1]),n=Math.max(n,h[2]),i=Math.max(i,h[3])}return[r,o,n,i]},Hg=new WeakSet,AD=function(){return b(this,ja)?Math.ceil(this.thickness*this.parentScale):0},ph=new WeakSet,vx=function(r=!1){if(this.isEmpty())return;if(!b(this,ja)){J(this,el,Oh).call(this);return}const n=J(this,QO,UB).call(this),o=J(this,Hg,AD).call(this);G(this,ch,Math.max(lr.MIN_SIZE,n[2]-n[0])),G(this,sh,Math.max(lr.MIN_SIZE,n[3]-n[1]));const i=Math.ceil(o+b(this,ch)*this.scaleFactor),a=Math.ceil(o+b(this,sh)*this.scaleFactor),[s,c]=this.parentDimensions;this.width=i/s,this.height=a/c,this.setAspectRatio(i,a);const l=this.translationX,d=this.translationY;this.translationX=-n[0],this.translationY=-n[1],J(this,Ru,cy).call(this),J(this,el,Oh).call(this),G(this,fh,i),G(this,hh,a),this.setDims(i,a);const h=r?o/this.scaleFactor/2:0;this.translate(l-this.translationX-h,d-this.translationY-h)},I(Vr,eD),I(Vr,JO),I(Vr,tD),Je(Vr,"_defaultColor",null),Je(Vr,"_defaultOpacity",1),Je(Vr,"_defaultThickness",1),Je(Vr,"_type","ink"),Je(Vr,"_editorType",Vt.INK);let WF=Vr;const rx=class rx extends lr{constructor(r){super({...r,name:"stampEditor"});I(this,mh);I(this,gh);I(this,Wg);I(this,ex);I(this,nD);I(this,oD);I(this,tx);I(this,Xg);I(this,iD);I(this,Eo,null);I(this,Po,null);I(this,Fu,null);I(this,tl,null);I(this,$u,null);I(this,kg,"");I(this,Xs,null);I(this,rl,null);I(this,Gs,null);I(this,Qa,!1);I(this,ZO,!1);G(this,tl,r.bitmapUrl),G(this,$u,r.bitmapFile)}static initialize(r,n){lr.initialize(r,n)}static get supportedTypes(){return qt(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(n=>`image/${n}`))}static get supportedTypesStr(){return qt(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(r){return this.supportedTypes.includes(r)}static paste(r,n){n.pasteEditor(Vt.STAMP,{bitmapFile:r.getAsFile()})}remove(){var r,n;b(this,Po)&&(G(this,Eo,null),this._uiManager.imageManager.deleteId(b(this,Po)),(r=b(this,Xs))==null||r.remove(),G(this,Xs,null),(n=b(this,rl))==null||n.disconnect(),G(this,rl,null),b(this,Gs)&&(clearTimeout(b(this,Gs)),G(this,Gs,null))),super.remove()}rebuild(){if(!this.parent){b(this,Po)&&J(this,Wg,DD).call(this);return}super.rebuild(),this.div!==null&&(b(this,Po)&&b(this,Xs)===null&&J(this,Wg,DD).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(){this._isDraggable=!0,this.div.focus()}isEmpty(){return!(b(this,Fu)||b(this,Eo)||b(this,tl)||b(this,$u)||b(this,Po))}get isResizable(){return!0}render(){if(this.div)return this.div;let r,n;if(this.width&&(r=this.x,n=this.y),super.render(),this.div.hidden=!0,this.addAltTextButton(),b(this,Eo)?J(this,ex,IB).call(this):J(this,Wg,DD).call(this),this.width){const[o,i]=this.parentDimensions;this.setAt(r*o,n*i,this.width*o,this.height*i)}return this.div}getImageForAltText(){return b(this,Xs)}static deserialize(r,n,o){if(r instanceof cY)return null;const i=super.deserialize(r,n,o),{rect:a,bitmapUrl:s,bitmapId:c,isSvg:l,accessibilityData:d}=r;c&&o.imageManager.isValidId(c)?G(i,Po,c):G(i,tl,s),G(i,Qa,l);const[h,p]=i.pageDimensions;return i.width=(a[2]-a[0])/h,i.height=(a[3]-a[1])/p,d&&(i.altTextData=d),i}serialize(r=!1,n=null){if(this.isEmpty())return null;const o={annotationType:Vt.STAMP,bitmapId:b(this,Po),pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:b(this,Qa),structTreeParentId:this._structTreeParentId};if(r)return o.bitmapUrl=J(this,Xg,zD).call(this,!0),o.accessibilityData=this.altTextData,o;const{decorative:i,altText:a}=this.altTextData;if(!i&&a&&(o.accessibilityData={type:"Figure",alt:a}),n===null)return o;n.stamps||(n.stamps=new Map);const s=b(this,Qa)?(o.rect[2]-o.rect[0])*(o.rect[3]-o.rect[1]):null;if(!n.stamps.has(b(this,Po)))n.stamps.set(b(this,Po),{area:s,serialized:o}),o.bitmap=J(this,Xg,zD).call(this,!1);else if(b(this,Qa)){const c=n.stamps.get(b(this,Po));s>c.area&&(c.area=s,c.serialized.bitmap.close(),c.serialized.bitmap=J(this,Xg,zD).call(this,!1))}return o}};Eo=new WeakMap,Po=new WeakMap,Fu=new WeakMap,tl=new WeakMap,$u=new WeakMap,kg=new WeakMap,Xs=new WeakMap,rl=new WeakMap,Gs=new WeakMap,Qa=new WeakMap,ZO=new WeakMap,mh=new WeakSet,wx=function(r,n=!1){if(!r){this.remove();return}G(this,Eo,r.bitmap),n||(G(this,Po,r.id),G(this,Qa,r.isSvg)),r.file&&G(this,kg,r.file.name),J(this,ex,IB).call(this)},gh=new WeakSet,_x=function(){G(this,Fu,null),this._uiManager.enableWaiting(!1),b(this,Xs)&&this.div.focus()},Wg=new WeakSet,DD=function(){if(b(this,Po)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(b(this,Po)).then(o=>J(this,mh,wx).call(this,o,!0)).finally(()=>J(this,gh,_x).call(this));return}if(b(this,tl)){const o=b(this,tl);G(this,tl,null),this._uiManager.enableWaiting(!0),G(this,Fu,this._uiManager.imageManager.getFromUrl(o).then(i=>J(this,mh,wx).call(this,i)).finally(()=>J(this,gh,_x).call(this)));return}if(b(this,$u)){const o=b(this,$u);G(this,$u,null),this._uiManager.enableWaiting(!0),G(this,Fu,this._uiManager.imageManager.getFromFile(o).then(i=>J(this,mh,wx).call(this,i)).finally(()=>J(this,gh,_x).call(this)));return}const r=document.createElement("input");r.type="file",r.accept=rx.supportedTypesStr;const n=this._uiManager._signal;G(this,Fu,new Promise(o=>{r.addEventListener("change",async()=>{if(!r.files||r.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const i=await this._uiManager.imageManager.getFromFile(r.files[0]);J(this,mh,wx).call(this,i)}o()},{signal:n}),r.addEventListener("cancel",()=>{this.remove(),o()},{signal:n})}).finally(()=>J(this,gh,_x).call(this))),r.click()},ex=new WeakSet,IB=function(){const{div:r}=this;let{width:n,height:o}=b(this,Eo);const[i,a]=this.pageDimensions,s=.75;if(this.width)n=this.width*i,o=this.height*a;else if(n>s*i||o>s*a){const h=Math.min(s*i/n,s*a/o);n*=h,o*=h}const[c,l]=this.parentDimensions;this.setDims(n*c/i,o*l/a),this._uiManager.enableWaiting(!1);const d=G(this,Xs,document.createElement("canvas"));r.append(d),r.hidden=!1,J(this,tx,NB).call(this,n,o),J(this,iD,aZ).call(this),b(this,ZO)||(this.parent.addUndoableEditor(this),G(this,ZO,!0)),this._reportTelemetry({action:"inserted_image"}),b(this,kg)&&d.setAttribute("aria-label",b(this,kg))},nD=new WeakSet,oZ=function(r,n){var s;const[o,i]=this.parentDimensions;this.width=r/o,this.height=n/i,this.setDims(r,n),(s=this._initialOptions)!=null&&s.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,b(this,Gs)!==null&&clearTimeout(b(this,Gs)),G(this,Gs,setTimeout(()=>{G(this,Gs,null),J(this,tx,NB).call(this,r,n)},200))},oD=new WeakSet,iZ=function(r,n){const{width:o,height:i}=b(this,Eo);let a=o,s=i,c=b(this,Eo);for(;a>2*r||s>2*n;){const l=a,d=s;a>2*r&&(a=a>=16384?Math.floor(a/2)-1:Math.ceil(a/2)),s>2*n&&(s=s>=16384?Math.floor(s/2)-1:Math.ceil(s/2));const h=new OffscreenCanvas(a,s);h.getContext("2d").drawImage(c,0,0,l,d,0,0,a,s),c=h.transferToImageBitmap()}return c},tx=new WeakSet,NB=function(r,n){r=Math.ceil(r),n=Math.ceil(n);const o=b(this,Xs);if(!o||o.width===r&&o.height===n)return;o.width=r,o.height=n;const i=b(this,Qa)?b(this,Eo):J(this,oD,iZ).call(this,r,n);if(this._uiManager.hasMLManager&&!this.hasAltText()){const c=new OffscreenCanvas(r,n).getContext("2d");c.drawImage(i,0,0,i.width,i.height,0,0,r,n),this._uiManager.mlGuess({service:"image-to-text",request:{data:c.getImageData(0,0,r,n).data,width:r,height:n,channels:4}}).then(l=>{const d=(l==null?void 0:l.output)||"";this.parent&&d&&!this.hasAltText()&&(this.altTextData={altText:d,decorative:!1})})}const a=o.getContext("2d");a.filter=this._uiManager.hcmFilter,a.drawImage(i,0,0,i.width,i.height,0,0,r,n)},Xg=new WeakSet,zD=function(r){if(r){if(b(this,Qa)){const i=this._uiManager.imageManager.getSvgUrl(b(this,Po));if(i)return i}const n=document.createElement("canvas");return{width:n.width,height:n.height}=b(this,Eo),n.getContext("2d").drawImage(b(this,Eo),0,0),n.toDataURL()}if(b(this,Qa)){const[n,o]=this.pageDimensions,i=Math.round(this.width*n*fu.PDF_TO_CSS_UNITS),a=Math.round(this.height*o*fu.PDF_TO_CSS_UNITS),s=new OffscreenCanvas(i,a);return s.getContext("2d").drawImage(b(this,Eo),0,0,b(this,Eo).width,b(this,Eo).height,0,0,i,a),s.transferToImageBitmap()}return structuredClone(b(this,Eo))},iD=new WeakSet,aZ=function(){this._uiManager._signal&&(G(this,rl,new ResizeObserver(r=>{const n=r[0].contentRect;n.width&&n.height&&J(this,nD,oZ).call(this,n.width,n.height)})),b(this,rl).observe(this.div),this._uiManager._signal.addEventListener("abort",()=>{var r;(r=b(this,rl))==null||r.disconnect(),G(this,rl,null)},{once:!0}))},Je(rx,"_type","stamp"),Je(rx,"_editorType",Vt.STAMP);let XF=rx;const Za=class Za{constructor({uiManager:t,pageIndex:r,div:n,accessibilityManager:o,annotationLayer:i,drawLayer:a,textLayer:s,viewport:c,l10n:l}){I(this,aD);I(this,nx);I(this,ox);I(this,ix);I(this,Jg);I(this,yh,void 0);I(this,Gg,!1);I(this,Ys,null);I(this,bh,null);I(this,nl,null);I(this,ol,null);I(this,il,null);I(this,Ji,new Map);I(this,Bu,!1);I(this,Yg,!1);I(this,qg,!1);I(this,ii,null);I(this,tt,void 0);const d=[...b(Za,Lu).values()];if(!Za._initialized){Za._initialized=!0;for(const h of d)h.initialize(l,t)}t.registerEditorTypes(d),G(this,tt,t),this.pageIndex=r,this.div=n,G(this,yh,o),G(this,Ys,i),this.viewport=c,G(this,ii,s),this.drawLayer=a,b(this,tt).addLayer(this)}get isEmpty(){return b(this,Ji).size===0}get isInvisible(){return this.isEmpty&&b(this,tt).getMode()===Vt.NONE}updateToolbar(t){b(this,tt).updateToolbar(t)}updateMode(t=b(this,tt).getMode()){switch(J(this,Jg,UD).call(this),t){case Vt.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case Vt.INK:this.addInkEditorIfNeeded(!1),this.disableTextSelection(),this.togglePointerEvents(!0),this.disableClick();break;case Vt.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);const{classList:r}=this.div;for(const n of b(Za,Lu).values())r.toggle(`${n._type}Editing`,t===n._editorType);this.div.hidden=!1}hasTextLayer(t){var r;return t===((r=b(this,ii))==null?void 0:r.div)}addInkEditorIfNeeded(t){if(b(this,tt).getMode()!==Vt.INK)return;if(!t){for(const n of b(this,Ji).values())if(n.isEmpty()){n.setInBackground();return}}this.createAndAddNewEditor({offsetX:0,offsetY:0},!1).setInBackground()}setEditingState(t){b(this,tt).setEditingState(t)}addCommands(t){b(this,tt).addCommands(t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){var r;(r=b(this,Ys))==null||r.div.classList.toggle("disabled",!t)}enable(){this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const n of b(this,Ji).values())n.enableEditing(),n.show(!0),n.annotationElementId&&(b(this,tt).removeChangedExistingAnnotation(n),t.add(n.annotationElementId));if(!b(this,Ys))return;const r=b(this,Ys).getEditableAnnotations();for(const n of r){if(n.hide(),b(this,tt).isDeletedAnnotationElement(n.data.id)||t.has(n.data.id))continue;const o=this.deserialize(n);o&&(this.addOrRebuild(o),o.enableEditing())}}disable(){var o;G(this,qg,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,r=new Map;for(const i of b(this,Ji).values())if(i.disableEditing(),!!i.annotationElementId){if(i.serialize()!==null){t.set(i.annotationElementId,i);continue}else r.set(i.annotationElementId,i);(o=this.getEditableAnnotation(i.annotationElementId))==null||o.show(),i.remove()}if(b(this,Ys)){const i=b(this,Ys).getEditableAnnotations();for(const a of i){const{id:s}=a.data;if(b(this,tt).isDeletedAnnotationElement(s))continue;let c=r.get(s);if(c){c.resetAnnotationElement(a),c.show(!1),a.show();continue}c=t.get(s),c&&(b(this,tt).addChangedExistingAnnotation(c),c.renderAnnotationElement(a),c.show(!1)),a.show()}}J(this,Jg,UD).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:n}=this.div;for(const i of b(Za,Lu).values())n.remove(`${i._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),G(this,qg,!1)}getEditableAnnotation(t){var r;return((r=b(this,Ys))==null?void 0:r.getEditableAnnotation(t))||null}setActiveEditor(t){b(this,tt).getActive()!==t&&b(this,tt).setActiveEditor(t)}enableTextSelection(){var t;this.div.tabIndex=-1,(t=b(this,ii))!=null&&t.div&&!b(this,ol)&&(G(this,ol,J(this,aD,sZ).bind(this)),b(this,ii).div.addEventListener("pointerdown",b(this,ol),{signal:b(this,tt)._signal}),b(this,ii).div.classList.add("highlighting"))}disableTextSelection(){var t;this.div.tabIndex=0,(t=b(this,ii))!=null&&t.div&&b(this,ol)&&(b(this,ii).div.removeEventListener("pointerdown",b(this,ol)),G(this,ol,null),b(this,ii).div.classList.remove("highlighting"))}enableClick(){if(b(this,nl))return;const t=b(this,tt)._signal;G(this,nl,this.pointerdown.bind(this)),G(this,bh,this.pointerup.bind(this)),this.div.addEventListener("pointerdown",b(this,nl),{signal:t}),this.div.addEventListener("pointerup",b(this,bh),{signal:t})}disableClick(){b(this,nl)&&(this.div.removeEventListener("pointerdown",b(this,nl)),this.div.removeEventListener("pointerup",b(this,bh)),G(this,nl,null),G(this,bh,null))}attach(t){b(this,Ji).set(t.id,t);const{annotationElementId:r}=t;r&&b(this,tt).isDeletedAnnotationElement(r)&&b(this,tt).removeDeletedAnnotationElement(t)}detach(t){var r;b(this,Ji).delete(t.id),(r=b(this,yh))==null||r.removePointerInTextLayer(t.contentDiv),!b(this,qg)&&t.annotationElementId&&b(this,tt).addDeletedAnnotationElement(t)}remove(t){this.detach(t),b(this,tt).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1,b(this,Yg)||this.addInkEditorIfNeeded(!1)}changeParent(t){var r;t.parent!==this&&(t.parent&&t.annotationElementId&&(b(this,tt).addDeletedAnnotationElement(t.annotationElementId),lr.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),(r=t.parent)==null||r.detach(t),t.setParent(this),t.div&&t.isAttachedToDOM&&(t.div.remove(),this.div.append(t.div)))}add(t){if(!(t.parent===this&&t.isAttachedToDOM)){if(this.changeParent(t),b(this,tt).addEditor(t),this.attach(t),!t.isAttachedToDOM){const r=t.render();this.div.append(r),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(),b(this,tt).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var n;if(!t.isAttachedToDOM)return;const{activeElement:r}=document;t.div.contains(r)&&!b(this,il)&&(t._focusEventsAllowed=!1,G(this,il,setTimeout(()=>{G(this,il,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:b(this,tt)._signal}),r.focus())},0))),t._structTreeParentId=(n=b(this,yh))==null?void 0:n.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){t.needsToBeRebuilt()?(t.parent||(t.parent=this),t.rebuild(),t.show()):this.add(t)}addUndoableEditor(t){const r=()=>t._uiManager.rebuild(t),n=()=>{t.remove()};this.addCommands({cmd:r,undo:n,mustExec:!1})}getNextId(){return b(this,tt).getId()}get _signal(){return b(this,tt)._signal}canCreateNewEmptyEditor(){var t;return(t=b(this,nx,RB))==null?void 0:t.canCreateNewEmptyEditor()}pasteEditor(t,r){b(this,tt).updateToolbar(t),b(this,tt).updateMode(t);const{offsetX:n,offsetY:o}=J(this,ix,$B).call(this),i=this.getNextId(),a=J(this,ox,FB).call(this,{parent:this,id:i,x:n,y:o,uiManager:b(this,tt),isCentered:!0,...r});a&&this.add(a)}deserialize(t){var r;return((r=b(Za,Lu).get(t.annotationType??t.annotationEditorType))==null?void 0:r.deserialize(t,this,b(this,tt)))||null}createAndAddNewEditor(t,r,n={}){const o=this.getNextId(),i=J(this,ox,FB).call(this,{parent:this,id:o,x:t.offsetX,y:t.offsetY,uiManager:b(this,tt),isCentered:r,...n});return i&&this.add(i),i}addNewEditor(){this.createAndAddNewEditor(J(this,ix,$B).call(this),!0)}setSelected(t){b(this,tt).setSelected(t)}toggleSelected(t){b(this,tt).toggleSelected(t)}isSelected(t){return b(this,tt).isSelected(t)}unselect(t){b(this,tt).unselect(t)}pointerup(t){const{isMac:r}=_i.platform;if(!(t.button!==0||t.ctrlKey&&r)&&t.target===this.div&&b(this,Bu)){if(G(this,Bu,!1),!b(this,Gg)){G(this,Gg,!0);return}if(b(this,tt).getMode()===Vt.STAMP){b(this,tt).unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){if(b(this,tt).getMode()===Vt.HIGHLIGHT&&this.enableTextSelection(),b(this,Bu)){G(this,Bu,!1);return}const{isMac:r}=_i.platform;if(t.button!==0||t.ctrlKey&&r||t.target!==this.div)return;G(this,Bu,!0);const n=b(this,tt).getActive();G(this,Gg,!n||n.isEmpty())}findNewParent(t,r,n){const o=b(this,tt).findParent(r,n);return o===null||o===this?!1:(o.changeParent(t),!0)}destroy(){var t,r;((t=b(this,tt).getActive())==null?void 0:t.parent)===this&&(b(this,tt).commitOrRemove(),b(this,tt).setActiveEditor(null)),b(this,il)&&(clearTimeout(b(this,il)),G(this,il,null));for(const n of b(this,Ji).values())(r=b(this,yh))==null||r.removePointerInTextLayer(n.contentDiv),n.setParent(null),n.isAttachedToDOM=!1,n.div.remove();this.div=null,b(this,Ji).clear(),b(this,tt).removeLayer(this)}render({viewport:t}){this.viewport=t,ef(this.div,t);for(const r of b(this,tt).getEditors(this.pageIndex))this.add(r),r.rebuild();this.updateMode()}update({viewport:t}){b(this,tt).commitOrRemove(),J(this,Jg,UD).call(this);const r=this.viewport.rotation,n=t.rotation;if(this.viewport=t,ef(this.div,{rotation:n}),r!==n)for(const o of b(this,Ji).values())o.rotate(n);this.addInkEditorIfNeeded(!1)}get pageDimensions(){const{pageWidth:t,pageHeight:r}=this.viewport.rawDims;return[t,r]}get scale(){return b(this,tt).viewParameters.realScale}};yh=new WeakMap,Gg=new WeakMap,Ys=new WeakMap,bh=new WeakMap,nl=new WeakMap,ol=new WeakMap,il=new WeakMap,Ji=new WeakMap,Bu=new WeakMap,Yg=new WeakMap,qg=new WeakMap,ii=new WeakMap,tt=new WeakMap,Lu=new WeakMap,aD=new WeakSet,sZ=function(t){if(b(this,tt).unselectAll(),t.target===b(this,ii).div){const{isMac:r}=_i.platform;if(t.button!==0||t.ctrlKey&&r)return;b(this,tt).showAllEditors("highlight",!0,!0),b(this,ii).div.classList.add("free"),QT.startHighlighting(this,b(this,tt).direction==="ltr",t),b(this,ii).div.addEventListener("pointerup",()=>{b(this,ii).div.classList.remove("free")},{once:!0,signal:b(this,tt)._signal}),t.preventDefault()}},nx=new WeakSet,RB=function(){return b(Za,Lu).get(b(this,tt).getMode())},ox=new WeakSet,FB=function(t){const r=b(this,nx,RB);return r?new r.prototype.constructor(t):null},ix=new WeakSet,$B=function(){const{x:t,y:r,width:n,height:o}=this.div.getBoundingClientRect(),i=Math.max(0,t),a=Math.max(0,r),s=Math.min(window.innerWidth,t+n),c=Math.min(window.innerHeight,r+o),l=(i+s)/2-t,d=(a+c)/2-r,[h,p]=this.viewport.rotation%180===0?[l,d]:[d,l];return{offsetX:h,offsetY:p}},Jg=new WeakSet,UD=function(){G(this,Yg,!0);for(const t of b(this,Ji).values())t.isEmpty()&&t.remove();G(this,Yg,!1)},Je(Za,"_initialized",!1),I(Za,Lu,new Map([KF,WF,XF,QT].map(t=>[t._editorType,t])));let GF=Za;const To=class To{constructor({pageIndex:t}){I(this,cx);I(this,sD);I(this,qs,null);I(this,ax,0);I(this,Xn,new Map);I(this,Vu,new Map);this.pageIndex=t}setParent(t){if(!b(this,qs)){G(this,qs,t);return}if(b(this,qs)!==t){if(b(this,Xn).size>0)for(const r of b(this,Xn).values())r.remove(),t.append(r);G(this,qs,t)}}static get _svgFactory(){return qt(this,"_svgFactory",new OF)}highlight(t,r,n,o=!1){const i=Zi(this,ax)._++,a=J(this,cx,LB).call(this,t.box);a.classList.add("highlight"),t.free&&a.classList.add("free");const s=To._svgFactory.createElement("defs");a.append(s);const c=To._svgFactory.createElement("path");s.append(c);const l=`path_p${this.pageIndex}_${i}`;c.setAttribute("id",l),c.setAttribute("d",t.toSVGPath()),o&&b(this,Vu).set(i,c);const d=J(this,sD,cZ).call(this,s,l),h=To._svgFactory.createElement("use");return a.append(h),a.setAttribute("fill",r),a.setAttribute("fill-opacity",n),h.setAttribute("href",`#${l}`),b(this,Xn).set(i,a),{id:i,clipPathId:`url(#${d})`}}highlightOutline(t){const r=Zi(this,ax)._++,n=J(this,cx,LB).call(this,t.box);n.classList.add("highlightOutline");const o=To._svgFactory.createElement("defs");n.append(o);const i=To._svgFactory.createElement("path");o.append(i);const a=`path_p${this.pageIndex}_${r}`;i.setAttribute("id",a),i.setAttribute("d",t.toSVGPath()),i.setAttribute("vector-effect","non-scaling-stroke");let s;if(t.free){n.classList.add("free");const d=To._svgFactory.createElement("mask");o.append(d),s=`mask_p${this.pageIndex}_${r}`,d.setAttribute("id",s),d.setAttribute("maskUnits","objectBoundingBox");const h=To._svgFactory.createElement("rect");d.append(h),h.setAttribute("width","1"),h.setAttribute("height","1"),h.setAttribute("fill","white");const p=To._svgFactory.createElement("use");d.append(p),p.setAttribute("href",`#${a}`),p.setAttribute("stroke","none"),p.setAttribute("fill","black"),p.setAttribute("fill-rule","nonzero"),p.classList.add("mask")}const c=To._svgFactory.createElement("use");n.append(c),c.setAttribute("href",`#${a}`),s&&c.setAttribute("mask",`url(#${s})`);const l=c.cloneNode();return n.append(l),c.classList.add("mainOutline"),l.classList.add("secondaryOutline"),b(this,Xn).set(r,n),r}finalizeLine(t,r){const n=b(this,Vu).get(t);b(this,Vu).delete(t),this.updateBox(t,r.box),n.setAttribute("d",r.toSVGPath())}updateLine(t,r){b(this,Xn).get(t).firstChild.firstChild.setAttribute("d",r.toSVGPath())}removeFreeHighlight(t){this.remove(t),b(this,Vu).delete(t)}updatePath(t,r){b(this,Vu).get(t).setAttribute("d",r.toSVGPath())}updateBox(t,r){var n;J(n=To,sx,BB).call(n,b(this,Xn).get(t),r)}show(t,r){b(this,Xn).get(t).classList.toggle("hidden",!r)}rotate(t,r){b(this,Xn).get(t).setAttribute("data-main-rotation",r)}changeColor(t,r){b(this,Xn).get(t).setAttribute("fill",r)}changeOpacity(t,r){b(this,Xn).get(t).setAttribute("fill-opacity",r)}addClass(t,r){b(this,Xn).get(t).classList.add(r)}removeClass(t,r){b(this,Xn).get(t).classList.remove(r)}remove(t){b(this,qs)!==null&&(b(this,Xn).get(t).remove(),b(this,Xn).delete(t))}destroy(){G(this,qs,null);for(const t of b(this,Xn).values())t.remove();b(this,Xn).clear()}};qs=new WeakMap,ax=new WeakMap,Xn=new WeakMap,Vu=new WeakMap,sx=new WeakSet,BB=function(t,{x:r=0,y:n=0,width:o=1,height:i=1}={}){const{style:a}=t;a.top=`${100*n}%`,a.left=`${100*r}%`,a.width=`${100*o}%`,a.height=`${100*i}%`},cx=new WeakSet,LB=function(t){var n;const r=To._svgFactory.create(1,1,!0);return b(this,qs).append(r),r.setAttribute("aria-hidden",!0),J(n=To,sx,BB).call(n,r,t),r},sD=new WeakSet,cZ=function(t,r){const n=To._svgFactory.createElement("clipPath");t.append(n);const o=`clip_${r}`;n.setAttribute("id",o),n.setAttribute("clipPathUnits","objectBoundingBox");const i=To._svgFactory.createElement("use");return n.append(i),i.setAttribute("href",`#${r}`),i.classList.add("clip"),o},I(To,sx);let YF=To;var a6e=ft.AbortException,s6e=ft.AnnotationEditorLayer,c6e=ft.AnnotationEditorParamsType,l6e=ft.AnnotationEditorType,u6e=ft.AnnotationEditorUIManager,uY=ft.AnnotationLayer,dY=ft.AnnotationMode,d6e=ft.CMapCompressionType,f6e=ft.ColorPicker,h6e=ft.DOMSVGFactory,p6e=ft.DrawLayer,m6e=ft.FeatureTest,qF=ft.GlobalWorkerOptions,g6e=ft.ImageKind,y6e=ft.InvalidPDFException,b6e=ft.MissingPDFException,v6e=ft.OPS,w6e=ft.Outliner,_6e=ft.PDFDataRangeTransport,O6e=ft.PDFDateString,x6e=ft.PDFWorker,j6e=ft.PasswordResponses,M6e=ft.PermissionFlag,S6e=ft.PixelsPerInch,E6e=ft.RenderingCancelledException,fY=ft.TextLayer,P6e=ft.UnexpectedResponseException,T6e=ft.Util,C6e=ft.VerbosityLevel,A6e=ft.XfaLayer,D6e=ft.build,z6e=ft.createValidAbsoluteUrl,U6e=ft.fetchData,hY=ft.getDocument,I6e=ft.getFilenameFromUrl,N6e=ft.getPdfFilenameFromUrl,R6e=ft.getXfaPageViewport,F6e=ft.isDataScheme,$6e=ft.isPdfFile,B6e=ft.noContextMenu,L6e=ft.normalizeUnicode,V6e=ft.renderTextLayer,K6e=ft.setLayerDimensions,H6e=ft.shadow,k6e=ft.updateTextLayer,pY=ft.version;const W6e=Object.freeze(Object.defineProperty({__proto__:null,AbortException:a6e,AnnotationEditorLayer:s6e,AnnotationEditorParamsType:c6e,AnnotationEditorType:l6e,AnnotationEditorUIManager:u6e,AnnotationLayer:uY,AnnotationMode:dY,CMapCompressionType:d6e,ColorPicker:f6e,DOMSVGFactory:h6e,DrawLayer:p6e,FeatureTest:m6e,GlobalWorkerOptions:qF,ImageKind:g6e,InvalidPDFException:y6e,MissingPDFException:b6e,OPS:v6e,Outliner:w6e,PDFDataRangeTransport:_6e,PDFDateString:O6e,PDFWorker:x6e,PasswordResponses:j6e,PermissionFlag:M6e,PixelsPerInch:S6e,RenderingCancelledException:E6e,TextLayer:fY,UnexpectedResponseException:P6e,Util:T6e,VerbosityLevel:C6e,XfaLayer:A6e,build:D6e,createValidAbsoluteUrl:z6e,fetchData:U6e,getDocument:hY,getFilenameFromUrl:I6e,getPdfFilenameFromUrl:N6e,getXfaPageViewport:R6e,isDataScheme:F6e,isPdfFile:$6e,noContextMenu:B6e,normalizeUnicode:L6e,renderTextLayer:V6e,setLayerDimensions:K6e,shadow:H6e,updateTextLayer:k6e,version:pY},Symbol.toStringTag,{value:"Module"}));var ao=function(e,t,r){if(r||arguments.length===2)for(var n=0,o=t.length,i;n<o;n++)(i||!(n in t))&&(i||(i=Array.prototype.slice.call(t,0,n)),i[n]=t[n]);return e.concat(i||Array.prototype.slice.call(t))},X6e=["onCopy","onCut","onPaste"],G6e=["onCompositionEnd","onCompositionStart","onCompositionUpdate"],Y6e=["onFocus","onBlur"],q6e=["onInput","onInvalid","onReset","onSubmit"],J6e=["onLoad","onError"],Q6e=["onKeyDown","onKeyPress","onKeyUp"],Z6e=["onAbort","onCanPlay","onCanPlayThrough","onDurationChange","onEmptied","onEncrypted","onEnded","onError","onLoadedData","onLoadedMetadata","onLoadStart","onPause","onPlay","onPlaying","onProgress","onRateChange","onSeeked","onSeeking","onStalled","onSuspend","onTimeUpdate","onVolumeChange","onWaiting"],e8e=["onClick","onContextMenu","onDoubleClick","onMouseDown","onMouseEnter","onMouseLeave","onMouseMove","onMouseOut","onMouseOver","onMouseUp"],t8e=["onDrag","onDragEnd","onDragEnter","onDragExit","onDragLeave","onDragOver","onDragStart","onDrop"],r8e=["onSelect"],n8e=["onTouchCancel","onTouchEnd","onTouchMove","onTouchStart"],o8e=["onPointerDown","onPointerMove","onPointerUp","onPointerCancel","onGotPointerCapture","onLostPointerCapture","onPointerEnter","onPointerLeave","onPointerOver","onPointerOut"],i8e=["onScroll"],a8e=["onWheel"],s8e=["onAnimationStart","onAnimationEnd","onAnimationIteration"],c8e=["onTransitionEnd"],l8e=["onToggle"],u8e=["onChange"],d8e=ao(ao(ao(ao(ao(ao(ao(ao(ao(ao(ao(ao(ao(ao(ao(ao(ao(ao([],X6e,!0),G6e,!0),Y6e,!0),q6e,!0),J6e,!0),Q6e,!0),Z6e,!0),e8e,!0),t8e,!0),r8e,!0),n8e,!0),o8e,!0),i8e,!0),a8e,!0),s8e,!0),c8e,!0),u8e,!0),l8e,!0);function mY(e,t){var r={};return d8e.forEach(function(n){var o=e[n];o&&(t?r[n]=function(i){return o(i,t(n))}:r[n]=o)}),r}function $_(e){var t=!1,r=new Promise(function(n,o){e.then(function(i){return!t&&n(i)}).catch(function(i){return!t&&o(i)})});return{promise:r,cancel:function(){t=!0}}}function gY(e){var t,r,n="";if(typeof e=="string"||typeof e=="number")n+=e;else if(typeof e=="object")if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(r=gY(e[t]))&&(n&&(n+=" "),n+=r)}else for(r in e)e[r]&&(n&&(n+=" "),n+=r);return n}function ZT(){for(var e,t,r=0,n="",o=arguments.length;r<o;r++)(e=arguments[r])&&(t=gY(e))&&(n&&(n+=" "),n+=t);return n}var f8e="Invariant failed";function Er(e,t){if(!e)throw new Error(f8e)}var yY=Object.prototype.hasOwnProperty;function bY(e,t,r){for(r of e.keys())if(Em(r,t))return r}function Em(e,t){var r,n,o;if(e===t)return!0;if(e&&t&&(r=e.constructor)===t.constructor){if(r===Date)return e.getTime()===t.getTime();if(r===RegExp)return e.toString()===t.toString();if(r===Array){if((n=e.length)===t.length)for(;n--&&Em(e[n],t[n]););return n===-1}if(r===Set){if(e.size!==t.size)return!1;for(n of e)if(o=n,o&&typeof o=="object"&&(o=bY(t,o),!o)||!t.has(o))return!1;return!0}if(r===Map){if(e.size!==t.size)return!1;for(n of e)if(o=n[0],o&&typeof o=="object"&&(o=bY(t,o),!o)||!Em(n[1],t.get(o)))return!1;return!0}if(r===ArrayBuffer)e=new Uint8Array(e),t=new Uint8Array(t);else if(r===DataView){if((n=e.byteLength)===t.byteLength)for(;n--&&e.getInt8(n)===t.getInt8(n););return n===-1}if(ArrayBuffer.isView(e)){if((n=e.byteLength)===t.byteLength)for(;n--&&e[n]===t[n];);return n===-1}if(!r||typeof e=="object"){n=0;for(r in e)if(yY.call(e,r)&&++n&&!yY.call(t,r)||!(r in t)||!Em(e[r],t[r]))return!1;return Object.keys(t).length===n}}return e!==e&&t!==t}const vY=_.createContext(null);function Pm({children:e,type:t}){return f.jsx("div",{className:`react-pdf__message react-pdf__message--${t}`,children:e})}const h8e="noopener noreferrer nofollow";class p8e{constructor(){this.externalLinkEnabled=!0,this.externalLinkRel=void 0,this.externalLinkTarget=void 0,this.isInPresentationMode=!1,this.pdfDocument=void 0,this.pdfViewer=void 0}setDocument(t){this.pdfDocument=t}setViewer(t){this.pdfViewer=t}setExternalLinkRel(t){this.externalLinkRel=t}setExternalLinkTarget(t){this.externalLinkTarget=t}setHistory(){}get pagesCount(){return this.pdfDocument?this.pdfDocument.numPages:0}get page(){return Er(this.pdfViewer),this.pdfViewer.currentPageNumber||0}set page(t){Er(this.pdfViewer),this.pdfViewer.currentPageNumber=t}get rotation(){return 0}set rotation(t){}goToDestination(t){return new Promise(r=>{Er(this.pdfDocument),Er(t),typeof t=="string"?this.pdfDocument.getDestination(t).then(r):Array.isArray(t)?r(t):t.then(r)}).then(r=>{Er(Array.isArray(r));const n=r[0];new Promise(o=>{Er(this.pdfDocument),n instanceof Object?this.pdfDocument.getPageIndex(n).then(i=>{o(i)}).catch(()=>{Er(!1)}):typeof n=="number"?o(n):Er(!1)}).then(o=>{const i=o+1;Er(this.pdfViewer),Er(i>=1&&i<=this.pagesCount),this.pdfViewer.scrollPageIntoView({dest:r,pageIndex:o,pageNumber:i})})})}navigateTo(t){this.goToDestination(t)}goToPage(t){const r=t-1;Er(this.pdfViewer),Er(t>=1&&t<=this.pagesCount),this.pdfViewer.scrollPageIntoView({pageIndex:r,pageNumber:t})}addLinkAttributes(t,r,n){t.href=r,t.rel=this.externalLinkRel||h8e,t.target=n?"_blank":this.externalLinkTarget||""}getDestinationHash(){return"#"}getAnchorUrl(){return"#"}setHash(){}executeNamedAction(){}cachePageRef(){}isPageVisible(){return!0}isPageCached(){return!0}executeSetOCGState(){}}const wY={NEED_PASSWORD:1,INCORRECT_PASSWORD:2},eC=typeof document<"u",_Y=eC&&window.location.protocol==="file:";function m8e(e){return typeof e<"u"}function of(e){return m8e(e)&&e!==null}function g8e(e){return typeof e=="string"}function y8e(e){return e instanceof ArrayBuffer}function b8e(e){return Er(eC),e instanceof Blob}function JF(e){return g8e(e)&&/^data:/.test(e)}function OY(e){Er(JF(e));const[t="",r=""]=e.split(",");return t.split(";").indexOf("base64")!==-1?atob(r):unescape(r)}function v8e(){return eC&&window.devicePixelRatio||1}const xY="On Chromium based browsers, you can use --allow-file-access-from-files flag for debugging purposes.";function jY(){wo(!_Y,`Loading PDF as base64 strings/URLs may not work on protocols other than HTTP/HTTPS. ${xY}`)}function w8e(){wo(!_Y,`Loading PDF.js worker may not work on protocols other than HTTP/HTTPS. ${xY}`)}function af(e){e!=null&&e.cancel&&e.cancel()}function QF(e,t){return Object.defineProperty(e,"width",{get(){return this.view[2]*t},configurable:!0}),Object.defineProperty(e,"height",{get(){return this.view[3]*t},configurable:!0}),Object.defineProperty(e,"originalWidth",{get(){return this.view[2]},configurable:!0}),Object.defineProperty(e,"originalHeight",{get(){return this.view[3]},configurable:!0}),e}function _8e(e){return e.name==="RenderingCancelledException"}function O8e(e){return new Promise((t,r)=>{const n=new FileReader;n.onload=()=>{if(!n.result)return r(new Error("Error while reading a file."));t(n.result)},n.onerror=o=>{if(!o.target)return r(new Error("Error while reading a file."));const{error:i}=o.target;if(!i)return r(new Error("Error while reading a file."));switch(i.code){case i.NOT_FOUND_ERR:return r(new Error("Error while reading a file: File not found."));case i.SECURITY_ERR:return r(new Error("Error while reading a file: Security error."));case i.ABORT_ERR:return r(new Error("Error while reading a file: Aborted."));default:return r(new Error("Error while reading a file."))}},n.readAsArrayBuffer(e)})}function x8e(e,t){switch(t.type){case"RESOLVE":return{value:t.value,error:void 0};case"REJECT":return{value:!1,error:t.error};case"RESET":return{value:void 0,error:void 0};default:return e}}function Tm(){return _.useReducer(x8e,{value:void 0,error:void 0})}var j8e=function(e,t,r,n){function o(i){return i instanceof r?i:new r(function(a){a(i)})}return new(r||(r=Promise))(function(i,a){function s(d){try{l(n.next(d))}catch(h){a(h)}}function c(d){try{l(n.throw(d))}catch(h){a(h)}}function l(d){d.done?i(d.value):o(d.value).then(s,c)}l((n=n.apply(e,t||[])).next())})},MY=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]]);return r};const{PDFDataRangeTransport:M8e}=W6e,S8e=(e,t)=>{switch(t){case wY.NEED_PASSWORD:{const r=prompt("Enter the password to open this PDF file.");e(r);break}case wY.INCORRECT_PASSWORD:{const r=prompt("Invalid password. Please try again.");e(r);break}}};function SY(e){return typeof e=="object"&&e!==null&&("data"in e||"range"in e||"url"in e)}const E8e=_.forwardRef(function(t,r){var{children:n,className:o,error:i="Failed to load PDF file.",externalLinkRel:a,externalLinkTarget:s,file:c,inputRef:l,imageResourcesPath:d,loading:h="Loading PDF…",noData:p="No PDF file specified.",onItemClick:m,onLoadError:g,onLoadProgress:y,onLoadSuccess:w,onPassword:v=S8e,onSourceError:O,onSourceSuccess:x,options:S,renderMode:j,rotate:P}=t,D=MY(t,["children","className","error","externalLinkRel","externalLinkTarget","file","inputRef","imageResourcesPath","loading","noData","onItemClick","onLoadError","onLoadProgress","onLoadSuccess","onPassword","onSourceError","onSourceSuccess","options","renderMode","rotate"]);const[M,T]=Tm(),{value:z,error:A}=M,[L,H]=Tm(),{value:X,error:K}=L,W=_.useRef(new p8e),$=_.useRef([]),Z=_.useRef(void 0),re=_.useRef(void 0);c&&c!==Z.current&&SY(c)&&(wo(!Em(c,Z.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.`),Z.current=c),S&&S!==re.current&&(wo(!Em(S,re.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.`),re.current=S);const B=_.useRef({scrollPageIntoView:ye=>{const{dest:je,pageNumber:Ee,pageIndex:Se=Ee-1}=ye;if(m){m({dest:je,pageIndex:Se,pageNumber:Ee});return}const Te=$.current[Se];if(Te){Te.scrollIntoView();return}wo(!1,`An internal link leading to page ${Ee} 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>.`)}});_.useImperativeHandle(r,()=>({linkService:W,pages:$,viewer:B}),[]);function ce(){x&&x()}function F(){A&&(wo(!1,A.toString()),O&&O(A))}function oe(){T({type:"RESET"})}_.useEffect(oe,[c,T]);const ie=_.useCallback(()=>j8e(this,void 0,void 0,function*(){if(!c)return null;if(typeof c=="string")return JF(c)?{data:OY(c)}:(jY(),{url:c});if(c instanceof M8e)return{range:c};if(y8e(c))return{data:c};if(eC&&b8e(c))return{data:yield O8e(c)};if(Er(typeof c=="object"),Er(SY(c)),"url"in c&&typeof c.url=="string"){if(JF(c.url)){const{url:ye}=c,je=MY(c,["url"]),Ee=OY(ye);return Object.assign({data:Ee},je)}jY()}return c}),[c]);_.useEffect(()=>{const ye=$_(ie());return ye.promise.then(je=>{T({type:"RESOLVE",value:je})}).catch(je=>{T({type:"REJECT",error:je})}),()=>{af(ye)}},[ie,T]),_.useEffect(()=>{if(!(typeof z>"u")){if(z===!1){F();return}ce()}},[z]);function le(){X&&(w&&w(X),$.current=new Array(X.numPages),W.current.setDocument(X))}function Y(){K&&(wo(!1,K.toString()),g&&g(K))}_.useEffect(function(){H({type:"RESET"})},[H,z]),_.useEffect(function(){if(!z)return;const je=Object.assign(Object.assign({},z),S),Ee=hY(je);y&&(Ee.onProgress=y),v&&(Ee.onPassword=v);const Se=Ee;return Se.promise.then(Te=>{H({type:"RESOLVE",value:Te})}).catch(Te=>{Se.destroyed||H({type:"REJECT",error:Te})}),()=>{Se.destroy()}},[S,H,z]),_.useEffect(()=>{if(!(typeof X>"u")){if(X===!1){Y();return}le()}},[X]),_.useEffect(function(){W.current.setViewer(B.current),W.current.setExternalLinkRel(a),W.current.setExternalLinkTarget(s)},[a,s]);const N=_.useCallback((ye,je)=>{$.current[ye]=je},[]),q=_.useCallback(ye=>{delete $.current[ye]},[]),te=_.useMemo(()=>({imageResourcesPath:d,linkService:W.current,onItemClick:m,pdf:X,registerPage:N,renderMode:j,rotate:P,unregisterPage:q}),[d,m,X,N,j,P,q]),fe=_.useMemo(()=>mY(D,()=>X),[D,X]);function R(){return f.jsx(vY.Provider,{value:te,children:n})}function k(){return c?X==null?f.jsx(Pm,{type:"loading",children:typeof h=="function"?h():h}):X===!1?f.jsx(Pm,{type:"error",children:typeof i=="function"?i():i}):R():f.jsx(Pm,{type:"no-data",children:typeof p=="function"?p():p})}return f.jsx("div",Object.assign({className:ZT("react-pdf__Document",o),ref:l,style:{"--scale-factor":"1"}},fe,{children:k()}))});function EY(){return _.useContext(vY)}function PY(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r=e.filter(Boolean);if(r.length<=1){var n=r[0];return n||null}return function(i){r.forEach(function(a){typeof a=="function"?a(i):a&&(a.current=i)})}}const TY=_.createContext(null),CY={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},P8e=/^H(\d+)$/;function T8e(e){return e in CY}function tC(e){return"children"in e}function AY(e){return tC(e)?e.children.length===1&&0 in e.children&&"id"in e.children[0]:!1}function C8e(e){const t={};if(tC(e)){const{role:r}=e,n=r.match(P8e);if(n)t.role="heading",t["aria-level"]=Number(n[1]);else if(T8e(r)){const o=CY[r];o&&(t.role=o)}}return t}function DY(e){const t={};if(tC(e)){if(e.alt!==void 0&&(t["aria-label"]=e.alt),e.lang!==void 0&&(t.lang=e.lang),AY(e)){const[r]=e.children;if(r){const n=DY(r);return Object.assign(Object.assign({},t),n)}}}else"id"in e&&(t["aria-owns"]=e.id);return t}function A8e(e){return e?Object.assign(Object.assign({},C8e(e)),DY(e)):null}function zY({className:e,node:t}){const r=_.useMemo(()=>A8e(t),[t]),n=_.useMemo(()=>!tC(t)||AY(t)?null:t.children.map((o,i)=>f.jsx(zY,{node:o},i)),[t]);return f.jsx("span",Object.assign({className:e},r,{children:n}))}function rC(){return _.useContext(TY)}function D8e(){const e=rC();Er(e);const{onGetStructTreeError:t,onGetStructTreeSuccess:r}=e,[n,o]=Tm(),{value:i,error:a}=n,{customTextRenderer:s,page:c}=e;function l(){i&&r&&r(i)}function d(){a&&(wo(!1,a.toString()),t&&t(a))}return _.useEffect(function(){o({type:"RESET"})},[o,c]),_.useEffect(function(){if(s||!c)return;const p=$_(c.getStructTree()),m=p;return p.promise.then(g=>{o({type:"RESOLVE",value:g})}).catch(g=>{o({type:"REJECT",error:g})}),()=>af(m)},[s,c,o]),_.useEffect(()=>{if(i!==void 0){if(i===!1){d();return}l()}},[i]),i?f.jsx(zY,{className:"react-pdf__Page__structTree structTree",node:i}):null}const UY=dY;function z8e(e){const t=rC();Er(t);const r=Object.assign(Object.assign({},t),e),{_className:n,canvasBackground:o,devicePixelRatio:i=v8e(),onRenderError:a,onRenderSuccess:s,page:c,renderForms:l,renderTextLayer:d,rotate:h,scale:p}=r,{canvasRef:m}=e;Er(c);const g=_.useRef(null);function y(){c&&s&&s(QF(c,p))}function w(S){_8e(S)||(wo(!1,S.toString()),a&&a(S))}const v=_.useMemo(()=>c.getViewport({scale:p*i,rotation:h}),[i,c,h,p]),O=_.useMemo(()=>c.getViewport({scale:p,rotation:h}),[c,h,p]);_.useEffect(function(){if(!c)return;c.cleanup();const{current:j}=g;if(!j)return;j.width=v.width,j.height=v.height,j.style.width=`${Math.floor(O.width)}px`,j.style.height=`${Math.floor(O.height)}px`,j.style.visibility="hidden";const P={annotationMode:l?UY.ENABLE_FORMS:UY.ENABLE,canvasContext:j.getContext("2d",{alpha:!1}),viewport:v};o&&(P.background=o);const D=c.render(P),M=D;return D.promise.then(()=>{j.style.visibility="",y()}).catch(w),()=>af(M)},[o,c,l,v,O]);const x=_.useCallback(()=>{const{current:S}=g;S&&(S.width=0,S.height=0)},[]);return _.useEffect(()=>x,[x]),f.jsx("canvas",{className:`${n}__canvas`,dir:"ltr",ref:PY(m,g),style:{display:"block",userSelect:"none"},children:d?f.jsx(D8e,{}):null})}function U8e(e){return"str"in e}function I8e(){const e=rC();Er(e);const{customTextRenderer:t,onGetTextError:r,onGetTextSuccess:n,onRenderTextLayerError:o,onRenderTextLayerSuccess:i,page:a,pageIndex:s,pageNumber:c,rotate:l,scale:d}=e;Er(a);const[h,p]=Tm(),{value:m,error:g}=h,y=_.useRef(null),w=_.useRef(void 0);wo(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 v(){m&&n&&n(m)}function O(){g&&(wo(!1,g.toString()),r&&r(g))}_.useEffect(function(){p({type:"RESET"})},[a,p]),_.useEffect(function(){if(!a)return;const T=$_(a.getTextContent()),z=T;return T.promise.then(A=>{p({type:"RESOLVE",value:A})}).catch(A=>{p({type:"REJECT",error:A})}),()=>af(z)},[a,p]),_.useEffect(()=>{if(m!==void 0){if(m===!1){O();return}v()}},[m]);const x=_.useCallback(()=>{i&&i()},[i]),S=_.useCallback(M=>{wo(!1,M.toString()),o&&o(M)},[o]);function j(){const M=w.current;M&&M.classList.add("active")}function P(){const M=w.current;M&&M.classList.remove("active")}const D=_.useMemo(()=>a.getViewport({scale:d,rotation:l}),[a,l,d]);return _.useLayoutEffect(function(){if(!a||!m)return;const{current:T}=y;if(!T)return;T.innerHTML="";const z=a.streamTextContent({includeMarkedContent:!0}),A={container:T,textContentSource:z,viewport:D},L=new fY(A),H=L;return L.render().then(()=>{const X=document.createElement("div");X.className="endOfContent",T.append(X),w.current=X;const K=T.querySelectorAll('[role="presentation"]');if(t){let W=0;m.items.forEach(($,Z)=>{if(!U8e($))return;const re=K[W];if(!re)return;const B=t(Object.assign({pageIndex:s,pageNumber:c,itemIndex:Z},$));re.innerHTML=B,W+=$.str&&$.hasEOL?2:1})}x()}).catch(S),()=>af(H)},[t,S,x,a,s,c,m,D]),f.jsx("div",{className:ZT("react-pdf__Page__textContent","textLayer"),onMouseUp:P,onMouseDown:j,ref:y})}function N8e(){const e=EY(),t=rC();Er(t);const r=Object.assign(Object.assign({},e),t),{imageResourcesPath:n,linkService:o,onGetAnnotationsError:i,onGetAnnotationsSuccess:a,onRenderAnnotationLayerError:s,onRenderAnnotationLayerSuccess:c,page:l,pdf:d,renderForms:h,rotate:p,scale:m=1}=r;Er(d),Er(l),Er(o);const[g,y]=Tm(),{value:w,error:v}=g,O=_.useRef(null);wo(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 x(){w&&a&&a(w)}function S(){v&&(wo(!1,v.toString()),i&&i(v))}_.useEffect(function(){y({type:"RESET"})},[y,l]),_.useEffect(function(){if(!l)return;const T=$_(l.getAnnotations()),z=T;return T.promise.then(A=>{y({type:"RESOLVE",value:A})}).catch(A=>{y({type:"REJECT",error:A})}),()=>{af(z)}},[y,l]),_.useEffect(()=>{if(w!==void 0){if(w===!1){S();return}x()}},[w]);function j(){c&&c()}function P(M){wo(!1,`${M}`),s&&s(M)}const D=_.useMemo(()=>l.getViewport({scale:m,rotation:p}),[l,p,m]);return _.useEffect(function(){if(!d||!l||!o||!w)return;const{current:T}=O;if(!T)return;const z=D.clone({dontFlip:!0}),A={accessibilityManager:null,annotationCanvasMap:null,annotationEditorUIManager:null,div:T,l10n:null,page:l,viewport:z},L={annotations:w,annotationStorage:d.annotationStorage,div:T,imageResourcesPath:n,linkService:o,page:l,renderForms:h,viewport:z};T.innerHTML="";try{new uY(A).render(L),j()}catch(H){P(H)}return()=>{}},[w,n,o,l,d,h,D]),f.jsx("div",{className:ZT("react-pdf__Page__annotations","annotationLayer"),ref:O})}var R8e=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]]);return r};const IY=1;function F8e(e){const t=EY(),r=Object.assign(Object.assign({},t),e),{_className:n="react-pdf__Page",_enableRegisterUnregisterPage:o=!0,canvasBackground:i,canvasRef:a,children:s,className:c,customRenderer:l,customTextRenderer:d,devicePixelRatio:h,error:p="Failed to load the page.",height:m,inputRef:g,loading:y="Loading page…",noData:w="No page specified.",onGetAnnotationsError:v,onGetAnnotationsSuccess:O,onGetStructTreeError:x,onGetStructTreeSuccess:S,onGetTextError:j,onGetTextSuccess:P,onLoadError:D,onLoadSuccess:M,onRenderAnnotationLayerError:T,onRenderAnnotationLayerSuccess:z,onRenderError:A,onRenderSuccess:L,onRenderTextLayerError:H,onRenderTextLayerSuccess:X,pageIndex:K,pageNumber:W,pdf:$,registerPage:Z,renderAnnotationLayer:re=!0,renderForms:B=!1,renderMode:ce="canvas",renderTextLayer:F=!0,rotate:oe,scale:ie=IY,unregisterPage:le,width:Y}=r,N=R8e(r,["_className","_enableRegisterUnregisterPage","canvasBackground","canvasRef","children","className","customRenderer","customTextRenderer","devicePixelRatio","error","height","inputRef","loading","noData","onGetAnnotationsError","onGetAnnotationsSuccess","onGetStructTreeError","onGetStructTreeSuccess","onGetTextError","onGetTextSuccess","onLoadError","onLoadSuccess","onRenderAnnotationLayerError","onRenderAnnotationLayerSuccess","onRenderError","onRenderSuccess","onRenderTextLayerError","onRenderTextLayerSuccess","pageIndex","pageNumber","pdf","registerPage","renderAnnotationLayer","renderForms","renderMode","renderTextLayer","rotate","scale","unregisterPage","width"]),[q,te]=Tm(),{value:fe,error:R}=q,k=_.useRef(null);Er($);const ye=of(W)?W-1:K??null,je=W??(of(K)?K+1:null),Ee=oe??(fe?fe.rotate:null),Se=_.useMemo(()=>{if(!fe)return null;let U=1;const E=ie??IY;if(Y||m){const C=fe.getViewport({scale:1,rotation:Ee});Y?U=Y/C.width:m&&(U=m/C.height)}return E*U},[m,fe,Ee,ie,Y]);_.useEffect(function(){return()=>{of(ye)&&o&&le&&le(ye)}},[o,$,ye,le]);function Te(){if(M){if(!fe||!Se)return;M(QF(fe,Se))}if(o&&Z){if(!of(ye)||!k.current)return;Z(ye,k.current)}}function ue(){R&&(wo(!1,R.toString()),D&&D(R))}_.useEffect(function(){te({type:"RESET"})},[te,$,ye]),_.useEffect(function(){if(!$||!je)return;const E=$_($.getPage(je)),C=E;return E.promise.then(ee=>{te({type:"RESOLVE",value:ee})}).catch(ee=>{te({type:"REJECT",error:ee})}),()=>af(C)},[te,$,je]),_.useEffect(()=>{if(fe!==void 0){if(fe===!1){ue();return}Te()}},[fe,Se]);const ne=_.useMemo(()=>fe&&of(ye)&&je&&of(Ee)&&of(Se)?{_className:n,canvasBackground:i,customTextRenderer:d,devicePixelRatio:h,onGetAnnotationsError:v,onGetAnnotationsSuccess:O,onGetStructTreeError:x,onGetStructTreeSuccess:S,onGetTextError:j,onGetTextSuccess:P,onRenderAnnotationLayerError:T,onRenderAnnotationLayerSuccess:z,onRenderError:A,onRenderSuccess:L,onRenderTextLayerError:H,onRenderTextLayerSuccess:X,page:fe,pageIndex:ye,pageNumber:je,renderForms:B,renderTextLayer:F,rotate:Ee,scale:Se}:null,[n,i,d,h,v,O,x,S,j,P,T,z,A,L,H,X,fe,ye,je,B,F,Ee,Se]),ve=_.useMemo(()=>mY(N,()=>fe&&(Se?QF(fe,Se):void 0)),[N,fe,Se]),we=`${ye}@${Se}/${Ee}`;function _e(){switch(ce){case"custom":return Er(l),f.jsx(l,{},`${we}_custom`);case"none":return null;case"canvas":default:return f.jsx(z8e,{canvasRef:a},`${we}_canvas`)}}function be(){return F?f.jsx(I8e,{},`${we}_text`):null}function V(){return re?f.jsx(N8e,{},`${we}_annotations`):null}function me(){return f.jsxs(TY.Provider,{value:ne,children:[_e(),be(),V(),s]})}function ae(){return je?$===null||fe===void 0||fe===null?f.jsx(Pm,{type:"loading",children:typeof y=="function"?y():y}):$===!1||fe===!1?f.jsx(Pm,{type:"error",children:typeof p=="function"?p():p}):me():f.jsx(Pm,{type:"no-data",children:typeof w=="function"?w():w})}return f.jsx("div",Object.assign({className:ZT(n,c),"data-page-number":je,ref:PY(g,k),style:{"--scale-factor":`${Se}`,backgroundColor:i||"white",position:"relative",minWidth:"min-content",minHeight:"min-content"}},ve,{children:ae()}))}w8e(),qF.workerSrc="pdf.worker.mjs";const pu=S9,$8e=YX;pu.extend($8e);const sf=({day:e=1,month:t,year:r})=>pu(`${r}-${t}-${e}`,"YYYY-M-D"),B_=(e,t,r,n)=>{let o=pu(sf({month:r,year:n})).day(t);return o.month()!==r-1&&(o=o.add(1,"week")),o=o.add(e-1,"week"),o},B8e=(e,t,r)=>{const n=pu(sf({month:t,year:r})).daysInMonth();let i=pu(`${r}-${t}-${n}`,"YYYY-M-D").day(e);return i.month()!==t-1&&(i=i.subtract(1,"week")),i},nC=(e=new Date().getFullYear(),{shiftSaturdayHolidays:t=!0,shiftSundayHolidays:r=!0}={})=>{const n=[];return n.push({name:"New Year's Day",date:sf({day:1,month:1,year:e})}),n.push({name:"Birthday of Martin Luther King, Jr.",date:B_(3,1,1,e)}),n.push({name:"Washington's Birthday",alsoObservedAs:"Presidents' Day",date:B_(3,1,2,e)}),n.push({name:"Memorial Day",date:B8e(1,5,e)}),e>2020&&n.push({name:"Juneteenth National Independence Day",date:sf({day:19,month:6,year:e})}),n.push({name:"Independence Day",date:sf({day:4,month:7,year:e})}),n.push({name:"Labor Day",date:B_(1,1,9,e)}),n.push({name:"Columbus Day",alsoObservedAs:"Indigenous Peoples' Day",date:B_(2,1,10,e)}),n.push({name:"Veterans Day",date:sf({day:11,month:11,year:e})}),n.push({name:"Thanksgiving Day",date:B_(4,4,11,e)}),n.push({name:"Christmas Day",date:sf({day:25,month:12,year:e})}),n.map(o=>{let i=pu(o.date);return i.day()===0&&r&&(i=i.add(1,"day")),i.day()===6&&t&&(i=i.subtract(1,"day")),{name:o.name,alsoObservedAs:o.alsoObservedAs,date:i.toDate(),dateString:i.format("YYYY-MM-DD")}})},L8e=(e=new Date,{shiftSaturdayHolidays:t=!0,shiftSundayHolidays:r=!0,utc:n=!1}={})=>{const o=n?pu.utc(e):pu(e),i=o.year(),a={shiftSaturdayHolidays:t,shiftSundayHolidays:r},s=nC(i,a),c=nC(i+1,a);return s.push(c[0]),s.some(l=>l.dateString===o.format("YYYY-MM-DD"))},V8e=()=>{const e=new Date;return e.setUTCFullYear(e.getUTCFullYear()+1),e};var K8e={isAHoliday:L8e,allForYear:nC,inRange:(e=new Date,t=V8e(),r=void 0)=>{const n=e.getFullYear(),o=t.getFullYear(),i=[];for(let a=n;a<=o;a+=1)i.push(...nC(a,r));return i.filter(a=>a.date>=e&&a.date<=t)}};const H8e=on(K8e).allForYear();function NY(e){const t=ke(e).day();return!(t===0||t===6||H8e.find(r=>ke(r.date).isSame(e,"day")))}ke.extend(aF),ke.extend(u3e),ke.extend(f3e);const k8e=wX;qF.workerSrc=`//unpkg.com/pdfjs-dist@${pY}/build/pdf.worker.min.js`;const oC=[Q.Mercoa.InvoiceStatus.Scheduled,Q.Mercoa.InvoiceStatus.Pending,Q.Mercoa.InvoiceStatus.Paid,Q.Mercoa.InvoiceStatus.Canceled,Q.Mercoa.InvoiceStatus.Archived,Q.Mercoa.InvoiceStatus.Refused];function RY({invoiceId:e,invoice:t,onRedirect:r,heightOffset:n,admin:o,documentPosition:i="left",invoicePreSubmit:a,children:s}){var P;const c=Be(),l=n??c.heightOffset,[d,h]=_.useState(),[p,m]=_.useState(),[g,y]=_.useState(t),[w,v]=_.useState(typeof window<"u"?window.innerHeight-l:0);async function O(D){var T,z;if(!c.token||!((T=c.entity)!=null&&T.id))return;const M=await((z=c.client)==null?void 0:z.invoice.get(D));M&&y(M)}_.useEffect(()=>{var D;!c.token||!((D=c.entity)!=null&&D.id)||!t&&e&&O(e)},[t,e,c.token,(P=c.entity)==null?void 0:P.id]);function x(){v(window.innerHeight-l)}if(_.useEffect(()=>(x(),window.addEventListener("resize",x,!1),()=>{window.removeEventListener("resize",x)}),[l]),!c.client)return f.jsx(nt,{componentName:"PayableDetails"});let S,j;if(s){const D=s({invoice:g,ocrResponse:d,uploadedDocument:p,setUploadedDocument:m,height:w,refreshInvoice:O,invoicePreSubmit:a,onOcrComplete:h,onRedirect:r});S=D[0],j=D[1]}else S=f.jsx(BY,{onOcrComplete:h,setUploadedDocument:m,height:w,invoice:g}),j=f.jsx(FY,{invoice:g,ocrResponse:d,uploadedDocument:p,setUploadedDocument:m,onRedirect:r,refreshInvoice:O,height:w,admin:o,invoicePreSubmit:a});return i==="none"||!j?j??S??f.jsx(f.Fragment,{}):f.jsxs(LX,{children:[f.jsx(OT,{className:"mercoa-relative mercoa-px-5",minSize:0,children:i==="left"?S:j}),f.jsx(VX,{size:10,className:"mercoa-cursor-col-resize mercoa-invisible min-[450px]:mercoa-visible",style:{background:"linear-gradient(180deg, rgba(229,231,235,1) 48%, rgba(145,145,145,1) 48%, rgba(145,145,145,1) 52%, rgba(229,231,235,1) 52%)"}}),f.jsx(OT,{className:"mercoa-relative mercoa-px-5",minSize:400,children:i==="right"?S:j})]})}function FY({invoice:e,ocrResponse:t,uploadedDocument:r,setUploadedDocument:n,onRedirect:o,refreshInvoice:i,height:a,admin:s,invoicePreSubmit:c,children:l}){var H,X,K,W,$,Z,re,B,ce,F,oe,ie,le,Y,N,q,te,fe,R,k,ye,je,Ee,Se,Te,ue,ne,ve,we,_e,be,V,me,ae,U,E,C,ee,he,xe,Pe;const d=Be(),[h,p]=_.useState(e==null?void 0:e.vendor),[m,g]=_.useState(!1),y=to({id:Fe().nullable(),status:Fe(),amount:gs().transform(v_).positive().typeError("Please enter a valid number"),invoiceNumber:Fe(),description:Fe(),processedAt:bo().nullable(),dueDate:bo().typeError("Please select a due date"),deductionDate:bo().typeError("Please select a deduction date"),invoiceDate:bo().typeError("Please select an invoice date"),approvers:yo(),lineItems:l1().of(to({id:Fe(),description:Fe().required(),amount:gs().transform(v_).required().typeError("Please enter a valid number"),quantity:gs().transform(v_).required().typeError("Please enter a valid number"),unitPrice:gs().transform(v_).required().typeError("Please enter a valid number"),currency:Fe().nullable(),metadata:yo().nullable(),glAccountId:Fe(),createdAt:bo().nullable(),updatedAt:bo().nullable()})),currency:Fe().required(),vendorId:Fe(),vendorName:Fe(),paymentDestinationId:Fe(),paymentDestinationType:Fe(),paymentDestinationSchemaId:Fe().nullable(),paymentDestinationOptions:yo().nullable(),paymentSourceId:Fe(),paymentSourceType:Fe(),paymentSourceCheckEnabled:Jl().nullable(),paymentSourceSchemaId:Fe().nullable(),hasDocuments:Jl().nullable(),saveAsStatus:Fe().nullable(),saveAsAdmin:Jl(),metadata:yo().nullable(),newBankAccount:yo().nullable(),newCheck:yo().nullable(),commentText:Fe().nullable(),comments:yo().nullable(),creatorUser:yo().nullable(),approvalPolicy:yo().nullable(),vendor:to().shape(p1),"~cpm~~":yo().nullable(),fees:yo().nullable(),failureType:Fe().nullable(),createdAt:bo().nullable(),updatedAt:bo().nullable()}).required(),w=Zn({resolver:za(y),defaultValues:{id:e==null?void 0:e.id,status:e==null?void 0:e.status,invoiceNumber:e==null?void 0:e.invoiceNumber,amount:e==null?void 0:e.amount,currency:(e==null?void 0:e.currency)??"USD",vendorId:(H=e==null?void 0:e.vendor)==null?void 0:H.id,vendorName:(X=e==null?void 0:e.vendor)==null?void 0:X.name,invoiceDate:e!=null&&e.invoiceDate?ke(e==null?void 0:e.invoiceDate).toDate():void 0,dueDate:e!=null&&e.dueDate?ke(e==null?void 0:e.dueDate).toDate():void 0,deductionDate:e!=null&&e.deductionDate?ke(e==null?void 0:e.deductionDate).toDate():void 0,processedAt:e!=null&&e.processedAt?ke(e==null?void 0:e.processedAt).toDate():void 0,lineItems:(e==null?void 0:e.lineItems)??[],paymentDestinationId:(K=e==null?void 0:e.paymentDestination)==null?void 0:K.id,paymentDestinationType:((W=e==null?void 0:e.paymentDestination)==null?void 0:W.type)??"",paymentDestinationOptions:e==null?void 0:e.paymentDestinationOptions,paymentSourceId:($=e==null?void 0:e.paymentSource)==null?void 0:$.id,paymentSourceType:((Z=e==null?void 0:e.paymentSource)==null?void 0:Z.type)??"",paymentSourceCheckEnabled:((B=(re=e==null?void 0:e.paymentSource)==null?void 0:re.checkOptions)==null?void 0:B.enabled)??!1,description:(e==null?void 0:e.noteToSelf)??"",hasDocuments:(e==null?void 0:e.hasDocuments)??!!r??!1,saveAsStatus:"",saveAsAdmin:!1,metadata:(e==null?void 0:e.metadata)??{},approvalPolicy:(e==null?void 0:e.approvalPolicy)??{type:"any",approvers:[]},approvers:(e==null?void 0:e.approvers)??[],fees:e==null?void 0:e.fees,createdAt:e==null?void 0:e.createdAt,updatedAt:e==null?void 0:e.updatedAt,newBankAccount:{routingNumber:"",accountNumber:"",bankName:"",accountType:Q.Mercoa.BankType.Checking},newCheck:{payToTheOrderOf:"",addressLine1:"",addressLine2:"",city:"",state:"",postalCode:"",country:"US"},"~cpm~~":{},failureType:(e==null?void 0:e.failureType)??"",commentText:"",comments:(e==null?void 0:e.comments)??[],creatorUser:e==null?void 0:e.creatorUser,vendor:{id:(ce=e==null?void 0:e.vendor)==null?void 0:ce.id,accountType:(F=e==null?void 0:e.vendor)==null?void 0:F.accountType,name:(oe=e==null?void 0:e.vendor)==null?void 0:oe.name,firstName:(N=(Y=(le=(ie=e==null?void 0:e.vendor)==null?void 0:ie.profile)==null?void 0:le.individual)==null?void 0:Y.name)==null?void 0:N.firstName,lastName:(R=(fe=(te=(q=e==null?void 0:e.vendor)==null?void 0:q.profile)==null?void 0:te.individual)==null?void 0:fe.name)==null?void 0:R.lastName,middleName:(Ee=(je=(ye=(k=e==null?void 0:e.vendor)==null?void 0:k.profile)==null?void 0:ye.individual)==null?void 0:je.name)==null?void 0:Ee.middleName,suffix:(ne=(ue=(Te=(Se=e==null?void 0:e.vendor)==null?void 0:Se.profile)==null?void 0:Te.individual)==null?void 0:ue.name)==null?void 0:ne.suffix,email:((ve=e==null?void 0:e.vendor)==null?void 0:ve.accountType)==="business"?(be=(_e=(we=e==null?void 0:e.vendor)==null?void 0:we.profile)==null?void 0:_e.business)==null?void 0:be.email:(ae=(me=(V=e==null?void 0:e.vendor)==null?void 0:V.profile)==null?void 0:me.individual)==null?void 0:ae.email,website:(C=(E=(U=e==null?void 0:e.vendor)==null?void 0:U.profile)==null?void 0:E.business)==null?void 0:C.website,description:(xe=(he=(ee=e==null?void 0:e.vendor)==null?void 0:ee.profile)==null?void 0:he.business)==null?void 0:xe.description,accounts:[]}}}),{handleSubmit:v,setValue:O,setError:x,clearErrors:S,watch:j,control:P,formState:{errors:D}}=w;_.useEffect(()=>{var Me,Ye,De,qe,it,Gn,Bt,Ei,lt,Kr,Yo,Co;e&&(e.vendor&&!h&&p(e.vendor),((Me=e.paymentDestination)==null?void 0:Me.type)==="custom"?O("paymentDestinationType",((Ye=e.paymentDestination)==null?void 0:Ye.schemaId)??""):O("paymentDestinationType",((De=e.paymentDestination)==null?void 0:De.type)??""),((qe=e.paymentSource)==null?void 0:qe.type)==="custom"?O("paymentSourceType",((it=e.paymentSource)==null?void 0:it.schemaId)??""):O("paymentSourceType",((Gn=e.paymentSource)==null?void 0:Gn.type)??""),O("id",e.id),O("status",e.status),O("invoiceNumber",e.invoiceNumber),O("amount",e.amount),O("currency",e.currency??"USD"),O("vendorId",(Bt=e.vendor)==null?void 0:Bt.id),O("vendorName",(Ei=e.vendor)==null?void 0:Ei.name),O("invoiceDate",e.invoiceDate?ke(e.invoiceDate).toDate():void 0),O("dueDate",e.dueDate?ke(e.dueDate).toDate():void 0),O("deductionDate",e.deductionDate?ke(e.deductionDate).toDate():void 0),O("lineItems",e.lineItems??[]),O("paymentDestinationId",(lt=e.paymentDestination)==null?void 0:lt.id),O("paymentDestinationOptions",e.paymentDestinationOptions),O("paymentSourceId",(Kr=e.paymentSource)==null?void 0:Kr.id),O("paymentSourceCheckEnabled",((Co=(Yo=e.paymentSource)==null?void 0:Yo.checkOptions)==null?void 0:Co.enabled)??!1),O("description",e.noteToSelf??""),O("hasDocuments",e.hasDocuments??r??!1),O("saveAsStatus",""),O("saveAsAdmin",!1),O("metadata",e.metadata??{}),O("approvers",(e==null?void 0:e.approvers)??[]),O("approvalPolicy",(e==null?void 0:e.approvalPolicy)??{type:"any",approvers:[]}),O("creatorUser",e==null?void 0:e.creatorUser),O("comments",(e==null?void 0:e.comments)??[]),O("fees",e==null?void 0:e.fees),O("failureType",(e==null?void 0:e.failureType)??""),O("createdAt",e==null?void 0:e.createdAt),O("updatedAt",e==null?void 0:e.updatedAt))},[e]);const{fields:M}=wd({control:P,name:"lineItems"}),T=j("vendorId");_.useEffect(()=>{h?h.id==="new"?(O("paymentDestinationId",""),O("paymentDestinationType",""),O("paymentDestinationOptions",void 0)):h.id&&(d.debug({selectedVendor:h}),O("vendorId",h.id),O("vendorName",h.name),h.id!=T&&(O("paymentDestinationId",""),O("paymentDestinationType",""),O("paymentDestinationOptions",void 0)),S("vendorId"),S("vendorName")):(O("vendorId",""),O("vendorName",""),S("vendorId"),S("vendorName"),O("paymentDestinationId",""),O("paymentDestinationType",""),O("paymentDestinationOptions",void 0))},[h]),_.useEffect(()=>{var Me,Ye;(Me=d.entity)!=null&&Me.id&&T&&((Ye=d.client)==null||Ye.entity.counterparty.findPayees(d.entity.id,{counterpartyId:T}).then(De=>{if(De.data.length>0){const qe=De.data[0].accounts;qe&&O("vendor.accounts",qe)}}))},[(Pe=d.entity)==null?void 0:Pe.id,T]),_.useEffect(()=>{var Me,Ye,De,qe,it,Gn;t&&(d.debug({ocrResponse:t}),t.invoice.amount&&O("amount",t.invoice.amount),t.invoice.invoiceNumber&&O("invoiceNumber",t.invoice.invoiceNumber),t.invoice.invoiceDate&&O("invoiceDate",ke(ke(t.invoice.invoiceDate).utc().format("YYYY-MM-DD")).toDate()),t.invoice.dueDate&&O("dueDate",ke(ke(t.invoice.dueDate).utc().format("YYYY-MM-DD")).toDate()),t.invoice.currency&&O("currency",t.invoice.currency),t.invoice.metadata&&O("metadata",t.invoice.metadata),t.invoice.lineItems&&((De=(Ye=(Me=d.iframeOptions)==null?void 0:Me.options)==null?void 0:Ye.invoice)==null?void 0:De.lineItems)!=Q.Mercoa.LineItemAvailabilities.Disabled&&O("lineItems",t.invoice.lineItems.map(Bt=>({description:Bt.description??"",currency:Bt.currency??"USD",amount:Bt.amount??0,quantity:Bt.quantity??0,unitPrice:Bt.unitPrice??0,name:Bt.name??"",metadata:Bt.metadata??{},glAccountId:Bt.glAccountId??"",id:Bt.id??"",createdAt:Bt.createdAt??new Date,updatedAt:Bt.updatedAt??new Date}))),t.bankAccount&&O("newBankAccount",{routingNumber:t.bankAccount.routingNumber,accountNumber:t.bankAccount.accountNumber,bankName:t.bankAccount.bankName,accountType:Q.Mercoa.BankType.Checking}),t.check&&O("newCheck",{addressLine1:t.check.addressLine1,addressLine2:t.check.addressLine2??"",city:t.check.city,state:t.check.stateOrProvince,postalCode:t.check.postalCode,country:"US",payToTheOrderOf:t.check.payToTheOrderOf}),t.vendor.id==="new"&&((Gn=(it=(qe=d.iframeOptions)==null?void 0:qe.options)==null?void 0:it.vendors)!=null&&Gn.disableCreation)?d.debug("new vendor creation disabled"):t.vendor.id&&(d.debug("setting selected vendor",t.vendor),p(t.vendor)))},[t]);async function z(Me){g(!0);try{await A(Me)}catch(Ye){console.error(Ye)}g(!1)}async function A(Me){var it,Gn,Bt,Ei,lt,Kr,Yo,Co,Pi,Qg,es,Qi,al,Zg,cD,Ku,ey,ty,vh,lD,fJ,hJ,pJ,mJ,gJ,yJ,bJ,vJ,wJ,_J,OJ,xJ,jJ,MJ,SJ,EJ,PJ,TJ,CJ,AJ,DJ,zJ;if(!d.token||!((it=d.entity)!=null&&it.id))return;if(d.debug({saveAsStatus:Me.saveAsStatus}),Me.saveAsStatus===Q.Mercoa.InvoiceStatus.Canceled){confirm("Are you sure you want to cancel this invoice? This cannot be undone.")&&await((Gn=d.client)==null?void 0:Gn.invoice.update(Me.id,{status:Q.Mercoa.InvoiceStatus.Canceled})),g(!1),i(Me.id);return}else if(Me.saveAsStatus===Q.Mercoa.InvoiceStatus.Archived){confirm("Are you sure you want to archive this invoice? This cannot be undone.")&&await((Bt=d.client)==null?void 0:Bt.invoice.update(Me.id,{status:Q.Mercoa.InvoiceStatus.Archived})),g(!1),i(Me.id);return}else if(Me.saveAsStatus==="COUNTERPARTY"){await h1({data:Me.vendor,mercoaSession:d,type:"payee",setError:x,onSelect:async Ne=>{await d.refresh(),setTimeout(()=>{p(Ne)},100)}});return}else if(Me.saveAsStatus==="CREATE_BANK_ACCOUNT"){if(T){try{const Ne=await((Ei=d.client)==null?void 0:Ei.entity.paymentMethod.create(T,{type:Q.Mercoa.PaymentMethodType.BankAccount,routingNumber:Me.newBankAccount.routingNumber,accountNumber:Me.newBankAccount.accountNumber,accountType:Me.newBankAccount.accountType}));await d.refresh(),setTimeout(()=>{O("paymentDestinationType",Q.Mercoa.PaymentMethodType.BankAccount,{shouldDirty:!0}),O("paymentDestinationId",Ne==null?void 0:Ne.id,{shouldDirty:!0}),O("saveAsStatus","CLOSE_INLINE_FORM")},100)}catch(Ne){x("newBankAccount",{message:Ne.body??"Invalid Bank Account Data"})}return}}else if(Me.saveAsStatus==="CREATE_COUNTERPARTY_ACCOUNT"){if(T){try{const Ne=await((lt=d.client)==null?void 0:lt.entity.counterparty.findPayees(d.entity.id,{counterpartyId:T}));let Ir=Ne==null?void 0:Ne.data[0].accounts;Ir?Ir==null||Ir.push({accountId:Me.newCounterpartyAccount.accountId,postalCode:Me.newCounterpartyAccount.postalCode,nameOnAccount:Me.newCounterpartyAccount.nameOnAccount}):Ir=[{accountId:Me.newCounterpartyAccount.accountId,postalCode:Me.newCounterpartyAccount.postalCode,nameOnAccount:Me.newCounterpartyAccount.nameOnAccount}],await((Kr=d.client)==null?void 0:Kr.entity.counterparty.addPayees(d.entity.id,{payees:[T],customizations:[{counterpartyId:T,accounts:Ir}]})),await d.refresh(),O("vendor.accounts",Ir),setTimeout(()=>{O("saveAsStatus","CLOSE_INLINE_FORM"),setTimeout(()=>{O("paymentDestinationType",Q.Mercoa.PaymentMethodType.Utility,{shouldDirty:!0}),O("paymentDestinationOptions",{type:"utility",accountId:Me.newCounterpartyAccount.accountId})},100)},100)}catch(Ne){x("vendor",{message:Ne.body??"Invalid Utility Account Data"})}return}}else if(Me.saveAsStatus==="CREATE_CHECK"){if(T){try{const Ne=await((Yo=d.client)==null?void 0:Yo.entity.paymentMethod.create(T,{type:Q.Mercoa.PaymentMethodType.Check,payToTheOrderOf:Me.newCheck.payToTheOrderOf,addressLine1:Me.newCheck.addressLine1,addressLine2:Me.newCheck.addressLine2,city:Me.newCheck.city,stateOrProvince:Me.newCheck.stateOrProvince,postalCode:Me.newCheck.postalCode,country:"US"}));d.refresh(),setTimeout(()=>{O("paymentDestinationType",Q.Mercoa.PaymentMethodType.Check,{shouldDirty:!0}),O("paymentDestinationId",Ne==null?void 0:Ne.id,{shouldDirty:!0}),O("saveAsStatus","CLOSE_INLINE_FORM")},1e3)}catch(Ne){x("newCheck",{message:Ne.body??"Invalid Check Data"})}return}}else if(Me.saveAsStatus==="CREATE_CUSTOM"){if(T){const Ne={};Object.entries(Me).forEach(([Ir,uo])=>{Ir.startsWith("~cpm~~")&&uo.forEach(ry=>{Ne[ry.name]=`${Ne[ry.name]??ry.value}`})});try{const Ir=await((Co=d.client)==null?void 0:Co.entity.paymentMethod.create(T,{type:Q.Mercoa.PaymentMethodType.Custom,schemaId:Me.paymentDestinationType,data:Ne}));d.refresh(),setTimeout(()=>{O("paymentDestinationType",Ir.schemaId,{shouldDirty:!0}),O("paymentDestinationId",Ir.id,{shouldDirty:!0}),O("saveAsStatus","CLOSE_INLINE_FORM")},1e3)}catch(Ir){x("~cpm~~",{message:Ir.body??"Invalid Data"})}return}}else if(Me.saveAsStatus==="DELETE"){if(e!=null&&e.id)try{confirm("Are your sure you want to delete this invoice? This cannot be undone.")&&(await((Pi=d.client)==null?void 0:Pi.invoice.delete(e.id)),Ce.success("Invoice deleted"),o&&o(void 0)),g(!1);return}catch(Ne){console.error(Ne),Ce.error(`There was an error deleting the invoice.
|
|
195
|
+
`)){const n=document.createElement("div");n.append(r?document.createTextNode(r):document.createElement("br")),this.editorDiv.append(n)}},MA=new WeakSet,TQ=function(){return b(this,Xi).replaceAll(" "," ")},wO=new WeakSet,_B=function(r){return r.replaceAll(" "," ")},SA=new WeakSet,CQ=function(r){const{value:n,fontSize:o,color:i,pageIndex:a}=b(this,Og);return this._hasBeenMoved||r.value!==n||r.fontSize!==o||r.color.some((s,c)=>s!==i[c])||r.pageIndex!==a},I(Tr,jg),I(Tr,wO),Je(Tr,"_freeTextDefaultContent",""),Je(Tr,"_internalPadding",0),Je(Tr,"_defaultColor",null),Je(Tr,"_defaultFontSize",10),Je(Tr,"_type","freetext"),Je(Tr,"_editorType",Vt.FREETEXT);let KF=Tr;class HF{constructor(t,r=0,n=0,o=!0){I(this,EA);I(this,Sg);I(this,PA);I(this,TA);I(this,OO);I(this,_O,void 0);I(this,Du,[]);I(this,Ga,[]);let i=1/0,a=-1/0,s=1/0,c=-1/0;const d=10**-4;for(const{x:v,y:O,width:x,height:S}of t){const j=Math.floor((v-r)/d)*d,P=Math.ceil((v+x+r)/d)*d,D=Math.floor((O-r)/d)*d,M=Math.ceil((O+S+r)/d)*d,T=[j,D,M,!0],z=[P,D,M,!1];b(this,Du).push(T,z),i=Math.min(i,j),a=Math.max(a,P),s=Math.min(s,D),c=Math.max(c,M)}const h=a-i+2*n,p=c-s+2*n,m=i-n,g=s-n,y=b(this,Du).at(o?-1:-2),w=[y[0],y[2]];for(const v of b(this,Du)){const[O,x,S]=v;v[0]=(O-m)/h,v[1]=(x-g)/p,v[2]=(S-g)/p}G(this,_O,{x:m,y:g,width:h,height:p,lastPoint:w})}getOutlines(){b(this,Du).sort((r,n)=>r[0]-n[0]||r[1]-n[1]||r[2]-n[2]);const t=[];for(const r of b(this,Du))r[3]?(t.push(...J(this,OO,OB).call(this,r)),J(this,PA,DQ).call(this,r)):(J(this,TA,zQ).call(this,r),t.push(...J(this,OO,OB).call(this,r)));return J(this,EA,AQ).call(this,t)}}_O=new WeakMap,Du=new WeakMap,Ga=new WeakMap,EA=new WeakSet,AQ=function(t){const r=[],n=new Set;for(const a of t){const[s,c,l]=a;r.push([s,c,a],[s,l,a])}r.sort((a,s)=>a[1]-s[1]||a[0]-s[0]);for(let a=0,s=r.length;a<s;a+=2){const c=r[a][2],l=r[a+1][2];c.push(l),l.push(c),n.add(c),n.add(l)}const o=[];let i;for(;n.size>0;){const a=n.values().next().value;let[s,c,l,d,h]=a;n.delete(a);let p=s,m=c;for(i=[s,l],o.push(i);;){let g;if(n.has(d))g=d;else if(n.has(h))g=h;else break;n.delete(g),[s,c,l,d,h]=g,p!==s&&(i.push(p,m,s,m===c?c:l),p=s),m=m===c?l:c}i.push(p,m)}return new i6e(o,b(this,_O))},Sg=new WeakSet,SD=function(t){const r=b(this,Ga);let n=0,o=r.length-1;for(;n<=o;){const i=n+o>>1,a=r[i][0];if(a===t)return i;a<t?n=i+1:o=i-1}return o+1},PA=new WeakSet,DQ=function([,t,r]){const n=J(this,Sg,SD).call(this,t);b(this,Ga).splice(n,0,[t,r])},TA=new WeakSet,zQ=function([,t,r]){const n=J(this,Sg,SD).call(this,t);for(let o=n;o<b(this,Ga).length;o++){const[i,a]=b(this,Ga)[o];if(i!==t)break;if(i===t&&a===r){b(this,Ga).splice(o,1);return}}for(let o=n-1;o>=0;o--){const[i,a]=b(this,Ga)[o];if(i!==t)break;if(i===t&&a===r){b(this,Ga).splice(o,1);return}}},OO=new WeakSet,OB=function(t){const[r,n,o]=t,i=[[r,n,o]],a=J(this,Sg,SD).call(this,o);for(let s=0;s<a;s++){const[c,l]=b(this,Ga)[s];for(let d=0,h=i.length;d<h;d++){const[,p,m]=i[d];if(!(l<=p||m<=c)){if(p>=c){if(m>l)i[d][1]=l;else{if(h===1)return[];i.splice(d,1),d--,h--}continue}i[d][2]=c,m>l&&i.push([r,l,m])}}}return i};class lY{toSVGPath(){throw new Error("Abstract method `toSVGPath` must be implemented.")}get box(){throw new Error("Abstract getter `box` must be implemented.")}serialize(t,r){throw new Error("Abstract method `serialize` must be implemented.")}get free(){return this instanceof kF}}class i6e extends lY{constructor(r,n){super();I(this,xO,void 0);I(this,Eg,void 0);G(this,Eg,r),G(this,xO,n)}toSVGPath(){const r=[];for(const n of b(this,Eg)){let[o,i]=n;r.push(`M${o} ${i}`);for(let a=2;a<n.length;a+=2){const s=n[a],c=n[a+1];s===o?(r.push(`V${c}`),i=c):c===i&&(r.push(`H${s}`),o=s)}r.push("Z")}return r.join(" ")}serialize([r,n,o,i],a){const s=[],c=o-r,l=i-n;for(const d of b(this,Eg)){const h=new Array(d.length);for(let p=0;p<d.length;p+=2)h[p]=r+d[p]*c,h[p+1]=i-d[p+1]*l;s.push(h)}return s}get box(){return b(this,xO)}}xO=new WeakMap,Eg=new WeakMap;const Gc=class Gc{constructor({x:t,y:r},n,o,i,a,s=0){I(this,EO);I(this,Vs,void 0);I(this,Xc,[]);I(this,Pg,void 0);I(this,Tg,void 0);I(this,Ks,[]);I(this,$t,new Float64Array(18));I(this,qf,void 0);I(this,Jf,void 0);I(this,jO,void 0);I(this,MO,void 0);I(this,Cg,void 0);I(this,Ag,void 0);I(this,zu,[]);G(this,Vs,n),G(this,Ag,i*o),G(this,Tg,a),b(this,$t).set([NaN,NaN,NaN,NaN,t,r],6),G(this,Pg,s),G(this,MO,b(Gc,SO)*o),G(this,jO,b(Gc,AA)*o),G(this,Cg,o),b(this,zu).push(t,r)}get free(){return!0}isEmpty(){return isNaN(b(this,$t)[8])}add({x:t,y:r}){var T;G(this,qf,t),G(this,Jf,r);const[n,o,i,a]=b(this,Vs);let[s,c,l,d]=b(this,$t).subarray(8,12);const h=t-l,p=r-d,m=Math.hypot(h,p);if(m<b(this,jO))return!1;const g=m-b(this,MO),y=g/m,w=y*h,v=y*p;let O=s,x=c;s=l,c=d,l+=w,d+=v,(T=b(this,zu))==null||T.push(t,r);const S=-v/g,j=w/g,P=S*b(this,Ag),D=j*b(this,Ag);return b(this,$t).set(b(this,$t).subarray(2,8),0),b(this,$t).set([l+P,d+D],4),b(this,$t).set(b(this,$t).subarray(14,18),12),b(this,$t).set([l-P,d-D],16),isNaN(b(this,$t)[6])?(b(this,Ks).length===0&&(b(this,$t).set([s+P,c+D],2),b(this,Ks).push(NaN,NaN,NaN,NaN,(s+P-n)/i,(c+D-o)/a),b(this,$t).set([s-P,c-D],14),b(this,Xc).push(NaN,NaN,NaN,NaN,(s-P-n)/i,(c-D-o)/a)),b(this,$t).set([O,x,s,c,l,d],6),!this.isEmpty()):(b(this,$t).set([O,x,s,c,l,d],6),Math.abs(Math.atan2(x-c,O-s)-Math.atan2(v,w))<Math.PI/2?([s,c,l,d]=b(this,$t).subarray(2,6),b(this,Ks).push(NaN,NaN,NaN,NaN,((s+l)/2-n)/i,((c+d)/2-o)/a),[s,c,O,x]=b(this,$t).subarray(14,18),b(this,Xc).push(NaN,NaN,NaN,NaN,((O+s)/2-n)/i,((x+c)/2-o)/a),!0):([O,x,s,c,l,d]=b(this,$t).subarray(0,6),b(this,Ks).push(((O+5*s)/6-n)/i,((x+5*c)/6-o)/a,((5*s+l)/6-n)/i,((5*c+d)/6-o)/a,((s+l)/2-n)/i,((c+d)/2-o)/a),[l,d,s,c,O,x]=b(this,$t).subarray(12,18),b(this,Xc).push(((O+5*s)/6-n)/i,((x+5*c)/6-o)/a,((5*s+l)/6-n)/i,((5*c+d)/6-o)/a,((s+l)/2-n)/i,((c+d)/2-o)/a),!0))}toSVGPath(){if(this.isEmpty())return"";const t=b(this,Ks),r=b(this,Xc),n=b(this,$t).subarray(4,6),o=b(this,$t).subarray(16,18),[i,a,s,c]=b(this,Vs),[l,d,h,p]=J(this,EO,xB).call(this);if(isNaN(b(this,$t)[6])&&!this.isEmpty())return`M${(b(this,$t)[2]-i)/s} ${(b(this,$t)[3]-a)/c} L${(b(this,$t)[4]-i)/s} ${(b(this,$t)[5]-a)/c} L${l} ${d} L${h} ${p} L${(b(this,$t)[16]-i)/s} ${(b(this,$t)[17]-a)/c} L${(b(this,$t)[14]-i)/s} ${(b(this,$t)[15]-a)/c} Z`;const m=[];m.push(`M${t[4]} ${t[5]}`);for(let g=6;g<t.length;g+=6)isNaN(t[g])?m.push(`L${t[g+4]} ${t[g+5]}`):m.push(`C${t[g]} ${t[g+1]} ${t[g+2]} ${t[g+3]} ${t[g+4]} ${t[g+5]}`);m.push(`L${(n[0]-i)/s} ${(n[1]-a)/c} L${l} ${d} L${h} ${p} L${(o[0]-i)/s} ${(o[1]-a)/c}`);for(let g=r.length-6;g>=6;g-=6)isNaN(r[g])?m.push(`L${r[g+4]} ${r[g+5]}`):m.push(`C${r[g]} ${r[g+1]} ${r[g+2]} ${r[g+3]} ${r[g+4]} ${r[g+5]}`);return m.push(`L${r[4]} ${r[5]} Z`),m.join(" ")}getOutlines(){var v;const t=b(this,Ks),r=b(this,Xc),n=b(this,$t),o=n.subarray(4,6),i=n.subarray(16,18),[a,s,c,l]=b(this,Vs),d=new Float64Array((((v=b(this,zu))==null?void 0:v.length)??0)+2);for(let O=0,x=d.length-2;O<x;O+=2)d[O]=(b(this,zu)[O]-a)/c,d[O+1]=(b(this,zu)[O+1]-s)/l;d[d.length-2]=(b(this,qf)-a)/c,d[d.length-1]=(b(this,Jf)-s)/l;const[h,p,m,g]=J(this,EO,xB).call(this);if(isNaN(n[6])&&!this.isEmpty()){const O=new Float64Array(36);return O.set([NaN,NaN,NaN,NaN,(n[2]-a)/c,(n[3]-s)/l,NaN,NaN,NaN,NaN,(n[4]-a)/c,(n[5]-s)/l,NaN,NaN,NaN,NaN,h,p,NaN,NaN,NaN,NaN,m,g,NaN,NaN,NaN,NaN,(n[16]-a)/c,(n[17]-s)/l,NaN,NaN,NaN,NaN,(n[14]-a)/c,(n[15]-s)/l],0),new kF(O,d,b(this,Vs),b(this,Cg),b(this,Pg),b(this,Tg))}const y=new Float64Array(b(this,Ks).length+24+b(this,Xc).length);let w=t.length;for(let O=0;O<w;O+=2){if(isNaN(t[O])){y[O]=y[O+1]=NaN;continue}y[O]=t[O],y[O+1]=t[O+1]}y.set([NaN,NaN,NaN,NaN,(o[0]-a)/c,(o[1]-s)/l,NaN,NaN,NaN,NaN,h,p,NaN,NaN,NaN,NaN,m,g,NaN,NaN,NaN,NaN,(i[0]-a)/c,(i[1]-s)/l],w),w+=24;for(let O=r.length-6;O>=6;O-=6)for(let x=0;x<6;x+=2){if(isNaN(r[O+x])){y[w]=y[w+1]=NaN,w+=2;continue}y[w]=r[O+x],y[w+1]=r[O+x+1],w+=2}return y.set([NaN,NaN,NaN,NaN,r[4],r[5]],w),new kF(y,d,b(this,Vs),b(this,Cg),b(this,Pg),b(this,Tg))}};Vs=new WeakMap,Xc=new WeakMap,Pg=new WeakMap,Tg=new WeakMap,Ks=new WeakMap,$t=new WeakMap,qf=new WeakMap,Jf=new WeakMap,jO=new WeakMap,MO=new WeakMap,Cg=new WeakMap,Ag=new WeakMap,zu=new WeakMap,SO=new WeakMap,CA=new WeakMap,AA=new WeakMap,EO=new WeakSet,xB=function(){const t=b(this,$t).subarray(4,6),r=b(this,$t).subarray(16,18),[n,o,i,a]=b(this,Vs);return[(b(this,qf)+(t[0]-r[0])/2-n)/i,(b(this,Jf)+(t[1]-r[1])/2-o)/a,(b(this,qf)+(r[0]-t[0])/2-n)/i,(b(this,Jf)+(r[1]-t[1])/2-o)/a]},I(Gc,SO,8),I(Gc,CA,2),I(Gc,AA,b(Gc,SO)+b(Gc,CA));let qT=Gc;class kF extends lY{constructor(r,n,o,i,a,s){super();I(this,Zf);I(this,eh);I(this,DA);I(this,Dg,void 0);I(this,Qf,null);I(this,Yc,void 0);I(this,PO,void 0);I(this,Yi,void 0);I(this,TO,void 0);I(this,jn,void 0);G(this,jn,r),G(this,Yi,n),G(this,Dg,o),G(this,TO,i),G(this,Yc,a),G(this,PO,s),J(this,DA,UQ).call(this,s);const{x:c,y:l,width:d,height:h}=b(this,Qf);for(let p=0,m=r.length;p<m;p+=2)r[p]=(r[p]-c)/d,r[p+1]=(r[p+1]-l)/h;for(let p=0,m=n.length;p<m;p+=2)n[p]=(n[p]-c)/d,n[p+1]=(n[p+1]-l)/h}toSVGPath(){const r=[`M${b(this,jn)[4]} ${b(this,jn)[5]}`];for(let n=6,o=b(this,jn).length;n<o;n+=6){if(isNaN(b(this,jn)[n])){r.push(`L${b(this,jn)[n+4]} ${b(this,jn)[n+5]}`);continue}r.push(`C${b(this,jn)[n]} ${b(this,jn)[n+1]} ${b(this,jn)[n+2]} ${b(this,jn)[n+3]} ${b(this,jn)[n+4]} ${b(this,jn)[n+5]}`)}return r.push("Z"),r.join(" ")}serialize([r,n,o,i],a){const s=o-r,c=i-n;let l,d;switch(a){case 0:l=J(this,Zf,mx).call(this,b(this,jn),r,i,s,-c),d=J(this,Zf,mx).call(this,b(this,Yi),r,i,s,-c);break;case 90:l=J(this,eh,gx).call(this,b(this,jn),r,n,s,c),d=J(this,eh,gx).call(this,b(this,Yi),r,n,s,c);break;case 180:l=J(this,Zf,mx).call(this,b(this,jn),o,n,-s,c),d=J(this,Zf,mx).call(this,b(this,Yi),o,n,-s,c);break;case 270:l=J(this,eh,gx).call(this,b(this,jn),o,i,-s,-c),d=J(this,eh,gx).call(this,b(this,Yi),o,i,-s,-c);break}return{outline:Array.from(l),points:[Array.from(d)]}}get box(){return b(this,Qf)}getNewOutline(r,n){const{x:o,y:i,width:a,height:s}=b(this,Qf),[c,l,d,h]=b(this,Dg),p=a*d,m=s*h,g=o*d+c,y=i*h+l,w=new qT({x:b(this,Yi)[0]*p+g,y:b(this,Yi)[1]*m+y},b(this,Dg),b(this,TO),r,b(this,PO),n??b(this,Yc));for(let v=2;v<b(this,Yi).length;v+=2)w.add({x:b(this,Yi)[v]*p+g,y:b(this,Yi)[v+1]*m+y});return w.getOutlines()}}Dg=new WeakMap,Qf=new WeakMap,Yc=new WeakMap,PO=new WeakMap,Yi=new WeakMap,TO=new WeakMap,jn=new WeakMap,Zf=new WeakSet,mx=function(r,n,o,i,a){const s=new Float64Array(r.length);for(let c=0,l=r.length;c<l;c+=2)s[c]=n+r[c]*i,s[c+1]=o+r[c+1]*a;return s},eh=new WeakSet,gx=function(r,n,o,i,a){const s=new Float64Array(r.length);for(let c=0,l=r.length;c<l;c+=2)s[c]=n+r[c+1]*i,s[c+1]=o+r[c]*a;return s},DA=new WeakSet,UQ=function(r){const n=b(this,jn);let o=n[4],i=n[5],a=o,s=i,c=o,l=i,d=o,h=i;const p=r?Math.max:Math.min;for(let v=6,O=n.length;v<O;v+=6){if(isNaN(n[v]))a=Math.min(a,n[v+4]),s=Math.min(s,n[v+5]),c=Math.max(c,n[v+4]),l=Math.max(l,n[v+5]),h<n[v+5]?(d=n[v+4],h=n[v+5]):h===n[v+5]&&(d=p(d,n[v+4]));else{const x=Ze.bezierBoundingBox(o,i,...n.slice(v,v+6));a=Math.min(a,x[0]),s=Math.min(s,x[1]),c=Math.max(c,x[2]),l=Math.max(l,x[3]),h<x[3]?(d=x[2],h=x[3]):h===x[3]&&(d=p(d,x[2]))}o=n[v+4],i=n[v+5]}const m=a-b(this,Yc),g=s-b(this,Yc),y=c-a+2*b(this,Yc),w=l-s+2*b(this,Yc);G(this,Qf,{x:m,y:g,width:y,height:w,lastPoint:[d,h]})};const Jc=class Jc{constructor({editor:t=null,uiManager:r=null}){I(this,IO);I(this,NO);I(this,zA);I(this,qc);I(this,UA);I(this,Hs);I(this,CO,J(this,zA,IQ).bind(this));I(this,AO,J(this,UA,NQ).bind(this));I(this,Ya,null);I(this,th,null);I(this,zg,void 0);I(this,kn,null);I(this,DO,!1);I(this,Ug,!1);I(this,zO,null);I(this,UO,void 0);I(this,qa,null);I(this,Ig,void 0);var n;t?(G(this,Ug,!1),G(this,Ig,mt.HIGHLIGHT_COLOR),G(this,zO,t)):(G(this,Ug,!0),G(this,Ig,mt.HIGHLIGHT_DEFAULT_COLOR)),G(this,qa,(t==null?void 0:t._uiManager)||r),G(this,UO,b(this,qa)._eventBus),G(this,zg,(t==null?void 0:t.color)||((n=b(this,qa))==null?void 0:n.highlightColors.values().next().value)||"#FFFF98")}static get _keyboardManager(){return qt(this,"_keyboardManager",new A_([[["Escape","mac+Escape"],Jc.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],Jc.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],Jc.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],Jc.prototype._moveToPrevious],[["Home","mac+Home"],Jc.prototype._moveToBeginning],[["End","mac+End"],Jc.prototype._moveToEnd]]))}renderButton(){const t=G(this,Ya,document.createElement("button"));t.className="colorPicker",t.tabIndex="0",t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-button"),t.setAttribute("aria-haspopup",!0);const r=b(this,qa)._signal;t.addEventListener("click",J(this,qc,_h).bind(this),{signal:r}),t.addEventListener("keydown",b(this,CO),{signal:r});const n=G(this,th,document.createElement("span"));return n.className="swatch",n.setAttribute("aria-hidden",!0),n.style.backgroundColor=b(this,zg),t.append(n),t}renderMainDropdown(){const t=G(this,kn,J(this,IO,jB).call(this));return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}_colorSelectFromKeyboard(t){if(t.target===b(this,Ya)){J(this,qc,_h).call(this,t);return}const r=t.target.getAttribute("data-color");r&&J(this,NO,MB).call(this,r,t)}_moveToNext(t){var r,n;if(!b(this,Hs,ku)){J(this,qc,_h).call(this,t);return}if(t.target===b(this,Ya)){(r=b(this,kn).firstChild)==null||r.focus();return}(n=t.target.nextSibling)==null||n.focus()}_moveToPrevious(t){var r,n;if(t.target===((r=b(this,kn))==null?void 0:r.firstChild)||t.target===b(this,Ya)){b(this,Hs,ku)&&this._hideDropdownFromKeyboard();return}b(this,Hs,ku)||J(this,qc,_h).call(this,t),(n=t.target.previousSibling)==null||n.focus()}_moveToBeginning(t){var r;if(!b(this,Hs,ku)){J(this,qc,_h).call(this,t);return}(r=b(this,kn).firstChild)==null||r.focus()}_moveToEnd(t){var r;if(!b(this,Hs,ku)){J(this,qc,_h).call(this,t);return}(r=b(this,kn).lastChild)==null||r.focus()}hideDropdown(){var t;(t=b(this,kn))==null||t.classList.add("hidden"),window.removeEventListener("pointerdown",b(this,AO))}_hideDropdownFromKeyboard(){var t;if(!b(this,Ug)){if(!b(this,Hs,ku)){(t=b(this,zO))==null||t.unselect();return}this.hideDropdown(),b(this,Ya).focus({preventScroll:!0,focusVisible:b(this,DO)})}}updateColor(t){if(b(this,th)&&(b(this,th).style.backgroundColor=t),!b(this,kn))return;const r=b(this,qa).highlightColors.values();for(const n of b(this,kn).children)n.setAttribute("aria-selected",r.next().value===t)}destroy(){var t,r;(t=b(this,Ya))==null||t.remove(),G(this,Ya,null),G(this,th,null),(r=b(this,kn))==null||r.remove(),G(this,kn,null)}};CO=new WeakMap,AO=new WeakMap,Ya=new WeakMap,th=new WeakMap,zg=new WeakMap,kn=new WeakMap,DO=new WeakMap,Ug=new WeakMap,zO=new WeakMap,UO=new WeakMap,qa=new WeakMap,Ig=new WeakMap,IO=new WeakSet,jB=function(){const t=document.createElement("div"),r=b(this,qa)._signal;t.addEventListener("contextmenu",Oi,{signal:r}),t.className="dropdown",t.role="listbox",t.setAttribute("aria-multiselectable",!1),t.setAttribute("aria-orientation","vertical"),t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown");for(const[n,o]of b(this,qa).highlightColors){const i=document.createElement("button");i.tabIndex="0",i.role="option",i.setAttribute("data-color",o),i.title=n,i.setAttribute("data-l10n-id",`pdfjs-editor-colorpicker-${n}`);const a=document.createElement("span");i.append(a),a.className="swatch",a.style.backgroundColor=o,i.setAttribute("aria-selected",o===b(this,zg)),i.addEventListener("click",J(this,NO,MB).bind(this,o),{signal:r}),t.append(i)}return t.addEventListener("keydown",b(this,CO),{signal:r}),t},NO=new WeakSet,MB=function(t,r){r.stopPropagation(),b(this,UO).dispatch("switchannotationeditorparams",{source:this,type:b(this,Ig),value:t})},zA=new WeakSet,IQ=function(t){Jc._keyboardManager.exec(this,t)},qc=new WeakSet,_h=function(t){if(b(this,Hs,ku)){this.hideDropdown();return}if(G(this,DO,t.detail===0),window.addEventListener("pointerdown",b(this,AO),{signal:b(this,qa)._signal}),b(this,kn)){b(this,kn).classList.remove("hidden");return}const r=G(this,kn,J(this,IO,jB).call(this));b(this,Ya).append(r)},UA=new WeakSet,NQ=function(t){var r;(r=b(this,kn))!=null&&r.contains(t.target)||this.hideDropdown()},Hs=new WeakSet,ku=function(){return b(this,kn)&&!b(this,kn).classList.contains("hidden")};let JT=Jc;const Jt=class Jt extends lr{constructor(r){super({...r,name:"highlightEditor"});I(this,LO);I(this,VO);I(this,NA);I(this,RA);I(this,FA);I(this,KO);I(this,ih);I(this,$A);I(this,Bg);I(this,ah);I(this,BA);I(this,LA);I(this,Ng,null);I(this,RO,0);I(this,Uu,void 0);I(this,rh,null);I(this,Rg,null);I(this,xa,null);I(this,FO,null);I(this,$O,0);I(this,nh,null);I(this,Ja,null);I(this,oi,null);I(this,qi,!1);I(this,IA,J(this,$A,BQ).bind(this));I(this,Fg,null);I(this,oh,void 0);I(this,Wn,null);I(this,$g,"");I(this,ks,void 0);I(this,BO,"");this.color=r.color||Jt._defaultColor,G(this,ks,r.thickness||Jt._defaultThickness),G(this,oh,r.opacity||Jt._defaultOpacity),G(this,Uu,r.boxes||null),G(this,BO,r.methodOfCreation||""),G(this,$g,r.text||""),this._isDraggable=!1,r.highlightId>-1?(G(this,qi,!0),J(this,VO,EB).call(this,r),J(this,ih,yx).call(this)):(G(this,Ng,r.anchorNode),G(this,RO,r.anchorOffset),G(this,FO,r.focusNode),G(this,$O,r.focusOffset),J(this,LO,SB).call(this),J(this,ih,yx).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const r=Jt.prototype;return qt(this,"_keyboardManager",new A_([[["ArrowLeft","mac+ArrowLeft"],r._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],r._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],r._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],r._moveCaret,{args:[3]}]]))}get telemetryInitialData(){return{action:"added",type:b(this,qi)?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:b(this,ks),methodOfCreation:b(this,BO)}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.highlightColorNames.get(this.color)}}static computeTelemetryFinalData(r){return{numberOfColors:r.get("color").size}}static initialize(r,n){var o;lr.initialize(r,n),Jt._defaultColor||(Jt._defaultColor=((o=n.highlightColors)==null?void 0:o.values().next().value)||"#fff066")}static updateDefaultParams(r,n){switch(r){case mt.HIGHLIGHT_DEFAULT_COLOR:Jt._defaultColor=n;break;case mt.HIGHLIGHT_THICKNESS:Jt._defaultThickness=n;break}}translateInPage(r,n){}get toolbarPosition(){return b(this,Fg)}updateParams(r,n){switch(r){case mt.HIGHLIGHT_COLOR:J(this,NA,RQ).call(this,n);break;case mt.HIGHLIGHT_THICKNESS:J(this,RA,FQ).call(this,n);break}}static get defaultPropertiesToUpdate(){return[[mt.HIGHLIGHT_DEFAULT_COLOR,Jt._defaultColor],[mt.HIGHLIGHT_THICKNESS,Jt._defaultThickness]]}get propertiesToUpdate(){return[[mt.HIGHLIGHT_COLOR,this.color||Jt._defaultColor],[mt.HIGHLIGHT_THICKNESS,b(this,ks)||Jt._defaultThickness],[mt.HIGHLIGHT_FREE,b(this,qi)]]}async addEditToolbar(){const r=await super.addEditToolbar();return r?(this._uiManager.highlightColors&&(G(this,Rg,new JT({editor:this})),r.addColorPicker(b(this,Rg))),r):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(J(this,ah,bx).call(this))}getBaseTranslation(){return[0,0]}getRect(r,n){return super.getRect(r,n,J(this,ah,bx).call(this))}onceAdded(){this.parent.addUndoableEditor(this),this.div.focus()}remove(){J(this,KO,PB).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(J(this,ih,yx).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(r){var o;let n=!1;this.parent&&!r?J(this,KO,PB).call(this):r&&(J(this,ih,yx).call(this,r),n=!this.parent&&((o=this.div)==null?void 0:o.classList.contains("selectedEditor"))),super.setParent(r),this.show(this._isVisible),n&&this.select()}rotate(r){var i,a,s;const{drawLayer:n}=this.parent;let o;b(this,qi)?(r=(r-this.rotation+360)%360,o=J(i=Jt,Iu,sy).call(i,b(this,Ja).box,r)):o=J(a=Jt,Iu,sy).call(a,this,r),n.rotate(b(this,oi),r),n.rotate(b(this,Wn),r),n.updateBox(b(this,oi),o),n.updateBox(b(this,Wn),J(s=Jt,Iu,sy).call(s,b(this,xa).box,r))}render(){if(this.div)return this.div;const r=super.render();b(this,$g)&&(r.setAttribute("aria-label",b(this,$g)),r.setAttribute("role","mark")),b(this,qi)?r.classList.add("free"):this.div.addEventListener("keydown",b(this,IA),{signal:this._uiManager._signal});const n=G(this,nh,document.createElement("div"));r.append(n),n.setAttribute("aria-hidden","true"),n.className="internal",n.style.clipPath=b(this,rh);const[o,i]=this.parentDimensions;return this.setDims(this.width*o,this.height*i),BT(this,b(this,nh),["pointerover","pointerleave"]),this.enableEditing(),r}pointerover(){this.parent.drawLayer.addClass(b(this,Wn),"hovered")}pointerleave(){this.parent.drawLayer.removeClass(b(this,Wn),"hovered")}_moveCaret(r){switch(this.parent.unselect(this),r){case 0:case 2:J(this,Bg,ED).call(this,!0);break;case 1:case 3:J(this,Bg,ED).call(this,!1);break}}select(){var r,n;super.select(),b(this,Wn)&&((r=this.parent)==null||r.drawLayer.removeClass(b(this,Wn),"hovered"),(n=this.parent)==null||n.drawLayer.addClass(b(this,Wn),"selected"))}unselect(){var r;super.unselect(),b(this,Wn)&&((r=this.parent)==null||r.drawLayer.removeClass(b(this,Wn),"selected"),b(this,qi)||J(this,Bg,ED).call(this,!1))}get _mustFixPosition(){return!b(this,qi)}show(r=this._isVisible){super.show(r),this.parent&&(this.parent.drawLayer.show(b(this,oi),r),this.parent.drawLayer.show(b(this,Wn),r))}static startHighlighting(r,n,{target:o,x:i,y:a}){const{x:s,y:c,width:l,height:d}=o.getBoundingClientRect(),h=w=>{J(this,VA,KQ).call(this,r,w)},p=r._signal,m={capture:!0,passive:!1,signal:p},g=w=>{w.preventDefault(),w.stopPropagation()},y=w=>{o.removeEventListener("pointermove",h),window.removeEventListener("blur",y),window.removeEventListener("pointerup",y),window.removeEventListener("pointerdown",g,m),window.removeEventListener("contextmenu",Oi),J(this,KA,HQ).call(this,r,w)};window.addEventListener("blur",y,{signal:p}),window.addEventListener("pointerup",y,{signal:p}),window.addEventListener("pointerdown",g,m),window.addEventListener("contextmenu",Oi,{signal:p}),o.addEventListener("pointermove",h,{signal:p}),this._freeHighlight=new qT({x:i,y:a},[s,c,l,d],r.scale,this._defaultThickness/2,n,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=r.drawLayer.highlight(this._freeHighlight,this._defaultColor,this._defaultOpacity,!0)}static deserialize(r,n,o){var y;const i=super.deserialize(r,n,o),{rect:[a,s,c,l],color:d,quadPoints:h}=r;i.color=Ze.makeHexColor(...d),G(i,oh,r.opacity);const[p,m]=i.pageDimensions;i.width=(c-a)/p,i.height=(l-s)/m;const g=G(i,Uu,[]);for(let w=0;w<h.length;w+=8)g.push({x:(h[4]-c)/p,y:(l-(1-h[w+5]))/m,width:(h[w+2]-h[w])/p,height:(h[w+5]-h[w+1])/m});return J(y=i,LO,SB).call(y),i}serialize(r=!1){if(this.isEmpty()||r)return null;const n=this.getRect(0,0),o=lr._colorManager.convert(this.color);return{annotationType:Vt.HIGHLIGHT,color:o,opacity:b(this,oh),thickness:b(this,ks),quadPoints:J(this,BA,LQ).call(this),outlines:J(this,LA,VQ).call(this,n),pageIndex:this.pageIndex,rect:n,rotation:J(this,ah,bx).call(this),structTreeParentId:this._structTreeParentId}}static canCreateNewEmptyEditor(){return!1}};Ng=new WeakMap,RO=new WeakMap,Uu=new WeakMap,rh=new WeakMap,Rg=new WeakMap,xa=new WeakMap,FO=new WeakMap,$O=new WeakMap,nh=new WeakMap,Ja=new WeakMap,oi=new WeakMap,qi=new WeakMap,IA=new WeakMap,Fg=new WeakMap,oh=new WeakMap,Wn=new WeakMap,$g=new WeakMap,ks=new WeakMap,BO=new WeakMap,LO=new WeakSet,SB=function(){const r=new HF(b(this,Uu),.001);G(this,Ja,r.getOutlines()),{x:this.x,y:this.y,width:this.width,height:this.height}=b(this,Ja).box;const n=new HF(b(this,Uu),.0025,.001,this._uiManager.direction==="ltr");G(this,xa,n.getOutlines());const{lastPoint:o}=b(this,xa).box;G(this,Fg,[(o[0]-this.x)/this.width,(o[1]-this.y)/this.height])},VO=new WeakSet,EB=function({highlightOutlines:r,highlightId:n,clipPathId:o}){var h,p;if(G(this,Ja,r),G(this,xa,r.getNewOutline(b(this,ks)/2+1.5,.0025)),n>=0)G(this,oi,n),G(this,rh,o),this.parent.drawLayer.finalizeLine(n,r),G(this,Wn,this.parent.drawLayer.highlightOutline(b(this,xa)));else if(this.parent){const m=this.parent.viewport.rotation;this.parent.drawLayer.updateLine(b(this,oi),r),this.parent.drawLayer.updateBox(b(this,oi),J(h=Jt,Iu,sy).call(h,b(this,Ja).box,(m-this.rotation+360)%360)),this.parent.drawLayer.updateLine(b(this,Wn),b(this,xa)),this.parent.drawLayer.updateBox(b(this,Wn),J(p=Jt,Iu,sy).call(p,b(this,xa).box,m))}const{x:a,y:s,width:c,height:l}=r.box;switch(this.rotation){case 0:this.x=a,this.y=s,this.width=c,this.height=l;break;case 90:{const[m,g]=this.parentDimensions;this.x=s,this.y=1-a,this.width=c*g/m,this.height=l*m/g;break}case 180:this.x=1-a,this.y=1-s,this.width=c,this.height=l;break;case 270:{const[m,g]=this.parentDimensions;this.x=1-s,this.y=a,this.width=c*g/m,this.height=l*m/g;break}}const{lastPoint:d}=b(this,xa).box;G(this,Fg,[(d[0]-a)/c,(d[1]-s)/l])},NA=new WeakSet,RQ=function(r){const n=i=>{var a,s;this.color=i,(a=this.parent)==null||a.drawLayer.changeColor(b(this,oi),i),(s=b(this,Rg))==null||s.updateColor(i)},o=this.color;this.addCommands({cmd:n.bind(this,r),undo:n.bind(this,o),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.highlightColorNames.get(r)},!0)},RA=new WeakSet,FQ=function(r){const n=b(this,ks),o=i=>{G(this,ks,i),J(this,FA,$Q).call(this,i)};this.addCommands({cmd:o.bind(this,r),undo:o.bind(this,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:mt.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:r},!0)},FA=new WeakSet,$Q=function(r){if(!b(this,qi))return;J(this,VO,EB).call(this,{highlightOutlines:b(this,Ja).getNewOutline(r/2)}),this.fixAndSetPosition();const[n,o]=this.parentDimensions;this.setDims(this.width*n,this.height*o)},KO=new WeakSet,PB=function(){b(this,oi)===null||!this.parent||(this.parent.drawLayer.remove(b(this,oi)),G(this,oi,null),this.parent.drawLayer.remove(b(this,Wn)),G(this,Wn,null))},ih=new WeakSet,yx=function(r=this.parent){b(this,oi)===null&&({id:Zi(this,oi)._,clipPathId:Zi(this,rh)._}=r.drawLayer.highlight(b(this,Ja),this.color,b(this,oh)),G(this,Wn,r.drawLayer.highlightOutline(b(this,xa))),b(this,nh)&&(b(this,nh).style.clipPath=b(this,rh)))},Iu=new WeakSet,sy=function({x:r,y:n,width:o,height:i},a){switch(a){case 90:return{x:1-n-i,y:r,width:i,height:o};case 180:return{x:1-r-o,y:1-n-i,width:o,height:i};case 270:return{x:n,y:1-r-o,width:i,height:o}}return{x:r,y:n,width:o,height:i}},$A=new WeakSet,BQ=function(r){Jt._keyboardManager.exec(this,r)},Bg=new WeakSet,ED=function(r){if(!b(this,Ng))return;const n=window.getSelection();r?n.setPosition(b(this,Ng),b(this,RO)):n.setPosition(b(this,FO),b(this,$O))},ah=new WeakSet,bx=function(){return b(this,qi)?this.rotation:0},BA=new WeakSet,LQ=function(){if(b(this,qi))return null;const[r,n]=this.pageDimensions,o=b(this,Uu),i=new Float32Array(o.length*8);let a=0;for(const{x:s,y:c,width:l,height:d}of o){const h=s*r,p=(1-c-d)*n;i[a]=i[a+4]=h,i[a+1]=i[a+3]=p,i[a+2]=i[a+6]=h+l*r,i[a+5]=i[a+7]=p+d*n,a+=8}return i},LA=new WeakSet,VQ=function(r){return b(this,Ja).serialize(r,J(this,ah,bx).call(this))},VA=new WeakSet,KQ=function(r,n){this._freeHighlight.add(n)&&r.drawLayer.updatePath(this._freeHighlightId,this._freeHighlight)},KA=new WeakSet,HQ=function(r,n){this._freeHighlight.isEmpty()?r.drawLayer.removeFreeHighlight(this._freeHighlightId):r.createAndAddNewEditor(n,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:"main_toolbar"}),this._freeHighlightId=-1,this._freeHighlight=null,this._freeHighlightClipId=""},I(Jt,Iu),I(Jt,VA),I(Jt,KA),Je(Jt,"_defaultColor",null),Je(Jt,"_defaultOpacity",1),Je(Jt,"_defaultThickness",12),Je(Jt,"_l10nPromise"),Je(Jt,"_type","highlight"),Je(Jt,"_editorType",Vt.HIGHLIGHT),Je(Jt,"_freeHighlightId",-1),Je(Jt,"_freeHighlight",null),Je(Jt,"_freeHighlightClipId","");let QT=Jt;const Vr=class Vr extends lr{constructor(r){super({...r,name:"inkEditor"});I(this,HA);I(this,kA);I(this,WA);I(this,XA);I(this,XO);I(this,GA);I(this,GO);I(this,YA);I(this,qA);I(this,JA);I(this,QA);I(this,ZA);I(this,el);I(this,YO);I(this,Lg);I(this,Vg);I(this,Ru);I(this,qO);I(this,Kg);I(this,rD);I(this,QO);I(this,Hg);I(this,ph);I(this,sh,0);I(this,ch,0);I(this,HO,this.canvasPointermove.bind(this));I(this,kO,this.canvasPointerleave.bind(this));I(this,WO,this.canvasPointerup.bind(this));I(this,lh,this.canvasPointerdown.bind(this));I(this,Ws,null);I(this,Qc,new Path2D);I(this,ja,!1);I(this,uh,!1);I(this,dh,!1);I(this,Zc,null);I(this,fh,0);I(this,hh,0);I(this,Nu,null);this.color=r.color||null,this.thickness=r.thickness||null,this.opacity=r.opacity||null,this.paths=[],this.bezierPath2D=[],this.allRawPaths=[],this.currentPath=[],this.scaleFactor=1,this.translationX=this.translationY=0,this.x=0,this.y=0,this._willKeepAspectRatio=!0}static initialize(r,n){lr.initialize(r,n)}static updateDefaultParams(r,n){switch(r){case mt.INK_THICKNESS:Vr._defaultThickness=n;break;case mt.INK_COLOR:Vr._defaultColor=n;break;case mt.INK_OPACITY:Vr._defaultOpacity=n/100;break}}updateParams(r,n){switch(r){case mt.INK_THICKNESS:J(this,HA,kQ).call(this,n);break;case mt.INK_COLOR:J(this,kA,WQ).call(this,n);break;case mt.INK_OPACITY:J(this,WA,XQ).call(this,n);break}}static get defaultPropertiesToUpdate(){return[[mt.INK_THICKNESS,Vr._defaultThickness],[mt.INK_COLOR,Vr._defaultColor||lr._defaultLineColor],[mt.INK_OPACITY,Math.round(Vr._defaultOpacity*100)]]}get propertiesToUpdate(){return[[mt.INK_THICKNESS,this.thickness||Vr._defaultThickness],[mt.INK_COLOR,this.color||Vr._defaultColor||lr._defaultLineColor],[mt.INK_OPACITY,Math.round(100*(this.opacity??Vr._defaultOpacity))]]}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.canvas||(J(this,Lg,PD).call(this),J(this,Vg,TD).call(this)),this.isAttachedToDOM||(this.parent.add(this),J(this,Ru,cy).call(this)),J(this,ph,vx).call(this)))}remove(){var r;this.canvas!==null&&(this.isEmpty()||this.commit(),this.canvas.width=this.canvas.height=0,this.canvas.remove(),this.canvas=null,b(this,Ws)&&(clearTimeout(b(this,Ws)),G(this,Ws,null)),(r=b(this,Zc))==null||r.disconnect(),G(this,Zc,null),super.remove())}setParent(r){!this.parent&&r?this._uiManager.removeShouldRescale(this):this.parent&&r===null&&this._uiManager.addShouldRescale(this),super.setParent(r)}onScaleChanging(){const[r,n]=this.parentDimensions,o=this.width*r,i=this.height*n;this.setDimensions(o,i)}enableEditMode(){b(this,ja)||this.canvas===null||(super.enableEditMode(),this._isDraggable=!1,this.canvas.addEventListener("pointerdown",b(this,lh),{signal:this._uiManager._signal}))}disableEditMode(){!this.isInEditMode()||this.canvas===null||(super.disableEditMode(),this._isDraggable=!this.isEmpty(),this.div.classList.remove("editing"),this.canvas.removeEventListener("pointerdown",b(this,lh)))}onceAdded(){this._isDraggable=!this.isEmpty()}isEmpty(){return this.paths.length===0||this.paths.length===1&&this.paths[0].length===0}commit(){b(this,ja)||(super.commit(),this.isEditing=!1,this.disableEditMode(),this.setInForeground(),G(this,ja,!0),this.div.classList.add("disabled"),J(this,ph,vx).call(this,!0),this.select(),this.parent.addInkEditorIfNeeded(!0),this.moveInDOM(),this.div.focus({preventScroll:!0}))}focusin(r){this._focusEventsAllowed&&(super.focusin(r),this.enableEditMode())}canvasPointerdown(r){r.button!==0||!this.isInEditMode()||b(this,ja)||(this.setInForeground(),r.preventDefault(),this.div.contains(document.activeElement)||this.div.focus({preventScroll:!0}),J(this,GA,YQ).call(this,r.offsetX,r.offsetY))}canvasPointermove(r){r.preventDefault(),J(this,GO,CB).call(this,r.offsetX,r.offsetY)}canvasPointerup(r){r.preventDefault(),J(this,YO,AB).call(this,r)}canvasPointerleave(r){J(this,YO,AB).call(this,r)}get isResizable(){return!this.isEmpty()&&b(this,ja)}render(){if(this.div)return this.div;let r,n;this.width&&(r=this.x,n=this.y),super.render(),this.div.setAttribute("data-l10n-id","pdfjs-ink");const[o,i,a,s]=J(this,XA,GQ).call(this);if(this.setAt(o,i,0,0),this.setDims(a,s),J(this,Lg,PD).call(this),this.width){const[c,l]=this.parentDimensions;this.setAspectRatio(this.width*c,this.height*l),this.setAt(r*c,n*l,this.width*c,this.height*l),G(this,dh,!0),J(this,Ru,cy).call(this),this.setDims(this.width*c,this.height*l),J(this,el,Oh).call(this),this.div.classList.add("disabled")}else this.div.classList.add("editing"),this.enableEditMode();return J(this,Vg,TD).call(this),this.div}setDimensions(r,n){const o=Math.round(r),i=Math.round(n);if(b(this,fh)===o&&b(this,hh)===i)return;G(this,fh,o),G(this,hh,i),this.canvas.style.visibility="hidden";const[a,s]=this.parentDimensions;this.width=r/a,this.height=n/s,this.fixAndSetPosition(),b(this,ja)&&J(this,qO,DB).call(this,r,n),J(this,Ru,cy).call(this),J(this,el,Oh).call(this),this.canvas.style.visibility="visible",this.fixDims()}static deserialize(r,n,o){var w,v,O;if(r instanceof sY)return null;const i=super.deserialize(r,n,o);i.thickness=r.thickness,i.color=Ze.makeHexColor(...r.color),i.opacity=r.opacity;const[a,s]=i.pageDimensions,c=i.width*a,l=i.height*s,d=i.parentScale,h=r.thickness/2;G(i,ja,!0),G(i,fh,Math.round(c)),G(i,hh,Math.round(l));const{paths:p,rect:m,rotation:g}=r;for(let{bezier:x}of p){x=J(w=Vr,tD,rZ).call(w,x,m,g);const S=[];i.paths.push(S);let j=d*(x[0]-h),P=d*(x[1]-h);for(let M=2,T=x.length;M<T;M+=6){const z=d*(x[M]-h),A=d*(x[M+1]-h),L=d*(x[M+2]-h),H=d*(x[M+3]-h),X=d*(x[M+4]-h),K=d*(x[M+5]-h);S.push([[j,P],[z,A],[L,H],[X,K]]),j=X,P=K}const D=J(this,eD,tZ).call(this,S);i.bezierPath2D.push(D)}const y=J(v=i,QO,UB).call(v);return G(i,ch,Math.max(lr.MIN_SIZE,y[2]-y[0])),G(i,sh,Math.max(lr.MIN_SIZE,y[3]-y[1])),J(O=i,qO,DB).call(O,c,l),i}serialize(){if(this.isEmpty())return null;const r=this.getRect(0,0),n=lr._colorManager.convert(this.ctx.strokeStyle);return{annotationType:Vt.INK,color:n,thickness:this.thickness,opacity:this.opacity,paths:J(this,rD,nZ).call(this,this.scaleFactor/this.parentScale,this.translationX,this.translationY,r),pageIndex:this.pageIndex,rect:r,rotation:this.rotation,structTreeParentId:this._structTreeParentId}}};sh=new WeakMap,ch=new WeakMap,HO=new WeakMap,kO=new WeakMap,WO=new WeakMap,lh=new WeakMap,Ws=new WeakMap,Qc=new WeakMap,ja=new WeakMap,uh=new WeakMap,dh=new WeakMap,Zc=new WeakMap,fh=new WeakMap,hh=new WeakMap,Nu=new WeakMap,HA=new WeakSet,kQ=function(r){const n=i=>{this.thickness=i,J(this,ph,vx).call(this)},o=this.thickness;this.addCommands({cmd:n.bind(this,r),undo:n.bind(this,o),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:mt.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0})},kA=new WeakSet,WQ=function(r){const n=i=>{this.color=i,J(this,el,Oh).call(this)},o=this.color;this.addCommands({cmd:n.bind(this,r),undo:n.bind(this,o),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:mt.INK_COLOR,overwriteIfSameType:!0,keepUndo:!0})},WA=new WeakSet,XQ=function(r){const n=i=>{this.opacity=i,J(this,el,Oh).call(this)};r/=100;const o=this.opacity;this.addCommands({cmd:n.bind(this,r),undo:n.bind(this,o),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:mt.INK_OPACITY,overwriteIfSameType:!0,keepUndo:!0})},XA=new WeakSet,GQ=function(){const{parentRotation:r,parentDimensions:[n,o]}=this;switch(r){case 90:return[0,o,o,n];case 180:return[n,o,n,o];case 270:return[n,0,o,n];default:return[0,0,n,o]}},XO=new WeakSet,TB=function(){const{ctx:r,color:n,opacity:o,thickness:i,parentScale:a,scaleFactor:s}=this;r.lineWidth=i*a/s,r.lineCap="round",r.lineJoin="round",r.miterLimit=10,r.strokeStyle=`${n}${T4e(o)}`},GA=new WeakSet,YQ=function(r,n){const o=this._uiManager._signal;this.canvas.addEventListener("contextmenu",Oi,{signal:o}),this.canvas.addEventListener("pointerleave",b(this,kO),{signal:o}),this.canvas.addEventListener("pointermove",b(this,HO),{signal:o}),this.canvas.addEventListener("pointerup",b(this,WO),{signal:o}),this.canvas.removeEventListener("pointerdown",b(this,lh)),this.isEditing=!0,b(this,dh)||(G(this,dh,!0),J(this,Ru,cy).call(this),this.thickness||(this.thickness=Vr._defaultThickness),this.color||(this.color=Vr._defaultColor||lr._defaultLineColor),this.opacity??(this.opacity=Vr._defaultOpacity)),this.currentPath.push([r,n]),G(this,uh,!1),J(this,XO,TB).call(this),G(this,Nu,()=>{J(this,JA,QQ).call(this),b(this,Nu)&&window.requestAnimationFrame(b(this,Nu))}),window.requestAnimationFrame(b(this,Nu))},GO=new WeakSet,CB=function(r,n){const[o,i]=this.currentPath.at(-1);if(this.currentPath.length>1&&r===o&&n===i)return;const a=this.currentPath;let s=b(this,Qc);if(a.push([r,n]),G(this,uh,!0),a.length<=2){s.moveTo(...a[0]),s.lineTo(r,n);return}a.length===3&&(G(this,Qc,s=new Path2D),s.moveTo(...a[0])),J(this,QA,ZQ).call(this,s,...a.at(-3),...a.at(-2),r,n)},YA=new WeakSet,qQ=function(){if(this.currentPath.length===0)return;const r=this.currentPath.at(-1);b(this,Qc).lineTo(...r)},qA=new WeakSet,JQ=function(r,n){G(this,Nu,null),r=Math.min(Math.max(r,0),this.canvas.width),n=Math.min(Math.max(n,0),this.canvas.height),J(this,GO,CB).call(this,r,n),J(this,YA,qQ).call(this);let o;if(this.currentPath.length!==1)o=J(this,ZA,eZ).call(this);else{const l=[r,n];o=[[l,l.slice(),l.slice(),l]]}const i=b(this,Qc),a=this.currentPath;this.currentPath=[],G(this,Qc,new Path2D);const s=()=>{this.allRawPaths.push(a),this.paths.push(o),this.bezierPath2D.push(i),this._uiManager.rebuild(this)},c=()=>{this.allRawPaths.pop(),this.paths.pop(),this.bezierPath2D.pop(),this.paths.length===0?this.remove():(this.canvas||(J(this,Lg,PD).call(this),J(this,Vg,TD).call(this)),J(this,ph,vx).call(this))};this.addCommands({cmd:s,undo:c,mustExec:!0})},JA=new WeakSet,QQ=function(){if(!b(this,uh))return;G(this,uh,!1);const r=Math.ceil(this.thickness*this.parentScale),n=this.currentPath.slice(-3),o=n.map(s=>s[0]),i=n.map(s=>s[1]);Math.min(...o)-r,Math.max(...o)+r,Math.min(...i)-r,Math.max(...i)+r;const{ctx:a}=this;a.save(),a.clearRect(0,0,this.canvas.width,this.canvas.height);for(const s of this.bezierPath2D)a.stroke(s);a.stroke(b(this,Qc)),a.restore()},QA=new WeakSet,ZQ=function(r,n,o,i,a,s,c){const l=(n+i)/2,d=(o+a)/2,h=(i+s)/2,p=(a+c)/2;r.bezierCurveTo(l+2*(i-l)/3,d+2*(a-d)/3,h+2*(i-h)/3,p+2*(a-p)/3,h,p)},ZA=new WeakSet,eZ=function(){const r=this.currentPath;if(r.length<=2)return[[r[0],r[0],r.at(-1),r.at(-1)]];const n=[];let o,[i,a]=r[0];for(o=1;o<r.length-2;o++){const[m,g]=r[o],[y,w]=r[o+1],v=(m+y)/2,O=(g+w)/2,x=[i+2*(m-i)/3,a+2*(g-a)/3],S=[v+2*(m-v)/3,O+2*(g-O)/3];n.push([[i,a],x,S,[v,O]]),[i,a]=[v,O]}const[s,c]=r[o],[l,d]=r[o+1],h=[i+2*(s-i)/3,a+2*(c-a)/3],p=[l+2*(s-l)/3,d+2*(c-d)/3];return n.push([[i,a],h,p,[l,d]]),n},el=new WeakSet,Oh=function(){if(this.isEmpty()){J(this,Kg,CD).call(this);return}J(this,XO,TB).call(this);const{canvas:r,ctx:n}=this;n.setTransform(1,0,0,1,0,0),n.clearRect(0,0,r.width,r.height),J(this,Kg,CD).call(this);for(const o of this.bezierPath2D)n.stroke(o)},YO=new WeakSet,AB=function(r){this.canvas.removeEventListener("pointerleave",b(this,kO)),this.canvas.removeEventListener("pointermove",b(this,HO)),this.canvas.removeEventListener("pointerup",b(this,WO)),this.canvas.addEventListener("pointerdown",b(this,lh),{signal:this._uiManager._signal}),b(this,Ws)&&clearTimeout(b(this,Ws)),G(this,Ws,setTimeout(()=>{G(this,Ws,null),this.canvas.removeEventListener("contextmenu",Oi)},10)),J(this,qA,JQ).call(this,r.offsetX,r.offsetY),this.addToAnnotationStorage(),this.setInBackground()},Lg=new WeakSet,PD=function(){this.canvas=document.createElement("canvas"),this.canvas.width=this.canvas.height=0,this.canvas.className="inkEditorCanvas",this.canvas.setAttribute("data-l10n-id","pdfjs-ink-canvas"),this.div.append(this.canvas),this.ctx=this.canvas.getContext("2d")},Vg=new WeakSet,TD=function(){G(this,Zc,new ResizeObserver(r=>{const n=r[0].contentRect;n.width&&n.height&&this.setDimensions(n.width,n.height)})),b(this,Zc).observe(this.div),this._uiManager._signal.addEventListener("abort",()=>{var r;(r=b(this,Zc))==null||r.disconnect(),G(this,Zc,null)},{once:!0})},Ru=new WeakSet,cy=function(){if(!b(this,dh))return;const[r,n]=this.parentDimensions;this.canvas.width=Math.ceil(this.width*r),this.canvas.height=Math.ceil(this.height*n),J(this,Kg,CD).call(this)},qO=new WeakSet,DB=function(r,n){const o=J(this,Hg,AD).call(this),i=(r-o)/b(this,ch),a=(n-o)/b(this,sh);this.scaleFactor=Math.min(i,a)},Kg=new WeakSet,CD=function(){const r=J(this,Hg,AD).call(this)/2;this.ctx.setTransform(this.scaleFactor,0,0,this.scaleFactor,this.translationX*this.scaleFactor+r,this.translationY*this.scaleFactor+r)},eD=new WeakSet,tZ=function(r){const n=new Path2D;for(let o=0,i=r.length;o<i;o++){const[a,s,c,l]=r[o];o===0&&n.moveTo(...a),n.bezierCurveTo(s[0],s[1],c[0],c[1],l[0],l[1])}return n},JO=new WeakSet,zB=function(r,n,o){const[i,a,s,c]=n;switch(o){case 0:for(let l=0,d=r.length;l<d;l+=2)r[l]+=i,r[l+1]=c-r[l+1];break;case 90:for(let l=0,d=r.length;l<d;l+=2){const h=r[l];r[l]=r[l+1]+i,r[l+1]=h+a}break;case 180:for(let l=0,d=r.length;l<d;l+=2)r[l]=s-r[l],r[l+1]+=a;break;case 270:for(let l=0,d=r.length;l<d;l+=2){const h=r[l];r[l]=s-r[l+1],r[l+1]=c-h}break;default:throw new Error("Invalid rotation")}return r},tD=new WeakSet,rZ=function(r,n,o){const[i,a,s,c]=n;switch(o){case 0:for(let l=0,d=r.length;l<d;l+=2)r[l]-=i,r[l+1]=c-r[l+1];break;case 90:for(let l=0,d=r.length;l<d;l+=2){const h=r[l];r[l]=r[l+1]-a,r[l+1]=h-i}break;case 180:for(let l=0,d=r.length;l<d;l+=2)r[l]=s-r[l],r[l+1]-=a;break;case 270:for(let l=0,d=r.length;l<d;l+=2){const h=r[l];r[l]=c-r[l+1],r[l+1]=s-h}break;default:throw new Error("Invalid rotation")}return r},rD=new WeakSet,nZ=function(r,n,o,i){var d,h;const a=[],s=this.thickness/2,c=r*n+s,l=r*o+s;for(const p of this.paths){const m=[],g=[];for(let y=0,w=p.length;y<w;y++){const[v,O,x,S]=p[y];if(v[0]===S[0]&&v[1]===S[1]&&w===1){const H=r*v[0]+c,X=r*v[1]+l;m.push(H,X),g.push(H,X);break}const j=r*v[0]+c,P=r*v[1]+l,D=r*O[0]+c,M=r*O[1]+l,T=r*x[0]+c,z=r*x[1]+l,A=r*S[0]+c,L=r*S[1]+l;y===0&&(m.push(j,P),g.push(j,P)),m.push(D,M,T,z,A,L),g.push(D,M),y===w-1&&g.push(A,L)}a.push({bezier:J(d=Vr,JO,zB).call(d,m,i,this.rotation),points:J(h=Vr,JO,zB).call(h,g,i,this.rotation)})}return a},QO=new WeakSet,UB=function(){let r=1/0,n=-1/0,o=1/0,i=-1/0;for(const a of this.paths)for(const[s,c,l,d]of a){const h=Ze.bezierBoundingBox(...s,...c,...l,...d);r=Math.min(r,h[0]),o=Math.min(o,h[1]),n=Math.max(n,h[2]),i=Math.max(i,h[3])}return[r,o,n,i]},Hg=new WeakSet,AD=function(){return b(this,ja)?Math.ceil(this.thickness*this.parentScale):0},ph=new WeakSet,vx=function(r=!1){if(this.isEmpty())return;if(!b(this,ja)){J(this,el,Oh).call(this);return}const n=J(this,QO,UB).call(this),o=J(this,Hg,AD).call(this);G(this,ch,Math.max(lr.MIN_SIZE,n[2]-n[0])),G(this,sh,Math.max(lr.MIN_SIZE,n[3]-n[1]));const i=Math.ceil(o+b(this,ch)*this.scaleFactor),a=Math.ceil(o+b(this,sh)*this.scaleFactor),[s,c]=this.parentDimensions;this.width=i/s,this.height=a/c,this.setAspectRatio(i,a);const l=this.translationX,d=this.translationY;this.translationX=-n[0],this.translationY=-n[1],J(this,Ru,cy).call(this),J(this,el,Oh).call(this),G(this,fh,i),G(this,hh,a),this.setDims(i,a);const h=r?o/this.scaleFactor/2:0;this.translate(l-this.translationX-h,d-this.translationY-h)},I(Vr,eD),I(Vr,JO),I(Vr,tD),Je(Vr,"_defaultColor",null),Je(Vr,"_defaultOpacity",1),Je(Vr,"_defaultThickness",1),Je(Vr,"_type","ink"),Je(Vr,"_editorType",Vt.INK);let WF=Vr;const rx=class rx extends lr{constructor(r){super({...r,name:"stampEditor"});I(this,mh);I(this,gh);I(this,Wg);I(this,ex);I(this,nD);I(this,oD);I(this,tx);I(this,Xg);I(this,iD);I(this,Eo,null);I(this,Po,null);I(this,Fu,null);I(this,tl,null);I(this,$u,null);I(this,kg,"");I(this,Xs,null);I(this,rl,null);I(this,Gs,null);I(this,Qa,!1);I(this,ZO,!1);G(this,tl,r.bitmapUrl),G(this,$u,r.bitmapFile)}static initialize(r,n){lr.initialize(r,n)}static get supportedTypes(){return qt(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(n=>`image/${n}`))}static get supportedTypesStr(){return qt(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(r){return this.supportedTypes.includes(r)}static paste(r,n){n.pasteEditor(Vt.STAMP,{bitmapFile:r.getAsFile()})}remove(){var r,n;b(this,Po)&&(G(this,Eo,null),this._uiManager.imageManager.deleteId(b(this,Po)),(r=b(this,Xs))==null||r.remove(),G(this,Xs,null),(n=b(this,rl))==null||n.disconnect(),G(this,rl,null),b(this,Gs)&&(clearTimeout(b(this,Gs)),G(this,Gs,null))),super.remove()}rebuild(){if(!this.parent){b(this,Po)&&J(this,Wg,DD).call(this);return}super.rebuild(),this.div!==null&&(b(this,Po)&&b(this,Xs)===null&&J(this,Wg,DD).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(){this._isDraggable=!0,this.div.focus()}isEmpty(){return!(b(this,Fu)||b(this,Eo)||b(this,tl)||b(this,$u)||b(this,Po))}get isResizable(){return!0}render(){if(this.div)return this.div;let r,n;if(this.width&&(r=this.x,n=this.y),super.render(),this.div.hidden=!0,this.addAltTextButton(),b(this,Eo)?J(this,ex,IB).call(this):J(this,Wg,DD).call(this),this.width){const[o,i]=this.parentDimensions;this.setAt(r*o,n*i,this.width*o,this.height*i)}return this.div}getImageForAltText(){return b(this,Xs)}static deserialize(r,n,o){if(r instanceof cY)return null;const i=super.deserialize(r,n,o),{rect:a,bitmapUrl:s,bitmapId:c,isSvg:l,accessibilityData:d}=r;c&&o.imageManager.isValidId(c)?G(i,Po,c):G(i,tl,s),G(i,Qa,l);const[h,p]=i.pageDimensions;return i.width=(a[2]-a[0])/h,i.height=(a[3]-a[1])/p,d&&(i.altTextData=d),i}serialize(r=!1,n=null){if(this.isEmpty())return null;const o={annotationType:Vt.STAMP,bitmapId:b(this,Po),pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:b(this,Qa),structTreeParentId:this._structTreeParentId};if(r)return o.bitmapUrl=J(this,Xg,zD).call(this,!0),o.accessibilityData=this.altTextData,o;const{decorative:i,altText:a}=this.altTextData;if(!i&&a&&(o.accessibilityData={type:"Figure",alt:a}),n===null)return o;n.stamps||(n.stamps=new Map);const s=b(this,Qa)?(o.rect[2]-o.rect[0])*(o.rect[3]-o.rect[1]):null;if(!n.stamps.has(b(this,Po)))n.stamps.set(b(this,Po),{area:s,serialized:o}),o.bitmap=J(this,Xg,zD).call(this,!1);else if(b(this,Qa)){const c=n.stamps.get(b(this,Po));s>c.area&&(c.area=s,c.serialized.bitmap.close(),c.serialized.bitmap=J(this,Xg,zD).call(this,!1))}return o}};Eo=new WeakMap,Po=new WeakMap,Fu=new WeakMap,tl=new WeakMap,$u=new WeakMap,kg=new WeakMap,Xs=new WeakMap,rl=new WeakMap,Gs=new WeakMap,Qa=new WeakMap,ZO=new WeakMap,mh=new WeakSet,wx=function(r,n=!1){if(!r){this.remove();return}G(this,Eo,r.bitmap),n||(G(this,Po,r.id),G(this,Qa,r.isSvg)),r.file&&G(this,kg,r.file.name),J(this,ex,IB).call(this)},gh=new WeakSet,_x=function(){G(this,Fu,null),this._uiManager.enableWaiting(!1),b(this,Xs)&&this.div.focus()},Wg=new WeakSet,DD=function(){if(b(this,Po)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(b(this,Po)).then(o=>J(this,mh,wx).call(this,o,!0)).finally(()=>J(this,gh,_x).call(this));return}if(b(this,tl)){const o=b(this,tl);G(this,tl,null),this._uiManager.enableWaiting(!0),G(this,Fu,this._uiManager.imageManager.getFromUrl(o).then(i=>J(this,mh,wx).call(this,i)).finally(()=>J(this,gh,_x).call(this)));return}if(b(this,$u)){const o=b(this,$u);G(this,$u,null),this._uiManager.enableWaiting(!0),G(this,Fu,this._uiManager.imageManager.getFromFile(o).then(i=>J(this,mh,wx).call(this,i)).finally(()=>J(this,gh,_x).call(this)));return}const r=document.createElement("input");r.type="file",r.accept=rx.supportedTypesStr;const n=this._uiManager._signal;G(this,Fu,new Promise(o=>{r.addEventListener("change",async()=>{if(!r.files||r.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const i=await this._uiManager.imageManager.getFromFile(r.files[0]);J(this,mh,wx).call(this,i)}o()},{signal:n}),r.addEventListener("cancel",()=>{this.remove(),o()},{signal:n})}).finally(()=>J(this,gh,_x).call(this))),r.click()},ex=new WeakSet,IB=function(){const{div:r}=this;let{width:n,height:o}=b(this,Eo);const[i,a]=this.pageDimensions,s=.75;if(this.width)n=this.width*i,o=this.height*a;else if(n>s*i||o>s*a){const h=Math.min(s*i/n,s*a/o);n*=h,o*=h}const[c,l]=this.parentDimensions;this.setDims(n*c/i,o*l/a),this._uiManager.enableWaiting(!1);const d=G(this,Xs,document.createElement("canvas"));r.append(d),r.hidden=!1,J(this,tx,NB).call(this,n,o),J(this,iD,aZ).call(this),b(this,ZO)||(this.parent.addUndoableEditor(this),G(this,ZO,!0)),this._reportTelemetry({action:"inserted_image"}),b(this,kg)&&d.setAttribute("aria-label",b(this,kg))},nD=new WeakSet,oZ=function(r,n){var s;const[o,i]=this.parentDimensions;this.width=r/o,this.height=n/i,this.setDims(r,n),(s=this._initialOptions)!=null&&s.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,b(this,Gs)!==null&&clearTimeout(b(this,Gs)),G(this,Gs,setTimeout(()=>{G(this,Gs,null),J(this,tx,NB).call(this,r,n)},200))},oD=new WeakSet,iZ=function(r,n){const{width:o,height:i}=b(this,Eo);let a=o,s=i,c=b(this,Eo);for(;a>2*r||s>2*n;){const l=a,d=s;a>2*r&&(a=a>=16384?Math.floor(a/2)-1:Math.ceil(a/2)),s>2*n&&(s=s>=16384?Math.floor(s/2)-1:Math.ceil(s/2));const h=new OffscreenCanvas(a,s);h.getContext("2d").drawImage(c,0,0,l,d,0,0,a,s),c=h.transferToImageBitmap()}return c},tx=new WeakSet,NB=function(r,n){r=Math.ceil(r),n=Math.ceil(n);const o=b(this,Xs);if(!o||o.width===r&&o.height===n)return;o.width=r,o.height=n;const i=b(this,Qa)?b(this,Eo):J(this,oD,iZ).call(this,r,n);if(this._uiManager.hasMLManager&&!this.hasAltText()){const c=new OffscreenCanvas(r,n).getContext("2d");c.drawImage(i,0,0,i.width,i.height,0,0,r,n),this._uiManager.mlGuess({service:"image-to-text",request:{data:c.getImageData(0,0,r,n).data,width:r,height:n,channels:4}}).then(l=>{const d=(l==null?void 0:l.output)||"";this.parent&&d&&!this.hasAltText()&&(this.altTextData={altText:d,decorative:!1})})}const a=o.getContext("2d");a.filter=this._uiManager.hcmFilter,a.drawImage(i,0,0,i.width,i.height,0,0,r,n)},Xg=new WeakSet,zD=function(r){if(r){if(b(this,Qa)){const i=this._uiManager.imageManager.getSvgUrl(b(this,Po));if(i)return i}const n=document.createElement("canvas");return{width:n.width,height:n.height}=b(this,Eo),n.getContext("2d").drawImage(b(this,Eo),0,0),n.toDataURL()}if(b(this,Qa)){const[n,o]=this.pageDimensions,i=Math.round(this.width*n*fu.PDF_TO_CSS_UNITS),a=Math.round(this.height*o*fu.PDF_TO_CSS_UNITS),s=new OffscreenCanvas(i,a);return s.getContext("2d").drawImage(b(this,Eo),0,0,b(this,Eo).width,b(this,Eo).height,0,0,i,a),s.transferToImageBitmap()}return structuredClone(b(this,Eo))},iD=new WeakSet,aZ=function(){this._uiManager._signal&&(G(this,rl,new ResizeObserver(r=>{const n=r[0].contentRect;n.width&&n.height&&J(this,nD,oZ).call(this,n.width,n.height)})),b(this,rl).observe(this.div),this._uiManager._signal.addEventListener("abort",()=>{var r;(r=b(this,rl))==null||r.disconnect(),G(this,rl,null)},{once:!0}))},Je(rx,"_type","stamp"),Je(rx,"_editorType",Vt.STAMP);let XF=rx;const Za=class Za{constructor({uiManager:t,pageIndex:r,div:n,accessibilityManager:o,annotationLayer:i,drawLayer:a,textLayer:s,viewport:c,l10n:l}){I(this,aD);I(this,nx);I(this,ox);I(this,ix);I(this,Jg);I(this,yh,void 0);I(this,Gg,!1);I(this,Ys,null);I(this,bh,null);I(this,nl,null);I(this,ol,null);I(this,il,null);I(this,Ji,new Map);I(this,Bu,!1);I(this,Yg,!1);I(this,qg,!1);I(this,ii,null);I(this,tt,void 0);const d=[...b(Za,Lu).values()];if(!Za._initialized){Za._initialized=!0;for(const h of d)h.initialize(l,t)}t.registerEditorTypes(d),G(this,tt,t),this.pageIndex=r,this.div=n,G(this,yh,o),G(this,Ys,i),this.viewport=c,G(this,ii,s),this.drawLayer=a,b(this,tt).addLayer(this)}get isEmpty(){return b(this,Ji).size===0}get isInvisible(){return this.isEmpty&&b(this,tt).getMode()===Vt.NONE}updateToolbar(t){b(this,tt).updateToolbar(t)}updateMode(t=b(this,tt).getMode()){switch(J(this,Jg,UD).call(this),t){case Vt.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case Vt.INK:this.addInkEditorIfNeeded(!1),this.disableTextSelection(),this.togglePointerEvents(!0),this.disableClick();break;case Vt.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);const{classList:r}=this.div;for(const n of b(Za,Lu).values())r.toggle(`${n._type}Editing`,t===n._editorType);this.div.hidden=!1}hasTextLayer(t){var r;return t===((r=b(this,ii))==null?void 0:r.div)}addInkEditorIfNeeded(t){if(b(this,tt).getMode()!==Vt.INK)return;if(!t){for(const n of b(this,Ji).values())if(n.isEmpty()){n.setInBackground();return}}this.createAndAddNewEditor({offsetX:0,offsetY:0},!1).setInBackground()}setEditingState(t){b(this,tt).setEditingState(t)}addCommands(t){b(this,tt).addCommands(t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){var r;(r=b(this,Ys))==null||r.div.classList.toggle("disabled",!t)}enable(){this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const n of b(this,Ji).values())n.enableEditing(),n.show(!0),n.annotationElementId&&(b(this,tt).removeChangedExistingAnnotation(n),t.add(n.annotationElementId));if(!b(this,Ys))return;const r=b(this,Ys).getEditableAnnotations();for(const n of r){if(n.hide(),b(this,tt).isDeletedAnnotationElement(n.data.id)||t.has(n.data.id))continue;const o=this.deserialize(n);o&&(this.addOrRebuild(o),o.enableEditing())}}disable(){var o;G(this,qg,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,r=new Map;for(const i of b(this,Ji).values())if(i.disableEditing(),!!i.annotationElementId){if(i.serialize()!==null){t.set(i.annotationElementId,i);continue}else r.set(i.annotationElementId,i);(o=this.getEditableAnnotation(i.annotationElementId))==null||o.show(),i.remove()}if(b(this,Ys)){const i=b(this,Ys).getEditableAnnotations();for(const a of i){const{id:s}=a.data;if(b(this,tt).isDeletedAnnotationElement(s))continue;let c=r.get(s);if(c){c.resetAnnotationElement(a),c.show(!1),a.show();continue}c=t.get(s),c&&(b(this,tt).addChangedExistingAnnotation(c),c.renderAnnotationElement(a),c.show(!1)),a.show()}}J(this,Jg,UD).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:n}=this.div;for(const i of b(Za,Lu).values())n.remove(`${i._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),G(this,qg,!1)}getEditableAnnotation(t){var r;return((r=b(this,Ys))==null?void 0:r.getEditableAnnotation(t))||null}setActiveEditor(t){b(this,tt).getActive()!==t&&b(this,tt).setActiveEditor(t)}enableTextSelection(){var t;this.div.tabIndex=-1,(t=b(this,ii))!=null&&t.div&&!b(this,ol)&&(G(this,ol,J(this,aD,sZ).bind(this)),b(this,ii).div.addEventListener("pointerdown",b(this,ol),{signal:b(this,tt)._signal}),b(this,ii).div.classList.add("highlighting"))}disableTextSelection(){var t;this.div.tabIndex=0,(t=b(this,ii))!=null&&t.div&&b(this,ol)&&(b(this,ii).div.removeEventListener("pointerdown",b(this,ol)),G(this,ol,null),b(this,ii).div.classList.remove("highlighting"))}enableClick(){if(b(this,nl))return;const t=b(this,tt)._signal;G(this,nl,this.pointerdown.bind(this)),G(this,bh,this.pointerup.bind(this)),this.div.addEventListener("pointerdown",b(this,nl),{signal:t}),this.div.addEventListener("pointerup",b(this,bh),{signal:t})}disableClick(){b(this,nl)&&(this.div.removeEventListener("pointerdown",b(this,nl)),this.div.removeEventListener("pointerup",b(this,bh)),G(this,nl,null),G(this,bh,null))}attach(t){b(this,Ji).set(t.id,t);const{annotationElementId:r}=t;r&&b(this,tt).isDeletedAnnotationElement(r)&&b(this,tt).removeDeletedAnnotationElement(t)}detach(t){var r;b(this,Ji).delete(t.id),(r=b(this,yh))==null||r.removePointerInTextLayer(t.contentDiv),!b(this,qg)&&t.annotationElementId&&b(this,tt).addDeletedAnnotationElement(t)}remove(t){this.detach(t),b(this,tt).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1,b(this,Yg)||this.addInkEditorIfNeeded(!1)}changeParent(t){var r;t.parent!==this&&(t.parent&&t.annotationElementId&&(b(this,tt).addDeletedAnnotationElement(t.annotationElementId),lr.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),(r=t.parent)==null||r.detach(t),t.setParent(this),t.div&&t.isAttachedToDOM&&(t.div.remove(),this.div.append(t.div)))}add(t){if(!(t.parent===this&&t.isAttachedToDOM)){if(this.changeParent(t),b(this,tt).addEditor(t),this.attach(t),!t.isAttachedToDOM){const r=t.render();this.div.append(r),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(),b(this,tt).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var n;if(!t.isAttachedToDOM)return;const{activeElement:r}=document;t.div.contains(r)&&!b(this,il)&&(t._focusEventsAllowed=!1,G(this,il,setTimeout(()=>{G(this,il,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:b(this,tt)._signal}),r.focus())},0))),t._structTreeParentId=(n=b(this,yh))==null?void 0:n.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){t.needsToBeRebuilt()?(t.parent||(t.parent=this),t.rebuild(),t.show()):this.add(t)}addUndoableEditor(t){const r=()=>t._uiManager.rebuild(t),n=()=>{t.remove()};this.addCommands({cmd:r,undo:n,mustExec:!1})}getNextId(){return b(this,tt).getId()}get _signal(){return b(this,tt)._signal}canCreateNewEmptyEditor(){var t;return(t=b(this,nx,RB))==null?void 0:t.canCreateNewEmptyEditor()}pasteEditor(t,r){b(this,tt).updateToolbar(t),b(this,tt).updateMode(t);const{offsetX:n,offsetY:o}=J(this,ix,$B).call(this),i=this.getNextId(),a=J(this,ox,FB).call(this,{parent:this,id:i,x:n,y:o,uiManager:b(this,tt),isCentered:!0,...r});a&&this.add(a)}deserialize(t){var r;return((r=b(Za,Lu).get(t.annotationType??t.annotationEditorType))==null?void 0:r.deserialize(t,this,b(this,tt)))||null}createAndAddNewEditor(t,r,n={}){const o=this.getNextId(),i=J(this,ox,FB).call(this,{parent:this,id:o,x:t.offsetX,y:t.offsetY,uiManager:b(this,tt),isCentered:r,...n});return i&&this.add(i),i}addNewEditor(){this.createAndAddNewEditor(J(this,ix,$B).call(this),!0)}setSelected(t){b(this,tt).setSelected(t)}toggleSelected(t){b(this,tt).toggleSelected(t)}isSelected(t){return b(this,tt).isSelected(t)}unselect(t){b(this,tt).unselect(t)}pointerup(t){const{isMac:r}=_i.platform;if(!(t.button!==0||t.ctrlKey&&r)&&t.target===this.div&&b(this,Bu)){if(G(this,Bu,!1),!b(this,Gg)){G(this,Gg,!0);return}if(b(this,tt).getMode()===Vt.STAMP){b(this,tt).unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){if(b(this,tt).getMode()===Vt.HIGHLIGHT&&this.enableTextSelection(),b(this,Bu)){G(this,Bu,!1);return}const{isMac:r}=_i.platform;if(t.button!==0||t.ctrlKey&&r||t.target!==this.div)return;G(this,Bu,!0);const n=b(this,tt).getActive();G(this,Gg,!n||n.isEmpty())}findNewParent(t,r,n){const o=b(this,tt).findParent(r,n);return o===null||o===this?!1:(o.changeParent(t),!0)}destroy(){var t,r;((t=b(this,tt).getActive())==null?void 0:t.parent)===this&&(b(this,tt).commitOrRemove(),b(this,tt).setActiveEditor(null)),b(this,il)&&(clearTimeout(b(this,il)),G(this,il,null));for(const n of b(this,Ji).values())(r=b(this,yh))==null||r.removePointerInTextLayer(n.contentDiv),n.setParent(null),n.isAttachedToDOM=!1,n.div.remove();this.div=null,b(this,Ji).clear(),b(this,tt).removeLayer(this)}render({viewport:t}){this.viewport=t,ef(this.div,t);for(const r of b(this,tt).getEditors(this.pageIndex))this.add(r),r.rebuild();this.updateMode()}update({viewport:t}){b(this,tt).commitOrRemove(),J(this,Jg,UD).call(this);const r=this.viewport.rotation,n=t.rotation;if(this.viewport=t,ef(this.div,{rotation:n}),r!==n)for(const o of b(this,Ji).values())o.rotate(n);this.addInkEditorIfNeeded(!1)}get pageDimensions(){const{pageWidth:t,pageHeight:r}=this.viewport.rawDims;return[t,r]}get scale(){return b(this,tt).viewParameters.realScale}};yh=new WeakMap,Gg=new WeakMap,Ys=new WeakMap,bh=new WeakMap,nl=new WeakMap,ol=new WeakMap,il=new WeakMap,Ji=new WeakMap,Bu=new WeakMap,Yg=new WeakMap,qg=new WeakMap,ii=new WeakMap,tt=new WeakMap,Lu=new WeakMap,aD=new WeakSet,sZ=function(t){if(b(this,tt).unselectAll(),t.target===b(this,ii).div){const{isMac:r}=_i.platform;if(t.button!==0||t.ctrlKey&&r)return;b(this,tt).showAllEditors("highlight",!0,!0),b(this,ii).div.classList.add("free"),QT.startHighlighting(this,b(this,tt).direction==="ltr",t),b(this,ii).div.addEventListener("pointerup",()=>{b(this,ii).div.classList.remove("free")},{once:!0,signal:b(this,tt)._signal}),t.preventDefault()}},nx=new WeakSet,RB=function(){return b(Za,Lu).get(b(this,tt).getMode())},ox=new WeakSet,FB=function(t){const r=b(this,nx,RB);return r?new r.prototype.constructor(t):null},ix=new WeakSet,$B=function(){const{x:t,y:r,width:n,height:o}=this.div.getBoundingClientRect(),i=Math.max(0,t),a=Math.max(0,r),s=Math.min(window.innerWidth,t+n),c=Math.min(window.innerHeight,r+o),l=(i+s)/2-t,d=(a+c)/2-r,[h,p]=this.viewport.rotation%180===0?[l,d]:[d,l];return{offsetX:h,offsetY:p}},Jg=new WeakSet,UD=function(){G(this,Yg,!0);for(const t of b(this,Ji).values())t.isEmpty()&&t.remove();G(this,Yg,!1)},Je(Za,"_initialized",!1),I(Za,Lu,new Map([KF,WF,XF,QT].map(t=>[t._editorType,t])));let GF=Za;const To=class To{constructor({pageIndex:t}){I(this,cx);I(this,sD);I(this,qs,null);I(this,ax,0);I(this,Xn,new Map);I(this,Vu,new Map);this.pageIndex=t}setParent(t){if(!b(this,qs)){G(this,qs,t);return}if(b(this,qs)!==t){if(b(this,Xn).size>0)for(const r of b(this,Xn).values())r.remove(),t.append(r);G(this,qs,t)}}static get _svgFactory(){return qt(this,"_svgFactory",new OF)}highlight(t,r,n,o=!1){const i=Zi(this,ax)._++,a=J(this,cx,LB).call(this,t.box);a.classList.add("highlight"),t.free&&a.classList.add("free");const s=To._svgFactory.createElement("defs");a.append(s);const c=To._svgFactory.createElement("path");s.append(c);const l=`path_p${this.pageIndex}_${i}`;c.setAttribute("id",l),c.setAttribute("d",t.toSVGPath()),o&&b(this,Vu).set(i,c);const d=J(this,sD,cZ).call(this,s,l),h=To._svgFactory.createElement("use");return a.append(h),a.setAttribute("fill",r),a.setAttribute("fill-opacity",n),h.setAttribute("href",`#${l}`),b(this,Xn).set(i,a),{id:i,clipPathId:`url(#${d})`}}highlightOutline(t){const r=Zi(this,ax)._++,n=J(this,cx,LB).call(this,t.box);n.classList.add("highlightOutline");const o=To._svgFactory.createElement("defs");n.append(o);const i=To._svgFactory.createElement("path");o.append(i);const a=`path_p${this.pageIndex}_${r}`;i.setAttribute("id",a),i.setAttribute("d",t.toSVGPath()),i.setAttribute("vector-effect","non-scaling-stroke");let s;if(t.free){n.classList.add("free");const d=To._svgFactory.createElement("mask");o.append(d),s=`mask_p${this.pageIndex}_${r}`,d.setAttribute("id",s),d.setAttribute("maskUnits","objectBoundingBox");const h=To._svgFactory.createElement("rect");d.append(h),h.setAttribute("width","1"),h.setAttribute("height","1"),h.setAttribute("fill","white");const p=To._svgFactory.createElement("use");d.append(p),p.setAttribute("href",`#${a}`),p.setAttribute("stroke","none"),p.setAttribute("fill","black"),p.setAttribute("fill-rule","nonzero"),p.classList.add("mask")}const c=To._svgFactory.createElement("use");n.append(c),c.setAttribute("href",`#${a}`),s&&c.setAttribute("mask",`url(#${s})`);const l=c.cloneNode();return n.append(l),c.classList.add("mainOutline"),l.classList.add("secondaryOutline"),b(this,Xn).set(r,n),r}finalizeLine(t,r){const n=b(this,Vu).get(t);b(this,Vu).delete(t),this.updateBox(t,r.box),n.setAttribute("d",r.toSVGPath())}updateLine(t,r){b(this,Xn).get(t).firstChild.firstChild.setAttribute("d",r.toSVGPath())}removeFreeHighlight(t){this.remove(t),b(this,Vu).delete(t)}updatePath(t,r){b(this,Vu).get(t).setAttribute("d",r.toSVGPath())}updateBox(t,r){var n;J(n=To,sx,BB).call(n,b(this,Xn).get(t),r)}show(t,r){b(this,Xn).get(t).classList.toggle("hidden",!r)}rotate(t,r){b(this,Xn).get(t).setAttribute("data-main-rotation",r)}changeColor(t,r){b(this,Xn).get(t).setAttribute("fill",r)}changeOpacity(t,r){b(this,Xn).get(t).setAttribute("fill-opacity",r)}addClass(t,r){b(this,Xn).get(t).classList.add(r)}removeClass(t,r){b(this,Xn).get(t).classList.remove(r)}remove(t){b(this,qs)!==null&&(b(this,Xn).get(t).remove(),b(this,Xn).delete(t))}destroy(){G(this,qs,null);for(const t of b(this,Xn).values())t.remove();b(this,Xn).clear()}};qs=new WeakMap,ax=new WeakMap,Xn=new WeakMap,Vu=new WeakMap,sx=new WeakSet,BB=function(t,{x:r=0,y:n=0,width:o=1,height:i=1}={}){const{style:a}=t;a.top=`${100*n}%`,a.left=`${100*r}%`,a.width=`${100*o}%`,a.height=`${100*i}%`},cx=new WeakSet,LB=function(t){var n;const r=To._svgFactory.create(1,1,!0);return b(this,qs).append(r),r.setAttribute("aria-hidden",!0),J(n=To,sx,BB).call(n,r,t),r},sD=new WeakSet,cZ=function(t,r){const n=To._svgFactory.createElement("clipPath");t.append(n);const o=`clip_${r}`;n.setAttribute("id",o),n.setAttribute("clipPathUnits","objectBoundingBox");const i=To._svgFactory.createElement("use");return n.append(i),i.setAttribute("href",`#${r}`),i.classList.add("clip"),o},I(To,sx);let YF=To;var a6e=ft.AbortException,s6e=ft.AnnotationEditorLayer,c6e=ft.AnnotationEditorParamsType,l6e=ft.AnnotationEditorType,u6e=ft.AnnotationEditorUIManager,uY=ft.AnnotationLayer,dY=ft.AnnotationMode,d6e=ft.CMapCompressionType,f6e=ft.ColorPicker,h6e=ft.DOMSVGFactory,p6e=ft.DrawLayer,m6e=ft.FeatureTest,qF=ft.GlobalWorkerOptions,g6e=ft.ImageKind,y6e=ft.InvalidPDFException,b6e=ft.MissingPDFException,v6e=ft.OPS,w6e=ft.Outliner,_6e=ft.PDFDataRangeTransport,O6e=ft.PDFDateString,x6e=ft.PDFWorker,j6e=ft.PasswordResponses,M6e=ft.PermissionFlag,S6e=ft.PixelsPerInch,E6e=ft.RenderingCancelledException,fY=ft.TextLayer,P6e=ft.UnexpectedResponseException,T6e=ft.Util,C6e=ft.VerbosityLevel,A6e=ft.XfaLayer,D6e=ft.build,z6e=ft.createValidAbsoluteUrl,U6e=ft.fetchData,hY=ft.getDocument,I6e=ft.getFilenameFromUrl,N6e=ft.getPdfFilenameFromUrl,R6e=ft.getXfaPageViewport,F6e=ft.isDataScheme,$6e=ft.isPdfFile,B6e=ft.noContextMenu,L6e=ft.normalizeUnicode,V6e=ft.renderTextLayer,K6e=ft.setLayerDimensions,H6e=ft.shadow,k6e=ft.updateTextLayer,pY=ft.version;const W6e=Object.freeze(Object.defineProperty({__proto__:null,AbortException:a6e,AnnotationEditorLayer:s6e,AnnotationEditorParamsType:c6e,AnnotationEditorType:l6e,AnnotationEditorUIManager:u6e,AnnotationLayer:uY,AnnotationMode:dY,CMapCompressionType:d6e,ColorPicker:f6e,DOMSVGFactory:h6e,DrawLayer:p6e,FeatureTest:m6e,GlobalWorkerOptions:qF,ImageKind:g6e,InvalidPDFException:y6e,MissingPDFException:b6e,OPS:v6e,Outliner:w6e,PDFDataRangeTransport:_6e,PDFDateString:O6e,PDFWorker:x6e,PasswordResponses:j6e,PermissionFlag:M6e,PixelsPerInch:S6e,RenderingCancelledException:E6e,TextLayer:fY,UnexpectedResponseException:P6e,Util:T6e,VerbosityLevel:C6e,XfaLayer:A6e,build:D6e,createValidAbsoluteUrl:z6e,fetchData:U6e,getDocument:hY,getFilenameFromUrl:I6e,getPdfFilenameFromUrl:N6e,getXfaPageViewport:R6e,isDataScheme:F6e,isPdfFile:$6e,noContextMenu:B6e,normalizeUnicode:L6e,renderTextLayer:V6e,setLayerDimensions:K6e,shadow:H6e,updateTextLayer:k6e,version:pY},Symbol.toStringTag,{value:"Module"}));var ao=function(e,t,r){if(r||arguments.length===2)for(var n=0,o=t.length,i;n<o;n++)(i||!(n in t))&&(i||(i=Array.prototype.slice.call(t,0,n)),i[n]=t[n]);return e.concat(i||Array.prototype.slice.call(t))},X6e=["onCopy","onCut","onPaste"],G6e=["onCompositionEnd","onCompositionStart","onCompositionUpdate"],Y6e=["onFocus","onBlur"],q6e=["onInput","onInvalid","onReset","onSubmit"],J6e=["onLoad","onError"],Q6e=["onKeyDown","onKeyPress","onKeyUp"],Z6e=["onAbort","onCanPlay","onCanPlayThrough","onDurationChange","onEmptied","onEncrypted","onEnded","onError","onLoadedData","onLoadedMetadata","onLoadStart","onPause","onPlay","onPlaying","onProgress","onRateChange","onSeeked","onSeeking","onStalled","onSuspend","onTimeUpdate","onVolumeChange","onWaiting"],e8e=["onClick","onContextMenu","onDoubleClick","onMouseDown","onMouseEnter","onMouseLeave","onMouseMove","onMouseOut","onMouseOver","onMouseUp"],t8e=["onDrag","onDragEnd","onDragEnter","onDragExit","onDragLeave","onDragOver","onDragStart","onDrop"],r8e=["onSelect"],n8e=["onTouchCancel","onTouchEnd","onTouchMove","onTouchStart"],o8e=["onPointerDown","onPointerMove","onPointerUp","onPointerCancel","onGotPointerCapture","onLostPointerCapture","onPointerEnter","onPointerLeave","onPointerOver","onPointerOut"],i8e=["onScroll"],a8e=["onWheel"],s8e=["onAnimationStart","onAnimationEnd","onAnimationIteration"],c8e=["onTransitionEnd"],l8e=["onToggle"],u8e=["onChange"],d8e=ao(ao(ao(ao(ao(ao(ao(ao(ao(ao(ao(ao(ao(ao(ao(ao(ao(ao([],X6e,!0),G6e,!0),Y6e,!0),q6e,!0),J6e,!0),Q6e,!0),Z6e,!0),e8e,!0),t8e,!0),r8e,!0),n8e,!0),o8e,!0),i8e,!0),a8e,!0),s8e,!0),c8e,!0),u8e,!0),l8e,!0);function mY(e,t){var r={};return d8e.forEach(function(n){var o=e[n];o&&(t?r[n]=function(i){return o(i,t(n))}:r[n]=o)}),r}function $_(e){var t=!1,r=new Promise(function(n,o){e.then(function(i){return!t&&n(i)}).catch(function(i){return!t&&o(i)})});return{promise:r,cancel:function(){t=!0}}}function gY(e){var t,r,n="";if(typeof e=="string"||typeof e=="number")n+=e;else if(typeof e=="object")if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(r=gY(e[t]))&&(n&&(n+=" "),n+=r)}else for(r in e)e[r]&&(n&&(n+=" "),n+=r);return n}function ZT(){for(var e,t,r=0,n="",o=arguments.length;r<o;r++)(e=arguments[r])&&(t=gY(e))&&(n&&(n+=" "),n+=t);return n}var f8e="Invariant failed";function Er(e,t){if(!e)throw new Error(f8e)}var yY=Object.prototype.hasOwnProperty;function bY(e,t,r){for(r of e.keys())if(Em(r,t))return r}function Em(e,t){var r,n,o;if(e===t)return!0;if(e&&t&&(r=e.constructor)===t.constructor){if(r===Date)return e.getTime()===t.getTime();if(r===RegExp)return e.toString()===t.toString();if(r===Array){if((n=e.length)===t.length)for(;n--&&Em(e[n],t[n]););return n===-1}if(r===Set){if(e.size!==t.size)return!1;for(n of e)if(o=n,o&&typeof o=="object"&&(o=bY(t,o),!o)||!t.has(o))return!1;return!0}if(r===Map){if(e.size!==t.size)return!1;for(n of e)if(o=n[0],o&&typeof o=="object"&&(o=bY(t,o),!o)||!Em(n[1],t.get(o)))return!1;return!0}if(r===ArrayBuffer)e=new Uint8Array(e),t=new Uint8Array(t);else if(r===DataView){if((n=e.byteLength)===t.byteLength)for(;n--&&e.getInt8(n)===t.getInt8(n););return n===-1}if(ArrayBuffer.isView(e)){if((n=e.byteLength)===t.byteLength)for(;n--&&e[n]===t[n];);return n===-1}if(!r||typeof e=="object"){n=0;for(r in e)if(yY.call(e,r)&&++n&&!yY.call(t,r)||!(r in t)||!Em(e[r],t[r]))return!1;return Object.keys(t).length===n}}return e!==e&&t!==t}const vY=_.createContext(null);function Pm({children:e,type:t}){return f.jsx("div",{className:`react-pdf__message react-pdf__message--${t}`,children:e})}const h8e="noopener noreferrer nofollow";class p8e{constructor(){this.externalLinkEnabled=!0,this.externalLinkRel=void 0,this.externalLinkTarget=void 0,this.isInPresentationMode=!1,this.pdfDocument=void 0,this.pdfViewer=void 0}setDocument(t){this.pdfDocument=t}setViewer(t){this.pdfViewer=t}setExternalLinkRel(t){this.externalLinkRel=t}setExternalLinkTarget(t){this.externalLinkTarget=t}setHistory(){}get pagesCount(){return this.pdfDocument?this.pdfDocument.numPages:0}get page(){return Er(this.pdfViewer),this.pdfViewer.currentPageNumber||0}set page(t){Er(this.pdfViewer),this.pdfViewer.currentPageNumber=t}get rotation(){return 0}set rotation(t){}goToDestination(t){return new Promise(r=>{Er(this.pdfDocument),Er(t),typeof t=="string"?this.pdfDocument.getDestination(t).then(r):Array.isArray(t)?r(t):t.then(r)}).then(r=>{Er(Array.isArray(r));const n=r[0];new Promise(o=>{Er(this.pdfDocument),n instanceof Object?this.pdfDocument.getPageIndex(n).then(i=>{o(i)}).catch(()=>{Er(!1)}):typeof n=="number"?o(n):Er(!1)}).then(o=>{const i=o+1;Er(this.pdfViewer),Er(i>=1&&i<=this.pagesCount),this.pdfViewer.scrollPageIntoView({dest:r,pageIndex:o,pageNumber:i})})})}navigateTo(t){this.goToDestination(t)}goToPage(t){const r=t-1;Er(this.pdfViewer),Er(t>=1&&t<=this.pagesCount),this.pdfViewer.scrollPageIntoView({pageIndex:r,pageNumber:t})}addLinkAttributes(t,r,n){t.href=r,t.rel=this.externalLinkRel||h8e,t.target=n?"_blank":this.externalLinkTarget||""}getDestinationHash(){return"#"}getAnchorUrl(){return"#"}setHash(){}executeNamedAction(){}cachePageRef(){}isPageVisible(){return!0}isPageCached(){return!0}executeSetOCGState(){}}const wY={NEED_PASSWORD:1,INCORRECT_PASSWORD:2},eC=typeof document<"u",_Y=eC&&window.location.protocol==="file:";function m8e(e){return typeof e<"u"}function of(e){return m8e(e)&&e!==null}function g8e(e){return typeof e=="string"}function y8e(e){return e instanceof ArrayBuffer}function b8e(e){return Er(eC),e instanceof Blob}function JF(e){return g8e(e)&&/^data:/.test(e)}function OY(e){Er(JF(e));const[t="",r=""]=e.split(",");return t.split(";").indexOf("base64")!==-1?atob(r):unescape(r)}function v8e(){return eC&&window.devicePixelRatio||1}const xY="On Chromium based browsers, you can use --allow-file-access-from-files flag for debugging purposes.";function jY(){wo(!_Y,`Loading PDF as base64 strings/URLs may not work on protocols other than HTTP/HTTPS. ${xY}`)}function w8e(){wo(!_Y,`Loading PDF.js worker may not work on protocols other than HTTP/HTTPS. ${xY}`)}function af(e){e!=null&&e.cancel&&e.cancel()}function QF(e,t){return Object.defineProperty(e,"width",{get(){return this.view[2]*t},configurable:!0}),Object.defineProperty(e,"height",{get(){return this.view[3]*t},configurable:!0}),Object.defineProperty(e,"originalWidth",{get(){return this.view[2]},configurable:!0}),Object.defineProperty(e,"originalHeight",{get(){return this.view[3]},configurable:!0}),e}function _8e(e){return e.name==="RenderingCancelledException"}function O8e(e){return new Promise((t,r)=>{const n=new FileReader;n.onload=()=>{if(!n.result)return r(new Error("Error while reading a file."));t(n.result)},n.onerror=o=>{if(!o.target)return r(new Error("Error while reading a file."));const{error:i}=o.target;if(!i)return r(new Error("Error while reading a file."));switch(i.code){case i.NOT_FOUND_ERR:return r(new Error("Error while reading a file: File not found."));case i.SECURITY_ERR:return r(new Error("Error while reading a file: Security error."));case i.ABORT_ERR:return r(new Error("Error while reading a file: Aborted."));default:return r(new Error("Error while reading a file."))}},n.readAsArrayBuffer(e)})}function x8e(e,t){switch(t.type){case"RESOLVE":return{value:t.value,error:void 0};case"REJECT":return{value:!1,error:t.error};case"RESET":return{value:void 0,error:void 0};default:return e}}function Tm(){return _.useReducer(x8e,{value:void 0,error:void 0})}var j8e=function(e,t,r,n){function o(i){return i instanceof r?i:new r(function(a){a(i)})}return new(r||(r=Promise))(function(i,a){function s(d){try{l(n.next(d))}catch(h){a(h)}}function c(d){try{l(n.throw(d))}catch(h){a(h)}}function l(d){d.done?i(d.value):o(d.value).then(s,c)}l((n=n.apply(e,t||[])).next())})},MY=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]]);return r};const{PDFDataRangeTransport:M8e}=W6e,S8e=(e,t)=>{switch(t){case wY.NEED_PASSWORD:{const r=prompt("Enter the password to open this PDF file.");e(r);break}case wY.INCORRECT_PASSWORD:{const r=prompt("Invalid password. Please try again.");e(r);break}}};function SY(e){return typeof e=="object"&&e!==null&&("data"in e||"range"in e||"url"in e)}const E8e=_.forwardRef(function(t,r){var{children:n,className:o,error:i="Failed to load PDF file.",externalLinkRel:a,externalLinkTarget:s,file:c,inputRef:l,imageResourcesPath:d,loading:h="Loading PDF…",noData:p="No PDF file specified.",onItemClick:m,onLoadError:g,onLoadProgress:y,onLoadSuccess:w,onPassword:v=S8e,onSourceError:O,onSourceSuccess:x,options:S,renderMode:j,rotate:P}=t,D=MY(t,["children","className","error","externalLinkRel","externalLinkTarget","file","inputRef","imageResourcesPath","loading","noData","onItemClick","onLoadError","onLoadProgress","onLoadSuccess","onPassword","onSourceError","onSourceSuccess","options","renderMode","rotate"]);const[M,T]=Tm(),{value:z,error:A}=M,[L,H]=Tm(),{value:X,error:K}=L,W=_.useRef(new p8e),$=_.useRef([]),Z=_.useRef(void 0),re=_.useRef(void 0);c&&c!==Z.current&&SY(c)&&(wo(!Em(c,Z.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.`),Z.current=c),S&&S!==re.current&&(wo(!Em(S,re.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.`),re.current=S);const B=_.useRef({scrollPageIntoView:ye=>{const{dest:je,pageNumber:Ee,pageIndex:Se=Ee-1}=ye;if(m){m({dest:je,pageIndex:Se,pageNumber:Ee});return}const Te=$.current[Se];if(Te){Te.scrollIntoView();return}wo(!1,`An internal link leading to page ${Ee} 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>.`)}});_.useImperativeHandle(r,()=>({linkService:W,pages:$,viewer:B}),[]);function ce(){x&&x()}function F(){A&&(wo(!1,A.toString()),O&&O(A))}function oe(){T({type:"RESET"})}_.useEffect(oe,[c,T]);const ie=_.useCallback(()=>j8e(this,void 0,void 0,function*(){if(!c)return null;if(typeof c=="string")return JF(c)?{data:OY(c)}:(jY(),{url:c});if(c instanceof M8e)return{range:c};if(y8e(c))return{data:c};if(eC&&b8e(c))return{data:yield O8e(c)};if(Er(typeof c=="object"),Er(SY(c)),"url"in c&&typeof c.url=="string"){if(JF(c.url)){const{url:ye}=c,je=MY(c,["url"]),Ee=OY(ye);return Object.assign({data:Ee},je)}jY()}return c}),[c]);_.useEffect(()=>{const ye=$_(ie());return ye.promise.then(je=>{T({type:"RESOLVE",value:je})}).catch(je=>{T({type:"REJECT",error:je})}),()=>{af(ye)}},[ie,T]),_.useEffect(()=>{if(!(typeof z>"u")){if(z===!1){F();return}ce()}},[z]);function le(){X&&(w&&w(X),$.current=new Array(X.numPages),W.current.setDocument(X))}function Y(){K&&(wo(!1,K.toString()),g&&g(K))}_.useEffect(function(){H({type:"RESET"})},[H,z]),_.useEffect(function(){if(!z)return;const je=Object.assign(Object.assign({},z),S),Ee=hY(je);y&&(Ee.onProgress=y),v&&(Ee.onPassword=v);const Se=Ee;return Se.promise.then(Te=>{H({type:"RESOLVE",value:Te})}).catch(Te=>{Se.destroyed||H({type:"REJECT",error:Te})}),()=>{Se.destroy()}},[S,H,z]),_.useEffect(()=>{if(!(typeof X>"u")){if(X===!1){Y();return}le()}},[X]),_.useEffect(function(){W.current.setViewer(B.current),W.current.setExternalLinkRel(a),W.current.setExternalLinkTarget(s)},[a,s]);const N=_.useCallback((ye,je)=>{$.current[ye]=je},[]),q=_.useCallback(ye=>{delete $.current[ye]},[]),te=_.useMemo(()=>({imageResourcesPath:d,linkService:W.current,onItemClick:m,pdf:X,registerPage:N,renderMode:j,rotate:P,unregisterPage:q}),[d,m,X,N,j,P,q]),fe=_.useMemo(()=>mY(D,()=>X),[D,X]);function R(){return f.jsx(vY.Provider,{value:te,children:n})}function k(){return c?X==null?f.jsx(Pm,{type:"loading",children:typeof h=="function"?h():h}):X===!1?f.jsx(Pm,{type:"error",children:typeof i=="function"?i():i}):R():f.jsx(Pm,{type:"no-data",children:typeof p=="function"?p():p})}return f.jsx("div",Object.assign({className:ZT("react-pdf__Document",o),ref:l,style:{"--scale-factor":"1"}},fe,{children:k()}))});function EY(){return _.useContext(vY)}function PY(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r=e.filter(Boolean);if(r.length<=1){var n=r[0];return n||null}return function(i){r.forEach(function(a){typeof a=="function"?a(i):a&&(a.current=i)})}}const TY=_.createContext(null),CY={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},P8e=/^H(\d+)$/;function T8e(e){return e in CY}function tC(e){return"children"in e}function AY(e){return tC(e)?e.children.length===1&&0 in e.children&&"id"in e.children[0]:!1}function C8e(e){const t={};if(tC(e)){const{role:r}=e,n=r.match(P8e);if(n)t.role="heading",t["aria-level"]=Number(n[1]);else if(T8e(r)){const o=CY[r];o&&(t.role=o)}}return t}function DY(e){const t={};if(tC(e)){if(e.alt!==void 0&&(t["aria-label"]=e.alt),e.lang!==void 0&&(t.lang=e.lang),AY(e)){const[r]=e.children;if(r){const n=DY(r);return Object.assign(Object.assign({},t),n)}}}else"id"in e&&(t["aria-owns"]=e.id);return t}function A8e(e){return e?Object.assign(Object.assign({},C8e(e)),DY(e)):null}function zY({className:e,node:t}){const r=_.useMemo(()=>A8e(t),[t]),n=_.useMemo(()=>!tC(t)||AY(t)?null:t.children.map((o,i)=>f.jsx(zY,{node:o},i)),[t]);return f.jsx("span",Object.assign({className:e},r,{children:n}))}function rC(){return _.useContext(TY)}function D8e(){const e=rC();Er(e);const{onGetStructTreeError:t,onGetStructTreeSuccess:r}=e,[n,o]=Tm(),{value:i,error:a}=n,{customTextRenderer:s,page:c}=e;function l(){i&&r&&r(i)}function d(){a&&(wo(!1,a.toString()),t&&t(a))}return _.useEffect(function(){o({type:"RESET"})},[o,c]),_.useEffect(function(){if(s||!c)return;const p=$_(c.getStructTree()),m=p;return p.promise.then(g=>{o({type:"RESOLVE",value:g})}).catch(g=>{o({type:"REJECT",error:g})}),()=>af(m)},[s,c,o]),_.useEffect(()=>{if(i!==void 0){if(i===!1){d();return}l()}},[i]),i?f.jsx(zY,{className:"react-pdf__Page__structTree structTree",node:i}):null}const UY=dY;function z8e(e){const t=rC();Er(t);const r=Object.assign(Object.assign({},t),e),{_className:n,canvasBackground:o,devicePixelRatio:i=v8e(),onRenderError:a,onRenderSuccess:s,page:c,renderForms:l,renderTextLayer:d,rotate:h,scale:p}=r,{canvasRef:m}=e;Er(c);const g=_.useRef(null);function y(){c&&s&&s(QF(c,p))}function w(S){_8e(S)||(wo(!1,S.toString()),a&&a(S))}const v=_.useMemo(()=>c.getViewport({scale:p*i,rotation:h}),[i,c,h,p]),O=_.useMemo(()=>c.getViewport({scale:p,rotation:h}),[c,h,p]);_.useEffect(function(){if(!c)return;c.cleanup();const{current:j}=g;if(!j)return;j.width=v.width,j.height=v.height,j.style.width=`${Math.floor(O.width)}px`,j.style.height=`${Math.floor(O.height)}px`,j.style.visibility="hidden";const P={annotationMode:l?UY.ENABLE_FORMS:UY.ENABLE,canvasContext:j.getContext("2d",{alpha:!1}),viewport:v};o&&(P.background=o);const D=c.render(P),M=D;return D.promise.then(()=>{j.style.visibility="",y()}).catch(w),()=>af(M)},[o,c,l,v,O]);const x=_.useCallback(()=>{const{current:S}=g;S&&(S.width=0,S.height=0)},[]);return _.useEffect(()=>x,[x]),f.jsx("canvas",{className:`${n}__canvas`,dir:"ltr",ref:PY(m,g),style:{display:"block",userSelect:"none"},children:d?f.jsx(D8e,{}):null})}function U8e(e){return"str"in e}function I8e(){const e=rC();Er(e);const{customTextRenderer:t,onGetTextError:r,onGetTextSuccess:n,onRenderTextLayerError:o,onRenderTextLayerSuccess:i,page:a,pageIndex:s,pageNumber:c,rotate:l,scale:d}=e;Er(a);const[h,p]=Tm(),{value:m,error:g}=h,y=_.useRef(null),w=_.useRef(void 0);wo(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 v(){m&&n&&n(m)}function O(){g&&(wo(!1,g.toString()),r&&r(g))}_.useEffect(function(){p({type:"RESET"})},[a,p]),_.useEffect(function(){if(!a)return;const T=$_(a.getTextContent()),z=T;return T.promise.then(A=>{p({type:"RESOLVE",value:A})}).catch(A=>{p({type:"REJECT",error:A})}),()=>af(z)},[a,p]),_.useEffect(()=>{if(m!==void 0){if(m===!1){O();return}v()}},[m]);const x=_.useCallback(()=>{i&&i()},[i]),S=_.useCallback(M=>{wo(!1,M.toString()),o&&o(M)},[o]);function j(){const M=w.current;M&&M.classList.add("active")}function P(){const M=w.current;M&&M.classList.remove("active")}const D=_.useMemo(()=>a.getViewport({scale:d,rotation:l}),[a,l,d]);return _.useLayoutEffect(function(){if(!a||!m)return;const{current:T}=y;if(!T)return;T.innerHTML="";const z=a.streamTextContent({includeMarkedContent:!0}),A={container:T,textContentSource:z,viewport:D},L=new fY(A),H=L;return L.render().then(()=>{const X=document.createElement("div");X.className="endOfContent",T.append(X),w.current=X;const K=T.querySelectorAll('[role="presentation"]');if(t){let W=0;m.items.forEach(($,Z)=>{if(!U8e($))return;const re=K[W];if(!re)return;const B=t(Object.assign({pageIndex:s,pageNumber:c,itemIndex:Z},$));re.innerHTML=B,W+=$.str&&$.hasEOL?2:1})}x()}).catch(S),()=>af(H)},[t,S,x,a,s,c,m,D]),f.jsx("div",{className:ZT("react-pdf__Page__textContent","textLayer"),onMouseUp:P,onMouseDown:j,ref:y})}function N8e(){const e=EY(),t=rC();Er(t);const r=Object.assign(Object.assign({},e),t),{imageResourcesPath:n,linkService:o,onGetAnnotationsError:i,onGetAnnotationsSuccess:a,onRenderAnnotationLayerError:s,onRenderAnnotationLayerSuccess:c,page:l,pdf:d,renderForms:h,rotate:p,scale:m=1}=r;Er(d),Er(l),Er(o);const[g,y]=Tm(),{value:w,error:v}=g,O=_.useRef(null);wo(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 x(){w&&a&&a(w)}function S(){v&&(wo(!1,v.toString()),i&&i(v))}_.useEffect(function(){y({type:"RESET"})},[y,l]),_.useEffect(function(){if(!l)return;const T=$_(l.getAnnotations()),z=T;return T.promise.then(A=>{y({type:"RESOLVE",value:A})}).catch(A=>{y({type:"REJECT",error:A})}),()=>{af(z)}},[y,l]),_.useEffect(()=>{if(w!==void 0){if(w===!1){S();return}x()}},[w]);function j(){c&&c()}function P(M){wo(!1,`${M}`),s&&s(M)}const D=_.useMemo(()=>l.getViewport({scale:m,rotation:p}),[l,p,m]);return _.useEffect(function(){if(!d||!l||!o||!w)return;const{current:T}=O;if(!T)return;const z=D.clone({dontFlip:!0}),A={accessibilityManager:null,annotationCanvasMap:null,annotationEditorUIManager:null,div:T,l10n:null,page:l,viewport:z},L={annotations:w,annotationStorage:d.annotationStorage,div:T,imageResourcesPath:n,linkService:o,page:l,renderForms:h,viewport:z};T.innerHTML="";try{new uY(A).render(L),j()}catch(H){P(H)}return()=>{}},[w,n,o,l,d,h,D]),f.jsx("div",{className:ZT("react-pdf__Page__annotations","annotationLayer"),ref:O})}var R8e=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]]);return r};const IY=1;function F8e(e){const t=EY(),r=Object.assign(Object.assign({},t),e),{_className:n="react-pdf__Page",_enableRegisterUnregisterPage:o=!0,canvasBackground:i,canvasRef:a,children:s,className:c,customRenderer:l,customTextRenderer:d,devicePixelRatio:h,error:p="Failed to load the page.",height:m,inputRef:g,loading:y="Loading page…",noData:w="No page specified.",onGetAnnotationsError:v,onGetAnnotationsSuccess:O,onGetStructTreeError:x,onGetStructTreeSuccess:S,onGetTextError:j,onGetTextSuccess:P,onLoadError:D,onLoadSuccess:M,onRenderAnnotationLayerError:T,onRenderAnnotationLayerSuccess:z,onRenderError:A,onRenderSuccess:L,onRenderTextLayerError:H,onRenderTextLayerSuccess:X,pageIndex:K,pageNumber:W,pdf:$,registerPage:Z,renderAnnotationLayer:re=!0,renderForms:B=!1,renderMode:ce="canvas",renderTextLayer:F=!0,rotate:oe,scale:ie=IY,unregisterPage:le,width:Y}=r,N=R8e(r,["_className","_enableRegisterUnregisterPage","canvasBackground","canvasRef","children","className","customRenderer","customTextRenderer","devicePixelRatio","error","height","inputRef","loading","noData","onGetAnnotationsError","onGetAnnotationsSuccess","onGetStructTreeError","onGetStructTreeSuccess","onGetTextError","onGetTextSuccess","onLoadError","onLoadSuccess","onRenderAnnotationLayerError","onRenderAnnotationLayerSuccess","onRenderError","onRenderSuccess","onRenderTextLayerError","onRenderTextLayerSuccess","pageIndex","pageNumber","pdf","registerPage","renderAnnotationLayer","renderForms","renderMode","renderTextLayer","rotate","scale","unregisterPage","width"]),[q,te]=Tm(),{value:fe,error:R}=q,k=_.useRef(null);Er($);const ye=of(W)?W-1:K??null,je=W??(of(K)?K+1:null),Ee=oe??(fe?fe.rotate:null),Se=_.useMemo(()=>{if(!fe)return null;let U=1;const E=ie??IY;if(Y||m){const C=fe.getViewport({scale:1,rotation:Ee});Y?U=Y/C.width:m&&(U=m/C.height)}return E*U},[m,fe,Ee,ie,Y]);_.useEffect(function(){return()=>{of(ye)&&o&&le&&le(ye)}},[o,$,ye,le]);function Te(){if(M){if(!fe||!Se)return;M(QF(fe,Se))}if(o&&Z){if(!of(ye)||!k.current)return;Z(ye,k.current)}}function ue(){R&&(wo(!1,R.toString()),D&&D(R))}_.useEffect(function(){te({type:"RESET"})},[te,$,ye]),_.useEffect(function(){if(!$||!je)return;const E=$_($.getPage(je)),C=E;return E.promise.then(ee=>{te({type:"RESOLVE",value:ee})}).catch(ee=>{te({type:"REJECT",error:ee})}),()=>af(C)},[te,$,je]),_.useEffect(()=>{if(fe!==void 0){if(fe===!1){ue();return}Te()}},[fe,Se]);const ne=_.useMemo(()=>fe&&of(ye)&&je&&of(Ee)&&of(Se)?{_className:n,canvasBackground:i,customTextRenderer:d,devicePixelRatio:h,onGetAnnotationsError:v,onGetAnnotationsSuccess:O,onGetStructTreeError:x,onGetStructTreeSuccess:S,onGetTextError:j,onGetTextSuccess:P,onRenderAnnotationLayerError:T,onRenderAnnotationLayerSuccess:z,onRenderError:A,onRenderSuccess:L,onRenderTextLayerError:H,onRenderTextLayerSuccess:X,page:fe,pageIndex:ye,pageNumber:je,renderForms:B,renderTextLayer:F,rotate:Ee,scale:Se}:null,[n,i,d,h,v,O,x,S,j,P,T,z,A,L,H,X,fe,ye,je,B,F,Ee,Se]),ve=_.useMemo(()=>mY(N,()=>fe&&(Se?QF(fe,Se):void 0)),[N,fe,Se]),we=`${ye}@${Se}/${Ee}`;function _e(){switch(ce){case"custom":return Er(l),f.jsx(l,{},`${we}_custom`);case"none":return null;case"canvas":default:return f.jsx(z8e,{canvasRef:a},`${we}_canvas`)}}function be(){return F?f.jsx(I8e,{},`${we}_text`):null}function V(){return re?f.jsx(N8e,{},`${we}_annotations`):null}function me(){return f.jsxs(TY.Provider,{value:ne,children:[_e(),be(),V(),s]})}function ae(){return je?$===null||fe===void 0||fe===null?f.jsx(Pm,{type:"loading",children:typeof y=="function"?y():y}):$===!1||fe===!1?f.jsx(Pm,{type:"error",children:typeof p=="function"?p():p}):me():f.jsx(Pm,{type:"no-data",children:typeof w=="function"?w():w})}return f.jsx("div",Object.assign({className:ZT(n,c),"data-page-number":je,ref:PY(g,k),style:{"--scale-factor":`${Se}`,backgroundColor:i||"white",position:"relative",minWidth:"min-content",minHeight:"min-content"}},ve,{children:ae()}))}w8e(),qF.workerSrc="pdf.worker.mjs";const pu=S9,$8e=YX;pu.extend($8e);const sf=({day:e=1,month:t,year:r})=>pu(`${r}-${t}-${e}`,"YYYY-M-D"),B_=(e,t,r,n)=>{let o=pu(sf({month:r,year:n})).day(t);return o.month()!==r-1&&(o=o.add(1,"week")),o=o.add(e-1,"week"),o},B8e=(e,t,r)=>{const n=pu(sf({month:t,year:r})).daysInMonth();let i=pu(`${r}-${t}-${n}`,"YYYY-M-D").day(e);return i.month()!==t-1&&(i=i.subtract(1,"week")),i},nC=(e=new Date().getFullYear(),{shiftSaturdayHolidays:t=!0,shiftSundayHolidays:r=!0}={})=>{const n=[];return n.push({name:"New Year's Day",date:sf({day:1,month:1,year:e})}),n.push({name:"Birthday of Martin Luther King, Jr.",date:B_(3,1,1,e)}),n.push({name:"Washington's Birthday",alsoObservedAs:"Presidents' Day",date:B_(3,1,2,e)}),n.push({name:"Memorial Day",date:B8e(1,5,e)}),e>2020&&n.push({name:"Juneteenth National Independence Day",date:sf({day:19,month:6,year:e})}),n.push({name:"Independence Day",date:sf({day:4,month:7,year:e})}),n.push({name:"Labor Day",date:B_(1,1,9,e)}),n.push({name:"Columbus Day",alsoObservedAs:"Indigenous Peoples' Day",date:B_(2,1,10,e)}),n.push({name:"Veterans Day",date:sf({day:11,month:11,year:e})}),n.push({name:"Thanksgiving Day",date:B_(4,4,11,e)}),n.push({name:"Christmas Day",date:sf({day:25,month:12,year:e})}),n.map(o=>{let i=pu(o.date);return i.day()===0&&r&&(i=i.add(1,"day")),i.day()===6&&t&&(i=i.subtract(1,"day")),{name:o.name,alsoObservedAs:o.alsoObservedAs,date:i.toDate(),dateString:i.format("YYYY-MM-DD")}})},L8e=(e=new Date,{shiftSaturdayHolidays:t=!0,shiftSundayHolidays:r=!0,utc:n=!1}={})=>{const o=n?pu.utc(e):pu(e),i=o.year(),a={shiftSaturdayHolidays:t,shiftSundayHolidays:r},s=nC(i,a),c=nC(i+1,a);return s.push(c[0]),s.some(l=>l.dateString===o.format("YYYY-MM-DD"))},V8e=()=>{const e=new Date;return e.setUTCFullYear(e.getUTCFullYear()+1),e};var K8e={isAHoliday:L8e,allForYear:nC,inRange:(e=new Date,t=V8e(),r=void 0)=>{const n=e.getFullYear(),o=t.getFullYear(),i=[];for(let a=n;a<=o;a+=1)i.push(...nC(a,r));return i.filter(a=>a.date>=e&&a.date<=t)}};const H8e=on(K8e).allForYear();function NY(e){const t=ke(e).day();return!(t===0||t===6||H8e.find(r=>ke(r.date).isSame(e,"day")))}ke.extend(aF),ke.extend(u3e),ke.extend(f3e);const k8e=wX;qF.workerSrc=`//unpkg.com/pdfjs-dist@${pY}/build/pdf.worker.min.mjs`;const oC=[Q.Mercoa.InvoiceStatus.Scheduled,Q.Mercoa.InvoiceStatus.Pending,Q.Mercoa.InvoiceStatus.Paid,Q.Mercoa.InvoiceStatus.Canceled,Q.Mercoa.InvoiceStatus.Archived,Q.Mercoa.InvoiceStatus.Refused];function RY({invoiceId:e,invoice:t,onRedirect:r,heightOffset:n,admin:o,documentPosition:i="left",invoicePreSubmit:a,children:s}){var P;const c=Be(),l=n??c.heightOffset,[d,h]=_.useState(),[p,m]=_.useState(),[g,y]=_.useState(t),[w,v]=_.useState(typeof window<"u"?window.innerHeight-l:0);async function O(D){var T,z;if(!c.token||!((T=c.entity)!=null&&T.id))return;const M=await((z=c.client)==null?void 0:z.invoice.get(D));M&&y(M)}_.useEffect(()=>{var D;!c.token||!((D=c.entity)!=null&&D.id)||!t&&e&&O(e)},[t,e,c.token,(P=c.entity)==null?void 0:P.id]);function x(){v(window.innerHeight-l)}if(_.useEffect(()=>(x(),window.addEventListener("resize",x,!1),()=>{window.removeEventListener("resize",x)}),[l]),!c.client)return f.jsx(nt,{componentName:"PayableDetails"});let S,j;if(s){const D=s({invoice:g,ocrResponse:d,uploadedDocument:p,setUploadedDocument:m,height:w,refreshInvoice:O,invoicePreSubmit:a,onOcrComplete:h,onRedirect:r});S=D[0],j=D[1]}else S=f.jsx(BY,{onOcrComplete:h,setUploadedDocument:m,height:w,invoice:g}),j=f.jsx(FY,{invoice:g,ocrResponse:d,uploadedDocument:p,setUploadedDocument:m,onRedirect:r,refreshInvoice:O,height:w,admin:o,invoicePreSubmit:a});return i==="none"||!j?j??S??f.jsx(f.Fragment,{}):f.jsxs(LX,{children:[f.jsx(OT,{className:"mercoa-relative mercoa-px-5",minSize:0,children:i==="left"?S:j}),f.jsx(VX,{size:10,className:"mercoa-cursor-col-resize mercoa-invisible min-[450px]:mercoa-visible",style:{background:"linear-gradient(180deg, rgba(229,231,235,1) 48%, rgba(145,145,145,1) 48%, rgba(145,145,145,1) 52%, rgba(229,231,235,1) 52%)"}}),f.jsx(OT,{className:"mercoa-relative mercoa-px-5",minSize:400,children:i==="right"?S:j})]})}function FY({invoice:e,ocrResponse:t,uploadedDocument:r,setUploadedDocument:n,onRedirect:o,refreshInvoice:i,height:a,admin:s,invoicePreSubmit:c,children:l}){var H,X,K,W,$,Z,re,B,ce,F,oe,ie,le,Y,N,q,te,fe,R,k,ye,je,Ee,Se,Te,ue,ne,ve,we,_e,be,V,me,ae,U,E,C,ee,he,xe,Pe;const d=Be(),[h,p]=_.useState(e==null?void 0:e.vendor),[m,g]=_.useState(!1),y=to({id:Fe().nullable(),status:Fe(),amount:gs().transform(v_).positive().typeError("Please enter a valid number"),invoiceNumber:Fe(),description:Fe(),processedAt:bo().nullable(),dueDate:bo().typeError("Please select a due date"),deductionDate:bo().typeError("Please select a deduction date"),invoiceDate:bo().typeError("Please select an invoice date"),approvers:yo(),lineItems:l1().of(to({id:Fe(),description:Fe().required(),amount:gs().transform(v_).required().typeError("Please enter a valid number"),quantity:gs().transform(v_).required().typeError("Please enter a valid number"),unitPrice:gs().transform(v_).required().typeError("Please enter a valid number"),currency:Fe().nullable(),metadata:yo().nullable(),glAccountId:Fe(),createdAt:bo().nullable(),updatedAt:bo().nullable()})),currency:Fe().required(),vendorId:Fe(),vendorName:Fe(),paymentDestinationId:Fe(),paymentDestinationType:Fe(),paymentDestinationSchemaId:Fe().nullable(),paymentDestinationOptions:yo().nullable(),paymentSourceId:Fe(),paymentSourceType:Fe(),paymentSourceCheckEnabled:Jl().nullable(),paymentSourceSchemaId:Fe().nullable(),hasDocuments:Jl().nullable(),saveAsStatus:Fe().nullable(),saveAsAdmin:Jl(),metadata:yo().nullable(),newBankAccount:yo().nullable(),newCheck:yo().nullable(),commentText:Fe().nullable(),comments:yo().nullable(),creatorUser:yo().nullable(),approvalPolicy:yo().nullable(),vendor:to().shape(p1),"~cpm~~":yo().nullable(),fees:yo().nullable(),failureType:Fe().nullable(),createdAt:bo().nullable(),updatedAt:bo().nullable()}).required(),w=Zn({resolver:za(y),defaultValues:{id:e==null?void 0:e.id,status:e==null?void 0:e.status,invoiceNumber:e==null?void 0:e.invoiceNumber,amount:e==null?void 0:e.amount,currency:(e==null?void 0:e.currency)??"USD",vendorId:(H=e==null?void 0:e.vendor)==null?void 0:H.id,vendorName:(X=e==null?void 0:e.vendor)==null?void 0:X.name,invoiceDate:e!=null&&e.invoiceDate?ke(e==null?void 0:e.invoiceDate).toDate():void 0,dueDate:e!=null&&e.dueDate?ke(e==null?void 0:e.dueDate).toDate():void 0,deductionDate:e!=null&&e.deductionDate?ke(e==null?void 0:e.deductionDate).toDate():void 0,processedAt:e!=null&&e.processedAt?ke(e==null?void 0:e.processedAt).toDate():void 0,lineItems:(e==null?void 0:e.lineItems)??[],paymentDestinationId:(K=e==null?void 0:e.paymentDestination)==null?void 0:K.id,paymentDestinationType:((W=e==null?void 0:e.paymentDestination)==null?void 0:W.type)??"",paymentDestinationOptions:e==null?void 0:e.paymentDestinationOptions,paymentSourceId:($=e==null?void 0:e.paymentSource)==null?void 0:$.id,paymentSourceType:((Z=e==null?void 0:e.paymentSource)==null?void 0:Z.type)??"",paymentSourceCheckEnabled:((B=(re=e==null?void 0:e.paymentSource)==null?void 0:re.checkOptions)==null?void 0:B.enabled)??!1,description:(e==null?void 0:e.noteToSelf)??"",hasDocuments:(e==null?void 0:e.hasDocuments)??!!r??!1,saveAsStatus:"",saveAsAdmin:!1,metadata:(e==null?void 0:e.metadata)??{},approvalPolicy:(e==null?void 0:e.approvalPolicy)??{type:"any",approvers:[]},approvers:(e==null?void 0:e.approvers)??[],fees:e==null?void 0:e.fees,createdAt:e==null?void 0:e.createdAt,updatedAt:e==null?void 0:e.updatedAt,newBankAccount:{routingNumber:"",accountNumber:"",bankName:"",accountType:Q.Mercoa.BankType.Checking},newCheck:{payToTheOrderOf:"",addressLine1:"",addressLine2:"",city:"",state:"",postalCode:"",country:"US"},"~cpm~~":{},failureType:(e==null?void 0:e.failureType)??"",commentText:"",comments:(e==null?void 0:e.comments)??[],creatorUser:e==null?void 0:e.creatorUser,vendor:{id:(ce=e==null?void 0:e.vendor)==null?void 0:ce.id,accountType:(F=e==null?void 0:e.vendor)==null?void 0:F.accountType,name:(oe=e==null?void 0:e.vendor)==null?void 0:oe.name,firstName:(N=(Y=(le=(ie=e==null?void 0:e.vendor)==null?void 0:ie.profile)==null?void 0:le.individual)==null?void 0:Y.name)==null?void 0:N.firstName,lastName:(R=(fe=(te=(q=e==null?void 0:e.vendor)==null?void 0:q.profile)==null?void 0:te.individual)==null?void 0:fe.name)==null?void 0:R.lastName,middleName:(Ee=(je=(ye=(k=e==null?void 0:e.vendor)==null?void 0:k.profile)==null?void 0:ye.individual)==null?void 0:je.name)==null?void 0:Ee.middleName,suffix:(ne=(ue=(Te=(Se=e==null?void 0:e.vendor)==null?void 0:Se.profile)==null?void 0:Te.individual)==null?void 0:ue.name)==null?void 0:ne.suffix,email:((ve=e==null?void 0:e.vendor)==null?void 0:ve.accountType)==="business"?(be=(_e=(we=e==null?void 0:e.vendor)==null?void 0:we.profile)==null?void 0:_e.business)==null?void 0:be.email:(ae=(me=(V=e==null?void 0:e.vendor)==null?void 0:V.profile)==null?void 0:me.individual)==null?void 0:ae.email,website:(C=(E=(U=e==null?void 0:e.vendor)==null?void 0:U.profile)==null?void 0:E.business)==null?void 0:C.website,description:(xe=(he=(ee=e==null?void 0:e.vendor)==null?void 0:ee.profile)==null?void 0:he.business)==null?void 0:xe.description,accounts:[]}}}),{handleSubmit:v,setValue:O,setError:x,clearErrors:S,watch:j,control:P,formState:{errors:D}}=w;_.useEffect(()=>{var Me,Ye,De,qe,it,Gn,Bt,Ei,lt,Kr,Yo,Co;e&&(e.vendor&&!h&&p(e.vendor),((Me=e.paymentDestination)==null?void 0:Me.type)==="custom"?O("paymentDestinationType",((Ye=e.paymentDestination)==null?void 0:Ye.schemaId)??""):O("paymentDestinationType",((De=e.paymentDestination)==null?void 0:De.type)??""),((qe=e.paymentSource)==null?void 0:qe.type)==="custom"?O("paymentSourceType",((it=e.paymentSource)==null?void 0:it.schemaId)??""):O("paymentSourceType",((Gn=e.paymentSource)==null?void 0:Gn.type)??""),O("id",e.id),O("status",e.status),O("invoiceNumber",e.invoiceNumber),O("amount",e.amount),O("currency",e.currency??"USD"),O("vendorId",(Bt=e.vendor)==null?void 0:Bt.id),O("vendorName",(Ei=e.vendor)==null?void 0:Ei.name),O("invoiceDate",e.invoiceDate?ke(e.invoiceDate).toDate():void 0),O("dueDate",e.dueDate?ke(e.dueDate).toDate():void 0),O("deductionDate",e.deductionDate?ke(e.deductionDate).toDate():void 0),O("lineItems",e.lineItems??[]),O("paymentDestinationId",(lt=e.paymentDestination)==null?void 0:lt.id),O("paymentDestinationOptions",e.paymentDestinationOptions),O("paymentSourceId",(Kr=e.paymentSource)==null?void 0:Kr.id),O("paymentSourceCheckEnabled",((Co=(Yo=e.paymentSource)==null?void 0:Yo.checkOptions)==null?void 0:Co.enabled)??!1),O("description",e.noteToSelf??""),O("hasDocuments",e.hasDocuments??r??!1),O("saveAsStatus",""),O("saveAsAdmin",!1),O("metadata",e.metadata??{}),O("approvers",(e==null?void 0:e.approvers)??[]),O("approvalPolicy",(e==null?void 0:e.approvalPolicy)??{type:"any",approvers:[]}),O("creatorUser",e==null?void 0:e.creatorUser),O("comments",(e==null?void 0:e.comments)??[]),O("fees",e==null?void 0:e.fees),O("failureType",(e==null?void 0:e.failureType)??""),O("createdAt",e==null?void 0:e.createdAt),O("updatedAt",e==null?void 0:e.updatedAt))},[e]);const{fields:M}=wd({control:P,name:"lineItems"}),T=j("vendorId");_.useEffect(()=>{h?h.id==="new"?(O("paymentDestinationId",""),O("paymentDestinationType",""),O("paymentDestinationOptions",void 0)):h.id&&(d.debug({selectedVendor:h}),O("vendorId",h.id),O("vendorName",h.name),h.id!=T&&(O("paymentDestinationId",""),O("paymentDestinationType",""),O("paymentDestinationOptions",void 0)),S("vendorId"),S("vendorName")):(O("vendorId",""),O("vendorName",""),S("vendorId"),S("vendorName"),O("paymentDestinationId",""),O("paymentDestinationType",""),O("paymentDestinationOptions",void 0))},[h]),_.useEffect(()=>{var Me,Ye;(Me=d.entity)!=null&&Me.id&&T&&((Ye=d.client)==null||Ye.entity.counterparty.findPayees(d.entity.id,{counterpartyId:T}).then(De=>{if(De.data.length>0){const qe=De.data[0].accounts;qe&&O("vendor.accounts",qe)}}))},[(Pe=d.entity)==null?void 0:Pe.id,T]),_.useEffect(()=>{var Me,Ye,De,qe,it,Gn;t&&(d.debug({ocrResponse:t}),t.invoice.amount&&O("amount",t.invoice.amount),t.invoice.invoiceNumber&&O("invoiceNumber",t.invoice.invoiceNumber),t.invoice.invoiceDate&&O("invoiceDate",ke(ke(t.invoice.invoiceDate).utc().format("YYYY-MM-DD")).toDate()),t.invoice.dueDate&&O("dueDate",ke(ke(t.invoice.dueDate).utc().format("YYYY-MM-DD")).toDate()),t.invoice.currency&&O("currency",t.invoice.currency),t.invoice.metadata&&O("metadata",t.invoice.metadata),t.invoice.lineItems&&((De=(Ye=(Me=d.iframeOptions)==null?void 0:Me.options)==null?void 0:Ye.invoice)==null?void 0:De.lineItems)!=Q.Mercoa.LineItemAvailabilities.Disabled&&O("lineItems",t.invoice.lineItems.map(Bt=>({description:Bt.description??"",currency:Bt.currency??"USD",amount:Bt.amount??0,quantity:Bt.quantity??0,unitPrice:Bt.unitPrice??0,name:Bt.name??"",metadata:Bt.metadata??{},glAccountId:Bt.glAccountId??"",id:Bt.id??"",createdAt:Bt.createdAt??new Date,updatedAt:Bt.updatedAt??new Date}))),t.bankAccount&&O("newBankAccount",{routingNumber:t.bankAccount.routingNumber,accountNumber:t.bankAccount.accountNumber,bankName:t.bankAccount.bankName,accountType:Q.Mercoa.BankType.Checking}),t.check&&O("newCheck",{addressLine1:t.check.addressLine1,addressLine2:t.check.addressLine2??"",city:t.check.city,state:t.check.stateOrProvince,postalCode:t.check.postalCode,country:"US",payToTheOrderOf:t.check.payToTheOrderOf}),t.vendor.id==="new"&&((Gn=(it=(qe=d.iframeOptions)==null?void 0:qe.options)==null?void 0:it.vendors)!=null&&Gn.disableCreation)?d.debug("new vendor creation disabled"):t.vendor.id&&(d.debug("setting selected vendor",t.vendor),p(t.vendor)))},[t]);async function z(Me){g(!0);try{await A(Me)}catch(Ye){console.error(Ye)}g(!1)}async function A(Me){var it,Gn,Bt,Ei,lt,Kr,Yo,Co,Pi,Qg,es,Qi,al,Zg,cD,Ku,ey,ty,vh,lD,fJ,hJ,pJ,mJ,gJ,yJ,bJ,vJ,wJ,_J,OJ,xJ,jJ,MJ,SJ,EJ,PJ,TJ,CJ,AJ,DJ,zJ;if(!d.token||!((it=d.entity)!=null&&it.id))return;if(d.debug({saveAsStatus:Me.saveAsStatus}),Me.saveAsStatus===Q.Mercoa.InvoiceStatus.Canceled){confirm("Are you sure you want to cancel this invoice? This cannot be undone.")&&await((Gn=d.client)==null?void 0:Gn.invoice.update(Me.id,{status:Q.Mercoa.InvoiceStatus.Canceled})),g(!1),i(Me.id);return}else if(Me.saveAsStatus===Q.Mercoa.InvoiceStatus.Archived){confirm("Are you sure you want to archive this invoice? This cannot be undone.")&&await((Bt=d.client)==null?void 0:Bt.invoice.update(Me.id,{status:Q.Mercoa.InvoiceStatus.Archived})),g(!1),i(Me.id);return}else if(Me.saveAsStatus==="COUNTERPARTY"){await h1({data:Me.vendor,mercoaSession:d,type:"payee",setError:x,onSelect:async Ne=>{await d.refresh(),setTimeout(()=>{p(Ne)},100)}});return}else if(Me.saveAsStatus==="CREATE_BANK_ACCOUNT"){if(T){try{const Ne=await((Ei=d.client)==null?void 0:Ei.entity.paymentMethod.create(T,{type:Q.Mercoa.PaymentMethodType.BankAccount,routingNumber:Me.newBankAccount.routingNumber,accountNumber:Me.newBankAccount.accountNumber,accountType:Me.newBankAccount.accountType}));await d.refresh(),setTimeout(()=>{O("paymentDestinationType",Q.Mercoa.PaymentMethodType.BankAccount,{shouldDirty:!0}),O("paymentDestinationId",Ne==null?void 0:Ne.id,{shouldDirty:!0}),O("saveAsStatus","CLOSE_INLINE_FORM")},100)}catch(Ne){x("newBankAccount",{message:Ne.body??"Invalid Bank Account Data"})}return}}else if(Me.saveAsStatus==="CREATE_COUNTERPARTY_ACCOUNT"){if(T){try{const Ne=await((lt=d.client)==null?void 0:lt.entity.counterparty.findPayees(d.entity.id,{counterpartyId:T}));let Ir=Ne==null?void 0:Ne.data[0].accounts;Ir?Ir==null||Ir.push({accountId:Me.newCounterpartyAccount.accountId,postalCode:Me.newCounterpartyAccount.postalCode,nameOnAccount:Me.newCounterpartyAccount.nameOnAccount}):Ir=[{accountId:Me.newCounterpartyAccount.accountId,postalCode:Me.newCounterpartyAccount.postalCode,nameOnAccount:Me.newCounterpartyAccount.nameOnAccount}],await((Kr=d.client)==null?void 0:Kr.entity.counterparty.addPayees(d.entity.id,{payees:[T],customizations:[{counterpartyId:T,accounts:Ir}]})),await d.refresh(),O("vendor.accounts",Ir),setTimeout(()=>{O("saveAsStatus","CLOSE_INLINE_FORM"),setTimeout(()=>{O("paymentDestinationType",Q.Mercoa.PaymentMethodType.Utility,{shouldDirty:!0}),O("paymentDestinationOptions",{type:"utility",accountId:Me.newCounterpartyAccount.accountId})},100)},100)}catch(Ne){x("vendor",{message:Ne.body??"Invalid Utility Account Data"})}return}}else if(Me.saveAsStatus==="CREATE_CHECK"){if(T){try{const Ne=await((Yo=d.client)==null?void 0:Yo.entity.paymentMethod.create(T,{type:Q.Mercoa.PaymentMethodType.Check,payToTheOrderOf:Me.newCheck.payToTheOrderOf,addressLine1:Me.newCheck.addressLine1,addressLine2:Me.newCheck.addressLine2,city:Me.newCheck.city,stateOrProvince:Me.newCheck.stateOrProvince,postalCode:Me.newCheck.postalCode,country:"US"}));d.refresh(),setTimeout(()=>{O("paymentDestinationType",Q.Mercoa.PaymentMethodType.Check,{shouldDirty:!0}),O("paymentDestinationId",Ne==null?void 0:Ne.id,{shouldDirty:!0}),O("saveAsStatus","CLOSE_INLINE_FORM")},1e3)}catch(Ne){x("newCheck",{message:Ne.body??"Invalid Check Data"})}return}}else if(Me.saveAsStatus==="CREATE_CUSTOM"){if(T){const Ne={};Object.entries(Me).forEach(([Ir,uo])=>{Ir.startsWith("~cpm~~")&&uo.forEach(ry=>{Ne[ry.name]=`${Ne[ry.name]??ry.value}`})});try{const Ir=await((Co=d.client)==null?void 0:Co.entity.paymentMethod.create(T,{type:Q.Mercoa.PaymentMethodType.Custom,schemaId:Me.paymentDestinationType,data:Ne}));d.refresh(),setTimeout(()=>{O("paymentDestinationType",Ir.schemaId,{shouldDirty:!0}),O("paymentDestinationId",Ir.id,{shouldDirty:!0}),O("saveAsStatus","CLOSE_INLINE_FORM")},1e3)}catch(Ir){x("~cpm~~",{message:Ir.body??"Invalid Data"})}return}}else if(Me.saveAsStatus==="DELETE"){if(e!=null&&e.id)try{confirm("Are your sure you want to delete this invoice? This cannot be undone.")&&(await((Pi=d.client)==null?void 0:Pi.invoice.delete(e.id)),Ce.success("Invoice deleted"),o&&o(void 0)),g(!1);return}catch(Ne){console.error(Ne),Ce.error(`There was an error deleting the invoice.
|
|
196
196
|
Error: ${Ne.body}`)}return}else if(Me.saveAsStatus==="PRINT_CHECK"){if(!(e!=null&&e.id))return;const Ne=e==null?void 0:e.paymentDestinationOptions;if((Ne==null?void 0:Ne.type)===Q.Mercoa.PaymentMethodType.Check&&(Ne==null?void 0:Ne.delivery)===Q.Mercoa.CheckDeliveryMethod.Print)if(confirm("Do you want to create a live check? This will mark the invoice as paid cannot be undone.")){const uo=await((Qg=d.client)==null?void 0:Qg.invoice.update(e==null?void 0:e.id,{status:Q.Mercoa.InvoiceStatus.Paid}));uo&&(Ce.success("Invoice marked as paid. Live check created."),i(uo.id))}else Ce.success("VOID check created");const Ir=await((es=d.client)==null?void 0:es.invoice.document.generateCheckPdf(e.id));Ir?window.open(Ir.uri,"_blank"):Ce.error("There was an error generating the check PDF");return}else if(Me.saveAsStatus==="APPROVE"){if(!(e!=null&&e.id)||!((Qi=d.user)!=null&&Qi.id))return;if(e.status!==Q.Mercoa.InvoiceStatus.New){i(e.id);return}try{await((Zg=d.client)==null?void 0:Zg.invoice.approval.approve(e.id,{userId:(al=d.user)==null?void 0:al.id})),Ce.success("Invoice approved"),o&&o(void 0)}catch(Ne){console.error(Ne),Ce.error(`There was an error approving the invoice.
|
|
197
197
|
Error: ${Ne.body}`)}return}else if(Me.saveAsStatus==="REJECT"){if(!(e!=null&&e.id)||!((cD=d.user)!=null&&cD.id))return;if(e.status!==Q.Mercoa.InvoiceStatus.New){i(e.id);return}try{await((ey=d.client)==null?void 0:ey.invoice.approval.reject(e.id,{userId:(Ku=d.user)==null?void 0:Ku.id})),Ce.success("Invoice rejected"),o&&o(void 0)}catch(Ne){console.error(Ne),Ce.error(`There was an error rejecting the invoice.
|
|
198
198
|
Error: ${Ne.body}`)}return}else if(Me.saveAsStatus==="MARK_PAID"){if(!(e!=null&&e.id))return;try{confirm("Are you sure you want to mark this invoice as paid? This cannot be undone.")&&(await((ty=d.client)==null?void 0:ty.invoice.update(e.id,{status:Q.Mercoa.InvoiceStatus.Paid})),Ce.success("Invoice marked as paid"),o&&o(void 0))}catch(Ne){console.error(Ne),Ce.error(`There was an error marking the invoice as paid.
|