@component-hook/pdf-canvas 1.1.0-alpha.8 → 1.1.0-alpha.9

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.
@@ -22786,7 +22786,7 @@ function OA(o, t, e) {
22786
22786
  }
22787
22787
  function DA(o, t) {
22788
22788
  if (!o) return;
22789
- const e = o._cornerSize || 8;
22789
+ const e = o._cornerSize || 6;
22790
22790
  o.borderScaleFactor = 1 / t, o.cornerSize = e * (1 / t), o.touchCornerSize = e * 4 * (1 / t), o.setCoords();
22791
22791
  }
22792
22792
  function RA(o) {
@@ -22807,7 +22807,7 @@ const IA = {
22807
22807
  scaleY: 0.5,
22808
22808
  borderColor: "black",
22809
22809
  cornerStrokeColor: "black",
22810
- cornerSize: 8,
22810
+ cornerSize: 6,
22811
22811
  selectionBackgroundColor: "rgba(245, 245, 245, 0.8)"
22812
22812
  }, jA = {
22813
22813
  top: 100,
@@ -22817,7 +22817,7 @@ const IA = {
22817
22817
  cornerStrokeColor: "black",
22818
22818
  scaleX: 0.7,
22819
22819
  scaleY: 0.7,
22820
- cornerSize: 8,
22820
+ cornerSize: 6,
22821
22821
  selectionBackgroundColor: "rgba(245, 245, 245, 0.8)"
22822
22822
  }, NA = {
22823
22823
  stroke: "#000",
@@ -535,4 +535,4 @@ void main() {
535
535
  `),position:v,pageIndex:_-1,rect:u.slice(0),rotation:d,id:f,deleted:!1,popupRef:g}}const r=await super.deserialize(e,s,i);return m(r,xs,e.fontSize),m(r,ui,q.makeHexColor(...e.color)),m(r,ws,w(a=Ot,kn,Zp).call(a,e.value)),r.annotationElementId=e.id||null,r._initialData=n,r}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const s=Ot._internalPadding*this.parentScale,i=this.getRect(s,s),n=Ht._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:l(this,ui)),r={annotationType:nt.FREETEXT,color:n,fontSize:l(this,xs),value:w(this,ie,My).call(this),pageIndex:this.pageIndex,rect:i,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?r:this.annotationElementId&&!w(this,ie,Oy).call(this,r)?null:(r.id=this.annotationElementId,r)}renderAnnotationElement(e){const s=super.renderAnnotationElement(e);if(this.deleted)return s;const{style:i}=s;i.fontSize=`calc(${l(this,xs)}px * var(--scale-factor))`,i.color=l(this,ui),s.replaceChildren();for(const r of l(this,ws).split(`
536
536
  `)){const a=document.createElement("div");a.append(r?document.createTextNode(r):document.createElement("br")),s.append(a)}const n=Ot._internalPadding*this.parentScale;return e.updateEdited({rect:this.getRect(n,n),popupContent:l(this,ws)}),s}resetAnnotationElement(e){super.resetAnnotationElement(e),e.resetEdited()}};ui=new WeakMap,ws=new WeakMap,Sc=new WeakMap,ja=new WeakMap,xs=new WeakMap,ie=new WeakSet,Ey=function(e){const s=n=>{this.editorDiv.style.fontSize=`calc(${n}px * var(--scale-factor))`,this.translate(0,-(n-l(this,xs))*this.parentScale),m(this,xs,n),w(this,ie,ff).call(this)},i=l(this,xs);this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:dt.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})},ky=function(e){const s=n=>{m(this,ui,this.editorDiv.style.color=n)},i=l(this,ui);this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:dt.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})},Py=function(){var i;const e=[];this.editorDiv.normalize();let s=null;for(const n of this.editorDiv.childNodes)(s==null?void 0:s.nodeType)===Node.TEXT_NODE&&n.nodeName==="BR"||(e.push(w(i=Ot,kn,gf).call(i,n)),s=n);return e.join(`
537
537
  `)},ff=function(){const[e,s]=this.parentDimensions;let i;if(this.isAttachedToDOM)i=this.div.getBoundingClientRect();else{const{currentLayer:n,div:r}=this,a=r.style.display,h=r.classList.contains("hidden");r.classList.remove("hidden"),r.style.display="hidden",n.div.append(this.div),i=r.getBoundingClientRect(),r.remove(),r.style.display=a,r.classList.toggle("hidden",h)}this.rotation%180===this.parentRotation%180?(this.width=i.width/e,this.height=i.height/s):(this.width=i.height/e,this.height=i.width/s),this.fixAndSetPosition()},kn=new WeakSet,gf=function(e){return(e.nodeType===Node.TEXT_NODE?e.nodeValue:e.innerText).replaceAll(xd,"")},pf=function(){if(this.editorDiv.replaceChildren(),!!l(this,ws))for(const e of l(this,ws).split(`
538
- `)){const s=document.createElement("div");s.append(e?document.createTextNode(e):document.createElement("br")),this.editorDiv.append(s)}},My=function(){return l(this,ws).replaceAll(" "," ")},Zp=function(e){return e.replaceAll(" "," ")},Oy=function(e){const{value:s,fontSize:i,color:n,pageIndex:r}=this._initialData;return this._hasBeenMoved||e.value!==s||e.fontSize!==i||e.color.some((a,h)=>a!==n[h])||e.pageIndex!==r},y(Ot,kn),J(Ot,"_freeTextDefaultContent",""),J(Ot,"_internalPadding",0),J(Ot,"_defaultColor",null),J(Ot,"_defaultFontSize",10),J(Ot,"_type","freetext"),J(Ot,"_editorType",nt.FREETEXT);let ep=Ot;class X{toSVGPath(){Et("Abstract method `toSVGPath` must be implemented.")}get box(){Et("Abstract getter `box` must be implemented.")}serialize(t,e){Et("Abstract method `serialize` must be implemented.")}static _rescale(t,e,s,i,n,r){r||(r=new Float32Array(t.length));for(let a=0,h=t.length;a<h;a+=2)r[a]=e+t[a]*i,r[a+1]=s+t[a+1]*n;return r}static _rescaleAndSwap(t,e,s,i,n,r){r||(r=new Float32Array(t.length));for(let a=0,h=t.length;a<h;a+=2)r[a]=e+t[a+1]*i,r[a+1]=s+t[a]*n;return r}static _translate(t,e,s,i){i||(i=new Float32Array(t.length));for(let n=0,r=t.length;n<r;n+=2)i[n]=e+t[n],i[n+1]=s+t[n+1];return i}static svgRound(t){return Math.round(t*1e4)}static _normalizePoint(t,e,s,i,n){switch(n){case 90:return[1-e/s,t/i];case 180:return[1-t/s,1-e/i];case 270:return[e/s,1-t/i];default:return[t/s,e/i]}}static _normalizePagePoint(t,e,s){switch(s){case 90:return[1-e,t];case 180:return[1-t,1-e];case 270:return[e,1-t];default:return[t,e]}}static createBezierPoints(t,e,s,i,n,r){return[(t+5*s)/6,(e+5*i)/6,(5*s+n)/6,(5*i+r)/6,(s+n)/2,(i+r)/2]}}J(X,"PRECISION",1e-4);const Pn=class Pn{constructor({x:t,y:e},s,i,n,r,a=0){y(this,ce);y(this,Ss);y(this,di,[]);y(this,oh);y(this,hh);y(this,ji,[]);y(this,lt,new Float32Array(18));y(this,Na);y(this,Ba);y(this,Cc);y(this,Ac);y(this,lh);y(this,ch);y(this,br,[]);m(this,Ss,s),m(this,ch,n*i),m(this,hh,r),l(this,lt).set([NaN,NaN,NaN,NaN,t,e],6),m(this,oh,a),m(this,Ac,l(Pn,Tc)*i),m(this,Cc,l(Pn,Vd)*i),m(this,lh,i),l(this,br).push(t,e)}isEmpty(){return isNaN(l(this,lt)[8])}add({x:t,y:e}){var R;m(this,Na,t),m(this,Ba,e);const[s,i,n,r]=l(this,Ss);let[a,h,c,u]=l(this,lt).subarray(8,12);const d=t-c,f=e-u,g=Math.hypot(d,f);if(g<l(this,Cc))return!1;const p=g-l(this,Ac),v=p/g,_=v*d,b=v*f;let x=a,C=h;a=c,h=u,c+=_,u+=b,(R=l(this,br))==null||R.push(t,e);const A=-b/p,P=_/p,D=A*l(this,ch),k=P*l(this,ch);return l(this,lt).set(l(this,lt).subarray(2,8),0),l(this,lt).set([c+D,u+k],4),l(this,lt).set(l(this,lt).subarray(14,18),12),l(this,lt).set([c-D,u-k],16),isNaN(l(this,lt)[6])?(l(this,ji).length===0&&(l(this,lt).set([a+D,h+k],2),l(this,ji).push(NaN,NaN,NaN,NaN,(a+D-s)/n,(h+k-i)/r),l(this,lt).set([a-D,h-k],14),l(this,di).push(NaN,NaN,NaN,NaN,(a-D-s)/n,(h-k-i)/r)),l(this,lt).set([x,C,a,h,c,u],6),!this.isEmpty()):(l(this,lt).set([x,C,a,h,c,u],6),Math.abs(Math.atan2(C-h,x-a)-Math.atan2(b,_))<Math.PI/2?([a,h,c,u]=l(this,lt).subarray(2,6),l(this,ji).push(NaN,NaN,NaN,NaN,((a+c)/2-s)/n,((h+u)/2-i)/r),[a,h,x,C]=l(this,lt).subarray(14,18),l(this,di).push(NaN,NaN,NaN,NaN,((x+a)/2-s)/n,((C+h)/2-i)/r),!0):([x,C,a,h,c,u]=l(this,lt).subarray(0,6),l(this,ji).push(((x+5*a)/6-s)/n,((C+5*h)/6-i)/r,((5*a+c)/6-s)/n,((5*h+u)/6-i)/r,((a+c)/2-s)/n,((h+u)/2-i)/r),[c,u,a,h,x,C]=l(this,lt).subarray(12,18),l(this,di).push(((x+5*a)/6-s)/n,((C+5*h)/6-i)/r,((5*a+c)/6-s)/n,((5*h+u)/6-i)/r,((a+c)/2-s)/n,((h+u)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";const t=l(this,ji),e=l(this,di);if(isNaN(l(this,lt)[6])&&!this.isEmpty())return w(this,ce,Dy).call(this);const s=[];s.push(`M${t[4]} ${t[5]}`);for(let i=6;i<t.length;i+=6)isNaN(t[i])?s.push(`L${t[i+4]} ${t[i+5]}`):s.push(`C${t[i]} ${t[i+1]} ${t[i+2]} ${t[i+3]} ${t[i+4]} ${t[i+5]}`);w(this,ce,Ly).call(this,s);for(let i=e.length-6;i>=6;i-=6)isNaN(e[i])?s.push(`L${e[i+4]} ${e[i+5]}`):s.push(`C${e[i]} ${e[i+1]} ${e[i+2]} ${e[i+3]} ${e[i+4]} ${e[i+5]}`);return w(this,ce,Ry).call(this,s),s.join(" ")}newFreeDrawOutline(t,e,s,i,n,r){return new gb(t,e,s,i,n,r)}getOutlines(){var d;const t=l(this,ji),e=l(this,di),s=l(this,lt),[i,n,r,a]=l(this,Ss),h=new Float32Array((((d=l(this,br))==null?void 0:d.length)??0)+2);for(let f=0,g=h.length-2;f<g;f+=2)h[f]=(l(this,br)[f]-i)/r,h[f+1]=(l(this,br)[f+1]-n)/a;if(h[h.length-2]=(l(this,Na)-i)/r,h[h.length-1]=(l(this,Ba)-n)/a,isNaN(s[6])&&!this.isEmpty())return w(this,ce,Fy).call(this,h);const c=new Float32Array(l(this,ji).length+24+l(this,di).length);let u=t.length;for(let f=0;f<u;f+=2){if(isNaN(t[f])){c[f]=c[f+1]=NaN;continue}c[f]=t[f],c[f+1]=t[f+1]}u=w(this,ce,jy).call(this,c,u);for(let f=e.length-6;f>=6;f-=6)for(let g=0;g<6;g+=2){if(isNaN(e[f+g])){c[u]=c[u+1]=NaN,u+=2;continue}c[u]=e[f+g],c[u+1]=e[f+g+1],u+=2}return w(this,ce,Iy).call(this,c,u),this.newFreeDrawOutline(c,h,l(this,Ss),l(this,lh),l(this,oh),l(this,hh))}};Ss=new WeakMap,di=new WeakMap,oh=new WeakMap,hh=new WeakMap,ji=new WeakMap,lt=new WeakMap,Na=new WeakMap,Ba=new WeakMap,Cc=new WeakMap,Ac=new WeakMap,lh=new WeakMap,ch=new WeakMap,br=new WeakMap,Tc=new WeakMap,Gd=new WeakMap,Vd=new WeakMap,ce=new WeakSet,Zc=function(){const t=l(this,lt).subarray(4,6),e=l(this,lt).subarray(16,18),[s,i,n,r]=l(this,Ss);return[(l(this,Na)+(t[0]-e[0])/2-s)/n,(l(this,Ba)+(t[1]-e[1])/2-i)/r,(l(this,Na)+(e[0]-t[0])/2-s)/n,(l(this,Ba)+(e[1]-t[1])/2-i)/r]},Dy=function(){const[t,e,s,i]=l(this,Ss),[n,r,a,h]=w(this,ce,Zc).call(this);return`M${(l(this,lt)[2]-t)/s} ${(l(this,lt)[3]-e)/i} L${(l(this,lt)[4]-t)/s} ${(l(this,lt)[5]-e)/i} L${n} ${r} L${a} ${h} L${(l(this,lt)[16]-t)/s} ${(l(this,lt)[17]-e)/i} L${(l(this,lt)[14]-t)/s} ${(l(this,lt)[15]-e)/i} Z`},Ry=function(t){const e=l(this,di);t.push(`L${e[4]} ${e[5]} Z`)},Ly=function(t){const[e,s,i,n]=l(this,Ss),r=l(this,lt).subarray(4,6),a=l(this,lt).subarray(16,18),[h,c,u,d]=w(this,ce,Zc).call(this);t.push(`L${(r[0]-e)/i} ${(r[1]-s)/n} L${h} ${c} L${u} ${d} L${(a[0]-e)/i} ${(a[1]-s)/n}`)},Fy=function(t){const e=l(this,lt),[s,i,n,r]=l(this,Ss),[a,h,c,u]=w(this,ce,Zc).call(this),d=new Float32Array(36);return d.set([NaN,NaN,NaN,NaN,(e[2]-s)/n,(e[3]-i)/r,NaN,NaN,NaN,NaN,(e[4]-s)/n,(e[5]-i)/r,NaN,NaN,NaN,NaN,a,h,NaN,NaN,NaN,NaN,c,u,NaN,NaN,NaN,NaN,(e[16]-s)/n,(e[17]-i)/r,NaN,NaN,NaN,NaN,(e[14]-s)/n,(e[15]-i)/r],0),this.newFreeDrawOutline(d,t,l(this,Ss),l(this,lh),l(this,oh),l(this,hh))},Iy=function(t,e){const s=l(this,di);return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6},jy=function(t,e){const s=l(this,lt).subarray(4,6),i=l(this,lt).subarray(16,18),[n,r,a,h]=l(this,Ss),[c,u,d,f]=w(this,ce,Zc).call(this);return t.set([NaN,NaN,NaN,NaN,(s[0]-n)/a,(s[1]-r)/h,NaN,NaN,NaN,NaN,c,u,NaN,NaN,NaN,NaN,d,f,NaN,NaN,NaN,NaN,(i[0]-n)/a,(i[1]-r)/h],e),e+=24},y(Pn,Tc,8),y(Pn,Gd,2),y(Pn,Vd,l(Pn,Tc)+l(Pn,Gd));let Sd=Pn;class gb extends X{constructor(e,s,i,n,r,a){super();y(this,Wd);y(this,uh);y(this,Ha,new Float32Array(4));y(this,Mn);y(this,Ec);y(this,Cs);y(this,kc);y(this,Jt);m(this,Jt,e),m(this,Cs,s),m(this,uh,i),m(this,kc,n),m(this,Mn,r),m(this,Ec,a),this.lastPoint=[NaN,NaN],w(this,Wd,Ny).call(this,a);const[h,c,u,d]=l(this,Ha);for(let f=0,g=e.length;f<g;f+=2)e[f]=(e[f]-h)/u,e[f+1]=(e[f+1]-c)/d;for(let f=0,g=s.length;f<g;f+=2)s[f]=(s[f]-h)/u,s[f+1]=(s[f+1]-c)/d}toSVGPath(){const e=[`M${l(this,Jt)[4]} ${l(this,Jt)[5]}`];for(let s=6,i=l(this,Jt).length;s<i;s+=6){if(isNaN(l(this,Jt)[s])){e.push(`L${l(this,Jt)[s+4]} ${l(this,Jt)[s+5]}`);continue}e.push(`C${l(this,Jt)[s]} ${l(this,Jt)[s+1]} ${l(this,Jt)[s+2]} ${l(this,Jt)[s+3]} ${l(this,Jt)[s+4]} ${l(this,Jt)[s+5]}`)}return e.push("Z"),e.join(" ")}serialize([e,s,i,n],r){const a=i-e,h=n-s;let c,u;switch(r){case 0:c=X._rescale(l(this,Jt),e,n,a,-h),u=X._rescale(l(this,Cs),e,n,a,-h);break;case 90:c=X._rescaleAndSwap(l(this,Jt),e,s,a,h),u=X._rescaleAndSwap(l(this,Cs),e,s,a,h);break;case 180:c=X._rescale(l(this,Jt),i,s,-a,h),u=X._rescale(l(this,Cs),i,s,-a,h);break;case 270:c=X._rescaleAndSwap(l(this,Jt),i,n,-a,-h),u=X._rescaleAndSwap(l(this,Cs),i,n,-a,-h);break}return{outline:Array.from(c),points:[Array.from(u)]}}get box(){return l(this,Ha)}newOutliner(e,s,i,n,r,a=0){return new Sd(e,s,i,n,r,a)}getNewOutline(e,s){const[i,n,r,a]=l(this,Ha),[h,c,u,d]=l(this,uh),f=r*u,g=a*d,p=i*u+h,v=n*d+c,_=this.newOutliner({x:l(this,Cs)[0]*f+p,y:l(this,Cs)[1]*g+v},l(this,uh),l(this,kc),e,l(this,Ec),s??l(this,Mn));for(let b=2;b<l(this,Cs).length;b+=2)_.add({x:l(this,Cs)[b]*f+p,y:l(this,Cs)[b+1]*g+v});return _.getOutlines()}}uh=new WeakMap,Ha=new WeakMap,Mn=new WeakMap,Ec=new WeakMap,Cs=new WeakMap,kc=new WeakMap,Jt=new WeakMap,Wd=new WeakSet,Ny=function(e){const s=l(this,Jt);let i=s[4],n=s[5],r=i,a=n,h=i,c=n,u=i,d=n;const f=e?Math.max:Math.min;for(let p=6,v=s.length;p<v;p+=6){if(isNaN(s[p]))r=Math.min(r,s[p+4]),a=Math.min(a,s[p+5]),h=Math.max(h,s[p+4]),c=Math.max(c,s[p+5]),d<s[p+5]?(u=s[p+4],d=s[p+5]):d===s[p+5]&&(u=f(u,s[p+4]));else{const _=q.bezierBoundingBox(i,n,...s.slice(p,p+6));r=Math.min(r,_[0]),a=Math.min(a,_[1]),h=Math.max(h,_[2]),c=Math.max(c,_[3]),d<_[3]?(u=_[2],d=_[3]):d===_[3]&&(u=f(u,_[2]))}i=s[p+4],n=s[p+5]}const g=l(this,Ha);g[0]=r-l(this,Mn),g[1]=a-l(this,Mn),g[2]=h-r+2*l(this,Mn),g[3]=c-a+2*l(this,Mn),this.lastPoint=[u,d]};class sp{constructor(t,e=0,s=0,i=!0){y(this,Ye);y(this,Pc);y(this,Mc);y(this,yr,[]);y(this,fi,[]);let n=1/0,r=-1/0,a=1/0,h=-1/0;const c=10**-4;for(const{x:_,y:b,width:x,height:C}of t){const A=Math.floor((_-e)/c)*c,P=Math.ceil((_+x+e)/c)*c,D=Math.floor((b-e)/c)*c,k=Math.ceil((b+C+e)/c)*c,M=[A,D,k,!0],R=[P,D,k,!1];l(this,yr).push(M,R),n=Math.min(n,A),r=Math.max(r,P),a=Math.min(a,D),h=Math.max(h,k)}const u=r-n+2*s,d=h-a+2*s,f=n-s,g=a-s,p=l(this,yr).at(i?-1:-2),v=[p[0],p[2]];for(const _ of l(this,yr)){const[b,x,C]=_;_[0]=(b-f)/u,_[1]=(x-g)/d,_[2]=(C-g)/d}m(this,Pc,new Float32Array([f,g,u,d])),m(this,Mc,v)}getOutlines(){l(this,yr).sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);const t=[];for(const e of l(this,yr))e[3]?(t.push(...w(this,Ye,tm).call(this,e)),w(this,Ye,Hy).call(this,e)):(w(this,Ye,Gy).call(this,e),t.push(...w(this,Ye,tm).call(this,e)));return w(this,Ye,By).call(this,t)}}Pc=new WeakMap,Mc=new WeakMap,yr=new WeakMap,fi=new WeakMap,Ye=new WeakSet,By=function(t){const e=[],s=new Set;for(const r of t){const[a,h,c]=r;e.push([a,h,r],[a,c,r])}e.sort((r,a)=>r[1]-a[1]||r[0]-a[0]);for(let r=0,a=e.length;r<a;r+=2){const h=e[r][2],c=e[r+1][2];h.push(c),c.push(h),s.add(h),s.add(c)}const i=[];let n;for(;s.size>0;){const r=s.values().next().value;let[a,h,c,u,d]=r;s.delete(r);let f=a,g=h;for(n=[a,c],i.push(n);;){let p;if(s.has(u))p=u;else if(s.has(d))p=d;else break;s.delete(p),[a,h,c,u,d]=p,f!==a&&(n.push(f,g,a,g===h?h:c),f=a),g=g===h?c:h}n.push(f,g)}return new DC(i,l(this,Pc),l(this,Mc))},mf=function(t){const e=l(this,fi);let s=0,i=e.length-1;for(;s<=i;){const n=s+i>>1,r=e[n][0];if(r===t)return n;r<t?s=n+1:i=n-1}return i+1},Hy=function([,t,e]){const s=w(this,Ye,mf).call(this,t);l(this,fi).splice(s,0,[t,e])},Gy=function([,t,e]){const s=w(this,Ye,mf).call(this,t);for(let i=s;i<l(this,fi).length;i++){const[n,r]=l(this,fi)[i];if(n!==t)break;if(n===t&&r===e){l(this,fi).splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=l(this,fi)[i];if(n!==t)break;if(n===t&&r===e){l(this,fi).splice(i,1);return}}},tm=function(t){const[e,s,i]=t,n=[[e,s,i]],r=w(this,Ye,mf).call(this,i);for(let a=0;a<r;a++){const[h,c]=l(this,fi)[a];for(let u=0,d=n.length;u<d;u++){const[,f,g]=n[u];if(!(c<=f||g<=h)){if(f>=h){if(g>c)n[u][1]=c;else{if(d===1)return[];n.splice(u,1),u--,d--}continue}n[u][2]=h,g>c&&n.push([e,c,g])}}}return n};class DC extends X{constructor(e,s,i){super();y(this,Oc);y(this,dh);m(this,dh,e),m(this,Oc,s),this.lastPoint=i}toSVGPath(){const e=[];for(const s of l(this,dh)){let[i,n]=s;e.push(`M${i} ${n}`);for(let r=2;r<s.length;r+=2){const a=s[r],h=s[r+1];a===i?(e.push(`V${h}`),n=h):h===n&&(e.push(`H${a}`),i=a)}e.push("Z")}return e.join(" ")}serialize([e,s,i,n],r){const a=[],h=i-e,c=n-s;for(const u of l(this,dh)){const d=new Array(u.length);for(let f=0;f<u.length;f+=2)d[f]=e+u[f]*h,d[f+1]=n-u[f+1]*c;a.push(d)}return a}get box(){return l(this,Oc)}get classNamesForOutlining(){return["highlightOutline"]}}Oc=new WeakMap,dh=new WeakMap;class ip extends Sd{newFreeDrawOutline(t,e,s,i,n,r){return new RC(t,e,s,i,n,r)}}class RC extends gb{newOutliner(t,e,s,i,n,r=0){return new ip(t,e,s,i,n,r)}}const hs=class hs{constructor({editor:t=null,uiManager:e=null}){y(this,At);y(this,gi,null);y(this,Ga,null);y(this,fh);y(this,ue,null);y(this,Dc,!1);y(this,gh,!1);y(this,Rc,null);y(this,Lc);y(this,_r,null);y(this,pi,null);y(this,ph);var s;t?(m(this,gh,!1),m(this,ph,dt.HIGHLIGHT_COLOR),m(this,Rc,t)):(m(this,gh,!0),m(this,ph,dt.HIGHLIGHT_DEFAULT_COLOR)),m(this,pi,(t==null?void 0:t._uiManager)||e),m(this,Lc,l(this,pi)._eventBus),m(this,fh,(t==null?void 0:t.color)||((s=l(this,pi))==null?void 0:s.highlightColors.values().next().value)||"#FFFF98"),l(hs,Fc)||m(hs,Fc,Object.freeze({blue:"pdfjs-editor-colorpicker-blue",green:"pdfjs-editor-colorpicker-green",pink:"pdfjs-editor-colorpicker-pink",red:"pdfjs-editor-colorpicker-red",yellow:"pdfjs-editor-colorpicker-yellow"}))}static get _keyboardManager(){return ht(this,"_keyboardManager",new ll([[["Escape","mac+Escape"],hs.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],hs.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],hs.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],hs.prototype._moveToPrevious],[["Home","mac+Home"],hs.prototype._moveToBeginning],[["End","mac+End"],hs.prototype._moveToEnd]]))}renderButton(){const t=m(this,gi,document.createElement("button"));t.className="colorPicker",t.tabIndex="0",t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-button"),t.setAttribute("aria-haspopup",!0);const e=l(this,pi)._signal;t.addEventListener("click",w(this,At,io).bind(this),{signal:e}),t.addEventListener("keydown",w(this,At,im).bind(this),{signal:e});const s=m(this,Ga,document.createElement("span"));return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=l(this,fh),t.append(s),t}renderMainDropdown(){const t=m(this,ue,w(this,At,em).call(this));return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}_colorSelectFromKeyboard(t){if(t.target===l(this,gi)){w(this,At,io).call(this,t);return}const e=t.target.getAttribute("data-color");e&&w(this,At,sm).call(this,e,t)}_moveToNext(t){var e,s;if(!l(this,At,Pr)){w(this,At,io).call(this,t);return}if(t.target===l(this,gi)){(e=l(this,ue).firstChild)==null||e.focus();return}(s=t.target.nextSibling)==null||s.focus()}_moveToPrevious(t){var e,s;if(t.target===((e=l(this,ue))==null?void 0:e.firstChild)||t.target===l(this,gi)){l(this,At,Pr)&&this._hideDropdownFromKeyboard();return}l(this,At,Pr)||w(this,At,io).call(this,t),(s=t.target.previousSibling)==null||s.focus()}_moveToBeginning(t){var e;if(!l(this,At,Pr)){w(this,At,io).call(this,t);return}(e=l(this,ue).firstChild)==null||e.focus()}_moveToEnd(t){var e;if(!l(this,At,Pr)){w(this,At,io).call(this,t);return}(e=l(this,ue).lastChild)==null||e.focus()}hideDropdown(){var t,e;(t=l(this,ue))==null||t.classList.add("hidden"),(e=l(this,_r))==null||e.abort(),m(this,_r,null)}_hideDropdownFromKeyboard(){var t;if(!l(this,gh)){if(!l(this,At,Pr)){(t=l(this,Rc))==null||t.unselect();return}this.hideDropdown(),l(this,gi).focus({preventScroll:!0,focusVisible:l(this,Dc)})}}updateColor(t){if(l(this,Ga)&&(l(this,Ga).style.backgroundColor=t),!l(this,ue))return;const e=l(this,pi).highlightColors.values();for(const s of l(this,ue).children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){var t,e;(t=l(this,gi))==null||t.remove(),m(this,gi,null),m(this,Ga,null),(e=l(this,ue))==null||e.remove(),m(this,ue,null)}};gi=new WeakMap,Ga=new WeakMap,fh=new WeakMap,ue=new WeakMap,Dc=new WeakMap,gh=new WeakMap,Rc=new WeakMap,Lc=new WeakMap,_r=new WeakMap,pi=new WeakMap,ph=new WeakMap,Fc=new WeakMap,At=new WeakSet,em=function(){const t=document.createElement("div"),e=l(this,pi)._signal;t.addEventListener("contextmenu",ii,{signal:e}),t.className="dropdown",t.role="listbox",t.setAttribute("aria-multiselectable",!1),t.setAttribute("aria-orientation","vertical"),t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown");for(const[s,i]of l(this,pi).highlightColors){const n=document.createElement("button");n.tabIndex="0",n.role="option",n.setAttribute("data-color",i),n.title=s,n.setAttribute("data-l10n-id",l(hs,Fc)[s]);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===l(this,fh)),n.addEventListener("click",w(this,At,sm).bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",w(this,At,im).bind(this),{signal:e}),t},sm=function(t,e){e.stopPropagation(),l(this,Lc).dispatch("switchannotationeditorparams",{source:this,type:l(this,ph),value:t})},im=function(t){hs._keyboardManager.exec(this,t)},io=function(t){if(l(this,At,Pr)){this.hideDropdown();return}if(m(this,Dc,t.detail===0),l(this,_r)||(m(this,_r,new AbortController),window.addEventListener("pointerdown",w(this,At,Vy).bind(this),{signal:l(this,pi).combinedSignal(l(this,_r))})),l(this,ue)){l(this,ue).classList.remove("hidden");return}const e=m(this,ue,w(this,At,em).call(this));l(this,gi).append(e)},Vy=function(t){var e;(e=l(this,ue))!=null&&e.contains(t.target)||this.hideDropdown()},Pr=function(){return l(this,ue)&&!l(this,ue).classList.contains("hidden")},y(hs,Fc,null);let Cd=hs;const bt=class bt extends Ht{constructor(e){super({...e,name:"highlightEditor"});y(this,st);y(this,mh,null);y(this,Ic,0);y(this,On);y(this,Va,null);y(this,vh,null);y(this,ls,null);y(this,jc,null);y(this,Nc,0);y(this,Wa,null);y(this,Hs,null);y(this,As,null);y(this,_e,!1);y(this,bh,null);y(this,Dn);y(this,Le,null);y(this,yh,"");y(this,Gs);y(this,Bc,"");this.color=e.color||bt._defaultColor,m(this,Gs,e.thickness||bt._defaultThickness),m(this,Dn,e.opacity||bt._defaultOpacity),m(this,On,e.boxes||null),m(this,Bc,e.methodOfCreation||""),m(this,yh,e.text||""),this._isDraggable=!1,e.highlightId>-1?(m(this,_e,!0),w(this,st,vf).call(this,e),w(this,st,no).call(this)):l(this,On)&&(m(this,mh,e.anchorNode),m(this,Ic,e.anchorOffset),m(this,jc,e.focusNode),m(this,Nc,e.focusOffset),w(this,st,nm).call(this),w(this,st,no).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const e=bt.prototype;return ht(this,"_keyboardManager",new ll([[["ArrowLeft","mac+ArrowLeft"],e._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],e._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],e._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],e._moveCaret,{args:[3]}]]))}get telemetryInitialData(){return{action:"added",type:l(this,_e)?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:l(this,Gs),methodOfCreation:l(this,Bc)}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.highlightColorNames.get(this.color)}}static computeTelemetryFinalData(e){return{numberOfColors:e.get("color").size}}static initialize(e,s){var i;Ht.initialize(e,s),bt._defaultColor||(bt._defaultColor=((i=s.highlightColors)==null?void 0:i.values().next().value)||"#fff066")}static updateDefaultParams(e,s){switch(e){case dt.HIGHLIGHT_DEFAULT_COLOR:bt._defaultColor=s;break;case dt.HIGHLIGHT_THICKNESS:bt._defaultThickness=s;break}}translateInPage(e,s){}get toolbarPosition(){return l(this,bh)}updateParams(e,s){switch(e){case dt.HIGHLIGHT_COLOR:w(this,st,Wy).call(this,s);break;case dt.HIGHLIGHT_THICKNESS:w(this,st,zy).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[dt.HIGHLIGHT_DEFAULT_COLOR,bt._defaultColor],[dt.HIGHLIGHT_THICKNESS,bt._defaultThickness]]}get propertiesToUpdate(){return[[dt.HIGHLIGHT_COLOR,this.color||bt._defaultColor],[dt.HIGHLIGHT_THICKNESS,l(this,Gs)||bt._defaultThickness],[dt.HIGHLIGHT_FREE,l(this,_e)]]}async addEditToolbar(){const e=await super.addEditToolbar();return e?(this._uiManager.highlightColors&&(m(this,vh,new Cd({editor:this})),e.addColorPicker(l(this,vh))),e):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(w(this,st,tu).call(this))}getBaseTranslation(){return[0,0]}getRect(e,s){return super.getRect(e,s,w(this,st,tu).call(this))}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),e&&this.div.focus()}remove(){w(this,st,rm).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,st,no).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?w(this,st,rm).call(this):e&&(w(this,st,no).call(this,e),s=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),this.show(this._isVisible),s&&this.select()}rotate(e){var n,r,a;const{drawLayer:s}=this.parent;let i;l(this,_e)?(e=(e-this.rotation+360)%360,i=w(n=bt,Vs,Nh).call(n,l(this,Hs).box,e)):i=w(r=bt,Vs,Nh).call(r,[this.x,this.y,this.width,this.height],e),s.updateProperties(l(this,As),{bbox:i,root:{"data-main-rotation":e}}),s.updateProperties(l(this,Le),{bbox:w(a=bt,Vs,Nh).call(a,l(this,ls).box,e),root:{"data-main-rotation":e}})}render(){if(this.div)return this.div;const e=super.render();l(this,yh)&&(e.setAttribute("aria-label",l(this,yh)),e.setAttribute("role","mark")),l(this,_e)?e.classList.add("free"):this.div.addEventListener("keydown",w(this,st,Uy).bind(this),{signal:this._uiManager._signal});const s=m(this,Wa,document.createElement("div"));e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",s.style.clipPath=l(this,Va);const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),gd(this,l(this,Wa),["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Le),{rootClass:{hovered:!0}})}pointerleave(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Le),{rootClass:{hovered:!1}})}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:w(this,st,bf).call(this,!0);break;case 1:case 3:w(this,st,bf).call(this,!1);break}}select(){var e;super.select(),l(this,Le)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Le),{rootClass:{hovered:!1,selected:!0}}))}unselect(){var e;super.unselect(),l(this,Le)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Le),{rootClass:{selected:!1}}),l(this,_e)||w(this,st,bf).call(this,!1))}get _mustFixPosition(){return!l(this,_e)}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.updateProperties(l(this,As),{rootClass:{hidden:!e}}),this.parent.drawLayer.updateProperties(l(this,Le),{rootClass:{hidden:!e}}))}static startHighlighting(e,s,{target:i,x:n,y:r}){const{x:a,y:h,width:c,height:u}=i.getBoundingClientRect(),d=new AbortController,f=e.combinedSignal(d),g=p=>{d.abort(),w(this,Vs,Ky).call(this,e,p)};window.addEventListener("blur",g,{signal:f}),window.addEventListener("pointerup",g,{signal:f}),window.addEventListener("pointerdown",gs,{capture:!0,passive:!1,signal:f}),window.addEventListener("contextmenu",ii,{signal:f}),i.addEventListener("pointermove",w(this,Vs,qy).bind(this,e),{signal:f}),this._freeHighlight=new ip({x:n,y:r},[a,h,c,u],e.scale,this._defaultThickness/2,s,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0)}static async deserialize(e,s,i){var v,_,b,x;let n=null;if(e instanceof db){const{data:{quadPoints:C,rect:A,rotation:P,id:D,color:k,opacity:M,popupRef:R},parent:{page:{pageNumber:F}}}=e;n=e={annotationType:nt.HIGHLIGHT,color:Array.from(k),opacity:M,quadPoints:C,boxes:null,pageIndex:F-1,rect:A.slice(0),rotation:P,id:D,deleted:!1,popupRef:R}}else if(e instanceof tp){const{data:{inkLists:C,rect:A,rotation:P,id:D,color:k,borderStyle:{rawWidth:M},popupRef:R},parent:{page:{pageNumber:F}}}=e;n=e={annotationType:nt.HIGHLIGHT,color:Array.from(k),thickness:M,inkLists:C,boxes:null,pageIndex:F-1,rect:A.slice(0),rotation:P,id:D,deleted:!1,popupRef:R}}const{color:r,quadPoints:a,inkLists:h,opacity:c}=e,u=await super.deserialize(e,s,i);u.color=q.makeHexColor(...r),m(u,Dn,c||1),h&&m(u,Gs,e.thickness),u.annotationElementId=e.id||null,u._initialData=n;const[d,f]=u.pageDimensions,[g,p]=u.pageTranslation;if(a){const C=m(u,On,[]);for(let A=0;A<a.length;A+=8)C.push({x:(a[A]-g)/d,y:1-(a[A+1]-p)/f,width:(a[A+2]-a[A])/d,height:(a[A+1]-a[A+5])/f});w(v=u,st,nm).call(v),w(_=u,st,no).call(_),u.rotate(u.rotation)}else if(h){m(u,_e,!0);const C=h[0],A={x:C[0]-g,y:f-(C[1]-p)},P=new ip(A,[0,0,d,f],1,l(u,Gs)/2,!0,.001);for(let M=0,R=C.length;M<R;M+=2)A.x=C[M]-g,A.y=f-(C[M+1]-p),P.add(A);const{id:D,clipPathId:k}=s.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:u.color,"fill-opacity":u._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:P.toSVGPath()}},!0,!0);w(b=u,st,vf).call(b,{highlightOutlines:P.getOutlines(),highlightId:D,clipPathId:k}),w(x=u,st,no).call(x)}return u}serialize(e=!1){if(this.isEmpty()||e)return null;if(this.deleted)return this.serializeDeleted();const s=this.getRect(0,0),i=Ht._colorManager.convert(this.color),n={annotationType:nt.HIGHLIGHT,color:i,opacity:l(this,Dn),thickness:l(this,Gs),quadPoints:w(this,st,Yy).call(this),outlines:w(this,st,$y).call(this,s),pageIndex:this.pageIndex,rect:s,rotation:w(this,st,tu).call(this),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!w(this,st,Jy).call(this,n)?null:(n.id=this.annotationElementId,n)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};mh=new WeakMap,Ic=new WeakMap,On=new WeakMap,Va=new WeakMap,vh=new WeakMap,ls=new WeakMap,jc=new WeakMap,Nc=new WeakMap,Wa=new WeakMap,Hs=new WeakMap,As=new WeakMap,_e=new WeakMap,bh=new WeakMap,Dn=new WeakMap,Le=new WeakMap,yh=new WeakMap,Gs=new WeakMap,Bc=new WeakMap,st=new WeakSet,nm=function(){const e=new sp(l(this,On),.001);m(this,Hs,e.getOutlines()),[this.x,this.y,this.width,this.height]=l(this,Hs).box;const s=new sp(l(this,On),.0025,.001,this._uiManager.direction==="ltr");m(this,ls,s.getOutlines());const{lastPoint:i}=l(this,ls);m(this,bh,[(i[0]-this.x)/this.width,(i[1]-this.y)/this.height])},vf=function({highlightOutlines:e,highlightId:s,clipPathId:i}){var d,f;if(m(this,Hs,e),m(this,ls,e.getNewOutline(l(this,Gs)/2+1.5,.0025)),s>=0)m(this,As,s),m(this,Va,i),this.parent.drawLayer.finalizeDraw(s,{bbox:e.box,path:{d:e.toSVGPath()}}),m(this,Le,this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:l(this,ls).box,path:{d:l(this,ls).toSVGPath()}},!0));else if(this.parent){const g=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(l(this,As),{bbox:w(d=bt,Vs,Nh).call(d,l(this,Hs).box,(g-this.rotation+360)%360),path:{d:e.toSVGPath()}}),this.parent.drawLayer.updateProperties(l(this,Le),{bbox:w(f=bt,Vs,Nh).call(f,l(this,ls).box,g),path:{d:l(this,ls).toSVGPath()}})}const[r,a,h,c]=e.box;switch(this.rotation){case 0:this.x=r,this.y=a,this.width=h,this.height=c;break;case 90:{const[g,p]=this.parentDimensions;this.x=a,this.y=1-r,this.width=h*p/g,this.height=c*g/p;break}case 180:this.x=1-r,this.y=1-a,this.width=h,this.height=c;break;case 270:{const[g,p]=this.parentDimensions;this.x=1-a,this.y=r,this.width=h*p/g,this.height=c*g/p;break}}const{lastPoint:u}=l(this,ls);m(this,bh,[(u[0]-r)/h,(u[1]-a)/c])},Wy=function(e){const s=(r,a)=>{var h,c;this.color=r,m(this,Dn,a),(h=this.parent)==null||h.drawLayer.updateProperties(l(this,As),{root:{fill:r,"fill-opacity":a}}),(c=l(this,vh))==null||c.updateColor(r)},i=this.color,n=l(this,Dn);this.addCommands({cmd:s.bind(this,e,bt._defaultOpacity),undo:s.bind(this,i,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:dt.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(e)},!0)},zy=function(e){const s=l(this,Gs),i=n=>{m(this,Gs,n),w(this,st,Xy).call(this,n)};this.addCommands({cmd:i.bind(this,e),undo:i.bind(this,s),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:dt.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)},Xy=function(e){if(!l(this,_e))return;w(this,st,vf).call(this,{highlightOutlines:l(this,Hs).getNewOutline(e/2)}),this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)},rm=function(){l(this,As)===null||!this.parent||(this.parent.drawLayer.remove(l(this,As)),m(this,As,null),this.parent.drawLayer.remove(l(this,Le)),m(this,Le,null))},no=function(e=this.parent){l(this,As)===null&&({id:Ze(this,As)._,clipPathId:Ze(this,Va)._}=e.drawLayer.draw({bbox:l(this,Hs).box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":l(this,Dn)},rootClass:{highlight:!0,free:l(this,_e)},path:{d:l(this,Hs).toSVGPath()}},!1,!0),m(this,Le,e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:l(this,_e)},bbox:l(this,ls).box,path:{d:l(this,ls).toSVGPath()}},l(this,_e))),l(this,Wa)&&(l(this,Wa).style.clipPath=l(this,Va)))},Vs=new WeakSet,Nh=function([e,s,i,n],r){switch(r){case 90:return[1-s-n,e,n,i];case 180:return[1-e-i,1-s-n,i,n];case 270:return[s,1-e-i,n,i]}return[e,s,i,n]},Uy=function(e){bt._keyboardManager.exec(this,e)},bf=function(e){if(!l(this,mh))return;const s=window.getSelection();e?s.setPosition(l(this,mh),l(this,Ic)):s.setPosition(l(this,jc),l(this,Nc))},tu=function(){return l(this,_e)?this.rotation:0},Yy=function(){if(l(this,_e))return null;const[e,s]=this.pageDimensions,[i,n]=this.pageTranslation,r=l(this,On),a=new Float32Array(r.length*8);let h=0;for(const{x:c,y:u,width:d,height:f}of r){const g=c*e+i,p=(1-u)*s+n;a[h]=a[h+4]=g,a[h+1]=a[h+3]=p,a[h+2]=a[h+6]=g+d*e,a[h+5]=a[h+7]=p-f*s,h+=8}return a},$y=function(e){return l(this,Hs).serialize(e,w(this,st,tu).call(this))},qy=function(e,s){this._freeHighlight.add(s)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})},Ky=function(e,s){this._freeHighlight.isEmpty()?e.drawLayer.remove(this._freeHighlightId):e.createAndAddNewEditor(s,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:"main_toolbar"}),this._freeHighlightId=-1,this._freeHighlight=null,this._freeHighlightClipId=""},Jy=function(e){const{color:s}=this._initialData;return e.color.some((i,n)=>i!==s[n])},y(bt,Vs),J(bt,"_defaultColor",null),J(bt,"_defaultOpacity",1),J(bt,"_defaultThickness",12),J(bt,"_type","highlight"),J(bt,"_editorType",nt.HIGHLIGHT),J(bt,"_freeHighlightId",-1),J(bt,"_freeHighlight",null),J(bt,"_freeHighlightClipId","");let Ad=bt;class LC{constructor(){y(this,za,Object.create(null))}updateProperty(t,e){this[t]=e,this.updateSVGProperty(t,e)}updateProperties(t){if(t)for(const[e,s]of Object.entries(t))this.updateProperty(e,s)}updateSVGProperty(t,e){l(this,za)[t]=e}toSVGProperties(){const t=l(this,za);return m(this,za,Object.create(null)),{root:t}}reset(){m(this,za,Object.create(null))}updateAll(t=this){this.updateProperties(t)}clone(){Et("Not implemented")}}za=new WeakMap;const U=class U extends Ht{constructor(e){super(e);y(this,mt);y(this,Ts,null);y(this,_h);J(this,"_drawId",null);m(this,_h,e.mustBeCommitted||!1),e.drawOutlines&&(w(this,mt,am).call(this,e),w(this,mt,eu).call(this))}static _mergeSVGProperties(e,s){const i=new Set(Object.keys(e));for(const[n,r]of Object.entries(s))i.has(n)?Object.assign(e[n],r):e[n]=r;return e}static getDefaultDrawingOptions(e){Et("Not implemented")}static get typesMap(){Et("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(e,s){const i=this.typesMap.get(e);i&&this._defaultDrawingOptions.updateProperty(i,s),this._currentParent&&(l(U,pe).updateProperty(i,s),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(e,s){const i=this.constructor.typesMap.get(e);i&&this._updateProperty(e,i,s)}static get defaultPropertiesToUpdate(){const e=[],s=this._defaultDrawingOptions;for(const[i,n]of this.typesMap)e.push([i,s[n]]);return e}get propertiesToUpdate(){const e=[],{_drawingOptions:s}=this;for(const[i,n]of this.constructor.typesMap)e.push([i,s[n]]);return e}_updateProperty(e,s,i){const n=this._drawingOptions,r=n[s],a=h=>{var u;n.updateProperty(s,h);const c=l(this,Ts).updateProperty(s,h);c&&w(this,mt,su).call(this,c),(u=this.parent)==null||u.drawLayer.updateProperties(this._drawId,n.toSVGProperties())};this.addCommands({cmd:a.bind(this,i),undo:a.bind(this,r),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:e,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,U._mergeSVGProperties(l(this,Ts).getPathResizingSVGProperties(w(this,mt,yf).call(this)),{bbox:w(this,mt,Bh).call(this)}))}_onResized(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,U._mergeSVGProperties(l(this,Ts).getPathResizedSVGProperties(w(this,mt,yf).call(this)),{bbox:w(this,mt,Bh).call(this)}))}_onTranslating(e,s){var i;(i=this.parent)==null||i.drawLayer.updateProperties(this._drawId,{bbox:w(this,mt,Bh).call(this,e,s)})}_onTranslated(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,U._mergeSVGProperties(l(this,Ts).getPathTranslatedSVGProperties(w(this,mt,yf).call(this),this.parentDimensions),{bbox:w(this,mt,Bh).call(this)}))}_onStartDragging(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}commit(){super.commit(),this.disableEditMode(),this.disableEditing()}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),this._isDraggable=!0,l(this,_h)&&(m(this,_h,!1),this.commit(),this.parent.setSelected(this),e&&this.isOnScreen&&this.div.focus())}remove(){w(this,mt,hm).call(this),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,mt,eu).call(this),w(this,mt,su).call(this,l(this,Ts).box),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?(this._uiManager.removeShouldRescale(this),w(this,mt,hm).call(this)):e&&(this._uiManager.addShouldRescale(this),w(this,mt,eu).call(this,e),s=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),s&&this.select()}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,U._mergeSVGProperties({bbox:w(this,mt,Bh).call(this)},l(this,Ts).updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&w(this,mt,su).call(this,l(this,Ts).updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;const e=super.render();e.classList.add("draw");const s=document.createElement("div");e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal";const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),this._uiManager.addShouldRescale(this),this.disableEditing(),e}static createDrawerInstance(e,s,i,n,r){Et("Not implemented")}static startDrawing(e,s,i,n){var _;const{target:r,offsetX:a,offsetY:h,pointerId:c,pointerType:u}=n;if(l(U,xr)&&l(U,xr)!==u)return;const{viewport:{rotation:d}}=e,{width:f,height:g}=r.getBoundingClientRect(),p=m(U,Xa,new AbortController),v=e.combinedSignal(p);if(l(U,wr)||m(U,wr,c),l(U,xr)??m(U,xr,u),window.addEventListener("pointerup",b=>{var x;l(U,wr)===b.pointerId?this._endDraw(b):(x=l(U,Sr))==null||x.delete(b.pointerId)},{signal:v}),window.addEventListener("pointercancel",b=>{var x;l(U,wr)===b.pointerId?this._currentParent.endDrawingSession():(x=l(U,Sr))==null||x.delete(b.pointerId)},{signal:v}),window.addEventListener("pointerdown",b=>{l(U,xr)===b.pointerType&&((l(U,Sr)||m(U,Sr,new Set)).add(b.pointerId),l(U,pe).isCancellable()&&(l(U,pe).removeLastElement(),l(U,pe).isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:v}),window.addEventListener("contextmenu",ii,{signal:v}),r.addEventListener("pointermove",this._drawMove.bind(this),{signal:v}),r.addEventListener("touchmove",b=>{b.timeStamp===l(U,Ya)&&gs(b)},{signal:v}),e.toggleDrawing(),(_=s._editorUndoBar)==null||_.hide(),l(U,pe)){e.drawLayer.updateProperties(this._currentDrawId,l(U,pe).startNew(a,h,f,g,d));return}s.updateUIForDefaultProperties(this),m(U,pe,this.createDrawerInstance(a,h,f,g,d)),m(U,Ua,this.getDefaultDrawingOptions()),this._currentParent=e,{id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties(l(U,Ua).toSVGProperties(),l(U,pe).defaultSVGProperties),!0,!1)}static _drawMove(e){var r;if(m(U,Ya,-1),!l(U,pe))return;const{offsetX:s,offsetY:i,pointerId:n}=e;if(l(U,wr)===n){if(((r=l(U,Sr))==null?void 0:r.size)>=1){this._endDraw(e);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,l(U,pe).add(s,i)),m(U,Ya,e.timeStamp),gs(e)}}static _cleanup(e){e&&(this._currentDrawId=-1,this._currentParent=null,m(U,pe,null),m(U,Ua,null),m(U,xr,null),m(U,Ya,NaN)),l(U,Xa)&&(l(U,Xa).abort(),m(U,Xa,null),m(U,wr,NaN),m(U,Sr,null))}static _endDraw(e){const s=this._currentParent;if(s){if(s.toggleDrawing(!0),this._cleanup(!1),e&&s.drawLayer.updateProperties(this._currentDrawId,l(U,pe).end(e.offsetX,e.offsetY)),this.supportMultipleDrawings){const i=l(U,pe),n=this._currentDrawId,r=i.getLastElement();s.addCommands({cmd:()=>{s.drawLayer.updateProperties(n,i.setLastElement(r))},undo:()=>{s.drawLayer.updateProperties(n,i.removeLastElement())},mustExec:!1,type:dt.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(e){const s=this._currentParent;if(!s)return null;if(s.toggleDrawing(!0),s.cleanUndoStack(dt.DRAW_STEP),!l(U,pe).isEmpty()){const{pageDimensions:[i,n],scale:r}=s,a=s.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:l(U,pe).getOutlines(i*r,n*r,r,this._INNER_MARGIN),drawingOptions:l(U,Ua),mustBeCommitted:!e});return this._cleanup(!0),a}return s.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(e){}static deserializeDraw(e,s,i,n,r,a){Et("Not implemented")}static async deserialize(e,s,i){var d,f;const{rawDims:{pageWidth:n,pageHeight:r,pageX:a,pageY:h}}=s.viewport,c=this.deserializeDraw(a,h,n,r,this._INNER_MARGIN,e),u=await super.deserialize(e,s,i);return u.createDrawingOptions(e),w(d=u,mt,am).call(d,{drawOutlines:c}),w(f=u,mt,eu).call(f),u.onScaleChanging(),u.rotate(),u}serializeDraw(e){const[s,i]=this.pageTranslation,[n,r]=this.pageDimensions;return l(this,Ts).serialize([s,i,n,r],e)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};Ts=new WeakMap,_h=new WeakMap,pe=new WeakMap,Xa=new WeakMap,Ua=new WeakMap,wr=new WeakMap,xr=new WeakMap,Sr=new WeakMap,Ya=new WeakMap,mt=new WeakSet,am=function({drawOutlines:e,drawId:s,drawingOptions:i}){m(this,Ts,e),this._drawingOptions||(this._drawingOptions=i),s>=0?(this._drawId=s,this.parent.drawLayer.finalizeDraw(s,e.defaultProperties)):this._drawId=w(this,mt,om).call(this,e,this.parent),w(this,mt,su).call(this,e.box)},om=function(e,s){const{id:i}=s.drawLayer.draw(U._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return i},hm=function(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())},eu=function(e=this.parent){if(!(this._drawId!==null&&this.parent===e)){if(this._drawId!==null){this.parent.drawLayer.updateParent(this._drawId,e.drawLayer);return}this._drawingOptions.updateAll(),this._drawId=w(this,mt,om).call(this,l(this,Ts),e)}},Qy=function([e,s,i,n]){const{parentDimensions:[r,a],rotation:h}=this;switch(h){case 90:return[s,1-e,i*(a/r),n*(r/a)];case 180:return[1-e,1-s,i,n];case 270:return[1-s,e,i*(a/r),n*(r/a)];default:return[e,s,i,n]}},yf=function(){const{x:e,y:s,width:i,height:n,parentDimensions:[r,a],rotation:h}=this;switch(h){case 90:return[1-s,e,i*(r/a),n*(a/r)];case 180:return[1-e,1-s,i,n];case 270:return[s,1-e,i*(r/a),n*(a/r)];default:return[e,s,i,n]}},su=function(e){if([this.x,this.y,this.width,this.height]=w(this,mt,Qy).call(this,e),this.div){this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)}this._onResized()},Bh=function(){const{x:e,y:s,width:i,height:n,rotation:r,parentRotation:a,parentDimensions:[h,c]}=this;switch((r*4+a)/90){case 1:return[1-s-n,e,n,i];case 2:return[1-e-i,1-s-n,i,n];case 3:return[s,1-e-i,n,i];case 4:return[e,s-i*(h/c),n*(c/h),i*(h/c)];case 5:return[1-s,e,i*(h/c),n*(c/h)];case 6:return[1-e-n*(c/h),1-s,n*(c/h),i*(h/c)];case 7:return[s-i*(h/c),1-e-n*(c/h),i*(h/c),n*(c/h)];case 8:return[e-i,s-n,i,n];case 9:return[1-s,e-i,n,i];case 10:return[1-e,1-s,i,n];case 11:return[s-n,1-e,n,i];case 12:return[e-n*(c/h),s,n*(c/h),i*(h/c)];case 13:return[1-s-i*(h/c),e-n*(c/h),i*(h/c),n*(c/h)];case 14:return[1-e,1-s-i*(h/c),n*(c/h),i*(h/c)];case 15:return[s,1-e,i*(h/c),n*(c/h)];default:return[e,s,i,n]}},J(U,"_currentDrawId",-1),J(U,"_currentParent",null),y(U,pe,null),y(U,Xa,null),y(U,Ua,null),y(U,wr,NaN),y(U,xr,null),y(U,Sr,null),y(U,Ya,NaN),J(U,"_INNER_MARGIN",3);let np=U;class FC{constructor(t,e,s,i,n,r){y(this,xh);y(this,Ni,new Float64Array(6));y(this,me);y(this,ve);y(this,$a);y(this,wh);y(this,$e);y(this,we,"");y(this,Ws,0);y(this,qa,new Td);y(this,Ka);y(this,Ja);m(this,Ka,s),m(this,Ja,i),m(this,$a,n),m(this,wh,r),[t,e]=w(this,xh,_f).call(this,t,e);const a=m(this,me,[NaN,NaN,NaN,NaN,t,e]);m(this,$e,[t,e]),m(this,ve,[{line:a,points:l(this,$e)}]),l(this,Ni).set(a,0)}updateProperty(t,e){t==="stroke-width"&&m(this,wh,e)}isEmpty(){return!l(this,ve)||l(this,ve).length===0}isCancellable(){return l(this,$e).length<=10}add(t,e){[t,e]=w(this,xh,_f).call(this,t,e);const[s,i,n,r]=l(this,Ni).subarray(2,6),a=t-n,h=e-r;return Math.hypot(l(this,Ka)*a,l(this,Ja)*h)<=2?null:(l(this,$e).push(t,e),isNaN(s)?(l(this,Ni).set([n,r,t,e],2),l(this,me).push(NaN,NaN,NaN,NaN,t,e),{path:{d:this.toSVGPath()}}):(isNaN(l(this,Ni)[0])&&l(this,me).splice(6,6),l(this,Ni).set([s,i,n,r,t,e],0),l(this,me).push(...X.createBezierPoints(s,i,n,r,t,e)),{path:{d:this.toSVGPath()}}))}end(t,e){const s=this.add(t,e);return s||(l(this,$e).length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,s,i,n){m(this,Ka,s),m(this,Ja,i),m(this,$a,n),[t,e]=w(this,xh,_f).call(this,t,e);const r=m(this,me,[NaN,NaN,NaN,NaN,t,e]);m(this,$e,[t,e]);const a=l(this,ve).at(-1);return a&&(a.line=new Float32Array(a.line),a.points=new Float32Array(a.points)),l(this,ve).push({line:r,points:l(this,$e)}),l(this,Ni).set(r,0),m(this,Ws,0),this.toSVGPath(),null}getLastElement(){return l(this,ve).at(-1)}setLastElement(t){return l(this,ve)?(l(this,ve).push(t),m(this,me,t.line),m(this,$e,t.points),m(this,Ws,0),{path:{d:this.toSVGPath()}}):l(this,qa).setLastElement(t)}removeLastElement(){if(!l(this,ve))return l(this,qa).removeLastElement();l(this,ve).pop(),m(this,we,"");for(let t=0,e=l(this,ve).length;t<e;t++){const{line:s,points:i}=l(this,ve)[t];m(this,me,s),m(this,$e,i),m(this,Ws,0),this.toSVGPath()}return{path:{d:l(this,we)}}}toSVGPath(){const t=X.svgRound(l(this,me)[4]),e=X.svgRound(l(this,me)[5]);if(l(this,$e).length===2)return m(this,we,`${l(this,we)} M ${t} ${e} Z`),l(this,we);if(l(this,$e).length<=6){const i=l(this,we).lastIndexOf("M");m(this,we,`${l(this,we).slice(0,i)} M ${t} ${e}`),m(this,Ws,6)}if(l(this,$e).length===4){const i=X.svgRound(l(this,me)[10]),n=X.svgRound(l(this,me)[11]);return m(this,we,`${l(this,we)} L ${i} ${n}`),m(this,Ws,12),l(this,we)}const s=[];l(this,Ws)===0&&(s.push(`M ${t} ${e}`),m(this,Ws,6));for(let i=l(this,Ws),n=l(this,me).length;i<n;i+=6){const[r,a,h,c,u,d]=l(this,me).slice(i,i+6).map(X.svgRound);s.push(`C${r} ${a} ${h} ${c} ${u} ${d}`)}return m(this,we,l(this,we)+s.join(" ")),m(this,Ws,l(this,me).length),l(this,we)}getOutlines(t,e,s,i){const n=l(this,ve).at(-1);return n.line=new Float32Array(n.line),n.points=new Float32Array(n.points),l(this,qa).build(l(this,ve),t,e,s,l(this,$a),l(this,wh),i),m(this,Ni,null),m(this,me,null),m(this,ve,null),m(this,we,null),l(this,qa)}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}Ni=new WeakMap,me=new WeakMap,ve=new WeakMap,$a=new WeakMap,wh=new WeakMap,$e=new WeakMap,we=new WeakMap,Ws=new WeakMap,qa=new WeakMap,Ka=new WeakMap,Ja=new WeakMap,xh=new WeakSet,_f=function(t,e){return X._normalizePoint(t,e,l(this,Ka),l(this,Ja),l(this,$a))};const gp=class gp extends X{constructor(){super(...arguments);y(this,xe);y(this,qe);y(this,Hc,0);y(this,Gc);y(this,Es);y(this,Bi);y(this,Hi);y(this,Sh);y(this,Ch);y(this,Ah)}build(e,s,i,n,r,a,h){m(this,Bi,s),m(this,Hi,i),m(this,Sh,n),m(this,Ch,r),m(this,Ah,a),m(this,Gc,h??0),m(this,Es,e),w(this,xe,t_).call(this)}setLastElement(e){return l(this,Es).push(e),{path:{d:this.toSVGPath()}}}removeLastElement(){return l(this,Es).pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const e=[];for(const{line:s}of l(this,Es)){if(e.push(`M${X.svgRound(s[4])} ${X.svgRound(s[5])}`),s.length===6){e.push("Z");continue}if(s.length===12){e.push(`L${X.svgRound(s[10])} ${X.svgRound(s[11])}`);continue}for(let i=6,n=s.length;i<n;i+=6){const[r,a,h,c,u,d]=s.subarray(i,i+6).map(X.svgRound);e.push(`C${r} ${a} ${h} ${c} ${u} ${d}`)}}return e.join("")}serialize([e,s,i,n],r){const a=[],h=[],[c,u,d,f]=w(this,xe,Zy).call(this);let g,p,v,_,b,x,C,A,P;switch(l(this,Ch)){case 0:P=X._rescale,g=e,p=s+n,v=i,_=-n,b=e+c*i,x=s+(1-u-f)*n,C=e+(c+d)*i,A=s+(1-u)*n;break;case 90:P=X._rescaleAndSwap,g=e,p=s,v=i,_=n,b=e+u*i,x=s+c*n,C=e+(u+f)*i,A=s+(c+d)*n;break;case 180:P=X._rescale,g=e+i,p=s,v=-i,_=n,b=e+(1-c-d)*i,x=s+u*n,C=e+(1-c)*i,A=s+(u+f)*n;break;case 270:P=X._rescaleAndSwap,g=e+i,p=s+n,v=-i,_=-n,b=e+(1-u-f)*i,x=s+(1-c-d)*n,C=e+(1-u)*i,A=s+(1-c)*n;break}for(const{line:D,points:k}of l(this,Es))a.push(P(D,g,p,v,_,r?new Array(D.length):null)),h.push(P(k,g,p,v,_,r?new Array(k.length):null));return{lines:a,points:h,rect:[b,x,C,A]}}static deserialize(e,s,i,n,r,{paths:{lines:a,points:h},rotation:c,thickness:u}){const d=[];let f,g,p,v,_;switch(c){case 0:_=X._rescale,f=-e/i,g=s/n+1,p=1/i,v=-1/n;break;case 90:_=X._rescaleAndSwap,f=-s/n,g=-e/i,p=1/n,v=1/i;break;case 180:_=X._rescale,f=e/i+1,g=-s/n,p=-1/i,v=1/n;break;case 270:_=X._rescaleAndSwap,f=s/n+1,g=e/i+1,p=-1/n,v=-1/i;break}if(!a){a=[];for(const x of h){const C=x.length;if(C===2){a.push(new Float32Array([NaN,NaN,NaN,NaN,x[0],x[1]]));continue}if(C===4){a.push(new Float32Array([NaN,NaN,NaN,NaN,x[0],x[1],NaN,NaN,NaN,NaN,x[2],x[3]]));continue}const A=new Float32Array(3*(C-2));a.push(A);let[P,D,k,M]=x.subarray(0,4);A.set([NaN,NaN,NaN,NaN,P,D],0);for(let R=4;R<C;R+=2){const F=x[R],I=x[R+1];A.set(X.createBezierPoints(P,D,k,M,F,I),(R-2)*3),[P,D,k,M]=[k,M,F,I]}}}for(let x=0,C=a.length;x<C;x++)d.push({line:_(a[x].map(A=>A??NaN),f,g,p,v),points:_(h[x].map(A=>A??NaN),f,g,p,v)});const b=new gp;return b.build(d,i,n,1,c,u,r),b}get box(){return l(this,qe)}updateProperty(e,s){return e==="stroke-width"?w(this,xe,e_).call(this,s):null}updateParentDimensions([e,s],i){const[n,r]=w(this,xe,Nn).call(this);m(this,Bi,e),m(this,Hi,s),m(this,Sh,i);const[a,h]=w(this,xe,Nn).call(this),c=a-n,u=h-r,d=l(this,qe);return d[0]-=c,d[1]-=u,d[2]+=2*c,d[3]+=2*u,d}updateRotation(e){return m(this,Hc,e),{path:{transform:this.rotationTransform}}}get viewBox(){return l(this,qe).map(X.svgRound).join(" ")}get defaultProperties(){const[e,s]=l(this,qe);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${X.svgRound(e)} ${X.svgRound(s)}`}}}get rotationTransform(){const[,,e,s]=l(this,qe);let i=0,n=0,r=0,a=0,h=0,c=0;switch(l(this,Hc)){case 90:n=s/e,r=-e/s,h=e;break;case 180:i=-1,a=-1,h=e,c=s;break;case 270:n=-s/e,r=e/s,c=s;break;default:return""}return`matrix(${i} ${n} ${r} ${a} ${X.svgRound(h)} ${X.svgRound(c)})`}getPathResizingSVGProperties([e,s,i,n]){const[r,a]=w(this,xe,Nn).call(this),[h,c,u,d]=l(this,qe);if(Math.abs(u-r)<=X.PRECISION||Math.abs(d-a)<=X.PRECISION){const _=e+i/2-(h+u/2),b=s+n/2-(c+d/2);return{path:{"transform-origin":`${X.svgRound(e)} ${X.svgRound(s)}`,transform:`${this.rotationTransform} translate(${_} ${b})`}}}const f=(i-2*r)/(u-2*r),g=(n-2*a)/(d-2*a),p=u/i,v=d/n;return{path:{"transform-origin":`${X.svgRound(h)} ${X.svgRound(c)}`,transform:`${this.rotationTransform} scale(${p} ${v}) translate(${X.svgRound(r)} ${X.svgRound(a)}) scale(${f} ${g}) translate(${X.svgRound(-r)} ${X.svgRound(-a)})`}}}getPathResizedSVGProperties([e,s,i,n]){const[r,a]=w(this,xe,Nn).call(this),h=l(this,qe),[c,u,d,f]=h;if(h[0]=e,h[1]=s,h[2]=i,h[3]=n,Math.abs(d-r)<=X.PRECISION||Math.abs(f-a)<=X.PRECISION){const b=e+i/2-(c+d/2),x=s+n/2-(u+f/2);for(const{line:C,points:A}of l(this,Es))X._translate(C,b,x,C),X._translate(A,b,x,A);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${X.svgRound(e)} ${X.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const g=(i-2*r)/(d-2*r),p=(n-2*a)/(f-2*a),v=-g*(c+r)+e+r,_=-p*(u+a)+s+a;if(g!==1||p!==1||v!==0||_!==0)for(const{line:b,points:x}of l(this,Es))X._rescale(b,v,_,g,p,b),X._rescale(x,v,_,g,p,x);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${X.svgRound(e)} ${X.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,s],i){const[n,r]=i,a=l(this,qe),h=e-a[0],c=s-a[1];if(l(this,Bi)===n&&l(this,Hi)===r)for(const{line:u,points:d}of l(this,Es))X._translate(u,h,c,u),X._translate(d,h,c,d);else{const u=l(this,Bi)/n,d=l(this,Hi)/r;m(this,Bi,n),m(this,Hi,r);for(const{line:f,points:g}of l(this,Es))X._rescale(f,h,c,u,d,f),X._rescale(g,h,c,u,d,g);a[2]*=u,a[3]*=d}return a[0]=e,a[1]=s,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${X.svgRound(e)} ${X.svgRound(s)}`}}}get defaultSVGProperties(){const e=l(this,qe);return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${X.svgRound(e[0])} ${X.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}};qe=new WeakMap,Hc=new WeakMap,Gc=new WeakMap,Es=new WeakMap,Bi=new WeakMap,Hi=new WeakMap,Sh=new WeakMap,Ch=new WeakMap,Ah=new WeakMap,xe=new WeakSet,Nn=function(e=l(this,Ah)){const s=l(this,Gc)+e/2*l(this,Sh);return l(this,Ch)%180===0?[s/l(this,Bi),s/l(this,Hi)]:[s/l(this,Hi),s/l(this,Bi)]},Zy=function(){const[e,s,i,n]=l(this,qe),[r,a]=w(this,xe,Nn).call(this,0);return[e+r,s+a,i-2*r,n-2*a]},t_=function(){const e=m(this,qe,new Float32Array([1/0,1/0,-1/0,-1/0]));for(const{line:n}of l(this,Es)){if(n.length<=12){for(let h=4,c=n.length;h<c;h+=6){const[u,d]=n.subarray(h,h+2);e[0]=Math.min(e[0],u),e[1]=Math.min(e[1],d),e[2]=Math.max(e[2],u),e[3]=Math.max(e[3],d)}continue}let r=n[4],a=n[5];for(let h=6,c=n.length;h<c;h+=6){const[u,d,f,g,p,v]=n.subarray(h,h+6);q.bezierBoundingBox(r,a,u,d,f,g,p,v,e),r=p,a=v}}const[s,i]=w(this,xe,Nn).call(this);e[0]=Math.min(1,Math.max(0,e[0]-s)),e[1]=Math.min(1,Math.max(0,e[1]-i)),e[2]=Math.min(1,Math.max(0,e[2]+s)),e[3]=Math.min(1,Math.max(0,e[3]+i)),e[2]-=e[0],e[3]-=e[1]},e_=function(e){const[s,i]=w(this,xe,Nn).call(this);m(this,Ah,e);const[n,r]=w(this,xe,Nn).call(this),[a,h]=[n-s,r-i],c=l(this,qe);return c[0]-=a,c[1]-=h,c[2]+=2*a,c[3]+=2*h,c};let Td=gp;const pp=class pp extends LC{constructor(e){super();y(this,Th);m(this,Th,e),super.updateProperties({fill:"none",stroke:Ht._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(e,s){e==="stroke-width"&&(s??(s=this["stroke-width"]),s*=l(this,Th).realScale),super.updateSVGProperty(e,s)}clone(){const e=new pp(l(this,Th));return e.updateAll(this),e}};Th=new WeakMap;let rp=pp;const Eh=class Eh extends np{constructor(e){super({...e,name:"inkEditor"});y(this,zd);this._willKeepAspectRatio=!0}static initialize(e,s){Ht.initialize(e,s),this._defaultDrawingOptions=new rp(s.viewParameters)}static getDefaultDrawingOptions(e){const s=this._defaultDrawingOptions.clone();return s.updateProperties(e),s}static get supportMultipleDrawings(){return!0}static get typesMap(){return ht(this,"typesMap",new Map([[dt.INK_THICKNESS,"stroke-width"],[dt.INK_COLOR,"stroke"],[dt.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(e,s,i,n,r){return new FC(e,s,i,n,r,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(e,s,i,n,r,a){return Td.deserialize(e,s,i,n,r,a)}static async deserialize(e,s,i){let n=null;if(e instanceof tp){const{data:{inkLists:a,rect:h,rotation:c,id:u,color:d,opacity:f,borderStyle:{rawWidth:g},popupRef:p},parent:{page:{pageNumber:v}}}=e;n=e={annotationType:nt.INK,color:Array.from(d),thickness:g,opacity:f,paths:{points:a},boxes:null,pageIndex:v-1,rect:h.slice(0),rotation:c,id:u,deleted:!1,popupRef:p}}const r=await super.deserialize(e,s,i);return r.annotationElementId=e.id||null,r._initialData=n,r}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();const{_drawId:e,_drawingOptions:s,parent:i}=this;s.updateSVGProperty("stroke-width"),i.drawLayer.updateProperties(e,s.toSVGProperties())}static onScaleChangingWhenDrawing(){const e=this._currentParent;e&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),e.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:e,thickness:s,opacity:i}){this._drawingOptions=Eh.getDefaultDrawingOptions({stroke:q.makeHexColor(...e),"stroke-width":s,"stroke-opacity":i})}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:s,points:i,rect:n}=this.serializeDraw(e),{_drawingOptions:{stroke:r,"stroke-opacity":a,"stroke-width":h}}=this,c={annotationType:nt.INK,color:Ht._colorManager.convert(r),opacity:a,thickness:h,paths:{lines:s,points:i},pageIndex:this.pageIndex,rect:n,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?c:this.annotationElementId&&!w(this,zd,s_).call(this,c)?null:(c.id=this.annotationElementId,c)}renderAnnotationElement(e){const{points:s,rect:i}=this.serializeDraw(!1);return e.updateEdited({rect:i,thickness:this._drawingOptions["stroke-width"],points:s}),null}};zd=new WeakSet,s_=function(e){const{color:s,thickness:i,opacity:n,pageIndex:r}=this._initialData;return this._hasBeenMoved||this._hasBeenResized||e.color.some((a,h)=>a!==s[h])||e.thickness!==i||e.opacity!==n||e.pageIndex!==r},J(Eh,"_type","ink"),J(Eh,"_editorType",nt.INK),J(Eh,"_defaultDrawingOptions",null);let ap=Eh;const Vc=class Vc extends Ht{constructor(e){super({...e,name:"stampEditor"});y(this,vt);y(this,Vt,null);y(this,Se,null);y(this,Cr,null);y(this,Rn,null);y(this,Ar,null);y(this,kh,"");y(this,Gi,null);y(this,Vi,null);y(this,ks,!1);y(this,Ph,!1);m(this,Rn,e.bitmapUrl),m(this,Ar,e.bitmapFile)}static initialize(e,s){Ht.initialize(e,s)}static get supportedTypes(){return ht(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(s=>`image/${s}`))}static get supportedTypesStr(){return ht(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(e){return this.supportedTypes.includes(e)}static paste(e,s){s.pasteEditor(nt.STAMP,{bitmapFile:e.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){var e;return{type:"stamp",hasAltText:!!((e=this.altTextData)!=null&&e.altText)}}static computeTelemetryFinalData(e){const s=e.get("hasAltText");return{hasAltText:s.get(!0)??0,hasNoAltText:s.get(!1)??0}}async mlGuessAltText(e=null,s=!0){if(this.hasAltTextData())return null;const{mlManager:i}=this._uiManager;if(!i)throw new Error("No ML.");if(!await i.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:n,width:r,height:a}=e||this.copyCanvas(null,null,!0).imageData,h=await i.guess({name:"altText",request:{data:n,width:r,height:a,channels:n.length/(r*a)}});if(!h)throw new Error("No response from the AI service.");if(h.error)throw new Error("Error from the AI service.");if(h.cancel)return null;if(!h.output)throw new Error("No valid response from the AI service.");const c=h.output;return await this.setGuessedAltText(c),s&&!this.hasAltTextData()&&(this.altTextData={alt:c,decorative:!1}),c}remove(){var e;l(this,Se)&&(m(this,Vt,null),this._uiManager.imageManager.deleteId(l(this,Se)),(e=l(this,Gi))==null||e.remove(),m(this,Gi,null),l(this,Vi)&&(clearTimeout(l(this,Vi)),m(this,Vi,null))),super.remove()}rebuild(){if(!this.parent){l(this,Se)&&w(this,vt,wf).call(this);return}super.rebuild(),this.div!==null&&(l(this,Se)&&l(this,Gi)===null&&w(this,vt,wf).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(e){this._isDraggable=!0,e&&this.div.focus()}isEmpty(){return!(l(this,Cr)||l(this,Vt)||l(this,Rn)||l(this,Ar)||l(this,Se))}get isResizable(){return!0}render(){if(this.div)return this.div;let e,s;if(this.width&&(e=this.x,s=this.y),super.render(),this.div.hidden=!0,this.div.setAttribute("role","figure"),this.addAltTextButton(),l(this,Vt)?w(this,vt,lm).call(this):w(this,vt,wf).call(this),this.width&&!this.annotationElementId){const[i,n]=this.parentDimensions;this.setAt(e*i,s*n,this.width*i,this.height*n)}return this._uiManager.addShouldRescale(this),this.div}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;l(this,Vi)!==null&&clearTimeout(l(this,Vi)),m(this,Vi,setTimeout(()=>{m(this,Vi,null),w(this,vt,cm).call(this)},200))}copyCanvas(e,s,i=!1){var g;e||(e=224);const{width:n,height:r}=l(this,Vt),a=new Ng;let h=l(this,Vt),c=n,u=r,d=null;if(s){if(n>s||r>s){const M=Math.min(s/n,s/r);c=Math.floor(n*M),u=Math.floor(r*M)}d=document.createElement("canvas");const p=d.width=Math.ceil(c*a.sx),v=d.height=Math.ceil(u*a.sy);l(this,ks)||(h=w(this,vt,xf).call(this,p,v));const _=d.getContext("2d");_.filter=this._uiManager.hcmFilter;let b="white",x="#cfcfd8";this._uiManager.hcmFilter!=="none"?x="black":(g=window.matchMedia)!=null&&g.call(window,"(prefers-color-scheme: dark)").matches&&(b="#8f8f9d",x="#42414d");const C=15,A=C*a.sx,P=C*a.sy,D=new OffscreenCanvas(A*2,P*2),k=D.getContext("2d");k.fillStyle=b,k.fillRect(0,0,A*2,P*2),k.fillStyle=x,k.fillRect(0,0,A,P),k.fillRect(A,P,A,P),_.fillStyle=_.createPattern(D,"repeat"),_.fillRect(0,0,p,v),_.drawImage(h,0,0,h.width,h.height,0,0,p,v)}let f=null;if(i){let p,v;if(a.symmetric&&h.width<e&&h.height<e)p=h.width,v=h.height;else if(h=l(this,Vt),n>e||r>e){const x=Math.min(e/n,e/r);p=Math.floor(n*x),v=Math.floor(r*x),l(this,ks)||(h=w(this,vt,xf).call(this,p,v))}const b=new OffscreenCanvas(p,v).getContext("2d",{willReadFrequently:!0});b.drawImage(h,0,0,h.width,h.height,0,0,p,v),f={width:p,height:v,data:b.getImageData(0,0,p,v).data}}return{canvas:d,width:c,height:u,imageData:f}}getImageForAltText(){return l(this,Gi)}static async deserialize(e,s,i){var v;let n=null;if(e instanceof fb){const{data:{rect:_,rotation:b,id:x,structParent:C,popupRef:A},container:P,parent:{page:{pageNumber:D}}}=e,k=P.querySelector("canvas"),M=i.imageManager.getFromCanvas(P.id,k);k.remove();const R=((v=await s._structTree.getAriaAttributes(`${Rg}${x}`))==null?void 0:v.get("aria-label"))||"";n=e={annotationType:nt.STAMP,bitmapId:M.id,bitmap:M.bitmap,pageIndex:D-1,rect:_.slice(0),rotation:b,id:x,deleted:!1,accessibilityData:{decorative:!1,altText:R},isSvg:!1,structParent:C,popupRef:A}}const r=await super.deserialize(e,s,i),{rect:a,bitmap:h,bitmapUrl:c,bitmapId:u,isSvg:d,accessibilityData:f}=e;u&&i.imageManager.isValidId(u)?(m(r,Se,u),h&&m(r,Vt,h)):m(r,Rn,c),m(r,ks,d);const[g,p]=r.pageDimensions;return r.width=(a[2]-a[0])/g,r.height=(a[3]-a[1])/p,r.annotationElementId=e.id||null,f&&(r.altTextData=f),r._initialData=n,m(r,Ph,!!n),r}serialize(e=!1,s=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const i={annotationType:nt.STAMP,bitmapId:l(this,Se),pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:l(this,ks),structTreeParentId:this._structTreeParentId};if(e)return i.bitmapUrl=w(this,vt,Sf).call(this,!0),i.accessibilityData=this.serializeAltText(!0),i;const{decorative:n,altText:r}=this.serializeAltText(!1);if(!n&&r&&(i.accessibilityData={type:"Figure",alt:r}),this.annotationElementId){const h=w(this,vt,i_).call(this,i);if(h.isSame)return null;h.isSameAltText?delete i.accessibilityData:i.accessibilityData.structParent=this._initialData.structParent??-1}if(i.id=this.annotationElementId,s===null)return i;s.stamps||(s.stamps=new Map);const a=l(this,ks)?(i.rect[2]-i.rect[0])*(i.rect[3]-i.rect[1]):null;if(!s.stamps.has(l(this,Se)))s.stamps.set(l(this,Se),{area:a,serialized:i}),i.bitmap=w(this,vt,Sf).call(this,!1);else if(l(this,ks)){const h=s.stamps.get(l(this,Se));a>h.area&&(h.area=a,h.serialized.bitmap.close(),h.serialized.bitmap=w(this,vt,Sf).call(this,!1))}return i}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}};Vt=new WeakMap,Se=new WeakMap,Cr=new WeakMap,Rn=new WeakMap,Ar=new WeakMap,kh=new WeakMap,Gi=new WeakMap,Vi=new WeakMap,ks=new WeakMap,Ph=new WeakMap,vt=new WeakSet,iu=function(e,s=!1){if(!e){this.remove();return}m(this,Vt,e.bitmap),s||(m(this,Se,e.id),m(this,ks,e.isSvg)),e.file&&m(this,kh,e.file.name),w(this,vt,lm).call(this)},nu=function(){if(m(this,Cr,null),this._uiManager.enableWaiting(!1),!!l(this,Gi)){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Vt)){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Vt)){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}},wf=function(){if(l(this,Se)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(l(this,Se)).then(i=>w(this,vt,iu).call(this,i,!0)).finally(()=>w(this,vt,nu).call(this));return}if(l(this,Rn)){const i=l(this,Rn);m(this,Rn,null),this._uiManager.enableWaiting(!0),m(this,Cr,this._uiManager.imageManager.getFromUrl(i).then(n=>w(this,vt,iu).call(this,n)).finally(()=>w(this,vt,nu).call(this)));return}if(l(this,Ar)){const i=l(this,Ar);m(this,Ar,null),this._uiManager.enableWaiting(!0),m(this,Cr,this._uiManager.imageManager.getFromFile(i).then(n=>w(this,vt,iu).call(this,n)).finally(()=>w(this,vt,nu).call(this)));return}const e=document.createElement("input");e.type="file",e.accept=Vc.supportedTypesStr;const s=this._uiManager._signal;m(this,Cr,new Promise(i=>{e.addEventListener("change",async()=>{if(!e.files||e.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const n=await this._uiManager.imageManager.getFromFile(e.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),w(this,vt,iu).call(this,n)}i()},{signal:s}),e.addEventListener("cancel",()=>{this.remove(),i()},{signal:s})}).finally(()=>w(this,vt,nu).call(this))),e.click()},lm=function(){var d;const{div:e}=this;let{width:s,height:i}=l(this,Vt);const[n,r]=this.pageDimensions,a=.75;if(this.width)s=this.width*n,i=this.height*r;else if(s>a*n||i>a*r){const f=Math.min(a*n/s,a*r/i);s*=f,i*=f}const[h,c]=this.parentDimensions;this.setDims(s*h/n,i*c/r),this._uiManager.enableWaiting(!1);const u=m(this,Gi,document.createElement("canvas"));u.setAttribute("role","img"),this.addContainer(u),this.width=s/n,this.height=i/r,(d=this._initialOptions)!=null&&d.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(e.hidden=!1),w(this,vt,cm).call(this),l(this,Ph)||(this.parent.addUndoableEditor(this),m(this,Ph,!0)),this._reportTelemetry({action:"inserted_image"}),l(this,kh)&&u.setAttribute("aria-label",l(this,kh))},xf=function(e,s){const{width:i,height:n}=l(this,Vt);let r=i,a=n,h=l(this,Vt);for(;r>2*e||a>2*s;){const c=r,u=a;r>2*e&&(r=r>=16384?Math.floor(r/2)-1:Math.ceil(r/2)),a>2*s&&(a=a>=16384?Math.floor(a/2)-1:Math.ceil(a/2));const d=new OffscreenCanvas(r,a);d.getContext("2d").drawImage(h,0,0,c,u,0,0,r,a),h=d.transferToImageBitmap()}return h},cm=function(){const[e,s]=this.parentDimensions,{width:i,height:n}=this,r=new Ng,a=Math.ceil(i*e*r.sx),h=Math.ceil(n*s*r.sy),c=l(this,Gi);if(!c||c.width===a&&c.height===h)return;c.width=a,c.height=h;const u=l(this,ks)?l(this,Vt):w(this,vt,xf).call(this,a,h),d=c.getContext("2d");d.filter=this._uiManager.hcmFilter,d.drawImage(u,0,0,u.width,u.height,0,0,a,h)},Sf=function(e){if(e){if(l(this,ks)){const n=this._uiManager.imageManager.getSvgUrl(l(this,Se));if(n)return n}const s=document.createElement("canvas");return{width:s.width,height:s.height}=l(this,Vt),s.getContext("2d").drawImage(l(this,Vt),0,0),s.toDataURL()}if(l(this,ks)){const[s,i]=this.pageDimensions,n=Math.round(this.width*s*Kn.PDF_TO_CSS_UNITS),r=Math.round(this.height*i*Kn.PDF_TO_CSS_UNITS),a=new OffscreenCanvas(n,r);return a.getContext("2d").drawImage(l(this,Vt),0,0,l(this,Vt).width,l(this,Vt).height,0,0,n,r),a.transferToImageBitmap()}return structuredClone(l(this,Vt))},i_=function(e){var a;const{pageIndex:s,accessibilityData:{altText:i}}=this._initialData,n=e.pageIndex===s,r=(((a=e.accessibilityData)==null?void 0:a.alt)||"")===i;return{isSame:!this._hasBeenMoved&&!this._hasBeenResized&&n&&r,isSameAltText:r}},J(Vc,"_type","stamp"),J(Vc,"_editorType",nt.STAMP);let op=Vc;const vi=class vi{constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:a,textLayer:h,viewport:c,l10n:u}){y(this,Nt);y(this,Qa);y(this,Mh,!1);y(this,Wi,null);y(this,Tr,null);y(this,Ln,null);y(this,zs,new Map);y(this,Er,!1);y(this,Oh,!1);y(this,Za,!1);y(this,mi,null);y(this,Fn,null);y(this,Fe,null);y(this,In,null);y(this,$);const d=[...l(vi,kr).values()];if(!vi._initialized){vi._initialized=!0;for(const f of d)f.initialize(u,t)}t.registerEditorTypes(d),m(this,$,t),this.pageIndex=e,this.div=s,m(this,Qa,n),m(this,Wi,r),this.viewport=c,m(this,Fe,h),this.drawLayer=a,this._structTree=i,l(this,$).addLayer(this)}get isEmpty(){return l(this,zs).size===0}get isInvisible(){return this.isEmpty&&l(this,$).getMode()===nt.NONE}updateToolbar(t){l(this,$).updateToolbar(t)}updateMode(t=l(this,$).getMode()){switch(w(this,Nt,Cf).call(this),t){case nt.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case nt.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case nt.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);const{classList:e}=this.div;for(const s of l(vi,kr).values())e.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){var e;return t===((e=l(this,Fe))==null?void 0:e.div)}setEditingState(t){l(this,$).setEditingState(t)}addCommands(t){l(this,$).addCommands(t)}cleanUndoStack(t){l(this,$).cleanUndoStack(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){var e;(e=l(this,Wi))==null||e.div.classList.toggle("disabled",!t)}async enable(){m(this,Za,!0),this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const s of l(this,zs).values())s.enableEditing(),s.show(!0),s.annotationElementId&&(l(this,$).removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!l(this,Wi)){m(this,Za,!1);return}const e=l(this,Wi).getEditableAnnotations();for(const s of e){if(s.hide(),l(this,$).isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;const i=await this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}m(this,Za,!1)}disable(){var i;m(this,Oh,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,e=new Map;for(const n of l(this,zs).values())if(n.disableEditing(),!!n.annotationElementId){if(n.serialize()!==null){t.set(n.annotationElementId,n);continue}else e.set(n.annotationElementId,n);(i=this.getEditableAnnotation(n.annotationElementId))==null||i.show(),n.remove()}if(l(this,Wi)){const n=l(this,Wi).getEditableAnnotations();for(const r of n){const{id:a}=r.data;if(l(this,$).isDeletedAnnotationElement(a))continue;let h=e.get(a);if(h){h.resetAnnotationElement(r),h.show(!1),r.show();continue}h=t.get(a),h&&(l(this,$).addChangedExistingAnnotation(h),h.renderAnnotationElement(r)&&h.show(!1)),r.show()}}w(this,Nt,Cf).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const n of l(vi,kr).values())s.remove(`${n._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),m(this,Oh,!1)}getEditableAnnotation(t){var e;return((e=l(this,Wi))==null?void 0:e.getEditableAnnotation(t))||null}setActiveEditor(t){l(this,$).getActive()!==t&&l(this,$).setActiveEditor(t)}enableTextSelection(){var t;if(this.div.tabIndex=-1,(t=l(this,Fe))!=null&&t.div&&!l(this,In)){m(this,In,new AbortController);const e=l(this,$).combinedSignal(l(this,In));l(this,Fe).div.addEventListener("pointerdown",w(this,Nt,n_).bind(this),{signal:e}),l(this,Fe).div.classList.add("highlighting")}}disableTextSelection(){var t;this.div.tabIndex=0,(t=l(this,Fe))!=null&&t.div&&l(this,In)&&(l(this,In).abort(),m(this,In,null),l(this,Fe).div.classList.remove("highlighting"))}enableClick(){if(l(this,Tr))return;m(this,Tr,new AbortController);const t=l(this,$).combinedSignal(l(this,Tr));this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t});const e=this.pointerup.bind(this);this.div.addEventListener("pointerup",e,{signal:t}),this.div.addEventListener("pointercancel",e,{signal:t})}disableClick(){var t;(t=l(this,Tr))==null||t.abort(),m(this,Tr,null)}attach(t){l(this,zs).set(t.id,t);const{annotationElementId:e}=t;e&&l(this,$).isDeletedAnnotationElement(e)&&l(this,$).removeDeletedAnnotationElement(t)}detach(t){var e;l(this,zs).delete(t.id),(e=l(this,Qa))==null||e.removePointerInTextLayer(t.contentDiv),!l(this,Oh)&&t.annotationElementId&&l(this,$).addDeletedAnnotationElement(t)}remove(t){this.detach(t),l(this,$).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){var e;t.parent!==this&&(t.parent&&t.annotationElementId&&(l(this,$).addDeletedAnnotationElement(t.annotationElementId),Ht.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),(e=t.parent)==null||e.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),l(this,$).addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!l(this,Za)),l(this,$).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var s;if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!l(this,Ln)&&(t._focusEventsAllowed=!1,m(this,Ln,setTimeout(()=>{m(this,Ln,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:l(this,$)._signal}),e.focus())},0))),t._structTreeParentId=(s=l(this,Qa))==null?void 0:s.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 e=()=>t._uiManager.rebuild(t),s=()=>{t.remove()};this.addCommands({cmd:e,undo:s,mustExec:!1})}getNextId(){return l(this,$).getId()}combinedSignal(t){return l(this,$).combinedSignal(t)}canCreateNewEmptyEditor(){var t;return(t=l(this,Nt,Ui))==null?void 0:t.canCreateNewEmptyEditor()}pasteEditor(t,e){l(this,$).updateToolbar(t),l(this,$).updateMode(t);const{offsetX:s,offsetY:i}=w(this,Nt,dm).call(this),n=this.getNextId(),r=w(this,Nt,um).call(this,{parent:this,id:n,x:s,y:i,uiManager:l(this,$),isCentered:!0,...e});r&&this.add(r)}async deserialize(t){var e;return await((e=l(vi,kr).get(t.annotationType??t.annotationEditorType))==null?void 0:e.deserialize(t,this,l(this,$)))||null}createAndAddNewEditor(t,e,s={}){const i=this.getNextId(),n=w(this,Nt,um).call(this,{parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:l(this,$),isCentered:e,...s});return n&&this.add(n),n}addNewEditor(){this.createAndAddNewEditor(w(this,Nt,dm).call(this),!0)}setSelected(t){l(this,$).setSelected(t)}toggleSelected(t){l(this,$).toggleSelected(t)}unselect(t){l(this,$).unselect(t)}pointerup(t){var s;const{isMac:e}=ze.platform;if(!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&l(this,Er)&&(m(this,Er,!1),!((s=l(this,Nt,Ui))!=null&&s.isDrawer&&l(this,Nt,Ui).supportMultipleDrawings))){if(!l(this,Mh)){m(this,Mh,!0);return}if(l(this,$).getMode()===nt.STAMP){l(this,$).unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){var i;if(l(this,$).getMode()===nt.HIGHLIGHT&&this.enableTextSelection(),l(this,Er)){m(this,Er,!1);return}const{isMac:e}=ze.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;if(m(this,Er,!0),(i=l(this,Nt,Ui))!=null&&i.isDrawer){this.startDrawingSession(t);return}const s=l(this,$).getActive();m(this,Mh,!s||s.isEmpty())}startDrawingSession(t){if(this.div.focus(),l(this,mi)){l(this,Nt,Ui).startDrawing(this,l(this,$),!1,t);return}l(this,$).setCurrentDrawingSession(this),m(this,mi,new AbortController);const e=l(this,$).combinedSignal(l(this,mi));this.div.addEventListener("blur",({relatedTarget:s})=>{s&&!this.div.contains(s)&&(m(this,Fn,null),this.commitOrRemove())},{signal:e}),l(this,Nt,Ui).startDrawing(this,l(this,$),!1,t)}pause(t){if(t){const{activeElement:e}=document;this.div.contains(e)&&m(this,Fn,e);return}l(this,Fn)&&setTimeout(()=>{var e;(e=l(this,Fn))==null||e.focus(),m(this,Fn,null)},0)}endDrawingSession(t=!1){return l(this,mi)?(l(this,$).setCurrentDrawingSession(null),l(this,mi).abort(),m(this,mi,null),m(this,Fn,null),l(this,Nt,Ui).endDrawing(t)):null}findNewParent(t,e,s){const i=l(this,$).findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}commitOrRemove(){return l(this,mi)?(this.endDrawingSession(),!0):!1}onScaleChanging(){l(this,mi)&&l(this,Nt,Ui).onScaleChangingWhenDrawing(this)}destroy(){var t,e;this.commitOrRemove(),((t=l(this,$).getActive())==null?void 0:t.parent)===this&&(l(this,$).commitOrRemove(),l(this,$).setActiveEditor(null)),l(this,Ln)&&(clearTimeout(l(this,Ln)),m(this,Ln,null));for(const s of l(this,zs).values())(e=l(this,Qa))==null||e.removePointerInTextLayer(s.contentDiv),s.setParent(null),s.isAttachedToDOM=!1,s.div.remove();this.div=null,l(this,zs).clear(),l(this,$).removeLayer(this)}render({viewport:t}){this.viewport=t,zr(this.div,t);for(const e of l(this,$).getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){l(this,$).commitOrRemove(),w(this,Nt,Cf).call(this);const e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,zr(this.div,{rotation:s}),e!==s)for(const i of l(this,zs).values())i.rotate(s)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return l(this,$).viewParameters.realScale}};Qa=new WeakMap,Mh=new WeakMap,Wi=new WeakMap,Tr=new WeakMap,Ln=new WeakMap,zs=new WeakMap,Er=new WeakMap,Oh=new WeakMap,Za=new WeakMap,mi=new WeakMap,Fn=new WeakMap,Fe=new WeakMap,In=new WeakMap,$=new WeakMap,kr=new WeakMap,Nt=new WeakSet,n_=function(t){l(this,$).unselectAll();const{target:e}=t;if(e===l(this,Fe).div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&l(this,Fe).div.contains(e)){const{isMac:s}=ze.platform;if(t.button!==0||t.ctrlKey&&s)return;l(this,$).showAllEditors("highlight",!0,!0),l(this,Fe).div.classList.add("free"),this.toggleDrawing(),Ad.startHighlighting(this,l(this,$).direction==="ltr",{target:l(this,Fe).div,x:t.x,y:t.y}),l(this,Fe).div.addEventListener("pointerup",()=>{l(this,Fe).div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:l(this,$)._signal}),t.preventDefault()}},Ui=function(){return l(vi,kr).get(l(this,$).getMode())},um=function(t){const e=l(this,Nt,Ui);return e?new e.prototype.constructor(t):null},dm=function(){const{x:t,y:e,width:s,height:i}=this.div.getBoundingClientRect(),n=Math.max(0,t),r=Math.max(0,e),a=Math.min(window.innerWidth,t+s),h=Math.min(window.innerHeight,e+i),c=(n+a)/2-t,u=(r+h)/2-e,[d,f]=this.viewport.rotation%180===0?[c,u]:[u,c];return{offsetX:d,offsetY:f}},Cf=function(){for(const t of l(this,zs).values())t.isEmpty()&&t.remove()},J(vi,"_initialized",!1),y(vi,kr,new Map([ep,ap,op,Ad].map(t=>[t._editorType,t])));let hp=vi;const Ie=class Ie{constructor({pageIndex:t}){y(this,zi);y(this,bi,null);y(this,Wc,0);y(this,Ke,new Map);y(this,to,new Map);this.pageIndex=t}setParent(t){if(!l(this,bi)){m(this,bi,t);return}if(l(this,bi)!==t){if(l(this,Ke).size>0)for(const e of l(this,Ke).values())e.remove(),t.append(e);m(this,bi,t)}}static get _svgFactory(){return ht(this,"_svgFactory",new Qg)}draw(t,e=!1,s=!1){const i=Ze(this,Wc)._++,n=w(this,zi,fm).call(this),r=Ie._svgFactory.createElement("defs");n.append(r);const a=Ie._svgFactory.createElement("path");r.append(a);const h=`path_p${this.pageIndex}_${i}`;a.setAttribute("id",h),a.setAttribute("vector-effect","non-scaling-stroke"),e&&l(this,to).set(i,a);const c=s?w(this,zi,a_).call(this,r,h):null,u=Ie._svgFactory.createElement("use");return n.append(u),u.setAttribute("href",`#${h}`),this.updateProperties(n,t),l(this,Ke).set(i,n),{id:i,clipPathId:`url(#${c})`}}drawOutline(t,e){const s=Ze(this,Wc)._++,i=w(this,zi,fm).call(this),n=Ie._svgFactory.createElement("defs");i.append(n);const r=Ie._svgFactory.createElement("path");n.append(r);const a=`path_p${this.pageIndex}_${s}`;r.setAttribute("id",a),r.setAttribute("vector-effect","non-scaling-stroke");let h;if(e){const d=Ie._svgFactory.createElement("mask");n.append(d),h=`mask_p${this.pageIndex}_${s}`,d.setAttribute("id",h),d.setAttribute("maskUnits","objectBoundingBox");const f=Ie._svgFactory.createElement("rect");d.append(f),f.setAttribute("width","1"),f.setAttribute("height","1"),f.setAttribute("fill","white");const g=Ie._svgFactory.createElement("use");d.append(g),g.setAttribute("href",`#${a}`),g.setAttribute("stroke","none"),g.setAttribute("fill","black"),g.setAttribute("fill-rule","nonzero"),g.classList.add("mask")}const c=Ie._svgFactory.createElement("use");i.append(c),c.setAttribute("href",`#${a}`),h&&c.setAttribute("mask",`url(#${h})`);const u=c.cloneNode();return i.append(u),c.classList.add("mainOutline"),u.classList.add("secondaryOutline"),this.updateProperties(i,t),l(this,Ke).set(s,i),s}finalizeDraw(t,e){l(this,to).delete(t),this.updateProperties(t,e)}updateProperties(t,e){var h;if(!e)return;const{root:s,bbox:i,rootClass:n,path:r}=e,a=typeof t=="number"?l(this,Ke).get(t):t;if(a){if(s&&w(this,zi,gm).call(this,a,s),i&&w(h=Ie,Xd,r_).call(h,a,i),n){const{classList:c}=a;for(const[u,d]of Object.entries(n))c.toggle(u,d)}if(r){const u=a.firstChild.firstChild;w(this,zi,gm).call(this,u,r)}}}updateParent(t,e){if(e===this)return;const s=l(this,Ke).get(t);s&&(l(e,bi).append(s),l(this,Ke).delete(t),l(e,Ke).set(t,s))}remove(t){l(this,to).delete(t),l(this,bi)!==null&&(l(this,Ke).get(t).remove(),l(this,Ke).delete(t))}destroy(){m(this,bi,null);for(const t of l(this,Ke).values())t.remove();l(this,Ke).clear(),l(this,to).clear()}};bi=new WeakMap,Wc=new WeakMap,Ke=new WeakMap,to=new WeakMap,Xd=new WeakSet,r_=function(t,[e,s,i,n]){const{style:r}=t;r.top=`${100*s}%`,r.left=`${100*e}%`,r.width=`${100*i}%`,r.height=`${100*n}%`},zi=new WeakSet,fm=function(){const t=Ie._svgFactory.create(1,1,!0);return l(this,bi).append(t),t.setAttribute("aria-hidden",!0),t},a_=function(t,e){const s=Ie._svgFactory.createElement("clipPath");t.append(s);const i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=Ie._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i},gm=function(t,e){for(const[s,i]of Object.entries(e))i===null?t.removeAttribute(s):t.setAttribute(s,i)},y(Ie,Xd);let lp=Ie;globalThis.pdfjsTestingUtils={HighlightOutliner:sp},Z.AbortException,Z.AnnotationEditorLayer,Z.AnnotationEditorParamsType,Z.AnnotationEditorType,Z.AnnotationEditorUIManager,Z.AnnotationLayer,Z.AnnotationMode,Z.ColorPicker,Z.DOMSVGFactory,Z.DrawLayer,Z.FeatureTest;var IC=Z.GlobalWorkerOptions;Z.ImageKind,Z.InvalidPDFException,Z.MissingPDFException,Z.OPS,Z.OutputScale,Z.PDFDataRangeTransport,Z.PDFDateString,Z.PDFWorker,Z.PasswordResponses,Z.PermissionFlag,Z.PixelsPerInch,Z.RenderingCancelledException,Z.TextLayer,Z.TouchManager,Z.UnexpectedResponseException,Z.Util,Z.VerbosityLevel,Z.XfaLayer,Z.build,Z.createValidAbsoluteUrl,Z.fetchData;var jC=Z.getDocument;Z.getFilenameFromUrl,Z.getPdfFilenameFromUrl,Z.getXfaPageViewport,Z.isDataScheme,Z.isPdfFile,Z.noContextMenu,Z.normalizeUnicode,Z.setLayerDimensions,Z.shadow,Z.stopEvent,Z.version;const NC={"pdfjs-dist":"4.10.38"};function BC(o){return new Promise((t,e)=>{const s=new FileReader;s.addEventListener("load",()=>t(s.result)),s.addEventListener("error",e),s.readAsDataURL(o)})}const HC=NC["pdfjs-dist"].replace("^","");IC.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${HC}/pdf.worker.min.mjs`;async function GC(o){const t="data:application/pdf;base64,",e=await BC(o);if(typeof e=="string")return window.atob(e.slice(t.length))}function VC(o,t){return jC({data:o,password:t}).promise}const WC="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2040%2040'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3ccircle%20cx='20'%20cy='20'%20r='10.75'%20stroke='currentColor'%20stroke-width='2.5'/%3e%3cpath%20d='M16%2024L23.7782%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3cpath%20d='M24%2024L16.2218%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3c/svg%3e";function zC(o){return new URL(Object.assign({"../assets/close.svg":WC})[`../assets/${o}`],typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Mt&&Mt.tagName.toUpperCase()==="SCRIPT"&&Mt.src||new URL("pdf-canvas.umd.js",document.baseURI).href).href}function XC(o){return new Promise((t,e)=>{const s=window.URL.createObjectURL(o),i=new Image;i.src=s,i.addEventListener("load",async()=>{window.URL.revokeObjectURL(s),t(await UC(i))}),i.addEventListener("error",n=>{window.URL.revokeObjectURL(s),e(n)})})}function UC(o){return new Promise(t=>{const e=document.createElement("canvas"),s=e.getContext("2d"),{naturalWidth:i,naturalHeight:n}=o;e.width=i,e.height=n,s==null||s.drawImage(o,0,0,i,n),t(e.toDataURL("image/jpeg",.8))})}let pb=null;function YC(){const o=document.createElement("div");o.style.width="1in",document.body.append(o);const t=o.offsetWidth;return o.remove(),t}function $C(){const o=pb??YC();return pb=o,o/72}function qC(o,t=500){if(typeof o!="function")throw new TypeError("The first argument is not a function.");let e=null;return function(...s){e&&clearTimeout(e),e=setTimeout(()=>{e=null,o.apply(this,s)},t)}}const Ls=new Map;function KC(o){const t=new fg(o);return Ls.set(o,t),t}function JC(o,t){const e=Date.now();return{PDFId:`${o.name}-${e}`,name:o.name.replace(/.pdf/,""),updateDate:e,PDFBase64:t}}function QC(o,t){const e=o.getViewport({scale:t}),s=document.createElement("canvas"),i=s.getContext("2d"),n=$C()/window.devicePixelRatio;s.width=Math.floor(e.width*n),s.height=Math.floor(e.height*n);const r={canvasContext:i,viewport:e,transform:[n,0,0,n,0,0]},a=o.render(r);return{canvas:s,renderTask:a}}async function ZC(o,t,e){const s=o||zC("close.svg"),{objects:i,options:n}=await Tx(s),r=i.filter(h=>h!==null),a=Hw.groupSVGElements(r,n);return r.forEach(h=>{h.stroke=t}),a.hoverCursor="pointer",a.stroke=`${t}-${e}`,a}function tA(o,t){if(!Ls.get(o))return;const s=1/3,i=aA(t,s);vb(o,i,s)}async function eA(o,t){const e=await XC(t),s=Date.now(),n={PDFId:`${t.name}${s}`,name:t.name.replace(/.png|.jpg|.jpeg/,""),updateDate:s,PDFBase64:e};return mb(o,{url:e}),{...n,pages:1}}async function mb(o,{url:t,scale:e=.5}){if(!Ls.get(o))return;const i=await ke.fromURL(t);i.scale(e),vb(o,i,e)}function vb(o,t,e){const s=Ls.get(o);s&&(s.setWidth(t.width*e),s.setHeight(t.height*e),s.backgroundImage=t,s.renderAll())}function vl(o,t){if(!t)return;const{oCoords:e}=o;if(!e)return;const{x:s,y:i}=e.tl.touchCorner.tl,{height:n,width:r,scaleY:a,scaleX:h}=t;t.top=i-n*a/2,t.left=s-r*h/2,t.setCoords()}function sA(o,t,e){!e||!o||(e.scale(1/t),vl(o,e))}function iA(o,t){if(!o)return;const e=o._cornerSize||8;o.borderScaleFactor=1/t,o.cornerSize=e*(1/t),o.touchCornerSize=e*4*(1/t),o.setCoords()}function nA(o){const t=Ls.get(o);t&&(t.discardActiveObject(),t.renderAll())}function rA(o){const t=Ls.get(o);t&&(t.clear(),Ls.delete(o))}function aA(o,t){return new ke(o,{scaleX:t,scaleY:t})}const oA={top:100,left:50,scaleX:.5,scaleY:.5,borderColor:"black",cornerStrokeColor:"black",cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},hA={top:100,left:50,fontFamily:"helvetica",borderColor:"black",cornerStrokeColor:"black",scaleX:.7,scaleY:.7,cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},lA={stroke:"#000",hoverStroke:"#B7EC5D",src:""};function bb(o=""){const t=Q.useRef(0),e=Q.useRef(null),s=Q.useRef(null),i=Q.useRef(1),n=Q.useRef({...lA});function r(){if(!o||Ls.has(o))return;const k=KC(o);return k.on("selection:cleared",()=>A(k)),k}function a(k,M){var I;const R=k.type,F={"application/pdf":h,"image/png":d,"image/jpeg":d};return((I=F[R])==null?void 0:I.call(F,k,M))??Promise.reject(new Error(`Unsupported ${R} file type.`))}async function h(k,M){const R=await GC(k);if(!R)return;const F=JC(k,R);try{return await c({page:1,PDFBase64:R,scale:.8,password:M}),{...F,pages:t.current}}catch(I){return Promise.reject(I)}}async function c({page:k,PDFBase64:M,scale:R,password:F}){try{const I=await VC(M,F),Y=await I.getPage(k),{renderTask:N,canvas:H}=QC(Y,R);return t.current=I.numPages,N.promise.then(()=>u(H))}catch(I){return Promise.reject(I)}}function u(k){tA(o,k)}async function d(k){return await eA(o,k)}async function f({url:k,scale:M=.5}){await mb(o,{url:k,scale:M})}async function g(k,M){const R=Ls.get(o);if(!R)return;const F=await ke.fromURL(k,{},{...oA,...M});R.add(F),v(R,F)}function p(k,M){const R=Ls.get(o);if(!R)return;const F=new Ee(k,{...hA,...M});R.add(F),v(R,F)}function v(k,M){M.on("selected",R=>_({canvas:k,target:R.target})),M.on("modified",R=>vl(R.target,e.current)),M.on("scaling",R=>vl(R.transform.target,e.current)),M.on("moving",R=>vl(R.transform.target,e.current)),M.on("rotating",R=>vl(R.transform.target,e.current))}async function _({canvas:k,target:M,stroke:R=n.current.stroke,uuid:F=Date.now()}){var Y;if(((Y=e.current)==null?void 0:Y.stroke)===`${R}-${F}`)return;const I=await ZC(n.current.src,R,F);A(k),e.current=I,s.current=M,b(k,M,F),x(i.current,!0),k.add(I)}function b(k,M,R){e.current&&(e.current.on("selected",()=>{k.remove(M),A(k)}),e.current.on("mouseover",()=>{_({canvas:k,target:M,stroke:n.current.hoverStroke,uuid:R})}),e.current.on("mouseout",()=>{_({canvas:k,target:M,stroke:n.current.stroke,uuid:R})}))}function x(k,M=!1){const R=Ls.get(o);i.current=k,R&&(iA(s.current,k),sA(s.current,k,e.current),!M&&R.renderAll())}function C(k){if(!k)return;n.current={...n.current,...k};const M=Ls.get(o);!e||!s.current||!M||_({target:s.current,canvas:M})}function A(k){e.current&&(k.remove(e.current),e.current=s.current=null)}function P(){nA(o)}function D(){rA(o)}return{createCanvas:r,loadFile:a,specifyPage:c,renderImage:f,addFabric:g,addTextFabric:p,clearActive:P,deleteCanvas:D,scaleFabric:x,setCloseSvgOptions:C}}function cA(o){let t=0;const e=qC(()=>{t!==window.innerWidth&&(t=window.innerWidth,o())});Q.useEffect(()=>(window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)),[])}const uA=Q.forwardRef(dA);function dA({file:o,page:t=1,canvasId:e="PDF-canvas",fileZoom:s=1,fileScale:i=1,canvasScale:n=1,canvasClass:r="",isDrop:a=!1,password:h,dropTextOptions:c,dropImageOptions:u,closeSvgOptions:d},f){const g=Q.useRef(null),p=`${e}-${t-1}`,v=Q.useMemo(()=>s*n,[s,n]),{createCanvas:_,specifyPage:b,addFabric:x,addTextFabric:C,renderImage:A,clearActive:P,deleteCanvas:D,scaleFabric:k,setCloseSvgOptions:M}=bb(p);cA(R);async function R(){window.requestAnimationFrame(async()=>{if(_(),o.PDFBase64.startsWith("data:image")||o.canvas){const{canvas:N}=o,H=N?7:3,at=N!=null&&N.length?N[t-1]:o.PDFBase64;A({url:at,scale:i/H});return}await b({page:t,PDFBase64:o.PDFBase64,scale:i,password:h})})}function F(N){if(N.preventDefault(),N.stopPropagation(),!a||!N.dataTransfer)return;const{dataTransfer:H,clientX:at,clientY:j}=N,W=H.getData("text/plain"),it=H.getData("text/uri-list"),kt={left:at-71,top:j-55};it?I(it,kt):W&&Y(W,kt)}function I(N,H){x(N,{...H,...u})}function Y(N,H){C(N,{...H,...c})}return Q.useImperativeHandle(f,()=>({addImage:I,addText:Y,clearActive:P,deleteCanvas:D,canvasRef:g})),Q.useEffect(()=>{R()},[i,t,o,h]),Q.useEffect(()=>{k(v)},[v]),Q.useEffect(()=>{M(d)},[d]),Q.useEffect(()=>()=>D(),[]),vm.jsx("div",{style:{transform:`scale(${v})`},onDragOver:N=>N.preventDefault(),onDragEnter:N=>N.preventDefault(),onDrop:F,children:vm.jsx("canvas",{id:p,ref:g,className:r})})}ut.default=uA,ut.useFabric=bb,Object.defineProperties(ut,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
538
+ `)){const s=document.createElement("div");s.append(e?document.createTextNode(e):document.createElement("br")),this.editorDiv.append(s)}},My=function(){return l(this,ws).replaceAll(" "," ")},Zp=function(e){return e.replaceAll(" "," ")},Oy=function(e){const{value:s,fontSize:i,color:n,pageIndex:r}=this._initialData;return this._hasBeenMoved||e.value!==s||e.fontSize!==i||e.color.some((a,h)=>a!==n[h])||e.pageIndex!==r},y(Ot,kn),J(Ot,"_freeTextDefaultContent",""),J(Ot,"_internalPadding",0),J(Ot,"_defaultColor",null),J(Ot,"_defaultFontSize",10),J(Ot,"_type","freetext"),J(Ot,"_editorType",nt.FREETEXT);let ep=Ot;class X{toSVGPath(){Et("Abstract method `toSVGPath` must be implemented.")}get box(){Et("Abstract getter `box` must be implemented.")}serialize(t,e){Et("Abstract method `serialize` must be implemented.")}static _rescale(t,e,s,i,n,r){r||(r=new Float32Array(t.length));for(let a=0,h=t.length;a<h;a+=2)r[a]=e+t[a]*i,r[a+1]=s+t[a+1]*n;return r}static _rescaleAndSwap(t,e,s,i,n,r){r||(r=new Float32Array(t.length));for(let a=0,h=t.length;a<h;a+=2)r[a]=e+t[a+1]*i,r[a+1]=s+t[a]*n;return r}static _translate(t,e,s,i){i||(i=new Float32Array(t.length));for(let n=0,r=t.length;n<r;n+=2)i[n]=e+t[n],i[n+1]=s+t[n+1];return i}static svgRound(t){return Math.round(t*1e4)}static _normalizePoint(t,e,s,i,n){switch(n){case 90:return[1-e/s,t/i];case 180:return[1-t/s,1-e/i];case 270:return[e/s,1-t/i];default:return[t/s,e/i]}}static _normalizePagePoint(t,e,s){switch(s){case 90:return[1-e,t];case 180:return[1-t,1-e];case 270:return[e,1-t];default:return[t,e]}}static createBezierPoints(t,e,s,i,n,r){return[(t+5*s)/6,(e+5*i)/6,(5*s+n)/6,(5*i+r)/6,(s+n)/2,(i+r)/2]}}J(X,"PRECISION",1e-4);const Pn=class Pn{constructor({x:t,y:e},s,i,n,r,a=0){y(this,ce);y(this,Ss);y(this,di,[]);y(this,oh);y(this,hh);y(this,ji,[]);y(this,lt,new Float32Array(18));y(this,Na);y(this,Ba);y(this,Cc);y(this,Ac);y(this,lh);y(this,ch);y(this,br,[]);m(this,Ss,s),m(this,ch,n*i),m(this,hh,r),l(this,lt).set([NaN,NaN,NaN,NaN,t,e],6),m(this,oh,a),m(this,Ac,l(Pn,Tc)*i),m(this,Cc,l(Pn,Vd)*i),m(this,lh,i),l(this,br).push(t,e)}isEmpty(){return isNaN(l(this,lt)[8])}add({x:t,y:e}){var R;m(this,Na,t),m(this,Ba,e);const[s,i,n,r]=l(this,Ss);let[a,h,c,u]=l(this,lt).subarray(8,12);const d=t-c,f=e-u,g=Math.hypot(d,f);if(g<l(this,Cc))return!1;const p=g-l(this,Ac),v=p/g,_=v*d,b=v*f;let x=a,C=h;a=c,h=u,c+=_,u+=b,(R=l(this,br))==null||R.push(t,e);const A=-b/p,P=_/p,D=A*l(this,ch),k=P*l(this,ch);return l(this,lt).set(l(this,lt).subarray(2,8),0),l(this,lt).set([c+D,u+k],4),l(this,lt).set(l(this,lt).subarray(14,18),12),l(this,lt).set([c-D,u-k],16),isNaN(l(this,lt)[6])?(l(this,ji).length===0&&(l(this,lt).set([a+D,h+k],2),l(this,ji).push(NaN,NaN,NaN,NaN,(a+D-s)/n,(h+k-i)/r),l(this,lt).set([a-D,h-k],14),l(this,di).push(NaN,NaN,NaN,NaN,(a-D-s)/n,(h-k-i)/r)),l(this,lt).set([x,C,a,h,c,u],6),!this.isEmpty()):(l(this,lt).set([x,C,a,h,c,u],6),Math.abs(Math.atan2(C-h,x-a)-Math.atan2(b,_))<Math.PI/2?([a,h,c,u]=l(this,lt).subarray(2,6),l(this,ji).push(NaN,NaN,NaN,NaN,((a+c)/2-s)/n,((h+u)/2-i)/r),[a,h,x,C]=l(this,lt).subarray(14,18),l(this,di).push(NaN,NaN,NaN,NaN,((x+a)/2-s)/n,((C+h)/2-i)/r),!0):([x,C,a,h,c,u]=l(this,lt).subarray(0,6),l(this,ji).push(((x+5*a)/6-s)/n,((C+5*h)/6-i)/r,((5*a+c)/6-s)/n,((5*h+u)/6-i)/r,((a+c)/2-s)/n,((h+u)/2-i)/r),[c,u,a,h,x,C]=l(this,lt).subarray(12,18),l(this,di).push(((x+5*a)/6-s)/n,((C+5*h)/6-i)/r,((5*a+c)/6-s)/n,((5*h+u)/6-i)/r,((a+c)/2-s)/n,((h+u)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";const t=l(this,ji),e=l(this,di);if(isNaN(l(this,lt)[6])&&!this.isEmpty())return w(this,ce,Dy).call(this);const s=[];s.push(`M${t[4]} ${t[5]}`);for(let i=6;i<t.length;i+=6)isNaN(t[i])?s.push(`L${t[i+4]} ${t[i+5]}`):s.push(`C${t[i]} ${t[i+1]} ${t[i+2]} ${t[i+3]} ${t[i+4]} ${t[i+5]}`);w(this,ce,Ly).call(this,s);for(let i=e.length-6;i>=6;i-=6)isNaN(e[i])?s.push(`L${e[i+4]} ${e[i+5]}`):s.push(`C${e[i]} ${e[i+1]} ${e[i+2]} ${e[i+3]} ${e[i+4]} ${e[i+5]}`);return w(this,ce,Ry).call(this,s),s.join(" ")}newFreeDrawOutline(t,e,s,i,n,r){return new gb(t,e,s,i,n,r)}getOutlines(){var d;const t=l(this,ji),e=l(this,di),s=l(this,lt),[i,n,r,a]=l(this,Ss),h=new Float32Array((((d=l(this,br))==null?void 0:d.length)??0)+2);for(let f=0,g=h.length-2;f<g;f+=2)h[f]=(l(this,br)[f]-i)/r,h[f+1]=(l(this,br)[f+1]-n)/a;if(h[h.length-2]=(l(this,Na)-i)/r,h[h.length-1]=(l(this,Ba)-n)/a,isNaN(s[6])&&!this.isEmpty())return w(this,ce,Fy).call(this,h);const c=new Float32Array(l(this,ji).length+24+l(this,di).length);let u=t.length;for(let f=0;f<u;f+=2){if(isNaN(t[f])){c[f]=c[f+1]=NaN;continue}c[f]=t[f],c[f+1]=t[f+1]}u=w(this,ce,jy).call(this,c,u);for(let f=e.length-6;f>=6;f-=6)for(let g=0;g<6;g+=2){if(isNaN(e[f+g])){c[u]=c[u+1]=NaN,u+=2;continue}c[u]=e[f+g],c[u+1]=e[f+g+1],u+=2}return w(this,ce,Iy).call(this,c,u),this.newFreeDrawOutline(c,h,l(this,Ss),l(this,lh),l(this,oh),l(this,hh))}};Ss=new WeakMap,di=new WeakMap,oh=new WeakMap,hh=new WeakMap,ji=new WeakMap,lt=new WeakMap,Na=new WeakMap,Ba=new WeakMap,Cc=new WeakMap,Ac=new WeakMap,lh=new WeakMap,ch=new WeakMap,br=new WeakMap,Tc=new WeakMap,Gd=new WeakMap,Vd=new WeakMap,ce=new WeakSet,Zc=function(){const t=l(this,lt).subarray(4,6),e=l(this,lt).subarray(16,18),[s,i,n,r]=l(this,Ss);return[(l(this,Na)+(t[0]-e[0])/2-s)/n,(l(this,Ba)+(t[1]-e[1])/2-i)/r,(l(this,Na)+(e[0]-t[0])/2-s)/n,(l(this,Ba)+(e[1]-t[1])/2-i)/r]},Dy=function(){const[t,e,s,i]=l(this,Ss),[n,r,a,h]=w(this,ce,Zc).call(this);return`M${(l(this,lt)[2]-t)/s} ${(l(this,lt)[3]-e)/i} L${(l(this,lt)[4]-t)/s} ${(l(this,lt)[5]-e)/i} L${n} ${r} L${a} ${h} L${(l(this,lt)[16]-t)/s} ${(l(this,lt)[17]-e)/i} L${(l(this,lt)[14]-t)/s} ${(l(this,lt)[15]-e)/i} Z`},Ry=function(t){const e=l(this,di);t.push(`L${e[4]} ${e[5]} Z`)},Ly=function(t){const[e,s,i,n]=l(this,Ss),r=l(this,lt).subarray(4,6),a=l(this,lt).subarray(16,18),[h,c,u,d]=w(this,ce,Zc).call(this);t.push(`L${(r[0]-e)/i} ${(r[1]-s)/n} L${h} ${c} L${u} ${d} L${(a[0]-e)/i} ${(a[1]-s)/n}`)},Fy=function(t){const e=l(this,lt),[s,i,n,r]=l(this,Ss),[a,h,c,u]=w(this,ce,Zc).call(this),d=new Float32Array(36);return d.set([NaN,NaN,NaN,NaN,(e[2]-s)/n,(e[3]-i)/r,NaN,NaN,NaN,NaN,(e[4]-s)/n,(e[5]-i)/r,NaN,NaN,NaN,NaN,a,h,NaN,NaN,NaN,NaN,c,u,NaN,NaN,NaN,NaN,(e[16]-s)/n,(e[17]-i)/r,NaN,NaN,NaN,NaN,(e[14]-s)/n,(e[15]-i)/r],0),this.newFreeDrawOutline(d,t,l(this,Ss),l(this,lh),l(this,oh),l(this,hh))},Iy=function(t,e){const s=l(this,di);return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6},jy=function(t,e){const s=l(this,lt).subarray(4,6),i=l(this,lt).subarray(16,18),[n,r,a,h]=l(this,Ss),[c,u,d,f]=w(this,ce,Zc).call(this);return t.set([NaN,NaN,NaN,NaN,(s[0]-n)/a,(s[1]-r)/h,NaN,NaN,NaN,NaN,c,u,NaN,NaN,NaN,NaN,d,f,NaN,NaN,NaN,NaN,(i[0]-n)/a,(i[1]-r)/h],e),e+=24},y(Pn,Tc,8),y(Pn,Gd,2),y(Pn,Vd,l(Pn,Tc)+l(Pn,Gd));let Sd=Pn;class gb extends X{constructor(e,s,i,n,r,a){super();y(this,Wd);y(this,uh);y(this,Ha,new Float32Array(4));y(this,Mn);y(this,Ec);y(this,Cs);y(this,kc);y(this,Jt);m(this,Jt,e),m(this,Cs,s),m(this,uh,i),m(this,kc,n),m(this,Mn,r),m(this,Ec,a),this.lastPoint=[NaN,NaN],w(this,Wd,Ny).call(this,a);const[h,c,u,d]=l(this,Ha);for(let f=0,g=e.length;f<g;f+=2)e[f]=(e[f]-h)/u,e[f+1]=(e[f+1]-c)/d;for(let f=0,g=s.length;f<g;f+=2)s[f]=(s[f]-h)/u,s[f+1]=(s[f+1]-c)/d}toSVGPath(){const e=[`M${l(this,Jt)[4]} ${l(this,Jt)[5]}`];for(let s=6,i=l(this,Jt).length;s<i;s+=6){if(isNaN(l(this,Jt)[s])){e.push(`L${l(this,Jt)[s+4]} ${l(this,Jt)[s+5]}`);continue}e.push(`C${l(this,Jt)[s]} ${l(this,Jt)[s+1]} ${l(this,Jt)[s+2]} ${l(this,Jt)[s+3]} ${l(this,Jt)[s+4]} ${l(this,Jt)[s+5]}`)}return e.push("Z"),e.join(" ")}serialize([e,s,i,n],r){const a=i-e,h=n-s;let c,u;switch(r){case 0:c=X._rescale(l(this,Jt),e,n,a,-h),u=X._rescale(l(this,Cs),e,n,a,-h);break;case 90:c=X._rescaleAndSwap(l(this,Jt),e,s,a,h),u=X._rescaleAndSwap(l(this,Cs),e,s,a,h);break;case 180:c=X._rescale(l(this,Jt),i,s,-a,h),u=X._rescale(l(this,Cs),i,s,-a,h);break;case 270:c=X._rescaleAndSwap(l(this,Jt),i,n,-a,-h),u=X._rescaleAndSwap(l(this,Cs),i,n,-a,-h);break}return{outline:Array.from(c),points:[Array.from(u)]}}get box(){return l(this,Ha)}newOutliner(e,s,i,n,r,a=0){return new Sd(e,s,i,n,r,a)}getNewOutline(e,s){const[i,n,r,a]=l(this,Ha),[h,c,u,d]=l(this,uh),f=r*u,g=a*d,p=i*u+h,v=n*d+c,_=this.newOutliner({x:l(this,Cs)[0]*f+p,y:l(this,Cs)[1]*g+v},l(this,uh),l(this,kc),e,l(this,Ec),s??l(this,Mn));for(let b=2;b<l(this,Cs).length;b+=2)_.add({x:l(this,Cs)[b]*f+p,y:l(this,Cs)[b+1]*g+v});return _.getOutlines()}}uh=new WeakMap,Ha=new WeakMap,Mn=new WeakMap,Ec=new WeakMap,Cs=new WeakMap,kc=new WeakMap,Jt=new WeakMap,Wd=new WeakSet,Ny=function(e){const s=l(this,Jt);let i=s[4],n=s[5],r=i,a=n,h=i,c=n,u=i,d=n;const f=e?Math.max:Math.min;for(let p=6,v=s.length;p<v;p+=6){if(isNaN(s[p]))r=Math.min(r,s[p+4]),a=Math.min(a,s[p+5]),h=Math.max(h,s[p+4]),c=Math.max(c,s[p+5]),d<s[p+5]?(u=s[p+4],d=s[p+5]):d===s[p+5]&&(u=f(u,s[p+4]));else{const _=q.bezierBoundingBox(i,n,...s.slice(p,p+6));r=Math.min(r,_[0]),a=Math.min(a,_[1]),h=Math.max(h,_[2]),c=Math.max(c,_[3]),d<_[3]?(u=_[2],d=_[3]):d===_[3]&&(u=f(u,_[2]))}i=s[p+4],n=s[p+5]}const g=l(this,Ha);g[0]=r-l(this,Mn),g[1]=a-l(this,Mn),g[2]=h-r+2*l(this,Mn),g[3]=c-a+2*l(this,Mn),this.lastPoint=[u,d]};class sp{constructor(t,e=0,s=0,i=!0){y(this,Ye);y(this,Pc);y(this,Mc);y(this,yr,[]);y(this,fi,[]);let n=1/0,r=-1/0,a=1/0,h=-1/0;const c=10**-4;for(const{x:_,y:b,width:x,height:C}of t){const A=Math.floor((_-e)/c)*c,P=Math.ceil((_+x+e)/c)*c,D=Math.floor((b-e)/c)*c,k=Math.ceil((b+C+e)/c)*c,M=[A,D,k,!0],R=[P,D,k,!1];l(this,yr).push(M,R),n=Math.min(n,A),r=Math.max(r,P),a=Math.min(a,D),h=Math.max(h,k)}const u=r-n+2*s,d=h-a+2*s,f=n-s,g=a-s,p=l(this,yr).at(i?-1:-2),v=[p[0],p[2]];for(const _ of l(this,yr)){const[b,x,C]=_;_[0]=(b-f)/u,_[1]=(x-g)/d,_[2]=(C-g)/d}m(this,Pc,new Float32Array([f,g,u,d])),m(this,Mc,v)}getOutlines(){l(this,yr).sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);const t=[];for(const e of l(this,yr))e[3]?(t.push(...w(this,Ye,tm).call(this,e)),w(this,Ye,Hy).call(this,e)):(w(this,Ye,Gy).call(this,e),t.push(...w(this,Ye,tm).call(this,e)));return w(this,Ye,By).call(this,t)}}Pc=new WeakMap,Mc=new WeakMap,yr=new WeakMap,fi=new WeakMap,Ye=new WeakSet,By=function(t){const e=[],s=new Set;for(const r of t){const[a,h,c]=r;e.push([a,h,r],[a,c,r])}e.sort((r,a)=>r[1]-a[1]||r[0]-a[0]);for(let r=0,a=e.length;r<a;r+=2){const h=e[r][2],c=e[r+1][2];h.push(c),c.push(h),s.add(h),s.add(c)}const i=[];let n;for(;s.size>0;){const r=s.values().next().value;let[a,h,c,u,d]=r;s.delete(r);let f=a,g=h;for(n=[a,c],i.push(n);;){let p;if(s.has(u))p=u;else if(s.has(d))p=d;else break;s.delete(p),[a,h,c,u,d]=p,f!==a&&(n.push(f,g,a,g===h?h:c),f=a),g=g===h?c:h}n.push(f,g)}return new DC(i,l(this,Pc),l(this,Mc))},mf=function(t){const e=l(this,fi);let s=0,i=e.length-1;for(;s<=i;){const n=s+i>>1,r=e[n][0];if(r===t)return n;r<t?s=n+1:i=n-1}return i+1},Hy=function([,t,e]){const s=w(this,Ye,mf).call(this,t);l(this,fi).splice(s,0,[t,e])},Gy=function([,t,e]){const s=w(this,Ye,mf).call(this,t);for(let i=s;i<l(this,fi).length;i++){const[n,r]=l(this,fi)[i];if(n!==t)break;if(n===t&&r===e){l(this,fi).splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=l(this,fi)[i];if(n!==t)break;if(n===t&&r===e){l(this,fi).splice(i,1);return}}},tm=function(t){const[e,s,i]=t,n=[[e,s,i]],r=w(this,Ye,mf).call(this,i);for(let a=0;a<r;a++){const[h,c]=l(this,fi)[a];for(let u=0,d=n.length;u<d;u++){const[,f,g]=n[u];if(!(c<=f||g<=h)){if(f>=h){if(g>c)n[u][1]=c;else{if(d===1)return[];n.splice(u,1),u--,d--}continue}n[u][2]=h,g>c&&n.push([e,c,g])}}}return n};class DC extends X{constructor(e,s,i){super();y(this,Oc);y(this,dh);m(this,dh,e),m(this,Oc,s),this.lastPoint=i}toSVGPath(){const e=[];for(const s of l(this,dh)){let[i,n]=s;e.push(`M${i} ${n}`);for(let r=2;r<s.length;r+=2){const a=s[r],h=s[r+1];a===i?(e.push(`V${h}`),n=h):h===n&&(e.push(`H${a}`),i=a)}e.push("Z")}return e.join(" ")}serialize([e,s,i,n],r){const a=[],h=i-e,c=n-s;for(const u of l(this,dh)){const d=new Array(u.length);for(let f=0;f<u.length;f+=2)d[f]=e+u[f]*h,d[f+1]=n-u[f+1]*c;a.push(d)}return a}get box(){return l(this,Oc)}get classNamesForOutlining(){return["highlightOutline"]}}Oc=new WeakMap,dh=new WeakMap;class ip extends Sd{newFreeDrawOutline(t,e,s,i,n,r){return new RC(t,e,s,i,n,r)}}class RC extends gb{newOutliner(t,e,s,i,n,r=0){return new ip(t,e,s,i,n,r)}}const hs=class hs{constructor({editor:t=null,uiManager:e=null}){y(this,At);y(this,gi,null);y(this,Ga,null);y(this,fh);y(this,ue,null);y(this,Dc,!1);y(this,gh,!1);y(this,Rc,null);y(this,Lc);y(this,_r,null);y(this,pi,null);y(this,ph);var s;t?(m(this,gh,!1),m(this,ph,dt.HIGHLIGHT_COLOR),m(this,Rc,t)):(m(this,gh,!0),m(this,ph,dt.HIGHLIGHT_DEFAULT_COLOR)),m(this,pi,(t==null?void 0:t._uiManager)||e),m(this,Lc,l(this,pi)._eventBus),m(this,fh,(t==null?void 0:t.color)||((s=l(this,pi))==null?void 0:s.highlightColors.values().next().value)||"#FFFF98"),l(hs,Fc)||m(hs,Fc,Object.freeze({blue:"pdfjs-editor-colorpicker-blue",green:"pdfjs-editor-colorpicker-green",pink:"pdfjs-editor-colorpicker-pink",red:"pdfjs-editor-colorpicker-red",yellow:"pdfjs-editor-colorpicker-yellow"}))}static get _keyboardManager(){return ht(this,"_keyboardManager",new ll([[["Escape","mac+Escape"],hs.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],hs.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],hs.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],hs.prototype._moveToPrevious],[["Home","mac+Home"],hs.prototype._moveToBeginning],[["End","mac+End"],hs.prototype._moveToEnd]]))}renderButton(){const t=m(this,gi,document.createElement("button"));t.className="colorPicker",t.tabIndex="0",t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-button"),t.setAttribute("aria-haspopup",!0);const e=l(this,pi)._signal;t.addEventListener("click",w(this,At,io).bind(this),{signal:e}),t.addEventListener("keydown",w(this,At,im).bind(this),{signal:e});const s=m(this,Ga,document.createElement("span"));return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=l(this,fh),t.append(s),t}renderMainDropdown(){const t=m(this,ue,w(this,At,em).call(this));return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}_colorSelectFromKeyboard(t){if(t.target===l(this,gi)){w(this,At,io).call(this,t);return}const e=t.target.getAttribute("data-color");e&&w(this,At,sm).call(this,e,t)}_moveToNext(t){var e,s;if(!l(this,At,Pr)){w(this,At,io).call(this,t);return}if(t.target===l(this,gi)){(e=l(this,ue).firstChild)==null||e.focus();return}(s=t.target.nextSibling)==null||s.focus()}_moveToPrevious(t){var e,s;if(t.target===((e=l(this,ue))==null?void 0:e.firstChild)||t.target===l(this,gi)){l(this,At,Pr)&&this._hideDropdownFromKeyboard();return}l(this,At,Pr)||w(this,At,io).call(this,t),(s=t.target.previousSibling)==null||s.focus()}_moveToBeginning(t){var e;if(!l(this,At,Pr)){w(this,At,io).call(this,t);return}(e=l(this,ue).firstChild)==null||e.focus()}_moveToEnd(t){var e;if(!l(this,At,Pr)){w(this,At,io).call(this,t);return}(e=l(this,ue).lastChild)==null||e.focus()}hideDropdown(){var t,e;(t=l(this,ue))==null||t.classList.add("hidden"),(e=l(this,_r))==null||e.abort(),m(this,_r,null)}_hideDropdownFromKeyboard(){var t;if(!l(this,gh)){if(!l(this,At,Pr)){(t=l(this,Rc))==null||t.unselect();return}this.hideDropdown(),l(this,gi).focus({preventScroll:!0,focusVisible:l(this,Dc)})}}updateColor(t){if(l(this,Ga)&&(l(this,Ga).style.backgroundColor=t),!l(this,ue))return;const e=l(this,pi).highlightColors.values();for(const s of l(this,ue).children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){var t,e;(t=l(this,gi))==null||t.remove(),m(this,gi,null),m(this,Ga,null),(e=l(this,ue))==null||e.remove(),m(this,ue,null)}};gi=new WeakMap,Ga=new WeakMap,fh=new WeakMap,ue=new WeakMap,Dc=new WeakMap,gh=new WeakMap,Rc=new WeakMap,Lc=new WeakMap,_r=new WeakMap,pi=new WeakMap,ph=new WeakMap,Fc=new WeakMap,At=new WeakSet,em=function(){const t=document.createElement("div"),e=l(this,pi)._signal;t.addEventListener("contextmenu",ii,{signal:e}),t.className="dropdown",t.role="listbox",t.setAttribute("aria-multiselectable",!1),t.setAttribute("aria-orientation","vertical"),t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown");for(const[s,i]of l(this,pi).highlightColors){const n=document.createElement("button");n.tabIndex="0",n.role="option",n.setAttribute("data-color",i),n.title=s,n.setAttribute("data-l10n-id",l(hs,Fc)[s]);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===l(this,fh)),n.addEventListener("click",w(this,At,sm).bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",w(this,At,im).bind(this),{signal:e}),t},sm=function(t,e){e.stopPropagation(),l(this,Lc).dispatch("switchannotationeditorparams",{source:this,type:l(this,ph),value:t})},im=function(t){hs._keyboardManager.exec(this,t)},io=function(t){if(l(this,At,Pr)){this.hideDropdown();return}if(m(this,Dc,t.detail===0),l(this,_r)||(m(this,_r,new AbortController),window.addEventListener("pointerdown",w(this,At,Vy).bind(this),{signal:l(this,pi).combinedSignal(l(this,_r))})),l(this,ue)){l(this,ue).classList.remove("hidden");return}const e=m(this,ue,w(this,At,em).call(this));l(this,gi).append(e)},Vy=function(t){var e;(e=l(this,ue))!=null&&e.contains(t.target)||this.hideDropdown()},Pr=function(){return l(this,ue)&&!l(this,ue).classList.contains("hidden")},y(hs,Fc,null);let Cd=hs;const bt=class bt extends Ht{constructor(e){super({...e,name:"highlightEditor"});y(this,st);y(this,mh,null);y(this,Ic,0);y(this,On);y(this,Va,null);y(this,vh,null);y(this,ls,null);y(this,jc,null);y(this,Nc,0);y(this,Wa,null);y(this,Hs,null);y(this,As,null);y(this,_e,!1);y(this,bh,null);y(this,Dn);y(this,Le,null);y(this,yh,"");y(this,Gs);y(this,Bc,"");this.color=e.color||bt._defaultColor,m(this,Gs,e.thickness||bt._defaultThickness),m(this,Dn,e.opacity||bt._defaultOpacity),m(this,On,e.boxes||null),m(this,Bc,e.methodOfCreation||""),m(this,yh,e.text||""),this._isDraggable=!1,e.highlightId>-1?(m(this,_e,!0),w(this,st,vf).call(this,e),w(this,st,no).call(this)):l(this,On)&&(m(this,mh,e.anchorNode),m(this,Ic,e.anchorOffset),m(this,jc,e.focusNode),m(this,Nc,e.focusOffset),w(this,st,nm).call(this),w(this,st,no).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const e=bt.prototype;return ht(this,"_keyboardManager",new ll([[["ArrowLeft","mac+ArrowLeft"],e._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],e._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],e._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],e._moveCaret,{args:[3]}]]))}get telemetryInitialData(){return{action:"added",type:l(this,_e)?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:l(this,Gs),methodOfCreation:l(this,Bc)}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.highlightColorNames.get(this.color)}}static computeTelemetryFinalData(e){return{numberOfColors:e.get("color").size}}static initialize(e,s){var i;Ht.initialize(e,s),bt._defaultColor||(bt._defaultColor=((i=s.highlightColors)==null?void 0:i.values().next().value)||"#fff066")}static updateDefaultParams(e,s){switch(e){case dt.HIGHLIGHT_DEFAULT_COLOR:bt._defaultColor=s;break;case dt.HIGHLIGHT_THICKNESS:bt._defaultThickness=s;break}}translateInPage(e,s){}get toolbarPosition(){return l(this,bh)}updateParams(e,s){switch(e){case dt.HIGHLIGHT_COLOR:w(this,st,Wy).call(this,s);break;case dt.HIGHLIGHT_THICKNESS:w(this,st,zy).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[dt.HIGHLIGHT_DEFAULT_COLOR,bt._defaultColor],[dt.HIGHLIGHT_THICKNESS,bt._defaultThickness]]}get propertiesToUpdate(){return[[dt.HIGHLIGHT_COLOR,this.color||bt._defaultColor],[dt.HIGHLIGHT_THICKNESS,l(this,Gs)||bt._defaultThickness],[dt.HIGHLIGHT_FREE,l(this,_e)]]}async addEditToolbar(){const e=await super.addEditToolbar();return e?(this._uiManager.highlightColors&&(m(this,vh,new Cd({editor:this})),e.addColorPicker(l(this,vh))),e):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(w(this,st,tu).call(this))}getBaseTranslation(){return[0,0]}getRect(e,s){return super.getRect(e,s,w(this,st,tu).call(this))}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),e&&this.div.focus()}remove(){w(this,st,rm).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,st,no).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?w(this,st,rm).call(this):e&&(w(this,st,no).call(this,e),s=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),this.show(this._isVisible),s&&this.select()}rotate(e){var n,r,a;const{drawLayer:s}=this.parent;let i;l(this,_e)?(e=(e-this.rotation+360)%360,i=w(n=bt,Vs,Nh).call(n,l(this,Hs).box,e)):i=w(r=bt,Vs,Nh).call(r,[this.x,this.y,this.width,this.height],e),s.updateProperties(l(this,As),{bbox:i,root:{"data-main-rotation":e}}),s.updateProperties(l(this,Le),{bbox:w(a=bt,Vs,Nh).call(a,l(this,ls).box,e),root:{"data-main-rotation":e}})}render(){if(this.div)return this.div;const e=super.render();l(this,yh)&&(e.setAttribute("aria-label",l(this,yh)),e.setAttribute("role","mark")),l(this,_e)?e.classList.add("free"):this.div.addEventListener("keydown",w(this,st,Uy).bind(this),{signal:this._uiManager._signal});const s=m(this,Wa,document.createElement("div"));e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",s.style.clipPath=l(this,Va);const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),gd(this,l(this,Wa),["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Le),{rootClass:{hovered:!0}})}pointerleave(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Le),{rootClass:{hovered:!1}})}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:w(this,st,bf).call(this,!0);break;case 1:case 3:w(this,st,bf).call(this,!1);break}}select(){var e;super.select(),l(this,Le)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Le),{rootClass:{hovered:!1,selected:!0}}))}unselect(){var e;super.unselect(),l(this,Le)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Le),{rootClass:{selected:!1}}),l(this,_e)||w(this,st,bf).call(this,!1))}get _mustFixPosition(){return!l(this,_e)}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.updateProperties(l(this,As),{rootClass:{hidden:!e}}),this.parent.drawLayer.updateProperties(l(this,Le),{rootClass:{hidden:!e}}))}static startHighlighting(e,s,{target:i,x:n,y:r}){const{x:a,y:h,width:c,height:u}=i.getBoundingClientRect(),d=new AbortController,f=e.combinedSignal(d),g=p=>{d.abort(),w(this,Vs,Ky).call(this,e,p)};window.addEventListener("blur",g,{signal:f}),window.addEventListener("pointerup",g,{signal:f}),window.addEventListener("pointerdown",gs,{capture:!0,passive:!1,signal:f}),window.addEventListener("contextmenu",ii,{signal:f}),i.addEventListener("pointermove",w(this,Vs,qy).bind(this,e),{signal:f}),this._freeHighlight=new ip({x:n,y:r},[a,h,c,u],e.scale,this._defaultThickness/2,s,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0)}static async deserialize(e,s,i){var v,_,b,x;let n=null;if(e instanceof db){const{data:{quadPoints:C,rect:A,rotation:P,id:D,color:k,opacity:M,popupRef:R},parent:{page:{pageNumber:F}}}=e;n=e={annotationType:nt.HIGHLIGHT,color:Array.from(k),opacity:M,quadPoints:C,boxes:null,pageIndex:F-1,rect:A.slice(0),rotation:P,id:D,deleted:!1,popupRef:R}}else if(e instanceof tp){const{data:{inkLists:C,rect:A,rotation:P,id:D,color:k,borderStyle:{rawWidth:M},popupRef:R},parent:{page:{pageNumber:F}}}=e;n=e={annotationType:nt.HIGHLIGHT,color:Array.from(k),thickness:M,inkLists:C,boxes:null,pageIndex:F-1,rect:A.slice(0),rotation:P,id:D,deleted:!1,popupRef:R}}const{color:r,quadPoints:a,inkLists:h,opacity:c}=e,u=await super.deserialize(e,s,i);u.color=q.makeHexColor(...r),m(u,Dn,c||1),h&&m(u,Gs,e.thickness),u.annotationElementId=e.id||null,u._initialData=n;const[d,f]=u.pageDimensions,[g,p]=u.pageTranslation;if(a){const C=m(u,On,[]);for(let A=0;A<a.length;A+=8)C.push({x:(a[A]-g)/d,y:1-(a[A+1]-p)/f,width:(a[A+2]-a[A])/d,height:(a[A+1]-a[A+5])/f});w(v=u,st,nm).call(v),w(_=u,st,no).call(_),u.rotate(u.rotation)}else if(h){m(u,_e,!0);const C=h[0],A={x:C[0]-g,y:f-(C[1]-p)},P=new ip(A,[0,0,d,f],1,l(u,Gs)/2,!0,.001);for(let M=0,R=C.length;M<R;M+=2)A.x=C[M]-g,A.y=f-(C[M+1]-p),P.add(A);const{id:D,clipPathId:k}=s.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:u.color,"fill-opacity":u._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:P.toSVGPath()}},!0,!0);w(b=u,st,vf).call(b,{highlightOutlines:P.getOutlines(),highlightId:D,clipPathId:k}),w(x=u,st,no).call(x)}return u}serialize(e=!1){if(this.isEmpty()||e)return null;if(this.deleted)return this.serializeDeleted();const s=this.getRect(0,0),i=Ht._colorManager.convert(this.color),n={annotationType:nt.HIGHLIGHT,color:i,opacity:l(this,Dn),thickness:l(this,Gs),quadPoints:w(this,st,Yy).call(this),outlines:w(this,st,$y).call(this,s),pageIndex:this.pageIndex,rect:s,rotation:w(this,st,tu).call(this),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!w(this,st,Jy).call(this,n)?null:(n.id=this.annotationElementId,n)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};mh=new WeakMap,Ic=new WeakMap,On=new WeakMap,Va=new WeakMap,vh=new WeakMap,ls=new WeakMap,jc=new WeakMap,Nc=new WeakMap,Wa=new WeakMap,Hs=new WeakMap,As=new WeakMap,_e=new WeakMap,bh=new WeakMap,Dn=new WeakMap,Le=new WeakMap,yh=new WeakMap,Gs=new WeakMap,Bc=new WeakMap,st=new WeakSet,nm=function(){const e=new sp(l(this,On),.001);m(this,Hs,e.getOutlines()),[this.x,this.y,this.width,this.height]=l(this,Hs).box;const s=new sp(l(this,On),.0025,.001,this._uiManager.direction==="ltr");m(this,ls,s.getOutlines());const{lastPoint:i}=l(this,ls);m(this,bh,[(i[0]-this.x)/this.width,(i[1]-this.y)/this.height])},vf=function({highlightOutlines:e,highlightId:s,clipPathId:i}){var d,f;if(m(this,Hs,e),m(this,ls,e.getNewOutline(l(this,Gs)/2+1.5,.0025)),s>=0)m(this,As,s),m(this,Va,i),this.parent.drawLayer.finalizeDraw(s,{bbox:e.box,path:{d:e.toSVGPath()}}),m(this,Le,this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:l(this,ls).box,path:{d:l(this,ls).toSVGPath()}},!0));else if(this.parent){const g=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(l(this,As),{bbox:w(d=bt,Vs,Nh).call(d,l(this,Hs).box,(g-this.rotation+360)%360),path:{d:e.toSVGPath()}}),this.parent.drawLayer.updateProperties(l(this,Le),{bbox:w(f=bt,Vs,Nh).call(f,l(this,ls).box,g),path:{d:l(this,ls).toSVGPath()}})}const[r,a,h,c]=e.box;switch(this.rotation){case 0:this.x=r,this.y=a,this.width=h,this.height=c;break;case 90:{const[g,p]=this.parentDimensions;this.x=a,this.y=1-r,this.width=h*p/g,this.height=c*g/p;break}case 180:this.x=1-r,this.y=1-a,this.width=h,this.height=c;break;case 270:{const[g,p]=this.parentDimensions;this.x=1-a,this.y=r,this.width=h*p/g,this.height=c*g/p;break}}const{lastPoint:u}=l(this,ls);m(this,bh,[(u[0]-r)/h,(u[1]-a)/c])},Wy=function(e){const s=(r,a)=>{var h,c;this.color=r,m(this,Dn,a),(h=this.parent)==null||h.drawLayer.updateProperties(l(this,As),{root:{fill:r,"fill-opacity":a}}),(c=l(this,vh))==null||c.updateColor(r)},i=this.color,n=l(this,Dn);this.addCommands({cmd:s.bind(this,e,bt._defaultOpacity),undo:s.bind(this,i,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:dt.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(e)},!0)},zy=function(e){const s=l(this,Gs),i=n=>{m(this,Gs,n),w(this,st,Xy).call(this,n)};this.addCommands({cmd:i.bind(this,e),undo:i.bind(this,s),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:dt.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)},Xy=function(e){if(!l(this,_e))return;w(this,st,vf).call(this,{highlightOutlines:l(this,Hs).getNewOutline(e/2)}),this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)},rm=function(){l(this,As)===null||!this.parent||(this.parent.drawLayer.remove(l(this,As)),m(this,As,null),this.parent.drawLayer.remove(l(this,Le)),m(this,Le,null))},no=function(e=this.parent){l(this,As)===null&&({id:Ze(this,As)._,clipPathId:Ze(this,Va)._}=e.drawLayer.draw({bbox:l(this,Hs).box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":l(this,Dn)},rootClass:{highlight:!0,free:l(this,_e)},path:{d:l(this,Hs).toSVGPath()}},!1,!0),m(this,Le,e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:l(this,_e)},bbox:l(this,ls).box,path:{d:l(this,ls).toSVGPath()}},l(this,_e))),l(this,Wa)&&(l(this,Wa).style.clipPath=l(this,Va)))},Vs=new WeakSet,Nh=function([e,s,i,n],r){switch(r){case 90:return[1-s-n,e,n,i];case 180:return[1-e-i,1-s-n,i,n];case 270:return[s,1-e-i,n,i]}return[e,s,i,n]},Uy=function(e){bt._keyboardManager.exec(this,e)},bf=function(e){if(!l(this,mh))return;const s=window.getSelection();e?s.setPosition(l(this,mh),l(this,Ic)):s.setPosition(l(this,jc),l(this,Nc))},tu=function(){return l(this,_e)?this.rotation:0},Yy=function(){if(l(this,_e))return null;const[e,s]=this.pageDimensions,[i,n]=this.pageTranslation,r=l(this,On),a=new Float32Array(r.length*8);let h=0;for(const{x:c,y:u,width:d,height:f}of r){const g=c*e+i,p=(1-u)*s+n;a[h]=a[h+4]=g,a[h+1]=a[h+3]=p,a[h+2]=a[h+6]=g+d*e,a[h+5]=a[h+7]=p-f*s,h+=8}return a},$y=function(e){return l(this,Hs).serialize(e,w(this,st,tu).call(this))},qy=function(e,s){this._freeHighlight.add(s)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})},Ky=function(e,s){this._freeHighlight.isEmpty()?e.drawLayer.remove(this._freeHighlightId):e.createAndAddNewEditor(s,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:"main_toolbar"}),this._freeHighlightId=-1,this._freeHighlight=null,this._freeHighlightClipId=""},Jy=function(e){const{color:s}=this._initialData;return e.color.some((i,n)=>i!==s[n])},y(bt,Vs),J(bt,"_defaultColor",null),J(bt,"_defaultOpacity",1),J(bt,"_defaultThickness",12),J(bt,"_type","highlight"),J(bt,"_editorType",nt.HIGHLIGHT),J(bt,"_freeHighlightId",-1),J(bt,"_freeHighlight",null),J(bt,"_freeHighlightClipId","");let Ad=bt;class LC{constructor(){y(this,za,Object.create(null))}updateProperty(t,e){this[t]=e,this.updateSVGProperty(t,e)}updateProperties(t){if(t)for(const[e,s]of Object.entries(t))this.updateProperty(e,s)}updateSVGProperty(t,e){l(this,za)[t]=e}toSVGProperties(){const t=l(this,za);return m(this,za,Object.create(null)),{root:t}}reset(){m(this,za,Object.create(null))}updateAll(t=this){this.updateProperties(t)}clone(){Et("Not implemented")}}za=new WeakMap;const U=class U extends Ht{constructor(e){super(e);y(this,mt);y(this,Ts,null);y(this,_h);J(this,"_drawId",null);m(this,_h,e.mustBeCommitted||!1),e.drawOutlines&&(w(this,mt,am).call(this,e),w(this,mt,eu).call(this))}static _mergeSVGProperties(e,s){const i=new Set(Object.keys(e));for(const[n,r]of Object.entries(s))i.has(n)?Object.assign(e[n],r):e[n]=r;return e}static getDefaultDrawingOptions(e){Et("Not implemented")}static get typesMap(){Et("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(e,s){const i=this.typesMap.get(e);i&&this._defaultDrawingOptions.updateProperty(i,s),this._currentParent&&(l(U,pe).updateProperty(i,s),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(e,s){const i=this.constructor.typesMap.get(e);i&&this._updateProperty(e,i,s)}static get defaultPropertiesToUpdate(){const e=[],s=this._defaultDrawingOptions;for(const[i,n]of this.typesMap)e.push([i,s[n]]);return e}get propertiesToUpdate(){const e=[],{_drawingOptions:s}=this;for(const[i,n]of this.constructor.typesMap)e.push([i,s[n]]);return e}_updateProperty(e,s,i){const n=this._drawingOptions,r=n[s],a=h=>{var u;n.updateProperty(s,h);const c=l(this,Ts).updateProperty(s,h);c&&w(this,mt,su).call(this,c),(u=this.parent)==null||u.drawLayer.updateProperties(this._drawId,n.toSVGProperties())};this.addCommands({cmd:a.bind(this,i),undo:a.bind(this,r),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:e,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,U._mergeSVGProperties(l(this,Ts).getPathResizingSVGProperties(w(this,mt,yf).call(this)),{bbox:w(this,mt,Bh).call(this)}))}_onResized(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,U._mergeSVGProperties(l(this,Ts).getPathResizedSVGProperties(w(this,mt,yf).call(this)),{bbox:w(this,mt,Bh).call(this)}))}_onTranslating(e,s){var i;(i=this.parent)==null||i.drawLayer.updateProperties(this._drawId,{bbox:w(this,mt,Bh).call(this,e,s)})}_onTranslated(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,U._mergeSVGProperties(l(this,Ts).getPathTranslatedSVGProperties(w(this,mt,yf).call(this),this.parentDimensions),{bbox:w(this,mt,Bh).call(this)}))}_onStartDragging(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}commit(){super.commit(),this.disableEditMode(),this.disableEditing()}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),this._isDraggable=!0,l(this,_h)&&(m(this,_h,!1),this.commit(),this.parent.setSelected(this),e&&this.isOnScreen&&this.div.focus())}remove(){w(this,mt,hm).call(this),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,mt,eu).call(this),w(this,mt,su).call(this,l(this,Ts).box),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?(this._uiManager.removeShouldRescale(this),w(this,mt,hm).call(this)):e&&(this._uiManager.addShouldRescale(this),w(this,mt,eu).call(this,e),s=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),s&&this.select()}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,U._mergeSVGProperties({bbox:w(this,mt,Bh).call(this)},l(this,Ts).updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&w(this,mt,su).call(this,l(this,Ts).updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;const e=super.render();e.classList.add("draw");const s=document.createElement("div");e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal";const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),this._uiManager.addShouldRescale(this),this.disableEditing(),e}static createDrawerInstance(e,s,i,n,r){Et("Not implemented")}static startDrawing(e,s,i,n){var _;const{target:r,offsetX:a,offsetY:h,pointerId:c,pointerType:u}=n;if(l(U,xr)&&l(U,xr)!==u)return;const{viewport:{rotation:d}}=e,{width:f,height:g}=r.getBoundingClientRect(),p=m(U,Xa,new AbortController),v=e.combinedSignal(p);if(l(U,wr)||m(U,wr,c),l(U,xr)??m(U,xr,u),window.addEventListener("pointerup",b=>{var x;l(U,wr)===b.pointerId?this._endDraw(b):(x=l(U,Sr))==null||x.delete(b.pointerId)},{signal:v}),window.addEventListener("pointercancel",b=>{var x;l(U,wr)===b.pointerId?this._currentParent.endDrawingSession():(x=l(U,Sr))==null||x.delete(b.pointerId)},{signal:v}),window.addEventListener("pointerdown",b=>{l(U,xr)===b.pointerType&&((l(U,Sr)||m(U,Sr,new Set)).add(b.pointerId),l(U,pe).isCancellable()&&(l(U,pe).removeLastElement(),l(U,pe).isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:v}),window.addEventListener("contextmenu",ii,{signal:v}),r.addEventListener("pointermove",this._drawMove.bind(this),{signal:v}),r.addEventListener("touchmove",b=>{b.timeStamp===l(U,Ya)&&gs(b)},{signal:v}),e.toggleDrawing(),(_=s._editorUndoBar)==null||_.hide(),l(U,pe)){e.drawLayer.updateProperties(this._currentDrawId,l(U,pe).startNew(a,h,f,g,d));return}s.updateUIForDefaultProperties(this),m(U,pe,this.createDrawerInstance(a,h,f,g,d)),m(U,Ua,this.getDefaultDrawingOptions()),this._currentParent=e,{id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties(l(U,Ua).toSVGProperties(),l(U,pe).defaultSVGProperties),!0,!1)}static _drawMove(e){var r;if(m(U,Ya,-1),!l(U,pe))return;const{offsetX:s,offsetY:i,pointerId:n}=e;if(l(U,wr)===n){if(((r=l(U,Sr))==null?void 0:r.size)>=1){this._endDraw(e);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,l(U,pe).add(s,i)),m(U,Ya,e.timeStamp),gs(e)}}static _cleanup(e){e&&(this._currentDrawId=-1,this._currentParent=null,m(U,pe,null),m(U,Ua,null),m(U,xr,null),m(U,Ya,NaN)),l(U,Xa)&&(l(U,Xa).abort(),m(U,Xa,null),m(U,wr,NaN),m(U,Sr,null))}static _endDraw(e){const s=this._currentParent;if(s){if(s.toggleDrawing(!0),this._cleanup(!1),e&&s.drawLayer.updateProperties(this._currentDrawId,l(U,pe).end(e.offsetX,e.offsetY)),this.supportMultipleDrawings){const i=l(U,pe),n=this._currentDrawId,r=i.getLastElement();s.addCommands({cmd:()=>{s.drawLayer.updateProperties(n,i.setLastElement(r))},undo:()=>{s.drawLayer.updateProperties(n,i.removeLastElement())},mustExec:!1,type:dt.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(e){const s=this._currentParent;if(!s)return null;if(s.toggleDrawing(!0),s.cleanUndoStack(dt.DRAW_STEP),!l(U,pe).isEmpty()){const{pageDimensions:[i,n],scale:r}=s,a=s.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:l(U,pe).getOutlines(i*r,n*r,r,this._INNER_MARGIN),drawingOptions:l(U,Ua),mustBeCommitted:!e});return this._cleanup(!0),a}return s.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(e){}static deserializeDraw(e,s,i,n,r,a){Et("Not implemented")}static async deserialize(e,s,i){var d,f;const{rawDims:{pageWidth:n,pageHeight:r,pageX:a,pageY:h}}=s.viewport,c=this.deserializeDraw(a,h,n,r,this._INNER_MARGIN,e),u=await super.deserialize(e,s,i);return u.createDrawingOptions(e),w(d=u,mt,am).call(d,{drawOutlines:c}),w(f=u,mt,eu).call(f),u.onScaleChanging(),u.rotate(),u}serializeDraw(e){const[s,i]=this.pageTranslation,[n,r]=this.pageDimensions;return l(this,Ts).serialize([s,i,n,r],e)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};Ts=new WeakMap,_h=new WeakMap,pe=new WeakMap,Xa=new WeakMap,Ua=new WeakMap,wr=new WeakMap,xr=new WeakMap,Sr=new WeakMap,Ya=new WeakMap,mt=new WeakSet,am=function({drawOutlines:e,drawId:s,drawingOptions:i}){m(this,Ts,e),this._drawingOptions||(this._drawingOptions=i),s>=0?(this._drawId=s,this.parent.drawLayer.finalizeDraw(s,e.defaultProperties)):this._drawId=w(this,mt,om).call(this,e,this.parent),w(this,mt,su).call(this,e.box)},om=function(e,s){const{id:i}=s.drawLayer.draw(U._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return i},hm=function(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())},eu=function(e=this.parent){if(!(this._drawId!==null&&this.parent===e)){if(this._drawId!==null){this.parent.drawLayer.updateParent(this._drawId,e.drawLayer);return}this._drawingOptions.updateAll(),this._drawId=w(this,mt,om).call(this,l(this,Ts),e)}},Qy=function([e,s,i,n]){const{parentDimensions:[r,a],rotation:h}=this;switch(h){case 90:return[s,1-e,i*(a/r),n*(r/a)];case 180:return[1-e,1-s,i,n];case 270:return[1-s,e,i*(a/r),n*(r/a)];default:return[e,s,i,n]}},yf=function(){const{x:e,y:s,width:i,height:n,parentDimensions:[r,a],rotation:h}=this;switch(h){case 90:return[1-s,e,i*(r/a),n*(a/r)];case 180:return[1-e,1-s,i,n];case 270:return[s,1-e,i*(r/a),n*(a/r)];default:return[e,s,i,n]}},su=function(e){if([this.x,this.y,this.width,this.height]=w(this,mt,Qy).call(this,e),this.div){this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)}this._onResized()},Bh=function(){const{x:e,y:s,width:i,height:n,rotation:r,parentRotation:a,parentDimensions:[h,c]}=this;switch((r*4+a)/90){case 1:return[1-s-n,e,n,i];case 2:return[1-e-i,1-s-n,i,n];case 3:return[s,1-e-i,n,i];case 4:return[e,s-i*(h/c),n*(c/h),i*(h/c)];case 5:return[1-s,e,i*(h/c),n*(c/h)];case 6:return[1-e-n*(c/h),1-s,n*(c/h),i*(h/c)];case 7:return[s-i*(h/c),1-e-n*(c/h),i*(h/c),n*(c/h)];case 8:return[e-i,s-n,i,n];case 9:return[1-s,e-i,n,i];case 10:return[1-e,1-s,i,n];case 11:return[s-n,1-e,n,i];case 12:return[e-n*(c/h),s,n*(c/h),i*(h/c)];case 13:return[1-s-i*(h/c),e-n*(c/h),i*(h/c),n*(c/h)];case 14:return[1-e,1-s-i*(h/c),n*(c/h),i*(h/c)];case 15:return[s,1-e,i*(h/c),n*(c/h)];default:return[e,s,i,n]}},J(U,"_currentDrawId",-1),J(U,"_currentParent",null),y(U,pe,null),y(U,Xa,null),y(U,Ua,null),y(U,wr,NaN),y(U,xr,null),y(U,Sr,null),y(U,Ya,NaN),J(U,"_INNER_MARGIN",3);let np=U;class FC{constructor(t,e,s,i,n,r){y(this,xh);y(this,Ni,new Float64Array(6));y(this,me);y(this,ve);y(this,$a);y(this,wh);y(this,$e);y(this,we,"");y(this,Ws,0);y(this,qa,new Td);y(this,Ka);y(this,Ja);m(this,Ka,s),m(this,Ja,i),m(this,$a,n),m(this,wh,r),[t,e]=w(this,xh,_f).call(this,t,e);const a=m(this,me,[NaN,NaN,NaN,NaN,t,e]);m(this,$e,[t,e]),m(this,ve,[{line:a,points:l(this,$e)}]),l(this,Ni).set(a,0)}updateProperty(t,e){t==="stroke-width"&&m(this,wh,e)}isEmpty(){return!l(this,ve)||l(this,ve).length===0}isCancellable(){return l(this,$e).length<=10}add(t,e){[t,e]=w(this,xh,_f).call(this,t,e);const[s,i,n,r]=l(this,Ni).subarray(2,6),a=t-n,h=e-r;return Math.hypot(l(this,Ka)*a,l(this,Ja)*h)<=2?null:(l(this,$e).push(t,e),isNaN(s)?(l(this,Ni).set([n,r,t,e],2),l(this,me).push(NaN,NaN,NaN,NaN,t,e),{path:{d:this.toSVGPath()}}):(isNaN(l(this,Ni)[0])&&l(this,me).splice(6,6),l(this,Ni).set([s,i,n,r,t,e],0),l(this,me).push(...X.createBezierPoints(s,i,n,r,t,e)),{path:{d:this.toSVGPath()}}))}end(t,e){const s=this.add(t,e);return s||(l(this,$e).length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,s,i,n){m(this,Ka,s),m(this,Ja,i),m(this,$a,n),[t,e]=w(this,xh,_f).call(this,t,e);const r=m(this,me,[NaN,NaN,NaN,NaN,t,e]);m(this,$e,[t,e]);const a=l(this,ve).at(-1);return a&&(a.line=new Float32Array(a.line),a.points=new Float32Array(a.points)),l(this,ve).push({line:r,points:l(this,$e)}),l(this,Ni).set(r,0),m(this,Ws,0),this.toSVGPath(),null}getLastElement(){return l(this,ve).at(-1)}setLastElement(t){return l(this,ve)?(l(this,ve).push(t),m(this,me,t.line),m(this,$e,t.points),m(this,Ws,0),{path:{d:this.toSVGPath()}}):l(this,qa).setLastElement(t)}removeLastElement(){if(!l(this,ve))return l(this,qa).removeLastElement();l(this,ve).pop(),m(this,we,"");for(let t=0,e=l(this,ve).length;t<e;t++){const{line:s,points:i}=l(this,ve)[t];m(this,me,s),m(this,$e,i),m(this,Ws,0),this.toSVGPath()}return{path:{d:l(this,we)}}}toSVGPath(){const t=X.svgRound(l(this,me)[4]),e=X.svgRound(l(this,me)[5]);if(l(this,$e).length===2)return m(this,we,`${l(this,we)} M ${t} ${e} Z`),l(this,we);if(l(this,$e).length<=6){const i=l(this,we).lastIndexOf("M");m(this,we,`${l(this,we).slice(0,i)} M ${t} ${e}`),m(this,Ws,6)}if(l(this,$e).length===4){const i=X.svgRound(l(this,me)[10]),n=X.svgRound(l(this,me)[11]);return m(this,we,`${l(this,we)} L ${i} ${n}`),m(this,Ws,12),l(this,we)}const s=[];l(this,Ws)===0&&(s.push(`M ${t} ${e}`),m(this,Ws,6));for(let i=l(this,Ws),n=l(this,me).length;i<n;i+=6){const[r,a,h,c,u,d]=l(this,me).slice(i,i+6).map(X.svgRound);s.push(`C${r} ${a} ${h} ${c} ${u} ${d}`)}return m(this,we,l(this,we)+s.join(" ")),m(this,Ws,l(this,me).length),l(this,we)}getOutlines(t,e,s,i){const n=l(this,ve).at(-1);return n.line=new Float32Array(n.line),n.points=new Float32Array(n.points),l(this,qa).build(l(this,ve),t,e,s,l(this,$a),l(this,wh),i),m(this,Ni,null),m(this,me,null),m(this,ve,null),m(this,we,null),l(this,qa)}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}Ni=new WeakMap,me=new WeakMap,ve=new WeakMap,$a=new WeakMap,wh=new WeakMap,$e=new WeakMap,we=new WeakMap,Ws=new WeakMap,qa=new WeakMap,Ka=new WeakMap,Ja=new WeakMap,xh=new WeakSet,_f=function(t,e){return X._normalizePoint(t,e,l(this,Ka),l(this,Ja),l(this,$a))};const gp=class gp extends X{constructor(){super(...arguments);y(this,xe);y(this,qe);y(this,Hc,0);y(this,Gc);y(this,Es);y(this,Bi);y(this,Hi);y(this,Sh);y(this,Ch);y(this,Ah)}build(e,s,i,n,r,a,h){m(this,Bi,s),m(this,Hi,i),m(this,Sh,n),m(this,Ch,r),m(this,Ah,a),m(this,Gc,h??0),m(this,Es,e),w(this,xe,t_).call(this)}setLastElement(e){return l(this,Es).push(e),{path:{d:this.toSVGPath()}}}removeLastElement(){return l(this,Es).pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const e=[];for(const{line:s}of l(this,Es)){if(e.push(`M${X.svgRound(s[4])} ${X.svgRound(s[5])}`),s.length===6){e.push("Z");continue}if(s.length===12){e.push(`L${X.svgRound(s[10])} ${X.svgRound(s[11])}`);continue}for(let i=6,n=s.length;i<n;i+=6){const[r,a,h,c,u,d]=s.subarray(i,i+6).map(X.svgRound);e.push(`C${r} ${a} ${h} ${c} ${u} ${d}`)}}return e.join("")}serialize([e,s,i,n],r){const a=[],h=[],[c,u,d,f]=w(this,xe,Zy).call(this);let g,p,v,_,b,x,C,A,P;switch(l(this,Ch)){case 0:P=X._rescale,g=e,p=s+n,v=i,_=-n,b=e+c*i,x=s+(1-u-f)*n,C=e+(c+d)*i,A=s+(1-u)*n;break;case 90:P=X._rescaleAndSwap,g=e,p=s,v=i,_=n,b=e+u*i,x=s+c*n,C=e+(u+f)*i,A=s+(c+d)*n;break;case 180:P=X._rescale,g=e+i,p=s,v=-i,_=n,b=e+(1-c-d)*i,x=s+u*n,C=e+(1-c)*i,A=s+(u+f)*n;break;case 270:P=X._rescaleAndSwap,g=e+i,p=s+n,v=-i,_=-n,b=e+(1-u-f)*i,x=s+(1-c-d)*n,C=e+(1-u)*i,A=s+(1-c)*n;break}for(const{line:D,points:k}of l(this,Es))a.push(P(D,g,p,v,_,r?new Array(D.length):null)),h.push(P(k,g,p,v,_,r?new Array(k.length):null));return{lines:a,points:h,rect:[b,x,C,A]}}static deserialize(e,s,i,n,r,{paths:{lines:a,points:h},rotation:c,thickness:u}){const d=[];let f,g,p,v,_;switch(c){case 0:_=X._rescale,f=-e/i,g=s/n+1,p=1/i,v=-1/n;break;case 90:_=X._rescaleAndSwap,f=-s/n,g=-e/i,p=1/n,v=1/i;break;case 180:_=X._rescale,f=e/i+1,g=-s/n,p=-1/i,v=1/n;break;case 270:_=X._rescaleAndSwap,f=s/n+1,g=e/i+1,p=-1/n,v=-1/i;break}if(!a){a=[];for(const x of h){const C=x.length;if(C===2){a.push(new Float32Array([NaN,NaN,NaN,NaN,x[0],x[1]]));continue}if(C===4){a.push(new Float32Array([NaN,NaN,NaN,NaN,x[0],x[1],NaN,NaN,NaN,NaN,x[2],x[3]]));continue}const A=new Float32Array(3*(C-2));a.push(A);let[P,D,k,M]=x.subarray(0,4);A.set([NaN,NaN,NaN,NaN,P,D],0);for(let R=4;R<C;R+=2){const F=x[R],I=x[R+1];A.set(X.createBezierPoints(P,D,k,M,F,I),(R-2)*3),[P,D,k,M]=[k,M,F,I]}}}for(let x=0,C=a.length;x<C;x++)d.push({line:_(a[x].map(A=>A??NaN),f,g,p,v),points:_(h[x].map(A=>A??NaN),f,g,p,v)});const b=new gp;return b.build(d,i,n,1,c,u,r),b}get box(){return l(this,qe)}updateProperty(e,s){return e==="stroke-width"?w(this,xe,e_).call(this,s):null}updateParentDimensions([e,s],i){const[n,r]=w(this,xe,Nn).call(this);m(this,Bi,e),m(this,Hi,s),m(this,Sh,i);const[a,h]=w(this,xe,Nn).call(this),c=a-n,u=h-r,d=l(this,qe);return d[0]-=c,d[1]-=u,d[2]+=2*c,d[3]+=2*u,d}updateRotation(e){return m(this,Hc,e),{path:{transform:this.rotationTransform}}}get viewBox(){return l(this,qe).map(X.svgRound).join(" ")}get defaultProperties(){const[e,s]=l(this,qe);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${X.svgRound(e)} ${X.svgRound(s)}`}}}get rotationTransform(){const[,,e,s]=l(this,qe);let i=0,n=0,r=0,a=0,h=0,c=0;switch(l(this,Hc)){case 90:n=s/e,r=-e/s,h=e;break;case 180:i=-1,a=-1,h=e,c=s;break;case 270:n=-s/e,r=e/s,c=s;break;default:return""}return`matrix(${i} ${n} ${r} ${a} ${X.svgRound(h)} ${X.svgRound(c)})`}getPathResizingSVGProperties([e,s,i,n]){const[r,a]=w(this,xe,Nn).call(this),[h,c,u,d]=l(this,qe);if(Math.abs(u-r)<=X.PRECISION||Math.abs(d-a)<=X.PRECISION){const _=e+i/2-(h+u/2),b=s+n/2-(c+d/2);return{path:{"transform-origin":`${X.svgRound(e)} ${X.svgRound(s)}`,transform:`${this.rotationTransform} translate(${_} ${b})`}}}const f=(i-2*r)/(u-2*r),g=(n-2*a)/(d-2*a),p=u/i,v=d/n;return{path:{"transform-origin":`${X.svgRound(h)} ${X.svgRound(c)}`,transform:`${this.rotationTransform} scale(${p} ${v}) translate(${X.svgRound(r)} ${X.svgRound(a)}) scale(${f} ${g}) translate(${X.svgRound(-r)} ${X.svgRound(-a)})`}}}getPathResizedSVGProperties([e,s,i,n]){const[r,a]=w(this,xe,Nn).call(this),h=l(this,qe),[c,u,d,f]=h;if(h[0]=e,h[1]=s,h[2]=i,h[3]=n,Math.abs(d-r)<=X.PRECISION||Math.abs(f-a)<=X.PRECISION){const b=e+i/2-(c+d/2),x=s+n/2-(u+f/2);for(const{line:C,points:A}of l(this,Es))X._translate(C,b,x,C),X._translate(A,b,x,A);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${X.svgRound(e)} ${X.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const g=(i-2*r)/(d-2*r),p=(n-2*a)/(f-2*a),v=-g*(c+r)+e+r,_=-p*(u+a)+s+a;if(g!==1||p!==1||v!==0||_!==0)for(const{line:b,points:x}of l(this,Es))X._rescale(b,v,_,g,p,b),X._rescale(x,v,_,g,p,x);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${X.svgRound(e)} ${X.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,s],i){const[n,r]=i,a=l(this,qe),h=e-a[0],c=s-a[1];if(l(this,Bi)===n&&l(this,Hi)===r)for(const{line:u,points:d}of l(this,Es))X._translate(u,h,c,u),X._translate(d,h,c,d);else{const u=l(this,Bi)/n,d=l(this,Hi)/r;m(this,Bi,n),m(this,Hi,r);for(const{line:f,points:g}of l(this,Es))X._rescale(f,h,c,u,d,f),X._rescale(g,h,c,u,d,g);a[2]*=u,a[3]*=d}return a[0]=e,a[1]=s,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${X.svgRound(e)} ${X.svgRound(s)}`}}}get defaultSVGProperties(){const e=l(this,qe);return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${X.svgRound(e[0])} ${X.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}};qe=new WeakMap,Hc=new WeakMap,Gc=new WeakMap,Es=new WeakMap,Bi=new WeakMap,Hi=new WeakMap,Sh=new WeakMap,Ch=new WeakMap,Ah=new WeakMap,xe=new WeakSet,Nn=function(e=l(this,Ah)){const s=l(this,Gc)+e/2*l(this,Sh);return l(this,Ch)%180===0?[s/l(this,Bi),s/l(this,Hi)]:[s/l(this,Hi),s/l(this,Bi)]},Zy=function(){const[e,s,i,n]=l(this,qe),[r,a]=w(this,xe,Nn).call(this,0);return[e+r,s+a,i-2*r,n-2*a]},t_=function(){const e=m(this,qe,new Float32Array([1/0,1/0,-1/0,-1/0]));for(const{line:n}of l(this,Es)){if(n.length<=12){for(let h=4,c=n.length;h<c;h+=6){const[u,d]=n.subarray(h,h+2);e[0]=Math.min(e[0],u),e[1]=Math.min(e[1],d),e[2]=Math.max(e[2],u),e[3]=Math.max(e[3],d)}continue}let r=n[4],a=n[5];for(let h=6,c=n.length;h<c;h+=6){const[u,d,f,g,p,v]=n.subarray(h,h+6);q.bezierBoundingBox(r,a,u,d,f,g,p,v,e),r=p,a=v}}const[s,i]=w(this,xe,Nn).call(this);e[0]=Math.min(1,Math.max(0,e[0]-s)),e[1]=Math.min(1,Math.max(0,e[1]-i)),e[2]=Math.min(1,Math.max(0,e[2]+s)),e[3]=Math.min(1,Math.max(0,e[3]+i)),e[2]-=e[0],e[3]-=e[1]},e_=function(e){const[s,i]=w(this,xe,Nn).call(this);m(this,Ah,e);const[n,r]=w(this,xe,Nn).call(this),[a,h]=[n-s,r-i],c=l(this,qe);return c[0]-=a,c[1]-=h,c[2]+=2*a,c[3]+=2*h,c};let Td=gp;const pp=class pp extends LC{constructor(e){super();y(this,Th);m(this,Th,e),super.updateProperties({fill:"none",stroke:Ht._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(e,s){e==="stroke-width"&&(s??(s=this["stroke-width"]),s*=l(this,Th).realScale),super.updateSVGProperty(e,s)}clone(){const e=new pp(l(this,Th));return e.updateAll(this),e}};Th=new WeakMap;let rp=pp;const Eh=class Eh extends np{constructor(e){super({...e,name:"inkEditor"});y(this,zd);this._willKeepAspectRatio=!0}static initialize(e,s){Ht.initialize(e,s),this._defaultDrawingOptions=new rp(s.viewParameters)}static getDefaultDrawingOptions(e){const s=this._defaultDrawingOptions.clone();return s.updateProperties(e),s}static get supportMultipleDrawings(){return!0}static get typesMap(){return ht(this,"typesMap",new Map([[dt.INK_THICKNESS,"stroke-width"],[dt.INK_COLOR,"stroke"],[dt.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(e,s,i,n,r){return new FC(e,s,i,n,r,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(e,s,i,n,r,a){return Td.deserialize(e,s,i,n,r,a)}static async deserialize(e,s,i){let n=null;if(e instanceof tp){const{data:{inkLists:a,rect:h,rotation:c,id:u,color:d,opacity:f,borderStyle:{rawWidth:g},popupRef:p},parent:{page:{pageNumber:v}}}=e;n=e={annotationType:nt.INK,color:Array.from(d),thickness:g,opacity:f,paths:{points:a},boxes:null,pageIndex:v-1,rect:h.slice(0),rotation:c,id:u,deleted:!1,popupRef:p}}const r=await super.deserialize(e,s,i);return r.annotationElementId=e.id||null,r._initialData=n,r}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();const{_drawId:e,_drawingOptions:s,parent:i}=this;s.updateSVGProperty("stroke-width"),i.drawLayer.updateProperties(e,s.toSVGProperties())}static onScaleChangingWhenDrawing(){const e=this._currentParent;e&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),e.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:e,thickness:s,opacity:i}){this._drawingOptions=Eh.getDefaultDrawingOptions({stroke:q.makeHexColor(...e),"stroke-width":s,"stroke-opacity":i})}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:s,points:i,rect:n}=this.serializeDraw(e),{_drawingOptions:{stroke:r,"stroke-opacity":a,"stroke-width":h}}=this,c={annotationType:nt.INK,color:Ht._colorManager.convert(r),opacity:a,thickness:h,paths:{lines:s,points:i},pageIndex:this.pageIndex,rect:n,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?c:this.annotationElementId&&!w(this,zd,s_).call(this,c)?null:(c.id=this.annotationElementId,c)}renderAnnotationElement(e){const{points:s,rect:i}=this.serializeDraw(!1);return e.updateEdited({rect:i,thickness:this._drawingOptions["stroke-width"],points:s}),null}};zd=new WeakSet,s_=function(e){const{color:s,thickness:i,opacity:n,pageIndex:r}=this._initialData;return this._hasBeenMoved||this._hasBeenResized||e.color.some((a,h)=>a!==s[h])||e.thickness!==i||e.opacity!==n||e.pageIndex!==r},J(Eh,"_type","ink"),J(Eh,"_editorType",nt.INK),J(Eh,"_defaultDrawingOptions",null);let ap=Eh;const Vc=class Vc extends Ht{constructor(e){super({...e,name:"stampEditor"});y(this,vt);y(this,Vt,null);y(this,Se,null);y(this,Cr,null);y(this,Rn,null);y(this,Ar,null);y(this,kh,"");y(this,Gi,null);y(this,Vi,null);y(this,ks,!1);y(this,Ph,!1);m(this,Rn,e.bitmapUrl),m(this,Ar,e.bitmapFile)}static initialize(e,s){Ht.initialize(e,s)}static get supportedTypes(){return ht(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(s=>`image/${s}`))}static get supportedTypesStr(){return ht(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(e){return this.supportedTypes.includes(e)}static paste(e,s){s.pasteEditor(nt.STAMP,{bitmapFile:e.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){var e;return{type:"stamp",hasAltText:!!((e=this.altTextData)!=null&&e.altText)}}static computeTelemetryFinalData(e){const s=e.get("hasAltText");return{hasAltText:s.get(!0)??0,hasNoAltText:s.get(!1)??0}}async mlGuessAltText(e=null,s=!0){if(this.hasAltTextData())return null;const{mlManager:i}=this._uiManager;if(!i)throw new Error("No ML.");if(!await i.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:n,width:r,height:a}=e||this.copyCanvas(null,null,!0).imageData,h=await i.guess({name:"altText",request:{data:n,width:r,height:a,channels:n.length/(r*a)}});if(!h)throw new Error("No response from the AI service.");if(h.error)throw new Error("Error from the AI service.");if(h.cancel)return null;if(!h.output)throw new Error("No valid response from the AI service.");const c=h.output;return await this.setGuessedAltText(c),s&&!this.hasAltTextData()&&(this.altTextData={alt:c,decorative:!1}),c}remove(){var e;l(this,Se)&&(m(this,Vt,null),this._uiManager.imageManager.deleteId(l(this,Se)),(e=l(this,Gi))==null||e.remove(),m(this,Gi,null),l(this,Vi)&&(clearTimeout(l(this,Vi)),m(this,Vi,null))),super.remove()}rebuild(){if(!this.parent){l(this,Se)&&w(this,vt,wf).call(this);return}super.rebuild(),this.div!==null&&(l(this,Se)&&l(this,Gi)===null&&w(this,vt,wf).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(e){this._isDraggable=!0,e&&this.div.focus()}isEmpty(){return!(l(this,Cr)||l(this,Vt)||l(this,Rn)||l(this,Ar)||l(this,Se))}get isResizable(){return!0}render(){if(this.div)return this.div;let e,s;if(this.width&&(e=this.x,s=this.y),super.render(),this.div.hidden=!0,this.div.setAttribute("role","figure"),this.addAltTextButton(),l(this,Vt)?w(this,vt,lm).call(this):w(this,vt,wf).call(this),this.width&&!this.annotationElementId){const[i,n]=this.parentDimensions;this.setAt(e*i,s*n,this.width*i,this.height*n)}return this._uiManager.addShouldRescale(this),this.div}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;l(this,Vi)!==null&&clearTimeout(l(this,Vi)),m(this,Vi,setTimeout(()=>{m(this,Vi,null),w(this,vt,cm).call(this)},200))}copyCanvas(e,s,i=!1){var g;e||(e=224);const{width:n,height:r}=l(this,Vt),a=new Ng;let h=l(this,Vt),c=n,u=r,d=null;if(s){if(n>s||r>s){const M=Math.min(s/n,s/r);c=Math.floor(n*M),u=Math.floor(r*M)}d=document.createElement("canvas");const p=d.width=Math.ceil(c*a.sx),v=d.height=Math.ceil(u*a.sy);l(this,ks)||(h=w(this,vt,xf).call(this,p,v));const _=d.getContext("2d");_.filter=this._uiManager.hcmFilter;let b="white",x="#cfcfd8";this._uiManager.hcmFilter!=="none"?x="black":(g=window.matchMedia)!=null&&g.call(window,"(prefers-color-scheme: dark)").matches&&(b="#8f8f9d",x="#42414d");const C=15,A=C*a.sx,P=C*a.sy,D=new OffscreenCanvas(A*2,P*2),k=D.getContext("2d");k.fillStyle=b,k.fillRect(0,0,A*2,P*2),k.fillStyle=x,k.fillRect(0,0,A,P),k.fillRect(A,P,A,P),_.fillStyle=_.createPattern(D,"repeat"),_.fillRect(0,0,p,v),_.drawImage(h,0,0,h.width,h.height,0,0,p,v)}let f=null;if(i){let p,v;if(a.symmetric&&h.width<e&&h.height<e)p=h.width,v=h.height;else if(h=l(this,Vt),n>e||r>e){const x=Math.min(e/n,e/r);p=Math.floor(n*x),v=Math.floor(r*x),l(this,ks)||(h=w(this,vt,xf).call(this,p,v))}const b=new OffscreenCanvas(p,v).getContext("2d",{willReadFrequently:!0});b.drawImage(h,0,0,h.width,h.height,0,0,p,v),f={width:p,height:v,data:b.getImageData(0,0,p,v).data}}return{canvas:d,width:c,height:u,imageData:f}}getImageForAltText(){return l(this,Gi)}static async deserialize(e,s,i){var v;let n=null;if(e instanceof fb){const{data:{rect:_,rotation:b,id:x,structParent:C,popupRef:A},container:P,parent:{page:{pageNumber:D}}}=e,k=P.querySelector("canvas"),M=i.imageManager.getFromCanvas(P.id,k);k.remove();const R=((v=await s._structTree.getAriaAttributes(`${Rg}${x}`))==null?void 0:v.get("aria-label"))||"";n=e={annotationType:nt.STAMP,bitmapId:M.id,bitmap:M.bitmap,pageIndex:D-1,rect:_.slice(0),rotation:b,id:x,deleted:!1,accessibilityData:{decorative:!1,altText:R},isSvg:!1,structParent:C,popupRef:A}}const r=await super.deserialize(e,s,i),{rect:a,bitmap:h,bitmapUrl:c,bitmapId:u,isSvg:d,accessibilityData:f}=e;u&&i.imageManager.isValidId(u)?(m(r,Se,u),h&&m(r,Vt,h)):m(r,Rn,c),m(r,ks,d);const[g,p]=r.pageDimensions;return r.width=(a[2]-a[0])/g,r.height=(a[3]-a[1])/p,r.annotationElementId=e.id||null,f&&(r.altTextData=f),r._initialData=n,m(r,Ph,!!n),r}serialize(e=!1,s=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const i={annotationType:nt.STAMP,bitmapId:l(this,Se),pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:l(this,ks),structTreeParentId:this._structTreeParentId};if(e)return i.bitmapUrl=w(this,vt,Sf).call(this,!0),i.accessibilityData=this.serializeAltText(!0),i;const{decorative:n,altText:r}=this.serializeAltText(!1);if(!n&&r&&(i.accessibilityData={type:"Figure",alt:r}),this.annotationElementId){const h=w(this,vt,i_).call(this,i);if(h.isSame)return null;h.isSameAltText?delete i.accessibilityData:i.accessibilityData.structParent=this._initialData.structParent??-1}if(i.id=this.annotationElementId,s===null)return i;s.stamps||(s.stamps=new Map);const a=l(this,ks)?(i.rect[2]-i.rect[0])*(i.rect[3]-i.rect[1]):null;if(!s.stamps.has(l(this,Se)))s.stamps.set(l(this,Se),{area:a,serialized:i}),i.bitmap=w(this,vt,Sf).call(this,!1);else if(l(this,ks)){const h=s.stamps.get(l(this,Se));a>h.area&&(h.area=a,h.serialized.bitmap.close(),h.serialized.bitmap=w(this,vt,Sf).call(this,!1))}return i}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}};Vt=new WeakMap,Se=new WeakMap,Cr=new WeakMap,Rn=new WeakMap,Ar=new WeakMap,kh=new WeakMap,Gi=new WeakMap,Vi=new WeakMap,ks=new WeakMap,Ph=new WeakMap,vt=new WeakSet,iu=function(e,s=!1){if(!e){this.remove();return}m(this,Vt,e.bitmap),s||(m(this,Se,e.id),m(this,ks,e.isSvg)),e.file&&m(this,kh,e.file.name),w(this,vt,lm).call(this)},nu=function(){if(m(this,Cr,null),this._uiManager.enableWaiting(!1),!!l(this,Gi)){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Vt)){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Vt)){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}},wf=function(){if(l(this,Se)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(l(this,Se)).then(i=>w(this,vt,iu).call(this,i,!0)).finally(()=>w(this,vt,nu).call(this));return}if(l(this,Rn)){const i=l(this,Rn);m(this,Rn,null),this._uiManager.enableWaiting(!0),m(this,Cr,this._uiManager.imageManager.getFromUrl(i).then(n=>w(this,vt,iu).call(this,n)).finally(()=>w(this,vt,nu).call(this)));return}if(l(this,Ar)){const i=l(this,Ar);m(this,Ar,null),this._uiManager.enableWaiting(!0),m(this,Cr,this._uiManager.imageManager.getFromFile(i).then(n=>w(this,vt,iu).call(this,n)).finally(()=>w(this,vt,nu).call(this)));return}const e=document.createElement("input");e.type="file",e.accept=Vc.supportedTypesStr;const s=this._uiManager._signal;m(this,Cr,new Promise(i=>{e.addEventListener("change",async()=>{if(!e.files||e.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const n=await this._uiManager.imageManager.getFromFile(e.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),w(this,vt,iu).call(this,n)}i()},{signal:s}),e.addEventListener("cancel",()=>{this.remove(),i()},{signal:s})}).finally(()=>w(this,vt,nu).call(this))),e.click()},lm=function(){var d;const{div:e}=this;let{width:s,height:i}=l(this,Vt);const[n,r]=this.pageDimensions,a=.75;if(this.width)s=this.width*n,i=this.height*r;else if(s>a*n||i>a*r){const f=Math.min(a*n/s,a*r/i);s*=f,i*=f}const[h,c]=this.parentDimensions;this.setDims(s*h/n,i*c/r),this._uiManager.enableWaiting(!1);const u=m(this,Gi,document.createElement("canvas"));u.setAttribute("role","img"),this.addContainer(u),this.width=s/n,this.height=i/r,(d=this._initialOptions)!=null&&d.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(e.hidden=!1),w(this,vt,cm).call(this),l(this,Ph)||(this.parent.addUndoableEditor(this),m(this,Ph,!0)),this._reportTelemetry({action:"inserted_image"}),l(this,kh)&&u.setAttribute("aria-label",l(this,kh))},xf=function(e,s){const{width:i,height:n}=l(this,Vt);let r=i,a=n,h=l(this,Vt);for(;r>2*e||a>2*s;){const c=r,u=a;r>2*e&&(r=r>=16384?Math.floor(r/2)-1:Math.ceil(r/2)),a>2*s&&(a=a>=16384?Math.floor(a/2)-1:Math.ceil(a/2));const d=new OffscreenCanvas(r,a);d.getContext("2d").drawImage(h,0,0,c,u,0,0,r,a),h=d.transferToImageBitmap()}return h},cm=function(){const[e,s]=this.parentDimensions,{width:i,height:n}=this,r=new Ng,a=Math.ceil(i*e*r.sx),h=Math.ceil(n*s*r.sy),c=l(this,Gi);if(!c||c.width===a&&c.height===h)return;c.width=a,c.height=h;const u=l(this,ks)?l(this,Vt):w(this,vt,xf).call(this,a,h),d=c.getContext("2d");d.filter=this._uiManager.hcmFilter,d.drawImage(u,0,0,u.width,u.height,0,0,a,h)},Sf=function(e){if(e){if(l(this,ks)){const n=this._uiManager.imageManager.getSvgUrl(l(this,Se));if(n)return n}const s=document.createElement("canvas");return{width:s.width,height:s.height}=l(this,Vt),s.getContext("2d").drawImage(l(this,Vt),0,0),s.toDataURL()}if(l(this,ks)){const[s,i]=this.pageDimensions,n=Math.round(this.width*s*Kn.PDF_TO_CSS_UNITS),r=Math.round(this.height*i*Kn.PDF_TO_CSS_UNITS),a=new OffscreenCanvas(n,r);return a.getContext("2d").drawImage(l(this,Vt),0,0,l(this,Vt).width,l(this,Vt).height,0,0,n,r),a.transferToImageBitmap()}return structuredClone(l(this,Vt))},i_=function(e){var a;const{pageIndex:s,accessibilityData:{altText:i}}=this._initialData,n=e.pageIndex===s,r=(((a=e.accessibilityData)==null?void 0:a.alt)||"")===i;return{isSame:!this._hasBeenMoved&&!this._hasBeenResized&&n&&r,isSameAltText:r}},J(Vc,"_type","stamp"),J(Vc,"_editorType",nt.STAMP);let op=Vc;const vi=class vi{constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:a,textLayer:h,viewport:c,l10n:u}){y(this,Nt);y(this,Qa);y(this,Mh,!1);y(this,Wi,null);y(this,Tr,null);y(this,Ln,null);y(this,zs,new Map);y(this,Er,!1);y(this,Oh,!1);y(this,Za,!1);y(this,mi,null);y(this,Fn,null);y(this,Fe,null);y(this,In,null);y(this,$);const d=[...l(vi,kr).values()];if(!vi._initialized){vi._initialized=!0;for(const f of d)f.initialize(u,t)}t.registerEditorTypes(d),m(this,$,t),this.pageIndex=e,this.div=s,m(this,Qa,n),m(this,Wi,r),this.viewport=c,m(this,Fe,h),this.drawLayer=a,this._structTree=i,l(this,$).addLayer(this)}get isEmpty(){return l(this,zs).size===0}get isInvisible(){return this.isEmpty&&l(this,$).getMode()===nt.NONE}updateToolbar(t){l(this,$).updateToolbar(t)}updateMode(t=l(this,$).getMode()){switch(w(this,Nt,Cf).call(this),t){case nt.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case nt.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case nt.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);const{classList:e}=this.div;for(const s of l(vi,kr).values())e.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){var e;return t===((e=l(this,Fe))==null?void 0:e.div)}setEditingState(t){l(this,$).setEditingState(t)}addCommands(t){l(this,$).addCommands(t)}cleanUndoStack(t){l(this,$).cleanUndoStack(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){var e;(e=l(this,Wi))==null||e.div.classList.toggle("disabled",!t)}async enable(){m(this,Za,!0),this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const s of l(this,zs).values())s.enableEditing(),s.show(!0),s.annotationElementId&&(l(this,$).removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!l(this,Wi)){m(this,Za,!1);return}const e=l(this,Wi).getEditableAnnotations();for(const s of e){if(s.hide(),l(this,$).isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;const i=await this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}m(this,Za,!1)}disable(){var i;m(this,Oh,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,e=new Map;for(const n of l(this,zs).values())if(n.disableEditing(),!!n.annotationElementId){if(n.serialize()!==null){t.set(n.annotationElementId,n);continue}else e.set(n.annotationElementId,n);(i=this.getEditableAnnotation(n.annotationElementId))==null||i.show(),n.remove()}if(l(this,Wi)){const n=l(this,Wi).getEditableAnnotations();for(const r of n){const{id:a}=r.data;if(l(this,$).isDeletedAnnotationElement(a))continue;let h=e.get(a);if(h){h.resetAnnotationElement(r),h.show(!1),r.show();continue}h=t.get(a),h&&(l(this,$).addChangedExistingAnnotation(h),h.renderAnnotationElement(r)&&h.show(!1)),r.show()}}w(this,Nt,Cf).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const n of l(vi,kr).values())s.remove(`${n._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),m(this,Oh,!1)}getEditableAnnotation(t){var e;return((e=l(this,Wi))==null?void 0:e.getEditableAnnotation(t))||null}setActiveEditor(t){l(this,$).getActive()!==t&&l(this,$).setActiveEditor(t)}enableTextSelection(){var t;if(this.div.tabIndex=-1,(t=l(this,Fe))!=null&&t.div&&!l(this,In)){m(this,In,new AbortController);const e=l(this,$).combinedSignal(l(this,In));l(this,Fe).div.addEventListener("pointerdown",w(this,Nt,n_).bind(this),{signal:e}),l(this,Fe).div.classList.add("highlighting")}}disableTextSelection(){var t;this.div.tabIndex=0,(t=l(this,Fe))!=null&&t.div&&l(this,In)&&(l(this,In).abort(),m(this,In,null),l(this,Fe).div.classList.remove("highlighting"))}enableClick(){if(l(this,Tr))return;m(this,Tr,new AbortController);const t=l(this,$).combinedSignal(l(this,Tr));this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t});const e=this.pointerup.bind(this);this.div.addEventListener("pointerup",e,{signal:t}),this.div.addEventListener("pointercancel",e,{signal:t})}disableClick(){var t;(t=l(this,Tr))==null||t.abort(),m(this,Tr,null)}attach(t){l(this,zs).set(t.id,t);const{annotationElementId:e}=t;e&&l(this,$).isDeletedAnnotationElement(e)&&l(this,$).removeDeletedAnnotationElement(t)}detach(t){var e;l(this,zs).delete(t.id),(e=l(this,Qa))==null||e.removePointerInTextLayer(t.contentDiv),!l(this,Oh)&&t.annotationElementId&&l(this,$).addDeletedAnnotationElement(t)}remove(t){this.detach(t),l(this,$).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){var e;t.parent!==this&&(t.parent&&t.annotationElementId&&(l(this,$).addDeletedAnnotationElement(t.annotationElementId),Ht.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),(e=t.parent)==null||e.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),l(this,$).addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!l(this,Za)),l(this,$).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var s;if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!l(this,Ln)&&(t._focusEventsAllowed=!1,m(this,Ln,setTimeout(()=>{m(this,Ln,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:l(this,$)._signal}),e.focus())},0))),t._structTreeParentId=(s=l(this,Qa))==null?void 0:s.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 e=()=>t._uiManager.rebuild(t),s=()=>{t.remove()};this.addCommands({cmd:e,undo:s,mustExec:!1})}getNextId(){return l(this,$).getId()}combinedSignal(t){return l(this,$).combinedSignal(t)}canCreateNewEmptyEditor(){var t;return(t=l(this,Nt,Ui))==null?void 0:t.canCreateNewEmptyEditor()}pasteEditor(t,e){l(this,$).updateToolbar(t),l(this,$).updateMode(t);const{offsetX:s,offsetY:i}=w(this,Nt,dm).call(this),n=this.getNextId(),r=w(this,Nt,um).call(this,{parent:this,id:n,x:s,y:i,uiManager:l(this,$),isCentered:!0,...e});r&&this.add(r)}async deserialize(t){var e;return await((e=l(vi,kr).get(t.annotationType??t.annotationEditorType))==null?void 0:e.deserialize(t,this,l(this,$)))||null}createAndAddNewEditor(t,e,s={}){const i=this.getNextId(),n=w(this,Nt,um).call(this,{parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:l(this,$),isCentered:e,...s});return n&&this.add(n),n}addNewEditor(){this.createAndAddNewEditor(w(this,Nt,dm).call(this),!0)}setSelected(t){l(this,$).setSelected(t)}toggleSelected(t){l(this,$).toggleSelected(t)}unselect(t){l(this,$).unselect(t)}pointerup(t){var s;const{isMac:e}=ze.platform;if(!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&l(this,Er)&&(m(this,Er,!1),!((s=l(this,Nt,Ui))!=null&&s.isDrawer&&l(this,Nt,Ui).supportMultipleDrawings))){if(!l(this,Mh)){m(this,Mh,!0);return}if(l(this,$).getMode()===nt.STAMP){l(this,$).unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){var i;if(l(this,$).getMode()===nt.HIGHLIGHT&&this.enableTextSelection(),l(this,Er)){m(this,Er,!1);return}const{isMac:e}=ze.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;if(m(this,Er,!0),(i=l(this,Nt,Ui))!=null&&i.isDrawer){this.startDrawingSession(t);return}const s=l(this,$).getActive();m(this,Mh,!s||s.isEmpty())}startDrawingSession(t){if(this.div.focus(),l(this,mi)){l(this,Nt,Ui).startDrawing(this,l(this,$),!1,t);return}l(this,$).setCurrentDrawingSession(this),m(this,mi,new AbortController);const e=l(this,$).combinedSignal(l(this,mi));this.div.addEventListener("blur",({relatedTarget:s})=>{s&&!this.div.contains(s)&&(m(this,Fn,null),this.commitOrRemove())},{signal:e}),l(this,Nt,Ui).startDrawing(this,l(this,$),!1,t)}pause(t){if(t){const{activeElement:e}=document;this.div.contains(e)&&m(this,Fn,e);return}l(this,Fn)&&setTimeout(()=>{var e;(e=l(this,Fn))==null||e.focus(),m(this,Fn,null)},0)}endDrawingSession(t=!1){return l(this,mi)?(l(this,$).setCurrentDrawingSession(null),l(this,mi).abort(),m(this,mi,null),m(this,Fn,null),l(this,Nt,Ui).endDrawing(t)):null}findNewParent(t,e,s){const i=l(this,$).findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}commitOrRemove(){return l(this,mi)?(this.endDrawingSession(),!0):!1}onScaleChanging(){l(this,mi)&&l(this,Nt,Ui).onScaleChangingWhenDrawing(this)}destroy(){var t,e;this.commitOrRemove(),((t=l(this,$).getActive())==null?void 0:t.parent)===this&&(l(this,$).commitOrRemove(),l(this,$).setActiveEditor(null)),l(this,Ln)&&(clearTimeout(l(this,Ln)),m(this,Ln,null));for(const s of l(this,zs).values())(e=l(this,Qa))==null||e.removePointerInTextLayer(s.contentDiv),s.setParent(null),s.isAttachedToDOM=!1,s.div.remove();this.div=null,l(this,zs).clear(),l(this,$).removeLayer(this)}render({viewport:t}){this.viewport=t,zr(this.div,t);for(const e of l(this,$).getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){l(this,$).commitOrRemove(),w(this,Nt,Cf).call(this);const e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,zr(this.div,{rotation:s}),e!==s)for(const i of l(this,zs).values())i.rotate(s)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return l(this,$).viewParameters.realScale}};Qa=new WeakMap,Mh=new WeakMap,Wi=new WeakMap,Tr=new WeakMap,Ln=new WeakMap,zs=new WeakMap,Er=new WeakMap,Oh=new WeakMap,Za=new WeakMap,mi=new WeakMap,Fn=new WeakMap,Fe=new WeakMap,In=new WeakMap,$=new WeakMap,kr=new WeakMap,Nt=new WeakSet,n_=function(t){l(this,$).unselectAll();const{target:e}=t;if(e===l(this,Fe).div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&l(this,Fe).div.contains(e)){const{isMac:s}=ze.platform;if(t.button!==0||t.ctrlKey&&s)return;l(this,$).showAllEditors("highlight",!0,!0),l(this,Fe).div.classList.add("free"),this.toggleDrawing(),Ad.startHighlighting(this,l(this,$).direction==="ltr",{target:l(this,Fe).div,x:t.x,y:t.y}),l(this,Fe).div.addEventListener("pointerup",()=>{l(this,Fe).div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:l(this,$)._signal}),t.preventDefault()}},Ui=function(){return l(vi,kr).get(l(this,$).getMode())},um=function(t){const e=l(this,Nt,Ui);return e?new e.prototype.constructor(t):null},dm=function(){const{x:t,y:e,width:s,height:i}=this.div.getBoundingClientRect(),n=Math.max(0,t),r=Math.max(0,e),a=Math.min(window.innerWidth,t+s),h=Math.min(window.innerHeight,e+i),c=(n+a)/2-t,u=(r+h)/2-e,[d,f]=this.viewport.rotation%180===0?[c,u]:[u,c];return{offsetX:d,offsetY:f}},Cf=function(){for(const t of l(this,zs).values())t.isEmpty()&&t.remove()},J(vi,"_initialized",!1),y(vi,kr,new Map([ep,ap,op,Ad].map(t=>[t._editorType,t])));let hp=vi;const Ie=class Ie{constructor({pageIndex:t}){y(this,zi);y(this,bi,null);y(this,Wc,0);y(this,Ke,new Map);y(this,to,new Map);this.pageIndex=t}setParent(t){if(!l(this,bi)){m(this,bi,t);return}if(l(this,bi)!==t){if(l(this,Ke).size>0)for(const e of l(this,Ke).values())e.remove(),t.append(e);m(this,bi,t)}}static get _svgFactory(){return ht(this,"_svgFactory",new Qg)}draw(t,e=!1,s=!1){const i=Ze(this,Wc)._++,n=w(this,zi,fm).call(this),r=Ie._svgFactory.createElement("defs");n.append(r);const a=Ie._svgFactory.createElement("path");r.append(a);const h=`path_p${this.pageIndex}_${i}`;a.setAttribute("id",h),a.setAttribute("vector-effect","non-scaling-stroke"),e&&l(this,to).set(i,a);const c=s?w(this,zi,a_).call(this,r,h):null,u=Ie._svgFactory.createElement("use");return n.append(u),u.setAttribute("href",`#${h}`),this.updateProperties(n,t),l(this,Ke).set(i,n),{id:i,clipPathId:`url(#${c})`}}drawOutline(t,e){const s=Ze(this,Wc)._++,i=w(this,zi,fm).call(this),n=Ie._svgFactory.createElement("defs");i.append(n);const r=Ie._svgFactory.createElement("path");n.append(r);const a=`path_p${this.pageIndex}_${s}`;r.setAttribute("id",a),r.setAttribute("vector-effect","non-scaling-stroke");let h;if(e){const d=Ie._svgFactory.createElement("mask");n.append(d),h=`mask_p${this.pageIndex}_${s}`,d.setAttribute("id",h),d.setAttribute("maskUnits","objectBoundingBox");const f=Ie._svgFactory.createElement("rect");d.append(f),f.setAttribute("width","1"),f.setAttribute("height","1"),f.setAttribute("fill","white");const g=Ie._svgFactory.createElement("use");d.append(g),g.setAttribute("href",`#${a}`),g.setAttribute("stroke","none"),g.setAttribute("fill","black"),g.setAttribute("fill-rule","nonzero"),g.classList.add("mask")}const c=Ie._svgFactory.createElement("use");i.append(c),c.setAttribute("href",`#${a}`),h&&c.setAttribute("mask",`url(#${h})`);const u=c.cloneNode();return i.append(u),c.classList.add("mainOutline"),u.classList.add("secondaryOutline"),this.updateProperties(i,t),l(this,Ke).set(s,i),s}finalizeDraw(t,e){l(this,to).delete(t),this.updateProperties(t,e)}updateProperties(t,e){var h;if(!e)return;const{root:s,bbox:i,rootClass:n,path:r}=e,a=typeof t=="number"?l(this,Ke).get(t):t;if(a){if(s&&w(this,zi,gm).call(this,a,s),i&&w(h=Ie,Xd,r_).call(h,a,i),n){const{classList:c}=a;for(const[u,d]of Object.entries(n))c.toggle(u,d)}if(r){const u=a.firstChild.firstChild;w(this,zi,gm).call(this,u,r)}}}updateParent(t,e){if(e===this)return;const s=l(this,Ke).get(t);s&&(l(e,bi).append(s),l(this,Ke).delete(t),l(e,Ke).set(t,s))}remove(t){l(this,to).delete(t),l(this,bi)!==null&&(l(this,Ke).get(t).remove(),l(this,Ke).delete(t))}destroy(){m(this,bi,null);for(const t of l(this,Ke).values())t.remove();l(this,Ke).clear(),l(this,to).clear()}};bi=new WeakMap,Wc=new WeakMap,Ke=new WeakMap,to=new WeakMap,Xd=new WeakSet,r_=function(t,[e,s,i,n]){const{style:r}=t;r.top=`${100*s}%`,r.left=`${100*e}%`,r.width=`${100*i}%`,r.height=`${100*n}%`},zi=new WeakSet,fm=function(){const t=Ie._svgFactory.create(1,1,!0);return l(this,bi).append(t),t.setAttribute("aria-hidden",!0),t},a_=function(t,e){const s=Ie._svgFactory.createElement("clipPath");t.append(s);const i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=Ie._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i},gm=function(t,e){for(const[s,i]of Object.entries(e))i===null?t.removeAttribute(s):t.setAttribute(s,i)},y(Ie,Xd);let lp=Ie;globalThis.pdfjsTestingUtils={HighlightOutliner:sp},Z.AbortException,Z.AnnotationEditorLayer,Z.AnnotationEditorParamsType,Z.AnnotationEditorType,Z.AnnotationEditorUIManager,Z.AnnotationLayer,Z.AnnotationMode,Z.ColorPicker,Z.DOMSVGFactory,Z.DrawLayer,Z.FeatureTest;var IC=Z.GlobalWorkerOptions;Z.ImageKind,Z.InvalidPDFException,Z.MissingPDFException,Z.OPS,Z.OutputScale,Z.PDFDataRangeTransport,Z.PDFDateString,Z.PDFWorker,Z.PasswordResponses,Z.PermissionFlag,Z.PixelsPerInch,Z.RenderingCancelledException,Z.TextLayer,Z.TouchManager,Z.UnexpectedResponseException,Z.Util,Z.VerbosityLevel,Z.XfaLayer,Z.build,Z.createValidAbsoluteUrl,Z.fetchData;var jC=Z.getDocument;Z.getFilenameFromUrl,Z.getPdfFilenameFromUrl,Z.getXfaPageViewport,Z.isDataScheme,Z.isPdfFile,Z.noContextMenu,Z.normalizeUnicode,Z.setLayerDimensions,Z.shadow,Z.stopEvent,Z.version;const NC={"pdfjs-dist":"4.10.38"};function BC(o){return new Promise((t,e)=>{const s=new FileReader;s.addEventListener("load",()=>t(s.result)),s.addEventListener("error",e),s.readAsDataURL(o)})}const HC=NC["pdfjs-dist"].replace("^","");IC.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${HC}/pdf.worker.min.mjs`;async function GC(o){const t="data:application/pdf;base64,",e=await BC(o);if(typeof e=="string")return window.atob(e.slice(t.length))}function VC(o,t){return jC({data:o,password:t}).promise}const WC="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2040%2040'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3ccircle%20cx='20'%20cy='20'%20r='10.75'%20stroke='currentColor'%20stroke-width='2.5'/%3e%3cpath%20d='M16%2024L23.7782%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3cpath%20d='M24%2024L16.2218%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3c/svg%3e";function zC(o){return new URL(Object.assign({"../assets/close.svg":WC})[`../assets/${o}`],typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Mt&&Mt.tagName.toUpperCase()==="SCRIPT"&&Mt.src||new URL("pdf-canvas.umd.js",document.baseURI).href).href}function XC(o){return new Promise((t,e)=>{const s=window.URL.createObjectURL(o),i=new Image;i.src=s,i.addEventListener("load",async()=>{window.URL.revokeObjectURL(s),t(await UC(i))}),i.addEventListener("error",n=>{window.URL.revokeObjectURL(s),e(n)})})}function UC(o){return new Promise(t=>{const e=document.createElement("canvas"),s=e.getContext("2d"),{naturalWidth:i,naturalHeight:n}=o;e.width=i,e.height=n,s==null||s.drawImage(o,0,0,i,n),t(e.toDataURL("image/jpeg",.8))})}let pb=null;function YC(){const o=document.createElement("div");o.style.width="1in",document.body.append(o);const t=o.offsetWidth;return o.remove(),t}function $C(){const o=pb??YC();return pb=o,o/72}function qC(o,t=500){if(typeof o!="function")throw new TypeError("The first argument is not a function.");let e=null;return function(...s){e&&clearTimeout(e),e=setTimeout(()=>{e=null,o.apply(this,s)},t)}}const Ls=new Map;function KC(o){const t=new fg(o);return Ls.set(o,t),t}function JC(o,t){const e=Date.now();return{PDFId:`${o.name}-${e}`,name:o.name.replace(/.pdf/,""),updateDate:e,PDFBase64:t}}function QC(o,t){const e=o.getViewport({scale:t}),s=document.createElement("canvas"),i=s.getContext("2d"),n=$C()/window.devicePixelRatio;s.width=Math.floor(e.width*n),s.height=Math.floor(e.height*n);const r={canvasContext:i,viewport:e,transform:[n,0,0,n,0,0]},a=o.render(r);return{canvas:s,renderTask:a}}async function ZC(o,t,e){const s=o||zC("close.svg"),{objects:i,options:n}=await Tx(s),r=i.filter(h=>h!==null),a=Hw.groupSVGElements(r,n);return r.forEach(h=>{h.stroke=t}),a.hoverCursor="pointer",a.stroke=`${t}-${e}`,a}function tA(o,t){if(!Ls.get(o))return;const s=1/3,i=aA(t,s);vb(o,i,s)}async function eA(o,t){const e=await XC(t),s=Date.now(),n={PDFId:`${t.name}${s}`,name:t.name.replace(/.png|.jpg|.jpeg/,""),updateDate:s,PDFBase64:e};return mb(o,{url:e}),{...n,pages:1}}async function mb(o,{url:t,scale:e=.5}){if(!Ls.get(o))return;const i=await ke.fromURL(t);i.scale(e),vb(o,i,e)}function vb(o,t,e){const s=Ls.get(o);s&&(s.setWidth(t.width*e),s.setHeight(t.height*e),s.backgroundImage=t,s.renderAll())}function vl(o,t){if(!t)return;const{oCoords:e}=o;if(!e)return;const{x:s,y:i}=e.tl.touchCorner.tl,{height:n,width:r,scaleY:a,scaleX:h}=t;t.top=i-n*a/2,t.left=s-r*h/2,t.setCoords()}function sA(o,t,e){!e||!o||(e.scale(1/t),vl(o,e))}function iA(o,t){if(!o)return;const e=o._cornerSize||6;o.borderScaleFactor=1/t,o.cornerSize=e*(1/t),o.touchCornerSize=e*4*(1/t),o.setCoords()}function nA(o){const t=Ls.get(o);t&&(t.discardActiveObject(),t.renderAll())}function rA(o){const t=Ls.get(o);t&&(t.clear(),Ls.delete(o))}function aA(o,t){return new ke(o,{scaleX:t,scaleY:t})}const oA={top:100,left:50,scaleX:.5,scaleY:.5,borderColor:"black",cornerStrokeColor:"black",cornerSize:6,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},hA={top:100,left:50,fontFamily:"helvetica",borderColor:"black",cornerStrokeColor:"black",scaleX:.7,scaleY:.7,cornerSize:6,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},lA={stroke:"#000",hoverStroke:"#B7EC5D",src:""};function bb(o=""){const t=Q.useRef(0),e=Q.useRef(null),s=Q.useRef(null),i=Q.useRef(1),n=Q.useRef({...lA});function r(){if(!o||Ls.has(o))return;const k=KC(o);return k.on("selection:cleared",()=>A(k)),k}function a(k,M){var I;const R=k.type,F={"application/pdf":h,"image/png":d,"image/jpeg":d};return((I=F[R])==null?void 0:I.call(F,k,M))??Promise.reject(new Error(`Unsupported ${R} file type.`))}async function h(k,M){const R=await GC(k);if(!R)return;const F=JC(k,R);try{return await c({page:1,PDFBase64:R,scale:.8,password:M}),{...F,pages:t.current}}catch(I){return Promise.reject(I)}}async function c({page:k,PDFBase64:M,scale:R,password:F}){try{const I=await VC(M,F),Y=await I.getPage(k),{renderTask:N,canvas:H}=QC(Y,R);return t.current=I.numPages,N.promise.then(()=>u(H))}catch(I){return Promise.reject(I)}}function u(k){tA(o,k)}async function d(k){return await eA(o,k)}async function f({url:k,scale:M=.5}){await mb(o,{url:k,scale:M})}async function g(k,M){const R=Ls.get(o);if(!R)return;const F=await ke.fromURL(k,{},{...oA,...M});R.add(F),v(R,F)}function p(k,M){const R=Ls.get(o);if(!R)return;const F=new Ee(k,{...hA,...M});R.add(F),v(R,F)}function v(k,M){M.on("selected",R=>_({canvas:k,target:R.target})),M.on("modified",R=>vl(R.target,e.current)),M.on("scaling",R=>vl(R.transform.target,e.current)),M.on("moving",R=>vl(R.transform.target,e.current)),M.on("rotating",R=>vl(R.transform.target,e.current))}async function _({canvas:k,target:M,stroke:R=n.current.stroke,uuid:F=Date.now()}){var Y;if(((Y=e.current)==null?void 0:Y.stroke)===`${R}-${F}`)return;const I=await ZC(n.current.src,R,F);A(k),e.current=I,s.current=M,b(k,M,F),x(i.current,!0),k.add(I)}function b(k,M,R){e.current&&(e.current.on("selected",()=>{k.remove(M),A(k)}),e.current.on("mouseover",()=>{_({canvas:k,target:M,stroke:n.current.hoverStroke,uuid:R})}),e.current.on("mouseout",()=>{_({canvas:k,target:M,stroke:n.current.stroke,uuid:R})}))}function x(k,M=!1){const R=Ls.get(o);i.current=k,R&&(iA(s.current,k),sA(s.current,k,e.current),!M&&R.renderAll())}function C(k){if(!k)return;n.current={...n.current,...k};const M=Ls.get(o);!e||!s.current||!M||_({target:s.current,canvas:M})}function A(k){e.current&&(k.remove(e.current),e.current=s.current=null)}function P(){nA(o)}function D(){rA(o)}return{createCanvas:r,loadFile:a,specifyPage:c,renderImage:f,addFabric:g,addTextFabric:p,clearActive:P,deleteCanvas:D,scaleFabric:x,setCloseSvgOptions:C}}function cA(o){let t=0;const e=qC(()=>{t!==window.innerWidth&&(t=window.innerWidth,o())});Q.useEffect(()=>(window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)),[])}const uA=Q.forwardRef(dA);function dA({file:o,page:t=1,canvasId:e="PDF-canvas",fileZoom:s=1,fileScale:i=1,canvasScale:n=1,canvasClass:r="",isDrop:a=!1,password:h,dropTextOptions:c,dropImageOptions:u,closeSvgOptions:d},f){const g=Q.useRef(null),p=`${e}-${t-1}`,v=Q.useMemo(()=>s*n,[s,n]),{createCanvas:_,specifyPage:b,addFabric:x,addTextFabric:C,renderImage:A,clearActive:P,deleteCanvas:D,scaleFabric:k,setCloseSvgOptions:M}=bb(p);cA(R);async function R(){window.requestAnimationFrame(async()=>{if(_(),o.PDFBase64.startsWith("data:image")||o.canvas){const{canvas:N}=o,H=N?7:3,at=N!=null&&N.length?N[t-1]:o.PDFBase64;A({url:at,scale:i/H});return}await b({page:t,PDFBase64:o.PDFBase64,scale:i,password:h})})}function F(N){if(N.preventDefault(),N.stopPropagation(),!a||!N.dataTransfer)return;const{dataTransfer:H,clientX:at,clientY:j}=N,W=H.getData("text/plain"),it=H.getData("text/uri-list"),kt={left:at-71,top:j-55};it?I(it,kt):W&&Y(W,kt)}function I(N,H){x(N,{...H,...u})}function Y(N,H){C(N,{...H,...c})}return Q.useImperativeHandle(f,()=>({addImage:I,addText:Y,clearActive:P,deleteCanvas:D,canvasRef:g})),Q.useEffect(()=>{R()},[i,t,o,h]),Q.useEffect(()=>{k(v)},[v]),Q.useEffect(()=>{M(d)},[d]),Q.useEffect(()=>()=>D(),[]),vm.jsx("div",{style:{transform:`scale(${v})`},onDragOver:N=>N.preventDefault(),onDragEnter:N=>N.preventDefault(),onDrop:F,children:vm.jsx("canvas",{id:p,ref:g,className:r})})}ut.default=uA,ut.useFabric=bb,Object.defineProperties(ut,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -22160,7 +22160,7 @@ function CC(a, t, e) {
22160
22160
  }
22161
22161
  function AC(a, t) {
22162
22162
  if (!a) return;
22163
- const e = a._cornerSize || 8;
22163
+ const e = a._cornerSize || 6;
22164
22164
  a.borderScaleFactor = 1 / t, a.cornerSize = e * (1 / t), a.touchCornerSize = e * 4 * (1 / t), a.setCoords();
22165
22165
  }
22166
22166
  function TC(a) {
@@ -22218,7 +22218,7 @@ const DC = {
22218
22218
  scaleY: 0.5,
22219
22219
  borderColor: "black",
22220
22220
  cornerStrokeColor: "black",
22221
- cornerSize: 8,
22221
+ cornerSize: 6,
22222
22222
  selectionBackgroundColor: "rgba(245, 245, 245, 0.8)"
22223
22223
  }, OC = {
22224
22224
  top: 100,
@@ -22228,12 +22228,12 @@ const DC = {
22228
22228
  cornerStrokeColor: "black",
22229
22229
  scaleX: 0.7,
22230
22230
  scaleY: 0.7,
22231
- cornerSize: 8,
22231
+ cornerSize: 6,
22232
22232
  selectionBackgroundColor: "rgba(245, 245, 245, 0.8)"
22233
22233
  }, RC = {
22234
22234
  borderColor: "black",
22235
22235
  cornerStrokeColor: "black",
22236
- cornerSize: 13,
22236
+ cornerSize: 8,
22237
22237
  selectionBackgroundColor: "rgba(245, 245, 245, 0.8)"
22238
22238
  }, LC = {
22239
22239
  stroke: "#000",
@@ -506,4 +506,4 @@ void main() {
506
506
  `),position:b,pageIndex:_-1,rect:u.slice(0),rotation:d,id:f,deleted:!1,popupRef:g}}const r=await super.deserialize(e,s,i);return m(r,ls,e.fontSize),m(r,qs,U.makeHexColor(...e.color)),m(r,hs,w(o=wt,fn,Tp).call(o,e.value)),r.annotationElementId=e.id||null,r._initialData=n,r}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const s=wt._internalPadding*this.parentScale,i=this.getRect(s,s),n=Pt._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:l(this,qs)),r={annotationType:Z.FREETEXT,color:n,fontSize:l(this,ls),value:w(this,Ut,Gy).call(this),pageIndex:this.pageIndex,rect:i,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?r:this.annotationElementId&&!w(this,Ut,Vy).call(this,r)?null:(r.id=this.annotationElementId,r)}renderAnnotationElement(e){const s=super.renderAnnotationElement(e);if(this.deleted)return s;const{style:i}=s;i.fontSize=`calc(${l(this,ls)}px * var(--scale-factor))`,i.color=l(this,qs),s.replaceChildren();for(const r of l(this,hs).split(`
507
507
  `)){const o=document.createElement("div");o.append(r?document.createTextNode(r):document.createElement("br")),s.append(o)}const n=wt._internalPadding*this.parentScale;return e.updateEdited({rect:this.getRect(n,n),popupContent:l(this,hs)}),s}resetAnnotationElement(e){super.resetAnnotationElement(e),e.resetEdited()}};qs=new WeakMap,hs=new WeakMap,ic=new WeakMap,xo=new WeakMap,ls=new WeakMap,Ut=new WeakSet,By=function(e){const s=n=>{this.editorDiv.style.fontSize=`calc(${n}px * var(--scale-factor))`,this.translate(0,-(n-l(this,ls))*this.parentScale),m(this,ls,n),w(this,Ut,Xd).call(this)},i=l(this,ls);this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:ot.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})},Hy=function(e){const s=n=>{m(this,qs,this.editorDiv.style.color=n)},i=l(this,qs);this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:ot.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})},zy=function(){var i;const e=[];this.editorDiv.normalize();let s=null;for(const n of this.editorDiv.childNodes)(s==null?void 0:s.nodeType)===Node.TEXT_NODE&&n.nodeName==="BR"||(e.push(w(i=wt,fn,Wd).call(i,n)),s=n);return e.join(`
508
508
  `)},Xd=function(){const[e,s]=this.parentDimensions;let i;if(this.isAttachedToDOM)i=this.div.getBoundingClientRect();else{const{currentLayer:n,div:r}=this,o=r.style.display,h=r.classList.contains("hidden");r.classList.remove("hidden"),r.style.display="hidden",n.div.append(this.div),i=r.getBoundingClientRect(),r.remove(),r.style.display=o,r.classList.toggle("hidden",h)}this.rotation%180===this.parentRotation%180?(this.width=i.width/e,this.height=i.height/s):(this.width=i.height/e,this.height=i.width/s),this.fixAndSetPosition()},fn=new WeakSet,Wd=function(e){return(e.nodeType===Node.TEXT_NODE?e.nodeValue:e.innerText).replaceAll(sd,"")},Ud=function(){if(this.editorDiv.replaceChildren(),!!l(this,hs))for(const e of l(this,hs).split(`
509
- `)){const s=document.createElement("div");s.append(e?document.createTextNode(e):document.createElement("br")),this.editorDiv.append(s)}},Gy=function(){return l(this,hs).replaceAll(" "," ")},Tp=function(e){return e.replaceAll(" "," ")},Vy=function(e){const{value:s,fontSize:i,color:n,pageIndex:r}=this._initialData;return this._hasBeenMoved||e.value!==s||e.fontSize!==i||e.color.some((o,h)=>o!==n[h])||e.pageIndex!==r},v(wt,fn),$(wt,"_freeTextDefaultContent",""),$(wt,"_internalPadding",0),$(wt,"_defaultColor",null),$(wt,"_defaultFontSize",10),$(wt,"_type","freetext"),$(wt,"_editorType",Z.FREETEXT);let Rg=wt;class H{toSVGPath(){vt("Abstract method `toSVGPath` must be implemented.")}get box(){vt("Abstract getter `box` must be implemented.")}serialize(t,e){vt("Abstract method `serialize` must be implemented.")}static _rescale(t,e,s,i,n,r){r||(r=new Float32Array(t.length));for(let o=0,h=t.length;o<h;o+=2)r[o]=e+t[o]*i,r[o+1]=s+t[o+1]*n;return r}static _rescaleAndSwap(t,e,s,i,n,r){r||(r=new Float32Array(t.length));for(let o=0,h=t.length;o<h;o+=2)r[o]=e+t[o+1]*i,r[o+1]=s+t[o]*n;return r}static _translate(t,e,s,i){i||(i=new Float32Array(t.length));for(let n=0,r=t.length;n<r;n+=2)i[n]=e+t[n],i[n+1]=s+t[n+1];return i}static svgRound(t){return Math.round(t*1e4)}static _normalizePoint(t,e,s,i,n){switch(n){case 90:return[1-e/s,t/i];case 180:return[1-t/s,1-e/i];case 270:return[e/s,1-t/i];default:return[t/s,e/i]}}static _normalizePagePoint(t,e,s){switch(s){case 90:return[1-e,t];case 180:return[1-t,1-e];case 270:return[e,1-t];default:return[t,e]}}static createBezierPoints(t,e,s,i,n,r){return[(t+5*s)/6,(e+5*i)/6,(5*s+n)/6,(5*i+r)/6,(s+n)/2,(i+r)/2]}}$(H,"PRECISION",1e-4);const gn=class gn{constructor({x:t,y:e},s,i,n,r,o=0){v(this,Jt);v(this,cs);v(this,Ks,[]);v(this,Xa);v(this,Wa);v(this,wi,[]);v(this,it,new Float32Array(18));v(this,So);v(this,Co);v(this,nc);v(this,rc);v(this,Ua);v(this,Ya);v(this,sr,[]);m(this,cs,s),m(this,Ya,n*i),m(this,Wa,r),l(this,it).set([NaN,NaN,NaN,NaN,t,e],6),m(this,Xa,o),m(this,rc,l(gn,oc)*i),m(this,nc,l(gn,xd)*i),m(this,Ua,i),l(this,sr).push(t,e)}isEmpty(){return isNaN(l(this,it)[8])}add({x:t,y:e}){var O;m(this,So,t),m(this,Co,e);const[s,i,n,r]=l(this,cs);let[o,h,c,u]=l(this,it).subarray(8,12);const d=t-c,f=e-u,g=Math.hypot(d,f);if(g<l(this,nc))return!1;const p=g-l(this,rc),b=p/g,_=b*d,y=b*f;let x=o,S=h;o=c,h=u,c+=_,u+=y,(O=l(this,sr))==null||O.push(t,e);const C=-y/p,E=_/p,D=C*l(this,Ya),M=E*l(this,Ya);return l(this,it).set(l(this,it).subarray(2,8),0),l(this,it).set([c+D,u+M],4),l(this,it).set(l(this,it).subarray(14,18),12),l(this,it).set([c-D,u-M],16),isNaN(l(this,it)[6])?(l(this,wi).length===0&&(l(this,it).set([o+D,h+M],2),l(this,wi).push(NaN,NaN,NaN,NaN,(o+D-s)/n,(h+M-i)/r),l(this,it).set([o-D,h-M],14),l(this,Ks).push(NaN,NaN,NaN,NaN,(o-D-s)/n,(h-M-i)/r)),l(this,it).set([x,S,o,h,c,u],6),!this.isEmpty()):(l(this,it).set([x,S,o,h,c,u],6),Math.abs(Math.atan2(S-h,x-o)-Math.atan2(y,_))<Math.PI/2?([o,h,c,u]=l(this,it).subarray(2,6),l(this,wi).push(NaN,NaN,NaN,NaN,((o+c)/2-s)/n,((h+u)/2-i)/r),[o,h,x,S]=l(this,it).subarray(14,18),l(this,Ks).push(NaN,NaN,NaN,NaN,((x+o)/2-s)/n,((S+h)/2-i)/r),!0):([x,S,o,h,c,u]=l(this,it).subarray(0,6),l(this,wi).push(((x+5*o)/6-s)/n,((S+5*h)/6-i)/r,((5*o+c)/6-s)/n,((5*h+u)/6-i)/r,((o+c)/2-s)/n,((h+u)/2-i)/r),[c,u,o,h,x,S]=l(this,it).subarray(12,18),l(this,Ks).push(((x+5*o)/6-s)/n,((S+5*h)/6-i)/r,((5*o+c)/6-s)/n,((5*h+u)/6-i)/r,((o+c)/2-s)/n,((h+u)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";const t=l(this,wi),e=l(this,Ks);if(isNaN(l(this,it)[6])&&!this.isEmpty())return w(this,Jt,Xy).call(this);const s=[];s.push(`M${t[4]} ${t[5]}`);for(let i=6;i<t.length;i+=6)isNaN(t[i])?s.push(`L${t[i+4]} ${t[i+5]}`):s.push(`C${t[i]} ${t[i+1]} ${t[i+2]} ${t[i+3]} ${t[i+4]} ${t[i+5]}`);w(this,Jt,Uy).call(this,s);for(let i=e.length-6;i>=6;i-=6)isNaN(e[i])?s.push(`L${e[i+4]} ${e[i+5]}`):s.push(`C${e[i]} ${e[i+1]} ${e[i+2]} ${e[i+3]} ${e[i+4]} ${e[i+5]}`);return w(this,Jt,Wy).call(this,s),s.join(" ")}newFreeDrawOutline(t,e,s,i,n,r){return new Nb(t,e,s,i,n,r)}getOutlines(){var d;const t=l(this,wi),e=l(this,Ks),s=l(this,it),[i,n,r,o]=l(this,cs),h=new Float32Array((((d=l(this,sr))==null?void 0:d.length)??0)+2);for(let f=0,g=h.length-2;f<g;f+=2)h[f]=(l(this,sr)[f]-i)/r,h[f+1]=(l(this,sr)[f+1]-n)/o;if(h[h.length-2]=(l(this,So)-i)/r,h[h.length-1]=(l(this,Co)-n)/o,isNaN(s[6])&&!this.isEmpty())return w(this,Jt,Yy).call(this,h);const c=new Float32Array(l(this,wi).length+24+l(this,Ks).length);let u=t.length;for(let f=0;f<u;f+=2){if(isNaN(t[f])){c[f]=c[f+1]=NaN;continue}c[f]=t[f],c[f+1]=t[f+1]}u=w(this,Jt,qy).call(this,c,u);for(let f=e.length-6;f>=6;f-=6)for(let g=0;g<6;g+=2){if(isNaN(e[f+g])){c[u]=c[u+1]=NaN,u+=2;continue}c[u]=e[f+g],c[u+1]=e[f+g+1],u+=2}return w(this,Jt,$y).call(this,c,u),this.newFreeDrawOutline(c,h,l(this,cs),l(this,Ua),l(this,Xa),l(this,Wa))}};cs=new WeakMap,Ks=new WeakMap,Xa=new WeakMap,Wa=new WeakMap,wi=new WeakMap,it=new WeakMap,So=new WeakMap,Co=new WeakMap,nc=new WeakMap,rc=new WeakMap,Ua=new WeakMap,Ya=new WeakMap,sr=new WeakMap,oc=new WeakMap,wd=new WeakMap,xd=new WeakMap,Jt=new WeakSet,Oc=function(){const t=l(this,it).subarray(4,6),e=l(this,it).subarray(16,18),[s,i,n,r]=l(this,cs);return[(l(this,So)+(t[0]-e[0])/2-s)/n,(l(this,Co)+(t[1]-e[1])/2-i)/r,(l(this,So)+(e[0]-t[0])/2-s)/n,(l(this,Co)+(e[1]-t[1])/2-i)/r]},Xy=function(){const[t,e,s,i]=l(this,cs),[n,r,o,h]=w(this,Jt,Oc).call(this);return`M${(l(this,it)[2]-t)/s} ${(l(this,it)[3]-e)/i} L${(l(this,it)[4]-t)/s} ${(l(this,it)[5]-e)/i} L${n} ${r} L${o} ${h} L${(l(this,it)[16]-t)/s} ${(l(this,it)[17]-e)/i} L${(l(this,it)[14]-t)/s} ${(l(this,it)[15]-e)/i} Z`},Wy=function(t){const e=l(this,Ks);t.push(`L${e[4]} ${e[5]} Z`)},Uy=function(t){const[e,s,i,n]=l(this,cs),r=l(this,it).subarray(4,6),o=l(this,it).subarray(16,18),[h,c,u,d]=w(this,Jt,Oc).call(this);t.push(`L${(r[0]-e)/i} ${(r[1]-s)/n} L${h} ${c} L${u} ${d} L${(o[0]-e)/i} ${(o[1]-s)/n}`)},Yy=function(t){const e=l(this,it),[s,i,n,r]=l(this,cs),[o,h,c,u]=w(this,Jt,Oc).call(this),d=new Float32Array(36);return d.set([NaN,NaN,NaN,NaN,(e[2]-s)/n,(e[3]-i)/r,NaN,NaN,NaN,NaN,(e[4]-s)/n,(e[5]-i)/r,NaN,NaN,NaN,NaN,o,h,NaN,NaN,NaN,NaN,c,u,NaN,NaN,NaN,NaN,(e[16]-s)/n,(e[17]-i)/r,NaN,NaN,NaN,NaN,(e[14]-s)/n,(e[15]-i)/r],0),this.newFreeDrawOutline(d,t,l(this,cs),l(this,Ua),l(this,Xa),l(this,Wa))},$y=function(t,e){const s=l(this,Ks);return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6},qy=function(t,e){const s=l(this,it).subarray(4,6),i=l(this,it).subarray(16,18),[n,r,o,h]=l(this,cs),[c,u,d,f]=w(this,Jt,Oc).call(this);return t.set([NaN,NaN,NaN,NaN,(s[0]-n)/o,(s[1]-r)/h,NaN,NaN,NaN,NaN,c,u,NaN,NaN,NaN,NaN,d,f,NaN,NaN,NaN,NaN,(i[0]-n)/o,(i[1]-r)/h],e),e+=24},v(gn,oc,8),v(gn,wd,2),v(gn,xd,l(gn,oc)+l(gn,wd));let id=gn;class Nb extends H{constructor(e,s,i,n,r,o){super();v(this,Sd);v(this,$a);v(this,Ao,new Float32Array(4));v(this,pn);v(this,ac);v(this,us);v(this,hc);v(this,Ht);m(this,Ht,e),m(this,us,s),m(this,$a,i),m(this,hc,n),m(this,pn,r),m(this,ac,o),this.lastPoint=[NaN,NaN],w(this,Sd,Ky).call(this,o);const[h,c,u,d]=l(this,Ao);for(let f=0,g=e.length;f<g;f+=2)e[f]=(e[f]-h)/u,e[f+1]=(e[f+1]-c)/d;for(let f=0,g=s.length;f<g;f+=2)s[f]=(s[f]-h)/u,s[f+1]=(s[f+1]-c)/d}toSVGPath(){const e=[`M${l(this,Ht)[4]} ${l(this,Ht)[5]}`];for(let s=6,i=l(this,Ht).length;s<i;s+=6){if(isNaN(l(this,Ht)[s])){e.push(`L${l(this,Ht)[s+4]} ${l(this,Ht)[s+5]}`);continue}e.push(`C${l(this,Ht)[s]} ${l(this,Ht)[s+1]} ${l(this,Ht)[s+2]} ${l(this,Ht)[s+3]} ${l(this,Ht)[s+4]} ${l(this,Ht)[s+5]}`)}return e.push("Z"),e.join(" ")}serialize([e,s,i,n],r){const o=i-e,h=n-s;let c,u;switch(r){case 0:c=H._rescale(l(this,Ht),e,n,o,-h),u=H._rescale(l(this,us),e,n,o,-h);break;case 90:c=H._rescaleAndSwap(l(this,Ht),e,s,o,h),u=H._rescaleAndSwap(l(this,us),e,s,o,h);break;case 180:c=H._rescale(l(this,Ht),i,s,-o,h),u=H._rescale(l(this,us),i,s,-o,h);break;case 270:c=H._rescaleAndSwap(l(this,Ht),i,n,-o,-h),u=H._rescaleAndSwap(l(this,us),i,n,-o,-h);break}return{outline:Array.from(c),points:[Array.from(u)]}}get box(){return l(this,Ao)}newOutliner(e,s,i,n,r,o=0){return new id(e,s,i,n,r,o)}getNewOutline(e,s){const[i,n,r,o]=l(this,Ao),[h,c,u,d]=l(this,$a),f=r*u,g=o*d,p=i*u+h,b=n*d+c,_=this.newOutliner({x:l(this,us)[0]*f+p,y:l(this,us)[1]*g+b},l(this,$a),l(this,hc),e,l(this,ac),s??l(this,pn));for(let y=2;y<l(this,us).length;y+=2)_.add({x:l(this,us)[y]*f+p,y:l(this,us)[y+1]*g+b});return _.getOutlines()}}$a=new WeakMap,Ao=new WeakMap,pn=new WeakMap,ac=new WeakMap,us=new WeakMap,hc=new WeakMap,Ht=new WeakMap,Sd=new WeakSet,Ky=function(e){const s=l(this,Ht);let i=s[4],n=s[5],r=i,o=n,h=i,c=n,u=i,d=n;const f=e?Math.max:Math.min;for(let p=6,b=s.length;p<b;p+=6){if(isNaN(s[p]))r=Math.min(r,s[p+4]),o=Math.min(o,s[p+5]),h=Math.max(h,s[p+4]),c=Math.max(c,s[p+5]),d<s[p+5]?(u=s[p+4],d=s[p+5]):d===s[p+5]&&(u=f(u,s[p+4]));else{const _=U.bezierBoundingBox(i,n,...s.slice(p,p+6));r=Math.min(r,_[0]),o=Math.min(o,_[1]),h=Math.max(h,_[2]),c=Math.max(c,_[3]),d<_[3]?(u=_[2],d=_[3]):d===_[3]&&(u=f(u,_[2]))}i=s[p+4],n=s[p+5]}const g=l(this,Ao);g[0]=r-l(this,pn),g[1]=o-l(this,pn),g[2]=h-r+2*l(this,pn),g[3]=c-o+2*l(this,pn),this.lastPoint=[u,d]};class Lg{constructor(t,e=0,s=0,i=!0){v(this,Ie);v(this,lc);v(this,cc);v(this,ir,[]);v(this,Qs,[]);let n=1/0,r=-1/0,o=1/0,h=-1/0;const c=10**-4;for(const{x:_,y,width:x,height:S}of t){const C=Math.floor((_-e)/c)*c,E=Math.ceil((_+x+e)/c)*c,D=Math.floor((y-e)/c)*c,M=Math.ceil((y+S+e)/c)*c,k=[C,D,M,!0],O=[E,D,M,!1];l(this,ir).push(k,O),n=Math.min(n,C),r=Math.max(r,E),o=Math.min(o,D),h=Math.max(h,M)}const u=r-n+2*s,d=h-o+2*s,f=n-s,g=o-s,p=l(this,ir).at(i?-1:-2),b=[p[0],p[2]];for(const _ of l(this,ir)){const[y,x,S]=_;_[0]=(y-f)/u,_[1]=(x-g)/d,_[2]=(S-g)/d}m(this,lc,new Float32Array([f,g,u,d])),m(this,cc,b)}getOutlines(){l(this,ir).sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);const t=[];for(const e of l(this,ir))e[3]?(t.push(...w(this,Ie,Ep).call(this,e)),w(this,Ie,Jy).call(this,e)):(w(this,Ie,Zy).call(this,e),t.push(...w(this,Ie,Ep).call(this,e)));return w(this,Ie,Qy).call(this,t)}}lc=new WeakMap,cc=new WeakMap,ir=new WeakMap,Qs=new WeakMap,Ie=new WeakSet,Qy=function(t){const e=[],s=new Set;for(const r of t){const[o,h,c]=r;e.push([o,h,r],[o,c,r])}e.sort((r,o)=>r[1]-o[1]||r[0]-o[0]);for(let r=0,o=e.length;r<o;r+=2){const h=e[r][2],c=e[r+1][2];h.push(c),c.push(h),s.add(h),s.add(c)}const i=[];let n;for(;s.size>0;){const r=s.values().next().value;let[o,h,c,u,d]=r;s.delete(r);let f=o,g=h;for(n=[o,c],i.push(n);;){let p;if(s.has(u))p=u;else if(s.has(d))p=d;else break;s.delete(p),[o,h,c,u,d]=p,f!==o&&(n.push(f,g,o,g===h?h:c),f=o),g=g===h?c:h}n.push(f,g)}return new GS(i,l(this,lc),l(this,cc))},Yd=function(t){const e=l(this,Qs);let s=0,i=e.length-1;for(;s<=i;){const n=s+i>>1,r=e[n][0];if(r===t)return n;r<t?s=n+1:i=n-1}return i+1},Jy=function([,t,e]){const s=w(this,Ie,Yd).call(this,t);l(this,Qs).splice(s,0,[t,e])},Zy=function([,t,e]){const s=w(this,Ie,Yd).call(this,t);for(let i=s;i<l(this,Qs).length;i++){const[n,r]=l(this,Qs)[i];if(n!==t)break;if(n===t&&r===e){l(this,Qs).splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=l(this,Qs)[i];if(n!==t)break;if(n===t&&r===e){l(this,Qs).splice(i,1);return}}},Ep=function(t){const[e,s,i]=t,n=[[e,s,i]],r=w(this,Ie,Yd).call(this,i);for(let o=0;o<r;o++){const[h,c]=l(this,Qs)[o];for(let u=0,d=n.length;u<d;u++){const[,f,g]=n[u];if(!(c<=f||g<=h)){if(f>=h){if(g>c)n[u][1]=c;else{if(d===1)return[];n.splice(u,1),u--,d--}continue}n[u][2]=h,g>c&&n.push([e,c,g])}}}return n};class GS extends H{constructor(e,s,i){super();v(this,uc);v(this,qa);m(this,qa,e),m(this,uc,s),this.lastPoint=i}toSVGPath(){const e=[];for(const s of l(this,qa)){let[i,n]=s;e.push(`M${i} ${n}`);for(let r=2;r<s.length;r+=2){const o=s[r],h=s[r+1];o===i?(e.push(`V${h}`),n=h):h===n&&(e.push(`H${o}`),i=o)}e.push("Z")}return e.join(" ")}serialize([e,s,i,n],r){const o=[],h=i-e,c=n-s;for(const u of l(this,qa)){const d=new Array(u.length);for(let f=0;f<u.length;f+=2)d[f]=e+u[f]*h,d[f+1]=n-u[f+1]*c;o.push(d)}return o}get box(){return l(this,uc)}get classNamesForOutlining(){return["highlightOutline"]}}uc=new WeakMap,qa=new WeakMap;class Fg extends id{newFreeDrawOutline(t,e,s,i,n,r){return new VS(t,e,s,i,n,r)}}class VS extends Nb{newOutliner(t,e,s,i,n,r=0){return new Fg(t,e,s,i,n,r)}}const Ke=class Ke{constructor({editor:t=null,uiManager:e=null}){v(this,yt);v(this,Js,null);v(this,To,null);v(this,Ka);v(this,Zt,null);v(this,dc,!1);v(this,Qa,!1);v(this,fc,null);v(this,gc);v(this,nr,null);v(this,Zs,null);v(this,Ja);var s;t?(m(this,Qa,!1),m(this,Ja,ot.HIGHLIGHT_COLOR),m(this,fc,t)):(m(this,Qa,!0),m(this,Ja,ot.HIGHLIGHT_DEFAULT_COLOR)),m(this,Zs,(t==null?void 0:t._uiManager)||e),m(this,gc,l(this,Zs)._eventBus),m(this,Ka,(t==null?void 0:t.color)||((s=l(this,Zs))==null?void 0:s.highlightColors.values().next().value)||"#FFFF98"),l(Ke,pc)||m(Ke,pc,Object.freeze({blue:"pdfjs-editor-colorpicker-blue",green:"pdfjs-editor-colorpicker-green",pink:"pdfjs-editor-colorpicker-pink",red:"pdfjs-editor-colorpicker-red",yellow:"pdfjs-editor-colorpicker-yellow"}))}static get _keyboardManager(){return st(this,"_keyboardManager",new Xh([[["Escape","mac+Escape"],Ke.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],Ke.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],Ke.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],Ke.prototype._moveToPrevious],[["Home","mac+Home"],Ke.prototype._moveToBeginning],[["End","mac+End"],Ke.prototype._moveToEnd]]))}renderButton(){const t=m(this,Js,document.createElement("button"));t.className="colorPicker",t.tabIndex="0",t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-button"),t.setAttribute("aria-haspopup",!0);const e=l(this,Zs)._signal;t.addEventListener("click",w(this,yt,zo).bind(this),{signal:e}),t.addEventListener("keydown",w(this,yt,Pp).bind(this),{signal:e});const s=m(this,To,document.createElement("span"));return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=l(this,Ka),t.append(s),t}renderMainDropdown(){const t=m(this,Zt,w(this,yt,kp).call(this));return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}_colorSelectFromKeyboard(t){if(t.target===l(this,Js)){w(this,yt,zo).call(this,t);return}const e=t.target.getAttribute("data-color");e&&w(this,yt,Mp).call(this,e,t)}_moveToNext(t){var e,s;if(!l(this,yt,gr)){w(this,yt,zo).call(this,t);return}if(t.target===l(this,Js)){(e=l(this,Zt).firstChild)==null||e.focus();return}(s=t.target.nextSibling)==null||s.focus()}_moveToPrevious(t){var e,s;if(t.target===((e=l(this,Zt))==null?void 0:e.firstChild)||t.target===l(this,Js)){l(this,yt,gr)&&this._hideDropdownFromKeyboard();return}l(this,yt,gr)||w(this,yt,zo).call(this,t),(s=t.target.previousSibling)==null||s.focus()}_moveToBeginning(t){var e;if(!l(this,yt,gr)){w(this,yt,zo).call(this,t);return}(e=l(this,Zt).firstChild)==null||e.focus()}_moveToEnd(t){var e;if(!l(this,yt,gr)){w(this,yt,zo).call(this,t);return}(e=l(this,Zt).lastChild)==null||e.focus()}hideDropdown(){var t,e;(t=l(this,Zt))==null||t.classList.add("hidden"),(e=l(this,nr))==null||e.abort(),m(this,nr,null)}_hideDropdownFromKeyboard(){var t;if(!l(this,Qa)){if(!l(this,yt,gr)){(t=l(this,fc))==null||t.unselect();return}this.hideDropdown(),l(this,Js).focus({preventScroll:!0,focusVisible:l(this,dc)})}}updateColor(t){if(l(this,To)&&(l(this,To).style.backgroundColor=t),!l(this,Zt))return;const e=l(this,Zs).highlightColors.values();for(const s of l(this,Zt).children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){var t,e;(t=l(this,Js))==null||t.remove(),m(this,Js,null),m(this,To,null),(e=l(this,Zt))==null||e.remove(),m(this,Zt,null)}};Js=new WeakMap,To=new WeakMap,Ka=new WeakMap,Zt=new WeakMap,dc=new WeakMap,Qa=new WeakMap,fc=new WeakMap,gc=new WeakMap,nr=new WeakMap,Zs=new WeakMap,Ja=new WeakMap,pc=new WeakMap,yt=new WeakSet,kp=function(){const t=document.createElement("div"),e=l(this,Zs)._signal;t.addEventListener("contextmenu",zs,{signal:e}),t.className="dropdown",t.role="listbox",t.setAttribute("aria-multiselectable",!1),t.setAttribute("aria-orientation","vertical"),t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown");for(const[s,i]of l(this,Zs).highlightColors){const n=document.createElement("button");n.tabIndex="0",n.role="option",n.setAttribute("data-color",i),n.title=s,n.setAttribute("data-l10n-id",l(Ke,pc)[s]);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===l(this,Ka)),n.addEventListener("click",w(this,yt,Mp).bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",w(this,yt,Pp).bind(this),{signal:e}),t},Mp=function(t,e){e.stopPropagation(),l(this,gc).dispatch("switchannotationeditorparams",{source:this,type:l(this,Ja),value:t})},Pp=function(t){Ke._keyboardManager.exec(this,t)},zo=function(t){if(l(this,yt,gr)){this.hideDropdown();return}if(m(this,dc,t.detail===0),l(this,nr)||(m(this,nr,new AbortController),window.addEventListener("pointerdown",w(this,yt,tv).bind(this),{signal:l(this,Zs).combinedSignal(l(this,nr))})),l(this,Zt)){l(this,Zt).classList.remove("hidden");return}const e=m(this,Zt,w(this,yt,kp).call(this));l(this,Js).append(e)},tv=function(t){var e;(e=l(this,Zt))!=null&&e.contains(t.target)||this.hideDropdown()},gr=function(){return l(this,Zt)&&!l(this,Zt).classList.contains("hidden")},v(Ke,pc,null);let nd=Ke;const ut=class ut extends Pt{constructor(e){super({...e,name:"highlightEditor"});v(this,J);v(this,Za,null);v(this,mc,0);v(this,mn);v(this,Eo,null);v(this,th,null);v(this,Qe,null);v(this,bc,null);v(this,yc,0);v(this,ko,null);v(this,Ts,null);v(this,ds,null);v(this,le,!1);v(this,eh,null);v(this,bn);v(this,Se,null);v(this,sh,"");v(this,Es);v(this,vc,"");this.color=e.color||ut._defaultColor,m(this,Es,e.thickness||ut._defaultThickness),m(this,bn,e.opacity||ut._defaultOpacity),m(this,mn,e.boxes||null),m(this,vc,e.methodOfCreation||""),m(this,sh,e.text||""),this._isDraggable=!1,e.highlightId>-1?(m(this,le,!0),w(this,J,$d).call(this,e),w(this,J,Go).call(this)):l(this,mn)&&(m(this,Za,e.anchorNode),m(this,mc,e.anchorOffset),m(this,bc,e.focusNode),m(this,yc,e.focusOffset),w(this,J,Dp).call(this),w(this,J,Go).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const e=ut.prototype;return st(this,"_keyboardManager",new Xh([[["ArrowLeft","mac+ArrowLeft"],e._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],e._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],e._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],e._moveCaret,{args:[3]}]]))}get telemetryInitialData(){return{action:"added",type:l(this,le)?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:l(this,Es),methodOfCreation:l(this,vc)}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.highlightColorNames.get(this.color)}}static computeTelemetryFinalData(e){return{numberOfColors:e.get("color").size}}static initialize(e,s){var i;Pt.initialize(e,s),ut._defaultColor||(ut._defaultColor=((i=s.highlightColors)==null?void 0:i.values().next().value)||"#fff066")}static updateDefaultParams(e,s){switch(e){case ot.HIGHLIGHT_DEFAULT_COLOR:ut._defaultColor=s;break;case ot.HIGHLIGHT_THICKNESS:ut._defaultThickness=s;break}}translateInPage(e,s){}get toolbarPosition(){return l(this,eh)}updateParams(e,s){switch(e){case ot.HIGHLIGHT_COLOR:w(this,J,ev).call(this,s);break;case ot.HIGHLIGHT_THICKNESS:w(this,J,sv).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[ot.HIGHLIGHT_DEFAULT_COLOR,ut._defaultColor],[ot.HIGHLIGHT_THICKNESS,ut._defaultThickness]]}get propertiesToUpdate(){return[[ot.HIGHLIGHT_COLOR,this.color||ut._defaultColor],[ot.HIGHLIGHT_THICKNESS,l(this,Es)||ut._defaultThickness],[ot.HIGHLIGHT_FREE,l(this,le)]]}async addEditToolbar(){const e=await super.addEditToolbar();return e?(this._uiManager.highlightColors&&(m(this,th,new nd({editor:this})),e.addColorPicker(l(this,th))),e):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(w(this,J,Rc).call(this))}getBaseTranslation(){return[0,0]}getRect(e,s){return super.getRect(e,s,w(this,J,Rc).call(this))}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),e&&this.div.focus()}remove(){w(this,J,Op).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,J,Go).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?w(this,J,Op).call(this):e&&(w(this,J,Go).call(this,e),s=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),this.show(this._isVisible),s&&this.select()}rotate(e){var n,r,o;const{drawLayer:s}=this.parent;let i;l(this,le)?(e=(e-this.rotation+360)%360,i=w(n=ut,ks,_h).call(n,l(this,Ts).box,e)):i=w(r=ut,ks,_h).call(r,[this.x,this.y,this.width,this.height],e),s.updateProperties(l(this,ds),{bbox:i,root:{"data-main-rotation":e}}),s.updateProperties(l(this,Se),{bbox:w(o=ut,ks,_h).call(o,l(this,Qe).box,e),root:{"data-main-rotation":e}})}render(){if(this.div)return this.div;const e=super.render();l(this,sh)&&(e.setAttribute("aria-label",l(this,sh)),e.setAttribute("role","mark")),l(this,le)?e.classList.add("free"):this.div.addEventListener("keydown",w(this,J,nv).bind(this),{signal:this._uiManager._signal});const s=m(this,ko,document.createElement("div"));e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",s.style.clipPath=l(this,Eo);const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),$u(this,l(this,ko),["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Se),{rootClass:{hovered:!0}})}pointerleave(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Se),{rootClass:{hovered:!1}})}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:w(this,J,qd).call(this,!0);break;case 1:case 3:w(this,J,qd).call(this,!1);break}}select(){var e;super.select(),l(this,Se)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Se),{rootClass:{hovered:!1,selected:!0}}))}unselect(){var e;super.unselect(),l(this,Se)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Se),{rootClass:{selected:!1}}),l(this,le)||w(this,J,qd).call(this,!1))}get _mustFixPosition(){return!l(this,le)}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.updateProperties(l(this,ds),{rootClass:{hidden:!e}}),this.parent.drawLayer.updateProperties(l(this,Se),{rootClass:{hidden:!e}}))}static startHighlighting(e,s,{target:i,x:n,y:r}){const{x:o,y:h,width:c,height:u}=i.getBoundingClientRect(),d=new AbortController,f=e.combinedSignal(d),g=p=>{d.abort(),w(this,ks,hv).call(this,e,p)};window.addEventListener("blur",g,{signal:f}),window.addEventListener("pointerup",g,{signal:f}),window.addEventListener("pointerdown",es,{capture:!0,passive:!1,signal:f}),window.addEventListener("contextmenu",zs,{signal:f}),i.addEventListener("pointermove",w(this,ks,av).bind(this,e),{signal:f}),this._freeHighlight=new Fg({x:n,y:r},[o,h,c,u],e.scale,this._defaultThickness/2,s,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0)}static async deserialize(e,s,i){var b,_,y,x;let n=null;if(e instanceof Fb){const{data:{quadPoints:S,rect:C,rotation:E,id:D,color:M,opacity:k,popupRef:O},parent:{page:{pageNumber:R}}}=e;n=e={annotationType:Z.HIGHLIGHT,color:Array.from(M),opacity:k,quadPoints:S,boxes:null,pageIndex:R-1,rect:C.slice(0),rotation:E,id:D,deleted:!1,popupRef:O}}else if(e instanceof Og){const{data:{inkLists:S,rect:C,rotation:E,id:D,color:M,borderStyle:{rawWidth:k},popupRef:O},parent:{page:{pageNumber:R}}}=e;n=e={annotationType:Z.HIGHLIGHT,color:Array.from(M),thickness:k,inkLists:S,boxes:null,pageIndex:R-1,rect:C.slice(0),rotation:E,id:D,deleted:!1,popupRef:O}}const{color:r,quadPoints:o,inkLists:h,opacity:c}=e,u=await super.deserialize(e,s,i);u.color=U.makeHexColor(...r),m(u,bn,c||1),h&&m(u,Es,e.thickness),u.annotationElementId=e.id||null,u._initialData=n;const[d,f]=u.pageDimensions,[g,p]=u.pageTranslation;if(o){const S=m(u,mn,[]);for(let C=0;C<o.length;C+=8)S.push({x:(o[C]-g)/d,y:1-(o[C+1]-p)/f,width:(o[C+2]-o[C])/d,height:(o[C+1]-o[C+5])/f});w(b=u,J,Dp).call(b),w(_=u,J,Go).call(_),u.rotate(u.rotation)}else if(h){m(u,le,!0);const S=h[0],C={x:S[0]-g,y:f-(S[1]-p)},E=new Fg(C,[0,0,d,f],1,l(u,Es)/2,!0,.001);for(let k=0,O=S.length;k<O;k+=2)C.x=S[k]-g,C.y=f-(S[k+1]-p),E.add(C);const{id:D,clipPathId:M}=s.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:u.color,"fill-opacity":u._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:E.toSVGPath()}},!0,!0);w(y=u,J,$d).call(y,{highlightOutlines:E.getOutlines(),highlightId:D,clipPathId:M}),w(x=u,J,Go).call(x)}return u}serialize(e=!1){if(this.isEmpty()||e)return null;if(this.deleted)return this.serializeDeleted();const s=this.getRect(0,0),i=Pt._colorManager.convert(this.color),n={annotationType:Z.HIGHLIGHT,color:i,opacity:l(this,bn),thickness:l(this,Es),quadPoints:w(this,J,rv).call(this),outlines:w(this,J,ov).call(this,s),pageIndex:this.pageIndex,rect:s,rotation:w(this,J,Rc).call(this),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!w(this,J,lv).call(this,n)?null:(n.id=this.annotationElementId,n)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};Za=new WeakMap,mc=new WeakMap,mn=new WeakMap,Eo=new WeakMap,th=new WeakMap,Qe=new WeakMap,bc=new WeakMap,yc=new WeakMap,ko=new WeakMap,Ts=new WeakMap,ds=new WeakMap,le=new WeakMap,eh=new WeakMap,bn=new WeakMap,Se=new WeakMap,sh=new WeakMap,Es=new WeakMap,vc=new WeakMap,J=new WeakSet,Dp=function(){const e=new Lg(l(this,mn),.001);m(this,Ts,e.getOutlines()),[this.x,this.y,this.width,this.height]=l(this,Ts).box;const s=new Lg(l(this,mn),.0025,.001,this._uiManager.direction==="ltr");m(this,Qe,s.getOutlines());const{lastPoint:i}=l(this,Qe);m(this,eh,[(i[0]-this.x)/this.width,(i[1]-this.y)/this.height])},$d=function({highlightOutlines:e,highlightId:s,clipPathId:i}){var d,f;if(m(this,Ts,e),m(this,Qe,e.getNewOutline(l(this,Es)/2+1.5,.0025)),s>=0)m(this,ds,s),m(this,Eo,i),this.parent.drawLayer.finalizeDraw(s,{bbox:e.box,path:{d:e.toSVGPath()}}),m(this,Se,this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:l(this,Qe).box,path:{d:l(this,Qe).toSVGPath()}},!0));else if(this.parent){const g=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(l(this,ds),{bbox:w(d=ut,ks,_h).call(d,l(this,Ts).box,(g-this.rotation+360)%360),path:{d:e.toSVGPath()}}),this.parent.drawLayer.updateProperties(l(this,Se),{bbox:w(f=ut,ks,_h).call(f,l(this,Qe).box,g),path:{d:l(this,Qe).toSVGPath()}})}const[r,o,h,c]=e.box;switch(this.rotation){case 0:this.x=r,this.y=o,this.width=h,this.height=c;break;case 90:{const[g,p]=this.parentDimensions;this.x=o,this.y=1-r,this.width=h*p/g,this.height=c*g/p;break}case 180:this.x=1-r,this.y=1-o,this.width=h,this.height=c;break;case 270:{const[g,p]=this.parentDimensions;this.x=1-o,this.y=r,this.width=h*p/g,this.height=c*g/p;break}}const{lastPoint:u}=l(this,Qe);m(this,eh,[(u[0]-r)/h,(u[1]-o)/c])},ev=function(e){const s=(r,o)=>{var h,c;this.color=r,m(this,bn,o),(h=this.parent)==null||h.drawLayer.updateProperties(l(this,ds),{root:{fill:r,"fill-opacity":o}}),(c=l(this,th))==null||c.updateColor(r)},i=this.color,n=l(this,bn);this.addCommands({cmd:s.bind(this,e,ut._defaultOpacity),undo:s.bind(this,i,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:ot.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(e)},!0)},sv=function(e){const s=l(this,Es),i=n=>{m(this,Es,n),w(this,J,iv).call(this,n)};this.addCommands({cmd:i.bind(this,e),undo:i.bind(this,s),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:ot.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)},iv=function(e){if(!l(this,le))return;w(this,J,$d).call(this,{highlightOutlines:l(this,Ts).getNewOutline(e/2)}),this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)},Op=function(){l(this,ds)===null||!this.parent||(this.parent.drawLayer.remove(l(this,ds)),m(this,ds,null),this.parent.drawLayer.remove(l(this,Se)),m(this,Se,null))},Go=function(e=this.parent){l(this,ds)===null&&({id:ze(this,ds)._,clipPathId:ze(this,Eo)._}=e.drawLayer.draw({bbox:l(this,Ts).box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":l(this,bn)},rootClass:{highlight:!0,free:l(this,le)},path:{d:l(this,Ts).toSVGPath()}},!1,!0),m(this,Se,e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:l(this,le)},bbox:l(this,Qe).box,path:{d:l(this,Qe).toSVGPath()}},l(this,le))),l(this,ko)&&(l(this,ko).style.clipPath=l(this,Eo)))},ks=new WeakSet,_h=function([e,s,i,n],r){switch(r){case 90:return[1-s-n,e,n,i];case 180:return[1-e-i,1-s-n,i,n];case 270:return[s,1-e-i,n,i]}return[e,s,i,n]},nv=function(e){ut._keyboardManager.exec(this,e)},qd=function(e){if(!l(this,Za))return;const s=window.getSelection();e?s.setPosition(l(this,Za),l(this,mc)):s.setPosition(l(this,bc),l(this,yc))},Rc=function(){return l(this,le)?this.rotation:0},rv=function(){if(l(this,le))return null;const[e,s]=this.pageDimensions,[i,n]=this.pageTranslation,r=l(this,mn),o=new Float32Array(r.length*8);let h=0;for(const{x:c,y:u,width:d,height:f}of r){const g=c*e+i,p=(1-u)*s+n;o[h]=o[h+4]=g,o[h+1]=o[h+3]=p,o[h+2]=o[h+6]=g+d*e,o[h+5]=o[h+7]=p-f*s,h+=8}return o},ov=function(e){return l(this,Ts).serialize(e,w(this,J,Rc).call(this))},av=function(e,s){this._freeHighlight.add(s)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})},hv=function(e,s){this._freeHighlight.isEmpty()?e.drawLayer.remove(this._freeHighlightId):e.createAndAddNewEditor(s,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:"main_toolbar"}),this._freeHighlightId=-1,this._freeHighlight=null,this._freeHighlightClipId=""},lv=function(e){const{color:s}=this._initialData;return e.color.some((i,n)=>i!==s[n])},v(ut,ks),$(ut,"_defaultColor",null),$(ut,"_defaultOpacity",1),$(ut,"_defaultThickness",12),$(ut,"_type","highlight"),$(ut,"_editorType",Z.HIGHLIGHT),$(ut,"_freeHighlightId",-1),$(ut,"_freeHighlight",null),$(ut,"_freeHighlightClipId","");let rd=ut;class XS{constructor(){v(this,Mo,Object.create(null))}updateProperty(t,e){this[t]=e,this.updateSVGProperty(t,e)}updateProperties(t){if(t)for(const[e,s]of Object.entries(t))this.updateProperty(e,s)}updateSVGProperty(t,e){l(this,Mo)[t]=e}toSVGProperties(){const t=l(this,Mo);return m(this,Mo,Object.create(null)),{root:t}}reset(){m(this,Mo,Object.create(null))}updateAll(t=this){this.updateProperties(t)}clone(){vt("Not implemented")}}Mo=new WeakMap;const z=class z extends Pt{constructor(e){super(e);v(this,lt);v(this,fs,null);v(this,ih);$(this,"_drawId",null);m(this,ih,e.mustBeCommitted||!1),e.drawOutlines&&(w(this,lt,Rp).call(this,e),w(this,lt,Lc).call(this))}static _mergeSVGProperties(e,s){const i=new Set(Object.keys(e));for(const[n,r]of Object.entries(s))i.has(n)?Object.assign(e[n],r):e[n]=r;return e}static getDefaultDrawingOptions(e){vt("Not implemented")}static get typesMap(){vt("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(e,s){const i=this.typesMap.get(e);i&&this._defaultDrawingOptions.updateProperty(i,s),this._currentParent&&(l(z,ne).updateProperty(i,s),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(e,s){const i=this.constructor.typesMap.get(e);i&&this._updateProperty(e,i,s)}static get defaultPropertiesToUpdate(){const e=[],s=this._defaultDrawingOptions;for(const[i,n]of this.typesMap)e.push([i,s[n]]);return e}get propertiesToUpdate(){const e=[],{_drawingOptions:s}=this;for(const[i,n]of this.constructor.typesMap)e.push([i,s[n]]);return e}_updateProperty(e,s,i){const n=this._drawingOptions,r=n[s],o=h=>{var u;n.updateProperty(s,h);const c=l(this,fs).updateProperty(s,h);c&&w(this,lt,Fc).call(this,c),(u=this.parent)==null||u.drawLayer.updateProperties(this._drawId,n.toSVGProperties())};this.addCommands({cmd:o.bind(this,i),undo:o.bind(this,r),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:e,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,z._mergeSVGProperties(l(this,fs).getPathResizingSVGProperties(w(this,lt,Kd).call(this)),{bbox:w(this,lt,wh).call(this)}))}_onResized(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,z._mergeSVGProperties(l(this,fs).getPathResizedSVGProperties(w(this,lt,Kd).call(this)),{bbox:w(this,lt,wh).call(this)}))}_onTranslating(e,s){var i;(i=this.parent)==null||i.drawLayer.updateProperties(this._drawId,{bbox:w(this,lt,wh).call(this,e,s)})}_onTranslated(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,z._mergeSVGProperties(l(this,fs).getPathTranslatedSVGProperties(w(this,lt,Kd).call(this),this.parentDimensions),{bbox:w(this,lt,wh).call(this)}))}_onStartDragging(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}commit(){super.commit(),this.disableEditMode(),this.disableEditing()}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),this._isDraggable=!0,l(this,ih)&&(m(this,ih,!1),this.commit(),this.parent.setSelected(this),e&&this.isOnScreen&&this.div.focus())}remove(){w(this,lt,Fp).call(this),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,lt,Lc).call(this),w(this,lt,Fc).call(this,l(this,fs).box),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?(this._uiManager.removeShouldRescale(this),w(this,lt,Fp).call(this)):e&&(this._uiManager.addShouldRescale(this),w(this,lt,Lc).call(this,e),s=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),s&&this.select()}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,z._mergeSVGProperties({bbox:w(this,lt,wh).call(this)},l(this,fs).updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&w(this,lt,Fc).call(this,l(this,fs).updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;const e=super.render();e.classList.add("draw");const s=document.createElement("div");e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal";const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),this._uiManager.addShouldRescale(this),this.disableEditing(),e}static createDrawerInstance(e,s,i,n,r){vt("Not implemented")}static startDrawing(e,s,i,n){var _;const{target:r,offsetX:o,offsetY:h,pointerId:c,pointerType:u}=n;if(l(z,or)&&l(z,or)!==u)return;const{viewport:{rotation:d}}=e,{width:f,height:g}=r.getBoundingClientRect(),p=m(z,Po,new AbortController),b=e.combinedSignal(p);if(l(z,rr)||m(z,rr,c),l(z,or)??m(z,or,u),window.addEventListener("pointerup",y=>{var x;l(z,rr)===y.pointerId?this._endDraw(y):(x=l(z,ar))==null||x.delete(y.pointerId)},{signal:b}),window.addEventListener("pointercancel",y=>{var x;l(z,rr)===y.pointerId?this._currentParent.endDrawingSession():(x=l(z,ar))==null||x.delete(y.pointerId)},{signal:b}),window.addEventListener("pointerdown",y=>{l(z,or)===y.pointerType&&((l(z,ar)||m(z,ar,new Set)).add(y.pointerId),l(z,ne).isCancellable()&&(l(z,ne).removeLastElement(),l(z,ne).isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:b}),window.addEventListener("contextmenu",zs,{signal:b}),r.addEventListener("pointermove",this._drawMove.bind(this),{signal:b}),r.addEventListener("touchmove",y=>{y.timeStamp===l(z,Oo)&&es(y)},{signal:b}),e.toggleDrawing(),(_=s._editorUndoBar)==null||_.hide(),l(z,ne)){e.drawLayer.updateProperties(this._currentDrawId,l(z,ne).startNew(o,h,f,g,d));return}s.updateUIForDefaultProperties(this),m(z,ne,this.createDrawerInstance(o,h,f,g,d)),m(z,Do,this.getDefaultDrawingOptions()),this._currentParent=e,{id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties(l(z,Do).toSVGProperties(),l(z,ne).defaultSVGProperties),!0,!1)}static _drawMove(e){var r;if(m(z,Oo,-1),!l(z,ne))return;const{offsetX:s,offsetY:i,pointerId:n}=e;if(l(z,rr)===n){if(((r=l(z,ar))==null?void 0:r.size)>=1){this._endDraw(e);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,l(z,ne).add(s,i)),m(z,Oo,e.timeStamp),es(e)}}static _cleanup(e){e&&(this._currentDrawId=-1,this._currentParent=null,m(z,ne,null),m(z,Do,null),m(z,or,null),m(z,Oo,NaN)),l(z,Po)&&(l(z,Po).abort(),m(z,Po,null),m(z,rr,NaN),m(z,ar,null))}static _endDraw(e){const s=this._currentParent;if(s){if(s.toggleDrawing(!0),this._cleanup(!1),e&&s.drawLayer.updateProperties(this._currentDrawId,l(z,ne).end(e.offsetX,e.offsetY)),this.supportMultipleDrawings){const i=l(z,ne),n=this._currentDrawId,r=i.getLastElement();s.addCommands({cmd:()=>{s.drawLayer.updateProperties(n,i.setLastElement(r))},undo:()=>{s.drawLayer.updateProperties(n,i.removeLastElement())},mustExec:!1,type:ot.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(e){const s=this._currentParent;if(!s)return null;if(s.toggleDrawing(!0),s.cleanUndoStack(ot.DRAW_STEP),!l(z,ne).isEmpty()){const{pageDimensions:[i,n],scale:r}=s,o=s.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:l(z,ne).getOutlines(i*r,n*r,r,this._INNER_MARGIN),drawingOptions:l(z,Do),mustBeCommitted:!e});return this._cleanup(!0),o}return s.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(e){}static deserializeDraw(e,s,i,n,r,o){vt("Not implemented")}static async deserialize(e,s,i){var d,f;const{rawDims:{pageWidth:n,pageHeight:r,pageX:o,pageY:h}}=s.viewport,c=this.deserializeDraw(o,h,n,r,this._INNER_MARGIN,e),u=await super.deserialize(e,s,i);return u.createDrawingOptions(e),w(d=u,lt,Rp).call(d,{drawOutlines:c}),w(f=u,lt,Lc).call(f),u.onScaleChanging(),u.rotate(),u}serializeDraw(e){const[s,i]=this.pageTranslation,[n,r]=this.pageDimensions;return l(this,fs).serialize([s,i,n,r],e)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};fs=new WeakMap,ih=new WeakMap,ne=new WeakMap,Po=new WeakMap,Do=new WeakMap,rr=new WeakMap,or=new WeakMap,ar=new WeakMap,Oo=new WeakMap,lt=new WeakSet,Rp=function({drawOutlines:e,drawId:s,drawingOptions:i}){m(this,fs,e),this._drawingOptions||(this._drawingOptions=i),s>=0?(this._drawId=s,this.parent.drawLayer.finalizeDraw(s,e.defaultProperties)):this._drawId=w(this,lt,Lp).call(this,e,this.parent),w(this,lt,Fc).call(this,e.box)},Lp=function(e,s){const{id:i}=s.drawLayer.draw(z._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return i},Fp=function(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())},Lc=function(e=this.parent){if(!(this._drawId!==null&&this.parent===e)){if(this._drawId!==null){this.parent.drawLayer.updateParent(this._drawId,e.drawLayer);return}this._drawingOptions.updateAll(),this._drawId=w(this,lt,Lp).call(this,l(this,fs),e)}},cv=function([e,s,i,n]){const{parentDimensions:[r,o],rotation:h}=this;switch(h){case 90:return[s,1-e,i*(o/r),n*(r/o)];case 180:return[1-e,1-s,i,n];case 270:return[1-s,e,i*(o/r),n*(r/o)];default:return[e,s,i,n]}},Kd=function(){const{x:e,y:s,width:i,height:n,parentDimensions:[r,o],rotation:h}=this;switch(h){case 90:return[1-s,e,i*(r/o),n*(o/r)];case 180:return[1-e,1-s,i,n];case 270:return[s,1-e,i*(r/o),n*(o/r)];default:return[e,s,i,n]}},Fc=function(e){if([this.x,this.y,this.width,this.height]=w(this,lt,cv).call(this,e),this.div){this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)}this._onResized()},wh=function(){const{x:e,y:s,width:i,height:n,rotation:r,parentRotation:o,parentDimensions:[h,c]}=this;switch((r*4+o)/90){case 1:return[1-s-n,e,n,i];case 2:return[1-e-i,1-s-n,i,n];case 3:return[s,1-e-i,n,i];case 4:return[e,s-i*(h/c),n*(c/h),i*(h/c)];case 5:return[1-s,e,i*(h/c),n*(c/h)];case 6:return[1-e-n*(c/h),1-s,n*(c/h),i*(h/c)];case 7:return[s-i*(h/c),1-e-n*(c/h),i*(h/c),n*(c/h)];case 8:return[e-i,s-n,i,n];case 9:return[1-s,e-i,n,i];case 10:return[1-e,1-s,i,n];case 11:return[s-n,1-e,n,i];case 12:return[e-n*(c/h),s,n*(c/h),i*(h/c)];case 13:return[1-s-i*(h/c),e-n*(c/h),i*(h/c),n*(c/h)];case 14:return[1-e,1-s-i*(h/c),n*(c/h),i*(h/c)];case 15:return[s,1-e,i*(h/c),n*(c/h)];default:return[e,s,i,n]}},$(z,"_currentDrawId",-1),$(z,"_currentParent",null),v(z,ne,null),v(z,Po,null),v(z,Do,null),v(z,rr,NaN),v(z,or,null),v(z,ar,null),v(z,Oo,NaN),$(z,"_INNER_MARGIN",3);let Ig=z;class WS{constructor(t,e,s,i,n,r){v(this,rh);v(this,xi,new Float64Array(6));v(this,re);v(this,oe);v(this,Ro);v(this,nh);v(this,Ne);v(this,ce,"");v(this,Ms,0);v(this,Lo,new od);v(this,Fo);v(this,Io);m(this,Fo,s),m(this,Io,i),m(this,Ro,n),m(this,nh,r),[t,e]=w(this,rh,Qd).call(this,t,e);const o=m(this,re,[NaN,NaN,NaN,NaN,t,e]);m(this,Ne,[t,e]),m(this,oe,[{line:o,points:l(this,Ne)}]),l(this,xi).set(o,0)}updateProperty(t,e){t==="stroke-width"&&m(this,nh,e)}isEmpty(){return!l(this,oe)||l(this,oe).length===0}isCancellable(){return l(this,Ne).length<=10}add(t,e){[t,e]=w(this,rh,Qd).call(this,t,e);const[s,i,n,r]=l(this,xi).subarray(2,6),o=t-n,h=e-r;return Math.hypot(l(this,Fo)*o,l(this,Io)*h)<=2?null:(l(this,Ne).push(t,e),isNaN(s)?(l(this,xi).set([n,r,t,e],2),l(this,re).push(NaN,NaN,NaN,NaN,t,e),{path:{d:this.toSVGPath()}}):(isNaN(l(this,xi)[0])&&l(this,re).splice(6,6),l(this,xi).set([s,i,n,r,t,e],0),l(this,re).push(...H.createBezierPoints(s,i,n,r,t,e)),{path:{d:this.toSVGPath()}}))}end(t,e){const s=this.add(t,e);return s||(l(this,Ne).length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,s,i,n){m(this,Fo,s),m(this,Io,i),m(this,Ro,n),[t,e]=w(this,rh,Qd).call(this,t,e);const r=m(this,re,[NaN,NaN,NaN,NaN,t,e]);m(this,Ne,[t,e]);const o=l(this,oe).at(-1);return o&&(o.line=new Float32Array(o.line),o.points=new Float32Array(o.points)),l(this,oe).push({line:r,points:l(this,Ne)}),l(this,xi).set(r,0),m(this,Ms,0),this.toSVGPath(),null}getLastElement(){return l(this,oe).at(-1)}setLastElement(t){return l(this,oe)?(l(this,oe).push(t),m(this,re,t.line),m(this,Ne,t.points),m(this,Ms,0),{path:{d:this.toSVGPath()}}):l(this,Lo).setLastElement(t)}removeLastElement(){if(!l(this,oe))return l(this,Lo).removeLastElement();l(this,oe).pop(),m(this,ce,"");for(let t=0,e=l(this,oe).length;t<e;t++){const{line:s,points:i}=l(this,oe)[t];m(this,re,s),m(this,Ne,i),m(this,Ms,0),this.toSVGPath()}return{path:{d:l(this,ce)}}}toSVGPath(){const t=H.svgRound(l(this,re)[4]),e=H.svgRound(l(this,re)[5]);if(l(this,Ne).length===2)return m(this,ce,`${l(this,ce)} M ${t} ${e} Z`),l(this,ce);if(l(this,Ne).length<=6){const i=l(this,ce).lastIndexOf("M");m(this,ce,`${l(this,ce).slice(0,i)} M ${t} ${e}`),m(this,Ms,6)}if(l(this,Ne).length===4){const i=H.svgRound(l(this,re)[10]),n=H.svgRound(l(this,re)[11]);return m(this,ce,`${l(this,ce)} L ${i} ${n}`),m(this,Ms,12),l(this,ce)}const s=[];l(this,Ms)===0&&(s.push(`M ${t} ${e}`),m(this,Ms,6));for(let i=l(this,Ms),n=l(this,re).length;i<n;i+=6){const[r,o,h,c,u,d]=l(this,re).slice(i,i+6).map(H.svgRound);s.push(`C${r} ${o} ${h} ${c} ${u} ${d}`)}return m(this,ce,l(this,ce)+s.join(" ")),m(this,Ms,l(this,re).length),l(this,ce)}getOutlines(t,e,s,i){const n=l(this,oe).at(-1);return n.line=new Float32Array(n.line),n.points=new Float32Array(n.points),l(this,Lo).build(l(this,oe),t,e,s,l(this,Ro),l(this,nh),i),m(this,xi,null),m(this,re,null),m(this,oe,null),m(this,ce,null),l(this,Lo)}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}xi=new WeakMap,re=new WeakMap,oe=new WeakMap,Ro=new WeakMap,nh=new WeakMap,Ne=new WeakMap,ce=new WeakMap,Ms=new WeakMap,Lo=new WeakMap,Fo=new WeakMap,Io=new WeakMap,rh=new WeakSet,Qd=function(t,e){return H._normalizePoint(t,e,l(this,Fo),l(this,Io),l(this,Ro))};const Ug=class Ug extends H{constructor(){super(...arguments);v(this,ue);v(this,je);v(this,_c,0);v(this,wc);v(this,gs);v(this,Si);v(this,Ci);v(this,oh);v(this,ah);v(this,hh)}build(e,s,i,n,r,o,h){m(this,Si,s),m(this,Ci,i),m(this,oh,n),m(this,ah,r),m(this,hh,o),m(this,wc,h??0),m(this,gs,e),w(this,ue,dv).call(this)}setLastElement(e){return l(this,gs).push(e),{path:{d:this.toSVGPath()}}}removeLastElement(){return l(this,gs).pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const e=[];for(const{line:s}of l(this,gs)){if(e.push(`M${H.svgRound(s[4])} ${H.svgRound(s[5])}`),s.length===6){e.push("Z");continue}if(s.length===12){e.push(`L${H.svgRound(s[10])} ${H.svgRound(s[11])}`);continue}for(let i=6,n=s.length;i<n;i+=6){const[r,o,h,c,u,d]=s.subarray(i,i+6).map(H.svgRound);e.push(`C${r} ${o} ${h} ${c} ${u} ${d}`)}}return e.join("")}serialize([e,s,i,n],r){const o=[],h=[],[c,u,d,f]=w(this,ue,uv).call(this);let g,p,b,_,y,x,S,C,E;switch(l(this,ah)){case 0:E=H._rescale,g=e,p=s+n,b=i,_=-n,y=e+c*i,x=s+(1-u-f)*n,S=e+(c+d)*i,C=s+(1-u)*n;break;case 90:E=H._rescaleAndSwap,g=e,p=s,b=i,_=n,y=e+u*i,x=s+c*n,S=e+(u+f)*i,C=s+(c+d)*n;break;case 180:E=H._rescale,g=e+i,p=s,b=-i,_=n,y=e+(1-c-d)*i,x=s+u*n,S=e+(1-c)*i,C=s+(u+f)*n;break;case 270:E=H._rescaleAndSwap,g=e+i,p=s+n,b=-i,_=-n,y=e+(1-u-f)*i,x=s+(1-c-d)*n,S=e+(1-u)*i,C=s+(1-c)*n;break}for(const{line:D,points:M}of l(this,gs))o.push(E(D,g,p,b,_,r?new Array(D.length):null)),h.push(E(M,g,p,b,_,r?new Array(M.length):null));return{lines:o,points:h,rect:[y,x,S,C]}}static deserialize(e,s,i,n,r,{paths:{lines:o,points:h},rotation:c,thickness:u}){const d=[];let f,g,p,b,_;switch(c){case 0:_=H._rescale,f=-e/i,g=s/n+1,p=1/i,b=-1/n;break;case 90:_=H._rescaleAndSwap,f=-s/n,g=-e/i,p=1/n,b=1/i;break;case 180:_=H._rescale,f=e/i+1,g=-s/n,p=-1/i,b=1/n;break;case 270:_=H._rescaleAndSwap,f=s/n+1,g=e/i+1,p=-1/n,b=-1/i;break}if(!o){o=[];for(const x of h){const S=x.length;if(S===2){o.push(new Float32Array([NaN,NaN,NaN,NaN,x[0],x[1]]));continue}if(S===4){o.push(new Float32Array([NaN,NaN,NaN,NaN,x[0],x[1],NaN,NaN,NaN,NaN,x[2],x[3]]));continue}const C=new Float32Array(3*(S-2));o.push(C);let[E,D,M,k]=x.subarray(0,4);C.set([NaN,NaN,NaN,NaN,E,D],0);for(let O=4;O<S;O+=2){const R=x[O],L=x[O+1];C.set(H.createBezierPoints(E,D,M,k,R,L),(O-2)*3),[E,D,M,k]=[M,k,R,L]}}}for(let x=0,S=o.length;x<S;x++)d.push({line:_(o[x].map(C=>C??NaN),f,g,p,b),points:_(h[x].map(C=>C??NaN),f,g,p,b)});const y=new Ug;return y.build(d,i,n,1,c,u,r),y}get box(){return l(this,je)}updateProperty(e,s){return e==="stroke-width"?w(this,ue,fv).call(this,s):null}updateParentDimensions([e,s],i){const[n,r]=w(this,ue,Sn).call(this);m(this,Si,e),m(this,Ci,s),m(this,oh,i);const[o,h]=w(this,ue,Sn).call(this),c=o-n,u=h-r,d=l(this,je);return d[0]-=c,d[1]-=u,d[2]+=2*c,d[3]+=2*u,d}updateRotation(e){return m(this,_c,e),{path:{transform:this.rotationTransform}}}get viewBox(){return l(this,je).map(H.svgRound).join(" ")}get defaultProperties(){const[e,s]=l(this,je);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${H.svgRound(e)} ${H.svgRound(s)}`}}}get rotationTransform(){const[,,e,s]=l(this,je);let i=0,n=0,r=0,o=0,h=0,c=0;switch(l(this,_c)){case 90:n=s/e,r=-e/s,h=e;break;case 180:i=-1,o=-1,h=e,c=s;break;case 270:n=-s/e,r=e/s,c=s;break;default:return""}return`matrix(${i} ${n} ${r} ${o} ${H.svgRound(h)} ${H.svgRound(c)})`}getPathResizingSVGProperties([e,s,i,n]){const[r,o]=w(this,ue,Sn).call(this),[h,c,u,d]=l(this,je);if(Math.abs(u-r)<=H.PRECISION||Math.abs(d-o)<=H.PRECISION){const _=e+i/2-(h+u/2),y=s+n/2-(c+d/2);return{path:{"transform-origin":`${H.svgRound(e)} ${H.svgRound(s)}`,transform:`${this.rotationTransform} translate(${_} ${y})`}}}const f=(i-2*r)/(u-2*r),g=(n-2*o)/(d-2*o),p=u/i,b=d/n;return{path:{"transform-origin":`${H.svgRound(h)} ${H.svgRound(c)}`,transform:`${this.rotationTransform} scale(${p} ${b}) translate(${H.svgRound(r)} ${H.svgRound(o)}) scale(${f} ${g}) translate(${H.svgRound(-r)} ${H.svgRound(-o)})`}}}getPathResizedSVGProperties([e,s,i,n]){const[r,o]=w(this,ue,Sn).call(this),h=l(this,je),[c,u,d,f]=h;if(h[0]=e,h[1]=s,h[2]=i,h[3]=n,Math.abs(d-r)<=H.PRECISION||Math.abs(f-o)<=H.PRECISION){const y=e+i/2-(c+d/2),x=s+n/2-(u+f/2);for(const{line:S,points:C}of l(this,gs))H._translate(S,y,x,S),H._translate(C,y,x,C);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${H.svgRound(e)} ${H.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const g=(i-2*r)/(d-2*r),p=(n-2*o)/(f-2*o),b=-g*(c+r)+e+r,_=-p*(u+o)+s+o;if(g!==1||p!==1||b!==0||_!==0)for(const{line:y,points:x}of l(this,gs))H._rescale(y,b,_,g,p,y),H._rescale(x,b,_,g,p,x);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${H.svgRound(e)} ${H.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,s],i){const[n,r]=i,o=l(this,je),h=e-o[0],c=s-o[1];if(l(this,Si)===n&&l(this,Ci)===r)for(const{line:u,points:d}of l(this,gs))H._translate(u,h,c,u),H._translate(d,h,c,d);else{const u=l(this,Si)/n,d=l(this,Ci)/r;m(this,Si,n),m(this,Ci,r);for(const{line:f,points:g}of l(this,gs))H._rescale(f,h,c,u,d,f),H._rescale(g,h,c,u,d,g);o[2]*=u,o[3]*=d}return o[0]=e,o[1]=s,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${H.svgRound(e)} ${H.svgRound(s)}`}}}get defaultSVGProperties(){const e=l(this,je);return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${H.svgRound(e[0])} ${H.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}};je=new WeakMap,_c=new WeakMap,wc=new WeakMap,gs=new WeakMap,Si=new WeakMap,Ci=new WeakMap,oh=new WeakMap,ah=new WeakMap,hh=new WeakMap,ue=new WeakSet,Sn=function(e=l(this,hh)){const s=l(this,wc)+e/2*l(this,oh);return l(this,ah)%180===0?[s/l(this,Si),s/l(this,Ci)]:[s/l(this,Ci),s/l(this,Si)]},uv=function(){const[e,s,i,n]=l(this,je),[r,o]=w(this,ue,Sn).call(this,0);return[e+r,s+o,i-2*r,n-2*o]},dv=function(){const e=m(this,je,new Float32Array([1/0,1/0,-1/0,-1/0]));for(const{line:n}of l(this,gs)){if(n.length<=12){for(let h=4,c=n.length;h<c;h+=6){const[u,d]=n.subarray(h,h+2);e[0]=Math.min(e[0],u),e[1]=Math.min(e[1],d),e[2]=Math.max(e[2],u),e[3]=Math.max(e[3],d)}continue}let r=n[4],o=n[5];for(let h=6,c=n.length;h<c;h+=6){const[u,d,f,g,p,b]=n.subarray(h,h+6);U.bezierBoundingBox(r,o,u,d,f,g,p,b,e),r=p,o=b}}const[s,i]=w(this,ue,Sn).call(this);e[0]=Math.min(1,Math.max(0,e[0]-s)),e[1]=Math.min(1,Math.max(0,e[1]-i)),e[2]=Math.min(1,Math.max(0,e[2]+s)),e[3]=Math.min(1,Math.max(0,e[3]+i)),e[2]-=e[0],e[3]-=e[1]},fv=function(e){const[s,i]=w(this,ue,Sn).call(this);m(this,hh,e);const[n,r]=w(this,ue,Sn).call(this),[o,h]=[n-s,r-i],c=l(this,je);return c[0]-=o,c[1]-=h,c[2]+=2*o,c[3]+=2*h,c};let od=Ug;const Yg=class Yg extends XS{constructor(e){super();v(this,lh);m(this,lh,e),super.updateProperties({fill:"none",stroke:Pt._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(e,s){e==="stroke-width"&&(s??(s=this["stroke-width"]),s*=l(this,lh).realScale),super.updateSVGProperty(e,s)}clone(){const e=new Yg(l(this,lh));return e.updateAll(this),e}};lh=new WeakMap;let Ng=Yg;const ch=class ch extends Ig{constructor(e){super({...e,name:"inkEditor"});v(this,Cd);this._willKeepAspectRatio=!0}static initialize(e,s){Pt.initialize(e,s),this._defaultDrawingOptions=new Ng(s.viewParameters)}static getDefaultDrawingOptions(e){const s=this._defaultDrawingOptions.clone();return s.updateProperties(e),s}static get supportMultipleDrawings(){return!0}static get typesMap(){return st(this,"typesMap",new Map([[ot.INK_THICKNESS,"stroke-width"],[ot.INK_COLOR,"stroke"],[ot.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(e,s,i,n,r){return new WS(e,s,i,n,r,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(e,s,i,n,r,o){return od.deserialize(e,s,i,n,r,o)}static async deserialize(e,s,i){let n=null;if(e instanceof Og){const{data:{inkLists:o,rect:h,rotation:c,id:u,color:d,opacity:f,borderStyle:{rawWidth:g},popupRef:p},parent:{page:{pageNumber:b}}}=e;n=e={annotationType:Z.INK,color:Array.from(d),thickness:g,opacity:f,paths:{points:o},boxes:null,pageIndex:b-1,rect:h.slice(0),rotation:c,id:u,deleted:!1,popupRef:p}}const r=await super.deserialize(e,s,i);return r.annotationElementId=e.id||null,r._initialData=n,r}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();const{_drawId:e,_drawingOptions:s,parent:i}=this;s.updateSVGProperty("stroke-width"),i.drawLayer.updateProperties(e,s.toSVGProperties())}static onScaleChangingWhenDrawing(){const e=this._currentParent;e&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),e.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:e,thickness:s,opacity:i}){this._drawingOptions=ch.getDefaultDrawingOptions({stroke:U.makeHexColor(...e),"stroke-width":s,"stroke-opacity":i})}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:s,points:i,rect:n}=this.serializeDraw(e),{_drawingOptions:{stroke:r,"stroke-opacity":o,"stroke-width":h}}=this,c={annotationType:Z.INK,color:Pt._colorManager.convert(r),opacity:o,thickness:h,paths:{lines:s,points:i},pageIndex:this.pageIndex,rect:n,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?c:this.annotationElementId&&!w(this,Cd,gv).call(this,c)?null:(c.id=this.annotationElementId,c)}renderAnnotationElement(e){const{points:s,rect:i}=this.serializeDraw(!1);return e.updateEdited({rect:i,thickness:this._drawingOptions["stroke-width"],points:s}),null}};Cd=new WeakSet,gv=function(e){const{color:s,thickness:i,opacity:n,pageIndex:r}=this._initialData;return this._hasBeenMoved||this._hasBeenResized||e.color.some((o,h)=>o!==s[h])||e.thickness!==i||e.opacity!==n||e.pageIndex!==r},$(ch,"_type","ink"),$(ch,"_editorType",Z.INK),$(ch,"_defaultDrawingOptions",null);let jg=ch;const xc=class xc extends Pt{constructor(e){super({...e,name:"stampEditor"});v(this,ct);v(this,Ot,null);v(this,de,null);v(this,hr,null);v(this,yn,null);v(this,lr,null);v(this,uh,"");v(this,Ai,null);v(this,Ti,null);v(this,ps,!1);v(this,dh,!1);m(this,yn,e.bitmapUrl),m(this,lr,e.bitmapFile)}static initialize(e,s){Pt.initialize(e,s)}static get supportedTypes(){return st(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(s=>`image/${s}`))}static get supportedTypesStr(){return st(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(e){return this.supportedTypes.includes(e)}static paste(e,s){s.pasteEditor(Z.STAMP,{bitmapFile:e.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){var e;return{type:"stamp",hasAltText:!!((e=this.altTextData)!=null&&e.altText)}}static computeTelemetryFinalData(e){const s=e.get("hasAltText");return{hasAltText:s.get(!0)??0,hasNoAltText:s.get(!1)??0}}async mlGuessAltText(e=null,s=!0){if(this.hasAltTextData())return null;const{mlManager:i}=this._uiManager;if(!i)throw new Error("No ML.");if(!await i.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:n,width:r,height:o}=e||this.copyCanvas(null,null,!0).imageData,h=await i.guess({name:"altText",request:{data:n,width:r,height:o,channels:n.length/(r*o)}});if(!h)throw new Error("No response from the AI service.");if(h.error)throw new Error("Error from the AI service.");if(h.cancel)return null;if(!h.output)throw new Error("No valid response from the AI service.");const c=h.output;return await this.setGuessedAltText(c),s&&!this.hasAltTextData()&&(this.altTextData={alt:c,decorative:!1}),c}remove(){var e;l(this,de)&&(m(this,Ot,null),this._uiManager.imageManager.deleteId(l(this,de)),(e=l(this,Ai))==null||e.remove(),m(this,Ai,null),l(this,Ti)&&(clearTimeout(l(this,Ti)),m(this,Ti,null))),super.remove()}rebuild(){if(!this.parent){l(this,de)&&w(this,ct,Jd).call(this);return}super.rebuild(),this.div!==null&&(l(this,de)&&l(this,Ai)===null&&w(this,ct,Jd).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(e){this._isDraggable=!0,e&&this.div.focus()}isEmpty(){return!(l(this,hr)||l(this,Ot)||l(this,yn)||l(this,lr)||l(this,de))}get isResizable(){return!0}render(){if(this.div)return this.div;let e,s;if(this.width&&(e=this.x,s=this.y),super.render(),this.div.hidden=!0,this.div.setAttribute("role","figure"),this.addAltTextButton(),l(this,Ot)?w(this,ct,Ip).call(this):w(this,ct,Jd).call(this),this.width&&!this.annotationElementId){const[i,n]=this.parentDimensions;this.setAt(e*i,s*n,this.width*i,this.height*n)}return this._uiManager.addShouldRescale(this),this.div}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;l(this,Ti)!==null&&clearTimeout(l(this,Ti)),m(this,Ti,setTimeout(()=>{m(this,Ti,null),w(this,ct,Np).call(this)},200))}copyCanvas(e,s,i=!1){var g;e||(e=224);const{width:n,height:r}=l(this,Ot),o=new mg;let h=l(this,Ot),c=n,u=r,d=null;if(s){if(n>s||r>s){const k=Math.min(s/n,s/r);c=Math.floor(n*k),u=Math.floor(r*k)}d=document.createElement("canvas");const p=d.width=Math.ceil(c*o.sx),b=d.height=Math.ceil(u*o.sy);l(this,ps)||(h=w(this,ct,Zd).call(this,p,b));const _=d.getContext("2d");_.filter=this._uiManager.hcmFilter;let y="white",x="#cfcfd8";this._uiManager.hcmFilter!=="none"?x="black":(g=window.matchMedia)!=null&&g.call(window,"(prefers-color-scheme: dark)").matches&&(y="#8f8f9d",x="#42414d");const S=15,C=S*o.sx,E=S*o.sy,D=new OffscreenCanvas(C*2,E*2),M=D.getContext("2d");M.fillStyle=y,M.fillRect(0,0,C*2,E*2),M.fillStyle=x,M.fillRect(0,0,C,E),M.fillRect(C,E,C,E),_.fillStyle=_.createPattern(D,"repeat"),_.fillRect(0,0,p,b),_.drawImage(h,0,0,h.width,h.height,0,0,p,b)}let f=null;if(i){let p,b;if(o.symmetric&&h.width<e&&h.height<e)p=h.width,b=h.height;else if(h=l(this,Ot),n>e||r>e){const x=Math.min(e/n,e/r);p=Math.floor(n*x),b=Math.floor(r*x),l(this,ps)||(h=w(this,ct,Zd).call(this,p,b))}const y=new OffscreenCanvas(p,b).getContext("2d",{willReadFrequently:!0});y.drawImage(h,0,0,h.width,h.height,0,0,p,b),f={width:p,height:b,data:y.getImageData(0,0,p,b).data}}return{canvas:d,width:c,height:u,imageData:f}}getImageForAltText(){return l(this,Ai)}static async deserialize(e,s,i){var b;let n=null;if(e instanceof Ib){const{data:{rect:_,rotation:y,id:x,structParent:S,popupRef:C},container:E,parent:{page:{pageNumber:D}}}=e,M=E.querySelector("canvas"),k=i.imageManager.getFromCanvas(E.id,M);M.remove();const O=((b=await s._structTree.getAriaAttributes(`${ug}${x}`))==null?void 0:b.get("aria-label"))||"";n=e={annotationType:Z.STAMP,bitmapId:k.id,bitmap:k.bitmap,pageIndex:D-1,rect:_.slice(0),rotation:y,id:x,deleted:!1,accessibilityData:{decorative:!1,altText:O},isSvg:!1,structParent:S,popupRef:C}}const r=await super.deserialize(e,s,i),{rect:o,bitmap:h,bitmapUrl:c,bitmapId:u,isSvg:d,accessibilityData:f}=e;u&&i.imageManager.isValidId(u)?(m(r,de,u),h&&m(r,Ot,h)):m(r,yn,c),m(r,ps,d);const[g,p]=r.pageDimensions;return r.width=(o[2]-o[0])/g,r.height=(o[3]-o[1])/p,r.annotationElementId=e.id||null,f&&(r.altTextData=f),r._initialData=n,m(r,dh,!!n),r}serialize(e=!1,s=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const i={annotationType:Z.STAMP,bitmapId:l(this,de),pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:l(this,ps),structTreeParentId:this._structTreeParentId};if(e)return i.bitmapUrl=w(this,ct,tf).call(this,!0),i.accessibilityData=this.serializeAltText(!0),i;const{decorative:n,altText:r}=this.serializeAltText(!1);if(!n&&r&&(i.accessibilityData={type:"Figure",alt:r}),this.annotationElementId){const h=w(this,ct,pv).call(this,i);if(h.isSame)return null;h.isSameAltText?delete i.accessibilityData:i.accessibilityData.structParent=this._initialData.structParent??-1}if(i.id=this.annotationElementId,s===null)return i;s.stamps||(s.stamps=new Map);const o=l(this,ps)?(i.rect[2]-i.rect[0])*(i.rect[3]-i.rect[1]):null;if(!s.stamps.has(l(this,de)))s.stamps.set(l(this,de),{area:o,serialized:i}),i.bitmap=w(this,ct,tf).call(this,!1);else if(l(this,ps)){const h=s.stamps.get(l(this,de));o>h.area&&(h.area=o,h.serialized.bitmap.close(),h.serialized.bitmap=w(this,ct,tf).call(this,!1))}return i}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}};Ot=new WeakMap,de=new WeakMap,hr=new WeakMap,yn=new WeakMap,lr=new WeakMap,uh=new WeakMap,Ai=new WeakMap,Ti=new WeakMap,ps=new WeakMap,dh=new WeakMap,ct=new WeakSet,Ic=function(e,s=!1){if(!e){this.remove();return}m(this,Ot,e.bitmap),s||(m(this,de,e.id),m(this,ps,e.isSvg)),e.file&&m(this,uh,e.file.name),w(this,ct,Ip).call(this)},Nc=function(){if(m(this,hr,null),this._uiManager.enableWaiting(!1),!!l(this,Ai)){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Ot)){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Ot)){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}},Jd=function(){if(l(this,de)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(l(this,de)).then(i=>w(this,ct,Ic).call(this,i,!0)).finally(()=>w(this,ct,Nc).call(this));return}if(l(this,yn)){const i=l(this,yn);m(this,yn,null),this._uiManager.enableWaiting(!0),m(this,hr,this._uiManager.imageManager.getFromUrl(i).then(n=>w(this,ct,Ic).call(this,n)).finally(()=>w(this,ct,Nc).call(this)));return}if(l(this,lr)){const i=l(this,lr);m(this,lr,null),this._uiManager.enableWaiting(!0),m(this,hr,this._uiManager.imageManager.getFromFile(i).then(n=>w(this,ct,Ic).call(this,n)).finally(()=>w(this,ct,Nc).call(this)));return}const e=document.createElement("input");e.type="file",e.accept=xc.supportedTypesStr;const s=this._uiManager._signal;m(this,hr,new Promise(i=>{e.addEventListener("change",async()=>{if(!e.files||e.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const n=await this._uiManager.imageManager.getFromFile(e.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),w(this,ct,Ic).call(this,n)}i()},{signal:s}),e.addEventListener("cancel",()=>{this.remove(),i()},{signal:s})}).finally(()=>w(this,ct,Nc).call(this))),e.click()},Ip=function(){var d;const{div:e}=this;let{width:s,height:i}=l(this,Ot);const[n,r]=this.pageDimensions,o=.75;if(this.width)s=this.width*n,i=this.height*r;else if(s>o*n||i>o*r){const f=Math.min(o*n/s,o*r/i);s*=f,i*=f}const[h,c]=this.parentDimensions;this.setDims(s*h/n,i*c/r),this._uiManager.enableWaiting(!1);const u=m(this,Ai,document.createElement("canvas"));u.setAttribute("role","img"),this.addContainer(u),this.width=s/n,this.height=i/r,(d=this._initialOptions)!=null&&d.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(e.hidden=!1),w(this,ct,Np).call(this),l(this,dh)||(this.parent.addUndoableEditor(this),m(this,dh,!0)),this._reportTelemetry({action:"inserted_image"}),l(this,uh)&&u.setAttribute("aria-label",l(this,uh))},Zd=function(e,s){const{width:i,height:n}=l(this,Ot);let r=i,o=n,h=l(this,Ot);for(;r>2*e||o>2*s;){const c=r,u=o;r>2*e&&(r=r>=16384?Math.floor(r/2)-1:Math.ceil(r/2)),o>2*s&&(o=o>=16384?Math.floor(o/2)-1:Math.ceil(o/2));const d=new OffscreenCanvas(r,o);d.getContext("2d").drawImage(h,0,0,c,u,0,0,r,o),h=d.transferToImageBitmap()}return h},Np=function(){const[e,s]=this.parentDimensions,{width:i,height:n}=this,r=new mg,o=Math.ceil(i*e*r.sx),h=Math.ceil(n*s*r.sy),c=l(this,Ai);if(!c||c.width===o&&c.height===h)return;c.width=o,c.height=h;const u=l(this,ps)?l(this,Ot):w(this,ct,Zd).call(this,o,h),d=c.getContext("2d");d.filter=this._uiManager.hcmFilter,d.drawImage(u,0,0,u.width,u.height,0,0,o,h)},tf=function(e){if(e){if(l(this,ps)){const n=this._uiManager.imageManager.getSvgUrl(l(this,de));if(n)return n}const s=document.createElement("canvas");return{width:s.width,height:s.height}=l(this,Ot),s.getContext("2d").drawImage(l(this,Ot),0,0),s.toDataURL()}if(l(this,ps)){const[s,i]=this.pageDimensions,n=Math.round(this.width*s*Ln.PDF_TO_CSS_UNITS),r=Math.round(this.height*i*Ln.PDF_TO_CSS_UNITS),o=new OffscreenCanvas(n,r);return o.getContext("2d").drawImage(l(this,Ot),0,0,l(this,Ot).width,l(this,Ot).height,0,0,n,r),o.transferToImageBitmap()}return structuredClone(l(this,Ot))},pv=function(e){var o;const{pageIndex:s,accessibilityData:{altText:i}}=this._initialData,n=e.pageIndex===s,r=(((o=e.accessibilityData)==null?void 0:o.alt)||"")===i;return{isSame:!this._hasBeenMoved&&!this._hasBeenResized&&n&&r,isSameAltText:r}},$(xc,"_type","stamp"),$(xc,"_editorType",Z.STAMP);let Bg=xc;const ei=class ei{constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:o,textLayer:h,viewport:c,l10n:u}){v(this,kt);v(this,No);v(this,fh,!1);v(this,Ei,null);v(this,cr,null);v(this,vn,null);v(this,Ps,new Map);v(this,ur,!1);v(this,gh,!1);v(this,jo,!1);v(this,ti,null);v(this,_n,null);v(this,Ce,null);v(this,wn,null);v(this,X);const d=[...l(ei,dr).values()];if(!ei._initialized){ei._initialized=!0;for(const f of d)f.initialize(u,t)}t.registerEditorTypes(d),m(this,X,t),this.pageIndex=e,this.div=s,m(this,No,n),m(this,Ei,r),this.viewport=c,m(this,Ce,h),this.drawLayer=o,this._structTree=i,l(this,X).addLayer(this)}get isEmpty(){return l(this,Ps).size===0}get isInvisible(){return this.isEmpty&&l(this,X).getMode()===Z.NONE}updateToolbar(t){l(this,X).updateToolbar(t)}updateMode(t=l(this,X).getMode()){switch(w(this,kt,ef).call(this),t){case Z.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case Z.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case Z.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);const{classList:e}=this.div;for(const s of l(ei,dr).values())e.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){var e;return t===((e=l(this,Ce))==null?void 0:e.div)}setEditingState(t){l(this,X).setEditingState(t)}addCommands(t){l(this,X).addCommands(t)}cleanUndoStack(t){l(this,X).cleanUndoStack(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){var e;(e=l(this,Ei))==null||e.div.classList.toggle("disabled",!t)}async enable(){m(this,jo,!0),this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const s of l(this,Ps).values())s.enableEditing(),s.show(!0),s.annotationElementId&&(l(this,X).removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!l(this,Ei)){m(this,jo,!1);return}const e=l(this,Ei).getEditableAnnotations();for(const s of e){if(s.hide(),l(this,X).isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;const i=await this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}m(this,jo,!1)}disable(){var i;m(this,gh,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,e=new Map;for(const n of l(this,Ps).values())if(n.disableEditing(),!!n.annotationElementId){if(n.serialize()!==null){t.set(n.annotationElementId,n);continue}else e.set(n.annotationElementId,n);(i=this.getEditableAnnotation(n.annotationElementId))==null||i.show(),n.remove()}if(l(this,Ei)){const n=l(this,Ei).getEditableAnnotations();for(const r of n){const{id:o}=r.data;if(l(this,X).isDeletedAnnotationElement(o))continue;let h=e.get(o);if(h){h.resetAnnotationElement(r),h.show(!1),r.show();continue}h=t.get(o),h&&(l(this,X).addChangedExistingAnnotation(h),h.renderAnnotationElement(r)&&h.show(!1)),r.show()}}w(this,kt,ef).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const n of l(ei,dr).values())s.remove(`${n._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),m(this,gh,!1)}getEditableAnnotation(t){var e;return((e=l(this,Ei))==null?void 0:e.getEditableAnnotation(t))||null}setActiveEditor(t){l(this,X).getActive()!==t&&l(this,X).setActiveEditor(t)}enableTextSelection(){var t;if(this.div.tabIndex=-1,(t=l(this,Ce))!=null&&t.div&&!l(this,wn)){m(this,wn,new AbortController);const e=l(this,X).combinedSignal(l(this,wn));l(this,Ce).div.addEventListener("pointerdown",w(this,kt,mv).bind(this),{signal:e}),l(this,Ce).div.classList.add("highlighting")}}disableTextSelection(){var t;this.div.tabIndex=0,(t=l(this,Ce))!=null&&t.div&&l(this,wn)&&(l(this,wn).abort(),m(this,wn,null),l(this,Ce).div.classList.remove("highlighting"))}enableClick(){if(l(this,cr))return;m(this,cr,new AbortController);const t=l(this,X).combinedSignal(l(this,cr));this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t});const e=this.pointerup.bind(this);this.div.addEventListener("pointerup",e,{signal:t}),this.div.addEventListener("pointercancel",e,{signal:t})}disableClick(){var t;(t=l(this,cr))==null||t.abort(),m(this,cr,null)}attach(t){l(this,Ps).set(t.id,t);const{annotationElementId:e}=t;e&&l(this,X).isDeletedAnnotationElement(e)&&l(this,X).removeDeletedAnnotationElement(t)}detach(t){var e;l(this,Ps).delete(t.id),(e=l(this,No))==null||e.removePointerInTextLayer(t.contentDiv),!l(this,gh)&&t.annotationElementId&&l(this,X).addDeletedAnnotationElement(t)}remove(t){this.detach(t),l(this,X).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){var e;t.parent!==this&&(t.parent&&t.annotationElementId&&(l(this,X).addDeletedAnnotationElement(t.annotationElementId),Pt.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),(e=t.parent)==null||e.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),l(this,X).addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!l(this,jo)),l(this,X).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var s;if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!l(this,vn)&&(t._focusEventsAllowed=!1,m(this,vn,setTimeout(()=>{m(this,vn,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:l(this,X)._signal}),e.focus())},0))),t._structTreeParentId=(s=l(this,No))==null?void 0:s.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 e=()=>t._uiManager.rebuild(t),s=()=>{t.remove()};this.addCommands({cmd:e,undo:s,mustExec:!1})}getNextId(){return l(this,X).getId()}combinedSignal(t){return l(this,X).combinedSignal(t)}canCreateNewEmptyEditor(){var t;return(t=l(this,kt,Di))==null?void 0:t.canCreateNewEmptyEditor()}pasteEditor(t,e){l(this,X).updateToolbar(t),l(this,X).updateMode(t);const{offsetX:s,offsetY:i}=w(this,kt,Bp).call(this),n=this.getNextId(),r=w(this,kt,jp).call(this,{parent:this,id:n,x:s,y:i,uiManager:l(this,X),isCentered:!0,...e});r&&this.add(r)}async deserialize(t){var e;return await((e=l(ei,dr).get(t.annotationType??t.annotationEditorType))==null?void 0:e.deserialize(t,this,l(this,X)))||null}createAndAddNewEditor(t,e,s={}){const i=this.getNextId(),n=w(this,kt,jp).call(this,{parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:l(this,X),isCentered:e,...s});return n&&this.add(n),n}addNewEditor(){this.createAndAddNewEditor(w(this,kt,Bp).call(this),!0)}setSelected(t){l(this,X).setSelected(t)}toggleSelected(t){l(this,X).toggleSelected(t)}unselect(t){l(this,X).unselect(t)}pointerup(t){var s;const{isMac:e}=Re.platform;if(!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&l(this,ur)&&(m(this,ur,!1),!((s=l(this,kt,Di))!=null&&s.isDrawer&&l(this,kt,Di).supportMultipleDrawings))){if(!l(this,fh)){m(this,fh,!0);return}if(l(this,X).getMode()===Z.STAMP){l(this,X).unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){var i;if(l(this,X).getMode()===Z.HIGHLIGHT&&this.enableTextSelection(),l(this,ur)){m(this,ur,!1);return}const{isMac:e}=Re.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;if(m(this,ur,!0),(i=l(this,kt,Di))!=null&&i.isDrawer){this.startDrawingSession(t);return}const s=l(this,X).getActive();m(this,fh,!s||s.isEmpty())}startDrawingSession(t){if(this.div.focus(),l(this,ti)){l(this,kt,Di).startDrawing(this,l(this,X),!1,t);return}l(this,X).setCurrentDrawingSession(this),m(this,ti,new AbortController);const e=l(this,X).combinedSignal(l(this,ti));this.div.addEventListener("blur",({relatedTarget:s})=>{s&&!this.div.contains(s)&&(m(this,_n,null),this.commitOrRemove())},{signal:e}),l(this,kt,Di).startDrawing(this,l(this,X),!1,t)}pause(t){if(t){const{activeElement:e}=document;this.div.contains(e)&&m(this,_n,e);return}l(this,_n)&&setTimeout(()=>{var e;(e=l(this,_n))==null||e.focus(),m(this,_n,null)},0)}endDrawingSession(t=!1){return l(this,ti)?(l(this,X).setCurrentDrawingSession(null),l(this,ti).abort(),m(this,ti,null),m(this,_n,null),l(this,kt,Di).endDrawing(t)):null}findNewParent(t,e,s){const i=l(this,X).findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}commitOrRemove(){return l(this,ti)?(this.endDrawingSession(),!0):!1}onScaleChanging(){l(this,ti)&&l(this,kt,Di).onScaleChangingWhenDrawing(this)}destroy(){var t,e;this.commitOrRemove(),((t=l(this,X).getActive())==null?void 0:t.parent)===this&&(l(this,X).commitOrRemove(),l(this,X).setActiveEditor(null)),l(this,vn)&&(clearTimeout(l(this,vn)),m(this,vn,null));for(const s of l(this,Ps).values())(e=l(this,No))==null||e.removePointerInTextLayer(s.contentDiv),s.setParent(null),s.isAttachedToDOM=!1,s.div.remove();this.div=null,l(this,Ps).clear(),l(this,X).removeLayer(this)}render({viewport:t}){this.viewport=t,kr(this.div,t);for(const e of l(this,X).getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){l(this,X).commitOrRemove(),w(this,kt,ef).call(this);const e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,kr(this.div,{rotation:s}),e!==s)for(const i of l(this,Ps).values())i.rotate(s)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return l(this,X).viewParameters.realScale}};No=new WeakMap,fh=new WeakMap,Ei=new WeakMap,cr=new WeakMap,vn=new WeakMap,Ps=new WeakMap,ur=new WeakMap,gh=new WeakMap,jo=new WeakMap,ti=new WeakMap,_n=new WeakMap,Ce=new WeakMap,wn=new WeakMap,X=new WeakMap,dr=new WeakMap,kt=new WeakSet,mv=function(t){l(this,X).unselectAll();const{target:e}=t;if(e===l(this,Ce).div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&l(this,Ce).div.contains(e)){const{isMac:s}=Re.platform;if(t.button!==0||t.ctrlKey&&s)return;l(this,X).showAllEditors("highlight",!0,!0),l(this,Ce).div.classList.add("free"),this.toggleDrawing(),rd.startHighlighting(this,l(this,X).direction==="ltr",{target:l(this,Ce).div,x:t.x,y:t.y}),l(this,Ce).div.addEventListener("pointerup",()=>{l(this,Ce).div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:l(this,X)._signal}),t.preventDefault()}},Di=function(){return l(ei,dr).get(l(this,X).getMode())},jp=function(t){const e=l(this,kt,Di);return e?new e.prototype.constructor(t):null},Bp=function(){const{x:t,y:e,width:s,height:i}=this.div.getBoundingClientRect(),n=Math.max(0,t),r=Math.max(0,e),o=Math.min(window.innerWidth,t+s),h=Math.min(window.innerHeight,e+i),c=(n+o)/2-t,u=(r+h)/2-e,[d,f]=this.viewport.rotation%180===0?[c,u]:[u,c];return{offsetX:d,offsetY:f}},ef=function(){for(const t of l(this,Ps).values())t.isEmpty()&&t.remove()},$(ei,"_initialized",!1),v(ei,dr,new Map([Rg,jg,Bg,rd].map(t=>[t._editorType,t])));let Hg=ei;const Ae=class Ae{constructor({pageIndex:t}){v(this,ki);v(this,si,null);v(this,Sc,0);v(this,Be,new Map);v(this,Bo,new Map);this.pageIndex=t}setParent(t){if(!l(this,si)){m(this,si,t);return}if(l(this,si)!==t){if(l(this,Be).size>0)for(const e of l(this,Be).values())e.remove(),t.append(e);m(this,si,t)}}static get _svgFactory(){return st(this,"_svgFactory",new Pg)}draw(t,e=!1,s=!1){const i=ze(this,Sc)._++,n=w(this,ki,Hp).call(this),r=Ae._svgFactory.createElement("defs");n.append(r);const o=Ae._svgFactory.createElement("path");r.append(o);const h=`path_p${this.pageIndex}_${i}`;o.setAttribute("id",h),o.setAttribute("vector-effect","non-scaling-stroke"),e&&l(this,Bo).set(i,o);const c=s?w(this,ki,yv).call(this,r,h):null,u=Ae._svgFactory.createElement("use");return n.append(u),u.setAttribute("href",`#${h}`),this.updateProperties(n,t),l(this,Be).set(i,n),{id:i,clipPathId:`url(#${c})`}}drawOutline(t,e){const s=ze(this,Sc)._++,i=w(this,ki,Hp).call(this),n=Ae._svgFactory.createElement("defs");i.append(n);const r=Ae._svgFactory.createElement("path");n.append(r);const o=`path_p${this.pageIndex}_${s}`;r.setAttribute("id",o),r.setAttribute("vector-effect","non-scaling-stroke");let h;if(e){const d=Ae._svgFactory.createElement("mask");n.append(d),h=`mask_p${this.pageIndex}_${s}`,d.setAttribute("id",h),d.setAttribute("maskUnits","objectBoundingBox");const f=Ae._svgFactory.createElement("rect");d.append(f),f.setAttribute("width","1"),f.setAttribute("height","1"),f.setAttribute("fill","white");const g=Ae._svgFactory.createElement("use");d.append(g),g.setAttribute("href",`#${o}`),g.setAttribute("stroke","none"),g.setAttribute("fill","black"),g.setAttribute("fill-rule","nonzero"),g.classList.add("mask")}const c=Ae._svgFactory.createElement("use");i.append(c),c.setAttribute("href",`#${o}`),h&&c.setAttribute("mask",`url(#${h})`);const u=c.cloneNode();return i.append(u),c.classList.add("mainOutline"),u.classList.add("secondaryOutline"),this.updateProperties(i,t),l(this,Be).set(s,i),s}finalizeDraw(t,e){l(this,Bo).delete(t),this.updateProperties(t,e)}updateProperties(t,e){var h;if(!e)return;const{root:s,bbox:i,rootClass:n,path:r}=e,o=typeof t=="number"?l(this,Be).get(t):t;if(o){if(s&&w(this,ki,zp).call(this,o,s),i&&w(h=Ae,Ad,bv).call(h,o,i),n){const{classList:c}=o;for(const[u,d]of Object.entries(n))c.toggle(u,d)}if(r){const u=o.firstChild.firstChild;w(this,ki,zp).call(this,u,r)}}}updateParent(t,e){if(e===this)return;const s=l(this,Be).get(t);s&&(l(e,si).append(s),l(this,Be).delete(t),l(e,Be).set(t,s))}remove(t){l(this,Bo).delete(t),l(this,si)!==null&&(l(this,Be).get(t).remove(),l(this,Be).delete(t))}destroy(){m(this,si,null);for(const t of l(this,Be).values())t.remove();l(this,Be).clear(),l(this,Bo).clear()}};si=new WeakMap,Sc=new WeakMap,Be=new WeakMap,Bo=new WeakMap,Ad=new WeakSet,bv=function(t,[e,s,i,n]){const{style:r}=t;r.top=`${100*s}%`,r.left=`${100*e}%`,r.width=`${100*i}%`,r.height=`${100*n}%`},ki=new WeakSet,Hp=function(){const t=Ae._svgFactory.create(1,1,!0);return l(this,si).append(t),t.setAttribute("aria-hidden",!0),t},yv=function(t,e){const s=Ae._svgFactory.createElement("clipPath");t.append(s);const i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=Ae._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i},zp=function(t,e){for(const[s,i]of Object.entries(e))i===null?t.removeAttribute(s):t.setAttribute(s,i)},v(Ae,Ad);let zg=Ae;globalThis.pdfjsTestingUtils={HighlightOutliner:Lg},K.AbortException,K.AnnotationEditorLayer,K.AnnotationEditorParamsType,K.AnnotationEditorType,K.AnnotationEditorUIManager,K.AnnotationLayer,K.AnnotationMode,K.ColorPicker,K.DOMSVGFactory,K.DrawLayer,K.FeatureTest;var US=K.GlobalWorkerOptions;K.ImageKind,K.InvalidPDFException,K.MissingPDFException,K.OPS,K.OutputScale,K.PDFDataRangeTransport,K.PDFDateString,K.PDFWorker,K.PasswordResponses,K.PermissionFlag,K.PixelsPerInch,K.RenderingCancelledException,K.TextLayer,K.TouchManager,K.UnexpectedResponseException,K.Util,K.VerbosityLevel,K.XfaLayer,K.build,K.createValidAbsoluteUrl,K.fetchData;var YS=K.getDocument;K.getFilenameFromUrl,K.getPdfFilenameFromUrl,K.getXfaPageViewport,K.isDataScheme,K.isPdfFile,K.noContextMenu,K.normalizeUnicode,K.setLayerDimensions,K.shadow,K.stopEvent,K.version;const $S={"pdfjs-dist":"4.10.38"};function qS(a){return new Promise((t,e)=>{const s=new FileReader;s.addEventListener("load",()=>t(s.result)),s.addEventListener("error",e),s.readAsDataURL(a)})}const KS=$S["pdfjs-dist"].replace("^","");US.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${KS}/pdf.worker.min.mjs`;async function QS(a){const t="data:application/pdf;base64,",e=await qS(a);if(typeof e=="string")return window.atob(e.slice(t.length))}function JS(a,t){return YS({data:a,password:t}).promise}const ZS="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2040%2040'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3ccircle%20cx='20'%20cy='20'%20r='10.75'%20stroke='currentColor'%20stroke-width='2.5'/%3e%3cpath%20d='M16%2024L23.7782%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3cpath%20d='M24%2024L16.2218%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3c/svg%3e";function tC(a){return new URL(Object.assign({"../assets/close.svg":ZS})[`../assets/${a}`],typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:_t&&_t.tagName.toUpperCase()==="SCRIPT"&&_t.src||new URL("pdf-canvas.umd.js",document.baseURI).href).href}function eC(a){return new Promise((t,e)=>{const s=window.URL.createObjectURL(a),i=new Image;i.src=s,i.addEventListener("load",async()=>{window.URL.revokeObjectURL(s),t(await sC(i))}),i.addEventListener("error",n=>{window.URL.revokeObjectURL(s),e(n)})})}function sC(a){return new Promise(t=>{const e=document.createElement("canvas"),s=e.getContext("2d"),{naturalWidth:i,naturalHeight:n}=a;e.width=i,e.height=n,s==null||s.drawImage(a,0,0,i,n),t(e.toDataURL("image/jpeg",.8))})}let jb=null;function iC(){const a=document.createElement("div");a.style.width="1in",document.body.append(a);const t=a.offsetWidth;return a.remove(),t}function nC(){const a=jb??iC();return jb=a,a/72}function rC(a,t=500){if(typeof a!="function")throw new TypeError("The first argument is not a function.");let e=null;return function(...s){e&&clearTimeout(e),e=setTimeout(()=>{e=null,a.apply(this,s)},t)}}const _s=new Map;function oC(a){const t=new Wf(a);return _s.set(a,t),t}function aC(a,t){const e=Date.now();return{PDFId:`${a.name}-${e}`,name:a.name.replace(/.pdf/,""),updateDate:e,PDFBase64:t}}function hC(a,t){const e=a.getViewport({scale:t}),s=document.createElement("canvas"),i=s.getContext("2d"),n=nC()/window.devicePixelRatio;s.width=Math.floor(e.width*n),s.height=Math.floor(e.height*n);const r={canvasContext:i,viewport:e,transform:[n,0,0,n,0,0]},o=a.render(r);return{canvas:s,renderTask:o}}async function lC(a,t,e){const s=a||tC("close.svg"),{objects:i,options:n}=await Iw(s),r=i.filter(h=>h!==null),o=K_.groupSVGElements(r,n);return r.forEach(h=>{h.stroke=t}),o.hoverCursor="pointer",o.stroke=`${t}-${e}`,o}function cC(a,t){if(!_s.get(a))return;const s=1/3,i=bC(t,s);Hb(a,i,s)}async function uC(a,t){const e=await eC(t),s=Date.now(),n={PDFId:`${t.name}${s}`,name:t.name.replace(/.png|.jpg|.jpeg/,""),updateDate:s,PDFBase64:e};return Bb(a,{url:e}),{...n,pages:1}}async function Bb(a,{url:t,scale:e=.5}){if(!_s.get(a))return;const i=await be.fromURL(t);i.scale(e),Hb(a,i,e)}function Hb(a,t,e){const s=_s.get(a);s&&(s.setWidth(t.width*e),s.setHeight(t.height*e),s.backgroundImage=t,s.renderAll())}function dC(a,t){if(!t)return;const{oCoords:e}=a;if(!e)return;const{x:s,y:i}=e.tl.touchCorner.tl,{height:n,width:r,scaleY:o,scaleX:h}=t;t.top=i-n*o/2,t.left=s-r*h/2,t.setCoords()}function fC(a,t,e){!e||!a||(e.scale(1/t),dC(a,e))}function gC(a,t){if(!a)return;const e=a._cornerSize||8;a.borderScaleFactor=1/t,a.cornerSize=e*(1/t),a.touchCornerSize=e*4*(1/t),a.setCoords()}function pC(a){const t=_s.get(a);t&&(t.discardActiveObject(),t.renderAll())}function mC(a){const t=_s.get(a);t&&(t.clear(),_s.delete(a))}function bC(a,t){return new be(a,{scaleX:t,scaleY:t})}function zb(a,t){if(!t)return;const{left:e,top:s,scaleX:i,scaleY:n,width:r,height:o}=a,h=t.x*r*i,c=t.y*o*n;a.set({left:e-h,top:s-c})}function Gb(a,t,e){var n;const s=a.type,i={"application/pdf":yC,"image/png":Xb,"image/jpeg":Xb};return((n=i[s])==null?void 0:n.call(i,a,t,e))??Promise.reject(new Error(`Unsupported ${s} file type.`))}async function yC(a,t,e){const s=await QS(a);if(!s)return;const i=aC(a,s);try{const n=await Vb({page:1,PDFBase64:s,scale:.8,password:t},e);return{...i,pages:n}}catch(n){return Promise.reject(n)}}async function Vb({page:a,PDFBase64:t,scale:e,password:s},i){try{const n=await JS(t,s),r=await n.getPage(a),{renderTask:o,canvas:h}=hC(r,e);return o.promise.then(()=>(i&&cC(i,h),n.numPages))}catch(n){return Promise.reject(n)}}async function Xb(a,t,e){if(e)return await uC(e,a)}const vC={top:100,left:50,scaleX:.5,scaleY:.5,borderColor:"black",cornerStrokeColor:"black",cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},_C={top:100,left:50,fontFamily:"helvetica",borderColor:"black",cornerStrokeColor:"black",scaleX:.7,scaleY:.7,cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},wC={borderColor:"black",cornerStrokeColor:"black",cornerSize:13,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},xC={stroke:"#000",hoverStroke:"#B7EC5D",src:""};function Wb(a){const{id:t="",selectionOptions:e,pointerDown:s,pointerMove:i,pointerUp:n}=a||{};let r=null,o=null,h=1,c={...xC};function u(){if(!t||_s.has(t))return;const k=oC(t);return k.on("selection:created",O=>{if(O.selected.length<=1)return;const R=k.getActiveObject();R&&(o=R,e!=null&&e.value&&o.set(e.value),o._cornerSize=o.cornerSize,S(h))}),k.on("selection:cleared",()=>E(k)),s&&k.on("mouse:down",s),i&&k.on("mouse:move",i),n&&k.on("mouse:up",n),k}function d(k,O){return Gb(k,O,t)}function f(k){return Vb(k,t)}async function g({url:k,scale:O=.5}){await Bb(t,{url:k,scale:O})}async function p(k,O,R){const L=_s.get(t);if(!L)return;const N=await be.fromURL(k,{},{...vC,...O});zb(N,R),L.add(N),_(L,N),L.setActiveObject(N)}function b(k,O,R){const L=_s.get(t);if(!L)return;const N=new me(k,{..._C,...O});zb(N,R),L.add(N),_(L,N),L.setActiveObject(N)}function _(k,O){O.on("selected",R=>y({canvas:k,target:R.target})),O.on("modified",R=>y({canvas:k,target:R.target})),O.on("scaling",()=>E(k)),O.on("moving",()=>E(k)),O.on("rotating",()=>E(k)),O._cornerSize=O.cornerSize}async function y({canvas:k,target:O,stroke:R=c.stroke,uuid:L=Date.now()}){if(k.getActiveObjects().length>1||(r==null?void 0:r.stroke)===`${R}-${L}`)return;const W=await lC(c.src,R,L);E(k),r=W,o=O,x(k,O,L),S(h,!0),k.add(W)}function x(k,O,R){r&&(r.on("selected",()=>{k.remove(O),E(k)}),r.on("mouseover",()=>{y({canvas:k,target:O,stroke:c.hoverStroke,uuid:R})}),r.on("mouseout",()=>{y({canvas:k,target:O,stroke:c.stroke,uuid:R})}))}function S(k,O=!1){const R=_s.get(t);h=k,R&&(gC(o,k),fC(o,k,r),!O&&R.renderAll())}function C(k){if(!k)return;c={...c,...k};const O=_s.get(t);!r||!o||!O||y({target:o,canvas:O})}function E(k){o=null,r&&(k.remove(r),r=null)}function D(){pC(t)}function M(){mC(t)}return{createCanvas:u,loadFile:d,specifyPage:f,renderImage:g,addFabric:p,addTextFabric:b,clearActive:D,deleteCanvas:M,scaleFabric:S,setCloseSvgOptions:C}}function SC(a){let t=0;const e=rC(()=>{t!==window.innerWidth&&(t=window.innerWidth,a())});q.onMounted(()=>{window.addEventListener("resize",e)}),q.onBeforeUnmount(()=>{window.removeEventListener("resize",e)})}const CC=q.defineComponent({__name:"pdf-canvas",props:{file:{},page:{default:1},canvasId:{default:"PDF-canvas"},fileZoom:{default:1},fileScale:{default:1},canvasScale:{default:1},canvasClass:{default:""},isDrop:{type:Boolean,default:!1},password:{},dropTextOptions:{},dropImageOptions:{},selectionOptions:{default:()=>({...wC})},closeSvgOptions:{},manualReload:{type:Boolean},onDestroy:{type:Function,default:q.onBeforeUnmount}},emits:["loaded","reload","pointerDown","pointerMove","pointerUp"],setup(a,{expose:t,emit:e}){const s=a,i=e,{onDestroy:n}=s,r=q.ref(null),o=`${s.canvasId}-${s.page-1}`,h=q.computed(()=>s.fileZoom*s.canvasScale),{createCanvas:c,specifyPage:u,addFabric:d,addTextFabric:f,renderImage:g,clearActive:p,deleteCanvas:b,scaleFabric:_,setCloseSvgOptions:y}=Wb({id:o,selectionOptions:q.toRef(s,"selectionOptions"),pointerDown:M=>i("pointerDown",M),pointerMove:M=>i("pointerMove",M),pointerUp:M=>i("pointerUp",M)});x(),SC(D);async function x(){const{file:M,page:k,fileScale:O}=s;window.requestAnimationFrame(async()=>{if(await q.nextTick(),c(),M.PDFBase64.startsWith("data:image")||M.canvas){const{canvas:R}=M,L=R?7:3,N=R!=null&&R.length?R[k-1]:M.PDFBase64;g({url:N,scale:O/L}),i("loaded");return}await u({page:k,PDFBase64:M.PDFBase64,scale:O,password:s.password}),i("loaded")})}function S(M){if(!s.isDrop||!M.dataTransfer)return;const{dataTransfer:k,offsetX:O,offsetY:R}=M,L=k.getData("text/plain"),N=k.getData("text/uri-list"),W=k.getData("custom/offset"),G=W?JSON.parse(W):null,at={top:R,left:O},F={x:(G==null?void 0:G.offsetX)??0,y:(G==null?void 0:G.offsetY)??0};N?C(N,at,F):L&&E(L,at,F)}function C(M,k,O){d(M,{...s.dropImageOptions,...k},O)}function E(M,k,O){f(M,{...s.dropTextOptions,...k},O)}function D(){s.manualReload||x(),i("reload")}return q.watch([()=>s.fileScale,()=>s.page,()=>s.file,()=>s.password],D),q.watch(h,M=>_(M),{immediate:!0}),q.watch(()=>s.closeSvgOptions,y,{immediate:!0}),n(b),t({reload:x,addImage:C,addText:E,clearActive:p,deleteCanvas:b,canvasRef:r}),(M,k)=>(q.openBlock(),q.createElementBlock("div",{style:q.normalizeStyle({transform:`scale(${h.value})`}),onDragover:k[0]||(k[0]=q.withModifiers(()=>{},["prevent"])),onDragenter:k[1]||(k[1]=q.withModifiers(()=>{},["prevent"])),onDrop:q.withModifiers(S,["stop","prevent"])},[q.createElementVNode("canvas",{id:o,ref_key:"canvasRef",ref:r,class:q.normalizeClass(M.canvasClass)},null,2)],36))}});nt.default=CC,nt.loadFile=Gb,nt.useFabric=Wb,Object.defineProperties(nt,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
509
+ `)){const s=document.createElement("div");s.append(e?document.createTextNode(e):document.createElement("br")),this.editorDiv.append(s)}},Gy=function(){return l(this,hs).replaceAll(" "," ")},Tp=function(e){return e.replaceAll(" "," ")},Vy=function(e){const{value:s,fontSize:i,color:n,pageIndex:r}=this._initialData;return this._hasBeenMoved||e.value!==s||e.fontSize!==i||e.color.some((o,h)=>o!==n[h])||e.pageIndex!==r},v(wt,fn),$(wt,"_freeTextDefaultContent",""),$(wt,"_internalPadding",0),$(wt,"_defaultColor",null),$(wt,"_defaultFontSize",10),$(wt,"_type","freetext"),$(wt,"_editorType",Z.FREETEXT);let Rg=wt;class H{toSVGPath(){vt("Abstract method `toSVGPath` must be implemented.")}get box(){vt("Abstract getter `box` must be implemented.")}serialize(t,e){vt("Abstract method `serialize` must be implemented.")}static _rescale(t,e,s,i,n,r){r||(r=new Float32Array(t.length));for(let o=0,h=t.length;o<h;o+=2)r[o]=e+t[o]*i,r[o+1]=s+t[o+1]*n;return r}static _rescaleAndSwap(t,e,s,i,n,r){r||(r=new Float32Array(t.length));for(let o=0,h=t.length;o<h;o+=2)r[o]=e+t[o+1]*i,r[o+1]=s+t[o]*n;return r}static _translate(t,e,s,i){i||(i=new Float32Array(t.length));for(let n=0,r=t.length;n<r;n+=2)i[n]=e+t[n],i[n+1]=s+t[n+1];return i}static svgRound(t){return Math.round(t*1e4)}static _normalizePoint(t,e,s,i,n){switch(n){case 90:return[1-e/s,t/i];case 180:return[1-t/s,1-e/i];case 270:return[e/s,1-t/i];default:return[t/s,e/i]}}static _normalizePagePoint(t,e,s){switch(s){case 90:return[1-e,t];case 180:return[1-t,1-e];case 270:return[e,1-t];default:return[t,e]}}static createBezierPoints(t,e,s,i,n,r){return[(t+5*s)/6,(e+5*i)/6,(5*s+n)/6,(5*i+r)/6,(s+n)/2,(i+r)/2]}}$(H,"PRECISION",1e-4);const gn=class gn{constructor({x:t,y:e},s,i,n,r,o=0){v(this,Jt);v(this,cs);v(this,Ks,[]);v(this,Xa);v(this,Wa);v(this,wi,[]);v(this,it,new Float32Array(18));v(this,So);v(this,Co);v(this,nc);v(this,rc);v(this,Ua);v(this,Ya);v(this,sr,[]);m(this,cs,s),m(this,Ya,n*i),m(this,Wa,r),l(this,it).set([NaN,NaN,NaN,NaN,t,e],6),m(this,Xa,o),m(this,rc,l(gn,oc)*i),m(this,nc,l(gn,xd)*i),m(this,Ua,i),l(this,sr).push(t,e)}isEmpty(){return isNaN(l(this,it)[8])}add({x:t,y:e}){var O;m(this,So,t),m(this,Co,e);const[s,i,n,r]=l(this,cs);let[o,h,c,u]=l(this,it).subarray(8,12);const d=t-c,f=e-u,g=Math.hypot(d,f);if(g<l(this,nc))return!1;const p=g-l(this,rc),b=p/g,_=b*d,y=b*f;let x=o,S=h;o=c,h=u,c+=_,u+=y,(O=l(this,sr))==null||O.push(t,e);const C=-y/p,E=_/p,D=C*l(this,Ya),M=E*l(this,Ya);return l(this,it).set(l(this,it).subarray(2,8),0),l(this,it).set([c+D,u+M],4),l(this,it).set(l(this,it).subarray(14,18),12),l(this,it).set([c-D,u-M],16),isNaN(l(this,it)[6])?(l(this,wi).length===0&&(l(this,it).set([o+D,h+M],2),l(this,wi).push(NaN,NaN,NaN,NaN,(o+D-s)/n,(h+M-i)/r),l(this,it).set([o-D,h-M],14),l(this,Ks).push(NaN,NaN,NaN,NaN,(o-D-s)/n,(h-M-i)/r)),l(this,it).set([x,S,o,h,c,u],6),!this.isEmpty()):(l(this,it).set([x,S,o,h,c,u],6),Math.abs(Math.atan2(S-h,x-o)-Math.atan2(y,_))<Math.PI/2?([o,h,c,u]=l(this,it).subarray(2,6),l(this,wi).push(NaN,NaN,NaN,NaN,((o+c)/2-s)/n,((h+u)/2-i)/r),[o,h,x,S]=l(this,it).subarray(14,18),l(this,Ks).push(NaN,NaN,NaN,NaN,((x+o)/2-s)/n,((S+h)/2-i)/r),!0):([x,S,o,h,c,u]=l(this,it).subarray(0,6),l(this,wi).push(((x+5*o)/6-s)/n,((S+5*h)/6-i)/r,((5*o+c)/6-s)/n,((5*h+u)/6-i)/r,((o+c)/2-s)/n,((h+u)/2-i)/r),[c,u,o,h,x,S]=l(this,it).subarray(12,18),l(this,Ks).push(((x+5*o)/6-s)/n,((S+5*h)/6-i)/r,((5*o+c)/6-s)/n,((5*h+u)/6-i)/r,((o+c)/2-s)/n,((h+u)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";const t=l(this,wi),e=l(this,Ks);if(isNaN(l(this,it)[6])&&!this.isEmpty())return w(this,Jt,Xy).call(this);const s=[];s.push(`M${t[4]} ${t[5]}`);for(let i=6;i<t.length;i+=6)isNaN(t[i])?s.push(`L${t[i+4]} ${t[i+5]}`):s.push(`C${t[i]} ${t[i+1]} ${t[i+2]} ${t[i+3]} ${t[i+4]} ${t[i+5]}`);w(this,Jt,Uy).call(this,s);for(let i=e.length-6;i>=6;i-=6)isNaN(e[i])?s.push(`L${e[i+4]} ${e[i+5]}`):s.push(`C${e[i]} ${e[i+1]} ${e[i+2]} ${e[i+3]} ${e[i+4]} ${e[i+5]}`);return w(this,Jt,Wy).call(this,s),s.join(" ")}newFreeDrawOutline(t,e,s,i,n,r){return new Nb(t,e,s,i,n,r)}getOutlines(){var d;const t=l(this,wi),e=l(this,Ks),s=l(this,it),[i,n,r,o]=l(this,cs),h=new Float32Array((((d=l(this,sr))==null?void 0:d.length)??0)+2);for(let f=0,g=h.length-2;f<g;f+=2)h[f]=(l(this,sr)[f]-i)/r,h[f+1]=(l(this,sr)[f+1]-n)/o;if(h[h.length-2]=(l(this,So)-i)/r,h[h.length-1]=(l(this,Co)-n)/o,isNaN(s[6])&&!this.isEmpty())return w(this,Jt,Yy).call(this,h);const c=new Float32Array(l(this,wi).length+24+l(this,Ks).length);let u=t.length;for(let f=0;f<u;f+=2){if(isNaN(t[f])){c[f]=c[f+1]=NaN;continue}c[f]=t[f],c[f+1]=t[f+1]}u=w(this,Jt,qy).call(this,c,u);for(let f=e.length-6;f>=6;f-=6)for(let g=0;g<6;g+=2){if(isNaN(e[f+g])){c[u]=c[u+1]=NaN,u+=2;continue}c[u]=e[f+g],c[u+1]=e[f+g+1],u+=2}return w(this,Jt,$y).call(this,c,u),this.newFreeDrawOutline(c,h,l(this,cs),l(this,Ua),l(this,Xa),l(this,Wa))}};cs=new WeakMap,Ks=new WeakMap,Xa=new WeakMap,Wa=new WeakMap,wi=new WeakMap,it=new WeakMap,So=new WeakMap,Co=new WeakMap,nc=new WeakMap,rc=new WeakMap,Ua=new WeakMap,Ya=new WeakMap,sr=new WeakMap,oc=new WeakMap,wd=new WeakMap,xd=new WeakMap,Jt=new WeakSet,Oc=function(){const t=l(this,it).subarray(4,6),e=l(this,it).subarray(16,18),[s,i,n,r]=l(this,cs);return[(l(this,So)+(t[0]-e[0])/2-s)/n,(l(this,Co)+(t[1]-e[1])/2-i)/r,(l(this,So)+(e[0]-t[0])/2-s)/n,(l(this,Co)+(e[1]-t[1])/2-i)/r]},Xy=function(){const[t,e,s,i]=l(this,cs),[n,r,o,h]=w(this,Jt,Oc).call(this);return`M${(l(this,it)[2]-t)/s} ${(l(this,it)[3]-e)/i} L${(l(this,it)[4]-t)/s} ${(l(this,it)[5]-e)/i} L${n} ${r} L${o} ${h} L${(l(this,it)[16]-t)/s} ${(l(this,it)[17]-e)/i} L${(l(this,it)[14]-t)/s} ${(l(this,it)[15]-e)/i} Z`},Wy=function(t){const e=l(this,Ks);t.push(`L${e[4]} ${e[5]} Z`)},Uy=function(t){const[e,s,i,n]=l(this,cs),r=l(this,it).subarray(4,6),o=l(this,it).subarray(16,18),[h,c,u,d]=w(this,Jt,Oc).call(this);t.push(`L${(r[0]-e)/i} ${(r[1]-s)/n} L${h} ${c} L${u} ${d} L${(o[0]-e)/i} ${(o[1]-s)/n}`)},Yy=function(t){const e=l(this,it),[s,i,n,r]=l(this,cs),[o,h,c,u]=w(this,Jt,Oc).call(this),d=new Float32Array(36);return d.set([NaN,NaN,NaN,NaN,(e[2]-s)/n,(e[3]-i)/r,NaN,NaN,NaN,NaN,(e[4]-s)/n,(e[5]-i)/r,NaN,NaN,NaN,NaN,o,h,NaN,NaN,NaN,NaN,c,u,NaN,NaN,NaN,NaN,(e[16]-s)/n,(e[17]-i)/r,NaN,NaN,NaN,NaN,(e[14]-s)/n,(e[15]-i)/r],0),this.newFreeDrawOutline(d,t,l(this,cs),l(this,Ua),l(this,Xa),l(this,Wa))},$y=function(t,e){const s=l(this,Ks);return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6},qy=function(t,e){const s=l(this,it).subarray(4,6),i=l(this,it).subarray(16,18),[n,r,o,h]=l(this,cs),[c,u,d,f]=w(this,Jt,Oc).call(this);return t.set([NaN,NaN,NaN,NaN,(s[0]-n)/o,(s[1]-r)/h,NaN,NaN,NaN,NaN,c,u,NaN,NaN,NaN,NaN,d,f,NaN,NaN,NaN,NaN,(i[0]-n)/o,(i[1]-r)/h],e),e+=24},v(gn,oc,8),v(gn,wd,2),v(gn,xd,l(gn,oc)+l(gn,wd));let id=gn;class Nb extends H{constructor(e,s,i,n,r,o){super();v(this,Sd);v(this,$a);v(this,Ao,new Float32Array(4));v(this,pn);v(this,ac);v(this,us);v(this,hc);v(this,Ht);m(this,Ht,e),m(this,us,s),m(this,$a,i),m(this,hc,n),m(this,pn,r),m(this,ac,o),this.lastPoint=[NaN,NaN],w(this,Sd,Ky).call(this,o);const[h,c,u,d]=l(this,Ao);for(let f=0,g=e.length;f<g;f+=2)e[f]=(e[f]-h)/u,e[f+1]=(e[f+1]-c)/d;for(let f=0,g=s.length;f<g;f+=2)s[f]=(s[f]-h)/u,s[f+1]=(s[f+1]-c)/d}toSVGPath(){const e=[`M${l(this,Ht)[4]} ${l(this,Ht)[5]}`];for(let s=6,i=l(this,Ht).length;s<i;s+=6){if(isNaN(l(this,Ht)[s])){e.push(`L${l(this,Ht)[s+4]} ${l(this,Ht)[s+5]}`);continue}e.push(`C${l(this,Ht)[s]} ${l(this,Ht)[s+1]} ${l(this,Ht)[s+2]} ${l(this,Ht)[s+3]} ${l(this,Ht)[s+4]} ${l(this,Ht)[s+5]}`)}return e.push("Z"),e.join(" ")}serialize([e,s,i,n],r){const o=i-e,h=n-s;let c,u;switch(r){case 0:c=H._rescale(l(this,Ht),e,n,o,-h),u=H._rescale(l(this,us),e,n,o,-h);break;case 90:c=H._rescaleAndSwap(l(this,Ht),e,s,o,h),u=H._rescaleAndSwap(l(this,us),e,s,o,h);break;case 180:c=H._rescale(l(this,Ht),i,s,-o,h),u=H._rescale(l(this,us),i,s,-o,h);break;case 270:c=H._rescaleAndSwap(l(this,Ht),i,n,-o,-h),u=H._rescaleAndSwap(l(this,us),i,n,-o,-h);break}return{outline:Array.from(c),points:[Array.from(u)]}}get box(){return l(this,Ao)}newOutliner(e,s,i,n,r,o=0){return new id(e,s,i,n,r,o)}getNewOutline(e,s){const[i,n,r,o]=l(this,Ao),[h,c,u,d]=l(this,$a),f=r*u,g=o*d,p=i*u+h,b=n*d+c,_=this.newOutliner({x:l(this,us)[0]*f+p,y:l(this,us)[1]*g+b},l(this,$a),l(this,hc),e,l(this,ac),s??l(this,pn));for(let y=2;y<l(this,us).length;y+=2)_.add({x:l(this,us)[y]*f+p,y:l(this,us)[y+1]*g+b});return _.getOutlines()}}$a=new WeakMap,Ao=new WeakMap,pn=new WeakMap,ac=new WeakMap,us=new WeakMap,hc=new WeakMap,Ht=new WeakMap,Sd=new WeakSet,Ky=function(e){const s=l(this,Ht);let i=s[4],n=s[5],r=i,o=n,h=i,c=n,u=i,d=n;const f=e?Math.max:Math.min;for(let p=6,b=s.length;p<b;p+=6){if(isNaN(s[p]))r=Math.min(r,s[p+4]),o=Math.min(o,s[p+5]),h=Math.max(h,s[p+4]),c=Math.max(c,s[p+5]),d<s[p+5]?(u=s[p+4],d=s[p+5]):d===s[p+5]&&(u=f(u,s[p+4]));else{const _=U.bezierBoundingBox(i,n,...s.slice(p,p+6));r=Math.min(r,_[0]),o=Math.min(o,_[1]),h=Math.max(h,_[2]),c=Math.max(c,_[3]),d<_[3]?(u=_[2],d=_[3]):d===_[3]&&(u=f(u,_[2]))}i=s[p+4],n=s[p+5]}const g=l(this,Ao);g[0]=r-l(this,pn),g[1]=o-l(this,pn),g[2]=h-r+2*l(this,pn),g[3]=c-o+2*l(this,pn),this.lastPoint=[u,d]};class Lg{constructor(t,e=0,s=0,i=!0){v(this,Ie);v(this,lc);v(this,cc);v(this,ir,[]);v(this,Qs,[]);let n=1/0,r=-1/0,o=1/0,h=-1/0;const c=10**-4;for(const{x:_,y,width:x,height:S}of t){const C=Math.floor((_-e)/c)*c,E=Math.ceil((_+x+e)/c)*c,D=Math.floor((y-e)/c)*c,M=Math.ceil((y+S+e)/c)*c,k=[C,D,M,!0],O=[E,D,M,!1];l(this,ir).push(k,O),n=Math.min(n,C),r=Math.max(r,E),o=Math.min(o,D),h=Math.max(h,M)}const u=r-n+2*s,d=h-o+2*s,f=n-s,g=o-s,p=l(this,ir).at(i?-1:-2),b=[p[0],p[2]];for(const _ of l(this,ir)){const[y,x,S]=_;_[0]=(y-f)/u,_[1]=(x-g)/d,_[2]=(S-g)/d}m(this,lc,new Float32Array([f,g,u,d])),m(this,cc,b)}getOutlines(){l(this,ir).sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);const t=[];for(const e of l(this,ir))e[3]?(t.push(...w(this,Ie,Ep).call(this,e)),w(this,Ie,Jy).call(this,e)):(w(this,Ie,Zy).call(this,e),t.push(...w(this,Ie,Ep).call(this,e)));return w(this,Ie,Qy).call(this,t)}}lc=new WeakMap,cc=new WeakMap,ir=new WeakMap,Qs=new WeakMap,Ie=new WeakSet,Qy=function(t){const e=[],s=new Set;for(const r of t){const[o,h,c]=r;e.push([o,h,r],[o,c,r])}e.sort((r,o)=>r[1]-o[1]||r[0]-o[0]);for(let r=0,o=e.length;r<o;r+=2){const h=e[r][2],c=e[r+1][2];h.push(c),c.push(h),s.add(h),s.add(c)}const i=[];let n;for(;s.size>0;){const r=s.values().next().value;let[o,h,c,u,d]=r;s.delete(r);let f=o,g=h;for(n=[o,c],i.push(n);;){let p;if(s.has(u))p=u;else if(s.has(d))p=d;else break;s.delete(p),[o,h,c,u,d]=p,f!==o&&(n.push(f,g,o,g===h?h:c),f=o),g=g===h?c:h}n.push(f,g)}return new GS(i,l(this,lc),l(this,cc))},Yd=function(t){const e=l(this,Qs);let s=0,i=e.length-1;for(;s<=i;){const n=s+i>>1,r=e[n][0];if(r===t)return n;r<t?s=n+1:i=n-1}return i+1},Jy=function([,t,e]){const s=w(this,Ie,Yd).call(this,t);l(this,Qs).splice(s,0,[t,e])},Zy=function([,t,e]){const s=w(this,Ie,Yd).call(this,t);for(let i=s;i<l(this,Qs).length;i++){const[n,r]=l(this,Qs)[i];if(n!==t)break;if(n===t&&r===e){l(this,Qs).splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=l(this,Qs)[i];if(n!==t)break;if(n===t&&r===e){l(this,Qs).splice(i,1);return}}},Ep=function(t){const[e,s,i]=t,n=[[e,s,i]],r=w(this,Ie,Yd).call(this,i);for(let o=0;o<r;o++){const[h,c]=l(this,Qs)[o];for(let u=0,d=n.length;u<d;u++){const[,f,g]=n[u];if(!(c<=f||g<=h)){if(f>=h){if(g>c)n[u][1]=c;else{if(d===1)return[];n.splice(u,1),u--,d--}continue}n[u][2]=h,g>c&&n.push([e,c,g])}}}return n};class GS extends H{constructor(e,s,i){super();v(this,uc);v(this,qa);m(this,qa,e),m(this,uc,s),this.lastPoint=i}toSVGPath(){const e=[];for(const s of l(this,qa)){let[i,n]=s;e.push(`M${i} ${n}`);for(let r=2;r<s.length;r+=2){const o=s[r],h=s[r+1];o===i?(e.push(`V${h}`),n=h):h===n&&(e.push(`H${o}`),i=o)}e.push("Z")}return e.join(" ")}serialize([e,s,i,n],r){const o=[],h=i-e,c=n-s;for(const u of l(this,qa)){const d=new Array(u.length);for(let f=0;f<u.length;f+=2)d[f]=e+u[f]*h,d[f+1]=n-u[f+1]*c;o.push(d)}return o}get box(){return l(this,uc)}get classNamesForOutlining(){return["highlightOutline"]}}uc=new WeakMap,qa=new WeakMap;class Fg extends id{newFreeDrawOutline(t,e,s,i,n,r){return new VS(t,e,s,i,n,r)}}class VS extends Nb{newOutliner(t,e,s,i,n,r=0){return new Fg(t,e,s,i,n,r)}}const Ke=class Ke{constructor({editor:t=null,uiManager:e=null}){v(this,yt);v(this,Js,null);v(this,To,null);v(this,Ka);v(this,Zt,null);v(this,dc,!1);v(this,Qa,!1);v(this,fc,null);v(this,gc);v(this,nr,null);v(this,Zs,null);v(this,Ja);var s;t?(m(this,Qa,!1),m(this,Ja,ot.HIGHLIGHT_COLOR),m(this,fc,t)):(m(this,Qa,!0),m(this,Ja,ot.HIGHLIGHT_DEFAULT_COLOR)),m(this,Zs,(t==null?void 0:t._uiManager)||e),m(this,gc,l(this,Zs)._eventBus),m(this,Ka,(t==null?void 0:t.color)||((s=l(this,Zs))==null?void 0:s.highlightColors.values().next().value)||"#FFFF98"),l(Ke,pc)||m(Ke,pc,Object.freeze({blue:"pdfjs-editor-colorpicker-blue",green:"pdfjs-editor-colorpicker-green",pink:"pdfjs-editor-colorpicker-pink",red:"pdfjs-editor-colorpicker-red",yellow:"pdfjs-editor-colorpicker-yellow"}))}static get _keyboardManager(){return st(this,"_keyboardManager",new Xh([[["Escape","mac+Escape"],Ke.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],Ke.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],Ke.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],Ke.prototype._moveToPrevious],[["Home","mac+Home"],Ke.prototype._moveToBeginning],[["End","mac+End"],Ke.prototype._moveToEnd]]))}renderButton(){const t=m(this,Js,document.createElement("button"));t.className="colorPicker",t.tabIndex="0",t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-button"),t.setAttribute("aria-haspopup",!0);const e=l(this,Zs)._signal;t.addEventListener("click",w(this,yt,zo).bind(this),{signal:e}),t.addEventListener("keydown",w(this,yt,Pp).bind(this),{signal:e});const s=m(this,To,document.createElement("span"));return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=l(this,Ka),t.append(s),t}renderMainDropdown(){const t=m(this,Zt,w(this,yt,kp).call(this));return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}_colorSelectFromKeyboard(t){if(t.target===l(this,Js)){w(this,yt,zo).call(this,t);return}const e=t.target.getAttribute("data-color");e&&w(this,yt,Mp).call(this,e,t)}_moveToNext(t){var e,s;if(!l(this,yt,gr)){w(this,yt,zo).call(this,t);return}if(t.target===l(this,Js)){(e=l(this,Zt).firstChild)==null||e.focus();return}(s=t.target.nextSibling)==null||s.focus()}_moveToPrevious(t){var e,s;if(t.target===((e=l(this,Zt))==null?void 0:e.firstChild)||t.target===l(this,Js)){l(this,yt,gr)&&this._hideDropdownFromKeyboard();return}l(this,yt,gr)||w(this,yt,zo).call(this,t),(s=t.target.previousSibling)==null||s.focus()}_moveToBeginning(t){var e;if(!l(this,yt,gr)){w(this,yt,zo).call(this,t);return}(e=l(this,Zt).firstChild)==null||e.focus()}_moveToEnd(t){var e;if(!l(this,yt,gr)){w(this,yt,zo).call(this,t);return}(e=l(this,Zt).lastChild)==null||e.focus()}hideDropdown(){var t,e;(t=l(this,Zt))==null||t.classList.add("hidden"),(e=l(this,nr))==null||e.abort(),m(this,nr,null)}_hideDropdownFromKeyboard(){var t;if(!l(this,Qa)){if(!l(this,yt,gr)){(t=l(this,fc))==null||t.unselect();return}this.hideDropdown(),l(this,Js).focus({preventScroll:!0,focusVisible:l(this,dc)})}}updateColor(t){if(l(this,To)&&(l(this,To).style.backgroundColor=t),!l(this,Zt))return;const e=l(this,Zs).highlightColors.values();for(const s of l(this,Zt).children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){var t,e;(t=l(this,Js))==null||t.remove(),m(this,Js,null),m(this,To,null),(e=l(this,Zt))==null||e.remove(),m(this,Zt,null)}};Js=new WeakMap,To=new WeakMap,Ka=new WeakMap,Zt=new WeakMap,dc=new WeakMap,Qa=new WeakMap,fc=new WeakMap,gc=new WeakMap,nr=new WeakMap,Zs=new WeakMap,Ja=new WeakMap,pc=new WeakMap,yt=new WeakSet,kp=function(){const t=document.createElement("div"),e=l(this,Zs)._signal;t.addEventListener("contextmenu",zs,{signal:e}),t.className="dropdown",t.role="listbox",t.setAttribute("aria-multiselectable",!1),t.setAttribute("aria-orientation","vertical"),t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown");for(const[s,i]of l(this,Zs).highlightColors){const n=document.createElement("button");n.tabIndex="0",n.role="option",n.setAttribute("data-color",i),n.title=s,n.setAttribute("data-l10n-id",l(Ke,pc)[s]);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===l(this,Ka)),n.addEventListener("click",w(this,yt,Mp).bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",w(this,yt,Pp).bind(this),{signal:e}),t},Mp=function(t,e){e.stopPropagation(),l(this,gc).dispatch("switchannotationeditorparams",{source:this,type:l(this,Ja),value:t})},Pp=function(t){Ke._keyboardManager.exec(this,t)},zo=function(t){if(l(this,yt,gr)){this.hideDropdown();return}if(m(this,dc,t.detail===0),l(this,nr)||(m(this,nr,new AbortController),window.addEventListener("pointerdown",w(this,yt,tv).bind(this),{signal:l(this,Zs).combinedSignal(l(this,nr))})),l(this,Zt)){l(this,Zt).classList.remove("hidden");return}const e=m(this,Zt,w(this,yt,kp).call(this));l(this,Js).append(e)},tv=function(t){var e;(e=l(this,Zt))!=null&&e.contains(t.target)||this.hideDropdown()},gr=function(){return l(this,Zt)&&!l(this,Zt).classList.contains("hidden")},v(Ke,pc,null);let nd=Ke;const ut=class ut extends Pt{constructor(e){super({...e,name:"highlightEditor"});v(this,J);v(this,Za,null);v(this,mc,0);v(this,mn);v(this,Eo,null);v(this,th,null);v(this,Qe,null);v(this,bc,null);v(this,yc,0);v(this,ko,null);v(this,Ts,null);v(this,ds,null);v(this,le,!1);v(this,eh,null);v(this,bn);v(this,Se,null);v(this,sh,"");v(this,Es);v(this,vc,"");this.color=e.color||ut._defaultColor,m(this,Es,e.thickness||ut._defaultThickness),m(this,bn,e.opacity||ut._defaultOpacity),m(this,mn,e.boxes||null),m(this,vc,e.methodOfCreation||""),m(this,sh,e.text||""),this._isDraggable=!1,e.highlightId>-1?(m(this,le,!0),w(this,J,$d).call(this,e),w(this,J,Go).call(this)):l(this,mn)&&(m(this,Za,e.anchorNode),m(this,mc,e.anchorOffset),m(this,bc,e.focusNode),m(this,yc,e.focusOffset),w(this,J,Dp).call(this),w(this,J,Go).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const e=ut.prototype;return st(this,"_keyboardManager",new Xh([[["ArrowLeft","mac+ArrowLeft"],e._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],e._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],e._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],e._moveCaret,{args:[3]}]]))}get telemetryInitialData(){return{action:"added",type:l(this,le)?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:l(this,Es),methodOfCreation:l(this,vc)}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.highlightColorNames.get(this.color)}}static computeTelemetryFinalData(e){return{numberOfColors:e.get("color").size}}static initialize(e,s){var i;Pt.initialize(e,s),ut._defaultColor||(ut._defaultColor=((i=s.highlightColors)==null?void 0:i.values().next().value)||"#fff066")}static updateDefaultParams(e,s){switch(e){case ot.HIGHLIGHT_DEFAULT_COLOR:ut._defaultColor=s;break;case ot.HIGHLIGHT_THICKNESS:ut._defaultThickness=s;break}}translateInPage(e,s){}get toolbarPosition(){return l(this,eh)}updateParams(e,s){switch(e){case ot.HIGHLIGHT_COLOR:w(this,J,ev).call(this,s);break;case ot.HIGHLIGHT_THICKNESS:w(this,J,sv).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[ot.HIGHLIGHT_DEFAULT_COLOR,ut._defaultColor],[ot.HIGHLIGHT_THICKNESS,ut._defaultThickness]]}get propertiesToUpdate(){return[[ot.HIGHLIGHT_COLOR,this.color||ut._defaultColor],[ot.HIGHLIGHT_THICKNESS,l(this,Es)||ut._defaultThickness],[ot.HIGHLIGHT_FREE,l(this,le)]]}async addEditToolbar(){const e=await super.addEditToolbar();return e?(this._uiManager.highlightColors&&(m(this,th,new nd({editor:this})),e.addColorPicker(l(this,th))),e):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(w(this,J,Rc).call(this))}getBaseTranslation(){return[0,0]}getRect(e,s){return super.getRect(e,s,w(this,J,Rc).call(this))}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),e&&this.div.focus()}remove(){w(this,J,Op).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,J,Go).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?w(this,J,Op).call(this):e&&(w(this,J,Go).call(this,e),s=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),this.show(this._isVisible),s&&this.select()}rotate(e){var n,r,o;const{drawLayer:s}=this.parent;let i;l(this,le)?(e=(e-this.rotation+360)%360,i=w(n=ut,ks,_h).call(n,l(this,Ts).box,e)):i=w(r=ut,ks,_h).call(r,[this.x,this.y,this.width,this.height],e),s.updateProperties(l(this,ds),{bbox:i,root:{"data-main-rotation":e}}),s.updateProperties(l(this,Se),{bbox:w(o=ut,ks,_h).call(o,l(this,Qe).box,e),root:{"data-main-rotation":e}})}render(){if(this.div)return this.div;const e=super.render();l(this,sh)&&(e.setAttribute("aria-label",l(this,sh)),e.setAttribute("role","mark")),l(this,le)?e.classList.add("free"):this.div.addEventListener("keydown",w(this,J,nv).bind(this),{signal:this._uiManager._signal});const s=m(this,ko,document.createElement("div"));e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",s.style.clipPath=l(this,Eo);const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),$u(this,l(this,ko),["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Se),{rootClass:{hovered:!0}})}pointerleave(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Se),{rootClass:{hovered:!1}})}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:w(this,J,qd).call(this,!0);break;case 1:case 3:w(this,J,qd).call(this,!1);break}}select(){var e;super.select(),l(this,Se)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Se),{rootClass:{hovered:!1,selected:!0}}))}unselect(){var e;super.unselect(),l(this,Se)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Se),{rootClass:{selected:!1}}),l(this,le)||w(this,J,qd).call(this,!1))}get _mustFixPosition(){return!l(this,le)}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.updateProperties(l(this,ds),{rootClass:{hidden:!e}}),this.parent.drawLayer.updateProperties(l(this,Se),{rootClass:{hidden:!e}}))}static startHighlighting(e,s,{target:i,x:n,y:r}){const{x:o,y:h,width:c,height:u}=i.getBoundingClientRect(),d=new AbortController,f=e.combinedSignal(d),g=p=>{d.abort(),w(this,ks,hv).call(this,e,p)};window.addEventListener("blur",g,{signal:f}),window.addEventListener("pointerup",g,{signal:f}),window.addEventListener("pointerdown",es,{capture:!0,passive:!1,signal:f}),window.addEventListener("contextmenu",zs,{signal:f}),i.addEventListener("pointermove",w(this,ks,av).bind(this,e),{signal:f}),this._freeHighlight=new Fg({x:n,y:r},[o,h,c,u],e.scale,this._defaultThickness/2,s,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0)}static async deserialize(e,s,i){var b,_,y,x;let n=null;if(e instanceof Fb){const{data:{quadPoints:S,rect:C,rotation:E,id:D,color:M,opacity:k,popupRef:O},parent:{page:{pageNumber:R}}}=e;n=e={annotationType:Z.HIGHLIGHT,color:Array.from(M),opacity:k,quadPoints:S,boxes:null,pageIndex:R-1,rect:C.slice(0),rotation:E,id:D,deleted:!1,popupRef:O}}else if(e instanceof Og){const{data:{inkLists:S,rect:C,rotation:E,id:D,color:M,borderStyle:{rawWidth:k},popupRef:O},parent:{page:{pageNumber:R}}}=e;n=e={annotationType:Z.HIGHLIGHT,color:Array.from(M),thickness:k,inkLists:S,boxes:null,pageIndex:R-1,rect:C.slice(0),rotation:E,id:D,deleted:!1,popupRef:O}}const{color:r,quadPoints:o,inkLists:h,opacity:c}=e,u=await super.deserialize(e,s,i);u.color=U.makeHexColor(...r),m(u,bn,c||1),h&&m(u,Es,e.thickness),u.annotationElementId=e.id||null,u._initialData=n;const[d,f]=u.pageDimensions,[g,p]=u.pageTranslation;if(o){const S=m(u,mn,[]);for(let C=0;C<o.length;C+=8)S.push({x:(o[C]-g)/d,y:1-(o[C+1]-p)/f,width:(o[C+2]-o[C])/d,height:(o[C+1]-o[C+5])/f});w(b=u,J,Dp).call(b),w(_=u,J,Go).call(_),u.rotate(u.rotation)}else if(h){m(u,le,!0);const S=h[0],C={x:S[0]-g,y:f-(S[1]-p)},E=new Fg(C,[0,0,d,f],1,l(u,Es)/2,!0,.001);for(let k=0,O=S.length;k<O;k+=2)C.x=S[k]-g,C.y=f-(S[k+1]-p),E.add(C);const{id:D,clipPathId:M}=s.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:u.color,"fill-opacity":u._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:E.toSVGPath()}},!0,!0);w(y=u,J,$d).call(y,{highlightOutlines:E.getOutlines(),highlightId:D,clipPathId:M}),w(x=u,J,Go).call(x)}return u}serialize(e=!1){if(this.isEmpty()||e)return null;if(this.deleted)return this.serializeDeleted();const s=this.getRect(0,0),i=Pt._colorManager.convert(this.color),n={annotationType:Z.HIGHLIGHT,color:i,opacity:l(this,bn),thickness:l(this,Es),quadPoints:w(this,J,rv).call(this),outlines:w(this,J,ov).call(this,s),pageIndex:this.pageIndex,rect:s,rotation:w(this,J,Rc).call(this),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!w(this,J,lv).call(this,n)?null:(n.id=this.annotationElementId,n)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};Za=new WeakMap,mc=new WeakMap,mn=new WeakMap,Eo=new WeakMap,th=new WeakMap,Qe=new WeakMap,bc=new WeakMap,yc=new WeakMap,ko=new WeakMap,Ts=new WeakMap,ds=new WeakMap,le=new WeakMap,eh=new WeakMap,bn=new WeakMap,Se=new WeakMap,sh=new WeakMap,Es=new WeakMap,vc=new WeakMap,J=new WeakSet,Dp=function(){const e=new Lg(l(this,mn),.001);m(this,Ts,e.getOutlines()),[this.x,this.y,this.width,this.height]=l(this,Ts).box;const s=new Lg(l(this,mn),.0025,.001,this._uiManager.direction==="ltr");m(this,Qe,s.getOutlines());const{lastPoint:i}=l(this,Qe);m(this,eh,[(i[0]-this.x)/this.width,(i[1]-this.y)/this.height])},$d=function({highlightOutlines:e,highlightId:s,clipPathId:i}){var d,f;if(m(this,Ts,e),m(this,Qe,e.getNewOutline(l(this,Es)/2+1.5,.0025)),s>=0)m(this,ds,s),m(this,Eo,i),this.parent.drawLayer.finalizeDraw(s,{bbox:e.box,path:{d:e.toSVGPath()}}),m(this,Se,this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:l(this,Qe).box,path:{d:l(this,Qe).toSVGPath()}},!0));else if(this.parent){const g=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(l(this,ds),{bbox:w(d=ut,ks,_h).call(d,l(this,Ts).box,(g-this.rotation+360)%360),path:{d:e.toSVGPath()}}),this.parent.drawLayer.updateProperties(l(this,Se),{bbox:w(f=ut,ks,_h).call(f,l(this,Qe).box,g),path:{d:l(this,Qe).toSVGPath()}})}const[r,o,h,c]=e.box;switch(this.rotation){case 0:this.x=r,this.y=o,this.width=h,this.height=c;break;case 90:{const[g,p]=this.parentDimensions;this.x=o,this.y=1-r,this.width=h*p/g,this.height=c*g/p;break}case 180:this.x=1-r,this.y=1-o,this.width=h,this.height=c;break;case 270:{const[g,p]=this.parentDimensions;this.x=1-o,this.y=r,this.width=h*p/g,this.height=c*g/p;break}}const{lastPoint:u}=l(this,Qe);m(this,eh,[(u[0]-r)/h,(u[1]-o)/c])},ev=function(e){const s=(r,o)=>{var h,c;this.color=r,m(this,bn,o),(h=this.parent)==null||h.drawLayer.updateProperties(l(this,ds),{root:{fill:r,"fill-opacity":o}}),(c=l(this,th))==null||c.updateColor(r)},i=this.color,n=l(this,bn);this.addCommands({cmd:s.bind(this,e,ut._defaultOpacity),undo:s.bind(this,i,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:ot.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(e)},!0)},sv=function(e){const s=l(this,Es),i=n=>{m(this,Es,n),w(this,J,iv).call(this,n)};this.addCommands({cmd:i.bind(this,e),undo:i.bind(this,s),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:ot.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)},iv=function(e){if(!l(this,le))return;w(this,J,$d).call(this,{highlightOutlines:l(this,Ts).getNewOutline(e/2)}),this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)},Op=function(){l(this,ds)===null||!this.parent||(this.parent.drawLayer.remove(l(this,ds)),m(this,ds,null),this.parent.drawLayer.remove(l(this,Se)),m(this,Se,null))},Go=function(e=this.parent){l(this,ds)===null&&({id:ze(this,ds)._,clipPathId:ze(this,Eo)._}=e.drawLayer.draw({bbox:l(this,Ts).box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":l(this,bn)},rootClass:{highlight:!0,free:l(this,le)},path:{d:l(this,Ts).toSVGPath()}},!1,!0),m(this,Se,e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:l(this,le)},bbox:l(this,Qe).box,path:{d:l(this,Qe).toSVGPath()}},l(this,le))),l(this,ko)&&(l(this,ko).style.clipPath=l(this,Eo)))},ks=new WeakSet,_h=function([e,s,i,n],r){switch(r){case 90:return[1-s-n,e,n,i];case 180:return[1-e-i,1-s-n,i,n];case 270:return[s,1-e-i,n,i]}return[e,s,i,n]},nv=function(e){ut._keyboardManager.exec(this,e)},qd=function(e){if(!l(this,Za))return;const s=window.getSelection();e?s.setPosition(l(this,Za),l(this,mc)):s.setPosition(l(this,bc),l(this,yc))},Rc=function(){return l(this,le)?this.rotation:0},rv=function(){if(l(this,le))return null;const[e,s]=this.pageDimensions,[i,n]=this.pageTranslation,r=l(this,mn),o=new Float32Array(r.length*8);let h=0;for(const{x:c,y:u,width:d,height:f}of r){const g=c*e+i,p=(1-u)*s+n;o[h]=o[h+4]=g,o[h+1]=o[h+3]=p,o[h+2]=o[h+6]=g+d*e,o[h+5]=o[h+7]=p-f*s,h+=8}return o},ov=function(e){return l(this,Ts).serialize(e,w(this,J,Rc).call(this))},av=function(e,s){this._freeHighlight.add(s)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})},hv=function(e,s){this._freeHighlight.isEmpty()?e.drawLayer.remove(this._freeHighlightId):e.createAndAddNewEditor(s,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:"main_toolbar"}),this._freeHighlightId=-1,this._freeHighlight=null,this._freeHighlightClipId=""},lv=function(e){const{color:s}=this._initialData;return e.color.some((i,n)=>i!==s[n])},v(ut,ks),$(ut,"_defaultColor",null),$(ut,"_defaultOpacity",1),$(ut,"_defaultThickness",12),$(ut,"_type","highlight"),$(ut,"_editorType",Z.HIGHLIGHT),$(ut,"_freeHighlightId",-1),$(ut,"_freeHighlight",null),$(ut,"_freeHighlightClipId","");let rd=ut;class XS{constructor(){v(this,Mo,Object.create(null))}updateProperty(t,e){this[t]=e,this.updateSVGProperty(t,e)}updateProperties(t){if(t)for(const[e,s]of Object.entries(t))this.updateProperty(e,s)}updateSVGProperty(t,e){l(this,Mo)[t]=e}toSVGProperties(){const t=l(this,Mo);return m(this,Mo,Object.create(null)),{root:t}}reset(){m(this,Mo,Object.create(null))}updateAll(t=this){this.updateProperties(t)}clone(){vt("Not implemented")}}Mo=new WeakMap;const z=class z extends Pt{constructor(e){super(e);v(this,lt);v(this,fs,null);v(this,ih);$(this,"_drawId",null);m(this,ih,e.mustBeCommitted||!1),e.drawOutlines&&(w(this,lt,Rp).call(this,e),w(this,lt,Lc).call(this))}static _mergeSVGProperties(e,s){const i=new Set(Object.keys(e));for(const[n,r]of Object.entries(s))i.has(n)?Object.assign(e[n],r):e[n]=r;return e}static getDefaultDrawingOptions(e){vt("Not implemented")}static get typesMap(){vt("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(e,s){const i=this.typesMap.get(e);i&&this._defaultDrawingOptions.updateProperty(i,s),this._currentParent&&(l(z,ne).updateProperty(i,s),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(e,s){const i=this.constructor.typesMap.get(e);i&&this._updateProperty(e,i,s)}static get defaultPropertiesToUpdate(){const e=[],s=this._defaultDrawingOptions;for(const[i,n]of this.typesMap)e.push([i,s[n]]);return e}get propertiesToUpdate(){const e=[],{_drawingOptions:s}=this;for(const[i,n]of this.constructor.typesMap)e.push([i,s[n]]);return e}_updateProperty(e,s,i){const n=this._drawingOptions,r=n[s],o=h=>{var u;n.updateProperty(s,h);const c=l(this,fs).updateProperty(s,h);c&&w(this,lt,Fc).call(this,c),(u=this.parent)==null||u.drawLayer.updateProperties(this._drawId,n.toSVGProperties())};this.addCommands({cmd:o.bind(this,i),undo:o.bind(this,r),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:e,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,z._mergeSVGProperties(l(this,fs).getPathResizingSVGProperties(w(this,lt,Kd).call(this)),{bbox:w(this,lt,wh).call(this)}))}_onResized(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,z._mergeSVGProperties(l(this,fs).getPathResizedSVGProperties(w(this,lt,Kd).call(this)),{bbox:w(this,lt,wh).call(this)}))}_onTranslating(e,s){var i;(i=this.parent)==null||i.drawLayer.updateProperties(this._drawId,{bbox:w(this,lt,wh).call(this,e,s)})}_onTranslated(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,z._mergeSVGProperties(l(this,fs).getPathTranslatedSVGProperties(w(this,lt,Kd).call(this),this.parentDimensions),{bbox:w(this,lt,wh).call(this)}))}_onStartDragging(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}commit(){super.commit(),this.disableEditMode(),this.disableEditing()}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),this._isDraggable=!0,l(this,ih)&&(m(this,ih,!1),this.commit(),this.parent.setSelected(this),e&&this.isOnScreen&&this.div.focus())}remove(){w(this,lt,Fp).call(this),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,lt,Lc).call(this),w(this,lt,Fc).call(this,l(this,fs).box),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?(this._uiManager.removeShouldRescale(this),w(this,lt,Fp).call(this)):e&&(this._uiManager.addShouldRescale(this),w(this,lt,Lc).call(this,e),s=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),s&&this.select()}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,z._mergeSVGProperties({bbox:w(this,lt,wh).call(this)},l(this,fs).updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&w(this,lt,Fc).call(this,l(this,fs).updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;const e=super.render();e.classList.add("draw");const s=document.createElement("div");e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal";const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),this._uiManager.addShouldRescale(this),this.disableEditing(),e}static createDrawerInstance(e,s,i,n,r){vt("Not implemented")}static startDrawing(e,s,i,n){var _;const{target:r,offsetX:o,offsetY:h,pointerId:c,pointerType:u}=n;if(l(z,or)&&l(z,or)!==u)return;const{viewport:{rotation:d}}=e,{width:f,height:g}=r.getBoundingClientRect(),p=m(z,Po,new AbortController),b=e.combinedSignal(p);if(l(z,rr)||m(z,rr,c),l(z,or)??m(z,or,u),window.addEventListener("pointerup",y=>{var x;l(z,rr)===y.pointerId?this._endDraw(y):(x=l(z,ar))==null||x.delete(y.pointerId)},{signal:b}),window.addEventListener("pointercancel",y=>{var x;l(z,rr)===y.pointerId?this._currentParent.endDrawingSession():(x=l(z,ar))==null||x.delete(y.pointerId)},{signal:b}),window.addEventListener("pointerdown",y=>{l(z,or)===y.pointerType&&((l(z,ar)||m(z,ar,new Set)).add(y.pointerId),l(z,ne).isCancellable()&&(l(z,ne).removeLastElement(),l(z,ne).isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:b}),window.addEventListener("contextmenu",zs,{signal:b}),r.addEventListener("pointermove",this._drawMove.bind(this),{signal:b}),r.addEventListener("touchmove",y=>{y.timeStamp===l(z,Oo)&&es(y)},{signal:b}),e.toggleDrawing(),(_=s._editorUndoBar)==null||_.hide(),l(z,ne)){e.drawLayer.updateProperties(this._currentDrawId,l(z,ne).startNew(o,h,f,g,d));return}s.updateUIForDefaultProperties(this),m(z,ne,this.createDrawerInstance(o,h,f,g,d)),m(z,Do,this.getDefaultDrawingOptions()),this._currentParent=e,{id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties(l(z,Do).toSVGProperties(),l(z,ne).defaultSVGProperties),!0,!1)}static _drawMove(e){var r;if(m(z,Oo,-1),!l(z,ne))return;const{offsetX:s,offsetY:i,pointerId:n}=e;if(l(z,rr)===n){if(((r=l(z,ar))==null?void 0:r.size)>=1){this._endDraw(e);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,l(z,ne).add(s,i)),m(z,Oo,e.timeStamp),es(e)}}static _cleanup(e){e&&(this._currentDrawId=-1,this._currentParent=null,m(z,ne,null),m(z,Do,null),m(z,or,null),m(z,Oo,NaN)),l(z,Po)&&(l(z,Po).abort(),m(z,Po,null),m(z,rr,NaN),m(z,ar,null))}static _endDraw(e){const s=this._currentParent;if(s){if(s.toggleDrawing(!0),this._cleanup(!1),e&&s.drawLayer.updateProperties(this._currentDrawId,l(z,ne).end(e.offsetX,e.offsetY)),this.supportMultipleDrawings){const i=l(z,ne),n=this._currentDrawId,r=i.getLastElement();s.addCommands({cmd:()=>{s.drawLayer.updateProperties(n,i.setLastElement(r))},undo:()=>{s.drawLayer.updateProperties(n,i.removeLastElement())},mustExec:!1,type:ot.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(e){const s=this._currentParent;if(!s)return null;if(s.toggleDrawing(!0),s.cleanUndoStack(ot.DRAW_STEP),!l(z,ne).isEmpty()){const{pageDimensions:[i,n],scale:r}=s,o=s.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:l(z,ne).getOutlines(i*r,n*r,r,this._INNER_MARGIN),drawingOptions:l(z,Do),mustBeCommitted:!e});return this._cleanup(!0),o}return s.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(e){}static deserializeDraw(e,s,i,n,r,o){vt("Not implemented")}static async deserialize(e,s,i){var d,f;const{rawDims:{pageWidth:n,pageHeight:r,pageX:o,pageY:h}}=s.viewport,c=this.deserializeDraw(o,h,n,r,this._INNER_MARGIN,e),u=await super.deserialize(e,s,i);return u.createDrawingOptions(e),w(d=u,lt,Rp).call(d,{drawOutlines:c}),w(f=u,lt,Lc).call(f),u.onScaleChanging(),u.rotate(),u}serializeDraw(e){const[s,i]=this.pageTranslation,[n,r]=this.pageDimensions;return l(this,fs).serialize([s,i,n,r],e)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};fs=new WeakMap,ih=new WeakMap,ne=new WeakMap,Po=new WeakMap,Do=new WeakMap,rr=new WeakMap,or=new WeakMap,ar=new WeakMap,Oo=new WeakMap,lt=new WeakSet,Rp=function({drawOutlines:e,drawId:s,drawingOptions:i}){m(this,fs,e),this._drawingOptions||(this._drawingOptions=i),s>=0?(this._drawId=s,this.parent.drawLayer.finalizeDraw(s,e.defaultProperties)):this._drawId=w(this,lt,Lp).call(this,e,this.parent),w(this,lt,Fc).call(this,e.box)},Lp=function(e,s){const{id:i}=s.drawLayer.draw(z._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return i},Fp=function(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())},Lc=function(e=this.parent){if(!(this._drawId!==null&&this.parent===e)){if(this._drawId!==null){this.parent.drawLayer.updateParent(this._drawId,e.drawLayer);return}this._drawingOptions.updateAll(),this._drawId=w(this,lt,Lp).call(this,l(this,fs),e)}},cv=function([e,s,i,n]){const{parentDimensions:[r,o],rotation:h}=this;switch(h){case 90:return[s,1-e,i*(o/r),n*(r/o)];case 180:return[1-e,1-s,i,n];case 270:return[1-s,e,i*(o/r),n*(r/o)];default:return[e,s,i,n]}},Kd=function(){const{x:e,y:s,width:i,height:n,parentDimensions:[r,o],rotation:h}=this;switch(h){case 90:return[1-s,e,i*(r/o),n*(o/r)];case 180:return[1-e,1-s,i,n];case 270:return[s,1-e,i*(r/o),n*(o/r)];default:return[e,s,i,n]}},Fc=function(e){if([this.x,this.y,this.width,this.height]=w(this,lt,cv).call(this,e),this.div){this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)}this._onResized()},wh=function(){const{x:e,y:s,width:i,height:n,rotation:r,parentRotation:o,parentDimensions:[h,c]}=this;switch((r*4+o)/90){case 1:return[1-s-n,e,n,i];case 2:return[1-e-i,1-s-n,i,n];case 3:return[s,1-e-i,n,i];case 4:return[e,s-i*(h/c),n*(c/h),i*(h/c)];case 5:return[1-s,e,i*(h/c),n*(c/h)];case 6:return[1-e-n*(c/h),1-s,n*(c/h),i*(h/c)];case 7:return[s-i*(h/c),1-e-n*(c/h),i*(h/c),n*(c/h)];case 8:return[e-i,s-n,i,n];case 9:return[1-s,e-i,n,i];case 10:return[1-e,1-s,i,n];case 11:return[s-n,1-e,n,i];case 12:return[e-n*(c/h),s,n*(c/h),i*(h/c)];case 13:return[1-s-i*(h/c),e-n*(c/h),i*(h/c),n*(c/h)];case 14:return[1-e,1-s-i*(h/c),n*(c/h),i*(h/c)];case 15:return[s,1-e,i*(h/c),n*(c/h)];default:return[e,s,i,n]}},$(z,"_currentDrawId",-1),$(z,"_currentParent",null),v(z,ne,null),v(z,Po,null),v(z,Do,null),v(z,rr,NaN),v(z,or,null),v(z,ar,null),v(z,Oo,NaN),$(z,"_INNER_MARGIN",3);let Ig=z;class WS{constructor(t,e,s,i,n,r){v(this,rh);v(this,xi,new Float64Array(6));v(this,re);v(this,oe);v(this,Ro);v(this,nh);v(this,Ne);v(this,ce,"");v(this,Ms,0);v(this,Lo,new od);v(this,Fo);v(this,Io);m(this,Fo,s),m(this,Io,i),m(this,Ro,n),m(this,nh,r),[t,e]=w(this,rh,Qd).call(this,t,e);const o=m(this,re,[NaN,NaN,NaN,NaN,t,e]);m(this,Ne,[t,e]),m(this,oe,[{line:o,points:l(this,Ne)}]),l(this,xi).set(o,0)}updateProperty(t,e){t==="stroke-width"&&m(this,nh,e)}isEmpty(){return!l(this,oe)||l(this,oe).length===0}isCancellable(){return l(this,Ne).length<=10}add(t,e){[t,e]=w(this,rh,Qd).call(this,t,e);const[s,i,n,r]=l(this,xi).subarray(2,6),o=t-n,h=e-r;return Math.hypot(l(this,Fo)*o,l(this,Io)*h)<=2?null:(l(this,Ne).push(t,e),isNaN(s)?(l(this,xi).set([n,r,t,e],2),l(this,re).push(NaN,NaN,NaN,NaN,t,e),{path:{d:this.toSVGPath()}}):(isNaN(l(this,xi)[0])&&l(this,re).splice(6,6),l(this,xi).set([s,i,n,r,t,e],0),l(this,re).push(...H.createBezierPoints(s,i,n,r,t,e)),{path:{d:this.toSVGPath()}}))}end(t,e){const s=this.add(t,e);return s||(l(this,Ne).length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,s,i,n){m(this,Fo,s),m(this,Io,i),m(this,Ro,n),[t,e]=w(this,rh,Qd).call(this,t,e);const r=m(this,re,[NaN,NaN,NaN,NaN,t,e]);m(this,Ne,[t,e]);const o=l(this,oe).at(-1);return o&&(o.line=new Float32Array(o.line),o.points=new Float32Array(o.points)),l(this,oe).push({line:r,points:l(this,Ne)}),l(this,xi).set(r,0),m(this,Ms,0),this.toSVGPath(),null}getLastElement(){return l(this,oe).at(-1)}setLastElement(t){return l(this,oe)?(l(this,oe).push(t),m(this,re,t.line),m(this,Ne,t.points),m(this,Ms,0),{path:{d:this.toSVGPath()}}):l(this,Lo).setLastElement(t)}removeLastElement(){if(!l(this,oe))return l(this,Lo).removeLastElement();l(this,oe).pop(),m(this,ce,"");for(let t=0,e=l(this,oe).length;t<e;t++){const{line:s,points:i}=l(this,oe)[t];m(this,re,s),m(this,Ne,i),m(this,Ms,0),this.toSVGPath()}return{path:{d:l(this,ce)}}}toSVGPath(){const t=H.svgRound(l(this,re)[4]),e=H.svgRound(l(this,re)[5]);if(l(this,Ne).length===2)return m(this,ce,`${l(this,ce)} M ${t} ${e} Z`),l(this,ce);if(l(this,Ne).length<=6){const i=l(this,ce).lastIndexOf("M");m(this,ce,`${l(this,ce).slice(0,i)} M ${t} ${e}`),m(this,Ms,6)}if(l(this,Ne).length===4){const i=H.svgRound(l(this,re)[10]),n=H.svgRound(l(this,re)[11]);return m(this,ce,`${l(this,ce)} L ${i} ${n}`),m(this,Ms,12),l(this,ce)}const s=[];l(this,Ms)===0&&(s.push(`M ${t} ${e}`),m(this,Ms,6));for(let i=l(this,Ms),n=l(this,re).length;i<n;i+=6){const[r,o,h,c,u,d]=l(this,re).slice(i,i+6).map(H.svgRound);s.push(`C${r} ${o} ${h} ${c} ${u} ${d}`)}return m(this,ce,l(this,ce)+s.join(" ")),m(this,Ms,l(this,re).length),l(this,ce)}getOutlines(t,e,s,i){const n=l(this,oe).at(-1);return n.line=new Float32Array(n.line),n.points=new Float32Array(n.points),l(this,Lo).build(l(this,oe),t,e,s,l(this,Ro),l(this,nh),i),m(this,xi,null),m(this,re,null),m(this,oe,null),m(this,ce,null),l(this,Lo)}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}xi=new WeakMap,re=new WeakMap,oe=new WeakMap,Ro=new WeakMap,nh=new WeakMap,Ne=new WeakMap,ce=new WeakMap,Ms=new WeakMap,Lo=new WeakMap,Fo=new WeakMap,Io=new WeakMap,rh=new WeakSet,Qd=function(t,e){return H._normalizePoint(t,e,l(this,Fo),l(this,Io),l(this,Ro))};const Ug=class Ug extends H{constructor(){super(...arguments);v(this,ue);v(this,je);v(this,_c,0);v(this,wc);v(this,gs);v(this,Si);v(this,Ci);v(this,oh);v(this,ah);v(this,hh)}build(e,s,i,n,r,o,h){m(this,Si,s),m(this,Ci,i),m(this,oh,n),m(this,ah,r),m(this,hh,o),m(this,wc,h??0),m(this,gs,e),w(this,ue,dv).call(this)}setLastElement(e){return l(this,gs).push(e),{path:{d:this.toSVGPath()}}}removeLastElement(){return l(this,gs).pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const e=[];for(const{line:s}of l(this,gs)){if(e.push(`M${H.svgRound(s[4])} ${H.svgRound(s[5])}`),s.length===6){e.push("Z");continue}if(s.length===12){e.push(`L${H.svgRound(s[10])} ${H.svgRound(s[11])}`);continue}for(let i=6,n=s.length;i<n;i+=6){const[r,o,h,c,u,d]=s.subarray(i,i+6).map(H.svgRound);e.push(`C${r} ${o} ${h} ${c} ${u} ${d}`)}}return e.join("")}serialize([e,s,i,n],r){const o=[],h=[],[c,u,d,f]=w(this,ue,uv).call(this);let g,p,b,_,y,x,S,C,E;switch(l(this,ah)){case 0:E=H._rescale,g=e,p=s+n,b=i,_=-n,y=e+c*i,x=s+(1-u-f)*n,S=e+(c+d)*i,C=s+(1-u)*n;break;case 90:E=H._rescaleAndSwap,g=e,p=s,b=i,_=n,y=e+u*i,x=s+c*n,S=e+(u+f)*i,C=s+(c+d)*n;break;case 180:E=H._rescale,g=e+i,p=s,b=-i,_=n,y=e+(1-c-d)*i,x=s+u*n,S=e+(1-c)*i,C=s+(u+f)*n;break;case 270:E=H._rescaleAndSwap,g=e+i,p=s+n,b=-i,_=-n,y=e+(1-u-f)*i,x=s+(1-c-d)*n,S=e+(1-u)*i,C=s+(1-c)*n;break}for(const{line:D,points:M}of l(this,gs))o.push(E(D,g,p,b,_,r?new Array(D.length):null)),h.push(E(M,g,p,b,_,r?new Array(M.length):null));return{lines:o,points:h,rect:[y,x,S,C]}}static deserialize(e,s,i,n,r,{paths:{lines:o,points:h},rotation:c,thickness:u}){const d=[];let f,g,p,b,_;switch(c){case 0:_=H._rescale,f=-e/i,g=s/n+1,p=1/i,b=-1/n;break;case 90:_=H._rescaleAndSwap,f=-s/n,g=-e/i,p=1/n,b=1/i;break;case 180:_=H._rescale,f=e/i+1,g=-s/n,p=-1/i,b=1/n;break;case 270:_=H._rescaleAndSwap,f=s/n+1,g=e/i+1,p=-1/n,b=-1/i;break}if(!o){o=[];for(const x of h){const S=x.length;if(S===2){o.push(new Float32Array([NaN,NaN,NaN,NaN,x[0],x[1]]));continue}if(S===4){o.push(new Float32Array([NaN,NaN,NaN,NaN,x[0],x[1],NaN,NaN,NaN,NaN,x[2],x[3]]));continue}const C=new Float32Array(3*(S-2));o.push(C);let[E,D,M,k]=x.subarray(0,4);C.set([NaN,NaN,NaN,NaN,E,D],0);for(let O=4;O<S;O+=2){const R=x[O],L=x[O+1];C.set(H.createBezierPoints(E,D,M,k,R,L),(O-2)*3),[E,D,M,k]=[M,k,R,L]}}}for(let x=0,S=o.length;x<S;x++)d.push({line:_(o[x].map(C=>C??NaN),f,g,p,b),points:_(h[x].map(C=>C??NaN),f,g,p,b)});const y=new Ug;return y.build(d,i,n,1,c,u,r),y}get box(){return l(this,je)}updateProperty(e,s){return e==="stroke-width"?w(this,ue,fv).call(this,s):null}updateParentDimensions([e,s],i){const[n,r]=w(this,ue,Sn).call(this);m(this,Si,e),m(this,Ci,s),m(this,oh,i);const[o,h]=w(this,ue,Sn).call(this),c=o-n,u=h-r,d=l(this,je);return d[0]-=c,d[1]-=u,d[2]+=2*c,d[3]+=2*u,d}updateRotation(e){return m(this,_c,e),{path:{transform:this.rotationTransform}}}get viewBox(){return l(this,je).map(H.svgRound).join(" ")}get defaultProperties(){const[e,s]=l(this,je);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${H.svgRound(e)} ${H.svgRound(s)}`}}}get rotationTransform(){const[,,e,s]=l(this,je);let i=0,n=0,r=0,o=0,h=0,c=0;switch(l(this,_c)){case 90:n=s/e,r=-e/s,h=e;break;case 180:i=-1,o=-1,h=e,c=s;break;case 270:n=-s/e,r=e/s,c=s;break;default:return""}return`matrix(${i} ${n} ${r} ${o} ${H.svgRound(h)} ${H.svgRound(c)})`}getPathResizingSVGProperties([e,s,i,n]){const[r,o]=w(this,ue,Sn).call(this),[h,c,u,d]=l(this,je);if(Math.abs(u-r)<=H.PRECISION||Math.abs(d-o)<=H.PRECISION){const _=e+i/2-(h+u/2),y=s+n/2-(c+d/2);return{path:{"transform-origin":`${H.svgRound(e)} ${H.svgRound(s)}`,transform:`${this.rotationTransform} translate(${_} ${y})`}}}const f=(i-2*r)/(u-2*r),g=(n-2*o)/(d-2*o),p=u/i,b=d/n;return{path:{"transform-origin":`${H.svgRound(h)} ${H.svgRound(c)}`,transform:`${this.rotationTransform} scale(${p} ${b}) translate(${H.svgRound(r)} ${H.svgRound(o)}) scale(${f} ${g}) translate(${H.svgRound(-r)} ${H.svgRound(-o)})`}}}getPathResizedSVGProperties([e,s,i,n]){const[r,o]=w(this,ue,Sn).call(this),h=l(this,je),[c,u,d,f]=h;if(h[0]=e,h[1]=s,h[2]=i,h[3]=n,Math.abs(d-r)<=H.PRECISION||Math.abs(f-o)<=H.PRECISION){const y=e+i/2-(c+d/2),x=s+n/2-(u+f/2);for(const{line:S,points:C}of l(this,gs))H._translate(S,y,x,S),H._translate(C,y,x,C);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${H.svgRound(e)} ${H.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const g=(i-2*r)/(d-2*r),p=(n-2*o)/(f-2*o),b=-g*(c+r)+e+r,_=-p*(u+o)+s+o;if(g!==1||p!==1||b!==0||_!==0)for(const{line:y,points:x}of l(this,gs))H._rescale(y,b,_,g,p,y),H._rescale(x,b,_,g,p,x);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${H.svgRound(e)} ${H.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,s],i){const[n,r]=i,o=l(this,je),h=e-o[0],c=s-o[1];if(l(this,Si)===n&&l(this,Ci)===r)for(const{line:u,points:d}of l(this,gs))H._translate(u,h,c,u),H._translate(d,h,c,d);else{const u=l(this,Si)/n,d=l(this,Ci)/r;m(this,Si,n),m(this,Ci,r);for(const{line:f,points:g}of l(this,gs))H._rescale(f,h,c,u,d,f),H._rescale(g,h,c,u,d,g);o[2]*=u,o[3]*=d}return o[0]=e,o[1]=s,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${H.svgRound(e)} ${H.svgRound(s)}`}}}get defaultSVGProperties(){const e=l(this,je);return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${H.svgRound(e[0])} ${H.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}};je=new WeakMap,_c=new WeakMap,wc=new WeakMap,gs=new WeakMap,Si=new WeakMap,Ci=new WeakMap,oh=new WeakMap,ah=new WeakMap,hh=new WeakMap,ue=new WeakSet,Sn=function(e=l(this,hh)){const s=l(this,wc)+e/2*l(this,oh);return l(this,ah)%180===0?[s/l(this,Si),s/l(this,Ci)]:[s/l(this,Ci),s/l(this,Si)]},uv=function(){const[e,s,i,n]=l(this,je),[r,o]=w(this,ue,Sn).call(this,0);return[e+r,s+o,i-2*r,n-2*o]},dv=function(){const e=m(this,je,new Float32Array([1/0,1/0,-1/0,-1/0]));for(const{line:n}of l(this,gs)){if(n.length<=12){for(let h=4,c=n.length;h<c;h+=6){const[u,d]=n.subarray(h,h+2);e[0]=Math.min(e[0],u),e[1]=Math.min(e[1],d),e[2]=Math.max(e[2],u),e[3]=Math.max(e[3],d)}continue}let r=n[4],o=n[5];for(let h=6,c=n.length;h<c;h+=6){const[u,d,f,g,p,b]=n.subarray(h,h+6);U.bezierBoundingBox(r,o,u,d,f,g,p,b,e),r=p,o=b}}const[s,i]=w(this,ue,Sn).call(this);e[0]=Math.min(1,Math.max(0,e[0]-s)),e[1]=Math.min(1,Math.max(0,e[1]-i)),e[2]=Math.min(1,Math.max(0,e[2]+s)),e[3]=Math.min(1,Math.max(0,e[3]+i)),e[2]-=e[0],e[3]-=e[1]},fv=function(e){const[s,i]=w(this,ue,Sn).call(this);m(this,hh,e);const[n,r]=w(this,ue,Sn).call(this),[o,h]=[n-s,r-i],c=l(this,je);return c[0]-=o,c[1]-=h,c[2]+=2*o,c[3]+=2*h,c};let od=Ug;const Yg=class Yg extends XS{constructor(e){super();v(this,lh);m(this,lh,e),super.updateProperties({fill:"none",stroke:Pt._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(e,s){e==="stroke-width"&&(s??(s=this["stroke-width"]),s*=l(this,lh).realScale),super.updateSVGProperty(e,s)}clone(){const e=new Yg(l(this,lh));return e.updateAll(this),e}};lh=new WeakMap;let Ng=Yg;const ch=class ch extends Ig{constructor(e){super({...e,name:"inkEditor"});v(this,Cd);this._willKeepAspectRatio=!0}static initialize(e,s){Pt.initialize(e,s),this._defaultDrawingOptions=new Ng(s.viewParameters)}static getDefaultDrawingOptions(e){const s=this._defaultDrawingOptions.clone();return s.updateProperties(e),s}static get supportMultipleDrawings(){return!0}static get typesMap(){return st(this,"typesMap",new Map([[ot.INK_THICKNESS,"stroke-width"],[ot.INK_COLOR,"stroke"],[ot.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(e,s,i,n,r){return new WS(e,s,i,n,r,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(e,s,i,n,r,o){return od.deserialize(e,s,i,n,r,o)}static async deserialize(e,s,i){let n=null;if(e instanceof Og){const{data:{inkLists:o,rect:h,rotation:c,id:u,color:d,opacity:f,borderStyle:{rawWidth:g},popupRef:p},parent:{page:{pageNumber:b}}}=e;n=e={annotationType:Z.INK,color:Array.from(d),thickness:g,opacity:f,paths:{points:o},boxes:null,pageIndex:b-1,rect:h.slice(0),rotation:c,id:u,deleted:!1,popupRef:p}}const r=await super.deserialize(e,s,i);return r.annotationElementId=e.id||null,r._initialData=n,r}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();const{_drawId:e,_drawingOptions:s,parent:i}=this;s.updateSVGProperty("stroke-width"),i.drawLayer.updateProperties(e,s.toSVGProperties())}static onScaleChangingWhenDrawing(){const e=this._currentParent;e&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),e.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:e,thickness:s,opacity:i}){this._drawingOptions=ch.getDefaultDrawingOptions({stroke:U.makeHexColor(...e),"stroke-width":s,"stroke-opacity":i})}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:s,points:i,rect:n}=this.serializeDraw(e),{_drawingOptions:{stroke:r,"stroke-opacity":o,"stroke-width":h}}=this,c={annotationType:Z.INK,color:Pt._colorManager.convert(r),opacity:o,thickness:h,paths:{lines:s,points:i},pageIndex:this.pageIndex,rect:n,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?c:this.annotationElementId&&!w(this,Cd,gv).call(this,c)?null:(c.id=this.annotationElementId,c)}renderAnnotationElement(e){const{points:s,rect:i}=this.serializeDraw(!1);return e.updateEdited({rect:i,thickness:this._drawingOptions["stroke-width"],points:s}),null}};Cd=new WeakSet,gv=function(e){const{color:s,thickness:i,opacity:n,pageIndex:r}=this._initialData;return this._hasBeenMoved||this._hasBeenResized||e.color.some((o,h)=>o!==s[h])||e.thickness!==i||e.opacity!==n||e.pageIndex!==r},$(ch,"_type","ink"),$(ch,"_editorType",Z.INK),$(ch,"_defaultDrawingOptions",null);let jg=ch;const xc=class xc extends Pt{constructor(e){super({...e,name:"stampEditor"});v(this,ct);v(this,Ot,null);v(this,de,null);v(this,hr,null);v(this,yn,null);v(this,lr,null);v(this,uh,"");v(this,Ai,null);v(this,Ti,null);v(this,ps,!1);v(this,dh,!1);m(this,yn,e.bitmapUrl),m(this,lr,e.bitmapFile)}static initialize(e,s){Pt.initialize(e,s)}static get supportedTypes(){return st(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(s=>`image/${s}`))}static get supportedTypesStr(){return st(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(e){return this.supportedTypes.includes(e)}static paste(e,s){s.pasteEditor(Z.STAMP,{bitmapFile:e.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){var e;return{type:"stamp",hasAltText:!!((e=this.altTextData)!=null&&e.altText)}}static computeTelemetryFinalData(e){const s=e.get("hasAltText");return{hasAltText:s.get(!0)??0,hasNoAltText:s.get(!1)??0}}async mlGuessAltText(e=null,s=!0){if(this.hasAltTextData())return null;const{mlManager:i}=this._uiManager;if(!i)throw new Error("No ML.");if(!await i.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:n,width:r,height:o}=e||this.copyCanvas(null,null,!0).imageData,h=await i.guess({name:"altText",request:{data:n,width:r,height:o,channels:n.length/(r*o)}});if(!h)throw new Error("No response from the AI service.");if(h.error)throw new Error("Error from the AI service.");if(h.cancel)return null;if(!h.output)throw new Error("No valid response from the AI service.");const c=h.output;return await this.setGuessedAltText(c),s&&!this.hasAltTextData()&&(this.altTextData={alt:c,decorative:!1}),c}remove(){var e;l(this,de)&&(m(this,Ot,null),this._uiManager.imageManager.deleteId(l(this,de)),(e=l(this,Ai))==null||e.remove(),m(this,Ai,null),l(this,Ti)&&(clearTimeout(l(this,Ti)),m(this,Ti,null))),super.remove()}rebuild(){if(!this.parent){l(this,de)&&w(this,ct,Jd).call(this);return}super.rebuild(),this.div!==null&&(l(this,de)&&l(this,Ai)===null&&w(this,ct,Jd).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(e){this._isDraggable=!0,e&&this.div.focus()}isEmpty(){return!(l(this,hr)||l(this,Ot)||l(this,yn)||l(this,lr)||l(this,de))}get isResizable(){return!0}render(){if(this.div)return this.div;let e,s;if(this.width&&(e=this.x,s=this.y),super.render(),this.div.hidden=!0,this.div.setAttribute("role","figure"),this.addAltTextButton(),l(this,Ot)?w(this,ct,Ip).call(this):w(this,ct,Jd).call(this),this.width&&!this.annotationElementId){const[i,n]=this.parentDimensions;this.setAt(e*i,s*n,this.width*i,this.height*n)}return this._uiManager.addShouldRescale(this),this.div}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;l(this,Ti)!==null&&clearTimeout(l(this,Ti)),m(this,Ti,setTimeout(()=>{m(this,Ti,null),w(this,ct,Np).call(this)},200))}copyCanvas(e,s,i=!1){var g;e||(e=224);const{width:n,height:r}=l(this,Ot),o=new mg;let h=l(this,Ot),c=n,u=r,d=null;if(s){if(n>s||r>s){const k=Math.min(s/n,s/r);c=Math.floor(n*k),u=Math.floor(r*k)}d=document.createElement("canvas");const p=d.width=Math.ceil(c*o.sx),b=d.height=Math.ceil(u*o.sy);l(this,ps)||(h=w(this,ct,Zd).call(this,p,b));const _=d.getContext("2d");_.filter=this._uiManager.hcmFilter;let y="white",x="#cfcfd8";this._uiManager.hcmFilter!=="none"?x="black":(g=window.matchMedia)!=null&&g.call(window,"(prefers-color-scheme: dark)").matches&&(y="#8f8f9d",x="#42414d");const S=15,C=S*o.sx,E=S*o.sy,D=new OffscreenCanvas(C*2,E*2),M=D.getContext("2d");M.fillStyle=y,M.fillRect(0,0,C*2,E*2),M.fillStyle=x,M.fillRect(0,0,C,E),M.fillRect(C,E,C,E),_.fillStyle=_.createPattern(D,"repeat"),_.fillRect(0,0,p,b),_.drawImage(h,0,0,h.width,h.height,0,0,p,b)}let f=null;if(i){let p,b;if(o.symmetric&&h.width<e&&h.height<e)p=h.width,b=h.height;else if(h=l(this,Ot),n>e||r>e){const x=Math.min(e/n,e/r);p=Math.floor(n*x),b=Math.floor(r*x),l(this,ps)||(h=w(this,ct,Zd).call(this,p,b))}const y=new OffscreenCanvas(p,b).getContext("2d",{willReadFrequently:!0});y.drawImage(h,0,0,h.width,h.height,0,0,p,b),f={width:p,height:b,data:y.getImageData(0,0,p,b).data}}return{canvas:d,width:c,height:u,imageData:f}}getImageForAltText(){return l(this,Ai)}static async deserialize(e,s,i){var b;let n=null;if(e instanceof Ib){const{data:{rect:_,rotation:y,id:x,structParent:S,popupRef:C},container:E,parent:{page:{pageNumber:D}}}=e,M=E.querySelector("canvas"),k=i.imageManager.getFromCanvas(E.id,M);M.remove();const O=((b=await s._structTree.getAriaAttributes(`${ug}${x}`))==null?void 0:b.get("aria-label"))||"";n=e={annotationType:Z.STAMP,bitmapId:k.id,bitmap:k.bitmap,pageIndex:D-1,rect:_.slice(0),rotation:y,id:x,deleted:!1,accessibilityData:{decorative:!1,altText:O},isSvg:!1,structParent:S,popupRef:C}}const r=await super.deserialize(e,s,i),{rect:o,bitmap:h,bitmapUrl:c,bitmapId:u,isSvg:d,accessibilityData:f}=e;u&&i.imageManager.isValidId(u)?(m(r,de,u),h&&m(r,Ot,h)):m(r,yn,c),m(r,ps,d);const[g,p]=r.pageDimensions;return r.width=(o[2]-o[0])/g,r.height=(o[3]-o[1])/p,r.annotationElementId=e.id||null,f&&(r.altTextData=f),r._initialData=n,m(r,dh,!!n),r}serialize(e=!1,s=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const i={annotationType:Z.STAMP,bitmapId:l(this,de),pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:l(this,ps),structTreeParentId:this._structTreeParentId};if(e)return i.bitmapUrl=w(this,ct,tf).call(this,!0),i.accessibilityData=this.serializeAltText(!0),i;const{decorative:n,altText:r}=this.serializeAltText(!1);if(!n&&r&&(i.accessibilityData={type:"Figure",alt:r}),this.annotationElementId){const h=w(this,ct,pv).call(this,i);if(h.isSame)return null;h.isSameAltText?delete i.accessibilityData:i.accessibilityData.structParent=this._initialData.structParent??-1}if(i.id=this.annotationElementId,s===null)return i;s.stamps||(s.stamps=new Map);const o=l(this,ps)?(i.rect[2]-i.rect[0])*(i.rect[3]-i.rect[1]):null;if(!s.stamps.has(l(this,de)))s.stamps.set(l(this,de),{area:o,serialized:i}),i.bitmap=w(this,ct,tf).call(this,!1);else if(l(this,ps)){const h=s.stamps.get(l(this,de));o>h.area&&(h.area=o,h.serialized.bitmap.close(),h.serialized.bitmap=w(this,ct,tf).call(this,!1))}return i}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}};Ot=new WeakMap,de=new WeakMap,hr=new WeakMap,yn=new WeakMap,lr=new WeakMap,uh=new WeakMap,Ai=new WeakMap,Ti=new WeakMap,ps=new WeakMap,dh=new WeakMap,ct=new WeakSet,Ic=function(e,s=!1){if(!e){this.remove();return}m(this,Ot,e.bitmap),s||(m(this,de,e.id),m(this,ps,e.isSvg)),e.file&&m(this,uh,e.file.name),w(this,ct,Ip).call(this)},Nc=function(){if(m(this,hr,null),this._uiManager.enableWaiting(!1),!!l(this,Ai)){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Ot)){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Ot)){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}},Jd=function(){if(l(this,de)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(l(this,de)).then(i=>w(this,ct,Ic).call(this,i,!0)).finally(()=>w(this,ct,Nc).call(this));return}if(l(this,yn)){const i=l(this,yn);m(this,yn,null),this._uiManager.enableWaiting(!0),m(this,hr,this._uiManager.imageManager.getFromUrl(i).then(n=>w(this,ct,Ic).call(this,n)).finally(()=>w(this,ct,Nc).call(this)));return}if(l(this,lr)){const i=l(this,lr);m(this,lr,null),this._uiManager.enableWaiting(!0),m(this,hr,this._uiManager.imageManager.getFromFile(i).then(n=>w(this,ct,Ic).call(this,n)).finally(()=>w(this,ct,Nc).call(this)));return}const e=document.createElement("input");e.type="file",e.accept=xc.supportedTypesStr;const s=this._uiManager._signal;m(this,hr,new Promise(i=>{e.addEventListener("change",async()=>{if(!e.files||e.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const n=await this._uiManager.imageManager.getFromFile(e.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),w(this,ct,Ic).call(this,n)}i()},{signal:s}),e.addEventListener("cancel",()=>{this.remove(),i()},{signal:s})}).finally(()=>w(this,ct,Nc).call(this))),e.click()},Ip=function(){var d;const{div:e}=this;let{width:s,height:i}=l(this,Ot);const[n,r]=this.pageDimensions,o=.75;if(this.width)s=this.width*n,i=this.height*r;else if(s>o*n||i>o*r){const f=Math.min(o*n/s,o*r/i);s*=f,i*=f}const[h,c]=this.parentDimensions;this.setDims(s*h/n,i*c/r),this._uiManager.enableWaiting(!1);const u=m(this,Ai,document.createElement("canvas"));u.setAttribute("role","img"),this.addContainer(u),this.width=s/n,this.height=i/r,(d=this._initialOptions)!=null&&d.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(e.hidden=!1),w(this,ct,Np).call(this),l(this,dh)||(this.parent.addUndoableEditor(this),m(this,dh,!0)),this._reportTelemetry({action:"inserted_image"}),l(this,uh)&&u.setAttribute("aria-label",l(this,uh))},Zd=function(e,s){const{width:i,height:n}=l(this,Ot);let r=i,o=n,h=l(this,Ot);for(;r>2*e||o>2*s;){const c=r,u=o;r>2*e&&(r=r>=16384?Math.floor(r/2)-1:Math.ceil(r/2)),o>2*s&&(o=o>=16384?Math.floor(o/2)-1:Math.ceil(o/2));const d=new OffscreenCanvas(r,o);d.getContext("2d").drawImage(h,0,0,c,u,0,0,r,o),h=d.transferToImageBitmap()}return h},Np=function(){const[e,s]=this.parentDimensions,{width:i,height:n}=this,r=new mg,o=Math.ceil(i*e*r.sx),h=Math.ceil(n*s*r.sy),c=l(this,Ai);if(!c||c.width===o&&c.height===h)return;c.width=o,c.height=h;const u=l(this,ps)?l(this,Ot):w(this,ct,Zd).call(this,o,h),d=c.getContext("2d");d.filter=this._uiManager.hcmFilter,d.drawImage(u,0,0,u.width,u.height,0,0,o,h)},tf=function(e){if(e){if(l(this,ps)){const n=this._uiManager.imageManager.getSvgUrl(l(this,de));if(n)return n}const s=document.createElement("canvas");return{width:s.width,height:s.height}=l(this,Ot),s.getContext("2d").drawImage(l(this,Ot),0,0),s.toDataURL()}if(l(this,ps)){const[s,i]=this.pageDimensions,n=Math.round(this.width*s*Ln.PDF_TO_CSS_UNITS),r=Math.round(this.height*i*Ln.PDF_TO_CSS_UNITS),o=new OffscreenCanvas(n,r);return o.getContext("2d").drawImage(l(this,Ot),0,0,l(this,Ot).width,l(this,Ot).height,0,0,n,r),o.transferToImageBitmap()}return structuredClone(l(this,Ot))},pv=function(e){var o;const{pageIndex:s,accessibilityData:{altText:i}}=this._initialData,n=e.pageIndex===s,r=(((o=e.accessibilityData)==null?void 0:o.alt)||"")===i;return{isSame:!this._hasBeenMoved&&!this._hasBeenResized&&n&&r,isSameAltText:r}},$(xc,"_type","stamp"),$(xc,"_editorType",Z.STAMP);let Bg=xc;const ei=class ei{constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:o,textLayer:h,viewport:c,l10n:u}){v(this,kt);v(this,No);v(this,fh,!1);v(this,Ei,null);v(this,cr,null);v(this,vn,null);v(this,Ps,new Map);v(this,ur,!1);v(this,gh,!1);v(this,jo,!1);v(this,ti,null);v(this,_n,null);v(this,Ce,null);v(this,wn,null);v(this,X);const d=[...l(ei,dr).values()];if(!ei._initialized){ei._initialized=!0;for(const f of d)f.initialize(u,t)}t.registerEditorTypes(d),m(this,X,t),this.pageIndex=e,this.div=s,m(this,No,n),m(this,Ei,r),this.viewport=c,m(this,Ce,h),this.drawLayer=o,this._structTree=i,l(this,X).addLayer(this)}get isEmpty(){return l(this,Ps).size===0}get isInvisible(){return this.isEmpty&&l(this,X).getMode()===Z.NONE}updateToolbar(t){l(this,X).updateToolbar(t)}updateMode(t=l(this,X).getMode()){switch(w(this,kt,ef).call(this),t){case Z.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case Z.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case Z.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);const{classList:e}=this.div;for(const s of l(ei,dr).values())e.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){var e;return t===((e=l(this,Ce))==null?void 0:e.div)}setEditingState(t){l(this,X).setEditingState(t)}addCommands(t){l(this,X).addCommands(t)}cleanUndoStack(t){l(this,X).cleanUndoStack(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){var e;(e=l(this,Ei))==null||e.div.classList.toggle("disabled",!t)}async enable(){m(this,jo,!0),this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const s of l(this,Ps).values())s.enableEditing(),s.show(!0),s.annotationElementId&&(l(this,X).removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!l(this,Ei)){m(this,jo,!1);return}const e=l(this,Ei).getEditableAnnotations();for(const s of e){if(s.hide(),l(this,X).isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;const i=await this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}m(this,jo,!1)}disable(){var i;m(this,gh,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,e=new Map;for(const n of l(this,Ps).values())if(n.disableEditing(),!!n.annotationElementId){if(n.serialize()!==null){t.set(n.annotationElementId,n);continue}else e.set(n.annotationElementId,n);(i=this.getEditableAnnotation(n.annotationElementId))==null||i.show(),n.remove()}if(l(this,Ei)){const n=l(this,Ei).getEditableAnnotations();for(const r of n){const{id:o}=r.data;if(l(this,X).isDeletedAnnotationElement(o))continue;let h=e.get(o);if(h){h.resetAnnotationElement(r),h.show(!1),r.show();continue}h=t.get(o),h&&(l(this,X).addChangedExistingAnnotation(h),h.renderAnnotationElement(r)&&h.show(!1)),r.show()}}w(this,kt,ef).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const n of l(ei,dr).values())s.remove(`${n._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),m(this,gh,!1)}getEditableAnnotation(t){var e;return((e=l(this,Ei))==null?void 0:e.getEditableAnnotation(t))||null}setActiveEditor(t){l(this,X).getActive()!==t&&l(this,X).setActiveEditor(t)}enableTextSelection(){var t;if(this.div.tabIndex=-1,(t=l(this,Ce))!=null&&t.div&&!l(this,wn)){m(this,wn,new AbortController);const e=l(this,X).combinedSignal(l(this,wn));l(this,Ce).div.addEventListener("pointerdown",w(this,kt,mv).bind(this),{signal:e}),l(this,Ce).div.classList.add("highlighting")}}disableTextSelection(){var t;this.div.tabIndex=0,(t=l(this,Ce))!=null&&t.div&&l(this,wn)&&(l(this,wn).abort(),m(this,wn,null),l(this,Ce).div.classList.remove("highlighting"))}enableClick(){if(l(this,cr))return;m(this,cr,new AbortController);const t=l(this,X).combinedSignal(l(this,cr));this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t});const e=this.pointerup.bind(this);this.div.addEventListener("pointerup",e,{signal:t}),this.div.addEventListener("pointercancel",e,{signal:t})}disableClick(){var t;(t=l(this,cr))==null||t.abort(),m(this,cr,null)}attach(t){l(this,Ps).set(t.id,t);const{annotationElementId:e}=t;e&&l(this,X).isDeletedAnnotationElement(e)&&l(this,X).removeDeletedAnnotationElement(t)}detach(t){var e;l(this,Ps).delete(t.id),(e=l(this,No))==null||e.removePointerInTextLayer(t.contentDiv),!l(this,gh)&&t.annotationElementId&&l(this,X).addDeletedAnnotationElement(t)}remove(t){this.detach(t),l(this,X).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){var e;t.parent!==this&&(t.parent&&t.annotationElementId&&(l(this,X).addDeletedAnnotationElement(t.annotationElementId),Pt.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),(e=t.parent)==null||e.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),l(this,X).addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!l(this,jo)),l(this,X).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var s;if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!l(this,vn)&&(t._focusEventsAllowed=!1,m(this,vn,setTimeout(()=>{m(this,vn,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:l(this,X)._signal}),e.focus())},0))),t._structTreeParentId=(s=l(this,No))==null?void 0:s.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 e=()=>t._uiManager.rebuild(t),s=()=>{t.remove()};this.addCommands({cmd:e,undo:s,mustExec:!1})}getNextId(){return l(this,X).getId()}combinedSignal(t){return l(this,X).combinedSignal(t)}canCreateNewEmptyEditor(){var t;return(t=l(this,kt,Di))==null?void 0:t.canCreateNewEmptyEditor()}pasteEditor(t,e){l(this,X).updateToolbar(t),l(this,X).updateMode(t);const{offsetX:s,offsetY:i}=w(this,kt,Bp).call(this),n=this.getNextId(),r=w(this,kt,jp).call(this,{parent:this,id:n,x:s,y:i,uiManager:l(this,X),isCentered:!0,...e});r&&this.add(r)}async deserialize(t){var e;return await((e=l(ei,dr).get(t.annotationType??t.annotationEditorType))==null?void 0:e.deserialize(t,this,l(this,X)))||null}createAndAddNewEditor(t,e,s={}){const i=this.getNextId(),n=w(this,kt,jp).call(this,{parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:l(this,X),isCentered:e,...s});return n&&this.add(n),n}addNewEditor(){this.createAndAddNewEditor(w(this,kt,Bp).call(this),!0)}setSelected(t){l(this,X).setSelected(t)}toggleSelected(t){l(this,X).toggleSelected(t)}unselect(t){l(this,X).unselect(t)}pointerup(t){var s;const{isMac:e}=Re.platform;if(!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&l(this,ur)&&(m(this,ur,!1),!((s=l(this,kt,Di))!=null&&s.isDrawer&&l(this,kt,Di).supportMultipleDrawings))){if(!l(this,fh)){m(this,fh,!0);return}if(l(this,X).getMode()===Z.STAMP){l(this,X).unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){var i;if(l(this,X).getMode()===Z.HIGHLIGHT&&this.enableTextSelection(),l(this,ur)){m(this,ur,!1);return}const{isMac:e}=Re.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;if(m(this,ur,!0),(i=l(this,kt,Di))!=null&&i.isDrawer){this.startDrawingSession(t);return}const s=l(this,X).getActive();m(this,fh,!s||s.isEmpty())}startDrawingSession(t){if(this.div.focus(),l(this,ti)){l(this,kt,Di).startDrawing(this,l(this,X),!1,t);return}l(this,X).setCurrentDrawingSession(this),m(this,ti,new AbortController);const e=l(this,X).combinedSignal(l(this,ti));this.div.addEventListener("blur",({relatedTarget:s})=>{s&&!this.div.contains(s)&&(m(this,_n,null),this.commitOrRemove())},{signal:e}),l(this,kt,Di).startDrawing(this,l(this,X),!1,t)}pause(t){if(t){const{activeElement:e}=document;this.div.contains(e)&&m(this,_n,e);return}l(this,_n)&&setTimeout(()=>{var e;(e=l(this,_n))==null||e.focus(),m(this,_n,null)},0)}endDrawingSession(t=!1){return l(this,ti)?(l(this,X).setCurrentDrawingSession(null),l(this,ti).abort(),m(this,ti,null),m(this,_n,null),l(this,kt,Di).endDrawing(t)):null}findNewParent(t,e,s){const i=l(this,X).findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}commitOrRemove(){return l(this,ti)?(this.endDrawingSession(),!0):!1}onScaleChanging(){l(this,ti)&&l(this,kt,Di).onScaleChangingWhenDrawing(this)}destroy(){var t,e;this.commitOrRemove(),((t=l(this,X).getActive())==null?void 0:t.parent)===this&&(l(this,X).commitOrRemove(),l(this,X).setActiveEditor(null)),l(this,vn)&&(clearTimeout(l(this,vn)),m(this,vn,null));for(const s of l(this,Ps).values())(e=l(this,No))==null||e.removePointerInTextLayer(s.contentDiv),s.setParent(null),s.isAttachedToDOM=!1,s.div.remove();this.div=null,l(this,Ps).clear(),l(this,X).removeLayer(this)}render({viewport:t}){this.viewport=t,kr(this.div,t);for(const e of l(this,X).getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){l(this,X).commitOrRemove(),w(this,kt,ef).call(this);const e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,kr(this.div,{rotation:s}),e!==s)for(const i of l(this,Ps).values())i.rotate(s)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return l(this,X).viewParameters.realScale}};No=new WeakMap,fh=new WeakMap,Ei=new WeakMap,cr=new WeakMap,vn=new WeakMap,Ps=new WeakMap,ur=new WeakMap,gh=new WeakMap,jo=new WeakMap,ti=new WeakMap,_n=new WeakMap,Ce=new WeakMap,wn=new WeakMap,X=new WeakMap,dr=new WeakMap,kt=new WeakSet,mv=function(t){l(this,X).unselectAll();const{target:e}=t;if(e===l(this,Ce).div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&l(this,Ce).div.contains(e)){const{isMac:s}=Re.platform;if(t.button!==0||t.ctrlKey&&s)return;l(this,X).showAllEditors("highlight",!0,!0),l(this,Ce).div.classList.add("free"),this.toggleDrawing(),rd.startHighlighting(this,l(this,X).direction==="ltr",{target:l(this,Ce).div,x:t.x,y:t.y}),l(this,Ce).div.addEventListener("pointerup",()=>{l(this,Ce).div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:l(this,X)._signal}),t.preventDefault()}},Di=function(){return l(ei,dr).get(l(this,X).getMode())},jp=function(t){const e=l(this,kt,Di);return e?new e.prototype.constructor(t):null},Bp=function(){const{x:t,y:e,width:s,height:i}=this.div.getBoundingClientRect(),n=Math.max(0,t),r=Math.max(0,e),o=Math.min(window.innerWidth,t+s),h=Math.min(window.innerHeight,e+i),c=(n+o)/2-t,u=(r+h)/2-e,[d,f]=this.viewport.rotation%180===0?[c,u]:[u,c];return{offsetX:d,offsetY:f}},ef=function(){for(const t of l(this,Ps).values())t.isEmpty()&&t.remove()},$(ei,"_initialized",!1),v(ei,dr,new Map([Rg,jg,Bg,rd].map(t=>[t._editorType,t])));let Hg=ei;const Ae=class Ae{constructor({pageIndex:t}){v(this,ki);v(this,si,null);v(this,Sc,0);v(this,Be,new Map);v(this,Bo,new Map);this.pageIndex=t}setParent(t){if(!l(this,si)){m(this,si,t);return}if(l(this,si)!==t){if(l(this,Be).size>0)for(const e of l(this,Be).values())e.remove(),t.append(e);m(this,si,t)}}static get _svgFactory(){return st(this,"_svgFactory",new Pg)}draw(t,e=!1,s=!1){const i=ze(this,Sc)._++,n=w(this,ki,Hp).call(this),r=Ae._svgFactory.createElement("defs");n.append(r);const o=Ae._svgFactory.createElement("path");r.append(o);const h=`path_p${this.pageIndex}_${i}`;o.setAttribute("id",h),o.setAttribute("vector-effect","non-scaling-stroke"),e&&l(this,Bo).set(i,o);const c=s?w(this,ki,yv).call(this,r,h):null,u=Ae._svgFactory.createElement("use");return n.append(u),u.setAttribute("href",`#${h}`),this.updateProperties(n,t),l(this,Be).set(i,n),{id:i,clipPathId:`url(#${c})`}}drawOutline(t,e){const s=ze(this,Sc)._++,i=w(this,ki,Hp).call(this),n=Ae._svgFactory.createElement("defs");i.append(n);const r=Ae._svgFactory.createElement("path");n.append(r);const o=`path_p${this.pageIndex}_${s}`;r.setAttribute("id",o),r.setAttribute("vector-effect","non-scaling-stroke");let h;if(e){const d=Ae._svgFactory.createElement("mask");n.append(d),h=`mask_p${this.pageIndex}_${s}`,d.setAttribute("id",h),d.setAttribute("maskUnits","objectBoundingBox");const f=Ae._svgFactory.createElement("rect");d.append(f),f.setAttribute("width","1"),f.setAttribute("height","1"),f.setAttribute("fill","white");const g=Ae._svgFactory.createElement("use");d.append(g),g.setAttribute("href",`#${o}`),g.setAttribute("stroke","none"),g.setAttribute("fill","black"),g.setAttribute("fill-rule","nonzero"),g.classList.add("mask")}const c=Ae._svgFactory.createElement("use");i.append(c),c.setAttribute("href",`#${o}`),h&&c.setAttribute("mask",`url(#${h})`);const u=c.cloneNode();return i.append(u),c.classList.add("mainOutline"),u.classList.add("secondaryOutline"),this.updateProperties(i,t),l(this,Be).set(s,i),s}finalizeDraw(t,e){l(this,Bo).delete(t),this.updateProperties(t,e)}updateProperties(t,e){var h;if(!e)return;const{root:s,bbox:i,rootClass:n,path:r}=e,o=typeof t=="number"?l(this,Be).get(t):t;if(o){if(s&&w(this,ki,zp).call(this,o,s),i&&w(h=Ae,Ad,bv).call(h,o,i),n){const{classList:c}=o;for(const[u,d]of Object.entries(n))c.toggle(u,d)}if(r){const u=o.firstChild.firstChild;w(this,ki,zp).call(this,u,r)}}}updateParent(t,e){if(e===this)return;const s=l(this,Be).get(t);s&&(l(e,si).append(s),l(this,Be).delete(t),l(e,Be).set(t,s))}remove(t){l(this,Bo).delete(t),l(this,si)!==null&&(l(this,Be).get(t).remove(),l(this,Be).delete(t))}destroy(){m(this,si,null);for(const t of l(this,Be).values())t.remove();l(this,Be).clear(),l(this,Bo).clear()}};si=new WeakMap,Sc=new WeakMap,Be=new WeakMap,Bo=new WeakMap,Ad=new WeakSet,bv=function(t,[e,s,i,n]){const{style:r}=t;r.top=`${100*s}%`,r.left=`${100*e}%`,r.width=`${100*i}%`,r.height=`${100*n}%`},ki=new WeakSet,Hp=function(){const t=Ae._svgFactory.create(1,1,!0);return l(this,si).append(t),t.setAttribute("aria-hidden",!0),t},yv=function(t,e){const s=Ae._svgFactory.createElement("clipPath");t.append(s);const i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=Ae._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i},zp=function(t,e){for(const[s,i]of Object.entries(e))i===null?t.removeAttribute(s):t.setAttribute(s,i)},v(Ae,Ad);let zg=Ae;globalThis.pdfjsTestingUtils={HighlightOutliner:Lg},K.AbortException,K.AnnotationEditorLayer,K.AnnotationEditorParamsType,K.AnnotationEditorType,K.AnnotationEditorUIManager,K.AnnotationLayer,K.AnnotationMode,K.ColorPicker,K.DOMSVGFactory,K.DrawLayer,K.FeatureTest;var US=K.GlobalWorkerOptions;K.ImageKind,K.InvalidPDFException,K.MissingPDFException,K.OPS,K.OutputScale,K.PDFDataRangeTransport,K.PDFDateString,K.PDFWorker,K.PasswordResponses,K.PermissionFlag,K.PixelsPerInch,K.RenderingCancelledException,K.TextLayer,K.TouchManager,K.UnexpectedResponseException,K.Util,K.VerbosityLevel,K.XfaLayer,K.build,K.createValidAbsoluteUrl,K.fetchData;var YS=K.getDocument;K.getFilenameFromUrl,K.getPdfFilenameFromUrl,K.getXfaPageViewport,K.isDataScheme,K.isPdfFile,K.noContextMenu,K.normalizeUnicode,K.setLayerDimensions,K.shadow,K.stopEvent,K.version;const $S={"pdfjs-dist":"4.10.38"};function qS(a){return new Promise((t,e)=>{const s=new FileReader;s.addEventListener("load",()=>t(s.result)),s.addEventListener("error",e),s.readAsDataURL(a)})}const KS=$S["pdfjs-dist"].replace("^","");US.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${KS}/pdf.worker.min.mjs`;async function QS(a){const t="data:application/pdf;base64,",e=await qS(a);if(typeof e=="string")return window.atob(e.slice(t.length))}function JS(a,t){return YS({data:a,password:t}).promise}const ZS="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2040%2040'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3ccircle%20cx='20'%20cy='20'%20r='10.75'%20stroke='currentColor'%20stroke-width='2.5'/%3e%3cpath%20d='M16%2024L23.7782%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3cpath%20d='M24%2024L16.2218%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3c/svg%3e";function tC(a){return new URL(Object.assign({"../assets/close.svg":ZS})[`../assets/${a}`],typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:_t&&_t.tagName.toUpperCase()==="SCRIPT"&&_t.src||new URL("pdf-canvas.umd.js",document.baseURI).href).href}function eC(a){return new Promise((t,e)=>{const s=window.URL.createObjectURL(a),i=new Image;i.src=s,i.addEventListener("load",async()=>{window.URL.revokeObjectURL(s),t(await sC(i))}),i.addEventListener("error",n=>{window.URL.revokeObjectURL(s),e(n)})})}function sC(a){return new Promise(t=>{const e=document.createElement("canvas"),s=e.getContext("2d"),{naturalWidth:i,naturalHeight:n}=a;e.width=i,e.height=n,s==null||s.drawImage(a,0,0,i,n),t(e.toDataURL("image/jpeg",.8))})}let jb=null;function iC(){const a=document.createElement("div");a.style.width="1in",document.body.append(a);const t=a.offsetWidth;return a.remove(),t}function nC(){const a=jb??iC();return jb=a,a/72}function rC(a,t=500){if(typeof a!="function")throw new TypeError("The first argument is not a function.");let e=null;return function(...s){e&&clearTimeout(e),e=setTimeout(()=>{e=null,a.apply(this,s)},t)}}const _s=new Map;function oC(a){const t=new Wf(a);return _s.set(a,t),t}function aC(a,t){const e=Date.now();return{PDFId:`${a.name}-${e}`,name:a.name.replace(/.pdf/,""),updateDate:e,PDFBase64:t}}function hC(a,t){const e=a.getViewport({scale:t}),s=document.createElement("canvas"),i=s.getContext("2d"),n=nC()/window.devicePixelRatio;s.width=Math.floor(e.width*n),s.height=Math.floor(e.height*n);const r={canvasContext:i,viewport:e,transform:[n,0,0,n,0,0]},o=a.render(r);return{canvas:s,renderTask:o}}async function lC(a,t,e){const s=a||tC("close.svg"),{objects:i,options:n}=await Iw(s),r=i.filter(h=>h!==null),o=K_.groupSVGElements(r,n);return r.forEach(h=>{h.stroke=t}),o.hoverCursor="pointer",o.stroke=`${t}-${e}`,o}function cC(a,t){if(!_s.get(a))return;const s=1/3,i=bC(t,s);Hb(a,i,s)}async function uC(a,t){const e=await eC(t),s=Date.now(),n={PDFId:`${t.name}${s}`,name:t.name.replace(/.png|.jpg|.jpeg/,""),updateDate:s,PDFBase64:e};return Bb(a,{url:e}),{...n,pages:1}}async function Bb(a,{url:t,scale:e=.5}){if(!_s.get(a))return;const i=await be.fromURL(t);i.scale(e),Hb(a,i,e)}function Hb(a,t,e){const s=_s.get(a);s&&(s.setWidth(t.width*e),s.setHeight(t.height*e),s.backgroundImage=t,s.renderAll())}function dC(a,t){if(!t)return;const{oCoords:e}=a;if(!e)return;const{x:s,y:i}=e.tl.touchCorner.tl,{height:n,width:r,scaleY:o,scaleX:h}=t;t.top=i-n*o/2,t.left=s-r*h/2,t.setCoords()}function fC(a,t,e){!e||!a||(e.scale(1/t),dC(a,e))}function gC(a,t){if(!a)return;const e=a._cornerSize||6;a.borderScaleFactor=1/t,a.cornerSize=e*(1/t),a.touchCornerSize=e*4*(1/t),a.setCoords()}function pC(a){const t=_s.get(a);t&&(t.discardActiveObject(),t.renderAll())}function mC(a){const t=_s.get(a);t&&(t.clear(),_s.delete(a))}function bC(a,t){return new be(a,{scaleX:t,scaleY:t})}function zb(a,t){if(!t)return;const{left:e,top:s,scaleX:i,scaleY:n,width:r,height:o}=a,h=t.x*r*i,c=t.y*o*n;a.set({left:e-h,top:s-c})}function Gb(a,t,e){var n;const s=a.type,i={"application/pdf":yC,"image/png":Xb,"image/jpeg":Xb};return((n=i[s])==null?void 0:n.call(i,a,t,e))??Promise.reject(new Error(`Unsupported ${s} file type.`))}async function yC(a,t,e){const s=await QS(a);if(!s)return;const i=aC(a,s);try{const n=await Vb({page:1,PDFBase64:s,scale:.8,password:t},e);return{...i,pages:n}}catch(n){return Promise.reject(n)}}async function Vb({page:a,PDFBase64:t,scale:e,password:s},i){try{const n=await JS(t,s),r=await n.getPage(a),{renderTask:o,canvas:h}=hC(r,e);return o.promise.then(()=>(i&&cC(i,h),n.numPages))}catch(n){return Promise.reject(n)}}async function Xb(a,t,e){if(e)return await uC(e,a)}const vC={top:100,left:50,scaleX:.5,scaleY:.5,borderColor:"black",cornerStrokeColor:"black",cornerSize:6,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},_C={top:100,left:50,fontFamily:"helvetica",borderColor:"black",cornerStrokeColor:"black",scaleX:.7,scaleY:.7,cornerSize:6,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},wC={borderColor:"black",cornerStrokeColor:"black",cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},xC={stroke:"#000",hoverStroke:"#B7EC5D",src:""};function Wb(a){const{id:t="",selectionOptions:e,pointerDown:s,pointerMove:i,pointerUp:n}=a||{};let r=null,o=null,h=1,c={...xC};function u(){if(!t||_s.has(t))return;const k=oC(t);return k.on("selection:created",O=>{if(O.selected.length<=1)return;const R=k.getActiveObject();R&&(o=R,e!=null&&e.value&&o.set(e.value),o._cornerSize=o.cornerSize,S(h))}),k.on("selection:cleared",()=>E(k)),s&&k.on("mouse:down",s),i&&k.on("mouse:move",i),n&&k.on("mouse:up",n),k}function d(k,O){return Gb(k,O,t)}function f(k){return Vb(k,t)}async function g({url:k,scale:O=.5}){await Bb(t,{url:k,scale:O})}async function p(k,O,R){const L=_s.get(t);if(!L)return;const N=await be.fromURL(k,{},{...vC,...O});zb(N,R),L.add(N),_(L,N),L.setActiveObject(N)}function b(k,O,R){const L=_s.get(t);if(!L)return;const N=new me(k,{..._C,...O});zb(N,R),L.add(N),_(L,N),L.setActiveObject(N)}function _(k,O){O.on("selected",R=>y({canvas:k,target:R.target})),O.on("modified",R=>y({canvas:k,target:R.target})),O.on("scaling",()=>E(k)),O.on("moving",()=>E(k)),O.on("rotating",()=>E(k)),O._cornerSize=O.cornerSize}async function y({canvas:k,target:O,stroke:R=c.stroke,uuid:L=Date.now()}){if(k.getActiveObjects().length>1||(r==null?void 0:r.stroke)===`${R}-${L}`)return;const W=await lC(c.src,R,L);E(k),r=W,o=O,x(k,O,L),S(h,!0),k.add(W)}function x(k,O,R){r&&(r.on("selected",()=>{k.remove(O),E(k)}),r.on("mouseover",()=>{y({canvas:k,target:O,stroke:c.hoverStroke,uuid:R})}),r.on("mouseout",()=>{y({canvas:k,target:O,stroke:c.stroke,uuid:R})}))}function S(k,O=!1){const R=_s.get(t);h=k,R&&(gC(o,k),fC(o,k,r),!O&&R.renderAll())}function C(k){if(!k)return;c={...c,...k};const O=_s.get(t);!r||!o||!O||y({target:o,canvas:O})}function E(k){o=null,r&&(k.remove(r),r=null)}function D(){pC(t)}function M(){mC(t)}return{createCanvas:u,loadFile:d,specifyPage:f,renderImage:g,addFabric:p,addTextFabric:b,clearActive:D,deleteCanvas:M,scaleFabric:S,setCloseSvgOptions:C}}function SC(a){let t=0;const e=rC(()=>{t!==window.innerWidth&&(t=window.innerWidth,a())});q.onMounted(()=>{window.addEventListener("resize",e)}),q.onBeforeUnmount(()=>{window.removeEventListener("resize",e)})}const CC=q.defineComponent({__name:"pdf-canvas",props:{file:{},page:{default:1},canvasId:{default:"PDF-canvas"},fileZoom:{default:1},fileScale:{default:1},canvasScale:{default:1},canvasClass:{default:""},isDrop:{type:Boolean,default:!1},password:{},dropTextOptions:{},dropImageOptions:{},selectionOptions:{default:()=>({...wC})},closeSvgOptions:{},manualReload:{type:Boolean},onDestroy:{type:Function,default:q.onBeforeUnmount}},emits:["loaded","reload","pointerDown","pointerMove","pointerUp"],setup(a,{expose:t,emit:e}){const s=a,i=e,{onDestroy:n}=s,r=q.ref(null),o=`${s.canvasId}-${s.page-1}`,h=q.computed(()=>s.fileZoom*s.canvasScale),{createCanvas:c,specifyPage:u,addFabric:d,addTextFabric:f,renderImage:g,clearActive:p,deleteCanvas:b,scaleFabric:_,setCloseSvgOptions:y}=Wb({id:o,selectionOptions:q.toRef(s,"selectionOptions"),pointerDown:M=>i("pointerDown",M),pointerMove:M=>i("pointerMove",M),pointerUp:M=>i("pointerUp",M)});x(),SC(D);async function x(){const{file:M,page:k,fileScale:O}=s;window.requestAnimationFrame(async()=>{if(await q.nextTick(),c(),M.PDFBase64.startsWith("data:image")||M.canvas){const{canvas:R}=M,L=R?7:3,N=R!=null&&R.length?R[k-1]:M.PDFBase64;g({url:N,scale:O/L}),i("loaded");return}await u({page:k,PDFBase64:M.PDFBase64,scale:O,password:s.password}),i("loaded")})}function S(M){if(!s.isDrop||!M.dataTransfer)return;const{dataTransfer:k,offsetX:O,offsetY:R}=M,L=k.getData("text/plain"),N=k.getData("text/uri-list"),W=k.getData("custom/offset"),G=W?JSON.parse(W):null,at={top:R,left:O},F={x:(G==null?void 0:G.offsetX)??0,y:(G==null?void 0:G.offsetY)??0};N?C(N,at,F):L&&E(L,at,F)}function C(M,k,O){d(M,{...s.dropImageOptions,...k},O)}function E(M,k,O){f(M,{...s.dropTextOptions,...k},O)}function D(){s.manualReload||x(),i("reload")}return q.watch([()=>s.fileScale,()=>s.page,()=>s.file,()=>s.password],D),q.watch(h,M=>_(M),{immediate:!0}),q.watch(()=>s.closeSvgOptions,y,{immediate:!0}),n(b),t({reload:x,addImage:C,addText:E,clearActive:p,deleteCanvas:b,canvasRef:r}),(M,k)=>(q.openBlock(),q.createElementBlock("div",{style:q.normalizeStyle({transform:`scale(${h.value})`}),onDragover:k[0]||(k[0]=q.withModifiers(()=>{},["prevent"])),onDragenter:k[1]||(k[1]=q.withModifiers(()=>{},["prevent"])),onDrop:q.withModifiers(S,["stop","prevent"])},[q.createElementVNode("canvas",{id:o,ref_key:"canvasRef",ref:r,class:q.normalizeClass(M.canvasClass)},null,2)],36))}});nt.default=CC,nt.loadFile=Gb,nt.useFabric=Wb,Object.defineProperties(nt,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@component-hook/pdf-canvas",
3
- "version": "1.1.0-alpha.8",
3
+ "version": "1.1.0-alpha.9",
4
4
  "description": "Rendering PDF documents onto a canvas with vue3 and react component",
5
5
  "license": "MIT",
6
6
  "type": "module",