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

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.
@@ -22305,7 +22305,7 @@ function FC(a) {
22305
22305
  }
22306
22306
  function S(k, O = !1) {
22307
22307
  const R = Ss.get(t);
22308
- R && (AC(o, k), CC(o, k, r), !O && R.renderAll());
22308
+ h = k, R && (AC(o, k), CC(o, k, r), !O && R.renderAll());
22309
22309
  }
22310
22310
  function C(k) {
22311
22311
  if (!k) return;
@@ -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);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||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"}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@component-hook/pdf-canvas",
3
- "version": "1.1.0-alpha.7",
3
+ "version": "1.1.0-alpha.8",
4
4
  "description": "Rendering PDF documents onto a canvas with vue3 and react component",
5
5
  "license": "MIT",
6
6
  "type": "module",