@mlightcad/cad-simple-viewer-cli 1.7.2 → 1.7.3

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,4 +1,4 @@
1
- import{ad as I6,ae as O6,af as jF,ag as zF,h as UF,ah as D6,ai as VF,aj as GF,ak as Db,al as qF,a7 as i5,am as s2,an as pa,ao as HF,a as XF,d as CA,ap as Xg,aq as KF,ar as _F,as as YF,at as So,au as ZF,av as Ks,aw as JF,ax as sf,j as QF,$ as R6,_ as Rb,u as yn,x as xy,b as Pi,ay as $F,k as tE,az as Bb,a2 as eE,z as nE,aA as Nb,aB as s5}from"./index-QZJdatvK.js";import{aC as Q_,aD as $_}from"./index-QZJdatvK.js";/*! *****************************************************************************
1
+ import{ad as I6,ae as O6,af as jF,ag as zF,f as UF,ah as D6,ai as VF,aj as GF,ak as Db,al as qF,a7 as i5,am as s2,an as pa,ao as HF,a as XF,d as CA,ap as Xg,aq as KF,ar as _F,as as YF,at as So,au as ZF,av as Ks,aw as JF,ax as sf,j as QF,$ as R6,_ as Rb,u as yn,v as xy,b as Pi,ay as $F,C as tE,az as Bb,a2 as eE,x as nE,aA as Nb,aB as s5}from"./index-B3SgHAxA.js";import{aC as Q_,aD as $_}from"./index-B3SgHAxA.js";/*! *****************************************************************************
2
2
  Copyright (c) Microsoft Corporation.
3
3
 
4
4
  Permission to use, copy, modify, and/or distribute this software for any
@@ -209,4 +209,4 @@ fn fs_main(in : VertexOutput) -> @location(0) vec4<f32> {
209
209
  `),position:S,pageIndex:k-1,rect:c.slice(0),rotation:h,annotationElementId:d,id:d,deleted:!1,popupRef:p,comment:(m==null?void 0:m.str)||null,richText:g,creationDate:y,modificationDate:v}}const a=await super.deserialize(t,e,r);return w(a,_i,t.fontSize),a.color=ft.makeHexColor(...t.color),w(a,Ki,F(i=Cr,ph,$x).call(i,t.value)),a._initialData=s,t.comment&&a.setCommentData(t),a}serialize(t=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const e=on._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:this.color),r=Object.assign(super.serialize(t),{color:e,fontSize:u(this,_i),value:F(this,hi,JP).call(this)});return this.addComment(r),t?(r.isCopy=!0,r):this.annotationElementId&&!F(this,hi,QP).call(this,r)?null:(r.id=this.annotationElementId,r)}renderAnnotationElement(t){const e=super.renderAnnotationElement(t);if(!e)return null;const{style:r}=e;r.fontSize=`calc(${u(this,_i)}px * var(--total-scale-factor))`,r.color=this.color,e.replaceChildren();for(const i of u(this,Ki).split(`
210
210
  `)){const s=document.createElement("div");s.append(i?document.createTextNode(i):document.createElement("br")),e.append(s)}return t.updateEdited({rect:this.getPDFRect(),popup:this._uiManager.hasCommentManager()||this.hasEditedComment?this.comment:{text:u(this,Ki)}}),e}resetAnnotationElement(t){super.resetAnnotationElement(t),t.resetEdited()}};Ki=new WeakMap,z1=new WeakMap,ju=new WeakMap,_i=new WeakMap,hi=new WeakSet,_P=function(n){const t=r=>{this.editorDiv.style.fontSize=`calc(${r}px * var(--total-scale-factor))`,this.translate(0,-(r-u(this,_i))*this.parentScale),w(this,_i,r),F(this,hi,pv).call(this)},e=u(this,_i);this.addCommands({cmd:t.bind(this,n),undo:t.bind(this,e),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:ce.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})},YP=function(n){const t=r=>{this.color=r,this.onUpdatedColor()},e=this.color;this.addCommands({cmd:t.bind(this,n),undo:t.bind(this,e),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:ce.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})},ZP=function(){var n;const t=[];this.editorDiv.normalize();let e=null;for(const r of this.editorDiv.childNodes)(e==null?void 0:e.nodeType)===Node.TEXT_NODE&&r.nodeName==="BR"||(t.push(F(n=La,ph,gv).call(n,r)),e=r);return t.join(`
211
211
  `)},pv=function(){const[n,t]=this.parentDimensions;let e;if(this.isAttachedToDOM)e=this.div.getBoundingClientRect();else{const{currentLayer:r,div:i}=this,s=i.style.display,a=i.classList.contains("hidden");i.classList.remove("hidden"),i.style.display="hidden",r.div.append(this.div),e=i.getBoundingClientRect(),i.remove(),i.style.display=s,i.classList.toggle("hidden",a)}this.rotation%180===this.parentRotation%180?(this.width=e.width/n,this.height=e.height/t):(this.width=e.height/n,this.height=e.width/t),this.fixAndSetPosition()},ph=new WeakSet,gv=function(n){return(n.nodeType===Node.TEXT_NODE?n.nodeValue:n.innerText).replaceAll(j1,"")},U1=function(){if(this.editorDiv.replaceChildren(),!!u(this,Ki))for(const n of u(this,Ki).split(`
212
- `)){const t=document.createElement("div");t.append(n?document.createTextNode(n):document.createElement("br")),this.editorDiv.append(t)}},JP=function(){return u(this,Ki).replaceAll(" "," ")},$x=function(n){return n.replaceAll(" "," ")},QP=function(n){const{value:t,fontSize:e,color:r,pageIndex:i}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||n.value!==t||n.fontSize!==e||n.color.some((s,a)=>s!==r[a])||n.pageIndex!==i},C(La,ph),J(La,"_freeTextDefaultContent",""),J(La,"_internalPadding",0),J(La,"_defaultColor",null),J(La,"_defaultFontSize",10),J(La,"_type","freetext"),J(La,"_editorType",te.FREETEXT);let P_=La;class Ft{toSVGPath(){Ne("Abstract method `toSVGPath` must be implemented.")}get box(){Ne("Abstract getter `box` must be implemented.")}serialize(t,e){Ne("Abstract method `serialize` must be implemented.")}static _rescale(t,e,r,i,s,a){a||(a=new Float32Array(t.length));for(let o=0,l=t.length;o<l;o+=2)a[o]=e+t[o]*i,a[o+1]=r+t[o+1]*s;return a}static _rescaleAndSwap(t,e,r,i,s,a){a||(a=new Float32Array(t.length));for(let o=0,l=t.length;o<l;o+=2)a[o]=e+t[o+1]*i,a[o+1]=r+t[o]*s;return a}static _translate(t,e,r,i){i||(i=new Float32Array(t.length));for(let s=0,a=t.length;s<a;s+=2)i[s]=e+t[s],i[s+1]=r+t[s+1];return i}static svgRound(t){return Math.round(t*1e4)}static _normalizePoint(t,e,r,i,s){switch(s){case 90:return[1-e/r,t/i];case 180:return[1-t/r,1-e/i];case 270:return[e/r,1-t/i];default:return[t/r,e/i]}}static _normalizePagePoint(t,e,r){switch(r){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,r,i,s,a){return[(t+5*r)/6,(e+5*i)/6,(5*r+s)/6,(5*i+a)/6,(r+s)/2,(i+a)/2]}}J(Ft,"PRECISION",1e-4);var Zi,ia,Bg,Ng,Wa,me,Bd,Nd,V1,G1,Lg,Up,Rc,q1,t2,tA,Ji,Tf,$P,tF,eF,nF,rF,iF;const zu=class eA{constructor({x:t,y:e},r,i,s,a,o=0){C(this,Ji),C(this,Zi),C(this,ia,[]),C(this,Bg),C(this,Ng),C(this,Wa,[]),C(this,me,new Float32Array(18)),C(this,Bd),C(this,Nd),C(this,V1),C(this,G1),C(this,Lg),C(this,Up),C(this,Rc,[]),w(this,Zi,r),w(this,Up,s*i),w(this,Ng,a),u(this,me).set([NaN,NaN,NaN,NaN,t,e],6),w(this,Bg,o),w(this,G1,u(eA,q1)*i),w(this,V1,u(eA,tA)*i),w(this,Lg,i),u(this,Rc).push(t,e)}isEmpty(){return isNaN(u(this,me)[8])}add({x:t,y:e}){var r;w(this,Bd,t),w(this,Nd,e);const[i,s,a,o]=u(this,Zi);let[l,c,h,d]=u(this,me).subarray(8,12);const p=t-h,g=e-d,m=Math.hypot(p,g);if(m<u(this,V1))return!1;const y=m-u(this,G1),v=y/m,b=v*p,S=v*g;let k=l,P=c;l=h,c=d,h+=b,d+=S,(r=u(this,Rc))==null||r.push(t,e);const T=-S/y,M=b/y,D=T*u(this,Up),L=M*u(this,Up);return u(this,me).set(u(this,me).subarray(2,8),0),u(this,me).set([h+D,d+L],4),u(this,me).set(u(this,me).subarray(14,18),12),u(this,me).set([h-D,d-L],16),isNaN(u(this,me)[6])?(u(this,Wa).length===0&&(u(this,me).set([l+D,c+L],2),u(this,Wa).push(NaN,NaN,NaN,NaN,(l+D-i)/a,(c+L-s)/o),u(this,me).set([l-D,c-L],14),u(this,ia).push(NaN,NaN,NaN,NaN,(l-D-i)/a,(c-L-s)/o)),u(this,me).set([k,P,l,c,h,d],6),!this.isEmpty()):(u(this,me).set([k,P,l,c,h,d],6),Math.abs(Math.atan2(P-c,k-l)-Math.atan2(S,b))<Math.PI/2?([l,c,h,d]=u(this,me).subarray(2,6),u(this,Wa).push(NaN,NaN,NaN,NaN,((l+h)/2-i)/a,((c+d)/2-s)/o),[l,c,k,P]=u(this,me).subarray(14,18),u(this,ia).push(NaN,NaN,NaN,NaN,((k+l)/2-i)/a,((P+c)/2-s)/o),!0):([k,P,l,c,h,d]=u(this,me).subarray(0,6),u(this,Wa).push(((k+5*l)/6-i)/a,((P+5*c)/6-s)/o,((5*l+h)/6-i)/a,((5*c+d)/6-s)/o,((l+h)/2-i)/a,((c+d)/2-s)/o),[h,d,l,c,k,P]=u(this,me).subarray(12,18),u(this,ia).push(((k+5*l)/6-i)/a,((P+5*c)/6-s)/o,((5*l+h)/6-i)/a,((5*c+d)/6-s)/o,((l+h)/2-i)/a,((c+d)/2-s)/o),!0))}toSVGPath(){if(this.isEmpty())return"";const t=u(this,Wa),e=u(this,ia);if(isNaN(u(this,me)[6])&&!this.isEmpty())return F(this,Ji,$P).call(this);const r=[];r.push(`M${t[4]} ${t[5]}`);for(let i=6;i<t.length;i+=6)isNaN(t[i])?r.push(`L${t[i+4]} ${t[i+5]}`):r.push(`C${t[i]} ${t[i+1]} ${t[i+2]} ${t[i+3]} ${t[i+4]} ${t[i+5]}`);F(this,Ji,eF).call(this,r);for(let i=e.length-6;i>=6;i-=6)isNaN(e[i])?r.push(`L${e[i+4]} ${e[i+5]}`):r.push(`C${e[i]} ${e[i+1]} ${e[i+2]} ${e[i+3]} ${e[i+4]} ${e[i+5]}`);return F(this,Ji,tF).call(this,r),r.join(" ")}newFreeDrawOutline(t,e,r,i,s,a){return new oF(t,e,r,i,s,a)}getOutlines(){var t;const e=u(this,Wa),r=u(this,ia),i=u(this,me),[s,a,o,l]=u(this,Zi),c=new Float32Array((((t=u(this,Rc))==null?void 0:t.length)??0)+2);for(let p=0,g=c.length-2;p<g;p+=2)c[p]=(u(this,Rc)[p]-s)/o,c[p+1]=(u(this,Rc)[p+1]-a)/l;if(c[c.length-2]=(u(this,Bd)-s)/o,c[c.length-1]=(u(this,Nd)-a)/l,isNaN(i[6])&&!this.isEmpty())return F(this,Ji,nF).call(this,c);const h=new Float32Array(u(this,Wa).length+24+u(this,ia).length);let d=e.length;for(let p=0;p<d;p+=2){if(isNaN(e[p])){h[p]=h[p+1]=NaN;continue}h[p]=e[p],h[p+1]=e[p+1]}d=F(this,Ji,iF).call(this,h,d);for(let p=r.length-6;p>=6;p-=6)for(let g=0;g<6;g+=2){if(isNaN(r[p+g])){h[d]=h[d+1]=NaN,d+=2;continue}h[d]=r[p+g],h[d+1]=r[p+g+1],d+=2}return F(this,Ji,rF).call(this,h,d),this.newFreeDrawOutline(h,c,u(this,Zi),u(this,Lg),u(this,Bg),u(this,Ng))}};Zi=new WeakMap,ia=new WeakMap,Bg=new WeakMap,Ng=new WeakMap,Wa=new WeakMap,me=new WeakMap,Bd=new WeakMap,Nd=new WeakMap,V1=new WeakMap,G1=new WeakMap,Lg=new WeakMap,Up=new WeakMap,Rc=new WeakMap,q1=new WeakMap,t2=new WeakMap,tA=new WeakMap,Ji=new WeakSet,Tf=function(){const n=u(this,me).subarray(4,6),t=u(this,me).subarray(16,18),[e,r,i,s]=u(this,Zi);return[(u(this,Bd)+(n[0]-t[0])/2-e)/i,(u(this,Nd)+(n[1]-t[1])/2-r)/s,(u(this,Bd)+(t[0]-n[0])/2-e)/i,(u(this,Nd)+(t[1]-n[1])/2-r)/s]},$P=function(){const[n,t,e,r]=u(this,Zi),[i,s,a,o]=F(this,Ji,Tf).call(this);return`M${(u(this,me)[2]-n)/e} ${(u(this,me)[3]-t)/r} L${(u(this,me)[4]-n)/e} ${(u(this,me)[5]-t)/r} L${i} ${s} L${a} ${o} L${(u(this,me)[16]-n)/e} ${(u(this,me)[17]-t)/r} L${(u(this,me)[14]-n)/e} ${(u(this,me)[15]-t)/r} Z`},tF=function(n){const t=u(this,ia);n.push(`L${t[4]} ${t[5]} Z`)},eF=function(n){const[t,e,r,i]=u(this,Zi),s=u(this,me).subarray(4,6),a=u(this,me).subarray(16,18),[o,l,c,h]=F(this,Ji,Tf).call(this);n.push(`L${(s[0]-t)/r} ${(s[1]-e)/i} L${o} ${l} L${c} ${h} L${(a[0]-t)/r} ${(a[1]-e)/i}`)},nF=function(n){const t=u(this,me),[e,r,i,s]=u(this,Zi),[a,o,l,c]=F(this,Ji,Tf).call(this),h=new Float32Array(36);return h.set([NaN,NaN,NaN,NaN,(t[2]-e)/i,(t[3]-r)/s,NaN,NaN,NaN,NaN,(t[4]-e)/i,(t[5]-r)/s,NaN,NaN,NaN,NaN,a,o,NaN,NaN,NaN,NaN,l,c,NaN,NaN,NaN,NaN,(t[16]-e)/i,(t[17]-r)/s,NaN,NaN,NaN,NaN,(t[14]-e)/i,(t[15]-r)/s],0),this.newFreeDrawOutline(h,n,u(this,Zi),u(this,Lg),u(this,Bg),u(this,Ng))},rF=function(n,t){const e=u(this,ia);return n.set([NaN,NaN,NaN,NaN,e[4],e[5]],t),t+=6},iF=function(n,t){const e=u(this,me).subarray(4,6),r=u(this,me).subarray(16,18),[i,s,a,o]=u(this,Zi),[l,c,h,d]=F(this,Ji,Tf).call(this);return n.set([NaN,NaN,NaN,NaN,(e[0]-i)/a,(e[1]-s)/o,NaN,NaN,NaN,NaN,l,c,NaN,NaN,NaN,NaN,h,d,NaN,NaN,NaN,NaN,(r[0]-i)/a,(r[1]-s)/o],t),t+=24},C(zu,q1,8),C(zu,t2,2),C(zu,tA,u(zu,q1)+u(zu,t2));let sF=zu;var Vp,dd,pl,H1,Wi,X1,zn,nA,aF;class oF extends Ft{constructor(t,e,r,i,s,a){super(),C(this,nA),C(this,Vp),C(this,dd,new Float32Array(4)),C(this,pl),C(this,H1),C(this,Wi),C(this,X1),C(this,zn),w(this,zn,t),w(this,Wi,e),w(this,Vp,r),w(this,X1,i),w(this,pl,s),w(this,H1,a),this.firstPoint=[NaN,NaN],this.lastPoint=[NaN,NaN],F(this,nA,aF).call(this,a);const[o,l,c,h]=u(this,dd);for(let d=0,p=t.length;d<p;d+=2)t[d]=(t[d]-o)/c,t[d+1]=(t[d+1]-l)/h;for(let d=0,p=e.length;d<p;d+=2)e[d]=(e[d]-o)/c,e[d+1]=(e[d+1]-l)/h}toSVGPath(){const t=[`M${u(this,zn)[4]} ${u(this,zn)[5]}`];for(let e=6,r=u(this,zn).length;e<r;e+=6){if(isNaN(u(this,zn)[e])){t.push(`L${u(this,zn)[e+4]} ${u(this,zn)[e+5]}`);continue}t.push(`C${u(this,zn)[e]} ${u(this,zn)[e+1]} ${u(this,zn)[e+2]} ${u(this,zn)[e+3]} ${u(this,zn)[e+4]} ${u(this,zn)[e+5]}`)}return t.push("Z"),t.join(" ")}serialize([t,e,r,i],s){const a=r-t,o=i-e;let l,c;switch(s){case 0:l=Ft._rescale(u(this,zn),t,i,a,-o),c=Ft._rescale(u(this,Wi),t,i,a,-o);break;case 90:l=Ft._rescaleAndSwap(u(this,zn),t,e,a,o),c=Ft._rescaleAndSwap(u(this,Wi),t,e,a,o);break;case 180:l=Ft._rescale(u(this,zn),r,e,-a,o),c=Ft._rescale(u(this,Wi),r,e,-a,o);break;case 270:l=Ft._rescaleAndSwap(u(this,zn),r,i,-a,-o),c=Ft._rescaleAndSwap(u(this,Wi),r,i,-a,-o);break}return{outline:Array.from(l),points:[Array.from(c)]}}get box(){return u(this,dd)}newOutliner(t,e,r,i,s,a=0){return new sF(t,e,r,i,s,a)}getNewOutline(t,e){const[r,i,s,a]=u(this,dd),[o,l,c,h]=u(this,Vp),d=s*c,p=a*h,g=r*c+o,m=i*h+l,y=this.newOutliner({x:u(this,Wi)[0]*d+g,y:u(this,Wi)[1]*p+m},u(this,Vp),u(this,X1),t,u(this,H1),e??u(this,pl));for(let v=2;v<u(this,Wi).length;v+=2)y.add({x:u(this,Wi)[v]*d+g,y:u(this,Wi)[v+1]*p+m});return y.getOutlines()}}Vp=new WeakMap,dd=new WeakMap,pl=new WeakMap,H1=new WeakMap,Wi=new WeakMap,X1=new WeakMap,zn=new WeakMap,nA=new WeakSet,aF=function(n){const t=u(this,zn);let e=t[4],r=t[5];const i=[e,r,e,r];let s=e,a=r,o=e,l=r;const c=n?Math.max:Math.min,h=new Float32Array(4);for(let p=6,g=t.length;p<g;p+=6){const m=t[p+4],y=t[p+5];isNaN(t[p])?(ft.pointBoundingBox(m,y,i),a>y?(s=m,a=y):a===y&&(s=c(s,m)),l<y?(o=m,l=y):l===y&&(o=c(o,m))):(h.set(co,0),ft.bezierBoundingBox(e,r,...t.slice(p,p+6),h),ft.rectBoundingBox(...h,i),a>h[1]?(s=h[0],a=h[1]):a===h[1]&&(s=c(s,h[0])),l<h[3]?(o=h[2],l=h[3]):l===h[3]&&(o=c(o,h[2]))),e=m,r=y}const d=u(this,dd);d[0]=i[0]-u(this,pl),d[1]=i[1]-u(this,pl),d[2]=i[2]-i[0]+2*u(this,pl),d[3]=i[3]-i[1]+2*u(this,pl),this.firstPoint=[s,a],this.lastPoint=[o,l]};var mv,yv,vv,Bc,Hs,ca,lF,yy,cF,hF,rA;class iA{constructor(t,e=0,r=0,i=!0){C(this,ca),C(this,mv),C(this,yv),C(this,vv),C(this,Bc,[]),C(this,Hs,[]);const s=co.slice(),a=10**-4;for(const{x:y,y:v,width:b,height:S}of t){const k=Math.floor((y-e)/a)*a,P=Math.ceil((y+b+e)/a)*a,T=Math.floor((v-e)/a)*a,M=Math.ceil((v+S+e)/a)*a,D=[k,T,M,!0],L=[P,T,M,!1];u(this,Bc).push(D,L),ft.rectBoundingBox(k,T,P,M,s)}const o=s[2]-s[0]+2*r,l=s[3]-s[1]+2*r,c=s[0]-r,h=s[1]-r;let d=i?-1/0:1/0,p=1/0;const g=u(this,Bc).at(i?-1:-2),m=[g[0],g[2]];for(const y of u(this,Bc)){const[v,b,S,k]=y;!k&&i?b<p?(p=b,d=v):b===p&&(d=Math.max(d,v)):k&&!i&&(b<p?(p=b,d=v):b===p&&(d=Math.min(d,v))),y[0]=(v-c)/o,y[1]=(b-h)/l,y[2]=(S-h)/l}w(this,mv,new Float32Array([c,h,o,l])),w(this,yv,[d,p]),w(this,vv,m)}getOutlines(){u(this,Bc).sort((e,r)=>e[0]-r[0]||e[1]-r[1]||e[2]-r[2]);const t=[];for(const e of u(this,Bc))e[3]?(t.push(...F(this,ca,rA).call(this,e)),F(this,ca,cF).call(this,e)):(F(this,ca,hF).call(this,e),t.push(...F(this,ca,rA).call(this,e)));return F(this,ca,lF).call(this,t)}}mv=new WeakMap,yv=new WeakMap,vv=new WeakMap,Bc=new WeakMap,Hs=new WeakMap,ca=new WeakSet,lF=function(n){const t=[],e=new Set;for(const s of n){const[a,o,l]=s;t.push([a,o,s],[a,l,s])}t.sort((s,a)=>s[1]-a[1]||s[0]-a[0]);for(let s=0,a=t.length;s<a;s+=2){const o=t[s][2],l=t[s+1][2];o.push(l),l.push(o),e.add(o),e.add(l)}const r=[];let i;for(;e.size>0;){const s=e.values().next().value;let[a,o,l,c,h]=s;e.delete(s);let d=a,p=o;for(i=[a,l],r.push(i);;){let g;if(e.has(c))g=c;else if(e.has(h))g=h;else break;e.delete(g),[a,o,l,c,h]=g,d!==a&&(i.push(d,p,a,p===o?o:l),d=a),p=p===o?l:o}i.push(d,p)}return new F_(r,u(this,mv),u(this,yv),u(this,vv))},yy=function(n){const t=u(this,Hs);let e=0,r=t.length-1;for(;e<=r;){const i=e+r>>1,s=t[i][0];if(s===n)return i;s<n?e=i+1:r=i-1}return r+1},cF=function([,n,t]){const e=F(this,ca,yy).call(this,n);u(this,Hs).splice(e,0,[n,t])},hF=function([,n,t]){const e=F(this,ca,yy).call(this,n);for(let r=e;r<u(this,Hs).length;r++){const[i,s]=u(this,Hs)[r];if(i!==n)break;if(i===n&&s===t){u(this,Hs).splice(r,1);return}}for(let r=e-1;r>=0;r--){const[i,s]=u(this,Hs)[r];if(i!==n)break;if(i===n&&s===t){u(this,Hs).splice(r,1);return}}},rA=function(n){const[t,e,r]=n,i=[[t,e,r]],s=F(this,ca,yy).call(this,r);for(let a=0;a<s;a++){const[o,l]=u(this,Hs)[a];for(let c=0,h=i.length;c<h;c++){const[,d,p]=i[c];if(!(l<=d||p<=o)){if(d>=o){if(p>l)i[c][1]=l;else{if(h===1)return[];i.splice(c,1),c--,h--}continue}i[c][2]=o,p>l&&i.push([t,l,p])}}}return i};var K1,Gp;class F_ extends Ft{constructor(t,e,r,i){super(),C(this,K1),C(this,Gp),w(this,Gp,t),w(this,K1,e),this.firstPoint=r,this.lastPoint=i}toSVGPath(){const t=[];for(const e of u(this,Gp)){let[r,i]=e;t.push(`M${r} ${i}`);for(let s=2;s<e.length;s+=2){const a=e[s],o=e[s+1];a===r?(t.push(`V${o}`),i=o):o===i&&(t.push(`H${a}`),r=a)}t.push("Z")}return t.join(" ")}serialize([t,e,r,i],s){const a=[],o=r-t,l=i-e;for(const c of u(this,Gp)){const h=new Array(c.length);for(let d=0;d<c.length;d+=2)h[d]=t+c[d]*o,h[d+1]=i-c[d+1]*l;a.push(h)}return a}get box(){return u(this,K1)}get classNamesForOutlining(){return["highlightOutline"]}}K1=new WeakMap,Gp=new WeakMap;class sA extends sF{newFreeDrawOutline(t,e,r,i,s,a){return new E_(t,e,r,i,s,a)}}class E_ extends oF{newOutliner(t,e,r,i,s,a=0){return new sA(t,e,r,i,s,a)}}var Wg,bv,Al,fd,_1,ui,wv,xv,Ld,zi,Yi,Er,jg,zg,jr,qp,Fs,Y1,Ue,aA,Av,uF,dF,C6,oA,Nc,ao,Wd,fF,Z1,Sv,pF,gF,mF,yF,vF;const Yr=class Tr extends on{constructor(t){super({...t,name:"highlightEditor"}),C(this,Ue),C(this,Wg,null),C(this,bv,0),C(this,Al),C(this,fd,null),C(this,_1,null),C(this,ui,null),C(this,wv,null),C(this,xv,0),C(this,Ld,null),C(this,zi,null),C(this,Yi,null),C(this,Er,!1),C(this,jg,null),C(this,zg,null),C(this,jr,null),C(this,qp,""),C(this,Fs),C(this,Y1,""),this.color=t.color||Tr._defaultColor,w(this,Fs,t.thickness||Tr._defaultThickness),this.opacity=t.opacity||Tr._defaultOpacity,w(this,Al,t.boxes||null),w(this,Y1,t.methodOfCreation||""),w(this,qp,t.text||""),this._isDraggable=!1,this.defaultL10nId="pdfjs-editor-highlight-editor",t.highlightId>-1?(w(this,Er,!0),F(this,Ue,Av).call(this,t),F(this,Ue,Nc).call(this)):u(this,Al)&&(w(this,Wg,t.anchorNode),w(this,bv,t.anchorOffset),w(this,wv,t.focusNode),w(this,xv,t.focusOffset),F(this,Ue,aA).call(this),F(this,Ue,Nc).call(this),this.rotate(this.rotation)),this.annotationElementId||this._uiManager.a11yAlert("pdfjs-editor-highlight-added-alert")}static get _keyboardManager(){const t=Tr.prototype;return se(this,"_keyboardManager",new Pm([[["ArrowLeft","mac+ArrowLeft"],t._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],t._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],t._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],t._moveCaret,{args:[3]}]]))}get telemetryInitialData(){return{action:"added",type:u(this,Er)?"free_highlight":"highlight",color:this._uiManager.getNonHCMColorName(this.color),thickness:u(this,Fs),methodOfCreation:u(this,Y1)}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.getNonHCMColorName(this.color)}}static computeTelemetryFinalData(t){return{numberOfColors:t.get("color").size}}static initialize(t,e){var r;on.initialize(t,e),Tr._defaultColor||(Tr._defaultColor=((r=e.highlightColors)==null?void 0:r.values().next().value)||"#fff066")}static updateDefaultParams(t,e){switch(t){case ce.HIGHLIGHT_COLOR:Tr._defaultColor=e;break;case ce.HIGHLIGHT_THICKNESS:Tr._defaultThickness=e;break}}translateInPage(t,e){}get toolbarPosition(){return u(this,zg)}get commentButtonPosition(){return u(this,jg)}updateParams(t,e){switch(t){case ce.HIGHLIGHT_COLOR:F(this,Ue,uF).call(this,e);break;case ce.HIGHLIGHT_THICKNESS:F(this,Ue,dF).call(this,e);break}}static get defaultPropertiesToUpdate(){return[[ce.HIGHLIGHT_COLOR,Tr._defaultColor],[ce.HIGHLIGHT_THICKNESS,Tr._defaultThickness]]}get propertiesToUpdate(){return[[ce.HIGHLIGHT_COLOR,this.color||Tr._defaultColor],[ce.HIGHLIGHT_THICKNESS,u(this,Fs)||Tr._defaultThickness],[ce.HIGHLIGHT_FREE,u(this,Er)]]}onUpdatedColor(){var t,e;(t=this.parent)==null||t.drawLayer.updateProperties(u(this,Yi),{root:{fill:this.color,"fill-opacity":this.opacity}}),(e=u(this,_1))==null||e.updateColor(this.color),super.onUpdatedColor()}get toolbarButtons(){return this._uiManager.highlightColors?[["colorPicker",w(this,_1,new QS({editor:this}))]]:super.toolbarButtons}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(F(this,Ue,Sv).call(this))}getBaseTranslation(){return[0,0]}getRect(t,e){return super.getRect(t,e,F(this,Ue,Sv).call(this))}onceAdded(t){this.annotationElementId||this.parent.addUndoableEditor(this),t&&this.div.focus()}remove(){F(this,Ue,oA).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(F(this,Ue,Nc).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(t){var e;let r=!1;this.parent&&!t?F(this,Ue,oA).call(this):t&&(F(this,Ue,Nc).call(this,t),r=!this.parent&&((e=this.div)==null?void 0:e.classList.contains("selectedEditor"))),super.setParent(t),this.show(this._isVisible),r&&this.select()}rotate(t){var e,r,i;const{drawLayer:s}=this.parent;let a;u(this,Er)?(t=(t-this.rotation+360)%360,a=F(e=Tr,ao,Wd).call(e,u(this,zi).box,t)):a=F(r=Tr,ao,Wd).call(r,[this.x,this.y,this.width,this.height],t),s.updateProperties(u(this,Yi),{bbox:a,root:{"data-main-rotation":t}}),s.updateProperties(u(this,jr),{bbox:F(i=Tr,ao,Wd).call(i,u(this,ui).box,t),root:{"data-main-rotation":t}})}render(){if(this.div)return this.div;const t=super.render();u(this,qp)&&(t.setAttribute("aria-label",u(this,qp)),t.setAttribute("role","mark")),u(this,Er)?t.classList.add("free"):this.div.addEventListener("keydown",F(this,Ue,fF).bind(this),{signal:this._uiManager._signal});const e=w(this,Ld,document.createElement("div"));return t.append(e),e.setAttribute("aria-hidden","true"),e.className="internal",e.style.clipPath=u(this,fd),this.setDims(),yM(this,u(this,Ld),["pointerover","pointerleave"]),this.enableEditing(),t}pointerover(){var t;this.isSelected||(t=this.parent)==null||t.drawLayer.updateProperties(u(this,jr),{rootClass:{hovered:!0}})}pointerleave(){var t;this.isSelected||(t=this.parent)==null||t.drawLayer.updateProperties(u(this,jr),{rootClass:{hovered:!1}})}_moveCaret(t){switch(this.parent.unselect(this),t){case 0:case 2:F(this,Ue,Z1).call(this,!0);break;case 1:case 3:F(this,Ue,Z1).call(this,!1);break}}select(){var t;super.select(),u(this,jr)&&((t=this.parent)==null||t.drawLayer.updateProperties(u(this,jr),{rootClass:{hovered:!1,selected:!0}}))}unselect(){var t;super.unselect(),u(this,jr)&&((t=this.parent)==null||t.drawLayer.updateProperties(u(this,jr),{rootClass:{selected:!1}}),u(this,Er)||F(this,Ue,Z1).call(this,!1))}get _mustFixPosition(){return!u(this,Er)}show(t=this._isVisible){super.show(t),this.parent&&(this.parent.drawLayer.updateProperties(u(this,Yi),{rootClass:{hidden:!t}}),this.parent.drawLayer.updateProperties(u(this,jr),{rootClass:{hidden:!t}}))}static startHighlighting(t,e,{target:r,x:i,y:s}){const{x:a,y:o,width:l,height:c}=r.getBoundingClientRect(),h=new AbortController,d=t.combinedSignal(h),p=g=>{h.abort(),F(this,ao,yF).call(this,t,g)};window.addEventListener("blur",p,{signal:d}),window.addEventListener("pointerup",p,{signal:d}),window.addEventListener("pointerdown",an,{capture:!0,passive:!1,signal:d}),window.addEventListener("contextmenu",Ti,{signal:d}),r.addEventListener("pointermove",F(this,ao,mF).bind(this,t),{signal:d}),this._freeHighlight=new sA({x:i,y:s},[a,o,l,c],t.scale,this._defaultThickness/2,e,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=t.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(t,e,r){var i,s,a,o;let l=null;if(t instanceof qP){const{data:{quadPoints:k,rect:P,rotation:T,id:M,color:D,opacity:L,popupRef:W,richText:z,contentsObj:V,creationDate:X,modificationDate:U},parent:{page:{pageNumber:K}}}=t;l=t={annotationType:te.HIGHLIGHT,color:Array.from(D),opacity:L,quadPoints:k,boxes:null,pageIndex:K-1,rect:P.slice(0),rotation:T,annotationElementId:M,id:M,deleted:!1,popupRef:W,richText:z,comment:(V==null?void 0:V.str)||null,creationDate:X,modificationDate:U}}else if(t instanceof t5){const{data:{inkLists:k,rect:P,rotation:T,id:M,color:D,borderStyle:{rawWidth:L},popupRef:W,richText:z,contentsObj:V,creationDate:X,modificationDate:U},parent:{page:{pageNumber:K}}}=t;l=t={annotationType:te.HIGHLIGHT,color:Array.from(D),thickness:L,inkLists:k,boxes:null,pageIndex:K-1,rect:P.slice(0),rotation:T,annotationElementId:M,id:M,deleted:!1,popupRef:W,richText:z,comment:(V==null?void 0:V.str)||null,creationDate:X,modificationDate:U}}const{color:c,quadPoints:h,inkLists:d,outlines:p,opacity:g}=t,m=await super.deserialize(t,e,r);m.color=ft.makeHexColor(...c),m.opacity=g||1,d&&w(m,Fs,t.thickness),m._initialData=l,t.comment&&m.setCommentData(t);const[y,v]=m.pageDimensions,[b,S]=m.pageTranslation;if(h){const k=w(m,Al,[]);for(let P=0;P<h.length;P+=8)k.push({x:(h[P]-b)/y,y:1-(h[P+1]-S)/v,width:(h[P+2]-h[P])/y,height:(h[P+1]-h[P+5])/v});F(i=m,Ue,aA).call(i),F(s=m,Ue,Nc).call(s),m.rotate(m.rotation)}else if(d||p){w(m,Er,!0);const k=(d||p.points)[0],P={x:k[0]-b,y:v-(k[1]-S)},T=new sA(P,[0,0,y,v],1,u(m,Fs)/2,!0,.001);for(let L=0,W=k.length;L<W;L+=2)P.x=k[L]-b,P.y=v-(k[L+1]-S),T.add(P);const{id:M,clipPathId:D}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:m.color,"fill-opacity":m._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:T.toSVGPath()}},!0,!0);F(a=m,Ue,Av).call(a,{highlightOutlines:T.getOutlines(),highlightId:M,clipPathId:D}),F(o=m,Ue,Nc).call(o),m.rotate(m.parentRotation)}return m}serialize(t=!1){if(this.isEmpty()||t)return null;if(this.deleted)return this.serializeDeleted();const e=on._colorManager.convert(this._uiManager.getNonHCMColor(this.color)),r=super.serialize(t);return Object.assign(r,{color:e,opacity:this.opacity,thickness:u(this,Fs),quadPoints:F(this,Ue,pF).call(this),outlines:F(this,Ue,gF).call(this,r.rect)}),this.addComment(r),this.annotationElementId&&!F(this,Ue,vF).call(this,r)?null:(r.id=this.annotationElementId,r)}renderAnnotationElement(t){return this.deleted?(t.hide(),null):(t.updateEdited({rect:this.getPDFRect(),popup:this.comment}),null)}static canCreateNewEmptyEditor(){return!1}};Wg=new WeakMap,bv=new WeakMap,Al=new WeakMap,fd=new WeakMap,_1=new WeakMap,ui=new WeakMap,wv=new WeakMap,xv=new WeakMap,Ld=new WeakMap,zi=new WeakMap,Yi=new WeakMap,Er=new WeakMap,jg=new WeakMap,zg=new WeakMap,jr=new WeakMap,qp=new WeakMap,Fs=new WeakMap,Y1=new WeakMap,Ue=new WeakSet,aA=function(){const n=new iA(u(this,Al),.001);w(this,zi,n.getOutlines()),[this.x,this.y,this.width,this.height]=u(this,zi).box;const t=new iA(u(this,Al),.0025,.001,this._uiManager.direction==="ltr");w(this,ui,t.getOutlines());const{firstPoint:e}=u(this,zi);w(this,jg,[(e[0]-this.x)/this.width,(e[1]-this.y)/this.height]);const{lastPoint:r}=u(this,ui);w(this,zg,[(r[0]-this.x)/this.width,(r[1]-this.y)/this.height])},Av=function({highlightOutlines:n,highlightId:t,clipPathId:e}){var r,i;if(w(this,zi,n),w(this,ui,n.getNewOutline(u(this,Fs)/2+1.5,.0025)),t>=0)w(this,Yi,t),w(this,fd,e),this.parent.drawLayer.finalizeDraw(t,{bbox:n.box,path:{d:n.toSVGPath()}}),w(this,jr,this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:u(this,ui).box,path:{d:u(this,ui).toSVGPath()}},!0));else if(this.parent){const d=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(u(this,Yi),{bbox:F(r=Yr,ao,Wd).call(r,u(this,zi).box,(d-this.rotation+360)%360),path:{d:n.toSVGPath()}}),this.parent.drawLayer.updateProperties(u(this,jr),{bbox:F(i=Yr,ao,Wd).call(i,u(this,ui).box,d),path:{d:u(this,ui).toSVGPath()}})}const[s,a,o,l]=n.box;switch(this.rotation){case 0:this.x=s,this.y=a,this.width=o,this.height=l;break;case 90:{const[d,p]=this.parentDimensions;this.x=a,this.y=1-s,this.width=o*p/d,this.height=l*d/p;break}case 180:this.x=1-s,this.y=1-a,this.width=o,this.height=l;break;case 270:{const[d,p]=this.parentDimensions;this.x=1-a,this.y=s,this.width=o*p/d,this.height=l*d/p;break}}const{firstPoint:c}=n;w(this,jg,[(c[0]-s)/o,(c[1]-a)/l]);const{lastPoint:h}=u(this,ui);w(this,zg,[(h[0]-s)/o,(h[1]-a)/l])},uF=function(n){const t=(i,s)=>{this.color=i,this.opacity=s,this.onUpdatedColor()},e=this.color,r=this.opacity;this.addCommands({cmd:t.bind(this,n,Yr._defaultOpacity),undo:t.bind(this,e,r),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:ce.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.getNonHCMColorName(n)},!0)},dF=function(n){const t=u(this,Fs),e=r=>{w(this,Fs,r),F(this,Ue,C6).call(this,r)};this.addCommands({cmd:e.bind(this,n),undo:e.bind(this,t),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:ce.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:n},!0)},C6=function(n){u(this,Er)&&(F(this,Ue,Av).call(this,{highlightOutlines:u(this,zi).getNewOutline(n/2)}),this.fixAndSetPosition(),this.setDims())},oA=function(){u(this,Yi)===null||!this.parent||(this.parent.drawLayer.remove(u(this,Yi)),w(this,Yi,null),this.parent.drawLayer.remove(u(this,jr)),w(this,jr,null))},Nc=function(n=this.parent){u(this,Yi)===null&&({id:Qn(this,Yi)._,clipPathId:Qn(this,fd)._}=n.drawLayer.draw({bbox:u(this,zi).box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":this.opacity},rootClass:{highlight:!0,free:u(this,Er)},path:{d:u(this,zi).toSVGPath()}},!1,!0),w(this,jr,n.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:u(this,Er)},bbox:u(this,ui).box,path:{d:u(this,ui).toSVGPath()}},u(this,Er))),u(this,Ld)&&(u(this,Ld).style.clipPath=u(this,fd)))},ao=new WeakSet,Wd=function([n,t,e,r],i){switch(i){case 90:return[1-t-r,n,r,e];case 180:return[1-n-e,1-t-r,e,r];case 270:return[t,1-n-e,r,e]}return[n,t,e,r]},fF=function(n){Yr._keyboardManager.exec(this,n)},Z1=function(n){if(!u(this,Wg))return;const t=window.getSelection();n?t.setPosition(u(this,Wg),u(this,bv)):t.setPosition(u(this,wv),u(this,xv))},Sv=function(){return u(this,Er)?this.rotation:0},pF=function(){if(u(this,Er))return null;const[n,t]=this.pageDimensions,[e,r]=this.pageTranslation,i=u(this,Al),s=new Float32Array(i.length*8);let a=0;for(const{x:o,y:l,width:c,height:h}of i){const d=o*n+e,p=(1-l)*t+r;s[a]=s[a+4]=d,s[a+1]=s[a+3]=p,s[a+2]=s[a+6]=d+c*n,s[a+5]=s[a+7]=p-h*t,a+=8}return s},gF=function(n){return u(this,zi).serialize(n,F(this,Ue,Sv).call(this))},mF=function(n,t){this._freeHighlight.add(t)&&n.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})},yF=function(n,t){this._freeHighlight.isEmpty()?n.drawLayer.remove(this._freeHighlightId):n.createAndAddNewEditor(t,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:"main_toolbar"}),this._freeHighlightId=-1,this._freeHighlight=null,this._freeHighlightClipId=""},vF=function(n){const{color:t}=this._initialData;return this.hasEditedComment||n.color.some((e,r)=>e!==t[r])},C(Yr,ao),J(Yr,"_defaultColor",null),J(Yr,"_defaultOpacity",1),J(Yr,"_defaultThickness",12),J(Yr,"_type","highlight"),J(Yr,"_editorType",te.HIGHLIGHT),J(Yr,"_freeHighlightId",-1),J(Yr,"_freeHighlight",null),J(Yr,"_freeHighlightClipId","");let T6=Yr;var Uu;class bF{constructor(){C(this,Uu,Object.create(null))}updateProperty(t,e){this[t]=e,this.updateSVGProperty(t,e)}updateProperties(t){if(t)for(const[e,r]of Object.entries(t))e.startsWith("_")||this.updateProperty(e,r)}updateSVGProperty(t,e){u(this,Uu)[t]=e}toSVGProperties(){const t=u(this,Uu);return w(this,Uu,Object.create(null)),{root:t}}reset(){w(this,Uu,Object.create(null))}updateAll(t=this){this.updateProperties(t)}clone(){Ne("Not implemented")}}Uu=new WeakMap;var ti,Hp,ur,pd,gd,Je,lA,e2,cA,Xp,M6,J1,Ug,Vu;const Ko=class ze extends on{constructor(t){super(t),C(this,Je),C(this,ti,null),C(this,Hp),J(this,"_colorPicker",null),J(this,"_drawId",null),w(this,Hp,t.mustBeCommitted||!1),this._addOutlines(t)}onUpdatedColor(){var t;(t=this._colorPicker)==null||t.update(this.color),super.onUpdatedColor()}onUpdatedOpacity(){var t,e;(e=(t=this._colorPicker)==null?void 0:t.updateOpacity)==null||e.call(t,this.opacity)}_addOutlines(t){t.drawOutlines&&(F(this,Je,lA).call(this,t),F(this,Je,Xp).call(this))}static _mergeSVGProperties(t,e){const r=new Set(Object.keys(t));for(const[i,s]of Object.entries(e))r.has(i)?Object.assign(t[i],s):t[i]=s;return t}static getDefaultDrawingOptions(t){Ne("Not implemented")}static get typesMap(){Ne("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(t,e){const r=this.typesMap.get(t);r&&this._defaultDrawingOptions.updateProperty(r,e),this._currentParent&&(u(ze,ur).updateProperty(r,e),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(t,e){const r=this.constructor.typesMap.get(t);r&&this._updateProperty(t,r,e)}static get defaultPropertiesToUpdate(){const t=[],e=this._defaultDrawingOptions;for(const[r,i]of this.typesMap)t.push([r,e[i]]);return t}get propertiesToUpdate(){const t=[],{_drawingOptions:e}=this;for(const[r,i]of this.constructor.typesMap)t.push([r,e[i]]);return t}_updateProperty(t,e,r){const i=this._drawingOptions,s=i[e],a=o=>{var l;i.updateProperty(e,o);const c=u(this,ti).updateProperty(e,o);c&&F(this,Je,Ug).call(this,c),(l=this.parent)==null||l.drawLayer.updateProperties(this._drawId,i.toSVGProperties()),t===this.colorType?this.onUpdatedColor():t===this.opacityType&&this.onUpdatedOpacity()};this.addCommands({cmd:a.bind(this,r),undo:a.bind(this,s),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:t,overwriteIfSameType:!0,keepUndo:!0})}_updateColorAndOpacity(t,e){const r=this.constructor.typesMap.get(this.colorType),i=this.constructor.typesMap.get(this.opacityType),s=this._drawingOptions,a=s[r],o=s[i],l=(c,h)=>{var d;s.updateProperty(r,c),s.updateProperty(i,h),u(this,ti).updateProperty(r,c),u(this,ti).updateProperty(i,h),(d=this.parent)==null||d.drawLayer.updateProperties(this._drawId,s.toSVGProperties()),this.onUpdatedColor(),this.onUpdatedOpacity()};this.addCommands({cmd:l.bind(this,t,e),undo:l.bind(this,a,o),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:ce.INK_COLOR_AND_OPACITY,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){var t;(t=this.parent)==null||t.drawLayer.updateProperties(this._drawId,ze._mergeSVGProperties(u(this,ti).getPathResizingSVGProperties(F(this,Je,J1).call(this)),{bbox:F(this,Je,Vu).call(this)}))}_onResized(){var t;(t=this.parent)==null||t.drawLayer.updateProperties(this._drawId,ze._mergeSVGProperties(u(this,ti).getPathResizedSVGProperties(F(this,Je,J1).call(this)),{bbox:F(this,Je,Vu).call(this)}))}_onTranslating(t,e){var r;(r=this.parent)==null||r.drawLayer.updateProperties(this._drawId,{bbox:F(this,Je,Vu).call(this)})}_onTranslated(){var t;(t=this.parent)==null||t.drawLayer.updateProperties(this._drawId,ze._mergeSVGProperties(u(this,ti).getPathTranslatedSVGProperties(F(this,Je,J1).call(this),this.parentDimensions),{bbox:F(this,Je,Vu).call(this)}))}_onStartDragging(){var t;(t=this.parent)==null||t.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){var t;(t=this.parent)==null||t.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(t){this.annotationElementId||this.parent.addUndoableEditor(this),this._isDraggable=!0,u(this,Hp)&&(w(this,Hp,!1),this.commit(),this.parent.setSelected(this),t&&this.isOnScreen&&this.div.focus())}remove(){F(this,Je,cA).call(this),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(F(this,Je,Xp).call(this),F(this,Je,Ug).call(this,u(this,ti).box),this.isAttachedToDOM||this.parent.add(this)))}setParent(t){var e;let r=!1;this.parent&&!t?(this._uiManager.removeShouldRescale(this),F(this,Je,cA).call(this)):t&&(this._uiManager.addShouldRescale(this),F(this,Je,Xp).call(this,t),r=!this.parent&&((e=this.div)==null?void 0:e.classList.contains("selectedEditor"))),super.setParent(t),r&&this.select()}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,ze._mergeSVGProperties({bbox:F(this,Je,Vu).call(this)},u(this,ti).updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&F(this,Je,Ug).call(this,u(this,ti).updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;let t,e;this._isCopy&&(t=this.x,e=this.y);const r=super.render();r.classList.add("draw");const i=document.createElement("div");return r.append(i),i.setAttribute("aria-hidden","true"),i.className="internal",this.setDims(),this._uiManager.addShouldRescale(this),this.disableEditing(),this._isCopy&&this._moveAfterPaste(t,e),r}static createDrawerInstance(t,e,r,i,s){Ne("Not implemented")}static startDrawing(t,e,r,i){var s;const{target:a,offsetX:o,offsetY:l,pointerId:c,pointerType:h}=i;if(Kr.isInitializedAndDifferentPointerType(h))return;const{viewport:{rotation:d}}=t,{width:p,height:g}=a.getBoundingClientRect(),m=w(ze,pd,new AbortController),y=t.combinedSignal(m);if(Kr.setPointer(h,c),window.addEventListener("pointerup",v=>{Kr.isSamePointerIdOrRemove(v.pointerId)&&this._endDraw(v)},{signal:y}),window.addEventListener("pointercancel",v=>{Kr.isSamePointerIdOrRemove(v.pointerId)&&this._currentParent.endDrawingSession()},{signal:y}),window.addEventListener("pointerdown",v=>{Kr.isSamePointerType(v.pointerType)&&(Kr.initializeAndAddPointerId(v.pointerId),u(ze,ur).isCancellable()&&(u(ze,ur).removeLastElement(),u(ze,ur).isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:y}),window.addEventListener("contextmenu",Ti,{signal:y}),a.addEventListener("pointermove",this._drawMove.bind(this),{signal:y}),a.addEventListener("touchmove",v=>{Kr.isSameTimeStamp(v.timeStamp)&&an(v)},{signal:y}),t.toggleDrawing(),(s=e._editorUndoBar)==null||s.hide(),u(ze,ur)){t.drawLayer.updateProperties(this._currentDrawId,u(ze,ur).startNew(o,l,p,g,d));return}e.updateUIForDefaultProperties(this),w(ze,ur,this.createDrawerInstance(o,l,p,g,d)),w(ze,gd,this.getDefaultDrawingOptions()),this._currentParent=t,{id:this._currentDrawId}=t.drawLayer.draw(this._mergeSVGProperties(u(ze,gd).toSVGProperties(),u(ze,ur).defaultSVGProperties),!0,!1)}static _drawMove(t){if(Kr.isSameTimeStamp(t.timeStamp),!u(ze,ur))return;const{offsetX:e,offsetY:r,pointerId:i}=t;if(Kr.isSamePointerId(i)){if(Kr.isUsingMultiplePointers()){this._endDraw(t);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,u(ze,ur).add(e,r)),Kr.setTimeStamp(t.timeStamp),an(t)}}static _cleanup(t){t&&(this._currentDrawId=-1,this._currentParent=null,w(ze,ur,null),w(ze,gd,null),Kr.clearTimeStamp()),u(ze,pd)&&(u(ze,pd).abort(),w(ze,pd,null),Kr.clearPointerIds())}static _endDraw(t){const e=this._currentParent;if(e){if(e.toggleDrawing(!0),this._cleanup(!1),(t==null?void 0:t.target)===e.div&&e.drawLayer.updateProperties(this._currentDrawId,u(ze,ur).end(t.offsetX,t.offsetY)),this.supportMultipleDrawings){const r=u(ze,ur),i=this._currentDrawId,s=r.getLastElement();e.addCommands({cmd:()=>{e.drawLayer.updateProperties(i,r.setLastElement(s))},undo:()=>{e.drawLayer.updateProperties(i,r.removeLastElement())},mustExec:!1,type:ce.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(t){const e=this._currentParent;if(!e)return null;if(e.toggleDrawing(!0),e.cleanUndoStack(ce.DRAW_STEP),!u(ze,ur).isEmpty()){const{pageDimensions:[r,i],scale:s}=e,a=e.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:u(ze,ur).getOutlines(r*s,i*s,s,this._INNER_MARGIN),drawingOptions:u(ze,gd),mustBeCommitted:!t});return this._cleanup(!0),a}return e.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(t){}static deserializeDraw(t,e,r,i,s,a){Ne("Not implemented")}static async deserialize(t,e,r){var i,s;const{rawDims:{pageWidth:a,pageHeight:o,pageX:l,pageY:c}}=e.viewport,h=this.deserializeDraw(l,c,a,o,this._INNER_MARGIN,t),d=await super.deserialize(t,e,r);return d.createDrawingOptions(t),F(i=d,Je,lA).call(i,{drawOutlines:h}),F(s=d,Je,Xp).call(s),d.onScaleChanging(),d.rotate(),d}serializeDraw(t){const[e,r]=this.pageTranslation,[i,s]=this.pageDimensions;return u(this,ti).serialize([e,r,i,s],t)}renderAnnotationElement(t){return t.updateEdited({rect:this.getPDFRect()}),null}static canCreateNewEmptyEditor(){return!1}};ti=new WeakMap,Hp=new WeakMap,ur=new WeakMap,pd=new WeakMap,gd=new WeakMap,Je=new WeakSet,lA=function({drawOutlines:n,drawId:t,drawingOptions:e}){w(this,ti,n),this._drawingOptions||(this._drawingOptions=e),this.annotationElementId||this._uiManager.a11yAlert(`pdfjs-editor-${this.editorType}-added-alert`),t>=0?(this._drawId=t,this.parent.drawLayer.finalizeDraw(t,n.defaultProperties)):this._drawId=F(this,Je,e2).call(this,n,this.parent),F(this,Je,Ug).call(this,n.box)},e2=function(n,t){const{id:e}=t.drawLayer.draw(Ko._mergeSVGProperties(this._drawingOptions.toSVGProperties(),n.defaultSVGProperties),!1,!1);return e},cA=function(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())},Xp=function(n=this.parent){if(!(this._drawId!==null&&this.parent===n)){if(this._drawId!==null){this.parent.drawLayer.updateParent(this._drawId,n.drawLayer);return}this._drawingOptions.updateAll(),this._drawId=F(this,Je,e2).call(this,u(this,ti),n)}},M6=function([n,t,e,r]){const{parentDimensions:[i,s],rotation:a}=this;switch(a){case 90:return[t,1-n,e*(s/i),r*(i/s)];case 180:return[1-n,1-t,e,r];case 270:return[1-t,n,e*(s/i),r*(i/s)];default:return[n,t,e,r]}},J1=function(){const{x:n,y:t,width:e,height:r,parentDimensions:[i,s],rotation:a}=this;switch(a){case 90:return[1-t,n,e*(i/s),r*(s/i)];case 180:return[1-n,1-t,e,r];case 270:return[t,1-n,e*(i/s),r*(s/i)];default:return[n,t,e,r]}},Ug=function(n){[this.x,this.y,this.width,this.height]=F(this,Je,M6).call(this,n),this.div&&(this.fixAndSetPosition(),this.setDims()),this._onResized()},Vu=function(){const{x:n,y:t,width:e,height:r,rotation:i,parentRotation:s,parentDimensions:[a,o]}=this;switch((i*4+s)/90){case 1:return[1-t-r,n,r,e];case 2:return[1-n-e,1-t-r,e,r];case 3:return[t,1-n-e,r,e];case 4:return[n,t-e*(a/o),r*(o/a),e*(a/o)];case 5:return[1-t,n,e*(a/o),r*(o/a)];case 6:return[1-n-r*(o/a),1-t,r*(o/a),e*(a/o)];case 7:return[t-e*(a/o),1-n-r*(o/a),e*(a/o),r*(o/a)];case 8:return[n-e,t-r,e,r];case 9:return[1-t,n-e,r,e];case 10:return[1-n,1-t,e,r];case 11:return[t-r,1-n,r,e];case 12:return[n-r*(o/a),t,r*(o/a),e*(a/o)];case 13:return[1-t-e*(a/o),n-r*(o/a),e*(a/o),r*(o/a)];case 14:return[1-n,1-t-e*(a/o),r*(o/a),e*(a/o)];case 15:return[t,1-n,e*(a/o),r*(o/a)];default:return[n,t,e,r]}},J(Ko,"_currentDrawId",-1),J(Ko,"_currentParent",null),C(Ko,ur,null),C(Ko,pd,null),C(Ko,gd,null),J(Ko,"_INNER_MARGIN",3);let wF=Ko;var ja,lr,cr,md,Kp,Zr,hr,ks,Gu,yd,vd,_p,Q1;class I_{constructor(t,e,r,i,s,a){C(this,_p),C(this,ja,new Float64Array(6)),C(this,lr),C(this,cr),C(this,md),C(this,Kp),C(this,Zr),C(this,hr,""),C(this,ks,0),C(this,Gu,new Fm),C(this,yd),C(this,vd),w(this,yd,r),w(this,vd,i),w(this,md,s),w(this,Kp,a),[t,e]=F(this,_p,Q1).call(this,t,e);const o=w(this,lr,[NaN,NaN,NaN,NaN,t,e]);w(this,Zr,[t,e]),w(this,cr,[{line:o,points:u(this,Zr)}]),u(this,ja).set(o,0)}updateProperty(t,e){t==="stroke-width"&&w(this,Kp,e)}isEmpty(){return!u(this,cr)||u(this,cr).length===0}isCancellable(){return u(this,Zr).length<=10}add(t,e){[t,e]=F(this,_p,Q1).call(this,t,e);const[r,i,s,a]=u(this,ja).subarray(2,6),o=t-s,l=e-a;return Math.hypot(u(this,yd)*o,u(this,vd)*l)<=2?null:(u(this,Zr).push(t,e),isNaN(r)?(u(this,ja).set([s,a,t,e],2),u(this,lr).push(NaN,NaN,NaN,NaN,t,e),{path:{d:this.toSVGPath()}}):(isNaN(u(this,ja)[0])&&u(this,lr).splice(6,6),u(this,ja).set([r,i,s,a,t,e],0),u(this,lr).push(...Ft.createBezierPoints(r,i,s,a,t,e)),{path:{d:this.toSVGPath()}}))}end(t,e){return this.add(t,e)||(u(this,Zr).length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,r,i,s){w(this,yd,r),w(this,vd,i),w(this,md,s),[t,e]=F(this,_p,Q1).call(this,t,e);const a=w(this,lr,[NaN,NaN,NaN,NaN,t,e]);w(this,Zr,[t,e]);const o=u(this,cr).at(-1);return o&&(o.line=new Float32Array(o.line),o.points=new Float32Array(o.points)),u(this,cr).push({line:a,points:u(this,Zr)}),u(this,ja).set(a,0),w(this,ks,0),this.toSVGPath(),null}getLastElement(){return u(this,cr).at(-1)}setLastElement(t){return u(this,cr)?(u(this,cr).push(t),w(this,lr,t.line),w(this,Zr,t.points),w(this,ks,0),{path:{d:this.toSVGPath()}}):u(this,Gu).setLastElement(t)}removeLastElement(){if(!u(this,cr))return u(this,Gu).removeLastElement();u(this,cr).pop(),w(this,hr,"");for(let t=0,e=u(this,cr).length;t<e;t++){const{line:r,points:i}=u(this,cr)[t];w(this,lr,r),w(this,Zr,i),w(this,ks,0),this.toSVGPath()}return{path:{d:u(this,hr)}}}toSVGPath(){const t=Ft.svgRound(u(this,lr)[4]),e=Ft.svgRound(u(this,lr)[5]);if(u(this,Zr).length===2)return w(this,hr,`${u(this,hr)} M ${t} ${e} Z`),u(this,hr);if(u(this,Zr).length<=6){const i=u(this,hr).lastIndexOf("M");w(this,hr,`${u(this,hr).slice(0,i)} M ${t} ${e}`),w(this,ks,6)}if(u(this,Zr).length===4){const i=Ft.svgRound(u(this,lr)[10]),s=Ft.svgRound(u(this,lr)[11]);return w(this,hr,`${u(this,hr)} L ${i} ${s}`),w(this,ks,12),u(this,hr)}const r=[];u(this,ks)===0&&(r.push(`M ${t} ${e}`),w(this,ks,6));for(let i=u(this,ks),s=u(this,lr).length;i<s;i+=6){const[a,o,l,c,h,d]=u(this,lr).slice(i,i+6).map(Ft.svgRound);r.push(`C${a} ${o} ${l} ${c} ${h} ${d}`)}return w(this,hr,u(this,hr)+r.join(" ")),w(this,ks,u(this,lr).length),u(this,hr)}getOutlines(t,e,r,i){const s=u(this,cr).at(-1);return s.line=new Float32Array(s.line),s.points=new Float32Array(s.points),u(this,Gu).build(u(this,cr),t,e,r,u(this,md),u(this,Kp),i),w(this,ja,null),w(this,lr,null),w(this,cr,null),w(this,hr,null),u(this,Gu)}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}ja=new WeakMap,lr=new WeakMap,cr=new WeakMap,md=new WeakMap,Kp=new WeakMap,Zr=new WeakMap,hr=new WeakMap,ks=new WeakMap,Gu=new WeakMap,yd=new WeakMap,vd=new WeakMap,_p=new WeakSet,Q1=function(n,t){return Ft._normalizePoint(n,t,u(this,yd),u(this,vd),u(this,md))};var ei,$1,kv,Ui,to,eo,Vg,Gg,jd,mi,oo,xF,AF,SF;class Fm extends Ft{constructor(){super(...arguments),C(this,mi),C(this,ei),C(this,$1,0),C(this,kv),C(this,Ui),C(this,to),C(this,eo),C(this,Vg),C(this,Gg),C(this,jd)}build(t,e,r,i,s,a,o){w(this,to,e),w(this,eo,r),w(this,Vg,i),w(this,Gg,s),w(this,jd,a),w(this,kv,o??0),w(this,Ui,t),F(this,mi,AF).call(this)}get thickness(){return u(this,jd)}setLastElement(t){return u(this,Ui).push(t),{path:{d:this.toSVGPath()}}}removeLastElement(){return u(this,Ui).pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const t=[];for(const{line:e}of u(this,Ui)){if(t.push(`M${Ft.svgRound(e[4])} ${Ft.svgRound(e[5])}`),e.length===6){t.push("Z");continue}if(e.length===12&&isNaN(e[6])){t.push(`L${Ft.svgRound(e[10])} ${Ft.svgRound(e[11])}`);continue}for(let r=6,i=e.length;r<i;r+=6){const[s,a,o,l,c,h]=e.subarray(r,r+6).map(Ft.svgRound);t.push(`C${s} ${a} ${o} ${l} ${c} ${h}`)}}return t.join("")}serialize([t,e,r,i],s){const a=[],o=[],[l,c,h,d]=F(this,mi,xF).call(this);let p,g,m,y,v,b,S,k,P;switch(u(this,Gg)){case 0:P=Ft._rescale,p=t,g=e+i,m=r,y=-i,v=t+l*r,b=e+(1-c-d)*i,S=t+(l+h)*r,k=e+(1-c)*i;break;case 90:P=Ft._rescaleAndSwap,p=t,g=e,m=r,y=i,v=t+c*r,b=e+l*i,S=t+(c+d)*r,k=e+(l+h)*i;break;case 180:P=Ft._rescale,p=t+r,g=e,m=-r,y=i,v=t+(1-l-h)*r,b=e+c*i,S=t+(1-l)*r,k=e+(c+d)*i;break;case 270:P=Ft._rescaleAndSwap,p=t+r,g=e+i,m=-r,y=-i,v=t+(1-c-d)*r,b=e+(1-l-h)*i,S=t+(1-c)*r,k=e+(1-l)*i;break}for(const{line:T,points:M}of u(this,Ui))a.push(P(T,p,g,m,y,s?new Array(T.length):null)),o.push(P(M,p,g,m,y,s?new Array(M.length):null));return{lines:a,points:o,rect:[v,b,S,k]}}static deserialize(t,e,r,i,s,{paths:{lines:a,points:o},rotation:l,thickness:c}){const h=[];let d,p,g,m,y;switch(l){case 0:y=Ft._rescale,d=-t/r,p=e/i+1,g=1/r,m=-1/i;break;case 90:y=Ft._rescaleAndSwap,d=-e/i,p=-t/r,g=1/i,m=1/r;break;case 180:y=Ft._rescale,d=t/r+1,p=-e/i,g=-1/r,m=1/i;break;case 270:y=Ft._rescaleAndSwap,d=e/i+1,p=t/r+1,g=-1/i,m=-1/r;break}if(!a){a=[];for(const b of o){const S=b.length;if(S===2){a.push(new Float32Array([NaN,NaN,NaN,NaN,b[0],b[1]]));continue}if(S===4){a.push(new Float32Array([NaN,NaN,NaN,NaN,b[0],b[1],NaN,NaN,NaN,NaN,b[2],b[3]]));continue}const k=new Float32Array(3*(S-2));a.push(k);let[P,T,M,D]=b.subarray(0,4);k.set([NaN,NaN,NaN,NaN,P,T],0);for(let L=4;L<S;L+=2){const W=b[L],z=b[L+1];k.set(Ft.createBezierPoints(P,T,M,D,W,z),(L-2)*3),[P,T,M,D]=[M,D,W,z]}}}for(let b=0,S=a.length;b<S;b++)h.push({line:y(a[b].map(k=>k??NaN),d,p,g,m),points:y(o[b].map(k=>k??NaN),d,p,g,m)});const v=new this.prototype.constructor;return v.build(h,r,i,1,l,c,s),v}get box(){return u(this,ei)}updateProperty(t,e){return t==="stroke-width"?F(this,mi,SF).call(this,e):null}updateParentDimensions([t,e],r){const[i,s]=F(this,mi,oo).call(this);w(this,to,t),w(this,eo,e),w(this,Vg,r);const[a,o]=F(this,mi,oo).call(this),l=a-i,c=o-s,h=u(this,ei);return h[0]-=l,h[1]-=c,h[2]+=2*l,h[3]+=2*c,h}updateRotation(t){return w(this,$1,t),{path:{transform:this.rotationTransform}}}get viewBox(){return u(this,ei).map(Ft.svgRound).join(" ")}get defaultProperties(){const[t,e]=u(this,ei);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Ft.svgRound(t)} ${Ft.svgRound(e)}`}}}get rotationTransform(){const[,,t,e]=u(this,ei);let r=0,i=0,s=0,a=0,o=0,l=0;switch(u(this,$1)){case 90:i=e/t,s=-t/e,o=t;break;case 180:r=-1,a=-1,o=t,l=e;break;case 270:i=-e/t,s=t/e,l=e;break;default:return""}return`matrix(${r} ${i} ${s} ${a} ${Ft.svgRound(o)} ${Ft.svgRound(l)})`}getPathResizingSVGProperties([t,e,r,i]){const[s,a]=F(this,mi,oo).call(this),[o,l,c,h]=u(this,ei);if(Math.abs(c-s)<=Ft.PRECISION||Math.abs(h-a)<=Ft.PRECISION){const y=t+r/2-(o+c/2),v=e+i/2-(l+h/2);return{path:{"transform-origin":`${Ft.svgRound(t)} ${Ft.svgRound(e)}`,transform:`${this.rotationTransform} translate(${y} ${v})`}}}const d=(r-2*s)/(c-2*s),p=(i-2*a)/(h-2*a),g=c/r,m=h/i;return{path:{"transform-origin":`${Ft.svgRound(o)} ${Ft.svgRound(l)}`,transform:`${this.rotationTransform} scale(${g} ${m}) translate(${Ft.svgRound(s)} ${Ft.svgRound(a)}) scale(${d} ${p}) translate(${Ft.svgRound(-s)} ${Ft.svgRound(-a)})`}}}getPathResizedSVGProperties([t,e,r,i]){const[s,a]=F(this,mi,oo).call(this),o=u(this,ei),[l,c,h,d]=o;if(o[0]=t,o[1]=e,o[2]=r,o[3]=i,Math.abs(h-s)<=Ft.PRECISION||Math.abs(d-a)<=Ft.PRECISION){const v=t+r/2-(l+h/2),b=e+i/2-(c+d/2);for(const{line:S,points:k}of u(this,Ui))Ft._translate(S,v,b,S),Ft._translate(k,v,b,k);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Ft.svgRound(t)} ${Ft.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const p=(r-2*s)/(h-2*s),g=(i-2*a)/(d-2*a),m=-p*(l+s)+t+s,y=-g*(c+a)+e+a;if(p!==1||g!==1||m!==0||y!==0)for(const{line:v,points:b}of u(this,Ui))Ft._rescale(v,m,y,p,g,v),Ft._rescale(b,m,y,p,g,b);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Ft.svgRound(t)} ${Ft.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([t,e],r){const[i,s]=r,a=u(this,ei),o=t-a[0],l=e-a[1];if(u(this,to)===i&&u(this,eo)===s)for(const{line:c,points:h}of u(this,Ui))Ft._translate(c,o,l,c),Ft._translate(h,o,l,h);else{const c=u(this,to)/i,h=u(this,eo)/s;w(this,to,i),w(this,eo,s);for(const{line:d,points:p}of u(this,Ui))Ft._rescale(d,o,l,c,h,d),Ft._rescale(p,o,l,c,h,p);a[2]*=c,a[3]*=h}return a[0]=t,a[1]=e,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${Ft.svgRound(t)} ${Ft.svgRound(e)}`}}}get defaultSVGProperties(){const t=u(this,ei);return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${Ft.svgRound(t[0])} ${Ft.svgRound(t[1])}`,transform:this.rotationTransform||null},bbox:t}}}ei=new WeakMap,$1=new WeakMap,kv=new WeakMap,Ui=new WeakMap,to=new WeakMap,eo=new WeakMap,Vg=new WeakMap,Gg=new WeakMap,jd=new WeakMap,mi=new WeakSet,oo=function(n=u(this,jd)){const t=u(this,kv)+n/2*u(this,Vg);return u(this,Gg)%180===0?[t/u(this,to),t/u(this,eo)]:[t/u(this,eo),t/u(this,to)]},xF=function(){const[n,t,e,r]=u(this,ei),[i,s]=F(this,mi,oo).call(this,0);return[n+i,t+s,e-2*i,r-2*s]},AF=function(){const n=w(this,ei,ah.slice());for(const{line:r}of u(this,Ui)){if(r.length<=12){for(let a=4,o=r.length;a<o;a+=6)ft.pointBoundingBox(r[a],r[a+1],n);continue}let i=r[4],s=r[5];for(let a=6,o=r.length;a<o;a+=6){const[l,c,h,d,p,g]=r.subarray(a,a+6);ft.bezierBoundingBox(i,s,l,c,h,d,p,g,n),i=p,s=g}}const[t,e]=F(this,mi,oo).call(this);n[0]=en(n[0]-t,0,1),n[1]=en(n[1]-e,0,1),n[2]=en(n[2]+t,0,1),n[3]=en(n[3]+e,0,1),n[2]-=n[0],n[3]-=n[1]},SF=function(n){const[t,e]=F(this,mi,oo).call(this);w(this,jd,n);const[r,i]=F(this,mi,oo).call(this),[s,a]=[r-t,i-e],o=u(this,ei);return o[0]-=s,o[1]-=a,o[2]+=2*s,o[3]+=2*a,o};class Ob extends bF{constructor(t){super(),this._viewParameters=t,super.updateProperties({fill:"none",stroke:on._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(t,e){t==="stroke-width"&&(e??(e=this["stroke-width"]),e*=this._viewParameters.realScale),super.updateSVGProperty(t,e)}clone(){const t=new Ob(this._viewParameters);return t.updateAll(this),t}}var hA,kF;const t0=class CF extends wF{constructor(t){super({...t,name:"inkEditor"}),C(this,hA),this._willKeepAspectRatio=!0,this.defaultL10nId="pdfjs-editor-ink-editor"}static initialize(t,e){on.initialize(t,e),this._defaultDrawingOptions=new Ob(e.viewParameters)}static getDefaultDrawingOptions(t){const e=this._defaultDrawingOptions.clone();return e.updateProperties(t),e}static get supportMultipleDrawings(){return!0}static get typesMap(){return se(this,"typesMap",new Map([[ce.INK_THICKNESS,"stroke-width"],[ce.INK_COLOR,"stroke"],[ce.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(t,e,r,i,s){return new I_(t,e,r,i,s,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(t,e,r,i,s,a){return Fm.deserialize(t,e,r,i,s,a)}static async deserialize(t,e,r){let i=null;if(t instanceof t5){const{data:{inkLists:a,rect:o,rotation:l,id:c,color:h,opacity:d,borderStyle:{rawWidth:p},popupRef:g,richText:m,contentsObj:y,creationDate:v,modificationDate:b},parent:{page:{pageNumber:S}}}=t;i=t={annotationType:te.INK,color:Array.from(h),thickness:p,opacity:d,paths:{points:a},boxes:null,pageIndex:S-1,rect:o.slice(0),rotation:l,annotationElementId:c,id:c,deleted:!1,popupRef:g,richText:m,comment:(y==null?void 0:y.str)||null,creationDate:v,modificationDate:b}}const s=await super.deserialize(t,e,r);return s._initialData=i,t.comment&&s.setCommentData(t),s}get toolbarButtons(){return this._colorPicker||(this._colorPicker=new BP(this)),[["colorPicker",this._colorPicker]]}get colorType(){return ce.INK_COLOR}get colorAndOpacityType(){return ce.INK_COLOR_AND_OPACITY}get opacityType(){return ce.INK_OPACITY}updateParams(t,e){if(t===ce.INK_COLOR_AND_OPACITY){this._updateColorAndOpacity(e.color,e.opacity);return}super.updateParams(t,e)}static updateDefaultParams(t,e){if(t===ce.INK_COLOR_AND_OPACITY){super.updateDefaultParams(ce.INK_COLOR,e.color),super.updateDefaultParams(ce.INK_OPACITY,e.opacity);return}super.updateDefaultParams(t,e)}get color(){return this._drawingOptions.stroke}get opacity(){return this._drawingOptions["stroke-opacity"]}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();const{_drawId:t,_drawingOptions:e,parent:r}=this;e.updateSVGProperty("stroke-width"),r.drawLayer.updateProperties(t,e.toSVGProperties())}static onScaleChangingWhenDrawing(){const t=this._currentParent;t&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),t.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:t,thickness:e,opacity:r}){this._drawingOptions=CF.getDefaultDrawingOptions({stroke:ft.makeHexColor(...t),"stroke-width":e,"stroke-opacity":r})}serialize(t=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:e,points:r}=this.serializeDraw(t),{_drawingOptions:{stroke:i,"stroke-opacity":s,"stroke-width":a}}=this,o=Object.assign(super.serialize(t),{color:on._colorManager.convert(i),opacity:s,thickness:a,paths:{lines:e,points:r}});return this.addComment(o),t?(o.isCopy=!0,o):this.annotationElementId&&!F(this,hA,kF).call(this,o)?null:(o.id=this.annotationElementId,o)}renderAnnotationElement(t){if(this.deleted)return t.hide(),null;const{points:e,rect:r}=this.serializeDraw(!1);return t.updateEdited({rect:r,thickness:this._drawingOptions["stroke-width"],points:e,popup:this.comment}),null}};hA=new WeakSet,kF=function(n){const{color:t,thickness:e,opacity:r,pageIndex:i}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized||n.color.some((s,a)=>s!==t[a])||n.thickness!==e||n.opacity!==r||n.pageIndex!==i},J(t0,"_type","ink"),J(t0,"_editorType",te.INK),J(t0,"_defaultDrawingOptions",null);let O_=t0;class uA extends Fm{toSVGPath(){let t=super.toSVGPath();return t.endsWith("Z")||(t+="Z"),t}}const vy=8,Mf=3;var zd,Zn,n2,Us,P6,F6,dA,by,TF,MF,PF,fA,pA,FF;class fa{static extractContoursFromText(t,{fontFamily:e,fontStyle:r,fontWeight:i},s,a,o,l){let c=new OffscreenCanvas(1,1),h=c.getContext("2d",{alpha:!1});const d=200,p=h.font=`${r} ${i} ${d}px ${e}`,{actualBoundingBoxLeft:g,actualBoundingBoxRight:m,actualBoundingBoxAscent:y,actualBoundingBoxDescent:v,fontBoundingBoxAscent:b,fontBoundingBoxDescent:S,width:k}=h.measureText(t),P=1.5,T=Math.ceil(Math.max(Math.abs(g)+Math.abs(m)||0,k)*P),M=Math.ceil(Math.max(Math.abs(y)+Math.abs(v)||d,Math.abs(b)+Math.abs(S)||d)*P);c=new OffscreenCanvas(T,M),h=c.getContext("2d",{alpha:!0,willReadFrequently:!0}),h.font=p,h.filter="grayscale(1)",h.fillStyle="white",h.fillRect(0,0,T,M),h.fillStyle="black",h.fillText(t,T*(P-1)/2,M*(3-P)/2);const D=F(this,Zn,fA).call(this,h.getImageData(0,0,T,M).data),L=F(this,Zn,PF).call(this,D),W=F(this,Zn,pA).call(this,L),z=F(this,Zn,dA).call(this,D,T,M,W);return this.processDrawnLines({lines:{curves:z,width:T,height:M},pageWidth:s,pageHeight:a,rotation:o,innerMargin:l,mustSmooth:!0,areContours:!0})}static process(t,e,r,i,s){const[a,o,l]=F(this,Zn,FF).call(this,t),[c,h]=F(this,Zn,MF).call(this,a,o,l,Math.hypot(o,l)*u(this,zd).sigmaSFactor,u(this,zd).sigmaR,u(this,zd).kernelSize),d=F(this,Zn,pA).call(this,h),p=F(this,Zn,dA).call(this,c,o,l,d);return this.processDrawnLines({lines:{curves:p,width:o,height:l},pageWidth:e,pageHeight:r,rotation:i,innerMargin:s,mustSmooth:!0,areContours:!0})}static processDrawnLines({lines:t,pageWidth:e,pageHeight:r,rotation:i,innerMargin:s,mustSmooth:a,areContours:o}){i%180!==0&&([e,r]=[r,e]);const{curves:l,width:c,height:h}=t,d=t.thickness??0,p=[],g=Math.min(e/c,r/h),m=g/e,y=g/r,v=[];for(const{points:S}of l){const k=a?F(this,Zn,TF).call(this,S):S;if(!k)continue;v.push(k);const P=k.length,T=new Float32Array(P),M=new Float32Array(3*(P===2?2:P-2));if(p.push({line:M,points:T}),P===2){T[0]=k[0]*m,T[1]=k[1]*y,M.set([NaN,NaN,NaN,NaN,T[0],T[1]],0);continue}let[D,L,W,z]=k;D*=m,L*=y,W*=m,z*=y,T.set([D,L,W,z],0),M.set([NaN,NaN,NaN,NaN,D,L],0);for(let V=4;V<P;V+=2){const X=T[V]=k[V]*m,U=T[V+1]=k[V+1]*y;M.set(Ft.createBezierPoints(D,L,W,z,X,U),(V-2)*3),[D,L,W,z]=[W,z,X,U]}}if(p.length===0)return null;const b=o?new uA:new Fm;return b.build(p,e,r,1,i,o?0:d,s),{outline:b,newCurves:v,areContours:o,thickness:d,width:c,height:h}}static async compressSignature({outlines:t,areContours:e,thickness:r,width:i,height:s}){let a=1/0,o=-1/0,l=0;for(const b of t){l+=b.length;for(let S=2,k=b.length;S<k;S++){const P=b[S]-b[S-2];a=Math.min(a,P),o=Math.max(o,P)}}let c;a>=-128&&o<=127?c=Int8Array:a>=-32768&&o<=32767?c=Int16Array:c=Int32Array;const h=t.length,d=vy+Mf*h,p=new Uint32Array(d);let g=0;p[g++]=d*Uint32Array.BYTES_PER_ELEMENT+(l-2*h)*c.BYTES_PER_ELEMENT,p[g++]=0,p[g++]=i,p[g++]=s,p[g++]=e?0:1,p[g++]=Math.max(0,Math.floor(r??0)),p[g++]=h,p[g++]=c.BYTES_PER_ELEMENT;for(const b of t)p[g++]=b.length-2,p[g++]=b[0],p[g++]=b[1];const m=new CompressionStream("deflate-raw"),y=m.writable.getWriter();await y.ready,y.write(p);const v=c.prototype.constructor;for(const b of t){const S=new v(b.length-2);for(let k=2,P=b.length;k<P;k++)S[k-2]=b[k]-b[k-2];y.write(S)}return y.close(),(await new Response(m.readable).bytes()).toBase64()}static async decompressSignature(t){try{const e=Uint8Array.fromBase64(t),{readable:r,writable:i}=new DecompressionStream("deflate-raw"),s=i.getWriter();await s.ready,s.write(e).then(async()=>{await s.ready,await s.close()}).catch(()=>{});let a=null,o=0;for await(const k of r)a||(a=new Uint8Array(new Uint32Array(k.buffer,0,4)[0])),a.set(k,o),o+=k.length;const l=new Uint32Array(a.buffer,0,a.length>>2),c=l[1];if(c!==0)throw new Error(`Invalid version: ${c}`);const h=l[2],d=l[3],p=l[4]===0,g=l[5],m=l[6],y=l[7],v=[],b=(vy+Mf*m)*Uint32Array.BYTES_PER_ELEMENT;let S;switch(y){case Int8Array.BYTES_PER_ELEMENT:S=new Int8Array(a.buffer,b);break;case Int16Array.BYTES_PER_ELEMENT:S=new Int16Array(a.buffer,b);break;case Int32Array.BYTES_PER_ELEMENT:S=new Int32Array(a.buffer,b);break}o=0;for(let k=0;k<m;k++){const P=l[Mf*k+vy],T=new Float32Array(P+2);v.push(T);for(let M=0;M<Mf-1;M++)T[M]=l[Mf*k+vy+M+1];for(let M=0;M<P;M++)T[M+2]=T[M]+S[o++]}return{areContours:p,thickness:g,outlines:v,width:h,height:d}}catch(e){return he(`decompressSignature: ${e}`),null}}}zd=new WeakMap,Zn=new WeakSet,n2=function(n,t,e,r){return e-=n,r-=t,e===0?r>0?0:4:e===1?r+6:2-r},Us=new WeakMap,P6=function(n,t,e,r,i,s,a){const o=F(this,Zn,n2).call(this,e,r,i,s);for(let l=0;l<8;l++){const c=(-l+o-a+16)%8,h=u(this,Us)[2*c],d=u(this,Us)[2*c+1];if(n[(e+h)*t+(r+d)]!==0)return c}return-1},F6=function(n,t,e,r,i,s,a){const o=F(this,Zn,n2).call(this,e,r,i,s);for(let l=0;l<8;l++){const c=(l+o+a+16)%8,h=u(this,Us)[2*c],d=u(this,Us)[2*c+1];if(n[(e+h)*t+(r+d)]!==0)return c}return-1},dA=function(n,t,e,r){const i=n.length,s=new Int32Array(i);for(let c=0;c<i;c++)s[c]=n[c]<=r?1:0;for(let c=1;c<e-1;c++)s[c*t]=s[c*t+t-1]=0;for(let c=0;c<t;c++)s[c]=s[t*e-1-c]=0;let a=1,o;const l=[];for(let c=1;c<e-1;c++){o=1;for(let h=1;h<t-1;h++){const d=c*t+h,p=s[d];if(p===0)continue;let g=c,m=h;if(p===1&&s[d-1]===0)a+=1,m-=1;else if(p>=1&&s[d+1]===0)a+=1,m+=1,p>1&&(o=p);else{p!==1&&(o=Math.abs(p));continue}const y=[h,c],v=m===h+1,b={isHole:v,points:y,id:a,parent:0};l.push(b);let S;for(const z of l)if(z.id===o){S=z;break}S?S.isHole?b.parent=v?S.parent:o:b.parent=v?o:S.parent:b.parent=v?o:0;const k=F(this,Zn,P6).call(this,s,t,c,h,g,m,0);if(k===-1){s[d]=-a,s[d]!==1&&(o=Math.abs(s[d]));continue}let P=u(this,Us)[2*k],T=u(this,Us)[2*k+1];const M=c+P,D=h+T;g=M,m=D;let L=c,W=h;for(;;){const z=F(this,Zn,F6).call(this,s,t,L,W,g,m,1);P=u(this,Us)[2*z],T=u(this,Us)[2*z+1];const V=L+P,X=W+T;y.push(X,V);const U=L*t+W;if(s[U+1]===0?s[U]=-a:s[U]===1&&(s[U]=a),V===c&&X===h&&L===M&&W===D){s[d]!==1&&(o=Math.abs(s[d]));break}else g=L,m=W,L=V,W=X}}}return l},by=function(n,t,e,r){if(e-t<=4){for(let M=t;M<e-2;M+=2)r.push(n[M],n[M+1]);return}const i=n[t],s=n[t+1],a=n[e-4]-i,o=n[e-3]-s,l=Math.hypot(a,o),c=a/l,h=o/l,d=c*s-h*i,p=o/a,g=1/l,m=Math.atan(p),y=Math.cos(m),v=Math.sin(m),b=g*(Math.abs(y)+Math.abs(v)),S=g*(1-b+b**2),k=Math.max(Math.atan(Math.abs(v+y)*S),Math.atan(Math.abs(v-y)*S));let P=0,T=t;for(let M=t+2;M<e-2;M+=2){const D=Math.abs(d-c*n[M+1]+h*n[M]);D>P&&(T=M,P=D)}P>(l*k)**2?(F(this,Zn,by).call(this,n,t,T+2,r),F(this,Zn,by).call(this,n,T,e,r)):r.push(i,s)},TF=function(n){const t=[],e=n.length;return F(this,Zn,by).call(this,n,0,e,t),t.push(n[e-2],n[e-1]),t.length<=4?null:t},MF=function(n,t,e,r,i,s){const a=new Float32Array(s**2),o=-2*r**2,l=s>>1;for(let m=0;m<s;m++){const y=(m-l)**2;for(let v=0;v<s;v++)a[m*s+v]=Math.exp((y+(v-l)**2)/o)}const c=new Float32Array(256),h=-2*i**2;for(let m=0;m<256;m++)c[m]=Math.exp(m**2/h);const d=n.length,p=new Uint8Array(d),g=new Uint32Array(256);for(let m=0;m<e;m++)for(let y=0;y<t;y++){const v=m*t+y,b=n[v];let S=0,k=0;for(let T=0;T<s;T++){const M=m+T-l;if(!(M<0||M>=e))for(let D=0;D<s;D++){const L=y+D-l;if(L<0||L>=t)continue;const W=n[M*t+L],z=a[T*s+D]*c[Math.abs(W-b)];S+=W*z,k+=z}}const P=p[v]=Math.round(S/k);g[P]++}return[p,g]},PF=function(n){const t=new Uint32Array(256);for(const e of n)t[e]++;return t},fA=function(n){const t=n.length,e=new Uint8ClampedArray(t>>2);let r=-1/0,i=1/0;for(let a=0,o=e.length;a<o;a++){const l=e[a]=n[a<<2];r=Math.max(r,l),i=Math.min(i,l)}const s=255/(r-i);for(let a=0,o=e.length;a<o;a++)e[a]=(e[a]-i)*s;return e},pA=function(n){let t,e=-1/0,r=-1/0;const i=n.findIndex(o=>o!==0);let s=i,a=i;for(t=i;t<256;t++){const o=n[t];o>e&&(t-s>r&&(r=t-s,a=t-1),e=o,s=t)}for(t=a-1;t>=0&&!(n[t]>n[t+1]);t--);return t},FF=function(n){const t=n,{width:e,height:r}=n,{maxDim:i}=u(this,zd);let s=e,a=r;if(e>i||r>i){let c=e,h=r,d=Math.log2(Math.max(e,r)/i);const p=Math.floor(d);d=d===p?p-1:p;for(let m=0;m<d;m++){s=Math.ceil(c/2),a=Math.ceil(h/2);const y=new OffscreenCanvas(s,a);y.getContext("2d").drawImage(n,0,0,c,h,0,0,s,a),c=s,h=a,n!==t&&n.close(),n=y.transferToImageBitmap()}const g=Math.min(i/s,i/a);s=Math.round(s*g),a=Math.round(a*g)}const o=new OffscreenCanvas(s,a).getContext("2d",{willReadFrequently:!0});o.fillStyle="white",o.fillRect(0,0,s,a),o.filter="grayscale(1)",o.drawImage(n,0,0,n.width,n.height,0,0,s,a);const l=o.getImageData(0,0,s,a).data;return[F(this,Zn,fA).call(this,l),s,a]},C(fa,Zn),C(fa,zd,{maxDim:512,sigmaSFactor:.02,sigmaR:25,kernelSize:16}),C(fa,Us,new Int32Array([0,1,-1,1,-1,0,-1,-1,0,-1,1,-1,1,0,1,1]));class e5 extends bF{constructor(){super(),super.updateProperties({fill:on._defaultLineColor,"stroke-width":0})}clone(){const t=new e5;return t.updateAll(this),t}}class n5 extends Ob{constructor(t){super(t),super.updateProperties({stroke:on._defaultLineColor,"stroke-width":1})}clone(){const t=new n5(this._viewParameters);return t.updateAll(this),t}}var Lc,za,Wc,qu;const e0=class Ua extends wF{constructor(t){super({...t,mustBeCommitted:!0,name:"signatureEditor"}),C(this,Lc,!1),C(this,za,null),C(this,Wc,null),C(this,qu,null),this._willKeepAspectRatio=!0,w(this,Wc,t.signatureData||null),w(this,za,null),this.defaultL10nId="pdfjs-editor-signature-editor1"}static initialize(t,e){on.initialize(t,e),this._defaultDrawingOptions=new e5,this._defaultDrawnSignatureOptions=new n5(e.viewParameters)}static getDefaultDrawingOptions(t){const e=this._defaultDrawingOptions.clone();return e.updateProperties(t),e}static get supportMultipleDrawings(){return!1}static get typesMap(){return se(this,"typesMap",new Map)}static get isDrawer(){return!1}get telemetryFinalData(){return{type:"signature",hasDescription:!!u(this,za)}}static computeTelemetryFinalData(t){const e=t.get("hasDescription");return{hasAltText:e.get(!0)??0,hasNoAltText:e.get(!1)??0}}get isResizable(){return!0}onScaleChanging(){this._drawId!==null&&super.onScaleChanging()}render(){if(this.div)return this.div;let t,e;const{_isCopy:r}=this;if(r&&(this._isCopy=!1,t=this.x,e=this.y),super.render(),this._drawId===null)if(u(this,Wc)){const{lines:i,mustSmooth:s,areContours:a,description:o,uuid:l,heightInPage:c}=u(this,Wc),{rawDims:{pageWidth:h,pageHeight:d},rotation:p}=this.parent.viewport,g=fa.processDrawnLines({lines:i,pageWidth:h,pageHeight:d,rotation:p,innerMargin:Ua._INNER_MARGIN,mustSmooth:s,areContours:a});this.addSignature(g,c,o,l)}else this.div.setAttribute("data-l10n-args",JSON.stringify({description:""})),this.div.hidden=!0,this._uiManager.getSignature(this);else this.div.setAttribute("data-l10n-args",JSON.stringify({description:u(this,za)||""}));return r&&(this._isCopy=!0,this._moveAfterPaste(t,e)),this.div}setUuid(t){w(this,qu,t),this.addEditToolbar()}getUuid(){return u(this,qu)}get description(){return u(this,za)}set description(t){w(this,za,t),this.div&&(this.div.setAttribute("data-l10n-args",JSON.stringify({description:t})),super.addEditToolbar().then(e=>{e==null||e.updateEditSignatureButton(t)}))}getSignaturePreview(){const{newCurves:t,areContours:e,thickness:r,width:i,height:s}=u(this,Wc),a=Math.max(i,s),o=fa.processDrawnLines({lines:{curves:t.map(l=>({points:l})),thickness:r,width:i,height:s},pageWidth:a,pageHeight:a,rotation:0,innerMargin:0,mustSmooth:!1,areContours:e});return{areContours:e,outline:o.outline}}get toolbarButtons(){return this._uiManager.signatureManager?[["editSignature",this._uiManager.signatureManager]]:super.toolbarButtons}addSignature(t,e,r,i){const{x:s,y:a}=this,{outline:o}=w(this,Wc,t);w(this,Lc,o instanceof uA),this.description=r;let l;u(this,Lc)?l=Ua.getDefaultDrawingOptions():(l=Ua._defaultDrawnSignatureOptions.clone(),l.updateProperties({"stroke-width":o.thickness})),this._addOutlines({drawOutlines:o,drawingOptions:l});const[,c]=this.pageDimensions;let h=e/c;h=h>=1?.5:h,this.width*=h/this.height,this.width>=1&&(h*=.9/this.width,this.width=.9),this.height=h,this.setDims(),this.x=s,this.y=a,this.center(),this._onResized(),this.onScaleChanging(),this.rotate(),this._uiManager.addToAnnotationStorage(this),this.setUuid(i),this._reportTelemetry({action:"pdfjs.signature.inserted",data:{hasBeenSaved:!!i,hasDescription:!!r}}),this.div.hidden=!1}getFromImage(t){const{rawDims:{pageWidth:e,pageHeight:r},rotation:i}=this.parent.viewport;return fa.process(t,e,r,i,Ua._INNER_MARGIN)}getFromText(t,e){const{rawDims:{pageWidth:r,pageHeight:i},rotation:s}=this.parent.viewport;return fa.extractContoursFromText(t,e,r,i,s,Ua._INNER_MARGIN)}getDrawnSignature(t){const{rawDims:{pageWidth:e,pageHeight:r},rotation:i}=this.parent.viewport;return fa.processDrawnLines({lines:t,pageWidth:e,pageHeight:r,rotation:i,innerMargin:Ua._INNER_MARGIN,mustSmooth:!1,areContours:!1})}createDrawingOptions({areContours:t,thickness:e}){t?this._drawingOptions=Ua.getDefaultDrawingOptions():(this._drawingOptions=Ua._defaultDrawnSignatureOptions.clone(),this._drawingOptions.updateProperties({"stroke-width":e}))}serialize(t=!1){if(this.isEmpty())return null;const{lines:e,points:r}=this.serializeDraw(t),{_drawingOptions:{"stroke-width":i}}=this,s=Object.assign(super.serialize(t),{isSignature:!0,areContours:u(this,Lc),color:[0,0,0],thickness:u(this,Lc)?0:i});return this.addComment(s),t?(s.paths={lines:e,points:r},s.uuid=u(this,qu),s.isCopy=!0):s.lines=e,u(this,za)&&(s.accessibilityData={type:"Figure",alt:u(this,za)}),s}static deserializeDraw(t,e,r,i,s,a){return a.areContours?uA.deserialize(t,e,r,i,s,a):Fm.deserialize(t,e,r,i,s,a)}static async deserialize(t,e,r){var i;const s=await super.deserialize(t,e,r);return w(s,Lc,t.areContours),s.description=((i=t.accessibilityData)==null?void 0:i.alt)||"",w(s,qu,t.uuid),s}};Lc=new WeakMap,za=new WeakMap,Wc=new WeakMap,qu=new WeakMap,J(e0,"_type","signature"),J(e0,"_editorType",te.SIGNATURE),J(e0,"_defaultDrawingOptions",null);let D_=e0;var fn,fr,eh,Sl,gh,Yp,kl,Hu,Va,Qi,qg,tn,Pf,Ff,n0,Cv,Tv,gA,r0,EF;class mA extends on{constructor(t){super({...t,name:"stampEditor"}),C(this,tn),C(this,fn,null),C(this,fr,null),C(this,eh,null),C(this,Sl,null),C(this,gh,null),C(this,Yp,""),C(this,kl,null),C(this,Hu,!1),C(this,Va,null),C(this,Qi,!1),C(this,qg,!1),w(this,Sl,t.bitmapUrl),w(this,gh,t.bitmapFile),this.defaultL10nId="pdfjs-editor-stamp-editor"}static initialize(t,e){on.initialize(t,e)}static isHandlingMimeForPasting(t){return Sb.includes(t)}static paste(t,e){e.pasteEditor({mode:te.STAMP},{bitmapFile:t.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){var t;return{type:"stamp",hasAltText:!!((t=this.altTextData)!=null&&t.altText)}}static computeTelemetryFinalData(t){const e=t.get("hasAltText");return{hasAltText:e.get(!0)??0,hasNoAltText:e.get(!1)??0}}async mlGuessAltText(t=null,e=!0){if(this.hasAltTextData())return null;const{mlManager:r}=this._uiManager;if(!r)throw new Error("No ML.");if(!await r.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:i,width:s,height:a}=t||this.copyCanvas(null,null,!0).imageData,o=await r.guess({name:"altText",request:{data:i,width:s,height:a,channels:i.length/(s*a)}});if(!o)throw new Error("No response from the AI service.");if(o.error)throw new Error("Error from the AI service.");if(o.cancel)return null;if(!o.output)throw new Error("No valid response from the AI service.");const l=o.output;return await this.setGuessedAltText(l),e&&!this.hasAltTextData()&&(this.altTextData={alt:l,decorative:!1}),l}remove(){var t;u(this,fr)&&(w(this,fn,null),this._uiManager.imageManager.deleteId(u(this,fr)),(t=u(this,kl))==null||t.remove(),w(this,kl,null),u(this,Va)&&(clearTimeout(u(this,Va)),w(this,Va,null))),super.remove()}rebuild(){if(!this.parent){u(this,fr)&&F(this,tn,n0).call(this);return}super.rebuild(),this.div!==null&&(u(this,fr)&&u(this,kl)===null&&F(this,tn,n0).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(t){this._isDraggable=!0,t&&this.div.focus()}isEmpty(){return!(u(this,eh)||u(this,fn)||u(this,Sl)||u(this,gh)||u(this,fr)||u(this,Hu))}get toolbarButtons(){return[["altText",this.createAltText()]]}get isResizable(){return!0}render(){if(this.div)return this.div;let t,e;return this._isCopy&&(t=this.x,e=this.y),super.render(),this.div.hidden=!0,this.createAltText(),u(this,Hu)||(u(this,fn)?F(this,tn,Cv).call(this):F(this,tn,n0).call(this)),this._isCopy&&this._moveAfterPaste(t,e),this._uiManager.addShouldRescale(this),this.div}setCanvas(t,e){const{id:r,bitmap:i}=this._uiManager.imageManager.getFromCanvas(t,e);e.remove(),r&&this._uiManager.imageManager.isValidId(r)&&(w(this,fr,r),i&&w(this,fn,i),w(this,Hu,!1),F(this,tn,Cv).call(this))}_onResized(){this.onScaleChanging()}onScaleChanging(){this.parent&&(u(this,Va)!==null&&clearTimeout(u(this,Va)),w(this,Va,setTimeout(()=>{w(this,Va,null),F(this,tn,gA).call(this)},200)))}copyCanvas(t,e,r=!1){t||(t=224);const{width:i,height:s}=u(this,fn),a=new Ds;let o=u(this,fn),l=i,c=s,h=null;if(e){if(i>e||s>e){const M=Math.min(e/i,e/s);l=Math.floor(i*M),c=Math.floor(s*M)}h=document.createElement("canvas");const p=h.width=Math.ceil(l*a.sx),g=h.height=Math.ceil(c*a.sy);u(this,Qi)||(o=F(this,tn,Tv).call(this,p,g));const m=h.getContext("2d");m.filter=this._uiManager.hcmFilter;let y="white",v="#cfcfd8";this._uiManager.hcmFilter!=="none"?v="black":WX.isDarkMode&&(y="#8f8f9d",v="#42414d");const b=15,S=b*a.sx,k=b*a.sy,P=new OffscreenCanvas(S*2,k*2),T=P.getContext("2d");T.fillStyle=y,T.fillRect(0,0,S*2,k*2),T.fillStyle=v,T.fillRect(0,0,S,k),T.fillRect(S,k,S,k),m.fillStyle=m.createPattern(P,"repeat"),m.fillRect(0,0,p,g),m.drawImage(o,0,0,o.width,o.height,0,0,p,g)}let d=null;if(r){let p,g;if(a.symmetric&&o.width<t&&o.height<t)p=o.width,g=o.height;else if(o=u(this,fn),i>t||s>t){const y=Math.min(t/i,t/s);p=Math.floor(i*y),g=Math.floor(s*y),u(this,Qi)||(o=F(this,tn,Tv).call(this,p,g))}const m=new OffscreenCanvas(p,g).getContext("2d",{willReadFrequently:!0});m.drawImage(o,0,0,o.width,o.height,0,0,p,g),d={width:p,height:g,data:m.getImageData(0,0,p,g).data}}return{canvas:h,width:l,height:c,imageData:d}}static async deserialize(t,e,r){var i;let s=null,a=!1;if(t instanceof HP){const{data:{rect:v,rotation:b,id:S,structParent:k,popupRef:P,richText:T,contentsObj:M,creationDate:D,modificationDate:L},container:W,parent:{page:{pageNumber:z}},canvas:V}=t;let X,U;V?(delete t.canvas,{id:X,bitmap:U}=r.imageManager.getFromCanvas(W.id,V),V.remove()):(a=!0,t._hasNoCanvas=!0);const K=((i=await e._structTree.getAriaAttributes(`${Td}${S}`))==null?void 0:i.get("aria-label"))||"";s=t={annotationType:te.STAMP,bitmapId:X,bitmap:U,pageIndex:z-1,rect:v.slice(0),rotation:b,annotationElementId:S,id:S,deleted:!1,accessibilityData:{decorative:!1,altText:K},isSvg:!1,structParent:k,popupRef:P,richText:T,comment:(M==null?void 0:M.str)||null,creationDate:D,modificationDate:L}}const o=await super.deserialize(t,e,r),{rect:l,bitmap:c,bitmapUrl:h,bitmapId:d,isSvg:p,accessibilityData:g}=t;a?(r.addMissingCanvas(t.id,o),w(o,Hu,!0)):d&&r.imageManager.isValidId(d)?(w(o,fr,d),c&&w(o,fn,c)):w(o,Sl,h),w(o,Qi,p);const[m,y]=o.pageDimensions;return o.width=(l[2]-l[0])/m,o.height=(l[3]-l[1])/y,g&&(o.altTextData=g),o._initialData=s,t.comment&&o.setCommentData(t),w(o,qg,!!s),o}serialize(t=!1,e=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const r=Object.assign(super.serialize(t),{bitmapId:u(this,fr),isSvg:u(this,Qi)});if(this.addComment(r),t)return r.bitmapUrl=F(this,tn,r0).call(this,!0),r.accessibilityData=this.serializeAltText(!0),r.isCopy=!0,r;const{decorative:i,altText:s}=this.serializeAltText(!1);if(!i&&s&&(r.accessibilityData={type:"Figure",alt:s}),this.annotationElementId){const o=F(this,tn,EF).call(this,r);return o.isSame?null:(o.isSameAltText?delete r.accessibilityData:r.accessibilityData.structParent=this._initialData.structParent??-1,r.id=this.annotationElementId,delete r.bitmapId,r)}if(e===null)return r;e.stamps||(e.stamps=new Map);const a=u(this,Qi)?(r.rect[2]-r.rect[0])*(r.rect[3]-r.rect[1]):null;if(!e.stamps.has(u(this,fr)))e.stamps.set(u(this,fr),{area:a,serialized:r}),r.bitmap=F(this,tn,r0).call(this,!1);else if(u(this,Qi)){const o=e.stamps.get(u(this,fr));a>o.area&&(o.area=a,o.serialized.bitmap.close(),o.serialized.bitmap=F(this,tn,r0).call(this,!1))}return r}renderAnnotationElement(t){return this.deleted?(t.hide(),null):(t.updateEdited({rect:this.getPDFRect(),popup:this.comment}),null)}}fn=new WeakMap,fr=new WeakMap,eh=new WeakMap,Sl=new WeakMap,gh=new WeakMap,Yp=new WeakMap,kl=new WeakMap,Hu=new WeakMap,Va=new WeakMap,Qi=new WeakMap,qg=new WeakMap,tn=new WeakSet,Pf=function(n,t=!1){if(!n){this.remove();return}w(this,fn,n.bitmap),t||(w(this,fr,n.id),w(this,Qi,n.isSvg)),n.file&&w(this,Yp,n.file.name),F(this,tn,Cv).call(this)},Ff=function(){if(w(this,eh,null),this._uiManager.enableWaiting(!1),!!u(this,kl)){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&u(this,fn)){this.addEditToolbar().then(()=>{this._editToolbar.hide(),this._uiManager.editAltText(this,!0)});return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&u(this,fn)){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}},n0=function(){if(u(this,fr)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(u(this,fr)).then(e=>F(this,tn,Pf).call(this,e,!0)).finally(()=>F(this,tn,Ff).call(this));return}if(u(this,Sl)){const e=u(this,Sl);w(this,Sl,null),this._uiManager.enableWaiting(!0),w(this,eh,this._uiManager.imageManager.getFromUrl(e).then(r=>F(this,tn,Pf).call(this,r)).finally(()=>F(this,tn,Ff).call(this)));return}if(u(this,gh)){const e=u(this,gh);w(this,gh,null),this._uiManager.enableWaiting(!0),w(this,eh,this._uiManager.imageManager.getFromFile(e).then(r=>F(this,tn,Pf).call(this,r)).finally(()=>F(this,tn,Ff).call(this)));return}const n=document.createElement("input");n.type="file",n.accept=Sb.join(",");const t=this._uiManager._signal;w(this,eh,new Promise(e=>{n.addEventListener("change",async()=>{if(!n.files||n.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const r=await this._uiManager.imageManager.getFromFile(n.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),F(this,tn,Pf).call(this,r)}e()},{signal:t}),n.addEventListener("cancel",()=>{this.remove(),e()},{signal:t})}).finally(()=>F(this,tn,Ff).call(this))),n.click()},Cv=function(){var n;const{div:t}=this;let{width:e,height:r}=u(this,fn);const[i,s]=this.pageDimensions,a=.75;if(this.width)e=this.width*i,r=this.height*s;else if(e>a*i||r>a*s){const l=Math.min(a*i/e,a*s/r);e*=l,r*=l}this._uiManager.enableWaiting(!1);const o=w(this,kl,document.createElement("canvas"));o.setAttribute("role","img"),this.addContainer(o),this.width=e/i,this.height=r/s,this.setDims(),(n=this._initialOptions)!=null&&n.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(t.hidden=!1),F(this,tn,gA).call(this),u(this,qg)||(this.parent.addUndoableEditor(this),w(this,qg,!0)),this._reportTelemetry({action:"inserted_image"}),u(this,Yp)&&this.div.setAttribute("aria-description",u(this,Yp)),this.annotationElementId||this._uiManager.a11yAlert("pdfjs-editor-stamp-added-alert")},Tv=function(n,t){const{width:e,height:r}=u(this,fn);let i=e,s=r,a=u(this,fn);for(;i>2*n||s>2*t;){const o=i,l=s;i>2*n&&(i=Math.ceil(i/2)),s>2*t&&(s=Math.ceil(s/2));const c=new OffscreenCanvas(i,s);c.getContext("2d").drawImage(a,0,0,o,l,0,0,i,s),a=c.transferToImageBitmap()}return a},gA=function(){const[n,t]=this.parentDimensions,{width:e,height:r}=this,i=new Ds,s=Math.ceil(e*n*i.sx),a=Math.ceil(r*t*i.sy),o=u(this,kl);if(!o||o.width===s&&o.height===a)return;o.width=s,o.height=a;const l=u(this,Qi)?u(this,fn):F(this,tn,Tv).call(this,s,a),c=o.getContext("2d");c.filter=this._uiManager.hcmFilter,c.drawImage(l,0,0,l.width,l.height,0,0,s,a)},r0=function(n){if(n){if(u(this,Qi)){const e=this._uiManager.imageManager.getSvgUrl(u(this,fr));if(e)return e}const t=document.createElement("canvas");return{width:t.width,height:t.height}=u(this,fn),t.getContext("2d").drawImage(u(this,fn),0,0),t.toDataURL()}if(u(this,Qi)){const[t,e]=this.pageDimensions,r=Math.round(this.width*t*Ah.PDF_TO_CSS_UNITS),i=Math.round(this.height*e*Ah.PDF_TO_CSS_UNITS),s=new OffscreenCanvas(r,i);return s.getContext("2d").drawImage(u(this,fn),0,0,u(this,fn).width,u(this,fn).height,0,0,r,i),s.transferToImageBitmap()}return structuredClone(u(this,fn))},EF=function(n){var t;const{pageIndex:e,accessibilityData:{altText:r}}=this._initialData,i=n.pageIndex===e,s=(((t=n.accessibilityData)==null?void 0:t.alt)||"")===r;return{isSame:!this.hasEditedComment&&!this._hasBeenMoved&&!this._hasBeenResized&&i&&s,isSameAltText:s}},J(mA,"_type","stamp"),J(mA,"_editorType",te.STAMP);var Xu,Zp,jc,zc,_o,pi,Uc,Jp,Qp,Xs,Yo,gr,Zo,Vc,$p,Bt,mh,kn,yA,IF,Zs,vA,bA,i0;const s0=class Gc{constructor({uiManager:t,pageIndex:e,div:r,structTreeLayer:i,accessibilityManager:s,annotationLayer:a,drawLayer:o,textLayer:l,viewport:c,l10n:h}){C(this,kn),C(this,Xu),C(this,Zp,!1),C(this,jc,null),C(this,zc,null),C(this,_o,null),C(this,pi,new Map),C(this,Uc,!1),C(this,Jp,!1),C(this,Qp,!1),C(this,Xs,null),C(this,Yo,null),C(this,gr,null),C(this,Zo,null),C(this,Vc,null),C(this,$p,-1),C(this,Bt);const d=[...u(Gc,mh).values()];if(!Gc._initialized){Gc._initialized=!0;for(const p of d)p.initialize(h,t)}t.registerEditorTypes(d),w(this,Bt,t),this.pageIndex=e,this.div=r,w(this,Xu,s),w(this,jc,a),this.viewport=c,w(this,gr,l),this.drawLayer=o,this._structTree=i,u(this,Bt).addLayer(this)}get isEmpty(){return u(this,pi).size===0}get isInvisible(){return this.isEmpty&&u(this,Bt).getMode()===te.NONE}updateToolbar(t){u(this,Bt).updateToolbar(t)}updateMode(t=u(this,Bt).getMode()){switch(F(this,kn,i0).call(this),t){case te.NONE:this.div.classList.toggle("nonEditing",!0),this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case te.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case te.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;if(e.toggle("nonEditing",!1),t===te.POPUP)e.toggle("commentEditing",!0);else{e.toggle("commentEditing",!1);for(const r of u(Gc,mh).values())e.toggle(`${r._type}Editing`,t===r._editorType)}this.div.hidden=!1}hasTextLayer(t){var e;return t===((e=u(this,gr))==null?void 0:e.div)}setEditingState(t){u(this,Bt).setEditingState(t)}addCommands(t){u(this,Bt).addCommands(t)}cleanUndoStack(t){u(this,Bt).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=u(this,jc))==null||e.togglePointerEvents(t)}async enable(){var t;w(this,Qp,!0),this.div.tabIndex=0,this.togglePointerEvents(!0),this.div.classList.toggle("nonEditing",!1),(t=u(this,Vc))==null||t.abort(),w(this,Vc,null);const e=new Set;for(const i of u(this,kn,yA))i.enableEditing(),i.show(!0),i.annotationElementId&&(u(this,Bt).removeChangedExistingAnnotation(i),e.add(i.annotationElementId));const r=u(this,jc);if(r)for(const i of r.getEditableAnnotations()){if(i.hide(),u(this,Bt).isDeletedAnnotationElement(i.data.id)||e.has(i.data.id))continue;const s=await this.deserialize(i);s&&(this.addOrRebuild(s),s.enableEditing())}w(this,Qp,!1),u(this,Bt)._eventBus.dispatch("editorsrendered",{source:this,pageNumber:this.pageIndex+1})}disable(){var t;if(w(this,Jp,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1),this.div.classList.toggle("nonEditing",!0),u(this,gr)&&!u(this,Vc)){w(this,Vc,new AbortController);const s=u(this,Bt).combinedSignal(u(this,Vc));u(this,gr).div.addEventListener("pointerdown",a=>{const{clientX:o,clientY:l,timeStamp:c}=a,h=u(this,$p);if(c-h>500){w(this,$p,c);return}w(this,$p,-1);const{classList:d}=this.div;d.toggle("getElements",!0);const p=document.elementsFromPoint(o,l);if(d.toggle("getElements",!1),!this.div.contains(p[0]))return;let g;const m=new RegExp(`^${sm}[0-9]+$`);for(const v of p)if(m.test(v.id)){g=v.id;break}if(!g)return;const y=u(this,pi).get(g);(y==null?void 0:y.annotationElementId)===null&&(an(a),y.dblclick(a))},{signal:s,capture:!0})}const e=u(this,jc),r=[];if(e){const s=new Map,a=new Map;for(const o of u(this,kn,yA)){if(o.disableEditing(),!o.annotationElementId){r.push(o);continue}if(o.serialize()!==null){s.set(o.annotationElementId,o);continue}else a.set(o.annotationElementId,o);(t=this.getEditableAnnotation(o.annotationElementId))==null||t.show(),o.remove()}for(const o of e.getEditableAnnotations()){const{id:l}=o.data;if(u(this,Bt).isDeletedAnnotationElement(l)){o.updateEdited({deleted:!0});continue}let c=a.get(l);if(c){c.resetAnnotationElement(o),c.show(!1),o.show();continue}c=s.get(l),c&&(u(this,Bt).addChangedExistingAnnotation(c),c.renderAnnotationElement(o)&&c.show(!1)),o.show()}}F(this,kn,i0).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:i}=this.div;for(const s of u(Gc,mh).values())i.remove(`${s._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),e==null||e.updateFakeAnnotations(r),w(this,Jp,!1)}getEditableAnnotation(t){var e;return((e=u(this,jc))==null?void 0:e.getEditableAnnotation(t))||null}setActiveEditor(t){u(this,Bt).getActive()!==t&&u(this,Bt).setActiveEditor(t)}enableTextSelection(){var t;if(this.div.tabIndex=-1,(t=u(this,gr))!=null&&t.div&&!u(this,Zo)){w(this,Zo,new AbortController);const e=u(this,Bt).combinedSignal(u(this,Zo));u(this,gr).div.addEventListener("pointerdown",F(this,kn,IF).bind(this),{signal:e}),u(this,gr).div.classList.add("highlighting")}}disableTextSelection(){var t;this.div.tabIndex=0,(t=u(this,gr))!=null&&t.div&&u(this,Zo)&&(u(this,Zo).abort(),w(this,Zo,null),u(this,gr).div.classList.remove("highlighting"))}enableClick(){if(u(this,zc))return;w(this,zc,new AbortController);const t=u(this,Bt).combinedSignal(u(this,zc));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=u(this,zc))==null||t.abort(),w(this,zc,null)}attach(t){u(this,pi).set(t.id,t);const{annotationElementId:e}=t;e&&u(this,Bt).isDeletedAnnotationElement(e)&&u(this,Bt).removeDeletedAnnotationElement(t)}detach(t){var e;u(this,pi).delete(t.id),(e=u(this,Xu))==null||e.removePointerInTextLayer(t.contentDiv),!u(this,Jp)&&t.annotationElementId&&u(this,Bt).addDeletedAnnotationElement(t)}remove(t){this.detach(t),u(this,Bt).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){var e;t.parent!==this&&(t.parent&&t.annotationElementId&&(u(this,Bt).addDeletedAnnotationElement(t),on.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),u(this,Bt).addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!u(this,Qp)),u(this,Bt).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var e;if(!t.isAttachedToDOM)return;const{activeElement:r}=document;t.div.contains(r)&&!u(this,_o)&&(t._focusEventsAllowed=!1,w(this,_o,setTimeout(()=>{w(this,_o,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:u(this,Bt)._signal}),r.focus())},0))),t._structTreeParentId=(e=u(this,Xu))==null?void 0:e.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),r=()=>{t.remove()};this.addCommands({cmd:e,undo:r,mustExec:!1})}getEditorByUID(t){for(const e of u(this,pi).values())if(e.uid===t)return e;return null}combinedSignal(t){return u(this,Bt).combinedSignal(t)}canCreateNewEmptyEditor(){var t;return(t=u(this,kn,Zs))==null?void 0:t.canCreateNewEmptyEditor()}async pasteEditor(t,e){this.updateToolbar(t),await u(this,Bt).updateMode(t.mode);const{offsetX:r,offsetY:i}=F(this,kn,bA).call(this),s=u(this,Bt).getId(),a=F(this,kn,vA).call(this,{parent:this,id:s,x:r,y:i,uiManager:u(this,Bt),isCentered:!0,...e});a&&this.add(a)}async deserialize(t){var e;return await((e=u(Gc,mh).get(t.annotationType??t.annotationEditorType))==null?void 0:e.deserialize(t,this,u(this,Bt)))||null}createAndAddNewEditor(t,e,r={}){const i=u(this,Bt).getId(),s=F(this,kn,vA).call(this,{parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:u(this,Bt),isCentered:e,...r});return s&&this.add(s),s}get boundingClientRect(){return this.div.getBoundingClientRect()}addNewEditor(t={}){this.createAndAddNewEditor(F(this,kn,bA).call(this),!0,t)}setSelected(t){u(this,Bt).setSelected(t)}toggleSelected(t){u(this,Bt).toggleSelected(t)}unselect(t){u(this,Bt).unselect(t)}pointerup(t){var e;const{isMac:r}=In.platform;if(t.button!==0||t.ctrlKey&&r||t.target!==this.div||!u(this,Uc)||(w(this,Uc,!1),(e=u(this,kn,Zs))!=null&&e.isDrawer&&u(this,kn,Zs).supportMultipleDrawings))return;if(!u(this,Zp)){w(this,Zp,!0);return}const i=u(this,Bt).getMode();if(i===te.STAMP||i===te.POPUP||i===te.SIGNATURE){u(this,Bt).unselectAll();return}this.createAndAddNewEditor(t,!1)}pointerdown(t){var e;if(u(this,Bt).getMode()===te.HIGHLIGHT&&this.enableTextSelection(),u(this,Uc)){w(this,Uc,!1);return}const{isMac:r}=In.platform;if(t.button!==0||t.ctrlKey&&r||t.target!==this.div)return;if(w(this,Uc,!0),(e=u(this,kn,Zs))!=null&&e.isDrawer){this.startDrawingSession(t);return}const i=u(this,Bt).getActive();w(this,Zp,!i||i.isEmpty())}startDrawingSession(t){if(this.div.focus({preventScroll:!0}),u(this,Xs)){u(this,kn,Zs).startDrawing(this,u(this,Bt),!1,t);return}u(this,Bt).setCurrentDrawingSession(this),w(this,Xs,new AbortController);const e=u(this,Bt).combinedSignal(u(this,Xs));this.div.addEventListener("blur",({relatedTarget:r})=>{r&&!this.div.contains(r)&&(w(this,Yo,null),this.commitOrRemove())},{signal:e}),u(this,kn,Zs).startDrawing(this,u(this,Bt),!1,t)}pause(t){if(t){const{activeElement:e}=document;this.div.contains(e)&&w(this,Yo,e);return}u(this,Yo)&&setTimeout(()=>{var e;(e=u(this,Yo))==null||e.focus(),w(this,Yo,null)},0)}endDrawingSession(t=!1){return u(this,Xs)?(u(this,Bt).setCurrentDrawingSession(null),u(this,Xs).abort(),w(this,Xs,null),w(this,Yo,null),u(this,kn,Zs).endDrawing(t)):null}findNewParent(t,e,r){const i=u(this,Bt).findParent(e,r);return i===null||i===this?!1:(i.changeParent(t),!0)}commitOrRemove(){return u(this,Xs)?(this.endDrawingSession(),!0):!1}onScaleChanging(){u(this,Xs)&&u(this,kn,Zs).onScaleChangingWhenDrawing(this)}destroy(){var t,e;this.commitOrRemove(),((t=u(this,Bt).getActive())==null?void 0:t.parent)===this&&(u(this,Bt).commitOrRemove(),u(this,Bt).setActiveEditor(null)),u(this,_o)&&(clearTimeout(u(this,_o)),w(this,_o,null));for(const r of u(this,pi).values())(e=u(this,Xu))==null||e.removePointerInTextLayer(r.contentDiv),r.setParent(null),r.isAttachedToDOM=!1,r.div.remove();this.div=null,u(this,pi).clear(),u(this,Bt).removeLayer(this)}async render({viewport:t}){this.viewport=t,jl(this.div,t);for(const e of u(this,Bt).getEditors(this.pageIndex))this.add(e),e.rebuild();await u(this,Bt).findClonesForPage(this),this.div.hidden=this.isEmpty,this.updateMode()}update({viewport:t}){u(this,Bt).commitOrRemove(),F(this,kn,i0).call(this);const e=this.viewport.rotation,r=t.rotation;if(this.viewport=t,jl(this.div,{rotation:r}),e!==r)for(const i of u(this,pi).values())i.rotate(r)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return u(this,Bt).viewParameters.realScale}};Xu=new WeakMap,Zp=new WeakMap,jc=new WeakMap,zc=new WeakMap,_o=new WeakMap,pi=new WeakMap,Uc=new WeakMap,Jp=new WeakMap,Qp=new WeakMap,Xs=new WeakMap,Yo=new WeakMap,gr=new WeakMap,Zo=new WeakMap,Vc=new WeakMap,$p=new WeakMap,Bt=new WeakMap,mh=new WeakMap,kn=new WeakSet,yA=function(){return u(this,pi).size!==0?u(this,pi).values():u(this,Bt).getEditors(this.pageIndex)},IF=function(n){u(this,Bt).unselectAll();const{target:t}=n;if(t===u(this,gr).div||(t.getAttribute("role")==="img"||t.classList.contains("endOfContent")||t.classList.contains("textLayerImagePlaceholder"))&&u(this,gr).div.contains(t)){const{isMac:e}=In.platform;if(n.button!==0||n.ctrlKey&&e)return;u(this,Bt).showAllEditors("highlight",!0,!0),u(this,gr).div.classList.add("free"),this.toggleDrawing(),T6.startHighlighting(this,u(this,Bt).direction==="ltr",{target:u(this,gr).div,x:n.x,y:n.y}),u(this,gr).div.addEventListener("pointerup",()=>{u(this,gr).div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:u(this,Bt)._signal}),n.preventDefault()}},Zs=function(){return u(s0,mh).get(u(this,Bt).getMode())},vA=function(n){const t=u(this,kn,Zs);return t?new t.prototype.constructor(n):null},bA=function(){const{x:n,y:t,width:e,height:r}=this.boundingClientRect,i=Math.max(0,n),s=Math.max(0,t),a=Math.min(window.innerWidth,n+e),o=Math.min(window.innerHeight,t+r),l=(i+a)/2-n,c=(s+o)/2-t,[h,d]=this.viewport.rotation%180===0?[l,c]:[c,l];return{offsetX:h,offsetY:d}},i0=function(){for(const n of u(this,pi).values())n.isEmpty()&&n.remove()},J(s0,"_initialized",!1),C(s0,mh,new Map([P_,O_,mA,T6,D_].map(n=>[n._editorType,n])));let OF=s0;var Js,Jr,Ku,Mv,wA,DF,qc,xA,RF,AA;const _u=class ci{constructor(){C(this,qc),C(this,Js,null),C(this,Jr,new Map),C(this,Ku,new Map)}setParent(t){if(!u(this,Js)){w(this,Js,t);return}if(u(this,Js)!==t){if(u(this,Jr).size>0)for(const e of u(this,Jr).values())e.remove(),t.append(e);w(this,Js,t)}}static get _svgFactory(){return se(this,"_svgFactory",new hm)}draw(t,e=!1,r=!1){const i=Qn(ci,Mv)._++,s=F(this,qc,xA).call(this),a=ci._svgFactory.createElement("defs");s.append(a);const o=ci._svgFactory.createElement("path");a.append(o);const l=`path_${i}`;o.setAttribute("id",l),o.setAttribute("vector-effect","non-scaling-stroke"),e&&u(this,Ku).set(i,o);const c=r?F(this,qc,RF).call(this,a,l):null,h=ci._svgFactory.createElement("use");return s.append(h),h.setAttribute("href",`#${l}`),this.updateProperties(s,t),u(this,Jr).set(i,s),{id:i,clipPathId:`url(#${c})`}}drawOutline(t,e){const r=Qn(ci,Mv)._++,i=F(this,qc,xA).call(this),s=ci._svgFactory.createElement("defs");i.append(s);const a=ci._svgFactory.createElement("path");s.append(a);const o=`path_${r}`;a.setAttribute("id",o),a.setAttribute("vector-effect","non-scaling-stroke");let l;if(e){const d=ci._svgFactory.createElement("mask");s.append(d),l=`mask_${r}`,d.setAttribute("id",l),d.setAttribute("maskUnits","objectBoundingBox");const p=ci._svgFactory.createElement("rect");d.append(p),p.setAttribute("width","1"),p.setAttribute("height","1"),p.setAttribute("fill","white");const g=ci._svgFactory.createElement("use");d.append(g),g.setAttribute("href",`#${o}`),g.setAttribute("stroke","none"),g.setAttribute("fill","black"),g.setAttribute("fill-rule","nonzero"),g.classList.add("mask")}const c=ci._svgFactory.createElement("use");i.append(c),c.setAttribute("href",`#${o}`),l&&c.setAttribute("mask",`url(#${l})`);const h=c.cloneNode();return i.append(h),c.classList.add("mainOutline"),h.classList.add("secondaryOutline"),this.updateProperties(i,t),u(this,Jr).set(r,i),r}finalizeDraw(t,e){u(this,Ku).delete(t),this.updateProperties(t,e)}updateProperties(t,e){var r;if(!e)return;const{root:i,bbox:s,rootClass:a,path:o}=e,l=typeof t=="number"?u(this,Jr).get(t):t;if(l){if(i&&F(this,qc,AA).call(this,l,i),s&&F(r=ci,wA,DF).call(r,l,s),a){const{classList:c}=l;for(const[h,d]of Object.entries(a))c.toggle(h,d)}if(o){const c=l.firstElementChild.firstElementChild;F(this,qc,AA).call(this,c,o)}}}updateParent(t,e){if(e===this)return;const r=u(this,Jr).get(t);r&&(u(e,Js).append(r),u(this,Jr).delete(t),u(e,Jr).set(t,r))}remove(t){u(this,Ku).delete(t),u(this,Js)!==null&&(u(this,Jr).get(t).remove(),u(this,Jr).delete(t))}destroy(){w(this,Js,null);for(const t of u(this,Jr).values())t.remove();u(this,Jr).clear(),u(this,Ku).clear()}};Js=new WeakMap,Jr=new WeakMap,Ku=new WeakMap,Mv=new WeakMap,wA=new WeakSet,DF=function(n,[t,e,r,i]){const{style:s}=n;s.top=`${100*e}%`,s.left=`${100*t}%`,s.width=`${100*r}%`,s.height=`${100*i}%`},qc=new WeakSet,xA=function(){const n=_u._svgFactory.create(1,1,!0);return u(this,Js).append(n),n.setAttribute("aria-hidden",!0),n},RF=function(n,t){const e=_u._svgFactory.createElement("clipPath");n.append(e);const r=`clip_${t}`;e.setAttribute("id",r),e.setAttribute("clipPathUnits","objectBoundingBox");const i=_u._svgFactory.createElement("use");return e.append(i),i.setAttribute("href",`#${t}`),i.classList.add("clip"),r},AA=function(n,t){for(const[e,r]of Object.entries(t))r===null?n.removeAttribute(e):n.setAttribute(e,r)},C(_u,wA),C(_u,Mv,0);let BF=_u;function wy(n){return`${(n*100).toFixed(2)}%`}var tg,Pv,a0,Hg,no,ro,Fv,SA,NF;const LF=class kA{constructor(t,e,r,i){C(this,SA),C(this,tg,[]),C(this,Pv,new Map),C(this,a0,null),C(this,Hg,0),C(this,no,0),C(this,ro,0),w(this,Hg,t),w(this,tg,e),w(this,no,r.rawDims.pageWidth),w(this,ro,r.rawDims.pageHeight),w(this,a0,i)}render(){const t=document.createElement("div");t.className="textLayerImages";for(let e=0;e<u(this,tg).length;e+=6){const r=F(this,SA,NF).call(this,u(this,tg).subarray(e,e+6));r&&t.append(r)}return t.addEventListener("contextmenu",e=>{var r;if(!(e.target instanceof HTMLCanvasElement))return;const i=e.target,s=u(this,Pv).get(i);if(!s)return;const a=(r=u(kA,Fv))==null?void 0:r.deref();if(a===i)return;a&&(a.width=0,a.height=0),w(kA,Fv,new WeakRef(i));const{inverseTransform:o,x1:l,y1:c,width:h,height:d}=s,p=u(this,a0).call(this),g=Math.ceil(l*p.width),m=Math.ceil(c*p.height),y=Math.floor((l+h/u(this,no))*p.width),v=Math.floor((c+d/u(this,ro))*p.height);i.width=y-g,i.height=v-m;const b=i.getContext("2d");b.setTransform(...o),b.translate(-g,-m),b.drawImage(p,0,0)}),t}};tg=new WeakMap,Pv=new WeakMap,a0=new WeakMap,Hg=new WeakMap,no=new WeakMap,ro=new WeakMap,Fv=new WeakMap,SA=new WeakSet,NF=function([n,t,e,r,i,s]){const a=Math.hypot((i-n)*u(this,no),(s-t)*u(this,ro)),o=Math.hypot((e-n)*u(this,no),(r-t)*u(this,ro));if(a<u(this,Hg)||o<u(this,Hg))return null;const l=[(i-n)*u(this,no)/a,(s-t)*u(this,ro)/a,(e-n)*u(this,no)/o,(r-t)*u(this,ro)/o,0,0],c=ft.inverseTransform(l),h=document.createElement("canvas");return h.className="textLayerImagePlaceholder",h.width=0,h.height=0,Object.assign(h.style,{opacity:0,position:"absolute",left:wy(n),top:wy(t),width:wy(a/u(this,no)),height:wy(o/u(this,ro)),transformOrigin:"0% 0%",transform:`matrix(${l.join(",")})`}),u(this,Pv).set(h,{inverseTransform:c,width:a,height:o,x1:n,y1:t}),h},C(LF,Fv,null);let WF=LF;globalThis._pdfjsTestingUtils={HighlightOutliner:iA};globalThis.pdfjsLib={AbortException:vo,AnnotationEditorLayer:OF,AnnotationEditorParamsType:ce,AnnotationEditorType:te,AnnotationEditorUIManager:Yd,AnnotationLayer:KP,AnnotationMode:io,AnnotationType:Cn,applyOpacity:uM,build:DP,ColorPicker:QS,createValidAbsoluteUrl:VS,CSSConstants:hM,DOMSVGFactory:hm,DrawLayer:BF,FeatureTest:In,fetchData:bb,findContrastColor:dM,getDocument:ZS,getFilenameFromUrl:oM,getPdfFilenameFromUrl:lM,getRGB:rf,getRGBA:Ab,getUuid:qS,getXfaPageViewport:cM,GlobalWorkerOptions:wa,ImageKind:ug,InvalidPDFException:N0,isDataScheme:Mm,isPdfFile:xb,isValidExplicitDest:YM,makeArr:yb,makeMap:vb,makeObj:L0,MathClamp:en,noContextMenu:Ti,normalizeUnicode:aM,OPS:aa,OutputScale:Ds,PasswordResponses:sM,PDFDataRangeTransport:JS,PDFDateString:lm,PDFWorker:ov,PermissionFlag:iM,PixelsPerInch:Ah,RenderingCancelledException:wb,renderRichText:XS,ResponseException:am,setLayerDimensions:jl,shadow:se,SignatureExtractor:fa,stopEvent:an,SupportedImageMimeTypes:Sb,TextLayer:sv,TextLayerImages:WF,TouchManager:KS,updateUrlHash:GS,Util:ft,VerbosityLevel:Cm,version:OP,XfaLayer:HS};const R_=Object.freeze(Object.defineProperty({__proto__:null,AbortException:vo,AnnotationEditorLayer:OF,AnnotationEditorParamsType:ce,AnnotationEditorType:te,AnnotationEditorUIManager:Yd,AnnotationLayer:KP,AnnotationMode:io,AnnotationType:Cn,CSSConstants:hM,ColorPicker:QS,DOMSVGFactory:hm,DrawLayer:BF,FeatureTest:In,GlobalWorkerOptions:wa,ImageKind:ug,InvalidPDFException:N0,MathClamp:en,OPS:aa,OutputScale:Ds,PDFDataRangeTransport:JS,PDFDateString:lm,PDFWorker:ov,PasswordResponses:sM,PermissionFlag:iM,PixelsPerInch:Ah,RenderingCancelledException:wb,ResponseException:am,SignatureExtractor:fa,SupportedImageMimeTypes:Sb,TextLayer:sv,TextLayerImages:WF,TouchManager:KS,Util:ft,VerbosityLevel:Cm,XfaLayer:HS,applyOpacity:uM,build:DP,createValidAbsoluteUrl:VS,fetchData:bb,findContrastColor:dM,getDocument:ZS,getFilenameFromUrl:oM,getPdfFilenameFromUrl:lM,getRGB:rf,getRGBA:Ab,getUuid:qS,getXfaPageViewport:cM,isDataScheme:Mm,isPdfFile:xb,isValidExplicitDest:YM,makeArr:yb,makeMap:vb,makeObj:L0,noContextMenu:Ti,normalizeUnicode:aM,renderRichText:XS,setLayerDimensions:jl,shadow:se,stopEvent:an,updateUrlHash:GS,version:OP},Symbol.toStringTag,{value:"Module"}));wa.workerSrc="";const E6=25.4/72,r2=8;class B_{importFromFilePicker(t){const e=document.createElement("input");e.type="file",e.accept=".pdf",e.style.display="none",document.body.appendChild(e),e.addEventListener("change",async()=>{var r;const i=(r=e.files)==null?void 0:r[0];if(document.body.removeChild(e),!i)return;const s=await i.arrayBuffer();await this.convert(t,s)}),e.click()}async convert(t,e,r=1){try{const i=await(await ZS({data:e}).promise).getPage(r),s=i.getViewport({scale:1}).height,a=await i.getOperatorList(),o=this.extractEntities(a,s);if(o.length===0){Bb.warn("[PdfImport] No vector paths found in PDF page.");return}const l=t.doc.database.tables.blockTable.modelSpace;for(const c of o)l.appendEntity(c);Bb.info(`[PdfImport] Imported ${o.length} entities from PDF.`)}catch(i){Bb.error("[PdfImport] Failed to import PDF:",i)}}extractEntities(t,e){const{OPS:r}=R_,{fnArray:i,argsArray:s}=t,a=[];let o=[],l=[],c=0,h=0;const d=()=>{l.length>1&&o.push(l),l=[]},p=()=>{d();for(const y of o){const v=this.subpathToEntity(y);v&&a.push(v)}o=[]},g=(y,v)=>y*E6,m=(y,v)=>(e-v)*E6;for(let y=0;y<i.length;y++){const v=i[y],b=s[y];switch(v){case r.moveTo:{d(),c=b[0],h=b[1],l=[{x:g(c),y:m(c,h)}];break}case r.lineTo:{c=b[0],h=b[1],l.push({x:g(c),y:m(c,h)});break}case r.curveTo:{const[S,k,P,T,M,D]=b,L=i2({x:c,y:h},{x:S,y:k},{x:P,y:T},{x:M,y:D},r2);for(const W of L)l.push({x:g(W.x,W.y),y:m(W.x,W.y)});c=M,h=D;break}case r.curveTo2:{const[S,k,P,T]=b,M=i2({x:c,y:h},{x:c,y:h},{x:S,y:k},{x:P,y:T},r2);for(const D of M)l.push({x:g(D.x,D.y),y:m(D.x,D.y)});c=P,h=T;break}case r.curveTo3:{const[S,k,P,T]=b,M=i2({x:c,y:h},{x:S,y:k},{x:P,y:T},{x:P,y:T},r2);for(const D of M)l.push({x:g(D.x,D.y),y:m(D.x,D.y)});c=P,h=T;break}case r.closePath:{l.length>0&&o.length===0&&l.push({...l[0]}),d();break}case r.stroke:case r.fill:case r.eoFill:case r.fillStroke:case r.eoFillStroke:case r.endPath:{p();break}}}return p(),a}subpathToEntity(t){if(t.length<2)return null;if(t.length===2)return new eE(new Ks(t[0].x,t[0].y,0),new Ks(t[1].x,t[1].y,0));const e=new nE;for(let o=0;o<t.length;o++)e.addVertexAt(o,new s2(t[o].x,t[o].y));const r=t[0],i=t[t.length-1],s=r.x-i.x,a=r.y-i.y;return Math.sqrt(s*s+a*a)<1e-6&&(e.closed=!0),e}}function i2(n,t,e,r,i){const s=[];for(let a=1;a<=i;a++){const o=a/i,l=1-o,c=l*l*l*n.x+3*l*l*o*t.x+3*l*o*o*e.x+o*o*o*r.x,h=l*l*l*n.y+3*l*l*o*t.y+3*l*o*o*e.y+o*o*o*r.y;s.push({x:c,y:h})}return s}class N_ extends R6{async execute(t){new B_().importFromFilePicker(t)}}const L_="1.7.2",W_={version:L_};class j_{constructor(t={}){this.name="PdfPlugin",this.version=W_.version,this.description="PDF export (-cpdf / cpdf) and import (ipdf) commands",this.registeredCommands=[],this._disableExport=t.disableExport===!0}onLoad(t,e){const r=QF.SYSTEMT_COMMAND_GROUP_NAME;if(!this._disableExport){const i=new MX;e.addCommand(r,"-cpdf","-cpdf",i),this.registeredCommands.push({group:r,name:"-cpdf"}),e.lookupGlobalCmd("cpdf")||(e.addCommand(r,"cpdf","cpdf",i),this.registeredCommands.push({group:r,name:"cpdf"}))}e.addCommand(r,"ipdf","ipdf",new N_),this.registeredCommands.push({group:r,name:"ipdf"})}onUnload(t,e){for(const r of this.registeredCommands)e.removeCmd(r.group,r.name);this.registeredCommands=[]}}async function Y_(n={}){return new j_(n)}export{MX as AcApConvertToPdfCmd,N_ as AcApImportPdfCmd,TX as AcApPdfConvertor,B_ as AcApPdfImportConvertor,j_ as AcApPdfPlugin,Q_ as PDF_PLUGIN_NAME,$_ as PDF_PLUGIN_TRIGGERS,Y_ as createPdfPlugin,Nf as resolveAcApPdfExportOptions,SX as resolveViewerTextFont};
212
+ `)){const t=document.createElement("div");t.append(n?document.createTextNode(n):document.createElement("br")),this.editorDiv.append(t)}},JP=function(){return u(this,Ki).replaceAll(" "," ")},$x=function(n){return n.replaceAll(" "," ")},QP=function(n){const{value:t,fontSize:e,color:r,pageIndex:i}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||n.value!==t||n.fontSize!==e||n.color.some((s,a)=>s!==r[a])||n.pageIndex!==i},C(La,ph),J(La,"_freeTextDefaultContent",""),J(La,"_internalPadding",0),J(La,"_defaultColor",null),J(La,"_defaultFontSize",10),J(La,"_type","freetext"),J(La,"_editorType",te.FREETEXT);let P_=La;class Ft{toSVGPath(){Ne("Abstract method `toSVGPath` must be implemented.")}get box(){Ne("Abstract getter `box` must be implemented.")}serialize(t,e){Ne("Abstract method `serialize` must be implemented.")}static _rescale(t,e,r,i,s,a){a||(a=new Float32Array(t.length));for(let o=0,l=t.length;o<l;o+=2)a[o]=e+t[o]*i,a[o+1]=r+t[o+1]*s;return a}static _rescaleAndSwap(t,e,r,i,s,a){a||(a=new Float32Array(t.length));for(let o=0,l=t.length;o<l;o+=2)a[o]=e+t[o+1]*i,a[o+1]=r+t[o]*s;return a}static _translate(t,e,r,i){i||(i=new Float32Array(t.length));for(let s=0,a=t.length;s<a;s+=2)i[s]=e+t[s],i[s+1]=r+t[s+1];return i}static svgRound(t){return Math.round(t*1e4)}static _normalizePoint(t,e,r,i,s){switch(s){case 90:return[1-e/r,t/i];case 180:return[1-t/r,1-e/i];case 270:return[e/r,1-t/i];default:return[t/r,e/i]}}static _normalizePagePoint(t,e,r){switch(r){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,r,i,s,a){return[(t+5*r)/6,(e+5*i)/6,(5*r+s)/6,(5*i+a)/6,(r+s)/2,(i+a)/2]}}J(Ft,"PRECISION",1e-4);var Zi,ia,Bg,Ng,Wa,me,Bd,Nd,V1,G1,Lg,Up,Rc,q1,t2,tA,Ji,Tf,$P,tF,eF,nF,rF,iF;const zu=class eA{constructor({x:t,y:e},r,i,s,a,o=0){C(this,Ji),C(this,Zi),C(this,ia,[]),C(this,Bg),C(this,Ng),C(this,Wa,[]),C(this,me,new Float32Array(18)),C(this,Bd),C(this,Nd),C(this,V1),C(this,G1),C(this,Lg),C(this,Up),C(this,Rc,[]),w(this,Zi,r),w(this,Up,s*i),w(this,Ng,a),u(this,me).set([NaN,NaN,NaN,NaN,t,e],6),w(this,Bg,o),w(this,G1,u(eA,q1)*i),w(this,V1,u(eA,tA)*i),w(this,Lg,i),u(this,Rc).push(t,e)}isEmpty(){return isNaN(u(this,me)[8])}add({x:t,y:e}){var r;w(this,Bd,t),w(this,Nd,e);const[i,s,a,o]=u(this,Zi);let[l,c,h,d]=u(this,me).subarray(8,12);const p=t-h,g=e-d,m=Math.hypot(p,g);if(m<u(this,V1))return!1;const y=m-u(this,G1),v=y/m,b=v*p,S=v*g;let k=l,P=c;l=h,c=d,h+=b,d+=S,(r=u(this,Rc))==null||r.push(t,e);const T=-S/y,M=b/y,D=T*u(this,Up),L=M*u(this,Up);return u(this,me).set(u(this,me).subarray(2,8),0),u(this,me).set([h+D,d+L],4),u(this,me).set(u(this,me).subarray(14,18),12),u(this,me).set([h-D,d-L],16),isNaN(u(this,me)[6])?(u(this,Wa).length===0&&(u(this,me).set([l+D,c+L],2),u(this,Wa).push(NaN,NaN,NaN,NaN,(l+D-i)/a,(c+L-s)/o),u(this,me).set([l-D,c-L],14),u(this,ia).push(NaN,NaN,NaN,NaN,(l-D-i)/a,(c-L-s)/o)),u(this,me).set([k,P,l,c,h,d],6),!this.isEmpty()):(u(this,me).set([k,P,l,c,h,d],6),Math.abs(Math.atan2(P-c,k-l)-Math.atan2(S,b))<Math.PI/2?([l,c,h,d]=u(this,me).subarray(2,6),u(this,Wa).push(NaN,NaN,NaN,NaN,((l+h)/2-i)/a,((c+d)/2-s)/o),[l,c,k,P]=u(this,me).subarray(14,18),u(this,ia).push(NaN,NaN,NaN,NaN,((k+l)/2-i)/a,((P+c)/2-s)/o),!0):([k,P,l,c,h,d]=u(this,me).subarray(0,6),u(this,Wa).push(((k+5*l)/6-i)/a,((P+5*c)/6-s)/o,((5*l+h)/6-i)/a,((5*c+d)/6-s)/o,((l+h)/2-i)/a,((c+d)/2-s)/o),[h,d,l,c,k,P]=u(this,me).subarray(12,18),u(this,ia).push(((k+5*l)/6-i)/a,((P+5*c)/6-s)/o,((5*l+h)/6-i)/a,((5*c+d)/6-s)/o,((l+h)/2-i)/a,((c+d)/2-s)/o),!0))}toSVGPath(){if(this.isEmpty())return"";const t=u(this,Wa),e=u(this,ia);if(isNaN(u(this,me)[6])&&!this.isEmpty())return F(this,Ji,$P).call(this);const r=[];r.push(`M${t[4]} ${t[5]}`);for(let i=6;i<t.length;i+=6)isNaN(t[i])?r.push(`L${t[i+4]} ${t[i+5]}`):r.push(`C${t[i]} ${t[i+1]} ${t[i+2]} ${t[i+3]} ${t[i+4]} ${t[i+5]}`);F(this,Ji,eF).call(this,r);for(let i=e.length-6;i>=6;i-=6)isNaN(e[i])?r.push(`L${e[i+4]} ${e[i+5]}`):r.push(`C${e[i]} ${e[i+1]} ${e[i+2]} ${e[i+3]} ${e[i+4]} ${e[i+5]}`);return F(this,Ji,tF).call(this,r),r.join(" ")}newFreeDrawOutline(t,e,r,i,s,a){return new oF(t,e,r,i,s,a)}getOutlines(){var t;const e=u(this,Wa),r=u(this,ia),i=u(this,me),[s,a,o,l]=u(this,Zi),c=new Float32Array((((t=u(this,Rc))==null?void 0:t.length)??0)+2);for(let p=0,g=c.length-2;p<g;p+=2)c[p]=(u(this,Rc)[p]-s)/o,c[p+1]=(u(this,Rc)[p+1]-a)/l;if(c[c.length-2]=(u(this,Bd)-s)/o,c[c.length-1]=(u(this,Nd)-a)/l,isNaN(i[6])&&!this.isEmpty())return F(this,Ji,nF).call(this,c);const h=new Float32Array(u(this,Wa).length+24+u(this,ia).length);let d=e.length;for(let p=0;p<d;p+=2){if(isNaN(e[p])){h[p]=h[p+1]=NaN;continue}h[p]=e[p],h[p+1]=e[p+1]}d=F(this,Ji,iF).call(this,h,d);for(let p=r.length-6;p>=6;p-=6)for(let g=0;g<6;g+=2){if(isNaN(r[p+g])){h[d]=h[d+1]=NaN,d+=2;continue}h[d]=r[p+g],h[d+1]=r[p+g+1],d+=2}return F(this,Ji,rF).call(this,h,d),this.newFreeDrawOutline(h,c,u(this,Zi),u(this,Lg),u(this,Bg),u(this,Ng))}};Zi=new WeakMap,ia=new WeakMap,Bg=new WeakMap,Ng=new WeakMap,Wa=new WeakMap,me=new WeakMap,Bd=new WeakMap,Nd=new WeakMap,V1=new WeakMap,G1=new WeakMap,Lg=new WeakMap,Up=new WeakMap,Rc=new WeakMap,q1=new WeakMap,t2=new WeakMap,tA=new WeakMap,Ji=new WeakSet,Tf=function(){const n=u(this,me).subarray(4,6),t=u(this,me).subarray(16,18),[e,r,i,s]=u(this,Zi);return[(u(this,Bd)+(n[0]-t[0])/2-e)/i,(u(this,Nd)+(n[1]-t[1])/2-r)/s,(u(this,Bd)+(t[0]-n[0])/2-e)/i,(u(this,Nd)+(t[1]-n[1])/2-r)/s]},$P=function(){const[n,t,e,r]=u(this,Zi),[i,s,a,o]=F(this,Ji,Tf).call(this);return`M${(u(this,me)[2]-n)/e} ${(u(this,me)[3]-t)/r} L${(u(this,me)[4]-n)/e} ${(u(this,me)[5]-t)/r} L${i} ${s} L${a} ${o} L${(u(this,me)[16]-n)/e} ${(u(this,me)[17]-t)/r} L${(u(this,me)[14]-n)/e} ${(u(this,me)[15]-t)/r} Z`},tF=function(n){const t=u(this,ia);n.push(`L${t[4]} ${t[5]} Z`)},eF=function(n){const[t,e,r,i]=u(this,Zi),s=u(this,me).subarray(4,6),a=u(this,me).subarray(16,18),[o,l,c,h]=F(this,Ji,Tf).call(this);n.push(`L${(s[0]-t)/r} ${(s[1]-e)/i} L${o} ${l} L${c} ${h} L${(a[0]-t)/r} ${(a[1]-e)/i}`)},nF=function(n){const t=u(this,me),[e,r,i,s]=u(this,Zi),[a,o,l,c]=F(this,Ji,Tf).call(this),h=new Float32Array(36);return h.set([NaN,NaN,NaN,NaN,(t[2]-e)/i,(t[3]-r)/s,NaN,NaN,NaN,NaN,(t[4]-e)/i,(t[5]-r)/s,NaN,NaN,NaN,NaN,a,o,NaN,NaN,NaN,NaN,l,c,NaN,NaN,NaN,NaN,(t[16]-e)/i,(t[17]-r)/s,NaN,NaN,NaN,NaN,(t[14]-e)/i,(t[15]-r)/s],0),this.newFreeDrawOutline(h,n,u(this,Zi),u(this,Lg),u(this,Bg),u(this,Ng))},rF=function(n,t){const e=u(this,ia);return n.set([NaN,NaN,NaN,NaN,e[4],e[5]],t),t+=6},iF=function(n,t){const e=u(this,me).subarray(4,6),r=u(this,me).subarray(16,18),[i,s,a,o]=u(this,Zi),[l,c,h,d]=F(this,Ji,Tf).call(this);return n.set([NaN,NaN,NaN,NaN,(e[0]-i)/a,(e[1]-s)/o,NaN,NaN,NaN,NaN,l,c,NaN,NaN,NaN,NaN,h,d,NaN,NaN,NaN,NaN,(r[0]-i)/a,(r[1]-s)/o],t),t+=24},C(zu,q1,8),C(zu,t2,2),C(zu,tA,u(zu,q1)+u(zu,t2));let sF=zu;var Vp,dd,pl,H1,Wi,X1,zn,nA,aF;class oF extends Ft{constructor(t,e,r,i,s,a){super(),C(this,nA),C(this,Vp),C(this,dd,new Float32Array(4)),C(this,pl),C(this,H1),C(this,Wi),C(this,X1),C(this,zn),w(this,zn,t),w(this,Wi,e),w(this,Vp,r),w(this,X1,i),w(this,pl,s),w(this,H1,a),this.firstPoint=[NaN,NaN],this.lastPoint=[NaN,NaN],F(this,nA,aF).call(this,a);const[o,l,c,h]=u(this,dd);for(let d=0,p=t.length;d<p;d+=2)t[d]=(t[d]-o)/c,t[d+1]=(t[d+1]-l)/h;for(let d=0,p=e.length;d<p;d+=2)e[d]=(e[d]-o)/c,e[d+1]=(e[d+1]-l)/h}toSVGPath(){const t=[`M${u(this,zn)[4]} ${u(this,zn)[5]}`];for(let e=6,r=u(this,zn).length;e<r;e+=6){if(isNaN(u(this,zn)[e])){t.push(`L${u(this,zn)[e+4]} ${u(this,zn)[e+5]}`);continue}t.push(`C${u(this,zn)[e]} ${u(this,zn)[e+1]} ${u(this,zn)[e+2]} ${u(this,zn)[e+3]} ${u(this,zn)[e+4]} ${u(this,zn)[e+5]}`)}return t.push("Z"),t.join(" ")}serialize([t,e,r,i],s){const a=r-t,o=i-e;let l,c;switch(s){case 0:l=Ft._rescale(u(this,zn),t,i,a,-o),c=Ft._rescale(u(this,Wi),t,i,a,-o);break;case 90:l=Ft._rescaleAndSwap(u(this,zn),t,e,a,o),c=Ft._rescaleAndSwap(u(this,Wi),t,e,a,o);break;case 180:l=Ft._rescale(u(this,zn),r,e,-a,o),c=Ft._rescale(u(this,Wi),r,e,-a,o);break;case 270:l=Ft._rescaleAndSwap(u(this,zn),r,i,-a,-o),c=Ft._rescaleAndSwap(u(this,Wi),r,i,-a,-o);break}return{outline:Array.from(l),points:[Array.from(c)]}}get box(){return u(this,dd)}newOutliner(t,e,r,i,s,a=0){return new sF(t,e,r,i,s,a)}getNewOutline(t,e){const[r,i,s,a]=u(this,dd),[o,l,c,h]=u(this,Vp),d=s*c,p=a*h,g=r*c+o,m=i*h+l,y=this.newOutliner({x:u(this,Wi)[0]*d+g,y:u(this,Wi)[1]*p+m},u(this,Vp),u(this,X1),t,u(this,H1),e??u(this,pl));for(let v=2;v<u(this,Wi).length;v+=2)y.add({x:u(this,Wi)[v]*d+g,y:u(this,Wi)[v+1]*p+m});return y.getOutlines()}}Vp=new WeakMap,dd=new WeakMap,pl=new WeakMap,H1=new WeakMap,Wi=new WeakMap,X1=new WeakMap,zn=new WeakMap,nA=new WeakSet,aF=function(n){const t=u(this,zn);let e=t[4],r=t[5];const i=[e,r,e,r];let s=e,a=r,o=e,l=r;const c=n?Math.max:Math.min,h=new Float32Array(4);for(let p=6,g=t.length;p<g;p+=6){const m=t[p+4],y=t[p+5];isNaN(t[p])?(ft.pointBoundingBox(m,y,i),a>y?(s=m,a=y):a===y&&(s=c(s,m)),l<y?(o=m,l=y):l===y&&(o=c(o,m))):(h.set(co,0),ft.bezierBoundingBox(e,r,...t.slice(p,p+6),h),ft.rectBoundingBox(...h,i),a>h[1]?(s=h[0],a=h[1]):a===h[1]&&(s=c(s,h[0])),l<h[3]?(o=h[2],l=h[3]):l===h[3]&&(o=c(o,h[2]))),e=m,r=y}const d=u(this,dd);d[0]=i[0]-u(this,pl),d[1]=i[1]-u(this,pl),d[2]=i[2]-i[0]+2*u(this,pl),d[3]=i[3]-i[1]+2*u(this,pl),this.firstPoint=[s,a],this.lastPoint=[o,l]};var mv,yv,vv,Bc,Hs,ca,lF,yy,cF,hF,rA;class iA{constructor(t,e=0,r=0,i=!0){C(this,ca),C(this,mv),C(this,yv),C(this,vv),C(this,Bc,[]),C(this,Hs,[]);const s=co.slice(),a=10**-4;for(const{x:y,y:v,width:b,height:S}of t){const k=Math.floor((y-e)/a)*a,P=Math.ceil((y+b+e)/a)*a,T=Math.floor((v-e)/a)*a,M=Math.ceil((v+S+e)/a)*a,D=[k,T,M,!0],L=[P,T,M,!1];u(this,Bc).push(D,L),ft.rectBoundingBox(k,T,P,M,s)}const o=s[2]-s[0]+2*r,l=s[3]-s[1]+2*r,c=s[0]-r,h=s[1]-r;let d=i?-1/0:1/0,p=1/0;const g=u(this,Bc).at(i?-1:-2),m=[g[0],g[2]];for(const y of u(this,Bc)){const[v,b,S,k]=y;!k&&i?b<p?(p=b,d=v):b===p&&(d=Math.max(d,v)):k&&!i&&(b<p?(p=b,d=v):b===p&&(d=Math.min(d,v))),y[0]=(v-c)/o,y[1]=(b-h)/l,y[2]=(S-h)/l}w(this,mv,new Float32Array([c,h,o,l])),w(this,yv,[d,p]),w(this,vv,m)}getOutlines(){u(this,Bc).sort((e,r)=>e[0]-r[0]||e[1]-r[1]||e[2]-r[2]);const t=[];for(const e of u(this,Bc))e[3]?(t.push(...F(this,ca,rA).call(this,e)),F(this,ca,cF).call(this,e)):(F(this,ca,hF).call(this,e),t.push(...F(this,ca,rA).call(this,e)));return F(this,ca,lF).call(this,t)}}mv=new WeakMap,yv=new WeakMap,vv=new WeakMap,Bc=new WeakMap,Hs=new WeakMap,ca=new WeakSet,lF=function(n){const t=[],e=new Set;for(const s of n){const[a,o,l]=s;t.push([a,o,s],[a,l,s])}t.sort((s,a)=>s[1]-a[1]||s[0]-a[0]);for(let s=0,a=t.length;s<a;s+=2){const o=t[s][2],l=t[s+1][2];o.push(l),l.push(o),e.add(o),e.add(l)}const r=[];let i;for(;e.size>0;){const s=e.values().next().value;let[a,o,l,c,h]=s;e.delete(s);let d=a,p=o;for(i=[a,l],r.push(i);;){let g;if(e.has(c))g=c;else if(e.has(h))g=h;else break;e.delete(g),[a,o,l,c,h]=g,d!==a&&(i.push(d,p,a,p===o?o:l),d=a),p=p===o?l:o}i.push(d,p)}return new F_(r,u(this,mv),u(this,yv),u(this,vv))},yy=function(n){const t=u(this,Hs);let e=0,r=t.length-1;for(;e<=r;){const i=e+r>>1,s=t[i][0];if(s===n)return i;s<n?e=i+1:r=i-1}return r+1},cF=function([,n,t]){const e=F(this,ca,yy).call(this,n);u(this,Hs).splice(e,0,[n,t])},hF=function([,n,t]){const e=F(this,ca,yy).call(this,n);for(let r=e;r<u(this,Hs).length;r++){const[i,s]=u(this,Hs)[r];if(i!==n)break;if(i===n&&s===t){u(this,Hs).splice(r,1);return}}for(let r=e-1;r>=0;r--){const[i,s]=u(this,Hs)[r];if(i!==n)break;if(i===n&&s===t){u(this,Hs).splice(r,1);return}}},rA=function(n){const[t,e,r]=n,i=[[t,e,r]],s=F(this,ca,yy).call(this,r);for(let a=0;a<s;a++){const[o,l]=u(this,Hs)[a];for(let c=0,h=i.length;c<h;c++){const[,d,p]=i[c];if(!(l<=d||p<=o)){if(d>=o){if(p>l)i[c][1]=l;else{if(h===1)return[];i.splice(c,1),c--,h--}continue}i[c][2]=o,p>l&&i.push([t,l,p])}}}return i};var K1,Gp;class F_ extends Ft{constructor(t,e,r,i){super(),C(this,K1),C(this,Gp),w(this,Gp,t),w(this,K1,e),this.firstPoint=r,this.lastPoint=i}toSVGPath(){const t=[];for(const e of u(this,Gp)){let[r,i]=e;t.push(`M${r} ${i}`);for(let s=2;s<e.length;s+=2){const a=e[s],o=e[s+1];a===r?(t.push(`V${o}`),i=o):o===i&&(t.push(`H${a}`),r=a)}t.push("Z")}return t.join(" ")}serialize([t,e,r,i],s){const a=[],o=r-t,l=i-e;for(const c of u(this,Gp)){const h=new Array(c.length);for(let d=0;d<c.length;d+=2)h[d]=t+c[d]*o,h[d+1]=i-c[d+1]*l;a.push(h)}return a}get box(){return u(this,K1)}get classNamesForOutlining(){return["highlightOutline"]}}K1=new WeakMap,Gp=new WeakMap;class sA extends sF{newFreeDrawOutline(t,e,r,i,s,a){return new E_(t,e,r,i,s,a)}}class E_ extends oF{newOutliner(t,e,r,i,s,a=0){return new sA(t,e,r,i,s,a)}}var Wg,bv,Al,fd,_1,ui,wv,xv,Ld,zi,Yi,Er,jg,zg,jr,qp,Fs,Y1,Ue,aA,Av,uF,dF,C6,oA,Nc,ao,Wd,fF,Z1,Sv,pF,gF,mF,yF,vF;const Yr=class Tr extends on{constructor(t){super({...t,name:"highlightEditor"}),C(this,Ue),C(this,Wg,null),C(this,bv,0),C(this,Al),C(this,fd,null),C(this,_1,null),C(this,ui,null),C(this,wv,null),C(this,xv,0),C(this,Ld,null),C(this,zi,null),C(this,Yi,null),C(this,Er,!1),C(this,jg,null),C(this,zg,null),C(this,jr,null),C(this,qp,""),C(this,Fs),C(this,Y1,""),this.color=t.color||Tr._defaultColor,w(this,Fs,t.thickness||Tr._defaultThickness),this.opacity=t.opacity||Tr._defaultOpacity,w(this,Al,t.boxes||null),w(this,Y1,t.methodOfCreation||""),w(this,qp,t.text||""),this._isDraggable=!1,this.defaultL10nId="pdfjs-editor-highlight-editor",t.highlightId>-1?(w(this,Er,!0),F(this,Ue,Av).call(this,t),F(this,Ue,Nc).call(this)):u(this,Al)&&(w(this,Wg,t.anchorNode),w(this,bv,t.anchorOffset),w(this,wv,t.focusNode),w(this,xv,t.focusOffset),F(this,Ue,aA).call(this),F(this,Ue,Nc).call(this),this.rotate(this.rotation)),this.annotationElementId||this._uiManager.a11yAlert("pdfjs-editor-highlight-added-alert")}static get _keyboardManager(){const t=Tr.prototype;return se(this,"_keyboardManager",new Pm([[["ArrowLeft","mac+ArrowLeft"],t._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],t._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],t._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],t._moveCaret,{args:[3]}]]))}get telemetryInitialData(){return{action:"added",type:u(this,Er)?"free_highlight":"highlight",color:this._uiManager.getNonHCMColorName(this.color),thickness:u(this,Fs),methodOfCreation:u(this,Y1)}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.getNonHCMColorName(this.color)}}static computeTelemetryFinalData(t){return{numberOfColors:t.get("color").size}}static initialize(t,e){var r;on.initialize(t,e),Tr._defaultColor||(Tr._defaultColor=((r=e.highlightColors)==null?void 0:r.values().next().value)||"#fff066")}static updateDefaultParams(t,e){switch(t){case ce.HIGHLIGHT_COLOR:Tr._defaultColor=e;break;case ce.HIGHLIGHT_THICKNESS:Tr._defaultThickness=e;break}}translateInPage(t,e){}get toolbarPosition(){return u(this,zg)}get commentButtonPosition(){return u(this,jg)}updateParams(t,e){switch(t){case ce.HIGHLIGHT_COLOR:F(this,Ue,uF).call(this,e);break;case ce.HIGHLIGHT_THICKNESS:F(this,Ue,dF).call(this,e);break}}static get defaultPropertiesToUpdate(){return[[ce.HIGHLIGHT_COLOR,Tr._defaultColor],[ce.HIGHLIGHT_THICKNESS,Tr._defaultThickness]]}get propertiesToUpdate(){return[[ce.HIGHLIGHT_COLOR,this.color||Tr._defaultColor],[ce.HIGHLIGHT_THICKNESS,u(this,Fs)||Tr._defaultThickness],[ce.HIGHLIGHT_FREE,u(this,Er)]]}onUpdatedColor(){var t,e;(t=this.parent)==null||t.drawLayer.updateProperties(u(this,Yi),{root:{fill:this.color,"fill-opacity":this.opacity}}),(e=u(this,_1))==null||e.updateColor(this.color),super.onUpdatedColor()}get toolbarButtons(){return this._uiManager.highlightColors?[["colorPicker",w(this,_1,new QS({editor:this}))]]:super.toolbarButtons}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(F(this,Ue,Sv).call(this))}getBaseTranslation(){return[0,0]}getRect(t,e){return super.getRect(t,e,F(this,Ue,Sv).call(this))}onceAdded(t){this.annotationElementId||this.parent.addUndoableEditor(this),t&&this.div.focus()}remove(){F(this,Ue,oA).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(F(this,Ue,Nc).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(t){var e;let r=!1;this.parent&&!t?F(this,Ue,oA).call(this):t&&(F(this,Ue,Nc).call(this,t),r=!this.parent&&((e=this.div)==null?void 0:e.classList.contains("selectedEditor"))),super.setParent(t),this.show(this._isVisible),r&&this.select()}rotate(t){var e,r,i;const{drawLayer:s}=this.parent;let a;u(this,Er)?(t=(t-this.rotation+360)%360,a=F(e=Tr,ao,Wd).call(e,u(this,zi).box,t)):a=F(r=Tr,ao,Wd).call(r,[this.x,this.y,this.width,this.height],t),s.updateProperties(u(this,Yi),{bbox:a,root:{"data-main-rotation":t}}),s.updateProperties(u(this,jr),{bbox:F(i=Tr,ao,Wd).call(i,u(this,ui).box,t),root:{"data-main-rotation":t}})}render(){if(this.div)return this.div;const t=super.render();u(this,qp)&&(t.setAttribute("aria-label",u(this,qp)),t.setAttribute("role","mark")),u(this,Er)?t.classList.add("free"):this.div.addEventListener("keydown",F(this,Ue,fF).bind(this),{signal:this._uiManager._signal});const e=w(this,Ld,document.createElement("div"));return t.append(e),e.setAttribute("aria-hidden","true"),e.className="internal",e.style.clipPath=u(this,fd),this.setDims(),yM(this,u(this,Ld),["pointerover","pointerleave"]),this.enableEditing(),t}pointerover(){var t;this.isSelected||(t=this.parent)==null||t.drawLayer.updateProperties(u(this,jr),{rootClass:{hovered:!0}})}pointerleave(){var t;this.isSelected||(t=this.parent)==null||t.drawLayer.updateProperties(u(this,jr),{rootClass:{hovered:!1}})}_moveCaret(t){switch(this.parent.unselect(this),t){case 0:case 2:F(this,Ue,Z1).call(this,!0);break;case 1:case 3:F(this,Ue,Z1).call(this,!1);break}}select(){var t;super.select(),u(this,jr)&&((t=this.parent)==null||t.drawLayer.updateProperties(u(this,jr),{rootClass:{hovered:!1,selected:!0}}))}unselect(){var t;super.unselect(),u(this,jr)&&((t=this.parent)==null||t.drawLayer.updateProperties(u(this,jr),{rootClass:{selected:!1}}),u(this,Er)||F(this,Ue,Z1).call(this,!1))}get _mustFixPosition(){return!u(this,Er)}show(t=this._isVisible){super.show(t),this.parent&&(this.parent.drawLayer.updateProperties(u(this,Yi),{rootClass:{hidden:!t}}),this.parent.drawLayer.updateProperties(u(this,jr),{rootClass:{hidden:!t}}))}static startHighlighting(t,e,{target:r,x:i,y:s}){const{x:a,y:o,width:l,height:c}=r.getBoundingClientRect(),h=new AbortController,d=t.combinedSignal(h),p=g=>{h.abort(),F(this,ao,yF).call(this,t,g)};window.addEventListener("blur",p,{signal:d}),window.addEventListener("pointerup",p,{signal:d}),window.addEventListener("pointerdown",an,{capture:!0,passive:!1,signal:d}),window.addEventListener("contextmenu",Ti,{signal:d}),r.addEventListener("pointermove",F(this,ao,mF).bind(this,t),{signal:d}),this._freeHighlight=new sA({x:i,y:s},[a,o,l,c],t.scale,this._defaultThickness/2,e,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=t.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(t,e,r){var i,s,a,o;let l=null;if(t instanceof qP){const{data:{quadPoints:k,rect:P,rotation:T,id:M,color:D,opacity:L,popupRef:W,richText:z,contentsObj:V,creationDate:X,modificationDate:U},parent:{page:{pageNumber:K}}}=t;l=t={annotationType:te.HIGHLIGHT,color:Array.from(D),opacity:L,quadPoints:k,boxes:null,pageIndex:K-1,rect:P.slice(0),rotation:T,annotationElementId:M,id:M,deleted:!1,popupRef:W,richText:z,comment:(V==null?void 0:V.str)||null,creationDate:X,modificationDate:U}}else if(t instanceof t5){const{data:{inkLists:k,rect:P,rotation:T,id:M,color:D,borderStyle:{rawWidth:L},popupRef:W,richText:z,contentsObj:V,creationDate:X,modificationDate:U},parent:{page:{pageNumber:K}}}=t;l=t={annotationType:te.HIGHLIGHT,color:Array.from(D),thickness:L,inkLists:k,boxes:null,pageIndex:K-1,rect:P.slice(0),rotation:T,annotationElementId:M,id:M,deleted:!1,popupRef:W,richText:z,comment:(V==null?void 0:V.str)||null,creationDate:X,modificationDate:U}}const{color:c,quadPoints:h,inkLists:d,outlines:p,opacity:g}=t,m=await super.deserialize(t,e,r);m.color=ft.makeHexColor(...c),m.opacity=g||1,d&&w(m,Fs,t.thickness),m._initialData=l,t.comment&&m.setCommentData(t);const[y,v]=m.pageDimensions,[b,S]=m.pageTranslation;if(h){const k=w(m,Al,[]);for(let P=0;P<h.length;P+=8)k.push({x:(h[P]-b)/y,y:1-(h[P+1]-S)/v,width:(h[P+2]-h[P])/y,height:(h[P+1]-h[P+5])/v});F(i=m,Ue,aA).call(i),F(s=m,Ue,Nc).call(s),m.rotate(m.rotation)}else if(d||p){w(m,Er,!0);const k=(d||p.points)[0],P={x:k[0]-b,y:v-(k[1]-S)},T=new sA(P,[0,0,y,v],1,u(m,Fs)/2,!0,.001);for(let L=0,W=k.length;L<W;L+=2)P.x=k[L]-b,P.y=v-(k[L+1]-S),T.add(P);const{id:M,clipPathId:D}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:m.color,"fill-opacity":m._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:T.toSVGPath()}},!0,!0);F(a=m,Ue,Av).call(a,{highlightOutlines:T.getOutlines(),highlightId:M,clipPathId:D}),F(o=m,Ue,Nc).call(o),m.rotate(m.parentRotation)}return m}serialize(t=!1){if(this.isEmpty()||t)return null;if(this.deleted)return this.serializeDeleted();const e=on._colorManager.convert(this._uiManager.getNonHCMColor(this.color)),r=super.serialize(t);return Object.assign(r,{color:e,opacity:this.opacity,thickness:u(this,Fs),quadPoints:F(this,Ue,pF).call(this),outlines:F(this,Ue,gF).call(this,r.rect)}),this.addComment(r),this.annotationElementId&&!F(this,Ue,vF).call(this,r)?null:(r.id=this.annotationElementId,r)}renderAnnotationElement(t){return this.deleted?(t.hide(),null):(t.updateEdited({rect:this.getPDFRect(),popup:this.comment}),null)}static canCreateNewEmptyEditor(){return!1}};Wg=new WeakMap,bv=new WeakMap,Al=new WeakMap,fd=new WeakMap,_1=new WeakMap,ui=new WeakMap,wv=new WeakMap,xv=new WeakMap,Ld=new WeakMap,zi=new WeakMap,Yi=new WeakMap,Er=new WeakMap,jg=new WeakMap,zg=new WeakMap,jr=new WeakMap,qp=new WeakMap,Fs=new WeakMap,Y1=new WeakMap,Ue=new WeakSet,aA=function(){const n=new iA(u(this,Al),.001);w(this,zi,n.getOutlines()),[this.x,this.y,this.width,this.height]=u(this,zi).box;const t=new iA(u(this,Al),.0025,.001,this._uiManager.direction==="ltr");w(this,ui,t.getOutlines());const{firstPoint:e}=u(this,zi);w(this,jg,[(e[0]-this.x)/this.width,(e[1]-this.y)/this.height]);const{lastPoint:r}=u(this,ui);w(this,zg,[(r[0]-this.x)/this.width,(r[1]-this.y)/this.height])},Av=function({highlightOutlines:n,highlightId:t,clipPathId:e}){var r,i;if(w(this,zi,n),w(this,ui,n.getNewOutline(u(this,Fs)/2+1.5,.0025)),t>=0)w(this,Yi,t),w(this,fd,e),this.parent.drawLayer.finalizeDraw(t,{bbox:n.box,path:{d:n.toSVGPath()}}),w(this,jr,this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:u(this,ui).box,path:{d:u(this,ui).toSVGPath()}},!0));else if(this.parent){const d=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(u(this,Yi),{bbox:F(r=Yr,ao,Wd).call(r,u(this,zi).box,(d-this.rotation+360)%360),path:{d:n.toSVGPath()}}),this.parent.drawLayer.updateProperties(u(this,jr),{bbox:F(i=Yr,ao,Wd).call(i,u(this,ui).box,d),path:{d:u(this,ui).toSVGPath()}})}const[s,a,o,l]=n.box;switch(this.rotation){case 0:this.x=s,this.y=a,this.width=o,this.height=l;break;case 90:{const[d,p]=this.parentDimensions;this.x=a,this.y=1-s,this.width=o*p/d,this.height=l*d/p;break}case 180:this.x=1-s,this.y=1-a,this.width=o,this.height=l;break;case 270:{const[d,p]=this.parentDimensions;this.x=1-a,this.y=s,this.width=o*p/d,this.height=l*d/p;break}}const{firstPoint:c}=n;w(this,jg,[(c[0]-s)/o,(c[1]-a)/l]);const{lastPoint:h}=u(this,ui);w(this,zg,[(h[0]-s)/o,(h[1]-a)/l])},uF=function(n){const t=(i,s)=>{this.color=i,this.opacity=s,this.onUpdatedColor()},e=this.color,r=this.opacity;this.addCommands({cmd:t.bind(this,n,Yr._defaultOpacity),undo:t.bind(this,e,r),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:ce.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.getNonHCMColorName(n)},!0)},dF=function(n){const t=u(this,Fs),e=r=>{w(this,Fs,r),F(this,Ue,C6).call(this,r)};this.addCommands({cmd:e.bind(this,n),undo:e.bind(this,t),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:ce.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:n},!0)},C6=function(n){u(this,Er)&&(F(this,Ue,Av).call(this,{highlightOutlines:u(this,zi).getNewOutline(n/2)}),this.fixAndSetPosition(),this.setDims())},oA=function(){u(this,Yi)===null||!this.parent||(this.parent.drawLayer.remove(u(this,Yi)),w(this,Yi,null),this.parent.drawLayer.remove(u(this,jr)),w(this,jr,null))},Nc=function(n=this.parent){u(this,Yi)===null&&({id:Qn(this,Yi)._,clipPathId:Qn(this,fd)._}=n.drawLayer.draw({bbox:u(this,zi).box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":this.opacity},rootClass:{highlight:!0,free:u(this,Er)},path:{d:u(this,zi).toSVGPath()}},!1,!0),w(this,jr,n.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:u(this,Er)},bbox:u(this,ui).box,path:{d:u(this,ui).toSVGPath()}},u(this,Er))),u(this,Ld)&&(u(this,Ld).style.clipPath=u(this,fd)))},ao=new WeakSet,Wd=function([n,t,e,r],i){switch(i){case 90:return[1-t-r,n,r,e];case 180:return[1-n-e,1-t-r,e,r];case 270:return[t,1-n-e,r,e]}return[n,t,e,r]},fF=function(n){Yr._keyboardManager.exec(this,n)},Z1=function(n){if(!u(this,Wg))return;const t=window.getSelection();n?t.setPosition(u(this,Wg),u(this,bv)):t.setPosition(u(this,wv),u(this,xv))},Sv=function(){return u(this,Er)?this.rotation:0},pF=function(){if(u(this,Er))return null;const[n,t]=this.pageDimensions,[e,r]=this.pageTranslation,i=u(this,Al),s=new Float32Array(i.length*8);let a=0;for(const{x:o,y:l,width:c,height:h}of i){const d=o*n+e,p=(1-l)*t+r;s[a]=s[a+4]=d,s[a+1]=s[a+3]=p,s[a+2]=s[a+6]=d+c*n,s[a+5]=s[a+7]=p-h*t,a+=8}return s},gF=function(n){return u(this,zi).serialize(n,F(this,Ue,Sv).call(this))},mF=function(n,t){this._freeHighlight.add(t)&&n.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})},yF=function(n,t){this._freeHighlight.isEmpty()?n.drawLayer.remove(this._freeHighlightId):n.createAndAddNewEditor(t,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:"main_toolbar"}),this._freeHighlightId=-1,this._freeHighlight=null,this._freeHighlightClipId=""},vF=function(n){const{color:t}=this._initialData;return this.hasEditedComment||n.color.some((e,r)=>e!==t[r])},C(Yr,ao),J(Yr,"_defaultColor",null),J(Yr,"_defaultOpacity",1),J(Yr,"_defaultThickness",12),J(Yr,"_type","highlight"),J(Yr,"_editorType",te.HIGHLIGHT),J(Yr,"_freeHighlightId",-1),J(Yr,"_freeHighlight",null),J(Yr,"_freeHighlightClipId","");let T6=Yr;var Uu;class bF{constructor(){C(this,Uu,Object.create(null))}updateProperty(t,e){this[t]=e,this.updateSVGProperty(t,e)}updateProperties(t){if(t)for(const[e,r]of Object.entries(t))e.startsWith("_")||this.updateProperty(e,r)}updateSVGProperty(t,e){u(this,Uu)[t]=e}toSVGProperties(){const t=u(this,Uu);return w(this,Uu,Object.create(null)),{root:t}}reset(){w(this,Uu,Object.create(null))}updateAll(t=this){this.updateProperties(t)}clone(){Ne("Not implemented")}}Uu=new WeakMap;var ti,Hp,ur,pd,gd,Je,lA,e2,cA,Xp,M6,J1,Ug,Vu;const Ko=class ze extends on{constructor(t){super(t),C(this,Je),C(this,ti,null),C(this,Hp),J(this,"_colorPicker",null),J(this,"_drawId",null),w(this,Hp,t.mustBeCommitted||!1),this._addOutlines(t)}onUpdatedColor(){var t;(t=this._colorPicker)==null||t.update(this.color),super.onUpdatedColor()}onUpdatedOpacity(){var t,e;(e=(t=this._colorPicker)==null?void 0:t.updateOpacity)==null||e.call(t,this.opacity)}_addOutlines(t){t.drawOutlines&&(F(this,Je,lA).call(this,t),F(this,Je,Xp).call(this))}static _mergeSVGProperties(t,e){const r=new Set(Object.keys(t));for(const[i,s]of Object.entries(e))r.has(i)?Object.assign(t[i],s):t[i]=s;return t}static getDefaultDrawingOptions(t){Ne("Not implemented")}static get typesMap(){Ne("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(t,e){const r=this.typesMap.get(t);r&&this._defaultDrawingOptions.updateProperty(r,e),this._currentParent&&(u(ze,ur).updateProperty(r,e),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(t,e){const r=this.constructor.typesMap.get(t);r&&this._updateProperty(t,r,e)}static get defaultPropertiesToUpdate(){const t=[],e=this._defaultDrawingOptions;for(const[r,i]of this.typesMap)t.push([r,e[i]]);return t}get propertiesToUpdate(){const t=[],{_drawingOptions:e}=this;for(const[r,i]of this.constructor.typesMap)t.push([r,e[i]]);return t}_updateProperty(t,e,r){const i=this._drawingOptions,s=i[e],a=o=>{var l;i.updateProperty(e,o);const c=u(this,ti).updateProperty(e,o);c&&F(this,Je,Ug).call(this,c),(l=this.parent)==null||l.drawLayer.updateProperties(this._drawId,i.toSVGProperties()),t===this.colorType?this.onUpdatedColor():t===this.opacityType&&this.onUpdatedOpacity()};this.addCommands({cmd:a.bind(this,r),undo:a.bind(this,s),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:t,overwriteIfSameType:!0,keepUndo:!0})}_updateColorAndOpacity(t,e){const r=this.constructor.typesMap.get(this.colorType),i=this.constructor.typesMap.get(this.opacityType),s=this._drawingOptions,a=s[r],o=s[i],l=(c,h)=>{var d;s.updateProperty(r,c),s.updateProperty(i,h),u(this,ti).updateProperty(r,c),u(this,ti).updateProperty(i,h),(d=this.parent)==null||d.drawLayer.updateProperties(this._drawId,s.toSVGProperties()),this.onUpdatedColor(),this.onUpdatedOpacity()};this.addCommands({cmd:l.bind(this,t,e),undo:l.bind(this,a,o),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:ce.INK_COLOR_AND_OPACITY,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){var t;(t=this.parent)==null||t.drawLayer.updateProperties(this._drawId,ze._mergeSVGProperties(u(this,ti).getPathResizingSVGProperties(F(this,Je,J1).call(this)),{bbox:F(this,Je,Vu).call(this)}))}_onResized(){var t;(t=this.parent)==null||t.drawLayer.updateProperties(this._drawId,ze._mergeSVGProperties(u(this,ti).getPathResizedSVGProperties(F(this,Je,J1).call(this)),{bbox:F(this,Je,Vu).call(this)}))}_onTranslating(t,e){var r;(r=this.parent)==null||r.drawLayer.updateProperties(this._drawId,{bbox:F(this,Je,Vu).call(this)})}_onTranslated(){var t;(t=this.parent)==null||t.drawLayer.updateProperties(this._drawId,ze._mergeSVGProperties(u(this,ti).getPathTranslatedSVGProperties(F(this,Je,J1).call(this),this.parentDimensions),{bbox:F(this,Je,Vu).call(this)}))}_onStartDragging(){var t;(t=this.parent)==null||t.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){var t;(t=this.parent)==null||t.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(t){this.annotationElementId||this.parent.addUndoableEditor(this),this._isDraggable=!0,u(this,Hp)&&(w(this,Hp,!1),this.commit(),this.parent.setSelected(this),t&&this.isOnScreen&&this.div.focus())}remove(){F(this,Je,cA).call(this),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(F(this,Je,Xp).call(this),F(this,Je,Ug).call(this,u(this,ti).box),this.isAttachedToDOM||this.parent.add(this)))}setParent(t){var e;let r=!1;this.parent&&!t?(this._uiManager.removeShouldRescale(this),F(this,Je,cA).call(this)):t&&(this._uiManager.addShouldRescale(this),F(this,Je,Xp).call(this,t),r=!this.parent&&((e=this.div)==null?void 0:e.classList.contains("selectedEditor"))),super.setParent(t),r&&this.select()}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,ze._mergeSVGProperties({bbox:F(this,Je,Vu).call(this)},u(this,ti).updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&F(this,Je,Ug).call(this,u(this,ti).updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;let t,e;this._isCopy&&(t=this.x,e=this.y);const r=super.render();r.classList.add("draw");const i=document.createElement("div");return r.append(i),i.setAttribute("aria-hidden","true"),i.className="internal",this.setDims(),this._uiManager.addShouldRescale(this),this.disableEditing(),this._isCopy&&this._moveAfterPaste(t,e),r}static createDrawerInstance(t,e,r,i,s){Ne("Not implemented")}static startDrawing(t,e,r,i){var s;const{target:a,offsetX:o,offsetY:l,pointerId:c,pointerType:h}=i;if(Kr.isInitializedAndDifferentPointerType(h))return;const{viewport:{rotation:d}}=t,{width:p,height:g}=a.getBoundingClientRect(),m=w(ze,pd,new AbortController),y=t.combinedSignal(m);if(Kr.setPointer(h,c),window.addEventListener("pointerup",v=>{Kr.isSamePointerIdOrRemove(v.pointerId)&&this._endDraw(v)},{signal:y}),window.addEventListener("pointercancel",v=>{Kr.isSamePointerIdOrRemove(v.pointerId)&&this._currentParent.endDrawingSession()},{signal:y}),window.addEventListener("pointerdown",v=>{Kr.isSamePointerType(v.pointerType)&&(Kr.initializeAndAddPointerId(v.pointerId),u(ze,ur).isCancellable()&&(u(ze,ur).removeLastElement(),u(ze,ur).isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:y}),window.addEventListener("contextmenu",Ti,{signal:y}),a.addEventListener("pointermove",this._drawMove.bind(this),{signal:y}),a.addEventListener("touchmove",v=>{Kr.isSameTimeStamp(v.timeStamp)&&an(v)},{signal:y}),t.toggleDrawing(),(s=e._editorUndoBar)==null||s.hide(),u(ze,ur)){t.drawLayer.updateProperties(this._currentDrawId,u(ze,ur).startNew(o,l,p,g,d));return}e.updateUIForDefaultProperties(this),w(ze,ur,this.createDrawerInstance(o,l,p,g,d)),w(ze,gd,this.getDefaultDrawingOptions()),this._currentParent=t,{id:this._currentDrawId}=t.drawLayer.draw(this._mergeSVGProperties(u(ze,gd).toSVGProperties(),u(ze,ur).defaultSVGProperties),!0,!1)}static _drawMove(t){if(Kr.isSameTimeStamp(t.timeStamp),!u(ze,ur))return;const{offsetX:e,offsetY:r,pointerId:i}=t;if(Kr.isSamePointerId(i)){if(Kr.isUsingMultiplePointers()){this._endDraw(t);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,u(ze,ur).add(e,r)),Kr.setTimeStamp(t.timeStamp),an(t)}}static _cleanup(t){t&&(this._currentDrawId=-1,this._currentParent=null,w(ze,ur,null),w(ze,gd,null),Kr.clearTimeStamp()),u(ze,pd)&&(u(ze,pd).abort(),w(ze,pd,null),Kr.clearPointerIds())}static _endDraw(t){const e=this._currentParent;if(e){if(e.toggleDrawing(!0),this._cleanup(!1),(t==null?void 0:t.target)===e.div&&e.drawLayer.updateProperties(this._currentDrawId,u(ze,ur).end(t.offsetX,t.offsetY)),this.supportMultipleDrawings){const r=u(ze,ur),i=this._currentDrawId,s=r.getLastElement();e.addCommands({cmd:()=>{e.drawLayer.updateProperties(i,r.setLastElement(s))},undo:()=>{e.drawLayer.updateProperties(i,r.removeLastElement())},mustExec:!1,type:ce.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(t){const e=this._currentParent;if(!e)return null;if(e.toggleDrawing(!0),e.cleanUndoStack(ce.DRAW_STEP),!u(ze,ur).isEmpty()){const{pageDimensions:[r,i],scale:s}=e,a=e.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:u(ze,ur).getOutlines(r*s,i*s,s,this._INNER_MARGIN),drawingOptions:u(ze,gd),mustBeCommitted:!t});return this._cleanup(!0),a}return e.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(t){}static deserializeDraw(t,e,r,i,s,a){Ne("Not implemented")}static async deserialize(t,e,r){var i,s;const{rawDims:{pageWidth:a,pageHeight:o,pageX:l,pageY:c}}=e.viewport,h=this.deserializeDraw(l,c,a,o,this._INNER_MARGIN,t),d=await super.deserialize(t,e,r);return d.createDrawingOptions(t),F(i=d,Je,lA).call(i,{drawOutlines:h}),F(s=d,Je,Xp).call(s),d.onScaleChanging(),d.rotate(),d}serializeDraw(t){const[e,r]=this.pageTranslation,[i,s]=this.pageDimensions;return u(this,ti).serialize([e,r,i,s],t)}renderAnnotationElement(t){return t.updateEdited({rect:this.getPDFRect()}),null}static canCreateNewEmptyEditor(){return!1}};ti=new WeakMap,Hp=new WeakMap,ur=new WeakMap,pd=new WeakMap,gd=new WeakMap,Je=new WeakSet,lA=function({drawOutlines:n,drawId:t,drawingOptions:e}){w(this,ti,n),this._drawingOptions||(this._drawingOptions=e),this.annotationElementId||this._uiManager.a11yAlert(`pdfjs-editor-${this.editorType}-added-alert`),t>=0?(this._drawId=t,this.parent.drawLayer.finalizeDraw(t,n.defaultProperties)):this._drawId=F(this,Je,e2).call(this,n,this.parent),F(this,Je,Ug).call(this,n.box)},e2=function(n,t){const{id:e}=t.drawLayer.draw(Ko._mergeSVGProperties(this._drawingOptions.toSVGProperties(),n.defaultSVGProperties),!1,!1);return e},cA=function(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())},Xp=function(n=this.parent){if(!(this._drawId!==null&&this.parent===n)){if(this._drawId!==null){this.parent.drawLayer.updateParent(this._drawId,n.drawLayer);return}this._drawingOptions.updateAll(),this._drawId=F(this,Je,e2).call(this,u(this,ti),n)}},M6=function([n,t,e,r]){const{parentDimensions:[i,s],rotation:a}=this;switch(a){case 90:return[t,1-n,e*(s/i),r*(i/s)];case 180:return[1-n,1-t,e,r];case 270:return[1-t,n,e*(s/i),r*(i/s)];default:return[n,t,e,r]}},J1=function(){const{x:n,y:t,width:e,height:r,parentDimensions:[i,s],rotation:a}=this;switch(a){case 90:return[1-t,n,e*(i/s),r*(s/i)];case 180:return[1-n,1-t,e,r];case 270:return[t,1-n,e*(i/s),r*(s/i)];default:return[n,t,e,r]}},Ug=function(n){[this.x,this.y,this.width,this.height]=F(this,Je,M6).call(this,n),this.div&&(this.fixAndSetPosition(),this.setDims()),this._onResized()},Vu=function(){const{x:n,y:t,width:e,height:r,rotation:i,parentRotation:s,parentDimensions:[a,o]}=this;switch((i*4+s)/90){case 1:return[1-t-r,n,r,e];case 2:return[1-n-e,1-t-r,e,r];case 3:return[t,1-n-e,r,e];case 4:return[n,t-e*(a/o),r*(o/a),e*(a/o)];case 5:return[1-t,n,e*(a/o),r*(o/a)];case 6:return[1-n-r*(o/a),1-t,r*(o/a),e*(a/o)];case 7:return[t-e*(a/o),1-n-r*(o/a),e*(a/o),r*(o/a)];case 8:return[n-e,t-r,e,r];case 9:return[1-t,n-e,r,e];case 10:return[1-n,1-t,e,r];case 11:return[t-r,1-n,r,e];case 12:return[n-r*(o/a),t,r*(o/a),e*(a/o)];case 13:return[1-t-e*(a/o),n-r*(o/a),e*(a/o),r*(o/a)];case 14:return[1-n,1-t-e*(a/o),r*(o/a),e*(a/o)];case 15:return[t,1-n,e*(a/o),r*(o/a)];default:return[n,t,e,r]}},J(Ko,"_currentDrawId",-1),J(Ko,"_currentParent",null),C(Ko,ur,null),C(Ko,pd,null),C(Ko,gd,null),J(Ko,"_INNER_MARGIN",3);let wF=Ko;var ja,lr,cr,md,Kp,Zr,hr,ks,Gu,yd,vd,_p,Q1;class I_{constructor(t,e,r,i,s,a){C(this,_p),C(this,ja,new Float64Array(6)),C(this,lr),C(this,cr),C(this,md),C(this,Kp),C(this,Zr),C(this,hr,""),C(this,ks,0),C(this,Gu,new Fm),C(this,yd),C(this,vd),w(this,yd,r),w(this,vd,i),w(this,md,s),w(this,Kp,a),[t,e]=F(this,_p,Q1).call(this,t,e);const o=w(this,lr,[NaN,NaN,NaN,NaN,t,e]);w(this,Zr,[t,e]),w(this,cr,[{line:o,points:u(this,Zr)}]),u(this,ja).set(o,0)}updateProperty(t,e){t==="stroke-width"&&w(this,Kp,e)}isEmpty(){return!u(this,cr)||u(this,cr).length===0}isCancellable(){return u(this,Zr).length<=10}add(t,e){[t,e]=F(this,_p,Q1).call(this,t,e);const[r,i,s,a]=u(this,ja).subarray(2,6),o=t-s,l=e-a;return Math.hypot(u(this,yd)*o,u(this,vd)*l)<=2?null:(u(this,Zr).push(t,e),isNaN(r)?(u(this,ja).set([s,a,t,e],2),u(this,lr).push(NaN,NaN,NaN,NaN,t,e),{path:{d:this.toSVGPath()}}):(isNaN(u(this,ja)[0])&&u(this,lr).splice(6,6),u(this,ja).set([r,i,s,a,t,e],0),u(this,lr).push(...Ft.createBezierPoints(r,i,s,a,t,e)),{path:{d:this.toSVGPath()}}))}end(t,e){return this.add(t,e)||(u(this,Zr).length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,r,i,s){w(this,yd,r),w(this,vd,i),w(this,md,s),[t,e]=F(this,_p,Q1).call(this,t,e);const a=w(this,lr,[NaN,NaN,NaN,NaN,t,e]);w(this,Zr,[t,e]);const o=u(this,cr).at(-1);return o&&(o.line=new Float32Array(o.line),o.points=new Float32Array(o.points)),u(this,cr).push({line:a,points:u(this,Zr)}),u(this,ja).set(a,0),w(this,ks,0),this.toSVGPath(),null}getLastElement(){return u(this,cr).at(-1)}setLastElement(t){return u(this,cr)?(u(this,cr).push(t),w(this,lr,t.line),w(this,Zr,t.points),w(this,ks,0),{path:{d:this.toSVGPath()}}):u(this,Gu).setLastElement(t)}removeLastElement(){if(!u(this,cr))return u(this,Gu).removeLastElement();u(this,cr).pop(),w(this,hr,"");for(let t=0,e=u(this,cr).length;t<e;t++){const{line:r,points:i}=u(this,cr)[t];w(this,lr,r),w(this,Zr,i),w(this,ks,0),this.toSVGPath()}return{path:{d:u(this,hr)}}}toSVGPath(){const t=Ft.svgRound(u(this,lr)[4]),e=Ft.svgRound(u(this,lr)[5]);if(u(this,Zr).length===2)return w(this,hr,`${u(this,hr)} M ${t} ${e} Z`),u(this,hr);if(u(this,Zr).length<=6){const i=u(this,hr).lastIndexOf("M");w(this,hr,`${u(this,hr).slice(0,i)} M ${t} ${e}`),w(this,ks,6)}if(u(this,Zr).length===4){const i=Ft.svgRound(u(this,lr)[10]),s=Ft.svgRound(u(this,lr)[11]);return w(this,hr,`${u(this,hr)} L ${i} ${s}`),w(this,ks,12),u(this,hr)}const r=[];u(this,ks)===0&&(r.push(`M ${t} ${e}`),w(this,ks,6));for(let i=u(this,ks),s=u(this,lr).length;i<s;i+=6){const[a,o,l,c,h,d]=u(this,lr).slice(i,i+6).map(Ft.svgRound);r.push(`C${a} ${o} ${l} ${c} ${h} ${d}`)}return w(this,hr,u(this,hr)+r.join(" ")),w(this,ks,u(this,lr).length),u(this,hr)}getOutlines(t,e,r,i){const s=u(this,cr).at(-1);return s.line=new Float32Array(s.line),s.points=new Float32Array(s.points),u(this,Gu).build(u(this,cr),t,e,r,u(this,md),u(this,Kp),i),w(this,ja,null),w(this,lr,null),w(this,cr,null),w(this,hr,null),u(this,Gu)}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}ja=new WeakMap,lr=new WeakMap,cr=new WeakMap,md=new WeakMap,Kp=new WeakMap,Zr=new WeakMap,hr=new WeakMap,ks=new WeakMap,Gu=new WeakMap,yd=new WeakMap,vd=new WeakMap,_p=new WeakSet,Q1=function(n,t){return Ft._normalizePoint(n,t,u(this,yd),u(this,vd),u(this,md))};var ei,$1,kv,Ui,to,eo,Vg,Gg,jd,mi,oo,xF,AF,SF;class Fm extends Ft{constructor(){super(...arguments),C(this,mi),C(this,ei),C(this,$1,0),C(this,kv),C(this,Ui),C(this,to),C(this,eo),C(this,Vg),C(this,Gg),C(this,jd)}build(t,e,r,i,s,a,o){w(this,to,e),w(this,eo,r),w(this,Vg,i),w(this,Gg,s),w(this,jd,a),w(this,kv,o??0),w(this,Ui,t),F(this,mi,AF).call(this)}get thickness(){return u(this,jd)}setLastElement(t){return u(this,Ui).push(t),{path:{d:this.toSVGPath()}}}removeLastElement(){return u(this,Ui).pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const t=[];for(const{line:e}of u(this,Ui)){if(t.push(`M${Ft.svgRound(e[4])} ${Ft.svgRound(e[5])}`),e.length===6){t.push("Z");continue}if(e.length===12&&isNaN(e[6])){t.push(`L${Ft.svgRound(e[10])} ${Ft.svgRound(e[11])}`);continue}for(let r=6,i=e.length;r<i;r+=6){const[s,a,o,l,c,h]=e.subarray(r,r+6).map(Ft.svgRound);t.push(`C${s} ${a} ${o} ${l} ${c} ${h}`)}}return t.join("")}serialize([t,e,r,i],s){const a=[],o=[],[l,c,h,d]=F(this,mi,xF).call(this);let p,g,m,y,v,b,S,k,P;switch(u(this,Gg)){case 0:P=Ft._rescale,p=t,g=e+i,m=r,y=-i,v=t+l*r,b=e+(1-c-d)*i,S=t+(l+h)*r,k=e+(1-c)*i;break;case 90:P=Ft._rescaleAndSwap,p=t,g=e,m=r,y=i,v=t+c*r,b=e+l*i,S=t+(c+d)*r,k=e+(l+h)*i;break;case 180:P=Ft._rescale,p=t+r,g=e,m=-r,y=i,v=t+(1-l-h)*r,b=e+c*i,S=t+(1-l)*r,k=e+(c+d)*i;break;case 270:P=Ft._rescaleAndSwap,p=t+r,g=e+i,m=-r,y=-i,v=t+(1-c-d)*r,b=e+(1-l-h)*i,S=t+(1-c)*r,k=e+(1-l)*i;break}for(const{line:T,points:M}of u(this,Ui))a.push(P(T,p,g,m,y,s?new Array(T.length):null)),o.push(P(M,p,g,m,y,s?new Array(M.length):null));return{lines:a,points:o,rect:[v,b,S,k]}}static deserialize(t,e,r,i,s,{paths:{lines:a,points:o},rotation:l,thickness:c}){const h=[];let d,p,g,m,y;switch(l){case 0:y=Ft._rescale,d=-t/r,p=e/i+1,g=1/r,m=-1/i;break;case 90:y=Ft._rescaleAndSwap,d=-e/i,p=-t/r,g=1/i,m=1/r;break;case 180:y=Ft._rescale,d=t/r+1,p=-e/i,g=-1/r,m=1/i;break;case 270:y=Ft._rescaleAndSwap,d=e/i+1,p=t/r+1,g=-1/i,m=-1/r;break}if(!a){a=[];for(const b of o){const S=b.length;if(S===2){a.push(new Float32Array([NaN,NaN,NaN,NaN,b[0],b[1]]));continue}if(S===4){a.push(new Float32Array([NaN,NaN,NaN,NaN,b[0],b[1],NaN,NaN,NaN,NaN,b[2],b[3]]));continue}const k=new Float32Array(3*(S-2));a.push(k);let[P,T,M,D]=b.subarray(0,4);k.set([NaN,NaN,NaN,NaN,P,T],0);for(let L=4;L<S;L+=2){const W=b[L],z=b[L+1];k.set(Ft.createBezierPoints(P,T,M,D,W,z),(L-2)*3),[P,T,M,D]=[M,D,W,z]}}}for(let b=0,S=a.length;b<S;b++)h.push({line:y(a[b].map(k=>k??NaN),d,p,g,m),points:y(o[b].map(k=>k??NaN),d,p,g,m)});const v=new this.prototype.constructor;return v.build(h,r,i,1,l,c,s),v}get box(){return u(this,ei)}updateProperty(t,e){return t==="stroke-width"?F(this,mi,SF).call(this,e):null}updateParentDimensions([t,e],r){const[i,s]=F(this,mi,oo).call(this);w(this,to,t),w(this,eo,e),w(this,Vg,r);const[a,o]=F(this,mi,oo).call(this),l=a-i,c=o-s,h=u(this,ei);return h[0]-=l,h[1]-=c,h[2]+=2*l,h[3]+=2*c,h}updateRotation(t){return w(this,$1,t),{path:{transform:this.rotationTransform}}}get viewBox(){return u(this,ei).map(Ft.svgRound).join(" ")}get defaultProperties(){const[t,e]=u(this,ei);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Ft.svgRound(t)} ${Ft.svgRound(e)}`}}}get rotationTransform(){const[,,t,e]=u(this,ei);let r=0,i=0,s=0,a=0,o=0,l=0;switch(u(this,$1)){case 90:i=e/t,s=-t/e,o=t;break;case 180:r=-1,a=-1,o=t,l=e;break;case 270:i=-e/t,s=t/e,l=e;break;default:return""}return`matrix(${r} ${i} ${s} ${a} ${Ft.svgRound(o)} ${Ft.svgRound(l)})`}getPathResizingSVGProperties([t,e,r,i]){const[s,a]=F(this,mi,oo).call(this),[o,l,c,h]=u(this,ei);if(Math.abs(c-s)<=Ft.PRECISION||Math.abs(h-a)<=Ft.PRECISION){const y=t+r/2-(o+c/2),v=e+i/2-(l+h/2);return{path:{"transform-origin":`${Ft.svgRound(t)} ${Ft.svgRound(e)}`,transform:`${this.rotationTransform} translate(${y} ${v})`}}}const d=(r-2*s)/(c-2*s),p=(i-2*a)/(h-2*a),g=c/r,m=h/i;return{path:{"transform-origin":`${Ft.svgRound(o)} ${Ft.svgRound(l)}`,transform:`${this.rotationTransform} scale(${g} ${m}) translate(${Ft.svgRound(s)} ${Ft.svgRound(a)}) scale(${d} ${p}) translate(${Ft.svgRound(-s)} ${Ft.svgRound(-a)})`}}}getPathResizedSVGProperties([t,e,r,i]){const[s,a]=F(this,mi,oo).call(this),o=u(this,ei),[l,c,h,d]=o;if(o[0]=t,o[1]=e,o[2]=r,o[3]=i,Math.abs(h-s)<=Ft.PRECISION||Math.abs(d-a)<=Ft.PRECISION){const v=t+r/2-(l+h/2),b=e+i/2-(c+d/2);for(const{line:S,points:k}of u(this,Ui))Ft._translate(S,v,b,S),Ft._translate(k,v,b,k);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Ft.svgRound(t)} ${Ft.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const p=(r-2*s)/(h-2*s),g=(i-2*a)/(d-2*a),m=-p*(l+s)+t+s,y=-g*(c+a)+e+a;if(p!==1||g!==1||m!==0||y!==0)for(const{line:v,points:b}of u(this,Ui))Ft._rescale(v,m,y,p,g,v),Ft._rescale(b,m,y,p,g,b);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Ft.svgRound(t)} ${Ft.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([t,e],r){const[i,s]=r,a=u(this,ei),o=t-a[0],l=e-a[1];if(u(this,to)===i&&u(this,eo)===s)for(const{line:c,points:h}of u(this,Ui))Ft._translate(c,o,l,c),Ft._translate(h,o,l,h);else{const c=u(this,to)/i,h=u(this,eo)/s;w(this,to,i),w(this,eo,s);for(const{line:d,points:p}of u(this,Ui))Ft._rescale(d,o,l,c,h,d),Ft._rescale(p,o,l,c,h,p);a[2]*=c,a[3]*=h}return a[0]=t,a[1]=e,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${Ft.svgRound(t)} ${Ft.svgRound(e)}`}}}get defaultSVGProperties(){const t=u(this,ei);return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${Ft.svgRound(t[0])} ${Ft.svgRound(t[1])}`,transform:this.rotationTransform||null},bbox:t}}}ei=new WeakMap,$1=new WeakMap,kv=new WeakMap,Ui=new WeakMap,to=new WeakMap,eo=new WeakMap,Vg=new WeakMap,Gg=new WeakMap,jd=new WeakMap,mi=new WeakSet,oo=function(n=u(this,jd)){const t=u(this,kv)+n/2*u(this,Vg);return u(this,Gg)%180===0?[t/u(this,to),t/u(this,eo)]:[t/u(this,eo),t/u(this,to)]},xF=function(){const[n,t,e,r]=u(this,ei),[i,s]=F(this,mi,oo).call(this,0);return[n+i,t+s,e-2*i,r-2*s]},AF=function(){const n=w(this,ei,ah.slice());for(const{line:r}of u(this,Ui)){if(r.length<=12){for(let a=4,o=r.length;a<o;a+=6)ft.pointBoundingBox(r[a],r[a+1],n);continue}let i=r[4],s=r[5];for(let a=6,o=r.length;a<o;a+=6){const[l,c,h,d,p,g]=r.subarray(a,a+6);ft.bezierBoundingBox(i,s,l,c,h,d,p,g,n),i=p,s=g}}const[t,e]=F(this,mi,oo).call(this);n[0]=en(n[0]-t,0,1),n[1]=en(n[1]-e,0,1),n[2]=en(n[2]+t,0,1),n[3]=en(n[3]+e,0,1),n[2]-=n[0],n[3]-=n[1]},SF=function(n){const[t,e]=F(this,mi,oo).call(this);w(this,jd,n);const[r,i]=F(this,mi,oo).call(this),[s,a]=[r-t,i-e],o=u(this,ei);return o[0]-=s,o[1]-=a,o[2]+=2*s,o[3]+=2*a,o};class Ob extends bF{constructor(t){super(),this._viewParameters=t,super.updateProperties({fill:"none",stroke:on._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(t,e){t==="stroke-width"&&(e??(e=this["stroke-width"]),e*=this._viewParameters.realScale),super.updateSVGProperty(t,e)}clone(){const t=new Ob(this._viewParameters);return t.updateAll(this),t}}var hA,kF;const t0=class CF extends wF{constructor(t){super({...t,name:"inkEditor"}),C(this,hA),this._willKeepAspectRatio=!0,this.defaultL10nId="pdfjs-editor-ink-editor"}static initialize(t,e){on.initialize(t,e),this._defaultDrawingOptions=new Ob(e.viewParameters)}static getDefaultDrawingOptions(t){const e=this._defaultDrawingOptions.clone();return e.updateProperties(t),e}static get supportMultipleDrawings(){return!0}static get typesMap(){return se(this,"typesMap",new Map([[ce.INK_THICKNESS,"stroke-width"],[ce.INK_COLOR,"stroke"],[ce.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(t,e,r,i,s){return new I_(t,e,r,i,s,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(t,e,r,i,s,a){return Fm.deserialize(t,e,r,i,s,a)}static async deserialize(t,e,r){let i=null;if(t instanceof t5){const{data:{inkLists:a,rect:o,rotation:l,id:c,color:h,opacity:d,borderStyle:{rawWidth:p},popupRef:g,richText:m,contentsObj:y,creationDate:v,modificationDate:b},parent:{page:{pageNumber:S}}}=t;i=t={annotationType:te.INK,color:Array.from(h),thickness:p,opacity:d,paths:{points:a},boxes:null,pageIndex:S-1,rect:o.slice(0),rotation:l,annotationElementId:c,id:c,deleted:!1,popupRef:g,richText:m,comment:(y==null?void 0:y.str)||null,creationDate:v,modificationDate:b}}const s=await super.deserialize(t,e,r);return s._initialData=i,t.comment&&s.setCommentData(t),s}get toolbarButtons(){return this._colorPicker||(this._colorPicker=new BP(this)),[["colorPicker",this._colorPicker]]}get colorType(){return ce.INK_COLOR}get colorAndOpacityType(){return ce.INK_COLOR_AND_OPACITY}get opacityType(){return ce.INK_OPACITY}updateParams(t,e){if(t===ce.INK_COLOR_AND_OPACITY){this._updateColorAndOpacity(e.color,e.opacity);return}super.updateParams(t,e)}static updateDefaultParams(t,e){if(t===ce.INK_COLOR_AND_OPACITY){super.updateDefaultParams(ce.INK_COLOR,e.color),super.updateDefaultParams(ce.INK_OPACITY,e.opacity);return}super.updateDefaultParams(t,e)}get color(){return this._drawingOptions.stroke}get opacity(){return this._drawingOptions["stroke-opacity"]}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();const{_drawId:t,_drawingOptions:e,parent:r}=this;e.updateSVGProperty("stroke-width"),r.drawLayer.updateProperties(t,e.toSVGProperties())}static onScaleChangingWhenDrawing(){const t=this._currentParent;t&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),t.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:t,thickness:e,opacity:r}){this._drawingOptions=CF.getDefaultDrawingOptions({stroke:ft.makeHexColor(...t),"stroke-width":e,"stroke-opacity":r})}serialize(t=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:e,points:r}=this.serializeDraw(t),{_drawingOptions:{stroke:i,"stroke-opacity":s,"stroke-width":a}}=this,o=Object.assign(super.serialize(t),{color:on._colorManager.convert(i),opacity:s,thickness:a,paths:{lines:e,points:r}});return this.addComment(o),t?(o.isCopy=!0,o):this.annotationElementId&&!F(this,hA,kF).call(this,o)?null:(o.id=this.annotationElementId,o)}renderAnnotationElement(t){if(this.deleted)return t.hide(),null;const{points:e,rect:r}=this.serializeDraw(!1);return t.updateEdited({rect:r,thickness:this._drawingOptions["stroke-width"],points:e,popup:this.comment}),null}};hA=new WeakSet,kF=function(n){const{color:t,thickness:e,opacity:r,pageIndex:i}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized||n.color.some((s,a)=>s!==t[a])||n.thickness!==e||n.opacity!==r||n.pageIndex!==i},J(t0,"_type","ink"),J(t0,"_editorType",te.INK),J(t0,"_defaultDrawingOptions",null);let O_=t0;class uA extends Fm{toSVGPath(){let t=super.toSVGPath();return t.endsWith("Z")||(t+="Z"),t}}const vy=8,Mf=3;var zd,Zn,n2,Us,P6,F6,dA,by,TF,MF,PF,fA,pA,FF;class fa{static extractContoursFromText(t,{fontFamily:e,fontStyle:r,fontWeight:i},s,a,o,l){let c=new OffscreenCanvas(1,1),h=c.getContext("2d",{alpha:!1});const d=200,p=h.font=`${r} ${i} ${d}px ${e}`,{actualBoundingBoxLeft:g,actualBoundingBoxRight:m,actualBoundingBoxAscent:y,actualBoundingBoxDescent:v,fontBoundingBoxAscent:b,fontBoundingBoxDescent:S,width:k}=h.measureText(t),P=1.5,T=Math.ceil(Math.max(Math.abs(g)+Math.abs(m)||0,k)*P),M=Math.ceil(Math.max(Math.abs(y)+Math.abs(v)||d,Math.abs(b)+Math.abs(S)||d)*P);c=new OffscreenCanvas(T,M),h=c.getContext("2d",{alpha:!0,willReadFrequently:!0}),h.font=p,h.filter="grayscale(1)",h.fillStyle="white",h.fillRect(0,0,T,M),h.fillStyle="black",h.fillText(t,T*(P-1)/2,M*(3-P)/2);const D=F(this,Zn,fA).call(this,h.getImageData(0,0,T,M).data),L=F(this,Zn,PF).call(this,D),W=F(this,Zn,pA).call(this,L),z=F(this,Zn,dA).call(this,D,T,M,W);return this.processDrawnLines({lines:{curves:z,width:T,height:M},pageWidth:s,pageHeight:a,rotation:o,innerMargin:l,mustSmooth:!0,areContours:!0})}static process(t,e,r,i,s){const[a,o,l]=F(this,Zn,FF).call(this,t),[c,h]=F(this,Zn,MF).call(this,a,o,l,Math.hypot(o,l)*u(this,zd).sigmaSFactor,u(this,zd).sigmaR,u(this,zd).kernelSize),d=F(this,Zn,pA).call(this,h),p=F(this,Zn,dA).call(this,c,o,l,d);return this.processDrawnLines({lines:{curves:p,width:o,height:l},pageWidth:e,pageHeight:r,rotation:i,innerMargin:s,mustSmooth:!0,areContours:!0})}static processDrawnLines({lines:t,pageWidth:e,pageHeight:r,rotation:i,innerMargin:s,mustSmooth:a,areContours:o}){i%180!==0&&([e,r]=[r,e]);const{curves:l,width:c,height:h}=t,d=t.thickness??0,p=[],g=Math.min(e/c,r/h),m=g/e,y=g/r,v=[];for(const{points:S}of l){const k=a?F(this,Zn,TF).call(this,S):S;if(!k)continue;v.push(k);const P=k.length,T=new Float32Array(P),M=new Float32Array(3*(P===2?2:P-2));if(p.push({line:M,points:T}),P===2){T[0]=k[0]*m,T[1]=k[1]*y,M.set([NaN,NaN,NaN,NaN,T[0],T[1]],0);continue}let[D,L,W,z]=k;D*=m,L*=y,W*=m,z*=y,T.set([D,L,W,z],0),M.set([NaN,NaN,NaN,NaN,D,L],0);for(let V=4;V<P;V+=2){const X=T[V]=k[V]*m,U=T[V+1]=k[V+1]*y;M.set(Ft.createBezierPoints(D,L,W,z,X,U),(V-2)*3),[D,L,W,z]=[W,z,X,U]}}if(p.length===0)return null;const b=o?new uA:new Fm;return b.build(p,e,r,1,i,o?0:d,s),{outline:b,newCurves:v,areContours:o,thickness:d,width:c,height:h}}static async compressSignature({outlines:t,areContours:e,thickness:r,width:i,height:s}){let a=1/0,o=-1/0,l=0;for(const b of t){l+=b.length;for(let S=2,k=b.length;S<k;S++){const P=b[S]-b[S-2];a=Math.min(a,P),o=Math.max(o,P)}}let c;a>=-128&&o<=127?c=Int8Array:a>=-32768&&o<=32767?c=Int16Array:c=Int32Array;const h=t.length,d=vy+Mf*h,p=new Uint32Array(d);let g=0;p[g++]=d*Uint32Array.BYTES_PER_ELEMENT+(l-2*h)*c.BYTES_PER_ELEMENT,p[g++]=0,p[g++]=i,p[g++]=s,p[g++]=e?0:1,p[g++]=Math.max(0,Math.floor(r??0)),p[g++]=h,p[g++]=c.BYTES_PER_ELEMENT;for(const b of t)p[g++]=b.length-2,p[g++]=b[0],p[g++]=b[1];const m=new CompressionStream("deflate-raw"),y=m.writable.getWriter();await y.ready,y.write(p);const v=c.prototype.constructor;for(const b of t){const S=new v(b.length-2);for(let k=2,P=b.length;k<P;k++)S[k-2]=b[k]-b[k-2];y.write(S)}return y.close(),(await new Response(m.readable).bytes()).toBase64()}static async decompressSignature(t){try{const e=Uint8Array.fromBase64(t),{readable:r,writable:i}=new DecompressionStream("deflate-raw"),s=i.getWriter();await s.ready,s.write(e).then(async()=>{await s.ready,await s.close()}).catch(()=>{});let a=null,o=0;for await(const k of r)a||(a=new Uint8Array(new Uint32Array(k.buffer,0,4)[0])),a.set(k,o),o+=k.length;const l=new Uint32Array(a.buffer,0,a.length>>2),c=l[1];if(c!==0)throw new Error(`Invalid version: ${c}`);const h=l[2],d=l[3],p=l[4]===0,g=l[5],m=l[6],y=l[7],v=[],b=(vy+Mf*m)*Uint32Array.BYTES_PER_ELEMENT;let S;switch(y){case Int8Array.BYTES_PER_ELEMENT:S=new Int8Array(a.buffer,b);break;case Int16Array.BYTES_PER_ELEMENT:S=new Int16Array(a.buffer,b);break;case Int32Array.BYTES_PER_ELEMENT:S=new Int32Array(a.buffer,b);break}o=0;for(let k=0;k<m;k++){const P=l[Mf*k+vy],T=new Float32Array(P+2);v.push(T);for(let M=0;M<Mf-1;M++)T[M]=l[Mf*k+vy+M+1];for(let M=0;M<P;M++)T[M+2]=T[M]+S[o++]}return{areContours:p,thickness:g,outlines:v,width:h,height:d}}catch(e){return he(`decompressSignature: ${e}`),null}}}zd=new WeakMap,Zn=new WeakSet,n2=function(n,t,e,r){return e-=n,r-=t,e===0?r>0?0:4:e===1?r+6:2-r},Us=new WeakMap,P6=function(n,t,e,r,i,s,a){const o=F(this,Zn,n2).call(this,e,r,i,s);for(let l=0;l<8;l++){const c=(-l+o-a+16)%8,h=u(this,Us)[2*c],d=u(this,Us)[2*c+1];if(n[(e+h)*t+(r+d)]!==0)return c}return-1},F6=function(n,t,e,r,i,s,a){const o=F(this,Zn,n2).call(this,e,r,i,s);for(let l=0;l<8;l++){const c=(l+o+a+16)%8,h=u(this,Us)[2*c],d=u(this,Us)[2*c+1];if(n[(e+h)*t+(r+d)]!==0)return c}return-1},dA=function(n,t,e,r){const i=n.length,s=new Int32Array(i);for(let c=0;c<i;c++)s[c]=n[c]<=r?1:0;for(let c=1;c<e-1;c++)s[c*t]=s[c*t+t-1]=0;for(let c=0;c<t;c++)s[c]=s[t*e-1-c]=0;let a=1,o;const l=[];for(let c=1;c<e-1;c++){o=1;for(let h=1;h<t-1;h++){const d=c*t+h,p=s[d];if(p===0)continue;let g=c,m=h;if(p===1&&s[d-1]===0)a+=1,m-=1;else if(p>=1&&s[d+1]===0)a+=1,m+=1,p>1&&(o=p);else{p!==1&&(o=Math.abs(p));continue}const y=[h,c],v=m===h+1,b={isHole:v,points:y,id:a,parent:0};l.push(b);let S;for(const z of l)if(z.id===o){S=z;break}S?S.isHole?b.parent=v?S.parent:o:b.parent=v?o:S.parent:b.parent=v?o:0;const k=F(this,Zn,P6).call(this,s,t,c,h,g,m,0);if(k===-1){s[d]=-a,s[d]!==1&&(o=Math.abs(s[d]));continue}let P=u(this,Us)[2*k],T=u(this,Us)[2*k+1];const M=c+P,D=h+T;g=M,m=D;let L=c,W=h;for(;;){const z=F(this,Zn,F6).call(this,s,t,L,W,g,m,1);P=u(this,Us)[2*z],T=u(this,Us)[2*z+1];const V=L+P,X=W+T;y.push(X,V);const U=L*t+W;if(s[U+1]===0?s[U]=-a:s[U]===1&&(s[U]=a),V===c&&X===h&&L===M&&W===D){s[d]!==1&&(o=Math.abs(s[d]));break}else g=L,m=W,L=V,W=X}}}return l},by=function(n,t,e,r){if(e-t<=4){for(let M=t;M<e-2;M+=2)r.push(n[M],n[M+1]);return}const i=n[t],s=n[t+1],a=n[e-4]-i,o=n[e-3]-s,l=Math.hypot(a,o),c=a/l,h=o/l,d=c*s-h*i,p=o/a,g=1/l,m=Math.atan(p),y=Math.cos(m),v=Math.sin(m),b=g*(Math.abs(y)+Math.abs(v)),S=g*(1-b+b**2),k=Math.max(Math.atan(Math.abs(v+y)*S),Math.atan(Math.abs(v-y)*S));let P=0,T=t;for(let M=t+2;M<e-2;M+=2){const D=Math.abs(d-c*n[M+1]+h*n[M]);D>P&&(T=M,P=D)}P>(l*k)**2?(F(this,Zn,by).call(this,n,t,T+2,r),F(this,Zn,by).call(this,n,T,e,r)):r.push(i,s)},TF=function(n){const t=[],e=n.length;return F(this,Zn,by).call(this,n,0,e,t),t.push(n[e-2],n[e-1]),t.length<=4?null:t},MF=function(n,t,e,r,i,s){const a=new Float32Array(s**2),o=-2*r**2,l=s>>1;for(let m=0;m<s;m++){const y=(m-l)**2;for(let v=0;v<s;v++)a[m*s+v]=Math.exp((y+(v-l)**2)/o)}const c=new Float32Array(256),h=-2*i**2;for(let m=0;m<256;m++)c[m]=Math.exp(m**2/h);const d=n.length,p=new Uint8Array(d),g=new Uint32Array(256);for(let m=0;m<e;m++)for(let y=0;y<t;y++){const v=m*t+y,b=n[v];let S=0,k=0;for(let T=0;T<s;T++){const M=m+T-l;if(!(M<0||M>=e))for(let D=0;D<s;D++){const L=y+D-l;if(L<0||L>=t)continue;const W=n[M*t+L],z=a[T*s+D]*c[Math.abs(W-b)];S+=W*z,k+=z}}const P=p[v]=Math.round(S/k);g[P]++}return[p,g]},PF=function(n){const t=new Uint32Array(256);for(const e of n)t[e]++;return t},fA=function(n){const t=n.length,e=new Uint8ClampedArray(t>>2);let r=-1/0,i=1/0;for(let a=0,o=e.length;a<o;a++){const l=e[a]=n[a<<2];r=Math.max(r,l),i=Math.min(i,l)}const s=255/(r-i);for(let a=0,o=e.length;a<o;a++)e[a]=(e[a]-i)*s;return e},pA=function(n){let t,e=-1/0,r=-1/0;const i=n.findIndex(o=>o!==0);let s=i,a=i;for(t=i;t<256;t++){const o=n[t];o>e&&(t-s>r&&(r=t-s,a=t-1),e=o,s=t)}for(t=a-1;t>=0&&!(n[t]>n[t+1]);t--);return t},FF=function(n){const t=n,{width:e,height:r}=n,{maxDim:i}=u(this,zd);let s=e,a=r;if(e>i||r>i){let c=e,h=r,d=Math.log2(Math.max(e,r)/i);const p=Math.floor(d);d=d===p?p-1:p;for(let m=0;m<d;m++){s=Math.ceil(c/2),a=Math.ceil(h/2);const y=new OffscreenCanvas(s,a);y.getContext("2d").drawImage(n,0,0,c,h,0,0,s,a),c=s,h=a,n!==t&&n.close(),n=y.transferToImageBitmap()}const g=Math.min(i/s,i/a);s=Math.round(s*g),a=Math.round(a*g)}const o=new OffscreenCanvas(s,a).getContext("2d",{willReadFrequently:!0});o.fillStyle="white",o.fillRect(0,0,s,a),o.filter="grayscale(1)",o.drawImage(n,0,0,n.width,n.height,0,0,s,a);const l=o.getImageData(0,0,s,a).data;return[F(this,Zn,fA).call(this,l),s,a]},C(fa,Zn),C(fa,zd,{maxDim:512,sigmaSFactor:.02,sigmaR:25,kernelSize:16}),C(fa,Us,new Int32Array([0,1,-1,1,-1,0,-1,-1,0,-1,1,-1,1,0,1,1]));class e5 extends bF{constructor(){super(),super.updateProperties({fill:on._defaultLineColor,"stroke-width":0})}clone(){const t=new e5;return t.updateAll(this),t}}class n5 extends Ob{constructor(t){super(t),super.updateProperties({stroke:on._defaultLineColor,"stroke-width":1})}clone(){const t=new n5(this._viewParameters);return t.updateAll(this),t}}var Lc,za,Wc,qu;const e0=class Ua extends wF{constructor(t){super({...t,mustBeCommitted:!0,name:"signatureEditor"}),C(this,Lc,!1),C(this,za,null),C(this,Wc,null),C(this,qu,null),this._willKeepAspectRatio=!0,w(this,Wc,t.signatureData||null),w(this,za,null),this.defaultL10nId="pdfjs-editor-signature-editor1"}static initialize(t,e){on.initialize(t,e),this._defaultDrawingOptions=new e5,this._defaultDrawnSignatureOptions=new n5(e.viewParameters)}static getDefaultDrawingOptions(t){const e=this._defaultDrawingOptions.clone();return e.updateProperties(t),e}static get supportMultipleDrawings(){return!1}static get typesMap(){return se(this,"typesMap",new Map)}static get isDrawer(){return!1}get telemetryFinalData(){return{type:"signature",hasDescription:!!u(this,za)}}static computeTelemetryFinalData(t){const e=t.get("hasDescription");return{hasAltText:e.get(!0)??0,hasNoAltText:e.get(!1)??0}}get isResizable(){return!0}onScaleChanging(){this._drawId!==null&&super.onScaleChanging()}render(){if(this.div)return this.div;let t,e;const{_isCopy:r}=this;if(r&&(this._isCopy=!1,t=this.x,e=this.y),super.render(),this._drawId===null)if(u(this,Wc)){const{lines:i,mustSmooth:s,areContours:a,description:o,uuid:l,heightInPage:c}=u(this,Wc),{rawDims:{pageWidth:h,pageHeight:d},rotation:p}=this.parent.viewport,g=fa.processDrawnLines({lines:i,pageWidth:h,pageHeight:d,rotation:p,innerMargin:Ua._INNER_MARGIN,mustSmooth:s,areContours:a});this.addSignature(g,c,o,l)}else this.div.setAttribute("data-l10n-args",JSON.stringify({description:""})),this.div.hidden=!0,this._uiManager.getSignature(this);else this.div.setAttribute("data-l10n-args",JSON.stringify({description:u(this,za)||""}));return r&&(this._isCopy=!0,this._moveAfterPaste(t,e)),this.div}setUuid(t){w(this,qu,t),this.addEditToolbar()}getUuid(){return u(this,qu)}get description(){return u(this,za)}set description(t){w(this,za,t),this.div&&(this.div.setAttribute("data-l10n-args",JSON.stringify({description:t})),super.addEditToolbar().then(e=>{e==null||e.updateEditSignatureButton(t)}))}getSignaturePreview(){const{newCurves:t,areContours:e,thickness:r,width:i,height:s}=u(this,Wc),a=Math.max(i,s),o=fa.processDrawnLines({lines:{curves:t.map(l=>({points:l})),thickness:r,width:i,height:s},pageWidth:a,pageHeight:a,rotation:0,innerMargin:0,mustSmooth:!1,areContours:e});return{areContours:e,outline:o.outline}}get toolbarButtons(){return this._uiManager.signatureManager?[["editSignature",this._uiManager.signatureManager]]:super.toolbarButtons}addSignature(t,e,r,i){const{x:s,y:a}=this,{outline:o}=w(this,Wc,t);w(this,Lc,o instanceof uA),this.description=r;let l;u(this,Lc)?l=Ua.getDefaultDrawingOptions():(l=Ua._defaultDrawnSignatureOptions.clone(),l.updateProperties({"stroke-width":o.thickness})),this._addOutlines({drawOutlines:o,drawingOptions:l});const[,c]=this.pageDimensions;let h=e/c;h=h>=1?.5:h,this.width*=h/this.height,this.width>=1&&(h*=.9/this.width,this.width=.9),this.height=h,this.setDims(),this.x=s,this.y=a,this.center(),this._onResized(),this.onScaleChanging(),this.rotate(),this._uiManager.addToAnnotationStorage(this),this.setUuid(i),this._reportTelemetry({action:"pdfjs.signature.inserted",data:{hasBeenSaved:!!i,hasDescription:!!r}}),this.div.hidden=!1}getFromImage(t){const{rawDims:{pageWidth:e,pageHeight:r},rotation:i}=this.parent.viewport;return fa.process(t,e,r,i,Ua._INNER_MARGIN)}getFromText(t,e){const{rawDims:{pageWidth:r,pageHeight:i},rotation:s}=this.parent.viewport;return fa.extractContoursFromText(t,e,r,i,s,Ua._INNER_MARGIN)}getDrawnSignature(t){const{rawDims:{pageWidth:e,pageHeight:r},rotation:i}=this.parent.viewport;return fa.processDrawnLines({lines:t,pageWidth:e,pageHeight:r,rotation:i,innerMargin:Ua._INNER_MARGIN,mustSmooth:!1,areContours:!1})}createDrawingOptions({areContours:t,thickness:e}){t?this._drawingOptions=Ua.getDefaultDrawingOptions():(this._drawingOptions=Ua._defaultDrawnSignatureOptions.clone(),this._drawingOptions.updateProperties({"stroke-width":e}))}serialize(t=!1){if(this.isEmpty())return null;const{lines:e,points:r}=this.serializeDraw(t),{_drawingOptions:{"stroke-width":i}}=this,s=Object.assign(super.serialize(t),{isSignature:!0,areContours:u(this,Lc),color:[0,0,0],thickness:u(this,Lc)?0:i});return this.addComment(s),t?(s.paths={lines:e,points:r},s.uuid=u(this,qu),s.isCopy=!0):s.lines=e,u(this,za)&&(s.accessibilityData={type:"Figure",alt:u(this,za)}),s}static deserializeDraw(t,e,r,i,s,a){return a.areContours?uA.deserialize(t,e,r,i,s,a):Fm.deserialize(t,e,r,i,s,a)}static async deserialize(t,e,r){var i;const s=await super.deserialize(t,e,r);return w(s,Lc,t.areContours),s.description=((i=t.accessibilityData)==null?void 0:i.alt)||"",w(s,qu,t.uuid),s}};Lc=new WeakMap,za=new WeakMap,Wc=new WeakMap,qu=new WeakMap,J(e0,"_type","signature"),J(e0,"_editorType",te.SIGNATURE),J(e0,"_defaultDrawingOptions",null);let D_=e0;var fn,fr,eh,Sl,gh,Yp,kl,Hu,Va,Qi,qg,tn,Pf,Ff,n0,Cv,Tv,gA,r0,EF;class mA extends on{constructor(t){super({...t,name:"stampEditor"}),C(this,tn),C(this,fn,null),C(this,fr,null),C(this,eh,null),C(this,Sl,null),C(this,gh,null),C(this,Yp,""),C(this,kl,null),C(this,Hu,!1),C(this,Va,null),C(this,Qi,!1),C(this,qg,!1),w(this,Sl,t.bitmapUrl),w(this,gh,t.bitmapFile),this.defaultL10nId="pdfjs-editor-stamp-editor"}static initialize(t,e){on.initialize(t,e)}static isHandlingMimeForPasting(t){return Sb.includes(t)}static paste(t,e){e.pasteEditor({mode:te.STAMP},{bitmapFile:t.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){var t;return{type:"stamp",hasAltText:!!((t=this.altTextData)!=null&&t.altText)}}static computeTelemetryFinalData(t){const e=t.get("hasAltText");return{hasAltText:e.get(!0)??0,hasNoAltText:e.get(!1)??0}}async mlGuessAltText(t=null,e=!0){if(this.hasAltTextData())return null;const{mlManager:r}=this._uiManager;if(!r)throw new Error("No ML.");if(!await r.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:i,width:s,height:a}=t||this.copyCanvas(null,null,!0).imageData,o=await r.guess({name:"altText",request:{data:i,width:s,height:a,channels:i.length/(s*a)}});if(!o)throw new Error("No response from the AI service.");if(o.error)throw new Error("Error from the AI service.");if(o.cancel)return null;if(!o.output)throw new Error("No valid response from the AI service.");const l=o.output;return await this.setGuessedAltText(l),e&&!this.hasAltTextData()&&(this.altTextData={alt:l,decorative:!1}),l}remove(){var t;u(this,fr)&&(w(this,fn,null),this._uiManager.imageManager.deleteId(u(this,fr)),(t=u(this,kl))==null||t.remove(),w(this,kl,null),u(this,Va)&&(clearTimeout(u(this,Va)),w(this,Va,null))),super.remove()}rebuild(){if(!this.parent){u(this,fr)&&F(this,tn,n0).call(this);return}super.rebuild(),this.div!==null&&(u(this,fr)&&u(this,kl)===null&&F(this,tn,n0).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(t){this._isDraggable=!0,t&&this.div.focus()}isEmpty(){return!(u(this,eh)||u(this,fn)||u(this,Sl)||u(this,gh)||u(this,fr)||u(this,Hu))}get toolbarButtons(){return[["altText",this.createAltText()]]}get isResizable(){return!0}render(){if(this.div)return this.div;let t,e;return this._isCopy&&(t=this.x,e=this.y),super.render(),this.div.hidden=!0,this.createAltText(),u(this,Hu)||(u(this,fn)?F(this,tn,Cv).call(this):F(this,tn,n0).call(this)),this._isCopy&&this._moveAfterPaste(t,e),this._uiManager.addShouldRescale(this),this.div}setCanvas(t,e){const{id:r,bitmap:i}=this._uiManager.imageManager.getFromCanvas(t,e);e.remove(),r&&this._uiManager.imageManager.isValidId(r)&&(w(this,fr,r),i&&w(this,fn,i),w(this,Hu,!1),F(this,tn,Cv).call(this))}_onResized(){this.onScaleChanging()}onScaleChanging(){this.parent&&(u(this,Va)!==null&&clearTimeout(u(this,Va)),w(this,Va,setTimeout(()=>{w(this,Va,null),F(this,tn,gA).call(this)},200)))}copyCanvas(t,e,r=!1){t||(t=224);const{width:i,height:s}=u(this,fn),a=new Ds;let o=u(this,fn),l=i,c=s,h=null;if(e){if(i>e||s>e){const M=Math.min(e/i,e/s);l=Math.floor(i*M),c=Math.floor(s*M)}h=document.createElement("canvas");const p=h.width=Math.ceil(l*a.sx),g=h.height=Math.ceil(c*a.sy);u(this,Qi)||(o=F(this,tn,Tv).call(this,p,g));const m=h.getContext("2d");m.filter=this._uiManager.hcmFilter;let y="white",v="#cfcfd8";this._uiManager.hcmFilter!=="none"?v="black":WX.isDarkMode&&(y="#8f8f9d",v="#42414d");const b=15,S=b*a.sx,k=b*a.sy,P=new OffscreenCanvas(S*2,k*2),T=P.getContext("2d");T.fillStyle=y,T.fillRect(0,0,S*2,k*2),T.fillStyle=v,T.fillRect(0,0,S,k),T.fillRect(S,k,S,k),m.fillStyle=m.createPattern(P,"repeat"),m.fillRect(0,0,p,g),m.drawImage(o,0,0,o.width,o.height,0,0,p,g)}let d=null;if(r){let p,g;if(a.symmetric&&o.width<t&&o.height<t)p=o.width,g=o.height;else if(o=u(this,fn),i>t||s>t){const y=Math.min(t/i,t/s);p=Math.floor(i*y),g=Math.floor(s*y),u(this,Qi)||(o=F(this,tn,Tv).call(this,p,g))}const m=new OffscreenCanvas(p,g).getContext("2d",{willReadFrequently:!0});m.drawImage(o,0,0,o.width,o.height,0,0,p,g),d={width:p,height:g,data:m.getImageData(0,0,p,g).data}}return{canvas:h,width:l,height:c,imageData:d}}static async deserialize(t,e,r){var i;let s=null,a=!1;if(t instanceof HP){const{data:{rect:v,rotation:b,id:S,structParent:k,popupRef:P,richText:T,contentsObj:M,creationDate:D,modificationDate:L},container:W,parent:{page:{pageNumber:z}},canvas:V}=t;let X,U;V?(delete t.canvas,{id:X,bitmap:U}=r.imageManager.getFromCanvas(W.id,V),V.remove()):(a=!0,t._hasNoCanvas=!0);const K=((i=await e._structTree.getAriaAttributes(`${Td}${S}`))==null?void 0:i.get("aria-label"))||"";s=t={annotationType:te.STAMP,bitmapId:X,bitmap:U,pageIndex:z-1,rect:v.slice(0),rotation:b,annotationElementId:S,id:S,deleted:!1,accessibilityData:{decorative:!1,altText:K},isSvg:!1,structParent:k,popupRef:P,richText:T,comment:(M==null?void 0:M.str)||null,creationDate:D,modificationDate:L}}const o=await super.deserialize(t,e,r),{rect:l,bitmap:c,bitmapUrl:h,bitmapId:d,isSvg:p,accessibilityData:g}=t;a?(r.addMissingCanvas(t.id,o),w(o,Hu,!0)):d&&r.imageManager.isValidId(d)?(w(o,fr,d),c&&w(o,fn,c)):w(o,Sl,h),w(o,Qi,p);const[m,y]=o.pageDimensions;return o.width=(l[2]-l[0])/m,o.height=(l[3]-l[1])/y,g&&(o.altTextData=g),o._initialData=s,t.comment&&o.setCommentData(t),w(o,qg,!!s),o}serialize(t=!1,e=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const r=Object.assign(super.serialize(t),{bitmapId:u(this,fr),isSvg:u(this,Qi)});if(this.addComment(r),t)return r.bitmapUrl=F(this,tn,r0).call(this,!0),r.accessibilityData=this.serializeAltText(!0),r.isCopy=!0,r;const{decorative:i,altText:s}=this.serializeAltText(!1);if(!i&&s&&(r.accessibilityData={type:"Figure",alt:s}),this.annotationElementId){const o=F(this,tn,EF).call(this,r);return o.isSame?null:(o.isSameAltText?delete r.accessibilityData:r.accessibilityData.structParent=this._initialData.structParent??-1,r.id=this.annotationElementId,delete r.bitmapId,r)}if(e===null)return r;e.stamps||(e.stamps=new Map);const a=u(this,Qi)?(r.rect[2]-r.rect[0])*(r.rect[3]-r.rect[1]):null;if(!e.stamps.has(u(this,fr)))e.stamps.set(u(this,fr),{area:a,serialized:r}),r.bitmap=F(this,tn,r0).call(this,!1);else if(u(this,Qi)){const o=e.stamps.get(u(this,fr));a>o.area&&(o.area=a,o.serialized.bitmap.close(),o.serialized.bitmap=F(this,tn,r0).call(this,!1))}return r}renderAnnotationElement(t){return this.deleted?(t.hide(),null):(t.updateEdited({rect:this.getPDFRect(),popup:this.comment}),null)}}fn=new WeakMap,fr=new WeakMap,eh=new WeakMap,Sl=new WeakMap,gh=new WeakMap,Yp=new WeakMap,kl=new WeakMap,Hu=new WeakMap,Va=new WeakMap,Qi=new WeakMap,qg=new WeakMap,tn=new WeakSet,Pf=function(n,t=!1){if(!n){this.remove();return}w(this,fn,n.bitmap),t||(w(this,fr,n.id),w(this,Qi,n.isSvg)),n.file&&w(this,Yp,n.file.name),F(this,tn,Cv).call(this)},Ff=function(){if(w(this,eh,null),this._uiManager.enableWaiting(!1),!!u(this,kl)){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&u(this,fn)){this.addEditToolbar().then(()=>{this._editToolbar.hide(),this._uiManager.editAltText(this,!0)});return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&u(this,fn)){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}},n0=function(){if(u(this,fr)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(u(this,fr)).then(e=>F(this,tn,Pf).call(this,e,!0)).finally(()=>F(this,tn,Ff).call(this));return}if(u(this,Sl)){const e=u(this,Sl);w(this,Sl,null),this._uiManager.enableWaiting(!0),w(this,eh,this._uiManager.imageManager.getFromUrl(e).then(r=>F(this,tn,Pf).call(this,r)).finally(()=>F(this,tn,Ff).call(this)));return}if(u(this,gh)){const e=u(this,gh);w(this,gh,null),this._uiManager.enableWaiting(!0),w(this,eh,this._uiManager.imageManager.getFromFile(e).then(r=>F(this,tn,Pf).call(this,r)).finally(()=>F(this,tn,Ff).call(this)));return}const n=document.createElement("input");n.type="file",n.accept=Sb.join(",");const t=this._uiManager._signal;w(this,eh,new Promise(e=>{n.addEventListener("change",async()=>{if(!n.files||n.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const r=await this._uiManager.imageManager.getFromFile(n.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),F(this,tn,Pf).call(this,r)}e()},{signal:t}),n.addEventListener("cancel",()=>{this.remove(),e()},{signal:t})}).finally(()=>F(this,tn,Ff).call(this))),n.click()},Cv=function(){var n;const{div:t}=this;let{width:e,height:r}=u(this,fn);const[i,s]=this.pageDimensions,a=.75;if(this.width)e=this.width*i,r=this.height*s;else if(e>a*i||r>a*s){const l=Math.min(a*i/e,a*s/r);e*=l,r*=l}this._uiManager.enableWaiting(!1);const o=w(this,kl,document.createElement("canvas"));o.setAttribute("role","img"),this.addContainer(o),this.width=e/i,this.height=r/s,this.setDims(),(n=this._initialOptions)!=null&&n.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(t.hidden=!1),F(this,tn,gA).call(this),u(this,qg)||(this.parent.addUndoableEditor(this),w(this,qg,!0)),this._reportTelemetry({action:"inserted_image"}),u(this,Yp)&&this.div.setAttribute("aria-description",u(this,Yp)),this.annotationElementId||this._uiManager.a11yAlert("pdfjs-editor-stamp-added-alert")},Tv=function(n,t){const{width:e,height:r}=u(this,fn);let i=e,s=r,a=u(this,fn);for(;i>2*n||s>2*t;){const o=i,l=s;i>2*n&&(i=Math.ceil(i/2)),s>2*t&&(s=Math.ceil(s/2));const c=new OffscreenCanvas(i,s);c.getContext("2d").drawImage(a,0,0,o,l,0,0,i,s),a=c.transferToImageBitmap()}return a},gA=function(){const[n,t]=this.parentDimensions,{width:e,height:r}=this,i=new Ds,s=Math.ceil(e*n*i.sx),a=Math.ceil(r*t*i.sy),o=u(this,kl);if(!o||o.width===s&&o.height===a)return;o.width=s,o.height=a;const l=u(this,Qi)?u(this,fn):F(this,tn,Tv).call(this,s,a),c=o.getContext("2d");c.filter=this._uiManager.hcmFilter,c.drawImage(l,0,0,l.width,l.height,0,0,s,a)},r0=function(n){if(n){if(u(this,Qi)){const e=this._uiManager.imageManager.getSvgUrl(u(this,fr));if(e)return e}const t=document.createElement("canvas");return{width:t.width,height:t.height}=u(this,fn),t.getContext("2d").drawImage(u(this,fn),0,0),t.toDataURL()}if(u(this,Qi)){const[t,e]=this.pageDimensions,r=Math.round(this.width*t*Ah.PDF_TO_CSS_UNITS),i=Math.round(this.height*e*Ah.PDF_TO_CSS_UNITS),s=new OffscreenCanvas(r,i);return s.getContext("2d").drawImage(u(this,fn),0,0,u(this,fn).width,u(this,fn).height,0,0,r,i),s.transferToImageBitmap()}return structuredClone(u(this,fn))},EF=function(n){var t;const{pageIndex:e,accessibilityData:{altText:r}}=this._initialData,i=n.pageIndex===e,s=(((t=n.accessibilityData)==null?void 0:t.alt)||"")===r;return{isSame:!this.hasEditedComment&&!this._hasBeenMoved&&!this._hasBeenResized&&i&&s,isSameAltText:s}},J(mA,"_type","stamp"),J(mA,"_editorType",te.STAMP);var Xu,Zp,jc,zc,_o,pi,Uc,Jp,Qp,Xs,Yo,gr,Zo,Vc,$p,Bt,mh,kn,yA,IF,Zs,vA,bA,i0;const s0=class Gc{constructor({uiManager:t,pageIndex:e,div:r,structTreeLayer:i,accessibilityManager:s,annotationLayer:a,drawLayer:o,textLayer:l,viewport:c,l10n:h}){C(this,kn),C(this,Xu),C(this,Zp,!1),C(this,jc,null),C(this,zc,null),C(this,_o,null),C(this,pi,new Map),C(this,Uc,!1),C(this,Jp,!1),C(this,Qp,!1),C(this,Xs,null),C(this,Yo,null),C(this,gr,null),C(this,Zo,null),C(this,Vc,null),C(this,$p,-1),C(this,Bt);const d=[...u(Gc,mh).values()];if(!Gc._initialized){Gc._initialized=!0;for(const p of d)p.initialize(h,t)}t.registerEditorTypes(d),w(this,Bt,t),this.pageIndex=e,this.div=r,w(this,Xu,s),w(this,jc,a),this.viewport=c,w(this,gr,l),this.drawLayer=o,this._structTree=i,u(this,Bt).addLayer(this)}get isEmpty(){return u(this,pi).size===0}get isInvisible(){return this.isEmpty&&u(this,Bt).getMode()===te.NONE}updateToolbar(t){u(this,Bt).updateToolbar(t)}updateMode(t=u(this,Bt).getMode()){switch(F(this,kn,i0).call(this),t){case te.NONE:this.div.classList.toggle("nonEditing",!0),this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case te.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case te.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;if(e.toggle("nonEditing",!1),t===te.POPUP)e.toggle("commentEditing",!0);else{e.toggle("commentEditing",!1);for(const r of u(Gc,mh).values())e.toggle(`${r._type}Editing`,t===r._editorType)}this.div.hidden=!1}hasTextLayer(t){var e;return t===((e=u(this,gr))==null?void 0:e.div)}setEditingState(t){u(this,Bt).setEditingState(t)}addCommands(t){u(this,Bt).addCommands(t)}cleanUndoStack(t){u(this,Bt).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=u(this,jc))==null||e.togglePointerEvents(t)}async enable(){var t;w(this,Qp,!0),this.div.tabIndex=0,this.togglePointerEvents(!0),this.div.classList.toggle("nonEditing",!1),(t=u(this,Vc))==null||t.abort(),w(this,Vc,null);const e=new Set;for(const i of u(this,kn,yA))i.enableEditing(),i.show(!0),i.annotationElementId&&(u(this,Bt).removeChangedExistingAnnotation(i),e.add(i.annotationElementId));const r=u(this,jc);if(r)for(const i of r.getEditableAnnotations()){if(i.hide(),u(this,Bt).isDeletedAnnotationElement(i.data.id)||e.has(i.data.id))continue;const s=await this.deserialize(i);s&&(this.addOrRebuild(s),s.enableEditing())}w(this,Qp,!1),u(this,Bt)._eventBus.dispatch("editorsrendered",{source:this,pageNumber:this.pageIndex+1})}disable(){var t;if(w(this,Jp,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1),this.div.classList.toggle("nonEditing",!0),u(this,gr)&&!u(this,Vc)){w(this,Vc,new AbortController);const s=u(this,Bt).combinedSignal(u(this,Vc));u(this,gr).div.addEventListener("pointerdown",a=>{const{clientX:o,clientY:l,timeStamp:c}=a,h=u(this,$p);if(c-h>500){w(this,$p,c);return}w(this,$p,-1);const{classList:d}=this.div;d.toggle("getElements",!0);const p=document.elementsFromPoint(o,l);if(d.toggle("getElements",!1),!this.div.contains(p[0]))return;let g;const m=new RegExp(`^${sm}[0-9]+$`);for(const v of p)if(m.test(v.id)){g=v.id;break}if(!g)return;const y=u(this,pi).get(g);(y==null?void 0:y.annotationElementId)===null&&(an(a),y.dblclick(a))},{signal:s,capture:!0})}const e=u(this,jc),r=[];if(e){const s=new Map,a=new Map;for(const o of u(this,kn,yA)){if(o.disableEditing(),!o.annotationElementId){r.push(o);continue}if(o.serialize()!==null){s.set(o.annotationElementId,o);continue}else a.set(o.annotationElementId,o);(t=this.getEditableAnnotation(o.annotationElementId))==null||t.show(),o.remove()}for(const o of e.getEditableAnnotations()){const{id:l}=o.data;if(u(this,Bt).isDeletedAnnotationElement(l)){o.updateEdited({deleted:!0});continue}let c=a.get(l);if(c){c.resetAnnotationElement(o),c.show(!1),o.show();continue}c=s.get(l),c&&(u(this,Bt).addChangedExistingAnnotation(c),c.renderAnnotationElement(o)&&c.show(!1)),o.show()}}F(this,kn,i0).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:i}=this.div;for(const s of u(Gc,mh).values())i.remove(`${s._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),e==null||e.updateFakeAnnotations(r),w(this,Jp,!1)}getEditableAnnotation(t){var e;return((e=u(this,jc))==null?void 0:e.getEditableAnnotation(t))||null}setActiveEditor(t){u(this,Bt).getActive()!==t&&u(this,Bt).setActiveEditor(t)}enableTextSelection(){var t;if(this.div.tabIndex=-1,(t=u(this,gr))!=null&&t.div&&!u(this,Zo)){w(this,Zo,new AbortController);const e=u(this,Bt).combinedSignal(u(this,Zo));u(this,gr).div.addEventListener("pointerdown",F(this,kn,IF).bind(this),{signal:e}),u(this,gr).div.classList.add("highlighting")}}disableTextSelection(){var t;this.div.tabIndex=0,(t=u(this,gr))!=null&&t.div&&u(this,Zo)&&(u(this,Zo).abort(),w(this,Zo,null),u(this,gr).div.classList.remove("highlighting"))}enableClick(){if(u(this,zc))return;w(this,zc,new AbortController);const t=u(this,Bt).combinedSignal(u(this,zc));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=u(this,zc))==null||t.abort(),w(this,zc,null)}attach(t){u(this,pi).set(t.id,t);const{annotationElementId:e}=t;e&&u(this,Bt).isDeletedAnnotationElement(e)&&u(this,Bt).removeDeletedAnnotationElement(t)}detach(t){var e;u(this,pi).delete(t.id),(e=u(this,Xu))==null||e.removePointerInTextLayer(t.contentDiv),!u(this,Jp)&&t.annotationElementId&&u(this,Bt).addDeletedAnnotationElement(t)}remove(t){this.detach(t),u(this,Bt).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){var e;t.parent!==this&&(t.parent&&t.annotationElementId&&(u(this,Bt).addDeletedAnnotationElement(t),on.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),u(this,Bt).addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!u(this,Qp)),u(this,Bt).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var e;if(!t.isAttachedToDOM)return;const{activeElement:r}=document;t.div.contains(r)&&!u(this,_o)&&(t._focusEventsAllowed=!1,w(this,_o,setTimeout(()=>{w(this,_o,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:u(this,Bt)._signal}),r.focus())},0))),t._structTreeParentId=(e=u(this,Xu))==null?void 0:e.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),r=()=>{t.remove()};this.addCommands({cmd:e,undo:r,mustExec:!1})}getEditorByUID(t){for(const e of u(this,pi).values())if(e.uid===t)return e;return null}combinedSignal(t){return u(this,Bt).combinedSignal(t)}canCreateNewEmptyEditor(){var t;return(t=u(this,kn,Zs))==null?void 0:t.canCreateNewEmptyEditor()}async pasteEditor(t,e){this.updateToolbar(t),await u(this,Bt).updateMode(t.mode);const{offsetX:r,offsetY:i}=F(this,kn,bA).call(this),s=u(this,Bt).getId(),a=F(this,kn,vA).call(this,{parent:this,id:s,x:r,y:i,uiManager:u(this,Bt),isCentered:!0,...e});a&&this.add(a)}async deserialize(t){var e;return await((e=u(Gc,mh).get(t.annotationType??t.annotationEditorType))==null?void 0:e.deserialize(t,this,u(this,Bt)))||null}createAndAddNewEditor(t,e,r={}){const i=u(this,Bt).getId(),s=F(this,kn,vA).call(this,{parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:u(this,Bt),isCentered:e,...r});return s&&this.add(s),s}get boundingClientRect(){return this.div.getBoundingClientRect()}addNewEditor(t={}){this.createAndAddNewEditor(F(this,kn,bA).call(this),!0,t)}setSelected(t){u(this,Bt).setSelected(t)}toggleSelected(t){u(this,Bt).toggleSelected(t)}unselect(t){u(this,Bt).unselect(t)}pointerup(t){var e;const{isMac:r}=In.platform;if(t.button!==0||t.ctrlKey&&r||t.target!==this.div||!u(this,Uc)||(w(this,Uc,!1),(e=u(this,kn,Zs))!=null&&e.isDrawer&&u(this,kn,Zs).supportMultipleDrawings))return;if(!u(this,Zp)){w(this,Zp,!0);return}const i=u(this,Bt).getMode();if(i===te.STAMP||i===te.POPUP||i===te.SIGNATURE){u(this,Bt).unselectAll();return}this.createAndAddNewEditor(t,!1)}pointerdown(t){var e;if(u(this,Bt).getMode()===te.HIGHLIGHT&&this.enableTextSelection(),u(this,Uc)){w(this,Uc,!1);return}const{isMac:r}=In.platform;if(t.button!==0||t.ctrlKey&&r||t.target!==this.div)return;if(w(this,Uc,!0),(e=u(this,kn,Zs))!=null&&e.isDrawer){this.startDrawingSession(t);return}const i=u(this,Bt).getActive();w(this,Zp,!i||i.isEmpty())}startDrawingSession(t){if(this.div.focus({preventScroll:!0}),u(this,Xs)){u(this,kn,Zs).startDrawing(this,u(this,Bt),!1,t);return}u(this,Bt).setCurrentDrawingSession(this),w(this,Xs,new AbortController);const e=u(this,Bt).combinedSignal(u(this,Xs));this.div.addEventListener("blur",({relatedTarget:r})=>{r&&!this.div.contains(r)&&(w(this,Yo,null),this.commitOrRemove())},{signal:e}),u(this,kn,Zs).startDrawing(this,u(this,Bt),!1,t)}pause(t){if(t){const{activeElement:e}=document;this.div.contains(e)&&w(this,Yo,e);return}u(this,Yo)&&setTimeout(()=>{var e;(e=u(this,Yo))==null||e.focus(),w(this,Yo,null)},0)}endDrawingSession(t=!1){return u(this,Xs)?(u(this,Bt).setCurrentDrawingSession(null),u(this,Xs).abort(),w(this,Xs,null),w(this,Yo,null),u(this,kn,Zs).endDrawing(t)):null}findNewParent(t,e,r){const i=u(this,Bt).findParent(e,r);return i===null||i===this?!1:(i.changeParent(t),!0)}commitOrRemove(){return u(this,Xs)?(this.endDrawingSession(),!0):!1}onScaleChanging(){u(this,Xs)&&u(this,kn,Zs).onScaleChangingWhenDrawing(this)}destroy(){var t,e;this.commitOrRemove(),((t=u(this,Bt).getActive())==null?void 0:t.parent)===this&&(u(this,Bt).commitOrRemove(),u(this,Bt).setActiveEditor(null)),u(this,_o)&&(clearTimeout(u(this,_o)),w(this,_o,null));for(const r of u(this,pi).values())(e=u(this,Xu))==null||e.removePointerInTextLayer(r.contentDiv),r.setParent(null),r.isAttachedToDOM=!1,r.div.remove();this.div=null,u(this,pi).clear(),u(this,Bt).removeLayer(this)}async render({viewport:t}){this.viewport=t,jl(this.div,t);for(const e of u(this,Bt).getEditors(this.pageIndex))this.add(e),e.rebuild();await u(this,Bt).findClonesForPage(this),this.div.hidden=this.isEmpty,this.updateMode()}update({viewport:t}){u(this,Bt).commitOrRemove(),F(this,kn,i0).call(this);const e=this.viewport.rotation,r=t.rotation;if(this.viewport=t,jl(this.div,{rotation:r}),e!==r)for(const i of u(this,pi).values())i.rotate(r)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return u(this,Bt).viewParameters.realScale}};Xu=new WeakMap,Zp=new WeakMap,jc=new WeakMap,zc=new WeakMap,_o=new WeakMap,pi=new WeakMap,Uc=new WeakMap,Jp=new WeakMap,Qp=new WeakMap,Xs=new WeakMap,Yo=new WeakMap,gr=new WeakMap,Zo=new WeakMap,Vc=new WeakMap,$p=new WeakMap,Bt=new WeakMap,mh=new WeakMap,kn=new WeakSet,yA=function(){return u(this,pi).size!==0?u(this,pi).values():u(this,Bt).getEditors(this.pageIndex)},IF=function(n){u(this,Bt).unselectAll();const{target:t}=n;if(t===u(this,gr).div||(t.getAttribute("role")==="img"||t.classList.contains("endOfContent")||t.classList.contains("textLayerImagePlaceholder"))&&u(this,gr).div.contains(t)){const{isMac:e}=In.platform;if(n.button!==0||n.ctrlKey&&e)return;u(this,Bt).showAllEditors("highlight",!0,!0),u(this,gr).div.classList.add("free"),this.toggleDrawing(),T6.startHighlighting(this,u(this,Bt).direction==="ltr",{target:u(this,gr).div,x:n.x,y:n.y}),u(this,gr).div.addEventListener("pointerup",()=>{u(this,gr).div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:u(this,Bt)._signal}),n.preventDefault()}},Zs=function(){return u(s0,mh).get(u(this,Bt).getMode())},vA=function(n){const t=u(this,kn,Zs);return t?new t.prototype.constructor(n):null},bA=function(){const{x:n,y:t,width:e,height:r}=this.boundingClientRect,i=Math.max(0,n),s=Math.max(0,t),a=Math.min(window.innerWidth,n+e),o=Math.min(window.innerHeight,t+r),l=(i+a)/2-n,c=(s+o)/2-t,[h,d]=this.viewport.rotation%180===0?[l,c]:[c,l];return{offsetX:h,offsetY:d}},i0=function(){for(const n of u(this,pi).values())n.isEmpty()&&n.remove()},J(s0,"_initialized",!1),C(s0,mh,new Map([P_,O_,mA,T6,D_].map(n=>[n._editorType,n])));let OF=s0;var Js,Jr,Ku,Mv,wA,DF,qc,xA,RF,AA;const _u=class ci{constructor(){C(this,qc),C(this,Js,null),C(this,Jr,new Map),C(this,Ku,new Map)}setParent(t){if(!u(this,Js)){w(this,Js,t);return}if(u(this,Js)!==t){if(u(this,Jr).size>0)for(const e of u(this,Jr).values())e.remove(),t.append(e);w(this,Js,t)}}static get _svgFactory(){return se(this,"_svgFactory",new hm)}draw(t,e=!1,r=!1){const i=Qn(ci,Mv)._++,s=F(this,qc,xA).call(this),a=ci._svgFactory.createElement("defs");s.append(a);const o=ci._svgFactory.createElement("path");a.append(o);const l=`path_${i}`;o.setAttribute("id",l),o.setAttribute("vector-effect","non-scaling-stroke"),e&&u(this,Ku).set(i,o);const c=r?F(this,qc,RF).call(this,a,l):null,h=ci._svgFactory.createElement("use");return s.append(h),h.setAttribute("href",`#${l}`),this.updateProperties(s,t),u(this,Jr).set(i,s),{id:i,clipPathId:`url(#${c})`}}drawOutline(t,e){const r=Qn(ci,Mv)._++,i=F(this,qc,xA).call(this),s=ci._svgFactory.createElement("defs");i.append(s);const a=ci._svgFactory.createElement("path");s.append(a);const o=`path_${r}`;a.setAttribute("id",o),a.setAttribute("vector-effect","non-scaling-stroke");let l;if(e){const d=ci._svgFactory.createElement("mask");s.append(d),l=`mask_${r}`,d.setAttribute("id",l),d.setAttribute("maskUnits","objectBoundingBox");const p=ci._svgFactory.createElement("rect");d.append(p),p.setAttribute("width","1"),p.setAttribute("height","1"),p.setAttribute("fill","white");const g=ci._svgFactory.createElement("use");d.append(g),g.setAttribute("href",`#${o}`),g.setAttribute("stroke","none"),g.setAttribute("fill","black"),g.setAttribute("fill-rule","nonzero"),g.classList.add("mask")}const c=ci._svgFactory.createElement("use");i.append(c),c.setAttribute("href",`#${o}`),l&&c.setAttribute("mask",`url(#${l})`);const h=c.cloneNode();return i.append(h),c.classList.add("mainOutline"),h.classList.add("secondaryOutline"),this.updateProperties(i,t),u(this,Jr).set(r,i),r}finalizeDraw(t,e){u(this,Ku).delete(t),this.updateProperties(t,e)}updateProperties(t,e){var r;if(!e)return;const{root:i,bbox:s,rootClass:a,path:o}=e,l=typeof t=="number"?u(this,Jr).get(t):t;if(l){if(i&&F(this,qc,AA).call(this,l,i),s&&F(r=ci,wA,DF).call(r,l,s),a){const{classList:c}=l;for(const[h,d]of Object.entries(a))c.toggle(h,d)}if(o){const c=l.firstElementChild.firstElementChild;F(this,qc,AA).call(this,c,o)}}}updateParent(t,e){if(e===this)return;const r=u(this,Jr).get(t);r&&(u(e,Js).append(r),u(this,Jr).delete(t),u(e,Jr).set(t,r))}remove(t){u(this,Ku).delete(t),u(this,Js)!==null&&(u(this,Jr).get(t).remove(),u(this,Jr).delete(t))}destroy(){w(this,Js,null);for(const t of u(this,Jr).values())t.remove();u(this,Jr).clear(),u(this,Ku).clear()}};Js=new WeakMap,Jr=new WeakMap,Ku=new WeakMap,Mv=new WeakMap,wA=new WeakSet,DF=function(n,[t,e,r,i]){const{style:s}=n;s.top=`${100*e}%`,s.left=`${100*t}%`,s.width=`${100*r}%`,s.height=`${100*i}%`},qc=new WeakSet,xA=function(){const n=_u._svgFactory.create(1,1,!0);return u(this,Js).append(n),n.setAttribute("aria-hidden",!0),n},RF=function(n,t){const e=_u._svgFactory.createElement("clipPath");n.append(e);const r=`clip_${t}`;e.setAttribute("id",r),e.setAttribute("clipPathUnits","objectBoundingBox");const i=_u._svgFactory.createElement("use");return e.append(i),i.setAttribute("href",`#${t}`),i.classList.add("clip"),r},AA=function(n,t){for(const[e,r]of Object.entries(t))r===null?n.removeAttribute(e):n.setAttribute(e,r)},C(_u,wA),C(_u,Mv,0);let BF=_u;function wy(n){return`${(n*100).toFixed(2)}%`}var tg,Pv,a0,Hg,no,ro,Fv,SA,NF;const LF=class kA{constructor(t,e,r,i){C(this,SA),C(this,tg,[]),C(this,Pv,new Map),C(this,a0,null),C(this,Hg,0),C(this,no,0),C(this,ro,0),w(this,Hg,t),w(this,tg,e),w(this,no,r.rawDims.pageWidth),w(this,ro,r.rawDims.pageHeight),w(this,a0,i)}render(){const t=document.createElement("div");t.className="textLayerImages";for(let e=0;e<u(this,tg).length;e+=6){const r=F(this,SA,NF).call(this,u(this,tg).subarray(e,e+6));r&&t.append(r)}return t.addEventListener("contextmenu",e=>{var r;if(!(e.target instanceof HTMLCanvasElement))return;const i=e.target,s=u(this,Pv).get(i);if(!s)return;const a=(r=u(kA,Fv))==null?void 0:r.deref();if(a===i)return;a&&(a.width=0,a.height=0),w(kA,Fv,new WeakRef(i));const{inverseTransform:o,x1:l,y1:c,width:h,height:d}=s,p=u(this,a0).call(this),g=Math.ceil(l*p.width),m=Math.ceil(c*p.height),y=Math.floor((l+h/u(this,no))*p.width),v=Math.floor((c+d/u(this,ro))*p.height);i.width=y-g,i.height=v-m;const b=i.getContext("2d");b.setTransform(...o),b.translate(-g,-m),b.drawImage(p,0,0)}),t}};tg=new WeakMap,Pv=new WeakMap,a0=new WeakMap,Hg=new WeakMap,no=new WeakMap,ro=new WeakMap,Fv=new WeakMap,SA=new WeakSet,NF=function([n,t,e,r,i,s]){const a=Math.hypot((i-n)*u(this,no),(s-t)*u(this,ro)),o=Math.hypot((e-n)*u(this,no),(r-t)*u(this,ro));if(a<u(this,Hg)||o<u(this,Hg))return null;const l=[(i-n)*u(this,no)/a,(s-t)*u(this,ro)/a,(e-n)*u(this,no)/o,(r-t)*u(this,ro)/o,0,0],c=ft.inverseTransform(l),h=document.createElement("canvas");return h.className="textLayerImagePlaceholder",h.width=0,h.height=0,Object.assign(h.style,{opacity:0,position:"absolute",left:wy(n),top:wy(t),width:wy(a/u(this,no)),height:wy(o/u(this,ro)),transformOrigin:"0% 0%",transform:`matrix(${l.join(",")})`}),u(this,Pv).set(h,{inverseTransform:c,width:a,height:o,x1:n,y1:t}),h},C(LF,Fv,null);let WF=LF;globalThis._pdfjsTestingUtils={HighlightOutliner:iA};globalThis.pdfjsLib={AbortException:vo,AnnotationEditorLayer:OF,AnnotationEditorParamsType:ce,AnnotationEditorType:te,AnnotationEditorUIManager:Yd,AnnotationLayer:KP,AnnotationMode:io,AnnotationType:Cn,applyOpacity:uM,build:DP,ColorPicker:QS,createValidAbsoluteUrl:VS,CSSConstants:hM,DOMSVGFactory:hm,DrawLayer:BF,FeatureTest:In,fetchData:bb,findContrastColor:dM,getDocument:ZS,getFilenameFromUrl:oM,getPdfFilenameFromUrl:lM,getRGB:rf,getRGBA:Ab,getUuid:qS,getXfaPageViewport:cM,GlobalWorkerOptions:wa,ImageKind:ug,InvalidPDFException:N0,isDataScheme:Mm,isPdfFile:xb,isValidExplicitDest:YM,makeArr:yb,makeMap:vb,makeObj:L0,MathClamp:en,noContextMenu:Ti,normalizeUnicode:aM,OPS:aa,OutputScale:Ds,PasswordResponses:sM,PDFDataRangeTransport:JS,PDFDateString:lm,PDFWorker:ov,PermissionFlag:iM,PixelsPerInch:Ah,RenderingCancelledException:wb,renderRichText:XS,ResponseException:am,setLayerDimensions:jl,shadow:se,SignatureExtractor:fa,stopEvent:an,SupportedImageMimeTypes:Sb,TextLayer:sv,TextLayerImages:WF,TouchManager:KS,updateUrlHash:GS,Util:ft,VerbosityLevel:Cm,version:OP,XfaLayer:HS};const R_=Object.freeze(Object.defineProperty({__proto__:null,AbortException:vo,AnnotationEditorLayer:OF,AnnotationEditorParamsType:ce,AnnotationEditorType:te,AnnotationEditorUIManager:Yd,AnnotationLayer:KP,AnnotationMode:io,AnnotationType:Cn,CSSConstants:hM,ColorPicker:QS,DOMSVGFactory:hm,DrawLayer:BF,FeatureTest:In,GlobalWorkerOptions:wa,ImageKind:ug,InvalidPDFException:N0,MathClamp:en,OPS:aa,OutputScale:Ds,PDFDataRangeTransport:JS,PDFDateString:lm,PDFWorker:ov,PasswordResponses:sM,PermissionFlag:iM,PixelsPerInch:Ah,RenderingCancelledException:wb,ResponseException:am,SignatureExtractor:fa,SupportedImageMimeTypes:Sb,TextLayer:sv,TextLayerImages:WF,TouchManager:KS,Util:ft,VerbosityLevel:Cm,XfaLayer:HS,applyOpacity:uM,build:DP,createValidAbsoluteUrl:VS,fetchData:bb,findContrastColor:dM,getDocument:ZS,getFilenameFromUrl:oM,getPdfFilenameFromUrl:lM,getRGB:rf,getRGBA:Ab,getUuid:qS,getXfaPageViewport:cM,isDataScheme:Mm,isPdfFile:xb,isValidExplicitDest:YM,makeArr:yb,makeMap:vb,makeObj:L0,noContextMenu:Ti,normalizeUnicode:aM,renderRichText:XS,setLayerDimensions:jl,shadow:se,stopEvent:an,updateUrlHash:GS,version:OP},Symbol.toStringTag,{value:"Module"}));wa.workerSrc="";const E6=25.4/72,r2=8;class B_{importFromFilePicker(t){const e=document.createElement("input");e.type="file",e.accept=".pdf",e.style.display="none",document.body.appendChild(e),e.addEventListener("change",async()=>{var r;const i=(r=e.files)==null?void 0:r[0];if(document.body.removeChild(e),!i)return;const s=await i.arrayBuffer();await this.convert(t,s)}),e.click()}async convert(t,e,r=1){try{const i=await(await ZS({data:e}).promise).getPage(r),s=i.getViewport({scale:1}).height,a=await i.getOperatorList(),o=this.extractEntities(a,s);if(o.length===0){Bb.warn("[PdfImport] No vector paths found in PDF page.");return}const l=t.doc.database.tables.blockTable.modelSpace;for(const c of o)l.appendEntity(c);Bb.info(`[PdfImport] Imported ${o.length} entities from PDF.`)}catch(i){Bb.error("[PdfImport] Failed to import PDF:",i)}}extractEntities(t,e){const{OPS:r}=R_,{fnArray:i,argsArray:s}=t,a=[];let o=[],l=[],c=0,h=0;const d=()=>{l.length>1&&o.push(l),l=[]},p=()=>{d();for(const y of o){const v=this.subpathToEntity(y);v&&a.push(v)}o=[]},g=(y,v)=>y*E6,m=(y,v)=>(e-v)*E6;for(let y=0;y<i.length;y++){const v=i[y],b=s[y];switch(v){case r.moveTo:{d(),c=b[0],h=b[1],l=[{x:g(c),y:m(c,h)}];break}case r.lineTo:{c=b[0],h=b[1],l.push({x:g(c),y:m(c,h)});break}case r.curveTo:{const[S,k,P,T,M,D]=b,L=i2({x:c,y:h},{x:S,y:k},{x:P,y:T},{x:M,y:D},r2);for(const W of L)l.push({x:g(W.x,W.y),y:m(W.x,W.y)});c=M,h=D;break}case r.curveTo2:{const[S,k,P,T]=b,M=i2({x:c,y:h},{x:c,y:h},{x:S,y:k},{x:P,y:T},r2);for(const D of M)l.push({x:g(D.x,D.y),y:m(D.x,D.y)});c=P,h=T;break}case r.curveTo3:{const[S,k,P,T]=b,M=i2({x:c,y:h},{x:S,y:k},{x:P,y:T},{x:P,y:T},r2);for(const D of M)l.push({x:g(D.x,D.y),y:m(D.x,D.y)});c=P,h=T;break}case r.closePath:{l.length>0&&o.length===0&&l.push({...l[0]}),d();break}case r.stroke:case r.fill:case r.eoFill:case r.fillStroke:case r.eoFillStroke:case r.endPath:{p();break}}}return p(),a}subpathToEntity(t){if(t.length<2)return null;if(t.length===2)return new eE(new Ks(t[0].x,t[0].y,0),new Ks(t[1].x,t[1].y,0));const e=new nE;for(let o=0;o<t.length;o++)e.addVertexAt(o,new s2(t[o].x,t[o].y));const r=t[0],i=t[t.length-1],s=r.x-i.x,a=r.y-i.y;return Math.sqrt(s*s+a*a)<1e-6&&(e.closed=!0),e}}function i2(n,t,e,r,i){const s=[];for(let a=1;a<=i;a++){const o=a/i,l=1-o,c=l*l*l*n.x+3*l*l*o*t.x+3*l*o*o*e.x+o*o*o*r.x,h=l*l*l*n.y+3*l*l*o*t.y+3*l*o*o*e.y+o*o*o*r.y;s.push({x:c,y:h})}return s}class N_ extends R6{async execute(t){new B_().importFromFilePicker(t)}}const L_="1.7.3",W_={version:L_};class j_{constructor(t={}){this.name="PdfPlugin",this.version=W_.version,this.description="PDF export (-cpdf / cpdf) and import (ipdf) commands",this.registeredCommands=[],this._disableExport=t.disableExport===!0}onLoad(t,e){const r=QF.SYSTEMT_COMMAND_GROUP_NAME;if(!this._disableExport){const i=new MX;e.addCommand(r,"-cpdf","-cpdf",i),this.registeredCommands.push({group:r,name:"-cpdf"}),e.lookupGlobalCmd("cpdf")||(e.addCommand(r,"cpdf","cpdf",i),this.registeredCommands.push({group:r,name:"cpdf"}))}e.addCommand(r,"ipdf","ipdf",new N_),this.registeredCommands.push({group:r,name:"ipdf"})}onUnload(t,e){for(const r of this.registeredCommands)e.removeCmd(r.group,r.name);this.registeredCommands=[]}}async function Y_(n={}){return new j_(n)}export{MX as AcApConvertToPdfCmd,N_ as AcApImportPdfCmd,TX as AcApPdfConvertor,B_ as AcApPdfImportConvertor,j_ as AcApPdfPlugin,Q_ as PDF_PLUGIN_NAME,$_ as PDF_PLUGIN_TRIGGERS,Y_ as createPdfPlugin,Nf as resolveAcApPdfExportOptions,SX as resolveViewerTextFont};
@@ -1,4 +1,4 @@
1
- import{j as Z,$ as Q,k as tt,ay as et,ap as H,ae as U,af as it,ag as st,h as q,ad as nt,ah as rt,ai as at,aj as ot,ak as E,al as ht,a7 as X,am as W,av as ct,ar as B,as as lt,aq as k,ax as v,ao as g,at as w,aE as ut,aF as mt}from"./index-QZJdatvK.js";import{aG as ce,aH as le}from"./index-QZJdatvK.js";class z{static toSvgTransform(t){const e=t.elements;return`matrix(${e[0]},${e[1]},${e[4]},${e[5]},${e[12]},${e[13]})`}static transformPoint(t,e){const i=t.elements,s=e.x,n=e.y,r=e.z??0,o=i[3]*s+i[7]*n+i[11]*r+i[15],h=o===0?1:1/o;return{x:(i[0]*s+i[4]*n+i[8]*r+i[12])*h,y:(i[1]*s+i[5]*n+i[9]*r+i[13])*h}}static transformBox(t,e){if(t.isEmpty())return;const i=t.min,s=t.max,n=[{x:i.x,y:i.y,z:0},{x:s.x,y:i.y,z:0},{x:s.x,y:s.y,z:0},{x:i.x,y:s.y,z:0}];let r=1/0,o=1/0,h=-1/0,c=-1/0;for(const l of n){const m=this.transformPoint(e,l);r=Math.min(r,m.x),o=Math.min(o,m.y),h=Math.max(h,m.x),c=Math.max(c,m.y)}t.min.set(r,o),t.max.set(h,c)}}class y{constructor(){this._objectId="",this._ownerId="",this._layerName="",this._visible=!0,this._userData={},this._box=new H,this._localSvg=""}get box(){return this._box}set box(t){this._box.copy(t)}get basePoint(){return this._basePoint}set basePoint(t){t==null?this._basePoint=t:this._basePoint=this._basePoint?this._basePoint.copy(t):new ct(t)}get svg(){return this.renderSvg()}set svg(t){this._localSvg=t}getLocalSvg(){return this._localSvg}renderSvg(){return this._localSvg?this._matrix?`<g transform="${z.toSvgTransform(this._matrix)}">
1
+ import{j as Z,$ as Q,C as tt,ay as et,ap as H,ae as U,af as it,ag as st,f as q,ad as nt,ah as rt,ai as at,aj as ot,ak as E,al as ht,a7 as X,am as W,av as ct,ar as B,as as lt,aq as k,ax as v,ao as g,at as w,aE as ut,aF as mt}from"./index-B3SgHAxA.js";import{aG as ce,aH as le}from"./index-B3SgHAxA.js";class z{static toSvgTransform(t){const e=t.elements;return`matrix(${e[0]},${e[1]},${e[4]},${e[5]},${e[12]},${e[13]})`}static transformPoint(t,e){const i=t.elements,s=e.x,n=e.y,r=e.z??0,o=i[3]*s+i[7]*n+i[11]*r+i[15],h=o===0?1:1/o;return{x:(i[0]*s+i[4]*n+i[8]*r+i[12])*h,y:(i[1]*s+i[5]*n+i[9]*r+i[13])*h}}static transformBox(t,e){if(t.isEmpty())return;const i=t.min,s=t.max,n=[{x:i.x,y:i.y,z:0},{x:s.x,y:i.y,z:0},{x:s.x,y:s.y,z:0},{x:i.x,y:s.y,z:0}];let r=1/0,o=1/0,h=-1/0,c=-1/0;for(const l of n){const m=this.transformPoint(e,l);r=Math.min(r,m.x),o=Math.min(o,m.y),h=Math.max(h,m.x),c=Math.max(c,m.y)}t.min.set(r,o),t.max.set(h,c)}}class y{constructor(){this._objectId="",this._ownerId="",this._layerName="",this._visible=!0,this._userData={},this._box=new H,this._localSvg=""}get box(){return this._box}set box(t){this._box.copy(t)}get basePoint(){return this._basePoint}set basePoint(t){t==null?this._basePoint=t:this._basePoint=this._basePoint?this._basePoint.copy(t):new ct(t)}get svg(){return this.renderSvg()}set svg(t){this._localSvg=t}getLocalSvg(){return this._localSvg}renderSvg(){return this._localSvg?this._matrix?`<g transform="${z.toSvgTransform(this._matrix)}">
2
2
  ${this._localSvg}
3
3
  </g>`:this._localSvg:""}get objectId(){return this._objectId}set objectId(t){this._objectId=t}get ownerId(){return this._ownerId}set ownerId(t){this._ownerId=t}get layerName(){return this._layerName}set layerName(t){this._layerName=t}get visible(){return this._visible}set visible(t){this._visible=t}get userData(){return this._userData}set userData(t){this._userData=t}applyMatrix(t){this._matrix?this._matrix=t.clone().multiply(this._matrix):this._matrix=t.clone(),z.transformBox(this._box,t)}recomputeBoundingBox(){}highlight(){}unhighlight(){}fastDeepClone(){return this}addChild(t){}}class u{static rgbToHex(t){const e=t>>16&255,i=t>>8&255,s=t&255;return`#${e.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`}static resolveRgb(t,e,i){return i==="fill"&&t.color.isForeground&&this.isSolidBackgroundHatch(t)?e.backgroundColor:U.fromBackgroundColor(e.backgroundColor).resolveSubEntityTraitsRgb(t)}static strokeAttributes(t,e){const i={stroke:this.rgbToHex(this.resolveRgb(t,e,"line")),fill:"none"};if(!e.showLineWeight)i["stroke-width"]="1",i["vector-effect"]="non-scaling-stroke";else{const r=this.resolveStrokeWidth(t.lineWeight);r!=null&&(i["stroke-width"]=String(r))}const s=this.resolveOpacity(t);s!=null&&s<1&&(i["stroke-opacity"]=String(s));const n=this.strokeDasharray(t,e);return n&&(i["stroke-dasharray"]=n),i}static fillAttributes(t,e){const i={fill:this.rgbToHex(this.resolveRgb(t,e,"fill")),stroke:"none"},s=this.resolveOpacity(t);return s!=null&&s<1&&(i["fill-opacity"]=String(s)),i}static textAttributes(t,e){const i={fill:this.rgbToHex(this.resolveRgb(t,e,"text")),stroke:"none"},s=this.resolveOpacity(t);return s!=null&&s<1&&(i["fill-opacity"]=String(s)),i}static pointAttributes(t,e){return this.textAttributes(t,e)}static formatAttributes(t){return Object.entries(t).map(([e,i])=>`${e}="${xt(i)}"`).join(" ")}static tag(t,e,i){const s=this.formatAttributes(e);return i==null?`<${t} ${s}/>`:`<${t} ${s}>${i}</${t}>`}static isSolidBackgroundHatch(t){if((t.drawOrder??0)>=0)return!1;const e=t.fillType;return e.gradient?!1:!e.definitionLines||e.definitionLines.length===0}static resolveStrokeWidth(t){return t<0?null:Math.max(.01,t/100)}static resolveOpacity(t){var e;const i=(e=t.transparency)==null?void 0:e.alpha;return i==null||Number.isNaN(i)?null:Math.min(1,Math.max(0,i))}static strokeDasharray(t,e){const i=t.lineType.pattern;if(!i||i.length===0)return;const s=e.ltscale*e.celtscale*t.lineTypeScale,n=this.patternToDashSegments(i,s);if(n.length!==0)return n.join(" ")}static patternToDashSegments(t,e){const i=[];for(const s of t){let n=s.elementLength;n<0&&s.elementTypeFlag!==0&&(n=Math.abs(n)),n*=e,n===0&&(n=.5*e),i.push(Math.abs(n))}return i}}function xt(a){return a.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;")}class gt extends y{constructor(t,e,i,s){super();const n=t.tessellate(s);let r="";for(const o of n){if(o.length===0)continue;const[h,...c]=o;r+=`M${h.x},${h.y}`;for(const l of c)r+=` L${l.x},${l.y}`;r+=" Z";for(const l of o)this._box.expandByPoint(l)}if(r){const o={d:r,"fill-rule":"evenodd",...u.fillAttributes(e,i)};this.svg=u.tag("path",o)}}}class ft extends y{constructor(t,e,i,s){super();const n=t.tessellate(s).reduce((o,h,c)=>(o+=c===0?"M":"L",o+=`${h.x},${h.y}`,o),"");if(n){const o={d:n,...u.strokeAttributes(e,i)};this.svg=u.tag("path",o)}const r=t.box;this._box.min.copy(r.min),this._box.max.copy(r.max)}}class dt extends y{constructor(t,e,i,s){super();const n=t.tessellate(s).reduce((o,h,c)=>(o+=c===0?"M":"L",o+=`${h.x},${h.y}`,o),"");if(n){const o={d:n,...u.strokeAttributes(e,i)};this.svg=u.tag("path",o)}const r=t.box;this._box.min.copy(r.min),this._box.max.copy(r.max)}}class Y{static isSafeEmbeddedUrl(t){const e=t.trim();return e.startsWith("data:")||e.startsWith("#")}static sanitizeExternalReferences(t){return t.replace(/<(?:image|use)\b[^>]*\s(?:xlink:)?href="(?!data:|#)[^"]*"[^>]*\/?>\s*/gi,"")}static async rasterizeSvgDataUrl(t){return typeof document>"u"?t:new Promise((e,i)=>{const s=new Image;s.onload=()=>{const n=Math.max(1,s.naturalWidth||1),r=Math.max(1,s.naturalHeight||1),o=document.createElement("canvas");o.width=n,o.height=r;const h=o.getContext("2d");if(!h){i(new Error("Canvas 2D context unavailable"));return}h.drawImage(s,0,0,n,r),e(o.toDataURL("image/png"))},s.onerror=()=>i(new Error("Failed to rasterize embedded SVG image")),s.src=t})}}class pt extends y{constructor(t){super(),this._childCount=t.length;const e=t.map(i=>i.renderSvg()).filter(Boolean).join(`
4
4
  `);this._localSvg=e;for(const i of t)this._box.union(i.box)}get childCount(){return this._childCount}}class F extends y{constructor(t,e,i,s){super();const{boundary:n}=e;if(n.length<2||!Y.isSafeEmbeddedUrl(t))return;let r=1/0,o=1/0,h=-1/0,c=-1/0;for(const x of n)x.x<r&&(r=x.x),x.y<o&&(o=x.y),x.x>h&&(h=x.x),x.y>c&&(c=x.y),this._box.expandByPoint(x);const l=h-r,m=c-o,f=bt(t);this._localSvg=`<image x="${r}" y="${o}" width="${l}" height="${m}" href="${f}" xlink:href="${f}" transform="scale(1,-1) translate(0,${-(o*2+m)})"/>`}static async fromBlob(t,e,i,s){let n=await yt(t);if(t.type==="image/svg+xml"||n.startsWith("data:image/svg+xml"))try{n=await Y.rasterizeSvgDataUrl(n)}catch{return new F("",e,i,s)}return new F(n,e,i,s)}}function yt(a){return new Promise((t,e)=>{const i=new FileReader;i.onload=()=>t(i.result),i.onerror=e,i.readAsDataURL(a)})}function bt(a){return a.replace(/&/g,"&amp;").replace(/"/g,"&quot;")}class vt extends y{constructor(t,e,i){super();const s=t.reduce((n,r,o)=>(n+=o===0?"M":"L",n+=r.x+","+r.y,this.box.expandByPoint(r),n),"");if(s){const n={d:s,...u.strokeAttributes(e,i)};this.svg=u.tag("path",n)}}}class wt extends y{constructor(t,e,i,s,n){super();const r=u.strokeAttributes(s,n),o=[];for(let h=0;h+1<i.length;h+=2){const c=i[h]*e,l=i[h+1]*e,m=t[c],f=t[c+1],x=t[l],p=t[l+1];o.push(u.tag("line",{x1:String(m),y1:String(f),x2:String(x),y2:String(p),...r})),this._box.expandByPoint({x:m,y:f}),this._box.expandByPoint({x,y:p})}this.svg=o.join(`
@@ -13,4 +13,4 @@ ${h}
13
13
  <g transform="matrix(1,0,0,-1,0,0)">
14
14
  ${i}
15
15
  </g>
16
- </svg>`)}buildBackgroundRect(t){const e=u.rgbToHex(this._currentBackgroundColor),i=Math.max(t.width,1),s=Math.max(t.height,1);return` <rect x="${t.x}" y="${t.y}" width="${i}" height="${s}" fill="${e}"/>`}}const Qt=new y;class te{async convert(t){j.prepareExport();const e=t.doc.database.tables.blockTable.modelSpace.newIterator(),i=new j;this.configureRenderer(i,t);for(const r of e)r.worldDraw(i);const s=await i.exportAsync(),n=tt(t.doc.fileName||t.doc.docTitle,"svg");this.createFileAndDownloadIt(s,n)}configureRenderer(t,e){const i=e.doc.database;t.ltscale=i.ltscale,t.celtscale=i.celtscale,t.showLineWeight=!!i.lwdisplay,t.setFontMapping(et.instance.fontMapping);const s=e.view,n=(s==null?void 0:s.backgroundColor)??16777215;t.currentBackgroundColor=n,t.changeForeground(n===0?16777215:0)}createFileAndDownloadIt(t,e){const i=new Blob([t],{type:"image/svg+xml;charset=utf-8"}),s=URL.createObjectURL(i),n=document.createElement("a");n.href=s,n.download=e,document.body.appendChild(n),n.click(),document.body.removeChild(n),window.setTimeout(()=>URL.revokeObjectURL(s),6e4)}}class ee extends Q{async execute(t){await new te().convert(t)}}const ie="1.7.2",se={version:ie};class ne{constructor(){this.name="SvgPlugin",this.version=se.version,this.description="SVG export (csvg) command",this.registeredCommands=[]}onLoad(t,e){const i=Z.SYSTEMT_COMMAND_GROUP_NAME;e.addCommand(i,"csvg","csvg",new ee),this.registeredCommands.push({group:i,name:"csvg"})}onUnload(t,e){for(const i of this.registeredCommands)e.removeCmd(i.group,i.name);this.registeredCommands=[]}}async function ae(){return new ne}export{ee as AcApConvertToSvgCmd,te as AcApSvgConvertor,j as AcSvgRenderer,ce as SVG_PLUGIN_NAME,le as SVG_PLUGIN_TRIGGERS,ae as createSvgPlugin};
16
+ </svg>`)}buildBackgroundRect(t){const e=u.rgbToHex(this._currentBackgroundColor),i=Math.max(t.width,1),s=Math.max(t.height,1);return` <rect x="${t.x}" y="${t.y}" width="${i}" height="${s}" fill="${e}"/>`}}const Qt=new y;class te{async convert(t){j.prepareExport();const e=t.doc.database.tables.blockTable.modelSpace.newIterator(),i=new j;this.configureRenderer(i,t);for(const r of e)r.worldDraw(i);const s=await i.exportAsync(),n=tt(t.doc.fileName||t.doc.docTitle,"svg");this.createFileAndDownloadIt(s,n)}configureRenderer(t,e){const i=e.doc.database;t.ltscale=i.ltscale,t.celtscale=i.celtscale,t.showLineWeight=!!i.lwdisplay,t.setFontMapping(et.instance.fontMapping);const s=e.view,n=(s==null?void 0:s.backgroundColor)??16777215;t.currentBackgroundColor=n,t.changeForeground(n===0?16777215:0)}createFileAndDownloadIt(t,e){const i=new Blob([t],{type:"image/svg+xml;charset=utf-8"}),s=URL.createObjectURL(i),n=document.createElement("a");n.href=s,n.download=e,document.body.appendChild(n),n.click(),document.body.removeChild(n),window.setTimeout(()=>URL.revokeObjectURL(s),6e4)}}class ee extends Q{async execute(t){await new te().convert(t)}}const ie="1.7.3",se={version:ie};class ne{constructor(){this.name="SvgPlugin",this.version=se.version,this.description="SVG export (csvg) command",this.registeredCommands=[]}onLoad(t,e){const i=Z.SYSTEMT_COMMAND_GROUP_NAME;e.addCommand(i,"csvg","csvg",new ee),this.registeredCommands.push({group:i,name:"csvg"})}onUnload(t,e){for(const i of this.registeredCommands)e.removeCmd(i.group,i.name);this.registeredCommands=[]}}async function ae(){return new ne}export{ee as AcApConvertToSvgCmd,te as AcApSvgConvertor,j as AcSvgRenderer,ce as SVG_PLUGIN_NAME,le as SVG_PLUGIN_TRIGGERS,ae as createSvgPlugin};