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

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.
@@ -1,6 +1,8 @@
1
1
  import { Canvas } from 'fabric';
2
+ import { FabricImage } from 'fabric';
2
3
  import { FabricObject } from 'fabric';
3
4
  import { FabricObjectProps } from 'fabric';
5
+ import { FabricText } from 'fabric';
4
6
  import { ForwardRefExoticComponent } from 'react';
5
7
  import { ImageProps } from 'fabric';
6
8
  import { ObjectEvents } from 'fabric';
@@ -13,6 +15,16 @@ import { TOptions } from 'fabric';
13
15
  import { TPointerEvent } from 'fabric';
14
16
  import { TPointerEventInfo } from 'fabric';
15
17
 
18
+ export declare type CacheFabricImage = FabricImage & CacheProperties;
19
+
20
+ export declare type CacheFabricObject = FabricObject & CacheProperties;
21
+
22
+ export declare type CacheFabricText = FabricText & CacheProperties;
23
+
24
+ declare interface CacheProperties {
25
+ _cornerSize?: number;
26
+ }
27
+
16
28
  export declare interface CloseSvgOptions {
17
29
  stroke: string;
18
30
  hoverStroke: string;
@@ -31,6 +43,7 @@ export declare interface ComponentProps {
31
43
  password?: string;
32
44
  dropTextOptions?: TOptions<TextProps>;
33
45
  dropImageOptions?: TOptions<ImageProps>;
46
+ selectionOptions?: TOptions<FabricObjectProps>;
34
47
  closeSvgOptions?: CloseSvgOptions;
35
48
  manualReload?: boolean;
36
49
  onDestroy?: (callback: () => void) => void;
@@ -22784,8 +22784,10 @@ function ll(o, t) {
22784
22784
  function OA(o, t, e) {
22785
22785
  !e || !o || (e.scale(1 / t), ll(o, e));
22786
22786
  }
22787
- function DA(o, t, e) {
22788
- o && (o.borderScaleFactor = 1 / t, o.cornerSize = 6 * (1 / t), o.touchCornerSize = 24 * (1 / t), o.cornerStrokeColor = e.stroke, o.setCoords());
22787
+ function DA(o, t) {
22788
+ if (!o) return;
22789
+ const e = o._cornerSize || 8;
22790
+ o.borderScaleFactor = 1 / t, o.cornerSize = e * (1 / t), o.touchCornerSize = e * 4 * (1 / t), o.setCoords();
22789
22791
  }
22790
22792
  function RA(o) {
22791
22793
  const t = Bs.get(o);
@@ -22910,7 +22912,7 @@ function BA(o = "") {
22910
22912
  }
22911
22913
  function x(k, M = !1) {
22912
22914
  const R = Bs.get(o);
22913
- i.current = k, R && (DA(s.current, k, n.current), OA(s.current, k, e.current), !M && R.renderAll());
22915
+ i.current = k, R && (DA(s.current, k), OA(s.current, k, e.current), !M && R.renderAll());
22914
22916
  }
22915
22917
  function C(k) {
22916
22918
  if (!k) return;
@@ -535,4 +535,4 @@ void main() {
535
535
  `),position:v,pageIndex:_-1,rect:u.slice(0),rotation:d,id:f,deleted:!1,popupRef:g}}const r=await super.deserialize(e,s,i);return m(r,xs,e.fontSize),m(r,ui,q.makeHexColor(...e.color)),m(r,ws,w(a=Ot,kn,Zp).call(a,e.value)),r.annotationElementId=e.id||null,r._initialData=n,r}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const s=Ot._internalPadding*this.parentScale,i=this.getRect(s,s),n=Ht._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:l(this,ui)),r={annotationType:nt.FREETEXT,color:n,fontSize:l(this,xs),value:w(this,ie,My).call(this),pageIndex:this.pageIndex,rect:i,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?r:this.annotationElementId&&!w(this,ie,Oy).call(this,r)?null:(r.id=this.annotationElementId,r)}renderAnnotationElement(e){const s=super.renderAnnotationElement(e);if(this.deleted)return s;const{style:i}=s;i.fontSize=`calc(${l(this,xs)}px * var(--scale-factor))`,i.color=l(this,ui),s.replaceChildren();for(const r of l(this,ws).split(`
536
536
  `)){const a=document.createElement("div");a.append(r?document.createTextNode(r):document.createElement("br")),s.append(a)}const n=Ot._internalPadding*this.parentScale;return e.updateEdited({rect:this.getRect(n,n),popupContent:l(this,ws)}),s}resetAnnotationElement(e){super.resetAnnotationElement(e),e.resetEdited()}};ui=new WeakMap,ws=new WeakMap,Sc=new WeakMap,ja=new WeakMap,xs=new WeakMap,ie=new WeakSet,Ey=function(e){const s=n=>{this.editorDiv.style.fontSize=`calc(${n}px * var(--scale-factor))`,this.translate(0,-(n-l(this,xs))*this.parentScale),m(this,xs,n),w(this,ie,ff).call(this)},i=l(this,xs);this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:dt.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})},ky=function(e){const s=n=>{m(this,ui,this.editorDiv.style.color=n)},i=l(this,ui);this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:dt.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})},Py=function(){var i;const e=[];this.editorDiv.normalize();let s=null;for(const n of this.editorDiv.childNodes)(s==null?void 0:s.nodeType)===Node.TEXT_NODE&&n.nodeName==="BR"||(e.push(w(i=Ot,kn,gf).call(i,n)),s=n);return e.join(`
537
537
  `)},ff=function(){const[e,s]=this.parentDimensions;let i;if(this.isAttachedToDOM)i=this.div.getBoundingClientRect();else{const{currentLayer:n,div:r}=this,a=r.style.display,h=r.classList.contains("hidden");r.classList.remove("hidden"),r.style.display="hidden",n.div.append(this.div),i=r.getBoundingClientRect(),r.remove(),r.style.display=a,r.classList.toggle("hidden",h)}this.rotation%180===this.parentRotation%180?(this.width=i.width/e,this.height=i.height/s):(this.width=i.height/e,this.height=i.width/s),this.fixAndSetPosition()},kn=new WeakSet,gf=function(e){return(e.nodeType===Node.TEXT_NODE?e.nodeValue:e.innerText).replaceAll(xd,"")},pf=function(){if(this.editorDiv.replaceChildren(),!!l(this,ws))for(const e of l(this,ws).split(`
538
- `)){const s=document.createElement("div");s.append(e?document.createTextNode(e):document.createElement("br")),this.editorDiv.append(s)}},My=function(){return l(this,ws).replaceAll(" "," ")},Zp=function(e){return e.replaceAll(" "," ")},Oy=function(e){const{value:s,fontSize:i,color:n,pageIndex:r}=this._initialData;return this._hasBeenMoved||e.value!==s||e.fontSize!==i||e.color.some((a,h)=>a!==n[h])||e.pageIndex!==r},y(Ot,kn),J(Ot,"_freeTextDefaultContent",""),J(Ot,"_internalPadding",0),J(Ot,"_defaultColor",null),J(Ot,"_defaultFontSize",10),J(Ot,"_type","freetext"),J(Ot,"_editorType",nt.FREETEXT);let ep=Ot;class X{toSVGPath(){Et("Abstract method `toSVGPath` must be implemented.")}get box(){Et("Abstract getter `box` must be implemented.")}serialize(t,e){Et("Abstract method `serialize` must be implemented.")}static _rescale(t,e,s,i,n,r){r||(r=new Float32Array(t.length));for(let a=0,h=t.length;a<h;a+=2)r[a]=e+t[a]*i,r[a+1]=s+t[a+1]*n;return r}static _rescaleAndSwap(t,e,s,i,n,r){r||(r=new Float32Array(t.length));for(let a=0,h=t.length;a<h;a+=2)r[a]=e+t[a+1]*i,r[a+1]=s+t[a]*n;return r}static _translate(t,e,s,i){i||(i=new Float32Array(t.length));for(let n=0,r=t.length;n<r;n+=2)i[n]=e+t[n],i[n+1]=s+t[n+1];return i}static svgRound(t){return Math.round(t*1e4)}static _normalizePoint(t,e,s,i,n){switch(n){case 90:return[1-e/s,t/i];case 180:return[1-t/s,1-e/i];case 270:return[e/s,1-t/i];default:return[t/s,e/i]}}static _normalizePagePoint(t,e,s){switch(s){case 90:return[1-e,t];case 180:return[1-t,1-e];case 270:return[e,1-t];default:return[t,e]}}static createBezierPoints(t,e,s,i,n,r){return[(t+5*s)/6,(e+5*i)/6,(5*s+n)/6,(5*i+r)/6,(s+n)/2,(i+r)/2]}}J(X,"PRECISION",1e-4);const Pn=class Pn{constructor({x:t,y:e},s,i,n,r,a=0){y(this,ce);y(this,Ss);y(this,di,[]);y(this,oh);y(this,hh);y(this,ji,[]);y(this,lt,new Float32Array(18));y(this,Na);y(this,Ba);y(this,Cc);y(this,Ac);y(this,lh);y(this,ch);y(this,br,[]);m(this,Ss,s),m(this,ch,n*i),m(this,hh,r),l(this,lt).set([NaN,NaN,NaN,NaN,t,e],6),m(this,oh,a),m(this,Ac,l(Pn,Tc)*i),m(this,Cc,l(Pn,Vd)*i),m(this,lh,i),l(this,br).push(t,e)}isEmpty(){return isNaN(l(this,lt)[8])}add({x:t,y:e}){var R;m(this,Na,t),m(this,Ba,e);const[s,i,n,r]=l(this,Ss);let[a,h,c,u]=l(this,lt).subarray(8,12);const d=t-c,f=e-u,g=Math.hypot(d,f);if(g<l(this,Cc))return!1;const p=g-l(this,Ac),v=p/g,_=v*d,b=v*f;let x=a,C=h;a=c,h=u,c+=_,u+=b,(R=l(this,br))==null||R.push(t,e);const A=-b/p,P=_/p,D=A*l(this,ch),k=P*l(this,ch);return l(this,lt).set(l(this,lt).subarray(2,8),0),l(this,lt).set([c+D,u+k],4),l(this,lt).set(l(this,lt).subarray(14,18),12),l(this,lt).set([c-D,u-k],16),isNaN(l(this,lt)[6])?(l(this,ji).length===0&&(l(this,lt).set([a+D,h+k],2),l(this,ji).push(NaN,NaN,NaN,NaN,(a+D-s)/n,(h+k-i)/r),l(this,lt).set([a-D,h-k],14),l(this,di).push(NaN,NaN,NaN,NaN,(a-D-s)/n,(h-k-i)/r)),l(this,lt).set([x,C,a,h,c,u],6),!this.isEmpty()):(l(this,lt).set([x,C,a,h,c,u],6),Math.abs(Math.atan2(C-h,x-a)-Math.atan2(b,_))<Math.PI/2?([a,h,c,u]=l(this,lt).subarray(2,6),l(this,ji).push(NaN,NaN,NaN,NaN,((a+c)/2-s)/n,((h+u)/2-i)/r),[a,h,x,C]=l(this,lt).subarray(14,18),l(this,di).push(NaN,NaN,NaN,NaN,((x+a)/2-s)/n,((C+h)/2-i)/r),!0):([x,C,a,h,c,u]=l(this,lt).subarray(0,6),l(this,ji).push(((x+5*a)/6-s)/n,((C+5*h)/6-i)/r,((5*a+c)/6-s)/n,((5*h+u)/6-i)/r,((a+c)/2-s)/n,((h+u)/2-i)/r),[c,u,a,h,x,C]=l(this,lt).subarray(12,18),l(this,di).push(((x+5*a)/6-s)/n,((C+5*h)/6-i)/r,((5*a+c)/6-s)/n,((5*h+u)/6-i)/r,((a+c)/2-s)/n,((h+u)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";const t=l(this,ji),e=l(this,di);if(isNaN(l(this,lt)[6])&&!this.isEmpty())return w(this,ce,Dy).call(this);const s=[];s.push(`M${t[4]} ${t[5]}`);for(let i=6;i<t.length;i+=6)isNaN(t[i])?s.push(`L${t[i+4]} ${t[i+5]}`):s.push(`C${t[i]} ${t[i+1]} ${t[i+2]} ${t[i+3]} ${t[i+4]} ${t[i+5]}`);w(this,ce,Ly).call(this,s);for(let i=e.length-6;i>=6;i-=6)isNaN(e[i])?s.push(`L${e[i+4]} ${e[i+5]}`):s.push(`C${e[i]} ${e[i+1]} ${e[i+2]} ${e[i+3]} ${e[i+4]} ${e[i+5]}`);return w(this,ce,Ry).call(this,s),s.join(" ")}newFreeDrawOutline(t,e,s,i,n,r){return new gb(t,e,s,i,n,r)}getOutlines(){var d;const t=l(this,ji),e=l(this,di),s=l(this,lt),[i,n,r,a]=l(this,Ss),h=new Float32Array((((d=l(this,br))==null?void 0:d.length)??0)+2);for(let f=0,g=h.length-2;f<g;f+=2)h[f]=(l(this,br)[f]-i)/r,h[f+1]=(l(this,br)[f+1]-n)/a;if(h[h.length-2]=(l(this,Na)-i)/r,h[h.length-1]=(l(this,Ba)-n)/a,isNaN(s[6])&&!this.isEmpty())return w(this,ce,Fy).call(this,h);const c=new Float32Array(l(this,ji).length+24+l(this,di).length);let u=t.length;for(let f=0;f<u;f+=2){if(isNaN(t[f])){c[f]=c[f+1]=NaN;continue}c[f]=t[f],c[f+1]=t[f+1]}u=w(this,ce,jy).call(this,c,u);for(let f=e.length-6;f>=6;f-=6)for(let g=0;g<6;g+=2){if(isNaN(e[f+g])){c[u]=c[u+1]=NaN,u+=2;continue}c[u]=e[f+g],c[u+1]=e[f+g+1],u+=2}return w(this,ce,Iy).call(this,c,u),this.newFreeDrawOutline(c,h,l(this,Ss),l(this,lh),l(this,oh),l(this,hh))}};Ss=new WeakMap,di=new WeakMap,oh=new WeakMap,hh=new WeakMap,ji=new WeakMap,lt=new WeakMap,Na=new WeakMap,Ba=new WeakMap,Cc=new WeakMap,Ac=new WeakMap,lh=new WeakMap,ch=new WeakMap,br=new WeakMap,Tc=new WeakMap,Gd=new WeakMap,Vd=new WeakMap,ce=new WeakSet,Zc=function(){const t=l(this,lt).subarray(4,6),e=l(this,lt).subarray(16,18),[s,i,n,r]=l(this,Ss);return[(l(this,Na)+(t[0]-e[0])/2-s)/n,(l(this,Ba)+(t[1]-e[1])/2-i)/r,(l(this,Na)+(e[0]-t[0])/2-s)/n,(l(this,Ba)+(e[1]-t[1])/2-i)/r]},Dy=function(){const[t,e,s,i]=l(this,Ss),[n,r,a,h]=w(this,ce,Zc).call(this);return`M${(l(this,lt)[2]-t)/s} ${(l(this,lt)[3]-e)/i} L${(l(this,lt)[4]-t)/s} ${(l(this,lt)[5]-e)/i} L${n} ${r} L${a} ${h} L${(l(this,lt)[16]-t)/s} ${(l(this,lt)[17]-e)/i} L${(l(this,lt)[14]-t)/s} ${(l(this,lt)[15]-e)/i} Z`},Ry=function(t){const e=l(this,di);t.push(`L${e[4]} ${e[5]} Z`)},Ly=function(t){const[e,s,i,n]=l(this,Ss),r=l(this,lt).subarray(4,6),a=l(this,lt).subarray(16,18),[h,c,u,d]=w(this,ce,Zc).call(this);t.push(`L${(r[0]-e)/i} ${(r[1]-s)/n} L${h} ${c} L${u} ${d} L${(a[0]-e)/i} ${(a[1]-s)/n}`)},Fy=function(t){const e=l(this,lt),[s,i,n,r]=l(this,Ss),[a,h,c,u]=w(this,ce,Zc).call(this),d=new Float32Array(36);return d.set([NaN,NaN,NaN,NaN,(e[2]-s)/n,(e[3]-i)/r,NaN,NaN,NaN,NaN,(e[4]-s)/n,(e[5]-i)/r,NaN,NaN,NaN,NaN,a,h,NaN,NaN,NaN,NaN,c,u,NaN,NaN,NaN,NaN,(e[16]-s)/n,(e[17]-i)/r,NaN,NaN,NaN,NaN,(e[14]-s)/n,(e[15]-i)/r],0),this.newFreeDrawOutline(d,t,l(this,Ss),l(this,lh),l(this,oh),l(this,hh))},Iy=function(t,e){const s=l(this,di);return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6},jy=function(t,e){const s=l(this,lt).subarray(4,6),i=l(this,lt).subarray(16,18),[n,r,a,h]=l(this,Ss),[c,u,d,f]=w(this,ce,Zc).call(this);return t.set([NaN,NaN,NaN,NaN,(s[0]-n)/a,(s[1]-r)/h,NaN,NaN,NaN,NaN,c,u,NaN,NaN,NaN,NaN,d,f,NaN,NaN,NaN,NaN,(i[0]-n)/a,(i[1]-r)/h],e),e+=24},y(Pn,Tc,8),y(Pn,Gd,2),y(Pn,Vd,l(Pn,Tc)+l(Pn,Gd));let Sd=Pn;class gb extends X{constructor(e,s,i,n,r,a){super();y(this,Wd);y(this,uh);y(this,Ha,new Float32Array(4));y(this,Mn);y(this,Ec);y(this,Cs);y(this,kc);y(this,Jt);m(this,Jt,e),m(this,Cs,s),m(this,uh,i),m(this,kc,n),m(this,Mn,r),m(this,Ec,a),this.lastPoint=[NaN,NaN],w(this,Wd,Ny).call(this,a);const[h,c,u,d]=l(this,Ha);for(let f=0,g=e.length;f<g;f+=2)e[f]=(e[f]-h)/u,e[f+1]=(e[f+1]-c)/d;for(let f=0,g=s.length;f<g;f+=2)s[f]=(s[f]-h)/u,s[f+1]=(s[f+1]-c)/d}toSVGPath(){const e=[`M${l(this,Jt)[4]} ${l(this,Jt)[5]}`];for(let s=6,i=l(this,Jt).length;s<i;s+=6){if(isNaN(l(this,Jt)[s])){e.push(`L${l(this,Jt)[s+4]} ${l(this,Jt)[s+5]}`);continue}e.push(`C${l(this,Jt)[s]} ${l(this,Jt)[s+1]} ${l(this,Jt)[s+2]} ${l(this,Jt)[s+3]} ${l(this,Jt)[s+4]} ${l(this,Jt)[s+5]}`)}return e.push("Z"),e.join(" ")}serialize([e,s,i,n],r){const a=i-e,h=n-s;let c,u;switch(r){case 0:c=X._rescale(l(this,Jt),e,n,a,-h),u=X._rescale(l(this,Cs),e,n,a,-h);break;case 90:c=X._rescaleAndSwap(l(this,Jt),e,s,a,h),u=X._rescaleAndSwap(l(this,Cs),e,s,a,h);break;case 180:c=X._rescale(l(this,Jt),i,s,-a,h),u=X._rescale(l(this,Cs),i,s,-a,h);break;case 270:c=X._rescaleAndSwap(l(this,Jt),i,n,-a,-h),u=X._rescaleAndSwap(l(this,Cs),i,n,-a,-h);break}return{outline:Array.from(c),points:[Array.from(u)]}}get box(){return l(this,Ha)}newOutliner(e,s,i,n,r,a=0){return new Sd(e,s,i,n,r,a)}getNewOutline(e,s){const[i,n,r,a]=l(this,Ha),[h,c,u,d]=l(this,uh),f=r*u,g=a*d,p=i*u+h,v=n*d+c,_=this.newOutliner({x:l(this,Cs)[0]*f+p,y:l(this,Cs)[1]*g+v},l(this,uh),l(this,kc),e,l(this,Ec),s??l(this,Mn));for(let b=2;b<l(this,Cs).length;b+=2)_.add({x:l(this,Cs)[b]*f+p,y:l(this,Cs)[b+1]*g+v});return _.getOutlines()}}uh=new WeakMap,Ha=new WeakMap,Mn=new WeakMap,Ec=new WeakMap,Cs=new WeakMap,kc=new WeakMap,Jt=new WeakMap,Wd=new WeakSet,Ny=function(e){const s=l(this,Jt);let i=s[4],n=s[5],r=i,a=n,h=i,c=n,u=i,d=n;const f=e?Math.max:Math.min;for(let p=6,v=s.length;p<v;p+=6){if(isNaN(s[p]))r=Math.min(r,s[p+4]),a=Math.min(a,s[p+5]),h=Math.max(h,s[p+4]),c=Math.max(c,s[p+5]),d<s[p+5]?(u=s[p+4],d=s[p+5]):d===s[p+5]&&(u=f(u,s[p+4]));else{const _=q.bezierBoundingBox(i,n,...s.slice(p,p+6));r=Math.min(r,_[0]),a=Math.min(a,_[1]),h=Math.max(h,_[2]),c=Math.max(c,_[3]),d<_[3]?(u=_[2],d=_[3]):d===_[3]&&(u=f(u,_[2]))}i=s[p+4],n=s[p+5]}const g=l(this,Ha);g[0]=r-l(this,Mn),g[1]=a-l(this,Mn),g[2]=h-r+2*l(this,Mn),g[3]=c-a+2*l(this,Mn),this.lastPoint=[u,d]};class sp{constructor(t,e=0,s=0,i=!0){y(this,Ye);y(this,Pc);y(this,Mc);y(this,yr,[]);y(this,fi,[]);let n=1/0,r=-1/0,a=1/0,h=-1/0;const c=10**-4;for(const{x:_,y:b,width:x,height:C}of t){const A=Math.floor((_-e)/c)*c,P=Math.ceil((_+x+e)/c)*c,D=Math.floor((b-e)/c)*c,k=Math.ceil((b+C+e)/c)*c,M=[A,D,k,!0],R=[P,D,k,!1];l(this,yr).push(M,R),n=Math.min(n,A),r=Math.max(r,P),a=Math.min(a,D),h=Math.max(h,k)}const u=r-n+2*s,d=h-a+2*s,f=n-s,g=a-s,p=l(this,yr).at(i?-1:-2),v=[p[0],p[2]];for(const _ of l(this,yr)){const[b,x,C]=_;_[0]=(b-f)/u,_[1]=(x-g)/d,_[2]=(C-g)/d}m(this,Pc,new Float32Array([f,g,u,d])),m(this,Mc,v)}getOutlines(){l(this,yr).sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);const t=[];for(const e of l(this,yr))e[3]?(t.push(...w(this,Ye,tm).call(this,e)),w(this,Ye,Hy).call(this,e)):(w(this,Ye,Gy).call(this,e),t.push(...w(this,Ye,tm).call(this,e)));return w(this,Ye,By).call(this,t)}}Pc=new WeakMap,Mc=new WeakMap,yr=new WeakMap,fi=new WeakMap,Ye=new WeakSet,By=function(t){const e=[],s=new Set;for(const r of t){const[a,h,c]=r;e.push([a,h,r],[a,c,r])}e.sort((r,a)=>r[1]-a[1]||r[0]-a[0]);for(let r=0,a=e.length;r<a;r+=2){const h=e[r][2],c=e[r+1][2];h.push(c),c.push(h),s.add(h),s.add(c)}const i=[];let n;for(;s.size>0;){const r=s.values().next().value;let[a,h,c,u,d]=r;s.delete(r);let f=a,g=h;for(n=[a,c],i.push(n);;){let p;if(s.has(u))p=u;else if(s.has(d))p=d;else break;s.delete(p),[a,h,c,u,d]=p,f!==a&&(n.push(f,g,a,g===h?h:c),f=a),g=g===h?c:h}n.push(f,g)}return new DC(i,l(this,Pc),l(this,Mc))},mf=function(t){const e=l(this,fi);let s=0,i=e.length-1;for(;s<=i;){const n=s+i>>1,r=e[n][0];if(r===t)return n;r<t?s=n+1:i=n-1}return i+1},Hy=function([,t,e]){const s=w(this,Ye,mf).call(this,t);l(this,fi).splice(s,0,[t,e])},Gy=function([,t,e]){const s=w(this,Ye,mf).call(this,t);for(let i=s;i<l(this,fi).length;i++){const[n,r]=l(this,fi)[i];if(n!==t)break;if(n===t&&r===e){l(this,fi).splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=l(this,fi)[i];if(n!==t)break;if(n===t&&r===e){l(this,fi).splice(i,1);return}}},tm=function(t){const[e,s,i]=t,n=[[e,s,i]],r=w(this,Ye,mf).call(this,i);for(let a=0;a<r;a++){const[h,c]=l(this,fi)[a];for(let u=0,d=n.length;u<d;u++){const[,f,g]=n[u];if(!(c<=f||g<=h)){if(f>=h){if(g>c)n[u][1]=c;else{if(d===1)return[];n.splice(u,1),u--,d--}continue}n[u][2]=h,g>c&&n.push([e,c,g])}}}return n};class DC extends X{constructor(e,s,i){super();y(this,Oc);y(this,dh);m(this,dh,e),m(this,Oc,s),this.lastPoint=i}toSVGPath(){const e=[];for(const s of l(this,dh)){let[i,n]=s;e.push(`M${i} ${n}`);for(let r=2;r<s.length;r+=2){const a=s[r],h=s[r+1];a===i?(e.push(`V${h}`),n=h):h===n&&(e.push(`H${a}`),i=a)}e.push("Z")}return e.join(" ")}serialize([e,s,i,n],r){const a=[],h=i-e,c=n-s;for(const u of l(this,dh)){const d=new Array(u.length);for(let f=0;f<u.length;f+=2)d[f]=e+u[f]*h,d[f+1]=n-u[f+1]*c;a.push(d)}return a}get box(){return l(this,Oc)}get classNamesForOutlining(){return["highlightOutline"]}}Oc=new WeakMap,dh=new WeakMap;class ip extends Sd{newFreeDrawOutline(t,e,s,i,n,r){return new RC(t,e,s,i,n,r)}}class RC extends gb{newOutliner(t,e,s,i,n,r=0){return new ip(t,e,s,i,n,r)}}const hs=class hs{constructor({editor:t=null,uiManager:e=null}){y(this,At);y(this,gi,null);y(this,Ga,null);y(this,fh);y(this,ue,null);y(this,Dc,!1);y(this,gh,!1);y(this,Rc,null);y(this,Lc);y(this,_r,null);y(this,pi,null);y(this,ph);var s;t?(m(this,gh,!1),m(this,ph,dt.HIGHLIGHT_COLOR),m(this,Rc,t)):(m(this,gh,!0),m(this,ph,dt.HIGHLIGHT_DEFAULT_COLOR)),m(this,pi,(t==null?void 0:t._uiManager)||e),m(this,Lc,l(this,pi)._eventBus),m(this,fh,(t==null?void 0:t.color)||((s=l(this,pi))==null?void 0:s.highlightColors.values().next().value)||"#FFFF98"),l(hs,Fc)||m(hs,Fc,Object.freeze({blue:"pdfjs-editor-colorpicker-blue",green:"pdfjs-editor-colorpicker-green",pink:"pdfjs-editor-colorpicker-pink",red:"pdfjs-editor-colorpicker-red",yellow:"pdfjs-editor-colorpicker-yellow"}))}static get _keyboardManager(){return ht(this,"_keyboardManager",new ll([[["Escape","mac+Escape"],hs.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],hs.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],hs.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],hs.prototype._moveToPrevious],[["Home","mac+Home"],hs.prototype._moveToBeginning],[["End","mac+End"],hs.prototype._moveToEnd]]))}renderButton(){const t=m(this,gi,document.createElement("button"));t.className="colorPicker",t.tabIndex="0",t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-button"),t.setAttribute("aria-haspopup",!0);const e=l(this,pi)._signal;t.addEventListener("click",w(this,At,io).bind(this),{signal:e}),t.addEventListener("keydown",w(this,At,im).bind(this),{signal:e});const s=m(this,Ga,document.createElement("span"));return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=l(this,fh),t.append(s),t}renderMainDropdown(){const t=m(this,ue,w(this,At,em).call(this));return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}_colorSelectFromKeyboard(t){if(t.target===l(this,gi)){w(this,At,io).call(this,t);return}const e=t.target.getAttribute("data-color");e&&w(this,At,sm).call(this,e,t)}_moveToNext(t){var e,s;if(!l(this,At,Pr)){w(this,At,io).call(this,t);return}if(t.target===l(this,gi)){(e=l(this,ue).firstChild)==null||e.focus();return}(s=t.target.nextSibling)==null||s.focus()}_moveToPrevious(t){var e,s;if(t.target===((e=l(this,ue))==null?void 0:e.firstChild)||t.target===l(this,gi)){l(this,At,Pr)&&this._hideDropdownFromKeyboard();return}l(this,At,Pr)||w(this,At,io).call(this,t),(s=t.target.previousSibling)==null||s.focus()}_moveToBeginning(t){var e;if(!l(this,At,Pr)){w(this,At,io).call(this,t);return}(e=l(this,ue).firstChild)==null||e.focus()}_moveToEnd(t){var e;if(!l(this,At,Pr)){w(this,At,io).call(this,t);return}(e=l(this,ue).lastChild)==null||e.focus()}hideDropdown(){var t,e;(t=l(this,ue))==null||t.classList.add("hidden"),(e=l(this,_r))==null||e.abort(),m(this,_r,null)}_hideDropdownFromKeyboard(){var t;if(!l(this,gh)){if(!l(this,At,Pr)){(t=l(this,Rc))==null||t.unselect();return}this.hideDropdown(),l(this,gi).focus({preventScroll:!0,focusVisible:l(this,Dc)})}}updateColor(t){if(l(this,Ga)&&(l(this,Ga).style.backgroundColor=t),!l(this,ue))return;const e=l(this,pi).highlightColors.values();for(const s of l(this,ue).children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){var t,e;(t=l(this,gi))==null||t.remove(),m(this,gi,null),m(this,Ga,null),(e=l(this,ue))==null||e.remove(),m(this,ue,null)}};gi=new WeakMap,Ga=new WeakMap,fh=new WeakMap,ue=new WeakMap,Dc=new WeakMap,gh=new WeakMap,Rc=new WeakMap,Lc=new WeakMap,_r=new WeakMap,pi=new WeakMap,ph=new WeakMap,Fc=new WeakMap,At=new WeakSet,em=function(){const t=document.createElement("div"),e=l(this,pi)._signal;t.addEventListener("contextmenu",ii,{signal:e}),t.className="dropdown",t.role="listbox",t.setAttribute("aria-multiselectable",!1),t.setAttribute("aria-orientation","vertical"),t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown");for(const[s,i]of l(this,pi).highlightColors){const n=document.createElement("button");n.tabIndex="0",n.role="option",n.setAttribute("data-color",i),n.title=s,n.setAttribute("data-l10n-id",l(hs,Fc)[s]);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===l(this,fh)),n.addEventListener("click",w(this,At,sm).bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",w(this,At,im).bind(this),{signal:e}),t},sm=function(t,e){e.stopPropagation(),l(this,Lc).dispatch("switchannotationeditorparams",{source:this,type:l(this,ph),value:t})},im=function(t){hs._keyboardManager.exec(this,t)},io=function(t){if(l(this,At,Pr)){this.hideDropdown();return}if(m(this,Dc,t.detail===0),l(this,_r)||(m(this,_r,new AbortController),window.addEventListener("pointerdown",w(this,At,Vy).bind(this),{signal:l(this,pi).combinedSignal(l(this,_r))})),l(this,ue)){l(this,ue).classList.remove("hidden");return}const e=m(this,ue,w(this,At,em).call(this));l(this,gi).append(e)},Vy=function(t){var e;(e=l(this,ue))!=null&&e.contains(t.target)||this.hideDropdown()},Pr=function(){return l(this,ue)&&!l(this,ue).classList.contains("hidden")},y(hs,Fc,null);let Cd=hs;const bt=class bt extends Ht{constructor(e){super({...e,name:"highlightEditor"});y(this,st);y(this,mh,null);y(this,Ic,0);y(this,On);y(this,Va,null);y(this,vh,null);y(this,ls,null);y(this,jc,null);y(this,Nc,0);y(this,Wa,null);y(this,Hs,null);y(this,As,null);y(this,_e,!1);y(this,bh,null);y(this,Dn);y(this,Le,null);y(this,yh,"");y(this,Gs);y(this,Bc,"");this.color=e.color||bt._defaultColor,m(this,Gs,e.thickness||bt._defaultThickness),m(this,Dn,e.opacity||bt._defaultOpacity),m(this,On,e.boxes||null),m(this,Bc,e.methodOfCreation||""),m(this,yh,e.text||""),this._isDraggable=!1,e.highlightId>-1?(m(this,_e,!0),w(this,st,vf).call(this,e),w(this,st,no).call(this)):l(this,On)&&(m(this,mh,e.anchorNode),m(this,Ic,e.anchorOffset),m(this,jc,e.focusNode),m(this,Nc,e.focusOffset),w(this,st,nm).call(this),w(this,st,no).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const e=bt.prototype;return ht(this,"_keyboardManager",new ll([[["ArrowLeft","mac+ArrowLeft"],e._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],e._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],e._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],e._moveCaret,{args:[3]}]]))}get telemetryInitialData(){return{action:"added",type:l(this,_e)?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:l(this,Gs),methodOfCreation:l(this,Bc)}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.highlightColorNames.get(this.color)}}static computeTelemetryFinalData(e){return{numberOfColors:e.get("color").size}}static initialize(e,s){var i;Ht.initialize(e,s),bt._defaultColor||(bt._defaultColor=((i=s.highlightColors)==null?void 0:i.values().next().value)||"#fff066")}static updateDefaultParams(e,s){switch(e){case dt.HIGHLIGHT_DEFAULT_COLOR:bt._defaultColor=s;break;case dt.HIGHLIGHT_THICKNESS:bt._defaultThickness=s;break}}translateInPage(e,s){}get toolbarPosition(){return l(this,bh)}updateParams(e,s){switch(e){case dt.HIGHLIGHT_COLOR:w(this,st,Wy).call(this,s);break;case dt.HIGHLIGHT_THICKNESS:w(this,st,zy).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[dt.HIGHLIGHT_DEFAULT_COLOR,bt._defaultColor],[dt.HIGHLIGHT_THICKNESS,bt._defaultThickness]]}get propertiesToUpdate(){return[[dt.HIGHLIGHT_COLOR,this.color||bt._defaultColor],[dt.HIGHLIGHT_THICKNESS,l(this,Gs)||bt._defaultThickness],[dt.HIGHLIGHT_FREE,l(this,_e)]]}async addEditToolbar(){const e=await super.addEditToolbar();return e?(this._uiManager.highlightColors&&(m(this,vh,new Cd({editor:this})),e.addColorPicker(l(this,vh))),e):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(w(this,st,tu).call(this))}getBaseTranslation(){return[0,0]}getRect(e,s){return super.getRect(e,s,w(this,st,tu).call(this))}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),e&&this.div.focus()}remove(){w(this,st,rm).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,st,no).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?w(this,st,rm).call(this):e&&(w(this,st,no).call(this,e),s=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),this.show(this._isVisible),s&&this.select()}rotate(e){var n,r,a;const{drawLayer:s}=this.parent;let i;l(this,_e)?(e=(e-this.rotation+360)%360,i=w(n=bt,Vs,Nh).call(n,l(this,Hs).box,e)):i=w(r=bt,Vs,Nh).call(r,[this.x,this.y,this.width,this.height],e),s.updateProperties(l(this,As),{bbox:i,root:{"data-main-rotation":e}}),s.updateProperties(l(this,Le),{bbox:w(a=bt,Vs,Nh).call(a,l(this,ls).box,e),root:{"data-main-rotation":e}})}render(){if(this.div)return this.div;const e=super.render();l(this,yh)&&(e.setAttribute("aria-label",l(this,yh)),e.setAttribute("role","mark")),l(this,_e)?e.classList.add("free"):this.div.addEventListener("keydown",w(this,st,Uy).bind(this),{signal:this._uiManager._signal});const s=m(this,Wa,document.createElement("div"));e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",s.style.clipPath=l(this,Va);const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),gd(this,l(this,Wa),["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Le),{rootClass:{hovered:!0}})}pointerleave(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Le),{rootClass:{hovered:!1}})}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:w(this,st,bf).call(this,!0);break;case 1:case 3:w(this,st,bf).call(this,!1);break}}select(){var e;super.select(),l(this,Le)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Le),{rootClass:{hovered:!1,selected:!0}}))}unselect(){var e;super.unselect(),l(this,Le)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Le),{rootClass:{selected:!1}}),l(this,_e)||w(this,st,bf).call(this,!1))}get _mustFixPosition(){return!l(this,_e)}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.updateProperties(l(this,As),{rootClass:{hidden:!e}}),this.parent.drawLayer.updateProperties(l(this,Le),{rootClass:{hidden:!e}}))}static startHighlighting(e,s,{target:i,x:n,y:r}){const{x:a,y:h,width:c,height:u}=i.getBoundingClientRect(),d=new AbortController,f=e.combinedSignal(d),g=p=>{d.abort(),w(this,Vs,Ky).call(this,e,p)};window.addEventListener("blur",g,{signal:f}),window.addEventListener("pointerup",g,{signal:f}),window.addEventListener("pointerdown",gs,{capture:!0,passive:!1,signal:f}),window.addEventListener("contextmenu",ii,{signal:f}),i.addEventListener("pointermove",w(this,Vs,qy).bind(this,e),{signal:f}),this._freeHighlight=new ip({x:n,y:r},[a,h,c,u],e.scale,this._defaultThickness/2,s,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0)}static async deserialize(e,s,i){var v,_,b,x;let n=null;if(e instanceof db){const{data:{quadPoints:C,rect:A,rotation:P,id:D,color:k,opacity:M,popupRef:R},parent:{page:{pageNumber:F}}}=e;n=e={annotationType:nt.HIGHLIGHT,color:Array.from(k),opacity:M,quadPoints:C,boxes:null,pageIndex:F-1,rect:A.slice(0),rotation:P,id:D,deleted:!1,popupRef:R}}else if(e instanceof tp){const{data:{inkLists:C,rect:A,rotation:P,id:D,color:k,borderStyle:{rawWidth:M},popupRef:R},parent:{page:{pageNumber:F}}}=e;n=e={annotationType:nt.HIGHLIGHT,color:Array.from(k),thickness:M,inkLists:C,boxes:null,pageIndex:F-1,rect:A.slice(0),rotation:P,id:D,deleted:!1,popupRef:R}}const{color:r,quadPoints:a,inkLists:h,opacity:c}=e,u=await super.deserialize(e,s,i);u.color=q.makeHexColor(...r),m(u,Dn,c||1),h&&m(u,Gs,e.thickness),u.annotationElementId=e.id||null,u._initialData=n;const[d,f]=u.pageDimensions,[g,p]=u.pageTranslation;if(a){const C=m(u,On,[]);for(let A=0;A<a.length;A+=8)C.push({x:(a[A]-g)/d,y:1-(a[A+1]-p)/f,width:(a[A+2]-a[A])/d,height:(a[A+1]-a[A+5])/f});w(v=u,st,nm).call(v),w(_=u,st,no).call(_),u.rotate(u.rotation)}else if(h){m(u,_e,!0);const C=h[0],A={x:C[0]-g,y:f-(C[1]-p)},P=new ip(A,[0,0,d,f],1,l(u,Gs)/2,!0,.001);for(let M=0,R=C.length;M<R;M+=2)A.x=C[M]-g,A.y=f-(C[M+1]-p),P.add(A);const{id:D,clipPathId:k}=s.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:u.color,"fill-opacity":u._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:P.toSVGPath()}},!0,!0);w(b=u,st,vf).call(b,{highlightOutlines:P.getOutlines(),highlightId:D,clipPathId:k}),w(x=u,st,no).call(x)}return u}serialize(e=!1){if(this.isEmpty()||e)return null;if(this.deleted)return this.serializeDeleted();const s=this.getRect(0,0),i=Ht._colorManager.convert(this.color),n={annotationType:nt.HIGHLIGHT,color:i,opacity:l(this,Dn),thickness:l(this,Gs),quadPoints:w(this,st,Yy).call(this),outlines:w(this,st,$y).call(this,s),pageIndex:this.pageIndex,rect:s,rotation:w(this,st,tu).call(this),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!w(this,st,Jy).call(this,n)?null:(n.id=this.annotationElementId,n)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};mh=new WeakMap,Ic=new WeakMap,On=new WeakMap,Va=new WeakMap,vh=new WeakMap,ls=new WeakMap,jc=new WeakMap,Nc=new WeakMap,Wa=new WeakMap,Hs=new WeakMap,As=new WeakMap,_e=new WeakMap,bh=new WeakMap,Dn=new WeakMap,Le=new WeakMap,yh=new WeakMap,Gs=new WeakMap,Bc=new WeakMap,st=new WeakSet,nm=function(){const e=new sp(l(this,On),.001);m(this,Hs,e.getOutlines()),[this.x,this.y,this.width,this.height]=l(this,Hs).box;const s=new sp(l(this,On),.0025,.001,this._uiManager.direction==="ltr");m(this,ls,s.getOutlines());const{lastPoint:i}=l(this,ls);m(this,bh,[(i[0]-this.x)/this.width,(i[1]-this.y)/this.height])},vf=function({highlightOutlines:e,highlightId:s,clipPathId:i}){var d,f;if(m(this,Hs,e),m(this,ls,e.getNewOutline(l(this,Gs)/2+1.5,.0025)),s>=0)m(this,As,s),m(this,Va,i),this.parent.drawLayer.finalizeDraw(s,{bbox:e.box,path:{d:e.toSVGPath()}}),m(this,Le,this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:l(this,ls).box,path:{d:l(this,ls).toSVGPath()}},!0));else if(this.parent){const g=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(l(this,As),{bbox:w(d=bt,Vs,Nh).call(d,l(this,Hs).box,(g-this.rotation+360)%360),path:{d:e.toSVGPath()}}),this.parent.drawLayer.updateProperties(l(this,Le),{bbox:w(f=bt,Vs,Nh).call(f,l(this,ls).box,g),path:{d:l(this,ls).toSVGPath()}})}const[r,a,h,c]=e.box;switch(this.rotation){case 0:this.x=r,this.y=a,this.width=h,this.height=c;break;case 90:{const[g,p]=this.parentDimensions;this.x=a,this.y=1-r,this.width=h*p/g,this.height=c*g/p;break}case 180:this.x=1-r,this.y=1-a,this.width=h,this.height=c;break;case 270:{const[g,p]=this.parentDimensions;this.x=1-a,this.y=r,this.width=h*p/g,this.height=c*g/p;break}}const{lastPoint:u}=l(this,ls);m(this,bh,[(u[0]-r)/h,(u[1]-a)/c])},Wy=function(e){const s=(r,a)=>{var h,c;this.color=r,m(this,Dn,a),(h=this.parent)==null||h.drawLayer.updateProperties(l(this,As),{root:{fill:r,"fill-opacity":a}}),(c=l(this,vh))==null||c.updateColor(r)},i=this.color,n=l(this,Dn);this.addCommands({cmd:s.bind(this,e,bt._defaultOpacity),undo:s.bind(this,i,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:dt.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(e)},!0)},zy=function(e){const s=l(this,Gs),i=n=>{m(this,Gs,n),w(this,st,Xy).call(this,n)};this.addCommands({cmd:i.bind(this,e),undo:i.bind(this,s),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:dt.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)},Xy=function(e){if(!l(this,_e))return;w(this,st,vf).call(this,{highlightOutlines:l(this,Hs).getNewOutline(e/2)}),this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)},rm=function(){l(this,As)===null||!this.parent||(this.parent.drawLayer.remove(l(this,As)),m(this,As,null),this.parent.drawLayer.remove(l(this,Le)),m(this,Le,null))},no=function(e=this.parent){l(this,As)===null&&({id:Ze(this,As)._,clipPathId:Ze(this,Va)._}=e.drawLayer.draw({bbox:l(this,Hs).box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":l(this,Dn)},rootClass:{highlight:!0,free:l(this,_e)},path:{d:l(this,Hs).toSVGPath()}},!1,!0),m(this,Le,e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:l(this,_e)},bbox:l(this,ls).box,path:{d:l(this,ls).toSVGPath()}},l(this,_e))),l(this,Wa)&&(l(this,Wa).style.clipPath=l(this,Va)))},Vs=new WeakSet,Nh=function([e,s,i,n],r){switch(r){case 90:return[1-s-n,e,n,i];case 180:return[1-e-i,1-s-n,i,n];case 270:return[s,1-e-i,n,i]}return[e,s,i,n]},Uy=function(e){bt._keyboardManager.exec(this,e)},bf=function(e){if(!l(this,mh))return;const s=window.getSelection();e?s.setPosition(l(this,mh),l(this,Ic)):s.setPosition(l(this,jc),l(this,Nc))},tu=function(){return l(this,_e)?this.rotation:0},Yy=function(){if(l(this,_e))return null;const[e,s]=this.pageDimensions,[i,n]=this.pageTranslation,r=l(this,On),a=new Float32Array(r.length*8);let h=0;for(const{x:c,y:u,width:d,height:f}of r){const g=c*e+i,p=(1-u)*s+n;a[h]=a[h+4]=g,a[h+1]=a[h+3]=p,a[h+2]=a[h+6]=g+d*e,a[h+5]=a[h+7]=p-f*s,h+=8}return a},$y=function(e){return l(this,Hs).serialize(e,w(this,st,tu).call(this))},qy=function(e,s){this._freeHighlight.add(s)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})},Ky=function(e,s){this._freeHighlight.isEmpty()?e.drawLayer.remove(this._freeHighlightId):e.createAndAddNewEditor(s,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:"main_toolbar"}),this._freeHighlightId=-1,this._freeHighlight=null,this._freeHighlightClipId=""},Jy=function(e){const{color:s}=this._initialData;return e.color.some((i,n)=>i!==s[n])},y(bt,Vs),J(bt,"_defaultColor",null),J(bt,"_defaultOpacity",1),J(bt,"_defaultThickness",12),J(bt,"_type","highlight"),J(bt,"_editorType",nt.HIGHLIGHT),J(bt,"_freeHighlightId",-1),J(bt,"_freeHighlight",null),J(bt,"_freeHighlightClipId","");let Ad=bt;class LC{constructor(){y(this,za,Object.create(null))}updateProperty(t,e){this[t]=e,this.updateSVGProperty(t,e)}updateProperties(t){if(t)for(const[e,s]of Object.entries(t))this.updateProperty(e,s)}updateSVGProperty(t,e){l(this,za)[t]=e}toSVGProperties(){const t=l(this,za);return m(this,za,Object.create(null)),{root:t}}reset(){m(this,za,Object.create(null))}updateAll(t=this){this.updateProperties(t)}clone(){Et("Not implemented")}}za=new WeakMap;const U=class U extends Ht{constructor(e){super(e);y(this,mt);y(this,Ts,null);y(this,_h);J(this,"_drawId",null);m(this,_h,e.mustBeCommitted||!1),e.drawOutlines&&(w(this,mt,am).call(this,e),w(this,mt,eu).call(this))}static _mergeSVGProperties(e,s){const i=new Set(Object.keys(e));for(const[n,r]of Object.entries(s))i.has(n)?Object.assign(e[n],r):e[n]=r;return e}static getDefaultDrawingOptions(e){Et("Not implemented")}static get typesMap(){Et("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(e,s){const i=this.typesMap.get(e);i&&this._defaultDrawingOptions.updateProperty(i,s),this._currentParent&&(l(U,pe).updateProperty(i,s),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(e,s){const i=this.constructor.typesMap.get(e);i&&this._updateProperty(e,i,s)}static get defaultPropertiesToUpdate(){const e=[],s=this._defaultDrawingOptions;for(const[i,n]of this.typesMap)e.push([i,s[n]]);return e}get propertiesToUpdate(){const e=[],{_drawingOptions:s}=this;for(const[i,n]of this.constructor.typesMap)e.push([i,s[n]]);return e}_updateProperty(e,s,i){const n=this._drawingOptions,r=n[s],a=h=>{var u;n.updateProperty(s,h);const c=l(this,Ts).updateProperty(s,h);c&&w(this,mt,su).call(this,c),(u=this.parent)==null||u.drawLayer.updateProperties(this._drawId,n.toSVGProperties())};this.addCommands({cmd:a.bind(this,i),undo:a.bind(this,r),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:e,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,U._mergeSVGProperties(l(this,Ts).getPathResizingSVGProperties(w(this,mt,yf).call(this)),{bbox:w(this,mt,Bh).call(this)}))}_onResized(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,U._mergeSVGProperties(l(this,Ts).getPathResizedSVGProperties(w(this,mt,yf).call(this)),{bbox:w(this,mt,Bh).call(this)}))}_onTranslating(e,s){var i;(i=this.parent)==null||i.drawLayer.updateProperties(this._drawId,{bbox:w(this,mt,Bh).call(this,e,s)})}_onTranslated(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,U._mergeSVGProperties(l(this,Ts).getPathTranslatedSVGProperties(w(this,mt,yf).call(this),this.parentDimensions),{bbox:w(this,mt,Bh).call(this)}))}_onStartDragging(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}commit(){super.commit(),this.disableEditMode(),this.disableEditing()}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),this._isDraggable=!0,l(this,_h)&&(m(this,_h,!1),this.commit(),this.parent.setSelected(this),e&&this.isOnScreen&&this.div.focus())}remove(){w(this,mt,hm).call(this),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,mt,eu).call(this),w(this,mt,su).call(this,l(this,Ts).box),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?(this._uiManager.removeShouldRescale(this),w(this,mt,hm).call(this)):e&&(this._uiManager.addShouldRescale(this),w(this,mt,eu).call(this,e),s=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),s&&this.select()}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,U._mergeSVGProperties({bbox:w(this,mt,Bh).call(this)},l(this,Ts).updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&w(this,mt,su).call(this,l(this,Ts).updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;const e=super.render();e.classList.add("draw");const s=document.createElement("div");e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal";const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),this._uiManager.addShouldRescale(this),this.disableEditing(),e}static createDrawerInstance(e,s,i,n,r){Et("Not implemented")}static startDrawing(e,s,i,n){var _;const{target:r,offsetX:a,offsetY:h,pointerId:c,pointerType:u}=n;if(l(U,xr)&&l(U,xr)!==u)return;const{viewport:{rotation:d}}=e,{width:f,height:g}=r.getBoundingClientRect(),p=m(U,Xa,new AbortController),v=e.combinedSignal(p);if(l(U,wr)||m(U,wr,c),l(U,xr)??m(U,xr,u),window.addEventListener("pointerup",b=>{var x;l(U,wr)===b.pointerId?this._endDraw(b):(x=l(U,Sr))==null||x.delete(b.pointerId)},{signal:v}),window.addEventListener("pointercancel",b=>{var x;l(U,wr)===b.pointerId?this._currentParent.endDrawingSession():(x=l(U,Sr))==null||x.delete(b.pointerId)},{signal:v}),window.addEventListener("pointerdown",b=>{l(U,xr)===b.pointerType&&((l(U,Sr)||m(U,Sr,new Set)).add(b.pointerId),l(U,pe).isCancellable()&&(l(U,pe).removeLastElement(),l(U,pe).isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:v}),window.addEventListener("contextmenu",ii,{signal:v}),r.addEventListener("pointermove",this._drawMove.bind(this),{signal:v}),r.addEventListener("touchmove",b=>{b.timeStamp===l(U,Ya)&&gs(b)},{signal:v}),e.toggleDrawing(),(_=s._editorUndoBar)==null||_.hide(),l(U,pe)){e.drawLayer.updateProperties(this._currentDrawId,l(U,pe).startNew(a,h,f,g,d));return}s.updateUIForDefaultProperties(this),m(U,pe,this.createDrawerInstance(a,h,f,g,d)),m(U,Ua,this.getDefaultDrawingOptions()),this._currentParent=e,{id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties(l(U,Ua).toSVGProperties(),l(U,pe).defaultSVGProperties),!0,!1)}static _drawMove(e){var r;if(m(U,Ya,-1),!l(U,pe))return;const{offsetX:s,offsetY:i,pointerId:n}=e;if(l(U,wr)===n){if(((r=l(U,Sr))==null?void 0:r.size)>=1){this._endDraw(e);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,l(U,pe).add(s,i)),m(U,Ya,e.timeStamp),gs(e)}}static _cleanup(e){e&&(this._currentDrawId=-1,this._currentParent=null,m(U,pe,null),m(U,Ua,null),m(U,xr,null),m(U,Ya,NaN)),l(U,Xa)&&(l(U,Xa).abort(),m(U,Xa,null),m(U,wr,NaN),m(U,Sr,null))}static _endDraw(e){const s=this._currentParent;if(s){if(s.toggleDrawing(!0),this._cleanup(!1),e&&s.drawLayer.updateProperties(this._currentDrawId,l(U,pe).end(e.offsetX,e.offsetY)),this.supportMultipleDrawings){const i=l(U,pe),n=this._currentDrawId,r=i.getLastElement();s.addCommands({cmd:()=>{s.drawLayer.updateProperties(n,i.setLastElement(r))},undo:()=>{s.drawLayer.updateProperties(n,i.removeLastElement())},mustExec:!1,type:dt.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(e){const s=this._currentParent;if(!s)return null;if(s.toggleDrawing(!0),s.cleanUndoStack(dt.DRAW_STEP),!l(U,pe).isEmpty()){const{pageDimensions:[i,n],scale:r}=s,a=s.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:l(U,pe).getOutlines(i*r,n*r,r,this._INNER_MARGIN),drawingOptions:l(U,Ua),mustBeCommitted:!e});return this._cleanup(!0),a}return s.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(e){}static deserializeDraw(e,s,i,n,r,a){Et("Not implemented")}static async deserialize(e,s,i){var d,f;const{rawDims:{pageWidth:n,pageHeight:r,pageX:a,pageY:h}}=s.viewport,c=this.deserializeDraw(a,h,n,r,this._INNER_MARGIN,e),u=await super.deserialize(e,s,i);return u.createDrawingOptions(e),w(d=u,mt,am).call(d,{drawOutlines:c}),w(f=u,mt,eu).call(f),u.onScaleChanging(),u.rotate(),u}serializeDraw(e){const[s,i]=this.pageTranslation,[n,r]=this.pageDimensions;return l(this,Ts).serialize([s,i,n,r],e)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};Ts=new WeakMap,_h=new WeakMap,pe=new WeakMap,Xa=new WeakMap,Ua=new WeakMap,wr=new WeakMap,xr=new WeakMap,Sr=new WeakMap,Ya=new WeakMap,mt=new WeakSet,am=function({drawOutlines:e,drawId:s,drawingOptions:i}){m(this,Ts,e),this._drawingOptions||(this._drawingOptions=i),s>=0?(this._drawId=s,this.parent.drawLayer.finalizeDraw(s,e.defaultProperties)):this._drawId=w(this,mt,om).call(this,e,this.parent),w(this,mt,su).call(this,e.box)},om=function(e,s){const{id:i}=s.drawLayer.draw(U._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return i},hm=function(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())},eu=function(e=this.parent){if(!(this._drawId!==null&&this.parent===e)){if(this._drawId!==null){this.parent.drawLayer.updateParent(this._drawId,e.drawLayer);return}this._drawingOptions.updateAll(),this._drawId=w(this,mt,om).call(this,l(this,Ts),e)}},Qy=function([e,s,i,n]){const{parentDimensions:[r,a],rotation:h}=this;switch(h){case 90:return[s,1-e,i*(a/r),n*(r/a)];case 180:return[1-e,1-s,i,n];case 270:return[1-s,e,i*(a/r),n*(r/a)];default:return[e,s,i,n]}},yf=function(){const{x:e,y:s,width:i,height:n,parentDimensions:[r,a],rotation:h}=this;switch(h){case 90:return[1-s,e,i*(r/a),n*(a/r)];case 180:return[1-e,1-s,i,n];case 270:return[s,1-e,i*(r/a),n*(a/r)];default:return[e,s,i,n]}},su=function(e){if([this.x,this.y,this.width,this.height]=w(this,mt,Qy).call(this,e),this.div){this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)}this._onResized()},Bh=function(){const{x:e,y:s,width:i,height:n,rotation:r,parentRotation:a,parentDimensions:[h,c]}=this;switch((r*4+a)/90){case 1:return[1-s-n,e,n,i];case 2:return[1-e-i,1-s-n,i,n];case 3:return[s,1-e-i,n,i];case 4:return[e,s-i*(h/c),n*(c/h),i*(h/c)];case 5:return[1-s,e,i*(h/c),n*(c/h)];case 6:return[1-e-n*(c/h),1-s,n*(c/h),i*(h/c)];case 7:return[s-i*(h/c),1-e-n*(c/h),i*(h/c),n*(c/h)];case 8:return[e-i,s-n,i,n];case 9:return[1-s,e-i,n,i];case 10:return[1-e,1-s,i,n];case 11:return[s-n,1-e,n,i];case 12:return[e-n*(c/h),s,n*(c/h),i*(h/c)];case 13:return[1-s-i*(h/c),e-n*(c/h),i*(h/c),n*(c/h)];case 14:return[1-e,1-s-i*(h/c),n*(c/h),i*(h/c)];case 15:return[s,1-e,i*(h/c),n*(c/h)];default:return[e,s,i,n]}},J(U,"_currentDrawId",-1),J(U,"_currentParent",null),y(U,pe,null),y(U,Xa,null),y(U,Ua,null),y(U,wr,NaN),y(U,xr,null),y(U,Sr,null),y(U,Ya,NaN),J(U,"_INNER_MARGIN",3);let np=U;class FC{constructor(t,e,s,i,n,r){y(this,xh);y(this,Ni,new Float64Array(6));y(this,me);y(this,ve);y(this,$a);y(this,wh);y(this,$e);y(this,we,"");y(this,Ws,0);y(this,qa,new Td);y(this,Ka);y(this,Ja);m(this,Ka,s),m(this,Ja,i),m(this,$a,n),m(this,wh,r),[t,e]=w(this,xh,_f).call(this,t,e);const a=m(this,me,[NaN,NaN,NaN,NaN,t,e]);m(this,$e,[t,e]),m(this,ve,[{line:a,points:l(this,$e)}]),l(this,Ni).set(a,0)}updateProperty(t,e){t==="stroke-width"&&m(this,wh,e)}isEmpty(){return!l(this,ve)||l(this,ve).length===0}isCancellable(){return l(this,$e).length<=10}add(t,e){[t,e]=w(this,xh,_f).call(this,t,e);const[s,i,n,r]=l(this,Ni).subarray(2,6),a=t-n,h=e-r;return Math.hypot(l(this,Ka)*a,l(this,Ja)*h)<=2?null:(l(this,$e).push(t,e),isNaN(s)?(l(this,Ni).set([n,r,t,e],2),l(this,me).push(NaN,NaN,NaN,NaN,t,e),{path:{d:this.toSVGPath()}}):(isNaN(l(this,Ni)[0])&&l(this,me).splice(6,6),l(this,Ni).set([s,i,n,r,t,e],0),l(this,me).push(...X.createBezierPoints(s,i,n,r,t,e)),{path:{d:this.toSVGPath()}}))}end(t,e){const s=this.add(t,e);return s||(l(this,$e).length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,s,i,n){m(this,Ka,s),m(this,Ja,i),m(this,$a,n),[t,e]=w(this,xh,_f).call(this,t,e);const r=m(this,me,[NaN,NaN,NaN,NaN,t,e]);m(this,$e,[t,e]);const a=l(this,ve).at(-1);return a&&(a.line=new Float32Array(a.line),a.points=new Float32Array(a.points)),l(this,ve).push({line:r,points:l(this,$e)}),l(this,Ni).set(r,0),m(this,Ws,0),this.toSVGPath(),null}getLastElement(){return l(this,ve).at(-1)}setLastElement(t){return l(this,ve)?(l(this,ve).push(t),m(this,me,t.line),m(this,$e,t.points),m(this,Ws,0),{path:{d:this.toSVGPath()}}):l(this,qa).setLastElement(t)}removeLastElement(){if(!l(this,ve))return l(this,qa).removeLastElement();l(this,ve).pop(),m(this,we,"");for(let t=0,e=l(this,ve).length;t<e;t++){const{line:s,points:i}=l(this,ve)[t];m(this,me,s),m(this,$e,i),m(this,Ws,0),this.toSVGPath()}return{path:{d:l(this,we)}}}toSVGPath(){const t=X.svgRound(l(this,me)[4]),e=X.svgRound(l(this,me)[5]);if(l(this,$e).length===2)return m(this,we,`${l(this,we)} M ${t} ${e} Z`),l(this,we);if(l(this,$e).length<=6){const i=l(this,we).lastIndexOf("M");m(this,we,`${l(this,we).slice(0,i)} M ${t} ${e}`),m(this,Ws,6)}if(l(this,$e).length===4){const i=X.svgRound(l(this,me)[10]),n=X.svgRound(l(this,me)[11]);return m(this,we,`${l(this,we)} L ${i} ${n}`),m(this,Ws,12),l(this,we)}const s=[];l(this,Ws)===0&&(s.push(`M ${t} ${e}`),m(this,Ws,6));for(let i=l(this,Ws),n=l(this,me).length;i<n;i+=6){const[r,a,h,c,u,d]=l(this,me).slice(i,i+6).map(X.svgRound);s.push(`C${r} ${a} ${h} ${c} ${u} ${d}`)}return m(this,we,l(this,we)+s.join(" ")),m(this,Ws,l(this,me).length),l(this,we)}getOutlines(t,e,s,i){const n=l(this,ve).at(-1);return n.line=new Float32Array(n.line),n.points=new Float32Array(n.points),l(this,qa).build(l(this,ve),t,e,s,l(this,$a),l(this,wh),i),m(this,Ni,null),m(this,me,null),m(this,ve,null),m(this,we,null),l(this,qa)}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}Ni=new WeakMap,me=new WeakMap,ve=new WeakMap,$a=new WeakMap,wh=new WeakMap,$e=new WeakMap,we=new WeakMap,Ws=new WeakMap,qa=new WeakMap,Ka=new WeakMap,Ja=new WeakMap,xh=new WeakSet,_f=function(t,e){return X._normalizePoint(t,e,l(this,Ka),l(this,Ja),l(this,$a))};const gp=class gp extends X{constructor(){super(...arguments);y(this,xe);y(this,qe);y(this,Hc,0);y(this,Gc);y(this,Es);y(this,Bi);y(this,Hi);y(this,Sh);y(this,Ch);y(this,Ah)}build(e,s,i,n,r,a,h){m(this,Bi,s),m(this,Hi,i),m(this,Sh,n),m(this,Ch,r),m(this,Ah,a),m(this,Gc,h??0),m(this,Es,e),w(this,xe,t_).call(this)}setLastElement(e){return l(this,Es).push(e),{path:{d:this.toSVGPath()}}}removeLastElement(){return l(this,Es).pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const e=[];for(const{line:s}of l(this,Es)){if(e.push(`M${X.svgRound(s[4])} ${X.svgRound(s[5])}`),s.length===6){e.push("Z");continue}if(s.length===12){e.push(`L${X.svgRound(s[10])} ${X.svgRound(s[11])}`);continue}for(let i=6,n=s.length;i<n;i+=6){const[r,a,h,c,u,d]=s.subarray(i,i+6).map(X.svgRound);e.push(`C${r} ${a} ${h} ${c} ${u} ${d}`)}}return e.join("")}serialize([e,s,i,n],r){const a=[],h=[],[c,u,d,f]=w(this,xe,Zy).call(this);let g,p,v,_,b,x,C,A,P;switch(l(this,Ch)){case 0:P=X._rescale,g=e,p=s+n,v=i,_=-n,b=e+c*i,x=s+(1-u-f)*n,C=e+(c+d)*i,A=s+(1-u)*n;break;case 90:P=X._rescaleAndSwap,g=e,p=s,v=i,_=n,b=e+u*i,x=s+c*n,C=e+(u+f)*i,A=s+(c+d)*n;break;case 180:P=X._rescale,g=e+i,p=s,v=-i,_=n,b=e+(1-c-d)*i,x=s+u*n,C=e+(1-c)*i,A=s+(u+f)*n;break;case 270:P=X._rescaleAndSwap,g=e+i,p=s+n,v=-i,_=-n,b=e+(1-u-f)*i,x=s+(1-c-d)*n,C=e+(1-u)*i,A=s+(1-c)*n;break}for(const{line:D,points:k}of l(this,Es))a.push(P(D,g,p,v,_,r?new Array(D.length):null)),h.push(P(k,g,p,v,_,r?new Array(k.length):null));return{lines:a,points:h,rect:[b,x,C,A]}}static deserialize(e,s,i,n,r,{paths:{lines:a,points:h},rotation:c,thickness:u}){const d=[];let f,g,p,v,_;switch(c){case 0:_=X._rescale,f=-e/i,g=s/n+1,p=1/i,v=-1/n;break;case 90:_=X._rescaleAndSwap,f=-s/n,g=-e/i,p=1/n,v=1/i;break;case 180:_=X._rescale,f=e/i+1,g=-s/n,p=-1/i,v=1/n;break;case 270:_=X._rescaleAndSwap,f=s/n+1,g=e/i+1,p=-1/n,v=-1/i;break}if(!a){a=[];for(const x of h){const C=x.length;if(C===2){a.push(new Float32Array([NaN,NaN,NaN,NaN,x[0],x[1]]));continue}if(C===4){a.push(new Float32Array([NaN,NaN,NaN,NaN,x[0],x[1],NaN,NaN,NaN,NaN,x[2],x[3]]));continue}const A=new Float32Array(3*(C-2));a.push(A);let[P,D,k,M]=x.subarray(0,4);A.set([NaN,NaN,NaN,NaN,P,D],0);for(let R=4;R<C;R+=2){const F=x[R],I=x[R+1];A.set(X.createBezierPoints(P,D,k,M,F,I),(R-2)*3),[P,D,k,M]=[k,M,F,I]}}}for(let x=0,C=a.length;x<C;x++)d.push({line:_(a[x].map(A=>A??NaN),f,g,p,v),points:_(h[x].map(A=>A??NaN),f,g,p,v)});const b=new gp;return b.build(d,i,n,1,c,u,r),b}get box(){return l(this,qe)}updateProperty(e,s){return e==="stroke-width"?w(this,xe,e_).call(this,s):null}updateParentDimensions([e,s],i){const[n,r]=w(this,xe,Nn).call(this);m(this,Bi,e),m(this,Hi,s),m(this,Sh,i);const[a,h]=w(this,xe,Nn).call(this),c=a-n,u=h-r,d=l(this,qe);return d[0]-=c,d[1]-=u,d[2]+=2*c,d[3]+=2*u,d}updateRotation(e){return m(this,Hc,e),{path:{transform:this.rotationTransform}}}get viewBox(){return l(this,qe).map(X.svgRound).join(" ")}get defaultProperties(){const[e,s]=l(this,qe);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${X.svgRound(e)} ${X.svgRound(s)}`}}}get rotationTransform(){const[,,e,s]=l(this,qe);let i=0,n=0,r=0,a=0,h=0,c=0;switch(l(this,Hc)){case 90:n=s/e,r=-e/s,h=e;break;case 180:i=-1,a=-1,h=e,c=s;break;case 270:n=-s/e,r=e/s,c=s;break;default:return""}return`matrix(${i} ${n} ${r} ${a} ${X.svgRound(h)} ${X.svgRound(c)})`}getPathResizingSVGProperties([e,s,i,n]){const[r,a]=w(this,xe,Nn).call(this),[h,c,u,d]=l(this,qe);if(Math.abs(u-r)<=X.PRECISION||Math.abs(d-a)<=X.PRECISION){const _=e+i/2-(h+u/2),b=s+n/2-(c+d/2);return{path:{"transform-origin":`${X.svgRound(e)} ${X.svgRound(s)}`,transform:`${this.rotationTransform} translate(${_} ${b})`}}}const f=(i-2*r)/(u-2*r),g=(n-2*a)/(d-2*a),p=u/i,v=d/n;return{path:{"transform-origin":`${X.svgRound(h)} ${X.svgRound(c)}`,transform:`${this.rotationTransform} scale(${p} ${v}) translate(${X.svgRound(r)} ${X.svgRound(a)}) scale(${f} ${g}) translate(${X.svgRound(-r)} ${X.svgRound(-a)})`}}}getPathResizedSVGProperties([e,s,i,n]){const[r,a]=w(this,xe,Nn).call(this),h=l(this,qe),[c,u,d,f]=h;if(h[0]=e,h[1]=s,h[2]=i,h[3]=n,Math.abs(d-r)<=X.PRECISION||Math.abs(f-a)<=X.PRECISION){const b=e+i/2-(c+d/2),x=s+n/2-(u+f/2);for(const{line:C,points:A}of l(this,Es))X._translate(C,b,x,C),X._translate(A,b,x,A);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${X.svgRound(e)} ${X.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const g=(i-2*r)/(d-2*r),p=(n-2*a)/(f-2*a),v=-g*(c+r)+e+r,_=-p*(u+a)+s+a;if(g!==1||p!==1||v!==0||_!==0)for(const{line:b,points:x}of l(this,Es))X._rescale(b,v,_,g,p,b),X._rescale(x,v,_,g,p,x);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${X.svgRound(e)} ${X.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,s],i){const[n,r]=i,a=l(this,qe),h=e-a[0],c=s-a[1];if(l(this,Bi)===n&&l(this,Hi)===r)for(const{line:u,points:d}of l(this,Es))X._translate(u,h,c,u),X._translate(d,h,c,d);else{const u=l(this,Bi)/n,d=l(this,Hi)/r;m(this,Bi,n),m(this,Hi,r);for(const{line:f,points:g}of l(this,Es))X._rescale(f,h,c,u,d,f),X._rescale(g,h,c,u,d,g);a[2]*=u,a[3]*=d}return a[0]=e,a[1]=s,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${X.svgRound(e)} ${X.svgRound(s)}`}}}get defaultSVGProperties(){const e=l(this,qe);return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${X.svgRound(e[0])} ${X.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}};qe=new WeakMap,Hc=new WeakMap,Gc=new WeakMap,Es=new WeakMap,Bi=new WeakMap,Hi=new WeakMap,Sh=new WeakMap,Ch=new WeakMap,Ah=new WeakMap,xe=new WeakSet,Nn=function(e=l(this,Ah)){const s=l(this,Gc)+e/2*l(this,Sh);return l(this,Ch)%180===0?[s/l(this,Bi),s/l(this,Hi)]:[s/l(this,Hi),s/l(this,Bi)]},Zy=function(){const[e,s,i,n]=l(this,qe),[r,a]=w(this,xe,Nn).call(this,0);return[e+r,s+a,i-2*r,n-2*a]},t_=function(){const e=m(this,qe,new Float32Array([1/0,1/0,-1/0,-1/0]));for(const{line:n}of l(this,Es)){if(n.length<=12){for(let h=4,c=n.length;h<c;h+=6){const[u,d]=n.subarray(h,h+2);e[0]=Math.min(e[0],u),e[1]=Math.min(e[1],d),e[2]=Math.max(e[2],u),e[3]=Math.max(e[3],d)}continue}let r=n[4],a=n[5];for(let h=6,c=n.length;h<c;h+=6){const[u,d,f,g,p,v]=n.subarray(h,h+6);q.bezierBoundingBox(r,a,u,d,f,g,p,v,e),r=p,a=v}}const[s,i]=w(this,xe,Nn).call(this);e[0]=Math.min(1,Math.max(0,e[0]-s)),e[1]=Math.min(1,Math.max(0,e[1]-i)),e[2]=Math.min(1,Math.max(0,e[2]+s)),e[3]=Math.min(1,Math.max(0,e[3]+i)),e[2]-=e[0],e[3]-=e[1]},e_=function(e){const[s,i]=w(this,xe,Nn).call(this);m(this,Ah,e);const[n,r]=w(this,xe,Nn).call(this),[a,h]=[n-s,r-i],c=l(this,qe);return c[0]-=a,c[1]-=h,c[2]+=2*a,c[3]+=2*h,c};let Td=gp;const pp=class pp extends LC{constructor(e){super();y(this,Th);m(this,Th,e),super.updateProperties({fill:"none",stroke:Ht._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(e,s){e==="stroke-width"&&(s??(s=this["stroke-width"]),s*=l(this,Th).realScale),super.updateSVGProperty(e,s)}clone(){const e=new pp(l(this,Th));return e.updateAll(this),e}};Th=new WeakMap;let rp=pp;const Eh=class Eh extends np{constructor(e){super({...e,name:"inkEditor"});y(this,zd);this._willKeepAspectRatio=!0}static initialize(e,s){Ht.initialize(e,s),this._defaultDrawingOptions=new rp(s.viewParameters)}static getDefaultDrawingOptions(e){const s=this._defaultDrawingOptions.clone();return s.updateProperties(e),s}static get supportMultipleDrawings(){return!0}static get typesMap(){return ht(this,"typesMap",new Map([[dt.INK_THICKNESS,"stroke-width"],[dt.INK_COLOR,"stroke"],[dt.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(e,s,i,n,r){return new FC(e,s,i,n,r,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(e,s,i,n,r,a){return Td.deserialize(e,s,i,n,r,a)}static async deserialize(e,s,i){let n=null;if(e instanceof tp){const{data:{inkLists:a,rect:h,rotation:c,id:u,color:d,opacity:f,borderStyle:{rawWidth:g},popupRef:p},parent:{page:{pageNumber:v}}}=e;n=e={annotationType:nt.INK,color:Array.from(d),thickness:g,opacity:f,paths:{points:a},boxes:null,pageIndex:v-1,rect:h.slice(0),rotation:c,id:u,deleted:!1,popupRef:p}}const r=await super.deserialize(e,s,i);return r.annotationElementId=e.id||null,r._initialData=n,r}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();const{_drawId:e,_drawingOptions:s,parent:i}=this;s.updateSVGProperty("stroke-width"),i.drawLayer.updateProperties(e,s.toSVGProperties())}static onScaleChangingWhenDrawing(){const e=this._currentParent;e&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),e.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:e,thickness:s,opacity:i}){this._drawingOptions=Eh.getDefaultDrawingOptions({stroke:q.makeHexColor(...e),"stroke-width":s,"stroke-opacity":i})}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:s,points:i,rect:n}=this.serializeDraw(e),{_drawingOptions:{stroke:r,"stroke-opacity":a,"stroke-width":h}}=this,c={annotationType:nt.INK,color:Ht._colorManager.convert(r),opacity:a,thickness:h,paths:{lines:s,points:i},pageIndex:this.pageIndex,rect:n,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?c:this.annotationElementId&&!w(this,zd,s_).call(this,c)?null:(c.id=this.annotationElementId,c)}renderAnnotationElement(e){const{points:s,rect:i}=this.serializeDraw(!1);return e.updateEdited({rect:i,thickness:this._drawingOptions["stroke-width"],points:s}),null}};zd=new WeakSet,s_=function(e){const{color:s,thickness:i,opacity:n,pageIndex:r}=this._initialData;return this._hasBeenMoved||this._hasBeenResized||e.color.some((a,h)=>a!==s[h])||e.thickness!==i||e.opacity!==n||e.pageIndex!==r},J(Eh,"_type","ink"),J(Eh,"_editorType",nt.INK),J(Eh,"_defaultDrawingOptions",null);let ap=Eh;const Vc=class Vc extends Ht{constructor(e){super({...e,name:"stampEditor"});y(this,vt);y(this,Vt,null);y(this,Se,null);y(this,Cr,null);y(this,Rn,null);y(this,Ar,null);y(this,kh,"");y(this,Gi,null);y(this,Vi,null);y(this,ks,!1);y(this,Ph,!1);m(this,Rn,e.bitmapUrl),m(this,Ar,e.bitmapFile)}static initialize(e,s){Ht.initialize(e,s)}static get supportedTypes(){return ht(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(s=>`image/${s}`))}static get supportedTypesStr(){return ht(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(e){return this.supportedTypes.includes(e)}static paste(e,s){s.pasteEditor(nt.STAMP,{bitmapFile:e.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){var e;return{type:"stamp",hasAltText:!!((e=this.altTextData)!=null&&e.altText)}}static computeTelemetryFinalData(e){const s=e.get("hasAltText");return{hasAltText:s.get(!0)??0,hasNoAltText:s.get(!1)??0}}async mlGuessAltText(e=null,s=!0){if(this.hasAltTextData())return null;const{mlManager:i}=this._uiManager;if(!i)throw new Error("No ML.");if(!await i.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:n,width:r,height:a}=e||this.copyCanvas(null,null,!0).imageData,h=await i.guess({name:"altText",request:{data:n,width:r,height:a,channels:n.length/(r*a)}});if(!h)throw new Error("No response from the AI service.");if(h.error)throw new Error("Error from the AI service.");if(h.cancel)return null;if(!h.output)throw new Error("No valid response from the AI service.");const c=h.output;return await this.setGuessedAltText(c),s&&!this.hasAltTextData()&&(this.altTextData={alt:c,decorative:!1}),c}remove(){var e;l(this,Se)&&(m(this,Vt,null),this._uiManager.imageManager.deleteId(l(this,Se)),(e=l(this,Gi))==null||e.remove(),m(this,Gi,null),l(this,Vi)&&(clearTimeout(l(this,Vi)),m(this,Vi,null))),super.remove()}rebuild(){if(!this.parent){l(this,Se)&&w(this,vt,wf).call(this);return}super.rebuild(),this.div!==null&&(l(this,Se)&&l(this,Gi)===null&&w(this,vt,wf).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(e){this._isDraggable=!0,e&&this.div.focus()}isEmpty(){return!(l(this,Cr)||l(this,Vt)||l(this,Rn)||l(this,Ar)||l(this,Se))}get isResizable(){return!0}render(){if(this.div)return this.div;let e,s;if(this.width&&(e=this.x,s=this.y),super.render(),this.div.hidden=!0,this.div.setAttribute("role","figure"),this.addAltTextButton(),l(this,Vt)?w(this,vt,lm).call(this):w(this,vt,wf).call(this),this.width&&!this.annotationElementId){const[i,n]=this.parentDimensions;this.setAt(e*i,s*n,this.width*i,this.height*n)}return this._uiManager.addShouldRescale(this),this.div}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;l(this,Vi)!==null&&clearTimeout(l(this,Vi)),m(this,Vi,setTimeout(()=>{m(this,Vi,null),w(this,vt,cm).call(this)},200))}copyCanvas(e,s,i=!1){var g;e||(e=224);const{width:n,height:r}=l(this,Vt),a=new Ng;let h=l(this,Vt),c=n,u=r,d=null;if(s){if(n>s||r>s){const M=Math.min(s/n,s/r);c=Math.floor(n*M),u=Math.floor(r*M)}d=document.createElement("canvas");const p=d.width=Math.ceil(c*a.sx),v=d.height=Math.ceil(u*a.sy);l(this,ks)||(h=w(this,vt,xf).call(this,p,v));const _=d.getContext("2d");_.filter=this._uiManager.hcmFilter;let b="white",x="#cfcfd8";this._uiManager.hcmFilter!=="none"?x="black":(g=window.matchMedia)!=null&&g.call(window,"(prefers-color-scheme: dark)").matches&&(b="#8f8f9d",x="#42414d");const C=15,A=C*a.sx,P=C*a.sy,D=new OffscreenCanvas(A*2,P*2),k=D.getContext("2d");k.fillStyle=b,k.fillRect(0,0,A*2,P*2),k.fillStyle=x,k.fillRect(0,0,A,P),k.fillRect(A,P,A,P),_.fillStyle=_.createPattern(D,"repeat"),_.fillRect(0,0,p,v),_.drawImage(h,0,0,h.width,h.height,0,0,p,v)}let f=null;if(i){let p,v;if(a.symmetric&&h.width<e&&h.height<e)p=h.width,v=h.height;else if(h=l(this,Vt),n>e||r>e){const x=Math.min(e/n,e/r);p=Math.floor(n*x),v=Math.floor(r*x),l(this,ks)||(h=w(this,vt,xf).call(this,p,v))}const b=new OffscreenCanvas(p,v).getContext("2d",{willReadFrequently:!0});b.drawImage(h,0,0,h.width,h.height,0,0,p,v),f={width:p,height:v,data:b.getImageData(0,0,p,v).data}}return{canvas:d,width:c,height:u,imageData:f}}getImageForAltText(){return l(this,Gi)}static async deserialize(e,s,i){var v;let n=null;if(e instanceof fb){const{data:{rect:_,rotation:b,id:x,structParent:C,popupRef:A},container:P,parent:{page:{pageNumber:D}}}=e,k=P.querySelector("canvas"),M=i.imageManager.getFromCanvas(P.id,k);k.remove();const R=((v=await s._structTree.getAriaAttributes(`${Rg}${x}`))==null?void 0:v.get("aria-label"))||"";n=e={annotationType:nt.STAMP,bitmapId:M.id,bitmap:M.bitmap,pageIndex:D-1,rect:_.slice(0),rotation:b,id:x,deleted:!1,accessibilityData:{decorative:!1,altText:R},isSvg:!1,structParent:C,popupRef:A}}const r=await super.deserialize(e,s,i),{rect:a,bitmap:h,bitmapUrl:c,bitmapId:u,isSvg:d,accessibilityData:f}=e;u&&i.imageManager.isValidId(u)?(m(r,Se,u),h&&m(r,Vt,h)):m(r,Rn,c),m(r,ks,d);const[g,p]=r.pageDimensions;return r.width=(a[2]-a[0])/g,r.height=(a[3]-a[1])/p,r.annotationElementId=e.id||null,f&&(r.altTextData=f),r._initialData=n,m(r,Ph,!!n),r}serialize(e=!1,s=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const i={annotationType:nt.STAMP,bitmapId:l(this,Se),pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:l(this,ks),structTreeParentId:this._structTreeParentId};if(e)return i.bitmapUrl=w(this,vt,Sf).call(this,!0),i.accessibilityData=this.serializeAltText(!0),i;const{decorative:n,altText:r}=this.serializeAltText(!1);if(!n&&r&&(i.accessibilityData={type:"Figure",alt:r}),this.annotationElementId){const h=w(this,vt,i_).call(this,i);if(h.isSame)return null;h.isSameAltText?delete i.accessibilityData:i.accessibilityData.structParent=this._initialData.structParent??-1}if(i.id=this.annotationElementId,s===null)return i;s.stamps||(s.stamps=new Map);const a=l(this,ks)?(i.rect[2]-i.rect[0])*(i.rect[3]-i.rect[1]):null;if(!s.stamps.has(l(this,Se)))s.stamps.set(l(this,Se),{area:a,serialized:i}),i.bitmap=w(this,vt,Sf).call(this,!1);else if(l(this,ks)){const h=s.stamps.get(l(this,Se));a>h.area&&(h.area=a,h.serialized.bitmap.close(),h.serialized.bitmap=w(this,vt,Sf).call(this,!1))}return i}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}};Vt=new WeakMap,Se=new WeakMap,Cr=new WeakMap,Rn=new WeakMap,Ar=new WeakMap,kh=new WeakMap,Gi=new WeakMap,Vi=new WeakMap,ks=new WeakMap,Ph=new WeakMap,vt=new WeakSet,iu=function(e,s=!1){if(!e){this.remove();return}m(this,Vt,e.bitmap),s||(m(this,Se,e.id),m(this,ks,e.isSvg)),e.file&&m(this,kh,e.file.name),w(this,vt,lm).call(this)},nu=function(){if(m(this,Cr,null),this._uiManager.enableWaiting(!1),!!l(this,Gi)){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Vt)){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Vt)){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}},wf=function(){if(l(this,Se)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(l(this,Se)).then(i=>w(this,vt,iu).call(this,i,!0)).finally(()=>w(this,vt,nu).call(this));return}if(l(this,Rn)){const i=l(this,Rn);m(this,Rn,null),this._uiManager.enableWaiting(!0),m(this,Cr,this._uiManager.imageManager.getFromUrl(i).then(n=>w(this,vt,iu).call(this,n)).finally(()=>w(this,vt,nu).call(this)));return}if(l(this,Ar)){const i=l(this,Ar);m(this,Ar,null),this._uiManager.enableWaiting(!0),m(this,Cr,this._uiManager.imageManager.getFromFile(i).then(n=>w(this,vt,iu).call(this,n)).finally(()=>w(this,vt,nu).call(this)));return}const e=document.createElement("input");e.type="file",e.accept=Vc.supportedTypesStr;const s=this._uiManager._signal;m(this,Cr,new Promise(i=>{e.addEventListener("change",async()=>{if(!e.files||e.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const n=await this._uiManager.imageManager.getFromFile(e.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),w(this,vt,iu).call(this,n)}i()},{signal:s}),e.addEventListener("cancel",()=>{this.remove(),i()},{signal:s})}).finally(()=>w(this,vt,nu).call(this))),e.click()},lm=function(){var d;const{div:e}=this;let{width:s,height:i}=l(this,Vt);const[n,r]=this.pageDimensions,a=.75;if(this.width)s=this.width*n,i=this.height*r;else if(s>a*n||i>a*r){const f=Math.min(a*n/s,a*r/i);s*=f,i*=f}const[h,c]=this.parentDimensions;this.setDims(s*h/n,i*c/r),this._uiManager.enableWaiting(!1);const u=m(this,Gi,document.createElement("canvas"));u.setAttribute("role","img"),this.addContainer(u),this.width=s/n,this.height=i/r,(d=this._initialOptions)!=null&&d.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(e.hidden=!1),w(this,vt,cm).call(this),l(this,Ph)||(this.parent.addUndoableEditor(this),m(this,Ph,!0)),this._reportTelemetry({action:"inserted_image"}),l(this,kh)&&u.setAttribute("aria-label",l(this,kh))},xf=function(e,s){const{width:i,height:n}=l(this,Vt);let r=i,a=n,h=l(this,Vt);for(;r>2*e||a>2*s;){const c=r,u=a;r>2*e&&(r=r>=16384?Math.floor(r/2)-1:Math.ceil(r/2)),a>2*s&&(a=a>=16384?Math.floor(a/2)-1:Math.ceil(a/2));const d=new OffscreenCanvas(r,a);d.getContext("2d").drawImage(h,0,0,c,u,0,0,r,a),h=d.transferToImageBitmap()}return h},cm=function(){const[e,s]=this.parentDimensions,{width:i,height:n}=this,r=new Ng,a=Math.ceil(i*e*r.sx),h=Math.ceil(n*s*r.sy),c=l(this,Gi);if(!c||c.width===a&&c.height===h)return;c.width=a,c.height=h;const u=l(this,ks)?l(this,Vt):w(this,vt,xf).call(this,a,h),d=c.getContext("2d");d.filter=this._uiManager.hcmFilter,d.drawImage(u,0,0,u.width,u.height,0,0,a,h)},Sf=function(e){if(e){if(l(this,ks)){const n=this._uiManager.imageManager.getSvgUrl(l(this,Se));if(n)return n}const s=document.createElement("canvas");return{width:s.width,height:s.height}=l(this,Vt),s.getContext("2d").drawImage(l(this,Vt),0,0),s.toDataURL()}if(l(this,ks)){const[s,i]=this.pageDimensions,n=Math.round(this.width*s*Kn.PDF_TO_CSS_UNITS),r=Math.round(this.height*i*Kn.PDF_TO_CSS_UNITS),a=new OffscreenCanvas(n,r);return a.getContext("2d").drawImage(l(this,Vt),0,0,l(this,Vt).width,l(this,Vt).height,0,0,n,r),a.transferToImageBitmap()}return structuredClone(l(this,Vt))},i_=function(e){var a;const{pageIndex:s,accessibilityData:{altText:i}}=this._initialData,n=e.pageIndex===s,r=(((a=e.accessibilityData)==null?void 0:a.alt)||"")===i;return{isSame:!this._hasBeenMoved&&!this._hasBeenResized&&n&&r,isSameAltText:r}},J(Vc,"_type","stamp"),J(Vc,"_editorType",nt.STAMP);let op=Vc;const vi=class vi{constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:a,textLayer:h,viewport:c,l10n:u}){y(this,Nt);y(this,Qa);y(this,Mh,!1);y(this,Wi,null);y(this,Tr,null);y(this,Ln,null);y(this,zs,new Map);y(this,Er,!1);y(this,Oh,!1);y(this,Za,!1);y(this,mi,null);y(this,Fn,null);y(this,Fe,null);y(this,In,null);y(this,$);const d=[...l(vi,kr).values()];if(!vi._initialized){vi._initialized=!0;for(const f of d)f.initialize(u,t)}t.registerEditorTypes(d),m(this,$,t),this.pageIndex=e,this.div=s,m(this,Qa,n),m(this,Wi,r),this.viewport=c,m(this,Fe,h),this.drawLayer=a,this._structTree=i,l(this,$).addLayer(this)}get isEmpty(){return l(this,zs).size===0}get isInvisible(){return this.isEmpty&&l(this,$).getMode()===nt.NONE}updateToolbar(t){l(this,$).updateToolbar(t)}updateMode(t=l(this,$).getMode()){switch(w(this,Nt,Cf).call(this),t){case nt.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case nt.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case nt.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);const{classList:e}=this.div;for(const s of l(vi,kr).values())e.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){var e;return t===((e=l(this,Fe))==null?void 0:e.div)}setEditingState(t){l(this,$).setEditingState(t)}addCommands(t){l(this,$).addCommands(t)}cleanUndoStack(t){l(this,$).cleanUndoStack(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){var e;(e=l(this,Wi))==null||e.div.classList.toggle("disabled",!t)}async enable(){m(this,Za,!0),this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const s of l(this,zs).values())s.enableEditing(),s.show(!0),s.annotationElementId&&(l(this,$).removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!l(this,Wi)){m(this,Za,!1);return}const e=l(this,Wi).getEditableAnnotations();for(const s of e){if(s.hide(),l(this,$).isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;const i=await this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}m(this,Za,!1)}disable(){var i;m(this,Oh,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,e=new Map;for(const n of l(this,zs).values())if(n.disableEditing(),!!n.annotationElementId){if(n.serialize()!==null){t.set(n.annotationElementId,n);continue}else e.set(n.annotationElementId,n);(i=this.getEditableAnnotation(n.annotationElementId))==null||i.show(),n.remove()}if(l(this,Wi)){const n=l(this,Wi).getEditableAnnotations();for(const r of n){const{id:a}=r.data;if(l(this,$).isDeletedAnnotationElement(a))continue;let h=e.get(a);if(h){h.resetAnnotationElement(r),h.show(!1),r.show();continue}h=t.get(a),h&&(l(this,$).addChangedExistingAnnotation(h),h.renderAnnotationElement(r)&&h.show(!1)),r.show()}}w(this,Nt,Cf).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const n of l(vi,kr).values())s.remove(`${n._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),m(this,Oh,!1)}getEditableAnnotation(t){var e;return((e=l(this,Wi))==null?void 0:e.getEditableAnnotation(t))||null}setActiveEditor(t){l(this,$).getActive()!==t&&l(this,$).setActiveEditor(t)}enableTextSelection(){var t;if(this.div.tabIndex=-1,(t=l(this,Fe))!=null&&t.div&&!l(this,In)){m(this,In,new AbortController);const e=l(this,$).combinedSignal(l(this,In));l(this,Fe).div.addEventListener("pointerdown",w(this,Nt,n_).bind(this),{signal:e}),l(this,Fe).div.classList.add("highlighting")}}disableTextSelection(){var t;this.div.tabIndex=0,(t=l(this,Fe))!=null&&t.div&&l(this,In)&&(l(this,In).abort(),m(this,In,null),l(this,Fe).div.classList.remove("highlighting"))}enableClick(){if(l(this,Tr))return;m(this,Tr,new AbortController);const t=l(this,$).combinedSignal(l(this,Tr));this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t});const e=this.pointerup.bind(this);this.div.addEventListener("pointerup",e,{signal:t}),this.div.addEventListener("pointercancel",e,{signal:t})}disableClick(){var t;(t=l(this,Tr))==null||t.abort(),m(this,Tr,null)}attach(t){l(this,zs).set(t.id,t);const{annotationElementId:e}=t;e&&l(this,$).isDeletedAnnotationElement(e)&&l(this,$).removeDeletedAnnotationElement(t)}detach(t){var e;l(this,zs).delete(t.id),(e=l(this,Qa))==null||e.removePointerInTextLayer(t.contentDiv),!l(this,Oh)&&t.annotationElementId&&l(this,$).addDeletedAnnotationElement(t)}remove(t){this.detach(t),l(this,$).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){var e;t.parent!==this&&(t.parent&&t.annotationElementId&&(l(this,$).addDeletedAnnotationElement(t.annotationElementId),Ht.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),(e=t.parent)==null||e.detach(t),t.setParent(this),t.div&&t.isAttachedToDOM&&(t.div.remove(),this.div.append(t.div)))}add(t){if(!(t.parent===this&&t.isAttachedToDOM)){if(this.changeParent(t),l(this,$).addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!l(this,Za)),l(this,$).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var s;if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!l(this,Ln)&&(t._focusEventsAllowed=!1,m(this,Ln,setTimeout(()=>{m(this,Ln,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:l(this,$)._signal}),e.focus())},0))),t._structTreeParentId=(s=l(this,Qa))==null?void 0:s.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){t.needsToBeRebuilt()?(t.parent||(t.parent=this),t.rebuild(),t.show()):this.add(t)}addUndoableEditor(t){const e=()=>t._uiManager.rebuild(t),s=()=>{t.remove()};this.addCommands({cmd:e,undo:s,mustExec:!1})}getNextId(){return l(this,$).getId()}combinedSignal(t){return l(this,$).combinedSignal(t)}canCreateNewEmptyEditor(){var t;return(t=l(this,Nt,Ui))==null?void 0:t.canCreateNewEmptyEditor()}pasteEditor(t,e){l(this,$).updateToolbar(t),l(this,$).updateMode(t);const{offsetX:s,offsetY:i}=w(this,Nt,dm).call(this),n=this.getNextId(),r=w(this,Nt,um).call(this,{parent:this,id:n,x:s,y:i,uiManager:l(this,$),isCentered:!0,...e});r&&this.add(r)}async deserialize(t){var e;return await((e=l(vi,kr).get(t.annotationType??t.annotationEditorType))==null?void 0:e.deserialize(t,this,l(this,$)))||null}createAndAddNewEditor(t,e,s={}){const i=this.getNextId(),n=w(this,Nt,um).call(this,{parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:l(this,$),isCentered:e,...s});return n&&this.add(n),n}addNewEditor(){this.createAndAddNewEditor(w(this,Nt,dm).call(this),!0)}setSelected(t){l(this,$).setSelected(t)}toggleSelected(t){l(this,$).toggleSelected(t)}unselect(t){l(this,$).unselect(t)}pointerup(t){var s;const{isMac:e}=ze.platform;if(!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&l(this,Er)&&(m(this,Er,!1),!((s=l(this,Nt,Ui))!=null&&s.isDrawer&&l(this,Nt,Ui).supportMultipleDrawings))){if(!l(this,Mh)){m(this,Mh,!0);return}if(l(this,$).getMode()===nt.STAMP){l(this,$).unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){var i;if(l(this,$).getMode()===nt.HIGHLIGHT&&this.enableTextSelection(),l(this,Er)){m(this,Er,!1);return}const{isMac:e}=ze.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;if(m(this,Er,!0),(i=l(this,Nt,Ui))!=null&&i.isDrawer){this.startDrawingSession(t);return}const s=l(this,$).getActive();m(this,Mh,!s||s.isEmpty())}startDrawingSession(t){if(this.div.focus(),l(this,mi)){l(this,Nt,Ui).startDrawing(this,l(this,$),!1,t);return}l(this,$).setCurrentDrawingSession(this),m(this,mi,new AbortController);const e=l(this,$).combinedSignal(l(this,mi));this.div.addEventListener("blur",({relatedTarget:s})=>{s&&!this.div.contains(s)&&(m(this,Fn,null),this.commitOrRemove())},{signal:e}),l(this,Nt,Ui).startDrawing(this,l(this,$),!1,t)}pause(t){if(t){const{activeElement:e}=document;this.div.contains(e)&&m(this,Fn,e);return}l(this,Fn)&&setTimeout(()=>{var e;(e=l(this,Fn))==null||e.focus(),m(this,Fn,null)},0)}endDrawingSession(t=!1){return l(this,mi)?(l(this,$).setCurrentDrawingSession(null),l(this,mi).abort(),m(this,mi,null),m(this,Fn,null),l(this,Nt,Ui).endDrawing(t)):null}findNewParent(t,e,s){const i=l(this,$).findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}commitOrRemove(){return l(this,mi)?(this.endDrawingSession(),!0):!1}onScaleChanging(){l(this,mi)&&l(this,Nt,Ui).onScaleChangingWhenDrawing(this)}destroy(){var t,e;this.commitOrRemove(),((t=l(this,$).getActive())==null?void 0:t.parent)===this&&(l(this,$).commitOrRemove(),l(this,$).setActiveEditor(null)),l(this,Ln)&&(clearTimeout(l(this,Ln)),m(this,Ln,null));for(const s of l(this,zs).values())(e=l(this,Qa))==null||e.removePointerInTextLayer(s.contentDiv),s.setParent(null),s.isAttachedToDOM=!1,s.div.remove();this.div=null,l(this,zs).clear(),l(this,$).removeLayer(this)}render({viewport:t}){this.viewport=t,zr(this.div,t);for(const e of l(this,$).getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){l(this,$).commitOrRemove(),w(this,Nt,Cf).call(this);const e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,zr(this.div,{rotation:s}),e!==s)for(const i of l(this,zs).values())i.rotate(s)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return l(this,$).viewParameters.realScale}};Qa=new WeakMap,Mh=new WeakMap,Wi=new WeakMap,Tr=new WeakMap,Ln=new WeakMap,zs=new WeakMap,Er=new WeakMap,Oh=new WeakMap,Za=new WeakMap,mi=new WeakMap,Fn=new WeakMap,Fe=new WeakMap,In=new WeakMap,$=new WeakMap,kr=new WeakMap,Nt=new WeakSet,n_=function(t){l(this,$).unselectAll();const{target:e}=t;if(e===l(this,Fe).div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&l(this,Fe).div.contains(e)){const{isMac:s}=ze.platform;if(t.button!==0||t.ctrlKey&&s)return;l(this,$).showAllEditors("highlight",!0,!0),l(this,Fe).div.classList.add("free"),this.toggleDrawing(),Ad.startHighlighting(this,l(this,$).direction==="ltr",{target:l(this,Fe).div,x:t.x,y:t.y}),l(this,Fe).div.addEventListener("pointerup",()=>{l(this,Fe).div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:l(this,$)._signal}),t.preventDefault()}},Ui=function(){return l(vi,kr).get(l(this,$).getMode())},um=function(t){const e=l(this,Nt,Ui);return e?new e.prototype.constructor(t):null},dm=function(){const{x:t,y:e,width:s,height:i}=this.div.getBoundingClientRect(),n=Math.max(0,t),r=Math.max(0,e),a=Math.min(window.innerWidth,t+s),h=Math.min(window.innerHeight,e+i),c=(n+a)/2-t,u=(r+h)/2-e,[d,f]=this.viewport.rotation%180===0?[c,u]:[u,c];return{offsetX:d,offsetY:f}},Cf=function(){for(const t of l(this,zs).values())t.isEmpty()&&t.remove()},J(vi,"_initialized",!1),y(vi,kr,new Map([ep,ap,op,Ad].map(t=>[t._editorType,t])));let hp=vi;const Ie=class Ie{constructor({pageIndex:t}){y(this,zi);y(this,bi,null);y(this,Wc,0);y(this,Ke,new Map);y(this,to,new Map);this.pageIndex=t}setParent(t){if(!l(this,bi)){m(this,bi,t);return}if(l(this,bi)!==t){if(l(this,Ke).size>0)for(const e of l(this,Ke).values())e.remove(),t.append(e);m(this,bi,t)}}static get _svgFactory(){return ht(this,"_svgFactory",new Qg)}draw(t,e=!1,s=!1){const i=Ze(this,Wc)._++,n=w(this,zi,fm).call(this),r=Ie._svgFactory.createElement("defs");n.append(r);const a=Ie._svgFactory.createElement("path");r.append(a);const h=`path_p${this.pageIndex}_${i}`;a.setAttribute("id",h),a.setAttribute("vector-effect","non-scaling-stroke"),e&&l(this,to).set(i,a);const c=s?w(this,zi,a_).call(this,r,h):null,u=Ie._svgFactory.createElement("use");return n.append(u),u.setAttribute("href",`#${h}`),this.updateProperties(n,t),l(this,Ke).set(i,n),{id:i,clipPathId:`url(#${c})`}}drawOutline(t,e){const s=Ze(this,Wc)._++,i=w(this,zi,fm).call(this),n=Ie._svgFactory.createElement("defs");i.append(n);const r=Ie._svgFactory.createElement("path");n.append(r);const a=`path_p${this.pageIndex}_${s}`;r.setAttribute("id",a),r.setAttribute("vector-effect","non-scaling-stroke");let h;if(e){const d=Ie._svgFactory.createElement("mask");n.append(d),h=`mask_p${this.pageIndex}_${s}`,d.setAttribute("id",h),d.setAttribute("maskUnits","objectBoundingBox");const f=Ie._svgFactory.createElement("rect");d.append(f),f.setAttribute("width","1"),f.setAttribute("height","1"),f.setAttribute("fill","white");const g=Ie._svgFactory.createElement("use");d.append(g),g.setAttribute("href",`#${a}`),g.setAttribute("stroke","none"),g.setAttribute("fill","black"),g.setAttribute("fill-rule","nonzero"),g.classList.add("mask")}const c=Ie._svgFactory.createElement("use");i.append(c),c.setAttribute("href",`#${a}`),h&&c.setAttribute("mask",`url(#${h})`);const u=c.cloneNode();return i.append(u),c.classList.add("mainOutline"),u.classList.add("secondaryOutline"),this.updateProperties(i,t),l(this,Ke).set(s,i),s}finalizeDraw(t,e){l(this,to).delete(t),this.updateProperties(t,e)}updateProperties(t,e){var h;if(!e)return;const{root:s,bbox:i,rootClass:n,path:r}=e,a=typeof t=="number"?l(this,Ke).get(t):t;if(a){if(s&&w(this,zi,gm).call(this,a,s),i&&w(h=Ie,Xd,r_).call(h,a,i),n){const{classList:c}=a;for(const[u,d]of Object.entries(n))c.toggle(u,d)}if(r){const u=a.firstChild.firstChild;w(this,zi,gm).call(this,u,r)}}}updateParent(t,e){if(e===this)return;const s=l(this,Ke).get(t);s&&(l(e,bi).append(s),l(this,Ke).delete(t),l(e,Ke).set(t,s))}remove(t){l(this,to).delete(t),l(this,bi)!==null&&(l(this,Ke).get(t).remove(),l(this,Ke).delete(t))}destroy(){m(this,bi,null);for(const t of l(this,Ke).values())t.remove();l(this,Ke).clear(),l(this,to).clear()}};bi=new WeakMap,Wc=new WeakMap,Ke=new WeakMap,to=new WeakMap,Xd=new WeakSet,r_=function(t,[e,s,i,n]){const{style:r}=t;r.top=`${100*s}%`,r.left=`${100*e}%`,r.width=`${100*i}%`,r.height=`${100*n}%`},zi=new WeakSet,fm=function(){const t=Ie._svgFactory.create(1,1,!0);return l(this,bi).append(t),t.setAttribute("aria-hidden",!0),t},a_=function(t,e){const s=Ie._svgFactory.createElement("clipPath");t.append(s);const i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=Ie._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i},gm=function(t,e){for(const[s,i]of Object.entries(e))i===null?t.removeAttribute(s):t.setAttribute(s,i)},y(Ie,Xd);let lp=Ie;globalThis.pdfjsTestingUtils={HighlightOutliner:sp},Z.AbortException,Z.AnnotationEditorLayer,Z.AnnotationEditorParamsType,Z.AnnotationEditorType,Z.AnnotationEditorUIManager,Z.AnnotationLayer,Z.AnnotationMode,Z.ColorPicker,Z.DOMSVGFactory,Z.DrawLayer,Z.FeatureTest;var IC=Z.GlobalWorkerOptions;Z.ImageKind,Z.InvalidPDFException,Z.MissingPDFException,Z.OPS,Z.OutputScale,Z.PDFDataRangeTransport,Z.PDFDateString,Z.PDFWorker,Z.PasswordResponses,Z.PermissionFlag,Z.PixelsPerInch,Z.RenderingCancelledException,Z.TextLayer,Z.TouchManager,Z.UnexpectedResponseException,Z.Util,Z.VerbosityLevel,Z.XfaLayer,Z.build,Z.createValidAbsoluteUrl,Z.fetchData;var jC=Z.getDocument;Z.getFilenameFromUrl,Z.getPdfFilenameFromUrl,Z.getXfaPageViewport,Z.isDataScheme,Z.isPdfFile,Z.noContextMenu,Z.normalizeUnicode,Z.setLayerDimensions,Z.shadow,Z.stopEvent,Z.version;const NC={"pdfjs-dist":"4.10.38"};function BC(o){return new Promise((t,e)=>{const s=new FileReader;s.addEventListener("load",()=>t(s.result)),s.addEventListener("error",e),s.readAsDataURL(o)})}const HC=NC["pdfjs-dist"].replace("^","");IC.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${HC}/pdf.worker.min.mjs`;async function GC(o){const t="data:application/pdf;base64,",e=await BC(o);if(typeof e=="string")return window.atob(e.slice(t.length))}function VC(o,t){return jC({data:o,password:t}).promise}const WC="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2040%2040'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3ccircle%20cx='20'%20cy='20'%20r='10.75'%20stroke='currentColor'%20stroke-width='2.5'/%3e%3cpath%20d='M16%2024L23.7782%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3cpath%20d='M24%2024L16.2218%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3c/svg%3e";function zC(o){return new URL(Object.assign({"../assets/close.svg":WC})[`../assets/${o}`],typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Mt&&Mt.tagName.toUpperCase()==="SCRIPT"&&Mt.src||new URL("pdf-canvas.umd.js",document.baseURI).href).href}function XC(o){return new Promise((t,e)=>{const s=window.URL.createObjectURL(o),i=new Image;i.src=s,i.addEventListener("load",async()=>{window.URL.revokeObjectURL(s),t(await UC(i))}),i.addEventListener("error",n=>{window.URL.revokeObjectURL(s),e(n)})})}function UC(o){return new Promise(t=>{const e=document.createElement("canvas"),s=e.getContext("2d"),{naturalWidth:i,naturalHeight:n}=o;e.width=i,e.height=n,s==null||s.drawImage(o,0,0,i,n),t(e.toDataURL("image/jpeg",.8))})}let pb=null;function YC(){const o=document.createElement("div");o.style.width="1in",document.body.append(o);const t=o.offsetWidth;return o.remove(),t}function $C(){const o=pb??YC();return pb=o,o/72}function qC(o,t=500){if(typeof o!="function")throw new TypeError("The first argument is not a function.");let e=null;return function(...s){e&&clearTimeout(e),e=setTimeout(()=>{e=null,o.apply(this,s)},t)}}const Ls=new Map;function KC(o){const t=new fg(o);return Ls.set(o,t),t}function JC(o,t){const e=Date.now();return{PDFId:`${o.name}-${e}`,name:o.name.replace(/.pdf/,""),updateDate:e,PDFBase64:t}}function QC(o,t){const e=o.getViewport({scale:t}),s=document.createElement("canvas"),i=s.getContext("2d"),n=$C()/window.devicePixelRatio;s.width=Math.floor(e.width*n),s.height=Math.floor(e.height*n);const r={canvasContext:i,viewport:e,transform:[n,0,0,n,0,0]},a=o.render(r);return{canvas:s,renderTask:a}}async function ZC(o,t,e){const s=o||zC("close.svg"),{objects:i,options:n}=await Tx(s),r=i.filter(h=>h!==null),a=Hw.groupSVGElements(r,n);return r.forEach(h=>{h.stroke=t}),a.hoverCursor="pointer",a.stroke=`${t}-${e}`,a}function tA(o,t){if(!Ls.get(o))return;const s=1/3,i=aA(t,s);vb(o,i,s)}async function eA(o,t){const e=await XC(t),s=Date.now(),n={PDFId:`${t.name}${s}`,name:t.name.replace(/.png|.jpg|.jpeg/,""),updateDate:s,PDFBase64:e};return mb(o,{url:e}),{...n,pages:1}}async function mb(o,{url:t,scale:e=.5}){if(!Ls.get(o))return;const i=await ke.fromURL(t);i.scale(e),vb(o,i,e)}function vb(o,t,e){const s=Ls.get(o);s&&(s.setWidth(t.width*e),s.setHeight(t.height*e),s.backgroundImage=t,s.renderAll())}function vl(o,t){if(!t)return;const{oCoords:e}=o;if(!e)return;const{x:s,y:i}=e.tl.touchCorner.tl,{height:n,width:r,scaleY:a,scaleX:h}=t;t.top=i-n*a/2,t.left=s-r*h/2,t.setCoords()}function sA(o,t,e){!e||!o||(e.scale(1/t),vl(o,e))}function iA(o,t,e){o&&(o.borderScaleFactor=1/t,o.cornerSize=6*(1/t),o.touchCornerSize=24*(1/t),o.cornerStrokeColor=e.stroke,o.setCoords())}function nA(o){const t=Ls.get(o);t&&(t.discardActiveObject(),t.renderAll())}function rA(o){const t=Ls.get(o);t&&(t.clear(),Ls.delete(o))}function aA(o,t){return new ke(o,{scaleX:t,scaleY:t})}const oA={top:100,left:50,scaleX:.5,scaleY:.5,borderColor:"black",cornerStrokeColor:"black",cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},hA={top:100,left:50,fontFamily:"helvetica",borderColor:"black",cornerStrokeColor:"black",scaleX:.7,scaleY:.7,cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},lA={stroke:"#000",hoverStroke:"#B7EC5D",src:""};function bb(o=""){const t=Q.useRef(0),e=Q.useRef(null),s=Q.useRef(null),i=Q.useRef(1),n=Q.useRef({...lA});function r(){if(!o||Ls.has(o))return;const k=KC(o);return k.on("selection:cleared",()=>A(k)),k}function a(k,M){var I;const R=k.type,F={"application/pdf":h,"image/png":d,"image/jpeg":d};return((I=F[R])==null?void 0:I.call(F,k,M))??Promise.reject(new Error(`Unsupported ${R} file type.`))}async function h(k,M){const R=await GC(k);if(!R)return;const F=JC(k,R);try{return await c({page:1,PDFBase64:R,scale:.8,password:M}),{...F,pages:t.current}}catch(I){return Promise.reject(I)}}async function c({page:k,PDFBase64:M,scale:R,password:F}){try{const I=await VC(M,F),Y=await I.getPage(k),{renderTask:N,canvas:H}=QC(Y,R);return t.current=I.numPages,N.promise.then(()=>u(H))}catch(I){return Promise.reject(I)}}function u(k){tA(o,k)}async function d(k){return await eA(o,k)}async function f({url:k,scale:M=.5}){await mb(o,{url:k,scale:M})}async function g(k,M){const R=Ls.get(o);if(!R)return;const F=await ke.fromURL(k,{},{...oA,...M});R.add(F),v(R,F)}function p(k,M){const R=Ls.get(o);if(!R)return;const F=new Ee(k,{...hA,...M});R.add(F),v(R,F)}function v(k,M){M.on("selected",R=>_({canvas:k,target:R.target})),M.on("modified",R=>vl(R.target,e.current)),M.on("scaling",R=>vl(R.transform.target,e.current)),M.on("moving",R=>vl(R.transform.target,e.current)),M.on("rotating",R=>vl(R.transform.target,e.current))}async function _({canvas:k,target:M,stroke:R=n.current.stroke,uuid:F=Date.now()}){var Y;if(((Y=e.current)==null?void 0:Y.stroke)===`${R}-${F}`)return;const I=await ZC(n.current.src,R,F);A(k),e.current=I,s.current=M,b(k,M,F),x(i.current,!0),k.add(I)}function b(k,M,R){e.current&&(e.current.on("selected",()=>{k.remove(M),A(k)}),e.current.on("mouseover",()=>{_({canvas:k,target:M,stroke:n.current.hoverStroke,uuid:R})}),e.current.on("mouseout",()=>{_({canvas:k,target:M,stroke:n.current.stroke,uuid:R})}))}function x(k,M=!1){const R=Ls.get(o);i.current=k,R&&(iA(s.current,k,n.current),sA(s.current,k,e.current),!M&&R.renderAll())}function C(k){if(!k)return;n.current={...n.current,...k};const M=Ls.get(o);!e||!s.current||!M||_({target:s.current,canvas:M})}function A(k){e.current&&(k.remove(e.current),e.current=s.current=null)}function P(){nA(o)}function D(){rA(o)}return{createCanvas:r,loadFile:a,specifyPage:c,renderImage:f,addFabric:g,addTextFabric:p,clearActive:P,deleteCanvas:D,scaleFabric:x,setCloseSvgOptions:C}}function cA(o){let t=0;const e=qC(()=>{t!==window.innerWidth&&(t=window.innerWidth,o())});Q.useEffect(()=>(window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)),[])}const uA=Q.forwardRef(dA);function dA({file:o,page:t=1,canvasId:e="PDF-canvas",fileZoom:s=1,fileScale:i=1,canvasScale:n=1,canvasClass:r="",isDrop:a=!1,password:h,dropTextOptions:c,dropImageOptions:u,closeSvgOptions:d},f){const g=Q.useRef(null),p=`${e}-${t-1}`,v=Q.useMemo(()=>s*n,[s,n]),{createCanvas:_,specifyPage:b,addFabric:x,addTextFabric:C,renderImage:A,clearActive:P,deleteCanvas:D,scaleFabric:k,setCloseSvgOptions:M}=bb(p);cA(R);async function R(){window.requestAnimationFrame(async()=>{if(_(),o.PDFBase64.startsWith("data:image")||o.canvas){const{canvas:N}=o,H=N?7:3,at=N!=null&&N.length?N[t-1]:o.PDFBase64;A({url:at,scale:i/H});return}await b({page:t,PDFBase64:o.PDFBase64,scale:i,password:h})})}function F(N){if(N.preventDefault(),N.stopPropagation(),!a||!N.dataTransfer)return;const{dataTransfer:H,clientX:at,clientY:j}=N,W=H.getData("text/plain"),it=H.getData("text/uri-list"),kt={left:at-71,top:j-55};it?I(it,kt):W&&Y(W,kt)}function I(N,H){x(N,{...H,...u})}function Y(N,H){C(N,{...H,...c})}return Q.useImperativeHandle(f,()=>({addImage:I,addText:Y,clearActive:P,deleteCanvas:D,canvasRef:g})),Q.useEffect(()=>{R()},[i,t,o,h]),Q.useEffect(()=>{k(v)},[v]),Q.useEffect(()=>{M(d)},[d]),Q.useEffect(()=>()=>D(),[]),vm.jsx("div",{style:{transform:`scale(${v})`},onDragOver:N=>N.preventDefault(),onDragEnter:N=>N.preventDefault(),onDrop:F,children:vm.jsx("canvas",{id:p,ref:g,className:r})})}ut.default=uA,ut.useFabric=bb,Object.defineProperties(ut,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
538
+ `)){const s=document.createElement("div");s.append(e?document.createTextNode(e):document.createElement("br")),this.editorDiv.append(s)}},My=function(){return l(this,ws).replaceAll(" "," ")},Zp=function(e){return e.replaceAll(" "," ")},Oy=function(e){const{value:s,fontSize:i,color:n,pageIndex:r}=this._initialData;return this._hasBeenMoved||e.value!==s||e.fontSize!==i||e.color.some((a,h)=>a!==n[h])||e.pageIndex!==r},y(Ot,kn),J(Ot,"_freeTextDefaultContent",""),J(Ot,"_internalPadding",0),J(Ot,"_defaultColor",null),J(Ot,"_defaultFontSize",10),J(Ot,"_type","freetext"),J(Ot,"_editorType",nt.FREETEXT);let ep=Ot;class X{toSVGPath(){Et("Abstract method `toSVGPath` must be implemented.")}get box(){Et("Abstract getter `box` must be implemented.")}serialize(t,e){Et("Abstract method `serialize` must be implemented.")}static _rescale(t,e,s,i,n,r){r||(r=new Float32Array(t.length));for(let a=0,h=t.length;a<h;a+=2)r[a]=e+t[a]*i,r[a+1]=s+t[a+1]*n;return r}static _rescaleAndSwap(t,e,s,i,n,r){r||(r=new Float32Array(t.length));for(let a=0,h=t.length;a<h;a+=2)r[a]=e+t[a+1]*i,r[a+1]=s+t[a]*n;return r}static _translate(t,e,s,i){i||(i=new Float32Array(t.length));for(let n=0,r=t.length;n<r;n+=2)i[n]=e+t[n],i[n+1]=s+t[n+1];return i}static svgRound(t){return Math.round(t*1e4)}static _normalizePoint(t,e,s,i,n){switch(n){case 90:return[1-e/s,t/i];case 180:return[1-t/s,1-e/i];case 270:return[e/s,1-t/i];default:return[t/s,e/i]}}static _normalizePagePoint(t,e,s){switch(s){case 90:return[1-e,t];case 180:return[1-t,1-e];case 270:return[e,1-t];default:return[t,e]}}static createBezierPoints(t,e,s,i,n,r){return[(t+5*s)/6,(e+5*i)/6,(5*s+n)/6,(5*i+r)/6,(s+n)/2,(i+r)/2]}}J(X,"PRECISION",1e-4);const Pn=class Pn{constructor({x:t,y:e},s,i,n,r,a=0){y(this,ce);y(this,Ss);y(this,di,[]);y(this,oh);y(this,hh);y(this,ji,[]);y(this,lt,new Float32Array(18));y(this,Na);y(this,Ba);y(this,Cc);y(this,Ac);y(this,lh);y(this,ch);y(this,br,[]);m(this,Ss,s),m(this,ch,n*i),m(this,hh,r),l(this,lt).set([NaN,NaN,NaN,NaN,t,e],6),m(this,oh,a),m(this,Ac,l(Pn,Tc)*i),m(this,Cc,l(Pn,Vd)*i),m(this,lh,i),l(this,br).push(t,e)}isEmpty(){return isNaN(l(this,lt)[8])}add({x:t,y:e}){var R;m(this,Na,t),m(this,Ba,e);const[s,i,n,r]=l(this,Ss);let[a,h,c,u]=l(this,lt).subarray(8,12);const d=t-c,f=e-u,g=Math.hypot(d,f);if(g<l(this,Cc))return!1;const p=g-l(this,Ac),v=p/g,_=v*d,b=v*f;let x=a,C=h;a=c,h=u,c+=_,u+=b,(R=l(this,br))==null||R.push(t,e);const A=-b/p,P=_/p,D=A*l(this,ch),k=P*l(this,ch);return l(this,lt).set(l(this,lt).subarray(2,8),0),l(this,lt).set([c+D,u+k],4),l(this,lt).set(l(this,lt).subarray(14,18),12),l(this,lt).set([c-D,u-k],16),isNaN(l(this,lt)[6])?(l(this,ji).length===0&&(l(this,lt).set([a+D,h+k],2),l(this,ji).push(NaN,NaN,NaN,NaN,(a+D-s)/n,(h+k-i)/r),l(this,lt).set([a-D,h-k],14),l(this,di).push(NaN,NaN,NaN,NaN,(a-D-s)/n,(h-k-i)/r)),l(this,lt).set([x,C,a,h,c,u],6),!this.isEmpty()):(l(this,lt).set([x,C,a,h,c,u],6),Math.abs(Math.atan2(C-h,x-a)-Math.atan2(b,_))<Math.PI/2?([a,h,c,u]=l(this,lt).subarray(2,6),l(this,ji).push(NaN,NaN,NaN,NaN,((a+c)/2-s)/n,((h+u)/2-i)/r),[a,h,x,C]=l(this,lt).subarray(14,18),l(this,di).push(NaN,NaN,NaN,NaN,((x+a)/2-s)/n,((C+h)/2-i)/r),!0):([x,C,a,h,c,u]=l(this,lt).subarray(0,6),l(this,ji).push(((x+5*a)/6-s)/n,((C+5*h)/6-i)/r,((5*a+c)/6-s)/n,((5*h+u)/6-i)/r,((a+c)/2-s)/n,((h+u)/2-i)/r),[c,u,a,h,x,C]=l(this,lt).subarray(12,18),l(this,di).push(((x+5*a)/6-s)/n,((C+5*h)/6-i)/r,((5*a+c)/6-s)/n,((5*h+u)/6-i)/r,((a+c)/2-s)/n,((h+u)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";const t=l(this,ji),e=l(this,di);if(isNaN(l(this,lt)[6])&&!this.isEmpty())return w(this,ce,Dy).call(this);const s=[];s.push(`M${t[4]} ${t[5]}`);for(let i=6;i<t.length;i+=6)isNaN(t[i])?s.push(`L${t[i+4]} ${t[i+5]}`):s.push(`C${t[i]} ${t[i+1]} ${t[i+2]} ${t[i+3]} ${t[i+4]} ${t[i+5]}`);w(this,ce,Ly).call(this,s);for(let i=e.length-6;i>=6;i-=6)isNaN(e[i])?s.push(`L${e[i+4]} ${e[i+5]}`):s.push(`C${e[i]} ${e[i+1]} ${e[i+2]} ${e[i+3]} ${e[i+4]} ${e[i+5]}`);return w(this,ce,Ry).call(this,s),s.join(" ")}newFreeDrawOutline(t,e,s,i,n,r){return new gb(t,e,s,i,n,r)}getOutlines(){var d;const t=l(this,ji),e=l(this,di),s=l(this,lt),[i,n,r,a]=l(this,Ss),h=new Float32Array((((d=l(this,br))==null?void 0:d.length)??0)+2);for(let f=0,g=h.length-2;f<g;f+=2)h[f]=(l(this,br)[f]-i)/r,h[f+1]=(l(this,br)[f+1]-n)/a;if(h[h.length-2]=(l(this,Na)-i)/r,h[h.length-1]=(l(this,Ba)-n)/a,isNaN(s[6])&&!this.isEmpty())return w(this,ce,Fy).call(this,h);const c=new Float32Array(l(this,ji).length+24+l(this,di).length);let u=t.length;for(let f=0;f<u;f+=2){if(isNaN(t[f])){c[f]=c[f+1]=NaN;continue}c[f]=t[f],c[f+1]=t[f+1]}u=w(this,ce,jy).call(this,c,u);for(let f=e.length-6;f>=6;f-=6)for(let g=0;g<6;g+=2){if(isNaN(e[f+g])){c[u]=c[u+1]=NaN,u+=2;continue}c[u]=e[f+g],c[u+1]=e[f+g+1],u+=2}return w(this,ce,Iy).call(this,c,u),this.newFreeDrawOutline(c,h,l(this,Ss),l(this,lh),l(this,oh),l(this,hh))}};Ss=new WeakMap,di=new WeakMap,oh=new WeakMap,hh=new WeakMap,ji=new WeakMap,lt=new WeakMap,Na=new WeakMap,Ba=new WeakMap,Cc=new WeakMap,Ac=new WeakMap,lh=new WeakMap,ch=new WeakMap,br=new WeakMap,Tc=new WeakMap,Gd=new WeakMap,Vd=new WeakMap,ce=new WeakSet,Zc=function(){const t=l(this,lt).subarray(4,6),e=l(this,lt).subarray(16,18),[s,i,n,r]=l(this,Ss);return[(l(this,Na)+(t[0]-e[0])/2-s)/n,(l(this,Ba)+(t[1]-e[1])/2-i)/r,(l(this,Na)+(e[0]-t[0])/2-s)/n,(l(this,Ba)+(e[1]-t[1])/2-i)/r]},Dy=function(){const[t,e,s,i]=l(this,Ss),[n,r,a,h]=w(this,ce,Zc).call(this);return`M${(l(this,lt)[2]-t)/s} ${(l(this,lt)[3]-e)/i} L${(l(this,lt)[4]-t)/s} ${(l(this,lt)[5]-e)/i} L${n} ${r} L${a} ${h} L${(l(this,lt)[16]-t)/s} ${(l(this,lt)[17]-e)/i} L${(l(this,lt)[14]-t)/s} ${(l(this,lt)[15]-e)/i} Z`},Ry=function(t){const e=l(this,di);t.push(`L${e[4]} ${e[5]} Z`)},Ly=function(t){const[e,s,i,n]=l(this,Ss),r=l(this,lt).subarray(4,6),a=l(this,lt).subarray(16,18),[h,c,u,d]=w(this,ce,Zc).call(this);t.push(`L${(r[0]-e)/i} ${(r[1]-s)/n} L${h} ${c} L${u} ${d} L${(a[0]-e)/i} ${(a[1]-s)/n}`)},Fy=function(t){const e=l(this,lt),[s,i,n,r]=l(this,Ss),[a,h,c,u]=w(this,ce,Zc).call(this),d=new Float32Array(36);return d.set([NaN,NaN,NaN,NaN,(e[2]-s)/n,(e[3]-i)/r,NaN,NaN,NaN,NaN,(e[4]-s)/n,(e[5]-i)/r,NaN,NaN,NaN,NaN,a,h,NaN,NaN,NaN,NaN,c,u,NaN,NaN,NaN,NaN,(e[16]-s)/n,(e[17]-i)/r,NaN,NaN,NaN,NaN,(e[14]-s)/n,(e[15]-i)/r],0),this.newFreeDrawOutline(d,t,l(this,Ss),l(this,lh),l(this,oh),l(this,hh))},Iy=function(t,e){const s=l(this,di);return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6},jy=function(t,e){const s=l(this,lt).subarray(4,6),i=l(this,lt).subarray(16,18),[n,r,a,h]=l(this,Ss),[c,u,d,f]=w(this,ce,Zc).call(this);return t.set([NaN,NaN,NaN,NaN,(s[0]-n)/a,(s[1]-r)/h,NaN,NaN,NaN,NaN,c,u,NaN,NaN,NaN,NaN,d,f,NaN,NaN,NaN,NaN,(i[0]-n)/a,(i[1]-r)/h],e),e+=24},y(Pn,Tc,8),y(Pn,Gd,2),y(Pn,Vd,l(Pn,Tc)+l(Pn,Gd));let Sd=Pn;class gb extends X{constructor(e,s,i,n,r,a){super();y(this,Wd);y(this,uh);y(this,Ha,new Float32Array(4));y(this,Mn);y(this,Ec);y(this,Cs);y(this,kc);y(this,Jt);m(this,Jt,e),m(this,Cs,s),m(this,uh,i),m(this,kc,n),m(this,Mn,r),m(this,Ec,a),this.lastPoint=[NaN,NaN],w(this,Wd,Ny).call(this,a);const[h,c,u,d]=l(this,Ha);for(let f=0,g=e.length;f<g;f+=2)e[f]=(e[f]-h)/u,e[f+1]=(e[f+1]-c)/d;for(let f=0,g=s.length;f<g;f+=2)s[f]=(s[f]-h)/u,s[f+1]=(s[f+1]-c)/d}toSVGPath(){const e=[`M${l(this,Jt)[4]} ${l(this,Jt)[5]}`];for(let s=6,i=l(this,Jt).length;s<i;s+=6){if(isNaN(l(this,Jt)[s])){e.push(`L${l(this,Jt)[s+4]} ${l(this,Jt)[s+5]}`);continue}e.push(`C${l(this,Jt)[s]} ${l(this,Jt)[s+1]} ${l(this,Jt)[s+2]} ${l(this,Jt)[s+3]} ${l(this,Jt)[s+4]} ${l(this,Jt)[s+5]}`)}return e.push("Z"),e.join(" ")}serialize([e,s,i,n],r){const a=i-e,h=n-s;let c,u;switch(r){case 0:c=X._rescale(l(this,Jt),e,n,a,-h),u=X._rescale(l(this,Cs),e,n,a,-h);break;case 90:c=X._rescaleAndSwap(l(this,Jt),e,s,a,h),u=X._rescaleAndSwap(l(this,Cs),e,s,a,h);break;case 180:c=X._rescale(l(this,Jt),i,s,-a,h),u=X._rescale(l(this,Cs),i,s,-a,h);break;case 270:c=X._rescaleAndSwap(l(this,Jt),i,n,-a,-h),u=X._rescaleAndSwap(l(this,Cs),i,n,-a,-h);break}return{outline:Array.from(c),points:[Array.from(u)]}}get box(){return l(this,Ha)}newOutliner(e,s,i,n,r,a=0){return new Sd(e,s,i,n,r,a)}getNewOutline(e,s){const[i,n,r,a]=l(this,Ha),[h,c,u,d]=l(this,uh),f=r*u,g=a*d,p=i*u+h,v=n*d+c,_=this.newOutliner({x:l(this,Cs)[0]*f+p,y:l(this,Cs)[1]*g+v},l(this,uh),l(this,kc),e,l(this,Ec),s??l(this,Mn));for(let b=2;b<l(this,Cs).length;b+=2)_.add({x:l(this,Cs)[b]*f+p,y:l(this,Cs)[b+1]*g+v});return _.getOutlines()}}uh=new WeakMap,Ha=new WeakMap,Mn=new WeakMap,Ec=new WeakMap,Cs=new WeakMap,kc=new WeakMap,Jt=new WeakMap,Wd=new WeakSet,Ny=function(e){const s=l(this,Jt);let i=s[4],n=s[5],r=i,a=n,h=i,c=n,u=i,d=n;const f=e?Math.max:Math.min;for(let p=6,v=s.length;p<v;p+=6){if(isNaN(s[p]))r=Math.min(r,s[p+4]),a=Math.min(a,s[p+5]),h=Math.max(h,s[p+4]),c=Math.max(c,s[p+5]),d<s[p+5]?(u=s[p+4],d=s[p+5]):d===s[p+5]&&(u=f(u,s[p+4]));else{const _=q.bezierBoundingBox(i,n,...s.slice(p,p+6));r=Math.min(r,_[0]),a=Math.min(a,_[1]),h=Math.max(h,_[2]),c=Math.max(c,_[3]),d<_[3]?(u=_[2],d=_[3]):d===_[3]&&(u=f(u,_[2]))}i=s[p+4],n=s[p+5]}const g=l(this,Ha);g[0]=r-l(this,Mn),g[1]=a-l(this,Mn),g[2]=h-r+2*l(this,Mn),g[3]=c-a+2*l(this,Mn),this.lastPoint=[u,d]};class sp{constructor(t,e=0,s=0,i=!0){y(this,Ye);y(this,Pc);y(this,Mc);y(this,yr,[]);y(this,fi,[]);let n=1/0,r=-1/0,a=1/0,h=-1/0;const c=10**-4;for(const{x:_,y:b,width:x,height:C}of t){const A=Math.floor((_-e)/c)*c,P=Math.ceil((_+x+e)/c)*c,D=Math.floor((b-e)/c)*c,k=Math.ceil((b+C+e)/c)*c,M=[A,D,k,!0],R=[P,D,k,!1];l(this,yr).push(M,R),n=Math.min(n,A),r=Math.max(r,P),a=Math.min(a,D),h=Math.max(h,k)}const u=r-n+2*s,d=h-a+2*s,f=n-s,g=a-s,p=l(this,yr).at(i?-1:-2),v=[p[0],p[2]];for(const _ of l(this,yr)){const[b,x,C]=_;_[0]=(b-f)/u,_[1]=(x-g)/d,_[2]=(C-g)/d}m(this,Pc,new Float32Array([f,g,u,d])),m(this,Mc,v)}getOutlines(){l(this,yr).sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);const t=[];for(const e of l(this,yr))e[3]?(t.push(...w(this,Ye,tm).call(this,e)),w(this,Ye,Hy).call(this,e)):(w(this,Ye,Gy).call(this,e),t.push(...w(this,Ye,tm).call(this,e)));return w(this,Ye,By).call(this,t)}}Pc=new WeakMap,Mc=new WeakMap,yr=new WeakMap,fi=new WeakMap,Ye=new WeakSet,By=function(t){const e=[],s=new Set;for(const r of t){const[a,h,c]=r;e.push([a,h,r],[a,c,r])}e.sort((r,a)=>r[1]-a[1]||r[0]-a[0]);for(let r=0,a=e.length;r<a;r+=2){const h=e[r][2],c=e[r+1][2];h.push(c),c.push(h),s.add(h),s.add(c)}const i=[];let n;for(;s.size>0;){const r=s.values().next().value;let[a,h,c,u,d]=r;s.delete(r);let f=a,g=h;for(n=[a,c],i.push(n);;){let p;if(s.has(u))p=u;else if(s.has(d))p=d;else break;s.delete(p),[a,h,c,u,d]=p,f!==a&&(n.push(f,g,a,g===h?h:c),f=a),g=g===h?c:h}n.push(f,g)}return new DC(i,l(this,Pc),l(this,Mc))},mf=function(t){const e=l(this,fi);let s=0,i=e.length-1;for(;s<=i;){const n=s+i>>1,r=e[n][0];if(r===t)return n;r<t?s=n+1:i=n-1}return i+1},Hy=function([,t,e]){const s=w(this,Ye,mf).call(this,t);l(this,fi).splice(s,0,[t,e])},Gy=function([,t,e]){const s=w(this,Ye,mf).call(this,t);for(let i=s;i<l(this,fi).length;i++){const[n,r]=l(this,fi)[i];if(n!==t)break;if(n===t&&r===e){l(this,fi).splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=l(this,fi)[i];if(n!==t)break;if(n===t&&r===e){l(this,fi).splice(i,1);return}}},tm=function(t){const[e,s,i]=t,n=[[e,s,i]],r=w(this,Ye,mf).call(this,i);for(let a=0;a<r;a++){const[h,c]=l(this,fi)[a];for(let u=0,d=n.length;u<d;u++){const[,f,g]=n[u];if(!(c<=f||g<=h)){if(f>=h){if(g>c)n[u][1]=c;else{if(d===1)return[];n.splice(u,1),u--,d--}continue}n[u][2]=h,g>c&&n.push([e,c,g])}}}return n};class DC extends X{constructor(e,s,i){super();y(this,Oc);y(this,dh);m(this,dh,e),m(this,Oc,s),this.lastPoint=i}toSVGPath(){const e=[];for(const s of l(this,dh)){let[i,n]=s;e.push(`M${i} ${n}`);for(let r=2;r<s.length;r+=2){const a=s[r],h=s[r+1];a===i?(e.push(`V${h}`),n=h):h===n&&(e.push(`H${a}`),i=a)}e.push("Z")}return e.join(" ")}serialize([e,s,i,n],r){const a=[],h=i-e,c=n-s;for(const u of l(this,dh)){const d=new Array(u.length);for(let f=0;f<u.length;f+=2)d[f]=e+u[f]*h,d[f+1]=n-u[f+1]*c;a.push(d)}return a}get box(){return l(this,Oc)}get classNamesForOutlining(){return["highlightOutline"]}}Oc=new WeakMap,dh=new WeakMap;class ip extends Sd{newFreeDrawOutline(t,e,s,i,n,r){return new RC(t,e,s,i,n,r)}}class RC extends gb{newOutliner(t,e,s,i,n,r=0){return new ip(t,e,s,i,n,r)}}const hs=class hs{constructor({editor:t=null,uiManager:e=null}){y(this,At);y(this,gi,null);y(this,Ga,null);y(this,fh);y(this,ue,null);y(this,Dc,!1);y(this,gh,!1);y(this,Rc,null);y(this,Lc);y(this,_r,null);y(this,pi,null);y(this,ph);var s;t?(m(this,gh,!1),m(this,ph,dt.HIGHLIGHT_COLOR),m(this,Rc,t)):(m(this,gh,!0),m(this,ph,dt.HIGHLIGHT_DEFAULT_COLOR)),m(this,pi,(t==null?void 0:t._uiManager)||e),m(this,Lc,l(this,pi)._eventBus),m(this,fh,(t==null?void 0:t.color)||((s=l(this,pi))==null?void 0:s.highlightColors.values().next().value)||"#FFFF98"),l(hs,Fc)||m(hs,Fc,Object.freeze({blue:"pdfjs-editor-colorpicker-blue",green:"pdfjs-editor-colorpicker-green",pink:"pdfjs-editor-colorpicker-pink",red:"pdfjs-editor-colorpicker-red",yellow:"pdfjs-editor-colorpicker-yellow"}))}static get _keyboardManager(){return ht(this,"_keyboardManager",new ll([[["Escape","mac+Escape"],hs.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],hs.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],hs.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],hs.prototype._moveToPrevious],[["Home","mac+Home"],hs.prototype._moveToBeginning],[["End","mac+End"],hs.prototype._moveToEnd]]))}renderButton(){const t=m(this,gi,document.createElement("button"));t.className="colorPicker",t.tabIndex="0",t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-button"),t.setAttribute("aria-haspopup",!0);const e=l(this,pi)._signal;t.addEventListener("click",w(this,At,io).bind(this),{signal:e}),t.addEventListener("keydown",w(this,At,im).bind(this),{signal:e});const s=m(this,Ga,document.createElement("span"));return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=l(this,fh),t.append(s),t}renderMainDropdown(){const t=m(this,ue,w(this,At,em).call(this));return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}_colorSelectFromKeyboard(t){if(t.target===l(this,gi)){w(this,At,io).call(this,t);return}const e=t.target.getAttribute("data-color");e&&w(this,At,sm).call(this,e,t)}_moveToNext(t){var e,s;if(!l(this,At,Pr)){w(this,At,io).call(this,t);return}if(t.target===l(this,gi)){(e=l(this,ue).firstChild)==null||e.focus();return}(s=t.target.nextSibling)==null||s.focus()}_moveToPrevious(t){var e,s;if(t.target===((e=l(this,ue))==null?void 0:e.firstChild)||t.target===l(this,gi)){l(this,At,Pr)&&this._hideDropdownFromKeyboard();return}l(this,At,Pr)||w(this,At,io).call(this,t),(s=t.target.previousSibling)==null||s.focus()}_moveToBeginning(t){var e;if(!l(this,At,Pr)){w(this,At,io).call(this,t);return}(e=l(this,ue).firstChild)==null||e.focus()}_moveToEnd(t){var e;if(!l(this,At,Pr)){w(this,At,io).call(this,t);return}(e=l(this,ue).lastChild)==null||e.focus()}hideDropdown(){var t,e;(t=l(this,ue))==null||t.classList.add("hidden"),(e=l(this,_r))==null||e.abort(),m(this,_r,null)}_hideDropdownFromKeyboard(){var t;if(!l(this,gh)){if(!l(this,At,Pr)){(t=l(this,Rc))==null||t.unselect();return}this.hideDropdown(),l(this,gi).focus({preventScroll:!0,focusVisible:l(this,Dc)})}}updateColor(t){if(l(this,Ga)&&(l(this,Ga).style.backgroundColor=t),!l(this,ue))return;const e=l(this,pi).highlightColors.values();for(const s of l(this,ue).children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){var t,e;(t=l(this,gi))==null||t.remove(),m(this,gi,null),m(this,Ga,null),(e=l(this,ue))==null||e.remove(),m(this,ue,null)}};gi=new WeakMap,Ga=new WeakMap,fh=new WeakMap,ue=new WeakMap,Dc=new WeakMap,gh=new WeakMap,Rc=new WeakMap,Lc=new WeakMap,_r=new WeakMap,pi=new WeakMap,ph=new WeakMap,Fc=new WeakMap,At=new WeakSet,em=function(){const t=document.createElement("div"),e=l(this,pi)._signal;t.addEventListener("contextmenu",ii,{signal:e}),t.className="dropdown",t.role="listbox",t.setAttribute("aria-multiselectable",!1),t.setAttribute("aria-orientation","vertical"),t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown");for(const[s,i]of l(this,pi).highlightColors){const n=document.createElement("button");n.tabIndex="0",n.role="option",n.setAttribute("data-color",i),n.title=s,n.setAttribute("data-l10n-id",l(hs,Fc)[s]);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===l(this,fh)),n.addEventListener("click",w(this,At,sm).bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",w(this,At,im).bind(this),{signal:e}),t},sm=function(t,e){e.stopPropagation(),l(this,Lc).dispatch("switchannotationeditorparams",{source:this,type:l(this,ph),value:t})},im=function(t){hs._keyboardManager.exec(this,t)},io=function(t){if(l(this,At,Pr)){this.hideDropdown();return}if(m(this,Dc,t.detail===0),l(this,_r)||(m(this,_r,new AbortController),window.addEventListener("pointerdown",w(this,At,Vy).bind(this),{signal:l(this,pi).combinedSignal(l(this,_r))})),l(this,ue)){l(this,ue).classList.remove("hidden");return}const e=m(this,ue,w(this,At,em).call(this));l(this,gi).append(e)},Vy=function(t){var e;(e=l(this,ue))!=null&&e.contains(t.target)||this.hideDropdown()},Pr=function(){return l(this,ue)&&!l(this,ue).classList.contains("hidden")},y(hs,Fc,null);let Cd=hs;const bt=class bt extends Ht{constructor(e){super({...e,name:"highlightEditor"});y(this,st);y(this,mh,null);y(this,Ic,0);y(this,On);y(this,Va,null);y(this,vh,null);y(this,ls,null);y(this,jc,null);y(this,Nc,0);y(this,Wa,null);y(this,Hs,null);y(this,As,null);y(this,_e,!1);y(this,bh,null);y(this,Dn);y(this,Le,null);y(this,yh,"");y(this,Gs);y(this,Bc,"");this.color=e.color||bt._defaultColor,m(this,Gs,e.thickness||bt._defaultThickness),m(this,Dn,e.opacity||bt._defaultOpacity),m(this,On,e.boxes||null),m(this,Bc,e.methodOfCreation||""),m(this,yh,e.text||""),this._isDraggable=!1,e.highlightId>-1?(m(this,_e,!0),w(this,st,vf).call(this,e),w(this,st,no).call(this)):l(this,On)&&(m(this,mh,e.anchorNode),m(this,Ic,e.anchorOffset),m(this,jc,e.focusNode),m(this,Nc,e.focusOffset),w(this,st,nm).call(this),w(this,st,no).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const e=bt.prototype;return ht(this,"_keyboardManager",new ll([[["ArrowLeft","mac+ArrowLeft"],e._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],e._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],e._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],e._moveCaret,{args:[3]}]]))}get telemetryInitialData(){return{action:"added",type:l(this,_e)?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:l(this,Gs),methodOfCreation:l(this,Bc)}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.highlightColorNames.get(this.color)}}static computeTelemetryFinalData(e){return{numberOfColors:e.get("color").size}}static initialize(e,s){var i;Ht.initialize(e,s),bt._defaultColor||(bt._defaultColor=((i=s.highlightColors)==null?void 0:i.values().next().value)||"#fff066")}static updateDefaultParams(e,s){switch(e){case dt.HIGHLIGHT_DEFAULT_COLOR:bt._defaultColor=s;break;case dt.HIGHLIGHT_THICKNESS:bt._defaultThickness=s;break}}translateInPage(e,s){}get toolbarPosition(){return l(this,bh)}updateParams(e,s){switch(e){case dt.HIGHLIGHT_COLOR:w(this,st,Wy).call(this,s);break;case dt.HIGHLIGHT_THICKNESS:w(this,st,zy).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[dt.HIGHLIGHT_DEFAULT_COLOR,bt._defaultColor],[dt.HIGHLIGHT_THICKNESS,bt._defaultThickness]]}get propertiesToUpdate(){return[[dt.HIGHLIGHT_COLOR,this.color||bt._defaultColor],[dt.HIGHLIGHT_THICKNESS,l(this,Gs)||bt._defaultThickness],[dt.HIGHLIGHT_FREE,l(this,_e)]]}async addEditToolbar(){const e=await super.addEditToolbar();return e?(this._uiManager.highlightColors&&(m(this,vh,new Cd({editor:this})),e.addColorPicker(l(this,vh))),e):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(w(this,st,tu).call(this))}getBaseTranslation(){return[0,0]}getRect(e,s){return super.getRect(e,s,w(this,st,tu).call(this))}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),e&&this.div.focus()}remove(){w(this,st,rm).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,st,no).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?w(this,st,rm).call(this):e&&(w(this,st,no).call(this,e),s=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),this.show(this._isVisible),s&&this.select()}rotate(e){var n,r,a;const{drawLayer:s}=this.parent;let i;l(this,_e)?(e=(e-this.rotation+360)%360,i=w(n=bt,Vs,Nh).call(n,l(this,Hs).box,e)):i=w(r=bt,Vs,Nh).call(r,[this.x,this.y,this.width,this.height],e),s.updateProperties(l(this,As),{bbox:i,root:{"data-main-rotation":e}}),s.updateProperties(l(this,Le),{bbox:w(a=bt,Vs,Nh).call(a,l(this,ls).box,e),root:{"data-main-rotation":e}})}render(){if(this.div)return this.div;const e=super.render();l(this,yh)&&(e.setAttribute("aria-label",l(this,yh)),e.setAttribute("role","mark")),l(this,_e)?e.classList.add("free"):this.div.addEventListener("keydown",w(this,st,Uy).bind(this),{signal:this._uiManager._signal});const s=m(this,Wa,document.createElement("div"));e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",s.style.clipPath=l(this,Va);const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),gd(this,l(this,Wa),["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Le),{rootClass:{hovered:!0}})}pointerleave(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Le),{rootClass:{hovered:!1}})}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:w(this,st,bf).call(this,!0);break;case 1:case 3:w(this,st,bf).call(this,!1);break}}select(){var e;super.select(),l(this,Le)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Le),{rootClass:{hovered:!1,selected:!0}}))}unselect(){var e;super.unselect(),l(this,Le)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Le),{rootClass:{selected:!1}}),l(this,_e)||w(this,st,bf).call(this,!1))}get _mustFixPosition(){return!l(this,_e)}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.updateProperties(l(this,As),{rootClass:{hidden:!e}}),this.parent.drawLayer.updateProperties(l(this,Le),{rootClass:{hidden:!e}}))}static startHighlighting(e,s,{target:i,x:n,y:r}){const{x:a,y:h,width:c,height:u}=i.getBoundingClientRect(),d=new AbortController,f=e.combinedSignal(d),g=p=>{d.abort(),w(this,Vs,Ky).call(this,e,p)};window.addEventListener("blur",g,{signal:f}),window.addEventListener("pointerup",g,{signal:f}),window.addEventListener("pointerdown",gs,{capture:!0,passive:!1,signal:f}),window.addEventListener("contextmenu",ii,{signal:f}),i.addEventListener("pointermove",w(this,Vs,qy).bind(this,e),{signal:f}),this._freeHighlight=new ip({x:n,y:r},[a,h,c,u],e.scale,this._defaultThickness/2,s,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0)}static async deserialize(e,s,i){var v,_,b,x;let n=null;if(e instanceof db){const{data:{quadPoints:C,rect:A,rotation:P,id:D,color:k,opacity:M,popupRef:R},parent:{page:{pageNumber:F}}}=e;n=e={annotationType:nt.HIGHLIGHT,color:Array.from(k),opacity:M,quadPoints:C,boxes:null,pageIndex:F-1,rect:A.slice(0),rotation:P,id:D,deleted:!1,popupRef:R}}else if(e instanceof tp){const{data:{inkLists:C,rect:A,rotation:P,id:D,color:k,borderStyle:{rawWidth:M},popupRef:R},parent:{page:{pageNumber:F}}}=e;n=e={annotationType:nt.HIGHLIGHT,color:Array.from(k),thickness:M,inkLists:C,boxes:null,pageIndex:F-1,rect:A.slice(0),rotation:P,id:D,deleted:!1,popupRef:R}}const{color:r,quadPoints:a,inkLists:h,opacity:c}=e,u=await super.deserialize(e,s,i);u.color=q.makeHexColor(...r),m(u,Dn,c||1),h&&m(u,Gs,e.thickness),u.annotationElementId=e.id||null,u._initialData=n;const[d,f]=u.pageDimensions,[g,p]=u.pageTranslation;if(a){const C=m(u,On,[]);for(let A=0;A<a.length;A+=8)C.push({x:(a[A]-g)/d,y:1-(a[A+1]-p)/f,width:(a[A+2]-a[A])/d,height:(a[A+1]-a[A+5])/f});w(v=u,st,nm).call(v),w(_=u,st,no).call(_),u.rotate(u.rotation)}else if(h){m(u,_e,!0);const C=h[0],A={x:C[0]-g,y:f-(C[1]-p)},P=new ip(A,[0,0,d,f],1,l(u,Gs)/2,!0,.001);for(let M=0,R=C.length;M<R;M+=2)A.x=C[M]-g,A.y=f-(C[M+1]-p),P.add(A);const{id:D,clipPathId:k}=s.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:u.color,"fill-opacity":u._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:P.toSVGPath()}},!0,!0);w(b=u,st,vf).call(b,{highlightOutlines:P.getOutlines(),highlightId:D,clipPathId:k}),w(x=u,st,no).call(x)}return u}serialize(e=!1){if(this.isEmpty()||e)return null;if(this.deleted)return this.serializeDeleted();const s=this.getRect(0,0),i=Ht._colorManager.convert(this.color),n={annotationType:nt.HIGHLIGHT,color:i,opacity:l(this,Dn),thickness:l(this,Gs),quadPoints:w(this,st,Yy).call(this),outlines:w(this,st,$y).call(this,s),pageIndex:this.pageIndex,rect:s,rotation:w(this,st,tu).call(this),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!w(this,st,Jy).call(this,n)?null:(n.id=this.annotationElementId,n)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};mh=new WeakMap,Ic=new WeakMap,On=new WeakMap,Va=new WeakMap,vh=new WeakMap,ls=new WeakMap,jc=new WeakMap,Nc=new WeakMap,Wa=new WeakMap,Hs=new WeakMap,As=new WeakMap,_e=new WeakMap,bh=new WeakMap,Dn=new WeakMap,Le=new WeakMap,yh=new WeakMap,Gs=new WeakMap,Bc=new WeakMap,st=new WeakSet,nm=function(){const e=new sp(l(this,On),.001);m(this,Hs,e.getOutlines()),[this.x,this.y,this.width,this.height]=l(this,Hs).box;const s=new sp(l(this,On),.0025,.001,this._uiManager.direction==="ltr");m(this,ls,s.getOutlines());const{lastPoint:i}=l(this,ls);m(this,bh,[(i[0]-this.x)/this.width,(i[1]-this.y)/this.height])},vf=function({highlightOutlines:e,highlightId:s,clipPathId:i}){var d,f;if(m(this,Hs,e),m(this,ls,e.getNewOutline(l(this,Gs)/2+1.5,.0025)),s>=0)m(this,As,s),m(this,Va,i),this.parent.drawLayer.finalizeDraw(s,{bbox:e.box,path:{d:e.toSVGPath()}}),m(this,Le,this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:l(this,ls).box,path:{d:l(this,ls).toSVGPath()}},!0));else if(this.parent){const g=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(l(this,As),{bbox:w(d=bt,Vs,Nh).call(d,l(this,Hs).box,(g-this.rotation+360)%360),path:{d:e.toSVGPath()}}),this.parent.drawLayer.updateProperties(l(this,Le),{bbox:w(f=bt,Vs,Nh).call(f,l(this,ls).box,g),path:{d:l(this,ls).toSVGPath()}})}const[r,a,h,c]=e.box;switch(this.rotation){case 0:this.x=r,this.y=a,this.width=h,this.height=c;break;case 90:{const[g,p]=this.parentDimensions;this.x=a,this.y=1-r,this.width=h*p/g,this.height=c*g/p;break}case 180:this.x=1-r,this.y=1-a,this.width=h,this.height=c;break;case 270:{const[g,p]=this.parentDimensions;this.x=1-a,this.y=r,this.width=h*p/g,this.height=c*g/p;break}}const{lastPoint:u}=l(this,ls);m(this,bh,[(u[0]-r)/h,(u[1]-a)/c])},Wy=function(e){const s=(r,a)=>{var h,c;this.color=r,m(this,Dn,a),(h=this.parent)==null||h.drawLayer.updateProperties(l(this,As),{root:{fill:r,"fill-opacity":a}}),(c=l(this,vh))==null||c.updateColor(r)},i=this.color,n=l(this,Dn);this.addCommands({cmd:s.bind(this,e,bt._defaultOpacity),undo:s.bind(this,i,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:dt.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(e)},!0)},zy=function(e){const s=l(this,Gs),i=n=>{m(this,Gs,n),w(this,st,Xy).call(this,n)};this.addCommands({cmd:i.bind(this,e),undo:i.bind(this,s),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:dt.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)},Xy=function(e){if(!l(this,_e))return;w(this,st,vf).call(this,{highlightOutlines:l(this,Hs).getNewOutline(e/2)}),this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)},rm=function(){l(this,As)===null||!this.parent||(this.parent.drawLayer.remove(l(this,As)),m(this,As,null),this.parent.drawLayer.remove(l(this,Le)),m(this,Le,null))},no=function(e=this.parent){l(this,As)===null&&({id:Ze(this,As)._,clipPathId:Ze(this,Va)._}=e.drawLayer.draw({bbox:l(this,Hs).box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":l(this,Dn)},rootClass:{highlight:!0,free:l(this,_e)},path:{d:l(this,Hs).toSVGPath()}},!1,!0),m(this,Le,e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:l(this,_e)},bbox:l(this,ls).box,path:{d:l(this,ls).toSVGPath()}},l(this,_e))),l(this,Wa)&&(l(this,Wa).style.clipPath=l(this,Va)))},Vs=new WeakSet,Nh=function([e,s,i,n],r){switch(r){case 90:return[1-s-n,e,n,i];case 180:return[1-e-i,1-s-n,i,n];case 270:return[s,1-e-i,n,i]}return[e,s,i,n]},Uy=function(e){bt._keyboardManager.exec(this,e)},bf=function(e){if(!l(this,mh))return;const s=window.getSelection();e?s.setPosition(l(this,mh),l(this,Ic)):s.setPosition(l(this,jc),l(this,Nc))},tu=function(){return l(this,_e)?this.rotation:0},Yy=function(){if(l(this,_e))return null;const[e,s]=this.pageDimensions,[i,n]=this.pageTranslation,r=l(this,On),a=new Float32Array(r.length*8);let h=0;for(const{x:c,y:u,width:d,height:f}of r){const g=c*e+i,p=(1-u)*s+n;a[h]=a[h+4]=g,a[h+1]=a[h+3]=p,a[h+2]=a[h+6]=g+d*e,a[h+5]=a[h+7]=p-f*s,h+=8}return a},$y=function(e){return l(this,Hs).serialize(e,w(this,st,tu).call(this))},qy=function(e,s){this._freeHighlight.add(s)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})},Ky=function(e,s){this._freeHighlight.isEmpty()?e.drawLayer.remove(this._freeHighlightId):e.createAndAddNewEditor(s,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:"main_toolbar"}),this._freeHighlightId=-1,this._freeHighlight=null,this._freeHighlightClipId=""},Jy=function(e){const{color:s}=this._initialData;return e.color.some((i,n)=>i!==s[n])},y(bt,Vs),J(bt,"_defaultColor",null),J(bt,"_defaultOpacity",1),J(bt,"_defaultThickness",12),J(bt,"_type","highlight"),J(bt,"_editorType",nt.HIGHLIGHT),J(bt,"_freeHighlightId",-1),J(bt,"_freeHighlight",null),J(bt,"_freeHighlightClipId","");let Ad=bt;class LC{constructor(){y(this,za,Object.create(null))}updateProperty(t,e){this[t]=e,this.updateSVGProperty(t,e)}updateProperties(t){if(t)for(const[e,s]of Object.entries(t))this.updateProperty(e,s)}updateSVGProperty(t,e){l(this,za)[t]=e}toSVGProperties(){const t=l(this,za);return m(this,za,Object.create(null)),{root:t}}reset(){m(this,za,Object.create(null))}updateAll(t=this){this.updateProperties(t)}clone(){Et("Not implemented")}}za=new WeakMap;const U=class U extends Ht{constructor(e){super(e);y(this,mt);y(this,Ts,null);y(this,_h);J(this,"_drawId",null);m(this,_h,e.mustBeCommitted||!1),e.drawOutlines&&(w(this,mt,am).call(this,e),w(this,mt,eu).call(this))}static _mergeSVGProperties(e,s){const i=new Set(Object.keys(e));for(const[n,r]of Object.entries(s))i.has(n)?Object.assign(e[n],r):e[n]=r;return e}static getDefaultDrawingOptions(e){Et("Not implemented")}static get typesMap(){Et("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(e,s){const i=this.typesMap.get(e);i&&this._defaultDrawingOptions.updateProperty(i,s),this._currentParent&&(l(U,pe).updateProperty(i,s),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(e,s){const i=this.constructor.typesMap.get(e);i&&this._updateProperty(e,i,s)}static get defaultPropertiesToUpdate(){const e=[],s=this._defaultDrawingOptions;for(const[i,n]of this.typesMap)e.push([i,s[n]]);return e}get propertiesToUpdate(){const e=[],{_drawingOptions:s}=this;for(const[i,n]of this.constructor.typesMap)e.push([i,s[n]]);return e}_updateProperty(e,s,i){const n=this._drawingOptions,r=n[s],a=h=>{var u;n.updateProperty(s,h);const c=l(this,Ts).updateProperty(s,h);c&&w(this,mt,su).call(this,c),(u=this.parent)==null||u.drawLayer.updateProperties(this._drawId,n.toSVGProperties())};this.addCommands({cmd:a.bind(this,i),undo:a.bind(this,r),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:e,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,U._mergeSVGProperties(l(this,Ts).getPathResizingSVGProperties(w(this,mt,yf).call(this)),{bbox:w(this,mt,Bh).call(this)}))}_onResized(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,U._mergeSVGProperties(l(this,Ts).getPathResizedSVGProperties(w(this,mt,yf).call(this)),{bbox:w(this,mt,Bh).call(this)}))}_onTranslating(e,s){var i;(i=this.parent)==null||i.drawLayer.updateProperties(this._drawId,{bbox:w(this,mt,Bh).call(this,e,s)})}_onTranslated(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,U._mergeSVGProperties(l(this,Ts).getPathTranslatedSVGProperties(w(this,mt,yf).call(this),this.parentDimensions),{bbox:w(this,mt,Bh).call(this)}))}_onStartDragging(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}commit(){super.commit(),this.disableEditMode(),this.disableEditing()}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),this._isDraggable=!0,l(this,_h)&&(m(this,_h,!1),this.commit(),this.parent.setSelected(this),e&&this.isOnScreen&&this.div.focus())}remove(){w(this,mt,hm).call(this),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,mt,eu).call(this),w(this,mt,su).call(this,l(this,Ts).box),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?(this._uiManager.removeShouldRescale(this),w(this,mt,hm).call(this)):e&&(this._uiManager.addShouldRescale(this),w(this,mt,eu).call(this,e),s=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),s&&this.select()}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,U._mergeSVGProperties({bbox:w(this,mt,Bh).call(this)},l(this,Ts).updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&w(this,mt,su).call(this,l(this,Ts).updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;const e=super.render();e.classList.add("draw");const s=document.createElement("div");e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal";const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),this._uiManager.addShouldRescale(this),this.disableEditing(),e}static createDrawerInstance(e,s,i,n,r){Et("Not implemented")}static startDrawing(e,s,i,n){var _;const{target:r,offsetX:a,offsetY:h,pointerId:c,pointerType:u}=n;if(l(U,xr)&&l(U,xr)!==u)return;const{viewport:{rotation:d}}=e,{width:f,height:g}=r.getBoundingClientRect(),p=m(U,Xa,new AbortController),v=e.combinedSignal(p);if(l(U,wr)||m(U,wr,c),l(U,xr)??m(U,xr,u),window.addEventListener("pointerup",b=>{var x;l(U,wr)===b.pointerId?this._endDraw(b):(x=l(U,Sr))==null||x.delete(b.pointerId)},{signal:v}),window.addEventListener("pointercancel",b=>{var x;l(U,wr)===b.pointerId?this._currentParent.endDrawingSession():(x=l(U,Sr))==null||x.delete(b.pointerId)},{signal:v}),window.addEventListener("pointerdown",b=>{l(U,xr)===b.pointerType&&((l(U,Sr)||m(U,Sr,new Set)).add(b.pointerId),l(U,pe).isCancellable()&&(l(U,pe).removeLastElement(),l(U,pe).isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:v}),window.addEventListener("contextmenu",ii,{signal:v}),r.addEventListener("pointermove",this._drawMove.bind(this),{signal:v}),r.addEventListener("touchmove",b=>{b.timeStamp===l(U,Ya)&&gs(b)},{signal:v}),e.toggleDrawing(),(_=s._editorUndoBar)==null||_.hide(),l(U,pe)){e.drawLayer.updateProperties(this._currentDrawId,l(U,pe).startNew(a,h,f,g,d));return}s.updateUIForDefaultProperties(this),m(U,pe,this.createDrawerInstance(a,h,f,g,d)),m(U,Ua,this.getDefaultDrawingOptions()),this._currentParent=e,{id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties(l(U,Ua).toSVGProperties(),l(U,pe).defaultSVGProperties),!0,!1)}static _drawMove(e){var r;if(m(U,Ya,-1),!l(U,pe))return;const{offsetX:s,offsetY:i,pointerId:n}=e;if(l(U,wr)===n){if(((r=l(U,Sr))==null?void 0:r.size)>=1){this._endDraw(e);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,l(U,pe).add(s,i)),m(U,Ya,e.timeStamp),gs(e)}}static _cleanup(e){e&&(this._currentDrawId=-1,this._currentParent=null,m(U,pe,null),m(U,Ua,null),m(U,xr,null),m(U,Ya,NaN)),l(U,Xa)&&(l(U,Xa).abort(),m(U,Xa,null),m(U,wr,NaN),m(U,Sr,null))}static _endDraw(e){const s=this._currentParent;if(s){if(s.toggleDrawing(!0),this._cleanup(!1),e&&s.drawLayer.updateProperties(this._currentDrawId,l(U,pe).end(e.offsetX,e.offsetY)),this.supportMultipleDrawings){const i=l(U,pe),n=this._currentDrawId,r=i.getLastElement();s.addCommands({cmd:()=>{s.drawLayer.updateProperties(n,i.setLastElement(r))},undo:()=>{s.drawLayer.updateProperties(n,i.removeLastElement())},mustExec:!1,type:dt.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(e){const s=this._currentParent;if(!s)return null;if(s.toggleDrawing(!0),s.cleanUndoStack(dt.DRAW_STEP),!l(U,pe).isEmpty()){const{pageDimensions:[i,n],scale:r}=s,a=s.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:l(U,pe).getOutlines(i*r,n*r,r,this._INNER_MARGIN),drawingOptions:l(U,Ua),mustBeCommitted:!e});return this._cleanup(!0),a}return s.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(e){}static deserializeDraw(e,s,i,n,r,a){Et("Not implemented")}static async deserialize(e,s,i){var d,f;const{rawDims:{pageWidth:n,pageHeight:r,pageX:a,pageY:h}}=s.viewport,c=this.deserializeDraw(a,h,n,r,this._INNER_MARGIN,e),u=await super.deserialize(e,s,i);return u.createDrawingOptions(e),w(d=u,mt,am).call(d,{drawOutlines:c}),w(f=u,mt,eu).call(f),u.onScaleChanging(),u.rotate(),u}serializeDraw(e){const[s,i]=this.pageTranslation,[n,r]=this.pageDimensions;return l(this,Ts).serialize([s,i,n,r],e)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};Ts=new WeakMap,_h=new WeakMap,pe=new WeakMap,Xa=new WeakMap,Ua=new WeakMap,wr=new WeakMap,xr=new WeakMap,Sr=new WeakMap,Ya=new WeakMap,mt=new WeakSet,am=function({drawOutlines:e,drawId:s,drawingOptions:i}){m(this,Ts,e),this._drawingOptions||(this._drawingOptions=i),s>=0?(this._drawId=s,this.parent.drawLayer.finalizeDraw(s,e.defaultProperties)):this._drawId=w(this,mt,om).call(this,e,this.parent),w(this,mt,su).call(this,e.box)},om=function(e,s){const{id:i}=s.drawLayer.draw(U._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return i},hm=function(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())},eu=function(e=this.parent){if(!(this._drawId!==null&&this.parent===e)){if(this._drawId!==null){this.parent.drawLayer.updateParent(this._drawId,e.drawLayer);return}this._drawingOptions.updateAll(),this._drawId=w(this,mt,om).call(this,l(this,Ts),e)}},Qy=function([e,s,i,n]){const{parentDimensions:[r,a],rotation:h}=this;switch(h){case 90:return[s,1-e,i*(a/r),n*(r/a)];case 180:return[1-e,1-s,i,n];case 270:return[1-s,e,i*(a/r),n*(r/a)];default:return[e,s,i,n]}},yf=function(){const{x:e,y:s,width:i,height:n,parentDimensions:[r,a],rotation:h}=this;switch(h){case 90:return[1-s,e,i*(r/a),n*(a/r)];case 180:return[1-e,1-s,i,n];case 270:return[s,1-e,i*(r/a),n*(a/r)];default:return[e,s,i,n]}},su=function(e){if([this.x,this.y,this.width,this.height]=w(this,mt,Qy).call(this,e),this.div){this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)}this._onResized()},Bh=function(){const{x:e,y:s,width:i,height:n,rotation:r,parentRotation:a,parentDimensions:[h,c]}=this;switch((r*4+a)/90){case 1:return[1-s-n,e,n,i];case 2:return[1-e-i,1-s-n,i,n];case 3:return[s,1-e-i,n,i];case 4:return[e,s-i*(h/c),n*(c/h),i*(h/c)];case 5:return[1-s,e,i*(h/c),n*(c/h)];case 6:return[1-e-n*(c/h),1-s,n*(c/h),i*(h/c)];case 7:return[s-i*(h/c),1-e-n*(c/h),i*(h/c),n*(c/h)];case 8:return[e-i,s-n,i,n];case 9:return[1-s,e-i,n,i];case 10:return[1-e,1-s,i,n];case 11:return[s-n,1-e,n,i];case 12:return[e-n*(c/h),s,n*(c/h),i*(h/c)];case 13:return[1-s-i*(h/c),e-n*(c/h),i*(h/c),n*(c/h)];case 14:return[1-e,1-s-i*(h/c),n*(c/h),i*(h/c)];case 15:return[s,1-e,i*(h/c),n*(c/h)];default:return[e,s,i,n]}},J(U,"_currentDrawId",-1),J(U,"_currentParent",null),y(U,pe,null),y(U,Xa,null),y(U,Ua,null),y(U,wr,NaN),y(U,xr,null),y(U,Sr,null),y(U,Ya,NaN),J(U,"_INNER_MARGIN",3);let np=U;class FC{constructor(t,e,s,i,n,r){y(this,xh);y(this,Ni,new Float64Array(6));y(this,me);y(this,ve);y(this,$a);y(this,wh);y(this,$e);y(this,we,"");y(this,Ws,0);y(this,qa,new Td);y(this,Ka);y(this,Ja);m(this,Ka,s),m(this,Ja,i),m(this,$a,n),m(this,wh,r),[t,e]=w(this,xh,_f).call(this,t,e);const a=m(this,me,[NaN,NaN,NaN,NaN,t,e]);m(this,$e,[t,e]),m(this,ve,[{line:a,points:l(this,$e)}]),l(this,Ni).set(a,0)}updateProperty(t,e){t==="stroke-width"&&m(this,wh,e)}isEmpty(){return!l(this,ve)||l(this,ve).length===0}isCancellable(){return l(this,$e).length<=10}add(t,e){[t,e]=w(this,xh,_f).call(this,t,e);const[s,i,n,r]=l(this,Ni).subarray(2,6),a=t-n,h=e-r;return Math.hypot(l(this,Ka)*a,l(this,Ja)*h)<=2?null:(l(this,$e).push(t,e),isNaN(s)?(l(this,Ni).set([n,r,t,e],2),l(this,me).push(NaN,NaN,NaN,NaN,t,e),{path:{d:this.toSVGPath()}}):(isNaN(l(this,Ni)[0])&&l(this,me).splice(6,6),l(this,Ni).set([s,i,n,r,t,e],0),l(this,me).push(...X.createBezierPoints(s,i,n,r,t,e)),{path:{d:this.toSVGPath()}}))}end(t,e){const s=this.add(t,e);return s||(l(this,$e).length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,s,i,n){m(this,Ka,s),m(this,Ja,i),m(this,$a,n),[t,e]=w(this,xh,_f).call(this,t,e);const r=m(this,me,[NaN,NaN,NaN,NaN,t,e]);m(this,$e,[t,e]);const a=l(this,ve).at(-1);return a&&(a.line=new Float32Array(a.line),a.points=new Float32Array(a.points)),l(this,ve).push({line:r,points:l(this,$e)}),l(this,Ni).set(r,0),m(this,Ws,0),this.toSVGPath(),null}getLastElement(){return l(this,ve).at(-1)}setLastElement(t){return l(this,ve)?(l(this,ve).push(t),m(this,me,t.line),m(this,$e,t.points),m(this,Ws,0),{path:{d:this.toSVGPath()}}):l(this,qa).setLastElement(t)}removeLastElement(){if(!l(this,ve))return l(this,qa).removeLastElement();l(this,ve).pop(),m(this,we,"");for(let t=0,e=l(this,ve).length;t<e;t++){const{line:s,points:i}=l(this,ve)[t];m(this,me,s),m(this,$e,i),m(this,Ws,0),this.toSVGPath()}return{path:{d:l(this,we)}}}toSVGPath(){const t=X.svgRound(l(this,me)[4]),e=X.svgRound(l(this,me)[5]);if(l(this,$e).length===2)return m(this,we,`${l(this,we)} M ${t} ${e} Z`),l(this,we);if(l(this,$e).length<=6){const i=l(this,we).lastIndexOf("M");m(this,we,`${l(this,we).slice(0,i)} M ${t} ${e}`),m(this,Ws,6)}if(l(this,$e).length===4){const i=X.svgRound(l(this,me)[10]),n=X.svgRound(l(this,me)[11]);return m(this,we,`${l(this,we)} L ${i} ${n}`),m(this,Ws,12),l(this,we)}const s=[];l(this,Ws)===0&&(s.push(`M ${t} ${e}`),m(this,Ws,6));for(let i=l(this,Ws),n=l(this,me).length;i<n;i+=6){const[r,a,h,c,u,d]=l(this,me).slice(i,i+6).map(X.svgRound);s.push(`C${r} ${a} ${h} ${c} ${u} ${d}`)}return m(this,we,l(this,we)+s.join(" ")),m(this,Ws,l(this,me).length),l(this,we)}getOutlines(t,e,s,i){const n=l(this,ve).at(-1);return n.line=new Float32Array(n.line),n.points=new Float32Array(n.points),l(this,qa).build(l(this,ve),t,e,s,l(this,$a),l(this,wh),i),m(this,Ni,null),m(this,me,null),m(this,ve,null),m(this,we,null),l(this,qa)}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}Ni=new WeakMap,me=new WeakMap,ve=new WeakMap,$a=new WeakMap,wh=new WeakMap,$e=new WeakMap,we=new WeakMap,Ws=new WeakMap,qa=new WeakMap,Ka=new WeakMap,Ja=new WeakMap,xh=new WeakSet,_f=function(t,e){return X._normalizePoint(t,e,l(this,Ka),l(this,Ja),l(this,$a))};const gp=class gp extends X{constructor(){super(...arguments);y(this,xe);y(this,qe);y(this,Hc,0);y(this,Gc);y(this,Es);y(this,Bi);y(this,Hi);y(this,Sh);y(this,Ch);y(this,Ah)}build(e,s,i,n,r,a,h){m(this,Bi,s),m(this,Hi,i),m(this,Sh,n),m(this,Ch,r),m(this,Ah,a),m(this,Gc,h??0),m(this,Es,e),w(this,xe,t_).call(this)}setLastElement(e){return l(this,Es).push(e),{path:{d:this.toSVGPath()}}}removeLastElement(){return l(this,Es).pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const e=[];for(const{line:s}of l(this,Es)){if(e.push(`M${X.svgRound(s[4])} ${X.svgRound(s[5])}`),s.length===6){e.push("Z");continue}if(s.length===12){e.push(`L${X.svgRound(s[10])} ${X.svgRound(s[11])}`);continue}for(let i=6,n=s.length;i<n;i+=6){const[r,a,h,c,u,d]=s.subarray(i,i+6).map(X.svgRound);e.push(`C${r} ${a} ${h} ${c} ${u} ${d}`)}}return e.join("")}serialize([e,s,i,n],r){const a=[],h=[],[c,u,d,f]=w(this,xe,Zy).call(this);let g,p,v,_,b,x,C,A,P;switch(l(this,Ch)){case 0:P=X._rescale,g=e,p=s+n,v=i,_=-n,b=e+c*i,x=s+(1-u-f)*n,C=e+(c+d)*i,A=s+(1-u)*n;break;case 90:P=X._rescaleAndSwap,g=e,p=s,v=i,_=n,b=e+u*i,x=s+c*n,C=e+(u+f)*i,A=s+(c+d)*n;break;case 180:P=X._rescale,g=e+i,p=s,v=-i,_=n,b=e+(1-c-d)*i,x=s+u*n,C=e+(1-c)*i,A=s+(u+f)*n;break;case 270:P=X._rescaleAndSwap,g=e+i,p=s+n,v=-i,_=-n,b=e+(1-u-f)*i,x=s+(1-c-d)*n,C=e+(1-u)*i,A=s+(1-c)*n;break}for(const{line:D,points:k}of l(this,Es))a.push(P(D,g,p,v,_,r?new Array(D.length):null)),h.push(P(k,g,p,v,_,r?new Array(k.length):null));return{lines:a,points:h,rect:[b,x,C,A]}}static deserialize(e,s,i,n,r,{paths:{lines:a,points:h},rotation:c,thickness:u}){const d=[];let f,g,p,v,_;switch(c){case 0:_=X._rescale,f=-e/i,g=s/n+1,p=1/i,v=-1/n;break;case 90:_=X._rescaleAndSwap,f=-s/n,g=-e/i,p=1/n,v=1/i;break;case 180:_=X._rescale,f=e/i+1,g=-s/n,p=-1/i,v=1/n;break;case 270:_=X._rescaleAndSwap,f=s/n+1,g=e/i+1,p=-1/n,v=-1/i;break}if(!a){a=[];for(const x of h){const C=x.length;if(C===2){a.push(new Float32Array([NaN,NaN,NaN,NaN,x[0],x[1]]));continue}if(C===4){a.push(new Float32Array([NaN,NaN,NaN,NaN,x[0],x[1],NaN,NaN,NaN,NaN,x[2],x[3]]));continue}const A=new Float32Array(3*(C-2));a.push(A);let[P,D,k,M]=x.subarray(0,4);A.set([NaN,NaN,NaN,NaN,P,D],0);for(let R=4;R<C;R+=2){const F=x[R],I=x[R+1];A.set(X.createBezierPoints(P,D,k,M,F,I),(R-2)*3),[P,D,k,M]=[k,M,F,I]}}}for(let x=0,C=a.length;x<C;x++)d.push({line:_(a[x].map(A=>A??NaN),f,g,p,v),points:_(h[x].map(A=>A??NaN),f,g,p,v)});const b=new gp;return b.build(d,i,n,1,c,u,r),b}get box(){return l(this,qe)}updateProperty(e,s){return e==="stroke-width"?w(this,xe,e_).call(this,s):null}updateParentDimensions([e,s],i){const[n,r]=w(this,xe,Nn).call(this);m(this,Bi,e),m(this,Hi,s),m(this,Sh,i);const[a,h]=w(this,xe,Nn).call(this),c=a-n,u=h-r,d=l(this,qe);return d[0]-=c,d[1]-=u,d[2]+=2*c,d[3]+=2*u,d}updateRotation(e){return m(this,Hc,e),{path:{transform:this.rotationTransform}}}get viewBox(){return l(this,qe).map(X.svgRound).join(" ")}get defaultProperties(){const[e,s]=l(this,qe);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${X.svgRound(e)} ${X.svgRound(s)}`}}}get rotationTransform(){const[,,e,s]=l(this,qe);let i=0,n=0,r=0,a=0,h=0,c=0;switch(l(this,Hc)){case 90:n=s/e,r=-e/s,h=e;break;case 180:i=-1,a=-1,h=e,c=s;break;case 270:n=-s/e,r=e/s,c=s;break;default:return""}return`matrix(${i} ${n} ${r} ${a} ${X.svgRound(h)} ${X.svgRound(c)})`}getPathResizingSVGProperties([e,s,i,n]){const[r,a]=w(this,xe,Nn).call(this),[h,c,u,d]=l(this,qe);if(Math.abs(u-r)<=X.PRECISION||Math.abs(d-a)<=X.PRECISION){const _=e+i/2-(h+u/2),b=s+n/2-(c+d/2);return{path:{"transform-origin":`${X.svgRound(e)} ${X.svgRound(s)}`,transform:`${this.rotationTransform} translate(${_} ${b})`}}}const f=(i-2*r)/(u-2*r),g=(n-2*a)/(d-2*a),p=u/i,v=d/n;return{path:{"transform-origin":`${X.svgRound(h)} ${X.svgRound(c)}`,transform:`${this.rotationTransform} scale(${p} ${v}) translate(${X.svgRound(r)} ${X.svgRound(a)}) scale(${f} ${g}) translate(${X.svgRound(-r)} ${X.svgRound(-a)})`}}}getPathResizedSVGProperties([e,s,i,n]){const[r,a]=w(this,xe,Nn).call(this),h=l(this,qe),[c,u,d,f]=h;if(h[0]=e,h[1]=s,h[2]=i,h[3]=n,Math.abs(d-r)<=X.PRECISION||Math.abs(f-a)<=X.PRECISION){const b=e+i/2-(c+d/2),x=s+n/2-(u+f/2);for(const{line:C,points:A}of l(this,Es))X._translate(C,b,x,C),X._translate(A,b,x,A);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${X.svgRound(e)} ${X.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const g=(i-2*r)/(d-2*r),p=(n-2*a)/(f-2*a),v=-g*(c+r)+e+r,_=-p*(u+a)+s+a;if(g!==1||p!==1||v!==0||_!==0)for(const{line:b,points:x}of l(this,Es))X._rescale(b,v,_,g,p,b),X._rescale(x,v,_,g,p,x);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${X.svgRound(e)} ${X.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,s],i){const[n,r]=i,a=l(this,qe),h=e-a[0],c=s-a[1];if(l(this,Bi)===n&&l(this,Hi)===r)for(const{line:u,points:d}of l(this,Es))X._translate(u,h,c,u),X._translate(d,h,c,d);else{const u=l(this,Bi)/n,d=l(this,Hi)/r;m(this,Bi,n),m(this,Hi,r);for(const{line:f,points:g}of l(this,Es))X._rescale(f,h,c,u,d,f),X._rescale(g,h,c,u,d,g);a[2]*=u,a[3]*=d}return a[0]=e,a[1]=s,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${X.svgRound(e)} ${X.svgRound(s)}`}}}get defaultSVGProperties(){const e=l(this,qe);return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${X.svgRound(e[0])} ${X.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}};qe=new WeakMap,Hc=new WeakMap,Gc=new WeakMap,Es=new WeakMap,Bi=new WeakMap,Hi=new WeakMap,Sh=new WeakMap,Ch=new WeakMap,Ah=new WeakMap,xe=new WeakSet,Nn=function(e=l(this,Ah)){const s=l(this,Gc)+e/2*l(this,Sh);return l(this,Ch)%180===0?[s/l(this,Bi),s/l(this,Hi)]:[s/l(this,Hi),s/l(this,Bi)]},Zy=function(){const[e,s,i,n]=l(this,qe),[r,a]=w(this,xe,Nn).call(this,0);return[e+r,s+a,i-2*r,n-2*a]},t_=function(){const e=m(this,qe,new Float32Array([1/0,1/0,-1/0,-1/0]));for(const{line:n}of l(this,Es)){if(n.length<=12){for(let h=4,c=n.length;h<c;h+=6){const[u,d]=n.subarray(h,h+2);e[0]=Math.min(e[0],u),e[1]=Math.min(e[1],d),e[2]=Math.max(e[2],u),e[3]=Math.max(e[3],d)}continue}let r=n[4],a=n[5];for(let h=6,c=n.length;h<c;h+=6){const[u,d,f,g,p,v]=n.subarray(h,h+6);q.bezierBoundingBox(r,a,u,d,f,g,p,v,e),r=p,a=v}}const[s,i]=w(this,xe,Nn).call(this);e[0]=Math.min(1,Math.max(0,e[0]-s)),e[1]=Math.min(1,Math.max(0,e[1]-i)),e[2]=Math.min(1,Math.max(0,e[2]+s)),e[3]=Math.min(1,Math.max(0,e[3]+i)),e[2]-=e[0],e[3]-=e[1]},e_=function(e){const[s,i]=w(this,xe,Nn).call(this);m(this,Ah,e);const[n,r]=w(this,xe,Nn).call(this),[a,h]=[n-s,r-i],c=l(this,qe);return c[0]-=a,c[1]-=h,c[2]+=2*a,c[3]+=2*h,c};let Td=gp;const pp=class pp extends LC{constructor(e){super();y(this,Th);m(this,Th,e),super.updateProperties({fill:"none",stroke:Ht._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(e,s){e==="stroke-width"&&(s??(s=this["stroke-width"]),s*=l(this,Th).realScale),super.updateSVGProperty(e,s)}clone(){const e=new pp(l(this,Th));return e.updateAll(this),e}};Th=new WeakMap;let rp=pp;const Eh=class Eh extends np{constructor(e){super({...e,name:"inkEditor"});y(this,zd);this._willKeepAspectRatio=!0}static initialize(e,s){Ht.initialize(e,s),this._defaultDrawingOptions=new rp(s.viewParameters)}static getDefaultDrawingOptions(e){const s=this._defaultDrawingOptions.clone();return s.updateProperties(e),s}static get supportMultipleDrawings(){return!0}static get typesMap(){return ht(this,"typesMap",new Map([[dt.INK_THICKNESS,"stroke-width"],[dt.INK_COLOR,"stroke"],[dt.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(e,s,i,n,r){return new FC(e,s,i,n,r,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(e,s,i,n,r,a){return Td.deserialize(e,s,i,n,r,a)}static async deserialize(e,s,i){let n=null;if(e instanceof tp){const{data:{inkLists:a,rect:h,rotation:c,id:u,color:d,opacity:f,borderStyle:{rawWidth:g},popupRef:p},parent:{page:{pageNumber:v}}}=e;n=e={annotationType:nt.INK,color:Array.from(d),thickness:g,opacity:f,paths:{points:a},boxes:null,pageIndex:v-1,rect:h.slice(0),rotation:c,id:u,deleted:!1,popupRef:p}}const r=await super.deserialize(e,s,i);return r.annotationElementId=e.id||null,r._initialData=n,r}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();const{_drawId:e,_drawingOptions:s,parent:i}=this;s.updateSVGProperty("stroke-width"),i.drawLayer.updateProperties(e,s.toSVGProperties())}static onScaleChangingWhenDrawing(){const e=this._currentParent;e&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),e.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:e,thickness:s,opacity:i}){this._drawingOptions=Eh.getDefaultDrawingOptions({stroke:q.makeHexColor(...e),"stroke-width":s,"stroke-opacity":i})}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:s,points:i,rect:n}=this.serializeDraw(e),{_drawingOptions:{stroke:r,"stroke-opacity":a,"stroke-width":h}}=this,c={annotationType:nt.INK,color:Ht._colorManager.convert(r),opacity:a,thickness:h,paths:{lines:s,points:i},pageIndex:this.pageIndex,rect:n,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?c:this.annotationElementId&&!w(this,zd,s_).call(this,c)?null:(c.id=this.annotationElementId,c)}renderAnnotationElement(e){const{points:s,rect:i}=this.serializeDraw(!1);return e.updateEdited({rect:i,thickness:this._drawingOptions["stroke-width"],points:s}),null}};zd=new WeakSet,s_=function(e){const{color:s,thickness:i,opacity:n,pageIndex:r}=this._initialData;return this._hasBeenMoved||this._hasBeenResized||e.color.some((a,h)=>a!==s[h])||e.thickness!==i||e.opacity!==n||e.pageIndex!==r},J(Eh,"_type","ink"),J(Eh,"_editorType",nt.INK),J(Eh,"_defaultDrawingOptions",null);let ap=Eh;const Vc=class Vc extends Ht{constructor(e){super({...e,name:"stampEditor"});y(this,vt);y(this,Vt,null);y(this,Se,null);y(this,Cr,null);y(this,Rn,null);y(this,Ar,null);y(this,kh,"");y(this,Gi,null);y(this,Vi,null);y(this,ks,!1);y(this,Ph,!1);m(this,Rn,e.bitmapUrl),m(this,Ar,e.bitmapFile)}static initialize(e,s){Ht.initialize(e,s)}static get supportedTypes(){return ht(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(s=>`image/${s}`))}static get supportedTypesStr(){return ht(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(e){return this.supportedTypes.includes(e)}static paste(e,s){s.pasteEditor(nt.STAMP,{bitmapFile:e.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){var e;return{type:"stamp",hasAltText:!!((e=this.altTextData)!=null&&e.altText)}}static computeTelemetryFinalData(e){const s=e.get("hasAltText");return{hasAltText:s.get(!0)??0,hasNoAltText:s.get(!1)??0}}async mlGuessAltText(e=null,s=!0){if(this.hasAltTextData())return null;const{mlManager:i}=this._uiManager;if(!i)throw new Error("No ML.");if(!await i.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:n,width:r,height:a}=e||this.copyCanvas(null,null,!0).imageData,h=await i.guess({name:"altText",request:{data:n,width:r,height:a,channels:n.length/(r*a)}});if(!h)throw new Error("No response from the AI service.");if(h.error)throw new Error("Error from the AI service.");if(h.cancel)return null;if(!h.output)throw new Error("No valid response from the AI service.");const c=h.output;return await this.setGuessedAltText(c),s&&!this.hasAltTextData()&&(this.altTextData={alt:c,decorative:!1}),c}remove(){var e;l(this,Se)&&(m(this,Vt,null),this._uiManager.imageManager.deleteId(l(this,Se)),(e=l(this,Gi))==null||e.remove(),m(this,Gi,null),l(this,Vi)&&(clearTimeout(l(this,Vi)),m(this,Vi,null))),super.remove()}rebuild(){if(!this.parent){l(this,Se)&&w(this,vt,wf).call(this);return}super.rebuild(),this.div!==null&&(l(this,Se)&&l(this,Gi)===null&&w(this,vt,wf).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(e){this._isDraggable=!0,e&&this.div.focus()}isEmpty(){return!(l(this,Cr)||l(this,Vt)||l(this,Rn)||l(this,Ar)||l(this,Se))}get isResizable(){return!0}render(){if(this.div)return this.div;let e,s;if(this.width&&(e=this.x,s=this.y),super.render(),this.div.hidden=!0,this.div.setAttribute("role","figure"),this.addAltTextButton(),l(this,Vt)?w(this,vt,lm).call(this):w(this,vt,wf).call(this),this.width&&!this.annotationElementId){const[i,n]=this.parentDimensions;this.setAt(e*i,s*n,this.width*i,this.height*n)}return this._uiManager.addShouldRescale(this),this.div}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;l(this,Vi)!==null&&clearTimeout(l(this,Vi)),m(this,Vi,setTimeout(()=>{m(this,Vi,null),w(this,vt,cm).call(this)},200))}copyCanvas(e,s,i=!1){var g;e||(e=224);const{width:n,height:r}=l(this,Vt),a=new Ng;let h=l(this,Vt),c=n,u=r,d=null;if(s){if(n>s||r>s){const M=Math.min(s/n,s/r);c=Math.floor(n*M),u=Math.floor(r*M)}d=document.createElement("canvas");const p=d.width=Math.ceil(c*a.sx),v=d.height=Math.ceil(u*a.sy);l(this,ks)||(h=w(this,vt,xf).call(this,p,v));const _=d.getContext("2d");_.filter=this._uiManager.hcmFilter;let b="white",x="#cfcfd8";this._uiManager.hcmFilter!=="none"?x="black":(g=window.matchMedia)!=null&&g.call(window,"(prefers-color-scheme: dark)").matches&&(b="#8f8f9d",x="#42414d");const C=15,A=C*a.sx,P=C*a.sy,D=new OffscreenCanvas(A*2,P*2),k=D.getContext("2d");k.fillStyle=b,k.fillRect(0,0,A*2,P*2),k.fillStyle=x,k.fillRect(0,0,A,P),k.fillRect(A,P,A,P),_.fillStyle=_.createPattern(D,"repeat"),_.fillRect(0,0,p,v),_.drawImage(h,0,0,h.width,h.height,0,0,p,v)}let f=null;if(i){let p,v;if(a.symmetric&&h.width<e&&h.height<e)p=h.width,v=h.height;else if(h=l(this,Vt),n>e||r>e){const x=Math.min(e/n,e/r);p=Math.floor(n*x),v=Math.floor(r*x),l(this,ks)||(h=w(this,vt,xf).call(this,p,v))}const b=new OffscreenCanvas(p,v).getContext("2d",{willReadFrequently:!0});b.drawImage(h,0,0,h.width,h.height,0,0,p,v),f={width:p,height:v,data:b.getImageData(0,0,p,v).data}}return{canvas:d,width:c,height:u,imageData:f}}getImageForAltText(){return l(this,Gi)}static async deserialize(e,s,i){var v;let n=null;if(e instanceof fb){const{data:{rect:_,rotation:b,id:x,structParent:C,popupRef:A},container:P,parent:{page:{pageNumber:D}}}=e,k=P.querySelector("canvas"),M=i.imageManager.getFromCanvas(P.id,k);k.remove();const R=((v=await s._structTree.getAriaAttributes(`${Rg}${x}`))==null?void 0:v.get("aria-label"))||"";n=e={annotationType:nt.STAMP,bitmapId:M.id,bitmap:M.bitmap,pageIndex:D-1,rect:_.slice(0),rotation:b,id:x,deleted:!1,accessibilityData:{decorative:!1,altText:R},isSvg:!1,structParent:C,popupRef:A}}const r=await super.deserialize(e,s,i),{rect:a,bitmap:h,bitmapUrl:c,bitmapId:u,isSvg:d,accessibilityData:f}=e;u&&i.imageManager.isValidId(u)?(m(r,Se,u),h&&m(r,Vt,h)):m(r,Rn,c),m(r,ks,d);const[g,p]=r.pageDimensions;return r.width=(a[2]-a[0])/g,r.height=(a[3]-a[1])/p,r.annotationElementId=e.id||null,f&&(r.altTextData=f),r._initialData=n,m(r,Ph,!!n),r}serialize(e=!1,s=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const i={annotationType:nt.STAMP,bitmapId:l(this,Se),pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:l(this,ks),structTreeParentId:this._structTreeParentId};if(e)return i.bitmapUrl=w(this,vt,Sf).call(this,!0),i.accessibilityData=this.serializeAltText(!0),i;const{decorative:n,altText:r}=this.serializeAltText(!1);if(!n&&r&&(i.accessibilityData={type:"Figure",alt:r}),this.annotationElementId){const h=w(this,vt,i_).call(this,i);if(h.isSame)return null;h.isSameAltText?delete i.accessibilityData:i.accessibilityData.structParent=this._initialData.structParent??-1}if(i.id=this.annotationElementId,s===null)return i;s.stamps||(s.stamps=new Map);const a=l(this,ks)?(i.rect[2]-i.rect[0])*(i.rect[3]-i.rect[1]):null;if(!s.stamps.has(l(this,Se)))s.stamps.set(l(this,Se),{area:a,serialized:i}),i.bitmap=w(this,vt,Sf).call(this,!1);else if(l(this,ks)){const h=s.stamps.get(l(this,Se));a>h.area&&(h.area=a,h.serialized.bitmap.close(),h.serialized.bitmap=w(this,vt,Sf).call(this,!1))}return i}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}};Vt=new WeakMap,Se=new WeakMap,Cr=new WeakMap,Rn=new WeakMap,Ar=new WeakMap,kh=new WeakMap,Gi=new WeakMap,Vi=new WeakMap,ks=new WeakMap,Ph=new WeakMap,vt=new WeakSet,iu=function(e,s=!1){if(!e){this.remove();return}m(this,Vt,e.bitmap),s||(m(this,Se,e.id),m(this,ks,e.isSvg)),e.file&&m(this,kh,e.file.name),w(this,vt,lm).call(this)},nu=function(){if(m(this,Cr,null),this._uiManager.enableWaiting(!1),!!l(this,Gi)){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Vt)){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Vt)){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}},wf=function(){if(l(this,Se)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(l(this,Se)).then(i=>w(this,vt,iu).call(this,i,!0)).finally(()=>w(this,vt,nu).call(this));return}if(l(this,Rn)){const i=l(this,Rn);m(this,Rn,null),this._uiManager.enableWaiting(!0),m(this,Cr,this._uiManager.imageManager.getFromUrl(i).then(n=>w(this,vt,iu).call(this,n)).finally(()=>w(this,vt,nu).call(this)));return}if(l(this,Ar)){const i=l(this,Ar);m(this,Ar,null),this._uiManager.enableWaiting(!0),m(this,Cr,this._uiManager.imageManager.getFromFile(i).then(n=>w(this,vt,iu).call(this,n)).finally(()=>w(this,vt,nu).call(this)));return}const e=document.createElement("input");e.type="file",e.accept=Vc.supportedTypesStr;const s=this._uiManager._signal;m(this,Cr,new Promise(i=>{e.addEventListener("change",async()=>{if(!e.files||e.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const n=await this._uiManager.imageManager.getFromFile(e.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),w(this,vt,iu).call(this,n)}i()},{signal:s}),e.addEventListener("cancel",()=>{this.remove(),i()},{signal:s})}).finally(()=>w(this,vt,nu).call(this))),e.click()},lm=function(){var d;const{div:e}=this;let{width:s,height:i}=l(this,Vt);const[n,r]=this.pageDimensions,a=.75;if(this.width)s=this.width*n,i=this.height*r;else if(s>a*n||i>a*r){const f=Math.min(a*n/s,a*r/i);s*=f,i*=f}const[h,c]=this.parentDimensions;this.setDims(s*h/n,i*c/r),this._uiManager.enableWaiting(!1);const u=m(this,Gi,document.createElement("canvas"));u.setAttribute("role","img"),this.addContainer(u),this.width=s/n,this.height=i/r,(d=this._initialOptions)!=null&&d.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(e.hidden=!1),w(this,vt,cm).call(this),l(this,Ph)||(this.parent.addUndoableEditor(this),m(this,Ph,!0)),this._reportTelemetry({action:"inserted_image"}),l(this,kh)&&u.setAttribute("aria-label",l(this,kh))},xf=function(e,s){const{width:i,height:n}=l(this,Vt);let r=i,a=n,h=l(this,Vt);for(;r>2*e||a>2*s;){const c=r,u=a;r>2*e&&(r=r>=16384?Math.floor(r/2)-1:Math.ceil(r/2)),a>2*s&&(a=a>=16384?Math.floor(a/2)-1:Math.ceil(a/2));const d=new OffscreenCanvas(r,a);d.getContext("2d").drawImage(h,0,0,c,u,0,0,r,a),h=d.transferToImageBitmap()}return h},cm=function(){const[e,s]=this.parentDimensions,{width:i,height:n}=this,r=new Ng,a=Math.ceil(i*e*r.sx),h=Math.ceil(n*s*r.sy),c=l(this,Gi);if(!c||c.width===a&&c.height===h)return;c.width=a,c.height=h;const u=l(this,ks)?l(this,Vt):w(this,vt,xf).call(this,a,h),d=c.getContext("2d");d.filter=this._uiManager.hcmFilter,d.drawImage(u,0,0,u.width,u.height,0,0,a,h)},Sf=function(e){if(e){if(l(this,ks)){const n=this._uiManager.imageManager.getSvgUrl(l(this,Se));if(n)return n}const s=document.createElement("canvas");return{width:s.width,height:s.height}=l(this,Vt),s.getContext("2d").drawImage(l(this,Vt),0,0),s.toDataURL()}if(l(this,ks)){const[s,i]=this.pageDimensions,n=Math.round(this.width*s*Kn.PDF_TO_CSS_UNITS),r=Math.round(this.height*i*Kn.PDF_TO_CSS_UNITS),a=new OffscreenCanvas(n,r);return a.getContext("2d").drawImage(l(this,Vt),0,0,l(this,Vt).width,l(this,Vt).height,0,0,n,r),a.transferToImageBitmap()}return structuredClone(l(this,Vt))},i_=function(e){var a;const{pageIndex:s,accessibilityData:{altText:i}}=this._initialData,n=e.pageIndex===s,r=(((a=e.accessibilityData)==null?void 0:a.alt)||"")===i;return{isSame:!this._hasBeenMoved&&!this._hasBeenResized&&n&&r,isSameAltText:r}},J(Vc,"_type","stamp"),J(Vc,"_editorType",nt.STAMP);let op=Vc;const vi=class vi{constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:a,textLayer:h,viewport:c,l10n:u}){y(this,Nt);y(this,Qa);y(this,Mh,!1);y(this,Wi,null);y(this,Tr,null);y(this,Ln,null);y(this,zs,new Map);y(this,Er,!1);y(this,Oh,!1);y(this,Za,!1);y(this,mi,null);y(this,Fn,null);y(this,Fe,null);y(this,In,null);y(this,$);const d=[...l(vi,kr).values()];if(!vi._initialized){vi._initialized=!0;for(const f of d)f.initialize(u,t)}t.registerEditorTypes(d),m(this,$,t),this.pageIndex=e,this.div=s,m(this,Qa,n),m(this,Wi,r),this.viewport=c,m(this,Fe,h),this.drawLayer=a,this._structTree=i,l(this,$).addLayer(this)}get isEmpty(){return l(this,zs).size===0}get isInvisible(){return this.isEmpty&&l(this,$).getMode()===nt.NONE}updateToolbar(t){l(this,$).updateToolbar(t)}updateMode(t=l(this,$).getMode()){switch(w(this,Nt,Cf).call(this),t){case nt.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case nt.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case nt.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);const{classList:e}=this.div;for(const s of l(vi,kr).values())e.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){var e;return t===((e=l(this,Fe))==null?void 0:e.div)}setEditingState(t){l(this,$).setEditingState(t)}addCommands(t){l(this,$).addCommands(t)}cleanUndoStack(t){l(this,$).cleanUndoStack(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){var e;(e=l(this,Wi))==null||e.div.classList.toggle("disabled",!t)}async enable(){m(this,Za,!0),this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const s of l(this,zs).values())s.enableEditing(),s.show(!0),s.annotationElementId&&(l(this,$).removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!l(this,Wi)){m(this,Za,!1);return}const e=l(this,Wi).getEditableAnnotations();for(const s of e){if(s.hide(),l(this,$).isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;const i=await this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}m(this,Za,!1)}disable(){var i;m(this,Oh,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,e=new Map;for(const n of l(this,zs).values())if(n.disableEditing(),!!n.annotationElementId){if(n.serialize()!==null){t.set(n.annotationElementId,n);continue}else e.set(n.annotationElementId,n);(i=this.getEditableAnnotation(n.annotationElementId))==null||i.show(),n.remove()}if(l(this,Wi)){const n=l(this,Wi).getEditableAnnotations();for(const r of n){const{id:a}=r.data;if(l(this,$).isDeletedAnnotationElement(a))continue;let h=e.get(a);if(h){h.resetAnnotationElement(r),h.show(!1),r.show();continue}h=t.get(a),h&&(l(this,$).addChangedExistingAnnotation(h),h.renderAnnotationElement(r)&&h.show(!1)),r.show()}}w(this,Nt,Cf).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const n of l(vi,kr).values())s.remove(`${n._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),m(this,Oh,!1)}getEditableAnnotation(t){var e;return((e=l(this,Wi))==null?void 0:e.getEditableAnnotation(t))||null}setActiveEditor(t){l(this,$).getActive()!==t&&l(this,$).setActiveEditor(t)}enableTextSelection(){var t;if(this.div.tabIndex=-1,(t=l(this,Fe))!=null&&t.div&&!l(this,In)){m(this,In,new AbortController);const e=l(this,$).combinedSignal(l(this,In));l(this,Fe).div.addEventListener("pointerdown",w(this,Nt,n_).bind(this),{signal:e}),l(this,Fe).div.classList.add("highlighting")}}disableTextSelection(){var t;this.div.tabIndex=0,(t=l(this,Fe))!=null&&t.div&&l(this,In)&&(l(this,In).abort(),m(this,In,null),l(this,Fe).div.classList.remove("highlighting"))}enableClick(){if(l(this,Tr))return;m(this,Tr,new AbortController);const t=l(this,$).combinedSignal(l(this,Tr));this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t});const e=this.pointerup.bind(this);this.div.addEventListener("pointerup",e,{signal:t}),this.div.addEventListener("pointercancel",e,{signal:t})}disableClick(){var t;(t=l(this,Tr))==null||t.abort(),m(this,Tr,null)}attach(t){l(this,zs).set(t.id,t);const{annotationElementId:e}=t;e&&l(this,$).isDeletedAnnotationElement(e)&&l(this,$).removeDeletedAnnotationElement(t)}detach(t){var e;l(this,zs).delete(t.id),(e=l(this,Qa))==null||e.removePointerInTextLayer(t.contentDiv),!l(this,Oh)&&t.annotationElementId&&l(this,$).addDeletedAnnotationElement(t)}remove(t){this.detach(t),l(this,$).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){var e;t.parent!==this&&(t.parent&&t.annotationElementId&&(l(this,$).addDeletedAnnotationElement(t.annotationElementId),Ht.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),(e=t.parent)==null||e.detach(t),t.setParent(this),t.div&&t.isAttachedToDOM&&(t.div.remove(),this.div.append(t.div)))}add(t){if(!(t.parent===this&&t.isAttachedToDOM)){if(this.changeParent(t),l(this,$).addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!l(this,Za)),l(this,$).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var s;if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!l(this,Ln)&&(t._focusEventsAllowed=!1,m(this,Ln,setTimeout(()=>{m(this,Ln,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:l(this,$)._signal}),e.focus())},0))),t._structTreeParentId=(s=l(this,Qa))==null?void 0:s.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){t.needsToBeRebuilt()?(t.parent||(t.parent=this),t.rebuild(),t.show()):this.add(t)}addUndoableEditor(t){const e=()=>t._uiManager.rebuild(t),s=()=>{t.remove()};this.addCommands({cmd:e,undo:s,mustExec:!1})}getNextId(){return l(this,$).getId()}combinedSignal(t){return l(this,$).combinedSignal(t)}canCreateNewEmptyEditor(){var t;return(t=l(this,Nt,Ui))==null?void 0:t.canCreateNewEmptyEditor()}pasteEditor(t,e){l(this,$).updateToolbar(t),l(this,$).updateMode(t);const{offsetX:s,offsetY:i}=w(this,Nt,dm).call(this),n=this.getNextId(),r=w(this,Nt,um).call(this,{parent:this,id:n,x:s,y:i,uiManager:l(this,$),isCentered:!0,...e});r&&this.add(r)}async deserialize(t){var e;return await((e=l(vi,kr).get(t.annotationType??t.annotationEditorType))==null?void 0:e.deserialize(t,this,l(this,$)))||null}createAndAddNewEditor(t,e,s={}){const i=this.getNextId(),n=w(this,Nt,um).call(this,{parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:l(this,$),isCentered:e,...s});return n&&this.add(n),n}addNewEditor(){this.createAndAddNewEditor(w(this,Nt,dm).call(this),!0)}setSelected(t){l(this,$).setSelected(t)}toggleSelected(t){l(this,$).toggleSelected(t)}unselect(t){l(this,$).unselect(t)}pointerup(t){var s;const{isMac:e}=ze.platform;if(!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&l(this,Er)&&(m(this,Er,!1),!((s=l(this,Nt,Ui))!=null&&s.isDrawer&&l(this,Nt,Ui).supportMultipleDrawings))){if(!l(this,Mh)){m(this,Mh,!0);return}if(l(this,$).getMode()===nt.STAMP){l(this,$).unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){var i;if(l(this,$).getMode()===nt.HIGHLIGHT&&this.enableTextSelection(),l(this,Er)){m(this,Er,!1);return}const{isMac:e}=ze.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;if(m(this,Er,!0),(i=l(this,Nt,Ui))!=null&&i.isDrawer){this.startDrawingSession(t);return}const s=l(this,$).getActive();m(this,Mh,!s||s.isEmpty())}startDrawingSession(t){if(this.div.focus(),l(this,mi)){l(this,Nt,Ui).startDrawing(this,l(this,$),!1,t);return}l(this,$).setCurrentDrawingSession(this),m(this,mi,new AbortController);const e=l(this,$).combinedSignal(l(this,mi));this.div.addEventListener("blur",({relatedTarget:s})=>{s&&!this.div.contains(s)&&(m(this,Fn,null),this.commitOrRemove())},{signal:e}),l(this,Nt,Ui).startDrawing(this,l(this,$),!1,t)}pause(t){if(t){const{activeElement:e}=document;this.div.contains(e)&&m(this,Fn,e);return}l(this,Fn)&&setTimeout(()=>{var e;(e=l(this,Fn))==null||e.focus(),m(this,Fn,null)},0)}endDrawingSession(t=!1){return l(this,mi)?(l(this,$).setCurrentDrawingSession(null),l(this,mi).abort(),m(this,mi,null),m(this,Fn,null),l(this,Nt,Ui).endDrawing(t)):null}findNewParent(t,e,s){const i=l(this,$).findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}commitOrRemove(){return l(this,mi)?(this.endDrawingSession(),!0):!1}onScaleChanging(){l(this,mi)&&l(this,Nt,Ui).onScaleChangingWhenDrawing(this)}destroy(){var t,e;this.commitOrRemove(),((t=l(this,$).getActive())==null?void 0:t.parent)===this&&(l(this,$).commitOrRemove(),l(this,$).setActiveEditor(null)),l(this,Ln)&&(clearTimeout(l(this,Ln)),m(this,Ln,null));for(const s of l(this,zs).values())(e=l(this,Qa))==null||e.removePointerInTextLayer(s.contentDiv),s.setParent(null),s.isAttachedToDOM=!1,s.div.remove();this.div=null,l(this,zs).clear(),l(this,$).removeLayer(this)}render({viewport:t}){this.viewport=t,zr(this.div,t);for(const e of l(this,$).getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){l(this,$).commitOrRemove(),w(this,Nt,Cf).call(this);const e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,zr(this.div,{rotation:s}),e!==s)for(const i of l(this,zs).values())i.rotate(s)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return l(this,$).viewParameters.realScale}};Qa=new WeakMap,Mh=new WeakMap,Wi=new WeakMap,Tr=new WeakMap,Ln=new WeakMap,zs=new WeakMap,Er=new WeakMap,Oh=new WeakMap,Za=new WeakMap,mi=new WeakMap,Fn=new WeakMap,Fe=new WeakMap,In=new WeakMap,$=new WeakMap,kr=new WeakMap,Nt=new WeakSet,n_=function(t){l(this,$).unselectAll();const{target:e}=t;if(e===l(this,Fe).div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&l(this,Fe).div.contains(e)){const{isMac:s}=ze.platform;if(t.button!==0||t.ctrlKey&&s)return;l(this,$).showAllEditors("highlight",!0,!0),l(this,Fe).div.classList.add("free"),this.toggleDrawing(),Ad.startHighlighting(this,l(this,$).direction==="ltr",{target:l(this,Fe).div,x:t.x,y:t.y}),l(this,Fe).div.addEventListener("pointerup",()=>{l(this,Fe).div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:l(this,$)._signal}),t.preventDefault()}},Ui=function(){return l(vi,kr).get(l(this,$).getMode())},um=function(t){const e=l(this,Nt,Ui);return e?new e.prototype.constructor(t):null},dm=function(){const{x:t,y:e,width:s,height:i}=this.div.getBoundingClientRect(),n=Math.max(0,t),r=Math.max(0,e),a=Math.min(window.innerWidth,t+s),h=Math.min(window.innerHeight,e+i),c=(n+a)/2-t,u=(r+h)/2-e,[d,f]=this.viewport.rotation%180===0?[c,u]:[u,c];return{offsetX:d,offsetY:f}},Cf=function(){for(const t of l(this,zs).values())t.isEmpty()&&t.remove()},J(vi,"_initialized",!1),y(vi,kr,new Map([ep,ap,op,Ad].map(t=>[t._editorType,t])));let hp=vi;const Ie=class Ie{constructor({pageIndex:t}){y(this,zi);y(this,bi,null);y(this,Wc,0);y(this,Ke,new Map);y(this,to,new Map);this.pageIndex=t}setParent(t){if(!l(this,bi)){m(this,bi,t);return}if(l(this,bi)!==t){if(l(this,Ke).size>0)for(const e of l(this,Ke).values())e.remove(),t.append(e);m(this,bi,t)}}static get _svgFactory(){return ht(this,"_svgFactory",new Qg)}draw(t,e=!1,s=!1){const i=Ze(this,Wc)._++,n=w(this,zi,fm).call(this),r=Ie._svgFactory.createElement("defs");n.append(r);const a=Ie._svgFactory.createElement("path");r.append(a);const h=`path_p${this.pageIndex}_${i}`;a.setAttribute("id",h),a.setAttribute("vector-effect","non-scaling-stroke"),e&&l(this,to).set(i,a);const c=s?w(this,zi,a_).call(this,r,h):null,u=Ie._svgFactory.createElement("use");return n.append(u),u.setAttribute("href",`#${h}`),this.updateProperties(n,t),l(this,Ke).set(i,n),{id:i,clipPathId:`url(#${c})`}}drawOutline(t,e){const s=Ze(this,Wc)._++,i=w(this,zi,fm).call(this),n=Ie._svgFactory.createElement("defs");i.append(n);const r=Ie._svgFactory.createElement("path");n.append(r);const a=`path_p${this.pageIndex}_${s}`;r.setAttribute("id",a),r.setAttribute("vector-effect","non-scaling-stroke");let h;if(e){const d=Ie._svgFactory.createElement("mask");n.append(d),h=`mask_p${this.pageIndex}_${s}`,d.setAttribute("id",h),d.setAttribute("maskUnits","objectBoundingBox");const f=Ie._svgFactory.createElement("rect");d.append(f),f.setAttribute("width","1"),f.setAttribute("height","1"),f.setAttribute("fill","white");const g=Ie._svgFactory.createElement("use");d.append(g),g.setAttribute("href",`#${a}`),g.setAttribute("stroke","none"),g.setAttribute("fill","black"),g.setAttribute("fill-rule","nonzero"),g.classList.add("mask")}const c=Ie._svgFactory.createElement("use");i.append(c),c.setAttribute("href",`#${a}`),h&&c.setAttribute("mask",`url(#${h})`);const u=c.cloneNode();return i.append(u),c.classList.add("mainOutline"),u.classList.add("secondaryOutline"),this.updateProperties(i,t),l(this,Ke).set(s,i),s}finalizeDraw(t,e){l(this,to).delete(t),this.updateProperties(t,e)}updateProperties(t,e){var h;if(!e)return;const{root:s,bbox:i,rootClass:n,path:r}=e,a=typeof t=="number"?l(this,Ke).get(t):t;if(a){if(s&&w(this,zi,gm).call(this,a,s),i&&w(h=Ie,Xd,r_).call(h,a,i),n){const{classList:c}=a;for(const[u,d]of Object.entries(n))c.toggle(u,d)}if(r){const u=a.firstChild.firstChild;w(this,zi,gm).call(this,u,r)}}}updateParent(t,e){if(e===this)return;const s=l(this,Ke).get(t);s&&(l(e,bi).append(s),l(this,Ke).delete(t),l(e,Ke).set(t,s))}remove(t){l(this,to).delete(t),l(this,bi)!==null&&(l(this,Ke).get(t).remove(),l(this,Ke).delete(t))}destroy(){m(this,bi,null);for(const t of l(this,Ke).values())t.remove();l(this,Ke).clear(),l(this,to).clear()}};bi=new WeakMap,Wc=new WeakMap,Ke=new WeakMap,to=new WeakMap,Xd=new WeakSet,r_=function(t,[e,s,i,n]){const{style:r}=t;r.top=`${100*s}%`,r.left=`${100*e}%`,r.width=`${100*i}%`,r.height=`${100*n}%`},zi=new WeakSet,fm=function(){const t=Ie._svgFactory.create(1,1,!0);return l(this,bi).append(t),t.setAttribute("aria-hidden",!0),t},a_=function(t,e){const s=Ie._svgFactory.createElement("clipPath");t.append(s);const i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=Ie._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i},gm=function(t,e){for(const[s,i]of Object.entries(e))i===null?t.removeAttribute(s):t.setAttribute(s,i)},y(Ie,Xd);let lp=Ie;globalThis.pdfjsTestingUtils={HighlightOutliner:sp},Z.AbortException,Z.AnnotationEditorLayer,Z.AnnotationEditorParamsType,Z.AnnotationEditorType,Z.AnnotationEditorUIManager,Z.AnnotationLayer,Z.AnnotationMode,Z.ColorPicker,Z.DOMSVGFactory,Z.DrawLayer,Z.FeatureTest;var IC=Z.GlobalWorkerOptions;Z.ImageKind,Z.InvalidPDFException,Z.MissingPDFException,Z.OPS,Z.OutputScale,Z.PDFDataRangeTransport,Z.PDFDateString,Z.PDFWorker,Z.PasswordResponses,Z.PermissionFlag,Z.PixelsPerInch,Z.RenderingCancelledException,Z.TextLayer,Z.TouchManager,Z.UnexpectedResponseException,Z.Util,Z.VerbosityLevel,Z.XfaLayer,Z.build,Z.createValidAbsoluteUrl,Z.fetchData;var jC=Z.getDocument;Z.getFilenameFromUrl,Z.getPdfFilenameFromUrl,Z.getXfaPageViewport,Z.isDataScheme,Z.isPdfFile,Z.noContextMenu,Z.normalizeUnicode,Z.setLayerDimensions,Z.shadow,Z.stopEvent,Z.version;const NC={"pdfjs-dist":"4.10.38"};function BC(o){return new Promise((t,e)=>{const s=new FileReader;s.addEventListener("load",()=>t(s.result)),s.addEventListener("error",e),s.readAsDataURL(o)})}const HC=NC["pdfjs-dist"].replace("^","");IC.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${HC}/pdf.worker.min.mjs`;async function GC(o){const t="data:application/pdf;base64,",e=await BC(o);if(typeof e=="string")return window.atob(e.slice(t.length))}function VC(o,t){return jC({data:o,password:t}).promise}const WC="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2040%2040'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3ccircle%20cx='20'%20cy='20'%20r='10.75'%20stroke='currentColor'%20stroke-width='2.5'/%3e%3cpath%20d='M16%2024L23.7782%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3cpath%20d='M24%2024L16.2218%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3c/svg%3e";function zC(o){return new URL(Object.assign({"../assets/close.svg":WC})[`../assets/${o}`],typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Mt&&Mt.tagName.toUpperCase()==="SCRIPT"&&Mt.src||new URL("pdf-canvas.umd.js",document.baseURI).href).href}function XC(o){return new Promise((t,e)=>{const s=window.URL.createObjectURL(o),i=new Image;i.src=s,i.addEventListener("load",async()=>{window.URL.revokeObjectURL(s),t(await UC(i))}),i.addEventListener("error",n=>{window.URL.revokeObjectURL(s),e(n)})})}function UC(o){return new Promise(t=>{const e=document.createElement("canvas"),s=e.getContext("2d"),{naturalWidth:i,naturalHeight:n}=o;e.width=i,e.height=n,s==null||s.drawImage(o,0,0,i,n),t(e.toDataURL("image/jpeg",.8))})}let pb=null;function YC(){const o=document.createElement("div");o.style.width="1in",document.body.append(o);const t=o.offsetWidth;return o.remove(),t}function $C(){const o=pb??YC();return pb=o,o/72}function qC(o,t=500){if(typeof o!="function")throw new TypeError("The first argument is not a function.");let e=null;return function(...s){e&&clearTimeout(e),e=setTimeout(()=>{e=null,o.apply(this,s)},t)}}const Ls=new Map;function KC(o){const t=new fg(o);return Ls.set(o,t),t}function JC(o,t){const e=Date.now();return{PDFId:`${o.name}-${e}`,name:o.name.replace(/.pdf/,""),updateDate:e,PDFBase64:t}}function QC(o,t){const e=o.getViewport({scale:t}),s=document.createElement("canvas"),i=s.getContext("2d"),n=$C()/window.devicePixelRatio;s.width=Math.floor(e.width*n),s.height=Math.floor(e.height*n);const r={canvasContext:i,viewport:e,transform:[n,0,0,n,0,0]},a=o.render(r);return{canvas:s,renderTask:a}}async function ZC(o,t,e){const s=o||zC("close.svg"),{objects:i,options:n}=await Tx(s),r=i.filter(h=>h!==null),a=Hw.groupSVGElements(r,n);return r.forEach(h=>{h.stroke=t}),a.hoverCursor="pointer",a.stroke=`${t}-${e}`,a}function tA(o,t){if(!Ls.get(o))return;const s=1/3,i=aA(t,s);vb(o,i,s)}async function eA(o,t){const e=await XC(t),s=Date.now(),n={PDFId:`${t.name}${s}`,name:t.name.replace(/.png|.jpg|.jpeg/,""),updateDate:s,PDFBase64:e};return mb(o,{url:e}),{...n,pages:1}}async function mb(o,{url:t,scale:e=.5}){if(!Ls.get(o))return;const i=await ke.fromURL(t);i.scale(e),vb(o,i,e)}function vb(o,t,e){const s=Ls.get(o);s&&(s.setWidth(t.width*e),s.setHeight(t.height*e),s.backgroundImage=t,s.renderAll())}function vl(o,t){if(!t)return;const{oCoords:e}=o;if(!e)return;const{x:s,y:i}=e.tl.touchCorner.tl,{height:n,width:r,scaleY:a,scaleX:h}=t;t.top=i-n*a/2,t.left=s-r*h/2,t.setCoords()}function sA(o,t,e){!e||!o||(e.scale(1/t),vl(o,e))}function iA(o,t){if(!o)return;const e=o._cornerSize||8;o.borderScaleFactor=1/t,o.cornerSize=e*(1/t),o.touchCornerSize=e*4*(1/t),o.setCoords()}function nA(o){const t=Ls.get(o);t&&(t.discardActiveObject(),t.renderAll())}function rA(o){const t=Ls.get(o);t&&(t.clear(),Ls.delete(o))}function aA(o,t){return new ke(o,{scaleX:t,scaleY:t})}const oA={top:100,left:50,scaleX:.5,scaleY:.5,borderColor:"black",cornerStrokeColor:"black",cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},hA={top:100,left:50,fontFamily:"helvetica",borderColor:"black",cornerStrokeColor:"black",scaleX:.7,scaleY:.7,cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},lA={stroke:"#000",hoverStroke:"#B7EC5D",src:""};function bb(o=""){const t=Q.useRef(0),e=Q.useRef(null),s=Q.useRef(null),i=Q.useRef(1),n=Q.useRef({...lA});function r(){if(!o||Ls.has(o))return;const k=KC(o);return k.on("selection:cleared",()=>A(k)),k}function a(k,M){var I;const R=k.type,F={"application/pdf":h,"image/png":d,"image/jpeg":d};return((I=F[R])==null?void 0:I.call(F,k,M))??Promise.reject(new Error(`Unsupported ${R} file type.`))}async function h(k,M){const R=await GC(k);if(!R)return;const F=JC(k,R);try{return await c({page:1,PDFBase64:R,scale:.8,password:M}),{...F,pages:t.current}}catch(I){return Promise.reject(I)}}async function c({page:k,PDFBase64:M,scale:R,password:F}){try{const I=await VC(M,F),Y=await I.getPage(k),{renderTask:N,canvas:H}=QC(Y,R);return t.current=I.numPages,N.promise.then(()=>u(H))}catch(I){return Promise.reject(I)}}function u(k){tA(o,k)}async function d(k){return await eA(o,k)}async function f({url:k,scale:M=.5}){await mb(o,{url:k,scale:M})}async function g(k,M){const R=Ls.get(o);if(!R)return;const F=await ke.fromURL(k,{},{...oA,...M});R.add(F),v(R,F)}function p(k,M){const R=Ls.get(o);if(!R)return;const F=new Ee(k,{...hA,...M});R.add(F),v(R,F)}function v(k,M){M.on("selected",R=>_({canvas:k,target:R.target})),M.on("modified",R=>vl(R.target,e.current)),M.on("scaling",R=>vl(R.transform.target,e.current)),M.on("moving",R=>vl(R.transform.target,e.current)),M.on("rotating",R=>vl(R.transform.target,e.current))}async function _({canvas:k,target:M,stroke:R=n.current.stroke,uuid:F=Date.now()}){var Y;if(((Y=e.current)==null?void 0:Y.stroke)===`${R}-${F}`)return;const I=await ZC(n.current.src,R,F);A(k),e.current=I,s.current=M,b(k,M,F),x(i.current,!0),k.add(I)}function b(k,M,R){e.current&&(e.current.on("selected",()=>{k.remove(M),A(k)}),e.current.on("mouseover",()=>{_({canvas:k,target:M,stroke:n.current.hoverStroke,uuid:R})}),e.current.on("mouseout",()=>{_({canvas:k,target:M,stroke:n.current.stroke,uuid:R})}))}function x(k,M=!1){const R=Ls.get(o);i.current=k,R&&(iA(s.current,k),sA(s.current,k,e.current),!M&&R.renderAll())}function C(k){if(!k)return;n.current={...n.current,...k};const M=Ls.get(o);!e||!s.current||!M||_({target:s.current,canvas:M})}function A(k){e.current&&(k.remove(e.current),e.current=s.current=null)}function P(){nA(o)}function D(){rA(o)}return{createCanvas:r,loadFile:a,specifyPage:c,renderImage:f,addFabric:g,addTextFabric:p,clearActive:P,deleteCanvas:D,scaleFabric:x,setCloseSvgOptions:C}}function cA(o){let t=0;const e=qC(()=>{t!==window.innerWidth&&(t=window.innerWidth,o())});Q.useEffect(()=>(window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)),[])}const uA=Q.forwardRef(dA);function dA({file:o,page:t=1,canvasId:e="PDF-canvas",fileZoom:s=1,fileScale:i=1,canvasScale:n=1,canvasClass:r="",isDrop:a=!1,password:h,dropTextOptions:c,dropImageOptions:u,closeSvgOptions:d},f){const g=Q.useRef(null),p=`${e}-${t-1}`,v=Q.useMemo(()=>s*n,[s,n]),{createCanvas:_,specifyPage:b,addFabric:x,addTextFabric:C,renderImage:A,clearActive:P,deleteCanvas:D,scaleFabric:k,setCloseSvgOptions:M}=bb(p);cA(R);async function R(){window.requestAnimationFrame(async()=>{if(_(),o.PDFBase64.startsWith("data:image")||o.canvas){const{canvas:N}=o,H=N?7:3,at=N!=null&&N.length?N[t-1]:o.PDFBase64;A({url:at,scale:i/H});return}await b({page:t,PDFBase64:o.PDFBase64,scale:i,password:h})})}function F(N){if(N.preventDefault(),N.stopPropagation(),!a||!N.dataTransfer)return;const{dataTransfer:H,clientX:at,clientY:j}=N,W=H.getData("text/plain"),it=H.getData("text/uri-list"),kt={left:at-71,top:j-55};it?I(it,kt):W&&Y(W,kt)}function I(N,H){x(N,{...H,...u})}function Y(N,H){C(N,{...H,...c})}return Q.useImperativeHandle(f,()=>({addImage:I,addText:Y,clearActive:P,deleteCanvas:D,canvasRef:g})),Q.useEffect(()=>{R()},[i,t,o,h]),Q.useEffect(()=>{k(v)},[v]),Q.useEffect(()=>{M(d)},[d]),Q.useEffect(()=>()=>D(),[]),vm.jsx("div",{style:{transform:`scale(${v})`},onDragOver:N=>N.preventDefault(),onDragEnter:N=>N.preventDefault(),onDrop:F,children:vm.jsx("canvas",{id:p,ref:g,className:r})})}ut.default=uA,ut.useFabric=bb,Object.defineProperties(ut,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -2,8 +2,10 @@ import { Canvas } from 'fabric';
2
2
  import { ComponentOptionsMixin } from 'vue';
3
3
  import { ComponentProvideOptions } from 'vue';
4
4
  import { DefineComponent } from 'vue';
5
+ import { FabricImage } from 'fabric';
5
6
  import { FabricObject } from 'fabric';
6
7
  import { FabricObjectProps } from 'fabric';
8
+ import { FabricText } from 'fabric';
7
9
  import { ImageProps } from 'fabric';
8
10
  import { ObjectEvents } from 'fabric';
9
11
  import { Point } from 'fabric';
@@ -20,6 +22,16 @@ declare function addImage(src: string, options?: TOptions<ImageProps>, offset?:
20
22
 
21
23
  declare function addText(text: string, options?: TOptions<TextProps>, offset?: DropOffset): void;
22
24
 
25
+ export declare type CacheFabricImage = FabricImage & CacheProperties;
26
+
27
+ export declare type CacheFabricObject = FabricObject & CacheProperties;
28
+
29
+ export declare type CacheFabricText = FabricText & CacheProperties;
30
+
31
+ declare interface CacheProperties {
32
+ _cornerSize?: number;
33
+ }
34
+
23
35
  export declare interface CloseSvgOptions {
24
36
  stroke: string;
25
37
  hoverStroke: string;
@@ -38,6 +50,7 @@ export declare interface ComponentProps {
38
50
  password?: string;
39
51
  dropTextOptions?: TOptions<TextProps>;
40
52
  dropImageOptions?: TOptions<ImageProps>;
53
+ selectionOptions?: TOptions<FabricObjectProps>;
41
54
  closeSvgOptions?: CloseSvgOptions;
42
55
  manualReload?: boolean;
43
56
  onDestroy?: (callback: () => void) => void;
@@ -71,6 +84,7 @@ onLoaded?: (() => any) | undefined;
71
84
  onReload?: (() => any) | undefined;
72
85
  }>, {
73
86
  page: number;
87
+ selectionOptions: TOptions<FabricObjectProps>;
74
88
  canvasId: string;
75
89
  fileZoom: number;
76
90
  fileScale: number;
@@ -140,7 +154,9 @@ export declare interface TCornerPoint {
140
154
  br: Point;
141
155
  }
142
156
 
143
- export declare function useFabric(params?: FabricHookParams): {
157
+ export declare function useFabric(params?: FabricHookParams & {
158
+ selectionOptions: Ref<TOptions<FabricObjectProps>>;
159
+ }): {
144
160
  createCanvas: () => Canvas | undefined;
145
161
  loadFile: (file: File, password?: string) => Promise<{
146
162
  pages: number;