@component-hook/pdf-canvas 1.1.0-alpha.11 → 1.1.0-alpha.12

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.
@@ -22236,7 +22236,13 @@ const kC = "data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%20
22236
22236
  stroke: "#000",
22237
22237
  hoverStroke: "#B7EC5D",
22238
22238
  src: kC
22239
- }, RC = ["borderColor", "cornerStrokeColor", "cornerSize", "selectionBackgroundColor"];
22239
+ }, RC = [
22240
+ "borderColor",
22241
+ "cornerStrokeColor",
22242
+ "cornerSize",
22243
+ "_cornerSize",
22244
+ "selectionBackgroundColor"
22245
+ ];
22240
22246
  function LC(a) {
22241
22247
  const {
22242
22248
  id: t = "",
@@ -22284,7 +22290,7 @@ function LC(a) {
22284
22290
  Cg(I, N), Y.add(I), x(Y, I), Y.setActiveObject(I);
22285
22291
  }
22286
22292
  function x(O, L) {
22287
- L.on("selected", (N) => S({ canvas: O, target: N.target })), L.on("modified", (N) => S({ canvas: O, target: N.target })), L.on("scaling", () => k(O)), L.on("moving", () => k(O)), L.on("rotating", () => k(O)), L._cornerSize = L.cornerSize;
22293
+ L.on("selected", (N) => S({ canvas: O, target: N.target })), L.on("modified", (N) => S({ canvas: O, target: N.target })), L.on("scaling", () => k(O)), L.on("moving", () => k(O)), L.on("rotating", () => k(O)), L._cornerSize = L._cornerSize ?? L.cornerSize;
22288
22294
  }
22289
22295
  async function S({
22290
22296
  canvas: O,
@@ -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,cs,e.fontSize),m(r,Ks,U.makeHexColor(...e.color)),m(r,ls,w(o=_t,fn,Ep).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=_t._internalPadding*this.parentScale,i=this.getRect(s,s),n=Dt._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:l(this,Ks)),r={annotationType:tt.FREETEXT,color:n,fontSize:l(this,cs),value:w(this,Ut,Gv).call(this),pageIndex:this.pageIndex,rect:i,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?r:this.annotationElementId&&!w(this,Ut,Vv).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,cs)}px * var(--scale-factor))`,i.color=l(this,Ks),s.replaceChildren();for(const r of l(this,ls).split(`
507
507
  `)){const o=document.createElement("div");o.append(r?document.createTextNode(r):document.createElement("br")),s.append(o)}const n=_t._internalPadding*this.parentScale;return e.updateEdited({rect:this.getRect(n,n),popupContent:l(this,ls)}),s}resetAnnotationElement(e){super.resetAnnotationElement(e),e.resetEdited()}};Ks=new WeakMap,ls=new WeakMap,ic=new WeakMap,xo=new WeakMap,cs=new WeakMap,Ut=new WeakSet,Bv=function(e){const s=n=>{this.editorDiv.style.fontSize=`calc(${n}px * var(--scale-factor))`,this.translate(0,-(n-l(this,cs))*this.parentScale),m(this,cs,n),w(this,Ut,Xd).call(this)},i=l(this,cs);this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:at.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})},Hv=function(e){const s=n=>{m(this,Ks,this.editorDiv.style.color=n)},i=l(this,Ks);this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:at.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})},zv=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=_t,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,ls))for(const e of l(this,ls).split(`
509
- `)){const s=document.createElement("div");s.append(e?document.createTextNode(e):document.createElement("br")),this.editorDiv.append(s)}},Gv=function(){return l(this,ls).replaceAll(" "," ")},Ep=function(e){return e.replaceAll(" "," ")},Vv=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(_t,fn),q(_t,"_freeTextDefaultContent",""),q(_t,"_internalPadding",0),q(_t,"_defaultColor",null),q(_t,"_defaultFontSize",10),q(_t,"_type","freetext"),q(_t,"_editorType",tt.FREETEXT);let Rg=_t;class V{toSVGPath(){yt("Abstract method `toSVGPath` must be implemented.")}get box(){yt("Abstract getter `box` must be implemented.")}serialize(t,e){yt("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]}}q(V,"PRECISION",1e-4);const gn=class gn{constructor({x:t,y:e},s,i,n,r,o=0){v(this,Jt);v(this,us);v(this,Qs,[]);v(this,Xa);v(this,Wa);v(this,wi,[]);v(this,rt,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,us,s),m(this,Ya,n*i),m(this,Wa,r),l(this,rt).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,rt)[8])}add({x:t,y:e}){var R;m(this,So,t),m(this,Co,e);const[s,i,n,r]=l(this,us);let[o,h,c,u]=l(this,rt).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,(R=l(this,sr))==null||R.push(t,e);const C=-y/p,E=_/p,P=C*l(this,Ya),k=E*l(this,Ya);return l(this,rt).set(l(this,rt).subarray(2,8),0),l(this,rt).set([c+P,u+k],4),l(this,rt).set(l(this,rt).subarray(14,18),12),l(this,rt).set([c-P,u-k],16),isNaN(l(this,rt)[6])?(l(this,wi).length===0&&(l(this,rt).set([o+P,h+k],2),l(this,wi).push(NaN,NaN,NaN,NaN,(o+P-s)/n,(h+k-i)/r),l(this,rt).set([o-P,h-k],14),l(this,Qs).push(NaN,NaN,NaN,NaN,(o-P-s)/n,(h-k-i)/r)),l(this,rt).set([x,S,o,h,c,u],6),!this.isEmpty()):(l(this,rt).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,rt).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,rt).subarray(14,18),l(this,Qs).push(NaN,NaN,NaN,NaN,((x+o)/2-s)/n,((S+h)/2-i)/r),!0):([x,S,o,h,c,u]=l(this,rt).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,rt).subarray(12,18),l(this,Qs).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,Qs);if(isNaN(l(this,rt)[6])&&!this.isEmpty())return w(this,Jt,Xv).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,Uv).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,Wv).call(this,s),s.join(" ")}newFreeDrawOutline(t,e,s,i,n,r){return new jb(t,e,s,i,n,r)}getOutlines(){var d;const t=l(this,wi),e=l(this,Qs),s=l(this,rt),[i,n,r,o]=l(this,us),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,Yv).call(this,h);const c=new Float32Array(l(this,wi).length+24+l(this,Qs).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,qv).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,$v).call(this,c,u),this.newFreeDrawOutline(c,h,l(this,us),l(this,Ua),l(this,Xa),l(this,Wa))}};us=new WeakMap,Qs=new WeakMap,Xa=new WeakMap,Wa=new WeakMap,wi=new WeakMap,rt=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,rt).subarray(4,6),e=l(this,rt).subarray(16,18),[s,i,n,r]=l(this,us);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]},Xv=function(){const[t,e,s,i]=l(this,us),[n,r,o,h]=w(this,Jt,Oc).call(this);return`M${(l(this,rt)[2]-t)/s} ${(l(this,rt)[3]-e)/i} L${(l(this,rt)[4]-t)/s} ${(l(this,rt)[5]-e)/i} L${n} ${r} L${o} ${h} L${(l(this,rt)[16]-t)/s} ${(l(this,rt)[17]-e)/i} L${(l(this,rt)[14]-t)/s} ${(l(this,rt)[15]-e)/i} Z`},Wv=function(t){const e=l(this,Qs);t.push(`L${e[4]} ${e[5]} Z`)},Uv=function(t){const[e,s,i,n]=l(this,us),r=l(this,rt).subarray(4,6),o=l(this,rt).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}`)},Yv=function(t){const e=l(this,rt),[s,i,n,r]=l(this,us),[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,us),l(this,Ua),l(this,Xa),l(this,Wa))},$v=function(t,e){const s=l(this,Qs);return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6},qv=function(t,e){const s=l(this,rt).subarray(4,6),i=l(this,rt).subarray(16,18),[n,r,o,h]=l(this,us),[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 jb extends V{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,ds);v(this,hc);v(this,zt);m(this,zt,e),m(this,ds,s),m(this,$a,i),m(this,hc,n),m(this,pn,r),m(this,ac,o),this.lastPoint=[NaN,NaN],w(this,Sd,Kv).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,zt)[4]} ${l(this,zt)[5]}`];for(let s=6,i=l(this,zt).length;s<i;s+=6){if(isNaN(l(this,zt)[s])){e.push(`L${l(this,zt)[s+4]} ${l(this,zt)[s+5]}`);continue}e.push(`C${l(this,zt)[s]} ${l(this,zt)[s+1]} ${l(this,zt)[s+2]} ${l(this,zt)[s+3]} ${l(this,zt)[s+4]} ${l(this,zt)[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=V._rescale(l(this,zt),e,n,o,-h),u=V._rescale(l(this,ds),e,n,o,-h);break;case 90:c=V._rescaleAndSwap(l(this,zt),e,s,o,h),u=V._rescaleAndSwap(l(this,ds),e,s,o,h);break;case 180:c=V._rescale(l(this,zt),i,s,-o,h),u=V._rescale(l(this,ds),i,s,-o,h);break;case 270:c=V._rescaleAndSwap(l(this,zt),i,n,-o,-h),u=V._rescaleAndSwap(l(this,ds),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,ds)[0]*f+p,y:l(this,ds)[1]*g+b},l(this,$a),l(this,hc),e,l(this,ac),s??l(this,pn));for(let y=2;y<l(this,ds).length;y+=2)_.add({x:l(this,ds)[y]*f+p,y:l(this,ds)[y+1]*g+b});return _.getOutlines()}}$a=new WeakMap,Ao=new WeakMap,pn=new WeakMap,ac=new WeakMap,ds=new WeakMap,hc=new WeakMap,zt=new WeakMap,Sd=new WeakSet,Kv=function(e){const s=l(this,zt);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,Js,[]);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,P=Math.floor((y-e)/c)*c,k=Math.ceil((y+S+e)/c)*c,D=[C,P,k,!0],R=[E,P,k,!1];l(this,ir).push(D,R),n=Math.min(n,C),r=Math.max(r,E),o=Math.min(o,P),h=Math.max(h,k)}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,kp).call(this,e)),w(this,Ie,Jv).call(this,e)):(w(this,Ie,Zv).call(this,e),t.push(...w(this,Ie,kp).call(this,e)));return w(this,Ie,Qv).call(this,t)}}lc=new WeakMap,cc=new WeakMap,ir=new WeakMap,Js=new WeakMap,Ie=new WeakSet,Qv=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,Js);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},Jv=function([,t,e]){const s=w(this,Ie,Yd).call(this,t);l(this,Js).splice(s,0,[t,e])},Zv=function([,t,e]){const s=w(this,Ie,Yd).call(this,t);for(let i=s;i<l(this,Js).length;i++){const[n,r]=l(this,Js)[i];if(n!==t)break;if(n===t&&r===e){l(this,Js).splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=l(this,Js)[i];if(n!==t)break;if(n===t&&r===e){l(this,Js).splice(i,1);return}}},kp=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,Js)[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 V{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 jb{newOutliner(t,e,s,i,n,r=0){return new Fg(t,e,s,i,n,r)}}const Qe=class Qe{constructor({editor:t=null,uiManager:e=null}){v(this,vt);v(this,Zs,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,ti,null);v(this,Ja);var s;t?(m(this,Qa,!1),m(this,Ja,at.HIGHLIGHT_COLOR),m(this,fc,t)):(m(this,Qa,!0),m(this,Ja,at.HIGHLIGHT_DEFAULT_COLOR)),m(this,ti,(t==null?void 0:t._uiManager)||e),m(this,gc,l(this,ti)._eventBus),m(this,Ka,(t==null?void 0:t.color)||((s=l(this,ti))==null?void 0:s.highlightColors.values().next().value)||"#FFFF98"),l(Qe,pc)||m(Qe,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 nt(this,"_keyboardManager",new Xh([[["Escape","mac+Escape"],Qe.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],Qe.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],Qe.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],Qe.prototype._moveToPrevious],[["Home","mac+Home"],Qe.prototype._moveToBeginning],[["End","mac+End"],Qe.prototype._moveToEnd]]))}renderButton(){const t=m(this,Zs,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,ti)._signal;t.addEventListener("click",w(this,vt,zo).bind(this),{signal:e}),t.addEventListener("keydown",w(this,vt,Dp).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,vt,Mp).call(this));return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}_colorSelectFromKeyboard(t){if(t.target===l(this,Zs)){w(this,vt,zo).call(this,t);return}const e=t.target.getAttribute("data-color");e&&w(this,vt,Pp).call(this,e,t)}_moveToNext(t){var e,s;if(!l(this,vt,gr)){w(this,vt,zo).call(this,t);return}if(t.target===l(this,Zs)){(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,Zs)){l(this,vt,gr)&&this._hideDropdownFromKeyboard();return}l(this,vt,gr)||w(this,vt,zo).call(this,t),(s=t.target.previousSibling)==null||s.focus()}_moveToBeginning(t){var e;if(!l(this,vt,gr)){w(this,vt,zo).call(this,t);return}(e=l(this,Zt).firstChild)==null||e.focus()}_moveToEnd(t){var e;if(!l(this,vt,gr)){w(this,vt,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,vt,gr)){(t=l(this,fc))==null||t.unselect();return}this.hideDropdown(),l(this,Zs).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,ti).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,Zs))==null||t.remove(),m(this,Zs,null),m(this,To,null),(e=l(this,Zt))==null||e.remove(),m(this,Zt,null)}};Zs=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,ti=new WeakMap,Ja=new WeakMap,pc=new WeakMap,vt=new WeakSet,Mp=function(){const t=document.createElement("div"),e=l(this,ti)._signal;t.addEventListener("contextmenu",Gs,{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,ti).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(Qe,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,vt,Pp).bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",w(this,vt,Dp).bind(this),{signal:e}),t},Pp=function(t,e){e.stopPropagation(),l(this,gc).dispatch("switchannotationeditorparams",{source:this,type:l(this,Ja),value:t})},Dp=function(t){Qe._keyboardManager.exec(this,t)},zo=function(t){if(l(this,vt,gr)){this.hideDropdown();return}if(m(this,dc,t.detail===0),l(this,nr)||(m(this,nr,new AbortController),window.addEventListener("pointerdown",w(this,vt,ty).bind(this),{signal:l(this,ti).combinedSignal(l(this,nr))})),l(this,Zt)){l(this,Zt).classList.remove("hidden");return}const e=m(this,Zt,w(this,vt,Mp).call(this));l(this,Zs).append(e)},ty=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(Qe,pc,null);let nd=Qe;const ut=class ut extends Dt{constructor(e){super({...e,name:"highlightEditor"});v(this,Z);v(this,Za,null);v(this,mc,0);v(this,mn);v(this,Eo,null);v(this,th,null);v(this,Je,null);v(this,bc,null);v(this,vc,0);v(this,ko,null);v(this,Es,null);v(this,fs,null);v(this,le,!1);v(this,eh,null);v(this,bn);v(this,Se,null);v(this,sh,"");v(this,ks);v(this,yc,"");this.color=e.color||ut._defaultColor,m(this,ks,e.thickness||ut._defaultThickness),m(this,bn,e.opacity||ut._defaultOpacity),m(this,mn,e.boxes||null),m(this,yc,e.methodOfCreation||""),m(this,sh,e.text||""),this._isDraggable=!1,e.highlightId>-1?(m(this,le,!0),w(this,Z,$d).call(this,e),w(this,Z,Go).call(this)):l(this,mn)&&(m(this,Za,e.anchorNode),m(this,mc,e.anchorOffset),m(this,bc,e.focusNode),m(this,vc,e.focusOffset),w(this,Z,Op).call(this),w(this,Z,Go).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const e=ut.prototype;return nt(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,ks),methodOfCreation:l(this,yc)}}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;Dt.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 at.HIGHLIGHT_DEFAULT_COLOR:ut._defaultColor=s;break;case at.HIGHLIGHT_THICKNESS:ut._defaultThickness=s;break}}translateInPage(e,s){}get toolbarPosition(){return l(this,eh)}updateParams(e,s){switch(e){case at.HIGHLIGHT_COLOR:w(this,Z,ey).call(this,s);break;case at.HIGHLIGHT_THICKNESS:w(this,Z,sy).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[at.HIGHLIGHT_DEFAULT_COLOR,ut._defaultColor],[at.HIGHLIGHT_THICKNESS,ut._defaultThickness]]}get propertiesToUpdate(){return[[at.HIGHLIGHT_COLOR,this.color||ut._defaultColor],[at.HIGHLIGHT_THICKNESS,l(this,ks)||ut._defaultThickness],[at.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,Z,Rc).call(this))}getBaseTranslation(){return[0,0]}getRect(e,s){return super.getRect(e,s,w(this,Z,Rc).call(this))}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),e&&this.div.focus()}remove(){w(this,Z,Rp).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,Z,Go).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?w(this,Z,Rp).call(this):e&&(w(this,Z,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,Ms,_h).call(n,l(this,Es).box,e)):i=w(r=ut,Ms,_h).call(r,[this.x,this.y,this.width,this.height],e),s.updateProperties(l(this,fs),{bbox:i,root:{"data-main-rotation":e}}),s.updateProperties(l(this,Se),{bbox:w(o=ut,Ms,_h).call(o,l(this,Je).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,Z,ny).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,Z,qd).call(this,!0);break;case 1:case 3:w(this,Z,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,Z,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,fs),{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,Ms,hy).call(this,e,p)};window.addEventListener("blur",g,{signal:f}),window.addEventListener("pointerup",g,{signal:f}),window.addEventListener("pointerdown",ss,{capture:!0,passive:!1,signal:f}),window.addEventListener("contextmenu",Gs,{signal:f}),i.addEventListener("pointermove",w(this,Ms,ay).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 Ib){const{data:{quadPoints:S,rect:C,rotation:E,id:P,color:k,opacity:D,popupRef:R},parent:{page:{pageNumber:F}}}=e;n=e={annotationType:tt.HIGHLIGHT,color:Array.from(k),opacity:D,quadPoints:S,boxes:null,pageIndex:F-1,rect:C.slice(0),rotation:E,id:P,deleted:!1,popupRef:R}}else if(e instanceof Og){const{data:{inkLists:S,rect:C,rotation:E,id:P,color:k,borderStyle:{rawWidth:D},popupRef:R},parent:{page:{pageNumber:F}}}=e;n=e={annotationType:tt.HIGHLIGHT,color:Array.from(k),thickness:D,inkLists:S,boxes:null,pageIndex:F-1,rect:C.slice(0),rotation:E,id:P,deleted:!1,popupRef:R}}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,ks,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,Z,Op).call(b),w(_=u,Z,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,ks)/2,!0,.001);for(let D=0,R=S.length;D<R;D+=2)C.x=S[D]-g,C.y=f-(S[D+1]-p),E.add(C);const{id:P,clipPathId:k}=s.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:u.color,"fill-opacity":u._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:E.toSVGPath()}},!0,!0);w(y=u,Z,$d).call(y,{highlightOutlines:E.getOutlines(),highlightId:P,clipPathId:k}),w(x=u,Z,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=Dt._colorManager.convert(this.color),n={annotationType:tt.HIGHLIGHT,color:i,opacity:l(this,bn),thickness:l(this,ks),quadPoints:w(this,Z,ry).call(this),outlines:w(this,Z,oy).call(this,s),pageIndex:this.pageIndex,rect:s,rotation:w(this,Z,Rc).call(this),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!w(this,Z,ly).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,Je=new WeakMap,bc=new WeakMap,vc=new WeakMap,ko=new WeakMap,Es=new WeakMap,fs=new WeakMap,le=new WeakMap,eh=new WeakMap,bn=new WeakMap,Se=new WeakMap,sh=new WeakMap,ks=new WeakMap,yc=new WeakMap,Z=new WeakSet,Op=function(){const e=new Lg(l(this,mn),.001);m(this,Es,e.getOutlines()),[this.x,this.y,this.width,this.height]=l(this,Es).box;const s=new Lg(l(this,mn),.0025,.001,this._uiManager.direction==="ltr");m(this,Je,s.getOutlines());const{lastPoint:i}=l(this,Je);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,Es,e),m(this,Je,e.getNewOutline(l(this,ks)/2+1.5,.0025)),s>=0)m(this,fs,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,Je).box,path:{d:l(this,Je).toSVGPath()}},!0));else if(this.parent){const g=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(l(this,fs),{bbox:w(d=ut,Ms,_h).call(d,l(this,Es).box,(g-this.rotation+360)%360),path:{d:e.toSVGPath()}}),this.parent.drawLayer.updateProperties(l(this,Se),{bbox:w(f=ut,Ms,_h).call(f,l(this,Je).box,g),path:{d:l(this,Je).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,Je);m(this,eh,[(u[0]-r)/h,(u[1]-o)/c])},ey=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,fs),{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:at.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(e)},!0)},sy=function(e){const s=l(this,ks),i=n=>{m(this,ks,n),w(this,Z,iy).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:at.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)},iy=function(e){if(!l(this,le))return;w(this,Z,$d).call(this,{highlightOutlines:l(this,Es).getNewOutline(e/2)}),this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)},Rp=function(){l(this,fs)===null||!this.parent||(this.parent.drawLayer.remove(l(this,fs)),m(this,fs,null),this.parent.drawLayer.remove(l(this,Se)),m(this,Se,null))},Go=function(e=this.parent){l(this,fs)===null&&({id:ze(this,fs)._,clipPathId:ze(this,Eo)._}=e.drawLayer.draw({bbox:l(this,Es).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,Es).toSVGPath()}},!1,!0),m(this,Se,e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:l(this,le)},bbox:l(this,Je).box,path:{d:l(this,Je).toSVGPath()}},l(this,le))),l(this,ko)&&(l(this,ko).style.clipPath=l(this,Eo)))},Ms=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]},ny=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,vc))},Rc=function(){return l(this,le)?this.rotation:0},ry=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},oy=function(e){return l(this,Es).serialize(e,w(this,Z,Rc).call(this))},ay=function(e,s){this._freeHighlight.add(s)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})},hy=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=""},ly=function(e){const{color:s}=this._initialData;return e.color.some((i,n)=>i!==s[n])},v(ut,Ms),q(ut,"_defaultColor",null),q(ut,"_defaultOpacity",1),q(ut,"_defaultThickness",12),q(ut,"_type","highlight"),q(ut,"_editorType",tt.HIGHLIGHT),q(ut,"_freeHighlightId",-1),q(ut,"_freeHighlight",null),q(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(){yt("Not implemented")}}Mo=new WeakMap;const X=class X extends Dt{constructor(e){super(e);v(this,lt);v(this,gs,null);v(this,ih);q(this,"_drawId",null);m(this,ih,e.mustBeCommitted||!1),e.drawOutlines&&(w(this,lt,Lp).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){yt("Not implemented")}static get typesMap(){yt("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(X,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,gs).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,X._mergeSVGProperties(l(this,gs).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,X._mergeSVGProperties(l(this,gs).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,X._mergeSVGProperties(l(this,gs).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,Ip).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,gs).box),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?(this._uiManager.removeShouldRescale(this),w(this,lt,Ip).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,X._mergeSVGProperties({bbox:w(this,lt,wh).call(this)},l(this,gs).updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&w(this,lt,Fc).call(this,l(this,gs).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){yt("Not implemented")}static startDrawing(e,s,i,n){var _;const{target:r,offsetX:o,offsetY:h,pointerId:c,pointerType:u}=n;if(l(X,or)&&l(X,or)!==u)return;const{viewport:{rotation:d}}=e,{width:f,height:g}=r.getBoundingClientRect(),p=m(X,Po,new AbortController),b=e.combinedSignal(p);if(l(X,rr)||m(X,rr,c),l(X,or)??m(X,or,u),window.addEventListener("pointerup",y=>{var x;l(X,rr)===y.pointerId?this._endDraw(y):(x=l(X,ar))==null||x.delete(y.pointerId)},{signal:b}),window.addEventListener("pointercancel",y=>{var x;l(X,rr)===y.pointerId?this._currentParent.endDrawingSession():(x=l(X,ar))==null||x.delete(y.pointerId)},{signal:b}),window.addEventListener("pointerdown",y=>{l(X,or)===y.pointerType&&((l(X,ar)||m(X,ar,new Set)).add(y.pointerId),l(X,ne).isCancellable()&&(l(X,ne).removeLastElement(),l(X,ne).isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:b}),window.addEventListener("contextmenu",Gs,{signal:b}),r.addEventListener("pointermove",this._drawMove.bind(this),{signal:b}),r.addEventListener("touchmove",y=>{y.timeStamp===l(X,Oo)&&ss(y)},{signal:b}),e.toggleDrawing(),(_=s._editorUndoBar)==null||_.hide(),l(X,ne)){e.drawLayer.updateProperties(this._currentDrawId,l(X,ne).startNew(o,h,f,g,d));return}s.updateUIForDefaultProperties(this),m(X,ne,this.createDrawerInstance(o,h,f,g,d)),m(X,Do,this.getDefaultDrawingOptions()),this._currentParent=e,{id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties(l(X,Do).toSVGProperties(),l(X,ne).defaultSVGProperties),!0,!1)}static _drawMove(e){var r;if(m(X,Oo,-1),!l(X,ne))return;const{offsetX:s,offsetY:i,pointerId:n}=e;if(l(X,rr)===n){if(((r=l(X,ar))==null?void 0:r.size)>=1){this._endDraw(e);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,l(X,ne).add(s,i)),m(X,Oo,e.timeStamp),ss(e)}}static _cleanup(e){e&&(this._currentDrawId=-1,this._currentParent=null,m(X,ne,null),m(X,Do,null),m(X,or,null),m(X,Oo,NaN)),l(X,Po)&&(l(X,Po).abort(),m(X,Po,null),m(X,rr,NaN),m(X,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(X,ne).end(e.offsetX,e.offsetY)),this.supportMultipleDrawings){const i=l(X,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:at.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(e){const s=this._currentParent;if(!s)return null;if(s.toggleDrawing(!0),s.cleanUndoStack(at.DRAW_STEP),!l(X,ne).isEmpty()){const{pageDimensions:[i,n],scale:r}=s,o=s.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:l(X,ne).getOutlines(i*r,n*r,r,this._INNER_MARGIN),drawingOptions:l(X,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){yt("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,Lp).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,gs).serialize([s,i,n,r],e)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};gs=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,Lp=function({drawOutlines:e,drawId:s,drawingOptions:i}){m(this,gs,e),this._drawingOptions||(this._drawingOptions=i),s>=0?(this._drawId=s,this.parent.drawLayer.finalizeDraw(s,e.defaultProperties)):this._drawId=w(this,lt,Fp).call(this,e,this.parent),w(this,lt,Fc).call(this,e.box)},Fp=function(e,s){const{id:i}=s.drawLayer.draw(X._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return i},Ip=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,Fp).call(this,l(this,gs),e)}},cy=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,cy).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]}},q(X,"_currentDrawId",-1),q(X,"_currentParent",null),v(X,ne,null),v(X,Po,null),v(X,Do,null),v(X,rr,NaN),v(X,or,null),v(X,ar,null),v(X,Oo,NaN),q(X,"_INNER_MARGIN",3);let Ig=X;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,Ps,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(...V.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,Ps,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,Ps,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,Ps,0),this.toSVGPath()}return{path:{d:l(this,ce)}}}toSVGPath(){const t=V.svgRound(l(this,re)[4]),e=V.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,Ps,6)}if(l(this,Ne).length===4){const i=V.svgRound(l(this,re)[10]),n=V.svgRound(l(this,re)[11]);return m(this,ce,`${l(this,ce)} L ${i} ${n}`),m(this,Ps,12),l(this,ce)}const s=[];l(this,Ps)===0&&(s.push(`M ${t} ${e}`),m(this,Ps,6));for(let i=l(this,Ps),n=l(this,re).length;i<n;i+=6){const[r,o,h,c,u,d]=l(this,re).slice(i,i+6).map(V.svgRound);s.push(`C${r} ${o} ${h} ${c} ${u} ${d}`)}return m(this,ce,l(this,ce)+s.join(" ")),m(this,Ps,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,Ps=new WeakMap,Lo=new WeakMap,Fo=new WeakMap,Io=new WeakMap,rh=new WeakSet,Qd=function(t,e){return V._normalizePoint(t,e,l(this,Fo),l(this,Io),l(this,Ro))};const Yg=class Yg extends V{constructor(){super(...arguments);v(this,ue);v(this,je);v(this,_c,0);v(this,wc);v(this,ps);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,ps,e),w(this,ue,dy).call(this)}setLastElement(e){return l(this,ps).push(e),{path:{d:this.toSVGPath()}}}removeLastElement(){return l(this,ps).pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const e=[];for(const{line:s}of l(this,ps)){if(e.push(`M${V.svgRound(s[4])} ${V.svgRound(s[5])}`),s.length===6){e.push("Z");continue}if(s.length===12){e.push(`L${V.svgRound(s[10])} ${V.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(V.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,uy).call(this);let g,p,b,_,y,x,S,C,E;switch(l(this,ah)){case 0:E=V._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=V._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=V._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=V._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:P,points:k}of l(this,ps))o.push(E(P,g,p,b,_,r?new Array(P.length):null)),h.push(E(k,g,p,b,_,r?new Array(k.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:_=V._rescale,f=-e/i,g=s/n+1,p=1/i,b=-1/n;break;case 90:_=V._rescaleAndSwap,f=-s/n,g=-e/i,p=1/n,b=1/i;break;case 180:_=V._rescale,f=e/i+1,g=-s/n,p=-1/i,b=1/n;break;case 270:_=V._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,P,k,D]=x.subarray(0,4);C.set([NaN,NaN,NaN,NaN,E,P],0);for(let R=4;R<S;R+=2){const F=x[R],j=x[R+1];C.set(V.createBezierPoints(E,P,k,D,F,j),(R-2)*3),[E,P,k,D]=[k,D,F,j]}}}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 Yg;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,fy).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(V.svgRound).join(" ")}get defaultProperties(){const[e,s]=l(this,je);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${V.svgRound(e)} ${V.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} ${V.svgRound(h)} ${V.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)<=V.PRECISION||Math.abs(d-o)<=V.PRECISION){const _=e+i/2-(h+u/2),y=s+n/2-(c+d/2);return{path:{"transform-origin":`${V.svgRound(e)} ${V.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":`${V.svgRound(h)} ${V.svgRound(c)}`,transform:`${this.rotationTransform} scale(${p} ${b}) translate(${V.svgRound(r)} ${V.svgRound(o)}) scale(${f} ${g}) translate(${V.svgRound(-r)} ${V.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)<=V.PRECISION||Math.abs(f-o)<=V.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,ps))V._translate(S,y,x,S),V._translate(C,y,x,C);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${V.svgRound(e)} ${V.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,ps))V._rescale(y,b,_,g,p,y),V._rescale(x,b,_,g,p,x);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${V.svgRound(e)} ${V.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,ps))V._translate(u,h,c,u),V._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,ps))V._rescale(f,h,c,u,d,f),V._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":`${V.svgRound(e)} ${V.svgRound(s)}`}}}get defaultSVGProperties(){const e=l(this,je);return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${V.svgRound(e[0])} ${V.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}};je=new WeakMap,_c=new WeakMap,wc=new WeakMap,ps=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)]},uy=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]},dy=function(){const e=m(this,je,new Float32Array([1/0,1/0,-1/0,-1/0]));for(const{line:n}of l(this,ps)){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]},fy=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=Yg;const $g=class $g extends XS{constructor(e){super();v(this,lh);m(this,lh,e),super.updateProperties({fill:"none",stroke:Dt._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 $g(l(this,lh));return e.updateAll(this),e}};lh=new WeakMap;let Ng=$g;const ch=class ch extends Ig{constructor(e){super({...e,name:"inkEditor"});v(this,Cd);this._willKeepAspectRatio=!0}static initialize(e,s){Dt.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 nt(this,"typesMap",new Map([[at.INK_THICKNESS,"stroke-width"],[at.INK_COLOR,"stroke"],[at.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:tt.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:tt.INK,color:Dt._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,gy).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,gy=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},q(ch,"_type","ink"),q(ch,"_editorType",tt.INK),q(ch,"_defaultDrawingOptions",null);let jg=ch;const xc=class xc extends Dt{constructor(e){super({...e,name:"stampEditor"});v(this,ct);v(this,Rt,null);v(this,de,null);v(this,hr,null);v(this,vn,null);v(this,lr,null);v(this,uh,"");v(this,Ai,null);v(this,Ti,null);v(this,ms,!1);v(this,dh,!1);m(this,vn,e.bitmapUrl),m(this,lr,e.bitmapFile)}static initialize(e,s){Dt.initialize(e,s)}static get supportedTypes(){return nt(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(s=>`image/${s}`))}static get supportedTypesStr(){return nt(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(e){return this.supportedTypes.includes(e)}static paste(e,s){s.pasteEditor(tt.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,Rt,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,Rt)||l(this,vn)||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,Rt)?w(this,ct,Np).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,jp).call(this)},200))}copyCanvas(e,s,i=!1){var g;e||(e=224);const{width:n,height:r}=l(this,Rt),o=new mg;let h=l(this,Rt),c=n,u=r,d=null;if(s){if(n>s||r>s){const D=Math.min(s/n,s/r);c=Math.floor(n*D),u=Math.floor(r*D)}d=document.createElement("canvas");const p=d.width=Math.ceil(c*o.sx),b=d.height=Math.ceil(u*o.sy);l(this,ms)||(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,P=new OffscreenCanvas(C*2,E*2),k=P.getContext("2d");k.fillStyle=y,k.fillRect(0,0,C*2,E*2),k.fillStyle=x,k.fillRect(0,0,C,E),k.fillRect(C,E,C,E),_.fillStyle=_.createPattern(P,"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,Rt),n>e||r>e){const x=Math.min(e/n,e/r);p=Math.floor(n*x),b=Math.floor(r*x),l(this,ms)||(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 Nb){const{data:{rect:_,rotation:y,id:x,structParent:S,popupRef:C},container:E,parent:{page:{pageNumber:P}}}=e,k=E.querySelector("canvas"),D=i.imageManager.getFromCanvas(E.id,k);k.remove();const R=((b=await s._structTree.getAriaAttributes(`${ug}${x}`))==null?void 0:b.get("aria-label"))||"";n=e={annotationType:tt.STAMP,bitmapId:D.id,bitmap:D.bitmap,pageIndex:P-1,rect:_.slice(0),rotation:y,id:x,deleted:!1,accessibilityData:{decorative:!1,altText:R},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,Rt,h)):m(r,vn,c),m(r,ms,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:tt.STAMP,bitmapId:l(this,de),pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:l(this,ms),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,py).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,ms)?(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,ms)){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}};Rt=new WeakMap,de=new WeakMap,hr=new WeakMap,vn=new WeakMap,lr=new WeakMap,uh=new WeakMap,Ai=new WeakMap,Ti=new WeakMap,ms=new WeakMap,dh=new WeakMap,ct=new WeakSet,Ic=function(e,s=!1){if(!e){this.remove();return}m(this,Rt,e.bitmap),s||(m(this,de,e.id),m(this,ms,e.isSvg)),e.file&&m(this,uh,e.file.name),w(this,ct,Np).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,Rt)){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Rt)){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,vn)){const i=l(this,vn);m(this,vn,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()},Np=function(){var d;const{div:e}=this;let{width:s,height:i}=l(this,Rt);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,jp).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,Rt);let r=i,o=n,h=l(this,Rt);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},jp=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,ms)?l(this,Rt):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,ms)){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,Rt),s.getContext("2d").drawImage(l(this,Rt),0,0),s.toDataURL()}if(l(this,ms)){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,Rt),0,0,l(this,Rt).width,l(this,Rt).height,0,0,n,r),o.transferToImageBitmap()}return structuredClone(l(this,Rt))},py=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}},q(xc,"_type","stamp"),q(xc,"_editorType",tt.STAMP);let Bg=xc;const si=class si{constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:o,textLayer:h,viewport:c,l10n:u}){v(this,Et);v(this,No);v(this,fh,!1);v(this,Ei,null);v(this,cr,null);v(this,yn,null);v(this,Ds,new Map);v(this,ur,!1);v(this,gh,!1);v(this,jo,!1);v(this,ei,null);v(this,_n,null);v(this,Ce,null);v(this,wn,null);v(this,W);const d=[...l(si,dr).values()];if(!si._initialized){si._initialized=!0;for(const f of d)f.initialize(u,t)}t.registerEditorTypes(d),m(this,W,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,W).addLayer(this)}get isEmpty(){return l(this,Ds).size===0}get isInvisible(){return this.isEmpty&&l(this,W).getMode()===tt.NONE}updateToolbar(t){l(this,W).updateToolbar(t)}updateMode(t=l(this,W).getMode()){switch(w(this,Et,ef).call(this),t){case tt.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case tt.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case tt.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(si,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,W).setEditingState(t)}addCommands(t){l(this,W).addCommands(t)}cleanUndoStack(t){l(this,W).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,Ds).values())s.enableEditing(),s.show(!0),s.annotationElementId&&(l(this,W).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,W).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,Ds).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,W).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,W).addChangedExistingAnnotation(h),h.renderAnnotationElement(r)&&h.show(!1)),r.show()}}w(this,Et,ef).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const n of l(si,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,W).getActive()!==t&&l(this,W).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,W).combinedSignal(l(this,wn));l(this,Ce).div.addEventListener("pointerdown",w(this,Et,my).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,W).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,Ds).set(t.id,t);const{annotationElementId:e}=t;e&&l(this,W).isDeletedAnnotationElement(e)&&l(this,W).removeDeletedAnnotationElement(t)}detach(t){var e;l(this,Ds).delete(t.id),(e=l(this,No))==null||e.removePointerInTextLayer(t.contentDiv),!l(this,gh)&&t.annotationElementId&&l(this,W).addDeletedAnnotationElement(t)}remove(t){this.detach(t),l(this,W).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){var e;t.parent!==this&&(t.parent&&t.annotationElementId&&(l(this,W).addDeletedAnnotationElement(t.annotationElementId),Dt.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,W).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,W).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var s;if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!l(this,yn)&&(t._focusEventsAllowed=!1,m(this,yn,setTimeout(()=>{m(this,yn,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:l(this,W)._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,W).getId()}combinedSignal(t){return l(this,W).combinedSignal(t)}canCreateNewEmptyEditor(){var t;return(t=l(this,Et,Di))==null?void 0:t.canCreateNewEmptyEditor()}pasteEditor(t,e){l(this,W).updateToolbar(t),l(this,W).updateMode(t);const{offsetX:s,offsetY:i}=w(this,Et,Hp).call(this),n=this.getNextId(),r=w(this,Et,Bp).call(this,{parent:this,id:n,x:s,y:i,uiManager:l(this,W),isCentered:!0,...e});r&&this.add(r)}async deserialize(t){var e;return await((e=l(si,dr).get(t.annotationType??t.annotationEditorType))==null?void 0:e.deserialize(t,this,l(this,W)))||null}createAndAddNewEditor(t,e,s={}){const i=this.getNextId(),n=w(this,Et,Bp).call(this,{parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:l(this,W),isCentered:e,...s});return n&&this.add(n),n}addNewEditor(){this.createAndAddNewEditor(w(this,Et,Hp).call(this),!0)}setSelected(t){l(this,W).setSelected(t)}toggleSelected(t){l(this,W).toggleSelected(t)}unselect(t){l(this,W).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,Et,Di))!=null&&s.isDrawer&&l(this,Et,Di).supportMultipleDrawings))){if(!l(this,fh)){m(this,fh,!0);return}if(l(this,W).getMode()===tt.STAMP){l(this,W).unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){var i;if(l(this,W).getMode()===tt.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,Et,Di))!=null&&i.isDrawer){this.startDrawingSession(t);return}const s=l(this,W).getActive();m(this,fh,!s||s.isEmpty())}startDrawingSession(t){if(this.div.focus(),l(this,ei)){l(this,Et,Di).startDrawing(this,l(this,W),!1,t);return}l(this,W).setCurrentDrawingSession(this),m(this,ei,new AbortController);const e=l(this,W).combinedSignal(l(this,ei));this.div.addEventListener("blur",({relatedTarget:s})=>{s&&!this.div.contains(s)&&(m(this,_n,null),this.commitOrRemove())},{signal:e}),l(this,Et,Di).startDrawing(this,l(this,W),!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,ei)?(l(this,W).setCurrentDrawingSession(null),l(this,ei).abort(),m(this,ei,null),m(this,_n,null),l(this,Et,Di).endDrawing(t)):null}findNewParent(t,e,s){const i=l(this,W).findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}commitOrRemove(){return l(this,ei)?(this.endDrawingSession(),!0):!1}onScaleChanging(){l(this,ei)&&l(this,Et,Di).onScaleChangingWhenDrawing(this)}destroy(){var t,e;this.commitOrRemove(),((t=l(this,W).getActive())==null?void 0:t.parent)===this&&(l(this,W).commitOrRemove(),l(this,W).setActiveEditor(null)),l(this,yn)&&(clearTimeout(l(this,yn)),m(this,yn,null));for(const s of l(this,Ds).values())(e=l(this,No))==null||e.removePointerInTextLayer(s.contentDiv),s.setParent(null),s.isAttachedToDOM=!1,s.div.remove();this.div=null,l(this,Ds).clear(),l(this,W).removeLayer(this)}render({viewport:t}){this.viewport=t,kr(this.div,t);for(const e of l(this,W).getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){l(this,W).commitOrRemove(),w(this,Et,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,Ds).values())i.rotate(s)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return l(this,W).viewParameters.realScale}};No=new WeakMap,fh=new WeakMap,Ei=new WeakMap,cr=new WeakMap,yn=new WeakMap,Ds=new WeakMap,ur=new WeakMap,gh=new WeakMap,jo=new WeakMap,ei=new WeakMap,_n=new WeakMap,Ce=new WeakMap,wn=new WeakMap,W=new WeakMap,dr=new WeakMap,Et=new WeakSet,my=function(t){l(this,W).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,W).showAllEditors("highlight",!0,!0),l(this,Ce).div.classList.add("free"),this.toggleDrawing(),rd.startHighlighting(this,l(this,W).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,W)._signal}),t.preventDefault()}},Di=function(){return l(si,dr).get(l(this,W).getMode())},Bp=function(t){const e=l(this,Et,Di);return e?new e.prototype.constructor(t):null},Hp=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,Ds).values())t.isEmpty()&&t.remove()},q(si,"_initialized",!1),v(si,dr,new Map([Rg,jg,Bg,rd].map(t=>[t._editorType,t])));let Hg=si;const Ae=class Ae{constructor({pageIndex:t}){v(this,ki);v(this,ii,null);v(this,Sc,0);v(this,Be,new Map);v(this,Bo,new Map);this.pageIndex=t}setParent(t){if(!l(this,ii)){m(this,ii,t);return}if(l(this,ii)!==t){if(l(this,Be).size>0)for(const e of l(this,Be).values())e.remove(),t.append(e);m(this,ii,t)}}static get _svgFactory(){return nt(this,"_svgFactory",new Pg)}draw(t,e=!1,s=!1){const i=ze(this,Sc)._++,n=w(this,ki,zp).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,vy).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,zp).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,Gp).call(this,o,s),i&&w(h=Ae,Ad,by).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,Gp).call(this,u,r)}}}updateParent(t,e){if(e===this)return;const s=l(this,Be).get(t);s&&(l(e,ii).append(s),l(this,Be).delete(t),l(e,Be).set(t,s))}remove(t){l(this,Bo).delete(t),l(this,ii)!==null&&(l(this,Be).get(t).remove(),l(this,Be).delete(t))}destroy(){m(this,ii,null);for(const t of l(this,Be).values())t.remove();l(this,Be).clear(),l(this,Bo).clear()}};ii=new WeakMap,Sc=new WeakMap,Be=new WeakMap,Bo=new WeakMap,Ad=new WeakSet,by=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,zp=function(){const t=Ae._svgFactory.create(1,1,!0);return l(this,ii).append(t),t.setAttribute("aria-hidden",!0),t},vy=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},Gp=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},Q.AbortException,Q.AnnotationEditorLayer,Q.AnnotationEditorParamsType,Q.AnnotationEditorType,Q.AnnotationEditorUIManager,Q.AnnotationLayer,Q.AnnotationMode,Q.ColorPicker,Q.DOMSVGFactory,Q.DrawLayer,Q.FeatureTest;var US=Q.GlobalWorkerOptions;Q.ImageKind,Q.InvalidPDFException,Q.MissingPDFException,Q.OPS,Q.OutputScale,Q.PDFDataRangeTransport,Q.PDFDateString,Q.PDFWorker,Q.PasswordResponses,Q.PermissionFlag,Q.PixelsPerInch,Q.RenderingCancelledException,Q.TextLayer,Q.TouchManager,Q.UnexpectedResponseException,Q.Util,Q.VerbosityLevel,Q.XfaLayer,Q.build,Q.createValidAbsoluteUrl,Q.fetchData;var YS=Q.getDocument;Q.getFilenameFromUrl,Q.getPdfFilenameFromUrl,Q.getXfaPageViewport,Q.isDataScheme,Q.isPdfFile,Q.noContextMenu,Q.normalizeUnicode,Q.setLayerDimensions,Q.shadow,Q.stopEvent,Q.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}function ZS(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 tC(i))}),i.addEventListener("error",n=>{window.URL.revokeObjectURL(s),e(n)})})}function tC(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 Bb=null;function eC(){const a=document.createElement("div");a.style.width="1in",document.body.append(a);const t=a.offsetWidth;return a.remove(),t}function sC(){const a=Bb??eC();return Bb=a,a/72}function iC(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 $e=new Map;function nC(a){const t=new Wf(a);return $e.set(a,t),t}function rC(a,t){const e=Date.now();return{PDFId:`${a.name}-${e}`,name:a.name.replace(/.pdf/,""),updateDate:e,PDFBase64:t}}function oC(a,t){const e=a.getViewport({scale:t}),s=document.createElement("canvas"),i=s.getContext("2d"),n=sC()/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 aC({src:a},t,e){if(!a||!e)return null;const{objects:s,options:i}=await Iw(a),n=s.filter(o=>o!==null),r=K_.groupSVGElements(n,i);return n.forEach(o=>{o.stroke=e}),r.hoverCursor="pointer",r.stroke=`${e}-${t}`,r}function hC(a,t){if(!$e.get(a))return;const s=1/3,i=pC(t,s);zb(a,i,s)}async function lC(a,t){const e=await ZS(t),s=Date.now(),n={PDFId:`${t.name}${s}`,name:t.name.replace(/.png|.jpg|.jpeg/,""),updateDate:s,PDFBase64:e};return Hb(a,{url:e}),{...n,pages:1}}async function Hb(a,{url:t,scale:e=.5}){if(!$e.get(a))return;const i=await be.fromURL(t);i.scale(e),zb(a,i,e)}function zb(a,t,e){const s=$e.get(a);s&&(s.setWidth(t.width*e),s.setHeight(t.height*e),s.backgroundImage=t,s.renderAll())}function cC(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 uC(a,t,e){!e||!a||(e.scale(1/t),cC(a,e))}function dC(a,t){if(!a)return;const e=a._cornerSize||6;a.borderScaleFactor=1/t,a.cornerSize=e*(1/t),a.touchCornerSize=e*4*(1/t),a.setCoords()}function fC(a){const t=$e.get(a);t&&(t.discardActiveObject(),t.renderAll())}function gC(a){const t=$e.get(a);t&&(t.clear(),$e.delete(a))}function pC(a,t){return new be(a,{scaleX:t,scaleY:t})}function Gg(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":mC,"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 mC(a,t,e){const s=await QS(a);if(!s)return;const i=rC(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}=oC(r,e);return o.promise.then(()=>(i&&hC(i,h),n.numPages))}catch(n){return Promise.reject(n)}}async function Xb(a,t,e){if(e)return await lC(e,a)}const bC="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",vC={top:100,left:50,scaleX:.5,scaleY:.5,borderColor:"black",cornerStrokeColor:"black",cornerSize:6,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},yC={top:100,left:50,fontFamily:"helvetica",borderColor:"black",cornerStrokeColor:"black",scaleX:.7,scaleY:.7,cornerSize:6,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},_C={borderColor:"black",cornerStrokeColor:"black",cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},wC={stroke:"#000",hoverStroke:"#B7EC5D",src:bC},xC=["borderColor","cornerStrokeColor","cornerSize","selectionBackgroundColor"];function Wb(a){const{id:t="",selectionOptions:e,pointerDown:s,pointerMove:i,pointerUp:n,selectionCreated:r,selectionCleared:o}=a||{};let h=null,c=null,u=1,d={...wC};function f(){if(!t||$e.has(t))return;const O=nC(t);return O.on("selection:created",L=>{if(r==null||r(L),L.selected.length<=1)return;const N=O.getActiveObject();N&&(c=N,e!=null&&e.value&&c.set(e.value),c._cornerSize=c.cornerSize,E(u))}),O.on("selection:cleared",L=>{o==null||o(L),k(O)}),s&&O.on("mouse:down",s),i&&O.on("mouse:move",i),n&&O.on("mouse:up",n),O}function g(O,L){return Gb(O,L,t)}function p(O){return Vb(O,t)}function b({url:O,scale:L=.5}){return Hb(t,{url:O,scale:L})}async function _(O,L,N){const Y=$e.get(t);if(!Y)return;const I=await be.fromURL(O,{},{...vC,...L});Gg(I,N),Y.add(I),x(Y,I),Y.setActiveObject(I)}function y(O,L,N){const Y=$e.get(t);if(!Y)return;const I=new me(O,{...yC,...L});Gg(I,N),Y.add(I),x(Y,I),Y.setActiveObject(I)}function x(O,L){L.on("selected",N=>S({canvas:O,target:N.target})),L.on("modified",N=>S({canvas:O,target:N.target})),L.on("scaling",()=>k(O)),L.on("moving",()=>k(O)),L.on("rotating",()=>k(O)),L._cornerSize=L.cornerSize}async function S({canvas:O,target:L,stroke:N=d.stroke,uuid:Y=Date.now()}){if(O.getActiveObjects().length>1||(h==null?void 0:h.stroke)===`${N}-${Y}`)return;const H=await aC(d,Y,N);k(O),h=H,c=L,C(O,L,Y),E(u,!0),H&&O.add(H)}function C(O,L,N){h&&(h.on("selected",()=>{O.remove(L),k(O)}),h.on("mouseover",()=>{S({canvas:O,target:L,stroke:d.hoverStroke,uuid:N})}),h.on("mouseout",()=>{S({canvas:O,target:L,stroke:d.stroke,uuid:N})}))}function E(O,L=!1){const N=$e.get(t);u=O,N&&(dC(c,O),uC(c,O,h),!L&&N.renderAll())}function P(O){if(!O)return;d={...d,...O};const L=$e.get(t);!h||!c||!L||S({target:c,canvas:L})}function k(O){c=null,h&&(O.remove(h),h=null)}function D(){fC(t)}function R(){gC(t)}async function F(){const O=$e.get(t);if(!O)return;const L=O==null?void 0:O.getActiveObject();if(!L)return;const N=await L.clone(xC);N instanceof ys?N.forEachObject(Y=>{O.add(Y),x(O,Y)}):(O.add(N),x(O,N)),Gg(N,{x:-.1,y:-.1}),O.setActiveObject(N)}function j(){const O=$e.get(t);if(!O)return;const L=O.getActiveObject();L&&(L instanceof ys?(L.forEachObject(N=>{O.remove(N)}),O.discardActiveObject()):O.remove(L))}return{createCanvas:f,loadFile:g,specifyPage:p,renderImage:b,addFabric:_,addTextFabric:y,clearActive:D,deleteCanvas:R,scaleFabric:E,setCloseSvgOptions:P,copyActiveFabric:F,deleteActiveFabric:j}}function SC(a){let t=0;const e=iC(()=>{t!==window.innerWidth&&(t=window.innerWidth,a())});K.onMounted(()=>{window.addEventListener("resize",e)}),K.onBeforeUnmount(()=>{window.removeEventListener("resize",e)})}const CC=K.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:{},closeSvgOptions:{},manualReload:{type:Boolean},onDestroy:{type:Function,default:K.onBeforeUnmount}},emits:["loaded","reload","pointerDown","pointerMove","pointerUp","selectionCreated","selectionCleared"],setup(a,{expose:t,emit:e}){const s=a,i=e,{onDestroy:n}=s,r=K.ref(null),o=`${s.canvasId}-${s.page-1}`,h=K.computed(()=>s.fileZoom*s.canvasScale),c=K.computed(()=>({..._C,...s.selectionOptions})),{createCanvas:u,specifyPage:d,addFabric:f,addTextFabric:g,renderImage:p,clearActive:b,deleteCanvas:_,scaleFabric:y,setCloseSvgOptions:x,copyActiveFabric:S,deleteActiveFabric:C}=Wb({id:o,selectionOptions:c,pointerDown:F=>i("pointerDown",F),pointerMove:F=>i("pointerMove",F),pointerUp:F=>i("pointerUp",F),selectionCreated:F=>i("selectionCreated",F),selectionCleared:F=>i("selectionCleared",F)});E(),SC(R);async function E(){const{file:F,page:j,fileScale:O}=s;window.requestAnimationFrame(async()=>{if(await K.nextTick(),u(),F.PDFBase64.startsWith("data:image")||F.canvas){const{canvas:L}=F,N=L?7:3,Y=L!=null&&L.length?L[j-1]:F.PDFBase64;p({url:Y,scale:O/N}),i("loaded");return}await d({page:j,PDFBase64:F.PDFBase64,scale:O,password:s.password}),i("loaded")})}function P(F){if(!s.isDrop||!F.dataTransfer)return;const{dataTransfer:j,offsetX:O,offsetY:L}=F,N=j.getData("text/plain"),Y=j.getData("text/uri-list"),I=j.getData("custom/offset"),H=I?JSON.parse(I):null,it={top:L,left:O},kt={x:(H==null?void 0:H.offsetX)??0,y:(H==null?void 0:H.offsetY)??0};Y?k(Y,it,kt):N&&D(N,it,kt)}function k(F,j,O){f(F,{...s.dropImageOptions,...j},O)}function D(F,j,O){g(F,{...s.dropTextOptions,...j},O)}function R(){s.manualReload||E(),i("reload")}return K.watch([()=>s.fileScale,()=>s.page,()=>s.file,()=>s.password],R),K.watch(h,F=>y(F),{immediate:!0}),K.watch(()=>s.closeSvgOptions,x,{immediate:!0}),n(_),t({reload:E,addImage:k,addText:D,clearActive:b,deleteCanvas:_,copyActiveFabric:S,deleteActiveFabric:C,canvasRef:r}),(F,j)=>(K.openBlock(),K.createElementBlock("div",{style:K.normalizeStyle({transform:`scale(${h.value})`}),onDragover:j[0]||(j[0]=K.withModifiers(()=>{},["prevent"])),onDragenter:j[1]||(j[1]=K.withModifiers(()=>{},["prevent"])),onDrop:K.withModifiers(P,["stop","prevent"])},[K.createElementVNode("canvas",{id:o,ref_key:"canvasRef",ref:r,class:K.normalizeClass(F.canvasClass)},null,2)],36))}});ot.default=CC,ot.loadFile=Gb,ot.useFabric=Wb,Object.defineProperties(ot,{__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)}},Gv=function(){return l(this,ls).replaceAll(" "," ")},Ep=function(e){return e.replaceAll(" "," ")},Vv=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(_t,fn),q(_t,"_freeTextDefaultContent",""),q(_t,"_internalPadding",0),q(_t,"_defaultColor",null),q(_t,"_defaultFontSize",10),q(_t,"_type","freetext"),q(_t,"_editorType",tt.FREETEXT);let Rg=_t;class V{toSVGPath(){yt("Abstract method `toSVGPath` must be implemented.")}get box(){yt("Abstract getter `box` must be implemented.")}serialize(t,e){yt("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]}}q(V,"PRECISION",1e-4);const gn=class gn{constructor({x:t,y:e},s,i,n,r,o=0){v(this,Jt);v(this,us);v(this,Qs,[]);v(this,Xa);v(this,Wa);v(this,wi,[]);v(this,rt,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,us,s),m(this,Ya,n*i),m(this,Wa,r),l(this,rt).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,rt)[8])}add({x:t,y:e}){var R;m(this,So,t),m(this,Co,e);const[s,i,n,r]=l(this,us);let[o,h,c,u]=l(this,rt).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,(R=l(this,sr))==null||R.push(t,e);const C=-y/p,E=_/p,P=C*l(this,Ya),k=E*l(this,Ya);return l(this,rt).set(l(this,rt).subarray(2,8),0),l(this,rt).set([c+P,u+k],4),l(this,rt).set(l(this,rt).subarray(14,18),12),l(this,rt).set([c-P,u-k],16),isNaN(l(this,rt)[6])?(l(this,wi).length===0&&(l(this,rt).set([o+P,h+k],2),l(this,wi).push(NaN,NaN,NaN,NaN,(o+P-s)/n,(h+k-i)/r),l(this,rt).set([o-P,h-k],14),l(this,Qs).push(NaN,NaN,NaN,NaN,(o-P-s)/n,(h-k-i)/r)),l(this,rt).set([x,S,o,h,c,u],6),!this.isEmpty()):(l(this,rt).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,rt).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,rt).subarray(14,18),l(this,Qs).push(NaN,NaN,NaN,NaN,((x+o)/2-s)/n,((S+h)/2-i)/r),!0):([x,S,o,h,c,u]=l(this,rt).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,rt).subarray(12,18),l(this,Qs).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,Qs);if(isNaN(l(this,rt)[6])&&!this.isEmpty())return w(this,Jt,Xv).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,Uv).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,Wv).call(this,s),s.join(" ")}newFreeDrawOutline(t,e,s,i,n,r){return new jb(t,e,s,i,n,r)}getOutlines(){var d;const t=l(this,wi),e=l(this,Qs),s=l(this,rt),[i,n,r,o]=l(this,us),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,Yv).call(this,h);const c=new Float32Array(l(this,wi).length+24+l(this,Qs).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,qv).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,$v).call(this,c,u),this.newFreeDrawOutline(c,h,l(this,us),l(this,Ua),l(this,Xa),l(this,Wa))}};us=new WeakMap,Qs=new WeakMap,Xa=new WeakMap,Wa=new WeakMap,wi=new WeakMap,rt=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,rt).subarray(4,6),e=l(this,rt).subarray(16,18),[s,i,n,r]=l(this,us);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]},Xv=function(){const[t,e,s,i]=l(this,us),[n,r,o,h]=w(this,Jt,Oc).call(this);return`M${(l(this,rt)[2]-t)/s} ${(l(this,rt)[3]-e)/i} L${(l(this,rt)[4]-t)/s} ${(l(this,rt)[5]-e)/i} L${n} ${r} L${o} ${h} L${(l(this,rt)[16]-t)/s} ${(l(this,rt)[17]-e)/i} L${(l(this,rt)[14]-t)/s} ${(l(this,rt)[15]-e)/i} Z`},Wv=function(t){const e=l(this,Qs);t.push(`L${e[4]} ${e[5]} Z`)},Uv=function(t){const[e,s,i,n]=l(this,us),r=l(this,rt).subarray(4,6),o=l(this,rt).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}`)},Yv=function(t){const e=l(this,rt),[s,i,n,r]=l(this,us),[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,us),l(this,Ua),l(this,Xa),l(this,Wa))},$v=function(t,e){const s=l(this,Qs);return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6},qv=function(t,e){const s=l(this,rt).subarray(4,6),i=l(this,rt).subarray(16,18),[n,r,o,h]=l(this,us),[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 jb extends V{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,ds);v(this,hc);v(this,zt);m(this,zt,e),m(this,ds,s),m(this,$a,i),m(this,hc,n),m(this,pn,r),m(this,ac,o),this.lastPoint=[NaN,NaN],w(this,Sd,Kv).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,zt)[4]} ${l(this,zt)[5]}`];for(let s=6,i=l(this,zt).length;s<i;s+=6){if(isNaN(l(this,zt)[s])){e.push(`L${l(this,zt)[s+4]} ${l(this,zt)[s+5]}`);continue}e.push(`C${l(this,zt)[s]} ${l(this,zt)[s+1]} ${l(this,zt)[s+2]} ${l(this,zt)[s+3]} ${l(this,zt)[s+4]} ${l(this,zt)[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=V._rescale(l(this,zt),e,n,o,-h),u=V._rescale(l(this,ds),e,n,o,-h);break;case 90:c=V._rescaleAndSwap(l(this,zt),e,s,o,h),u=V._rescaleAndSwap(l(this,ds),e,s,o,h);break;case 180:c=V._rescale(l(this,zt),i,s,-o,h),u=V._rescale(l(this,ds),i,s,-o,h);break;case 270:c=V._rescaleAndSwap(l(this,zt),i,n,-o,-h),u=V._rescaleAndSwap(l(this,ds),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,ds)[0]*f+p,y:l(this,ds)[1]*g+b},l(this,$a),l(this,hc),e,l(this,ac),s??l(this,pn));for(let y=2;y<l(this,ds).length;y+=2)_.add({x:l(this,ds)[y]*f+p,y:l(this,ds)[y+1]*g+b});return _.getOutlines()}}$a=new WeakMap,Ao=new WeakMap,pn=new WeakMap,ac=new WeakMap,ds=new WeakMap,hc=new WeakMap,zt=new WeakMap,Sd=new WeakSet,Kv=function(e){const s=l(this,zt);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,Js,[]);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,P=Math.floor((y-e)/c)*c,k=Math.ceil((y+S+e)/c)*c,D=[C,P,k,!0],R=[E,P,k,!1];l(this,ir).push(D,R),n=Math.min(n,C),r=Math.max(r,E),o=Math.min(o,P),h=Math.max(h,k)}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,kp).call(this,e)),w(this,Ie,Jv).call(this,e)):(w(this,Ie,Zv).call(this,e),t.push(...w(this,Ie,kp).call(this,e)));return w(this,Ie,Qv).call(this,t)}}lc=new WeakMap,cc=new WeakMap,ir=new WeakMap,Js=new WeakMap,Ie=new WeakSet,Qv=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,Js);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},Jv=function([,t,e]){const s=w(this,Ie,Yd).call(this,t);l(this,Js).splice(s,0,[t,e])},Zv=function([,t,e]){const s=w(this,Ie,Yd).call(this,t);for(let i=s;i<l(this,Js).length;i++){const[n,r]=l(this,Js)[i];if(n!==t)break;if(n===t&&r===e){l(this,Js).splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=l(this,Js)[i];if(n!==t)break;if(n===t&&r===e){l(this,Js).splice(i,1);return}}},kp=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,Js)[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 V{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 jb{newOutliner(t,e,s,i,n,r=0){return new Fg(t,e,s,i,n,r)}}const Qe=class Qe{constructor({editor:t=null,uiManager:e=null}){v(this,vt);v(this,Zs,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,ti,null);v(this,Ja);var s;t?(m(this,Qa,!1),m(this,Ja,at.HIGHLIGHT_COLOR),m(this,fc,t)):(m(this,Qa,!0),m(this,Ja,at.HIGHLIGHT_DEFAULT_COLOR)),m(this,ti,(t==null?void 0:t._uiManager)||e),m(this,gc,l(this,ti)._eventBus),m(this,Ka,(t==null?void 0:t.color)||((s=l(this,ti))==null?void 0:s.highlightColors.values().next().value)||"#FFFF98"),l(Qe,pc)||m(Qe,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 nt(this,"_keyboardManager",new Xh([[["Escape","mac+Escape"],Qe.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],Qe.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],Qe.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],Qe.prototype._moveToPrevious],[["Home","mac+Home"],Qe.prototype._moveToBeginning],[["End","mac+End"],Qe.prototype._moveToEnd]]))}renderButton(){const t=m(this,Zs,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,ti)._signal;t.addEventListener("click",w(this,vt,zo).bind(this),{signal:e}),t.addEventListener("keydown",w(this,vt,Dp).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,vt,Mp).call(this));return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}_colorSelectFromKeyboard(t){if(t.target===l(this,Zs)){w(this,vt,zo).call(this,t);return}const e=t.target.getAttribute("data-color");e&&w(this,vt,Pp).call(this,e,t)}_moveToNext(t){var e,s;if(!l(this,vt,gr)){w(this,vt,zo).call(this,t);return}if(t.target===l(this,Zs)){(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,Zs)){l(this,vt,gr)&&this._hideDropdownFromKeyboard();return}l(this,vt,gr)||w(this,vt,zo).call(this,t),(s=t.target.previousSibling)==null||s.focus()}_moveToBeginning(t){var e;if(!l(this,vt,gr)){w(this,vt,zo).call(this,t);return}(e=l(this,Zt).firstChild)==null||e.focus()}_moveToEnd(t){var e;if(!l(this,vt,gr)){w(this,vt,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,vt,gr)){(t=l(this,fc))==null||t.unselect();return}this.hideDropdown(),l(this,Zs).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,ti).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,Zs))==null||t.remove(),m(this,Zs,null),m(this,To,null),(e=l(this,Zt))==null||e.remove(),m(this,Zt,null)}};Zs=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,ti=new WeakMap,Ja=new WeakMap,pc=new WeakMap,vt=new WeakSet,Mp=function(){const t=document.createElement("div"),e=l(this,ti)._signal;t.addEventListener("contextmenu",Gs,{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,ti).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(Qe,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,vt,Pp).bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",w(this,vt,Dp).bind(this),{signal:e}),t},Pp=function(t,e){e.stopPropagation(),l(this,gc).dispatch("switchannotationeditorparams",{source:this,type:l(this,Ja),value:t})},Dp=function(t){Qe._keyboardManager.exec(this,t)},zo=function(t){if(l(this,vt,gr)){this.hideDropdown();return}if(m(this,dc,t.detail===0),l(this,nr)||(m(this,nr,new AbortController),window.addEventListener("pointerdown",w(this,vt,ty).bind(this),{signal:l(this,ti).combinedSignal(l(this,nr))})),l(this,Zt)){l(this,Zt).classList.remove("hidden");return}const e=m(this,Zt,w(this,vt,Mp).call(this));l(this,Zs).append(e)},ty=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(Qe,pc,null);let nd=Qe;const ut=class ut extends Dt{constructor(e){super({...e,name:"highlightEditor"});v(this,Z);v(this,Za,null);v(this,mc,0);v(this,mn);v(this,Eo,null);v(this,th,null);v(this,Je,null);v(this,bc,null);v(this,vc,0);v(this,ko,null);v(this,Es,null);v(this,fs,null);v(this,le,!1);v(this,eh,null);v(this,bn);v(this,Se,null);v(this,sh,"");v(this,ks);v(this,yc,"");this.color=e.color||ut._defaultColor,m(this,ks,e.thickness||ut._defaultThickness),m(this,bn,e.opacity||ut._defaultOpacity),m(this,mn,e.boxes||null),m(this,yc,e.methodOfCreation||""),m(this,sh,e.text||""),this._isDraggable=!1,e.highlightId>-1?(m(this,le,!0),w(this,Z,$d).call(this,e),w(this,Z,Go).call(this)):l(this,mn)&&(m(this,Za,e.anchorNode),m(this,mc,e.anchorOffset),m(this,bc,e.focusNode),m(this,vc,e.focusOffset),w(this,Z,Op).call(this),w(this,Z,Go).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const e=ut.prototype;return nt(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,ks),methodOfCreation:l(this,yc)}}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;Dt.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 at.HIGHLIGHT_DEFAULT_COLOR:ut._defaultColor=s;break;case at.HIGHLIGHT_THICKNESS:ut._defaultThickness=s;break}}translateInPage(e,s){}get toolbarPosition(){return l(this,eh)}updateParams(e,s){switch(e){case at.HIGHLIGHT_COLOR:w(this,Z,ey).call(this,s);break;case at.HIGHLIGHT_THICKNESS:w(this,Z,sy).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[at.HIGHLIGHT_DEFAULT_COLOR,ut._defaultColor],[at.HIGHLIGHT_THICKNESS,ut._defaultThickness]]}get propertiesToUpdate(){return[[at.HIGHLIGHT_COLOR,this.color||ut._defaultColor],[at.HIGHLIGHT_THICKNESS,l(this,ks)||ut._defaultThickness],[at.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,Z,Rc).call(this))}getBaseTranslation(){return[0,0]}getRect(e,s){return super.getRect(e,s,w(this,Z,Rc).call(this))}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),e&&this.div.focus()}remove(){w(this,Z,Rp).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,Z,Go).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?w(this,Z,Rp).call(this):e&&(w(this,Z,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,Ms,_h).call(n,l(this,Es).box,e)):i=w(r=ut,Ms,_h).call(r,[this.x,this.y,this.width,this.height],e),s.updateProperties(l(this,fs),{bbox:i,root:{"data-main-rotation":e}}),s.updateProperties(l(this,Se),{bbox:w(o=ut,Ms,_h).call(o,l(this,Je).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,Z,ny).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,Z,qd).call(this,!0);break;case 1:case 3:w(this,Z,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,Z,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,fs),{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,Ms,hy).call(this,e,p)};window.addEventListener("blur",g,{signal:f}),window.addEventListener("pointerup",g,{signal:f}),window.addEventListener("pointerdown",ss,{capture:!0,passive:!1,signal:f}),window.addEventListener("contextmenu",Gs,{signal:f}),i.addEventListener("pointermove",w(this,Ms,ay).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 Ib){const{data:{quadPoints:S,rect:C,rotation:E,id:P,color:k,opacity:D,popupRef:R},parent:{page:{pageNumber:F}}}=e;n=e={annotationType:tt.HIGHLIGHT,color:Array.from(k),opacity:D,quadPoints:S,boxes:null,pageIndex:F-1,rect:C.slice(0),rotation:E,id:P,deleted:!1,popupRef:R}}else if(e instanceof Og){const{data:{inkLists:S,rect:C,rotation:E,id:P,color:k,borderStyle:{rawWidth:D},popupRef:R},parent:{page:{pageNumber:F}}}=e;n=e={annotationType:tt.HIGHLIGHT,color:Array.from(k),thickness:D,inkLists:S,boxes:null,pageIndex:F-1,rect:C.slice(0),rotation:E,id:P,deleted:!1,popupRef:R}}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,ks,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,Z,Op).call(b),w(_=u,Z,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,ks)/2,!0,.001);for(let D=0,R=S.length;D<R;D+=2)C.x=S[D]-g,C.y=f-(S[D+1]-p),E.add(C);const{id:P,clipPathId:k}=s.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:u.color,"fill-opacity":u._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:E.toSVGPath()}},!0,!0);w(y=u,Z,$d).call(y,{highlightOutlines:E.getOutlines(),highlightId:P,clipPathId:k}),w(x=u,Z,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=Dt._colorManager.convert(this.color),n={annotationType:tt.HIGHLIGHT,color:i,opacity:l(this,bn),thickness:l(this,ks),quadPoints:w(this,Z,ry).call(this),outlines:w(this,Z,oy).call(this,s),pageIndex:this.pageIndex,rect:s,rotation:w(this,Z,Rc).call(this),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!w(this,Z,ly).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,Je=new WeakMap,bc=new WeakMap,vc=new WeakMap,ko=new WeakMap,Es=new WeakMap,fs=new WeakMap,le=new WeakMap,eh=new WeakMap,bn=new WeakMap,Se=new WeakMap,sh=new WeakMap,ks=new WeakMap,yc=new WeakMap,Z=new WeakSet,Op=function(){const e=new Lg(l(this,mn),.001);m(this,Es,e.getOutlines()),[this.x,this.y,this.width,this.height]=l(this,Es).box;const s=new Lg(l(this,mn),.0025,.001,this._uiManager.direction==="ltr");m(this,Je,s.getOutlines());const{lastPoint:i}=l(this,Je);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,Es,e),m(this,Je,e.getNewOutline(l(this,ks)/2+1.5,.0025)),s>=0)m(this,fs,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,Je).box,path:{d:l(this,Je).toSVGPath()}},!0));else if(this.parent){const g=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(l(this,fs),{bbox:w(d=ut,Ms,_h).call(d,l(this,Es).box,(g-this.rotation+360)%360),path:{d:e.toSVGPath()}}),this.parent.drawLayer.updateProperties(l(this,Se),{bbox:w(f=ut,Ms,_h).call(f,l(this,Je).box,g),path:{d:l(this,Je).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,Je);m(this,eh,[(u[0]-r)/h,(u[1]-o)/c])},ey=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,fs),{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:at.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(e)},!0)},sy=function(e){const s=l(this,ks),i=n=>{m(this,ks,n),w(this,Z,iy).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:at.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)},iy=function(e){if(!l(this,le))return;w(this,Z,$d).call(this,{highlightOutlines:l(this,Es).getNewOutline(e/2)}),this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)},Rp=function(){l(this,fs)===null||!this.parent||(this.parent.drawLayer.remove(l(this,fs)),m(this,fs,null),this.parent.drawLayer.remove(l(this,Se)),m(this,Se,null))},Go=function(e=this.parent){l(this,fs)===null&&({id:ze(this,fs)._,clipPathId:ze(this,Eo)._}=e.drawLayer.draw({bbox:l(this,Es).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,Es).toSVGPath()}},!1,!0),m(this,Se,e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:l(this,le)},bbox:l(this,Je).box,path:{d:l(this,Je).toSVGPath()}},l(this,le))),l(this,ko)&&(l(this,ko).style.clipPath=l(this,Eo)))},Ms=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]},ny=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,vc))},Rc=function(){return l(this,le)?this.rotation:0},ry=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},oy=function(e){return l(this,Es).serialize(e,w(this,Z,Rc).call(this))},ay=function(e,s){this._freeHighlight.add(s)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})},hy=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=""},ly=function(e){const{color:s}=this._initialData;return e.color.some((i,n)=>i!==s[n])},v(ut,Ms),q(ut,"_defaultColor",null),q(ut,"_defaultOpacity",1),q(ut,"_defaultThickness",12),q(ut,"_type","highlight"),q(ut,"_editorType",tt.HIGHLIGHT),q(ut,"_freeHighlightId",-1),q(ut,"_freeHighlight",null),q(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(){yt("Not implemented")}}Mo=new WeakMap;const X=class X extends Dt{constructor(e){super(e);v(this,lt);v(this,gs,null);v(this,ih);q(this,"_drawId",null);m(this,ih,e.mustBeCommitted||!1),e.drawOutlines&&(w(this,lt,Lp).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){yt("Not implemented")}static get typesMap(){yt("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(X,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,gs).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,X._mergeSVGProperties(l(this,gs).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,X._mergeSVGProperties(l(this,gs).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,X._mergeSVGProperties(l(this,gs).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,Ip).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,gs).box),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?(this._uiManager.removeShouldRescale(this),w(this,lt,Ip).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,X._mergeSVGProperties({bbox:w(this,lt,wh).call(this)},l(this,gs).updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&w(this,lt,Fc).call(this,l(this,gs).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){yt("Not implemented")}static startDrawing(e,s,i,n){var _;const{target:r,offsetX:o,offsetY:h,pointerId:c,pointerType:u}=n;if(l(X,or)&&l(X,or)!==u)return;const{viewport:{rotation:d}}=e,{width:f,height:g}=r.getBoundingClientRect(),p=m(X,Po,new AbortController),b=e.combinedSignal(p);if(l(X,rr)||m(X,rr,c),l(X,or)??m(X,or,u),window.addEventListener("pointerup",y=>{var x;l(X,rr)===y.pointerId?this._endDraw(y):(x=l(X,ar))==null||x.delete(y.pointerId)},{signal:b}),window.addEventListener("pointercancel",y=>{var x;l(X,rr)===y.pointerId?this._currentParent.endDrawingSession():(x=l(X,ar))==null||x.delete(y.pointerId)},{signal:b}),window.addEventListener("pointerdown",y=>{l(X,or)===y.pointerType&&((l(X,ar)||m(X,ar,new Set)).add(y.pointerId),l(X,ne).isCancellable()&&(l(X,ne).removeLastElement(),l(X,ne).isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:b}),window.addEventListener("contextmenu",Gs,{signal:b}),r.addEventListener("pointermove",this._drawMove.bind(this),{signal:b}),r.addEventListener("touchmove",y=>{y.timeStamp===l(X,Oo)&&ss(y)},{signal:b}),e.toggleDrawing(),(_=s._editorUndoBar)==null||_.hide(),l(X,ne)){e.drawLayer.updateProperties(this._currentDrawId,l(X,ne).startNew(o,h,f,g,d));return}s.updateUIForDefaultProperties(this),m(X,ne,this.createDrawerInstance(o,h,f,g,d)),m(X,Do,this.getDefaultDrawingOptions()),this._currentParent=e,{id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties(l(X,Do).toSVGProperties(),l(X,ne).defaultSVGProperties),!0,!1)}static _drawMove(e){var r;if(m(X,Oo,-1),!l(X,ne))return;const{offsetX:s,offsetY:i,pointerId:n}=e;if(l(X,rr)===n){if(((r=l(X,ar))==null?void 0:r.size)>=1){this._endDraw(e);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,l(X,ne).add(s,i)),m(X,Oo,e.timeStamp),ss(e)}}static _cleanup(e){e&&(this._currentDrawId=-1,this._currentParent=null,m(X,ne,null),m(X,Do,null),m(X,or,null),m(X,Oo,NaN)),l(X,Po)&&(l(X,Po).abort(),m(X,Po,null),m(X,rr,NaN),m(X,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(X,ne).end(e.offsetX,e.offsetY)),this.supportMultipleDrawings){const i=l(X,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:at.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(e){const s=this._currentParent;if(!s)return null;if(s.toggleDrawing(!0),s.cleanUndoStack(at.DRAW_STEP),!l(X,ne).isEmpty()){const{pageDimensions:[i,n],scale:r}=s,o=s.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:l(X,ne).getOutlines(i*r,n*r,r,this._INNER_MARGIN),drawingOptions:l(X,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){yt("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,Lp).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,gs).serialize([s,i,n,r],e)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};gs=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,Lp=function({drawOutlines:e,drawId:s,drawingOptions:i}){m(this,gs,e),this._drawingOptions||(this._drawingOptions=i),s>=0?(this._drawId=s,this.parent.drawLayer.finalizeDraw(s,e.defaultProperties)):this._drawId=w(this,lt,Fp).call(this,e,this.parent),w(this,lt,Fc).call(this,e.box)},Fp=function(e,s){const{id:i}=s.drawLayer.draw(X._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return i},Ip=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,Fp).call(this,l(this,gs),e)}},cy=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,cy).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]}},q(X,"_currentDrawId",-1),q(X,"_currentParent",null),v(X,ne,null),v(X,Po,null),v(X,Do,null),v(X,rr,NaN),v(X,or,null),v(X,ar,null),v(X,Oo,NaN),q(X,"_INNER_MARGIN",3);let Ig=X;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,Ps,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(...V.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,Ps,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,Ps,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,Ps,0),this.toSVGPath()}return{path:{d:l(this,ce)}}}toSVGPath(){const t=V.svgRound(l(this,re)[4]),e=V.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,Ps,6)}if(l(this,Ne).length===4){const i=V.svgRound(l(this,re)[10]),n=V.svgRound(l(this,re)[11]);return m(this,ce,`${l(this,ce)} L ${i} ${n}`),m(this,Ps,12),l(this,ce)}const s=[];l(this,Ps)===0&&(s.push(`M ${t} ${e}`),m(this,Ps,6));for(let i=l(this,Ps),n=l(this,re).length;i<n;i+=6){const[r,o,h,c,u,d]=l(this,re).slice(i,i+6).map(V.svgRound);s.push(`C${r} ${o} ${h} ${c} ${u} ${d}`)}return m(this,ce,l(this,ce)+s.join(" ")),m(this,Ps,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,Ps=new WeakMap,Lo=new WeakMap,Fo=new WeakMap,Io=new WeakMap,rh=new WeakSet,Qd=function(t,e){return V._normalizePoint(t,e,l(this,Fo),l(this,Io),l(this,Ro))};const Yg=class Yg extends V{constructor(){super(...arguments);v(this,ue);v(this,je);v(this,_c,0);v(this,wc);v(this,ps);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,ps,e),w(this,ue,dy).call(this)}setLastElement(e){return l(this,ps).push(e),{path:{d:this.toSVGPath()}}}removeLastElement(){return l(this,ps).pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const e=[];for(const{line:s}of l(this,ps)){if(e.push(`M${V.svgRound(s[4])} ${V.svgRound(s[5])}`),s.length===6){e.push("Z");continue}if(s.length===12){e.push(`L${V.svgRound(s[10])} ${V.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(V.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,uy).call(this);let g,p,b,_,y,x,S,C,E;switch(l(this,ah)){case 0:E=V._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=V._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=V._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=V._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:P,points:k}of l(this,ps))o.push(E(P,g,p,b,_,r?new Array(P.length):null)),h.push(E(k,g,p,b,_,r?new Array(k.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:_=V._rescale,f=-e/i,g=s/n+1,p=1/i,b=-1/n;break;case 90:_=V._rescaleAndSwap,f=-s/n,g=-e/i,p=1/n,b=1/i;break;case 180:_=V._rescale,f=e/i+1,g=-s/n,p=-1/i,b=1/n;break;case 270:_=V._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,P,k,D]=x.subarray(0,4);C.set([NaN,NaN,NaN,NaN,E,P],0);for(let R=4;R<S;R+=2){const F=x[R],j=x[R+1];C.set(V.createBezierPoints(E,P,k,D,F,j),(R-2)*3),[E,P,k,D]=[k,D,F,j]}}}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 Yg;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,fy).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(V.svgRound).join(" ")}get defaultProperties(){const[e,s]=l(this,je);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${V.svgRound(e)} ${V.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} ${V.svgRound(h)} ${V.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)<=V.PRECISION||Math.abs(d-o)<=V.PRECISION){const _=e+i/2-(h+u/2),y=s+n/2-(c+d/2);return{path:{"transform-origin":`${V.svgRound(e)} ${V.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":`${V.svgRound(h)} ${V.svgRound(c)}`,transform:`${this.rotationTransform} scale(${p} ${b}) translate(${V.svgRound(r)} ${V.svgRound(o)}) scale(${f} ${g}) translate(${V.svgRound(-r)} ${V.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)<=V.PRECISION||Math.abs(f-o)<=V.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,ps))V._translate(S,y,x,S),V._translate(C,y,x,C);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${V.svgRound(e)} ${V.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,ps))V._rescale(y,b,_,g,p,y),V._rescale(x,b,_,g,p,x);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${V.svgRound(e)} ${V.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,ps))V._translate(u,h,c,u),V._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,ps))V._rescale(f,h,c,u,d,f),V._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":`${V.svgRound(e)} ${V.svgRound(s)}`}}}get defaultSVGProperties(){const e=l(this,je);return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${V.svgRound(e[0])} ${V.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}};je=new WeakMap,_c=new WeakMap,wc=new WeakMap,ps=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)]},uy=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]},dy=function(){const e=m(this,je,new Float32Array([1/0,1/0,-1/0,-1/0]));for(const{line:n}of l(this,ps)){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]},fy=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=Yg;const $g=class $g extends XS{constructor(e){super();v(this,lh);m(this,lh,e),super.updateProperties({fill:"none",stroke:Dt._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 $g(l(this,lh));return e.updateAll(this),e}};lh=new WeakMap;let Ng=$g;const ch=class ch extends Ig{constructor(e){super({...e,name:"inkEditor"});v(this,Cd);this._willKeepAspectRatio=!0}static initialize(e,s){Dt.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 nt(this,"typesMap",new Map([[at.INK_THICKNESS,"stroke-width"],[at.INK_COLOR,"stroke"],[at.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:tt.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:tt.INK,color:Dt._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,gy).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,gy=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},q(ch,"_type","ink"),q(ch,"_editorType",tt.INK),q(ch,"_defaultDrawingOptions",null);let jg=ch;const xc=class xc extends Dt{constructor(e){super({...e,name:"stampEditor"});v(this,ct);v(this,Rt,null);v(this,de,null);v(this,hr,null);v(this,vn,null);v(this,lr,null);v(this,uh,"");v(this,Ai,null);v(this,Ti,null);v(this,ms,!1);v(this,dh,!1);m(this,vn,e.bitmapUrl),m(this,lr,e.bitmapFile)}static initialize(e,s){Dt.initialize(e,s)}static get supportedTypes(){return nt(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(s=>`image/${s}`))}static get supportedTypesStr(){return nt(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(e){return this.supportedTypes.includes(e)}static paste(e,s){s.pasteEditor(tt.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,Rt,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,Rt)||l(this,vn)||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,Rt)?w(this,ct,Np).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,jp).call(this)},200))}copyCanvas(e,s,i=!1){var g;e||(e=224);const{width:n,height:r}=l(this,Rt),o=new mg;let h=l(this,Rt),c=n,u=r,d=null;if(s){if(n>s||r>s){const D=Math.min(s/n,s/r);c=Math.floor(n*D),u=Math.floor(r*D)}d=document.createElement("canvas");const p=d.width=Math.ceil(c*o.sx),b=d.height=Math.ceil(u*o.sy);l(this,ms)||(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,P=new OffscreenCanvas(C*2,E*2),k=P.getContext("2d");k.fillStyle=y,k.fillRect(0,0,C*2,E*2),k.fillStyle=x,k.fillRect(0,0,C,E),k.fillRect(C,E,C,E),_.fillStyle=_.createPattern(P,"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,Rt),n>e||r>e){const x=Math.min(e/n,e/r);p=Math.floor(n*x),b=Math.floor(r*x),l(this,ms)||(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 Nb){const{data:{rect:_,rotation:y,id:x,structParent:S,popupRef:C},container:E,parent:{page:{pageNumber:P}}}=e,k=E.querySelector("canvas"),D=i.imageManager.getFromCanvas(E.id,k);k.remove();const R=((b=await s._structTree.getAriaAttributes(`${ug}${x}`))==null?void 0:b.get("aria-label"))||"";n=e={annotationType:tt.STAMP,bitmapId:D.id,bitmap:D.bitmap,pageIndex:P-1,rect:_.slice(0),rotation:y,id:x,deleted:!1,accessibilityData:{decorative:!1,altText:R},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,Rt,h)):m(r,vn,c),m(r,ms,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:tt.STAMP,bitmapId:l(this,de),pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:l(this,ms),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,py).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,ms)?(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,ms)){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}};Rt=new WeakMap,de=new WeakMap,hr=new WeakMap,vn=new WeakMap,lr=new WeakMap,uh=new WeakMap,Ai=new WeakMap,Ti=new WeakMap,ms=new WeakMap,dh=new WeakMap,ct=new WeakSet,Ic=function(e,s=!1){if(!e){this.remove();return}m(this,Rt,e.bitmap),s||(m(this,de,e.id),m(this,ms,e.isSvg)),e.file&&m(this,uh,e.file.name),w(this,ct,Np).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,Rt)){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Rt)){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,vn)){const i=l(this,vn);m(this,vn,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()},Np=function(){var d;const{div:e}=this;let{width:s,height:i}=l(this,Rt);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,jp).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,Rt);let r=i,o=n,h=l(this,Rt);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},jp=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,ms)?l(this,Rt):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,ms)){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,Rt),s.getContext("2d").drawImage(l(this,Rt),0,0),s.toDataURL()}if(l(this,ms)){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,Rt),0,0,l(this,Rt).width,l(this,Rt).height,0,0,n,r),o.transferToImageBitmap()}return structuredClone(l(this,Rt))},py=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}},q(xc,"_type","stamp"),q(xc,"_editorType",tt.STAMP);let Bg=xc;const si=class si{constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:o,textLayer:h,viewport:c,l10n:u}){v(this,Et);v(this,No);v(this,fh,!1);v(this,Ei,null);v(this,cr,null);v(this,yn,null);v(this,Ds,new Map);v(this,ur,!1);v(this,gh,!1);v(this,jo,!1);v(this,ei,null);v(this,_n,null);v(this,Ce,null);v(this,wn,null);v(this,W);const d=[...l(si,dr).values()];if(!si._initialized){si._initialized=!0;for(const f of d)f.initialize(u,t)}t.registerEditorTypes(d),m(this,W,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,W).addLayer(this)}get isEmpty(){return l(this,Ds).size===0}get isInvisible(){return this.isEmpty&&l(this,W).getMode()===tt.NONE}updateToolbar(t){l(this,W).updateToolbar(t)}updateMode(t=l(this,W).getMode()){switch(w(this,Et,ef).call(this),t){case tt.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case tt.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case tt.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(si,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,W).setEditingState(t)}addCommands(t){l(this,W).addCommands(t)}cleanUndoStack(t){l(this,W).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,Ds).values())s.enableEditing(),s.show(!0),s.annotationElementId&&(l(this,W).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,W).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,Ds).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,W).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,W).addChangedExistingAnnotation(h),h.renderAnnotationElement(r)&&h.show(!1)),r.show()}}w(this,Et,ef).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const n of l(si,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,W).getActive()!==t&&l(this,W).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,W).combinedSignal(l(this,wn));l(this,Ce).div.addEventListener("pointerdown",w(this,Et,my).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,W).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,Ds).set(t.id,t);const{annotationElementId:e}=t;e&&l(this,W).isDeletedAnnotationElement(e)&&l(this,W).removeDeletedAnnotationElement(t)}detach(t){var e;l(this,Ds).delete(t.id),(e=l(this,No))==null||e.removePointerInTextLayer(t.contentDiv),!l(this,gh)&&t.annotationElementId&&l(this,W).addDeletedAnnotationElement(t)}remove(t){this.detach(t),l(this,W).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){var e;t.parent!==this&&(t.parent&&t.annotationElementId&&(l(this,W).addDeletedAnnotationElement(t.annotationElementId),Dt.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,W).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,W).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var s;if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!l(this,yn)&&(t._focusEventsAllowed=!1,m(this,yn,setTimeout(()=>{m(this,yn,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:l(this,W)._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,W).getId()}combinedSignal(t){return l(this,W).combinedSignal(t)}canCreateNewEmptyEditor(){var t;return(t=l(this,Et,Di))==null?void 0:t.canCreateNewEmptyEditor()}pasteEditor(t,e){l(this,W).updateToolbar(t),l(this,W).updateMode(t);const{offsetX:s,offsetY:i}=w(this,Et,Hp).call(this),n=this.getNextId(),r=w(this,Et,Bp).call(this,{parent:this,id:n,x:s,y:i,uiManager:l(this,W),isCentered:!0,...e});r&&this.add(r)}async deserialize(t){var e;return await((e=l(si,dr).get(t.annotationType??t.annotationEditorType))==null?void 0:e.deserialize(t,this,l(this,W)))||null}createAndAddNewEditor(t,e,s={}){const i=this.getNextId(),n=w(this,Et,Bp).call(this,{parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:l(this,W),isCentered:e,...s});return n&&this.add(n),n}addNewEditor(){this.createAndAddNewEditor(w(this,Et,Hp).call(this),!0)}setSelected(t){l(this,W).setSelected(t)}toggleSelected(t){l(this,W).toggleSelected(t)}unselect(t){l(this,W).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,Et,Di))!=null&&s.isDrawer&&l(this,Et,Di).supportMultipleDrawings))){if(!l(this,fh)){m(this,fh,!0);return}if(l(this,W).getMode()===tt.STAMP){l(this,W).unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){var i;if(l(this,W).getMode()===tt.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,Et,Di))!=null&&i.isDrawer){this.startDrawingSession(t);return}const s=l(this,W).getActive();m(this,fh,!s||s.isEmpty())}startDrawingSession(t){if(this.div.focus(),l(this,ei)){l(this,Et,Di).startDrawing(this,l(this,W),!1,t);return}l(this,W).setCurrentDrawingSession(this),m(this,ei,new AbortController);const e=l(this,W).combinedSignal(l(this,ei));this.div.addEventListener("blur",({relatedTarget:s})=>{s&&!this.div.contains(s)&&(m(this,_n,null),this.commitOrRemove())},{signal:e}),l(this,Et,Di).startDrawing(this,l(this,W),!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,ei)?(l(this,W).setCurrentDrawingSession(null),l(this,ei).abort(),m(this,ei,null),m(this,_n,null),l(this,Et,Di).endDrawing(t)):null}findNewParent(t,e,s){const i=l(this,W).findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}commitOrRemove(){return l(this,ei)?(this.endDrawingSession(),!0):!1}onScaleChanging(){l(this,ei)&&l(this,Et,Di).onScaleChangingWhenDrawing(this)}destroy(){var t,e;this.commitOrRemove(),((t=l(this,W).getActive())==null?void 0:t.parent)===this&&(l(this,W).commitOrRemove(),l(this,W).setActiveEditor(null)),l(this,yn)&&(clearTimeout(l(this,yn)),m(this,yn,null));for(const s of l(this,Ds).values())(e=l(this,No))==null||e.removePointerInTextLayer(s.contentDiv),s.setParent(null),s.isAttachedToDOM=!1,s.div.remove();this.div=null,l(this,Ds).clear(),l(this,W).removeLayer(this)}render({viewport:t}){this.viewport=t,kr(this.div,t);for(const e of l(this,W).getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){l(this,W).commitOrRemove(),w(this,Et,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,Ds).values())i.rotate(s)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return l(this,W).viewParameters.realScale}};No=new WeakMap,fh=new WeakMap,Ei=new WeakMap,cr=new WeakMap,yn=new WeakMap,Ds=new WeakMap,ur=new WeakMap,gh=new WeakMap,jo=new WeakMap,ei=new WeakMap,_n=new WeakMap,Ce=new WeakMap,wn=new WeakMap,W=new WeakMap,dr=new WeakMap,Et=new WeakSet,my=function(t){l(this,W).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,W).showAllEditors("highlight",!0,!0),l(this,Ce).div.classList.add("free"),this.toggleDrawing(),rd.startHighlighting(this,l(this,W).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,W)._signal}),t.preventDefault()}},Di=function(){return l(si,dr).get(l(this,W).getMode())},Bp=function(t){const e=l(this,Et,Di);return e?new e.prototype.constructor(t):null},Hp=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,Ds).values())t.isEmpty()&&t.remove()},q(si,"_initialized",!1),v(si,dr,new Map([Rg,jg,Bg,rd].map(t=>[t._editorType,t])));let Hg=si;const Ae=class Ae{constructor({pageIndex:t}){v(this,ki);v(this,ii,null);v(this,Sc,0);v(this,Be,new Map);v(this,Bo,new Map);this.pageIndex=t}setParent(t){if(!l(this,ii)){m(this,ii,t);return}if(l(this,ii)!==t){if(l(this,Be).size>0)for(const e of l(this,Be).values())e.remove(),t.append(e);m(this,ii,t)}}static get _svgFactory(){return nt(this,"_svgFactory",new Pg)}draw(t,e=!1,s=!1){const i=ze(this,Sc)._++,n=w(this,ki,zp).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,vy).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,zp).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,Gp).call(this,o,s),i&&w(h=Ae,Ad,by).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,Gp).call(this,u,r)}}}updateParent(t,e){if(e===this)return;const s=l(this,Be).get(t);s&&(l(e,ii).append(s),l(this,Be).delete(t),l(e,Be).set(t,s))}remove(t){l(this,Bo).delete(t),l(this,ii)!==null&&(l(this,Be).get(t).remove(),l(this,Be).delete(t))}destroy(){m(this,ii,null);for(const t of l(this,Be).values())t.remove();l(this,Be).clear(),l(this,Bo).clear()}};ii=new WeakMap,Sc=new WeakMap,Be=new WeakMap,Bo=new WeakMap,Ad=new WeakSet,by=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,zp=function(){const t=Ae._svgFactory.create(1,1,!0);return l(this,ii).append(t),t.setAttribute("aria-hidden",!0),t},vy=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},Gp=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},Q.AbortException,Q.AnnotationEditorLayer,Q.AnnotationEditorParamsType,Q.AnnotationEditorType,Q.AnnotationEditorUIManager,Q.AnnotationLayer,Q.AnnotationMode,Q.ColorPicker,Q.DOMSVGFactory,Q.DrawLayer,Q.FeatureTest;var US=Q.GlobalWorkerOptions;Q.ImageKind,Q.InvalidPDFException,Q.MissingPDFException,Q.OPS,Q.OutputScale,Q.PDFDataRangeTransport,Q.PDFDateString,Q.PDFWorker,Q.PasswordResponses,Q.PermissionFlag,Q.PixelsPerInch,Q.RenderingCancelledException,Q.TextLayer,Q.TouchManager,Q.UnexpectedResponseException,Q.Util,Q.VerbosityLevel,Q.XfaLayer,Q.build,Q.createValidAbsoluteUrl,Q.fetchData;var YS=Q.getDocument;Q.getFilenameFromUrl,Q.getPdfFilenameFromUrl,Q.getXfaPageViewport,Q.isDataScheme,Q.isPdfFile,Q.noContextMenu,Q.normalizeUnicode,Q.setLayerDimensions,Q.shadow,Q.stopEvent,Q.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}function ZS(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 tC(i))}),i.addEventListener("error",n=>{window.URL.revokeObjectURL(s),e(n)})})}function tC(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 Bb=null;function eC(){const a=document.createElement("div");a.style.width="1in",document.body.append(a);const t=a.offsetWidth;return a.remove(),t}function sC(){const a=Bb??eC();return Bb=a,a/72}function iC(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 $e=new Map;function nC(a){const t=new Wf(a);return $e.set(a,t),t}function rC(a,t){const e=Date.now();return{PDFId:`${a.name}-${e}`,name:a.name.replace(/.pdf/,""),updateDate:e,PDFBase64:t}}function oC(a,t){const e=a.getViewport({scale:t}),s=document.createElement("canvas"),i=s.getContext("2d"),n=sC()/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 aC({src:a},t,e){if(!a||!e)return null;const{objects:s,options:i}=await Iw(a),n=s.filter(o=>o!==null),r=K_.groupSVGElements(n,i);return n.forEach(o=>{o.stroke=e}),r.hoverCursor="pointer",r.stroke=`${e}-${t}`,r}function hC(a,t){if(!$e.get(a))return;const s=1/3,i=pC(t,s);zb(a,i,s)}async function lC(a,t){const e=await ZS(t),s=Date.now(),n={PDFId:`${t.name}${s}`,name:t.name.replace(/.png|.jpg|.jpeg/,""),updateDate:s,PDFBase64:e};return Hb(a,{url:e}),{...n,pages:1}}async function Hb(a,{url:t,scale:e=.5}){if(!$e.get(a))return;const i=await be.fromURL(t);i.scale(e),zb(a,i,e)}function zb(a,t,e){const s=$e.get(a);s&&(s.setWidth(t.width*e),s.setHeight(t.height*e),s.backgroundImage=t,s.renderAll())}function cC(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 uC(a,t,e){!e||!a||(e.scale(1/t),cC(a,e))}function dC(a,t){if(!a)return;const e=a._cornerSize||6;a.borderScaleFactor=1/t,a.cornerSize=e*(1/t),a.touchCornerSize=e*4*(1/t),a.setCoords()}function fC(a){const t=$e.get(a);t&&(t.discardActiveObject(),t.renderAll())}function gC(a){const t=$e.get(a);t&&(t.clear(),$e.delete(a))}function pC(a,t){return new be(a,{scaleX:t,scaleY:t})}function Gg(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":mC,"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 mC(a,t,e){const s=await QS(a);if(!s)return;const i=rC(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}=oC(r,e);return o.promise.then(()=>(i&&hC(i,h),n.numPages))}catch(n){return Promise.reject(n)}}async function Xb(a,t,e){if(e)return await lC(e,a)}const bC="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",vC={top:100,left:50,scaleX:.5,scaleY:.5,borderColor:"black",cornerStrokeColor:"black",cornerSize:6,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},yC={top:100,left:50,fontFamily:"helvetica",borderColor:"black",cornerStrokeColor:"black",scaleX:.7,scaleY:.7,cornerSize:6,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},_C={borderColor:"black",cornerStrokeColor:"black",cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},wC={stroke:"#000",hoverStroke:"#B7EC5D",src:bC},xC=["borderColor","cornerStrokeColor","cornerSize","_cornerSize","selectionBackgroundColor"];function Wb(a){const{id:t="",selectionOptions:e,pointerDown:s,pointerMove:i,pointerUp:n,selectionCreated:r,selectionCleared:o}=a||{};let h=null,c=null,u=1,d={...wC};function f(){if(!t||$e.has(t))return;const O=nC(t);return O.on("selection:created",L=>{if(r==null||r(L),L.selected.length<=1)return;const N=O.getActiveObject();N&&(c=N,e!=null&&e.value&&c.set(e.value),c._cornerSize=c.cornerSize,E(u))}),O.on("selection:cleared",L=>{o==null||o(L),k(O)}),s&&O.on("mouse:down",s),i&&O.on("mouse:move",i),n&&O.on("mouse:up",n),O}function g(O,L){return Gb(O,L,t)}function p(O){return Vb(O,t)}function b({url:O,scale:L=.5}){return Hb(t,{url:O,scale:L})}async function _(O,L,N){const Y=$e.get(t);if(!Y)return;const I=await be.fromURL(O,{},{...vC,...L});Gg(I,N),Y.add(I),x(Y,I),Y.setActiveObject(I)}function y(O,L,N){const Y=$e.get(t);if(!Y)return;const I=new me(O,{...yC,...L});Gg(I,N),Y.add(I),x(Y,I),Y.setActiveObject(I)}function x(O,L){L.on("selected",N=>S({canvas:O,target:N.target})),L.on("modified",N=>S({canvas:O,target:N.target})),L.on("scaling",()=>k(O)),L.on("moving",()=>k(O)),L.on("rotating",()=>k(O)),L._cornerSize=L._cornerSize??L.cornerSize}async function S({canvas:O,target:L,stroke:N=d.stroke,uuid:Y=Date.now()}){if(O.getActiveObjects().length>1||(h==null?void 0:h.stroke)===`${N}-${Y}`)return;const H=await aC(d,Y,N);k(O),h=H,c=L,C(O,L,Y),E(u,!0),H&&O.add(H)}function C(O,L,N){h&&(h.on("selected",()=>{O.remove(L),k(O)}),h.on("mouseover",()=>{S({canvas:O,target:L,stroke:d.hoverStroke,uuid:N})}),h.on("mouseout",()=>{S({canvas:O,target:L,stroke:d.stroke,uuid:N})}))}function E(O,L=!1){const N=$e.get(t);u=O,N&&(dC(c,O),uC(c,O,h),!L&&N.renderAll())}function P(O){if(!O)return;d={...d,...O};const L=$e.get(t);!h||!c||!L||S({target:c,canvas:L})}function k(O){c=null,h&&(O.remove(h),h=null)}function D(){fC(t)}function R(){gC(t)}async function F(){const O=$e.get(t);if(!O)return;const L=O==null?void 0:O.getActiveObject();if(!L)return;const N=await L.clone(xC);N instanceof ys?N.forEachObject(Y=>{O.add(Y),x(O,Y)}):(O.add(N),x(O,N)),Gg(N,{x:-.1,y:-.1}),O.setActiveObject(N)}function j(){const O=$e.get(t);if(!O)return;const L=O.getActiveObject();L&&(L instanceof ys?(L.forEachObject(N=>{O.remove(N)}),O.discardActiveObject()):O.remove(L))}return{createCanvas:f,loadFile:g,specifyPage:p,renderImage:b,addFabric:_,addTextFabric:y,clearActive:D,deleteCanvas:R,scaleFabric:E,setCloseSvgOptions:P,copyActiveFabric:F,deleteActiveFabric:j}}function SC(a){let t=0;const e=iC(()=>{t!==window.innerWidth&&(t=window.innerWidth,a())});K.onMounted(()=>{window.addEventListener("resize",e)}),K.onBeforeUnmount(()=>{window.removeEventListener("resize",e)})}const CC=K.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:{},closeSvgOptions:{},manualReload:{type:Boolean},onDestroy:{type:Function,default:K.onBeforeUnmount}},emits:["loaded","reload","pointerDown","pointerMove","pointerUp","selectionCreated","selectionCleared"],setup(a,{expose:t,emit:e}){const s=a,i=e,{onDestroy:n}=s,r=K.ref(null),o=`${s.canvasId}-${s.page-1}`,h=K.computed(()=>s.fileZoom*s.canvasScale),c=K.computed(()=>({..._C,...s.selectionOptions})),{createCanvas:u,specifyPage:d,addFabric:f,addTextFabric:g,renderImage:p,clearActive:b,deleteCanvas:_,scaleFabric:y,setCloseSvgOptions:x,copyActiveFabric:S,deleteActiveFabric:C}=Wb({id:o,selectionOptions:c,pointerDown:F=>i("pointerDown",F),pointerMove:F=>i("pointerMove",F),pointerUp:F=>i("pointerUp",F),selectionCreated:F=>i("selectionCreated",F),selectionCleared:F=>i("selectionCleared",F)});E(),SC(R);async function E(){const{file:F,page:j,fileScale:O}=s;window.requestAnimationFrame(async()=>{if(await K.nextTick(),u(),F.PDFBase64.startsWith("data:image")||F.canvas){const{canvas:L}=F,N=L?7:3,Y=L!=null&&L.length?L[j-1]:F.PDFBase64;p({url:Y,scale:O/N}),i("loaded");return}await d({page:j,PDFBase64:F.PDFBase64,scale:O,password:s.password}),i("loaded")})}function P(F){if(!s.isDrop||!F.dataTransfer)return;const{dataTransfer:j,offsetX:O,offsetY:L}=F,N=j.getData("text/plain"),Y=j.getData("text/uri-list"),I=j.getData("custom/offset"),H=I?JSON.parse(I):null,it={top:L,left:O},kt={x:(H==null?void 0:H.offsetX)??0,y:(H==null?void 0:H.offsetY)??0};Y?k(Y,it,kt):N&&D(N,it,kt)}function k(F,j,O){f(F,{...s.dropImageOptions,...j},O)}function D(F,j,O){g(F,{...s.dropTextOptions,...j},O)}function R(){s.manualReload||E(),i("reload")}return K.watch([()=>s.fileScale,()=>s.page,()=>s.file,()=>s.password],R),K.watch(h,F=>y(F),{immediate:!0}),K.watch(()=>s.closeSvgOptions,x,{immediate:!0}),n(_),t({reload:E,addImage:k,addText:D,clearActive:b,deleteCanvas:_,copyActiveFabric:S,deleteActiveFabric:C,canvasRef:r}),(F,j)=>(K.openBlock(),K.createElementBlock("div",{style:K.normalizeStyle({transform:`scale(${h.value})`}),onDragover:j[0]||(j[0]=K.withModifiers(()=>{},["prevent"])),onDragenter:j[1]||(j[1]=K.withModifiers(()=>{},["prevent"])),onDrop:K.withModifiers(P,["stop","prevent"])},[K.createElementVNode("canvas",{id:o,ref_key:"canvasRef",ref:r,class:K.normalizeClass(F.canvasClass)},null,2)],36))}});ot.default=CC,ot.loadFile=Gb,ot.useFabric=Wb,Object.defineProperties(ot,{__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.11",
3
+ "version": "1.1.0-alpha.12",
4
4
  "description": "Rendering PDF documents onto a canvas with vue3 and react component",
5
5
  "license": "MIT",
6
6
  "type": "module",