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

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,5 +1,5 @@
1
- (function(nt,q){typeof exports=="object"&&typeof module<"u"?q(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],q):(nt=typeof globalThis<"u"?globalThis:nt||self,q(nt["pdf-canvas"]={},nt.Vue))})(this,function(nt,q){"use strict";var CC=Object.defineProperty;var Yb=nt=>{throw TypeError(nt)};var AC=(nt,q,_t)=>q in nt?CC(nt,q,{enumerable:!0,configurable:!0,writable:!0,value:_t}):nt[q]=_t;var $=(nt,q,_t)=>AC(nt,typeof q!="symbol"?q+"":q,_t),$g=(nt,q,_t)=>q.has(nt)||Yb("Cannot "+_t);var l=(nt,q,_t)=>($g(nt,q,"read from private field"),_t?_t.call(nt):q.get(nt)),y=(nt,q,_t)=>q.has(nt)?Yb("Cannot add the same private member more than once"):q instanceof WeakSet?q.add(nt):q.set(nt,_t),m=(nt,q,_t,A)=>($g(nt,q,"write to private field"),A?A.call(nt,_t):q.set(nt,_t),_t),w=(nt,q,_t)=>($g(nt,q,"access private method"),_t);var Ge=(nt,q,_t,A)=>({set _(jc){m(nt,q,jc,_t)},get _(){return l(nt,q,A)}});var Xi,Ed,qg,Jh,In,Rr,zs,Lr,Zh,tl,ad,$b,Le,qb,Kb,kd,Qb,Kg,el,Fr,Ir,Nn,Jb,Zb,ty,hd,ha,sl,we,la,Md,Bt,jn,il,Dt,ld,ey,ca,ss,Kt,ae,ua,Ui,da,ws,Bn,Nr,fa,jr,ui,Vs,Br,nl,rl,ga,ol,di,Hn,pa,Gn,fi,ud,zn,al,Vn,Hr,hl,ll,ee,pt,Yi,Gr,cl,ul,Xn,gi,$i,dl,xs,I,Pd,Qg,sy,iy,Dd,ny,ry,oy,Jg,ay,Zg,tp,hy,ze,xn,ly,cy,ep,uy,Cc,sp,se,pi,Xs,ba,mi,is,ya,bi,$e,qi,zr,yi,Wn,Ws,Ac,Od,fl,Vr,gl,pl,ml,bl,yl,va,Ki,Xr,Un,Qi,dy,fy,ip,Wr,Us,xt,_a,Yn,vl,Ur,he,Yr,Ji,$n,_l,$r,ns,wl,qr,Zi,vi,wa,xa,Ss,Kr,xl,dd,Y,np,Sl,rp,Rd,gy,py,op,Ld,ap,my,by,yy,hp,vy,lp,_y,wy,xy,cp,Tc,Qr,Jr,ie,fd,Sy,Cl,Sa,Ca,Cs,Cy,Ay,Ty,Fd,Al,Zr,Aa,tn,en,xe,to,eo,j,Te,Ec,mh,Id,bh,Ey,up,yh,kc,Mc,dp,Pc,Ys,fp,gp,pp,Tl,El,so,kl,Ml,Pl,Dl,Ta,qn,mt,Ea,ka,Ol,mp,Ub,Kn,qe,Rl,Ll,io,sn,Fl,Il,no,Ma,Pa,Qn,Da,Nl,Oa,ro,jl,Bl,oo,ao,Hl,Jn,Ra,nn,ky,My,bp,rs,Nd,yp,Py,Dy,pd,Zn,rn,As,vh,jd,on,bd,yd,ho,lo,La,Bd,Fa,Hd,an,_i,Ia,Na,hn,co,Dc,os,Gl,vp,tr,er,uo,go,ja,Ba,zl,_p,as,Ho,Oy,Ry,Ha,vd,_d,Ga,po,Lt,ln,za,Vl,Xl,Va,cn,$s,un,Wl,dn,Ul,mo,bo,bt,Gd,wp,Ly,Fy,Iy,Ny,zd,Vd,xp,Yl,$l,ql,Kl,Ql,yo,Jl,Sp,Zl,tc,Cp,ec,vo,_o,sc,wo,jy,Ap,qs,hs,ic,xo,ls,Ut,By,Hy,Gy,Xd,fn,Wd,Ud,zy,Tp,Vy,cs,Ks,Xa,Wa,wi,it,So,Co,nc,rc,Ua,Ya,sr,oc,wd,xd,Jt,Oc,Xy,Wy,Uy,Yy,$y,qy,$a,Ao,pn,ac,us,hc,Ht,Sd,Ky,lc,cc,ir,Qs,Ie,Qy,Yd,Jy,Zy,Ep,uc,qa,Js,To,Ka,Zt,dc,Qa,fc,gc,nr,Zs,Ja,pc,yt,kp,Mp,Pp,Go,tv,gr,Za,mc,mn,Eo,th,Qe,bc,yc,ko,Ts,ds,le,eh,bn,Se,sh,Es,vc,J,Dp,$d,ev,sv,iv,Op,zo,ks,_h,nv,qd,Rc,rv,ov,av,hv,lv,Mo,fs,ih,ne,Po,Do,rr,or,ar,Oo,lt,Rp,Lp,Fp,Lc,cv,Kd,Fc,wh,xi,re,oe,Ro,nh,Ne,ce,Ms,Lo,Fo,Io,rh,Qd,je,_c,wc,gs,Si,Ci,oh,ah,hh,ue,Sn,uv,dv,fv,lh,Cd,gv,Ot,de,hr,yn,lr,uh,Ai,Ti,ps,dh,ct,Ic,Nc,Jd,Ip,Zd,Np,tf,pv,No,fh,Ei,cr,vn,Ps,ur,gh,jo,ti,_n,Ce,wn,V,dr,kt,mv,Di,jp,Bp,ef,si,Sc,Be,Bo,Ad,bv,ki,Hp,yv,Gp;var _t=typeof document<"u"?document.currentScript:null;function A(a,t,e){return(t=function(s){var i=function(n,r){if(typeof n!="object"||!n)return n;var o=n[Symbol.toPrimitive];if(o!==void 0){var h=o.call(n,r);if(typeof h!="object")return h;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(n)}(s,"string");return typeof i=="symbol"?i:i+""}(t))in a?Object.defineProperty(a,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):a[t]=e,a}function jc(a,t){var e=Object.keys(a);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(a);t&&(s=s.filter(function(i){return Object.getOwnPropertyDescriptor(a,i).enumerable})),e.push.apply(e,s)}return e}function E(a){for(var t=1;t<arguments.length;t++){var e=arguments[t]!=null?arguments[t]:{};t%2?jc(Object(e),!0).forEach(function(s){A(a,s,e[s])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(e)):jc(Object(e)).forEach(function(s){Object.defineProperty(a,s,Object.getOwnPropertyDescriptor(e,s))})}return a}function Ct(a,t){if(a==null)return{};var e,s,i=function(r,o){if(r==null)return{};var h={};for(var c in r)if({}.hasOwnProperty.call(r,c)){if(o.indexOf(c)>=0)continue;h[c]=r[c]}return h}(a,t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(a);for(s=0;s<n.length;s++)e=n[s],t.indexOf(e)>=0||{}.propertyIsEnumerable.call(a,e)&&(i[e]=a[e])}return i}function Cn(a,t){return t||(t=a.slice(0)),Object.freeze(Object.defineProperties(a,{raw:{value:Object.freeze(t)}}))}class zp{constructor(){A(this,"browserShadowBlurConstant",1),A(this,"DPI",96),A(this,"devicePixelRatio",typeof window<"u"?window.devicePixelRatio:1),A(this,"perfLimitSizeTotal",2097152),A(this,"maxCacheSideLimit",4096),A(this,"minCacheSideLimit",256),A(this,"disableStyleCopyPaste",!1),A(this,"enableGLFiltering",!0),A(this,"textureSize",4096),A(this,"forceGLPutImageData",!1),A(this,"cachesBoundsOfCurve",!1),A(this,"fontPaths",{}),A(this,"NUM_FRACTION_DIGITS",4)}}const ht=new class extends zp{constructor(a){super(),this.configure(a)}configure(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Object.assign(this,a)}addFonts(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.fontPaths=E(E({},this.fontPaths),a)}removeFonts(){(arguments.length>0&&arguments[0]!==void 0?arguments[0]:[]).forEach(a=>{delete this.fontPaths[a]})}clearFonts(){this.fontPaths={}}restoreDefaults(a){const t=new zp,e=(a==null?void 0:a.reduce((s,i)=>(s[i]=t[i],s),{}))||t;this.configure(e)}},Oi=function(a){for(var t=arguments.length,e=new Array(t>1?t-1:0),s=1;s<t;s++)e[s-1]=arguments[s];return console[a]("fabric",...e)};class ii extends Error{constructor(t,e){super("fabric: ".concat(t),e)}}class sf extends ii{constructor(t){super("".concat(t," 'options.signal' is in 'aborted' state"))}}class vv{}class _v extends vv{testPrecision(t,e){const s="precision ".concat(e,` float;
2
- void main(){}`),i=t.createShader(t.FRAGMENT_SHADER);return!!i&&(t.shaderSource(i,s),t.compileShader(i),!!t.getShaderParameter(i,t.COMPILE_STATUS))}queryWebGL(t){const e=t.getContext("webgl");e&&(this.maxTextureSize=e.getParameter(e.MAX_TEXTURE_SIZE),this.GLPrecision=["highp","mediump","lowp"].find(s=>this.testPrecision(e,s)),e.getExtension("WEBGL_lose_context").loseContext(),Oi("log","WebGL: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const wv={};let Vp;const ni=()=>Vp||(Vp={document,window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new _v,dispose(){},copyPasteData:wv}),Vo=()=>ni().document,Bc=()=>ni().window,Xp=()=>{var a;return Math.max((a=ht.devicePixelRatio)!==null&&a!==void 0?a:Bc().devicePixelRatio,1)},xh=new class{constructor(){A(this,"charWidthsCache",{}),A(this,"boundsOfCurveCache",{})}getFontCache(a){let{fontFamily:t,fontStyle:e,fontWeight:s}=a;t=t.toLowerCase(),this.charWidthsCache[t]||(this.charWidthsCache[t]={});const i=this.charWidthsCache[t],n="".concat(e.toLowerCase(),"_").concat((s+"").toLowerCase());return i[n]||(i[n]={}),i[n]}clearFontCache(a){(a=(a||"").toLowerCase())?this.charWidthsCache[a]&&delete this.charWidthsCache[a]:this.charWidthsCache={}}limitDimsByArea(a){const{perfLimitSizeTotal:t}=ht,e=Math.sqrt(t*a);return[Math.floor(e),Math.floor(t/e)]}},nf="6.6.1";function pr(){}const An=Math.PI/2,Ri=2*Math.PI,rf=Math.PI/180,Ee=Object.freeze([1,0,0,1,0,0]),of=16,Tn=.4477152502,Q="center",dt="left",Ve="top",af="bottom",It="right",ke="none",hf=/\r?\n/,Wp="moving",Hc="scaling",Up="rotating",lf="rotate",Yp="skewing",Sh="resizing",xv="modifyPoly",Sv="modifyPath",Gc="changed",zc="scale",Me="scaleX",Je="scaleY",Xo="skewX",Wo="skewY",zt="fill",Pe="stroke",Vc="modified",Uo="json",cf="svg",N=new class{constructor(){this[Uo]=new Map,this[cf]=new Map}has(a){return this[Uo].has(a)}getClass(a){const t=this[Uo].get(a);if(!t)throw new ii("No class registered for ".concat(a));return t}setClass(a,t){t?this[Uo].set(t,a):(this[Uo].set(a.type,a),this[Uo].set(a.type.toLowerCase(),a))}getSVGClass(a){return this[cf].get(a)}setSVGClass(a,t){this[cf].set(t??a.type.toLowerCase(),a)}},Xc=new class extends Array{remove(a){const t=this.indexOf(a);t>-1&&this.splice(t,1)}cancelAll(){const a=this.splice(0);return a.forEach(t=>t.abort()),a}cancelByCanvas(a){if(!a)return[];const t=this.filter(e=>{var s;return e.target===a||typeof e.target=="object"&&((s=e.target)===null||s===void 0?void 0:s.canvas)===a});return t.forEach(e=>e.abort()),t}cancelByTarget(a){if(!a)return[];const t=this.filter(e=>e.target===a);return t.forEach(e=>e.abort()),t}};class Cv{constructor(){A(this,"__eventListeners",{})}on(t,e){if(this.__eventListeners||(this.__eventListeners={}),typeof t=="object")return Object.entries(t).forEach(s=>{let[i,n]=s;this.on(i,n)}),()=>this.off(t);if(e){const s=t;return this.__eventListeners[s]||(this.__eventListeners[s]=[]),this.__eventListeners[s].push(e),()=>this.off(s,e)}return()=>!1}once(t,e){if(typeof t=="object"){const s=[];return Object.entries(t).forEach(i=>{let[n,r]=i;s.push(this.once(n,r))}),()=>s.forEach(i=>i())}if(e){const s=this.on(t,function(){for(var i=arguments.length,n=new Array(i),r=0;r<i;r++)n[r]=arguments[r];e.call(this,...n),s()});return s}return()=>!1}_removeEventListener(t,e){if(this.__eventListeners[t])if(e){const s=this.__eventListeners[t],i=s.indexOf(e);i>-1&&s.splice(i,1)}else this.__eventListeners[t]=[]}off(t,e){if(this.__eventListeners)if(t===void 0)for(const s in this.__eventListeners)this._removeEventListener(s);else typeof t=="object"?Object.entries(t).forEach(s=>{let[i,n]=s;this._removeEventListener(i,n)}):this._removeEventListener(t,e)}fire(t,e){var s;if(!this.__eventListeners)return;const i=(s=this.__eventListeners[t])===null||s===void 0?void 0:s.concat();if(i)for(let n=0;n<i.length;n++)i[n].call(this,e||{})}}const mr=(a,t)=>{const e=a.indexOf(t);return e!==-1&&a.splice(e,1),a},Ds=a=>{if(a===0)return 1;switch(Math.abs(a)/An){case 1:case 3:return 0;case 2:return-1}return Math.cos(a)},Os=a=>{if(a===0)return 0;const t=a/An,e=Math.sign(a);switch(t){case 1:return e;case 2:return 0;case 3:return-e}return Math.sin(a)};class P{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;typeof t=="object"?(this.x=t.x,this.y=t.y):(this.x=t,this.y=e)}add(t){return new P(this.x+t.x,this.y+t.y)}addEquals(t){return this.x+=t.x,this.y+=t.y,this}scalarAdd(t){return new P(this.x+t,this.y+t)}scalarAddEquals(t){return this.x+=t,this.y+=t,this}subtract(t){return new P(this.x-t.x,this.y-t.y)}subtractEquals(t){return this.x-=t.x,this.y-=t.y,this}scalarSubtract(t){return new P(this.x-t,this.y-t)}scalarSubtractEquals(t){return this.x-=t,this.y-=t,this}multiply(t){return new P(this.x*t.x,this.y*t.y)}scalarMultiply(t){return new P(this.x*t,this.y*t)}scalarMultiplyEquals(t){return this.x*=t,this.y*=t,this}divide(t){return new P(this.x/t.x,this.y/t.y)}scalarDivide(t){return new P(this.x/t,this.y/t)}scalarDivideEquals(t){return this.x/=t,this.y/=t,this}eq(t){return this.x===t.x&&this.y===t.y}lt(t){return this.x<t.x&&this.y<t.y}lte(t){return this.x<=t.x&&this.y<=t.y}gt(t){return this.x>t.x&&this.y>t.y}gte(t){return this.x>=t.x&&this.y>=t.y}lerp(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:.5;return e=Math.max(Math.min(1,e),0),new P(this.x+(t.x-this.x)*e,this.y+(t.y-this.y)*e)}distanceFrom(t){const e=this.x-t.x,s=this.y-t.y;return Math.sqrt(e*e+s*s)}midPointFrom(t){return this.lerp(t)}min(t){return new P(Math.min(this.x,t.x),Math.min(this.y,t.y))}max(t){return new P(Math.max(this.x,t.x),Math.max(this.y,t.y))}toString(){return"".concat(this.x,",").concat(this.y)}setXY(t,e){return this.x=t,this.y=e,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setFromPoint(t){return this.x=t.x,this.y=t.y,this}swap(t){const e=this.x,s=this.y;this.x=t.x,this.y=t.y,t.x=e,t.y=s}clone(){return new P(this.x,this.y)}rotate(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:uf;const s=Os(t),i=Ds(t),n=this.subtract(e);return new P(n.x*i-n.y*s,n.x*s+n.y*i).add(e)}transform(t){let e=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return new P(t[0]*this.x+t[2]*this.y+(e?0:t[4]),t[1]*this.x+t[3]*this.y+(e?0:t[5]))}}const uf=new P(0,0),Wc=a=>!!a&&Array.isArray(a._objects);function $p(a){class t extends a{constructor(){super(...arguments),A(this,"_objects",[])}_onObjectAdded(s){}_onObjectRemoved(s){}_onStackOrderChanged(s){}add(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];const r=this._objects.push(...i);return i.forEach(o=>this._onObjectAdded(o)),r}insertAt(s){for(var i=arguments.length,n=new Array(i>1?i-1:0),r=1;r<i;r++)n[r-1]=arguments[r];return this._objects.splice(s,0,...n),n.forEach(o=>this._onObjectAdded(o)),this._objects.length}remove(){const s=this._objects,i=[];for(var n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return r.forEach(h=>{const c=s.indexOf(h);c!==-1&&(s.splice(c,1),i.push(h),this._onObjectRemoved(h))}),i}forEachObject(s){this.getObjects().forEach((i,n,r)=>s(i,n,r))}getObjects(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];return i.length===0?[...this._objects]:this._objects.filter(r=>r.isType(...i))}item(s){return this._objects[s]}isEmpty(){return this._objects.length===0}size(){return this._objects.length}contains(s,i){return!!this._objects.includes(s)||!!i&&this._objects.some(n=>n instanceof t&&n.contains(s,!0))}complexity(){return this._objects.reduce((s,i)=>s+=i.complexity?i.complexity():0,0)}sendObjectToBack(s){return!(!s||s===this._objects[0])&&(mr(this._objects,s),this._objects.unshift(s),this._onStackOrderChanged(s),!0)}bringObjectToFront(s){return!(!s||s===this._objects[this._objects.length-1])&&(mr(this._objects,s),this._objects.push(s),this._onStackOrderChanged(s),!0)}sendObjectBackwards(s,i){if(!s)return!1;const n=this._objects.indexOf(s);if(n!==0){const r=this.findNewLowerIndex(s,n,i);return mr(this._objects,s),this._objects.splice(r,0,s),this._onStackOrderChanged(s),!0}return!1}bringObjectForward(s,i){if(!s)return!1;const n=this._objects.indexOf(s);if(n!==this._objects.length-1){const r=this.findNewUpperIndex(s,n,i);return mr(this._objects,s),this._objects.splice(r,0,s),this._onStackOrderChanged(s),!0}return!1}moveObjectTo(s,i){return s!==this._objects[i]&&(mr(this._objects,s),this._objects.splice(i,0,s),this._onStackOrderChanged(s),!0)}findNewLowerIndex(s,i,n){let r;if(n){r=i;for(let o=i-1;o>=0;--o)if(s.isOverlapping(this._objects[o])){r=o;break}}else r=i-1;return r}findNewUpperIndex(s,i,n){let r;if(n){r=i;for(let o=i+1;o<this._objects.length;++o)if(s.isOverlapping(this._objects[o])){r=o;break}}else r=i+1;return r}collectObjects(s){let{left:i,top:n,width:r,height:o}=s,{includeIntersecting:h=!0}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const c=[],u=new P(i,n),d=u.add(new P(r,o));for(let f=this._objects.length-1;f>=0;f--){const g=this._objects[f];g.selectable&&g.visible&&(h&&g.intersectsWithRect(u,d)||g.isContainedWithinRect(u,d)||h&&g.containsPoint(u)||h&&g.containsPoint(d))&&c.push(g)}return c}}return t}class qp extends Cv{_setOptions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};for(const e in t)this.set(e,t[e])}_setObject(t){for(const e in t)this._set(e,t[e])}set(t,e){return typeof t=="object"?this._setObject(t):this._set(t,e),this}_set(t,e){this[t]=e}toggle(t){const e=this.get(t);return typeof e=="boolean"&&this.set(t,!e),this}get(t){return this[t]}}function Ch(a){return Bc().requestAnimationFrame(a)}function Kp(a){return Bc().cancelAnimationFrame(a)}let Av=0;const En=()=>Av++,ms=()=>{const a=Vo().createElement("canvas");if(!a||a.getContext===void 0)throw new ii("Failed to create `canvas` element");return a},Qp=()=>Vo().createElement("img"),Rs=a=>{const t=ms();return t.width=a.width,t.height=a.height,t},df=(a,t,e)=>a.toDataURL("image/".concat(t),e),ff=(a,t,e)=>new Promise((s,i)=>{a.toBlob(s,"image/".concat(t),e)}),Rt=a=>a*rf,kn=a=>a/rf,Jp=a=>a.every((t,e)=>t===Ee[e]),ge=(a,t,e)=>new P(a).transform(t,e),Xe=a=>{const t=1/(a[0]*a[3]-a[1]*a[2]),e=[t*a[3],-t*a[1],-t*a[2],t*a[0],0,0],{x:s,y:i}=new P(a[4],a[5]).transform(e,!0);return e[4]=-s,e[5]=-i,e},Nt=(a,t,e)=>[a[0]*t[0]+a[2]*t[1],a[1]*t[0]+a[3]*t[1],a[0]*t[2]+a[2]*t[3],a[1]*t[2]+a[3]*t[3],e?0:a[0]*t[4]+a[2]*t[5]+a[4],e?0:a[1]*t[4]+a[3]*t[5]+a[5]],Uc=(a,t)=>a.reduceRight((e,s)=>s&&e?Nt(s,e,t):s||e,void 0)||Ee.concat(),Zp=a=>{let[t,e]=a;return Math.atan2(e,t)},br=a=>{const t=Zp(a),e=Math.pow(a[0],2)+Math.pow(a[1],2),s=Math.sqrt(e),i=(a[0]*a[3]-a[2]*a[1])/s,n=Math.atan2(a[0]*a[2]+a[1]*a[3],e);return{angle:kn(t),scaleX:s,scaleY:i,skewX:kn(n),skewY:0,translateX:a[4]||0,translateY:a[5]||0}},Yo=function(a){return[1,0,0,1,a,arguments.length>1&&arguments[1]!==void 0?arguments[1]:0]};function $o(){let{angle:a=0}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},{x:t=0,y:e=0}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const s=Rt(a),i=Ds(s),n=Os(s);return[i,n,-n,i,t?t-(i*t-n*e):0,e?e-(n*t+i*e):0]}const Yc=function(a){return[a,0,0,arguments.length>1&&arguments[1]!==void 0?arguments[1]:a,0,0]},tm=a=>Math.tan(Rt(a)),gf=a=>[1,0,tm(a),1,0,0],pf=a=>[1,tm(a),0,1,0,0],Ah=a=>{let{scaleX:t=1,scaleY:e=1,flipX:s=!1,flipY:i=!1,skewX:n=0,skewY:r=0}=a,o=Yc(s?-t:t,i?-e:e);return n&&(o=Nt(o,gf(n),!0)),r&&(o=Nt(o,pf(r),!0)),o},em=a=>{const{translateX:t=0,translateY:e=0,angle:s=0}=a;let i=Yo(t,e);s&&(i=Nt(i,$o({angle:s})));const n=Ah(a);return Jp(n)||(i=Nt(i,n)),i},Th=function(a){let{signal:t,crossOrigin:e=null}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise(function(s,i){if(t&&t.aborted)return i(new sf("loadImage"));const n=Qp();let r;t&&(r=function(h){n.src="",i(h)},t.addEventListener("abort",r,{once:!0}));const o=function(){n.onload=n.onerror=null,r&&(t==null||t.removeEventListener("abort",r)),s(n)};a?(n.onload=o,n.onerror=function(){r&&(t==null||t.removeEventListener("abort",r)),i(new ii("Error loading ".concat(n.src)))},e&&(n.crossOrigin=e),n.src=a):o()})},qo=function(a){let{signal:t,reviver:e=pr}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise((s,i)=>{const n=[];t&&t.addEventListener("abort",i,{once:!0}),Promise.all(a.map(r=>N.getClass(r.type).fromObject(r,{signal:t}).then(o=>(e(r,o),n.push(o),o)))).then(s).catch(r=>{n.forEach(o=>{o.dispose&&o.dispose()}),i(r)}).finally(()=>{t&&t.removeEventListener("abort",i)})})},Eh=function(a){let{signal:t}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise((e,s)=>{const i=[];t&&t.addEventListener("abort",s,{once:!0});const n=Object.values(a).map(o=>o&&o.type&&N.has(o.type)?qo([o],{signal:t}).then(h=>{let[c]=h;return i.push(c),c}):o),r=Object.keys(a);Promise.all(n).then(o=>o.reduce((h,c,u)=>(h[r[u]]=c,h),{})).then(e).catch(o=>{i.forEach(h=>{h.dispose&&h.dispose()}),s(o)}).finally(()=>{t&&t.removeEventListener("abort",s)})})},yr=function(a){return(arguments.length>1&&arguments[1]!==void 0?arguments[1]:[]).reduce((t,e)=>(e in a&&(t[e]=a[e]),t),{})},mf=(a,t)=>Object.keys(a).reduce((e,s)=>(t(a[s],s,a)&&(e[s]=a[s]),e),{}),sm={aliceblue:"#F0F8FF",antiquewhite:"#FAEBD7",aqua:"#0FF",aquamarine:"#7FFFD4",azure:"#F0FFFF",beige:"#F5F5DC",bisque:"#FFE4C4",black:"#000",blanchedalmond:"#FFEBCD",blue:"#00F",blueviolet:"#8A2BE2",brown:"#A52A2A",burlywood:"#DEB887",cadetblue:"#5F9EA0",chartreuse:"#7FFF00",chocolate:"#D2691E",coral:"#FF7F50",cornflowerblue:"#6495ED",cornsilk:"#FFF8DC",crimson:"#DC143C",cyan:"#0FF",darkblue:"#00008B",darkcyan:"#008B8B",darkgoldenrod:"#B8860B",darkgray:"#A9A9A9",darkgrey:"#A9A9A9",darkgreen:"#006400",darkkhaki:"#BDB76B",darkmagenta:"#8B008B",darkolivegreen:"#556B2F",darkorange:"#FF8C00",darkorchid:"#9932CC",darkred:"#8B0000",darksalmon:"#E9967A",darkseagreen:"#8FBC8F",darkslateblue:"#483D8B",darkslategray:"#2F4F4F",darkslategrey:"#2F4F4F",darkturquoise:"#00CED1",darkviolet:"#9400D3",deeppink:"#FF1493",deepskyblue:"#00BFFF",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1E90FF",firebrick:"#B22222",floralwhite:"#FFFAF0",forestgreen:"#228B22",fuchsia:"#F0F",gainsboro:"#DCDCDC",ghostwhite:"#F8F8FF",gold:"#FFD700",goldenrod:"#DAA520",gray:"#808080",grey:"#808080",green:"#008000",greenyellow:"#ADFF2F",honeydew:"#F0FFF0",hotpink:"#FF69B4",indianred:"#CD5C5C",indigo:"#4B0082",ivory:"#FFFFF0",khaki:"#F0E68C",lavender:"#E6E6FA",lavenderblush:"#FFF0F5",lawngreen:"#7CFC00",lemonchiffon:"#FFFACD",lightblue:"#ADD8E6",lightcoral:"#F08080",lightcyan:"#E0FFFF",lightgoldenrodyellow:"#FAFAD2",lightgray:"#D3D3D3",lightgrey:"#D3D3D3",lightgreen:"#90EE90",lightpink:"#FFB6C1",lightsalmon:"#FFA07A",lightseagreen:"#20B2AA",lightskyblue:"#87CEFA",lightslategray:"#789",lightslategrey:"#789",lightsteelblue:"#B0C4DE",lightyellow:"#FFFFE0",lime:"#0F0",limegreen:"#32CD32",linen:"#FAF0E6",magenta:"#F0F",maroon:"#800000",mediumaquamarine:"#66CDAA",mediumblue:"#0000CD",mediumorchid:"#BA55D3",mediumpurple:"#9370DB",mediumseagreen:"#3CB371",mediumslateblue:"#7B68EE",mediumspringgreen:"#00FA9A",mediumturquoise:"#48D1CC",mediumvioletred:"#C71585",midnightblue:"#191970",mintcream:"#F5FFFA",mistyrose:"#FFE4E1",moccasin:"#FFE4B5",navajowhite:"#FFDEAD",navy:"#000080",oldlace:"#FDF5E6",olive:"#808000",olivedrab:"#6B8E23",orange:"#FFA500",orangered:"#FF4500",orchid:"#DA70D6",palegoldenrod:"#EEE8AA",palegreen:"#98FB98",paleturquoise:"#AFEEEE",palevioletred:"#DB7093",papayawhip:"#FFEFD5",peachpuff:"#FFDAB9",peru:"#CD853F",pink:"#FFC0CB",plum:"#DDA0DD",powderblue:"#B0E0E6",purple:"#800080",rebeccapurple:"#639",red:"#F00",rosybrown:"#BC8F8F",royalblue:"#4169E1",saddlebrown:"#8B4513",salmon:"#FA8072",sandybrown:"#F4A460",seagreen:"#2E8B57",seashell:"#FFF5EE",sienna:"#A0522D",silver:"#C0C0C0",skyblue:"#87CEEB",slateblue:"#6A5ACD",slategray:"#708090",slategrey:"#708090",snow:"#FFFAFA",springgreen:"#00FF7F",steelblue:"#4682B4",tan:"#D2B48C",teal:"#008080",thistle:"#D8BFD8",tomato:"#FF6347",turquoise:"#40E0D0",violet:"#EE82EE",wheat:"#F5DEB3",white:"#FFF",whitesmoke:"#F5F5F5",yellow:"#FF0",yellowgreen:"#9ACD32"},bf=(a,t,e)=>(e<0&&(e+=1),e>1&&(e-=1),e<1/6?a+6*(t-a)*e:e<.5?t:e<2/3?a+(t-a)*(2/3-e)*6:a),im=(a,t,e,s)=>{a/=255,t/=255,e/=255;const i=Math.max(a,t,e),n=Math.min(a,t,e);let r,o;const h=(i+n)/2;if(i===n)r=o=0;else{const c=i-n;switch(o=h>.5?c/(2-i-n):c/(i+n),i){case a:r=(t-e)/c+(t<e?6:0);break;case t:r=(e-a)/c+2;break;case e:r=(a-t)/c+4}r/=6}return[Math.round(360*r),Math.round(100*o),Math.round(100*h),s]},nm=function(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"1";return parseFloat(a)/(a.endsWith("%")?100:1)},$c=a=>Math.min(Math.round(a),255).toString(16).toUpperCase().padStart(2,"0"),rm=a=>{let[t,e,s,i=1]=a;const n=Math.round(.3*t+.59*e+.11*s);return[n,n,n,i]};class gt{constructor(t){if(A(this,"isUnrecognised",!1),t)if(t instanceof gt)this.setSource([...t._source]);else if(Array.isArray(t)){const[e,s,i,n=1]=t;this.setSource([e,s,i,n])}else this.setSource(this._tryParsingColor(t));else this.setSource([0,0,0,1])}_tryParsingColor(t){return(t=t.toLowerCase())in sm&&(t=sm[t]),t==="transparent"?[255,255,255,0]:gt.sourceFromHex(t)||gt.sourceFromRgb(t)||gt.sourceFromHsl(t)||(this.isUnrecognised=!0)&&[0,0,0,1]}getSource(){return this._source}setSource(t){this._source=t}toRgb(){const[t,e,s]=this.getSource();return"rgb(".concat(t,",").concat(e,",").concat(s,")")}toRgba(){return"rgba(".concat(this.getSource().join(","),")")}toHsl(){const[t,e,s]=im(...this.getSource());return"hsl(".concat(t,",").concat(e,"%,").concat(s,"%)")}toHsla(){const[t,e,s,i]=im(...this.getSource());return"hsla(".concat(t,",").concat(e,"%,").concat(s,"%,").concat(i,")")}toHex(){return this.toHexa().slice(0,6)}toHexa(){const[t,e,s,i]=this.getSource();return"".concat($c(t)).concat($c(e)).concat($c(s)).concat($c(Math.round(255*i)))}getAlpha(){return this.getSource()[3]}setAlpha(t){return this._source[3]=t,this}toGrayscale(){return this.setSource(rm(this.getSource())),this}toBlackWhite(t){const[e,,,s]=rm(this.getSource()),i=e<(t||127)?0:255;return this.setSource([i,i,i,s]),this}overlayWith(t){t instanceof gt||(t=new gt(t));const e=this.getSource(),s=t.getSource(),[i,n,r]=e.map((o,h)=>Math.round(.5*o+.5*s[h]));return this.setSource([i,n,r,e[3]]),this}static fromRgb(t){return gt.fromRgba(t)}static fromRgba(t){return new gt(gt.sourceFromRgb(t))}static sourceFromRgb(t){const e=t.match(/^rgba?\(\s*(\d{0,3}(?:\.\d+)?%?)\s*[\s|,]\s*(\d{0,3}(?:\.\d+)?%?)\s*[\s|,]\s*(\d{0,3}(?:\.\d+)?%?)\s*(?:\s*[,/]\s*(\d{0,3}(?:\.\d+)?%?)\s*)?\)$/i);if(e){const[s,i,n]=e.slice(1,4).map(r=>{const o=parseFloat(r);return r.endsWith("%")?Math.round(2.55*o):o});return[s,i,n,nm(e[4])]}}static fromHsl(t){return gt.fromHsla(t)}static fromHsla(t){return new gt(gt.sourceFromHsl(t))}static sourceFromHsl(t){const e=t.match(/^hsla?\(\s*([+-]?\d{0,3}(?:\.\d+)?(?:deg|turn|rad)?)\s*[\s|,]\s*(\d{0,3}(?:\.\d+)?%?)\s*[\s|,]\s*(\d{0,3}(?:\.\d+)?%?)\s*(?:\s*[,/]\s*(\d*(?:\.\d+)?%?)\s*)?\)$/i);if(!e)return;const s=(gt.parseAngletoDegrees(e[1])%360+360)%360/360,i=parseFloat(e[2])/100,n=parseFloat(e[3])/100;let r,o,h;if(i===0)r=o=h=n;else{const c=n<=.5?n*(i+1):n+i-n*i,u=2*n-c;r=bf(u,c,s+1/3),o=bf(u,c,s),h=bf(u,c,s-1/3)}return[Math.round(255*r),Math.round(255*o),Math.round(255*h),nm(e[4])]}static fromHex(t){return new gt(gt.sourceFromHex(t))}static sourceFromHex(t){if(t.match(/^#?(([0-9a-f]){3,4}|([0-9a-f]{2}){3,4})$/i)){const e=t.slice(t.indexOf("#")+1);let s;s=e.length<=4?e.split("").map(h=>h+h):e.match(/.{2}/g);const[i,n,r,o=255]=s.map(h=>parseInt(h,16));return[i,n,r,o/255]}}static parseAngletoDegrees(t){const e=t.toLowerCase(),s=parseFloat(e);return e.includes("rad")?kn(s):e.includes("turn")?360*s:s}}const At=(a,t)=>parseFloat(Number(a).toFixed(t)),De=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:of;const e=/\D{0,2}$/.exec(a),s=parseFloat(a),i=ht.DPI;switch(e==null?void 0:e[0]){case"mm":return s*i/25.4;case"cm":return s*i/2.54;case"in":return s*i;case"pt":return s*i/72;case"pc":return s*i/72*12;case"em":return s*t;default:return s}},yf=a=>{const[t,e]=a.trim().split(" "),[s,i]=(n=t)&&n!==ke?[n.slice(1,4),n.slice(5,8)]:n===ke?[n,n]:["Mid","Mid"];var n;return{meetOrSlice:e||"meet",alignX:s,alignY:i}},kh=a=>"matrix("+a.map(t=>At(t,ht.NUM_FRACTION_DIGITS)).join(" ")+")",Mh=function(a,t){let e,s,i=!(arguments.length>2&&arguments[2]!==void 0)||arguments[2];if(t)if(t.toLive)e="url(#SVGID_".concat(t.id,")");else{const n=new gt(t),r=n.getAlpha();e=n.toRgb(),r!==1&&(s=r.toString())}else e="none";return i?"".concat(a,": ").concat(e,"; ").concat(s?"".concat(a,"-opacity: ").concat(s,"; "):""):"".concat(a,'="').concat(e,'" ').concat(s?"".concat(a,'-opacity="').concat(s,'" '):"")},bs=a=>!!a&&a.toLive!==void 0,om=a=>!!a&&typeof a.toObject=="function",am=a=>!!a&&a.offsetX!==void 0&&"source"in a,vr=a=>!!a&&"multiSelectionStacking"in a;function hm(a){const t=a&&Ls(a);let e=0,s=0;if(!a||!t)return{left:e,top:s};let i=a;const n=t.documentElement,r=t.body||{scrollLeft:0,scrollTop:0};for(;i&&(i.parentNode||i.host)&&(i=i.parentNode||i.host,i===t?(e=r.scrollLeft||n.scrollLeft||0,s=r.scrollTop||n.scrollTop||0):(e+=i.scrollLeft||0,s+=i.scrollTop||0),i.nodeType!==1||i.style.position!=="fixed"););return{left:e,top:s}}const Ls=a=>a.ownerDocument||null,lm=a=>{var t;return((t=a.ownerDocument)===null||t===void 0?void 0:t.defaultView)||null},cm=function(a,t,e){let{width:s,height:i}=e,n=arguments.length>3&&arguments[3]!==void 0?arguments[3]:1;a.width=s,a.height=i,n>1&&(a.setAttribute("width",(s*n).toString()),a.setAttribute("height",(i*n).toString()),t.scale(n,n))},vf=(a,t)=>{let{width:e,height:s}=t;e&&(a.style.width=typeof e=="number"?"".concat(e,"px"):e),s&&(a.style.height=typeof s=="number"?"".concat(s,"px"):s)};function um(a){return a.onselectstart!==void 0&&(a.onselectstart=()=>!1),a.style.userSelect=ke,a}class dm{constructor(t){A(this,"_originalCanvasStyle",void 0),A(this,"lower",void 0);const e=this.createLowerCanvas(t);this.lower={el:e,ctx:e.getContext("2d")}}createLowerCanvas(t){const e=(s=t)&&s.getContext!==void 0?t:t&&Vo().getElementById(t)||ms();var s;if(e.hasAttribute("data-fabric"))throw new ii("Trying to initialize a canvas that has already been initialized. Did you forget to dispose the canvas?");return this._originalCanvasStyle=e.style.cssText,e.setAttribute("data-fabric","main"),e.classList.add("lower-canvas"),e}cleanupDOM(t){let{width:e,height:s}=t;const{el:i}=this.lower;i.classList.remove("lower-canvas"),i.removeAttribute("data-fabric"),i.setAttribute("width","".concat(e)),i.setAttribute("height","".concat(s)),i.style.cssText=this._originalCanvasStyle||"",this._originalCanvasStyle=void 0}setDimensions(t,e){const{el:s,ctx:i}=this.lower;cm(s,i,t,e)}setCSSDimensions(t){vf(this.lower.el,t)}calcOffset(){return function(t){var e;const s=t&&Ls(t),i={left:0,top:0};if(!s)return i;const n=((e=lm(t))===null||e===void 0?void 0:e.getComputedStyle(t,null))||{};i.left+=parseInt(n.borderLeftWidth,10)||0,i.top+=parseInt(n.borderTopWidth,10)||0,i.left+=parseInt(n.paddingLeft,10)||0,i.top+=parseInt(n.paddingTop,10)||0;let r={left:0,top:0};const o=s.documentElement;t.getBoundingClientRect!==void 0&&(r=t.getBoundingClientRect());const h=hm(t);return{left:r.left+h.left-(o.clientLeft||0)+i.left,top:r.top+h.top-(o.clientTop||0)+i.top}}(this.lower.el)}dispose(){ni().dispose(this.lower.el),delete this.lower}}const Tv={backgroundVpt:!0,backgroundColor:"",overlayVpt:!0,overlayColor:"",includeDefaultValues:!0,svgViewportTransformation:!0,renderOnAddRemove:!0,skipOffscreen:!0,enableRetinaScaling:!0,imageSmoothingEnabled:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,viewportTransform:[...Ee]};class Ph extends $p(qp){get lowerCanvasEl(){var t;return(t=this.elements.lower)===null||t===void 0?void 0:t.el}get contextContainer(){var t;return(t=this.elements.lower)===null||t===void 0?void 0:t.ctx}static getDefaults(){return Ph.ownDefaults}constructor(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),Object.assign(this,this.constructor.getDefaults()),this.set(e),this.initElements(t),this._setDimensionsImpl({width:this.width||this.elements.lower.el.width||0,height:this.height||this.elements.lower.el.height||0}),this.skipControlsDrawing=!1,this.viewportTransform=[...this.viewportTransform],this.calcViewportBoundaries()}initElements(t){this.elements=new dm(t)}add(){const t=super.add(...arguments);return arguments.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),t}insertAt(t){for(var e=arguments.length,s=new Array(e>1?e-1:0),i=1;i<e;i++)s[i-1]=arguments[i];const n=super.insertAt(t,...s);return s.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),n}remove(){const t=super.remove(...arguments);return t.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),t}_onObjectAdded(t){t.canvas&&t.canvas!==this&&(Oi("warn",`Canvas is trying to add an object that belongs to a different canvas.
1
+ (function(nt,q){typeof exports=="object"&&typeof module<"u"?q(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],q):(nt=typeof globalThis<"u"?globalThis:nt||self,q(nt["pdf-canvas"]={},nt.Vue))})(this,function(nt,q){"use strict";var CC=Object.defineProperty;var Yb=nt=>{throw TypeError(nt)};var AC=(nt,q,_t)=>q in nt?CC(nt,q,{enumerable:!0,configurable:!0,writable:!0,value:_t}):nt[q]=_t;var $=(nt,q,_t)=>AC(nt,typeof q!="symbol"?q+"":q,_t),$g=(nt,q,_t)=>q.has(nt)||Yb("Cannot "+_t);var l=(nt,q,_t)=>($g(nt,q,"read from private field"),_t?_t.call(nt):q.get(nt)),y=(nt,q,_t)=>q.has(nt)?Yb("Cannot add the same private member more than once"):q instanceof WeakSet?q.add(nt):q.set(nt,_t),m=(nt,q,_t,T)=>($g(nt,q,"write to private field"),T?T.call(nt,_t):q.set(nt,_t),_t),w=(nt,q,_t)=>($g(nt,q,"access private method"),_t);var Ge=(nt,q,_t,T)=>({set _(jc){m(nt,q,jc,_t)},get _(){return l(nt,q,T)}});var Xi,Ed,qg,Jh,In,Rr,zs,Lr,Zh,tl,ad,$b,Le,qb,Kb,kd,Qb,Kg,el,Fr,Ir,Nn,Jb,Zb,ty,hd,ha,sl,we,la,Md,Bt,jn,il,Dt,ld,ey,ca,ss,Kt,ae,ua,Ui,da,ws,Bn,Nr,fa,jr,ui,Vs,Br,nl,rl,ga,ol,di,Hn,pa,Gn,fi,ud,zn,al,Vn,Hr,hl,ll,ee,pt,Yi,Gr,cl,ul,Xn,gi,$i,dl,xs,I,Pd,Qg,sy,iy,Dd,ny,ry,oy,Jg,ay,Zg,tp,hy,ze,xn,ly,cy,ep,uy,Cc,sp,se,pi,Xs,ba,mi,is,ya,bi,$e,qi,zr,yi,Wn,Ws,Ac,Od,fl,Vr,gl,pl,ml,bl,yl,va,Ki,Xr,Un,Qi,dy,fy,ip,Wr,Us,xt,_a,Yn,vl,Ur,he,Yr,Ji,$n,_l,$r,ns,wl,qr,Zi,vi,wa,xa,Ss,Kr,xl,dd,Y,np,Sl,rp,Rd,gy,py,op,Ld,ap,my,by,yy,hp,vy,lp,_y,wy,xy,cp,Tc,Qr,Jr,ie,fd,Sy,Cl,Sa,Ca,Cs,Cy,Ay,Ty,Fd,Al,Zr,Aa,tn,en,xe,to,eo,j,Te,Ec,mh,Id,bh,Ey,up,yh,kc,Mc,dp,Pc,Ys,fp,gp,pp,Tl,El,so,kl,Ml,Pl,Dl,Ta,qn,mt,Ea,ka,Ol,mp,Ub,Kn,qe,Rl,Ll,io,sn,Fl,Il,no,Ma,Pa,Qn,Da,Nl,Oa,ro,jl,Bl,oo,ao,Hl,Jn,Ra,nn,ky,My,bp,rs,Nd,yp,Py,Dy,pd,Zn,rn,As,vh,jd,on,bd,yd,ho,lo,La,Bd,Fa,Hd,an,_i,Ia,Na,hn,co,Dc,os,Gl,vp,tr,er,uo,go,ja,Ba,zl,_p,as,Ho,Oy,Ry,Ha,vd,_d,Ga,po,Lt,ln,za,Vl,Xl,Va,cn,$s,un,Wl,dn,Ul,mo,bo,bt,Gd,wp,Ly,Fy,Iy,Ny,zd,Vd,xp,Yl,$l,ql,Kl,Ql,yo,Jl,Sp,Zl,tc,Cp,ec,vo,_o,sc,wo,jy,Ap,qs,hs,ic,xo,ls,Ut,By,Hy,Gy,Xd,fn,Wd,Ud,zy,Tp,Vy,cs,Ks,Xa,Wa,wi,it,So,Co,nc,rc,Ua,Ya,sr,oc,wd,xd,Jt,Oc,Xy,Wy,Uy,Yy,$y,qy,$a,Ao,pn,ac,us,hc,Ht,Sd,Ky,lc,cc,ir,Qs,Ie,Qy,Yd,Jy,Zy,Ep,uc,qa,Js,To,Ka,Zt,dc,Qa,fc,gc,nr,Zs,Ja,pc,yt,kp,Mp,Pp,Go,tv,gr,Za,mc,mn,Eo,th,Qe,bc,yc,ko,Ts,ds,le,eh,bn,Se,sh,Es,vc,J,Dp,$d,ev,sv,iv,Op,zo,ks,_h,nv,qd,Rc,rv,ov,av,hv,lv,Mo,fs,ih,ne,Po,Do,rr,or,ar,Oo,lt,Rp,Lp,Fp,Lc,cv,Kd,Fc,wh,xi,re,oe,Ro,nh,Ne,ce,Ms,Lo,Fo,Io,rh,Qd,je,_c,wc,gs,Si,Ci,oh,ah,hh,ue,Sn,uv,dv,fv,lh,Cd,gv,Ot,de,hr,yn,lr,uh,Ai,Ti,ps,dh,ct,Ic,Nc,Jd,Ip,Zd,Np,tf,pv,No,fh,Ei,cr,vn,Ps,ur,gh,jo,ti,_n,Ce,wn,X,dr,kt,mv,Di,jp,Bp,ef,si,Sc,Be,Bo,Ad,bv,ki,Hp,yv,Gp;var _t=typeof document<"u"?document.currentScript:null;function T(a,t,e){return(t=function(s){var i=function(n,r){if(typeof n!="object"||!n)return n;var o=n[Symbol.toPrimitive];if(o!==void 0){var h=o.call(n,r);if(typeof h!="object")return h;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(n)}(s,"string");return typeof i=="symbol"?i:i+""}(t))in a?Object.defineProperty(a,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):a[t]=e,a}function jc(a,t){var e=Object.keys(a);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(a);t&&(s=s.filter(function(i){return Object.getOwnPropertyDescriptor(a,i).enumerable})),e.push.apply(e,s)}return e}function E(a){for(var t=1;t<arguments.length;t++){var e=arguments[t]!=null?arguments[t]:{};t%2?jc(Object(e),!0).forEach(function(s){T(a,s,e[s])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(e)):jc(Object(e)).forEach(function(s){Object.defineProperty(a,s,Object.getOwnPropertyDescriptor(e,s))})}return a}function Ct(a,t){if(a==null)return{};var e,s,i=function(r,o){if(r==null)return{};var h={};for(var c in r)if({}.hasOwnProperty.call(r,c)){if(o.indexOf(c)>=0)continue;h[c]=r[c]}return h}(a,t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(a);for(s=0;s<n.length;s++)e=n[s],t.indexOf(e)>=0||{}.propertyIsEnumerable.call(a,e)&&(i[e]=a[e])}return i}function Cn(a,t){return t||(t=a.slice(0)),Object.freeze(Object.defineProperties(a,{raw:{value:Object.freeze(t)}}))}class zp{constructor(){T(this,"browserShadowBlurConstant",1),T(this,"DPI",96),T(this,"devicePixelRatio",typeof window<"u"?window.devicePixelRatio:1),T(this,"perfLimitSizeTotal",2097152),T(this,"maxCacheSideLimit",4096),T(this,"minCacheSideLimit",256),T(this,"disableStyleCopyPaste",!1),T(this,"enableGLFiltering",!0),T(this,"textureSize",4096),T(this,"forceGLPutImageData",!1),T(this,"cachesBoundsOfCurve",!1),T(this,"fontPaths",{}),T(this,"NUM_FRACTION_DIGITS",4)}}const ht=new class extends zp{constructor(a){super(),this.configure(a)}configure(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Object.assign(this,a)}addFonts(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.fontPaths=E(E({},this.fontPaths),a)}removeFonts(){(arguments.length>0&&arguments[0]!==void 0?arguments[0]:[]).forEach(a=>{delete this.fontPaths[a]})}clearFonts(){this.fontPaths={}}restoreDefaults(a){const t=new zp,e=(a==null?void 0:a.reduce((s,i)=>(s[i]=t[i],s),{}))||t;this.configure(e)}},Oi=function(a){for(var t=arguments.length,e=new Array(t>1?t-1:0),s=1;s<t;s++)e[s-1]=arguments[s];return console[a]("fabric",...e)};class ii extends Error{constructor(t,e){super("fabric: ".concat(t),e)}}class sf extends ii{constructor(t){super("".concat(t," 'options.signal' is in 'aborted' state"))}}class vv{}class _v extends vv{testPrecision(t,e){const s="precision ".concat(e,` float;
2
+ void main(){}`),i=t.createShader(t.FRAGMENT_SHADER);return!!i&&(t.shaderSource(i,s),t.compileShader(i),!!t.getShaderParameter(i,t.COMPILE_STATUS))}queryWebGL(t){const e=t.getContext("webgl");e&&(this.maxTextureSize=e.getParameter(e.MAX_TEXTURE_SIZE),this.GLPrecision=["highp","mediump","lowp"].find(s=>this.testPrecision(e,s)),e.getExtension("WEBGL_lose_context").loseContext(),Oi("log","WebGL: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const wv={};let Vp;const ni=()=>Vp||(Vp={document,window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new _v,dispose(){},copyPasteData:wv}),Vo=()=>ni().document,Bc=()=>ni().window,Xp=()=>{var a;return Math.max((a=ht.devicePixelRatio)!==null&&a!==void 0?a:Bc().devicePixelRatio,1)},xh=new class{constructor(){T(this,"charWidthsCache",{}),T(this,"boundsOfCurveCache",{})}getFontCache(a){let{fontFamily:t,fontStyle:e,fontWeight:s}=a;t=t.toLowerCase(),this.charWidthsCache[t]||(this.charWidthsCache[t]={});const i=this.charWidthsCache[t],n="".concat(e.toLowerCase(),"_").concat((s+"").toLowerCase());return i[n]||(i[n]={}),i[n]}clearFontCache(a){(a=(a||"").toLowerCase())?this.charWidthsCache[a]&&delete this.charWidthsCache[a]:this.charWidthsCache={}}limitDimsByArea(a){const{perfLimitSizeTotal:t}=ht,e=Math.sqrt(t*a);return[Math.floor(e),Math.floor(t/e)]}},nf="6.6.1";function pr(){}const An=Math.PI/2,Ri=2*Math.PI,rf=Math.PI/180,Ee=Object.freeze([1,0,0,1,0,0]),of=16,Tn=.4477152502,Q="center",dt="left",Ve="top",af="bottom",It="right",ke="none",hf=/\r?\n/,Wp="moving",Hc="scaling",Up="rotating",lf="rotate",Yp="skewing",Sh="resizing",xv="modifyPoly",Sv="modifyPath",Gc="changed",zc="scale",Me="scaleX",Je="scaleY",Xo="skewX",Wo="skewY",zt="fill",Pe="stroke",Vc="modified",Uo="json",cf="svg",N=new class{constructor(){this[Uo]=new Map,this[cf]=new Map}has(a){return this[Uo].has(a)}getClass(a){const t=this[Uo].get(a);if(!t)throw new ii("No class registered for ".concat(a));return t}setClass(a,t){t?this[Uo].set(t,a):(this[Uo].set(a.type,a),this[Uo].set(a.type.toLowerCase(),a))}getSVGClass(a){return this[cf].get(a)}setSVGClass(a,t){this[cf].set(t??a.type.toLowerCase(),a)}},Xc=new class extends Array{remove(a){const t=this.indexOf(a);t>-1&&this.splice(t,1)}cancelAll(){const a=this.splice(0);return a.forEach(t=>t.abort()),a}cancelByCanvas(a){if(!a)return[];const t=this.filter(e=>{var s;return e.target===a||typeof e.target=="object"&&((s=e.target)===null||s===void 0?void 0:s.canvas)===a});return t.forEach(e=>e.abort()),t}cancelByTarget(a){if(!a)return[];const t=this.filter(e=>e.target===a);return t.forEach(e=>e.abort()),t}};class Cv{constructor(){T(this,"__eventListeners",{})}on(t,e){if(this.__eventListeners||(this.__eventListeners={}),typeof t=="object")return Object.entries(t).forEach(s=>{let[i,n]=s;this.on(i,n)}),()=>this.off(t);if(e){const s=t;return this.__eventListeners[s]||(this.__eventListeners[s]=[]),this.__eventListeners[s].push(e),()=>this.off(s,e)}return()=>!1}once(t,e){if(typeof t=="object"){const s=[];return Object.entries(t).forEach(i=>{let[n,r]=i;s.push(this.once(n,r))}),()=>s.forEach(i=>i())}if(e){const s=this.on(t,function(){for(var i=arguments.length,n=new Array(i),r=0;r<i;r++)n[r]=arguments[r];e.call(this,...n),s()});return s}return()=>!1}_removeEventListener(t,e){if(this.__eventListeners[t])if(e){const s=this.__eventListeners[t],i=s.indexOf(e);i>-1&&s.splice(i,1)}else this.__eventListeners[t]=[]}off(t,e){if(this.__eventListeners)if(t===void 0)for(const s in this.__eventListeners)this._removeEventListener(s);else typeof t=="object"?Object.entries(t).forEach(s=>{let[i,n]=s;this._removeEventListener(i,n)}):this._removeEventListener(t,e)}fire(t,e){var s;if(!this.__eventListeners)return;const i=(s=this.__eventListeners[t])===null||s===void 0?void 0:s.concat();if(i)for(let n=0;n<i.length;n++)i[n].call(this,e||{})}}const mr=(a,t)=>{const e=a.indexOf(t);return e!==-1&&a.splice(e,1),a},Ds=a=>{if(a===0)return 1;switch(Math.abs(a)/An){case 1:case 3:return 0;case 2:return-1}return Math.cos(a)},Os=a=>{if(a===0)return 0;const t=a/An,e=Math.sign(a);switch(t){case 1:return e;case 2:return 0;case 3:return-e}return Math.sin(a)};class P{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;typeof t=="object"?(this.x=t.x,this.y=t.y):(this.x=t,this.y=e)}add(t){return new P(this.x+t.x,this.y+t.y)}addEquals(t){return this.x+=t.x,this.y+=t.y,this}scalarAdd(t){return new P(this.x+t,this.y+t)}scalarAddEquals(t){return this.x+=t,this.y+=t,this}subtract(t){return new P(this.x-t.x,this.y-t.y)}subtractEquals(t){return this.x-=t.x,this.y-=t.y,this}scalarSubtract(t){return new P(this.x-t,this.y-t)}scalarSubtractEquals(t){return this.x-=t,this.y-=t,this}multiply(t){return new P(this.x*t.x,this.y*t.y)}scalarMultiply(t){return new P(this.x*t,this.y*t)}scalarMultiplyEquals(t){return this.x*=t,this.y*=t,this}divide(t){return new P(this.x/t.x,this.y/t.y)}scalarDivide(t){return new P(this.x/t,this.y/t)}scalarDivideEquals(t){return this.x/=t,this.y/=t,this}eq(t){return this.x===t.x&&this.y===t.y}lt(t){return this.x<t.x&&this.y<t.y}lte(t){return this.x<=t.x&&this.y<=t.y}gt(t){return this.x>t.x&&this.y>t.y}gte(t){return this.x>=t.x&&this.y>=t.y}lerp(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:.5;return e=Math.max(Math.min(1,e),0),new P(this.x+(t.x-this.x)*e,this.y+(t.y-this.y)*e)}distanceFrom(t){const e=this.x-t.x,s=this.y-t.y;return Math.sqrt(e*e+s*s)}midPointFrom(t){return this.lerp(t)}min(t){return new P(Math.min(this.x,t.x),Math.min(this.y,t.y))}max(t){return new P(Math.max(this.x,t.x),Math.max(this.y,t.y))}toString(){return"".concat(this.x,",").concat(this.y)}setXY(t,e){return this.x=t,this.y=e,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setFromPoint(t){return this.x=t.x,this.y=t.y,this}swap(t){const e=this.x,s=this.y;this.x=t.x,this.y=t.y,t.x=e,t.y=s}clone(){return new P(this.x,this.y)}rotate(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:uf;const s=Os(t),i=Ds(t),n=this.subtract(e);return new P(n.x*i-n.y*s,n.x*s+n.y*i).add(e)}transform(t){let e=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return new P(t[0]*this.x+t[2]*this.y+(e?0:t[4]),t[1]*this.x+t[3]*this.y+(e?0:t[5]))}}const uf=new P(0,0),Wc=a=>!!a&&Array.isArray(a._objects);function $p(a){class t extends a{constructor(){super(...arguments),T(this,"_objects",[])}_onObjectAdded(s){}_onObjectRemoved(s){}_onStackOrderChanged(s){}add(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];const r=this._objects.push(...i);return i.forEach(o=>this._onObjectAdded(o)),r}insertAt(s){for(var i=arguments.length,n=new Array(i>1?i-1:0),r=1;r<i;r++)n[r-1]=arguments[r];return this._objects.splice(s,0,...n),n.forEach(o=>this._onObjectAdded(o)),this._objects.length}remove(){const s=this._objects,i=[];for(var n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return r.forEach(h=>{const c=s.indexOf(h);c!==-1&&(s.splice(c,1),i.push(h),this._onObjectRemoved(h))}),i}forEachObject(s){this.getObjects().forEach((i,n,r)=>s(i,n,r))}getObjects(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];return i.length===0?[...this._objects]:this._objects.filter(r=>r.isType(...i))}item(s){return this._objects[s]}isEmpty(){return this._objects.length===0}size(){return this._objects.length}contains(s,i){return!!this._objects.includes(s)||!!i&&this._objects.some(n=>n instanceof t&&n.contains(s,!0))}complexity(){return this._objects.reduce((s,i)=>s+=i.complexity?i.complexity():0,0)}sendObjectToBack(s){return!(!s||s===this._objects[0])&&(mr(this._objects,s),this._objects.unshift(s),this._onStackOrderChanged(s),!0)}bringObjectToFront(s){return!(!s||s===this._objects[this._objects.length-1])&&(mr(this._objects,s),this._objects.push(s),this._onStackOrderChanged(s),!0)}sendObjectBackwards(s,i){if(!s)return!1;const n=this._objects.indexOf(s);if(n!==0){const r=this.findNewLowerIndex(s,n,i);return mr(this._objects,s),this._objects.splice(r,0,s),this._onStackOrderChanged(s),!0}return!1}bringObjectForward(s,i){if(!s)return!1;const n=this._objects.indexOf(s);if(n!==this._objects.length-1){const r=this.findNewUpperIndex(s,n,i);return mr(this._objects,s),this._objects.splice(r,0,s),this._onStackOrderChanged(s),!0}return!1}moveObjectTo(s,i){return s!==this._objects[i]&&(mr(this._objects,s),this._objects.splice(i,0,s),this._onStackOrderChanged(s),!0)}findNewLowerIndex(s,i,n){let r;if(n){r=i;for(let o=i-1;o>=0;--o)if(s.isOverlapping(this._objects[o])){r=o;break}}else r=i-1;return r}findNewUpperIndex(s,i,n){let r;if(n){r=i;for(let o=i+1;o<this._objects.length;++o)if(s.isOverlapping(this._objects[o])){r=o;break}}else r=i+1;return r}collectObjects(s){let{left:i,top:n,width:r,height:o}=s,{includeIntersecting:h=!0}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const c=[],u=new P(i,n),d=u.add(new P(r,o));for(let f=this._objects.length-1;f>=0;f--){const g=this._objects[f];g.selectable&&g.visible&&(h&&g.intersectsWithRect(u,d)||g.isContainedWithinRect(u,d)||h&&g.containsPoint(u)||h&&g.containsPoint(d))&&c.push(g)}return c}}return t}class qp extends Cv{_setOptions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};for(const e in t)this.set(e,t[e])}_setObject(t){for(const e in t)this._set(e,t[e])}set(t,e){return typeof t=="object"?this._setObject(t):this._set(t,e),this}_set(t,e){this[t]=e}toggle(t){const e=this.get(t);return typeof e=="boolean"&&this.set(t,!e),this}get(t){return this[t]}}function Ch(a){return Bc().requestAnimationFrame(a)}function Kp(a){return Bc().cancelAnimationFrame(a)}let Av=0;const En=()=>Av++,ms=()=>{const a=Vo().createElement("canvas");if(!a||a.getContext===void 0)throw new ii("Failed to create `canvas` element");return a},Qp=()=>Vo().createElement("img"),Rs=a=>{const t=ms();return t.width=a.width,t.height=a.height,t},df=(a,t,e)=>a.toDataURL("image/".concat(t),e),ff=(a,t,e)=>new Promise((s,i)=>{a.toBlob(s,"image/".concat(t),e)}),Rt=a=>a*rf,kn=a=>a/rf,Jp=a=>a.every((t,e)=>t===Ee[e]),ge=(a,t,e)=>new P(a).transform(t,e),Xe=a=>{const t=1/(a[0]*a[3]-a[1]*a[2]),e=[t*a[3],-t*a[1],-t*a[2],t*a[0],0,0],{x:s,y:i}=new P(a[4],a[5]).transform(e,!0);return e[4]=-s,e[5]=-i,e},Nt=(a,t,e)=>[a[0]*t[0]+a[2]*t[1],a[1]*t[0]+a[3]*t[1],a[0]*t[2]+a[2]*t[3],a[1]*t[2]+a[3]*t[3],e?0:a[0]*t[4]+a[2]*t[5]+a[4],e?0:a[1]*t[4]+a[3]*t[5]+a[5]],Uc=(a,t)=>a.reduceRight((e,s)=>s&&e?Nt(s,e,t):s||e,void 0)||Ee.concat(),Zp=a=>{let[t,e]=a;return Math.atan2(e,t)},br=a=>{const t=Zp(a),e=Math.pow(a[0],2)+Math.pow(a[1],2),s=Math.sqrt(e),i=(a[0]*a[3]-a[2]*a[1])/s,n=Math.atan2(a[0]*a[2]+a[1]*a[3],e);return{angle:kn(t),scaleX:s,scaleY:i,skewX:kn(n),skewY:0,translateX:a[4]||0,translateY:a[5]||0}},Yo=function(a){return[1,0,0,1,a,arguments.length>1&&arguments[1]!==void 0?arguments[1]:0]};function $o(){let{angle:a=0}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},{x:t=0,y:e=0}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const s=Rt(a),i=Ds(s),n=Os(s);return[i,n,-n,i,t?t-(i*t-n*e):0,e?e-(n*t+i*e):0]}const Yc=function(a){return[a,0,0,arguments.length>1&&arguments[1]!==void 0?arguments[1]:a,0,0]},tm=a=>Math.tan(Rt(a)),gf=a=>[1,0,tm(a),1,0,0],pf=a=>[1,tm(a),0,1,0,0],Ah=a=>{let{scaleX:t=1,scaleY:e=1,flipX:s=!1,flipY:i=!1,skewX:n=0,skewY:r=0}=a,o=Yc(s?-t:t,i?-e:e);return n&&(o=Nt(o,gf(n),!0)),r&&(o=Nt(o,pf(r),!0)),o},em=a=>{const{translateX:t=0,translateY:e=0,angle:s=0}=a;let i=Yo(t,e);s&&(i=Nt(i,$o({angle:s})));const n=Ah(a);return Jp(n)||(i=Nt(i,n)),i},Th=function(a){let{signal:t,crossOrigin:e=null}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise(function(s,i){if(t&&t.aborted)return i(new sf("loadImage"));const n=Qp();let r;t&&(r=function(h){n.src="",i(h)},t.addEventListener("abort",r,{once:!0}));const o=function(){n.onload=n.onerror=null,r&&(t==null||t.removeEventListener("abort",r)),s(n)};a?(n.onload=o,n.onerror=function(){r&&(t==null||t.removeEventListener("abort",r)),i(new ii("Error loading ".concat(n.src)))},e&&(n.crossOrigin=e),n.src=a):o()})},qo=function(a){let{signal:t,reviver:e=pr}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise((s,i)=>{const n=[];t&&t.addEventListener("abort",i,{once:!0}),Promise.all(a.map(r=>N.getClass(r.type).fromObject(r,{signal:t}).then(o=>(e(r,o),n.push(o),o)))).then(s).catch(r=>{n.forEach(o=>{o.dispose&&o.dispose()}),i(r)}).finally(()=>{t&&t.removeEventListener("abort",i)})})},Eh=function(a){let{signal:t}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise((e,s)=>{const i=[];t&&t.addEventListener("abort",s,{once:!0});const n=Object.values(a).map(o=>o&&o.type&&N.has(o.type)?qo([o],{signal:t}).then(h=>{let[c]=h;return i.push(c),c}):o),r=Object.keys(a);Promise.all(n).then(o=>o.reduce((h,c,u)=>(h[r[u]]=c,h),{})).then(e).catch(o=>{i.forEach(h=>{h.dispose&&h.dispose()}),s(o)}).finally(()=>{t&&t.removeEventListener("abort",s)})})},yr=function(a){return(arguments.length>1&&arguments[1]!==void 0?arguments[1]:[]).reduce((t,e)=>(e in a&&(t[e]=a[e]),t),{})},mf=(a,t)=>Object.keys(a).reduce((e,s)=>(t(a[s],s,a)&&(e[s]=a[s]),e),{}),sm={aliceblue:"#F0F8FF",antiquewhite:"#FAEBD7",aqua:"#0FF",aquamarine:"#7FFFD4",azure:"#F0FFFF",beige:"#F5F5DC",bisque:"#FFE4C4",black:"#000",blanchedalmond:"#FFEBCD",blue:"#00F",blueviolet:"#8A2BE2",brown:"#A52A2A",burlywood:"#DEB887",cadetblue:"#5F9EA0",chartreuse:"#7FFF00",chocolate:"#D2691E",coral:"#FF7F50",cornflowerblue:"#6495ED",cornsilk:"#FFF8DC",crimson:"#DC143C",cyan:"#0FF",darkblue:"#00008B",darkcyan:"#008B8B",darkgoldenrod:"#B8860B",darkgray:"#A9A9A9",darkgrey:"#A9A9A9",darkgreen:"#006400",darkkhaki:"#BDB76B",darkmagenta:"#8B008B",darkolivegreen:"#556B2F",darkorange:"#FF8C00",darkorchid:"#9932CC",darkred:"#8B0000",darksalmon:"#E9967A",darkseagreen:"#8FBC8F",darkslateblue:"#483D8B",darkslategray:"#2F4F4F",darkslategrey:"#2F4F4F",darkturquoise:"#00CED1",darkviolet:"#9400D3",deeppink:"#FF1493",deepskyblue:"#00BFFF",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1E90FF",firebrick:"#B22222",floralwhite:"#FFFAF0",forestgreen:"#228B22",fuchsia:"#F0F",gainsboro:"#DCDCDC",ghostwhite:"#F8F8FF",gold:"#FFD700",goldenrod:"#DAA520",gray:"#808080",grey:"#808080",green:"#008000",greenyellow:"#ADFF2F",honeydew:"#F0FFF0",hotpink:"#FF69B4",indianred:"#CD5C5C",indigo:"#4B0082",ivory:"#FFFFF0",khaki:"#F0E68C",lavender:"#E6E6FA",lavenderblush:"#FFF0F5",lawngreen:"#7CFC00",lemonchiffon:"#FFFACD",lightblue:"#ADD8E6",lightcoral:"#F08080",lightcyan:"#E0FFFF",lightgoldenrodyellow:"#FAFAD2",lightgray:"#D3D3D3",lightgrey:"#D3D3D3",lightgreen:"#90EE90",lightpink:"#FFB6C1",lightsalmon:"#FFA07A",lightseagreen:"#20B2AA",lightskyblue:"#87CEFA",lightslategray:"#789",lightslategrey:"#789",lightsteelblue:"#B0C4DE",lightyellow:"#FFFFE0",lime:"#0F0",limegreen:"#32CD32",linen:"#FAF0E6",magenta:"#F0F",maroon:"#800000",mediumaquamarine:"#66CDAA",mediumblue:"#0000CD",mediumorchid:"#BA55D3",mediumpurple:"#9370DB",mediumseagreen:"#3CB371",mediumslateblue:"#7B68EE",mediumspringgreen:"#00FA9A",mediumturquoise:"#48D1CC",mediumvioletred:"#C71585",midnightblue:"#191970",mintcream:"#F5FFFA",mistyrose:"#FFE4E1",moccasin:"#FFE4B5",navajowhite:"#FFDEAD",navy:"#000080",oldlace:"#FDF5E6",olive:"#808000",olivedrab:"#6B8E23",orange:"#FFA500",orangered:"#FF4500",orchid:"#DA70D6",palegoldenrod:"#EEE8AA",palegreen:"#98FB98",paleturquoise:"#AFEEEE",palevioletred:"#DB7093",papayawhip:"#FFEFD5",peachpuff:"#FFDAB9",peru:"#CD853F",pink:"#FFC0CB",plum:"#DDA0DD",powderblue:"#B0E0E6",purple:"#800080",rebeccapurple:"#639",red:"#F00",rosybrown:"#BC8F8F",royalblue:"#4169E1",saddlebrown:"#8B4513",salmon:"#FA8072",sandybrown:"#F4A460",seagreen:"#2E8B57",seashell:"#FFF5EE",sienna:"#A0522D",silver:"#C0C0C0",skyblue:"#87CEEB",slateblue:"#6A5ACD",slategray:"#708090",slategrey:"#708090",snow:"#FFFAFA",springgreen:"#00FF7F",steelblue:"#4682B4",tan:"#D2B48C",teal:"#008080",thistle:"#D8BFD8",tomato:"#FF6347",turquoise:"#40E0D0",violet:"#EE82EE",wheat:"#F5DEB3",white:"#FFF",whitesmoke:"#F5F5F5",yellow:"#FF0",yellowgreen:"#9ACD32"},bf=(a,t,e)=>(e<0&&(e+=1),e>1&&(e-=1),e<1/6?a+6*(t-a)*e:e<.5?t:e<2/3?a+(t-a)*(2/3-e)*6:a),im=(a,t,e,s)=>{a/=255,t/=255,e/=255;const i=Math.max(a,t,e),n=Math.min(a,t,e);let r,o;const h=(i+n)/2;if(i===n)r=o=0;else{const c=i-n;switch(o=h>.5?c/(2-i-n):c/(i+n),i){case a:r=(t-e)/c+(t<e?6:0);break;case t:r=(e-a)/c+2;break;case e:r=(a-t)/c+4}r/=6}return[Math.round(360*r),Math.round(100*o),Math.round(100*h),s]},nm=function(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"1";return parseFloat(a)/(a.endsWith("%")?100:1)},$c=a=>Math.min(Math.round(a),255).toString(16).toUpperCase().padStart(2,"0"),rm=a=>{let[t,e,s,i=1]=a;const n=Math.round(.3*t+.59*e+.11*s);return[n,n,n,i]};class gt{constructor(t){if(T(this,"isUnrecognised",!1),t)if(t instanceof gt)this.setSource([...t._source]);else if(Array.isArray(t)){const[e,s,i,n=1]=t;this.setSource([e,s,i,n])}else this.setSource(this._tryParsingColor(t));else this.setSource([0,0,0,1])}_tryParsingColor(t){return(t=t.toLowerCase())in sm&&(t=sm[t]),t==="transparent"?[255,255,255,0]:gt.sourceFromHex(t)||gt.sourceFromRgb(t)||gt.sourceFromHsl(t)||(this.isUnrecognised=!0)&&[0,0,0,1]}getSource(){return this._source}setSource(t){this._source=t}toRgb(){const[t,e,s]=this.getSource();return"rgb(".concat(t,",").concat(e,",").concat(s,")")}toRgba(){return"rgba(".concat(this.getSource().join(","),")")}toHsl(){const[t,e,s]=im(...this.getSource());return"hsl(".concat(t,",").concat(e,"%,").concat(s,"%)")}toHsla(){const[t,e,s,i]=im(...this.getSource());return"hsla(".concat(t,",").concat(e,"%,").concat(s,"%,").concat(i,")")}toHex(){return this.toHexa().slice(0,6)}toHexa(){const[t,e,s,i]=this.getSource();return"".concat($c(t)).concat($c(e)).concat($c(s)).concat($c(Math.round(255*i)))}getAlpha(){return this.getSource()[3]}setAlpha(t){return this._source[3]=t,this}toGrayscale(){return this.setSource(rm(this.getSource())),this}toBlackWhite(t){const[e,,,s]=rm(this.getSource()),i=e<(t||127)?0:255;return this.setSource([i,i,i,s]),this}overlayWith(t){t instanceof gt||(t=new gt(t));const e=this.getSource(),s=t.getSource(),[i,n,r]=e.map((o,h)=>Math.round(.5*o+.5*s[h]));return this.setSource([i,n,r,e[3]]),this}static fromRgb(t){return gt.fromRgba(t)}static fromRgba(t){return new gt(gt.sourceFromRgb(t))}static sourceFromRgb(t){const e=t.match(/^rgba?\(\s*(\d{0,3}(?:\.\d+)?%?)\s*[\s|,]\s*(\d{0,3}(?:\.\d+)?%?)\s*[\s|,]\s*(\d{0,3}(?:\.\d+)?%?)\s*(?:\s*[,/]\s*(\d{0,3}(?:\.\d+)?%?)\s*)?\)$/i);if(e){const[s,i,n]=e.slice(1,4).map(r=>{const o=parseFloat(r);return r.endsWith("%")?Math.round(2.55*o):o});return[s,i,n,nm(e[4])]}}static fromHsl(t){return gt.fromHsla(t)}static fromHsla(t){return new gt(gt.sourceFromHsl(t))}static sourceFromHsl(t){const e=t.match(/^hsla?\(\s*([+-]?\d{0,3}(?:\.\d+)?(?:deg|turn|rad)?)\s*[\s|,]\s*(\d{0,3}(?:\.\d+)?%?)\s*[\s|,]\s*(\d{0,3}(?:\.\d+)?%?)\s*(?:\s*[,/]\s*(\d*(?:\.\d+)?%?)\s*)?\)$/i);if(!e)return;const s=(gt.parseAngletoDegrees(e[1])%360+360)%360/360,i=parseFloat(e[2])/100,n=parseFloat(e[3])/100;let r,o,h;if(i===0)r=o=h=n;else{const c=n<=.5?n*(i+1):n+i-n*i,u=2*n-c;r=bf(u,c,s+1/3),o=bf(u,c,s),h=bf(u,c,s-1/3)}return[Math.round(255*r),Math.round(255*o),Math.round(255*h),nm(e[4])]}static fromHex(t){return new gt(gt.sourceFromHex(t))}static sourceFromHex(t){if(t.match(/^#?(([0-9a-f]){3,4}|([0-9a-f]{2}){3,4})$/i)){const e=t.slice(t.indexOf("#")+1);let s;s=e.length<=4?e.split("").map(h=>h+h):e.match(/.{2}/g);const[i,n,r,o=255]=s.map(h=>parseInt(h,16));return[i,n,r,o/255]}}static parseAngletoDegrees(t){const e=t.toLowerCase(),s=parseFloat(e);return e.includes("rad")?kn(s):e.includes("turn")?360*s:s}}const At=(a,t)=>parseFloat(Number(a).toFixed(t)),De=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:of;const e=/\D{0,2}$/.exec(a),s=parseFloat(a),i=ht.DPI;switch(e==null?void 0:e[0]){case"mm":return s*i/25.4;case"cm":return s*i/2.54;case"in":return s*i;case"pt":return s*i/72;case"pc":return s*i/72*12;case"em":return s*t;default:return s}},yf=a=>{const[t,e]=a.trim().split(" "),[s,i]=(n=t)&&n!==ke?[n.slice(1,4),n.slice(5,8)]:n===ke?[n,n]:["Mid","Mid"];var n;return{meetOrSlice:e||"meet",alignX:s,alignY:i}},kh=a=>"matrix("+a.map(t=>At(t,ht.NUM_FRACTION_DIGITS)).join(" ")+")",Mh=function(a,t){let e,s,i=!(arguments.length>2&&arguments[2]!==void 0)||arguments[2];if(t)if(t.toLive)e="url(#SVGID_".concat(t.id,")");else{const n=new gt(t),r=n.getAlpha();e=n.toRgb(),r!==1&&(s=r.toString())}else e="none";return i?"".concat(a,": ").concat(e,"; ").concat(s?"".concat(a,"-opacity: ").concat(s,"; "):""):"".concat(a,'="').concat(e,'" ').concat(s?"".concat(a,'-opacity="').concat(s,'" '):"")},bs=a=>!!a&&a.toLive!==void 0,om=a=>!!a&&typeof a.toObject=="function",am=a=>!!a&&a.offsetX!==void 0&&"source"in a,vr=a=>!!a&&"multiSelectionStacking"in a;function hm(a){const t=a&&Ls(a);let e=0,s=0;if(!a||!t)return{left:e,top:s};let i=a;const n=t.documentElement,r=t.body||{scrollLeft:0,scrollTop:0};for(;i&&(i.parentNode||i.host)&&(i=i.parentNode||i.host,i===t?(e=r.scrollLeft||n.scrollLeft||0,s=r.scrollTop||n.scrollTop||0):(e+=i.scrollLeft||0,s+=i.scrollTop||0),i.nodeType!==1||i.style.position!=="fixed"););return{left:e,top:s}}const Ls=a=>a.ownerDocument||null,lm=a=>{var t;return((t=a.ownerDocument)===null||t===void 0?void 0:t.defaultView)||null},cm=function(a,t,e){let{width:s,height:i}=e,n=arguments.length>3&&arguments[3]!==void 0?arguments[3]:1;a.width=s,a.height=i,n>1&&(a.setAttribute("width",(s*n).toString()),a.setAttribute("height",(i*n).toString()),t.scale(n,n))},vf=(a,t)=>{let{width:e,height:s}=t;e&&(a.style.width=typeof e=="number"?"".concat(e,"px"):e),s&&(a.style.height=typeof s=="number"?"".concat(s,"px"):s)};function um(a){return a.onselectstart!==void 0&&(a.onselectstart=()=>!1),a.style.userSelect=ke,a}class dm{constructor(t){T(this,"_originalCanvasStyle",void 0),T(this,"lower",void 0);const e=this.createLowerCanvas(t);this.lower={el:e,ctx:e.getContext("2d")}}createLowerCanvas(t){const e=(s=t)&&s.getContext!==void 0?t:t&&Vo().getElementById(t)||ms();var s;if(e.hasAttribute("data-fabric"))throw new ii("Trying to initialize a canvas that has already been initialized. Did you forget to dispose the canvas?");return this._originalCanvasStyle=e.style.cssText,e.setAttribute("data-fabric","main"),e.classList.add("lower-canvas"),e}cleanupDOM(t){let{width:e,height:s}=t;const{el:i}=this.lower;i.classList.remove("lower-canvas"),i.removeAttribute("data-fabric"),i.setAttribute("width","".concat(e)),i.setAttribute("height","".concat(s)),i.style.cssText=this._originalCanvasStyle||"",this._originalCanvasStyle=void 0}setDimensions(t,e){const{el:s,ctx:i}=this.lower;cm(s,i,t,e)}setCSSDimensions(t){vf(this.lower.el,t)}calcOffset(){return function(t){var e;const s=t&&Ls(t),i={left:0,top:0};if(!s)return i;const n=((e=lm(t))===null||e===void 0?void 0:e.getComputedStyle(t,null))||{};i.left+=parseInt(n.borderLeftWidth,10)||0,i.top+=parseInt(n.borderTopWidth,10)||0,i.left+=parseInt(n.paddingLeft,10)||0,i.top+=parseInt(n.paddingTop,10)||0;let r={left:0,top:0};const o=s.documentElement;t.getBoundingClientRect!==void 0&&(r=t.getBoundingClientRect());const h=hm(t);return{left:r.left+h.left-(o.clientLeft||0)+i.left,top:r.top+h.top-(o.clientTop||0)+i.top}}(this.lower.el)}dispose(){ni().dispose(this.lower.el),delete this.lower}}const Tv={backgroundVpt:!0,backgroundColor:"",overlayVpt:!0,overlayColor:"",includeDefaultValues:!0,svgViewportTransformation:!0,renderOnAddRemove:!0,skipOffscreen:!0,enableRetinaScaling:!0,imageSmoothingEnabled:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,viewportTransform:[...Ee]};class Ph extends $p(qp){get lowerCanvasEl(){var t;return(t=this.elements.lower)===null||t===void 0?void 0:t.el}get contextContainer(){var t;return(t=this.elements.lower)===null||t===void 0?void 0:t.ctx}static getDefaults(){return Ph.ownDefaults}constructor(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),Object.assign(this,this.constructor.getDefaults()),this.set(e),this.initElements(t),this._setDimensionsImpl({width:this.width||this.elements.lower.el.width||0,height:this.height||this.elements.lower.el.height||0}),this.skipControlsDrawing=!1,this.viewportTransform=[...this.viewportTransform],this.calcViewportBoundaries()}initElements(t){this.elements=new dm(t)}add(){const t=super.add(...arguments);return arguments.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),t}insertAt(t){for(var e=arguments.length,s=new Array(e>1?e-1:0),i=1;i<e;i++)s[i-1]=arguments[i];const n=super.insertAt(t,...s);return s.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),n}remove(){const t=super.remove(...arguments);return t.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),t}_onObjectAdded(t){t.canvas&&t.canvas!==this&&(Oi("warn",`Canvas is trying to add an object that belongs to a different canvas.
3
3
  Resulting to default behavior: removing object from previous canvas and adding to new canvas`),t.canvas.remove(t)),t._set("canvas",this),t.setCoords(),this.fire("object:added",{target:t}),t.fire("added",{target:this})}_onObjectRemoved(t){t._set("canvas",void 0),this.fire("object:removed",{target:t}),t.fire("removed",{target:this})}_onStackOrderChanged(){this.renderOnAddRemove&&this.requestRenderAll()}getRetinaScaling(){return this.enableRetinaScaling?Xp():1}calcOffset(){return this._offset=this.elements.calcOffset()}getWidth(){return this.width}getHeight(){return this.height}setWidth(t,e){return this.setDimensions({width:t},e)}setHeight(t,e){return this.setDimensions({height:t},e)}_setDimensionsImpl(t){let{cssOnly:e=!1,backstoreOnly:s=!1}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!e){const i=E({width:this.width,height:this.height},t);this.elements.setDimensions(i,this.getRetinaScaling()),this.hasLostContext=!0,this.width=i.width,this.height=i.height}s||this.elements.setCSSDimensions(t),this.calcOffset()}setDimensions(t,e){this._setDimensionsImpl(t,e),e&&e.cssOnly||this.requestRenderAll()}getZoom(){return this.viewportTransform[0]}setViewportTransform(t){this.viewportTransform=t,this.calcViewportBoundaries(),this.renderOnAddRemove&&this.requestRenderAll()}zoomToPoint(t,e){const s=t,i=[...this.viewportTransform],n=ge(t,Xe(i));i[0]=e,i[3]=e;const r=ge(n,i);i[4]+=s.x-r.x,i[5]+=s.y-r.y,this.setViewportTransform(i)}setZoom(t){this.zoomToPoint(new P(0,0),t)}absolutePan(t){const e=[...this.viewportTransform];return e[4]=-t.x,e[5]=-t.y,this.setViewportTransform(e)}relativePan(t){return this.absolutePan(new P(-t.x-this.viewportTransform[4],-t.y-this.viewportTransform[5]))}getElement(){return this.elements.lower.el}clearContext(t){t.clearRect(0,0,this.width,this.height)}getContext(){return this.elements.lower.ctx}clear(){this.remove(...this.getObjects()),this.backgroundImage=void 0,this.overlayImage=void 0,this.backgroundColor="",this.overlayColor="",this.clearContext(this.getContext()),this.fire("canvas:cleared"),this.renderOnAddRemove&&this.requestRenderAll()}renderAll(){this.cancelRequestedRender(),this.destroyed||this.renderCanvas(this.getContext(),this._objects)}renderAndReset(){this.nextRenderHandle=0,this.renderAll()}requestRenderAll(){this.nextRenderHandle||this.disposed||this.destroyed||(this.nextRenderHandle=Ch(()=>this.renderAndReset()))}calcViewportBoundaries(){const t=this.width,e=this.height,s=Xe(this.viewportTransform),i=ge({x:0,y:0},s),n=ge({x:t,y:e},s),r=i.min(n),o=i.max(n);return this.vptCoords={tl:r,tr:new P(o.x,r.y),bl:new P(r.x,o.y),br:o}}cancelRequestedRender(){this.nextRenderHandle&&(Kp(this.nextRenderHandle),this.nextRenderHandle=0)}drawControls(t){}renderCanvas(t,e){if(this.destroyed)return;const s=this.viewportTransform,i=this.clipPath;this.calcViewportBoundaries(),this.clearContext(t),t.imageSmoothingEnabled=this.imageSmoothingEnabled,t.patternQuality="best",this.fire("before:render",{ctx:t}),this._renderBackground(t),t.save(),t.transform(s[0],s[1],s[2],s[3],s[4],s[5]),this._renderObjects(t,e),t.restore(),this.controlsAboveOverlay||this.skipControlsDrawing||this.drawControls(t),i&&(i._set("canvas",this),i.shouldCache(),i._transformDone=!0,i.renderCache({forClipping:!0}),this.drawClipPathOnCanvas(t,i)),this._renderOverlay(t),this.controlsAboveOverlay&&!this.skipControlsDrawing&&this.drawControls(t),this.fire("after:render",{ctx:t}),this.__cleanupTask&&(this.__cleanupTask(),this.__cleanupTask=void 0)}drawClipPathOnCanvas(t,e){const s=this.viewportTransform;t.save(),t.transform(...s),t.globalCompositeOperation="destination-in",e.transform(t),t.scale(1/e.zoomX,1/e.zoomY),t.drawImage(e._cacheCanvas,-e.cacheTranslationX,-e.cacheTranslationY),t.restore()}_renderObjects(t,e){for(let s=0,i=e.length;s<i;++s)e[s]&&e[s].render(t)}_renderBackgroundOrOverlay(t,e){const s=this["".concat(e,"Color")],i=this["".concat(e,"Image")],n=this.viewportTransform,r=this["".concat(e,"Vpt")];if(!s&&!i)return;const o=bs(s);if(s){if(t.save(),t.beginPath(),t.moveTo(0,0),t.lineTo(this.width,0),t.lineTo(this.width,this.height),t.lineTo(0,this.height),t.closePath(),t.fillStyle=o?s.toLive(t):s,r&&t.transform(...n),o){t.transform(1,0,0,1,s.offsetX||0,s.offsetY||0);const h=s.gradientTransform||s.patternTransform;h&&t.transform(...h)}t.fill(),t.restore()}if(i){t.save();const{skipOffscreen:h}=this;this.skipOffscreen=r,r&&t.transform(...n),i.render(t),this.skipOffscreen=h,t.restore()}}_renderBackground(t){this._renderBackgroundOrOverlay(t,"background")}_renderOverlay(t){this._renderBackgroundOrOverlay(t,"overlay")}getCenter(){return{top:this.height/2,left:this.width/2}}getCenterPoint(){return new P(this.width/2,this.height/2)}centerObjectH(t){return this._centerObject(t,new P(this.getCenterPoint().x,t.getCenterPoint().y))}centerObjectV(t){return this._centerObject(t,new P(t.getCenterPoint().x,this.getCenterPoint().y))}centerObject(t){return this._centerObject(t,this.getCenterPoint())}viewportCenterObject(t){return this._centerObject(t,this.getVpCenter())}viewportCenterObjectH(t){return this._centerObject(t,new P(this.getVpCenter().x,t.getCenterPoint().y))}viewportCenterObjectV(t){return this._centerObject(t,new P(t.getCenterPoint().x,this.getVpCenter().y))}getVpCenter(){return ge(this.getCenterPoint(),Xe(this.viewportTransform))}_centerObject(t,e){t.setXY(e,Q,Q),t.setCoords(),this.renderOnAddRemove&&this.requestRenderAll()}toDatalessJSON(t){return this.toDatalessObject(t)}toObject(t){return this._toObjectMethod("toObject",t)}toJSON(){return this.toObject()}toDatalessObject(t){return this._toObjectMethod("toDatalessObject",t)}_toObjectMethod(t,e){const s=this.clipPath,i=s&&!s.excludeFromExport?this._toObject(s,t,e):null;return E(E(E({version:nf},yr(this,e)),{},{objects:this._objects.filter(n=>!n.excludeFromExport).map(n=>this._toObject(n,t,e))},this.__serializeBgOverlay(t,e)),i?{clipPath:i}:null)}_toObject(t,e,s){let i;this.includeDefaultValues||(i=t.includeDefaultValues,t.includeDefaultValues=!1);const n=t[e](s);return this.includeDefaultValues||(t.includeDefaultValues=!!i),n}__serializeBgOverlay(t,e){const s={},i=this.backgroundImage,n=this.overlayImage,r=this.backgroundColor,o=this.overlayColor;return bs(r)?r.excludeFromExport||(s.background=r.toObject(e)):r&&(s.background=r),bs(o)?o.excludeFromExport||(s.overlay=o.toObject(e)):o&&(s.overlay=o),i&&!i.excludeFromExport&&(s.backgroundImage=this._toObject(i,t,e)),n&&!n.excludeFromExport&&(s.overlayImage=this._toObject(n,t,e)),s}toSVG(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0;t.reviver=e;const s=[];return this._setSVGPreamble(s,t),this._setSVGHeader(s,t),this.clipPath&&s.push('<g clip-path="url(#'.concat(this.clipPath.clipPathId,`)" >
4
4
  `)),this._setSVGBgOverlayColor(s,"background"),this._setSVGBgOverlayImage(s,"backgroundImage",e),this._setSVGObjects(s,e),this.clipPath&&s.push(`</g>
5
5
  `),this._setSVGBgOverlayColor(s,"overlay"),this._setSVGBgOverlayImage(s,"overlayImage",e),s.push("</svg>"),s.join("")}_setSVGPreamble(t,e){e.suppressPreamble||t.push('<?xml version="1.0" encoding="',e.encoding||"UTF-8",`" standalone="no" ?>
@@ -18,7 +18,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
18
18
  `.concat(i,`]]></style>
19
19
  `):""}_setSVGObjects(t,e){this.forEachObject(s=>{s.excludeFromExport||this._setSVGObject(t,s,e)})}_setSVGObject(t,e,s){t.push(e.toSVG(s))}_setSVGBgOverlayImage(t,e,s){const i=this[e];i&&!i.excludeFromExport&&i.toSVG&&t.push(i.toSVG(s))}_setSVGBgOverlayColor(t,e){const s=this["".concat(e,"Color")];if(s)if(bs(s)){const i=s.repeat||"",n=this.width,r=this.height,o=this["".concat(e,"Vpt")]?kh(Xe(this.viewportTransform)):"";t.push('<rect transform="'.concat(o," translate(").concat(n/2,",").concat(r/2,')" x="').concat(s.offsetX-n/2,'" y="').concat(s.offsetY-r/2,'" width="').concat(i!=="repeat-y"&&i!=="no-repeat"||!am(s)?n:s.source.width,'" height="').concat(i!=="repeat-x"&&i!=="no-repeat"||!am(s)?r:s.source.height,'" fill="url(#SVGID_').concat(s.id,`)"></rect>
20
20
  `))}else t.push('<rect x="0" y="0" width="100%" height="100%" ','fill="',s,'"',`></rect>
21
- `)}loadFromJSON(t,e){let{signal:s}=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(!t)return Promise.reject(new ii("`json` is undefined"));const i=typeof t=="string"?JSON.parse(t):t,{objects:n=[],backgroundImage:r,background:o,overlayImage:h,overlay:c,clipPath:u}=i,d=this.renderOnAddRemove;return this.renderOnAddRemove=!1,Promise.all([qo(n,{reviver:e,signal:s}),Eh({backgroundImage:r,backgroundColor:o,overlayImage:h,overlayColor:c,clipPath:u},{signal:s})]).then(f=>{let[g,p]=f;return this.clear(),this.add(...g),this.set(i),this.set(p),this.renderOnAddRemove=d,this})}clone(t){const e=this.toObject(t);return this.cloneWithoutData().loadFromJSON(e)}cloneWithoutData(){const t=Rs(this);return new this.constructor(t)}toDataURL(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const{format:e="png",quality:s=1,multiplier:i=1,enableRetinaScaling:n=!1}=t,r=i*(n?this.getRetinaScaling():1);return df(this.toCanvasElement(r,t),e,s)}toBlob(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const{format:e="png",quality:s=1,multiplier:i=1,enableRetinaScaling:n=!1}=t,r=i*(n?this.getRetinaScaling():1);return ff(this.toCanvasElement(r,t),e,s)}toCanvasElement(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:1,{width:e,height:s,left:i,top:n,filter:r}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const o=(e||this.width)*t,h=(s||this.height)*t,c=this.getZoom(),u=this.width,d=this.height,f=this.skipControlsDrawing,g=c*t,p=this.viewportTransform,b=[g,0,0,g,(p[4]-(i||0))*t,(p[5]-(n||0))*t],v=this.enableRetinaScaling,_=Rs({width:o,height:h}),x=r?this._objects.filter(C=>r(C)):this._objects;return this.enableRetinaScaling=!1,this.viewportTransform=b,this.width=o,this.height=h,this.skipControlsDrawing=!0,this.calcViewportBoundaries(),this.renderCanvas(_.getContext("2d"),x),this.viewportTransform=p,this.width=u,this.height=d,this.calcViewportBoundaries(),this.enableRetinaScaling=v,this.skipControlsDrawing=f,_}dispose(){return!this.disposed&&this.elements.cleanupDOM({width:this.width,height:this.height}),Xc.cancelByCanvas(this),this.disposed=!0,new Promise((t,e)=>{const s=()=>{this.destroy(),t(!0)};s.kill=e,this.__cleanupTask&&this.__cleanupTask.kill("aborted"),this.destroyed?t(!1):this.nextRenderHandle?this.__cleanupTask=s:s()})}destroy(){this.destroyed=!0,this.cancelRequestedRender(),this.forEachObject(t=>t.dispose()),this._objects=[],this.backgroundImage&&this.backgroundImage.dispose(),this.backgroundImage=void 0,this.overlayImage&&this.overlayImage.dispose(),this.overlayImage=void 0,this.elements.dispose()}toString(){return"#<Canvas (".concat(this.complexity(),"): { objects: ").concat(this._objects.length," }>")}}A(Ph,"ownDefaults",Tv);const Ev=["touchstart","touchmove","touchend"],fm=a=>{const t=hm(a.target),e=function(s){const i=s.changedTouches;return i&&i[0]?i[0]:s}(a);return new P(e.clientX+t.left,e.clientY+t.top)},qc=a=>Ev.includes(a.type)||a.pointerType==="touch",_f=a=>{a.preventDefault(),a.stopPropagation()},ri=a=>{let t=0,e=0,s=0,i=0;for(let n=0,r=a.length;n<r;n++){const{x:o,y:h}=a[n];(o>s||!n)&&(s=o),(o<t||!n)&&(t=o),(h>i||!n)&&(i=h),(h<e||!n)&&(e=h)}return{left:t,top:e,width:s-t,height:i-e}},kv=["translateX","translateY","scaleX","scaleY"],gm=(a,t)=>Ko(a,Nt(t,a.calcOwnMatrix())),Ko=(a,t)=>{const e=br(t),{translateX:s,translateY:i,scaleX:n,scaleY:r}=e,o=Ct(e,kv),h=new P(s,i);a.flipX=!1,a.flipY=!1,Object.assign(a,o),a.set({scaleX:n,scaleY:r}),a.setPositionByOrigin(h,Q,Q)},pm=a=>{a.scaleX=1,a.scaleY=1,a.skewX=0,a.skewY=0,a.flipX=!1,a.flipY=!1,a.rotate(0)},wf=a=>({scaleX:a.scaleX,scaleY:a.scaleY,skewX:a.skewX,skewY:a.skewY,angle:a.angle,left:a.left,flipX:a.flipX,flipY:a.flipY,top:a.top}),Kc=(a,t,e)=>{const s=a/2,i=t/2,n=[new P(-s,-i),new P(s,-i),new P(-s,i),new P(s,i)].map(o=>o.transform(e)),r=ri(n);return new P(r.width,r.height)},Dh=function(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:Ee;return Nt(Xe(arguments.length>1&&arguments[1]!==void 0?arguments[1]:Ee),a)},_r=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Ee,e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Ee;return a.transform(Dh(t,e))},mm=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Ee,e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Ee;return a.transform(Dh(t,e),!0)},xf=(a,t,e)=>{const s=Dh(t,e);return Ko(a,Nt(s,a.calcOwnMatrix())),s},bm=(a,t)=>{var e;const{transform:{target:s}}=t;(e=s.canvas)===null||e===void 0||e.fire("object:".concat(a),E(E({},t),{},{target:s})),s.fire(a,t)},Mv={left:-.5,top:-.5,center:0,bottom:.5,right:.5},Vt=a=>typeof a=="string"?Mv[a]:a-.5,Qc="not-allowed";function ym(a){return Vt(a.originX)===Vt(Q)&&Vt(a.originY)===Vt(Q)}function vm(a){return .5-Vt(a)}const Fs=(a,t)=>a[t],_m=(a,t,e,s)=>({e:a,transform:t,pointer:new P(e,s)});function wm(a,t){const e=a.getTotalAngle()+kn(Math.atan2(t.y,t.x))+360;return Math.round(e%360/45)}function Sf(a,t,e,s,i){var n;let{target:r,corner:o}=a;const h=r.controls[o],c=((n=r.canvas)===null||n===void 0?void 0:n.getZoom())||1,u=r.padding/c,d=function(f,g,p,b){const v=f.getRelativeCenterPoint(),_=p!==void 0&&b!==void 0?f.translateToGivenOrigin(v,Q,Q,p,b):new P(f.left,f.top);return(f.angle?g.rotate(-Rt(f.angle),v):g).subtract(_)}(r,new P(s,i),t,e);return d.x>=u&&(d.x-=u),d.x<=-u&&(d.x+=u),d.y>=u&&(d.y-=u),d.y<=u&&(d.y+=u),d.x-=h.offsetX,d.y-=h.offsetY,d}const Pv=(a,t,e,s)=>{const{target:i,offsetX:n,offsetY:r}=t,o=e-n,h=s-r,c=!Fs(i,"lockMovementX")&&i.left!==o,u=!Fs(i,"lockMovementY")&&i.top!==h;return c&&i.set(dt,o),u&&i.set(Ve,h),(c||u)&&bm(Wp,_m(a,t,e,s)),c||u};class xm{getSvgStyles(t){const e=this.fillRule?this.fillRule:"nonzero",s=this.strokeWidth?this.strokeWidth:"0",i=this.strokeDashArray?this.strokeDashArray.join(" "):ke,n=this.strokeDashOffset?this.strokeDashOffset:"0",r=this.strokeLineCap?this.strokeLineCap:"butt",o=this.strokeLineJoin?this.strokeLineJoin:"miter",h=this.strokeMiterLimit?this.strokeMiterLimit:"4",c=this.opacity!==void 0?this.opacity:"1",u=this.visible?"":" visibility: hidden;",d=t?"":this.getSvgFilter(),f=Mh(zt,this.fill);return[Mh(Pe,this.stroke),"stroke-width: ",s,"; ","stroke-dasharray: ",i,"; ","stroke-linecap: ",r,"; ","stroke-dashoffset: ",n,"; ","stroke-linejoin: ",o,"; ","stroke-miterlimit: ",h,"; ",f,"fill-rule: ",e,"; ","opacity: ",c,";",d,u].join("")}getSvgFilter(){return this.shadow?"filter: url(#SVGID_".concat(this.shadow.id,");"):""}getSvgCommons(){return[this.id?'id="'.concat(this.id,'" '):"",this.clipPath?'clip-path="url(#'.concat(this.clipPath.clipPathId,')" '):""].join("")}getSvgTransform(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"";const s=t?this.calcTransformMatrix():this.calcOwnMatrix(),i='transform="'.concat(kh(s));return"".concat(i).concat(e,'" ')}_toSVG(t){return[""]}toSVG(t){return this._createBaseSVGMarkup(this._toSVG(t),{reviver:t})}toClipPathSVG(t){return" "+this._createBaseClipPathSVGMarkup(this._toSVG(t),{reviver:t})}_createBaseClipPathSVGMarkup(t){let{reviver:e,additionalTransform:s=""}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const i=[this.getSvgTransform(!0,s),this.getSvgCommons()].join(""),n=t.indexOf("COMMON_PARTS");return t[n]=i,e?e(t.join("")):t.join("")}_createBaseSVGMarkup(t){let{noStyle:e,reviver:s,withShadow:i,additionalTransform:n}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const r=e?"":'style="'.concat(this.getSvgStyles(),'" '),o=i?'style="'.concat(this.getSvgFilter(),'" '):"",h=this.clipPath,c=this.strokeUniform?'vector-effect="non-scaling-stroke" ':"",u=h&&h.absolutePositioned,d=this.stroke,f=this.fill,g=this.shadow,p=[],b=t.indexOf("COMMON_PARTS");let v;h&&(h.clipPathId="CLIPPATH_".concat(En()),v='<clipPath id="'.concat(h.clipPathId,`" >
21
+ `)}loadFromJSON(t,e){let{signal:s}=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(!t)return Promise.reject(new ii("`json` is undefined"));const i=typeof t=="string"?JSON.parse(t):t,{objects:n=[],backgroundImage:r,background:o,overlayImage:h,overlay:c,clipPath:u}=i,d=this.renderOnAddRemove;return this.renderOnAddRemove=!1,Promise.all([qo(n,{reviver:e,signal:s}),Eh({backgroundImage:r,backgroundColor:o,overlayImage:h,overlayColor:c,clipPath:u},{signal:s})]).then(f=>{let[g,p]=f;return this.clear(),this.add(...g),this.set(i),this.set(p),this.renderOnAddRemove=d,this})}clone(t){const e=this.toObject(t);return this.cloneWithoutData().loadFromJSON(e)}cloneWithoutData(){const t=Rs(this);return new this.constructor(t)}toDataURL(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const{format:e="png",quality:s=1,multiplier:i=1,enableRetinaScaling:n=!1}=t,r=i*(n?this.getRetinaScaling():1);return df(this.toCanvasElement(r,t),e,s)}toBlob(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const{format:e="png",quality:s=1,multiplier:i=1,enableRetinaScaling:n=!1}=t,r=i*(n?this.getRetinaScaling():1);return ff(this.toCanvasElement(r,t),e,s)}toCanvasElement(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:1,{width:e,height:s,left:i,top:n,filter:r}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const o=(e||this.width)*t,h=(s||this.height)*t,c=this.getZoom(),u=this.width,d=this.height,f=this.skipControlsDrawing,g=c*t,p=this.viewportTransform,b=[g,0,0,g,(p[4]-(i||0))*t,(p[5]-(n||0))*t],v=this.enableRetinaScaling,_=Rs({width:o,height:h}),x=r?this._objects.filter(C=>r(C)):this._objects;return this.enableRetinaScaling=!1,this.viewportTransform=b,this.width=o,this.height=h,this.skipControlsDrawing=!0,this.calcViewportBoundaries(),this.renderCanvas(_.getContext("2d"),x),this.viewportTransform=p,this.width=u,this.height=d,this.calcViewportBoundaries(),this.enableRetinaScaling=v,this.skipControlsDrawing=f,_}dispose(){return!this.disposed&&this.elements.cleanupDOM({width:this.width,height:this.height}),Xc.cancelByCanvas(this),this.disposed=!0,new Promise((t,e)=>{const s=()=>{this.destroy(),t(!0)};s.kill=e,this.__cleanupTask&&this.__cleanupTask.kill("aborted"),this.destroyed?t(!1):this.nextRenderHandle?this.__cleanupTask=s:s()})}destroy(){this.destroyed=!0,this.cancelRequestedRender(),this.forEachObject(t=>t.dispose()),this._objects=[],this.backgroundImage&&this.backgroundImage.dispose(),this.backgroundImage=void 0,this.overlayImage&&this.overlayImage.dispose(),this.overlayImage=void 0,this.elements.dispose()}toString(){return"#<Canvas (".concat(this.complexity(),"): { objects: ").concat(this._objects.length," }>")}}T(Ph,"ownDefaults",Tv);const Ev=["touchstart","touchmove","touchend"],fm=a=>{const t=hm(a.target),e=function(s){const i=s.changedTouches;return i&&i[0]?i[0]:s}(a);return new P(e.clientX+t.left,e.clientY+t.top)},qc=a=>Ev.includes(a.type)||a.pointerType==="touch",_f=a=>{a.preventDefault(),a.stopPropagation()},ri=a=>{let t=0,e=0,s=0,i=0;for(let n=0,r=a.length;n<r;n++){const{x:o,y:h}=a[n];(o>s||!n)&&(s=o),(o<t||!n)&&(t=o),(h>i||!n)&&(i=h),(h<e||!n)&&(e=h)}return{left:t,top:e,width:s-t,height:i-e}},kv=["translateX","translateY","scaleX","scaleY"],gm=(a,t)=>Ko(a,Nt(t,a.calcOwnMatrix())),Ko=(a,t)=>{const e=br(t),{translateX:s,translateY:i,scaleX:n,scaleY:r}=e,o=Ct(e,kv),h=new P(s,i);a.flipX=!1,a.flipY=!1,Object.assign(a,o),a.set({scaleX:n,scaleY:r}),a.setPositionByOrigin(h,Q,Q)},pm=a=>{a.scaleX=1,a.scaleY=1,a.skewX=0,a.skewY=0,a.flipX=!1,a.flipY=!1,a.rotate(0)},wf=a=>({scaleX:a.scaleX,scaleY:a.scaleY,skewX:a.skewX,skewY:a.skewY,angle:a.angle,left:a.left,flipX:a.flipX,flipY:a.flipY,top:a.top}),Kc=(a,t,e)=>{const s=a/2,i=t/2,n=[new P(-s,-i),new P(s,-i),new P(-s,i),new P(s,i)].map(o=>o.transform(e)),r=ri(n);return new P(r.width,r.height)},Dh=function(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:Ee;return Nt(Xe(arguments.length>1&&arguments[1]!==void 0?arguments[1]:Ee),a)},_r=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Ee,e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Ee;return a.transform(Dh(t,e))},mm=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Ee,e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Ee;return a.transform(Dh(t,e),!0)},xf=(a,t,e)=>{const s=Dh(t,e);return Ko(a,Nt(s,a.calcOwnMatrix())),s},bm=(a,t)=>{var e;const{transform:{target:s}}=t;(e=s.canvas)===null||e===void 0||e.fire("object:".concat(a),E(E({},t),{},{target:s})),s.fire(a,t)},Mv={left:-.5,top:-.5,center:0,bottom:.5,right:.5},Vt=a=>typeof a=="string"?Mv[a]:a-.5,Qc="not-allowed";function ym(a){return Vt(a.originX)===Vt(Q)&&Vt(a.originY)===Vt(Q)}function vm(a){return .5-Vt(a)}const Fs=(a,t)=>a[t],_m=(a,t,e,s)=>({e:a,transform:t,pointer:new P(e,s)});function wm(a,t){const e=a.getTotalAngle()+kn(Math.atan2(t.y,t.x))+360;return Math.round(e%360/45)}function Sf(a,t,e,s,i){var n;let{target:r,corner:o}=a;const h=r.controls[o],c=((n=r.canvas)===null||n===void 0?void 0:n.getZoom())||1,u=r.padding/c,d=function(f,g,p,b){const v=f.getRelativeCenterPoint(),_=p!==void 0&&b!==void 0?f.translateToGivenOrigin(v,Q,Q,p,b):new P(f.left,f.top);return(f.angle?g.rotate(-Rt(f.angle),v):g).subtract(_)}(r,new P(s,i),t,e);return d.x>=u&&(d.x-=u),d.x<=-u&&(d.x+=u),d.y>=u&&(d.y-=u),d.y<=u&&(d.y+=u),d.x-=h.offsetX,d.y-=h.offsetY,d}const Pv=(a,t,e,s)=>{const{target:i,offsetX:n,offsetY:r}=t,o=e-n,h=s-r,c=!Fs(i,"lockMovementX")&&i.left!==o,u=!Fs(i,"lockMovementY")&&i.top!==h;return c&&i.set(dt,o),u&&i.set(Ve,h),(c||u)&&bm(Wp,_m(a,t,e,s)),c||u};class xm{getSvgStyles(t){const e=this.fillRule?this.fillRule:"nonzero",s=this.strokeWidth?this.strokeWidth:"0",i=this.strokeDashArray?this.strokeDashArray.join(" "):ke,n=this.strokeDashOffset?this.strokeDashOffset:"0",r=this.strokeLineCap?this.strokeLineCap:"butt",o=this.strokeLineJoin?this.strokeLineJoin:"miter",h=this.strokeMiterLimit?this.strokeMiterLimit:"4",c=this.opacity!==void 0?this.opacity:"1",u=this.visible?"":" visibility: hidden;",d=t?"":this.getSvgFilter(),f=Mh(zt,this.fill);return[Mh(Pe,this.stroke),"stroke-width: ",s,"; ","stroke-dasharray: ",i,"; ","stroke-linecap: ",r,"; ","stroke-dashoffset: ",n,"; ","stroke-linejoin: ",o,"; ","stroke-miterlimit: ",h,"; ",f,"fill-rule: ",e,"; ","opacity: ",c,";",d,u].join("")}getSvgFilter(){return this.shadow?"filter: url(#SVGID_".concat(this.shadow.id,");"):""}getSvgCommons(){return[this.id?'id="'.concat(this.id,'" '):"",this.clipPath?'clip-path="url(#'.concat(this.clipPath.clipPathId,')" '):""].join("")}getSvgTransform(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"";const s=t?this.calcTransformMatrix():this.calcOwnMatrix(),i='transform="'.concat(kh(s));return"".concat(i).concat(e,'" ')}_toSVG(t){return[""]}toSVG(t){return this._createBaseSVGMarkup(this._toSVG(t),{reviver:t})}toClipPathSVG(t){return" "+this._createBaseClipPathSVGMarkup(this._toSVG(t),{reviver:t})}_createBaseClipPathSVGMarkup(t){let{reviver:e,additionalTransform:s=""}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const i=[this.getSvgTransform(!0,s),this.getSvgCommons()].join(""),n=t.indexOf("COMMON_PARTS");return t[n]=i,e?e(t.join("")):t.join("")}_createBaseSVGMarkup(t){let{noStyle:e,reviver:s,withShadow:i,additionalTransform:n}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const r=e?"":'style="'.concat(this.getSvgStyles(),'" '),o=i?'style="'.concat(this.getSvgFilter(),'" '):"",h=this.clipPath,c=this.strokeUniform?'vector-effect="non-scaling-stroke" ':"",u=h&&h.absolutePositioned,d=this.stroke,f=this.fill,g=this.shadow,p=[],b=t.indexOf("COMMON_PARTS");let v;h&&(h.clipPathId="CLIPPATH_".concat(En()),v='<clipPath id="'.concat(h.clipPathId,`" >
22
22
  `).concat(h.toClipPathSVG(s),`</clipPath>
23
23
  `)),u&&p.push("<g ",o,this.getSvgCommons(),` >
24
24
  `),p.push("<g ",this.getSvgTransform(!1),u?"":o+this.getSvgCommons(),` >
@@ -34,32 +34,32 @@ Resulting to default behavior: removing object from previous canvas and adding t
34
34
  <feMergeNode in="SourceGraphic"></feMergeNode>
35
35
  </feMerge>
36
36
  </filter>
37
- `)}toObject(){const t={color:this.color,blur:this.blur,offsetX:this.offsetX,offsetY:this.offsetY,affectStroke:this.affectStroke,nonScaling:this.nonScaling,type:this.constructor.type},e=Li.ownDefaults;return this.includeDefaultValues?t:mf(t,(s,i)=>s!==e[i])}static async fromObject(t){return new this(t)}}A(Li,"ownDefaults",{color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1}),A(Li,"type","shadow"),N.setClass(Li,"shadow");const wr=(a,t,e)=>Math.max(a,Math.min(t,e)),Iv=[Ve,dt,Me,Je,"flipX","flipY","originX","originY","angle","opacity","globalCompositeOperation","shadow","visible",Xo,Wo],Fi=[zt,Pe,"strokeWidth","strokeDashArray","width","height","paintFirst","strokeUniform","strokeLineCap","strokeDashOffset","strokeLineJoin","strokeMiterLimit","backgroundColor","clipPath"],Nv={top:0,left:0,width:0,height:0,angle:0,flipX:!1,flipY:!1,scaleX:1,scaleY:1,minScaleLimit:0,skewX:0,skewY:0,originX:dt,originY:Ve,strokeWidth:1,strokeUniform:!1,padding:0,opacity:1,paintFirst:zt,fill:"rgb(0,0,0)",fillRule:"nonzero",stroke:null,strokeDashArray:null,strokeDashOffset:0,strokeLineCap:"butt",strokeLineJoin:"miter",strokeMiterLimit:4,globalCompositeOperation:"source-over",backgroundColor:"",shadow:null,visible:!0,includeDefaultValues:!0,excludeFromExport:!1,objectCaching:!0,clipPath:void 0,inverted:!1,absolutePositioned:!1,centeredRotation:!0,centeredScaling:!1,dirty:!0},Pf=(a,t,e,s)=>(a<Math.abs(t)?(a=t,s=e/4):s=t===0&&a===0?e/Ri*Math.asin(1):e/Ri*Math.asin(t/a),{a,c:t,p:e,s}),Dm=(a,t,e,s,i)=>a*Math.pow(2,10*(s-=1))*Math.sin((s*i-t)*Ri/e),Om=(a,t,e,s)=>-e*Math.cos(a/s*An)+e+t,Df=(a,t,e,s)=>(a/=s)<1/2.75?e*(7.5625*a*a)+t:a<2/2.75?e*(7.5625*(a-=1.5/2.75)*a+.75)+t:a<2.5/2.75?e*(7.5625*(a-=2.25/2.75)*a+.9375)+t:e*(7.5625*(a-=2.625/2.75)*a+.984375)+t,Rm=(a,t,e,s)=>e-Df(s-a,0,e,s)+t;var jv=Object.freeze({__proto__:null,defaultEasing:Om,easeInBack:function(a,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:1.70158;return e*(a/=s)*a*((i+1)*a-i)+t},easeInBounce:Rm,easeInCirc:(a,t,e,s)=>-e*(Math.sqrt(1-(a/=s)*a)-1)+t,easeInCubic:(a,t,e,s)=>e*(a/s)**3+t,easeInElastic:(a,t,e,s)=>{const i=e;let n=0;if(a===0)return t;if((a/=s)===1)return t+e;n||(n=.3*s);const{a:r,s:o,p:h}=Pf(i,e,n,1.70158);return-Dm(r,o,h,a,s)+t},easeInExpo:(a,t,e,s)=>a===0?t:e*2**(10*(a/s-1))+t,easeInOutBack:function(a,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:1.70158;return(a/=s/2)<1?e/2*(a*a*((1+(i*=1.525))*a-i))+t:e/2*((a-=2)*a*((1+(i*=1.525))*a+i)+2)+t},easeInOutBounce:(a,t,e,s)=>a<s/2?.5*Rm(2*a,0,e,s)+t:.5*Df(2*a-s,0,e,s)+.5*e+t,easeInOutCirc:(a,t,e,s)=>(a/=s/2)<1?-e/2*(Math.sqrt(1-a**2)-1)+t:e/2*(Math.sqrt(1-(a-=2)*a)+1)+t,easeInOutCubic:(a,t,e,s)=>(a/=s/2)<1?e/2*a**3+t:e/2*((a-2)**3+2)+t,easeInOutElastic:(a,t,e,s)=>{const i=e;let n=0;if(a===0)return t;if((a/=s/2)===2)return t+e;n||(n=s*(.3*1.5));const{a:r,s:o,p:h,c}=Pf(i,e,n,1.70158);return a<1?-.5*Dm(r,o,h,a,s)+t:r*Math.pow(2,-10*(a-=1))*Math.sin((a*s-o)*Ri/h)*.5+c+t},easeInOutExpo:(a,t,e,s)=>a===0?t:a===s?t+e:(a/=s/2)<1?e/2*2**(10*(a-1))+t:e/2*-(2**(-10*--a)+2)+t,easeInOutQuad:(a,t,e,s)=>(a/=s/2)<1?e/2*a**2+t:-e/2*(--a*(a-2)-1)+t,easeInOutQuart:(a,t,e,s)=>(a/=s/2)<1?e/2*a**4+t:-e/2*((a-=2)*a**3-2)+t,easeInOutQuint:(a,t,e,s)=>(a/=s/2)<1?e/2*a**5+t:e/2*((a-2)**5+2)+t,easeInOutSine:(a,t,e,s)=>-e/2*(Math.cos(Math.PI*a/s)-1)+t,easeInQuad:(a,t,e,s)=>e*(a/=s)*a+t,easeInQuart:(a,t,e,s)=>e*(a/=s)*a**3+t,easeInQuint:(a,t,e,s)=>e*(a/s)**5+t,easeInSine:(a,t,e,s)=>-e*Math.cos(a/s*An)+e+t,easeOutBack:function(a,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:1.70158;return e*((a=a/s-1)*a*((i+1)*a+i)+1)+t},easeOutBounce:Df,easeOutCirc:(a,t,e,s)=>e*Math.sqrt(1-(a=a/s-1)*a)+t,easeOutCubic:(a,t,e,s)=>e*((a/s-1)**3+1)+t,easeOutElastic:(a,t,e,s)=>{const i=e;let n=0;if(a===0)return t;if((a/=s)===1)return t+e;n||(n=.3*s);const{a:r,s:o,p:h,c}=Pf(i,e,n,1.70158);return r*2**(-10*a)*Math.sin((a*s-o)*Ri/h)+c+t},easeOutExpo:(a,t,e,s)=>a===s?t+e:e*-(2**(-10*a/s)+1)+t,easeOutQuad:(a,t,e,s)=>-e*(a/=s)*(a-2)+t,easeOutQuart:(a,t,e,s)=>-e*((a=a/s-1)*a**3-1)+t,easeOutQuint:(a,t,e,s)=>e*((a/s-1)**5+1)+t,easeOutSine:(a,t,e,s)=>e*Math.sin(a/s*An)+t});const Bv=()=>!1;class Of{constructor(t){let{startValue:e,byValue:s,duration:i=500,delay:n=0,easing:r=Om,onStart:o=pr,onChange:h=pr,onComplete:c=pr,abort:u=Bv,target:d}=t;A(this,"_state","pending"),A(this,"durationProgress",0),A(this,"valueProgress",0),this.tick=this.tick.bind(this),this.duration=i,this.delay=n,this.easing=r,this._onStart=o,this._onChange=h,this._onComplete=c,this._abort=u,this.target=d,this.startValue=e,this.byValue=s,this.value=this.startValue,this.endValue=Object.freeze(this.calculate(this.duration).value)}get state(){return this._state}isDone(){return this._state==="aborted"||this._state==="completed"}start(){const t=e=>{this._state==="pending"&&(this.startTime=e||+new Date,this._state="running",this._onStart(),this.tick(this.startTime))};this.register(),this.delay>0?setTimeout(()=>Ch(t),this.delay):Ch(t)}tick(t){const e=(t||+new Date)-this.startTime,s=Math.min(e,this.duration);this.durationProgress=s/this.duration;const{value:i,valueProgress:n}=this.calculate(s);this.value=Object.freeze(i),this.valueProgress=n,this._state!=="aborted"&&(this._abort(this.value,this.valueProgress,this.durationProgress)?(this._state="aborted",this.unregister()):e>=this.duration?(this.durationProgress=this.valueProgress=1,this._onChange(this.endValue,this.valueProgress,this.durationProgress),this._state="completed",this._onComplete(this.endValue,this.valueProgress,this.durationProgress),this.unregister()):(this._onChange(this.value,this.valueProgress,this.durationProgress),Ch(this.tick)))}register(){Xc.push(this)}unregister(){Xc.remove(this)}abort(){this._state="aborted",this.unregister()}}const Hv=["startValue","endValue"];class Gv extends Of{constructor(t){let{startValue:e=0,endValue:s=100}=t;super(E(E({},Ct(t,Hv)),{},{startValue:e,byValue:s-e}))}calculate(t){const e=this.easing(t,this.startValue,this.byValue,this.duration);return{value:e,valueProgress:Math.abs((e-this.startValue)/this.byValue)}}}const zv=["startValue","endValue"];class Vv extends Of{constructor(t){let{startValue:e=[0],endValue:s=[100]}=t;super(E(E({},Ct(t,zv)),{},{startValue:e,byValue:s.map((i,n)=>i-e[n])}))}calculate(t){const e=this.startValue.map((s,i)=>this.easing(t,s,this.byValue[i],this.duration,i));return{value:e,valueProgress:Math.abs((e[0]-this.startValue[0])/this.byValue[0])}}}const Xv=["startValue","endValue","easing","onChange","onComplete","abort"],Wv=(a,t,e,s)=>t+e*(1-Math.cos(a/s*An)),Rf=a=>a&&((t,e,s)=>a(new gt(t).toRgba(),e,s));class Uv extends Of{constructor(t){let{startValue:e,endValue:s,easing:i=Wv,onChange:n,onComplete:r,abort:o}=t,h=Ct(t,Xv);const c=new gt(e).getSource(),u=new gt(s).getSource();super(E(E({},h),{},{startValue:c,byValue:u.map((d,f)=>d-c[f]),easing:i,onChange:Rf(n),onComplete:Rf(r),abort:Rf(o)}))}calculate(t){const[e,s,i,n]=this.startValue.map((o,h)=>this.easing(t,o,this.byValue[h],this.duration,h)),r=[...[e,s,i].map(Math.round),wr(0,n,1)];return{value:r,valueProgress:r.map((o,h)=>this.byValue[h]!==0?Math.abs((o-this.startValue[h])/this.byValue[h]):0).find(o=>o!==0)||0}}}function Lf(a){const t=(e=>Array.isArray(e.startValue)||Array.isArray(e.endValue))(a)?new Vv(a):new Gv(a);return t.start(),t}function Lm(a){const t=new Uv(a);return t.start(),t}class Mt{constructor(t){this.status=t,this.points=[]}includes(t){return this.points.some(e=>e.eq(t))}append(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];return this.points=this.points.concat(e.filter(i=>!this.includes(i))),this}static isPointContained(t,e,s){let i=arguments.length>3&&arguments[3]!==void 0&&arguments[3];if(e.eq(s))return t.eq(e);if(e.x===s.x)return t.x===e.x&&(i||t.y>=Math.min(e.y,s.y)&&t.y<=Math.max(e.y,s.y));if(e.y===s.y)return t.y===e.y&&(i||t.x>=Math.min(e.x,s.x)&&t.x<=Math.max(e.x,s.x));{const n=Zc(e,s),r=Zc(e,t).divide(n);return i?Math.abs(r.x)===Math.abs(r.y):r.x===r.y&&r.x>=0&&r.x<=1}}static isPointInPolygon(t,e){const s=new P(t).setX(Math.min(t.x-1,...e.map(n=>n.x)));let i=0;for(let n=0;n<e.length;n++){const r=this.intersectSegmentSegment(e[n],e[(n+1)%e.length],t,s);if(r.includes(t))return!0;i+=+(r.status==="Intersection")}return i%2==1}static intersectLineLine(t,e,s,i){let n=!(arguments.length>4&&arguments[4]!==void 0)||arguments[4],r=!(arguments.length>5&&arguments[5]!==void 0)||arguments[5];const o=e.x-t.x,h=e.y-t.y,c=i.x-s.x,u=i.y-s.y,d=t.x-s.x,f=t.y-s.y,g=c*f-u*d,p=o*f-h*d,b=u*o-c*h;if(b!==0){const v=g/b,_=p/b;return(n||0<=v&&v<=1)&&(r||0<=_&&_<=1)?new Mt("Intersection").append(new P(t.x+v*o,t.y+v*h)):new Mt}if(g===0||p===0){const v=n||r||Mt.isPointContained(t,s,i)||Mt.isPointContained(e,s,i)||Mt.isPointContained(s,t,e)||Mt.isPointContained(i,t,e);return new Mt(v?"Coincident":void 0)}return new Mt("Parallel")}static intersectSegmentLine(t,e,s,i){return Mt.intersectLineLine(t,e,s,i,!1,!0)}static intersectSegmentSegment(t,e,s,i){return Mt.intersectLineLine(t,e,s,i,!1,!1)}static intersectLinePolygon(t,e,s){let i=!(arguments.length>3&&arguments[3]!==void 0)||arguments[3];const n=new Mt,r=s.length;for(let o,h,c,u=0;u<r;u++){if(o=s[u],h=s[(u+1)%r],c=Mt.intersectLineLine(t,e,o,h,i,!1),c.status==="Coincident")return c;n.append(...c.points)}return n.points.length>0&&(n.status="Intersection"),n}static intersectSegmentPolygon(t,e,s){return Mt.intersectLinePolygon(t,e,s,!1)}static intersectPolygonPolygon(t,e){const s=new Mt,i=t.length,n=[];for(let r=0;r<i;r++){const o=t[r],h=t[(r+1)%i],c=Mt.intersectSegmentPolygon(o,h,e);c.status==="Coincident"?(n.push(c),s.append(o,h)):s.append(...c.points)}return n.length>0&&n.length===t.length?new Mt("Coincident"):(s.points.length>0&&(s.status="Intersection"),s)}static intersectPolygonRectangle(t,e,s){const i=e.min(s),n=e.max(s),r=new P(n.x,i.y),o=new P(i.x,n.y);return Mt.intersectPolygonPolygon(t,[i,r,n,o])}}class Yv extends qp{getX(){return this.getXY().x}setX(t){this.setXY(this.getXY().setX(t))}getY(){return this.getXY().y}setY(t){this.setXY(this.getXY().setY(t))}getRelativeX(){return this.left}setRelativeX(t){this.left=t}getRelativeY(){return this.top}setRelativeY(t){this.top=t}getXY(){const t=this.getRelativeXY();return this.group?ge(t,this.group.calcTransformMatrix()):t}setXY(t,e,s){this.group&&(t=ge(t,Xe(this.group.calcTransformMatrix()))),this.setRelativeXY(t,e,s)}getRelativeXY(){return new P(this.left,this.top)}setRelativeXY(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.originX,s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.originY;this.setPositionByOrigin(t,e,s)}isStrokeAccountedForInDimensions(){return!1}getCoords(){const{tl:t,tr:e,br:s,bl:i}=this.aCoords||(this.aCoords=this.calcACoords()),n=[t,e,s,i];if(this.group){const r=this.group.calcTransformMatrix();return n.map(o=>ge(o,r))}return n}intersectsWithRect(t,e){return Mt.intersectPolygonRectangle(this.getCoords(),t,e).status==="Intersection"}intersectsWithObject(t){const e=Mt.intersectPolygonPolygon(this.getCoords(),t.getCoords());return e.status==="Intersection"||e.status==="Coincident"||t.isContainedWithinObject(this)||this.isContainedWithinObject(t)}isContainedWithinObject(t){return this.getCoords().every(e=>t.containsPoint(e))}isContainedWithinRect(t,e){const{left:s,top:i,width:n,height:r}=this.getBoundingRect();return s>=t.x&&s+n<=e.x&&i>=t.y&&i+r<=e.y}isOverlapping(t){return this.intersectsWithObject(t)||this.isContainedWithinObject(t)||t.isContainedWithinObject(this)}containsPoint(t){return Mt.isPointInPolygon(t,this.getCoords())}isOnScreen(){if(!this.canvas)return!1;const{tl:t,br:e}=this.canvas.vptCoords;return!!this.getCoords().some(s=>s.x<=e.x&&s.x>=t.x&&s.y<=e.y&&s.y>=t.y)||!!this.intersectsWithRect(t,e)||this.containsPoint(t.midPointFrom(e))}isPartiallyOnScreen(){if(!this.canvas)return!1;const{tl:t,br:e}=this.canvas.vptCoords;return this.intersectsWithRect(t,e)?!0:this.getCoords().every(s=>(s.x>=e.x||s.x<=t.x)&&(s.y>=e.y||s.y<=t.y))&&this.containsPoint(t.midPointFrom(e))}getBoundingRect(){return ri(this.getCoords())}getScaledWidth(){return this._getTransformedDimensions().x}getScaledHeight(){return this._getTransformedDimensions().y}scale(t){this._set(Me,t),this._set(Je,t),this.setCoords()}scaleToWidth(t){const e=this.getBoundingRect().width/this.getScaledWidth();return this.scale(t/this.width/e)}scaleToHeight(t){const e=this.getBoundingRect().height/this.getScaledHeight();return this.scale(t/this.height/e)}getCanvasRetinaScaling(){var t;return((t=this.canvas)===null||t===void 0?void 0:t.getRetinaScaling())||1}getTotalAngle(){return this.group?kn(Zp(this.calcTransformMatrix())):this.angle}getViewportTransform(){var t;return((t=this.canvas)===null||t===void 0?void 0:t.viewportTransform)||Ee.concat()}calcACoords(){const t=$o({angle:this.angle}),{x:e,y:s}=this.getRelativeCenterPoint(),i=Yo(e,s),n=Nt(i,t),r=this._getTransformedDimensions(),o=r.x/2,h=r.y/2;return{tl:ge({x:-o,y:-h},n),tr:ge({x:o,y:-h},n),bl:ge({x:-o,y:h},n),br:ge({x:o,y:h},n)}}setCoords(){this.aCoords=this.calcACoords()}transformMatrixKey(){let t=arguments.length>0&&arguments[0]!==void 0&&arguments[0],e=[];return!t&&this.group&&(e=this.group.transformMatrixKey(t)),e.push(this.top,this.left,this.width,this.height,this.scaleX,this.scaleY,this.angle,this.strokeWidth,this.skewX,this.skewY,+this.flipX,+this.flipY,Vt(this.originX),Vt(this.originY)),e}calcTransformMatrix(){let t=arguments.length>0&&arguments[0]!==void 0&&arguments[0],e=this.calcOwnMatrix();if(t||!this.group)return e;const s=this.transformMatrixKey(t),i=this.matrixCache;return i&&i.key.every((n,r)=>n===s[r])?i.value:(this.group&&(e=Nt(this.group.calcTransformMatrix(!1),e)),this.matrixCache={key:s,value:e},e)}calcOwnMatrix(){const t=this.transformMatrixKey(!0),e=this.ownMatrixCache;if(e&&e.key===t)return e.value;const s=this.getRelativeCenterPoint(),i={angle:this.angle,translateX:s.x,translateY:s.y,scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,flipX:this.flipX,flipY:this.flipY},n=em(i);return this.ownMatrixCache={key:t,value:n},n}_getNonTransformedDimensions(){return new P(this.width,this.height).scalarAdd(this.strokeWidth)}_calculateCurrentDimensions(t){return this._getTransformedDimensions(t).transform(this.getViewportTransform(),!0).scalarAdd(2*this.padding)}_getTransformedDimensions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=E({scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,width:this.width,height:this.height,strokeWidth:this.strokeWidth},t),s=e.strokeWidth;let i=s,n=0;this.strokeUniform&&(i=0,n=s);const r=e.width+i,o=e.height+i;let h;return h=e.skewX===0&&e.skewY===0?new P(r*e.scaleX,o*e.scaleY):Kc(r,o,Ah(e)),h.scalarAdd(n)}translateToGivenOrigin(t,e,s,i,n){let r=t.x,o=t.y;const h=Vt(i)-Vt(e),c=Vt(n)-Vt(s);if(h||c){const u=this._getTransformedDimensions();r+=h*u.x,o+=c*u.y}return new P(r,o)}translateToCenterPoint(t,e,s){if(e===Q&&s===Q)return t;const i=this.translateToGivenOrigin(t,e,s,Q,Q);return this.angle?i.rotate(Rt(this.angle),t):i}translateToOriginPoint(t,e,s){const i=this.translateToGivenOrigin(t,Q,Q,e,s);return this.angle?i.rotate(Rt(this.angle),t):i}getCenterPoint(){const t=this.getRelativeCenterPoint();return this.group?ge(t,this.group.calcTransformMatrix()):t}getRelativeCenterPoint(){return this.translateToCenterPoint(new P(this.left,this.top),this.originX,this.originY)}getPointByOrigin(t,e){return this.translateToOriginPoint(this.getRelativeCenterPoint(),t,e)}setPositionByOrigin(t,e,s){const i=this.translateToCenterPoint(t,e,s),n=this.translateToOriginPoint(i,this.originX,this.originY);this.set({left:n.x,top:n.y})}_getLeftTopCoords(){return this.translateToOriginPoint(this.getRelativeCenterPoint(),dt,Ve)}}const $v=["type"],qv=["extraParam"];let Ii=class Td extends Yv{static getDefaults(){return Td.ownDefaults}get type(){const t=this.constructor.type;return t==="FabricObject"?"object":t.toLowerCase()}set type(t){Oi("warn","Setting type has no effect",t)}constructor(t){super(),A(this,"_cacheContext",null),Object.assign(this,Td.ownDefaults),this.setOptions(t)}_createCacheCanvas(){this._cacheCanvas=ms(),this._cacheContext=this._cacheCanvas.getContext("2d"),this._updateCacheCanvas(),this.dirty=!0}_limitCacheSize(t){const e=t.width,s=t.height,i=ht.maxCacheSideLimit,n=ht.minCacheSideLimit;if(e<=i&&s<=i&&e*s<=ht.perfLimitSizeTotal)return e<n&&(t.width=n),s<n&&(t.height=n),t;const r=e/s,[o,h]=xh.limitDimsByArea(r),c=wr(n,o,i),u=wr(n,h,i);return e>c&&(t.zoomX/=e/c,t.width=c,t.capped=!0),s>u&&(t.zoomY/=s/u,t.height=u,t.capped=!0),t}_getCacheCanvasDimensions(){const t=this.getTotalObjectScaling(),e=this._getTransformedDimensions({skewX:0,skewY:0}),s=e.x*t.x/this.scaleX,i=e.y*t.y/this.scaleY;return{width:Math.ceil(s+2),height:Math.ceil(i+2),zoomX:t.x,zoomY:t.y,x:s,y:i}}_updateCacheCanvas(){const t=this._cacheCanvas,e=this._cacheContext,{width:s,height:i,zoomX:n,zoomY:r,x:o,y:h}=this._limitCacheSize(this._getCacheCanvasDimensions()),c=s!==t.width||i!==t.height,u=this.zoomX!==n||this.zoomY!==r;if(!t||!e)return!1;if(c||u){s!==t.width||i!==t.height?(t.width=s,t.height=i):(e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,t.width,t.height));const d=o/2,f=h/2;return this.cacheTranslationX=Math.round(t.width/2-d)+d,this.cacheTranslationY=Math.round(t.height/2-f)+f,e.translate(this.cacheTranslationX,this.cacheTranslationY),e.scale(n,r),this.zoomX=n,this.zoomY=r,!0}return!1}setOptions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this._setOptions(t)}transform(t){const e=this.group&&!this.group._transformDone||this.group&&this.canvas&&t===this.canvas.contextTop,s=this.calcTransformMatrix(!e);t.transform(s[0],s[1],s[2],s[3],s[4],s[5])}getObjectScaling(){if(!this.group)return new P(Math.abs(this.scaleX),Math.abs(this.scaleY));const t=br(this.calcTransformMatrix());return new P(Math.abs(t.scaleX),Math.abs(t.scaleY))}getTotalObjectScaling(){const t=this.getObjectScaling();if(this.canvas){const e=this.canvas.getZoom(),s=this.getCanvasRetinaScaling();return t.scalarMultiply(e*s)}return t}getObjectOpacity(){let t=this.opacity;return this.group&&(t*=this.group.getObjectOpacity()),t}_constrainScale(t){return Math.abs(t)<this.minScaleLimit?t<0?-this.minScaleLimit:this.minScaleLimit:t===0?1e-4:t}_set(t,e){t!==Me&&t!==Je||(e=this._constrainScale(e)),t===Me&&e<0?(this.flipX=!this.flipX,e*=-1):t==="scaleY"&&e<0?(this.flipY=!this.flipY,e*=-1):t!=="shadow"||!e||e instanceof Li||(e=new Li(e));const s=this[t]!==e;return this[t]=e,s&&this.constructor.cacheProperties.includes(t)&&(this.dirty=!0),this.parent&&(this.dirty||s&&this.constructor.stateProperties.includes(t))&&this.parent._set("dirty",!0),this}isNotVisible(){return this.opacity===0||!this.width&&!this.height&&this.strokeWidth===0||!this.visible}render(t){this.isNotVisible()||this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(t.save(),this._setupCompositeOperation(t),this.drawSelectionBackground(t),this.transform(t),this._setOpacity(t),this._setShadow(t),this.shouldCache()?(this.renderCache(),this.drawCacheOnCanvas(t)):(this._removeCacheCanvas(),this.drawObject(t,!1,{}),this.dirty=!1),t.restore())}drawSelectionBackground(t){}renderCache(t){if(t=t||{},this._cacheCanvas&&this._cacheContext||this._createCacheCanvas(),this.isCacheDirty()&&this._cacheContext){const{zoomX:e,zoomY:s,cacheTranslationX:i,cacheTranslationY:n}=this,{width:r,height:o}=this._cacheCanvas;this.drawObject(this._cacheContext,t.forClipping,{zoomX:e,zoomY:s,cacheTranslationX:i,cacheTranslationY:n,width:r,height:o,parentClipPaths:[]}),this.dirty=!1}}_removeCacheCanvas(){this._cacheCanvas=void 0,this._cacheContext=null}hasStroke(){return this.stroke&&this.stroke!=="transparent"&&this.strokeWidth!==0}hasFill(){return this.fill&&this.fill!=="transparent"}needsItsOwnCache(){return!!(this.paintFirst===Pe&&this.hasFill()&&this.hasStroke()&&this.shadow)||!!this.clipPath}shouldCache(){return this.ownCaching=this.objectCaching&&(!this.parent||!this.parent.isOnACache())||this.needsItsOwnCache(),this.ownCaching}willDrawShadow(){return!!this.shadow&&(this.shadow.offsetX!==0||this.shadow.offsetY!==0)}drawClipPathOnCache(t,e,s){t.save(),e.inverted?t.globalCompositeOperation="destination-out":t.globalCompositeOperation="destination-in",t.setTransform(1,0,0,1,0,0),t.drawImage(s,0,0),t.restore()}drawObject(t,e,s){const i=this.fill,n=this.stroke;e?(this.fill="black",this.stroke="",this._setClippingProperties(t)):this._renderBackground(t),this._render(t),this._drawClipPath(t,this.clipPath,s),this.fill=i,this.stroke=n}createClipPathLayer(t,e){const s=Rs(e),i=s.getContext("2d");if(i.translate(e.cacheTranslationX,e.cacheTranslationY),i.scale(e.zoomX,e.zoomY),t._cacheCanvas=s,e.parentClipPaths.forEach(n=>{n.transform(i)}),e.parentClipPaths.push(t),t.absolutePositioned){const n=Xe(this.calcTransformMatrix());i.transform(n[0],n[1],n[2],n[3],n[4],n[5])}return t.transform(i),t.drawObject(i,!0,e),s}_drawClipPath(t,e,s){if(!e)return;e._transformDone=!0;const i=this.createClipPathLayer(e,s);this.drawClipPathOnCache(t,e,i)}drawCacheOnCanvas(t){t.scale(1/this.zoomX,1/this.zoomY),t.drawImage(this._cacheCanvas,-this.cacheTranslationX,-this.cacheTranslationY)}isCacheDirty(){let t=arguments.length>0&&arguments[0]!==void 0&&arguments[0];if(this.isNotVisible())return!1;const e=this._cacheCanvas,s=this._cacheContext;return!(!e||!s||t||!this._updateCacheCanvas())||!!(this.dirty||this.clipPath&&this.clipPath.absolutePositioned)&&(e&&s&&!t&&(s.save(),s.setTransform(1,0,0,1,0,0),s.clearRect(0,0,e.width,e.height),s.restore()),!0)}_renderBackground(t){if(!this.backgroundColor)return;const e=this._getNonTransformedDimensions();t.fillStyle=this.backgroundColor,t.fillRect(-e.x/2,-e.y/2,e.x,e.y),this._removeShadow(t)}_setOpacity(t){this.group&&!this.group._transformDone?t.globalAlpha=this.getObjectOpacity():t.globalAlpha*=this.opacity}_setStrokeStyles(t,e){const s=e.stroke;s&&(t.lineWidth=e.strokeWidth,t.lineCap=e.strokeLineCap,t.lineDashOffset=e.strokeDashOffset,t.lineJoin=e.strokeLineJoin,t.miterLimit=e.strokeMiterLimit,bs(s)?s.gradientUnits==="percentage"||s.gradientTransform||s.patternTransform?this._applyPatternForTransformedGradient(t,s):(t.strokeStyle=s.toLive(t),this._applyPatternGradientTransform(t,s)):t.strokeStyle=e.stroke)}_setFillStyles(t,e){let{fill:s}=e;s&&(bs(s)?(t.fillStyle=s.toLive(t),this._applyPatternGradientTransform(t,s)):t.fillStyle=s)}_setClippingProperties(t){t.globalAlpha=1,t.strokeStyle="transparent",t.fillStyle="#000000"}_setLineDash(t,e){e&&e.length!==0&&t.setLineDash(e)}_setShadow(t){if(!this.shadow)return;const e=this.shadow,s=this.canvas,i=this.getCanvasRetinaScaling(),[n,,,r]=(s==null?void 0:s.viewportTransform)||Ee,o=n*i,h=r*i,c=e.nonScaling?new P(1,1):this.getObjectScaling();t.shadowColor=e.color,t.shadowBlur=e.blur*ht.browserShadowBlurConstant*(o+h)*(c.x+c.y)/4,t.shadowOffsetX=e.offsetX*o*c.x,t.shadowOffsetY=e.offsetY*h*c.y}_removeShadow(t){this.shadow&&(t.shadowColor="",t.shadowBlur=t.shadowOffsetX=t.shadowOffsetY=0)}_applyPatternGradientTransform(t,e){if(!bs(e))return{offsetX:0,offsetY:0};const s=e.gradientTransform||e.patternTransform,i=-this.width/2+e.offsetX||0,n=-this.height/2+e.offsetY||0;return e.gradientUnits==="percentage"?t.transform(this.width,0,0,this.height,i,n):t.transform(1,0,0,1,i,n),s&&t.transform(s[0],s[1],s[2],s[3],s[4],s[5]),{offsetX:i,offsetY:n}}_renderPaintInOrder(t){this.paintFirst===Pe?(this._renderStroke(t),this._renderFill(t)):(this._renderFill(t),this._renderStroke(t))}_render(t){}_renderFill(t){this.fill&&(t.save(),this._setFillStyles(t,this),this.fillRule==="evenodd"?t.fill("evenodd"):t.fill(),t.restore())}_renderStroke(t){if(this.stroke&&this.strokeWidth!==0){if(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this.strokeUniform){const e=this.getObjectScaling();t.scale(1/e.x,1/e.y)}this._setLineDash(t,this.strokeDashArray),this._setStrokeStyles(t,this),t.stroke(),t.restore()}}_applyPatternForTransformedGradient(t,e){var s;const i=this._limitCacheSize(this._getCacheCanvasDimensions()),n=this.getCanvasRetinaScaling(),r=i.x/this.scaleX/n,o=i.y/this.scaleY/n,h=Rs({width:Math.ceil(r),height:Math.ceil(o)}),c=h.getContext("2d");c&&(c.beginPath(),c.moveTo(0,0),c.lineTo(r,0),c.lineTo(r,o),c.lineTo(0,o),c.closePath(),c.translate(r/2,o/2),c.scale(i.zoomX/this.scaleX/n,i.zoomY/this.scaleY/n),this._applyPatternGradientTransform(c,e),c.fillStyle=e.toLive(t),c.fill(),t.translate(-this.width/2-this.strokeWidth/2,-this.height/2-this.strokeWidth/2),t.scale(n*this.scaleX/i.zoomX,n*this.scaleY/i.zoomY),t.strokeStyle=(s=c.createPattern(h,"no-repeat"))!==null&&s!==void 0?s:"")}_findCenterFromElement(){return new P(this.left+this.width/2,this.top+this.height/2)}clone(t){const e=this.toObject(t);return this.constructor.fromObject(e)}cloneAsImage(t){const e=this.toCanvasElement(t);return new(N.getClass("image"))(e)}toCanvasElement(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=wf(this),s=this.group,i=this.shadow,n=Math.abs,r=t.enableRetinaScaling?Xp():1,o=(t.multiplier||1)*r,h=t.canvasProvider||(x=>new Ph(x,{enableRetinaScaling:!1,renderOnAddRemove:!1,skipOffscreen:!1}));delete this.group,t.withoutTransform&&pm(this),t.withoutShadow&&(this.shadow=null),t.viewportTransform&&xf(this,this.getViewportTransform()),this.setCoords();const c=ms(),u=this.getBoundingRect(),d=this.shadow,f=new P;if(d){const x=d.blur,C=d.nonScaling?new P(1,1):this.getObjectScaling();f.x=2*Math.round(n(d.offsetX)+x)*n(C.x),f.y=2*Math.round(n(d.offsetY)+x)*n(C.y)}const g=u.width+f.x,p=u.height+f.y;c.width=Math.ceil(g),c.height=Math.ceil(p);const b=h(c);t.format==="jpeg"&&(b.backgroundColor="#fff"),this.setPositionByOrigin(new P(b.width/2,b.height/2),Q,Q);const v=this.canvas;b._objects=[this],this.set("canvas",b),this.setCoords();const _=b.toCanvasElement(o||1,t);return this.set("canvas",v),this.shadow=i,s&&(this.group=s),this.set(e),this.setCoords(),b._objects=[],b.destroy(),_}toDataURL(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return df(this.toCanvasElement(t),t.format||"png",t.quality||1)}toBlob(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return ff(this.toCanvasElement(t),t.format||"png",t.quality||1)}isType(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];return e.includes(this.constructor.type)||e.includes(this.type)}complexity(){return 1}toJSON(){return this.toObject()}rotate(t){const{centeredRotation:e,originX:s,originY:i}=this;if(e){const{x:n,y:r}=this.getRelativeCenterPoint();this.originX=Q,this.originY=Q,this.left=n,this.top=r}if(this.set("angle",t),e){const{x:n,y:r}=this.translateToOriginPoint(this.getRelativeCenterPoint(),s,i);this.left=n,this.top=r,this.originX=s,this.originY=i}}setOnGroup(){}_setupCompositeOperation(t){this.globalCompositeOperation&&(t.globalCompositeOperation=this.globalCompositeOperation)}dispose(){Xc.cancelByTarget(this),this.off(),this._set("canvas",void 0),this._cacheCanvas&&ni().dispose(this._cacheCanvas),this._cacheCanvas=void 0,this._cacheContext=null}animate(t,e){return Object.entries(t).reduce((s,i)=>{let[n,r]=i;return s[n]=this._animate(n,r,e),s},{})}_animate(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const i=t.split("."),n=this.constructor.colorProperties.includes(i[i.length-1]),{abort:r,startValue:o,onChange:h,onComplete:c}=s,u=E(E({},s),{},{target:this,startValue:o??i.reduce((d,f)=>d[f],this),endValue:e,abort:r==null?void 0:r.bind(this),onChange:(d,f,g)=>{i.reduce((p,b,v)=>(v===i.length-1&&(p[b]=d),p[b]),this),h&&h(d,f,g)},onComplete:(d,f,g)=>{this.setCoords(),c&&c(d,f,g)}});return n?Lm(u):Lf(u)}isDescendantOf(t){const{parent:e,group:s}=this;return e===t||s===t||!!e&&e.isDescendantOf(t)||!!s&&s!==e&&s.isDescendantOf(t)}getAncestors(){const t=[];let e=this;do e=e.parent,e&&t.push(e);while(e);return t}findCommonAncestors(t){if(this===t)return{fork:[],otherFork:[],common:[this,...this.getAncestors()]};const e=this.getAncestors(),s=t.getAncestors();if(e.length===0&&s.length>0&&this===s[s.length-1])return{fork:[],otherFork:[t,...s.slice(0,s.length-1)],common:[this]};for(let i,n=0;n<e.length;n++){if(i=e[n],i===t)return{fork:[this,...e.slice(0,n)],otherFork:[],common:e.slice(n)};for(let r=0;r<s.length;r++){if(this===s[r])return{fork:[],otherFork:[t,...s.slice(0,r)],common:[this,...e]};if(i===s[r])return{fork:[this,...e.slice(0,n)],otherFork:[t,...s.slice(0,r)],common:e.slice(n)}}}return{fork:[this,...e],otherFork:[t,...s],common:[]}}hasCommonAncestors(t){const e=this.findCommonAncestors(t);return e&&!!e.common.length}isInFrontOf(t){if(this===t)return;const e=this.findCommonAncestors(t);if(e.fork.includes(t))return!0;if(e.otherFork.includes(this))return!1;const s=e.common[0]||this.canvas;if(!s)return;const i=e.fork.pop(),n=e.otherFork.pop(),r=s._objects.indexOf(i),o=s._objects.indexOf(n);return r>-1&&r>o}toObject(){const t=(arguments.length>0&&arguments[0]!==void 0?arguments[0]:[]).concat(Td.customProperties,this.constructor.customProperties||[]);let e;const s=ht.NUM_FRACTION_DIGITS,{clipPath:i,fill:n,stroke:r,shadow:o,strokeDashArray:h,left:c,top:u,originX:d,originY:f,width:g,height:p,strokeWidth:b,strokeLineCap:v,strokeDashOffset:_,strokeLineJoin:x,strokeUniform:C,strokeMiterLimit:S,scaleX:k,scaleY:D,angle:T,flipX:M,flipY:O,opacity:R,visible:L,backgroundColor:W,fillRule:U,paintFirst:G,globalCompositeOperation:at,skewX:F,skewY:z}=this;i&&!i.excludeFromExport&&(e=i.toObject(t.concat("inverted","absolutePositioned")));const rt=te=>At(te,s),Gt=E(E({},yr(this,t)),{},{type:this.constructor.type,version:nf,originX:d,originY:f,left:rt(c),top:rt(u),width:rt(g),height:rt(p),fill:om(n)?n.toObject():n,stroke:om(r)?r.toObject():r,strokeWidth:rt(b),strokeDashArray:h&&h.concat(),strokeLineCap:v,strokeDashOffset:_,strokeLineJoin:x,strokeUniform:C,strokeMiterLimit:rt(S),scaleX:rt(k),scaleY:rt(D),angle:rt(T),flipX:M,flipY:O,opacity:rt(R),shadow:o&&o.toObject(),visible:L,backgroundColor:W,fillRule:U,paintFirst:G,globalCompositeOperation:at,skewX:rt(F),skewY:rt(z)},e?{clipPath:e}:null);return this.includeDefaultValues?Gt:this._removeDefaultValues(Gt)}toDatalessObject(t){return this.toObject(t)}_removeDefaultValues(t){const e=this.constructor.getDefaults(),s=Object.keys(e).length>0?e:Object.getPrototypeOf(this);return mf(t,(i,n)=>{if(n===dt||n===Ve||n==="type")return!0;const r=s[n];return i!==r&&!(Array.isArray(i)&&Array.isArray(r)&&i.length===0&&r.length===0)})}toString(){return"#<".concat(this.constructor.type,">")}static _fromObject(t){let e=Ct(t,$v),s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{extraParam:i}=s,n=Ct(s,qv);return Eh(e,n).then(r=>i?(delete r[i],new this(e[i],r)):new this(r))}static fromObject(t,e){return this._fromObject(t,e)}};A(Ii,"stateProperties",Iv),A(Ii,"cacheProperties",Fi),A(Ii,"ownDefaults",Nv),A(Ii,"type","FabricObject"),A(Ii,"colorProperties",[zt,Pe,"backgroundColor"]),A(Ii,"customProperties",[]),N.setClass(Ii),N.setClass(Ii,"object");const Jo=(a,t,e)=>(s,i,n,r)=>{const o=t(s,i,n,r);return o&&bm(a,E(E({},_m(s,i,n,r)),e)),o};function Zo(a){return(t,e,s,i)=>{const{target:n,originX:r,originY:o}=e,h=n.getRelativeCenterPoint(),c=n.translateToOriginPoint(h,r,o),u=a(t,e,s,i);return n.setPositionByOrigin(c,e.originX,e.originY),u}}const Fm=Jo(Sh,Zo((a,t,e,s)=>{const i=Sf(t,t.originX,t.originY,e,s);if(Vt(t.originX)===Vt(Q)||Vt(t.originX)===Vt(It)&&i.x<0||Vt(t.originX)===Vt(dt)&&i.x>0){const{target:n}=t,r=n.strokeWidth/(n.strokeUniform?n.scaleX:1),o=ym(t)?2:1,h=n.width,c=Math.abs(i.x*o/n.scaleX)-r;return n.set("width",Math.max(c,1)),h!==n.width}return!1}));function Kv(a,t,e,s,i){s=s||{};const n=this.sizeX||s.cornerSize||i.cornerSize,r=this.sizeY||s.cornerSize||i.cornerSize,o=s.transparentCorners!==void 0?s.transparentCorners:i.transparentCorners,h=o?Pe:zt,c=!o&&(s.cornerStrokeColor||i.cornerStrokeColor);let u,d=t,f=e;a.save(),a.fillStyle=s.cornerColor||i.cornerColor||"",a.strokeStyle=s.cornerStrokeColor||i.cornerStrokeColor||"",n>r?(u=n,a.scale(1,r/n),f=e*n/r):r>n?(u=r,a.scale(n/r,1),d=t*r/n):u=n,a.beginPath(),a.arc(d,f,u/2,0,Ri,!1),a[h](),c&&a.stroke(),a.restore()}function Qv(a,t,e,s,i){s=s||{};const n=this.sizeX||s.cornerSize||i.cornerSize,r=this.sizeY||s.cornerSize||i.cornerSize,o=s.transparentCorners!==void 0?s.transparentCorners:i.transparentCorners,h=o?Pe:zt,c=!o&&(s.cornerStrokeColor||i.cornerStrokeColor),u=n/2,d=r/2;a.save(),a.fillStyle=s.cornerColor||i.cornerColor||"",a.strokeStyle=s.cornerStrokeColor||i.cornerStrokeColor||"",a.translate(t,e);const f=i.getTotalAngle();a.rotate(Rt(f)),a["".concat(h,"Rect")](-u,-d,n,r),c&&a.strokeRect(-u,-d,n,r),a.restore()}class Ns{constructor(t){A(this,"visible",!0),A(this,"actionName",zc),A(this,"angle",0),A(this,"x",0),A(this,"y",0),A(this,"offsetX",0),A(this,"offsetY",0),A(this,"sizeX",0),A(this,"sizeY",0),A(this,"touchSizeX",0),A(this,"touchSizeY",0),A(this,"cursorStyle","crosshair"),A(this,"withConnection",!1),Object.assign(this,t)}shouldActivate(t,e,s,i){var n;let{tl:r,tr:o,br:h,bl:c}=i;return((n=e.canvas)===null||n===void 0?void 0:n.getActiveObject())===e&&e.isControlVisible(t)&&Mt.isPointInPolygon(s,[r,o,h,c])}getActionHandler(t,e,s){return this.actionHandler}getMouseDownHandler(t,e,s){return this.mouseDownHandler}getMouseUpHandler(t,e,s){return this.mouseUpHandler}cursorStyleHandler(t,e,s){return e.cursorStyle}getActionName(t,e,s){return e.actionName}getVisibility(t,e){var s,i;return(s=(i=t._controlsVisibility)===null||i===void 0?void 0:i[e])!==null&&s!==void 0?s:this.visible}setVisibility(t,e,s){this.visible=t}positionHandler(t,e,s,i){return new P(this.x*t.x+this.offsetX,this.y*t.y+this.offsetY).transform(e)}calcCornerCoords(t,e,s,i,n,r){const o=Uc([Yo(s,i),$o({angle:t}),Yc((n?this.touchSizeX:this.sizeX)||e,(n?this.touchSizeY:this.sizeY)||e)]);return{tl:new P(-.5,-.5).transform(o),tr:new P(.5,-.5).transform(o),br:new P(.5,.5).transform(o),bl:new P(-.5,.5).transform(o)}}render(t,e,s,i,n){((i=i||{}).cornerStyle||n.cornerStyle)==="circle"?Kv.call(this,t,e,s,i,n):Qv.call(this,t,e,s,i,n)}}const Jv=(a,t,e)=>e.lockRotation?Qc:t.cursorStyle,Zv=Jo(Up,Zo((a,t,e,s)=>{let{target:i,ex:n,ey:r,theta:o,originX:h,originY:c}=t;const u=i.translateToOriginPoint(i.getRelativeCenterPoint(),h,c);if(Fs(i,"lockRotation"))return!1;const d=Math.atan2(r-u.y,n-u.x),f=Math.atan2(s-u.y,e-u.x);let g=kn(f-d+o);if(i.snapAngle&&i.snapAngle>0){const b=i.snapAngle,v=i.snapThreshold||b,_=Math.ceil(g/b)*b,x=Math.floor(g/b)*b;Math.abs(g-x)<v?g=x:Math.abs(g-_)<v&&(g=_)}g<0&&(g=360+g),g%=360;const p=i.angle!==g;return i.angle=g,p}));function Im(a,t){const e=t.canvas,s=a[e.uniScaleKey];return e.uniformScaling&&!s||!e.uniformScaling&&s}function Nm(a,t,e){const s=Fs(a,"lockScalingX"),i=Fs(a,"lockScalingY");if(s&&i||!t&&(s||i)&&e||s&&t==="x"||i&&t==="y")return!0;const{width:n,height:r,strokeWidth:o}=a;return n===0&&o===0&&t!=="y"||r===0&&o===0&&t!=="x"}const t_=["e","se","s","sw","w","nw","n","ne","e"],Oh=(a,t,e)=>{const s=Im(a,e);if(Nm(e,t.x!==0&&t.y===0?"x":t.x===0&&t.y!==0?"y":"",s))return Qc;const i=wm(e,t);return"".concat(t_[i],"-resize")};function Ff(a,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{};const n=t.target,r=i.by,o=Im(a,n);let h,c,u,d,f,g;if(Nm(n,r,o))return!1;if(t.gestureScale)c=t.scaleX*t.gestureScale,u=t.scaleY*t.gestureScale;else{if(h=Sf(t,t.originX,t.originY,e,s),f=r!=="y"?Math.sign(h.x||t.signX||1):1,g=r!=="x"?Math.sign(h.y||t.signY||1):1,t.signX||(t.signX=f),t.signY||(t.signY=g),Fs(n,"lockScalingFlip")&&(t.signX!==f||t.signY!==g))return!1;if(d=n._getTransformedDimensions(),o&&!r){const v=Math.abs(h.x)+Math.abs(h.y),{original:_}=t,x=v/(Math.abs(d.x*_.scaleX/n.scaleX)+Math.abs(d.y*_.scaleY/n.scaleY));c=_.scaleX*x,u=_.scaleY*x}else c=Math.abs(h.x*n.scaleX/d.x),u=Math.abs(h.y*n.scaleY/d.y);ym(t)&&(c*=2,u*=2),t.signX!==f&&r!=="y"&&(t.originX=vm(t.originX),c*=-1,t.signX=f),t.signY!==g&&r!=="x"&&(t.originY=vm(t.originY),u*=-1,t.signY=g)}const p=n.scaleX,b=n.scaleY;return r?(r==="x"&&n.set(Me,c),r==="y"&&n.set(Je,u)):(!Fs(n,"lockScalingX")&&n.set(Me,c),!Fs(n,"lockScalingY")&&n.set(Je,u)),p!==n.scaleX||b!==n.scaleY}const iu=Jo(Hc,Zo((a,t,e,s)=>Ff(a,t,e,s))),e_=Jo(Hc,Zo((a,t,e,s)=>Ff(a,t,e,s,{by:"x"}))),s_=Jo(Hc,Zo((a,t,e,s)=>Ff(a,t,e,s,{by:"y"}))),i_=["target","ex","ey","skewingSide"],If={x:{counterAxis:"y",scale:Me,skew:Xo,lockSkewing:"lockSkewingX",origin:"originX",flip:"flipX"},y:{counterAxis:"x",scale:Je,skew:Wo,lockSkewing:"lockSkewingY",origin:"originY",flip:"flipY"}},n_=["ns","nesw","ew","nwse"],r_=(a,t,e)=>{if(t.x!==0&&Fs(e,"lockSkewingY")||t.y!==0&&Fs(e,"lockSkewingX"))return Qc;const s=wm(e,t)%4;return"".concat(n_[s],"-resize")};function jm(a,t,e,s,i){const{target:n}=e,{counterAxis:r,origin:o,lockSkewing:h,skew:c,flip:u}=If[a];if(Fs(n,h))return!1;const{origin:d,flip:f}=If[r],g=Vt(e[d])*(n[f]?-1:1),p=-Math.sign(g)*(n[u]?-1:1),b=.5*-((n[c]===0&&Sf(e,Q,Q,s,i)[a]>0||n[c]>0?1:-1)*p)+.5;return Jo(Yp,Zo((_,x,C,S)=>function(k,D,T){let{target:M,ex:O,ey:R,skewingSide:L}=D,W=Ct(D,i_);const{skew:U}=If[k],G=T.subtract(new P(O,R)).divide(new P(M.scaleX,M.scaleY))[k],at=M[U],F=W[U],z=Math.tan(Rt(F)),rt=k==="y"?M._getTransformedDimensions({scaleX:1,scaleY:1,skewX:0}).x:M._getTransformedDimensions({scaleX:1,scaleY:1}).y,Gt=2*G*L/Math.max(rt,1)+z,te=kn(Math.atan(Gt));M.set(U,te);const fe=at!==M[U];if(fe&&k==="y"){const{skewX:Yt,scaleX:St}=M,He=M._getTransformedDimensions({skewY:at}),Mi=M._getTransformedDimensions(),Ft=Yt!==0?He.x/Mi.x:1;Ft!==1&&M.set(Me,Ft*St)}return fe}(a,x,new P(C,S))))(t,E(E({},e),{},{[o]:b,skewingSide:p}),s,i)}const o_=(a,t,e,s)=>jm("x",a,t,e,s),a_=(a,t,e,s)=>jm("y",a,t,e,s);function nu(a,t){return a[t.canvas.altActionKey]}const ru=(a,t,e)=>{const s=nu(a,e);return t.x===0?s?Xo:Je:t.y===0?s?Wo:Me:""},ta=(a,t,e)=>nu(a,e)?r_(0,t,e):Oh(a,t,e),Bm=(a,t,e,s)=>nu(a,t.target)?a_(a,t,e,s):e_(a,t,e,s),Hm=(a,t,e,s)=>nu(a,t.target)?o_(a,t,e,s):s_(a,t,e,s),Gm=()=>({ml:new Ns({x:-.5,y:0,cursorStyleHandler:ta,actionHandler:Bm,getActionName:ru}),mr:new Ns({x:.5,y:0,cursorStyleHandler:ta,actionHandler:Bm,getActionName:ru}),mb:new Ns({x:0,y:.5,cursorStyleHandler:ta,actionHandler:Hm,getActionName:ru}),mt:new Ns({x:0,y:-.5,cursorStyleHandler:ta,actionHandler:Hm,getActionName:ru}),tl:new Ns({x:-.5,y:-.5,cursorStyleHandler:Oh,actionHandler:iu}),tr:new Ns({x:.5,y:-.5,cursorStyleHandler:Oh,actionHandler:iu}),bl:new Ns({x:-.5,y:.5,cursorStyleHandler:Oh,actionHandler:iu}),br:new Ns({x:.5,y:.5,cursorStyleHandler:Oh,actionHandler:iu}),mtr:new Ns({x:0,y:-.5,actionHandler:Zv,cursorStyleHandler:Jv,offsetY:-40,withConnection:!0,actionName:lf})}),h_=()=>({mr:new Ns({x:.5,y:0,actionHandler:Fm,cursorStyleHandler:ta,actionName:Sh}),ml:new Ns({x:-.5,y:0,actionHandler:Fm,cursorStyleHandler:ta,actionName:Sh})}),l_=()=>E(E({},Gm()),h_());class Rh extends Ii{static getDefaults(){return E(E({},super.getDefaults()),Rh.ownDefaults)}constructor(t){super(),Object.assign(this,this.constructor.createControls(),Rh.ownDefaults),this.setOptions(t)}static createControls(){return{controls:Gm()}}_updateCacheCanvas(){const t=this.canvas;if(this.noScaleCache&&t&&t._currentTransform){const e=t._currentTransform,s=e.target,i=e.action;if(this===s&&i&&i.startsWith(zc))return!1}return super._updateCacheCanvas()}getActiveControl(){const t=this.__corner;return t?{key:t,control:this.controls[t],coord:this.oCoords[t]}:void 0}findControl(t){let e=arguments.length>1&&arguments[1]!==void 0&&arguments[1];if(!this.hasControls||!this.canvas)return;this.__corner=void 0;const s=Object.entries(this.oCoords);for(let i=s.length-1;i>=0;i--){const[n,r]=s[i],o=this.controls[n];if(o.shouldActivate(n,this,t,e?r.touchCorner:r.corner))return this.__corner=n,{key:n,control:o,coord:this.oCoords[n]}}}calcOCoords(){const t=this.getViewportTransform(),e=this.getCenterPoint(),s=Yo(e.x,e.y),i=$o({angle:this.getTotalAngle()-(this.group&&this.flipX?180:0)}),n=Nt(s,i),r=Nt(t,n),o=Nt(r,[1/t[0],0,0,1/t[3],0,0]),h=this.group?br(this.calcTransformMatrix()):void 0;h&&(h.scaleX=Math.abs(h.scaleX),h.scaleY=Math.abs(h.scaleY));const c=this._calculateCurrentDimensions(h),u={};return this.forEachControl((d,f)=>{const g=d.positionHandler(c,o,this,d);u[f]=Object.assign(g,this._calcCornerCoords(d,g))}),u}_calcCornerCoords(t,e){const s=this.getTotalAngle();return{corner:t.calcCornerCoords(s,this.cornerSize,e.x,e.y,!1,this),touchCorner:t.calcCornerCoords(s,this.touchCornerSize,e.x,e.y,!0,this)}}setCoords(){super.setCoords(),this.canvas&&(this.oCoords=this.calcOCoords())}forEachControl(t){for(const e in this.controls)t(this.controls[e],e,this)}drawSelectionBackground(t){if(!this.selectionBackgroundColor||this.canvas&&this.canvas._activeObject!==this)return;t.save();const e=this.getRelativeCenterPoint(),s=this._calculateCurrentDimensions(),i=this.getViewportTransform();t.translate(e.x,e.y),t.scale(1/i[0],1/i[3]),t.rotate(Rt(this.angle)),t.fillStyle=this.selectionBackgroundColor,t.fillRect(-s.x/2,-s.y/2,s.x,s.y),t.restore()}strokeBorders(t,e){t.strokeRect(-e.x/2,-e.y/2,e.x,e.y)}_drawBorders(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const i=E({hasControls:this.hasControls,borderColor:this.borderColor,borderDashArray:this.borderDashArray},s);t.save(),t.strokeStyle=i.borderColor,this._setLineDash(t,i.borderDashArray),this.strokeBorders(t,e),i.hasControls&&this.drawControlsConnectingLines(t,e),t.restore()}_renderControls(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const{hasBorders:s,hasControls:i}=this,n=E({hasBorders:s,hasControls:i},e),r=this.getViewportTransform(),o=n.hasBorders,h=n.hasControls,c=Nt(r,this.calcTransformMatrix()),u=br(c);t.save(),t.translate(u.translateX,u.translateY),t.lineWidth=this.borderScaleFactor,this.group===this.parent&&(t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1),this.flipX&&(u.angle-=180),t.rotate(Rt(this.group?u.angle:this.angle)),o&&this.drawBorders(t,u,e),h&&this.drawControls(t,e),t.restore()}drawBorders(t,e,s){let i;if(s&&s.forActiveSelection||this.group){const n=Kc(this.width,this.height,Ah(e)),r=this.isStrokeAccountedForInDimensions()?uf:(this.strokeUniform?new P().scalarAdd(this.canvas?this.canvas.getZoom():1):new P(e.scaleX,e.scaleY)).scalarMultiply(this.strokeWidth);i=n.add(r).scalarAdd(this.borderScaleFactor).scalarAdd(2*this.padding)}else i=this._calculateCurrentDimensions().scalarAdd(this.borderScaleFactor);this._drawBorders(t,i,s)}drawControlsConnectingLines(t,e){let s=!1;t.beginPath(),this.forEachControl((i,n)=>{i.withConnection&&i.getVisibility(this,n)&&(s=!0,t.moveTo(i.x*e.x,i.y*e.y),t.lineTo(i.x*e.x+i.offsetX,i.y*e.y+i.offsetY))}),s&&t.stroke()}drawControls(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};t.save();const s=this.getCanvasRetinaScaling(),{cornerStrokeColor:i,cornerDashArray:n,cornerColor:r}=this,o=E({cornerStrokeColor:i,cornerDashArray:n,cornerColor:r},e);t.setTransform(s,0,0,s,0,0),t.strokeStyle=t.fillStyle=o.cornerColor,this.transparentCorners||(t.strokeStyle=o.cornerStrokeColor),this._setLineDash(t,o.cornerDashArray),this.forEachControl((h,c)=>{if(h.getVisibility(this,c)){const u=this.oCoords[c];h.render(t,u.x,u.y,o,this)}}),t.restore()}isControlVisible(t){return this.controls[t]&&this.controls[t].getVisibility(this,t)}setControlVisible(t,e){this._controlsVisibility||(this._controlsVisibility={}),this._controlsVisibility[t]=e}setControlsVisibility(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Object.entries(t).forEach(e=>{let[s,i]=e;return this.setControlVisible(s,i)})}clearContextTop(t){if(!this.canvas)return;const e=this.canvas.contextTop;if(!e)return;const s=this.canvas.viewportTransform;e.save(),e.transform(s[0],s[1],s[2],s[3],s[4],s[5]),this.transform(e);const i=this.width+4,n=this.height+4;return e.clearRect(-i/2,-n/2,i,n),t||e.restore(),e}onDeselect(t){return!1}onSelect(t){return!1}shouldStartDragging(t){return!1}onDragStart(t){return!1}canDrop(t){return!1}renderDragSourceEffect(t){}renderDropTargetEffect(t){}}function zm(a,t){return t.forEach(e=>{Object.getOwnPropertyNames(e.prototype).forEach(s=>{s!=="constructor"&&Object.defineProperty(a.prototype,s,Object.getOwnPropertyDescriptor(e.prototype,s)||Object.create(null))})}),a}A(Rh,"ownDefaults",{noScaleCache:!0,lockMovementX:!1,lockMovementY:!1,lockRotation:!1,lockScalingX:!1,lockScalingY:!1,lockSkewingX:!1,lockSkewingY:!1,lockScalingFlip:!1,cornerSize:13,touchCornerSize:24,transparentCorners:!0,cornerColor:"rgb(178,204,255)",cornerStrokeColor:"",cornerStyle:"rect",cornerDashArray:null,hasControls:!0,borderColor:"rgb(178,204,255)",borderDashArray:null,borderOpacityWhenMoving:.4,borderScaleFactor:1,hasBorders:!0,selectionBackgroundColor:"",selectable:!0,evented:!0,perPixelTargetFind:!1,activeOn:"down",hoverCursor:null,moveCursor:null});class pe extends Rh{}zm(pe,[xm]),N.setClass(pe),N.setClass(pe,"object");const Vm=(a,t,e,s)=>{const i=2*(s=Math.round(s))+1,{data:n}=a.getImageData(t-s,e-s,i,i);for(let r=3;r<n.length;r+=4)if(n[r]>0)return!1;return!0};class Xm{constructor(t){this.options=t,this.strokeProjectionMagnitude=this.options.strokeWidth/2,this.scale=new P(this.options.scaleX,this.options.scaleY),this.strokeUniformScalar=this.options.strokeUniform?new P(1/this.options.scaleX,1/this.options.scaleY):new P(1,1)}createSideVector(t,e){const s=Zc(t,e);return this.options.strokeUniform?s.multiply(this.scale):s}projectOrthogonally(t,e,s){return this.applySkew(t.add(this.calcOrthogonalProjection(t,e,s)))}isSkewed(){return this.options.skewX!==0||this.options.skewY!==0}applySkew(t){const e=new P(t);return e.y+=e.x*Math.tan(Rt(this.options.skewY)),e.x+=e.y*Math.tan(Rt(this.options.skewX)),e}scaleUnitVector(t,e){return t.multiply(this.strokeUniformScalar).scalarMultiply(e)}}const c_=new P;class ea extends Xm{static getOrthogonalRotationFactor(t,e){const s=e?eu(t,e):Em(t);return Math.abs(s)<An?-1:1}constructor(t,e,s,i){super(i),A(this,"AB",void 0),A(this,"AC",void 0),A(this,"alpha",void 0),A(this,"bisector",void 0),this.A=new P(t),this.B=new P(e),this.C=new P(s),this.AB=this.createSideVector(this.A,this.B),this.AC=this.createSideVector(this.A,this.C),this.alpha=eu(this.AB,this.AC),this.bisector=su(Ef(this.AB.eq(c_)?this.AC:this.AB,this.alpha/2))}calcOrthogonalProjection(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.strokeProjectionMagnitude;const i=this.createSideVector(t,e),n=kf(i),r=ea.getOrthogonalRotationFactor(n,this.bisector);return this.scaleUnitVector(n,s*r)}projectBevel(){const t=[];return(this.alpha%Ri==0?[this.B]:[this.B,this.C]).forEach(e=>{t.push(this.projectOrthogonally(this.A,e)),t.push(this.projectOrthogonally(this.A,e,-this.strokeProjectionMagnitude))}),t}projectMiter(){const t=[],e=Math.abs(this.alpha),s=1/Math.sin(e/2),i=this.scaleUnitVector(this.bisector,-this.strokeProjectionMagnitude*s),n=this.options.strokeUniform?tu(this.scaleUnitVector(this.bisector,this.options.strokeMiterLimit)):this.options.strokeMiterLimit;return tu(i)/this.strokeProjectionMagnitude<=n&&t.push(this.applySkew(this.A.add(i))),t.push(...this.projectBevel()),t}projectRoundNoSkew(t,e){const s=[],i=new P(ea.getOrthogonalRotationFactor(this.bisector),ea.getOrthogonalRotationFactor(new P(this.bisector.y,this.bisector.x)));return[new P(1,0).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(i),new P(0,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(i)].forEach(n=>{Mf(n,t,e)&&s.push(this.A.add(n))}),s}projectRoundWithSkew(t,e){const s=[],{skewX:i,skewY:n,scaleX:r,scaleY:o,strokeUniform:h}=this.options,c=new P(Math.tan(Rt(i)),Math.tan(Rt(n))),u=this.strokeProjectionMagnitude,d=h?u/o/Math.sqrt(1/o**2+1/r**2*c.y**2):u/Math.sqrt(1+c.y**2),f=new P(Math.sqrt(Math.max(u**2-d**2,0)),d),g=h?u/Math.sqrt(1+c.x**2*(1/o)**2/(1/r+1/r*c.x*c.y)**2):u/Math.sqrt(1+c.x**2/(1+c.x*c.y)**2),p=new P(g,Math.sqrt(Math.max(u**2-g**2,0)));return[p,p.scalarMultiply(-1),f,f.scalarMultiply(-1)].map(b=>this.applySkew(h?b.multiply(this.strokeUniformScalar):b)).forEach(b=>{Mf(b,t,e)&&s.push(this.applySkew(this.A).add(b))}),s}projectRound(){const t=[];t.push(...this.projectBevel());const e=this.alpha%Ri==0,s=this.applySkew(this.A),i=t[e?0:2].subtract(s),n=t[e?1:0].subtract(s),r=e?this.applySkew(this.AB.scalarMultiply(-1)):this.applySkew(this.bisector.multiply(this.strokeUniformScalar).scalarMultiply(-1)),o=Qo(i,r)>0,h=o?i:n,c=o?n:i;return this.isSkewed()?t.push(...this.projectRoundWithSkew(h,c)):t.push(...this.projectRoundNoSkew(h,c)),t}projectPoints(){switch(this.options.strokeLineJoin){case"miter":return this.projectMiter();case"round":return this.projectRound();default:return this.projectBevel()}}project(){return this.projectPoints().map(t=>({originPoint:this.A,projectedPoint:t,angle:this.alpha,bisector:this.bisector}))}}class Wm extends Xm{constructor(t,e,s){super(s),this.A=new P(t),this.T=new P(e)}calcOrthogonalProjection(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.strokeProjectionMagnitude;const i=this.createSideVector(t,e);return this.scaleUnitVector(kf(i),s)}projectButt(){return[this.projectOrthogonally(this.A,this.T,this.strokeProjectionMagnitude),this.projectOrthogonally(this.A,this.T,-this.strokeProjectionMagnitude)]}projectRound(){const t=[];if(!this.isSkewed()&&this.A.eq(this.T)){const e=new P(1,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar);t.push(this.applySkew(this.A.add(e)),this.applySkew(this.A.subtract(e)))}else t.push(...new ea(this.A,this.T,this.T,this.options).projectRound());return t}projectSquare(){const t=[];if(this.A.eq(this.T)){const e=new P(1,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar);t.push(this.A.add(e),this.A.subtract(e))}else{const e=this.calcOrthogonalProjection(this.A,this.T,this.strokeProjectionMagnitude),s=this.scaleUnitVector(su(this.createSideVector(this.A,this.T)),-this.strokeProjectionMagnitude),i=this.A.add(s);t.push(i.add(e),i.subtract(e))}return t.map(e=>this.applySkew(e))}projectPoints(){switch(this.options.strokeLineCap){case"round":return this.projectRound();case"square":return this.projectSquare();default:return this.projectButt()}}project(){return this.projectPoints().map(t=>({originPoint:this.A,projectedPoint:t}))}}const Um=function(a,t){let e=arguments.length>2&&arguments[2]!==void 0&&arguments[2];const s=[];if(a.length===0)return s;const i=a.reduce((n,r)=>(n[n.length-1].eq(r)||n.push(new P(r)),n),[new P(a[0])]);if(i.length===1)e=!0;else if(!e){const n=i[0],r=((o,h)=>{for(let c=o.length-1;c>=0;c--)if(h(o[c],c,o))return c;return-1})(i,o=>!o.eq(n));i.splice(r+1)}return i.forEach((n,r,o)=>{let h,c;r===0?(c=o[1],h=e?n:o[o.length-1]):r===o.length-1?(h=o[r-1],c=e?n:o[0]):(h=o[r-1],c=o[r+1]),e&&o.length===1?s.push(...new Wm(n,n,t).project()):!e||r!==0&&r!==o.length-1?s.push(...new ea(n,h,c,t).project()):s.push(...new Wm(n,r===0?c:h,t).project())}),s},Nf=a=>{const t={};return Object.keys(a).forEach(e=>{t[e]={},Object.keys(a[e]).forEach(s=>{t[e][s]=E({},a[e][s])})}),t},Ym=a=>a.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/'/g,"&apos;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),ou=a=>{const t=[];for(let e,s=0;s<a.length;s++)(e=u_(a,s))!==!1&&t.push(e);return t},u_=(a,t)=>{const e=a.charCodeAt(t);if(isNaN(e))return"";if(e<55296||e>57343)return a.charAt(t);if(55296<=e&&e<=56319){if(a.length<=t+1)throw"High surrogate without following low surrogate";const i=a.charCodeAt(t+1);if(56320>i||i>57343)throw"High surrogate without following low surrogate";return a.charAt(t)+a.charAt(t+1)}if(t===0)throw"Low surrogate without preceding high surrogate";const s=a.charCodeAt(t-1);if(55296>s||s>56319)throw"Low surrogate without preceding high surrogate";return!1};var d_=Object.freeze({__proto__:null,capitalize:function(a){let t=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return"".concat(a.charAt(0).toUpperCase()).concat(t?a.slice(1):a.slice(1).toLowerCase())},escapeXml:Ym,graphemeSplit:ou});const au=function(a,t){let e=arguments.length>2&&arguments[2]!==void 0&&arguments[2];return a.fill!==t.fill||a.stroke!==t.stroke||a.strokeWidth!==t.strokeWidth||a.fontSize!==t.fontSize||a.fontFamily!==t.fontFamily||a.fontWeight!==t.fontWeight||a.fontStyle!==t.fontStyle||a.textBackgroundColor!==t.textBackgroundColor||a.deltaY!==t.deltaY||e&&(a.overline!==t.overline||a.underline!==t.underline||a.linethrough!==t.linethrough)},$m=(a,t)=>{const e=t.split(`
37
+ `)}toObject(){const t={color:this.color,blur:this.blur,offsetX:this.offsetX,offsetY:this.offsetY,affectStroke:this.affectStroke,nonScaling:this.nonScaling,type:this.constructor.type},e=Li.ownDefaults;return this.includeDefaultValues?t:mf(t,(s,i)=>s!==e[i])}static async fromObject(t){return new this(t)}}T(Li,"ownDefaults",{color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1}),T(Li,"type","shadow"),N.setClass(Li,"shadow");const wr=(a,t,e)=>Math.max(a,Math.min(t,e)),Iv=[Ve,dt,Me,Je,"flipX","flipY","originX","originY","angle","opacity","globalCompositeOperation","shadow","visible",Xo,Wo],Fi=[zt,Pe,"strokeWidth","strokeDashArray","width","height","paintFirst","strokeUniform","strokeLineCap","strokeDashOffset","strokeLineJoin","strokeMiterLimit","backgroundColor","clipPath"],Nv={top:0,left:0,width:0,height:0,angle:0,flipX:!1,flipY:!1,scaleX:1,scaleY:1,minScaleLimit:0,skewX:0,skewY:0,originX:dt,originY:Ve,strokeWidth:1,strokeUniform:!1,padding:0,opacity:1,paintFirst:zt,fill:"rgb(0,0,0)",fillRule:"nonzero",stroke:null,strokeDashArray:null,strokeDashOffset:0,strokeLineCap:"butt",strokeLineJoin:"miter",strokeMiterLimit:4,globalCompositeOperation:"source-over",backgroundColor:"",shadow:null,visible:!0,includeDefaultValues:!0,excludeFromExport:!1,objectCaching:!0,clipPath:void 0,inverted:!1,absolutePositioned:!1,centeredRotation:!0,centeredScaling:!1,dirty:!0},Pf=(a,t,e,s)=>(a<Math.abs(t)?(a=t,s=e/4):s=t===0&&a===0?e/Ri*Math.asin(1):e/Ri*Math.asin(t/a),{a,c:t,p:e,s}),Dm=(a,t,e,s,i)=>a*Math.pow(2,10*(s-=1))*Math.sin((s*i-t)*Ri/e),Om=(a,t,e,s)=>-e*Math.cos(a/s*An)+e+t,Df=(a,t,e,s)=>(a/=s)<1/2.75?e*(7.5625*a*a)+t:a<2/2.75?e*(7.5625*(a-=1.5/2.75)*a+.75)+t:a<2.5/2.75?e*(7.5625*(a-=2.25/2.75)*a+.9375)+t:e*(7.5625*(a-=2.625/2.75)*a+.984375)+t,Rm=(a,t,e,s)=>e-Df(s-a,0,e,s)+t;var jv=Object.freeze({__proto__:null,defaultEasing:Om,easeInBack:function(a,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:1.70158;return e*(a/=s)*a*((i+1)*a-i)+t},easeInBounce:Rm,easeInCirc:(a,t,e,s)=>-e*(Math.sqrt(1-(a/=s)*a)-1)+t,easeInCubic:(a,t,e,s)=>e*(a/s)**3+t,easeInElastic:(a,t,e,s)=>{const i=e;let n=0;if(a===0)return t;if((a/=s)===1)return t+e;n||(n=.3*s);const{a:r,s:o,p:h}=Pf(i,e,n,1.70158);return-Dm(r,o,h,a,s)+t},easeInExpo:(a,t,e,s)=>a===0?t:e*2**(10*(a/s-1))+t,easeInOutBack:function(a,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:1.70158;return(a/=s/2)<1?e/2*(a*a*((1+(i*=1.525))*a-i))+t:e/2*((a-=2)*a*((1+(i*=1.525))*a+i)+2)+t},easeInOutBounce:(a,t,e,s)=>a<s/2?.5*Rm(2*a,0,e,s)+t:.5*Df(2*a-s,0,e,s)+.5*e+t,easeInOutCirc:(a,t,e,s)=>(a/=s/2)<1?-e/2*(Math.sqrt(1-a**2)-1)+t:e/2*(Math.sqrt(1-(a-=2)*a)+1)+t,easeInOutCubic:(a,t,e,s)=>(a/=s/2)<1?e/2*a**3+t:e/2*((a-2)**3+2)+t,easeInOutElastic:(a,t,e,s)=>{const i=e;let n=0;if(a===0)return t;if((a/=s/2)===2)return t+e;n||(n=s*(.3*1.5));const{a:r,s:o,p:h,c}=Pf(i,e,n,1.70158);return a<1?-.5*Dm(r,o,h,a,s)+t:r*Math.pow(2,-10*(a-=1))*Math.sin((a*s-o)*Ri/h)*.5+c+t},easeInOutExpo:(a,t,e,s)=>a===0?t:a===s?t+e:(a/=s/2)<1?e/2*2**(10*(a-1))+t:e/2*-(2**(-10*--a)+2)+t,easeInOutQuad:(a,t,e,s)=>(a/=s/2)<1?e/2*a**2+t:-e/2*(--a*(a-2)-1)+t,easeInOutQuart:(a,t,e,s)=>(a/=s/2)<1?e/2*a**4+t:-e/2*((a-=2)*a**3-2)+t,easeInOutQuint:(a,t,e,s)=>(a/=s/2)<1?e/2*a**5+t:e/2*((a-2)**5+2)+t,easeInOutSine:(a,t,e,s)=>-e/2*(Math.cos(Math.PI*a/s)-1)+t,easeInQuad:(a,t,e,s)=>e*(a/=s)*a+t,easeInQuart:(a,t,e,s)=>e*(a/=s)*a**3+t,easeInQuint:(a,t,e,s)=>e*(a/s)**5+t,easeInSine:(a,t,e,s)=>-e*Math.cos(a/s*An)+e+t,easeOutBack:function(a,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:1.70158;return e*((a=a/s-1)*a*((i+1)*a+i)+1)+t},easeOutBounce:Df,easeOutCirc:(a,t,e,s)=>e*Math.sqrt(1-(a=a/s-1)*a)+t,easeOutCubic:(a,t,e,s)=>e*((a/s-1)**3+1)+t,easeOutElastic:(a,t,e,s)=>{const i=e;let n=0;if(a===0)return t;if((a/=s)===1)return t+e;n||(n=.3*s);const{a:r,s:o,p:h,c}=Pf(i,e,n,1.70158);return r*2**(-10*a)*Math.sin((a*s-o)*Ri/h)+c+t},easeOutExpo:(a,t,e,s)=>a===s?t+e:e*-(2**(-10*a/s)+1)+t,easeOutQuad:(a,t,e,s)=>-e*(a/=s)*(a-2)+t,easeOutQuart:(a,t,e,s)=>-e*((a=a/s-1)*a**3-1)+t,easeOutQuint:(a,t,e,s)=>e*((a/s-1)**5+1)+t,easeOutSine:(a,t,e,s)=>e*Math.sin(a/s*An)+t});const Bv=()=>!1;class Of{constructor(t){let{startValue:e,byValue:s,duration:i=500,delay:n=0,easing:r=Om,onStart:o=pr,onChange:h=pr,onComplete:c=pr,abort:u=Bv,target:d}=t;T(this,"_state","pending"),T(this,"durationProgress",0),T(this,"valueProgress",0),this.tick=this.tick.bind(this),this.duration=i,this.delay=n,this.easing=r,this._onStart=o,this._onChange=h,this._onComplete=c,this._abort=u,this.target=d,this.startValue=e,this.byValue=s,this.value=this.startValue,this.endValue=Object.freeze(this.calculate(this.duration).value)}get state(){return this._state}isDone(){return this._state==="aborted"||this._state==="completed"}start(){const t=e=>{this._state==="pending"&&(this.startTime=e||+new Date,this._state="running",this._onStart(),this.tick(this.startTime))};this.register(),this.delay>0?setTimeout(()=>Ch(t),this.delay):Ch(t)}tick(t){const e=(t||+new Date)-this.startTime,s=Math.min(e,this.duration);this.durationProgress=s/this.duration;const{value:i,valueProgress:n}=this.calculate(s);this.value=Object.freeze(i),this.valueProgress=n,this._state!=="aborted"&&(this._abort(this.value,this.valueProgress,this.durationProgress)?(this._state="aborted",this.unregister()):e>=this.duration?(this.durationProgress=this.valueProgress=1,this._onChange(this.endValue,this.valueProgress,this.durationProgress),this._state="completed",this._onComplete(this.endValue,this.valueProgress,this.durationProgress),this.unregister()):(this._onChange(this.value,this.valueProgress,this.durationProgress),Ch(this.tick)))}register(){Xc.push(this)}unregister(){Xc.remove(this)}abort(){this._state="aborted",this.unregister()}}const Hv=["startValue","endValue"];class Gv extends Of{constructor(t){let{startValue:e=0,endValue:s=100}=t;super(E(E({},Ct(t,Hv)),{},{startValue:e,byValue:s-e}))}calculate(t){const e=this.easing(t,this.startValue,this.byValue,this.duration);return{value:e,valueProgress:Math.abs((e-this.startValue)/this.byValue)}}}const zv=["startValue","endValue"];class Vv extends Of{constructor(t){let{startValue:e=[0],endValue:s=[100]}=t;super(E(E({},Ct(t,zv)),{},{startValue:e,byValue:s.map((i,n)=>i-e[n])}))}calculate(t){const e=this.startValue.map((s,i)=>this.easing(t,s,this.byValue[i],this.duration,i));return{value:e,valueProgress:Math.abs((e[0]-this.startValue[0])/this.byValue[0])}}}const Xv=["startValue","endValue","easing","onChange","onComplete","abort"],Wv=(a,t,e,s)=>t+e*(1-Math.cos(a/s*An)),Rf=a=>a&&((t,e,s)=>a(new gt(t).toRgba(),e,s));class Uv extends Of{constructor(t){let{startValue:e,endValue:s,easing:i=Wv,onChange:n,onComplete:r,abort:o}=t,h=Ct(t,Xv);const c=new gt(e).getSource(),u=new gt(s).getSource();super(E(E({},h),{},{startValue:c,byValue:u.map((d,f)=>d-c[f]),easing:i,onChange:Rf(n),onComplete:Rf(r),abort:Rf(o)}))}calculate(t){const[e,s,i,n]=this.startValue.map((o,h)=>this.easing(t,o,this.byValue[h],this.duration,h)),r=[...[e,s,i].map(Math.round),wr(0,n,1)];return{value:r,valueProgress:r.map((o,h)=>this.byValue[h]!==0?Math.abs((o-this.startValue[h])/this.byValue[h]):0).find(o=>o!==0)||0}}}function Lf(a){const t=(e=>Array.isArray(e.startValue)||Array.isArray(e.endValue))(a)?new Vv(a):new Gv(a);return t.start(),t}function Lm(a){const t=new Uv(a);return t.start(),t}class Mt{constructor(t){this.status=t,this.points=[]}includes(t){return this.points.some(e=>e.eq(t))}append(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];return this.points=this.points.concat(e.filter(i=>!this.includes(i))),this}static isPointContained(t,e,s){let i=arguments.length>3&&arguments[3]!==void 0&&arguments[3];if(e.eq(s))return t.eq(e);if(e.x===s.x)return t.x===e.x&&(i||t.y>=Math.min(e.y,s.y)&&t.y<=Math.max(e.y,s.y));if(e.y===s.y)return t.y===e.y&&(i||t.x>=Math.min(e.x,s.x)&&t.x<=Math.max(e.x,s.x));{const n=Zc(e,s),r=Zc(e,t).divide(n);return i?Math.abs(r.x)===Math.abs(r.y):r.x===r.y&&r.x>=0&&r.x<=1}}static isPointInPolygon(t,e){const s=new P(t).setX(Math.min(t.x-1,...e.map(n=>n.x)));let i=0;for(let n=0;n<e.length;n++){const r=this.intersectSegmentSegment(e[n],e[(n+1)%e.length],t,s);if(r.includes(t))return!0;i+=+(r.status==="Intersection")}return i%2==1}static intersectLineLine(t,e,s,i){let n=!(arguments.length>4&&arguments[4]!==void 0)||arguments[4],r=!(arguments.length>5&&arguments[5]!==void 0)||arguments[5];const o=e.x-t.x,h=e.y-t.y,c=i.x-s.x,u=i.y-s.y,d=t.x-s.x,f=t.y-s.y,g=c*f-u*d,p=o*f-h*d,b=u*o-c*h;if(b!==0){const v=g/b,_=p/b;return(n||0<=v&&v<=1)&&(r||0<=_&&_<=1)?new Mt("Intersection").append(new P(t.x+v*o,t.y+v*h)):new Mt}if(g===0||p===0){const v=n||r||Mt.isPointContained(t,s,i)||Mt.isPointContained(e,s,i)||Mt.isPointContained(s,t,e)||Mt.isPointContained(i,t,e);return new Mt(v?"Coincident":void 0)}return new Mt("Parallel")}static intersectSegmentLine(t,e,s,i){return Mt.intersectLineLine(t,e,s,i,!1,!0)}static intersectSegmentSegment(t,e,s,i){return Mt.intersectLineLine(t,e,s,i,!1,!1)}static intersectLinePolygon(t,e,s){let i=!(arguments.length>3&&arguments[3]!==void 0)||arguments[3];const n=new Mt,r=s.length;for(let o,h,c,u=0;u<r;u++){if(o=s[u],h=s[(u+1)%r],c=Mt.intersectLineLine(t,e,o,h,i,!1),c.status==="Coincident")return c;n.append(...c.points)}return n.points.length>0&&(n.status="Intersection"),n}static intersectSegmentPolygon(t,e,s){return Mt.intersectLinePolygon(t,e,s,!1)}static intersectPolygonPolygon(t,e){const s=new Mt,i=t.length,n=[];for(let r=0;r<i;r++){const o=t[r],h=t[(r+1)%i],c=Mt.intersectSegmentPolygon(o,h,e);c.status==="Coincident"?(n.push(c),s.append(o,h)):s.append(...c.points)}return n.length>0&&n.length===t.length?new Mt("Coincident"):(s.points.length>0&&(s.status="Intersection"),s)}static intersectPolygonRectangle(t,e,s){const i=e.min(s),n=e.max(s),r=new P(n.x,i.y),o=new P(i.x,n.y);return Mt.intersectPolygonPolygon(t,[i,r,n,o])}}class Yv extends qp{getX(){return this.getXY().x}setX(t){this.setXY(this.getXY().setX(t))}getY(){return this.getXY().y}setY(t){this.setXY(this.getXY().setY(t))}getRelativeX(){return this.left}setRelativeX(t){this.left=t}getRelativeY(){return this.top}setRelativeY(t){this.top=t}getXY(){const t=this.getRelativeXY();return this.group?ge(t,this.group.calcTransformMatrix()):t}setXY(t,e,s){this.group&&(t=ge(t,Xe(this.group.calcTransformMatrix()))),this.setRelativeXY(t,e,s)}getRelativeXY(){return new P(this.left,this.top)}setRelativeXY(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.originX,s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.originY;this.setPositionByOrigin(t,e,s)}isStrokeAccountedForInDimensions(){return!1}getCoords(){const{tl:t,tr:e,br:s,bl:i}=this.aCoords||(this.aCoords=this.calcACoords()),n=[t,e,s,i];if(this.group){const r=this.group.calcTransformMatrix();return n.map(o=>ge(o,r))}return n}intersectsWithRect(t,e){return Mt.intersectPolygonRectangle(this.getCoords(),t,e).status==="Intersection"}intersectsWithObject(t){const e=Mt.intersectPolygonPolygon(this.getCoords(),t.getCoords());return e.status==="Intersection"||e.status==="Coincident"||t.isContainedWithinObject(this)||this.isContainedWithinObject(t)}isContainedWithinObject(t){return this.getCoords().every(e=>t.containsPoint(e))}isContainedWithinRect(t,e){const{left:s,top:i,width:n,height:r}=this.getBoundingRect();return s>=t.x&&s+n<=e.x&&i>=t.y&&i+r<=e.y}isOverlapping(t){return this.intersectsWithObject(t)||this.isContainedWithinObject(t)||t.isContainedWithinObject(this)}containsPoint(t){return Mt.isPointInPolygon(t,this.getCoords())}isOnScreen(){if(!this.canvas)return!1;const{tl:t,br:e}=this.canvas.vptCoords;return!!this.getCoords().some(s=>s.x<=e.x&&s.x>=t.x&&s.y<=e.y&&s.y>=t.y)||!!this.intersectsWithRect(t,e)||this.containsPoint(t.midPointFrom(e))}isPartiallyOnScreen(){if(!this.canvas)return!1;const{tl:t,br:e}=this.canvas.vptCoords;return this.intersectsWithRect(t,e)?!0:this.getCoords().every(s=>(s.x>=e.x||s.x<=t.x)&&(s.y>=e.y||s.y<=t.y))&&this.containsPoint(t.midPointFrom(e))}getBoundingRect(){return ri(this.getCoords())}getScaledWidth(){return this._getTransformedDimensions().x}getScaledHeight(){return this._getTransformedDimensions().y}scale(t){this._set(Me,t),this._set(Je,t),this.setCoords()}scaleToWidth(t){const e=this.getBoundingRect().width/this.getScaledWidth();return this.scale(t/this.width/e)}scaleToHeight(t){const e=this.getBoundingRect().height/this.getScaledHeight();return this.scale(t/this.height/e)}getCanvasRetinaScaling(){var t;return((t=this.canvas)===null||t===void 0?void 0:t.getRetinaScaling())||1}getTotalAngle(){return this.group?kn(Zp(this.calcTransformMatrix())):this.angle}getViewportTransform(){var t;return((t=this.canvas)===null||t===void 0?void 0:t.viewportTransform)||Ee.concat()}calcACoords(){const t=$o({angle:this.angle}),{x:e,y:s}=this.getRelativeCenterPoint(),i=Yo(e,s),n=Nt(i,t),r=this._getTransformedDimensions(),o=r.x/2,h=r.y/2;return{tl:ge({x:-o,y:-h},n),tr:ge({x:o,y:-h},n),bl:ge({x:-o,y:h},n),br:ge({x:o,y:h},n)}}setCoords(){this.aCoords=this.calcACoords()}transformMatrixKey(){let t=arguments.length>0&&arguments[0]!==void 0&&arguments[0],e=[];return!t&&this.group&&(e=this.group.transformMatrixKey(t)),e.push(this.top,this.left,this.width,this.height,this.scaleX,this.scaleY,this.angle,this.strokeWidth,this.skewX,this.skewY,+this.flipX,+this.flipY,Vt(this.originX),Vt(this.originY)),e}calcTransformMatrix(){let t=arguments.length>0&&arguments[0]!==void 0&&arguments[0],e=this.calcOwnMatrix();if(t||!this.group)return e;const s=this.transformMatrixKey(t),i=this.matrixCache;return i&&i.key.every((n,r)=>n===s[r])?i.value:(this.group&&(e=Nt(this.group.calcTransformMatrix(!1),e)),this.matrixCache={key:s,value:e},e)}calcOwnMatrix(){const t=this.transformMatrixKey(!0),e=this.ownMatrixCache;if(e&&e.key===t)return e.value;const s=this.getRelativeCenterPoint(),i={angle:this.angle,translateX:s.x,translateY:s.y,scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,flipX:this.flipX,flipY:this.flipY},n=em(i);return this.ownMatrixCache={key:t,value:n},n}_getNonTransformedDimensions(){return new P(this.width,this.height).scalarAdd(this.strokeWidth)}_calculateCurrentDimensions(t){return this._getTransformedDimensions(t).transform(this.getViewportTransform(),!0).scalarAdd(2*this.padding)}_getTransformedDimensions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=E({scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,width:this.width,height:this.height,strokeWidth:this.strokeWidth},t),s=e.strokeWidth;let i=s,n=0;this.strokeUniform&&(i=0,n=s);const r=e.width+i,o=e.height+i;let h;return h=e.skewX===0&&e.skewY===0?new P(r*e.scaleX,o*e.scaleY):Kc(r,o,Ah(e)),h.scalarAdd(n)}translateToGivenOrigin(t,e,s,i,n){let r=t.x,o=t.y;const h=Vt(i)-Vt(e),c=Vt(n)-Vt(s);if(h||c){const u=this._getTransformedDimensions();r+=h*u.x,o+=c*u.y}return new P(r,o)}translateToCenterPoint(t,e,s){if(e===Q&&s===Q)return t;const i=this.translateToGivenOrigin(t,e,s,Q,Q);return this.angle?i.rotate(Rt(this.angle),t):i}translateToOriginPoint(t,e,s){const i=this.translateToGivenOrigin(t,Q,Q,e,s);return this.angle?i.rotate(Rt(this.angle),t):i}getCenterPoint(){const t=this.getRelativeCenterPoint();return this.group?ge(t,this.group.calcTransformMatrix()):t}getRelativeCenterPoint(){return this.translateToCenterPoint(new P(this.left,this.top),this.originX,this.originY)}getPointByOrigin(t,e){return this.translateToOriginPoint(this.getRelativeCenterPoint(),t,e)}setPositionByOrigin(t,e,s){const i=this.translateToCenterPoint(t,e,s),n=this.translateToOriginPoint(i,this.originX,this.originY);this.set({left:n.x,top:n.y})}_getLeftTopCoords(){return this.translateToOriginPoint(this.getRelativeCenterPoint(),dt,Ve)}}const $v=["type"],qv=["extraParam"];let Ii=class Td extends Yv{static getDefaults(){return Td.ownDefaults}get type(){const t=this.constructor.type;return t==="FabricObject"?"object":t.toLowerCase()}set type(t){Oi("warn","Setting type has no effect",t)}constructor(t){super(),T(this,"_cacheContext",null),Object.assign(this,Td.ownDefaults),this.setOptions(t)}_createCacheCanvas(){this._cacheCanvas=ms(),this._cacheContext=this._cacheCanvas.getContext("2d"),this._updateCacheCanvas(),this.dirty=!0}_limitCacheSize(t){const e=t.width,s=t.height,i=ht.maxCacheSideLimit,n=ht.minCacheSideLimit;if(e<=i&&s<=i&&e*s<=ht.perfLimitSizeTotal)return e<n&&(t.width=n),s<n&&(t.height=n),t;const r=e/s,[o,h]=xh.limitDimsByArea(r),c=wr(n,o,i),u=wr(n,h,i);return e>c&&(t.zoomX/=e/c,t.width=c,t.capped=!0),s>u&&(t.zoomY/=s/u,t.height=u,t.capped=!0),t}_getCacheCanvasDimensions(){const t=this.getTotalObjectScaling(),e=this._getTransformedDimensions({skewX:0,skewY:0}),s=e.x*t.x/this.scaleX,i=e.y*t.y/this.scaleY;return{width:Math.ceil(s+2),height:Math.ceil(i+2),zoomX:t.x,zoomY:t.y,x:s,y:i}}_updateCacheCanvas(){const t=this._cacheCanvas,e=this._cacheContext,{width:s,height:i,zoomX:n,zoomY:r,x:o,y:h}=this._limitCacheSize(this._getCacheCanvasDimensions()),c=s!==t.width||i!==t.height,u=this.zoomX!==n||this.zoomY!==r;if(!t||!e)return!1;if(c||u){s!==t.width||i!==t.height?(t.width=s,t.height=i):(e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,t.width,t.height));const d=o/2,f=h/2;return this.cacheTranslationX=Math.round(t.width/2-d)+d,this.cacheTranslationY=Math.round(t.height/2-f)+f,e.translate(this.cacheTranslationX,this.cacheTranslationY),e.scale(n,r),this.zoomX=n,this.zoomY=r,!0}return!1}setOptions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this._setOptions(t)}transform(t){const e=this.group&&!this.group._transformDone||this.group&&this.canvas&&t===this.canvas.contextTop,s=this.calcTransformMatrix(!e);t.transform(s[0],s[1],s[2],s[3],s[4],s[5])}getObjectScaling(){if(!this.group)return new P(Math.abs(this.scaleX),Math.abs(this.scaleY));const t=br(this.calcTransformMatrix());return new P(Math.abs(t.scaleX),Math.abs(t.scaleY))}getTotalObjectScaling(){const t=this.getObjectScaling();if(this.canvas){const e=this.canvas.getZoom(),s=this.getCanvasRetinaScaling();return t.scalarMultiply(e*s)}return t}getObjectOpacity(){let t=this.opacity;return this.group&&(t*=this.group.getObjectOpacity()),t}_constrainScale(t){return Math.abs(t)<this.minScaleLimit?t<0?-this.minScaleLimit:this.minScaleLimit:t===0?1e-4:t}_set(t,e){t!==Me&&t!==Je||(e=this._constrainScale(e)),t===Me&&e<0?(this.flipX=!this.flipX,e*=-1):t==="scaleY"&&e<0?(this.flipY=!this.flipY,e*=-1):t!=="shadow"||!e||e instanceof Li||(e=new Li(e));const s=this[t]!==e;return this[t]=e,s&&this.constructor.cacheProperties.includes(t)&&(this.dirty=!0),this.parent&&(this.dirty||s&&this.constructor.stateProperties.includes(t))&&this.parent._set("dirty",!0),this}isNotVisible(){return this.opacity===0||!this.width&&!this.height&&this.strokeWidth===0||!this.visible}render(t){this.isNotVisible()||this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(t.save(),this._setupCompositeOperation(t),this.drawSelectionBackground(t),this.transform(t),this._setOpacity(t),this._setShadow(t),this.shouldCache()?(this.renderCache(),this.drawCacheOnCanvas(t)):(this._removeCacheCanvas(),this.drawObject(t,!1,{}),this.dirty=!1),t.restore())}drawSelectionBackground(t){}renderCache(t){if(t=t||{},this._cacheCanvas&&this._cacheContext||this._createCacheCanvas(),this.isCacheDirty()&&this._cacheContext){const{zoomX:e,zoomY:s,cacheTranslationX:i,cacheTranslationY:n}=this,{width:r,height:o}=this._cacheCanvas;this.drawObject(this._cacheContext,t.forClipping,{zoomX:e,zoomY:s,cacheTranslationX:i,cacheTranslationY:n,width:r,height:o,parentClipPaths:[]}),this.dirty=!1}}_removeCacheCanvas(){this._cacheCanvas=void 0,this._cacheContext=null}hasStroke(){return this.stroke&&this.stroke!=="transparent"&&this.strokeWidth!==0}hasFill(){return this.fill&&this.fill!=="transparent"}needsItsOwnCache(){return!!(this.paintFirst===Pe&&this.hasFill()&&this.hasStroke()&&this.shadow)||!!this.clipPath}shouldCache(){return this.ownCaching=this.objectCaching&&(!this.parent||!this.parent.isOnACache())||this.needsItsOwnCache(),this.ownCaching}willDrawShadow(){return!!this.shadow&&(this.shadow.offsetX!==0||this.shadow.offsetY!==0)}drawClipPathOnCache(t,e,s){t.save(),e.inverted?t.globalCompositeOperation="destination-out":t.globalCompositeOperation="destination-in",t.setTransform(1,0,0,1,0,0),t.drawImage(s,0,0),t.restore()}drawObject(t,e,s){const i=this.fill,n=this.stroke;e?(this.fill="black",this.stroke="",this._setClippingProperties(t)):this._renderBackground(t),this._render(t),this._drawClipPath(t,this.clipPath,s),this.fill=i,this.stroke=n}createClipPathLayer(t,e){const s=Rs(e),i=s.getContext("2d");if(i.translate(e.cacheTranslationX,e.cacheTranslationY),i.scale(e.zoomX,e.zoomY),t._cacheCanvas=s,e.parentClipPaths.forEach(n=>{n.transform(i)}),e.parentClipPaths.push(t),t.absolutePositioned){const n=Xe(this.calcTransformMatrix());i.transform(n[0],n[1],n[2],n[3],n[4],n[5])}return t.transform(i),t.drawObject(i,!0,e),s}_drawClipPath(t,e,s){if(!e)return;e._transformDone=!0;const i=this.createClipPathLayer(e,s);this.drawClipPathOnCache(t,e,i)}drawCacheOnCanvas(t){t.scale(1/this.zoomX,1/this.zoomY),t.drawImage(this._cacheCanvas,-this.cacheTranslationX,-this.cacheTranslationY)}isCacheDirty(){let t=arguments.length>0&&arguments[0]!==void 0&&arguments[0];if(this.isNotVisible())return!1;const e=this._cacheCanvas,s=this._cacheContext;return!(!e||!s||t||!this._updateCacheCanvas())||!!(this.dirty||this.clipPath&&this.clipPath.absolutePositioned)&&(e&&s&&!t&&(s.save(),s.setTransform(1,0,0,1,0,0),s.clearRect(0,0,e.width,e.height),s.restore()),!0)}_renderBackground(t){if(!this.backgroundColor)return;const e=this._getNonTransformedDimensions();t.fillStyle=this.backgroundColor,t.fillRect(-e.x/2,-e.y/2,e.x,e.y),this._removeShadow(t)}_setOpacity(t){this.group&&!this.group._transformDone?t.globalAlpha=this.getObjectOpacity():t.globalAlpha*=this.opacity}_setStrokeStyles(t,e){const s=e.stroke;s&&(t.lineWidth=e.strokeWidth,t.lineCap=e.strokeLineCap,t.lineDashOffset=e.strokeDashOffset,t.lineJoin=e.strokeLineJoin,t.miterLimit=e.strokeMiterLimit,bs(s)?s.gradientUnits==="percentage"||s.gradientTransform||s.patternTransform?this._applyPatternForTransformedGradient(t,s):(t.strokeStyle=s.toLive(t),this._applyPatternGradientTransform(t,s)):t.strokeStyle=e.stroke)}_setFillStyles(t,e){let{fill:s}=e;s&&(bs(s)?(t.fillStyle=s.toLive(t),this._applyPatternGradientTransform(t,s)):t.fillStyle=s)}_setClippingProperties(t){t.globalAlpha=1,t.strokeStyle="transparent",t.fillStyle="#000000"}_setLineDash(t,e){e&&e.length!==0&&t.setLineDash(e)}_setShadow(t){if(!this.shadow)return;const e=this.shadow,s=this.canvas,i=this.getCanvasRetinaScaling(),[n,,,r]=(s==null?void 0:s.viewportTransform)||Ee,o=n*i,h=r*i,c=e.nonScaling?new P(1,1):this.getObjectScaling();t.shadowColor=e.color,t.shadowBlur=e.blur*ht.browserShadowBlurConstant*(o+h)*(c.x+c.y)/4,t.shadowOffsetX=e.offsetX*o*c.x,t.shadowOffsetY=e.offsetY*h*c.y}_removeShadow(t){this.shadow&&(t.shadowColor="",t.shadowBlur=t.shadowOffsetX=t.shadowOffsetY=0)}_applyPatternGradientTransform(t,e){if(!bs(e))return{offsetX:0,offsetY:0};const s=e.gradientTransform||e.patternTransform,i=-this.width/2+e.offsetX||0,n=-this.height/2+e.offsetY||0;return e.gradientUnits==="percentage"?t.transform(this.width,0,0,this.height,i,n):t.transform(1,0,0,1,i,n),s&&t.transform(s[0],s[1],s[2],s[3],s[4],s[5]),{offsetX:i,offsetY:n}}_renderPaintInOrder(t){this.paintFirst===Pe?(this._renderStroke(t),this._renderFill(t)):(this._renderFill(t),this._renderStroke(t))}_render(t){}_renderFill(t){this.fill&&(t.save(),this._setFillStyles(t,this),this.fillRule==="evenodd"?t.fill("evenodd"):t.fill(),t.restore())}_renderStroke(t){if(this.stroke&&this.strokeWidth!==0){if(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this.strokeUniform){const e=this.getObjectScaling();t.scale(1/e.x,1/e.y)}this._setLineDash(t,this.strokeDashArray),this._setStrokeStyles(t,this),t.stroke(),t.restore()}}_applyPatternForTransformedGradient(t,e){var s;const i=this._limitCacheSize(this._getCacheCanvasDimensions()),n=this.getCanvasRetinaScaling(),r=i.x/this.scaleX/n,o=i.y/this.scaleY/n,h=Rs({width:Math.ceil(r),height:Math.ceil(o)}),c=h.getContext("2d");c&&(c.beginPath(),c.moveTo(0,0),c.lineTo(r,0),c.lineTo(r,o),c.lineTo(0,o),c.closePath(),c.translate(r/2,o/2),c.scale(i.zoomX/this.scaleX/n,i.zoomY/this.scaleY/n),this._applyPatternGradientTransform(c,e),c.fillStyle=e.toLive(t),c.fill(),t.translate(-this.width/2-this.strokeWidth/2,-this.height/2-this.strokeWidth/2),t.scale(n*this.scaleX/i.zoomX,n*this.scaleY/i.zoomY),t.strokeStyle=(s=c.createPattern(h,"no-repeat"))!==null&&s!==void 0?s:"")}_findCenterFromElement(){return new P(this.left+this.width/2,this.top+this.height/2)}clone(t){const e=this.toObject(t);return this.constructor.fromObject(e)}cloneAsImage(t){const e=this.toCanvasElement(t);return new(N.getClass("image"))(e)}toCanvasElement(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=wf(this),s=this.group,i=this.shadow,n=Math.abs,r=t.enableRetinaScaling?Xp():1,o=(t.multiplier||1)*r,h=t.canvasProvider||(x=>new Ph(x,{enableRetinaScaling:!1,renderOnAddRemove:!1,skipOffscreen:!1}));delete this.group,t.withoutTransform&&pm(this),t.withoutShadow&&(this.shadow=null),t.viewportTransform&&xf(this,this.getViewportTransform()),this.setCoords();const c=ms(),u=this.getBoundingRect(),d=this.shadow,f=new P;if(d){const x=d.blur,C=d.nonScaling?new P(1,1):this.getObjectScaling();f.x=2*Math.round(n(d.offsetX)+x)*n(C.x),f.y=2*Math.round(n(d.offsetY)+x)*n(C.y)}const g=u.width+f.x,p=u.height+f.y;c.width=Math.ceil(g),c.height=Math.ceil(p);const b=h(c);t.format==="jpeg"&&(b.backgroundColor="#fff"),this.setPositionByOrigin(new P(b.width/2,b.height/2),Q,Q);const v=this.canvas;b._objects=[this],this.set("canvas",b),this.setCoords();const _=b.toCanvasElement(o||1,t);return this.set("canvas",v),this.shadow=i,s&&(this.group=s),this.set(e),this.setCoords(),b._objects=[],b.destroy(),_}toDataURL(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return df(this.toCanvasElement(t),t.format||"png",t.quality||1)}toBlob(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return ff(this.toCanvasElement(t),t.format||"png",t.quality||1)}isType(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];return e.includes(this.constructor.type)||e.includes(this.type)}complexity(){return 1}toJSON(){return this.toObject()}rotate(t){const{centeredRotation:e,originX:s,originY:i}=this;if(e){const{x:n,y:r}=this.getRelativeCenterPoint();this.originX=Q,this.originY=Q,this.left=n,this.top=r}if(this.set("angle",t),e){const{x:n,y:r}=this.translateToOriginPoint(this.getRelativeCenterPoint(),s,i);this.left=n,this.top=r,this.originX=s,this.originY=i}}setOnGroup(){}_setupCompositeOperation(t){this.globalCompositeOperation&&(t.globalCompositeOperation=this.globalCompositeOperation)}dispose(){Xc.cancelByTarget(this),this.off(),this._set("canvas",void 0),this._cacheCanvas&&ni().dispose(this._cacheCanvas),this._cacheCanvas=void 0,this._cacheContext=null}animate(t,e){return Object.entries(t).reduce((s,i)=>{let[n,r]=i;return s[n]=this._animate(n,r,e),s},{})}_animate(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const i=t.split("."),n=this.constructor.colorProperties.includes(i[i.length-1]),{abort:r,startValue:o,onChange:h,onComplete:c}=s,u=E(E({},s),{},{target:this,startValue:o??i.reduce((d,f)=>d[f],this),endValue:e,abort:r==null?void 0:r.bind(this),onChange:(d,f,g)=>{i.reduce((p,b,v)=>(v===i.length-1&&(p[b]=d),p[b]),this),h&&h(d,f,g)},onComplete:(d,f,g)=>{this.setCoords(),c&&c(d,f,g)}});return n?Lm(u):Lf(u)}isDescendantOf(t){const{parent:e,group:s}=this;return e===t||s===t||!!e&&e.isDescendantOf(t)||!!s&&s!==e&&s.isDescendantOf(t)}getAncestors(){const t=[];let e=this;do e=e.parent,e&&t.push(e);while(e);return t}findCommonAncestors(t){if(this===t)return{fork:[],otherFork:[],common:[this,...this.getAncestors()]};const e=this.getAncestors(),s=t.getAncestors();if(e.length===0&&s.length>0&&this===s[s.length-1])return{fork:[],otherFork:[t,...s.slice(0,s.length-1)],common:[this]};for(let i,n=0;n<e.length;n++){if(i=e[n],i===t)return{fork:[this,...e.slice(0,n)],otherFork:[],common:e.slice(n)};for(let r=0;r<s.length;r++){if(this===s[r])return{fork:[],otherFork:[t,...s.slice(0,r)],common:[this,...e]};if(i===s[r])return{fork:[this,...e.slice(0,n)],otherFork:[t,...s.slice(0,r)],common:e.slice(n)}}}return{fork:[this,...e],otherFork:[t,...s],common:[]}}hasCommonAncestors(t){const e=this.findCommonAncestors(t);return e&&!!e.common.length}isInFrontOf(t){if(this===t)return;const e=this.findCommonAncestors(t);if(e.fork.includes(t))return!0;if(e.otherFork.includes(this))return!1;const s=e.common[0]||this.canvas;if(!s)return;const i=e.fork.pop(),n=e.otherFork.pop(),r=s._objects.indexOf(i),o=s._objects.indexOf(n);return r>-1&&r>o}toObject(){const t=(arguments.length>0&&arguments[0]!==void 0?arguments[0]:[]).concat(Td.customProperties,this.constructor.customProperties||[]);let e;const s=ht.NUM_FRACTION_DIGITS,{clipPath:i,fill:n,stroke:r,shadow:o,strokeDashArray:h,left:c,top:u,originX:d,originY:f,width:g,height:p,strokeWidth:b,strokeLineCap:v,strokeDashOffset:_,strokeLineJoin:x,strokeUniform:C,strokeMiterLimit:S,scaleX:k,scaleY:D,angle:A,flipX:M,flipY:O,opacity:R,visible:L,backgroundColor:V,fillRule:U,paintFirst:G,globalCompositeOperation:at,skewX:F,skewY:z}=this;i&&!i.excludeFromExport&&(e=i.toObject(t.concat("inverted","absolutePositioned")));const rt=te=>At(te,s),Gt=E(E({},yr(this,t)),{},{type:this.constructor.type,version:nf,originX:d,originY:f,left:rt(c),top:rt(u),width:rt(g),height:rt(p),fill:om(n)?n.toObject():n,stroke:om(r)?r.toObject():r,strokeWidth:rt(b),strokeDashArray:h&&h.concat(),strokeLineCap:v,strokeDashOffset:_,strokeLineJoin:x,strokeUniform:C,strokeMiterLimit:rt(S),scaleX:rt(k),scaleY:rt(D),angle:rt(A),flipX:M,flipY:O,opacity:rt(R),shadow:o&&o.toObject(),visible:L,backgroundColor:V,fillRule:U,paintFirst:G,globalCompositeOperation:at,skewX:rt(F),skewY:rt(z)},e?{clipPath:e}:null);return this.includeDefaultValues?Gt:this._removeDefaultValues(Gt)}toDatalessObject(t){return this.toObject(t)}_removeDefaultValues(t){const e=this.constructor.getDefaults(),s=Object.keys(e).length>0?e:Object.getPrototypeOf(this);return mf(t,(i,n)=>{if(n===dt||n===Ve||n==="type")return!0;const r=s[n];return i!==r&&!(Array.isArray(i)&&Array.isArray(r)&&i.length===0&&r.length===0)})}toString(){return"#<".concat(this.constructor.type,">")}static _fromObject(t){let e=Ct(t,$v),s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{extraParam:i}=s,n=Ct(s,qv);return Eh(e,n).then(r=>i?(delete r[i],new this(e[i],r)):new this(r))}static fromObject(t,e){return this._fromObject(t,e)}};T(Ii,"stateProperties",Iv),T(Ii,"cacheProperties",Fi),T(Ii,"ownDefaults",Nv),T(Ii,"type","FabricObject"),T(Ii,"colorProperties",[zt,Pe,"backgroundColor"]),T(Ii,"customProperties",[]),N.setClass(Ii),N.setClass(Ii,"object");const Jo=(a,t,e)=>(s,i,n,r)=>{const o=t(s,i,n,r);return o&&bm(a,E(E({},_m(s,i,n,r)),e)),o};function Zo(a){return(t,e,s,i)=>{const{target:n,originX:r,originY:o}=e,h=n.getRelativeCenterPoint(),c=n.translateToOriginPoint(h,r,o),u=a(t,e,s,i);return n.setPositionByOrigin(c,e.originX,e.originY),u}}const Fm=Jo(Sh,Zo((a,t,e,s)=>{const i=Sf(t,t.originX,t.originY,e,s);if(Vt(t.originX)===Vt(Q)||Vt(t.originX)===Vt(It)&&i.x<0||Vt(t.originX)===Vt(dt)&&i.x>0){const{target:n}=t,r=n.strokeWidth/(n.strokeUniform?n.scaleX:1),o=ym(t)?2:1,h=n.width,c=Math.abs(i.x*o/n.scaleX)-r;return n.set("width",Math.max(c,1)),h!==n.width}return!1}));function Kv(a,t,e,s,i){s=s||{};const n=this.sizeX||s.cornerSize||i.cornerSize,r=this.sizeY||s.cornerSize||i.cornerSize,o=s.transparentCorners!==void 0?s.transparentCorners:i.transparentCorners,h=o?Pe:zt,c=!o&&(s.cornerStrokeColor||i.cornerStrokeColor);let u,d=t,f=e;a.save(),a.fillStyle=s.cornerColor||i.cornerColor||"",a.strokeStyle=s.cornerStrokeColor||i.cornerStrokeColor||"",n>r?(u=n,a.scale(1,r/n),f=e*n/r):r>n?(u=r,a.scale(n/r,1),d=t*r/n):u=n,a.beginPath(),a.arc(d,f,u/2,0,Ri,!1),a[h](),c&&a.stroke(),a.restore()}function Qv(a,t,e,s,i){s=s||{};const n=this.sizeX||s.cornerSize||i.cornerSize,r=this.sizeY||s.cornerSize||i.cornerSize,o=s.transparentCorners!==void 0?s.transparentCorners:i.transparentCorners,h=o?Pe:zt,c=!o&&(s.cornerStrokeColor||i.cornerStrokeColor),u=n/2,d=r/2;a.save(),a.fillStyle=s.cornerColor||i.cornerColor||"",a.strokeStyle=s.cornerStrokeColor||i.cornerStrokeColor||"",a.translate(t,e);const f=i.getTotalAngle();a.rotate(Rt(f)),a["".concat(h,"Rect")](-u,-d,n,r),c&&a.strokeRect(-u,-d,n,r),a.restore()}class Ns{constructor(t){T(this,"visible",!0),T(this,"actionName",zc),T(this,"angle",0),T(this,"x",0),T(this,"y",0),T(this,"offsetX",0),T(this,"offsetY",0),T(this,"sizeX",0),T(this,"sizeY",0),T(this,"touchSizeX",0),T(this,"touchSizeY",0),T(this,"cursorStyle","crosshair"),T(this,"withConnection",!1),Object.assign(this,t)}shouldActivate(t,e,s,i){var n;let{tl:r,tr:o,br:h,bl:c}=i;return((n=e.canvas)===null||n===void 0?void 0:n.getActiveObject())===e&&e.isControlVisible(t)&&Mt.isPointInPolygon(s,[r,o,h,c])}getActionHandler(t,e,s){return this.actionHandler}getMouseDownHandler(t,e,s){return this.mouseDownHandler}getMouseUpHandler(t,e,s){return this.mouseUpHandler}cursorStyleHandler(t,e,s){return e.cursorStyle}getActionName(t,e,s){return e.actionName}getVisibility(t,e){var s,i;return(s=(i=t._controlsVisibility)===null||i===void 0?void 0:i[e])!==null&&s!==void 0?s:this.visible}setVisibility(t,e,s){this.visible=t}positionHandler(t,e,s,i){return new P(this.x*t.x+this.offsetX,this.y*t.y+this.offsetY).transform(e)}calcCornerCoords(t,e,s,i,n,r){const o=Uc([Yo(s,i),$o({angle:t}),Yc((n?this.touchSizeX:this.sizeX)||e,(n?this.touchSizeY:this.sizeY)||e)]);return{tl:new P(-.5,-.5).transform(o),tr:new P(.5,-.5).transform(o),br:new P(.5,.5).transform(o),bl:new P(-.5,.5).transform(o)}}render(t,e,s,i,n){((i=i||{}).cornerStyle||n.cornerStyle)==="circle"?Kv.call(this,t,e,s,i,n):Qv.call(this,t,e,s,i,n)}}const Jv=(a,t,e)=>e.lockRotation?Qc:t.cursorStyle,Zv=Jo(Up,Zo((a,t,e,s)=>{let{target:i,ex:n,ey:r,theta:o,originX:h,originY:c}=t;const u=i.translateToOriginPoint(i.getRelativeCenterPoint(),h,c);if(Fs(i,"lockRotation"))return!1;const d=Math.atan2(r-u.y,n-u.x),f=Math.atan2(s-u.y,e-u.x);let g=kn(f-d+o);if(i.snapAngle&&i.snapAngle>0){const b=i.snapAngle,v=i.snapThreshold||b,_=Math.ceil(g/b)*b,x=Math.floor(g/b)*b;Math.abs(g-x)<v?g=x:Math.abs(g-_)<v&&(g=_)}g<0&&(g=360+g),g%=360;const p=i.angle!==g;return i.angle=g,p}));function Im(a,t){const e=t.canvas,s=a[e.uniScaleKey];return e.uniformScaling&&!s||!e.uniformScaling&&s}function Nm(a,t,e){const s=Fs(a,"lockScalingX"),i=Fs(a,"lockScalingY");if(s&&i||!t&&(s||i)&&e||s&&t==="x"||i&&t==="y")return!0;const{width:n,height:r,strokeWidth:o}=a;return n===0&&o===0&&t!=="y"||r===0&&o===0&&t!=="x"}const t_=["e","se","s","sw","w","nw","n","ne","e"],Oh=(a,t,e)=>{const s=Im(a,e);if(Nm(e,t.x!==0&&t.y===0?"x":t.x===0&&t.y!==0?"y":"",s))return Qc;const i=wm(e,t);return"".concat(t_[i],"-resize")};function Ff(a,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{};const n=t.target,r=i.by,o=Im(a,n);let h,c,u,d,f,g;if(Nm(n,r,o))return!1;if(t.gestureScale)c=t.scaleX*t.gestureScale,u=t.scaleY*t.gestureScale;else{if(h=Sf(t,t.originX,t.originY,e,s),f=r!=="y"?Math.sign(h.x||t.signX||1):1,g=r!=="x"?Math.sign(h.y||t.signY||1):1,t.signX||(t.signX=f),t.signY||(t.signY=g),Fs(n,"lockScalingFlip")&&(t.signX!==f||t.signY!==g))return!1;if(d=n._getTransformedDimensions(),o&&!r){const v=Math.abs(h.x)+Math.abs(h.y),{original:_}=t,x=v/(Math.abs(d.x*_.scaleX/n.scaleX)+Math.abs(d.y*_.scaleY/n.scaleY));c=_.scaleX*x,u=_.scaleY*x}else c=Math.abs(h.x*n.scaleX/d.x),u=Math.abs(h.y*n.scaleY/d.y);ym(t)&&(c*=2,u*=2),t.signX!==f&&r!=="y"&&(t.originX=vm(t.originX),c*=-1,t.signX=f),t.signY!==g&&r!=="x"&&(t.originY=vm(t.originY),u*=-1,t.signY=g)}const p=n.scaleX,b=n.scaleY;return r?(r==="x"&&n.set(Me,c),r==="y"&&n.set(Je,u)):(!Fs(n,"lockScalingX")&&n.set(Me,c),!Fs(n,"lockScalingY")&&n.set(Je,u)),p!==n.scaleX||b!==n.scaleY}const iu=Jo(Hc,Zo((a,t,e,s)=>Ff(a,t,e,s))),e_=Jo(Hc,Zo((a,t,e,s)=>Ff(a,t,e,s,{by:"x"}))),s_=Jo(Hc,Zo((a,t,e,s)=>Ff(a,t,e,s,{by:"y"}))),i_=["target","ex","ey","skewingSide"],If={x:{counterAxis:"y",scale:Me,skew:Xo,lockSkewing:"lockSkewingX",origin:"originX",flip:"flipX"},y:{counterAxis:"x",scale:Je,skew:Wo,lockSkewing:"lockSkewingY",origin:"originY",flip:"flipY"}},n_=["ns","nesw","ew","nwse"],r_=(a,t,e)=>{if(t.x!==0&&Fs(e,"lockSkewingY")||t.y!==0&&Fs(e,"lockSkewingX"))return Qc;const s=wm(e,t)%4;return"".concat(n_[s],"-resize")};function jm(a,t,e,s,i){const{target:n}=e,{counterAxis:r,origin:o,lockSkewing:h,skew:c,flip:u}=If[a];if(Fs(n,h))return!1;const{origin:d,flip:f}=If[r],g=Vt(e[d])*(n[f]?-1:1),p=-Math.sign(g)*(n[u]?-1:1),b=.5*-((n[c]===0&&Sf(e,Q,Q,s,i)[a]>0||n[c]>0?1:-1)*p)+.5;return Jo(Yp,Zo((_,x,C,S)=>function(k,D,A){let{target:M,ex:O,ey:R,skewingSide:L}=D,V=Ct(D,i_);const{skew:U}=If[k],G=A.subtract(new P(O,R)).divide(new P(M.scaleX,M.scaleY))[k],at=M[U],F=V[U],z=Math.tan(Rt(F)),rt=k==="y"?M._getTransformedDimensions({scaleX:1,scaleY:1,skewX:0}).x:M._getTransformedDimensions({scaleX:1,scaleY:1}).y,Gt=2*G*L/Math.max(rt,1)+z,te=kn(Math.atan(Gt));M.set(U,te);const fe=at!==M[U];if(fe&&k==="y"){const{skewX:Yt,scaleX:St}=M,He=M._getTransformedDimensions({skewY:at}),Mi=M._getTransformedDimensions(),Ft=Yt!==0?He.x/Mi.x:1;Ft!==1&&M.set(Me,Ft*St)}return fe}(a,x,new P(C,S))))(t,E(E({},e),{},{[o]:b,skewingSide:p}),s,i)}const o_=(a,t,e,s)=>jm("x",a,t,e,s),a_=(a,t,e,s)=>jm("y",a,t,e,s);function nu(a,t){return a[t.canvas.altActionKey]}const ru=(a,t,e)=>{const s=nu(a,e);return t.x===0?s?Xo:Je:t.y===0?s?Wo:Me:""},ta=(a,t,e)=>nu(a,e)?r_(0,t,e):Oh(a,t,e),Bm=(a,t,e,s)=>nu(a,t.target)?a_(a,t,e,s):e_(a,t,e,s),Hm=(a,t,e,s)=>nu(a,t.target)?o_(a,t,e,s):s_(a,t,e,s),Gm=()=>({ml:new Ns({x:-.5,y:0,cursorStyleHandler:ta,actionHandler:Bm,getActionName:ru}),mr:new Ns({x:.5,y:0,cursorStyleHandler:ta,actionHandler:Bm,getActionName:ru}),mb:new Ns({x:0,y:.5,cursorStyleHandler:ta,actionHandler:Hm,getActionName:ru}),mt:new Ns({x:0,y:-.5,cursorStyleHandler:ta,actionHandler:Hm,getActionName:ru}),tl:new Ns({x:-.5,y:-.5,cursorStyleHandler:Oh,actionHandler:iu}),tr:new Ns({x:.5,y:-.5,cursorStyleHandler:Oh,actionHandler:iu}),bl:new Ns({x:-.5,y:.5,cursorStyleHandler:Oh,actionHandler:iu}),br:new Ns({x:.5,y:.5,cursorStyleHandler:Oh,actionHandler:iu}),mtr:new Ns({x:0,y:-.5,actionHandler:Zv,cursorStyleHandler:Jv,offsetY:-40,withConnection:!0,actionName:lf})}),h_=()=>({mr:new Ns({x:.5,y:0,actionHandler:Fm,cursorStyleHandler:ta,actionName:Sh}),ml:new Ns({x:-.5,y:0,actionHandler:Fm,cursorStyleHandler:ta,actionName:Sh})}),l_=()=>E(E({},Gm()),h_());class Rh extends Ii{static getDefaults(){return E(E({},super.getDefaults()),Rh.ownDefaults)}constructor(t){super(),Object.assign(this,this.constructor.createControls(),Rh.ownDefaults),this.setOptions(t)}static createControls(){return{controls:Gm()}}_updateCacheCanvas(){const t=this.canvas;if(this.noScaleCache&&t&&t._currentTransform){const e=t._currentTransform,s=e.target,i=e.action;if(this===s&&i&&i.startsWith(zc))return!1}return super._updateCacheCanvas()}getActiveControl(){const t=this.__corner;return t?{key:t,control:this.controls[t],coord:this.oCoords[t]}:void 0}findControl(t){let e=arguments.length>1&&arguments[1]!==void 0&&arguments[1];if(!this.hasControls||!this.canvas)return;this.__corner=void 0;const s=Object.entries(this.oCoords);for(let i=s.length-1;i>=0;i--){const[n,r]=s[i],o=this.controls[n];if(o.shouldActivate(n,this,t,e?r.touchCorner:r.corner))return this.__corner=n,{key:n,control:o,coord:this.oCoords[n]}}}calcOCoords(){const t=this.getViewportTransform(),e=this.getCenterPoint(),s=Yo(e.x,e.y),i=$o({angle:this.getTotalAngle()-(this.group&&this.flipX?180:0)}),n=Nt(s,i),r=Nt(t,n),o=Nt(r,[1/t[0],0,0,1/t[3],0,0]),h=this.group?br(this.calcTransformMatrix()):void 0;h&&(h.scaleX=Math.abs(h.scaleX),h.scaleY=Math.abs(h.scaleY));const c=this._calculateCurrentDimensions(h),u={};return this.forEachControl((d,f)=>{const g=d.positionHandler(c,o,this,d);u[f]=Object.assign(g,this._calcCornerCoords(d,g))}),u}_calcCornerCoords(t,e){const s=this.getTotalAngle();return{corner:t.calcCornerCoords(s,this.cornerSize,e.x,e.y,!1,this),touchCorner:t.calcCornerCoords(s,this.touchCornerSize,e.x,e.y,!0,this)}}setCoords(){super.setCoords(),this.canvas&&(this.oCoords=this.calcOCoords())}forEachControl(t){for(const e in this.controls)t(this.controls[e],e,this)}drawSelectionBackground(t){if(!this.selectionBackgroundColor||this.canvas&&this.canvas._activeObject!==this)return;t.save();const e=this.getRelativeCenterPoint(),s=this._calculateCurrentDimensions(),i=this.getViewportTransform();t.translate(e.x,e.y),t.scale(1/i[0],1/i[3]),t.rotate(Rt(this.angle)),t.fillStyle=this.selectionBackgroundColor,t.fillRect(-s.x/2,-s.y/2,s.x,s.y),t.restore()}strokeBorders(t,e){t.strokeRect(-e.x/2,-e.y/2,e.x,e.y)}_drawBorders(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const i=E({hasControls:this.hasControls,borderColor:this.borderColor,borderDashArray:this.borderDashArray},s);t.save(),t.strokeStyle=i.borderColor,this._setLineDash(t,i.borderDashArray),this.strokeBorders(t,e),i.hasControls&&this.drawControlsConnectingLines(t,e),t.restore()}_renderControls(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const{hasBorders:s,hasControls:i}=this,n=E({hasBorders:s,hasControls:i},e),r=this.getViewportTransform(),o=n.hasBorders,h=n.hasControls,c=Nt(r,this.calcTransformMatrix()),u=br(c);t.save(),t.translate(u.translateX,u.translateY),t.lineWidth=this.borderScaleFactor,this.group===this.parent&&(t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1),this.flipX&&(u.angle-=180),t.rotate(Rt(this.group?u.angle:this.angle)),o&&this.drawBorders(t,u,e),h&&this.drawControls(t,e),t.restore()}drawBorders(t,e,s){let i;if(s&&s.forActiveSelection||this.group){const n=Kc(this.width,this.height,Ah(e)),r=this.isStrokeAccountedForInDimensions()?uf:(this.strokeUniform?new P().scalarAdd(this.canvas?this.canvas.getZoom():1):new P(e.scaleX,e.scaleY)).scalarMultiply(this.strokeWidth);i=n.add(r).scalarAdd(this.borderScaleFactor).scalarAdd(2*this.padding)}else i=this._calculateCurrentDimensions().scalarAdd(this.borderScaleFactor);this._drawBorders(t,i,s)}drawControlsConnectingLines(t,e){let s=!1;t.beginPath(),this.forEachControl((i,n)=>{i.withConnection&&i.getVisibility(this,n)&&(s=!0,t.moveTo(i.x*e.x,i.y*e.y),t.lineTo(i.x*e.x+i.offsetX,i.y*e.y+i.offsetY))}),s&&t.stroke()}drawControls(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};t.save();const s=this.getCanvasRetinaScaling(),{cornerStrokeColor:i,cornerDashArray:n,cornerColor:r}=this,o=E({cornerStrokeColor:i,cornerDashArray:n,cornerColor:r},e);t.setTransform(s,0,0,s,0,0),t.strokeStyle=t.fillStyle=o.cornerColor,this.transparentCorners||(t.strokeStyle=o.cornerStrokeColor),this._setLineDash(t,o.cornerDashArray),this.forEachControl((h,c)=>{if(h.getVisibility(this,c)){const u=this.oCoords[c];h.render(t,u.x,u.y,o,this)}}),t.restore()}isControlVisible(t){return this.controls[t]&&this.controls[t].getVisibility(this,t)}setControlVisible(t,e){this._controlsVisibility||(this._controlsVisibility={}),this._controlsVisibility[t]=e}setControlsVisibility(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Object.entries(t).forEach(e=>{let[s,i]=e;return this.setControlVisible(s,i)})}clearContextTop(t){if(!this.canvas)return;const e=this.canvas.contextTop;if(!e)return;const s=this.canvas.viewportTransform;e.save(),e.transform(s[0],s[1],s[2],s[3],s[4],s[5]),this.transform(e);const i=this.width+4,n=this.height+4;return e.clearRect(-i/2,-n/2,i,n),t||e.restore(),e}onDeselect(t){return!1}onSelect(t){return!1}shouldStartDragging(t){return!1}onDragStart(t){return!1}canDrop(t){return!1}renderDragSourceEffect(t){}renderDropTargetEffect(t){}}function zm(a,t){return t.forEach(e=>{Object.getOwnPropertyNames(e.prototype).forEach(s=>{s!=="constructor"&&Object.defineProperty(a.prototype,s,Object.getOwnPropertyDescriptor(e.prototype,s)||Object.create(null))})}),a}T(Rh,"ownDefaults",{noScaleCache:!0,lockMovementX:!1,lockMovementY:!1,lockRotation:!1,lockScalingX:!1,lockScalingY:!1,lockSkewingX:!1,lockSkewingY:!1,lockScalingFlip:!1,cornerSize:13,touchCornerSize:24,transparentCorners:!0,cornerColor:"rgb(178,204,255)",cornerStrokeColor:"",cornerStyle:"rect",cornerDashArray:null,hasControls:!0,borderColor:"rgb(178,204,255)",borderDashArray:null,borderOpacityWhenMoving:.4,borderScaleFactor:1,hasBorders:!0,selectionBackgroundColor:"",selectable:!0,evented:!0,perPixelTargetFind:!1,activeOn:"down",hoverCursor:null,moveCursor:null});class pe extends Rh{}zm(pe,[xm]),N.setClass(pe),N.setClass(pe,"object");const Vm=(a,t,e,s)=>{const i=2*(s=Math.round(s))+1,{data:n}=a.getImageData(t-s,e-s,i,i);for(let r=3;r<n.length;r+=4)if(n[r]>0)return!1;return!0};class Xm{constructor(t){this.options=t,this.strokeProjectionMagnitude=this.options.strokeWidth/2,this.scale=new P(this.options.scaleX,this.options.scaleY),this.strokeUniformScalar=this.options.strokeUniform?new P(1/this.options.scaleX,1/this.options.scaleY):new P(1,1)}createSideVector(t,e){const s=Zc(t,e);return this.options.strokeUniform?s.multiply(this.scale):s}projectOrthogonally(t,e,s){return this.applySkew(t.add(this.calcOrthogonalProjection(t,e,s)))}isSkewed(){return this.options.skewX!==0||this.options.skewY!==0}applySkew(t){const e=new P(t);return e.y+=e.x*Math.tan(Rt(this.options.skewY)),e.x+=e.y*Math.tan(Rt(this.options.skewX)),e}scaleUnitVector(t,e){return t.multiply(this.strokeUniformScalar).scalarMultiply(e)}}const c_=new P;class ea extends Xm{static getOrthogonalRotationFactor(t,e){const s=e?eu(t,e):Em(t);return Math.abs(s)<An?-1:1}constructor(t,e,s,i){super(i),T(this,"AB",void 0),T(this,"AC",void 0),T(this,"alpha",void 0),T(this,"bisector",void 0),this.A=new P(t),this.B=new P(e),this.C=new P(s),this.AB=this.createSideVector(this.A,this.B),this.AC=this.createSideVector(this.A,this.C),this.alpha=eu(this.AB,this.AC),this.bisector=su(Ef(this.AB.eq(c_)?this.AC:this.AB,this.alpha/2))}calcOrthogonalProjection(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.strokeProjectionMagnitude;const i=this.createSideVector(t,e),n=kf(i),r=ea.getOrthogonalRotationFactor(n,this.bisector);return this.scaleUnitVector(n,s*r)}projectBevel(){const t=[];return(this.alpha%Ri==0?[this.B]:[this.B,this.C]).forEach(e=>{t.push(this.projectOrthogonally(this.A,e)),t.push(this.projectOrthogonally(this.A,e,-this.strokeProjectionMagnitude))}),t}projectMiter(){const t=[],e=Math.abs(this.alpha),s=1/Math.sin(e/2),i=this.scaleUnitVector(this.bisector,-this.strokeProjectionMagnitude*s),n=this.options.strokeUniform?tu(this.scaleUnitVector(this.bisector,this.options.strokeMiterLimit)):this.options.strokeMiterLimit;return tu(i)/this.strokeProjectionMagnitude<=n&&t.push(this.applySkew(this.A.add(i))),t.push(...this.projectBevel()),t}projectRoundNoSkew(t,e){const s=[],i=new P(ea.getOrthogonalRotationFactor(this.bisector),ea.getOrthogonalRotationFactor(new P(this.bisector.y,this.bisector.x)));return[new P(1,0).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(i),new P(0,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(i)].forEach(n=>{Mf(n,t,e)&&s.push(this.A.add(n))}),s}projectRoundWithSkew(t,e){const s=[],{skewX:i,skewY:n,scaleX:r,scaleY:o,strokeUniform:h}=this.options,c=new P(Math.tan(Rt(i)),Math.tan(Rt(n))),u=this.strokeProjectionMagnitude,d=h?u/o/Math.sqrt(1/o**2+1/r**2*c.y**2):u/Math.sqrt(1+c.y**2),f=new P(Math.sqrt(Math.max(u**2-d**2,0)),d),g=h?u/Math.sqrt(1+c.x**2*(1/o)**2/(1/r+1/r*c.x*c.y)**2):u/Math.sqrt(1+c.x**2/(1+c.x*c.y)**2),p=new P(g,Math.sqrt(Math.max(u**2-g**2,0)));return[p,p.scalarMultiply(-1),f,f.scalarMultiply(-1)].map(b=>this.applySkew(h?b.multiply(this.strokeUniformScalar):b)).forEach(b=>{Mf(b,t,e)&&s.push(this.applySkew(this.A).add(b))}),s}projectRound(){const t=[];t.push(...this.projectBevel());const e=this.alpha%Ri==0,s=this.applySkew(this.A),i=t[e?0:2].subtract(s),n=t[e?1:0].subtract(s),r=e?this.applySkew(this.AB.scalarMultiply(-1)):this.applySkew(this.bisector.multiply(this.strokeUniformScalar).scalarMultiply(-1)),o=Qo(i,r)>0,h=o?i:n,c=o?n:i;return this.isSkewed()?t.push(...this.projectRoundWithSkew(h,c)):t.push(...this.projectRoundNoSkew(h,c)),t}projectPoints(){switch(this.options.strokeLineJoin){case"miter":return this.projectMiter();case"round":return this.projectRound();default:return this.projectBevel()}}project(){return this.projectPoints().map(t=>({originPoint:this.A,projectedPoint:t,angle:this.alpha,bisector:this.bisector}))}}class Wm extends Xm{constructor(t,e,s){super(s),this.A=new P(t),this.T=new P(e)}calcOrthogonalProjection(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.strokeProjectionMagnitude;const i=this.createSideVector(t,e);return this.scaleUnitVector(kf(i),s)}projectButt(){return[this.projectOrthogonally(this.A,this.T,this.strokeProjectionMagnitude),this.projectOrthogonally(this.A,this.T,-this.strokeProjectionMagnitude)]}projectRound(){const t=[];if(!this.isSkewed()&&this.A.eq(this.T)){const e=new P(1,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar);t.push(this.applySkew(this.A.add(e)),this.applySkew(this.A.subtract(e)))}else t.push(...new ea(this.A,this.T,this.T,this.options).projectRound());return t}projectSquare(){const t=[];if(this.A.eq(this.T)){const e=new P(1,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar);t.push(this.A.add(e),this.A.subtract(e))}else{const e=this.calcOrthogonalProjection(this.A,this.T,this.strokeProjectionMagnitude),s=this.scaleUnitVector(su(this.createSideVector(this.A,this.T)),-this.strokeProjectionMagnitude),i=this.A.add(s);t.push(i.add(e),i.subtract(e))}return t.map(e=>this.applySkew(e))}projectPoints(){switch(this.options.strokeLineCap){case"round":return this.projectRound();case"square":return this.projectSquare();default:return this.projectButt()}}project(){return this.projectPoints().map(t=>({originPoint:this.A,projectedPoint:t}))}}const Um=function(a,t){let e=arguments.length>2&&arguments[2]!==void 0&&arguments[2];const s=[];if(a.length===0)return s;const i=a.reduce((n,r)=>(n[n.length-1].eq(r)||n.push(new P(r)),n),[new P(a[0])]);if(i.length===1)e=!0;else if(!e){const n=i[0],r=((o,h)=>{for(let c=o.length-1;c>=0;c--)if(h(o[c],c,o))return c;return-1})(i,o=>!o.eq(n));i.splice(r+1)}return i.forEach((n,r,o)=>{let h,c;r===0?(c=o[1],h=e?n:o[o.length-1]):r===o.length-1?(h=o[r-1],c=e?n:o[0]):(h=o[r-1],c=o[r+1]),e&&o.length===1?s.push(...new Wm(n,n,t).project()):!e||r!==0&&r!==o.length-1?s.push(...new ea(n,h,c,t).project()):s.push(...new Wm(n,r===0?c:h,t).project())}),s},Nf=a=>{const t={};return Object.keys(a).forEach(e=>{t[e]={},Object.keys(a[e]).forEach(s=>{t[e][s]=E({},a[e][s])})}),t},Ym=a=>a.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/'/g,"&apos;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),ou=a=>{const t=[];for(let e,s=0;s<a.length;s++)(e=u_(a,s))!==!1&&t.push(e);return t},u_=(a,t)=>{const e=a.charCodeAt(t);if(isNaN(e))return"";if(e<55296||e>57343)return a.charAt(t);if(55296<=e&&e<=56319){if(a.length<=t+1)throw"High surrogate without following low surrogate";const i=a.charCodeAt(t+1);if(56320>i||i>57343)throw"High surrogate without following low surrogate";return a.charAt(t)+a.charAt(t+1)}if(t===0)throw"Low surrogate without preceding high surrogate";const s=a.charCodeAt(t-1);if(55296>s||s>56319)throw"Low surrogate without preceding high surrogate";return!1};var d_=Object.freeze({__proto__:null,capitalize:function(a){let t=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return"".concat(a.charAt(0).toUpperCase()).concat(t?a.slice(1):a.slice(1).toLowerCase())},escapeXml:Ym,graphemeSplit:ou});const au=function(a,t){let e=arguments.length>2&&arguments[2]!==void 0&&arguments[2];return a.fill!==t.fill||a.stroke!==t.stroke||a.strokeWidth!==t.strokeWidth||a.fontSize!==t.fontSize||a.fontFamily!==t.fontFamily||a.fontWeight!==t.fontWeight||a.fontStyle!==t.fontStyle||a.textBackgroundColor!==t.textBackgroundColor||a.deltaY!==t.deltaY||e&&(a.overline!==t.overline||a.underline!==t.underline||a.linethrough!==t.linethrough)},$m=(a,t)=>{const e=t.split(`
38
38
  `),s=[];let i=-1,n={};a=Nf(a);for(let r=0;r<e.length;r++){const o=ou(e[r]);if(a[r])for(let h=0;h<o.length;h++){i++;const c=a[r][h];c&&Object.keys(c).length>0&&(au(n,c,!0)?s.push({start:i,end:i+1,style:c}):s[s.length-1].end++),n=c||{}}else i+=o.length,n={}}return s},qm=(a,t)=>{if(!Array.isArray(a))return Nf(a);const e=t.split(hf),s={};let i=-1,n=0;for(let r=0;r<e.length;r++){const o=ou(e[r]);for(let h=0;h<o.length;h++)i++,a[n]&&a[n].start<=i&&i<a[n].end&&(s[r]=s[r]||{},s[r][h]=E({},a[n].style),i===a[n].end-1&&n++)}return s},Mn=["display","transform",zt,"fill-opacity","fill-rule","opacity",Pe,"stroke-dasharray","stroke-linecap","stroke-dashoffset","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","id","paint-order","vector-effect","instantiated_by_use","clip-path"];function Km(a,t){const e=a.nodeName,s=a.getAttribute("class"),i=a.getAttribute("id"),n="(?![a-zA-Z\\-]+)";let r;if(r=new RegExp("^"+e,"i"),t=t.replace(r,""),i&&t.length&&(r=new RegExp("#"+i+n,"i"),t=t.replace(r,"")),s&&t.length){const o=s.split(" ");for(let h=o.length;h--;)r=new RegExp("\\."+o[h]+n,"i"),t=t.replace(r,"")}return t.length===0}function f_(a,t){let e=!0;const s=Km(a,t.pop());return s&&t.length&&(e=function(i,n){let r,o=!0;for(;i.parentElement&&i.parentElement.nodeType===1&&n.length;)o&&(r=n.pop()),o=Km(i=i.parentElement,r);return n.length===0}(a,t)),s&&e&&t.length===0}const g_=a=>{var t;return(t=Ov[a])!==null&&t!==void 0?t:a},p_=new RegExp("(".concat(Is,")"),"gi"),m_=a=>a.replace(p_," $1 ").replace(/,/gi," ").replace(/\s+/gi," ");var Qm,Jm,Zm,t0,e0,s0,i0;const Oe="(".concat(Is,")"),b_=String.raw(Qm||(Qm=Cn(["(skewX)(",")"],["(skewX)\\(","\\)"])),Oe),y_=String.raw(Jm||(Jm=Cn(["(skewY)(",")"],["(skewY)\\(","\\)"])),Oe),v_=String.raw(Zm||(Zm=Cn(["(rotate)(","(?: "," ",")?)"],["(rotate)\\(","(?: "," ",")?\\)"])),Oe,Oe,Oe),__=String.raw(t0||(t0=Cn(["(scale)(","(?: ",")?)"],["(scale)\\(","(?: ",")?\\)"])),Oe,Oe),w_=String.raw(e0||(e0=Cn(["(translate)(","(?: ",")?)"],["(translate)\\(","(?: ",")?\\)"])),Oe,Oe),x_=String.raw(s0||(s0=Cn(["(matrix)("," "," "," "," "," ",")"],["(matrix)\\("," "," "," "," "," ","\\)"])),Oe,Oe,Oe,Oe,Oe,Oe),jf="(?:".concat(x_,"|").concat(w_,"|").concat(v_,"|").concat(__,"|").concat(b_,"|").concat(y_,")"),S_="(?:".concat(jf,"*)"),C_=String.raw(i0||(i0=Cn(["^s*(?:","?)s*$"],["^\\s*(?:","?)\\s*$"])),S_),A_=new RegExp(C_),T_=new RegExp(jf),E_=new RegExp(jf,"g");function hu(a){const t=[];if(!(a=m_(a).replace(/\s*([()])\s*/gi,"$1"))||a&&!A_.test(a))return[...Ee];for(const e of a.matchAll(E_)){const s=T_.exec(e[0]);if(!s)continue;let i=Ee;const n=s.filter(p=>!!p),[,r,...o]=n,[h,c,u,d,f,g]=o.map(p=>parseFloat(p));switch(r){case"translate":i=Yo(h,c);break;case lf:i=$o({angle:h},{x:c,y:u});break;case zc:i=Yc(h,c);break;case Xo:i=gf(h);break;case Wo:i=pf(h);break;case"matrix":i=[h,c,u,d,f,g]}t.push(i)}return Uc(t)}function k_(a,t,e,s){const i=Array.isArray(t);let n,r=t;if(a!==zt&&a!==Pe||t!==ke){if(a==="strokeUniform")return t==="non-scaling-stroke";if(a==="strokeDashArray")r=t===ke?null:t.replace(/,/g," ").split(/\s+/).map(parseFloat);else if(a==="transformMatrix")r=e&&e.transformMatrix?Nt(e.transformMatrix,hu(t)):hu(t);else if(a==="visible")r=t!==ke&&t!=="hidden",e&&e.visible===!1&&(r=!1);else if(a==="opacity")r=parseFloat(t),e&&e.opacity!==void 0&&(r*=e.opacity);else if(a==="textAnchor")r=t==="start"?dt:t==="end"?It:Q;else if(a==="charSpacing")n=De(t,s)/s*1e3;else if(a==="paintFirst"){const o=t.indexOf(zt),h=t.indexOf(Pe);r=zt,(o>-1&&h>-1&&h<o||o===-1&&h>-1)&&(r=Pe)}else{if(a==="href"||a==="xlink:href"||a==="font"||a==="id")return t;if(a==="imageSmoothing")return t==="optimizeQuality";n=i?t.map(De):De(t,s)}}else r="";return!i&&isNaN(n)?r:n}function M_(a,t){const e=a.match(Dv);if(!e)return;const s=e[1],i=e[3],n=e[4],r=e[5],o=e[6];s&&(t.fontStyle=s),i&&(t.fontWeight=isNaN(parseFloat(i))?i:parseFloat(i)),n&&(t.fontSize=De(n)),o&&(t.fontFamily=o),r&&(t.lineHeight=r==="normal"?1:r)}function Bf(a,t){a.replace(/;\s*$/,"").split(";").forEach(e=>{if(!e)return;const[s,i]=e.split(":");t[s.trim().toLowerCase()]=i.trim()})}function P_(a){const t={},e=a.getAttribute("style");return e&&(typeof e=="string"?Bf(e,t):function(s,i){Object.entries(s).forEach(n=>{let[r,o]=n;o!==void 0&&(i[r.toLowerCase()]=o)})}(e,t)),t}const D_={stroke:"strokeOpacity",fill:"fillOpacity"};function Ni(a,t,e){if(!a)return{};let s,i={},n=of;a.parentNode&&Cm.test(a.parentNode.nodeName)&&(i=Ni(a.parentElement,t,e),i.fontSize&&(s=n=De(i.fontSize)));const r=E(E(E({},t.reduce((c,u)=>{const d=a.getAttribute(u);return d&&(c[u]=d),c},{})),function(c){let u=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},d={};for(const f in u)f_(c,f.split(" "))&&(d=E(E({},d),u[f]));return d}(a,e)),P_(a));r[Tf]&&a.setAttribute(Tf,r[Tf]),r[Af]&&(s=De(r[Af],n),r[Af]="".concat(s));const o={};for(const c in r){const u=g_(c),d=k_(u,r[c],i,s);o[u]=d}o&&o.font&&M_(o.font,o);const h=E(E({},i),o);return Cm.test(a.nodeName)?h:function(c){const u=pe.getDefaults();return Object.entries(D_).forEach(d=>{let[f,g]=d;if(c[g]===void 0||c[f]==="")return;if(c[f]===void 0){if(!u[f])return;c[f]=u[f]}if(c[f].indexOf("url(")===0)return;const p=new gt(c[f]);c[f]=p.setAlpha(At(p.getAlpha()*c[g],2)).toRgba()}),c}(h)}const O_=["left","top","width","height","visible"],n0=["rx","ry"];class oi extends pe{static getDefaults(){return E(E({},super.getDefaults()),oi.ownDefaults)}constructor(t){super(),Object.assign(this,oi.ownDefaults),this.setOptions(t),this._initRxRy()}_initRxRy(){const{rx:t,ry:e}=this;t&&!e?this.ry=t:e&&!t&&(this.rx=e)}_render(t){const{width:e,height:s}=this,i=-e/2,n=-s/2,r=this.rx?Math.min(this.rx,e/2):0,o=this.ry?Math.min(this.ry,s/2):0,h=r!==0||o!==0;t.beginPath(),t.moveTo(i+r,n),t.lineTo(i+e-r,n),h&&t.bezierCurveTo(i+e-Tn*r,n,i+e,n+Tn*o,i+e,n+o),t.lineTo(i+e,n+s-o),h&&t.bezierCurveTo(i+e,n+s-Tn*o,i+e-Tn*r,n+s,i+e-r,n+s),t.lineTo(i+r,n+s),h&&t.bezierCurveTo(i+Tn*r,n+s,i,n+s-Tn*o,i,n+s-o),t.lineTo(i,n+o),h&&t.bezierCurveTo(i,n+Tn*o,i+Tn*r,n,i+r,n),t.closePath(),this._renderPaintInOrder(t)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject([...n0,...t])}_toSVG(){const{width:t,height:e,rx:s,ry:i}=this;return["<rect ","COMMON_PARTS",'x="'.concat(-t/2,'" y="').concat(-e/2,'" rx="').concat(s,'" ry="').concat(i,'" width="').concat(t,'" height="').concat(e,`" />
39
- `)]}static async fromElement(t,e,s){const i=Ni(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:r=0,width:o=0,height:h=0,visible:c=!0}=i,u=Ct(i,O_);return new this(E(E(E({},e),u),{},{left:n,top:r,width:o,height:h,visible:!!(c&&o&&h)}))}}A(oi,"type","Rect"),A(oi,"cacheProperties",[...Fi,...n0]),A(oi,"ownDefaults",{rx:0,ry:0}),A(oi,"ATTRIBUTE_NAMES",[...Mn,"x","y","rx","ry","width","height"]),N.setClass(oi),N.setSVGClass(oi);const ji="initialization",lu="added",Hf="removed",cu="imperative",r0=(a,t)=>{const{strokeUniform:e,strokeWidth:s,width:i,height:n,group:r}=t,o=r&&r!==a?Dh(r.calcTransformMatrix(),a.calcTransformMatrix()):null,h=o?t.getRelativeCenterPoint().transform(o):t.getRelativeCenterPoint(),c=!t.isStrokeAccountedForInDimensions(),u=e&&c?mm(new P(s,s),void 0,a.calcTransformMatrix()):uf,d=!e&&c?s:0,f=Kc(i+d,n+d,Uc([o,t.calcOwnMatrix()],!0)).add(u).scalarDivide(2);return[h.subtract(f),h.add(f)]};class uu{calcLayoutResult(t,e){if(this.shouldPerformLayout(t))return this.calcBoundingBox(e,t)}shouldPerformLayout(t){let{type:e,prevStrategy:s,strategy:i}=t;return e===ji||e===cu||!!s&&i!==s}shouldLayoutClipPath(t){let{type:e,target:{clipPath:s}}=t;return e!==ji&&s&&!s.absolutePositioned}getInitialSize(t,e){return e.size}calcBoundingBox(t,e){const{type:s,target:i}=e;if(s===cu&&e.overrides)return e.overrides;if(t.length===0)return;const{left:n,top:r,width:o,height:h}=ri(t.map(d=>r0(i,d)).reduce((d,f)=>d.concat(f),[])),c=new P(o,h),u=new P(n,r).add(c.scalarDivide(2));if(s===ji){const d=this.getInitialSize(e,{size:c,center:u});return{center:u,relativeCorrection:new P(0,0),size:d}}return{center:u.transform(i.calcOwnMatrix()),size:c}}}A(uu,"type","strategy");class Gf extends uu{shouldPerformLayout(t){return!0}}A(Gf,"type","fit-content"),N.setClass(Gf);const R_=["strategy"],L_=["target","strategy","bubbles","prevStrategy"],o0="layoutManager";class Lh{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:new Gf;A(this,"strategy",void 0),this.strategy=t,this._subscriptions=new Map}performLayout(t){const e=E(E({bubbles:!0,strategy:this.strategy},t),{},{prevStrategy:this._prevLayoutStrategy,stopPropagation(){this.bubbles=!1}});this.onBeforeLayout(e);const s=this.getLayoutResult(e);s&&this.commitLayout(e,s),this.onAfterLayout(e,s),this._prevLayoutStrategy=e.strategy}attachHandlers(t,e){const{target:s}=e;return[Vc,Wp,Sh,Up,Hc,Yp,Gc,xv,Sv].map(i=>t.on(i,n=>this.performLayout(i===Vc?{type:"object_modified",trigger:i,e:n,target:s}:{type:"object_modifying",trigger:i,e:n,target:s})))}subscribe(t,e){this.unsubscribe(t,e);const s=this.attachHandlers(t,e);this._subscriptions.set(t,s)}unsubscribe(t,e){(this._subscriptions.get(t)||[]).forEach(s=>s()),this._subscriptions.delete(t)}unsubscribeTargets(t){t.targets.forEach(e=>this.unsubscribe(e,t))}subscribeTargets(t){t.targets.forEach(e=>this.subscribe(e,t))}onBeforeLayout(t){const{target:e,type:s}=t,{canvas:i}=e;if(s===ji||s===lu?this.subscribeTargets(t):s===Hf&&this.unsubscribeTargets(t),e.fire("layout:before",{context:t}),i&&i.fire("object:layout:before",{target:e,context:t}),s===cu&&t.deep){const n=Ct(t,R_);e.forEachObject(r=>r.layoutManager&&r.layoutManager.performLayout(E(E({},n),{},{bubbles:!1,target:r})))}}getLayoutResult(t){const{target:e,strategy:s,type:i}=t,n=s.calcLayoutResult(t,e.getObjects());if(!n)return;const r=i===ji?new P:e.getRelativeCenterPoint(),{center:o,correction:h=new P,relativeCorrection:c=new P}=n,u=r.subtract(o).add(h).transform(i===ji?Ee:Xe(e.calcOwnMatrix()),!0).add(c);return{result:n,prevCenter:r,nextCenter:o,offset:u}}commitLayout(t,e){const{target:s}=t,{result:{size:i},nextCenter:n}=e;var r,o;s.set({width:i.x,height:i.y}),this.layoutObjects(t,e),t.type===ji?s.set({left:(r=t.x)!==null&&r!==void 0?r:n.x+i.x*Vt(s.originX),top:(o=t.y)!==null&&o!==void 0?o:n.y+i.y*Vt(s.originY)}):(s.setPositionByOrigin(n,Q,Q),s.setCoords(),s.set("dirty",!0))}layoutObjects(t,e){const{target:s}=t;s.forEachObject(i=>{i.group===s&&this.layoutObject(t,e,i)}),t.strategy.shouldLayoutClipPath(t)&&this.layoutObject(t,e,s.clipPath)}layoutObject(t,e,s){let{offset:i}=e;s.set({left:s.left+i.x,top:s.top+i.y})}onAfterLayout(t,e){const{target:s,strategy:i,bubbles:n,prevStrategy:r}=t,o=Ct(t,L_),{canvas:h}=s;s.fire("layout:after",{context:t,result:e}),h&&h.fire("object:layout:after",{context:t,result:e,target:s});const c=s.parent;n&&c!=null&&c.layoutManager&&((o.path||(o.path=[])).push(s),c.layoutManager.performLayout(E(E({},o),{},{target:c}))),s.set("dirty",!0)}dispose(){const{_subscriptions:t}=this;t.forEach(e=>e.forEach(s=>s())),t.clear()}toObject(){return{type:o0,strategy:this.strategy.constructor.type}}toJSON(){return this.toObject()}}N.setClass(Lh,o0);const F_=["type","objects","layoutManager"];class I_ extends Lh{performLayout(){}}class ai extends $p(pe){static getDefaults(){return E(E({},super.getDefaults()),ai.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),A(this,"_activeObjects",[]),A(this,"__objectSelectionTracker",void 0),A(this,"__objectSelectionDisposer",void 0),Object.assign(this,ai.ownDefaults),this.setOptions(e),this.groupInit(t,e)}groupInit(t,e){var s;this._objects=[...t],this.__objectSelectionTracker=this.__objectSelectionMonitor.bind(this,!0),this.__objectSelectionDisposer=this.__objectSelectionMonitor.bind(this,!1),this.forEachObject(i=>{this.enterGroup(i,!1)}),this.layoutManager=(s=e.layoutManager)!==null&&s!==void 0?s:new Lh,this.layoutManager.performLayout({type:ji,target:this,targets:[...t],x:e.left,y:e.top})}canEnterGroup(t){return t===this||this.isDescendantOf(t)?(Oi("error","Group: circular object trees are not supported, this call has no effect"),!1):this._objects.indexOf(t)===-1||(Oi("error","Group: duplicate objects are not supported inside group, this call has no effect"),!1)}_filterObjectsBeforeEnteringGroup(t){return t.filter((e,s,i)=>this.canEnterGroup(e)&&i.indexOf(e)===s)}add(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];const i=this._filterObjectsBeforeEnteringGroup(e),n=super.add(...i);return this._onAfterObjectsChange(lu,i),n}insertAt(t){for(var e=arguments.length,s=new Array(e>1?e-1:0),i=1;i<e;i++)s[i-1]=arguments[i];const n=this._filterObjectsBeforeEnteringGroup(s),r=super.insertAt(t,...n);return this._onAfterObjectsChange(lu,n),r}remove(){const t=super.remove(...arguments);return this._onAfterObjectsChange(Hf,t),t}_onObjectAdded(t){this.enterGroup(t,!0),this.fire("object:added",{target:t}),t.fire("added",{target:this})}_onObjectRemoved(t,e){this.exitGroup(t,e),this.fire("object:removed",{target:t}),t.fire("removed",{target:this})}_onAfterObjectsChange(t,e){this.layoutManager.performLayout({type:t,targets:e,target:this})}_onStackOrderChanged(){this._set("dirty",!0)}_set(t,e){const s=this[t];return super._set(t,e),t==="canvas"&&s!==e&&(this._objects||[]).forEach(i=>{i._set(t,e)}),this}_shouldSetNestedCoords(){return this.subTargetCheck}removeAll(){return this._activeObjects=[],this.remove(...this._objects)}__objectSelectionMonitor(t,e){let{target:s}=e;const i=this._activeObjects;if(t)i.push(s),this._set("dirty",!0);else if(i.length>0){const n=i.indexOf(s);n>-1&&(i.splice(n,1),this._set("dirty",!0))}}_watchObject(t,e){t&&this._watchObject(!1,e),t?(e.on("selected",this.__objectSelectionTracker),e.on("deselected",this.__objectSelectionDisposer)):(e.off("selected",this.__objectSelectionTracker),e.off("deselected",this.__objectSelectionDisposer))}enterGroup(t,e){t.group&&t.group.remove(t),t._set("parent",this),this._enterGroup(t,e)}_enterGroup(t,e){e&&Ko(t,Nt(Xe(this.calcTransformMatrix()),t.calcTransformMatrix())),this._shouldSetNestedCoords()&&t.setCoords(),t._set("group",this),t._set("canvas",this.canvas),this._watchObject(!0,t);const s=this.canvas&&this.canvas.getActiveObject&&this.canvas.getActiveObject();s&&(s===t||t.isDescendantOf(s))&&this._activeObjects.push(t)}exitGroup(t,e){this._exitGroup(t,e),t._set("parent",void 0),t._set("canvas",void 0)}_exitGroup(t,e){t._set("group",void 0),e||(Ko(t,Nt(this.calcTransformMatrix(),t.calcTransformMatrix())),t.setCoords()),this._watchObject(!1,t);const s=this._activeObjects.length>0?this._activeObjects.indexOf(t):-1;s>-1&&this._activeObjects.splice(s,1)}shouldCache(){const t=pe.prototype.shouldCache.call(this);if(t){for(let e=0;e<this._objects.length;e++)if(this._objects[e].willDrawShadow())return this.ownCaching=!1,!1}return t}willDrawShadow(){if(super.willDrawShadow())return!0;for(let t=0;t<this._objects.length;t++)if(this._objects[t].willDrawShadow())return!0;return!1}isOnACache(){return this.ownCaching||!!this.parent&&this.parent.isOnACache()}drawObject(t,e,s){this._renderBackground(t);for(let n=0;n<this._objects.length;n++){var i;const r=this._objects[n];(i=this.canvas)!==null&&i!==void 0&&i.preserveObjectStacking&&r.group!==this?(t.save(),t.transform(...Xe(this.calcTransformMatrix())),r.render(t),t.restore()):r.group===this&&r.render(t)}this._drawClipPath(t,this.clipPath,s)}setCoords(){super.setCoords(),this._shouldSetNestedCoords()&&this.forEachObject(t=>t.setCoords())}triggerLayout(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.layoutManager.performLayout(E({target:this,type:cu},t))}render(t){this._transformDone=!0,super.render(t),this._transformDone=!1}__serializeObjects(t,e){const s=this.includeDefaultValues;return this._objects.filter(function(i){return!i.excludeFromExport}).map(function(i){const n=i.includeDefaultValues;i.includeDefaultValues=s;const r=i[t||"toObject"](e);return i.includeDefaultValues=n,r})}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const e=this.layoutManager.toObject();return E(E(E({},super.toObject(["subTargetCheck","interactive",...t])),e.strategy!=="fit-content"||this.includeDefaultValues?{layoutManager:e}:{}),{},{objects:this.__serializeObjects("toObject",t)})}toString(){return"#<Group: (".concat(this.complexity(),")>")}dispose(){this.layoutManager.unsubscribeTargets({targets:this.getObjects(),target:this}),this._activeObjects=[],this.forEachObject(t=>{this._watchObject(!1,t),t.dispose()}),super.dispose()}_createSVGBgRect(t){if(!this.backgroundColor)return"";const e=oi.prototype._toSVG.call(this),s=e.indexOf("COMMON_PARTS");e[s]='for="group" ';const i=e.join("");return t?t(i):i}_toSVG(t){const e=["<g ","COMMON_PARTS",` >
39
+ `)]}static async fromElement(t,e,s){const i=Ni(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:r=0,width:o=0,height:h=0,visible:c=!0}=i,u=Ct(i,O_);return new this(E(E(E({},e),u),{},{left:n,top:r,width:o,height:h,visible:!!(c&&o&&h)}))}}T(oi,"type","Rect"),T(oi,"cacheProperties",[...Fi,...n0]),T(oi,"ownDefaults",{rx:0,ry:0}),T(oi,"ATTRIBUTE_NAMES",[...Mn,"x","y","rx","ry","width","height"]),N.setClass(oi),N.setSVGClass(oi);const ji="initialization",lu="added",Hf="removed",cu="imperative",r0=(a,t)=>{const{strokeUniform:e,strokeWidth:s,width:i,height:n,group:r}=t,o=r&&r!==a?Dh(r.calcTransformMatrix(),a.calcTransformMatrix()):null,h=o?t.getRelativeCenterPoint().transform(o):t.getRelativeCenterPoint(),c=!t.isStrokeAccountedForInDimensions(),u=e&&c?mm(new P(s,s),void 0,a.calcTransformMatrix()):uf,d=!e&&c?s:0,f=Kc(i+d,n+d,Uc([o,t.calcOwnMatrix()],!0)).add(u).scalarDivide(2);return[h.subtract(f),h.add(f)]};class uu{calcLayoutResult(t,e){if(this.shouldPerformLayout(t))return this.calcBoundingBox(e,t)}shouldPerformLayout(t){let{type:e,prevStrategy:s,strategy:i}=t;return e===ji||e===cu||!!s&&i!==s}shouldLayoutClipPath(t){let{type:e,target:{clipPath:s}}=t;return e!==ji&&s&&!s.absolutePositioned}getInitialSize(t,e){return e.size}calcBoundingBox(t,e){const{type:s,target:i}=e;if(s===cu&&e.overrides)return e.overrides;if(t.length===0)return;const{left:n,top:r,width:o,height:h}=ri(t.map(d=>r0(i,d)).reduce((d,f)=>d.concat(f),[])),c=new P(o,h),u=new P(n,r).add(c.scalarDivide(2));if(s===ji){const d=this.getInitialSize(e,{size:c,center:u});return{center:u,relativeCorrection:new P(0,0),size:d}}return{center:u.transform(i.calcOwnMatrix()),size:c}}}T(uu,"type","strategy");class Gf extends uu{shouldPerformLayout(t){return!0}}T(Gf,"type","fit-content"),N.setClass(Gf);const R_=["strategy"],L_=["target","strategy","bubbles","prevStrategy"],o0="layoutManager";class Lh{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:new Gf;T(this,"strategy",void 0),this.strategy=t,this._subscriptions=new Map}performLayout(t){const e=E(E({bubbles:!0,strategy:this.strategy},t),{},{prevStrategy:this._prevLayoutStrategy,stopPropagation(){this.bubbles=!1}});this.onBeforeLayout(e);const s=this.getLayoutResult(e);s&&this.commitLayout(e,s),this.onAfterLayout(e,s),this._prevLayoutStrategy=e.strategy}attachHandlers(t,e){const{target:s}=e;return[Vc,Wp,Sh,Up,Hc,Yp,Gc,xv,Sv].map(i=>t.on(i,n=>this.performLayout(i===Vc?{type:"object_modified",trigger:i,e:n,target:s}:{type:"object_modifying",trigger:i,e:n,target:s})))}subscribe(t,e){this.unsubscribe(t,e);const s=this.attachHandlers(t,e);this._subscriptions.set(t,s)}unsubscribe(t,e){(this._subscriptions.get(t)||[]).forEach(s=>s()),this._subscriptions.delete(t)}unsubscribeTargets(t){t.targets.forEach(e=>this.unsubscribe(e,t))}subscribeTargets(t){t.targets.forEach(e=>this.subscribe(e,t))}onBeforeLayout(t){const{target:e,type:s}=t,{canvas:i}=e;if(s===ji||s===lu?this.subscribeTargets(t):s===Hf&&this.unsubscribeTargets(t),e.fire("layout:before",{context:t}),i&&i.fire("object:layout:before",{target:e,context:t}),s===cu&&t.deep){const n=Ct(t,R_);e.forEachObject(r=>r.layoutManager&&r.layoutManager.performLayout(E(E({},n),{},{bubbles:!1,target:r})))}}getLayoutResult(t){const{target:e,strategy:s,type:i}=t,n=s.calcLayoutResult(t,e.getObjects());if(!n)return;const r=i===ji?new P:e.getRelativeCenterPoint(),{center:o,correction:h=new P,relativeCorrection:c=new P}=n,u=r.subtract(o).add(h).transform(i===ji?Ee:Xe(e.calcOwnMatrix()),!0).add(c);return{result:n,prevCenter:r,nextCenter:o,offset:u}}commitLayout(t,e){const{target:s}=t,{result:{size:i},nextCenter:n}=e;var r,o;s.set({width:i.x,height:i.y}),this.layoutObjects(t,e),t.type===ji?s.set({left:(r=t.x)!==null&&r!==void 0?r:n.x+i.x*Vt(s.originX),top:(o=t.y)!==null&&o!==void 0?o:n.y+i.y*Vt(s.originY)}):(s.setPositionByOrigin(n,Q,Q),s.setCoords(),s.set("dirty",!0))}layoutObjects(t,e){const{target:s}=t;s.forEachObject(i=>{i.group===s&&this.layoutObject(t,e,i)}),t.strategy.shouldLayoutClipPath(t)&&this.layoutObject(t,e,s.clipPath)}layoutObject(t,e,s){let{offset:i}=e;s.set({left:s.left+i.x,top:s.top+i.y})}onAfterLayout(t,e){const{target:s,strategy:i,bubbles:n,prevStrategy:r}=t,o=Ct(t,L_),{canvas:h}=s;s.fire("layout:after",{context:t,result:e}),h&&h.fire("object:layout:after",{context:t,result:e,target:s});const c=s.parent;n&&c!=null&&c.layoutManager&&((o.path||(o.path=[])).push(s),c.layoutManager.performLayout(E(E({},o),{},{target:c}))),s.set("dirty",!0)}dispose(){const{_subscriptions:t}=this;t.forEach(e=>e.forEach(s=>s())),t.clear()}toObject(){return{type:o0,strategy:this.strategy.constructor.type}}toJSON(){return this.toObject()}}N.setClass(Lh,o0);const F_=["type","objects","layoutManager"];class I_ extends Lh{performLayout(){}}class ai extends $p(pe){static getDefaults(){return E(E({},super.getDefaults()),ai.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),T(this,"_activeObjects",[]),T(this,"__objectSelectionTracker",void 0),T(this,"__objectSelectionDisposer",void 0),Object.assign(this,ai.ownDefaults),this.setOptions(e),this.groupInit(t,e)}groupInit(t,e){var s;this._objects=[...t],this.__objectSelectionTracker=this.__objectSelectionMonitor.bind(this,!0),this.__objectSelectionDisposer=this.__objectSelectionMonitor.bind(this,!1),this.forEachObject(i=>{this.enterGroup(i,!1)}),this.layoutManager=(s=e.layoutManager)!==null&&s!==void 0?s:new Lh,this.layoutManager.performLayout({type:ji,target:this,targets:[...t],x:e.left,y:e.top})}canEnterGroup(t){return t===this||this.isDescendantOf(t)?(Oi("error","Group: circular object trees are not supported, this call has no effect"),!1):this._objects.indexOf(t)===-1||(Oi("error","Group: duplicate objects are not supported inside group, this call has no effect"),!1)}_filterObjectsBeforeEnteringGroup(t){return t.filter((e,s,i)=>this.canEnterGroup(e)&&i.indexOf(e)===s)}add(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];const i=this._filterObjectsBeforeEnteringGroup(e),n=super.add(...i);return this._onAfterObjectsChange(lu,i),n}insertAt(t){for(var e=arguments.length,s=new Array(e>1?e-1:0),i=1;i<e;i++)s[i-1]=arguments[i];const n=this._filterObjectsBeforeEnteringGroup(s),r=super.insertAt(t,...n);return this._onAfterObjectsChange(lu,n),r}remove(){const t=super.remove(...arguments);return this._onAfterObjectsChange(Hf,t),t}_onObjectAdded(t){this.enterGroup(t,!0),this.fire("object:added",{target:t}),t.fire("added",{target:this})}_onObjectRemoved(t,e){this.exitGroup(t,e),this.fire("object:removed",{target:t}),t.fire("removed",{target:this})}_onAfterObjectsChange(t,e){this.layoutManager.performLayout({type:t,targets:e,target:this})}_onStackOrderChanged(){this._set("dirty",!0)}_set(t,e){const s=this[t];return super._set(t,e),t==="canvas"&&s!==e&&(this._objects||[]).forEach(i=>{i._set(t,e)}),this}_shouldSetNestedCoords(){return this.subTargetCheck}removeAll(){return this._activeObjects=[],this.remove(...this._objects)}__objectSelectionMonitor(t,e){let{target:s}=e;const i=this._activeObjects;if(t)i.push(s),this._set("dirty",!0);else if(i.length>0){const n=i.indexOf(s);n>-1&&(i.splice(n,1),this._set("dirty",!0))}}_watchObject(t,e){t&&this._watchObject(!1,e),t?(e.on("selected",this.__objectSelectionTracker),e.on("deselected",this.__objectSelectionDisposer)):(e.off("selected",this.__objectSelectionTracker),e.off("deselected",this.__objectSelectionDisposer))}enterGroup(t,e){t.group&&t.group.remove(t),t._set("parent",this),this._enterGroup(t,e)}_enterGroup(t,e){e&&Ko(t,Nt(Xe(this.calcTransformMatrix()),t.calcTransformMatrix())),this._shouldSetNestedCoords()&&t.setCoords(),t._set("group",this),t._set("canvas",this.canvas),this._watchObject(!0,t);const s=this.canvas&&this.canvas.getActiveObject&&this.canvas.getActiveObject();s&&(s===t||t.isDescendantOf(s))&&this._activeObjects.push(t)}exitGroup(t,e){this._exitGroup(t,e),t._set("parent",void 0),t._set("canvas",void 0)}_exitGroup(t,e){t._set("group",void 0),e||(Ko(t,Nt(this.calcTransformMatrix(),t.calcTransformMatrix())),t.setCoords()),this._watchObject(!1,t);const s=this._activeObjects.length>0?this._activeObjects.indexOf(t):-1;s>-1&&this._activeObjects.splice(s,1)}shouldCache(){const t=pe.prototype.shouldCache.call(this);if(t){for(let e=0;e<this._objects.length;e++)if(this._objects[e].willDrawShadow())return this.ownCaching=!1,!1}return t}willDrawShadow(){if(super.willDrawShadow())return!0;for(let t=0;t<this._objects.length;t++)if(this._objects[t].willDrawShadow())return!0;return!1}isOnACache(){return this.ownCaching||!!this.parent&&this.parent.isOnACache()}drawObject(t,e,s){this._renderBackground(t);for(let n=0;n<this._objects.length;n++){var i;const r=this._objects[n];(i=this.canvas)!==null&&i!==void 0&&i.preserveObjectStacking&&r.group!==this?(t.save(),t.transform(...Xe(this.calcTransformMatrix())),r.render(t),t.restore()):r.group===this&&r.render(t)}this._drawClipPath(t,this.clipPath,s)}setCoords(){super.setCoords(),this._shouldSetNestedCoords()&&this.forEachObject(t=>t.setCoords())}triggerLayout(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.layoutManager.performLayout(E({target:this,type:cu},t))}render(t){this._transformDone=!0,super.render(t),this._transformDone=!1}__serializeObjects(t,e){const s=this.includeDefaultValues;return this._objects.filter(function(i){return!i.excludeFromExport}).map(function(i){const n=i.includeDefaultValues;i.includeDefaultValues=s;const r=i[t||"toObject"](e);return i.includeDefaultValues=n,r})}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const e=this.layoutManager.toObject();return E(E(E({},super.toObject(["subTargetCheck","interactive",...t])),e.strategy!=="fit-content"||this.includeDefaultValues?{layoutManager:e}:{}),{},{objects:this.__serializeObjects("toObject",t)})}toString(){return"#<Group: (".concat(this.complexity(),")>")}dispose(){this.layoutManager.unsubscribeTargets({targets:this.getObjects(),target:this}),this._activeObjects=[],this.forEachObject(t=>{this._watchObject(!1,t),t.dispose()}),super.dispose()}_createSVGBgRect(t){if(!this.backgroundColor)return"";const e=oi.prototype._toSVG.call(this),s=e.indexOf("COMMON_PARTS");e[s]='for="group" ';const i=e.join("");return t?t(i):i}_toSVG(t){const e=["<g ","COMMON_PARTS",` >
40
40
  `],s=this._createSVGBgRect(t);s&&e.push(" ",s);for(let i=0;i<this._objects.length;i++)e.push(" ",this._objects[i].toSVG(t));return e.push(`</g>
41
- `),e}getSvgStyles(){const t=this.opacity!==void 0&&this.opacity!==1?"opacity: ".concat(this.opacity,";"):"",e=this.visible?"":" visibility: hidden;";return[t,this.getSvgFilter(),e].join("")}toClipPathSVG(t){const e=[],s=this._createSVGBgRect(t);s&&e.push(" ",s);for(let i=0;i<this._objects.length;i++)e.push(" ",this._objects[i].toClipPathSVG(t));return this._createBaseClipPathSVGMarkup(e,{reviver:t})}static fromObject(t,e){let{type:s,objects:i=[],layoutManager:n}=t,r=Ct(t,F_);return Promise.all([qo(i,e),Eh(r,e)]).then(o=>{let[h,c]=o;const u=new this(h,E(E(E({},r),c),{},{layoutManager:new I_}));if(n){const d=N.getClass(n.type),f=N.getClass(n.strategy);u.layoutManager=new d(new f)}else u.layoutManager=new Lh;return u.layoutManager.subscribeTargets({type:ji,target:u,targets:u.getObjects()}),u.setCoords(),u})}}A(ai,"type","Group"),A(ai,"ownDefaults",{strokeWidth:0,subTargetCheck:!1,interactive:!1}),N.setClass(ai);const a0=(a,t)=>Math.min(t.width/a.width,t.height/a.height),h0=(a,t)=>Math.max(t.width/a.width,t.height/a.height),zf="\\s*,?\\s*",Fh="".concat(zf,"(").concat(Is,")"),N_="".concat(Fh).concat(Fh).concat(Fh).concat(zf,"([01])").concat(zf,"([01])").concat(Fh).concat(Fh),j_={m:"l",M:"L"},B_=(a,t,e,s,i,n,r,o,h,c,u)=>{const d=Ds(a),f=Os(a),g=Ds(t),p=Os(t),b=e*i*g-s*n*p+r,v=s*i*g+e*n*p+o;return["C",c+h*(-e*i*f-s*n*d),u+h*(-s*i*f+e*n*d),b+h*(e*i*p+s*n*g),v+h*(s*i*p-e*n*g),b,v]},l0=(a,t,e,s)=>{const i=Math.atan2(t,a),n=Math.atan2(s,e);return n>=i?n-i:2*Math.PI-(i-n)};function Vf(a,t,e,s,i,n,r,o){let h;if(ht.cachesBoundsOfCurve&&(h=[...arguments].join(),xh.boundsOfCurveCache[h]))return xh.boundsOfCurveCache[h];const c=Math.sqrt,u=Math.abs,d=[],f=[[0,0],[0,0]];let g=6*a-12*e+6*i,p=-3*a+9*e-9*i+3*r,b=3*e-3*a;for(let S=0;S<2;++S){if(S>0&&(g=6*t-12*s+6*n,p=-3*t+9*s-9*n+3*o,b=3*s-3*t),u(p)<1e-12){if(u(g)<1e-12)continue;const O=-b/g;0<O&&O<1&&d.push(O);continue}const k=g*g-4*b*p;if(k<0)continue;const D=c(k),T=(-g+D)/(2*p);0<T&&T<1&&d.push(T);const M=(-g-D)/(2*p);0<M&&M<1&&d.push(M)}let v=d.length;const _=v,x=u0(a,t,e,s,i,n,r,o);for(;v--;){const{x:S,y:k}=x(d[v]);f[0][v]=S,f[1][v]=k}f[0][_]=a,f[1][_]=t,f[0][_+1]=r,f[1][_+1]=o;const C=[new P(Math.min(...f[0]),Math.min(...f[1])),new P(Math.max(...f[0]),Math.max(...f[1]))];return ht.cachesBoundsOfCurve&&(xh.boundsOfCurveCache[h]=C),C}const H_=(a,t,e)=>{let[s,i,n,r,o,h,c,u]=e;const d=((f,g,p,b,v,_,x)=>{if(p===0||b===0)return[];let C=0,S=0,k=0;const D=Math.PI,T=x*rf,M=Os(T),O=Ds(T),R=.5*(-O*f-M*g),L=.5*(-O*g+M*f),W=p**2,U=b**2,G=L**2,at=R**2,F=W*U-W*G-U*at;let z=Math.abs(p),rt=Math.abs(b);if(F<0){const Pi=Math.sqrt(1-F/(W*U));z*=Pi,rt*=Pi}else k=(v===_?-1:1)*Math.sqrt(F/(W*G+U*at));const Gt=k*z*L/rt,te=-k*rt*R/z,fe=O*Gt-M*te+.5*f,Yt=M*Gt+O*te+.5*g;let St=l0(1,0,(R-Gt)/z,(L-te)/rt),He=l0((R-Gt)/z,(L-te)/rt,(-R-Gt)/z,(-L-te)/rt);_===0&&He>0?He-=2*D:_===1&&He<0&&(He+=2*D);const Mi=Math.ceil(Math.abs(He/D*2)),Ft=[],ft=He/Mi,fr=8/3*Math.sin(ft/4)*Math.sin(ft/4)/Math.sin(ft/2);let ph=St+ft;for(let Pi=0;Pi<Mi;Pi++)Ft[Pi]=B_(St,ph,O,M,z,rt,fe,Yt,fr,C,S),C=Ft[Pi][5],S=Ft[Pi][6],St=ph,ph+=ft;return Ft})(c-a,u-t,i,n,o,h,r);for(let f=0,g=d.length;f<g;f++)d[f][1]+=a,d[f][2]+=t,d[f][3]+=a,d[f][4]+=t,d[f][5]+=a,d[f][6]+=t;return d},c0=a=>{let t=0,e=0,s=0,i=0;const n=[];let r,o=0,h=0;for(const c of a){const u=[...c];let d;switch(u[0]){case"l":u[1]+=t,u[2]+=e;case"L":t=u[1],e=u[2],d=["L",t,e];break;case"h":u[1]+=t;case"H":t=u[1],d=["L",t,e];break;case"v":u[1]+=e;case"V":e=u[1],d=["L",t,e];break;case"m":u[1]+=t,u[2]+=e;case"M":t=u[1],e=u[2],s=u[1],i=u[2],d=["M",t,e];break;case"c":u[1]+=t,u[2]+=e,u[3]+=t,u[4]+=e,u[5]+=t,u[6]+=e;case"C":o=u[3],h=u[4],t=u[5],e=u[6],d=["C",u[1],u[2],o,h,t,e];break;case"s":u[1]+=t,u[2]+=e,u[3]+=t,u[4]+=e;case"S":r==="C"?(o=2*t-o,h=2*e-h):(o=t,h=e),t=u[3],e=u[4],d=["C",o,h,u[1],u[2],t,e],o=d[3],h=d[4];break;case"q":u[1]+=t,u[2]+=e,u[3]+=t,u[4]+=e;case"Q":o=u[1],h=u[2],t=u[3],e=u[4],d=["Q",o,h,t,e];break;case"t":u[1]+=t,u[2]+=e;case"T":r==="Q"?(o=2*t-o,h=2*e-h):(o=t,h=e),t=u[1],e=u[2],d=["Q",o,h,t,e];break;case"a":u[6]+=t,u[7]+=e;case"A":H_(t,e,u).forEach(f=>n.push(f)),t=u[6],e=u[7];break;case"z":case"Z":t=s,e=i,d=["Z"]}d?(n.push(d),r=d[0]):r=""}return n},du=(a,t,e,s)=>Math.sqrt((e-a)**2+(s-t)**2),u0=(a,t,e,s,i,n,r,o)=>h=>{const c=h**3,u=(g=>3*g**2*(1-g))(h),d=(g=>3*g*(1-g)**2)(h),f=(g=>(1-g)**3)(h);return new P(r*c+i*u+e*d+a*f,o*c+n*u+s*d+t*f)},d0=a=>a**2,f0=a=>2*a*(1-a),g0=a=>(1-a)**2,G_=(a,t,e,s,i,n,r,o)=>h=>{const c=d0(h),u=f0(h),d=g0(h),f=3*(d*(e-a)+u*(i-e)+c*(r-i)),g=3*(d*(s-t)+u*(n-s)+c*(o-n));return Math.atan2(g,f)},z_=(a,t,e,s,i,n)=>r=>{const o=d0(r),h=f0(r),c=g0(r);return new P(i*o+e*h+a*c,n*o+s*h+t*c)},V_=(a,t,e,s,i,n)=>r=>{const o=1-r,h=2*(o*(e-a)+r*(i-e)),c=2*(o*(s-t)+r*(n-s));return Math.atan2(c,h)},p0=(a,t,e)=>{let s=new P(t,e),i=0;for(let n=1;n<=100;n+=1){const r=a(n/100);i+=du(s.x,s.y,r.x,r.y),s=r}return i},X_=(a,t)=>{let e,s=0,i=0,n={x:a.x,y:a.y},r=E({},n),o=.01,h=0;const c=a.iterator,u=a.angleFinder;for(;i<t&&o>1e-4;)r=c(s),h=s,e=du(n.x,n.y,r.x,r.y),e+i>t?(s-=o,o/=2):(n=r,s+=o,i+=e);return E(E({},r),{},{angle:u(h)})},Xf=a=>{let t,e,s=0,i=0,n=0,r=0,o=0;const h=[];for(const c of a){const u={x:i,y:n,command:c[0],length:0};switch(c[0]){case"M":e=u,e.x=r=i=c[1],e.y=o=n=c[2];break;case"L":e=u,e.length=du(i,n,c[1],c[2]),i=c[1],n=c[2];break;case"C":t=u0(i,n,c[1],c[2],c[3],c[4],c[5],c[6]),e=u,e.iterator=t,e.angleFinder=G_(i,n,c[1],c[2],c[3],c[4],c[5],c[6]),e.length=p0(t,i,n),i=c[5],n=c[6];break;case"Q":t=z_(i,n,c[1],c[2],c[3],c[4]),e=u,e.iterator=t,e.angleFinder=V_(i,n,c[1],c[2],c[3],c[4]),e.length=p0(t,i,n),i=c[3],n=c[4];break;case"Z":e=u,e.destX=r,e.destY=o,e.length=du(i,n,r,o),i=r,n=o}s+=e.length,h.push(e)}return h.push({length:s,x:i,y:n}),h},m0=function(a,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Xf(a),s=0;for(;t-e[s].length>0&&s<e.length-2;)t-=e[s].length,s++;const i=e[s],n=t/i.length,r=a[s];switch(i.command){case"M":return{x:i.x,y:i.y,angle:0};case"Z":return E(E({},new P(i.x,i.y).lerp(new P(i.destX,i.destY),n)),{},{angle:Math.atan2(i.destY-i.y,i.destX-i.x)});case"L":return E(E({},new P(i.x,i.y).lerp(new P(r[1],r[2]),n)),{},{angle:Math.atan2(r[2]-i.y,r[1]-i.x)});case"C":case"Q":return X_(i,t)}},W_=new RegExp("[mzlhvcsqta][^mzlhvcsqta]*","gi"),b0=new RegExp(N_,"g"),U_=new RegExp(Is,"gi"),Y_={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},y0=a=>{var t;const e=[],s=(t=a.match(W_))!==null&&t!==void 0?t:[];for(const i of s){const n=i[0];if(n==="z"||n==="Z"){e.push([n]);continue}const r=Y_[n.toLowerCase()];let o=[];if(n==="a"||n==="A"){b0.lastIndex=0;for(let h=null;h=b0.exec(i);)o.push(...h.slice(1))}else o=i.match(U_)||[];for(let h=0;h<o.length;h+=r){const c=new Array(r),u=j_[n];c[0]=h>0&&u?u:n;for(let d=0;d<r;d++)c[d+1]=parseFloat(o[h+d]);e.push(c)}}return e},$_=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,e=new P(a[0]),s=new P(a[1]),i=1,n=0;const r=[],o=a.length,h=o>2;let c;for(h&&(i=a[2].x<s.x?-1:a[2].x===s.x?0:1,n=a[2].y<s.y?-1:a[2].y===s.y?0:1),r.push(["M",e.x-i*t,e.y-n*t]),c=1;c<o;c++){if(!e.eq(s)){const u=e.midPointFrom(s);r.push(["Q",e.x,e.y,u.x,u.y])}e=a[c],c+1<a.length&&(s=a[c+1])}return h&&(i=e.x>a[c-2].x?1:e.x===a[c-2].x?0:-1,n=e.y>a[c-2].y?1:e.y===a[c-2].y?0:-1),r.push(["L",e.x+i*t,e.y+n*t]),r},v0=(a,t)=>a.map(e=>e.map((s,i)=>i===0||t===void 0?s:At(s,t)).join(" ")).join(" ");function fu(a,t){const e=a.style;e&&t&&(typeof t=="string"?e.cssText+=";"+t:Object.entries(t).forEach(s=>{let[i,n]=s;return e.setProperty(i,n)}))}const q_=(a,t)=>Math.floor(Math.random()*(t-a+1))+a;function _0(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const e=t.onComplete||pr,s=new(Bc()).XMLHttpRequest,i=t.signal,n=function(){s.abort()},r=function(){i&&i.removeEventListener("abort",n),s.onerror=s.ontimeout=pr};if(i&&i.aborted)throw new sf("request");return i&&i.addEventListener("abort",n,{once:!0}),s.onreadystatechange=function(){s.readyState===4&&(r(),e(s),s.onreadystatechange=pr)},s.onerror=s.ontimeout=r,s.open("get",a,!0),s.send(),s}const gu=(a,t)=>{let e=a._findCenterFromElement();a.transformMatrix&&((s=>{if(s.transformMatrix){const{scaleX:i,scaleY:n,angle:r,skewX:o}=br(s.transformMatrix);s.flipX=!1,s.flipY=!1,s.set(Me,i),s.set(Je,n),s.angle=r,s.skewX=o,s.skewY=0}})(a),e=e.transform(a.transformMatrix)),delete a.transformMatrix,t&&(a.scaleX*=t.scaleX,a.scaleY*=t.scaleY,a.cropX=t.cropX,a.cropY=t.cropY,e.x+=t.offsetLeft,e.y+=t.offsetTop,a.width=t.width,a.height=t.height),a.setPositionByOrigin(e,Q,Q)};var K_=Object.freeze({__proto__:null,addTransformToObject:gm,animate:Lf,animateColor:Lm,applyTransformToObject:Ko,calcAngleBetweenVectors:eu,calcDimensionsMatrix:Ah,calcPlaneChangeMatrix:Dh,calcVectorRotation:Em,cancelAnimFrame:Kp,capValue:wr,composeMatrix:em,copyCanvasElement:a=>{var t;const e=Rs(a);return(t=e.getContext("2d"))===null||t===void 0||t.drawImage(a,0,0),e},cos:Ds,createCanvasElement:ms,createImage:Qp,createRotateMatrix:$o,createScaleMatrix:Yc,createSkewXMatrix:gf,createSkewYMatrix:pf,createTranslateMatrix:Yo,createVector:Zc,crossProduct:Qo,degreesToRadians:Rt,dotProduct:km,ease:jv,enlivenObjectEnlivables:Eh,enlivenObjects:qo,findScaleToCover:h0,findScaleToFit:a0,getBoundsOfCurve:Vf,getOrthonormalVector:kf,getPathSegmentsInfo:Xf,getPointOnPath:m0,getPointer:fm,getRandomInt:q_,getRegularPolygonPath:(a,t)=>{const e=2*Math.PI/a;let s=-An;a%2==0&&(s+=e/2);const i=new Array(a+1);for(let n=0;n<a;n++){const r=n*e+s,{x:o,y:h}=new P(Ds(r),Os(r)).scalarMultiply(t);i[n]=[n===0?"M":"L",o,h]}return i[a]=["Z"],i},getSmoothPathFromPoints:$_,getSvgAttributes:a=>{const t=["instantiated_by_use","style","id","class"];switch(a){case"linearGradient":return t.concat(["x1","y1","x2","y2","gradientUnits","gradientTransform"]);case"radialGradient":return t.concat(["gradientUnits","gradientTransform","cx","cy","r","fx","fy","fr"]);case"stop":return t.concat(["offset","stop-color","stop-opacity"])}return t},getUnitVector:su,groupSVGElements:(a,t)=>a&&a.length===1?a[0]:new ai(a,t),hasStyleChanged:au,invertTransform:Xe,isBetweenVectors:Mf,isIdentityMatrix:Jp,isTouchEvent:qc,isTransparent:Vm,joinPath:v0,loadImage:Th,magnitude:tu,makeBoundingBoxFromPoints:ri,makePathSimpler:c0,matrixToSVG:kh,mergeClipPaths:(a,t)=>{var e;let s=a,i=t;s.inverted&&!i.inverted&&(s=t,i=a),xf(i,(e=i.group)===null||e===void 0?void 0:e.calcTransformMatrix(),s.calcTransformMatrix());const n=s.inverted&&i.inverted;return n&&(s.inverted=i.inverted=!1),new ai([s],{clipPath:i,inverted:n})},multiplyTransformMatrices:Nt,multiplyTransformMatrixArray:Uc,parsePath:y0,parsePreserveAspectRatioAttribute:yf,parseUnit:De,pick:yr,projectStrokeOnPoints:Um,qrDecompose:br,radiansToDegrees:kn,removeFromArray:mr,removeTransformFromObject:(a,t)=>{const e=Xe(t),s=Nt(e,a.calcOwnMatrix());Ko(a,s)},removeTransformMatrixForSvgParsing:gu,request:_0,requestAnimFrame:Ch,resetObjectTransform:pm,rotatePoint:(a,t,e)=>a.rotate(e,t),rotateVector:Ef,saveObjectTransform:wf,sendObjectToPlane:xf,sendPointToPlane:_r,sendVectorToPlane:mm,setStyle:fu,sin:Os,sizeAfterTransform:Kc,string:d_,stylesFromArray:qm,stylesToArray:$m,toBlob:ff,toDataURL:df,toFixed:At,transformPath:(a,t,e)=>(e&&(t=Nt(t,[1,0,0,1,-e.x,-e.y])),a.map(s=>{const i=[...s];for(let n=1;n<s.length-1;n+=2){const{x:r,y:o}=ge({x:s[n],y:s[n+1]},t);i[n]=r,i[n+1]=o}return i})),transformPoint:ge});class Q_ extends dm{constructor(t){let{allowTouchScrolling:e=!1,containerClass:s=""}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(t),A(this,"upper",void 0),A(this,"container",void 0);const{el:i}=this.lower,n=this.createUpperCanvas();this.upper={el:n,ctx:n.getContext("2d")},this.applyCanvasStyle(i,{allowTouchScrolling:e}),this.applyCanvasStyle(n,{allowTouchScrolling:e,styles:{position:"absolute",left:"0",top:"0"}});const r=this.createContainerElement();r.classList.add(s),i.parentNode&&i.parentNode.replaceChild(r,i),r.append(i,n),this.container=r}createUpperCanvas(){const{el:t}=this.lower,e=ms();return e.className=t.className,e.classList.remove("lower-canvas"),e.classList.add("upper-canvas"),e.setAttribute("data-fabric","top"),e.style.cssText=t.style.cssText,e.setAttribute("draggable","true"),e}createContainerElement(){const t=Vo().createElement("div");return t.setAttribute("data-fabric","wrapper"),fu(t,{position:"relative"}),um(t),t}applyCanvasStyle(t,e){const{styles:s,allowTouchScrolling:i}=e;fu(t,E(E({},s),{},{"touch-action":i?"manipulation":ke})),um(t)}setDimensions(t,e){super.setDimensions(t,e);const{el:s,ctx:i}=this.upper;cm(s,i,t,e)}setCSSDimensions(t){super.setCSSDimensions(t),vf(this.upper.el,t),vf(this.container,t)}cleanupDOM(t){const e=this.container,{el:s}=this.lower,{el:i}=this.upper;super.cleanupDOM(t),e.removeChild(i),e.removeChild(s),e.parentNode&&e.parentNode.replaceChild(s,e)}dispose(){super.dispose(),ni().dispose(this.upper.el),delete this.upper,delete this.container}}class pu extends Ph{constructor(){super(...arguments),A(this,"targets",[]),A(this,"_hoveredTargets",[]),A(this,"_objectsToRender",void 0),A(this,"_currentTransform",null),A(this,"_groupSelector",null),A(this,"contextTopDirty",!1)}static getDefaults(){return E(E({},super.getDefaults()),pu.ownDefaults)}get upperCanvasEl(){var t;return(t=this.elements.upper)===null||t===void 0?void 0:t.el}get contextTop(){var t;return(t=this.elements.upper)===null||t===void 0?void 0:t.ctx}get wrapperEl(){return this.elements.container}initElements(t){this.elements=new Q_(t,{allowTouchScrolling:this.allowTouchScrolling,containerClass:this.containerClass}),this._createCacheCanvas()}_onObjectAdded(t){this._objectsToRender=void 0,super._onObjectAdded(t)}_onObjectRemoved(t){this._objectsToRender=void 0,t===this._activeObject&&(this.fire("before:selection:cleared",{deselected:[t]}),this._discardActiveObject(),this.fire("selection:cleared",{deselected:[t]}),t.fire("deselected",{target:t})),t===this._hoveredTarget&&(this._hoveredTarget=void 0,this._hoveredTargets=[]),super._onObjectRemoved(t)}_onStackOrderChanged(){this._objectsToRender=void 0,super._onStackOrderChanged()}_chooseObjectsToRender(){const t=this._activeObject;return!this.preserveObjectStacking&&t?this._objects.filter(e=>!e.group&&e!==t).concat(t):this._objects}renderAll(){this.cancelRequestedRender(),this.destroyed||(!this.contextTopDirty||this._groupSelector||this.isDrawingMode||(this.clearContext(this.contextTop),this.contextTopDirty=!1),this.hasLostContext&&(this.renderTopLayer(this.contextTop),this.hasLostContext=!1),!this._objectsToRender&&(this._objectsToRender=this._chooseObjectsToRender()),this.renderCanvas(this.getContext(),this._objectsToRender))}renderTopLayer(t){t.save(),this.isDrawingMode&&this._isCurrentlyDrawing&&(this.freeDrawingBrush&&this.freeDrawingBrush._render(),this.contextTopDirty=!0),this.selection&&this._groupSelector&&(this._drawSelection(t),this.contextTopDirty=!0),t.restore()}renderTop(){const t=this.contextTop;this.clearContext(t),this.renderTopLayer(t),this.fire("after:render",{ctx:t})}setTargetFindTolerance(t){t=Math.round(t),this.targetFindTolerance=t;const e=this.getRetinaScaling(),s=Math.ceil((2*t+1)*e);this.pixelFindCanvasEl.width=this.pixelFindCanvasEl.height=s,this.pixelFindContext.scale(e,e)}isTargetTransparent(t,e,s){const i=this.targetFindTolerance,n=this.pixelFindContext;this.clearContext(n),n.save(),n.translate(-e+i,-s+i),n.transform(...this.viewportTransform);const r=t.selectionBackgroundColor;t.selectionBackgroundColor="",t.render(n),t.selectionBackgroundColor=r,n.restore();const o=Math.round(i*this.getRetinaScaling());return Vm(n,o,o,o)}_isSelectionKeyPressed(t){const e=this.selectionKey;return!!e&&(Array.isArray(e)?!!e.find(s=>!!s&&t[s]===!0):t[e])}_shouldClearSelection(t,e){const s=this.getActiveObjects(),i=this._activeObject;return!!(!e||e&&i&&s.length>1&&s.indexOf(e)===-1&&i!==e&&!this._isSelectionKeyPressed(t)||e&&!e.evented||e&&!e.selectable&&i&&i!==e)}_shouldCenterTransform(t,e,s){if(!t)return;let i;return e===zc||e===Me||e===Je||e===Sh?i=this.centeredScaling||t.centeredScaling:e===lf&&(i=this.centeredRotation||t.centeredRotation),i?!s:s}_getOriginFromCorner(t,e){const s={x:t.originX,y:t.originY};return e&&(["ml","tl","bl"].includes(e)?s.x=It:["mr","tr","br"].includes(e)&&(s.x=dt),["tl","mt","tr"].includes(e)?s.y=af:["bl","mb","br"].includes(e)&&(s.y=Ve)),s}_setupCurrentTransform(t,e,s){var i;const n=e.group?_r(this.getScenePoint(t),void 0,e.group.calcTransformMatrix()):this.getScenePoint(t),{key:r="",control:o}=e.getActiveControl()||{},h=s&&o?(i=o.getActionHandler(t,e,o))===null||i===void 0?void 0:i.bind(o):Pv,c=((g,p,b,v)=>{if(!p||!g)return"drag";const _=v.controls[p];return _.getActionName(b,_,v)})(s,r,t,e),u=t[this.centeredKey],d=this._shouldCenterTransform(e,c,u)?{x:Q,y:Q}:this._getOriginFromCorner(e,r),f={target:e,action:c,actionHandler:h,actionPerformed:!1,corner:r,scaleX:e.scaleX,scaleY:e.scaleY,skewX:e.skewX,skewY:e.skewY,offsetX:n.x-e.left,offsetY:n.y-e.top,originX:d.x,originY:d.y,ex:n.x,ey:n.y,lastX:n.x,lastY:n.y,theta:Rt(e.angle),width:e.width,height:e.height,shiftKey:t.shiftKey,altKey:u,original:E(E({},wf(e)),{},{originX:d.x,originY:d.y})};this._currentTransform=f,this.fire("before:transform",{e:t,transform:f})}setCursor(t){this.upperCanvasEl.style.cursor=t}_drawSelection(t){const{x:e,y:s,deltaX:i,deltaY:n}=this._groupSelector,r=new P(e,s).transform(this.viewportTransform),o=new P(e+i,s+n).transform(this.viewportTransform),h=this.selectionLineWidth/2;let c=Math.min(r.x,o.x),u=Math.min(r.y,o.y),d=Math.max(r.x,o.x),f=Math.max(r.y,o.y);this.selectionColor&&(t.fillStyle=this.selectionColor,t.fillRect(c,u,d-c,f-u)),this.selectionLineWidth&&this.selectionBorderColor&&(t.lineWidth=this.selectionLineWidth,t.strokeStyle=this.selectionBorderColor,c+=h,u+=h,d-=h,f-=h,pe.prototype._setLineDash.call(this,t,this.selectionDashArray),t.strokeRect(c,u,d-c,f-u))}findTarget(t){if(this.skipTargetFind)return;const e=this.getViewportPoint(t),s=this._activeObject,i=this.getActiveObjects();if(this.targets=[],s&&i.length>=1){if(s.findControl(e,qc(t))||i.length>1&&this.searchPossibleTargets([s],e))return s;if(s===this.searchPossibleTargets([s],e)){if(this.preserveObjectStacking){const n=this.targets;this.targets=[];const r=this.searchPossibleTargets(this._objects,e);return t[this.altSelectionKey]&&r&&r!==s?(this.targets=n,s):r}return s}}return this.searchPossibleTargets(this._objects,e)}_pointIsInObjectSelectionArea(t,e){let s=t.getCoords();const i=this.getZoom(),n=t.padding/i;if(n){const[r,o,h,c]=s,u=Math.atan2(o.y-r.y,o.x-r.x),d=Ds(u)*n,f=Os(u)*n,g=d+f,p=d-f;s=[new P(r.x-p,r.y-g),new P(o.x+g,o.y-p),new P(h.x+p,h.y+g),new P(c.x-g,c.y+p)]}return Mt.isPointInPolygon(e,s)}_checkTarget(t,e){return!!(t&&t.visible&&t.evented&&this._pointIsInObjectSelectionArea(t,_r(e,void 0,this.viewportTransform))&&(!this.perPixelTargetFind&&!t.perPixelTargetFind||t.isEditing||!this.isTargetTransparent(t,e.x,e.y)))}_searchPossibleTargets(t,e){let s=t.length;for(;s--;){const i=t[s];if(this._checkTarget(i,e)){if(Wc(i)&&i.subTargetCheck){const n=this._searchPossibleTargets(i._objects,e);n&&this.targets.push(n)}return i}}}searchPossibleTargets(t,e){const s=this._searchPossibleTargets(t,e);if(s&&Wc(s)&&s.interactive&&this.targets[0]){const i=this.targets;for(let n=i.length-1;n>0;n--){const r=i[n];if(!Wc(r)||!r.interactive)return r}return i[0]}return s}getViewportPoint(t){return this._pointer?this._pointer:this.getPointer(t,!0)}getScenePoint(t){return this._absolutePointer?this._absolutePointer:this.getPointer(t)}getPointer(t){let e=arguments.length>1&&arguments[1]!==void 0&&arguments[1];const s=this.upperCanvasEl,i=s.getBoundingClientRect();let n=fm(t),r=i.width||0,o=i.height||0;r&&o||(Ve in i&&af in i&&(o=Math.abs(i.top-i.bottom)),It in i&&dt in i&&(r=Math.abs(i.right-i.left))),this.calcOffset(),n.x=n.x-this._offset.left,n.y=n.y-this._offset.top,e||(n=_r(n,void 0,this.viewportTransform));const h=this.getRetinaScaling();h!==1&&(n.x/=h,n.y/=h);const c=r===0||o===0?new P(1,1):new P(s.width/r,s.height/o);return n.multiply(c)}_setDimensionsImpl(t,e){this._resetTransformEventData(),super._setDimensionsImpl(t,e),this._isCurrentlyDrawing&&this.freeDrawingBrush&&this.freeDrawingBrush._setBrushStyles(this.contextTop)}_createCacheCanvas(){this.pixelFindCanvasEl=ms(),this.pixelFindContext=this.pixelFindCanvasEl.getContext("2d",{willReadFrequently:!0}),this.setTargetFindTolerance(this.targetFindTolerance)}getTopContext(){return this.elements.upper.ctx}getSelectionContext(){return this.elements.upper.ctx}getSelectionElement(){return this.elements.upper.el}getActiveObject(){return this._activeObject}getActiveObjects(){const t=this._activeObject;return vr(t)?t.getObjects():t?[t]:[]}_fireSelectionEvents(t,e){let s=!1,i=!1;const n=this.getActiveObjects(),r=[],o=[];t.forEach(h=>{n.includes(h)||(s=!0,h.fire("deselected",{e,target:h}),o.push(h))}),n.forEach(h=>{t.includes(h)||(s=!0,h.fire("selected",{e,target:h}),r.push(h))}),t.length>0&&n.length>0?(i=!0,s&&this.fire("selection:updated",{e,selected:r,deselected:o})):n.length>0?(i=!0,this.fire("selection:created",{e,selected:r})):t.length>0&&(i=!0,this.fire("selection:cleared",{e,deselected:o})),i&&(this._objectsToRender=void 0)}setActiveObject(t,e){const s=this.getActiveObjects(),i=this._setActiveObject(t,e);return this._fireSelectionEvents(s,e),i}_setActiveObject(t,e){const s=this._activeObject;return s!==t&&!(!this._discardActiveObject(e,t)&&this._activeObject)&&!t.onSelect({e})&&(this._activeObject=t,vr(t)&&s!==t&&t.set("canvas",this),t.setCoords(),!0)}_discardActiveObject(t,e){const s=this._activeObject;return!!s&&!s.onDeselect({e:t,object:e})&&(this._currentTransform&&this._currentTransform.target===s&&this.endCurrentTransform(t),vr(s)&&s===this._hoveredTarget&&(this._hoveredTarget=void 0),this._activeObject=void 0,!0)}discardActiveObject(t){const e=this.getActiveObjects(),s=this.getActiveObject();e.length&&this.fire("before:selection:cleared",{e:t,deselected:[s]});const i=this._discardActiveObject(t);return this._fireSelectionEvents(e,t),i}endCurrentTransform(t){const e=this._currentTransform;this._finalizeCurrentTransform(t),e&&e.target&&(e.target.isMoving=!1),this._currentTransform=null}_finalizeCurrentTransform(t){const e=this._currentTransform,s=e.target,i={e:t,target:s,transform:e,action:e.action};s._scaling&&(s._scaling=!1),s.setCoords(),e.actionPerformed&&(this.fire("object:modified",i),s.fire(Vc,i))}setViewportTransform(t){super.setViewportTransform(t);const e=this._activeObject;e&&e.setCoords()}destroy(){const t=this._activeObject;vr(t)&&(t.removeAll(),t.dispose()),delete this._activeObject,super.destroy(),this.pixelFindContext=null,this.pixelFindCanvasEl=void 0}clear(){this.discardActiveObject(),this._activeObject=void 0,this.clearContext(this.contextTop),super.clear()}drawControls(t){const e=this._activeObject;e&&e._renderControls(t)}_toObject(t,e,s){const i=this._realizeGroupTransformOnObject(t),n=super._toObject(t,e,s);return t.set(i),n}_realizeGroupTransformOnObject(t){const{group:e}=t;if(e&&vr(e)&&this._activeObject===e){const s=yr(t,["angle","flipX","flipY",dt,Me,Je,Xo,Wo,Ve]);return gm(t,e.calcOwnMatrix()),s}return{}}_setSVGObject(t,e,s){const i=this._realizeGroupTransformOnObject(e);super._setSVGObject(t,e,s),e.set(i)}}A(pu,"ownDefaults",{uniformScaling:!0,uniScaleKey:"shiftKey",centeredScaling:!1,centeredRotation:!1,centeredKey:"altKey",altActionKey:"shiftKey",selection:!0,selectionKey:"shiftKey",selectionColor:"rgba(100, 100, 255, 0.3)",selectionDashArray:[],selectionBorderColor:"rgba(255, 255, 255, 0.3)",selectionLineWidth:1,selectionFullyContained:!1,hoverCursor:"move",moveCursor:"move",defaultCursor:"default",freeDrawingCursor:"crosshair",notAllowedCursor:"not-allowed",perPixelTargetFind:!1,targetFindTolerance:0,skipTargetFind:!1,stopContextMenu:!1,fireRightClick:!1,fireMiddleClick:!1,enablePointerEvents:!1,containerClass:"canvas-container",preserveObjectStacking:!1});class J_{constructor(t){A(this,"targets",[]),A(this,"__disposer",void 0);const e=()=>{const{hiddenTextarea:i}=t.getActiveObject()||{};i&&i.focus()},s=t.upperCanvasEl;s.addEventListener("click",e),this.__disposer=()=>s.removeEventListener("click",e)}exitTextEditing(){this.target=void 0,this.targets.forEach(t=>{t.isEditing&&t.exitEditing()})}add(t){this.targets.push(t)}remove(t){this.unregister(t),mr(this.targets,t)}register(t){this.target=t}unregister(t){t===this.target&&(this.target=void 0)}onMouseMove(t){var e;!((e=this.target)===null||e===void 0)&&e.isEditing&&this.target.updateSelectionOnMouseMove(t)}clear(){this.targets=[],this.target=void 0}dispose(){this.clear(),this.__disposer(),delete this.__disposer}}const Z_=["target","oldTarget","fireCanvas","e"],Ze={passive:!1},sa=(a,t)=>{const e=a.getViewportPoint(t),s=a.getScenePoint(t);return{viewportPoint:e,scenePoint:s,pointer:e,absolutePointer:s}},Pn=function(a){for(var t=arguments.length,e=new Array(t>1?t-1:0),s=1;s<t;s++)e[s-1]=arguments[s];return a.addEventListener(...e)},ys=function(a){for(var t=arguments.length,e=new Array(t>1?t-1:0),s=1;s<t;s++)e[s-1]=arguments[s];return a.removeEventListener(...e)},tw={mouse:{in:"over",out:"out",targetIn:"mouseover",targetOut:"mouseout",canvasIn:"mouse:over",canvasOut:"mouse:out"},drag:{in:"enter",out:"leave",targetIn:"dragenter",targetOut:"dragleave",canvasIn:"drag:enter",canvasOut:"drag:leave"}};class Wf extends pu{constructor(t){super(t,arguments.length>1&&arguments[1]!==void 0?arguments[1]:{}),A(this,"_isClick",void 0),A(this,"textEditingManager",new J_(this)),["_onMouseDown","_onTouchStart","_onMouseMove","_onMouseUp","_onTouchEnd","_onResize","_onMouseWheel","_onMouseOut","_onMouseEnter","_onContextMenu","_onDoubleClick","_onDragStart","_onDragEnd","_onDragProgress","_onDragOver","_onDragEnter","_onDragLeave","_onDrop"].forEach(e=>{this[e]=this[e].bind(this)}),this.addOrRemove(Pn,"add")}_getEventPrefix(){return this.enablePointerEvents?"pointer":"mouse"}addOrRemove(t,e){const s=this.upperCanvasEl,i=this._getEventPrefix();t(lm(s),"resize",this._onResize),t(s,i+"down",this._onMouseDown),t(s,"".concat(i,"move"),this._onMouseMove,Ze),t(s,"".concat(i,"out"),this._onMouseOut),t(s,"".concat(i,"enter"),this._onMouseEnter),t(s,"wheel",this._onMouseWheel),t(s,"contextmenu",this._onContextMenu),t(s,"dblclick",this._onDoubleClick),t(s,"dragstart",this._onDragStart),t(s,"dragend",this._onDragEnd),t(s,"dragover",this._onDragOver),t(s,"dragenter",this._onDragEnter),t(s,"dragleave",this._onDragLeave),t(s,"drop",this._onDrop),this.enablePointerEvents||t(s,"touchstart",this._onTouchStart,Ze)}removeListeners(){this.addOrRemove(ys,"remove");const t=this._getEventPrefix(),e=Ls(this.upperCanvasEl);ys(e,"".concat(t,"up"),this._onMouseUp),ys(e,"touchend",this._onTouchEnd,Ze),ys(e,"".concat(t,"move"),this._onMouseMove,Ze),ys(e,"touchmove",this._onMouseMove,Ze),clearTimeout(this._willAddMouseDown)}_onMouseWheel(t){this.__onMouseWheel(t)}_onMouseOut(t){const e=this._hoveredTarget,s=E({e:t},sa(this,t));this.fire("mouse:out",E(E({},s),{},{target:e})),this._hoveredTarget=void 0,e&&e.fire("mouseout",E({},s)),this._hoveredTargets.forEach(i=>{this.fire("mouse:out",E(E({},s),{},{target:i})),i&&i.fire("mouseout",E({},s))}),this._hoveredTargets=[]}_onMouseEnter(t){this._currentTransform||this.findTarget(t)||(this.fire("mouse:over",E({e:t},sa(this,t))),this._hoveredTarget=void 0,this._hoveredTargets=[])}_onDragStart(t){this._isClick=!1;const e=this.getActiveObject();if(e&&e.onDragStart(t)){this._dragSource=e;const s={e:t,target:e};return this.fire("dragstart",s),e.fire("dragstart",s),void Pn(this.upperCanvasEl,"drag",this._onDragProgress)}_f(t)}_renderDragEffects(t,e,s){let i=!1;const n=this._dropTarget;n&&n!==e&&n!==s&&(n.clearContextTop(),i=!0),e==null||e.clearContextTop(),s!==e&&(s==null||s.clearContextTop());const r=this.contextTop;r.save(),r.transform(...this.viewportTransform),e&&(r.save(),e.transform(r),e.renderDragSourceEffect(t),r.restore(),i=!0),s&&(r.save(),s.transform(r),s.renderDropTargetEffect(t),r.restore(),i=!0),r.restore(),i&&(this.contextTopDirty=!0)}_onDragEnd(t){const e=!!t.dataTransfer&&t.dataTransfer.dropEffect!==ke,s=e?this._activeObject:void 0,i={e:t,target:this._dragSource,subTargets:this.targets,dragSource:this._dragSource,didDrop:e,dropTarget:s};ys(this.upperCanvasEl,"drag",this._onDragProgress),this.fire("dragend",i),this._dragSource&&this._dragSource.fire("dragend",i),delete this._dragSource,this._onMouseUp(t)}_onDragProgress(t){const e={e:t,target:this._dragSource,dragSource:this._dragSource,dropTarget:this._draggedoverTarget};this.fire("drag",e),this._dragSource&&this._dragSource.fire("drag",e)}findDragTargets(t){return this.targets=[],{target:this._searchPossibleTargets(this._objects,this.getViewportPoint(t)),targets:[...this.targets]}}_onDragOver(t){const e="dragover",{target:s,targets:i}=this.findDragTargets(t),n=this._dragSource,r={e:t,target:s,subTargets:i,dragSource:n,canDrop:!1,dropTarget:void 0};let o;this.fire(e,r),this._fireEnterLeaveEvents(s,r),s&&(s.canDrop(t)&&(o=s),s.fire(e,r));for(let h=0;h<i.length;h++){const c=i[h];c.canDrop(t)&&(o=c),c.fire(e,r)}this._renderDragEffects(t,n,o),this._dropTarget=o}_onDragEnter(t){const{target:e,targets:s}=this.findDragTargets(t),i={e:t,target:e,subTargets:s,dragSource:this._dragSource};this.fire("dragenter",i),this._fireEnterLeaveEvents(e,i)}_onDragLeave(t){const e={e:t,target:this._draggedoverTarget,subTargets:this.targets,dragSource:this._dragSource};this.fire("dragleave",e),this._fireEnterLeaveEvents(void 0,e),this._renderDragEffects(t,this._dragSource),this._dropTarget=void 0,this.targets=[],this._hoveredTargets=[]}_onDrop(t){const{target:e,targets:s}=this.findDragTargets(t),i=this._basicEventHandler("drop:before",E({e:t,target:e,subTargets:s,dragSource:this._dragSource},sa(this,t)));i.didDrop=!1,i.dropTarget=void 0,this._basicEventHandler("drop",i),this.fire("drop:after",i)}_onContextMenu(t){const e=this.findTarget(t),s=this.targets||[],i=this._basicEventHandler("contextmenu:before",{e:t,target:e,subTargets:s});return this.stopContextMenu&&_f(t),this._basicEventHandler("contextmenu",i),!1}_onDoubleClick(t){this._cacheTransformEventData(t),this._handleEvent(t,"dblclick"),this._resetTransformEventData()}getPointerId(t){const e=t.changedTouches;return e?e[0]&&e[0].identifier:this.enablePointerEvents?t.pointerId:-1}_isMainEvent(t){return t.isPrimary===!0||t.isPrimary!==!1&&(t.type==="touchend"&&t.touches.length===0||!t.changedTouches||t.changedTouches[0].identifier===this.mainTouchId)}_onTouchStart(t){let e=!this.allowTouchScrolling;const s=this._activeObject;this.mainTouchId===void 0&&(this.mainTouchId=this.getPointerId(t)),this.__onMouseDown(t),(this.isDrawingMode||s&&this._target===s)&&(e=!0),e&&t.preventDefault(),this._resetTransformEventData();const i=this.upperCanvasEl,n=this._getEventPrefix(),r=Ls(i);Pn(r,"touchend",this._onTouchEnd,Ze),e&&Pn(r,"touchmove",this._onMouseMove,Ze),ys(i,"".concat(n,"down"),this._onMouseDown)}_onMouseDown(t){this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();ys(e,"".concat(s,"move"),this._onMouseMove,Ze);const i=Ls(e);Pn(i,"".concat(s,"up"),this._onMouseUp),Pn(i,"".concat(s,"move"),this._onMouseMove,Ze)}_onTouchEnd(t){if(t.touches.length>0)return;this.__onMouseUp(t),this._resetTransformEventData(),delete this.mainTouchId;const e=this._getEventPrefix(),s=Ls(this.upperCanvasEl);ys(s,"touchend",this._onTouchEnd,Ze),ys(s,"touchmove",this._onMouseMove,Ze),this._willAddMouseDown&&clearTimeout(this._willAddMouseDown),this._willAddMouseDown=setTimeout(()=>{Pn(this.upperCanvasEl,"".concat(e,"down"),this._onMouseDown),this._willAddMouseDown=0},400)}_onMouseUp(t){this.__onMouseUp(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();if(this._isMainEvent(t)){const i=Ls(this.upperCanvasEl);ys(i,"".concat(s,"up"),this._onMouseUp),ys(i,"".concat(s,"move"),this._onMouseMove,Ze),Pn(e,"".concat(s,"move"),this._onMouseMove,Ze)}}_onMouseMove(t){const e=this.getActiveObject();!this.allowTouchScrolling&&(!e||!e.shouldStartDragging(t))&&t.preventDefault&&t.preventDefault(),this.__onMouseMove(t)}_onResize(){this.calcOffset(),this._resetTransformEventData()}_shouldRender(t){const e=this.getActiveObject();return!!e!=!!t||e&&t&&e!==t}__onMouseUp(t){var e;this._cacheTransformEventData(t),this._handleEvent(t,"up:before");const s=this._currentTransform,i=this._isClick,n=this._target,{button:r}=t;if(r)return(this.fireMiddleClick&&r===1||this.fireRightClick&&r===2)&&this._handleEvent(t,"up"),void this._resetTransformEventData();if(this.isDrawingMode&&this._isCurrentlyDrawing)return void this._onMouseUpInDrawingMode(t);if(!this._isMainEvent(t))return;let o,h,c=!1;if(s&&(this._finalizeCurrentTransform(t),c=s.actionPerformed),!i){const u=n===this._activeObject;this.handleSelection(t),c||(c=this._shouldRender(n)||!u&&n===this._activeObject)}if(n){const u=n.findControl(this.getViewportPoint(t),qc(t)),{key:d,control:f}=u||{};if(h=d,n.selectable&&n!==this._activeObject&&n.activeOn==="up")this.setActiveObject(n,t),c=!0;else if(f){const g=f.getMouseUpHandler(t,n,f);g&&(o=this.getScenePoint(t),g.call(f,t,s,o.x,o.y))}n.isMoving=!1}if(s&&(s.target!==n||s.corner!==h)){const u=s.target&&s.target.controls[s.corner],d=u&&u.getMouseUpHandler(t,s.target,u);o=o||this.getScenePoint(t),d&&d.call(u,t,s,o.x,o.y)}this._setCursorFromEvent(t,n),this._handleEvent(t,"up"),this._groupSelector=null,this._currentTransform=null,n&&(n.__corner=void 0),c?this.requestRenderAll():i||(e=this._activeObject)!==null&&e!==void 0&&e.isEditing||this.renderTop()}_basicEventHandler(t,e){const{target:s,subTargets:i=[]}=e;this.fire(t,e),s&&s.fire(t,e);for(let n=0;n<i.length;n++)i[n]!==s&&i[n].fire(t,e);return e}_handleEvent(t,e){const s=this._target,i=this.targets||[],n=E(E({e:t,target:s,subTargets:i},sa(this,t)),{},{transform:this._currentTransform},e==="up:before"||e==="up"?{isClick:this._isClick,currentTarget:this.findTarget(t),currentSubTargets:this.targets}:{});this.fire("mouse:".concat(e),n),s&&s.fire("mouse".concat(e),n);for(let r=0;r<i.length;r++)i[r]!==s&&i[r].fire("mouse".concat(e),n)}_onMouseDownInDrawingMode(t){this._isCurrentlyDrawing=!0,this.getActiveObject()&&(this.discardActiveObject(t),this.requestRenderAll());const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseDown(e,{e:t,pointer:e}),this._handleEvent(t,"down")}_onMouseMoveInDrawingMode(t){if(this._isCurrentlyDrawing){const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseMove(e,{e:t,pointer:e})}this.setCursor(this.freeDrawingCursor),this._handleEvent(t,"move")}_onMouseUpInDrawingMode(t){const e=this.getScenePoint(t);this.freeDrawingBrush?this._isCurrentlyDrawing=!!this.freeDrawingBrush.onMouseUp({e:t,pointer:e}):this._isCurrentlyDrawing=!1,this._handleEvent(t,"up")}__onMouseDown(t){this._isClick=!0,this._cacheTransformEventData(t),this._handleEvent(t,"down:before");let e=this._target;const{button:s}=t;if(s)return(this.fireMiddleClick&&s===1||this.fireRightClick&&s===2)&&this._handleEvent(t,"down"),void this._resetTransformEventData();if(this.isDrawingMode)return void this._onMouseDownInDrawingMode(t);if(!this._isMainEvent(t)||this._currentTransform)return;let i=this._shouldRender(e),n=!1;if(this.handleMultiSelection(t,e)?(e=this._activeObject,n=!0,i=!0):this._shouldClearSelection(t,e)&&this.discardActiveObject(t),this.selection&&(!e||!e.selectable&&!e.isEditing&&e!==this._activeObject)){const r=this.getScenePoint(t);this._groupSelector={x:r.x,y:r.y,deltaY:0,deltaX:0}}if(e){const r=e===this._activeObject;e.selectable&&e.activeOn==="down"&&this.setActiveObject(e,t);const o=e.findControl(this.getViewportPoint(t),qc(t));if(e===this._activeObject&&(o||!n)){this._setupCurrentTransform(t,e,r);const h=o?o.control:void 0,c=this.getScenePoint(t),u=h&&h.getMouseDownHandler(t,e,h);u&&u.call(h,t,this._currentTransform,c.x,c.y)}}i&&(this._objectsToRender=void 0),this._handleEvent(t,"down"),i&&this.requestRenderAll()}_resetTransformEventData(){this._target=this._pointer=this._absolutePointer=void 0}_cacheTransformEventData(t){this._resetTransformEventData(),this._pointer=this.getViewportPoint(t),this._absolutePointer=_r(this._pointer,void 0,this.viewportTransform),this._target=this._currentTransform?this._currentTransform.target:this.findTarget(t)}__onMouseMove(t){if(this._isClick=!1,this._cacheTransformEventData(t),this._handleEvent(t,"move:before"),this.isDrawingMode)return void this._onMouseMoveInDrawingMode(t);if(!this._isMainEvent(t))return;const e=this._groupSelector;if(e){const s=this.getScenePoint(t);e.deltaX=s.x-e.x,e.deltaY=s.y-e.y,this.renderTop()}else if(this._currentTransform)this._transformObject(t);else{const s=this.findTarget(t);this._setCursorFromEvent(t,s),this._fireOverOutEvents(t,s)}this.textEditingManager.onMouseMove(t),this._handleEvent(t,"move"),this._resetTransformEventData()}_fireOverOutEvents(t,e){const s=this._hoveredTarget,i=this._hoveredTargets,n=this.targets,r=Math.max(i.length,n.length);this.fireSyntheticInOutEvents("mouse",{e:t,target:e,oldTarget:s,fireCanvas:!0});for(let o=0;o<r;o++)this.fireSyntheticInOutEvents("mouse",{e:t,target:n[o],oldTarget:i[o]});this._hoveredTarget=e,this._hoveredTargets=this.targets.concat()}_fireEnterLeaveEvents(t,e){const s=this._draggedoverTarget,i=this._hoveredTargets,n=this.targets,r=Math.max(i.length,n.length);this.fireSyntheticInOutEvents("drag",E(E({},e),{},{target:t,oldTarget:s,fireCanvas:!0}));for(let o=0;o<r;o++)this.fireSyntheticInOutEvents("drag",E(E({},e),{},{target:n[o],oldTarget:i[o]}));this._draggedoverTarget=t}fireSyntheticInOutEvents(t,e){let{target:s,oldTarget:i,fireCanvas:n,e:r}=e,o=Ct(e,Z_);const{targetIn:h,targetOut:c,canvasIn:u,canvasOut:d}=tw[t],f=i!==s;if(i&&f){const g=E(E({},o),{},{e:r,target:i,nextTarget:s},sa(this,r));n&&this.fire(d,g),i.fire(c,g)}if(s&&f){const g=E(E({},o),{},{e:r,target:s,previousTarget:i},sa(this,r));n&&this.fire(u,g),s.fire(h,g)}}__onMouseWheel(t){this._cacheTransformEventData(t),this._handleEvent(t,"wheel"),this._resetTransformEventData()}_transformObject(t){const e=this.getScenePoint(t),s=this._currentTransform,i=s.target,n=i.group?_r(e,void 0,i.group.calcTransformMatrix()):e;s.shiftKey=t.shiftKey,s.altKey=!!this.centeredKey&&t[this.centeredKey],this._performTransformAction(t,s,n),s.actionPerformed&&this.requestRenderAll()}_performTransformAction(t,e,s){const{action:i,actionHandler:n,target:r}=e,o=!!n&&n(t,e,s.x,s.y);o&&r.setCoords(),i==="drag"&&o&&(e.target.isMoving=!0,this.setCursor(e.target.moveCursor||this.moveCursor)),e.actionPerformed=e.actionPerformed||o}_setCursorFromEvent(t,e){if(!e)return void this.setCursor(this.defaultCursor);let s=e.hoverCursor||this.hoverCursor;const i=vr(this._activeObject)?this._activeObject:null,n=(!i||e.group!==i)&&e.findControl(this.getViewportPoint(t));if(n){const r=n.control;this.setCursor(r.cursorStyleHandler(t,r,e))}else e.subTargetCheck&&this.targets.concat().reverse().map(r=>{s=r.hoverCursor||s}),this.setCursor(s)}handleMultiSelection(t,e){const s=this._activeObject,i=vr(s);if(s&&this._isSelectionKeyPressed(t)&&this.selection&&e&&e.selectable&&(s!==e||i)&&(i||!e.isDescendantOf(s)&&!s.isDescendantOf(e))&&!e.onSelect({e:t})&&!s.getActiveControl()){if(i){const n=s.getObjects();if(e===s){const r=this.getViewportPoint(t);if(!(e=this.searchPossibleTargets(n,r)||this.searchPossibleTargets(this._objects,r))||!e.selectable)return!1}e.group===s?(s.remove(e),this._hoveredTarget=e,this._hoveredTargets=[...this.targets],s.size()===1&&this._setActiveObject(s.item(0),t)):(s.multiSelectAdd(e),this._hoveredTarget=s,this._hoveredTargets=[...this.targets]),this._fireSelectionEvents(n,t)}else{s.isEditing&&s.exitEditing();const n=new(N.getClass("ActiveSelection"))([],{canvas:this});n.multiSelectAdd(s,e),this._hoveredTarget=n,this._setActiveObject(n,t),this._fireSelectionEvents([s],t)}return!0}return!1}handleSelection(t){if(!this.selection||!this._groupSelector)return!1;const{x:e,y:s,deltaX:i,deltaY:n}=this._groupSelector,r=new P(e,s),o=r.add(new P(i,n)),h=r.min(o),c=r.max(o).subtract(h),u=this.collectObjects({left:h.x,top:h.y,width:c.x,height:c.y},{includeIntersecting:!this.selectionFullyContained}),d=r.eq(o)?u[0]?[u[0]]:[]:u.length>1?u.filter(f=>!f.onSelect({e:t})).reverse():u;if(d.length===1)this.setActiveObject(d[0],t);else if(d.length>1){const f=N.getClass("ActiveSelection");this.setActiveObject(new f(d,{canvas:this}),t)}return this._groupSelector=null,!0}clear(){this.textEditingManager.clear(),super.clear()}destroy(){this.removeListeners(),this.textEditingManager.dispose(),super.destroy()}}const w0={x1:0,y1:0,x2:0,y2:0},ew=E(E({},w0),{},{r1:0,r2:0}),ia=(a,t)=>isNaN(a)&&typeof t=="number"?t:a,sw=/^(\d+\.\d+)%|(\d+)%$/;function x0(a){return a&&sw.test(a)}function S0(a,t){const e=typeof a=="number"?a:typeof a=="string"?parseFloat(a)/(x0(a)?100:1):NaN;return wr(0,ia(e,t),1)}const iw=/\s*;\s*/,nw=/\s*:\s*/;function rw(a,t){let e,s;const i=a.getAttribute("style");if(i){const r=i.split(iw);r[r.length-1]===""&&r.pop();for(let o=r.length;o--;){const[h,c]=r[o].split(nw).map(u=>u.trim());h==="stop-color"?e=c:h==="stop-opacity"&&(s=c)}}const n=new gt(e||a.getAttribute("stop-color")||"rgb(0,0,0)");return{offset:S0(a.getAttribute("offset"),0),color:n.toRgb(),opacity:ia(parseFloat(s||a.getAttribute("stop-opacity")||""),1)*n.getAlpha()*t}}function ow(a,t){const e=[],s=a.getElementsByTagName("stop"),i=S0(t,1);for(let n=s.length;n--;)e.push(rw(s[n],i));return e}function C0(a){return a.nodeName==="linearGradient"||a.nodeName==="LINEARGRADIENT"?"linear":"radial"}function A0(a){return a.getAttribute("gradientUnits")==="userSpaceOnUse"?"pixels":"percentage"}function js(a,t){return a.getAttribute(t)}function aw(a,t){return function(e,s){let i,{width:n,height:r,gradientUnits:o}=s;return Object.keys(e).reduce((h,c)=>{const u=e[c];return u==="Infinity"?i=1:u==="-Infinity"?i=0:(i=typeof u=="string"?parseFloat(u):u,typeof u=="string"&&x0(u)&&(i*=.01,o==="pixels"&&(c!=="x1"&&c!=="x2"&&c!=="r2"||(i*=n),c!=="y1"&&c!=="y2"||(i*=r)))),h[c]=i,h},{})}(C0(a)==="linear"?function(e){return{x1:js(e,"x1")||0,y1:js(e,"y1")||0,x2:js(e,"x2")||"100%",y2:js(e,"y2")||0}}(a):function(e){return{x1:js(e,"fx")||js(e,"cx")||"50%",y1:js(e,"fy")||js(e,"cy")||"50%",r1:0,x2:js(e,"cx")||"50%",y2:js(e,"cy")||"50%",r2:js(e,"r")||"50%"}}(a),E(E({},t),{},{gradientUnits:A0(a)}))}class Ih{constructor(t){const{type:e="linear",gradientUnits:s="pixels",coords:i={},colorStops:n=[],offsetX:r=0,offsetY:o=0,gradientTransform:h,id:c}=t||{};Object.assign(this,{type:e,gradientUnits:s,coords:E(E({},e==="radial"?ew:w0),i),colorStops:n,offsetX:r,offsetY:o,gradientTransform:h,id:c?"".concat(c,"_").concat(En()):En()})}addColorStop(t){for(const e in t){const s=new gt(t[e]);this.colorStops.push({offset:parseFloat(e),color:s.toRgb(),opacity:s.getAlpha()})}return this}toObject(t){return E(E({},yr(this,t)),{},{type:this.type,coords:E({},this.coords),colorStops:this.colorStops.map(e=>E({},e)),offsetX:this.offsetX,offsetY:this.offsetY,gradientUnits:this.gradientUnits,gradientTransform:this.gradientTransform?[...this.gradientTransform]:void 0})}toSVG(t){let{additionalTransform:e}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const s=[],i=this.gradientTransform?this.gradientTransform.concat():Ee.concat(),n=this.gradientUnits==="pixels"?"userSpaceOnUse":"objectBoundingBox",r=this.colorStops.map(d=>E({},d)).sort((d,f)=>d.offset-f.offset);let o=-this.offsetX,h=-this.offsetY;var c;n==="objectBoundingBox"?(o/=t.width,h/=t.height):(o+=t.width/2,h+=t.height/2),(c=t)&&typeof c._renderPathCommands=="function"&&this.gradientUnits!=="percentage"&&(o-=t.pathOffset.x,h-=t.pathOffset.y),i[4]-=o,i[5]-=h;const u=['id="SVGID_'.concat(this.id,'"'),'gradientUnits="'.concat(n,'"'),'gradientTransform="'.concat(e?e+" ":"").concat(kh(i),'"'),""].join(" ");if(this.type==="linear"){const{x1:d,y1:f,x2:g,y2:p}=this.coords;s.push("<linearGradient ",u,' x1="',d,'" y1="',f,'" x2="',g,'" y2="',p,`">
41
+ `),e}getSvgStyles(){const t=this.opacity!==void 0&&this.opacity!==1?"opacity: ".concat(this.opacity,";"):"",e=this.visible?"":" visibility: hidden;";return[t,this.getSvgFilter(),e].join("")}toClipPathSVG(t){const e=[],s=this._createSVGBgRect(t);s&&e.push(" ",s);for(let i=0;i<this._objects.length;i++)e.push(" ",this._objects[i].toClipPathSVG(t));return this._createBaseClipPathSVGMarkup(e,{reviver:t})}static fromObject(t,e){let{type:s,objects:i=[],layoutManager:n}=t,r=Ct(t,F_);return Promise.all([qo(i,e),Eh(r,e)]).then(o=>{let[h,c]=o;const u=new this(h,E(E(E({},r),c),{},{layoutManager:new I_}));if(n){const d=N.getClass(n.type),f=N.getClass(n.strategy);u.layoutManager=new d(new f)}else u.layoutManager=new Lh;return u.layoutManager.subscribeTargets({type:ji,target:u,targets:u.getObjects()}),u.setCoords(),u})}}T(ai,"type","Group"),T(ai,"ownDefaults",{strokeWidth:0,subTargetCheck:!1,interactive:!1}),N.setClass(ai);const a0=(a,t)=>Math.min(t.width/a.width,t.height/a.height),h0=(a,t)=>Math.max(t.width/a.width,t.height/a.height),zf="\\s*,?\\s*",Fh="".concat(zf,"(").concat(Is,")"),N_="".concat(Fh).concat(Fh).concat(Fh).concat(zf,"([01])").concat(zf,"([01])").concat(Fh).concat(Fh),j_={m:"l",M:"L"},B_=(a,t,e,s,i,n,r,o,h,c,u)=>{const d=Ds(a),f=Os(a),g=Ds(t),p=Os(t),b=e*i*g-s*n*p+r,v=s*i*g+e*n*p+o;return["C",c+h*(-e*i*f-s*n*d),u+h*(-s*i*f+e*n*d),b+h*(e*i*p+s*n*g),v+h*(s*i*p-e*n*g),b,v]},l0=(a,t,e,s)=>{const i=Math.atan2(t,a),n=Math.atan2(s,e);return n>=i?n-i:2*Math.PI-(i-n)};function Vf(a,t,e,s,i,n,r,o){let h;if(ht.cachesBoundsOfCurve&&(h=[...arguments].join(),xh.boundsOfCurveCache[h]))return xh.boundsOfCurveCache[h];const c=Math.sqrt,u=Math.abs,d=[],f=[[0,0],[0,0]];let g=6*a-12*e+6*i,p=-3*a+9*e-9*i+3*r,b=3*e-3*a;for(let S=0;S<2;++S){if(S>0&&(g=6*t-12*s+6*n,p=-3*t+9*s-9*n+3*o,b=3*s-3*t),u(p)<1e-12){if(u(g)<1e-12)continue;const O=-b/g;0<O&&O<1&&d.push(O);continue}const k=g*g-4*b*p;if(k<0)continue;const D=c(k),A=(-g+D)/(2*p);0<A&&A<1&&d.push(A);const M=(-g-D)/(2*p);0<M&&M<1&&d.push(M)}let v=d.length;const _=v,x=u0(a,t,e,s,i,n,r,o);for(;v--;){const{x:S,y:k}=x(d[v]);f[0][v]=S,f[1][v]=k}f[0][_]=a,f[1][_]=t,f[0][_+1]=r,f[1][_+1]=o;const C=[new P(Math.min(...f[0]),Math.min(...f[1])),new P(Math.max(...f[0]),Math.max(...f[1]))];return ht.cachesBoundsOfCurve&&(xh.boundsOfCurveCache[h]=C),C}const H_=(a,t,e)=>{let[s,i,n,r,o,h,c,u]=e;const d=((f,g,p,b,v,_,x)=>{if(p===0||b===0)return[];let C=0,S=0,k=0;const D=Math.PI,A=x*rf,M=Os(A),O=Ds(A),R=.5*(-O*f-M*g),L=.5*(-O*g+M*f),V=p**2,U=b**2,G=L**2,at=R**2,F=V*U-V*G-U*at;let z=Math.abs(p),rt=Math.abs(b);if(F<0){const Pi=Math.sqrt(1-F/(V*U));z*=Pi,rt*=Pi}else k=(v===_?-1:1)*Math.sqrt(F/(V*G+U*at));const Gt=k*z*L/rt,te=-k*rt*R/z,fe=O*Gt-M*te+.5*f,Yt=M*Gt+O*te+.5*g;let St=l0(1,0,(R-Gt)/z,(L-te)/rt),He=l0((R-Gt)/z,(L-te)/rt,(-R-Gt)/z,(-L-te)/rt);_===0&&He>0?He-=2*D:_===1&&He<0&&(He+=2*D);const Mi=Math.ceil(Math.abs(He/D*2)),Ft=[],ft=He/Mi,fr=8/3*Math.sin(ft/4)*Math.sin(ft/4)/Math.sin(ft/2);let ph=St+ft;for(let Pi=0;Pi<Mi;Pi++)Ft[Pi]=B_(St,ph,O,M,z,rt,fe,Yt,fr,C,S),C=Ft[Pi][5],S=Ft[Pi][6],St=ph,ph+=ft;return Ft})(c-a,u-t,i,n,o,h,r);for(let f=0,g=d.length;f<g;f++)d[f][1]+=a,d[f][2]+=t,d[f][3]+=a,d[f][4]+=t,d[f][5]+=a,d[f][6]+=t;return d},c0=a=>{let t=0,e=0,s=0,i=0;const n=[];let r,o=0,h=0;for(const c of a){const u=[...c];let d;switch(u[0]){case"l":u[1]+=t,u[2]+=e;case"L":t=u[1],e=u[2],d=["L",t,e];break;case"h":u[1]+=t;case"H":t=u[1],d=["L",t,e];break;case"v":u[1]+=e;case"V":e=u[1],d=["L",t,e];break;case"m":u[1]+=t,u[2]+=e;case"M":t=u[1],e=u[2],s=u[1],i=u[2],d=["M",t,e];break;case"c":u[1]+=t,u[2]+=e,u[3]+=t,u[4]+=e,u[5]+=t,u[6]+=e;case"C":o=u[3],h=u[4],t=u[5],e=u[6],d=["C",u[1],u[2],o,h,t,e];break;case"s":u[1]+=t,u[2]+=e,u[3]+=t,u[4]+=e;case"S":r==="C"?(o=2*t-o,h=2*e-h):(o=t,h=e),t=u[3],e=u[4],d=["C",o,h,u[1],u[2],t,e],o=d[3],h=d[4];break;case"q":u[1]+=t,u[2]+=e,u[3]+=t,u[4]+=e;case"Q":o=u[1],h=u[2],t=u[3],e=u[4],d=["Q",o,h,t,e];break;case"t":u[1]+=t,u[2]+=e;case"T":r==="Q"?(o=2*t-o,h=2*e-h):(o=t,h=e),t=u[1],e=u[2],d=["Q",o,h,t,e];break;case"a":u[6]+=t,u[7]+=e;case"A":H_(t,e,u).forEach(f=>n.push(f)),t=u[6],e=u[7];break;case"z":case"Z":t=s,e=i,d=["Z"]}d?(n.push(d),r=d[0]):r=""}return n},du=(a,t,e,s)=>Math.sqrt((e-a)**2+(s-t)**2),u0=(a,t,e,s,i,n,r,o)=>h=>{const c=h**3,u=(g=>3*g**2*(1-g))(h),d=(g=>3*g*(1-g)**2)(h),f=(g=>(1-g)**3)(h);return new P(r*c+i*u+e*d+a*f,o*c+n*u+s*d+t*f)},d0=a=>a**2,f0=a=>2*a*(1-a),g0=a=>(1-a)**2,G_=(a,t,e,s,i,n,r,o)=>h=>{const c=d0(h),u=f0(h),d=g0(h),f=3*(d*(e-a)+u*(i-e)+c*(r-i)),g=3*(d*(s-t)+u*(n-s)+c*(o-n));return Math.atan2(g,f)},z_=(a,t,e,s,i,n)=>r=>{const o=d0(r),h=f0(r),c=g0(r);return new P(i*o+e*h+a*c,n*o+s*h+t*c)},V_=(a,t,e,s,i,n)=>r=>{const o=1-r,h=2*(o*(e-a)+r*(i-e)),c=2*(o*(s-t)+r*(n-s));return Math.atan2(c,h)},p0=(a,t,e)=>{let s=new P(t,e),i=0;for(let n=1;n<=100;n+=1){const r=a(n/100);i+=du(s.x,s.y,r.x,r.y),s=r}return i},X_=(a,t)=>{let e,s=0,i=0,n={x:a.x,y:a.y},r=E({},n),o=.01,h=0;const c=a.iterator,u=a.angleFinder;for(;i<t&&o>1e-4;)r=c(s),h=s,e=du(n.x,n.y,r.x,r.y),e+i>t?(s-=o,o/=2):(n=r,s+=o,i+=e);return E(E({},r),{},{angle:u(h)})},Xf=a=>{let t,e,s=0,i=0,n=0,r=0,o=0;const h=[];for(const c of a){const u={x:i,y:n,command:c[0],length:0};switch(c[0]){case"M":e=u,e.x=r=i=c[1],e.y=o=n=c[2];break;case"L":e=u,e.length=du(i,n,c[1],c[2]),i=c[1],n=c[2];break;case"C":t=u0(i,n,c[1],c[2],c[3],c[4],c[5],c[6]),e=u,e.iterator=t,e.angleFinder=G_(i,n,c[1],c[2],c[3],c[4],c[5],c[6]),e.length=p0(t,i,n),i=c[5],n=c[6];break;case"Q":t=z_(i,n,c[1],c[2],c[3],c[4]),e=u,e.iterator=t,e.angleFinder=V_(i,n,c[1],c[2],c[3],c[4]),e.length=p0(t,i,n),i=c[3],n=c[4];break;case"Z":e=u,e.destX=r,e.destY=o,e.length=du(i,n,r,o),i=r,n=o}s+=e.length,h.push(e)}return h.push({length:s,x:i,y:n}),h},m0=function(a,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Xf(a),s=0;for(;t-e[s].length>0&&s<e.length-2;)t-=e[s].length,s++;const i=e[s],n=t/i.length,r=a[s];switch(i.command){case"M":return{x:i.x,y:i.y,angle:0};case"Z":return E(E({},new P(i.x,i.y).lerp(new P(i.destX,i.destY),n)),{},{angle:Math.atan2(i.destY-i.y,i.destX-i.x)});case"L":return E(E({},new P(i.x,i.y).lerp(new P(r[1],r[2]),n)),{},{angle:Math.atan2(r[2]-i.y,r[1]-i.x)});case"C":case"Q":return X_(i,t)}},W_=new RegExp("[mzlhvcsqta][^mzlhvcsqta]*","gi"),b0=new RegExp(N_,"g"),U_=new RegExp(Is,"gi"),Y_={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},y0=a=>{var t;const e=[],s=(t=a.match(W_))!==null&&t!==void 0?t:[];for(const i of s){const n=i[0];if(n==="z"||n==="Z"){e.push([n]);continue}const r=Y_[n.toLowerCase()];let o=[];if(n==="a"||n==="A"){b0.lastIndex=0;for(let h=null;h=b0.exec(i);)o.push(...h.slice(1))}else o=i.match(U_)||[];for(let h=0;h<o.length;h+=r){const c=new Array(r),u=j_[n];c[0]=h>0&&u?u:n;for(let d=0;d<r;d++)c[d+1]=parseFloat(o[h+d]);e.push(c)}}return e},$_=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,e=new P(a[0]),s=new P(a[1]),i=1,n=0;const r=[],o=a.length,h=o>2;let c;for(h&&(i=a[2].x<s.x?-1:a[2].x===s.x?0:1,n=a[2].y<s.y?-1:a[2].y===s.y?0:1),r.push(["M",e.x-i*t,e.y-n*t]),c=1;c<o;c++){if(!e.eq(s)){const u=e.midPointFrom(s);r.push(["Q",e.x,e.y,u.x,u.y])}e=a[c],c+1<a.length&&(s=a[c+1])}return h&&(i=e.x>a[c-2].x?1:e.x===a[c-2].x?0:-1,n=e.y>a[c-2].y?1:e.y===a[c-2].y?0:-1),r.push(["L",e.x+i*t,e.y+n*t]),r},v0=(a,t)=>a.map(e=>e.map((s,i)=>i===0||t===void 0?s:At(s,t)).join(" ")).join(" ");function fu(a,t){const e=a.style;e&&t&&(typeof t=="string"?e.cssText+=";"+t:Object.entries(t).forEach(s=>{let[i,n]=s;return e.setProperty(i,n)}))}const q_=(a,t)=>Math.floor(Math.random()*(t-a+1))+a;function _0(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const e=t.onComplete||pr,s=new(Bc()).XMLHttpRequest,i=t.signal,n=function(){s.abort()},r=function(){i&&i.removeEventListener("abort",n),s.onerror=s.ontimeout=pr};if(i&&i.aborted)throw new sf("request");return i&&i.addEventListener("abort",n,{once:!0}),s.onreadystatechange=function(){s.readyState===4&&(r(),e(s),s.onreadystatechange=pr)},s.onerror=s.ontimeout=r,s.open("get",a,!0),s.send(),s}const gu=(a,t)=>{let e=a._findCenterFromElement();a.transformMatrix&&((s=>{if(s.transformMatrix){const{scaleX:i,scaleY:n,angle:r,skewX:o}=br(s.transformMatrix);s.flipX=!1,s.flipY=!1,s.set(Me,i),s.set(Je,n),s.angle=r,s.skewX=o,s.skewY=0}})(a),e=e.transform(a.transformMatrix)),delete a.transformMatrix,t&&(a.scaleX*=t.scaleX,a.scaleY*=t.scaleY,a.cropX=t.cropX,a.cropY=t.cropY,e.x+=t.offsetLeft,e.y+=t.offsetTop,a.width=t.width,a.height=t.height),a.setPositionByOrigin(e,Q,Q)};var K_=Object.freeze({__proto__:null,addTransformToObject:gm,animate:Lf,animateColor:Lm,applyTransformToObject:Ko,calcAngleBetweenVectors:eu,calcDimensionsMatrix:Ah,calcPlaneChangeMatrix:Dh,calcVectorRotation:Em,cancelAnimFrame:Kp,capValue:wr,composeMatrix:em,copyCanvasElement:a=>{var t;const e=Rs(a);return(t=e.getContext("2d"))===null||t===void 0||t.drawImage(a,0,0),e},cos:Ds,createCanvasElement:ms,createImage:Qp,createRotateMatrix:$o,createScaleMatrix:Yc,createSkewXMatrix:gf,createSkewYMatrix:pf,createTranslateMatrix:Yo,createVector:Zc,crossProduct:Qo,degreesToRadians:Rt,dotProduct:km,ease:jv,enlivenObjectEnlivables:Eh,enlivenObjects:qo,findScaleToCover:h0,findScaleToFit:a0,getBoundsOfCurve:Vf,getOrthonormalVector:kf,getPathSegmentsInfo:Xf,getPointOnPath:m0,getPointer:fm,getRandomInt:q_,getRegularPolygonPath:(a,t)=>{const e=2*Math.PI/a;let s=-An;a%2==0&&(s+=e/2);const i=new Array(a+1);for(let n=0;n<a;n++){const r=n*e+s,{x:o,y:h}=new P(Ds(r),Os(r)).scalarMultiply(t);i[n]=[n===0?"M":"L",o,h]}return i[a]=["Z"],i},getSmoothPathFromPoints:$_,getSvgAttributes:a=>{const t=["instantiated_by_use","style","id","class"];switch(a){case"linearGradient":return t.concat(["x1","y1","x2","y2","gradientUnits","gradientTransform"]);case"radialGradient":return t.concat(["gradientUnits","gradientTransform","cx","cy","r","fx","fy","fr"]);case"stop":return t.concat(["offset","stop-color","stop-opacity"])}return t},getUnitVector:su,groupSVGElements:(a,t)=>a&&a.length===1?a[0]:new ai(a,t),hasStyleChanged:au,invertTransform:Xe,isBetweenVectors:Mf,isIdentityMatrix:Jp,isTouchEvent:qc,isTransparent:Vm,joinPath:v0,loadImage:Th,magnitude:tu,makeBoundingBoxFromPoints:ri,makePathSimpler:c0,matrixToSVG:kh,mergeClipPaths:(a,t)=>{var e;let s=a,i=t;s.inverted&&!i.inverted&&(s=t,i=a),xf(i,(e=i.group)===null||e===void 0?void 0:e.calcTransformMatrix(),s.calcTransformMatrix());const n=s.inverted&&i.inverted;return n&&(s.inverted=i.inverted=!1),new ai([s],{clipPath:i,inverted:n})},multiplyTransformMatrices:Nt,multiplyTransformMatrixArray:Uc,parsePath:y0,parsePreserveAspectRatioAttribute:yf,parseUnit:De,pick:yr,projectStrokeOnPoints:Um,qrDecompose:br,radiansToDegrees:kn,removeFromArray:mr,removeTransformFromObject:(a,t)=>{const e=Xe(t),s=Nt(e,a.calcOwnMatrix());Ko(a,s)},removeTransformMatrixForSvgParsing:gu,request:_0,requestAnimFrame:Ch,resetObjectTransform:pm,rotatePoint:(a,t,e)=>a.rotate(e,t),rotateVector:Ef,saveObjectTransform:wf,sendObjectToPlane:xf,sendPointToPlane:_r,sendVectorToPlane:mm,setStyle:fu,sin:Os,sizeAfterTransform:Kc,string:d_,stylesFromArray:qm,stylesToArray:$m,toBlob:ff,toDataURL:df,toFixed:At,transformPath:(a,t,e)=>(e&&(t=Nt(t,[1,0,0,1,-e.x,-e.y])),a.map(s=>{const i=[...s];for(let n=1;n<s.length-1;n+=2){const{x:r,y:o}=ge({x:s[n],y:s[n+1]},t);i[n]=r,i[n+1]=o}return i})),transformPoint:ge});class Q_ extends dm{constructor(t){let{allowTouchScrolling:e=!1,containerClass:s=""}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(t),T(this,"upper",void 0),T(this,"container",void 0);const{el:i}=this.lower,n=this.createUpperCanvas();this.upper={el:n,ctx:n.getContext("2d")},this.applyCanvasStyle(i,{allowTouchScrolling:e}),this.applyCanvasStyle(n,{allowTouchScrolling:e,styles:{position:"absolute",left:"0",top:"0"}});const r=this.createContainerElement();r.classList.add(s),i.parentNode&&i.parentNode.replaceChild(r,i),r.append(i,n),this.container=r}createUpperCanvas(){const{el:t}=this.lower,e=ms();return e.className=t.className,e.classList.remove("lower-canvas"),e.classList.add("upper-canvas"),e.setAttribute("data-fabric","top"),e.style.cssText=t.style.cssText,e.setAttribute("draggable","true"),e}createContainerElement(){const t=Vo().createElement("div");return t.setAttribute("data-fabric","wrapper"),fu(t,{position:"relative"}),um(t),t}applyCanvasStyle(t,e){const{styles:s,allowTouchScrolling:i}=e;fu(t,E(E({},s),{},{"touch-action":i?"manipulation":ke})),um(t)}setDimensions(t,e){super.setDimensions(t,e);const{el:s,ctx:i}=this.upper;cm(s,i,t,e)}setCSSDimensions(t){super.setCSSDimensions(t),vf(this.upper.el,t),vf(this.container,t)}cleanupDOM(t){const e=this.container,{el:s}=this.lower,{el:i}=this.upper;super.cleanupDOM(t),e.removeChild(i),e.removeChild(s),e.parentNode&&e.parentNode.replaceChild(s,e)}dispose(){super.dispose(),ni().dispose(this.upper.el),delete this.upper,delete this.container}}class pu extends Ph{constructor(){super(...arguments),T(this,"targets",[]),T(this,"_hoveredTargets",[]),T(this,"_objectsToRender",void 0),T(this,"_currentTransform",null),T(this,"_groupSelector",null),T(this,"contextTopDirty",!1)}static getDefaults(){return E(E({},super.getDefaults()),pu.ownDefaults)}get upperCanvasEl(){var t;return(t=this.elements.upper)===null||t===void 0?void 0:t.el}get contextTop(){var t;return(t=this.elements.upper)===null||t===void 0?void 0:t.ctx}get wrapperEl(){return this.elements.container}initElements(t){this.elements=new Q_(t,{allowTouchScrolling:this.allowTouchScrolling,containerClass:this.containerClass}),this._createCacheCanvas()}_onObjectAdded(t){this._objectsToRender=void 0,super._onObjectAdded(t)}_onObjectRemoved(t){this._objectsToRender=void 0,t===this._activeObject&&(this.fire("before:selection:cleared",{deselected:[t]}),this._discardActiveObject(),this.fire("selection:cleared",{deselected:[t]}),t.fire("deselected",{target:t})),t===this._hoveredTarget&&(this._hoveredTarget=void 0,this._hoveredTargets=[]),super._onObjectRemoved(t)}_onStackOrderChanged(){this._objectsToRender=void 0,super._onStackOrderChanged()}_chooseObjectsToRender(){const t=this._activeObject;return!this.preserveObjectStacking&&t?this._objects.filter(e=>!e.group&&e!==t).concat(t):this._objects}renderAll(){this.cancelRequestedRender(),this.destroyed||(!this.contextTopDirty||this._groupSelector||this.isDrawingMode||(this.clearContext(this.contextTop),this.contextTopDirty=!1),this.hasLostContext&&(this.renderTopLayer(this.contextTop),this.hasLostContext=!1),!this._objectsToRender&&(this._objectsToRender=this._chooseObjectsToRender()),this.renderCanvas(this.getContext(),this._objectsToRender))}renderTopLayer(t){t.save(),this.isDrawingMode&&this._isCurrentlyDrawing&&(this.freeDrawingBrush&&this.freeDrawingBrush._render(),this.contextTopDirty=!0),this.selection&&this._groupSelector&&(this._drawSelection(t),this.contextTopDirty=!0),t.restore()}renderTop(){const t=this.contextTop;this.clearContext(t),this.renderTopLayer(t),this.fire("after:render",{ctx:t})}setTargetFindTolerance(t){t=Math.round(t),this.targetFindTolerance=t;const e=this.getRetinaScaling(),s=Math.ceil((2*t+1)*e);this.pixelFindCanvasEl.width=this.pixelFindCanvasEl.height=s,this.pixelFindContext.scale(e,e)}isTargetTransparent(t,e,s){const i=this.targetFindTolerance,n=this.pixelFindContext;this.clearContext(n),n.save(),n.translate(-e+i,-s+i),n.transform(...this.viewportTransform);const r=t.selectionBackgroundColor;t.selectionBackgroundColor="",t.render(n),t.selectionBackgroundColor=r,n.restore();const o=Math.round(i*this.getRetinaScaling());return Vm(n,o,o,o)}_isSelectionKeyPressed(t){const e=this.selectionKey;return!!e&&(Array.isArray(e)?!!e.find(s=>!!s&&t[s]===!0):t[e])}_shouldClearSelection(t,e){const s=this.getActiveObjects(),i=this._activeObject;return!!(!e||e&&i&&s.length>1&&s.indexOf(e)===-1&&i!==e&&!this._isSelectionKeyPressed(t)||e&&!e.evented||e&&!e.selectable&&i&&i!==e)}_shouldCenterTransform(t,e,s){if(!t)return;let i;return e===zc||e===Me||e===Je||e===Sh?i=this.centeredScaling||t.centeredScaling:e===lf&&(i=this.centeredRotation||t.centeredRotation),i?!s:s}_getOriginFromCorner(t,e){const s={x:t.originX,y:t.originY};return e&&(["ml","tl","bl"].includes(e)?s.x=It:["mr","tr","br"].includes(e)&&(s.x=dt),["tl","mt","tr"].includes(e)?s.y=af:["bl","mb","br"].includes(e)&&(s.y=Ve)),s}_setupCurrentTransform(t,e,s){var i;const n=e.group?_r(this.getScenePoint(t),void 0,e.group.calcTransformMatrix()):this.getScenePoint(t),{key:r="",control:o}=e.getActiveControl()||{},h=s&&o?(i=o.getActionHandler(t,e,o))===null||i===void 0?void 0:i.bind(o):Pv,c=((g,p,b,v)=>{if(!p||!g)return"drag";const _=v.controls[p];return _.getActionName(b,_,v)})(s,r,t,e),u=t[this.centeredKey],d=this._shouldCenterTransform(e,c,u)?{x:Q,y:Q}:this._getOriginFromCorner(e,r),f={target:e,action:c,actionHandler:h,actionPerformed:!1,corner:r,scaleX:e.scaleX,scaleY:e.scaleY,skewX:e.skewX,skewY:e.skewY,offsetX:n.x-e.left,offsetY:n.y-e.top,originX:d.x,originY:d.y,ex:n.x,ey:n.y,lastX:n.x,lastY:n.y,theta:Rt(e.angle),width:e.width,height:e.height,shiftKey:t.shiftKey,altKey:u,original:E(E({},wf(e)),{},{originX:d.x,originY:d.y})};this._currentTransform=f,this.fire("before:transform",{e:t,transform:f})}setCursor(t){this.upperCanvasEl.style.cursor=t}_drawSelection(t){const{x:e,y:s,deltaX:i,deltaY:n}=this._groupSelector,r=new P(e,s).transform(this.viewportTransform),o=new P(e+i,s+n).transform(this.viewportTransform),h=this.selectionLineWidth/2;let c=Math.min(r.x,o.x),u=Math.min(r.y,o.y),d=Math.max(r.x,o.x),f=Math.max(r.y,o.y);this.selectionColor&&(t.fillStyle=this.selectionColor,t.fillRect(c,u,d-c,f-u)),this.selectionLineWidth&&this.selectionBorderColor&&(t.lineWidth=this.selectionLineWidth,t.strokeStyle=this.selectionBorderColor,c+=h,u+=h,d-=h,f-=h,pe.prototype._setLineDash.call(this,t,this.selectionDashArray),t.strokeRect(c,u,d-c,f-u))}findTarget(t){if(this.skipTargetFind)return;const e=this.getViewportPoint(t),s=this._activeObject,i=this.getActiveObjects();if(this.targets=[],s&&i.length>=1){if(s.findControl(e,qc(t))||i.length>1&&this.searchPossibleTargets([s],e))return s;if(s===this.searchPossibleTargets([s],e)){if(this.preserveObjectStacking){const n=this.targets;this.targets=[];const r=this.searchPossibleTargets(this._objects,e);return t[this.altSelectionKey]&&r&&r!==s?(this.targets=n,s):r}return s}}return this.searchPossibleTargets(this._objects,e)}_pointIsInObjectSelectionArea(t,e){let s=t.getCoords();const i=this.getZoom(),n=t.padding/i;if(n){const[r,o,h,c]=s,u=Math.atan2(o.y-r.y,o.x-r.x),d=Ds(u)*n,f=Os(u)*n,g=d+f,p=d-f;s=[new P(r.x-p,r.y-g),new P(o.x+g,o.y-p),new P(h.x+p,h.y+g),new P(c.x-g,c.y+p)]}return Mt.isPointInPolygon(e,s)}_checkTarget(t,e){return!!(t&&t.visible&&t.evented&&this._pointIsInObjectSelectionArea(t,_r(e,void 0,this.viewportTransform))&&(!this.perPixelTargetFind&&!t.perPixelTargetFind||t.isEditing||!this.isTargetTransparent(t,e.x,e.y)))}_searchPossibleTargets(t,e){let s=t.length;for(;s--;){const i=t[s];if(this._checkTarget(i,e)){if(Wc(i)&&i.subTargetCheck){const n=this._searchPossibleTargets(i._objects,e);n&&this.targets.push(n)}return i}}}searchPossibleTargets(t,e){const s=this._searchPossibleTargets(t,e);if(s&&Wc(s)&&s.interactive&&this.targets[0]){const i=this.targets;for(let n=i.length-1;n>0;n--){const r=i[n];if(!Wc(r)||!r.interactive)return r}return i[0]}return s}getViewportPoint(t){return this._pointer?this._pointer:this.getPointer(t,!0)}getScenePoint(t){return this._absolutePointer?this._absolutePointer:this.getPointer(t)}getPointer(t){let e=arguments.length>1&&arguments[1]!==void 0&&arguments[1];const s=this.upperCanvasEl,i=s.getBoundingClientRect();let n=fm(t),r=i.width||0,o=i.height||0;r&&o||(Ve in i&&af in i&&(o=Math.abs(i.top-i.bottom)),It in i&&dt in i&&(r=Math.abs(i.right-i.left))),this.calcOffset(),n.x=n.x-this._offset.left,n.y=n.y-this._offset.top,e||(n=_r(n,void 0,this.viewportTransform));const h=this.getRetinaScaling();h!==1&&(n.x/=h,n.y/=h);const c=r===0||o===0?new P(1,1):new P(s.width/r,s.height/o);return n.multiply(c)}_setDimensionsImpl(t,e){this._resetTransformEventData(),super._setDimensionsImpl(t,e),this._isCurrentlyDrawing&&this.freeDrawingBrush&&this.freeDrawingBrush._setBrushStyles(this.contextTop)}_createCacheCanvas(){this.pixelFindCanvasEl=ms(),this.pixelFindContext=this.pixelFindCanvasEl.getContext("2d",{willReadFrequently:!0}),this.setTargetFindTolerance(this.targetFindTolerance)}getTopContext(){return this.elements.upper.ctx}getSelectionContext(){return this.elements.upper.ctx}getSelectionElement(){return this.elements.upper.el}getActiveObject(){return this._activeObject}getActiveObjects(){const t=this._activeObject;return vr(t)?t.getObjects():t?[t]:[]}_fireSelectionEvents(t,e){let s=!1,i=!1;const n=this.getActiveObjects(),r=[],o=[];t.forEach(h=>{n.includes(h)||(s=!0,h.fire("deselected",{e,target:h}),o.push(h))}),n.forEach(h=>{t.includes(h)||(s=!0,h.fire("selected",{e,target:h}),r.push(h))}),t.length>0&&n.length>0?(i=!0,s&&this.fire("selection:updated",{e,selected:r,deselected:o})):n.length>0?(i=!0,this.fire("selection:created",{e,selected:r})):t.length>0&&(i=!0,this.fire("selection:cleared",{e,deselected:o})),i&&(this._objectsToRender=void 0)}setActiveObject(t,e){const s=this.getActiveObjects(),i=this._setActiveObject(t,e);return this._fireSelectionEvents(s,e),i}_setActiveObject(t,e){const s=this._activeObject;return s!==t&&!(!this._discardActiveObject(e,t)&&this._activeObject)&&!t.onSelect({e})&&(this._activeObject=t,vr(t)&&s!==t&&t.set("canvas",this),t.setCoords(),!0)}_discardActiveObject(t,e){const s=this._activeObject;return!!s&&!s.onDeselect({e:t,object:e})&&(this._currentTransform&&this._currentTransform.target===s&&this.endCurrentTransform(t),vr(s)&&s===this._hoveredTarget&&(this._hoveredTarget=void 0),this._activeObject=void 0,!0)}discardActiveObject(t){const e=this.getActiveObjects(),s=this.getActiveObject();e.length&&this.fire("before:selection:cleared",{e:t,deselected:[s]});const i=this._discardActiveObject(t);return this._fireSelectionEvents(e,t),i}endCurrentTransform(t){const e=this._currentTransform;this._finalizeCurrentTransform(t),e&&e.target&&(e.target.isMoving=!1),this._currentTransform=null}_finalizeCurrentTransform(t){const e=this._currentTransform,s=e.target,i={e:t,target:s,transform:e,action:e.action};s._scaling&&(s._scaling=!1),s.setCoords(),e.actionPerformed&&(this.fire("object:modified",i),s.fire(Vc,i))}setViewportTransform(t){super.setViewportTransform(t);const e=this._activeObject;e&&e.setCoords()}destroy(){const t=this._activeObject;vr(t)&&(t.removeAll(),t.dispose()),delete this._activeObject,super.destroy(),this.pixelFindContext=null,this.pixelFindCanvasEl=void 0}clear(){this.discardActiveObject(),this._activeObject=void 0,this.clearContext(this.contextTop),super.clear()}drawControls(t){const e=this._activeObject;e&&e._renderControls(t)}_toObject(t,e,s){const i=this._realizeGroupTransformOnObject(t),n=super._toObject(t,e,s);return t.set(i),n}_realizeGroupTransformOnObject(t){const{group:e}=t;if(e&&vr(e)&&this._activeObject===e){const s=yr(t,["angle","flipX","flipY",dt,Me,Je,Xo,Wo,Ve]);return gm(t,e.calcOwnMatrix()),s}return{}}_setSVGObject(t,e,s){const i=this._realizeGroupTransformOnObject(e);super._setSVGObject(t,e,s),e.set(i)}}T(pu,"ownDefaults",{uniformScaling:!0,uniScaleKey:"shiftKey",centeredScaling:!1,centeredRotation:!1,centeredKey:"altKey",altActionKey:"shiftKey",selection:!0,selectionKey:"shiftKey",selectionColor:"rgba(100, 100, 255, 0.3)",selectionDashArray:[],selectionBorderColor:"rgba(255, 255, 255, 0.3)",selectionLineWidth:1,selectionFullyContained:!1,hoverCursor:"move",moveCursor:"move",defaultCursor:"default",freeDrawingCursor:"crosshair",notAllowedCursor:"not-allowed",perPixelTargetFind:!1,targetFindTolerance:0,skipTargetFind:!1,stopContextMenu:!1,fireRightClick:!1,fireMiddleClick:!1,enablePointerEvents:!1,containerClass:"canvas-container",preserveObjectStacking:!1});class J_{constructor(t){T(this,"targets",[]),T(this,"__disposer",void 0);const e=()=>{const{hiddenTextarea:i}=t.getActiveObject()||{};i&&i.focus()},s=t.upperCanvasEl;s.addEventListener("click",e),this.__disposer=()=>s.removeEventListener("click",e)}exitTextEditing(){this.target=void 0,this.targets.forEach(t=>{t.isEditing&&t.exitEditing()})}add(t){this.targets.push(t)}remove(t){this.unregister(t),mr(this.targets,t)}register(t){this.target=t}unregister(t){t===this.target&&(this.target=void 0)}onMouseMove(t){var e;!((e=this.target)===null||e===void 0)&&e.isEditing&&this.target.updateSelectionOnMouseMove(t)}clear(){this.targets=[],this.target=void 0}dispose(){this.clear(),this.__disposer(),delete this.__disposer}}const Z_=["target","oldTarget","fireCanvas","e"],Ze={passive:!1},sa=(a,t)=>{const e=a.getViewportPoint(t),s=a.getScenePoint(t);return{viewportPoint:e,scenePoint:s,pointer:e,absolutePointer:s}},Pn=function(a){for(var t=arguments.length,e=new Array(t>1?t-1:0),s=1;s<t;s++)e[s-1]=arguments[s];return a.addEventListener(...e)},ys=function(a){for(var t=arguments.length,e=new Array(t>1?t-1:0),s=1;s<t;s++)e[s-1]=arguments[s];return a.removeEventListener(...e)},tw={mouse:{in:"over",out:"out",targetIn:"mouseover",targetOut:"mouseout",canvasIn:"mouse:over",canvasOut:"mouse:out"},drag:{in:"enter",out:"leave",targetIn:"dragenter",targetOut:"dragleave",canvasIn:"drag:enter",canvasOut:"drag:leave"}};class Wf extends pu{constructor(t){super(t,arguments.length>1&&arguments[1]!==void 0?arguments[1]:{}),T(this,"_isClick",void 0),T(this,"textEditingManager",new J_(this)),["_onMouseDown","_onTouchStart","_onMouseMove","_onMouseUp","_onTouchEnd","_onResize","_onMouseWheel","_onMouseOut","_onMouseEnter","_onContextMenu","_onDoubleClick","_onDragStart","_onDragEnd","_onDragProgress","_onDragOver","_onDragEnter","_onDragLeave","_onDrop"].forEach(e=>{this[e]=this[e].bind(this)}),this.addOrRemove(Pn,"add")}_getEventPrefix(){return this.enablePointerEvents?"pointer":"mouse"}addOrRemove(t,e){const s=this.upperCanvasEl,i=this._getEventPrefix();t(lm(s),"resize",this._onResize),t(s,i+"down",this._onMouseDown),t(s,"".concat(i,"move"),this._onMouseMove,Ze),t(s,"".concat(i,"out"),this._onMouseOut),t(s,"".concat(i,"enter"),this._onMouseEnter),t(s,"wheel",this._onMouseWheel),t(s,"contextmenu",this._onContextMenu),t(s,"dblclick",this._onDoubleClick),t(s,"dragstart",this._onDragStart),t(s,"dragend",this._onDragEnd),t(s,"dragover",this._onDragOver),t(s,"dragenter",this._onDragEnter),t(s,"dragleave",this._onDragLeave),t(s,"drop",this._onDrop),this.enablePointerEvents||t(s,"touchstart",this._onTouchStart,Ze)}removeListeners(){this.addOrRemove(ys,"remove");const t=this._getEventPrefix(),e=Ls(this.upperCanvasEl);ys(e,"".concat(t,"up"),this._onMouseUp),ys(e,"touchend",this._onTouchEnd,Ze),ys(e,"".concat(t,"move"),this._onMouseMove,Ze),ys(e,"touchmove",this._onMouseMove,Ze),clearTimeout(this._willAddMouseDown)}_onMouseWheel(t){this.__onMouseWheel(t)}_onMouseOut(t){const e=this._hoveredTarget,s=E({e:t},sa(this,t));this.fire("mouse:out",E(E({},s),{},{target:e})),this._hoveredTarget=void 0,e&&e.fire("mouseout",E({},s)),this._hoveredTargets.forEach(i=>{this.fire("mouse:out",E(E({},s),{},{target:i})),i&&i.fire("mouseout",E({},s))}),this._hoveredTargets=[]}_onMouseEnter(t){this._currentTransform||this.findTarget(t)||(this.fire("mouse:over",E({e:t},sa(this,t))),this._hoveredTarget=void 0,this._hoveredTargets=[])}_onDragStart(t){this._isClick=!1;const e=this.getActiveObject();if(e&&e.onDragStart(t)){this._dragSource=e;const s={e:t,target:e};return this.fire("dragstart",s),e.fire("dragstart",s),void Pn(this.upperCanvasEl,"drag",this._onDragProgress)}_f(t)}_renderDragEffects(t,e,s){let i=!1;const n=this._dropTarget;n&&n!==e&&n!==s&&(n.clearContextTop(),i=!0),e==null||e.clearContextTop(),s!==e&&(s==null||s.clearContextTop());const r=this.contextTop;r.save(),r.transform(...this.viewportTransform),e&&(r.save(),e.transform(r),e.renderDragSourceEffect(t),r.restore(),i=!0),s&&(r.save(),s.transform(r),s.renderDropTargetEffect(t),r.restore(),i=!0),r.restore(),i&&(this.contextTopDirty=!0)}_onDragEnd(t){const e=!!t.dataTransfer&&t.dataTransfer.dropEffect!==ke,s=e?this._activeObject:void 0,i={e:t,target:this._dragSource,subTargets:this.targets,dragSource:this._dragSource,didDrop:e,dropTarget:s};ys(this.upperCanvasEl,"drag",this._onDragProgress),this.fire("dragend",i),this._dragSource&&this._dragSource.fire("dragend",i),delete this._dragSource,this._onMouseUp(t)}_onDragProgress(t){const e={e:t,target:this._dragSource,dragSource:this._dragSource,dropTarget:this._draggedoverTarget};this.fire("drag",e),this._dragSource&&this._dragSource.fire("drag",e)}findDragTargets(t){return this.targets=[],{target:this._searchPossibleTargets(this._objects,this.getViewportPoint(t)),targets:[...this.targets]}}_onDragOver(t){const e="dragover",{target:s,targets:i}=this.findDragTargets(t),n=this._dragSource,r={e:t,target:s,subTargets:i,dragSource:n,canDrop:!1,dropTarget:void 0};let o;this.fire(e,r),this._fireEnterLeaveEvents(s,r),s&&(s.canDrop(t)&&(o=s),s.fire(e,r));for(let h=0;h<i.length;h++){const c=i[h];c.canDrop(t)&&(o=c),c.fire(e,r)}this._renderDragEffects(t,n,o),this._dropTarget=o}_onDragEnter(t){const{target:e,targets:s}=this.findDragTargets(t),i={e:t,target:e,subTargets:s,dragSource:this._dragSource};this.fire("dragenter",i),this._fireEnterLeaveEvents(e,i)}_onDragLeave(t){const e={e:t,target:this._draggedoverTarget,subTargets:this.targets,dragSource:this._dragSource};this.fire("dragleave",e),this._fireEnterLeaveEvents(void 0,e),this._renderDragEffects(t,this._dragSource),this._dropTarget=void 0,this.targets=[],this._hoveredTargets=[]}_onDrop(t){const{target:e,targets:s}=this.findDragTargets(t),i=this._basicEventHandler("drop:before",E({e:t,target:e,subTargets:s,dragSource:this._dragSource},sa(this,t)));i.didDrop=!1,i.dropTarget=void 0,this._basicEventHandler("drop",i),this.fire("drop:after",i)}_onContextMenu(t){const e=this.findTarget(t),s=this.targets||[],i=this._basicEventHandler("contextmenu:before",{e:t,target:e,subTargets:s});return this.stopContextMenu&&_f(t),this._basicEventHandler("contextmenu",i),!1}_onDoubleClick(t){this._cacheTransformEventData(t),this._handleEvent(t,"dblclick"),this._resetTransformEventData()}getPointerId(t){const e=t.changedTouches;return e?e[0]&&e[0].identifier:this.enablePointerEvents?t.pointerId:-1}_isMainEvent(t){return t.isPrimary===!0||t.isPrimary!==!1&&(t.type==="touchend"&&t.touches.length===0||!t.changedTouches||t.changedTouches[0].identifier===this.mainTouchId)}_onTouchStart(t){let e=!this.allowTouchScrolling;const s=this._activeObject;this.mainTouchId===void 0&&(this.mainTouchId=this.getPointerId(t)),this.__onMouseDown(t),(this.isDrawingMode||s&&this._target===s)&&(e=!0),e&&t.preventDefault(),this._resetTransformEventData();const i=this.upperCanvasEl,n=this._getEventPrefix(),r=Ls(i);Pn(r,"touchend",this._onTouchEnd,Ze),e&&Pn(r,"touchmove",this._onMouseMove,Ze),ys(i,"".concat(n,"down"),this._onMouseDown)}_onMouseDown(t){this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();ys(e,"".concat(s,"move"),this._onMouseMove,Ze);const i=Ls(e);Pn(i,"".concat(s,"up"),this._onMouseUp),Pn(i,"".concat(s,"move"),this._onMouseMove,Ze)}_onTouchEnd(t){if(t.touches.length>0)return;this.__onMouseUp(t),this._resetTransformEventData(),delete this.mainTouchId;const e=this._getEventPrefix(),s=Ls(this.upperCanvasEl);ys(s,"touchend",this._onTouchEnd,Ze),ys(s,"touchmove",this._onMouseMove,Ze),this._willAddMouseDown&&clearTimeout(this._willAddMouseDown),this._willAddMouseDown=setTimeout(()=>{Pn(this.upperCanvasEl,"".concat(e,"down"),this._onMouseDown),this._willAddMouseDown=0},400)}_onMouseUp(t){this.__onMouseUp(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();if(this._isMainEvent(t)){const i=Ls(this.upperCanvasEl);ys(i,"".concat(s,"up"),this._onMouseUp),ys(i,"".concat(s,"move"),this._onMouseMove,Ze),Pn(e,"".concat(s,"move"),this._onMouseMove,Ze)}}_onMouseMove(t){const e=this.getActiveObject();!this.allowTouchScrolling&&(!e||!e.shouldStartDragging(t))&&t.preventDefault&&t.preventDefault(),this.__onMouseMove(t)}_onResize(){this.calcOffset(),this._resetTransformEventData()}_shouldRender(t){const e=this.getActiveObject();return!!e!=!!t||e&&t&&e!==t}__onMouseUp(t){var e;this._cacheTransformEventData(t),this._handleEvent(t,"up:before");const s=this._currentTransform,i=this._isClick,n=this._target,{button:r}=t;if(r)return(this.fireMiddleClick&&r===1||this.fireRightClick&&r===2)&&this._handleEvent(t,"up"),void this._resetTransformEventData();if(this.isDrawingMode&&this._isCurrentlyDrawing)return void this._onMouseUpInDrawingMode(t);if(!this._isMainEvent(t))return;let o,h,c=!1;if(s&&(this._finalizeCurrentTransform(t),c=s.actionPerformed),!i){const u=n===this._activeObject;this.handleSelection(t),c||(c=this._shouldRender(n)||!u&&n===this._activeObject)}if(n){const u=n.findControl(this.getViewportPoint(t),qc(t)),{key:d,control:f}=u||{};if(h=d,n.selectable&&n!==this._activeObject&&n.activeOn==="up")this.setActiveObject(n,t),c=!0;else if(f){const g=f.getMouseUpHandler(t,n,f);g&&(o=this.getScenePoint(t),g.call(f,t,s,o.x,o.y))}n.isMoving=!1}if(s&&(s.target!==n||s.corner!==h)){const u=s.target&&s.target.controls[s.corner],d=u&&u.getMouseUpHandler(t,s.target,u);o=o||this.getScenePoint(t),d&&d.call(u,t,s,o.x,o.y)}this._setCursorFromEvent(t,n),this._handleEvent(t,"up"),this._groupSelector=null,this._currentTransform=null,n&&(n.__corner=void 0),c?this.requestRenderAll():i||(e=this._activeObject)!==null&&e!==void 0&&e.isEditing||this.renderTop()}_basicEventHandler(t,e){const{target:s,subTargets:i=[]}=e;this.fire(t,e),s&&s.fire(t,e);for(let n=0;n<i.length;n++)i[n]!==s&&i[n].fire(t,e);return e}_handleEvent(t,e){const s=this._target,i=this.targets||[],n=E(E({e:t,target:s,subTargets:i},sa(this,t)),{},{transform:this._currentTransform},e==="up:before"||e==="up"?{isClick:this._isClick,currentTarget:this.findTarget(t),currentSubTargets:this.targets}:{});this.fire("mouse:".concat(e),n),s&&s.fire("mouse".concat(e),n);for(let r=0;r<i.length;r++)i[r]!==s&&i[r].fire("mouse".concat(e),n)}_onMouseDownInDrawingMode(t){this._isCurrentlyDrawing=!0,this.getActiveObject()&&(this.discardActiveObject(t),this.requestRenderAll());const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseDown(e,{e:t,pointer:e}),this._handleEvent(t,"down")}_onMouseMoveInDrawingMode(t){if(this._isCurrentlyDrawing){const e=this.getScenePoint(t);this.freeDrawingBrush&&this.freeDrawingBrush.onMouseMove(e,{e:t,pointer:e})}this.setCursor(this.freeDrawingCursor),this._handleEvent(t,"move")}_onMouseUpInDrawingMode(t){const e=this.getScenePoint(t);this.freeDrawingBrush?this._isCurrentlyDrawing=!!this.freeDrawingBrush.onMouseUp({e:t,pointer:e}):this._isCurrentlyDrawing=!1,this._handleEvent(t,"up")}__onMouseDown(t){this._isClick=!0,this._cacheTransformEventData(t),this._handleEvent(t,"down:before");let e=this._target;const{button:s}=t;if(s)return(this.fireMiddleClick&&s===1||this.fireRightClick&&s===2)&&this._handleEvent(t,"down"),void this._resetTransformEventData();if(this.isDrawingMode)return void this._onMouseDownInDrawingMode(t);if(!this._isMainEvent(t)||this._currentTransform)return;let i=this._shouldRender(e),n=!1;if(this.handleMultiSelection(t,e)?(e=this._activeObject,n=!0,i=!0):this._shouldClearSelection(t,e)&&this.discardActiveObject(t),this.selection&&(!e||!e.selectable&&!e.isEditing&&e!==this._activeObject)){const r=this.getScenePoint(t);this._groupSelector={x:r.x,y:r.y,deltaY:0,deltaX:0}}if(e){const r=e===this._activeObject;e.selectable&&e.activeOn==="down"&&this.setActiveObject(e,t);const o=e.findControl(this.getViewportPoint(t),qc(t));if(e===this._activeObject&&(o||!n)){this._setupCurrentTransform(t,e,r);const h=o?o.control:void 0,c=this.getScenePoint(t),u=h&&h.getMouseDownHandler(t,e,h);u&&u.call(h,t,this._currentTransform,c.x,c.y)}}i&&(this._objectsToRender=void 0),this._handleEvent(t,"down"),i&&this.requestRenderAll()}_resetTransformEventData(){this._target=this._pointer=this._absolutePointer=void 0}_cacheTransformEventData(t){this._resetTransformEventData(),this._pointer=this.getViewportPoint(t),this._absolutePointer=_r(this._pointer,void 0,this.viewportTransform),this._target=this._currentTransform?this._currentTransform.target:this.findTarget(t)}__onMouseMove(t){if(this._isClick=!1,this._cacheTransformEventData(t),this._handleEvent(t,"move:before"),this.isDrawingMode)return void this._onMouseMoveInDrawingMode(t);if(!this._isMainEvent(t))return;const e=this._groupSelector;if(e){const s=this.getScenePoint(t);e.deltaX=s.x-e.x,e.deltaY=s.y-e.y,this.renderTop()}else if(this._currentTransform)this._transformObject(t);else{const s=this.findTarget(t);this._setCursorFromEvent(t,s),this._fireOverOutEvents(t,s)}this.textEditingManager.onMouseMove(t),this._handleEvent(t,"move"),this._resetTransformEventData()}_fireOverOutEvents(t,e){const s=this._hoveredTarget,i=this._hoveredTargets,n=this.targets,r=Math.max(i.length,n.length);this.fireSyntheticInOutEvents("mouse",{e:t,target:e,oldTarget:s,fireCanvas:!0});for(let o=0;o<r;o++)this.fireSyntheticInOutEvents("mouse",{e:t,target:n[o],oldTarget:i[o]});this._hoveredTarget=e,this._hoveredTargets=this.targets.concat()}_fireEnterLeaveEvents(t,e){const s=this._draggedoverTarget,i=this._hoveredTargets,n=this.targets,r=Math.max(i.length,n.length);this.fireSyntheticInOutEvents("drag",E(E({},e),{},{target:t,oldTarget:s,fireCanvas:!0}));for(let o=0;o<r;o++)this.fireSyntheticInOutEvents("drag",E(E({},e),{},{target:n[o],oldTarget:i[o]}));this._draggedoverTarget=t}fireSyntheticInOutEvents(t,e){let{target:s,oldTarget:i,fireCanvas:n,e:r}=e,o=Ct(e,Z_);const{targetIn:h,targetOut:c,canvasIn:u,canvasOut:d}=tw[t],f=i!==s;if(i&&f){const g=E(E({},o),{},{e:r,target:i,nextTarget:s},sa(this,r));n&&this.fire(d,g),i.fire(c,g)}if(s&&f){const g=E(E({},o),{},{e:r,target:s,previousTarget:i},sa(this,r));n&&this.fire(u,g),s.fire(h,g)}}__onMouseWheel(t){this._cacheTransformEventData(t),this._handleEvent(t,"wheel"),this._resetTransformEventData()}_transformObject(t){const e=this.getScenePoint(t),s=this._currentTransform,i=s.target,n=i.group?_r(e,void 0,i.group.calcTransformMatrix()):e;s.shiftKey=t.shiftKey,s.altKey=!!this.centeredKey&&t[this.centeredKey],this._performTransformAction(t,s,n),s.actionPerformed&&this.requestRenderAll()}_performTransformAction(t,e,s){const{action:i,actionHandler:n,target:r}=e,o=!!n&&n(t,e,s.x,s.y);o&&r.setCoords(),i==="drag"&&o&&(e.target.isMoving=!0,this.setCursor(e.target.moveCursor||this.moveCursor)),e.actionPerformed=e.actionPerformed||o}_setCursorFromEvent(t,e){if(!e)return void this.setCursor(this.defaultCursor);let s=e.hoverCursor||this.hoverCursor;const i=vr(this._activeObject)?this._activeObject:null,n=(!i||e.group!==i)&&e.findControl(this.getViewportPoint(t));if(n){const r=n.control;this.setCursor(r.cursorStyleHandler(t,r,e))}else e.subTargetCheck&&this.targets.concat().reverse().map(r=>{s=r.hoverCursor||s}),this.setCursor(s)}handleMultiSelection(t,e){const s=this._activeObject,i=vr(s);if(s&&this._isSelectionKeyPressed(t)&&this.selection&&e&&e.selectable&&(s!==e||i)&&(i||!e.isDescendantOf(s)&&!s.isDescendantOf(e))&&!e.onSelect({e:t})&&!s.getActiveControl()){if(i){const n=s.getObjects();if(e===s){const r=this.getViewportPoint(t);if(!(e=this.searchPossibleTargets(n,r)||this.searchPossibleTargets(this._objects,r))||!e.selectable)return!1}e.group===s?(s.remove(e),this._hoveredTarget=e,this._hoveredTargets=[...this.targets],s.size()===1&&this._setActiveObject(s.item(0),t)):(s.multiSelectAdd(e),this._hoveredTarget=s,this._hoveredTargets=[...this.targets]),this._fireSelectionEvents(n,t)}else{s.isEditing&&s.exitEditing();const n=new(N.getClass("ActiveSelection"))([],{canvas:this});n.multiSelectAdd(s,e),this._hoveredTarget=n,this._setActiveObject(n,t),this._fireSelectionEvents([s],t)}return!0}return!1}handleSelection(t){if(!this.selection||!this._groupSelector)return!1;const{x:e,y:s,deltaX:i,deltaY:n}=this._groupSelector,r=new P(e,s),o=r.add(new P(i,n)),h=r.min(o),c=r.max(o).subtract(h),u=this.collectObjects({left:h.x,top:h.y,width:c.x,height:c.y},{includeIntersecting:!this.selectionFullyContained}),d=r.eq(o)?u[0]?[u[0]]:[]:u.length>1?u.filter(f=>!f.onSelect({e:t})).reverse():u;if(d.length===1)this.setActiveObject(d[0],t);else if(d.length>1){const f=N.getClass("ActiveSelection");this.setActiveObject(new f(d,{canvas:this}),t)}return this._groupSelector=null,!0}clear(){this.textEditingManager.clear(),super.clear()}destroy(){this.removeListeners(),this.textEditingManager.dispose(),super.destroy()}}const w0={x1:0,y1:0,x2:0,y2:0},ew=E(E({},w0),{},{r1:0,r2:0}),ia=(a,t)=>isNaN(a)&&typeof t=="number"?t:a,sw=/^(\d+\.\d+)%|(\d+)%$/;function x0(a){return a&&sw.test(a)}function S0(a,t){const e=typeof a=="number"?a:typeof a=="string"?parseFloat(a)/(x0(a)?100:1):NaN;return wr(0,ia(e,t),1)}const iw=/\s*;\s*/,nw=/\s*:\s*/;function rw(a,t){let e,s;const i=a.getAttribute("style");if(i){const r=i.split(iw);r[r.length-1]===""&&r.pop();for(let o=r.length;o--;){const[h,c]=r[o].split(nw).map(u=>u.trim());h==="stop-color"?e=c:h==="stop-opacity"&&(s=c)}}const n=new gt(e||a.getAttribute("stop-color")||"rgb(0,0,0)");return{offset:S0(a.getAttribute("offset"),0),color:n.toRgb(),opacity:ia(parseFloat(s||a.getAttribute("stop-opacity")||""),1)*n.getAlpha()*t}}function ow(a,t){const e=[],s=a.getElementsByTagName("stop"),i=S0(t,1);for(let n=s.length;n--;)e.push(rw(s[n],i));return e}function C0(a){return a.nodeName==="linearGradient"||a.nodeName==="LINEARGRADIENT"?"linear":"radial"}function A0(a){return a.getAttribute("gradientUnits")==="userSpaceOnUse"?"pixels":"percentage"}function js(a,t){return a.getAttribute(t)}function aw(a,t){return function(e,s){let i,{width:n,height:r,gradientUnits:o}=s;return Object.keys(e).reduce((h,c)=>{const u=e[c];return u==="Infinity"?i=1:u==="-Infinity"?i=0:(i=typeof u=="string"?parseFloat(u):u,typeof u=="string"&&x0(u)&&(i*=.01,o==="pixels"&&(c!=="x1"&&c!=="x2"&&c!=="r2"||(i*=n),c!=="y1"&&c!=="y2"||(i*=r)))),h[c]=i,h},{})}(C0(a)==="linear"?function(e){return{x1:js(e,"x1")||0,y1:js(e,"y1")||0,x2:js(e,"x2")||"100%",y2:js(e,"y2")||0}}(a):function(e){return{x1:js(e,"fx")||js(e,"cx")||"50%",y1:js(e,"fy")||js(e,"cy")||"50%",r1:0,x2:js(e,"cx")||"50%",y2:js(e,"cy")||"50%",r2:js(e,"r")||"50%"}}(a),E(E({},t),{},{gradientUnits:A0(a)}))}class Ih{constructor(t){const{type:e="linear",gradientUnits:s="pixels",coords:i={},colorStops:n=[],offsetX:r=0,offsetY:o=0,gradientTransform:h,id:c}=t||{};Object.assign(this,{type:e,gradientUnits:s,coords:E(E({},e==="radial"?ew:w0),i),colorStops:n,offsetX:r,offsetY:o,gradientTransform:h,id:c?"".concat(c,"_").concat(En()):En()})}addColorStop(t){for(const e in t){const s=new gt(t[e]);this.colorStops.push({offset:parseFloat(e),color:s.toRgb(),opacity:s.getAlpha()})}return this}toObject(t){return E(E({},yr(this,t)),{},{type:this.type,coords:E({},this.coords),colorStops:this.colorStops.map(e=>E({},e)),offsetX:this.offsetX,offsetY:this.offsetY,gradientUnits:this.gradientUnits,gradientTransform:this.gradientTransform?[...this.gradientTransform]:void 0})}toSVG(t){let{additionalTransform:e}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const s=[],i=this.gradientTransform?this.gradientTransform.concat():Ee.concat(),n=this.gradientUnits==="pixels"?"userSpaceOnUse":"objectBoundingBox",r=this.colorStops.map(d=>E({},d)).sort((d,f)=>d.offset-f.offset);let o=-this.offsetX,h=-this.offsetY;var c;n==="objectBoundingBox"?(o/=t.width,h/=t.height):(o+=t.width/2,h+=t.height/2),(c=t)&&typeof c._renderPathCommands=="function"&&this.gradientUnits!=="percentage"&&(o-=t.pathOffset.x,h-=t.pathOffset.y),i[4]-=o,i[5]-=h;const u=['id="SVGID_'.concat(this.id,'"'),'gradientUnits="'.concat(n,'"'),'gradientTransform="'.concat(e?e+" ":"").concat(kh(i),'"'),""].join(" ");if(this.type==="linear"){const{x1:d,y1:f,x2:g,y2:p}=this.coords;s.push("<linearGradient ",u,' x1="',d,'" y1="',f,'" x2="',g,'" y2="',p,`">
42
42
  `)}else if(this.type==="radial"){const{x1:d,y1:f,x2:g,y2:p,r1:b,r2:v}=this.coords,_=b>v;s.push("<radialGradient ",u,' cx="',_?d:g,'" cy="',_?f:p,'" r="',_?b:v,'" fx="',_?g:d,'" fy="',_?p:f,`">
43
43
  `),_&&(r.reverse(),r.forEach(C=>{C.offset=1-C.offset}));const x=Math.min(b,v);if(x>0){const C=x/Math.max(b,v);r.forEach(S=>{S.offset+=C*(1-S.offset)})}}return r.forEach(d=>{let{color:f,offset:g,opacity:p}=d;s.push("<stop ",'offset="',100*g+"%",'" style="stop-color:',f,p!==void 0?";stop-opacity: "+p:";",`"/>
44
44
  `)}),s.push(this.type==="linear"?"</linearGradient>":"</radialGradient>",`
45
- `),s.join("")}toLive(t){const{x1:e,y1:s,x2:i,y2:n,r1:r,r2:o}=this.coords,h=this.type==="linear"?t.createLinearGradient(e,s,i,n):t.createRadialGradient(e,s,r,i,n,o);return this.colorStops.forEach(c=>{let{color:u,opacity:d,offset:f}=c;h.addColorStop(f,d!==void 0?new gt(u).setAlpha(d).toRgba():u)}),h}static async fromObject(t){const{colorStops:e,gradientTransform:s}=t;return new this(E(E({},t),{},{colorStops:e?e.map(i=>E({},i)):void 0,gradientTransform:s?[...s]:void 0}))}static fromElement(t,e,s){const i=A0(t),n=e._findCenterFromElement();return new this(E({id:t.getAttribute("id")||void 0,type:C0(t),coords:aw(t,{width:s.viewBoxWidth||s.width,height:s.viewBoxHeight||s.height}),colorStops:ow(t,s.opacity),gradientUnits:i,gradientTransform:hu(t.getAttribute("gradientTransform")||"")},i==="pixels"?{offsetX:e.width/2-n.x,offsetY:e.height/2-n.y}:{offsetX:0,offsetY:0}))}}A(Ih,"type","Gradient"),N.setClass(Ih,"gradient"),N.setClass(Ih,"linear"),N.setClass(Ih,"radial");const hw=["type","source","patternTransform"];class Uf{get type(){return"pattern"}set type(t){Oi("warn","Setting type has no effect",t)}constructor(t){A(this,"repeat","repeat"),A(this,"offsetX",0),A(this,"offsetY",0),A(this,"crossOrigin",""),this.id=En(),Object.assign(this,t)}isImageSource(){return!!this.source&&typeof this.source.src=="string"}isCanvasSource(){return!!this.source&&!!this.source.toDataURL}sourceToString(){return this.isImageSource()?this.source.src:this.isCanvasSource()?this.source.toDataURL():""}toLive(t){return this.source&&(!this.isImageSource()||this.source.complete&&this.source.naturalWidth!==0&&this.source.naturalHeight!==0)?t.createPattern(this.source,this.repeat):null}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const{repeat:e,crossOrigin:s}=this;return E(E({},yr(this,t)),{},{type:"pattern",source:this.sourceToString(),repeat:e,crossOrigin:s,offsetX:At(this.offsetX,ht.NUM_FRACTION_DIGITS),offsetY:At(this.offsetY,ht.NUM_FRACTION_DIGITS),patternTransform:this.patternTransform?[...this.patternTransform]:null})}toSVG(t){let{width:e,height:s}=t;const{source:i,repeat:n,id:r}=this,o=ia(this.offsetX/e,0),h=ia(this.offsetY/s,0),c=n==="repeat-y"||n==="no-repeat"?1+Math.abs(o||0):ia(i.width/e,0),u=n==="repeat-x"||n==="no-repeat"?1+Math.abs(h||0):ia(i.height/s,0);return['<pattern id="SVGID_'.concat(r,'" x="').concat(o,'" y="').concat(h,'" width="').concat(c,'" height="').concat(u,'">'),'<image x="0" y="0" width="'.concat(i.width,'" height="').concat(i.height,'" xlink:href="').concat(this.sourceToString(),'"></image>'),"</pattern>",""].join(`
46
- `)}static async fromObject(t,e){let{type:s,source:i,patternTransform:n}=t,r=Ct(t,hw);const o=await Th(i,E(E({},e),{},{crossOrigin:r.crossOrigin}));return new this(E(E({},r),{},{patternTransform:n&&n.slice(0),source:o}))}}A(Uf,"type","Pattern"),N.setClass(Uf),N.setClass(Uf,"pattern");const lw=["path","left","top"],cw=["d"];class xr extends pe{constructor(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{path:s,left:i,top:n}=e,r=Ct(e,lw);super(),Object.assign(this,xr.ownDefaults),this.setOptions(r),this._setPath(t||[],!0),typeof i=="number"&&this.set(dt,i),typeof n=="number"&&this.set(Ve,n)}_setPath(t,e){this.path=c0(Array.isArray(t)?t:y0(t)),this.setBoundingBox(e)}_findCenterFromElement(){const t=this._calcBoundsFromPath();return new P(t.left+t.width/2,t.top+t.height/2)}_renderPathCommands(t){const e=-this.pathOffset.x,s=-this.pathOffset.y;t.beginPath();for(const i of this.path)switch(i[0]){case"L":t.lineTo(i[1]+e,i[2]+s);break;case"M":t.moveTo(i[1]+e,i[2]+s);break;case"C":t.bezierCurveTo(i[1]+e,i[2]+s,i[3]+e,i[4]+s,i[5]+e,i[6]+s);break;case"Q":t.quadraticCurveTo(i[1]+e,i[2]+s,i[3]+e,i[4]+s);break;case"Z":t.closePath()}}_render(t){this._renderPathCommands(t),this._renderPaintInOrder(t)}toString(){return"#<Path (".concat(this.complexity(),'): { "top": ').concat(this.top,', "left": ').concat(this.left," }>")}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return E(E({},super.toObject(t)),{},{path:this.path.map(e=>e.slice())})}toDatalessObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const e=this.toObject(t);return this.sourcePath&&(delete e.path,e.sourcePath=this.sourcePath),e}_toSVG(){const t=v0(this.path,ht.NUM_FRACTION_DIGITS);return["<path ","COMMON_PARTS",'d="'.concat(t,`" stroke-linecap="round" />
47
- `)]}_getOffsetTransform(){const t=ht.NUM_FRACTION_DIGITS;return" translate(".concat(At(-this.pathOffset.x,t),", ").concat(At(-this.pathOffset.y,t),")")}toClipPathSVG(t){const e=this._getOffsetTransform();return" "+this._createBaseClipPathSVGMarkup(this._toSVG(),{reviver:t,additionalTransform:e})}toSVG(t){const e=this._getOffsetTransform();return this._createBaseSVGMarkup(this._toSVG(),{reviver:t,additionalTransform:e})}complexity(){return this.path.length}setDimensions(){this.setBoundingBox()}setBoundingBox(t){const{width:e,height:s,pathOffset:i}=this._calcDimensions();this.set({width:e,height:s,pathOffset:i}),t&&this.setPositionByOrigin(i,Q,Q)}_calcBoundsFromPath(){const t=[];let e=0,s=0,i=0,n=0;for(const r of this.path)switch(r[0]){case"L":i=r[1],n=r[2],t.push({x:e,y:s},{x:i,y:n});break;case"M":i=r[1],n=r[2],e=i,s=n;break;case"C":t.push(...Vf(i,n,r[1],r[2],r[3],r[4],r[5],r[6])),i=r[5],n=r[6];break;case"Q":t.push(...Vf(i,n,r[1],r[2],r[1],r[2],r[3],r[4])),i=r[3],n=r[4];break;case"Z":i=e,n=s}return ri(t)}_calcDimensions(){const t=this._calcBoundsFromPath();return E(E({},t),{},{pathOffset:new P(t.left+t.width/2,t.top+t.height/2)})}static fromObject(t){return this._fromObject(t,{extraParam:"path"})}static async fromElement(t,e,s){const i=Ni(t,this.ATTRIBUTE_NAMES,s),{d:n}=i;return new this(n,E(E(E({},Ct(i,cw)),e),{},{left:void 0,top:void 0}))}}A(xr,"type","Path"),A(xr,"cacheProperties",[...Fi,"path","fillRule"]),A(xr,"ATTRIBUTE_NAMES",[...Mn,"d"]),N.setClass(xr),N.setSVGClass(xr);const uw=["left","top","radius"],T0=["radius","startAngle","endAngle","counterClockwise"];class Bi extends pe{static getDefaults(){return E(E({},super.getDefaults()),Bi.ownDefaults)}constructor(t){super(),Object.assign(this,Bi.ownDefaults),this.setOptions(t)}_set(t,e){return super._set(t,e),t==="radius"&&this.setRadius(e),this}_render(t){t.beginPath(),t.arc(0,0,this.radius,Rt(this.startAngle),Rt(this.endAngle),this.counterClockwise),this._renderPaintInOrder(t)}getRadiusX(){return this.get("radius")*this.get(Me)}getRadiusY(){return this.get("radius")*this.get(Je)}setRadius(t){this.radius=t,this.set({width:2*t,height:2*t})}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject([...T0,...t])}_toSVG(){const t=(this.endAngle-this.startAngle)%360;if(t===0)return["<circle ","COMMON_PARTS",'cx="0" cy="0" ','r="',"".concat(this.radius),`" />
45
+ `),s.join("")}toLive(t){const{x1:e,y1:s,x2:i,y2:n,r1:r,r2:o}=this.coords,h=this.type==="linear"?t.createLinearGradient(e,s,i,n):t.createRadialGradient(e,s,r,i,n,o);return this.colorStops.forEach(c=>{let{color:u,opacity:d,offset:f}=c;h.addColorStop(f,d!==void 0?new gt(u).setAlpha(d).toRgba():u)}),h}static async fromObject(t){const{colorStops:e,gradientTransform:s}=t;return new this(E(E({},t),{},{colorStops:e?e.map(i=>E({},i)):void 0,gradientTransform:s?[...s]:void 0}))}static fromElement(t,e,s){const i=A0(t),n=e._findCenterFromElement();return new this(E({id:t.getAttribute("id")||void 0,type:C0(t),coords:aw(t,{width:s.viewBoxWidth||s.width,height:s.viewBoxHeight||s.height}),colorStops:ow(t,s.opacity),gradientUnits:i,gradientTransform:hu(t.getAttribute("gradientTransform")||"")},i==="pixels"?{offsetX:e.width/2-n.x,offsetY:e.height/2-n.y}:{offsetX:0,offsetY:0}))}}T(Ih,"type","Gradient"),N.setClass(Ih,"gradient"),N.setClass(Ih,"linear"),N.setClass(Ih,"radial");const hw=["type","source","patternTransform"];class Uf{get type(){return"pattern"}set type(t){Oi("warn","Setting type has no effect",t)}constructor(t){T(this,"repeat","repeat"),T(this,"offsetX",0),T(this,"offsetY",0),T(this,"crossOrigin",""),this.id=En(),Object.assign(this,t)}isImageSource(){return!!this.source&&typeof this.source.src=="string"}isCanvasSource(){return!!this.source&&!!this.source.toDataURL}sourceToString(){return this.isImageSource()?this.source.src:this.isCanvasSource()?this.source.toDataURL():""}toLive(t){return this.source&&(!this.isImageSource()||this.source.complete&&this.source.naturalWidth!==0&&this.source.naturalHeight!==0)?t.createPattern(this.source,this.repeat):null}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const{repeat:e,crossOrigin:s}=this;return E(E({},yr(this,t)),{},{type:"pattern",source:this.sourceToString(),repeat:e,crossOrigin:s,offsetX:At(this.offsetX,ht.NUM_FRACTION_DIGITS),offsetY:At(this.offsetY,ht.NUM_FRACTION_DIGITS),patternTransform:this.patternTransform?[...this.patternTransform]:null})}toSVG(t){let{width:e,height:s}=t;const{source:i,repeat:n,id:r}=this,o=ia(this.offsetX/e,0),h=ia(this.offsetY/s,0),c=n==="repeat-y"||n==="no-repeat"?1+Math.abs(o||0):ia(i.width/e,0),u=n==="repeat-x"||n==="no-repeat"?1+Math.abs(h||0):ia(i.height/s,0);return['<pattern id="SVGID_'.concat(r,'" x="').concat(o,'" y="').concat(h,'" width="').concat(c,'" height="').concat(u,'">'),'<image x="0" y="0" width="'.concat(i.width,'" height="').concat(i.height,'" xlink:href="').concat(this.sourceToString(),'"></image>'),"</pattern>",""].join(`
46
+ `)}static async fromObject(t,e){let{type:s,source:i,patternTransform:n}=t,r=Ct(t,hw);const o=await Th(i,E(E({},e),{},{crossOrigin:r.crossOrigin}));return new this(E(E({},r),{},{patternTransform:n&&n.slice(0),source:o}))}}T(Uf,"type","Pattern"),N.setClass(Uf),N.setClass(Uf,"pattern");const lw=["path","left","top"],cw=["d"];class xr extends pe{constructor(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{path:s,left:i,top:n}=e,r=Ct(e,lw);super(),Object.assign(this,xr.ownDefaults),this.setOptions(r),this._setPath(t||[],!0),typeof i=="number"&&this.set(dt,i),typeof n=="number"&&this.set(Ve,n)}_setPath(t,e){this.path=c0(Array.isArray(t)?t:y0(t)),this.setBoundingBox(e)}_findCenterFromElement(){const t=this._calcBoundsFromPath();return new P(t.left+t.width/2,t.top+t.height/2)}_renderPathCommands(t){const e=-this.pathOffset.x,s=-this.pathOffset.y;t.beginPath();for(const i of this.path)switch(i[0]){case"L":t.lineTo(i[1]+e,i[2]+s);break;case"M":t.moveTo(i[1]+e,i[2]+s);break;case"C":t.bezierCurveTo(i[1]+e,i[2]+s,i[3]+e,i[4]+s,i[5]+e,i[6]+s);break;case"Q":t.quadraticCurveTo(i[1]+e,i[2]+s,i[3]+e,i[4]+s);break;case"Z":t.closePath()}}_render(t){this._renderPathCommands(t),this._renderPaintInOrder(t)}toString(){return"#<Path (".concat(this.complexity(),'): { "top": ').concat(this.top,', "left": ').concat(this.left," }>")}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return E(E({},super.toObject(t)),{},{path:this.path.map(e=>e.slice())})}toDatalessObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const e=this.toObject(t);return this.sourcePath&&(delete e.path,e.sourcePath=this.sourcePath),e}_toSVG(){const t=v0(this.path,ht.NUM_FRACTION_DIGITS);return["<path ","COMMON_PARTS",'d="'.concat(t,`" stroke-linecap="round" />
47
+ `)]}_getOffsetTransform(){const t=ht.NUM_FRACTION_DIGITS;return" translate(".concat(At(-this.pathOffset.x,t),", ").concat(At(-this.pathOffset.y,t),")")}toClipPathSVG(t){const e=this._getOffsetTransform();return" "+this._createBaseClipPathSVGMarkup(this._toSVG(),{reviver:t,additionalTransform:e})}toSVG(t){const e=this._getOffsetTransform();return this._createBaseSVGMarkup(this._toSVG(),{reviver:t,additionalTransform:e})}complexity(){return this.path.length}setDimensions(){this.setBoundingBox()}setBoundingBox(t){const{width:e,height:s,pathOffset:i}=this._calcDimensions();this.set({width:e,height:s,pathOffset:i}),t&&this.setPositionByOrigin(i,Q,Q)}_calcBoundsFromPath(){const t=[];let e=0,s=0,i=0,n=0;for(const r of this.path)switch(r[0]){case"L":i=r[1],n=r[2],t.push({x:e,y:s},{x:i,y:n});break;case"M":i=r[1],n=r[2],e=i,s=n;break;case"C":t.push(...Vf(i,n,r[1],r[2],r[3],r[4],r[5],r[6])),i=r[5],n=r[6];break;case"Q":t.push(...Vf(i,n,r[1],r[2],r[1],r[2],r[3],r[4])),i=r[3],n=r[4];break;case"Z":i=e,n=s}return ri(t)}_calcDimensions(){const t=this._calcBoundsFromPath();return E(E({},t),{},{pathOffset:new P(t.left+t.width/2,t.top+t.height/2)})}static fromObject(t){return this._fromObject(t,{extraParam:"path"})}static async fromElement(t,e,s){const i=Ni(t,this.ATTRIBUTE_NAMES,s),{d:n}=i;return new this(n,E(E(E({},Ct(i,cw)),e),{},{left:void 0,top:void 0}))}}T(xr,"type","Path"),T(xr,"cacheProperties",[...Fi,"path","fillRule"]),T(xr,"ATTRIBUTE_NAMES",[...Mn,"d"]),N.setClass(xr),N.setSVGClass(xr);const uw=["left","top","radius"],T0=["radius","startAngle","endAngle","counterClockwise"];class Bi extends pe{static getDefaults(){return E(E({},super.getDefaults()),Bi.ownDefaults)}constructor(t){super(),Object.assign(this,Bi.ownDefaults),this.setOptions(t)}_set(t,e){return super._set(t,e),t==="radius"&&this.setRadius(e),this}_render(t){t.beginPath(),t.arc(0,0,this.radius,Rt(this.startAngle),Rt(this.endAngle),this.counterClockwise),this._renderPaintInOrder(t)}getRadiusX(){return this.get("radius")*this.get(Me)}getRadiusY(){return this.get("radius")*this.get(Je)}setRadius(t){this.radius=t,this.set({width:2*t,height:2*t})}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject([...T0,...t])}_toSVG(){const t=(this.endAngle-this.startAngle)%360;if(t===0)return["<circle ","COMMON_PARTS",'cx="0" cy="0" ','r="',"".concat(this.radius),`" />
48
48
  `];{const{radius:e}=this,s=Rt(this.startAngle),i=Rt(this.endAngle),n=Ds(s)*e,r=Os(s)*e,o=Ds(i)*e,h=Os(i)*e,c=t>180?1:0,u=this.counterClockwise?0:1;return['<path d="M '.concat(n," ").concat(r," A ").concat(e," ").concat(e," 0 ").concat(c," ").concat(u," ").concat(o," ").concat(h,'" '),"COMMON_PARTS",` />
49
- `]}}static async fromElement(t,e,s){const i=Ni(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:r=0,radius:o=0}=i;return new this(E(E({},Ct(i,uw)),{},{radius:o,left:n-o,top:r-o}))}static fromObject(t){return super._fromObject(t)}}A(Bi,"type","Circle"),A(Bi,"cacheProperties",[...Fi,...T0]),A(Bi,"ownDefaults",{radius:0,startAngle:0,endAngle:360,counterClockwise:!1}),A(Bi,"ATTRIBUTE_NAMES",["cx","cy","r",...Mn]),N.setClass(Bi),N.setSVGClass(Bi);const dw=["x1","y1","x2","y2"],fw=["x1","y1","x2","y2"],Yf=["x1","x2","y1","y2"];class Sr extends pe{constructor(){let[t,e,s,i]=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[0,0,0,0],n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),Object.assign(this,Sr.ownDefaults),this.setOptions(n),this.x1=t,this.x2=s,this.y1=e,this.y2=i,this._setWidthHeight();const{left:r,top:o}=n;typeof r=="number"&&this.set(dt,r),typeof o=="number"&&this.set(Ve,o)}_setWidthHeight(){const{x1:t,y1:e,x2:s,y2:i}=this;this.width=Math.abs(s-t),this.height=Math.abs(i-e);const{left:n,top:r,width:o,height:h}=ri([{x:t,y:e},{x:s,y:i}]),c=new P(n+o/2,r+h/2);this.setPositionByOrigin(c,Q,Q)}_set(t,e){return super._set(t,e),Yf.includes(t)&&this._setWidthHeight(),this}_render(t){t.beginPath();const e=this.calcLinePoints();t.moveTo(e.x1,e.y1),t.lineTo(e.x2,e.y2),t.lineWidth=this.strokeWidth;const s=t.strokeStyle;var i;bs(this.stroke)?t.strokeStyle=this.stroke.toLive(t):t.strokeStyle=(i=this.stroke)!==null&&i!==void 0?i:t.fillStyle,this.stroke&&this._renderStroke(t),t.strokeStyle=s}_findCenterFromElement(){return new P((this.x1+this.x2)/2,(this.y1+this.y2)/2)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return E(E({},super.toObject(t)),this.calcLinePoints())}_getNonTransformedDimensions(){const t=super._getNonTransformedDimensions();return this.strokeLineCap==="butt"&&(this.width===0&&(t.y-=this.strokeWidth),this.height===0&&(t.x-=this.strokeWidth)),t}calcLinePoints(){const{x1:t,x2:e,y1:s,y2:i,width:n,height:r}=this,o=t<=e?-1:1,h=s<=i?-1:1;return{x1:o*n/2,x2:o*-n/2,y1:h*r/2,y2:h*-r/2}}_toSVG(){const{x1:t,x2:e,y1:s,y2:i}=this.calcLinePoints();return["<line ","COMMON_PARTS",'x1="'.concat(t,'" y1="').concat(s,'" x2="').concat(e,'" y2="').concat(i,`" />
50
- `)]}static async fromElement(t,e,s){const i=Ni(t,this.ATTRIBUTE_NAMES,s),{x1:n=0,y1:r=0,x2:o=0,y2:h=0}=i;return new this([n,r,o,h],Ct(i,dw))}static fromObject(t){let{x1:e,y1:s,x2:i,y2:n}=t,r=Ct(t,fw);return this._fromObject(E(E({},r),{},{points:[e,s,i,n]}),{extraParam:"points"})}}A(Sr,"type","Line"),A(Sr,"cacheProperties",[...Fi,...Yf]),A(Sr,"ATTRIBUTE_NAMES",Mn.concat(Yf)),N.setClass(Sr),N.setSVGClass(Sr);class Cr extends pe{static getDefaults(){return E(E({},super.getDefaults()),Cr.ownDefaults)}constructor(t){super(),Object.assign(this,Cr.ownDefaults),this.setOptions(t)}_render(t){const e=this.width/2,s=this.height/2;t.beginPath(),t.moveTo(-e,s),t.lineTo(0,-s),t.lineTo(e,s),t.closePath(),this._renderPaintInOrder(t)}_toSVG(){const t=this.width/2,e=this.height/2;return["<polygon ","COMMON_PARTS",'points="',"".concat(-t," ").concat(e,",0 ").concat(-e,",").concat(t," ").concat(e),'" />']}}A(Cr,"type","Triangle"),A(Cr,"ownDefaults",{width:100,height:100}),N.setClass(Cr),N.setSVGClass(Cr);const E0=["rx","ry"];class Hi extends pe{static getDefaults(){return E(E({},super.getDefaults()),Hi.ownDefaults)}constructor(t){super(),Object.assign(this,Hi.ownDefaults),this.setOptions(t)}_set(t,e){switch(super._set(t,e),t){case"rx":this.rx=e,this.set("width",2*e);break;case"ry":this.ry=e,this.set("height",2*e)}return this}getRx(){return this.get("rx")*this.get(Me)}getRy(){return this.get("ry")*this.get(Je)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject([...E0,...t])}_toSVG(){return["<ellipse ","COMMON_PARTS",'cx="0" cy="0" rx="'.concat(this.rx,'" ry="').concat(this.ry,`" />
51
- `)]}_render(t){t.beginPath(),t.save(),t.transform(1,0,0,this.ry/this.rx,0,0),t.arc(0,0,this.rx,0,Ri,!1),t.restore(),this._renderPaintInOrder(t)}static async fromElement(t,e,s){const i=Ni(t,this.ATTRIBUTE_NAMES,s);return i.left=(i.left||0)-i.rx,i.top=(i.top||0)-i.ry,new this(i)}}function gw(a){if(!a)return[];const t=a.replace(/,/g," ").trim().split(/\s+/),e=[];for(let s=0;s<t.length;s+=2)e.push({x:parseFloat(t[s]),y:parseFloat(t[s+1])});return e}A(Hi,"type","Ellipse"),A(Hi,"cacheProperties",[...Fi,...E0]),A(Hi,"ownDefaults",{rx:0,ry:0}),A(Hi,"ATTRIBUTE_NAMES",[...Mn,"cx","cy","rx","ry"]),N.setClass(Hi),N.setSVGClass(Hi);const pw=["left","top"],k0={exactBoundingBox:!1};class Bs extends pe{static getDefaults(){return E(E({},super.getDefaults()),Bs.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),A(this,"strokeDiff",void 0),Object.assign(this,Bs.ownDefaults),this.setOptions(e),this.points=t;const{left:s,top:i}=e;this.initialized=!0,this.setBoundingBox(!0),typeof s=="number"&&this.set(dt,s),typeof i=="number"&&this.set(Ve,i)}isOpen(){return!0}_projectStrokeOnPoints(t){return Um(this.points,t,this.isOpen())}_calcDimensions(t){t=E({scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,strokeLineCap:this.strokeLineCap,strokeLineJoin:this.strokeLineJoin,strokeMiterLimit:this.strokeMiterLimit,strokeUniform:this.strokeUniform,strokeWidth:this.strokeWidth},t||{});const e=this.exactBoundingBox?this._projectStrokeOnPoints(t).map(c=>c.projectedPoint):this.points;if(e.length===0)return{left:0,top:0,width:0,height:0,pathOffset:new P,strokeOffset:new P,strokeDiff:new P};const s=ri(e),i=Ah(E(E({},t),{},{scaleX:1,scaleY:1})),n=ri(this.points.map(c=>ge(c,i,!0))),r=new P(this.scaleX,this.scaleY);let o=s.left+s.width/2,h=s.top+s.height/2;return this.exactBoundingBox&&(o-=h*Math.tan(Rt(this.skewX)),h-=o*Math.tan(Rt(this.skewY))),E(E({},s),{},{pathOffset:new P(o,h),strokeOffset:new P(n.left,n.top).subtract(new P(s.left,s.top)).multiply(r),strokeDiff:new P(s.width,s.height).subtract(new P(n.width,n.height)).multiply(r)})}_findCenterFromElement(){const t=ri(this.points);return new P(t.left+t.width/2,t.top+t.height/2)}setDimensions(){this.setBoundingBox()}setBoundingBox(t){const{left:e,top:s,width:i,height:n,pathOffset:r,strokeOffset:o,strokeDiff:h}=this._calcDimensions();this.set({width:i,height:n,pathOffset:r,strokeOffset:o,strokeDiff:h}),t&&this.setPositionByOrigin(new P(e+i/2,s+n/2),Q,Q)}isStrokeAccountedForInDimensions(){return this.exactBoundingBox}_getNonTransformedDimensions(){return this.exactBoundingBox?new P(this.width,this.height):super._getNonTransformedDimensions()}_getTransformedDimensions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(this.exactBoundingBox){let r;if(Object.keys(t).some(o=>this.strokeUniform||this.constructor.layoutProperties.includes(o))){var e,s;const{width:o,height:h}=this._calcDimensions(t);r=new P((e=t.width)!==null&&e!==void 0?e:o,(s=t.height)!==null&&s!==void 0?s:h)}else{var i,n;r=new P((i=t.width)!==null&&i!==void 0?i:this.width,(n=t.height)!==null&&n!==void 0?n:this.height)}return r.multiply(new P(t.scaleX||this.scaleX,t.scaleY||this.scaleY))}return super._getTransformedDimensions(t)}_set(t,e){const s=this.initialized&&this[t]!==e,i=super._set(t,e);return this.exactBoundingBox&&s&&((t===Me||t===Je)&&this.strokeUniform&&this.constructor.layoutProperties.includes("strokeUniform")||this.constructor.layoutProperties.includes(t))&&this.setDimensions(),i}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return E(E({},super.toObject(t)),{},{points:this.points.map(e=>{let{x:s,y:i}=e;return{x:s,y:i}})})}_toSVG(){const t=[],e=this.pathOffset.x,s=this.pathOffset.y,i=ht.NUM_FRACTION_DIGITS;for(let n=0,r=this.points.length;n<r;n++)t.push(At(this.points[n].x-e,i),",",At(this.points[n].y-s,i)," ");return["<".concat(this.constructor.type.toLowerCase()," "),"COMMON_PARTS",'points="'.concat(t.join(""),`" />
52
- `)]}_render(t){const e=this.points.length,s=this.pathOffset.x,i=this.pathOffset.y;if(e&&!isNaN(this.points[e-1].y)){t.beginPath(),t.moveTo(this.points[0].x-s,this.points[0].y-i);for(let n=0;n<e;n++){const r=this.points[n];t.lineTo(r.x-s,r.y-i)}!this.isOpen()&&t.closePath(),this._renderPaintInOrder(t)}}complexity(){return this.points.length}static async fromElement(t,e,s){return new this(gw(t.getAttribute("points")),E(E({},Ct(Ni(t,this.ATTRIBUTE_NAMES,s),pw)),e))}static fromObject(t){return this._fromObject(t,{extraParam:"points"})}}A(Bs,"ownDefaults",k0),A(Bs,"type","Polyline"),A(Bs,"layoutProperties",[Xo,Wo,"strokeLineCap","strokeLineJoin","strokeMiterLimit","strokeWidth","strokeUniform","points"]),A(Bs,"cacheProperties",[...Fi,"points"]),A(Bs,"ATTRIBUTE_NAMES",[...Mn]),N.setClass(Bs),N.setSVGClass(Bs);class mu extends Bs{isOpen(){return!1}}A(mu,"ownDefaults",k0),A(mu,"type","Polygon"),N.setClass(mu),N.setSVGClass(mu);const M0=["fontSize","fontWeight","fontFamily","fontStyle"],P0=["underline","overline","linethrough"],D0=[...M0,"lineHeight","text","charSpacing","textAlign","styles","path","pathStartOffset","pathSide","pathAlign"],O0=[...D0,...P0,"textBackgroundColor","direction"],mw=[...M0,...P0,Pe,"strokeWidth",zt,"deltaY","textBackgroundColor"],bw={_reNewline:hf,_reSpacesAndTabs:/[ \t\r]/g,_reSpaceAndTab:/[ \t\r]/,_reWords:/\S+/g,fontSize:40,fontWeight:"normal",fontFamily:"Times New Roman",underline:!1,overline:!1,linethrough:!1,textAlign:dt,fontStyle:"normal",lineHeight:1.16,superscript:{size:.6,baseline:-.35},subscript:{size:.6,baseline:.11},textBackgroundColor:"",stroke:null,shadow:null,path:void 0,pathStartOffset:0,pathSide:dt,pathAlign:"baseline",_fontSizeFraction:.222,offsets:{underline:.1,linethrough:-.315,overline:-.88},_fontSizeMult:1.13,charSpacing:0,deltaY:0,direction:"ltr",CACHE_FONT_SIZE:400,MIN_TEXT_WIDTH:2},hi="justify",bu="justify-left",Nh="justify-right",jh="justify-center";class R0 extends pe{isEmptyStyles(t){if(!this.styles||t!==void 0&&!this.styles[t])return!0;const e=t===void 0?this.styles:{line:this.styles[t]};for(const s in e)for(const i in e[s])for(const n in e[s][i])return!1;return!0}styleHas(t,e){if(!this.styles||e!==void 0&&!this.styles[e])return!1;const s=e===void 0?this.styles:{0:this.styles[e]};for(const i in s)for(const n in s[i])if(s[i][n][t]!==void 0)return!0;return!1}cleanStyle(t){if(!this.styles)return!1;const e=this.styles;let s,i,n=0,r=!0,o=0;for(const h in e){s=0;for(const c in e[h]){const u=e[h][c]||{};n++,u[t]!==void 0?(i?u[t]!==i&&(r=!1):i=u[t],u[t]===this[t]&&delete u[t]):r=!1,Object.keys(u).length!==0?s++:delete e[h][c]}s===0&&delete e[h]}for(let h=0;h<this._textLines.length;h++)o+=this._textLines[h].length;r&&n===o&&(this[t]=i,this.removeStyle(t))}removeStyle(t){if(!this.styles)return;const e=this.styles;let s,i,n;for(i in e){for(n in s=e[i],s)delete s[n][t],Object.keys(s[n]).length===0&&delete s[n];Object.keys(s).length===0&&delete e[i]}}_extendStyles(t,e){const{lineIndex:s,charIndex:i}=this.get2DCursorLocation(t);this._getLineStyle(s)||this._setLineStyle(s);const n=mf(E(E({},this._getStyleDeclaration(s,i)),e),r=>r!==void 0);this._setStyleDeclaration(s,i,n)}getSelectionStyles(t,e,s){const i=[];for(let n=t;n<(e||t);n++)i.push(this.getStyleAtPosition(n,s));return i}getStyleAtPosition(t,e){const{lineIndex:s,charIndex:i}=this.get2DCursorLocation(t);return e?this.getCompleteStyleDeclaration(s,i):this._getStyleDeclaration(s,i)}setSelectionStyles(t,e,s){for(let i=e;i<(s||e);i++)this._extendStyles(i,t);this._forceClearCache=!0}_getStyleDeclaration(t,e){var s;const i=this.styles&&this.styles[t];return i&&(s=i[e])!==null&&s!==void 0?s:{}}getCompleteStyleDeclaration(t,e){return E(E({},yr(this,this.constructor._styleProperties)),this._getStyleDeclaration(t,e))}_setStyleDeclaration(t,e,s){this.styles[t][e]=s}_deleteStyleDeclaration(t,e){delete this.styles[t][e]}_getLineStyle(t){return!!this.styles[t]}_setLineStyle(t){this.styles[t]={}}_deleteLineStyle(t){delete this.styles[t]}}A(R0,"_styleProperties",mw);const yw=/ +/g,vw=/"/g;function $f(a,t,e,s,i){return" ".concat(function(n,r){let{left:o,top:h,width:c,height:u}=r,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:ht.NUM_FRACTION_DIGITS;const f=Mh(zt,n,!1),[g,p,b,v]=[o,h,c,u].map(_=>At(_,d));return"<rect ".concat(f,' x="').concat(g,'" y="').concat(p,'" width="').concat(b,'" height="').concat(v,'"></rect>')}(a,{left:t,top:e,width:s,height:i}),`
53
- `)}const _w=["textAnchor","textDecoration","dx","dy","top","left","fontSize","strokeWidth"];let qf;class me extends R0{static getDefaults(){return E(E({},super.getDefaults()),me.ownDefaults)}constructor(t,e){super(),A(this,"__charBounds",[]),Object.assign(this,me.ownDefaults),this.setOptions(e),this.styles||(this.styles={}),this.text=t,this.initialized=!0,this.path&&this.setPathInfo(),this.initDimensions(),this.setCoords()}setPathInfo(){const t=this.path;t&&(t.segmentsInfo=Xf(t.path))}_splitText(){const t=this._splitTextIntoLines(this.text);return this.textLines=t.lines,this._textLines=t.graphemeLines,this._unwrappedTextLines=t._unwrappedLines,this._text=t.graphemeText,t}initDimensions(){this._splitText(),this._clearCache(),this.dirty=!0,this.path?(this.width=this.path.width,this.height=this.path.height):(this.width=this.calcTextWidth()||this.cursorWidth||this.MIN_TEXT_WIDTH,this.height=this.calcTextHeight()),this.textAlign.includes(hi)&&this.enlargeSpaces()}enlargeSpaces(){let t,e,s,i,n,r,o;for(let h=0,c=this._textLines.length;h<c;h++)if((this.textAlign===hi||h!==c-1&&!this.isEndOfWrapping(h))&&(i=0,n=this._textLines[h],e=this.getLineWidth(h),e<this.width&&(o=this.textLines[h].match(this._reSpacesAndTabs)))){s=o.length,t=(this.width-e)/s;for(let u=0;u<=n.length;u++)r=this.__charBounds[h][u],this._reSpaceAndTab.test(n[u])?(r.width+=t,r.kernedWidth+=t,r.left+=i,i+=t):r.left+=i}}isEndOfWrapping(t){return t===this._textLines.length-1}missingNewlineOffset(t){return 1}get2DCursorLocation(t,e){const s=e?this._unwrappedTextLines:this._textLines;let i;for(i=0;i<s.length;i++){if(t<=s[i].length)return{lineIndex:i,charIndex:t};t-=s[i].length+this.missingNewlineOffset(i,e)}return{lineIndex:i-1,charIndex:s[i-1].length<t?s[i-1].length:t}}toString(){return"#<Text (".concat(this.complexity(),'): { "text": "').concat(this.text,'", "fontFamily": "').concat(this.fontFamily,'" }>')}_getCacheCanvasDimensions(){const t=super._getCacheCanvasDimensions(),e=this.fontSize;return t.width+=e*t.zoomX,t.height+=e*t.zoomY,t}_render(t){const e=this.path;e&&!e.isNotVisible()&&e._render(t),this._setTextStyles(t),this._renderTextLinesBackground(t),this._renderTextDecoration(t,"underline"),this._renderText(t),this._renderTextDecoration(t,"overline"),this._renderTextDecoration(t,"linethrough")}_renderText(t){this.paintFirst===Pe?(this._renderTextStroke(t),this._renderTextFill(t)):(this._renderTextFill(t),this._renderTextStroke(t))}_setTextStyles(t,e,s){if(t.textBaseline="alphabetic",this.path)switch(this.pathAlign){case Q:t.textBaseline="middle";break;case"ascender":t.textBaseline=Ve;break;case"descender":t.textBaseline=af}t.font=this._getFontDeclaration(e,s)}calcTextWidth(){let t=this.getLineWidth(0);for(let e=1,s=this._textLines.length;e<s;e++){const i=this.getLineWidth(e);i>t&&(t=i)}return t}_renderTextLine(t,e,s,i,n,r){this._renderChars(t,e,s,i,n,r)}_renderTextLinesBackground(t){if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor"))return;const e=t.fillStyle,s=this._getLeftOffset();let i=this._getTopOffset();for(let n=0,r=this._textLines.length;n<r;n++){const o=this.getHeightOfLine(n);if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor",n)){i+=o;continue}const h=this._textLines[n].length,c=this._getLineLeftOffset(n);let u,d,f=0,g=0,p=this.getValueOfPropertyAt(n,0,"textBackgroundColor");for(let b=0;b<h;b++){const v=this.__charBounds[n][b];d=this.getValueOfPropertyAt(n,b,"textBackgroundColor"),this.path?(t.save(),t.translate(v.renderLeft,v.renderTop),t.rotate(v.angle),t.fillStyle=d,d&&t.fillRect(-v.width/2,-o/this.lineHeight*(1-this._fontSizeFraction),v.width,o/this.lineHeight),t.restore()):d!==p?(u=s+c+g,this.direction==="rtl"&&(u=this.width-u-f),t.fillStyle=p,p&&t.fillRect(u,i,f,o/this.lineHeight),g=v.left,f=v.width,p=d):f+=v.kernedWidth}d&&!this.path&&(u=s+c+g,this.direction==="rtl"&&(u=this.width-u-f),t.fillStyle=d,t.fillRect(u,i,f,o/this.lineHeight)),i+=o}t.fillStyle=e,this._removeShadow(t)}_measureChar(t,e,s,i){const n=xh.getFontCache(e),r=this._getFontDeclaration(e),o=s+t,h=s&&r===this._getFontDeclaration(i),c=e.fontSize/this.CACHE_FONT_SIZE;let u,d,f,g;if(s&&n[s]!==void 0&&(f=n[s]),n[t]!==void 0&&(g=u=n[t]),h&&n[o]!==void 0&&(d=n[o],g=d-f),u===void 0||f===void 0||d===void 0){const p=function(){return qf||(qf=Rs({width:0,height:0}).getContext("2d")),qf}();this._setTextStyles(p,e,!0),u===void 0&&(g=u=p.measureText(t).width,n[t]=u),f===void 0&&h&&s&&(f=p.measureText(s).width,n[s]=f),h&&d===void 0&&(d=p.measureText(o).width,n[o]=d,g=d-f)}return{width:u*c,kernedWidth:g*c}}getHeightOfChar(t,e){return this.getValueOfPropertyAt(t,e,"fontSize")}measureLine(t){const e=this._measureLine(t);return this.charSpacing!==0&&(e.width-=this._getWidthOfCharSpacing()),e.width<0&&(e.width=0),e}_measureLine(t){let e,s,i=0;const n=this.pathSide===It,r=this.path,o=this._textLines[t],h=o.length,c=new Array(h);this.__charBounds[t]=c;for(let u=0;u<h;u++){const d=o[u];s=this._getGraphemeBox(d,t,u,e),c[u]=s,i+=s.kernedWidth,e=d}if(c[h]={left:s?s.left+s.width:0,width:0,kernedWidth:0,height:this.fontSize,deltaY:0},r&&r.segmentsInfo){let u=0;const d=r.segmentsInfo[r.segmentsInfo.length-1].length;switch(this.textAlign){case dt:u=n?d-i:0;break;case Q:u=(d-i)/2;break;case It:u=n?0:d-i}u+=this.pathStartOffset*(n?-1:1);for(let f=n?h-1:0;n?f>=0:f<h;n?f--:f++)s=c[f],u>d?u%=d:u<0&&(u+=d),this._setGraphemeOnPath(u,s),u+=s.kernedWidth}return{width:i,numOfSpaces:0}}_setGraphemeOnPath(t,e){const s=t+e.kernedWidth/2,i=this.path,n=m0(i.path,s,i.segmentsInfo);e.renderLeft=n.x-i.pathOffset.x,e.renderTop=n.y-i.pathOffset.y,e.angle=n.angle+(this.pathSide===It?Math.PI:0)}_getGraphemeBox(t,e,s,i,n){const r=this.getCompleteStyleDeclaration(e,s),o=i?this.getCompleteStyleDeclaration(e,s-1):{},h=this._measureChar(t,r,i,o);let c,u=h.kernedWidth,d=h.width;this.charSpacing!==0&&(c=this._getWidthOfCharSpacing(),d+=c,u+=c);const f={width:d,left:0,height:r.fontSize,kernedWidth:u,deltaY:r.deltaY};if(s>0&&!n){const g=this.__charBounds[e][s-1];f.left=g.left+g.width+h.kernedWidth-h.width}return f}getHeightOfLine(t){if(this.__lineHeights[t])return this.__lineHeights[t];let e=this.getHeightOfChar(t,0);for(let s=1,i=this._textLines[t].length;s<i;s++)e=Math.max(this.getHeightOfChar(t,s),e);return this.__lineHeights[t]=e*this.lineHeight*this._fontSizeMult}calcTextHeight(){let t,e=0;for(let s=0,i=this._textLines.length;s<i;s++)t=this.getHeightOfLine(s),e+=s===i-1?t/this.lineHeight:t;return e}_getLeftOffset(){return this.direction==="ltr"?-this.width/2:this.width/2}_getTopOffset(){return-this.height/2}_renderTextCommon(t,e){t.save();let s=0;const i=this._getLeftOffset(),n=this._getTopOffset();for(let r=0,o=this._textLines.length;r<o;r++){const h=this.getHeightOfLine(r),c=h/this.lineHeight,u=this._getLineLeftOffset(r);this._renderTextLine(e,t,this._textLines[r],i+u,n+s+c,r),s+=h}t.restore()}_renderTextFill(t){(this.fill||this.styleHas(zt))&&this._renderTextCommon(t,"fillText")}_renderTextStroke(t){(this.stroke&&this.strokeWidth!==0||!this.isEmptyStyles())&&(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this._setLineDash(t,this.strokeDashArray),t.beginPath(),this._renderTextCommon(t,"strokeText"),t.closePath(),t.restore())}_renderChars(t,e,s,i,n,r){const o=this.getHeightOfLine(r),h=this.textAlign.includes(hi),c=this.path,u=!h&&this.charSpacing===0&&this.isEmptyStyles(r)&&!c,d=this.direction==="ltr",f=this.direction==="ltr"?1:-1,g=e.direction;let p,b,v,_,x,C="",S=0;if(e.save(),g!==this.direction&&(e.canvas.setAttribute("dir",d?"ltr":"rtl"),e.direction=d?"ltr":"rtl",e.textAlign=d?dt:It),n-=o*this._fontSizeFraction/this.lineHeight,u)return this._renderChar(t,e,r,0,s.join(""),i,n),void e.restore();for(let k=0,D=s.length-1;k<=D;k++)_=k===D||this.charSpacing||c,C+=s[k],v=this.__charBounds[r][k],S===0?(i+=f*(v.kernedWidth-v.width),S+=v.width):S+=v.kernedWidth,h&&!_&&this._reSpaceAndTab.test(s[k])&&(_=!0),_||(p=p||this.getCompleteStyleDeclaration(r,k),b=this.getCompleteStyleDeclaration(r,k+1),_=au(p,b,!1)),_&&(c?(e.save(),e.translate(v.renderLeft,v.renderTop),e.rotate(v.angle),this._renderChar(t,e,r,k,C,-S/2,0),e.restore()):(x=i,this._renderChar(t,e,r,k,C,x,n)),C="",p=b,i+=f*S,S=0);e.restore()}_applyPatternGradientTransformText(t){const e=this.width+this.strokeWidth,s=this.height+this.strokeWidth,i=Rs({width:e,height:s}),n=i.getContext("2d");return i.width=e,i.height=s,n.beginPath(),n.moveTo(0,0),n.lineTo(e,0),n.lineTo(e,s),n.lineTo(0,s),n.closePath(),n.translate(e/2,s/2),n.fillStyle=t.toLive(n),this._applyPatternGradientTransform(n,t),n.fill(),n.createPattern(i,"no-repeat")}handleFiller(t,e,s){let i,n;return bs(s)?s.gradientUnits==="percentage"||s.gradientTransform||s.patternTransform?(i=-this.width/2,n=-this.height/2,t.translate(i,n),t[e]=this._applyPatternGradientTransformText(s),{offsetX:i,offsetY:n}):(t[e]=s.toLive(t),this._applyPatternGradientTransform(t,s)):(t[e]=s,{offsetX:0,offsetY:0})}_setStrokeStyles(t,e){let{stroke:s,strokeWidth:i}=e;return t.lineWidth=i,t.lineCap=this.strokeLineCap,t.lineDashOffset=this.strokeDashOffset,t.lineJoin=this.strokeLineJoin,t.miterLimit=this.strokeMiterLimit,this.handleFiller(t,"strokeStyle",s)}_setFillStyles(t,e){let{fill:s}=e;return this.handleFiller(t,"fillStyle",s)}_renderChar(t,e,s,i,n,r,o){const h=this._getStyleDeclaration(s,i),c=this.getCompleteStyleDeclaration(s,i),u=t==="fillText"&&c.fill,d=t==="strokeText"&&c.stroke&&c.strokeWidth;if(d||u){if(e.save(),e.font=this._getFontDeclaration(c),h.textBackgroundColor&&this._removeShadow(e),h.deltaY&&(o+=h.deltaY),u){const f=this._setFillStyles(e,c);e.fillText(n,r-f.offsetX,o-f.offsetY)}if(d){const f=this._setStrokeStyles(e,c);e.strokeText(n,r-f.offsetX,o-f.offsetY)}e.restore()}}setSuperscript(t,e){this._setScript(t,e,this.superscript)}setSubscript(t,e){this._setScript(t,e,this.subscript)}_setScript(t,e,s){const i=this.get2DCursorLocation(t,!0),n=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"fontSize"),r=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"deltaY"),o={fontSize:n*s.size,deltaY:r+n*s.baseline};this.setSelectionStyles(o,t,e)}_getLineLeftOffset(t){const e=this.getLineWidth(t),s=this.width-e,i=this.textAlign,n=this.direction,r=this.isEndOfWrapping(t);let o=0;return i===hi||i===jh&&!r||i===Nh&&!r||i===bu&&!r?0:(i===Q&&(o=s/2),i===It&&(o=s),i===jh&&(o=s/2),i===Nh&&(o=s),n==="rtl"&&(i===It||i===hi||i===Nh?o=0:i===dt||i===bu?o=-s:i!==Q&&i!==jh||(o=-s/2)),o)}_clearCache(){this._forceClearCache=!1,this.__lineWidths=[],this.__lineHeights=[],this.__charBounds=[]}getLineWidth(t){if(this.__lineWidths[t]!==void 0)return this.__lineWidths[t];const{width:e}=this.measureLine(t);return this.__lineWidths[t]=e,e}_getWidthOfCharSpacing(){return this.charSpacing!==0?this.fontSize*this.charSpacing/1e3:0}getValueOfPropertyAt(t,e,s){var i;return(i=this._getStyleDeclaration(t,e)[s])!==null&&i!==void 0?i:this[s]}_renderTextDecoration(t,e){if(!this[e]&&!this.styleHas(e))return;let s=this._getTopOffset();const i=this._getLeftOffset(),n=this.path,r=this._getWidthOfCharSpacing(),o=this.offsets[e];for(let h=0,c=this._textLines.length;h<c;h++){const u=this.getHeightOfLine(h);if(!this[e]&&!this.styleHas(e,h)){s+=u;continue}const d=this._textLines[h],f=u/this.lineHeight,g=this._getLineLeftOffset(h);let p,b,v=0,_=0,x=this.getValueOfPropertyAt(h,0,e),C=this.getValueOfPropertyAt(h,0,zt);const S=s+f*(1-this._fontSizeFraction);let k=this.getHeightOfChar(h,0),D=this.getValueOfPropertyAt(h,0,"deltaY");for(let M=0,O=d.length;M<O;M++){const R=this.__charBounds[h][M];p=this.getValueOfPropertyAt(h,M,e),b=this.getValueOfPropertyAt(h,M,zt);const L=this.getHeightOfChar(h,M),W=this.getValueOfPropertyAt(h,M,"deltaY");if(n&&p&&b)t.save(),t.fillStyle=C,t.translate(R.renderLeft,R.renderTop),t.rotate(R.angle),t.fillRect(-R.kernedWidth/2,o*L+W,R.kernedWidth,this.fontSize/15),t.restore();else if((p!==x||b!==C||L!==k||W!==D)&&_>0){let U=i+g+v;this.direction==="rtl"&&(U=this.width-U-_),x&&C&&(t.fillStyle=C,t.fillRect(U,S+o*k+D,_,this.fontSize/15)),v=R.left,_=R.width,x=p,C=b,k=L,D=W}else _+=R.kernedWidth}let T=i+g+v;this.direction==="rtl"&&(T=this.width-T-_),t.fillStyle=b,p&&b&&t.fillRect(T,S+o*k+D,_-r,this.fontSize/15),s+=u}this._removeShadow(t)}_getFontDeclaration(){let{fontFamily:t=this.fontFamily,fontStyle:e=this.fontStyle,fontWeight:s=this.fontWeight,fontSize:i=this.fontSize}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;const r=t.includes("'")||t.includes('"')||t.includes(",")||me.genericFonts.includes(t.toLowerCase())?t:'"'.concat(t,'"');return[e,s,"".concat(n?this.CACHE_FONT_SIZE:i,"px"),r].join(" ")}render(t){this.visible&&(this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(this._forceClearCache&&this.initDimensions(),super.render(t)))}graphemeSplit(t){return ou(t)}_splitTextIntoLines(t){const e=t.split(this._reNewline),s=new Array(e.length),i=[`
54
- `];let n=[];for(let r=0;r<e.length;r++)s[r]=this.graphemeSplit(e[r]),n=n.concat(s[r],i);return n.pop(),{_unwrappedLines:s,lines:e,graphemeText:n,graphemeLines:s}}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return E(E({},super.toObject([...O0,...t])),{},{styles:$m(this.styles,this.text)},this.path?{path:this.path.toObject()}:{})}set(t,e){const{textLayoutProperties:s}=this.constructor;super.set(t,e);let i=!1,n=!1;if(typeof t=="object")for(const r in t)r==="path"&&this.setPathInfo(),i=i||s.includes(r),n=n||r==="path";else i=s.includes(t),n=t==="path";return n&&this.setPathInfo(),i&&this.initialized&&(this.initDimensions(),this.setCoords()),this}complexity(){return 1}static async fromElement(t,e,s){const i=Ni(t,me.ATTRIBUTE_NAMES,s),n=E(E({},e),i),{textAnchor:r=dt,textDecoration:o="",dx:h=0,dy:c=0,top:u=0,left:d=0,fontSize:f=of,strokeWidth:g=1}=n,p=Ct(n,_w),b=new this((t.textContent||"").replace(/^\s+|\s+$|\n+/g,"").replace(/\s+/g," "),E({left:d+h,top:u+c,underline:o.includes("underline"),overline:o.includes("overline"),linethrough:o.includes("line-through"),strokeWidth:0,fontSize:f},p)),v=b.getScaledHeight()/b.height,_=((b.height+b.strokeWidth)*b.lineHeight-b.height)*v,x=b.getScaledHeight()+_;let C=0;return r===Q&&(C=b.getScaledWidth()/2),r===It&&(C=b.getScaledWidth()),b.set({left:b.left-C,top:b.top-(x-b.fontSize*(.07+b._fontSizeFraction))/b.lineHeight,strokeWidth:g}),b}static fromObject(t){return this._fromObject(E(E({},t),{},{styles:qm(t.styles||{},t.text)}),{extraParam:"text"})}}A(me,"textLayoutProperties",D0),A(me,"cacheProperties",[...Fi,...O0]),A(me,"ownDefaults",bw),A(me,"type","Text"),A(me,"genericFonts",["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","math","emoji","fangsong"]),A(me,"ATTRIBUTE_NAMES",Mn.concat("x","y","dx","dy","font-family","font-style","font-weight","font-size","letter-spacing","text-decoration","text-anchor")),zm(me,[class extends xm{_toSVG(){const a=this._getSVGLeftTopOffsets(),t=this._getSVGTextAndBg(a.textTop,a.textLeft);return this._wrapSVGTextAndBg(t)}toSVG(a){return this._createBaseSVGMarkup(this._toSVG(),{reviver:a,noStyle:!0,withShadow:!0})}_getSVGLeftTopOffsets(){return{textLeft:-this.width/2,textTop:-this.height/2,lineTop:this.getHeightOfLine(0)}}_wrapSVGTextAndBg(a){let{textBgRects:t,textSpans:e}=a;const s=this.getSvgTextDecoration(this);return[t.join(""),' <text xml:space="preserve" ',this.fontFamily?'font-family="'.concat(this.fontFamily.replace(vw,"'"),'" '):"",this.fontSize?'font-size="'.concat(this.fontSize,'" '):"",this.fontStyle?'font-style="'.concat(this.fontStyle,'" '):"",this.fontWeight?'font-weight="'.concat(this.fontWeight,'" '):"",s?'text-decoration="'.concat(s,'" '):"",this.direction==="rtl"?'direction="'.concat(this.direction,'" '):"",'style="',this.getSvgStyles(!0),'"',this.addPaintOrder()," >",e.join(""),`</text>
55
- `]}_getSVGTextAndBg(a,t){const e=[],s=[];let i,n=a;this.backgroundColor&&s.push(...$f(this.backgroundColor,-this.width/2,-this.height/2,this.width,this.height));for(let r=0,o=this._textLines.length;r<o;r++)i=this._getLineLeftOffset(r),this.direction==="rtl"&&(i+=this.width),(this.textBackgroundColor||this.styleHas("textBackgroundColor",r))&&this._setSVGTextLineBg(s,r,t+i,n),this._setSVGTextLineText(e,r,t+i,n),n+=this.getHeightOfLine(r);return{textSpans:e,textBgRects:s}}_createTextCharSpan(a,t,e,s){const i=this.getSvgSpanStyles(t,a!==a.trim()||!!a.match(yw)),n=i?'style="'.concat(i,'"'):"",r=t.deltaY,o=r?' dy="'.concat(At(r,ht.NUM_FRACTION_DIGITS),'" '):"";return'<tspan x="'.concat(At(e,ht.NUM_FRACTION_DIGITS),'" y="').concat(At(s,ht.NUM_FRACTION_DIGITS),'" ').concat(o).concat(n,">").concat(Ym(a),"</tspan>")}_setSVGTextLineText(a,t,e,s){const i=this.getHeightOfLine(t),n=this.textAlign.includes(hi),r=this._textLines[t];let o,h,c,u,d,f="",g=0;s+=i*(1-this._fontSizeFraction)/this.lineHeight;for(let p=0,b=r.length-1;p<=b;p++)d=p===b||this.charSpacing,f+=r[p],c=this.__charBounds[t][p],g===0?(e+=c.kernedWidth-c.width,g+=c.width):g+=c.kernedWidth,n&&!d&&this._reSpaceAndTab.test(r[p])&&(d=!0),d||(o=o||this.getCompleteStyleDeclaration(t,p),h=this.getCompleteStyleDeclaration(t,p+1),d=au(o,h,!0)),d&&(u=this._getStyleDeclaration(t,p),a.push(this._createTextCharSpan(f,u,e,s)),f="",o=h,this.direction==="rtl"?e-=g:e+=g,g=0)}_setSVGTextLineBg(a,t,e,s){const i=this._textLines[t],n=this.getHeightOfLine(t)/this.lineHeight;let r,o=0,h=0,c=this.getValueOfPropertyAt(t,0,"textBackgroundColor");for(let u=0;u<i.length;u++){const{left:d,width:f,kernedWidth:g}=this.__charBounds[t][u];r=this.getValueOfPropertyAt(t,u,"textBackgroundColor"),r!==c?(c&&a.push(...$f(c,e+h,s,o,n)),h=d,o=f,c=r):o+=g}r&&a.push(...$f(c,e+h,s,o,n))}_getSVGLineTopOffset(a){let t,e=0;for(t=0;t<a;t++)e+=this.getHeightOfLine(t);const s=this.getHeightOfLine(t);return{lineTop:e,offset:(this._fontSizeMult-this._fontSizeFraction)*s/(this.lineHeight*this._fontSizeMult)}}getSvgStyles(a){return"".concat(super.getSvgStyles(a)," white-space: pre;")}getSvgSpanStyles(a,t){const{fontFamily:e,strokeWidth:s,stroke:i,fill:n,fontSize:r,fontStyle:o,fontWeight:h,deltaY:c}=a,u=this.getSvgTextDecoration(a);return[i?Mh(Pe,i):"",s?"stroke-width: ".concat(s,"; "):"",e?"font-family: ".concat(e.includes("'")||e.includes('"')?e:"'".concat(e,"'"),"; "):"",r?"font-size: ".concat(r,"px; "):"",o?"font-style: ".concat(o,"; "):"",h?"font-weight: ".concat(h,"; "):"",u&&"text-decoration: ".concat(u,"; "),n?Mh(zt,n):"",c?"baseline-shift: ".concat(-c,"; "):"",t?"white-space: pre; ":""].join("")}getSvgTextDecoration(a){return["overline","underline","line-through"].filter(t=>a[t.replace("-","")]).join(" ")}}]),N.setClass(me),N.setSVGClass(me);class ww{constructor(t){A(this,"target",void 0),A(this,"__mouseDownInPlace",!1),A(this,"__dragStartFired",!1),A(this,"__isDraggingOver",!1),A(this,"__dragStartSelection",void 0),A(this,"__dragImageDisposer",void 0),A(this,"_dispose",void 0),this.target=t;const e=[this.target.on("dragenter",this.dragEnterHandler.bind(this)),this.target.on("dragover",this.dragOverHandler.bind(this)),this.target.on("dragleave",this.dragLeaveHandler.bind(this)),this.target.on("dragend",this.dragEndHandler.bind(this)),this.target.on("drop",this.dropHandler.bind(this))];this._dispose=()=>{e.forEach(s=>s()),this._dispose=void 0}}isPointerOverSelection(t){const e=this.target,s=e.getSelectionStartFromPointer(t);return e.isEditing&&s>=e.selectionStart&&s<=e.selectionEnd&&e.selectionStart<e.selectionEnd}start(t){return this.__mouseDownInPlace=this.isPointerOverSelection(t)}isActive(){return this.__mouseDownInPlace}end(t){const e=this.isActive();return e&&!this.__dragStartFired&&(this.target.setCursorByClick(t),this.target.initDelayedCursor(!0)),this.__mouseDownInPlace=!1,this.__dragStartFired=!1,this.__isDraggingOver=!1,e}getDragStartSelection(){return this.__dragStartSelection}setDragImage(t,e){var s;let{selectionStart:i,selectionEnd:n}=e;const r=this.target,o=r.canvas,h=new P(r.flipX?-1:1,r.flipY?-1:1),c=r._getCursorBoundaries(i),u=new P(c.left+c.leftOffset,c.top+c.topOffset).multiply(h).transform(r.calcTransformMatrix()),d=o.getScenePoint(t).subtract(u),f=r.getCanvasRetinaScaling(),g=r.getBoundingRect(),p=u.subtract(new P(g.left,g.top)),b=o.viewportTransform,v=p.add(d).transform(b,!0),_=r.backgroundColor,x=Nf(r.styles);r.backgroundColor="";const C={stroke:"transparent",fill:"transparent",textBackgroundColor:"transparent"};r.setSelectionStyles(C,0,i),r.setSelectionStyles(C,n,r.text.length),r.dirty=!0;const S=r.toCanvasElement({enableRetinaScaling:o.enableRetinaScaling,viewportTransform:!0});r.backgroundColor=_,r.styles=x,r.dirty=!0,fu(S,{position:"fixed",left:"".concat(-S.width,"px"),border:ke,width:"".concat(S.width/f,"px"),height:"".concat(S.height/f,"px")}),this.__dragImageDisposer&&this.__dragImageDisposer(),this.__dragImageDisposer=()=>{S.remove()},Ls(t.target||this.target.hiddenTextarea).body.appendChild(S),(s=t.dataTransfer)===null||s===void 0||s.setDragImage(S,v.x,v.y)}onDragStart(t){this.__dragStartFired=!0;const e=this.target,s=this.isActive();if(s&&t.dataTransfer){const i=this.__dragStartSelection={selectionStart:e.selectionStart,selectionEnd:e.selectionEnd},n=e._text.slice(i.selectionStart,i.selectionEnd).join(""),r=E({text:e.text,value:n},i);t.dataTransfer.setData("text/plain",n),t.dataTransfer.setData("application/fabric",JSON.stringify({value:n,styles:e.getSelectionStyles(i.selectionStart,i.selectionEnd,!0)})),t.dataTransfer.effectAllowed="copyMove",this.setDragImage(t,r)}return e.abortCursorAnimation(),s}canDrop(t){if(this.target.editable&&!this.target.getActiveControl()&&!t.defaultPrevented){if(this.isActive()&&this.__dragStartSelection){const e=this.target.getSelectionStartFromPointer(t),s=this.__dragStartSelection;return e<s.selectionStart||e>s.selectionEnd}return!0}return!1}targetCanDrop(t){return this.target.canDrop(t)}dragEnterHandler(t){let{e}=t;const s=this.targetCanDrop(e);!this.__isDraggingOver&&s&&(this.__isDraggingOver=!0)}dragOverHandler(t){const{e}=t,s=this.targetCanDrop(e);!this.__isDraggingOver&&s?this.__isDraggingOver=!0:this.__isDraggingOver&&!s&&(this.__isDraggingOver=!1),this.__isDraggingOver&&(e.preventDefault(),t.canDrop=!0,t.dropTarget=this.target)}dragLeaveHandler(){(this.__isDraggingOver||this.isActive())&&(this.__isDraggingOver=!1)}dropHandler(t){var e;const{e:s}=t,i=s.defaultPrevented;this.__isDraggingOver=!1,s.preventDefault();let n=(e=s.dataTransfer)===null||e===void 0?void 0:e.getData("text/plain");if(n&&!i){const r=this.target,o=r.canvas;let h=r.getSelectionStartFromPointer(s);const{styles:c}=s.dataTransfer.types.includes("application/fabric")?JSON.parse(s.dataTransfer.getData("application/fabric")):{},u=n[Math.max(0,n.length-1)],d=0;if(this.__dragStartSelection){const f=this.__dragStartSelection.selectionStart,g=this.__dragStartSelection.selectionEnd;h>f&&h<=g?h=f:h>g&&(h-=g-f),r.removeChars(f,g),delete this.__dragStartSelection}r._reNewline.test(u)&&(r._reNewline.test(r._text[h])||h===r._text.length)&&(n=n.trimEnd()),t.didDrop=!0,t.dropTarget=r,r.insertChars(n,c,h),o.setActiveObject(r),r.enterEditing(s),r.selectionStart=Math.min(h+d,r._text.length),r.selectionEnd=Math.min(r.selectionStart+n.length,r._text.length),r.hiddenTextarea.value=r.text,r._updateTextarea(),r.hiddenTextarea.focus(),r.fire(Gc,{index:h+d,action:"drop"}),o.fire("text:changed",{target:r}),o.contextTopDirty=!0,o.requestRenderAll()}}dragEndHandler(t){let{e}=t;if(this.isActive()&&this.__dragStartFired&&this.__dragStartSelection){var s;const i=this.target,n=this.target.canvas,{selectionStart:r,selectionEnd:o}=this.__dragStartSelection,h=((s=e.dataTransfer)===null||s===void 0?void 0:s.dropEffect)||ke;h===ke?(i.selectionStart=r,i.selectionEnd=o,i._updateTextarea(),i.hiddenTextarea.focus()):(i.clearContextTop(),h==="move"&&(i.removeChars(r,o),i.selectionStart=i.selectionEnd=r,i.hiddenTextarea&&(i.hiddenTextarea.value=i.text),i._updateTextarea(),i.fire(Gc,{index:r,action:"dragend"}),n.fire("text:changed",{target:i}),n.requestRenderAll()),i.exitEditing())}this.__dragImageDisposer&&this.__dragImageDisposer(),delete this.__dragImageDisposer,delete this.__dragStartSelection,this.__isDraggingOver=!1}dispose(){this._dispose&&this._dispose()}}const L0=/[ \n\.,;!\?\-]/;class xw extends me{constructor(){super(...arguments),A(this,"_currentCursorOpacity",1)}initBehavior(){this._tick=this._tick.bind(this),this._onTickComplete=this._onTickComplete.bind(this),this.updateSelectionOnMouseMove=this.updateSelectionOnMouseMove.bind(this)}onDeselect(t){return this.isEditing&&this.exitEditing(),this.selected=!1,super.onDeselect(t)}_animateCursor(t){let{toValue:e,duration:s,delay:i,onComplete:n}=t;return Lf({startValue:this._currentCursorOpacity,endValue:e,duration:s,delay:i,onComplete:n,abort:()=>!this.canvas||this.selectionStart!==this.selectionEnd,onChange:r=>{this._currentCursorOpacity=r,this.renderCursorOrSelection()}})}_tick(t){this._currentTickState=this._animateCursor({toValue:0,duration:this.cursorDuration/2,delay:Math.max(t||0,100),onComplete:this._onTickComplete})}_onTickComplete(){var t;(t=this._currentTickCompleteState)===null||t===void 0||t.abort(),this._currentTickCompleteState=this._animateCursor({toValue:1,duration:this.cursorDuration,onComplete:this._tick})}initDelayedCursor(t){this.abortCursorAnimation(),this._tick(t?0:this.cursorDelay)}abortCursorAnimation(){let t=!1;[this._currentTickState,this._currentTickCompleteState].forEach(e=>{e&&!e.isDone()&&(t=!0,e.abort())}),this._currentCursorOpacity=1,t&&this.clearContextTop()}restartCursorIfNeeded(){[this._currentTickState,this._currentTickCompleteState].some(t=>!t||t.isDone())&&this.initDelayedCursor()}selectAll(){return this.selectionStart=0,this.selectionEnd=this._text.length,this._fireSelectionChanged(),this._updateTextarea(),this}getSelectedText(){return this._text.slice(this.selectionStart,this.selectionEnd).join("")}findWordBoundaryLeft(t){let e=0,s=t-1;if(this._reSpace.test(this._text[s]))for(;this._reSpace.test(this._text[s]);)e++,s--;for(;/\S/.test(this._text[s])&&s>-1;)e++,s--;return t-e}findWordBoundaryRight(t){let e=0,s=t;if(this._reSpace.test(this._text[s]))for(;this._reSpace.test(this._text[s]);)e++,s++;for(;/\S/.test(this._text[s])&&s<this._text.length;)e++,s++;return t+e}findLineBoundaryLeft(t){let e=0,s=t-1;for(;!/\n/.test(this._text[s])&&s>-1;)e++,s--;return t-e}findLineBoundaryRight(t){let e=0,s=t;for(;!/\n/.test(this._text[s])&&s<this._text.length;)e++,s++;return t+e}searchWordBoundary(t,e){const s=this._text;let i=t>0&&this._reSpace.test(s[t])&&(e===-1||!hf.test(s[t-1]))?t-1:t,n=s[i];for(;i>0&&i<s.length&&!L0.test(n);)i+=e,n=s[i];return e===-1&&L0.test(n)&&i++,i}selectWord(t){t=t||this.selectionStart;const e=this.searchWordBoundary(t,-1),s=Math.max(e,this.searchWordBoundary(t,1));this.selectionStart=e,this.selectionEnd=s,this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()}selectLine(t){t=t||this.selectionStart;const e=this.findLineBoundaryLeft(t),s=this.findLineBoundaryRight(t);return this.selectionStart=e,this.selectionEnd=s,this._fireSelectionChanged(),this._updateTextarea(),this}enterEditing(t){!this.isEditing&&this.editable&&(this.enterEditingImpl(),this.fire("editing:entered",t?{e:t}:void 0),this._fireSelectionChanged(),this.canvas&&(this.canvas.fire("text:editing:entered",{target:this,e:t}),this.canvas.requestRenderAll()))}enterEditingImpl(){this.canvas&&(this.canvas.calcOffset(),this.canvas.textEditingManager.exitTextEditing()),this.isEditing=!0,this.initHiddenTextarea(),this.hiddenTextarea.focus(),this.hiddenTextarea.value=this.text,this._updateTextarea(),this._saveEditingProps(),this._setEditingProps(),this._textBeforeEdit=this.text,this._tick()}updateSelectionOnMouseMove(t){if(this.getActiveControl())return;const e=this.hiddenTextarea;Ls(e).activeElement!==e&&e.focus();const s=this.getSelectionStartFromPointer(t),i=this.selectionStart,n=this.selectionEnd;(s===this.__selectionStartOnMouseDown&&i!==n||i!==s&&n!==s)&&(s>this.__selectionStartOnMouseDown?(this.selectionStart=this.__selectionStartOnMouseDown,this.selectionEnd=s):(this.selectionStart=s,this.selectionEnd=this.__selectionStartOnMouseDown),this.selectionStart===i&&this.selectionEnd===n||(this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()))}_setEditingProps(){this.hoverCursor="text",this.canvas&&(this.canvas.defaultCursor=this.canvas.moveCursor="text"),this.borderColor=this.editingBorderColor,this.hasControls=this.selectable=!1,this.lockMovementX=this.lockMovementY=!0}fromStringToGraphemeSelection(t,e,s){const i=s.slice(0,t),n=this.graphemeSplit(i).length;if(t===e)return{selectionStart:n,selectionEnd:n};const r=s.slice(t,e);return{selectionStart:n,selectionEnd:n+this.graphemeSplit(r).length}}fromGraphemeToStringSelection(t,e,s){const i=s.slice(0,t).join("").length;return t===e?{selectionStart:i,selectionEnd:i}:{selectionStart:i,selectionEnd:i+s.slice(t,e).join("").length}}_updateTextarea(){if(this.cursorOffsetCache={},this.hiddenTextarea){if(!this.inCompositionMode){const t=this.fromGraphemeToStringSelection(this.selectionStart,this.selectionEnd,this._text);this.hiddenTextarea.selectionStart=t.selectionStart,this.hiddenTextarea.selectionEnd=t.selectionEnd}this.updateTextareaPosition()}}updateFromTextArea(){if(!this.hiddenTextarea)return;this.cursorOffsetCache={};const t=this.hiddenTextarea;this.text=t.value,this.set("dirty",!0),this.initDimensions(),this.setCoords();const e=this.fromStringToGraphemeSelection(t.selectionStart,t.selectionEnd,t.value);this.selectionEnd=this.selectionStart=e.selectionEnd,this.inCompositionMode||(this.selectionStart=e.selectionStart),this.updateTextareaPosition()}updateTextareaPosition(){if(this.selectionStart===this.selectionEnd){const t=this._calcTextareaPosition();this.hiddenTextarea.style.left=t.left,this.hiddenTextarea.style.top=t.top}}_calcTextareaPosition(){if(!this.canvas)return{left:"1px",top:"1px"};const t=this.inCompositionMode?this.compositionStart:this.selectionStart,e=this._getCursorBoundaries(t),s=this.get2DCursorLocation(t),i=s.lineIndex,n=s.charIndex,r=this.getValueOfPropertyAt(i,n,"fontSize")*this.lineHeight,o=e.leftOffset,h=this.getCanvasRetinaScaling(),c=this.canvas.upperCanvasEl,u=c.width/h,d=c.height/h,f=u-r,g=d-r,p=new P(e.left+o,e.top+e.topOffset+r).transform(this.calcTransformMatrix()).transform(this.canvas.viewportTransform).multiply(new P(c.clientWidth/u,c.clientHeight/d));return p.x<0&&(p.x=0),p.x>f&&(p.x=f),p.y<0&&(p.y=0),p.y>g&&(p.y=g),p.x+=this.canvas._offset.left,p.y+=this.canvas._offset.top,{left:"".concat(p.x,"px"),top:"".concat(p.y,"px"),fontSize:"".concat(r,"px"),charHeight:r}}_saveEditingProps(){this._savedProps={hasControls:this.hasControls,borderColor:this.borderColor,lockMovementX:this.lockMovementX,lockMovementY:this.lockMovementY,hoverCursor:this.hoverCursor,selectable:this.selectable,defaultCursor:this.canvas&&this.canvas.defaultCursor,moveCursor:this.canvas&&this.canvas.moveCursor}}_restoreEditingProps(){this._savedProps&&(this.hoverCursor=this._savedProps.hoverCursor,this.hasControls=this._savedProps.hasControls,this.borderColor=this._savedProps.borderColor,this.selectable=this._savedProps.selectable,this.lockMovementX=this._savedProps.lockMovementX,this.lockMovementY=this._savedProps.lockMovementY,this.canvas&&(this.canvas.defaultCursor=this._savedProps.defaultCursor||this.canvas.defaultCursor,this.canvas.moveCursor=this._savedProps.moveCursor||this.canvas.moveCursor),delete this._savedProps)}_exitEditing(){const t=this.hiddenTextarea;this.selected=!1,this.isEditing=!1,t&&(t.blur&&t.blur(),t.parentNode&&t.parentNode.removeChild(t)),this.hiddenTextarea=null,this.abortCursorAnimation(),this.selectionStart!==this.selectionEnd&&this.clearContextTop()}exitEditingImpl(){this._exitEditing(),this.selectionEnd=this.selectionStart,this._restoreEditingProps(),this._forceClearCache&&(this.initDimensions(),this.setCoords())}exitEditing(){const t=this._textBeforeEdit!==this.text;return this.exitEditingImpl(),this.fire("editing:exited"),t&&this.fire(Vc),this.canvas&&(this.canvas.fire("text:editing:exited",{target:this}),t&&this.canvas.fire("object:modified",{target:this})),this}_removeExtraneousStyles(){for(const t in this.styles)this._textLines[t]||delete this.styles[t]}removeStyleFromTo(t,e){const{lineIndex:s,charIndex:i}=this.get2DCursorLocation(t,!0),{lineIndex:n,charIndex:r}=this.get2DCursorLocation(e,!0);if(s!==n){if(this.styles[s])for(let o=i;o<this._unwrappedTextLines[s].length;o++)delete this.styles[s][o];if(this.styles[n])for(let o=r;o<this._unwrappedTextLines[n].length;o++){const h=this.styles[n][o];h&&(this.styles[s]||(this.styles[s]={}),this.styles[s][i+o-r]=h)}for(let o=s+1;o<=n;o++)delete this.styles[o];this.shiftLineStyles(n,s-n)}else if(this.styles[s]){const o=this.styles[s],h=r-i;for(let c=i;c<r;c++)delete o[c];for(const c in this.styles[s]){const u=parseInt(c,10);u>=r&&(o[u-h]=o[c],delete o[c])}}}shiftLineStyles(t,e){const s=Object.assign({},this.styles);for(const i in this.styles){const n=parseInt(i,10);n>t&&(this.styles[n+e]=s[n],s[n-e]||delete this.styles[n])}}insertNewlineStyleObject(t,e,s,i){const n={},r=this._unwrappedTextLines[t].length,o=r===e;let h=!1;s||(s=1),this.shiftLineStyles(t,s);const c=this.styles[t]?this.styles[t][e===0?e:e-1]:void 0;for(const d in this.styles[t]){const f=parseInt(d,10);f>=e&&(h=!0,n[f-e]=this.styles[t][d],o&&e===0||delete this.styles[t][d])}let u=!1;for(h&&!o&&(this.styles[t+s]=n,u=!0),(u||r>e)&&s--;s>0;)i&&i[s-1]?this.styles[t+s]={0:E({},i[s-1])}:c?this.styles[t+s]={0:E({},c)}:delete this.styles[t+s],s--;this._forceClearCache=!0}insertCharStyleObject(t,e,s,i){this.styles||(this.styles={});const n=this.styles[t],r=n?E({},n):{};s||(s=1);for(const h in r){const c=parseInt(h,10);c>=e&&(n[c+s]=r[c],r[c-s]||delete n[c])}if(this._forceClearCache=!0,i){for(;s--;)Object.keys(i[s]).length&&(this.styles[t]||(this.styles[t]={}),this.styles[t][e+s]=E({},i[s]));return}if(!n)return;const o=n[e?e-1:1];for(;o&&s--;)this.styles[t][e+s]=E({},o)}insertNewStyleBlock(t,e,s){const i=this.get2DCursorLocation(e,!0),n=[0];let r,o=0;for(let h=0;h<t.length;h++)t[h]===`
56
- `?(o++,n[o]=0):n[o]++;for(n[0]>0&&(this.insertCharStyleObject(i.lineIndex,i.charIndex,n[0],s),s=s&&s.slice(n[0]+1)),o&&this.insertNewlineStyleObject(i.lineIndex,i.charIndex+n[0],o),r=1;r<o;r++)n[r]>0?this.insertCharStyleObject(i.lineIndex+r,0,n[r],s):s&&this.styles[i.lineIndex+r]&&s[0]&&(this.styles[i.lineIndex+r][0]=s[0]),s=s&&s.slice(n[r]+1);n[r]>0&&this.insertCharStyleObject(i.lineIndex+r,0,n[r],s)}removeChars(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:t+1;this.removeStyleFromTo(t,e),this._text.splice(t,e-t),this.text=this._text.join(""),this.set("dirty",!0),this.initDimensions(),this.setCoords(),this._removeExtraneousStyles()}insertChars(t,e,s){let i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:s;i>s&&this.removeStyleFromTo(s,i);const n=this.graphemeSplit(t);this.insertNewStyleBlock(n,s,e),this._text=[...this._text.slice(0,s),...n,...this._text.slice(i)],this.text=this._text.join(""),this.set("dirty",!0),this.initDimensions(),this.setCoords(),this._removeExtraneousStyles()}setSelectionStartEndWithShift(t,e,s){s<=t?(e===t?this._selectionDirection=dt:this._selectionDirection===It&&(this._selectionDirection=dt,this.selectionEnd=t),this.selectionStart=s):s>t&&s<e?this._selectionDirection===It?this.selectionEnd=s:this.selectionStart=s:(e===t?this._selectionDirection=It:this._selectionDirection===dt&&(this._selectionDirection=It,this.selectionStart=e),this.selectionEnd=s)}}class Sw extends xw{initHiddenTextarea(){const t=this.canvas&&Ls(this.canvas.getElement())||Vo(),e=t.createElement("textarea");Object.entries({autocapitalize:"off",autocorrect:"off",autocomplete:"off",spellcheck:"false","data-fabric":"textarea",wrap:"off"}).map(r=>{let[o,h]=r;return e.setAttribute(o,h)});const{top:s,left:i,fontSize:n}=this._calcTextareaPosition();e.style.cssText="position: absolute; top: ".concat(s,"; left: ").concat(i,"; z-index: -999; opacity: 0; width: 1px; height: 1px; font-size: 1px; padding-top: ").concat(n,";"),(this.hiddenTextareaContainer||t.body).appendChild(e),Object.entries({blur:"blur",keydown:"onKeyDown",keyup:"onKeyUp",input:"onInput",copy:"copy",cut:"copy",paste:"paste",compositionstart:"onCompositionStart",compositionupdate:"onCompositionUpdate",compositionend:"onCompositionEnd"}).map(r=>{let[o,h]=r;return e.addEventListener(o,this[h].bind(this))}),this.hiddenTextarea=e}blur(){this.abortCursorAnimation()}onKeyDown(t){if(!this.isEditing)return;const e=this.direction==="rtl"?this.keysMapRtl:this.keysMap;if(t.keyCode in e)this[e[t.keyCode]](t);else{if(!(t.keyCode in this.ctrlKeysMapDown)||!t.ctrlKey&&!t.metaKey)return;this[this.ctrlKeysMapDown[t.keyCode]](t)}t.stopImmediatePropagation(),t.preventDefault(),t.keyCode>=33&&t.keyCode<=40?(this.inCompositionMode=!1,this.clearContextTop(),this.renderCursorOrSelection()):this.canvas&&this.canvas.requestRenderAll()}onKeyUp(t){!this.isEditing||this._copyDone||this.inCompositionMode?this._copyDone=!1:t.keyCode in this.ctrlKeysMapUp&&(t.ctrlKey||t.metaKey)&&(this[this.ctrlKeysMapUp[t.keyCode]](t),t.stopImmediatePropagation(),t.preventDefault(),this.canvas&&this.canvas.requestRenderAll())}onInput(t){const e=this.fromPaste;if(this.fromPaste=!1,t&&t.stopPropagation(),!this.isEditing)return;const s=()=>{this.updateFromTextArea(),this.fire(Gc),this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll())};if(this.hiddenTextarea.value==="")return this.styles={},void s();const i=this._splitTextIntoLines(this.hiddenTextarea.value).graphemeText,n=this._text.length,r=i.length,o=this.selectionStart,h=this.selectionEnd,c=o!==h;let u,d,f,g,p=r-n;const b=this.fromStringToGraphemeSelection(this.hiddenTextarea.selectionStart,this.hiddenTextarea.selectionEnd,this.hiddenTextarea.value),v=o>b.selectionStart;c?(d=this._text.slice(o,h),p+=h-o):r<n&&(d=v?this._text.slice(h+p,h):this._text.slice(o,o-p));const _=i.slice(b.selectionEnd-p,b.selectionEnd);if(d&&d.length&&(_.length&&(u=this.getSelectionStyles(o,o+1,!1),u=_.map(()=>u[0])),c?(f=o,g=h):v?(f=h-d.length,g=h):(f=h,g=h+d.length),this.removeStyleFromTo(f,g)),_.length){const{copyPasteData:x}=ni();e&&_.join("")===x.copiedText&&!ht.disableStyleCopyPaste&&(u=x.copiedTextStyle),this.insertNewStyleBlock(_,o,u)}s()}onCompositionStart(){this.inCompositionMode=!0}onCompositionEnd(){this.inCompositionMode=!1}onCompositionUpdate(t){let{target:e}=t;const{selectionStart:s,selectionEnd:i}=e;this.compositionStart=s,this.compositionEnd=i,this.updateTextareaPosition()}copy(){if(this.selectionStart===this.selectionEnd)return;const{copyPasteData:t}=ni();t.copiedText=this.getSelectedText(),ht.disableStyleCopyPaste?t.copiedTextStyle=void 0:t.copiedTextStyle=this.getSelectionStyles(this.selectionStart,this.selectionEnd,!0),this._copyDone=!0}paste(){this.fromPaste=!0}_getWidthBeforeCursor(t,e){let s,i=this._getLineLeftOffset(t);return e>0&&(s=this.__charBounds[t][e-1],i+=s.left+s.width),i}getDownCursorOffset(t,e){const s=this._getSelectionForOffset(t,e),i=this.get2DCursorLocation(s),n=i.lineIndex;if(n===this._textLines.length-1||t.metaKey||t.keyCode===34)return this._text.length-s;const r=i.charIndex,o=this._getWidthBeforeCursor(n,r),h=this._getIndexOnLine(n+1,o);return this._textLines[n].slice(r).length+h+1+this.missingNewlineOffset(n)}_getSelectionForOffset(t,e){return t.shiftKey&&this.selectionStart!==this.selectionEnd&&e?this.selectionEnd:this.selectionStart}getUpCursorOffset(t,e){const s=this._getSelectionForOffset(t,e),i=this.get2DCursorLocation(s),n=i.lineIndex;if(n===0||t.metaKey||t.keyCode===33)return-s;const r=i.charIndex,o=this._getWidthBeforeCursor(n,r),h=this._getIndexOnLine(n-1,o),c=this._textLines[n].slice(0,r),u=this.missingNewlineOffset(n-1);return-this._textLines[n-1].length+h-c.length+(1-u)}_getIndexOnLine(t,e){const s=this._textLines[t];let i,n,r=this._getLineLeftOffset(t),o=0;for(let h=0,c=s.length;h<c;h++)if(i=this.__charBounds[t][h].width,r+=i,r>e){n=!0;const u=r-i,d=r,f=Math.abs(u-e);o=Math.abs(d-e)<f?h:h-1;break}return n||(o=s.length-1),o}moveCursorDown(t){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorUpOrDown("Down",t)}moveCursorUp(t){this.selectionStart===0&&this.selectionEnd===0||this._moveCursorUpOrDown("Up",t)}_moveCursorUpOrDown(t,e){const s=this["get".concat(t,"CursorOffset")](e,this._selectionDirection===It);if(e.shiftKey?this.moveCursorWithShift(s):this.moveCursorWithoutShift(s),s!==0){const i=this.text.length;this.selectionStart=wr(0,this.selectionStart,i),this.selectionEnd=wr(0,this.selectionEnd,i),this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea()}}moveCursorWithShift(t){const e=this._selectionDirection===dt?this.selectionStart+t:this.selectionEnd+t;return this.setSelectionStartEndWithShift(this.selectionStart,this.selectionEnd,e),t!==0}moveCursorWithoutShift(t){return t<0?(this.selectionStart+=t,this.selectionEnd=this.selectionStart):(this.selectionEnd+=t,this.selectionStart=this.selectionEnd),t!==0}moveCursorLeft(t){this.selectionStart===0&&this.selectionEnd===0||this._moveCursorLeftOrRight("Left",t)}_move(t,e,s){let i;if(t.altKey)i=this["findWordBoundary".concat(s)](this[e]);else{if(!t.metaKey&&t.keyCode!==35&&t.keyCode!==36)return this[e]+=s==="Left"?-1:1,!0;i=this["findLineBoundary".concat(s)](this[e])}return i!==void 0&&this[e]!==i&&(this[e]=i,!0)}_moveLeft(t,e){return this._move(t,e,"Left")}_moveRight(t,e){return this._move(t,e,"Right")}moveCursorLeftWithoutShift(t){let e=!0;return this._selectionDirection=dt,this.selectionEnd===this.selectionStart&&this.selectionStart!==0&&(e=this._moveLeft(t,"selectionStart")),this.selectionEnd=this.selectionStart,e}moveCursorLeftWithShift(t){return this._selectionDirection===It&&this.selectionStart!==this.selectionEnd?this._moveLeft(t,"selectionEnd"):this.selectionStart!==0?(this._selectionDirection=dt,this._moveLeft(t,"selectionStart")):void 0}moveCursorRight(t){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorLeftOrRight("Right",t)}_moveCursorLeftOrRight(t,e){const s="moveCursor".concat(t).concat(e.shiftKey?"WithShift":"WithoutShift");this._currentCursorOpacity=1,this[s](e)&&(this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea())}moveCursorRightWithShift(t){return this._selectionDirection===dt&&this.selectionStart!==this.selectionEnd?this._moveRight(t,"selectionStart"):this.selectionEnd!==this._text.length?(this._selectionDirection=It,this._moveRight(t,"selectionEnd")):void 0}moveCursorRightWithoutShift(t){let e=!0;return this._selectionDirection=It,this.selectionStart===this.selectionEnd?(e=this._moveRight(t,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,e}}const Kf=a=>!!a.button;class Cw extends Sw{constructor(){super(...arguments),A(this,"draggableTextDelegate",void 0)}initBehavior(){this.on("mousedown",this._mouseDownHandler),this.on("mousedown:before",this._mouseDownHandlerBefore),this.on("mouseup",this.mouseUpHandler),this.on("mousedblclick",this.doubleClickHandler),this.on("tripleclick",this.tripleClickHandler),this.__lastClickTime=+new Date,this.__lastLastClickTime=+new Date,this.__lastPointer={},this.on("mousedown",this.onMouseDown),this.draggableTextDelegate=new ww(this),super.initBehavior()}shouldStartDragging(){return this.draggableTextDelegate.isActive()}onDragStart(t){return this.draggableTextDelegate.onDragStart(t)}canDrop(t){return this.draggableTextDelegate.canDrop(t)}onMouseDown(t){if(!this.canvas)return;this.__newClickTime=+new Date;const e=t.pointer;this.isTripleClick(e)&&(this.fire("tripleclick",t),_f(t.e)),this.__lastLastClickTime=this.__lastClickTime,this.__lastClickTime=this.__newClickTime,this.__lastPointer=e,this.__lastSelected=this.selected&&!this.getActiveControl()}isTripleClick(t){return this.__newClickTime-this.__lastClickTime<500&&this.__lastClickTime-this.__lastLastClickTime<500&&this.__lastPointer.x===t.x&&this.__lastPointer.y===t.y}doubleClickHandler(t){this.isEditing&&this.selectWord(this.getSelectionStartFromPointer(t.e))}tripleClickHandler(t){this.isEditing&&this.selectLine(this.getSelectionStartFromPointer(t.e))}_mouseDownHandler(t){let{e}=t;this.canvas&&this.editable&&!Kf(e)&&!this.getActiveControl()&&(this.draggableTextDelegate.start(e)||(this.canvas.textEditingManager.register(this),this.selected&&(this.inCompositionMode=!1,this.setCursorByClick(e)),this.isEditing&&(this.__selectionStartOnMouseDown=this.selectionStart,this.selectionStart===this.selectionEnd&&this.abortCursorAnimation(),this.renderCursorOrSelection())))}_mouseDownHandlerBefore(t){let{e}=t;this.canvas&&this.editable&&!Kf(e)&&(this.selected=this===this.canvas._activeObject)}mouseUpHandler(t){let{e,transform:s}=t;const i=this.draggableTextDelegate.end(e);if(this.canvas){this.canvas.textEditingManager.unregister(this);const n=this.canvas._activeObject;if(n&&n!==this)return}!this.editable||this.group&&!this.group.interactive||s&&s.actionPerformed||Kf(e)||i||(this.__lastSelected&&!this.getActiveControl()?(this.selected=!1,this.__lastSelected=!1,this.enterEditing(e),this.selectionStart===this.selectionEnd?this.initDelayedCursor(!0):this.renderCursorOrSelection()):this.selected=!0)}setCursorByClick(t){const e=this.getSelectionStartFromPointer(t),s=this.selectionStart,i=this.selectionEnd;t.shiftKey?this.setSelectionStartEndWithShift(s,i,e):(this.selectionStart=e,this.selectionEnd=e),this.isEditing&&(this._fireSelectionChanged(),this._updateTextarea())}getSelectionStartFromPointer(t){const e=this.canvas.getScenePoint(t).transform(Xe(this.calcTransformMatrix())).add(new P(-this._getLeftOffset(),-this._getTopOffset()));let s=0,i=0,n=0;for(let c=0;c<this._textLines.length&&s<=e.y;c++)s+=this.getHeightOfLine(c),n=c,c>0&&(i+=this._textLines[c-1].length+this.missingNewlineOffset(c-1));let r=Math.abs(this._getLineLeftOffset(n));const o=this._textLines[n].length,h=this.__charBounds[n];for(let c=0;c<o;c++){const u=r+h[c].kernedWidth;if(e.x<=u){Math.abs(e.x-u)<=Math.abs(e.x-r)&&i++;break}r=u,i++}return Math.min(this.flipX?o-i:i,this._text.length)}}const yu="moveCursorUp",vu="moveCursorDown",_u="moveCursorLeft",wu="moveCursorRight",xu="exitEditing",Aw=E({selectionStart:0,selectionEnd:0,selectionColor:"rgba(17,119,255,0.3)",isEditing:!1,editable:!0,editingBorderColor:"rgba(102,153,255,0.25)",cursorWidth:2,cursorColor:"",cursorDelay:1e3,cursorDuration:600,caching:!0,hiddenTextareaContainer:null,keysMap:{9:xu,27:xu,33:yu,34:vu,35:wu,36:_u,37:_u,38:yu,39:wu,40:vu},keysMapRtl:{9:xu,27:xu,33:yu,34:vu,35:_u,36:wu,37:wu,38:yu,39:_u,40:vu},ctrlKeysMapDown:{65:"selectAll"},ctrlKeysMapUp:{67:"copy",88:"cut"}},{_selectionDirection:null,_reSpace:/\s|\r?\n/,inCompositionMode:!1});class Gi extends Cw{static getDefaults(){return E(E({},super.getDefaults()),Gi.ownDefaults)}get type(){const t=super.type;return t==="itext"?"i-text":t}constructor(t,e){super(t,E(E({},Gi.ownDefaults),e)),this.initBehavior()}_set(t,e){return this.isEditing&&this._savedProps&&t in this._savedProps?(this._savedProps[t]=e,this):(t==="canvas"&&(this.canvas instanceof Wf&&this.canvas.textEditingManager.remove(this),e instanceof Wf&&e.textEditingManager.add(this)),super._set(t,e))}setSelectionStart(t){t=Math.max(t,0),this._updateAndFire("selectionStart",t)}setSelectionEnd(t){t=Math.min(t,this.text.length),this._updateAndFire("selectionEnd",t)}_updateAndFire(t,e){this[t]!==e&&(this._fireSelectionChanged(),this[t]=e),this._updateTextarea()}_fireSelectionChanged(){this.fire("selection:changed"),this.canvas&&this.canvas.fire("text:selection:changed",{target:this})}initDimensions(){this.isEditing&&this.initDelayedCursor(),super.initDimensions()}getSelectionStyles(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart||0,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.selectionEnd,s=arguments.length>2?arguments[2]:void 0;return super.getSelectionStyles(t,e,s)}setSelectionStyles(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.selectionStart||0,s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.selectionEnd;return super.setSelectionStyles(t,e,s)}get2DCursorLocation(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;return super.get2DCursorLocation(t,e)}render(t){super.render(t),this.cursorOffsetCache={},this.renderCursorOrSelection()}toCanvasElement(t){const e=this.isEditing;this.isEditing=!1;const s=super.toCanvasElement(t);return this.isEditing=e,s}renderCursorOrSelection(){if(!this.isEditing)return;const t=this.clearContextTop(!0);if(!t)return;const e=this._getCursorBoundaries();this.selectionStart!==this.selectionEnd||this.inCompositionMode?this.renderSelection(t,e):this.renderCursor(t,e),this.canvas.contextTopDirty=!0,t.restore()}_getCursorBoundaries(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;const s=this._getLeftOffset(),i=this._getTopOffset(),n=this._getCursorBoundariesOffsets(t,e);return{left:s,top:i,leftOffset:n.left,topOffset:n.top}}_getCursorBoundariesOffsets(t,e){return e?this.__getCursorBoundariesOffsets(t):this.cursorOffsetCache&&"top"in this.cursorOffsetCache?this.cursorOffsetCache:this.cursorOffsetCache=this.__getCursorBoundariesOffsets(t)}__getCursorBoundariesOffsets(t){let e=0,s=0;const{charIndex:i,lineIndex:n}=this.get2DCursorLocation(t);for(let c=0;c<n;c++)e+=this.getHeightOfLine(c);const r=this._getLineLeftOffset(n),o=this.__charBounds[n][i];o&&(s=o.left),this.charSpacing!==0&&i===this._textLines[n].length&&(s-=this._getWidthOfCharSpacing());const h={top:e,left:r+(s>0?s:0)};return this.direction==="rtl"&&(this.textAlign===It||this.textAlign===hi||this.textAlign===Nh?h.left*=-1:this.textAlign===dt||this.textAlign===bu?h.left=r-(s>0?s:0):this.textAlign!==Q&&this.textAlign!==jh||(h.left=r-(s>0?s:0))),h}renderCursorAt(t){this._renderCursor(this.canvas.contextTop,this._getCursorBoundaries(t,!0),t)}renderCursor(t,e){this._renderCursor(t,e,this.selectionStart)}getCursorRenderingData(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this._getCursorBoundaries(t);const s=this.get2DCursorLocation(t),i=s.lineIndex,n=s.charIndex>0?s.charIndex-1:0,r=this.getValueOfPropertyAt(i,n,"fontSize"),o=this.getObjectScaling().x*this.canvas.getZoom(),h=this.cursorWidth/o,c=this.getValueOfPropertyAt(i,n,"deltaY"),u=e.topOffset+(1-this._fontSizeFraction)*this.getHeightOfLine(i)/this.lineHeight-r*(1-this._fontSizeFraction);return{color:this.cursorColor||this.getValueOfPropertyAt(i,n,"fill"),opacity:this._currentCursorOpacity,left:e.left+e.leftOffset-h/2,top:u+e.top+c,width:h,height:r}}_renderCursor(t,e,s){const{color:i,opacity:n,left:r,top:o,width:h,height:c}=this.getCursorRenderingData(s,e);t.fillStyle=i,t.globalAlpha=n,t.fillRect(r,o,h,c)}renderSelection(t,e){const s={selectionStart:this.inCompositionMode?this.hiddenTextarea.selectionStart:this.selectionStart,selectionEnd:this.inCompositionMode?this.hiddenTextarea.selectionEnd:this.selectionEnd};this._renderSelection(t,s,e)}renderDragSourceEffect(){const t=this.draggableTextDelegate.getDragStartSelection();this._renderSelection(this.canvas.contextTop,t,this._getCursorBoundaries(t.selectionStart,!0))}renderDropTargetEffect(t){const e=this.getSelectionStartFromPointer(t);this.renderCursorAt(e)}_renderSelection(t,e,s){const i=e.selectionStart,n=e.selectionEnd,r=this.textAlign.includes(hi),o=this.get2DCursorLocation(i),h=this.get2DCursorLocation(n),c=o.lineIndex,u=h.lineIndex,d=o.charIndex<0?0:o.charIndex,f=h.charIndex<0?0:h.charIndex;for(let g=c;g<=u;g++){const p=this._getLineLeftOffset(g)||0;let b=this.getHeightOfLine(g),v=0,_=0,x=0;if(g===c&&(_=this.__charBounds[c][d].left),g>=c&&g<u)x=r&&!this.isEndOfWrapping(g)?this.width:this.getLineWidth(g)||5;else if(g===u)if(f===0)x=this.__charBounds[u][f].left;else{const T=this._getWidthOfCharSpacing();x=this.__charBounds[u][f-1].left+this.__charBounds[u][f-1].width-T}v=b,(this.lineHeight<1||g===u&&this.lineHeight>1)&&(b/=this.lineHeight);let C=s.left+p+_,S=b,k=0;const D=x-_;this.inCompositionMode?(t.fillStyle=this.compositionColor||"black",S=1,k=b):t.fillStyle=this.selectionColor,this.direction==="rtl"&&(this.textAlign===It||this.textAlign===hi||this.textAlign===Nh?C=this.width-C-D:this.textAlign===dt||this.textAlign===bu?C=s.left+p-x:this.textAlign!==Q&&this.textAlign!==jh||(C=s.left+p-x)),t.fillRect(C,s.top+s.topOffset+k,D,S),s.topOffset+=v}}getCurrentCharFontSize(){const t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,"fontSize")}getCurrentCharColor(){const t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,zt)}_getCurrentCharIndex(){const t=this.get2DCursorLocation(this.selectionStart,!0),e=t.charIndex>0?t.charIndex-1:0;return{l:t.lineIndex,c:e}}dispose(){this.exitEditingImpl(),this.draggableTextDelegate.dispose(),super.dispose()}}A(Gi,"ownDefaults",Aw),A(Gi,"type","IText"),N.setClass(Gi),N.setClass(Gi,"i-text");class Ar extends Gi{static getDefaults(){return E(E({},super.getDefaults()),Ar.ownDefaults)}constructor(t,e){super(t,E(E({},Ar.ownDefaults),e))}static createControls(){return{controls:l_()}}initDimensions(){this.initialized&&(this.isEditing&&this.initDelayedCursor(),this._clearCache(),this.dynamicMinWidth=0,this._styleMap=this._generateStyleMap(this._splitText()),this.dynamicMinWidth>this.width&&this._set("width",this.dynamicMinWidth),this.textAlign.includes(hi)&&this.enlargeSpaces(),this.height=this.calcTextHeight())}_generateStyleMap(t){let e=0,s=0,i=0;const n={};for(let r=0;r<t.graphemeLines.length;r++)t.graphemeText[i]===`
57
- `&&r>0?(s=0,i++,e++):!this.splitByGrapheme&&this._reSpaceAndTab.test(t.graphemeText[i])&&r>0&&(s++,i++),n[r]={line:e,offset:s},i+=t.graphemeLines[r].length,s+=t.graphemeLines[r].length;return n}styleHas(t,e){if(this._styleMap&&!this.isWrapping){const s=this._styleMap[e];s&&(e=s.line)}return super.styleHas(t,e)}isEmptyStyles(t){if(!this.styles)return!0;let e,s=0,i=t+1,n=!1;const r=this._styleMap[t],o=this._styleMap[t+1];r&&(t=r.line,s=r.offset),o&&(i=o.line,n=i===t,e=o.offset);const h=t===void 0?this.styles:{line:this.styles[t]};for(const c in h)for(const u in h[c]){const d=parseInt(u,10);if(d>=s&&(!n||d<e))for(const f in h[c][u])return!1}return!0}_getStyleDeclaration(t,e){if(this._styleMap&&!this.isWrapping){const s=this._styleMap[t];if(!s)return{};t=s.line,e=s.offset+e}return super._getStyleDeclaration(t,e)}_setStyleDeclaration(t,e,s){const i=this._styleMap[t];super._setStyleDeclaration(i.line,i.offset+e,s)}_deleteStyleDeclaration(t,e){const s=this._styleMap[t];super._deleteStyleDeclaration(s.line,s.offset+e)}_getLineStyle(t){const e=this._styleMap[t];return!!this.styles[e.line]}_setLineStyle(t){const e=this._styleMap[t];super._setLineStyle(e.line)}_wrapText(t,e){this.isWrapping=!0;const s=this.getGraphemeDataForRender(t),i=[];for(let n=0;n<s.wordsData.length;n++)i.push(...this._wrapLine(n,e,s));return this.isWrapping=!1,i}getGraphemeDataForRender(t){const e=this.splitByGrapheme,s=e?"":" ";let i=0;return{wordsData:t.map((n,r)=>{let o=0;const h=e?this.graphemeSplit(n):this.wordSplit(n);return h.length===0?[{word:[],width:0}]:h.map(c=>{const u=e?[c]:this.graphemeSplit(c),d=this._measureWord(u,r,o);return i=Math.max(d,i),o+=u.length+s.length,{word:u,width:d}})}),largestWordWidth:i}}_measureWord(t,e){let s,i=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0,n=0;for(let r=0,o=t.length;r<o;r++)n+=this._getGraphemeBox(t[r],e,r+i,s,!0).kernedWidth,s=t[r];return n}wordSplit(t){return t.split(this._wordJoiners)}_wrapLine(t,e,s){let{largestWordWidth:i,wordsData:n}=s,r=arguments.length>3&&arguments[3]!==void 0?arguments[3]:0;const o=this._getWidthOfCharSpacing(),h=this.splitByGrapheme,c=[],u=h?"":" ";let d=0,f=[],g=0,p=0,b=!0;e-=r;const v=Math.max(e,i,this.dynamicMinWidth),_=n[t];let x;for(g=0,x=0;x<_.length;x++){const{word:C,width:S}=_[x];g+=C.length,d+=p+S-o,d>v&&!b?(c.push(f),f=[],d=S,b=!0):d+=o,b||h||f.push(u),f=f.concat(C),p=h?0:this._measureWord([u],t,g),g++,b=!1}return x&&c.push(f),i+r>this.dynamicMinWidth&&(this.dynamicMinWidth=i-o+r),c}isEndOfWrapping(t){return!this._styleMap[t+1]||this._styleMap[t+1].line!==this._styleMap[t].line}missingNewlineOffset(t,e){return this.splitByGrapheme&&!e?this.isEndOfWrapping(t)?1:0:1}_splitTextIntoLines(t){const e=super._splitTextIntoLines(t),s=this._wrapText(e.lines,this.width),i=new Array(s.length);for(let n=0;n<s.length;n++)i[n]=s[n].join("");return e.lines=i,e.graphemeLines=s,e}getMinWidth(){return Math.max(this.minWidth,this.dynamicMinWidth)}_removeExtraneousStyles(){const t=new Map;for(const e in this._styleMap){const s=parseInt(e,10);if(this._textLines[s]){const i=this._styleMap[e].line;t.set("".concat(i),!0)}}for(const e in this.styles)t.has(e)||delete this.styles[e]}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject(["minWidth","splitByGrapheme",...t])}}A(Ar,"type","Textbox"),A(Ar,"textLayoutProperties",[...Gi.textLayoutProperties,"width"]),A(Ar,"ownDefaults",{minWidth:20,dynamicMinWidth:2,lockScalingFlip:!0,noScaleCache:!1,_wordJoiners:/[ \t\r]/,splitByGrapheme:!1}),N.setClass(Ar);class F0 extends uu{shouldPerformLayout(t){return!!t.target.clipPath&&super.shouldPerformLayout(t)}shouldLayoutClipPath(){return!1}calcLayoutResult(t,e){const{target:s}=t,{clipPath:i,group:n}=s;if(!i||!this.shouldPerformLayout(t))return;const{width:r,height:o}=ri(r0(s,i)),h=new P(r,o);if(i.absolutePositioned)return{center:_r(i.getRelativeCenterPoint(),void 0,n?n.calcTransformMatrix():void 0),size:h};{const c=i.getRelativeCenterPoint().transform(s.calcOwnMatrix(),!0);if(this.shouldPerformLayout(t)){const{center:u=new P,correction:d=new P}=this.calcBoundingBox(e,t)||{};return{center:u.add(c),correction:d.subtract(c),size:h}}return{center:s.getRelativeCenterPoint().add(c),size:h}}}}A(F0,"type","clip-path"),N.setClass(F0);class I0 extends uu{getInitialSize(t,e){let{target:s}=t,{size:i}=e;return new P(s.width||i.x,s.height||i.y)}}A(I0,"type","fixed"),N.setClass(I0);class Tw extends Lh{subscribeTargets(t){const e=t.target;t.targets.reduce((s,i)=>(i.parent&&s.add(i.parent),s),new Set).forEach(s=>{s.layoutManager.subscribeTargets({target:s,targets:[e]})})}unsubscribeTargets(t){const e=t.target,s=e.getObjects();t.targets.reduce((i,n)=>(n.parent&&i.add(n.parent),i),new Set).forEach(i=>{!s.some(n=>n.parent===i)&&i.layoutManager.unsubscribeTargets({target:i,targets:[e]})})}}class Tr extends ai{static getDefaults(){return E(E({},super.getDefaults()),Tr.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),Object.assign(this,Tr.ownDefaults),this.setOptions(e);const{left:s,top:i,layoutManager:n}=e;this.groupInit(t,{left:s,top:i,layoutManager:n??new Tw})}_shouldSetNestedCoords(){return!0}__objectSelectionMonitor(){}multiSelectAdd(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];this.multiSelectionStacking==="selection-order"?this.add(...e):e.forEach(i=>{const n=this._objects.findIndex(o=>o.isInFrontOf(i)),r=n===-1?this.size():n;this.insertAt(r,i)})}canEnterGroup(t){return this.getObjects().some(e=>e.isDescendantOf(t)||t.isDescendantOf(e))?(Oi("error","ActiveSelection: circular object trees are not supported, this call has no effect"),!1):super.canEnterGroup(t)}enterGroup(t,e){t.parent&&t.parent===t.group?t.parent._exitGroup(t):t.group&&t.parent!==t.group&&t.group.remove(t),this._enterGroup(t,e)}exitGroup(t,e){this._exitGroup(t,e),t.parent&&t.parent._enterGroup(t,!0)}_onAfterObjectsChange(t,e){super._onAfterObjectsChange(t,e);const s=new Set;e.forEach(i=>{const{parent:n}=i;n&&s.add(n)}),t===Hf?s.forEach(i=>{i._onAfterObjectsChange(lu,e)}):s.forEach(i=>{i._set("dirty",!0)})}onDeselect(){return this.removeAll(),!1}toString(){return"#<ActiveSelection: (".concat(this.complexity(),")>")}shouldCache(){return!1}isOnACache(){return!1}_renderControls(t,e,s){t.save(),t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1;const i=E(E({hasControls:!1},s),{},{forActiveSelection:!0});for(let n=0;n<this._objects.length;n++)this._objects[n]._renderControls(t,i);super._renderControls(t,e),t.restore()}}A(Tr,"type","ActiveSelection"),A(Tr,"ownDefaults",{multiSelectionStacking:"canvas-stacking"}),N.setClass(Tr),N.setClass(Tr,"activeSelection");class Ew{constructor(){A(this,"resources",{})}applyFilters(t,e,s,i,n){const r=n.getContext("2d");if(!r)return;r.drawImage(e,0,0,s,i);const o={sourceWidth:s,sourceHeight:i,imageData:r.getImageData(0,0,s,i),originalEl:e,originalImageData:r.getImageData(0,0,s,i),canvasEl:n,ctx:r,filterBackend:this};t.forEach(c=>{c.applyTo(o)});const{imageData:h}=o;return h.width===s&&h.height===i||(n.width=h.width,n.height=h.height),r.putImageData(h,0,0),o}}class N0{constructor(){let{tileSize:t=ht.textureSize}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};A(this,"aPosition",new Float32Array([0,0,0,1,1,0,1,1])),A(this,"resources",{}),this.tileSize=t,this.setupGLContext(t,t),this.captureGPUInfo()}setupGLContext(t,e){this.dispose(),this.createWebGLCanvas(t,e)}createWebGLCanvas(t,e){const s=Rs({width:t,height:e}),i=s.getContext("webgl",{alpha:!0,premultipliedAlpha:!1,depth:!1,stencil:!1,antialias:!1});i&&(i.clearColor(0,0,0,0),this.canvas=s,this.gl=i)}applyFilters(t,e,s,i,n,r){const o=this.gl,h=n.getContext("2d");if(!o||!h)return;let c;r&&(c=this.getCachedTexture(r,e));const u={originalWidth:e.width||e.naturalWidth||0,originalHeight:e.height||e.naturalHeight||0,sourceWidth:s,sourceHeight:i,destinationWidth:s,destinationHeight:i,context:o,sourceTexture:this.createTexture(o,s,i,c?void 0:e),targetTexture:this.createTexture(o,s,i),originalTexture:c||this.createTexture(o,s,i,c?void 0:e),passes:t.length,webgl:!0,aPosition:this.aPosition,programCache:this.programCache,pass:0,filterBackend:this,targetCanvas:n},d=o.createFramebuffer();return o.bindFramebuffer(o.FRAMEBUFFER,d),t.forEach(f=>{f&&f.applyTo(u)}),function(f){const g=f.targetCanvas,p=g.width,b=g.height,v=f.destinationWidth,_=f.destinationHeight;p===v&&b===_||(g.width=v,g.height=_)}(u),this.copyGLTo2D(o,u),o.bindTexture(o.TEXTURE_2D,null),o.deleteTexture(u.sourceTexture),o.deleteTexture(u.targetTexture),o.deleteFramebuffer(d),h.setTransform(1,0,0,1,0,0),u}dispose(){this.canvas&&(this.canvas=null,this.gl=null),this.clearWebGLCaches()}clearWebGLCaches(){this.programCache={},this.textureCache={}}createTexture(t,e,s,i,n){const{NEAREST:r,TEXTURE_2D:o,RGBA:h,UNSIGNED_BYTE:c,CLAMP_TO_EDGE:u,TEXTURE_MAG_FILTER:d,TEXTURE_MIN_FILTER:f,TEXTURE_WRAP_S:g,TEXTURE_WRAP_T:p}=t,b=t.createTexture();return t.bindTexture(o,b),t.texParameteri(o,d,n||r),t.texParameteri(o,f,n||r),t.texParameteri(o,g,u),t.texParameteri(o,p,u),i?t.texImage2D(o,0,h,h,c,i):t.texImage2D(o,0,h,e,s,0,h,c,null),b}getCachedTexture(t,e,s){const{textureCache:i}=this;if(i[t])return i[t];{const n=this.createTexture(this.gl,e.width,e.height,e,s);return n&&(i[t]=n),n}}evictCachesForKey(t){this.textureCache[t]&&(this.gl.deleteTexture(this.textureCache[t]),delete this.textureCache[t])}copyGLTo2D(t,e){const s=t.canvas,i=e.targetCanvas,n=i.getContext("2d");if(!n)return;n.translate(0,i.height),n.scale(1,-1);const r=s.height-i.height;n.drawImage(s,0,r,i.width,i.height,0,0,i.width,i.height)}copyGLTo2DPutImageData(t,e){const s=e.targetCanvas.getContext("2d"),i=e.destinationWidth,n=e.destinationHeight,r=i*n*4;if(!s)return;const o=new Uint8Array(this.imageBuffer,0,r),h=new Uint8ClampedArray(this.imageBuffer,0,r);t.readPixels(0,0,i,n,t.RGBA,t.UNSIGNED_BYTE,o);const c=new ImageData(h,i,n);s.putImageData(c,0,0)}captureGPUInfo(){if(this.gpuInfo)return this.gpuInfo;const t=this.gl,e={renderer:"",vendor:""};if(!t)return e;const s=t.getExtension("WEBGL_debug_renderer_info");if(s){const i=t.getParameter(s.UNMASKED_RENDERER_WEBGL),n=t.getParameter(s.UNMASKED_VENDOR_WEBGL);i&&(e.renderer=i.toLowerCase()),n&&(e.vendor=n.toLowerCase())}return this.gpuInfo=e,e}}let Qf;function kw(){const{WebGLProbe:a}=ni();return a.queryWebGL(ms()),ht.enableGLFiltering&&a.isSupported(ht.textureSize)?new N0({tileSize:ht.textureSize}):new Ew}function Jf(){return!Qf&&(!(arguments.length>0&&arguments[0]!==void 0)||arguments[0])&&(Qf=kw()),Qf}const Mw=["filters","resizeFilter","src","crossOrigin","type"],j0=["cropX","cropY"];class be extends pe{static getDefaults(){return E(E({},super.getDefaults()),be.ownDefaults)}constructor(t,e){super(),A(this,"_lastScaleX",1),A(this,"_lastScaleY",1),A(this,"_filterScalingX",1),A(this,"_filterScalingY",1),this.filters=[],Object.assign(this,be.ownDefaults),this.setOptions(e),this.cacheKey="texture".concat(En()),this.setElement(typeof t=="string"?(this.canvas&&Ls(this.canvas.getElement())||Vo()).getElementById(t):t,e)}getElement(){return this._element}setElement(t){var e;let s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.removeTexture(this.cacheKey),this.removeTexture("".concat(this.cacheKey,"_filtered")),this._element=t,this._originalElement=t,this._setWidthHeight(s),(e=t.classList)===null||e===void 0||e.add(be.CSS_CANVAS),this.filters.length!==0&&this.applyFilters(),this.resizeFilter&&this.applyResizeFilters()}removeTexture(t){const e=Jf(!1);e instanceof N0&&e.evictCachesForKey(t)}dispose(){super.dispose(),this.removeTexture(this.cacheKey),this.removeTexture("".concat(this.cacheKey,"_filtered")),this._cacheContext=null,["_originalElement","_element","_filteredEl","_cacheCanvas"].forEach(t=>{const e=this[t];e&&ni().dispose(e),this[t]=void 0})}getCrossOrigin(){return this._originalElement&&(this._originalElement.crossOrigin||null)}getOriginalSize(){const t=this.getElement();return t?{width:t.naturalWidth||t.width,height:t.naturalHeight||t.height}:{width:0,height:0}}_stroke(t){if(!this.stroke||this.strokeWidth===0)return;const e=this.width/2,s=this.height/2;t.beginPath(),t.moveTo(-e,-s),t.lineTo(e,-s),t.lineTo(e,s),t.lineTo(-e,s),t.lineTo(-e,-s),t.closePath()}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const e=[];return this.filters.forEach(s=>{s&&e.push(s.toObject())}),E(E({},super.toObject([...j0,...t])),{},{src:this.getSrc(),crossOrigin:this.getCrossOrigin(),filters:e},this.resizeFilter?{resizeFilter:this.resizeFilter.toObject()}:{})}hasCrop(){return!!this.cropX||!!this.cropY||this.width<this._element.width||this.height<this._element.height}_toSVG(){const t=[],e=this._element,s=-this.width/2,i=-this.height/2;let n=[],r=[],o="",h="";if(!e)return[];if(this.hasCrop()){const c=En();n.push('<clipPath id="imageCrop_'+c+`">
49
+ `]}}static async fromElement(t,e,s){const i=Ni(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:r=0,radius:o=0}=i;return new this(E(E({},Ct(i,uw)),{},{radius:o,left:n-o,top:r-o}))}static fromObject(t){return super._fromObject(t)}}T(Bi,"type","Circle"),T(Bi,"cacheProperties",[...Fi,...T0]),T(Bi,"ownDefaults",{radius:0,startAngle:0,endAngle:360,counterClockwise:!1}),T(Bi,"ATTRIBUTE_NAMES",["cx","cy","r",...Mn]),N.setClass(Bi),N.setSVGClass(Bi);const dw=["x1","y1","x2","y2"],fw=["x1","y1","x2","y2"],Yf=["x1","x2","y1","y2"];class Sr extends pe{constructor(){let[t,e,s,i]=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[0,0,0,0],n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),Object.assign(this,Sr.ownDefaults),this.setOptions(n),this.x1=t,this.x2=s,this.y1=e,this.y2=i,this._setWidthHeight();const{left:r,top:o}=n;typeof r=="number"&&this.set(dt,r),typeof o=="number"&&this.set(Ve,o)}_setWidthHeight(){const{x1:t,y1:e,x2:s,y2:i}=this;this.width=Math.abs(s-t),this.height=Math.abs(i-e);const{left:n,top:r,width:o,height:h}=ri([{x:t,y:e},{x:s,y:i}]),c=new P(n+o/2,r+h/2);this.setPositionByOrigin(c,Q,Q)}_set(t,e){return super._set(t,e),Yf.includes(t)&&this._setWidthHeight(),this}_render(t){t.beginPath();const e=this.calcLinePoints();t.moveTo(e.x1,e.y1),t.lineTo(e.x2,e.y2),t.lineWidth=this.strokeWidth;const s=t.strokeStyle;var i;bs(this.stroke)?t.strokeStyle=this.stroke.toLive(t):t.strokeStyle=(i=this.stroke)!==null&&i!==void 0?i:t.fillStyle,this.stroke&&this._renderStroke(t),t.strokeStyle=s}_findCenterFromElement(){return new P((this.x1+this.x2)/2,(this.y1+this.y2)/2)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return E(E({},super.toObject(t)),this.calcLinePoints())}_getNonTransformedDimensions(){const t=super._getNonTransformedDimensions();return this.strokeLineCap==="butt"&&(this.width===0&&(t.y-=this.strokeWidth),this.height===0&&(t.x-=this.strokeWidth)),t}calcLinePoints(){const{x1:t,x2:e,y1:s,y2:i,width:n,height:r}=this,o=t<=e?-1:1,h=s<=i?-1:1;return{x1:o*n/2,x2:o*-n/2,y1:h*r/2,y2:h*-r/2}}_toSVG(){const{x1:t,x2:e,y1:s,y2:i}=this.calcLinePoints();return["<line ","COMMON_PARTS",'x1="'.concat(t,'" y1="').concat(s,'" x2="').concat(e,'" y2="').concat(i,`" />
50
+ `)]}static async fromElement(t,e,s){const i=Ni(t,this.ATTRIBUTE_NAMES,s),{x1:n=0,y1:r=0,x2:o=0,y2:h=0}=i;return new this([n,r,o,h],Ct(i,dw))}static fromObject(t){let{x1:e,y1:s,x2:i,y2:n}=t,r=Ct(t,fw);return this._fromObject(E(E({},r),{},{points:[e,s,i,n]}),{extraParam:"points"})}}T(Sr,"type","Line"),T(Sr,"cacheProperties",[...Fi,...Yf]),T(Sr,"ATTRIBUTE_NAMES",Mn.concat(Yf)),N.setClass(Sr),N.setSVGClass(Sr);class Cr extends pe{static getDefaults(){return E(E({},super.getDefaults()),Cr.ownDefaults)}constructor(t){super(),Object.assign(this,Cr.ownDefaults),this.setOptions(t)}_render(t){const e=this.width/2,s=this.height/2;t.beginPath(),t.moveTo(-e,s),t.lineTo(0,-s),t.lineTo(e,s),t.closePath(),this._renderPaintInOrder(t)}_toSVG(){const t=this.width/2,e=this.height/2;return["<polygon ","COMMON_PARTS",'points="',"".concat(-t," ").concat(e,",0 ").concat(-e,",").concat(t," ").concat(e),'" />']}}T(Cr,"type","Triangle"),T(Cr,"ownDefaults",{width:100,height:100}),N.setClass(Cr),N.setSVGClass(Cr);const E0=["rx","ry"];class Hi extends pe{static getDefaults(){return E(E({},super.getDefaults()),Hi.ownDefaults)}constructor(t){super(),Object.assign(this,Hi.ownDefaults),this.setOptions(t)}_set(t,e){switch(super._set(t,e),t){case"rx":this.rx=e,this.set("width",2*e);break;case"ry":this.ry=e,this.set("height",2*e)}return this}getRx(){return this.get("rx")*this.get(Me)}getRy(){return this.get("ry")*this.get(Je)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject([...E0,...t])}_toSVG(){return["<ellipse ","COMMON_PARTS",'cx="0" cy="0" rx="'.concat(this.rx,'" ry="').concat(this.ry,`" />
51
+ `)]}_render(t){t.beginPath(),t.save(),t.transform(1,0,0,this.ry/this.rx,0,0),t.arc(0,0,this.rx,0,Ri,!1),t.restore(),this._renderPaintInOrder(t)}static async fromElement(t,e,s){const i=Ni(t,this.ATTRIBUTE_NAMES,s);return i.left=(i.left||0)-i.rx,i.top=(i.top||0)-i.ry,new this(i)}}function gw(a){if(!a)return[];const t=a.replace(/,/g," ").trim().split(/\s+/),e=[];for(let s=0;s<t.length;s+=2)e.push({x:parseFloat(t[s]),y:parseFloat(t[s+1])});return e}T(Hi,"type","Ellipse"),T(Hi,"cacheProperties",[...Fi,...E0]),T(Hi,"ownDefaults",{rx:0,ry:0}),T(Hi,"ATTRIBUTE_NAMES",[...Mn,"cx","cy","rx","ry"]),N.setClass(Hi),N.setSVGClass(Hi);const pw=["left","top"],k0={exactBoundingBox:!1};class Bs extends pe{static getDefaults(){return E(E({},super.getDefaults()),Bs.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),T(this,"strokeDiff",void 0),Object.assign(this,Bs.ownDefaults),this.setOptions(e),this.points=t;const{left:s,top:i}=e;this.initialized=!0,this.setBoundingBox(!0),typeof s=="number"&&this.set(dt,s),typeof i=="number"&&this.set(Ve,i)}isOpen(){return!0}_projectStrokeOnPoints(t){return Um(this.points,t,this.isOpen())}_calcDimensions(t){t=E({scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,strokeLineCap:this.strokeLineCap,strokeLineJoin:this.strokeLineJoin,strokeMiterLimit:this.strokeMiterLimit,strokeUniform:this.strokeUniform,strokeWidth:this.strokeWidth},t||{});const e=this.exactBoundingBox?this._projectStrokeOnPoints(t).map(c=>c.projectedPoint):this.points;if(e.length===0)return{left:0,top:0,width:0,height:0,pathOffset:new P,strokeOffset:new P,strokeDiff:new P};const s=ri(e),i=Ah(E(E({},t),{},{scaleX:1,scaleY:1})),n=ri(this.points.map(c=>ge(c,i,!0))),r=new P(this.scaleX,this.scaleY);let o=s.left+s.width/2,h=s.top+s.height/2;return this.exactBoundingBox&&(o-=h*Math.tan(Rt(this.skewX)),h-=o*Math.tan(Rt(this.skewY))),E(E({},s),{},{pathOffset:new P(o,h),strokeOffset:new P(n.left,n.top).subtract(new P(s.left,s.top)).multiply(r),strokeDiff:new P(s.width,s.height).subtract(new P(n.width,n.height)).multiply(r)})}_findCenterFromElement(){const t=ri(this.points);return new P(t.left+t.width/2,t.top+t.height/2)}setDimensions(){this.setBoundingBox()}setBoundingBox(t){const{left:e,top:s,width:i,height:n,pathOffset:r,strokeOffset:o,strokeDiff:h}=this._calcDimensions();this.set({width:i,height:n,pathOffset:r,strokeOffset:o,strokeDiff:h}),t&&this.setPositionByOrigin(new P(e+i/2,s+n/2),Q,Q)}isStrokeAccountedForInDimensions(){return this.exactBoundingBox}_getNonTransformedDimensions(){return this.exactBoundingBox?new P(this.width,this.height):super._getNonTransformedDimensions()}_getTransformedDimensions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(this.exactBoundingBox){let r;if(Object.keys(t).some(o=>this.strokeUniform||this.constructor.layoutProperties.includes(o))){var e,s;const{width:o,height:h}=this._calcDimensions(t);r=new P((e=t.width)!==null&&e!==void 0?e:o,(s=t.height)!==null&&s!==void 0?s:h)}else{var i,n;r=new P((i=t.width)!==null&&i!==void 0?i:this.width,(n=t.height)!==null&&n!==void 0?n:this.height)}return r.multiply(new P(t.scaleX||this.scaleX,t.scaleY||this.scaleY))}return super._getTransformedDimensions(t)}_set(t,e){const s=this.initialized&&this[t]!==e,i=super._set(t,e);return this.exactBoundingBox&&s&&((t===Me||t===Je)&&this.strokeUniform&&this.constructor.layoutProperties.includes("strokeUniform")||this.constructor.layoutProperties.includes(t))&&this.setDimensions(),i}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return E(E({},super.toObject(t)),{},{points:this.points.map(e=>{let{x:s,y:i}=e;return{x:s,y:i}})})}_toSVG(){const t=[],e=this.pathOffset.x,s=this.pathOffset.y,i=ht.NUM_FRACTION_DIGITS;for(let n=0,r=this.points.length;n<r;n++)t.push(At(this.points[n].x-e,i),",",At(this.points[n].y-s,i)," ");return["<".concat(this.constructor.type.toLowerCase()," "),"COMMON_PARTS",'points="'.concat(t.join(""),`" />
52
+ `)]}_render(t){const e=this.points.length,s=this.pathOffset.x,i=this.pathOffset.y;if(e&&!isNaN(this.points[e-1].y)){t.beginPath(),t.moveTo(this.points[0].x-s,this.points[0].y-i);for(let n=0;n<e;n++){const r=this.points[n];t.lineTo(r.x-s,r.y-i)}!this.isOpen()&&t.closePath(),this._renderPaintInOrder(t)}}complexity(){return this.points.length}static async fromElement(t,e,s){return new this(gw(t.getAttribute("points")),E(E({},Ct(Ni(t,this.ATTRIBUTE_NAMES,s),pw)),e))}static fromObject(t){return this._fromObject(t,{extraParam:"points"})}}T(Bs,"ownDefaults",k0),T(Bs,"type","Polyline"),T(Bs,"layoutProperties",[Xo,Wo,"strokeLineCap","strokeLineJoin","strokeMiterLimit","strokeWidth","strokeUniform","points"]),T(Bs,"cacheProperties",[...Fi,"points"]),T(Bs,"ATTRIBUTE_NAMES",[...Mn]),N.setClass(Bs),N.setSVGClass(Bs);class mu extends Bs{isOpen(){return!1}}T(mu,"ownDefaults",k0),T(mu,"type","Polygon"),N.setClass(mu),N.setSVGClass(mu);const M0=["fontSize","fontWeight","fontFamily","fontStyle"],P0=["underline","overline","linethrough"],D0=[...M0,"lineHeight","text","charSpacing","textAlign","styles","path","pathStartOffset","pathSide","pathAlign"],O0=[...D0,...P0,"textBackgroundColor","direction"],mw=[...M0,...P0,Pe,"strokeWidth",zt,"deltaY","textBackgroundColor"],bw={_reNewline:hf,_reSpacesAndTabs:/[ \t\r]/g,_reSpaceAndTab:/[ \t\r]/,_reWords:/\S+/g,fontSize:40,fontWeight:"normal",fontFamily:"Times New Roman",underline:!1,overline:!1,linethrough:!1,textAlign:dt,fontStyle:"normal",lineHeight:1.16,superscript:{size:.6,baseline:-.35},subscript:{size:.6,baseline:.11},textBackgroundColor:"",stroke:null,shadow:null,path:void 0,pathStartOffset:0,pathSide:dt,pathAlign:"baseline",_fontSizeFraction:.222,offsets:{underline:.1,linethrough:-.315,overline:-.88},_fontSizeMult:1.13,charSpacing:0,deltaY:0,direction:"ltr",CACHE_FONT_SIZE:400,MIN_TEXT_WIDTH:2},hi="justify",bu="justify-left",Nh="justify-right",jh="justify-center";class R0 extends pe{isEmptyStyles(t){if(!this.styles||t!==void 0&&!this.styles[t])return!0;const e=t===void 0?this.styles:{line:this.styles[t]};for(const s in e)for(const i in e[s])for(const n in e[s][i])return!1;return!0}styleHas(t,e){if(!this.styles||e!==void 0&&!this.styles[e])return!1;const s=e===void 0?this.styles:{0:this.styles[e]};for(const i in s)for(const n in s[i])if(s[i][n][t]!==void 0)return!0;return!1}cleanStyle(t){if(!this.styles)return!1;const e=this.styles;let s,i,n=0,r=!0,o=0;for(const h in e){s=0;for(const c in e[h]){const u=e[h][c]||{};n++,u[t]!==void 0?(i?u[t]!==i&&(r=!1):i=u[t],u[t]===this[t]&&delete u[t]):r=!1,Object.keys(u).length!==0?s++:delete e[h][c]}s===0&&delete e[h]}for(let h=0;h<this._textLines.length;h++)o+=this._textLines[h].length;r&&n===o&&(this[t]=i,this.removeStyle(t))}removeStyle(t){if(!this.styles)return;const e=this.styles;let s,i,n;for(i in e){for(n in s=e[i],s)delete s[n][t],Object.keys(s[n]).length===0&&delete s[n];Object.keys(s).length===0&&delete e[i]}}_extendStyles(t,e){const{lineIndex:s,charIndex:i}=this.get2DCursorLocation(t);this._getLineStyle(s)||this._setLineStyle(s);const n=mf(E(E({},this._getStyleDeclaration(s,i)),e),r=>r!==void 0);this._setStyleDeclaration(s,i,n)}getSelectionStyles(t,e,s){const i=[];for(let n=t;n<(e||t);n++)i.push(this.getStyleAtPosition(n,s));return i}getStyleAtPosition(t,e){const{lineIndex:s,charIndex:i}=this.get2DCursorLocation(t);return e?this.getCompleteStyleDeclaration(s,i):this._getStyleDeclaration(s,i)}setSelectionStyles(t,e,s){for(let i=e;i<(s||e);i++)this._extendStyles(i,t);this._forceClearCache=!0}_getStyleDeclaration(t,e){var s;const i=this.styles&&this.styles[t];return i&&(s=i[e])!==null&&s!==void 0?s:{}}getCompleteStyleDeclaration(t,e){return E(E({},yr(this,this.constructor._styleProperties)),this._getStyleDeclaration(t,e))}_setStyleDeclaration(t,e,s){this.styles[t][e]=s}_deleteStyleDeclaration(t,e){delete this.styles[t][e]}_getLineStyle(t){return!!this.styles[t]}_setLineStyle(t){this.styles[t]={}}_deleteLineStyle(t){delete this.styles[t]}}T(R0,"_styleProperties",mw);const yw=/ +/g,vw=/"/g;function $f(a,t,e,s,i){return" ".concat(function(n,r){let{left:o,top:h,width:c,height:u}=r,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:ht.NUM_FRACTION_DIGITS;const f=Mh(zt,n,!1),[g,p,b,v]=[o,h,c,u].map(_=>At(_,d));return"<rect ".concat(f,' x="').concat(g,'" y="').concat(p,'" width="').concat(b,'" height="').concat(v,'"></rect>')}(a,{left:t,top:e,width:s,height:i}),`
53
+ `)}const _w=["textAnchor","textDecoration","dx","dy","top","left","fontSize","strokeWidth"];let qf;class me extends R0{static getDefaults(){return E(E({},super.getDefaults()),me.ownDefaults)}constructor(t,e){super(),T(this,"__charBounds",[]),Object.assign(this,me.ownDefaults),this.setOptions(e),this.styles||(this.styles={}),this.text=t,this.initialized=!0,this.path&&this.setPathInfo(),this.initDimensions(),this.setCoords()}setPathInfo(){const t=this.path;t&&(t.segmentsInfo=Xf(t.path))}_splitText(){const t=this._splitTextIntoLines(this.text);return this.textLines=t.lines,this._textLines=t.graphemeLines,this._unwrappedTextLines=t._unwrappedLines,this._text=t.graphemeText,t}initDimensions(){this._splitText(),this._clearCache(),this.dirty=!0,this.path?(this.width=this.path.width,this.height=this.path.height):(this.width=this.calcTextWidth()||this.cursorWidth||this.MIN_TEXT_WIDTH,this.height=this.calcTextHeight()),this.textAlign.includes(hi)&&this.enlargeSpaces()}enlargeSpaces(){let t,e,s,i,n,r,o;for(let h=0,c=this._textLines.length;h<c;h++)if((this.textAlign===hi||h!==c-1&&!this.isEndOfWrapping(h))&&(i=0,n=this._textLines[h],e=this.getLineWidth(h),e<this.width&&(o=this.textLines[h].match(this._reSpacesAndTabs)))){s=o.length,t=(this.width-e)/s;for(let u=0;u<=n.length;u++)r=this.__charBounds[h][u],this._reSpaceAndTab.test(n[u])?(r.width+=t,r.kernedWidth+=t,r.left+=i,i+=t):r.left+=i}}isEndOfWrapping(t){return t===this._textLines.length-1}missingNewlineOffset(t){return 1}get2DCursorLocation(t,e){const s=e?this._unwrappedTextLines:this._textLines;let i;for(i=0;i<s.length;i++){if(t<=s[i].length)return{lineIndex:i,charIndex:t};t-=s[i].length+this.missingNewlineOffset(i,e)}return{lineIndex:i-1,charIndex:s[i-1].length<t?s[i-1].length:t}}toString(){return"#<Text (".concat(this.complexity(),'): { "text": "').concat(this.text,'", "fontFamily": "').concat(this.fontFamily,'" }>')}_getCacheCanvasDimensions(){const t=super._getCacheCanvasDimensions(),e=this.fontSize;return t.width+=e*t.zoomX,t.height+=e*t.zoomY,t}_render(t){const e=this.path;e&&!e.isNotVisible()&&e._render(t),this._setTextStyles(t),this._renderTextLinesBackground(t),this._renderTextDecoration(t,"underline"),this._renderText(t),this._renderTextDecoration(t,"overline"),this._renderTextDecoration(t,"linethrough")}_renderText(t){this.paintFirst===Pe?(this._renderTextStroke(t),this._renderTextFill(t)):(this._renderTextFill(t),this._renderTextStroke(t))}_setTextStyles(t,e,s){if(t.textBaseline="alphabetic",this.path)switch(this.pathAlign){case Q:t.textBaseline="middle";break;case"ascender":t.textBaseline=Ve;break;case"descender":t.textBaseline=af}t.font=this._getFontDeclaration(e,s)}calcTextWidth(){let t=this.getLineWidth(0);for(let e=1,s=this._textLines.length;e<s;e++){const i=this.getLineWidth(e);i>t&&(t=i)}return t}_renderTextLine(t,e,s,i,n,r){this._renderChars(t,e,s,i,n,r)}_renderTextLinesBackground(t){if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor"))return;const e=t.fillStyle,s=this._getLeftOffset();let i=this._getTopOffset();for(let n=0,r=this._textLines.length;n<r;n++){const o=this.getHeightOfLine(n);if(!this.textBackgroundColor&&!this.styleHas("textBackgroundColor",n)){i+=o;continue}const h=this._textLines[n].length,c=this._getLineLeftOffset(n);let u,d,f=0,g=0,p=this.getValueOfPropertyAt(n,0,"textBackgroundColor");for(let b=0;b<h;b++){const v=this.__charBounds[n][b];d=this.getValueOfPropertyAt(n,b,"textBackgroundColor"),this.path?(t.save(),t.translate(v.renderLeft,v.renderTop),t.rotate(v.angle),t.fillStyle=d,d&&t.fillRect(-v.width/2,-o/this.lineHeight*(1-this._fontSizeFraction),v.width,o/this.lineHeight),t.restore()):d!==p?(u=s+c+g,this.direction==="rtl"&&(u=this.width-u-f),t.fillStyle=p,p&&t.fillRect(u,i,f,o/this.lineHeight),g=v.left,f=v.width,p=d):f+=v.kernedWidth}d&&!this.path&&(u=s+c+g,this.direction==="rtl"&&(u=this.width-u-f),t.fillStyle=d,t.fillRect(u,i,f,o/this.lineHeight)),i+=o}t.fillStyle=e,this._removeShadow(t)}_measureChar(t,e,s,i){const n=xh.getFontCache(e),r=this._getFontDeclaration(e),o=s+t,h=s&&r===this._getFontDeclaration(i),c=e.fontSize/this.CACHE_FONT_SIZE;let u,d,f,g;if(s&&n[s]!==void 0&&(f=n[s]),n[t]!==void 0&&(g=u=n[t]),h&&n[o]!==void 0&&(d=n[o],g=d-f),u===void 0||f===void 0||d===void 0){const p=function(){return qf||(qf=Rs({width:0,height:0}).getContext("2d")),qf}();this._setTextStyles(p,e,!0),u===void 0&&(g=u=p.measureText(t).width,n[t]=u),f===void 0&&h&&s&&(f=p.measureText(s).width,n[s]=f),h&&d===void 0&&(d=p.measureText(o).width,n[o]=d,g=d-f)}return{width:u*c,kernedWidth:g*c}}getHeightOfChar(t,e){return this.getValueOfPropertyAt(t,e,"fontSize")}measureLine(t){const e=this._measureLine(t);return this.charSpacing!==0&&(e.width-=this._getWidthOfCharSpacing()),e.width<0&&(e.width=0),e}_measureLine(t){let e,s,i=0;const n=this.pathSide===It,r=this.path,o=this._textLines[t],h=o.length,c=new Array(h);this.__charBounds[t]=c;for(let u=0;u<h;u++){const d=o[u];s=this._getGraphemeBox(d,t,u,e),c[u]=s,i+=s.kernedWidth,e=d}if(c[h]={left:s?s.left+s.width:0,width:0,kernedWidth:0,height:this.fontSize,deltaY:0},r&&r.segmentsInfo){let u=0;const d=r.segmentsInfo[r.segmentsInfo.length-1].length;switch(this.textAlign){case dt:u=n?d-i:0;break;case Q:u=(d-i)/2;break;case It:u=n?0:d-i}u+=this.pathStartOffset*(n?-1:1);for(let f=n?h-1:0;n?f>=0:f<h;n?f--:f++)s=c[f],u>d?u%=d:u<0&&(u+=d),this._setGraphemeOnPath(u,s),u+=s.kernedWidth}return{width:i,numOfSpaces:0}}_setGraphemeOnPath(t,e){const s=t+e.kernedWidth/2,i=this.path,n=m0(i.path,s,i.segmentsInfo);e.renderLeft=n.x-i.pathOffset.x,e.renderTop=n.y-i.pathOffset.y,e.angle=n.angle+(this.pathSide===It?Math.PI:0)}_getGraphemeBox(t,e,s,i,n){const r=this.getCompleteStyleDeclaration(e,s),o=i?this.getCompleteStyleDeclaration(e,s-1):{},h=this._measureChar(t,r,i,o);let c,u=h.kernedWidth,d=h.width;this.charSpacing!==0&&(c=this._getWidthOfCharSpacing(),d+=c,u+=c);const f={width:d,left:0,height:r.fontSize,kernedWidth:u,deltaY:r.deltaY};if(s>0&&!n){const g=this.__charBounds[e][s-1];f.left=g.left+g.width+h.kernedWidth-h.width}return f}getHeightOfLine(t){if(this.__lineHeights[t])return this.__lineHeights[t];let e=this.getHeightOfChar(t,0);for(let s=1,i=this._textLines[t].length;s<i;s++)e=Math.max(this.getHeightOfChar(t,s),e);return this.__lineHeights[t]=e*this.lineHeight*this._fontSizeMult}calcTextHeight(){let t,e=0;for(let s=0,i=this._textLines.length;s<i;s++)t=this.getHeightOfLine(s),e+=s===i-1?t/this.lineHeight:t;return e}_getLeftOffset(){return this.direction==="ltr"?-this.width/2:this.width/2}_getTopOffset(){return-this.height/2}_renderTextCommon(t,e){t.save();let s=0;const i=this._getLeftOffset(),n=this._getTopOffset();for(let r=0,o=this._textLines.length;r<o;r++){const h=this.getHeightOfLine(r),c=h/this.lineHeight,u=this._getLineLeftOffset(r);this._renderTextLine(e,t,this._textLines[r],i+u,n+s+c,r),s+=h}t.restore()}_renderTextFill(t){(this.fill||this.styleHas(zt))&&this._renderTextCommon(t,"fillText")}_renderTextStroke(t){(this.stroke&&this.strokeWidth!==0||!this.isEmptyStyles())&&(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this._setLineDash(t,this.strokeDashArray),t.beginPath(),this._renderTextCommon(t,"strokeText"),t.closePath(),t.restore())}_renderChars(t,e,s,i,n,r){const o=this.getHeightOfLine(r),h=this.textAlign.includes(hi),c=this.path,u=!h&&this.charSpacing===0&&this.isEmptyStyles(r)&&!c,d=this.direction==="ltr",f=this.direction==="ltr"?1:-1,g=e.direction;let p,b,v,_,x,C="",S=0;if(e.save(),g!==this.direction&&(e.canvas.setAttribute("dir",d?"ltr":"rtl"),e.direction=d?"ltr":"rtl",e.textAlign=d?dt:It),n-=o*this._fontSizeFraction/this.lineHeight,u)return this._renderChar(t,e,r,0,s.join(""),i,n),void e.restore();for(let k=0,D=s.length-1;k<=D;k++)_=k===D||this.charSpacing||c,C+=s[k],v=this.__charBounds[r][k],S===0?(i+=f*(v.kernedWidth-v.width),S+=v.width):S+=v.kernedWidth,h&&!_&&this._reSpaceAndTab.test(s[k])&&(_=!0),_||(p=p||this.getCompleteStyleDeclaration(r,k),b=this.getCompleteStyleDeclaration(r,k+1),_=au(p,b,!1)),_&&(c?(e.save(),e.translate(v.renderLeft,v.renderTop),e.rotate(v.angle),this._renderChar(t,e,r,k,C,-S/2,0),e.restore()):(x=i,this._renderChar(t,e,r,k,C,x,n)),C="",p=b,i+=f*S,S=0);e.restore()}_applyPatternGradientTransformText(t){const e=this.width+this.strokeWidth,s=this.height+this.strokeWidth,i=Rs({width:e,height:s}),n=i.getContext("2d");return i.width=e,i.height=s,n.beginPath(),n.moveTo(0,0),n.lineTo(e,0),n.lineTo(e,s),n.lineTo(0,s),n.closePath(),n.translate(e/2,s/2),n.fillStyle=t.toLive(n),this._applyPatternGradientTransform(n,t),n.fill(),n.createPattern(i,"no-repeat")}handleFiller(t,e,s){let i,n;return bs(s)?s.gradientUnits==="percentage"||s.gradientTransform||s.patternTransform?(i=-this.width/2,n=-this.height/2,t.translate(i,n),t[e]=this._applyPatternGradientTransformText(s),{offsetX:i,offsetY:n}):(t[e]=s.toLive(t),this._applyPatternGradientTransform(t,s)):(t[e]=s,{offsetX:0,offsetY:0})}_setStrokeStyles(t,e){let{stroke:s,strokeWidth:i}=e;return t.lineWidth=i,t.lineCap=this.strokeLineCap,t.lineDashOffset=this.strokeDashOffset,t.lineJoin=this.strokeLineJoin,t.miterLimit=this.strokeMiterLimit,this.handleFiller(t,"strokeStyle",s)}_setFillStyles(t,e){let{fill:s}=e;return this.handleFiller(t,"fillStyle",s)}_renderChar(t,e,s,i,n,r,o){const h=this._getStyleDeclaration(s,i),c=this.getCompleteStyleDeclaration(s,i),u=t==="fillText"&&c.fill,d=t==="strokeText"&&c.stroke&&c.strokeWidth;if(d||u){if(e.save(),e.font=this._getFontDeclaration(c),h.textBackgroundColor&&this._removeShadow(e),h.deltaY&&(o+=h.deltaY),u){const f=this._setFillStyles(e,c);e.fillText(n,r-f.offsetX,o-f.offsetY)}if(d){const f=this._setStrokeStyles(e,c);e.strokeText(n,r-f.offsetX,o-f.offsetY)}e.restore()}}setSuperscript(t,e){this._setScript(t,e,this.superscript)}setSubscript(t,e){this._setScript(t,e,this.subscript)}_setScript(t,e,s){const i=this.get2DCursorLocation(t,!0),n=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"fontSize"),r=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"deltaY"),o={fontSize:n*s.size,deltaY:r+n*s.baseline};this.setSelectionStyles(o,t,e)}_getLineLeftOffset(t){const e=this.getLineWidth(t),s=this.width-e,i=this.textAlign,n=this.direction,r=this.isEndOfWrapping(t);let o=0;return i===hi||i===jh&&!r||i===Nh&&!r||i===bu&&!r?0:(i===Q&&(o=s/2),i===It&&(o=s),i===jh&&(o=s/2),i===Nh&&(o=s),n==="rtl"&&(i===It||i===hi||i===Nh?o=0:i===dt||i===bu?o=-s:i!==Q&&i!==jh||(o=-s/2)),o)}_clearCache(){this._forceClearCache=!1,this.__lineWidths=[],this.__lineHeights=[],this.__charBounds=[]}getLineWidth(t){if(this.__lineWidths[t]!==void 0)return this.__lineWidths[t];const{width:e}=this.measureLine(t);return this.__lineWidths[t]=e,e}_getWidthOfCharSpacing(){return this.charSpacing!==0?this.fontSize*this.charSpacing/1e3:0}getValueOfPropertyAt(t,e,s){var i;return(i=this._getStyleDeclaration(t,e)[s])!==null&&i!==void 0?i:this[s]}_renderTextDecoration(t,e){if(!this[e]&&!this.styleHas(e))return;let s=this._getTopOffset();const i=this._getLeftOffset(),n=this.path,r=this._getWidthOfCharSpacing(),o=this.offsets[e];for(let h=0,c=this._textLines.length;h<c;h++){const u=this.getHeightOfLine(h);if(!this[e]&&!this.styleHas(e,h)){s+=u;continue}const d=this._textLines[h],f=u/this.lineHeight,g=this._getLineLeftOffset(h);let p,b,v=0,_=0,x=this.getValueOfPropertyAt(h,0,e),C=this.getValueOfPropertyAt(h,0,zt);const S=s+f*(1-this._fontSizeFraction);let k=this.getHeightOfChar(h,0),D=this.getValueOfPropertyAt(h,0,"deltaY");for(let M=0,O=d.length;M<O;M++){const R=this.__charBounds[h][M];p=this.getValueOfPropertyAt(h,M,e),b=this.getValueOfPropertyAt(h,M,zt);const L=this.getHeightOfChar(h,M),V=this.getValueOfPropertyAt(h,M,"deltaY");if(n&&p&&b)t.save(),t.fillStyle=C,t.translate(R.renderLeft,R.renderTop),t.rotate(R.angle),t.fillRect(-R.kernedWidth/2,o*L+V,R.kernedWidth,this.fontSize/15),t.restore();else if((p!==x||b!==C||L!==k||V!==D)&&_>0){let U=i+g+v;this.direction==="rtl"&&(U=this.width-U-_),x&&C&&(t.fillStyle=C,t.fillRect(U,S+o*k+D,_,this.fontSize/15)),v=R.left,_=R.width,x=p,C=b,k=L,D=V}else _+=R.kernedWidth}let A=i+g+v;this.direction==="rtl"&&(A=this.width-A-_),t.fillStyle=b,p&&b&&t.fillRect(A,S+o*k+D,_-r,this.fontSize/15),s+=u}this._removeShadow(t)}_getFontDeclaration(){let{fontFamily:t=this.fontFamily,fontStyle:e=this.fontStyle,fontWeight:s=this.fontWeight,fontSize:i=this.fontSize}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;const r=t.includes("'")||t.includes('"')||t.includes(",")||me.genericFonts.includes(t.toLowerCase())?t:'"'.concat(t,'"');return[e,s,"".concat(n?this.CACHE_FONT_SIZE:i,"px"),r].join(" ")}render(t){this.visible&&(this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(this._forceClearCache&&this.initDimensions(),super.render(t)))}graphemeSplit(t){return ou(t)}_splitTextIntoLines(t){const e=t.split(this._reNewline),s=new Array(e.length),i=[`
54
+ `];let n=[];for(let r=0;r<e.length;r++)s[r]=this.graphemeSplit(e[r]),n=n.concat(s[r],i);return n.pop(),{_unwrappedLines:s,lines:e,graphemeText:n,graphemeLines:s}}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return E(E({},super.toObject([...O0,...t])),{},{styles:$m(this.styles,this.text)},this.path?{path:this.path.toObject()}:{})}set(t,e){const{textLayoutProperties:s}=this.constructor;super.set(t,e);let i=!1,n=!1;if(typeof t=="object")for(const r in t)r==="path"&&this.setPathInfo(),i=i||s.includes(r),n=n||r==="path";else i=s.includes(t),n=t==="path";return n&&this.setPathInfo(),i&&this.initialized&&(this.initDimensions(),this.setCoords()),this}complexity(){return 1}static async fromElement(t,e,s){const i=Ni(t,me.ATTRIBUTE_NAMES,s),n=E(E({},e),i),{textAnchor:r=dt,textDecoration:o="",dx:h=0,dy:c=0,top:u=0,left:d=0,fontSize:f=of,strokeWidth:g=1}=n,p=Ct(n,_w),b=new this((t.textContent||"").replace(/^\s+|\s+$|\n+/g,"").replace(/\s+/g," "),E({left:d+h,top:u+c,underline:o.includes("underline"),overline:o.includes("overline"),linethrough:o.includes("line-through"),strokeWidth:0,fontSize:f},p)),v=b.getScaledHeight()/b.height,_=((b.height+b.strokeWidth)*b.lineHeight-b.height)*v,x=b.getScaledHeight()+_;let C=0;return r===Q&&(C=b.getScaledWidth()/2),r===It&&(C=b.getScaledWidth()),b.set({left:b.left-C,top:b.top-(x-b.fontSize*(.07+b._fontSizeFraction))/b.lineHeight,strokeWidth:g}),b}static fromObject(t){return this._fromObject(E(E({},t),{},{styles:qm(t.styles||{},t.text)}),{extraParam:"text"})}}T(me,"textLayoutProperties",D0),T(me,"cacheProperties",[...Fi,...O0]),T(me,"ownDefaults",bw),T(me,"type","Text"),T(me,"genericFonts",["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","math","emoji","fangsong"]),T(me,"ATTRIBUTE_NAMES",Mn.concat("x","y","dx","dy","font-family","font-style","font-weight","font-size","letter-spacing","text-decoration","text-anchor")),zm(me,[class extends xm{_toSVG(){const a=this._getSVGLeftTopOffsets(),t=this._getSVGTextAndBg(a.textTop,a.textLeft);return this._wrapSVGTextAndBg(t)}toSVG(a){return this._createBaseSVGMarkup(this._toSVG(),{reviver:a,noStyle:!0,withShadow:!0})}_getSVGLeftTopOffsets(){return{textLeft:-this.width/2,textTop:-this.height/2,lineTop:this.getHeightOfLine(0)}}_wrapSVGTextAndBg(a){let{textBgRects:t,textSpans:e}=a;const s=this.getSvgTextDecoration(this);return[t.join(""),' <text xml:space="preserve" ',this.fontFamily?'font-family="'.concat(this.fontFamily.replace(vw,"'"),'" '):"",this.fontSize?'font-size="'.concat(this.fontSize,'" '):"",this.fontStyle?'font-style="'.concat(this.fontStyle,'" '):"",this.fontWeight?'font-weight="'.concat(this.fontWeight,'" '):"",s?'text-decoration="'.concat(s,'" '):"",this.direction==="rtl"?'direction="'.concat(this.direction,'" '):"",'style="',this.getSvgStyles(!0),'"',this.addPaintOrder()," >",e.join(""),`</text>
55
+ `]}_getSVGTextAndBg(a,t){const e=[],s=[];let i,n=a;this.backgroundColor&&s.push(...$f(this.backgroundColor,-this.width/2,-this.height/2,this.width,this.height));for(let r=0,o=this._textLines.length;r<o;r++)i=this._getLineLeftOffset(r),this.direction==="rtl"&&(i+=this.width),(this.textBackgroundColor||this.styleHas("textBackgroundColor",r))&&this._setSVGTextLineBg(s,r,t+i,n),this._setSVGTextLineText(e,r,t+i,n),n+=this.getHeightOfLine(r);return{textSpans:e,textBgRects:s}}_createTextCharSpan(a,t,e,s){const i=this.getSvgSpanStyles(t,a!==a.trim()||!!a.match(yw)),n=i?'style="'.concat(i,'"'):"",r=t.deltaY,o=r?' dy="'.concat(At(r,ht.NUM_FRACTION_DIGITS),'" '):"";return'<tspan x="'.concat(At(e,ht.NUM_FRACTION_DIGITS),'" y="').concat(At(s,ht.NUM_FRACTION_DIGITS),'" ').concat(o).concat(n,">").concat(Ym(a),"</tspan>")}_setSVGTextLineText(a,t,e,s){const i=this.getHeightOfLine(t),n=this.textAlign.includes(hi),r=this._textLines[t];let o,h,c,u,d,f="",g=0;s+=i*(1-this._fontSizeFraction)/this.lineHeight;for(let p=0,b=r.length-1;p<=b;p++)d=p===b||this.charSpacing,f+=r[p],c=this.__charBounds[t][p],g===0?(e+=c.kernedWidth-c.width,g+=c.width):g+=c.kernedWidth,n&&!d&&this._reSpaceAndTab.test(r[p])&&(d=!0),d||(o=o||this.getCompleteStyleDeclaration(t,p),h=this.getCompleteStyleDeclaration(t,p+1),d=au(o,h,!0)),d&&(u=this._getStyleDeclaration(t,p),a.push(this._createTextCharSpan(f,u,e,s)),f="",o=h,this.direction==="rtl"?e-=g:e+=g,g=0)}_setSVGTextLineBg(a,t,e,s){const i=this._textLines[t],n=this.getHeightOfLine(t)/this.lineHeight;let r,o=0,h=0,c=this.getValueOfPropertyAt(t,0,"textBackgroundColor");for(let u=0;u<i.length;u++){const{left:d,width:f,kernedWidth:g}=this.__charBounds[t][u];r=this.getValueOfPropertyAt(t,u,"textBackgroundColor"),r!==c?(c&&a.push(...$f(c,e+h,s,o,n)),h=d,o=f,c=r):o+=g}r&&a.push(...$f(c,e+h,s,o,n))}_getSVGLineTopOffset(a){let t,e=0;for(t=0;t<a;t++)e+=this.getHeightOfLine(t);const s=this.getHeightOfLine(t);return{lineTop:e,offset:(this._fontSizeMult-this._fontSizeFraction)*s/(this.lineHeight*this._fontSizeMult)}}getSvgStyles(a){return"".concat(super.getSvgStyles(a)," white-space: pre;")}getSvgSpanStyles(a,t){const{fontFamily:e,strokeWidth:s,stroke:i,fill:n,fontSize:r,fontStyle:o,fontWeight:h,deltaY:c}=a,u=this.getSvgTextDecoration(a);return[i?Mh(Pe,i):"",s?"stroke-width: ".concat(s,"; "):"",e?"font-family: ".concat(e.includes("'")||e.includes('"')?e:"'".concat(e,"'"),"; "):"",r?"font-size: ".concat(r,"px; "):"",o?"font-style: ".concat(o,"; "):"",h?"font-weight: ".concat(h,"; "):"",u&&"text-decoration: ".concat(u,"; "),n?Mh(zt,n):"",c?"baseline-shift: ".concat(-c,"; "):"",t?"white-space: pre; ":""].join("")}getSvgTextDecoration(a){return["overline","underline","line-through"].filter(t=>a[t.replace("-","")]).join(" ")}}]),N.setClass(me),N.setSVGClass(me);class ww{constructor(t){T(this,"target",void 0),T(this,"__mouseDownInPlace",!1),T(this,"__dragStartFired",!1),T(this,"__isDraggingOver",!1),T(this,"__dragStartSelection",void 0),T(this,"__dragImageDisposer",void 0),T(this,"_dispose",void 0),this.target=t;const e=[this.target.on("dragenter",this.dragEnterHandler.bind(this)),this.target.on("dragover",this.dragOverHandler.bind(this)),this.target.on("dragleave",this.dragLeaveHandler.bind(this)),this.target.on("dragend",this.dragEndHandler.bind(this)),this.target.on("drop",this.dropHandler.bind(this))];this._dispose=()=>{e.forEach(s=>s()),this._dispose=void 0}}isPointerOverSelection(t){const e=this.target,s=e.getSelectionStartFromPointer(t);return e.isEditing&&s>=e.selectionStart&&s<=e.selectionEnd&&e.selectionStart<e.selectionEnd}start(t){return this.__mouseDownInPlace=this.isPointerOverSelection(t)}isActive(){return this.__mouseDownInPlace}end(t){const e=this.isActive();return e&&!this.__dragStartFired&&(this.target.setCursorByClick(t),this.target.initDelayedCursor(!0)),this.__mouseDownInPlace=!1,this.__dragStartFired=!1,this.__isDraggingOver=!1,e}getDragStartSelection(){return this.__dragStartSelection}setDragImage(t,e){var s;let{selectionStart:i,selectionEnd:n}=e;const r=this.target,o=r.canvas,h=new P(r.flipX?-1:1,r.flipY?-1:1),c=r._getCursorBoundaries(i),u=new P(c.left+c.leftOffset,c.top+c.topOffset).multiply(h).transform(r.calcTransformMatrix()),d=o.getScenePoint(t).subtract(u),f=r.getCanvasRetinaScaling(),g=r.getBoundingRect(),p=u.subtract(new P(g.left,g.top)),b=o.viewportTransform,v=p.add(d).transform(b,!0),_=r.backgroundColor,x=Nf(r.styles);r.backgroundColor="";const C={stroke:"transparent",fill:"transparent",textBackgroundColor:"transparent"};r.setSelectionStyles(C,0,i),r.setSelectionStyles(C,n,r.text.length),r.dirty=!0;const S=r.toCanvasElement({enableRetinaScaling:o.enableRetinaScaling,viewportTransform:!0});r.backgroundColor=_,r.styles=x,r.dirty=!0,fu(S,{position:"fixed",left:"".concat(-S.width,"px"),border:ke,width:"".concat(S.width/f,"px"),height:"".concat(S.height/f,"px")}),this.__dragImageDisposer&&this.__dragImageDisposer(),this.__dragImageDisposer=()=>{S.remove()},Ls(t.target||this.target.hiddenTextarea).body.appendChild(S),(s=t.dataTransfer)===null||s===void 0||s.setDragImage(S,v.x,v.y)}onDragStart(t){this.__dragStartFired=!0;const e=this.target,s=this.isActive();if(s&&t.dataTransfer){const i=this.__dragStartSelection={selectionStart:e.selectionStart,selectionEnd:e.selectionEnd},n=e._text.slice(i.selectionStart,i.selectionEnd).join(""),r=E({text:e.text,value:n},i);t.dataTransfer.setData("text/plain",n),t.dataTransfer.setData("application/fabric",JSON.stringify({value:n,styles:e.getSelectionStyles(i.selectionStart,i.selectionEnd,!0)})),t.dataTransfer.effectAllowed="copyMove",this.setDragImage(t,r)}return e.abortCursorAnimation(),s}canDrop(t){if(this.target.editable&&!this.target.getActiveControl()&&!t.defaultPrevented){if(this.isActive()&&this.__dragStartSelection){const e=this.target.getSelectionStartFromPointer(t),s=this.__dragStartSelection;return e<s.selectionStart||e>s.selectionEnd}return!0}return!1}targetCanDrop(t){return this.target.canDrop(t)}dragEnterHandler(t){let{e}=t;const s=this.targetCanDrop(e);!this.__isDraggingOver&&s&&(this.__isDraggingOver=!0)}dragOverHandler(t){const{e}=t,s=this.targetCanDrop(e);!this.__isDraggingOver&&s?this.__isDraggingOver=!0:this.__isDraggingOver&&!s&&(this.__isDraggingOver=!1),this.__isDraggingOver&&(e.preventDefault(),t.canDrop=!0,t.dropTarget=this.target)}dragLeaveHandler(){(this.__isDraggingOver||this.isActive())&&(this.__isDraggingOver=!1)}dropHandler(t){var e;const{e:s}=t,i=s.defaultPrevented;this.__isDraggingOver=!1,s.preventDefault();let n=(e=s.dataTransfer)===null||e===void 0?void 0:e.getData("text/plain");if(n&&!i){const r=this.target,o=r.canvas;let h=r.getSelectionStartFromPointer(s);const{styles:c}=s.dataTransfer.types.includes("application/fabric")?JSON.parse(s.dataTransfer.getData("application/fabric")):{},u=n[Math.max(0,n.length-1)],d=0;if(this.__dragStartSelection){const f=this.__dragStartSelection.selectionStart,g=this.__dragStartSelection.selectionEnd;h>f&&h<=g?h=f:h>g&&(h-=g-f),r.removeChars(f,g),delete this.__dragStartSelection}r._reNewline.test(u)&&(r._reNewline.test(r._text[h])||h===r._text.length)&&(n=n.trimEnd()),t.didDrop=!0,t.dropTarget=r,r.insertChars(n,c,h),o.setActiveObject(r),r.enterEditing(s),r.selectionStart=Math.min(h+d,r._text.length),r.selectionEnd=Math.min(r.selectionStart+n.length,r._text.length),r.hiddenTextarea.value=r.text,r._updateTextarea(),r.hiddenTextarea.focus(),r.fire(Gc,{index:h+d,action:"drop"}),o.fire("text:changed",{target:r}),o.contextTopDirty=!0,o.requestRenderAll()}}dragEndHandler(t){let{e}=t;if(this.isActive()&&this.__dragStartFired&&this.__dragStartSelection){var s;const i=this.target,n=this.target.canvas,{selectionStart:r,selectionEnd:o}=this.__dragStartSelection,h=((s=e.dataTransfer)===null||s===void 0?void 0:s.dropEffect)||ke;h===ke?(i.selectionStart=r,i.selectionEnd=o,i._updateTextarea(),i.hiddenTextarea.focus()):(i.clearContextTop(),h==="move"&&(i.removeChars(r,o),i.selectionStart=i.selectionEnd=r,i.hiddenTextarea&&(i.hiddenTextarea.value=i.text),i._updateTextarea(),i.fire(Gc,{index:r,action:"dragend"}),n.fire("text:changed",{target:i}),n.requestRenderAll()),i.exitEditing())}this.__dragImageDisposer&&this.__dragImageDisposer(),delete this.__dragImageDisposer,delete this.__dragStartSelection,this.__isDraggingOver=!1}dispose(){this._dispose&&this._dispose()}}const L0=/[ \n\.,;!\?\-]/;class xw extends me{constructor(){super(...arguments),T(this,"_currentCursorOpacity",1)}initBehavior(){this._tick=this._tick.bind(this),this._onTickComplete=this._onTickComplete.bind(this),this.updateSelectionOnMouseMove=this.updateSelectionOnMouseMove.bind(this)}onDeselect(t){return this.isEditing&&this.exitEditing(),this.selected=!1,super.onDeselect(t)}_animateCursor(t){let{toValue:e,duration:s,delay:i,onComplete:n}=t;return Lf({startValue:this._currentCursorOpacity,endValue:e,duration:s,delay:i,onComplete:n,abort:()=>!this.canvas||this.selectionStart!==this.selectionEnd,onChange:r=>{this._currentCursorOpacity=r,this.renderCursorOrSelection()}})}_tick(t){this._currentTickState=this._animateCursor({toValue:0,duration:this.cursorDuration/2,delay:Math.max(t||0,100),onComplete:this._onTickComplete})}_onTickComplete(){var t;(t=this._currentTickCompleteState)===null||t===void 0||t.abort(),this._currentTickCompleteState=this._animateCursor({toValue:1,duration:this.cursorDuration,onComplete:this._tick})}initDelayedCursor(t){this.abortCursorAnimation(),this._tick(t?0:this.cursorDelay)}abortCursorAnimation(){let t=!1;[this._currentTickState,this._currentTickCompleteState].forEach(e=>{e&&!e.isDone()&&(t=!0,e.abort())}),this._currentCursorOpacity=1,t&&this.clearContextTop()}restartCursorIfNeeded(){[this._currentTickState,this._currentTickCompleteState].some(t=>!t||t.isDone())&&this.initDelayedCursor()}selectAll(){return this.selectionStart=0,this.selectionEnd=this._text.length,this._fireSelectionChanged(),this._updateTextarea(),this}getSelectedText(){return this._text.slice(this.selectionStart,this.selectionEnd).join("")}findWordBoundaryLeft(t){let e=0,s=t-1;if(this._reSpace.test(this._text[s]))for(;this._reSpace.test(this._text[s]);)e++,s--;for(;/\S/.test(this._text[s])&&s>-1;)e++,s--;return t-e}findWordBoundaryRight(t){let e=0,s=t;if(this._reSpace.test(this._text[s]))for(;this._reSpace.test(this._text[s]);)e++,s++;for(;/\S/.test(this._text[s])&&s<this._text.length;)e++,s++;return t+e}findLineBoundaryLeft(t){let e=0,s=t-1;for(;!/\n/.test(this._text[s])&&s>-1;)e++,s--;return t-e}findLineBoundaryRight(t){let e=0,s=t;for(;!/\n/.test(this._text[s])&&s<this._text.length;)e++,s++;return t+e}searchWordBoundary(t,e){const s=this._text;let i=t>0&&this._reSpace.test(s[t])&&(e===-1||!hf.test(s[t-1]))?t-1:t,n=s[i];for(;i>0&&i<s.length&&!L0.test(n);)i+=e,n=s[i];return e===-1&&L0.test(n)&&i++,i}selectWord(t){t=t||this.selectionStart;const e=this.searchWordBoundary(t,-1),s=Math.max(e,this.searchWordBoundary(t,1));this.selectionStart=e,this.selectionEnd=s,this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()}selectLine(t){t=t||this.selectionStart;const e=this.findLineBoundaryLeft(t),s=this.findLineBoundaryRight(t);return this.selectionStart=e,this.selectionEnd=s,this._fireSelectionChanged(),this._updateTextarea(),this}enterEditing(t){!this.isEditing&&this.editable&&(this.enterEditingImpl(),this.fire("editing:entered",t?{e:t}:void 0),this._fireSelectionChanged(),this.canvas&&(this.canvas.fire("text:editing:entered",{target:this,e:t}),this.canvas.requestRenderAll()))}enterEditingImpl(){this.canvas&&(this.canvas.calcOffset(),this.canvas.textEditingManager.exitTextEditing()),this.isEditing=!0,this.initHiddenTextarea(),this.hiddenTextarea.focus(),this.hiddenTextarea.value=this.text,this._updateTextarea(),this._saveEditingProps(),this._setEditingProps(),this._textBeforeEdit=this.text,this._tick()}updateSelectionOnMouseMove(t){if(this.getActiveControl())return;const e=this.hiddenTextarea;Ls(e).activeElement!==e&&e.focus();const s=this.getSelectionStartFromPointer(t),i=this.selectionStart,n=this.selectionEnd;(s===this.__selectionStartOnMouseDown&&i!==n||i!==s&&n!==s)&&(s>this.__selectionStartOnMouseDown?(this.selectionStart=this.__selectionStartOnMouseDown,this.selectionEnd=s):(this.selectionStart=s,this.selectionEnd=this.__selectionStartOnMouseDown),this.selectionStart===i&&this.selectionEnd===n||(this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()))}_setEditingProps(){this.hoverCursor="text",this.canvas&&(this.canvas.defaultCursor=this.canvas.moveCursor="text"),this.borderColor=this.editingBorderColor,this.hasControls=this.selectable=!1,this.lockMovementX=this.lockMovementY=!0}fromStringToGraphemeSelection(t,e,s){const i=s.slice(0,t),n=this.graphemeSplit(i).length;if(t===e)return{selectionStart:n,selectionEnd:n};const r=s.slice(t,e);return{selectionStart:n,selectionEnd:n+this.graphemeSplit(r).length}}fromGraphemeToStringSelection(t,e,s){const i=s.slice(0,t).join("").length;return t===e?{selectionStart:i,selectionEnd:i}:{selectionStart:i,selectionEnd:i+s.slice(t,e).join("").length}}_updateTextarea(){if(this.cursorOffsetCache={},this.hiddenTextarea){if(!this.inCompositionMode){const t=this.fromGraphemeToStringSelection(this.selectionStart,this.selectionEnd,this._text);this.hiddenTextarea.selectionStart=t.selectionStart,this.hiddenTextarea.selectionEnd=t.selectionEnd}this.updateTextareaPosition()}}updateFromTextArea(){if(!this.hiddenTextarea)return;this.cursorOffsetCache={};const t=this.hiddenTextarea;this.text=t.value,this.set("dirty",!0),this.initDimensions(),this.setCoords();const e=this.fromStringToGraphemeSelection(t.selectionStart,t.selectionEnd,t.value);this.selectionEnd=this.selectionStart=e.selectionEnd,this.inCompositionMode||(this.selectionStart=e.selectionStart),this.updateTextareaPosition()}updateTextareaPosition(){if(this.selectionStart===this.selectionEnd){const t=this._calcTextareaPosition();this.hiddenTextarea.style.left=t.left,this.hiddenTextarea.style.top=t.top}}_calcTextareaPosition(){if(!this.canvas)return{left:"1px",top:"1px"};const t=this.inCompositionMode?this.compositionStart:this.selectionStart,e=this._getCursorBoundaries(t),s=this.get2DCursorLocation(t),i=s.lineIndex,n=s.charIndex,r=this.getValueOfPropertyAt(i,n,"fontSize")*this.lineHeight,o=e.leftOffset,h=this.getCanvasRetinaScaling(),c=this.canvas.upperCanvasEl,u=c.width/h,d=c.height/h,f=u-r,g=d-r,p=new P(e.left+o,e.top+e.topOffset+r).transform(this.calcTransformMatrix()).transform(this.canvas.viewportTransform).multiply(new P(c.clientWidth/u,c.clientHeight/d));return p.x<0&&(p.x=0),p.x>f&&(p.x=f),p.y<0&&(p.y=0),p.y>g&&(p.y=g),p.x+=this.canvas._offset.left,p.y+=this.canvas._offset.top,{left:"".concat(p.x,"px"),top:"".concat(p.y,"px"),fontSize:"".concat(r,"px"),charHeight:r}}_saveEditingProps(){this._savedProps={hasControls:this.hasControls,borderColor:this.borderColor,lockMovementX:this.lockMovementX,lockMovementY:this.lockMovementY,hoverCursor:this.hoverCursor,selectable:this.selectable,defaultCursor:this.canvas&&this.canvas.defaultCursor,moveCursor:this.canvas&&this.canvas.moveCursor}}_restoreEditingProps(){this._savedProps&&(this.hoverCursor=this._savedProps.hoverCursor,this.hasControls=this._savedProps.hasControls,this.borderColor=this._savedProps.borderColor,this.selectable=this._savedProps.selectable,this.lockMovementX=this._savedProps.lockMovementX,this.lockMovementY=this._savedProps.lockMovementY,this.canvas&&(this.canvas.defaultCursor=this._savedProps.defaultCursor||this.canvas.defaultCursor,this.canvas.moveCursor=this._savedProps.moveCursor||this.canvas.moveCursor),delete this._savedProps)}_exitEditing(){const t=this.hiddenTextarea;this.selected=!1,this.isEditing=!1,t&&(t.blur&&t.blur(),t.parentNode&&t.parentNode.removeChild(t)),this.hiddenTextarea=null,this.abortCursorAnimation(),this.selectionStart!==this.selectionEnd&&this.clearContextTop()}exitEditingImpl(){this._exitEditing(),this.selectionEnd=this.selectionStart,this._restoreEditingProps(),this._forceClearCache&&(this.initDimensions(),this.setCoords())}exitEditing(){const t=this._textBeforeEdit!==this.text;return this.exitEditingImpl(),this.fire("editing:exited"),t&&this.fire(Vc),this.canvas&&(this.canvas.fire("text:editing:exited",{target:this}),t&&this.canvas.fire("object:modified",{target:this})),this}_removeExtraneousStyles(){for(const t in this.styles)this._textLines[t]||delete this.styles[t]}removeStyleFromTo(t,e){const{lineIndex:s,charIndex:i}=this.get2DCursorLocation(t,!0),{lineIndex:n,charIndex:r}=this.get2DCursorLocation(e,!0);if(s!==n){if(this.styles[s])for(let o=i;o<this._unwrappedTextLines[s].length;o++)delete this.styles[s][o];if(this.styles[n])for(let o=r;o<this._unwrappedTextLines[n].length;o++){const h=this.styles[n][o];h&&(this.styles[s]||(this.styles[s]={}),this.styles[s][i+o-r]=h)}for(let o=s+1;o<=n;o++)delete this.styles[o];this.shiftLineStyles(n,s-n)}else if(this.styles[s]){const o=this.styles[s],h=r-i;for(let c=i;c<r;c++)delete o[c];for(const c in this.styles[s]){const u=parseInt(c,10);u>=r&&(o[u-h]=o[c],delete o[c])}}}shiftLineStyles(t,e){const s=Object.assign({},this.styles);for(const i in this.styles){const n=parseInt(i,10);n>t&&(this.styles[n+e]=s[n],s[n-e]||delete this.styles[n])}}insertNewlineStyleObject(t,e,s,i){const n={},r=this._unwrappedTextLines[t].length,o=r===e;let h=!1;s||(s=1),this.shiftLineStyles(t,s);const c=this.styles[t]?this.styles[t][e===0?e:e-1]:void 0;for(const d in this.styles[t]){const f=parseInt(d,10);f>=e&&(h=!0,n[f-e]=this.styles[t][d],o&&e===0||delete this.styles[t][d])}let u=!1;for(h&&!o&&(this.styles[t+s]=n,u=!0),(u||r>e)&&s--;s>0;)i&&i[s-1]?this.styles[t+s]={0:E({},i[s-1])}:c?this.styles[t+s]={0:E({},c)}:delete this.styles[t+s],s--;this._forceClearCache=!0}insertCharStyleObject(t,e,s,i){this.styles||(this.styles={});const n=this.styles[t],r=n?E({},n):{};s||(s=1);for(const h in r){const c=parseInt(h,10);c>=e&&(n[c+s]=r[c],r[c-s]||delete n[c])}if(this._forceClearCache=!0,i){for(;s--;)Object.keys(i[s]).length&&(this.styles[t]||(this.styles[t]={}),this.styles[t][e+s]=E({},i[s]));return}if(!n)return;const o=n[e?e-1:1];for(;o&&s--;)this.styles[t][e+s]=E({},o)}insertNewStyleBlock(t,e,s){const i=this.get2DCursorLocation(e,!0),n=[0];let r,o=0;for(let h=0;h<t.length;h++)t[h]===`
56
+ `?(o++,n[o]=0):n[o]++;for(n[0]>0&&(this.insertCharStyleObject(i.lineIndex,i.charIndex,n[0],s),s=s&&s.slice(n[0]+1)),o&&this.insertNewlineStyleObject(i.lineIndex,i.charIndex+n[0],o),r=1;r<o;r++)n[r]>0?this.insertCharStyleObject(i.lineIndex+r,0,n[r],s):s&&this.styles[i.lineIndex+r]&&s[0]&&(this.styles[i.lineIndex+r][0]=s[0]),s=s&&s.slice(n[r]+1);n[r]>0&&this.insertCharStyleObject(i.lineIndex+r,0,n[r],s)}removeChars(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:t+1;this.removeStyleFromTo(t,e),this._text.splice(t,e-t),this.text=this._text.join(""),this.set("dirty",!0),this.initDimensions(),this.setCoords(),this._removeExtraneousStyles()}insertChars(t,e,s){let i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:s;i>s&&this.removeStyleFromTo(s,i);const n=this.graphemeSplit(t);this.insertNewStyleBlock(n,s,e),this._text=[...this._text.slice(0,s),...n,...this._text.slice(i)],this.text=this._text.join(""),this.set("dirty",!0),this.initDimensions(),this.setCoords(),this._removeExtraneousStyles()}setSelectionStartEndWithShift(t,e,s){s<=t?(e===t?this._selectionDirection=dt:this._selectionDirection===It&&(this._selectionDirection=dt,this.selectionEnd=t),this.selectionStart=s):s>t&&s<e?this._selectionDirection===It?this.selectionEnd=s:this.selectionStart=s:(e===t?this._selectionDirection=It:this._selectionDirection===dt&&(this._selectionDirection=It,this.selectionStart=e),this.selectionEnd=s)}}class Sw extends xw{initHiddenTextarea(){const t=this.canvas&&Ls(this.canvas.getElement())||Vo(),e=t.createElement("textarea");Object.entries({autocapitalize:"off",autocorrect:"off",autocomplete:"off",spellcheck:"false","data-fabric":"textarea",wrap:"off"}).map(r=>{let[o,h]=r;return e.setAttribute(o,h)});const{top:s,left:i,fontSize:n}=this._calcTextareaPosition();e.style.cssText="position: absolute; top: ".concat(s,"; left: ").concat(i,"; z-index: -999; opacity: 0; width: 1px; height: 1px; font-size: 1px; padding-top: ").concat(n,";"),(this.hiddenTextareaContainer||t.body).appendChild(e),Object.entries({blur:"blur",keydown:"onKeyDown",keyup:"onKeyUp",input:"onInput",copy:"copy",cut:"copy",paste:"paste",compositionstart:"onCompositionStart",compositionupdate:"onCompositionUpdate",compositionend:"onCompositionEnd"}).map(r=>{let[o,h]=r;return e.addEventListener(o,this[h].bind(this))}),this.hiddenTextarea=e}blur(){this.abortCursorAnimation()}onKeyDown(t){if(!this.isEditing)return;const e=this.direction==="rtl"?this.keysMapRtl:this.keysMap;if(t.keyCode in e)this[e[t.keyCode]](t);else{if(!(t.keyCode in this.ctrlKeysMapDown)||!t.ctrlKey&&!t.metaKey)return;this[this.ctrlKeysMapDown[t.keyCode]](t)}t.stopImmediatePropagation(),t.preventDefault(),t.keyCode>=33&&t.keyCode<=40?(this.inCompositionMode=!1,this.clearContextTop(),this.renderCursorOrSelection()):this.canvas&&this.canvas.requestRenderAll()}onKeyUp(t){!this.isEditing||this._copyDone||this.inCompositionMode?this._copyDone=!1:t.keyCode in this.ctrlKeysMapUp&&(t.ctrlKey||t.metaKey)&&(this[this.ctrlKeysMapUp[t.keyCode]](t),t.stopImmediatePropagation(),t.preventDefault(),this.canvas&&this.canvas.requestRenderAll())}onInput(t){const e=this.fromPaste;if(this.fromPaste=!1,t&&t.stopPropagation(),!this.isEditing)return;const s=()=>{this.updateFromTextArea(),this.fire(Gc),this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll())};if(this.hiddenTextarea.value==="")return this.styles={},void s();const i=this._splitTextIntoLines(this.hiddenTextarea.value).graphemeText,n=this._text.length,r=i.length,o=this.selectionStart,h=this.selectionEnd,c=o!==h;let u,d,f,g,p=r-n;const b=this.fromStringToGraphemeSelection(this.hiddenTextarea.selectionStart,this.hiddenTextarea.selectionEnd,this.hiddenTextarea.value),v=o>b.selectionStart;c?(d=this._text.slice(o,h),p+=h-o):r<n&&(d=v?this._text.slice(h+p,h):this._text.slice(o,o-p));const _=i.slice(b.selectionEnd-p,b.selectionEnd);if(d&&d.length&&(_.length&&(u=this.getSelectionStyles(o,o+1,!1),u=_.map(()=>u[0])),c?(f=o,g=h):v?(f=h-d.length,g=h):(f=h,g=h+d.length),this.removeStyleFromTo(f,g)),_.length){const{copyPasteData:x}=ni();e&&_.join("")===x.copiedText&&!ht.disableStyleCopyPaste&&(u=x.copiedTextStyle),this.insertNewStyleBlock(_,o,u)}s()}onCompositionStart(){this.inCompositionMode=!0}onCompositionEnd(){this.inCompositionMode=!1}onCompositionUpdate(t){let{target:e}=t;const{selectionStart:s,selectionEnd:i}=e;this.compositionStart=s,this.compositionEnd=i,this.updateTextareaPosition()}copy(){if(this.selectionStart===this.selectionEnd)return;const{copyPasteData:t}=ni();t.copiedText=this.getSelectedText(),ht.disableStyleCopyPaste?t.copiedTextStyle=void 0:t.copiedTextStyle=this.getSelectionStyles(this.selectionStart,this.selectionEnd,!0),this._copyDone=!0}paste(){this.fromPaste=!0}_getWidthBeforeCursor(t,e){let s,i=this._getLineLeftOffset(t);return e>0&&(s=this.__charBounds[t][e-1],i+=s.left+s.width),i}getDownCursorOffset(t,e){const s=this._getSelectionForOffset(t,e),i=this.get2DCursorLocation(s),n=i.lineIndex;if(n===this._textLines.length-1||t.metaKey||t.keyCode===34)return this._text.length-s;const r=i.charIndex,o=this._getWidthBeforeCursor(n,r),h=this._getIndexOnLine(n+1,o);return this._textLines[n].slice(r).length+h+1+this.missingNewlineOffset(n)}_getSelectionForOffset(t,e){return t.shiftKey&&this.selectionStart!==this.selectionEnd&&e?this.selectionEnd:this.selectionStart}getUpCursorOffset(t,e){const s=this._getSelectionForOffset(t,e),i=this.get2DCursorLocation(s),n=i.lineIndex;if(n===0||t.metaKey||t.keyCode===33)return-s;const r=i.charIndex,o=this._getWidthBeforeCursor(n,r),h=this._getIndexOnLine(n-1,o),c=this._textLines[n].slice(0,r),u=this.missingNewlineOffset(n-1);return-this._textLines[n-1].length+h-c.length+(1-u)}_getIndexOnLine(t,e){const s=this._textLines[t];let i,n,r=this._getLineLeftOffset(t),o=0;for(let h=0,c=s.length;h<c;h++)if(i=this.__charBounds[t][h].width,r+=i,r>e){n=!0;const u=r-i,d=r,f=Math.abs(u-e);o=Math.abs(d-e)<f?h:h-1;break}return n||(o=s.length-1),o}moveCursorDown(t){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorUpOrDown("Down",t)}moveCursorUp(t){this.selectionStart===0&&this.selectionEnd===0||this._moveCursorUpOrDown("Up",t)}_moveCursorUpOrDown(t,e){const s=this["get".concat(t,"CursorOffset")](e,this._selectionDirection===It);if(e.shiftKey?this.moveCursorWithShift(s):this.moveCursorWithoutShift(s),s!==0){const i=this.text.length;this.selectionStart=wr(0,this.selectionStart,i),this.selectionEnd=wr(0,this.selectionEnd,i),this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea()}}moveCursorWithShift(t){const e=this._selectionDirection===dt?this.selectionStart+t:this.selectionEnd+t;return this.setSelectionStartEndWithShift(this.selectionStart,this.selectionEnd,e),t!==0}moveCursorWithoutShift(t){return t<0?(this.selectionStart+=t,this.selectionEnd=this.selectionStart):(this.selectionEnd+=t,this.selectionStart=this.selectionEnd),t!==0}moveCursorLeft(t){this.selectionStart===0&&this.selectionEnd===0||this._moveCursorLeftOrRight("Left",t)}_move(t,e,s){let i;if(t.altKey)i=this["findWordBoundary".concat(s)](this[e]);else{if(!t.metaKey&&t.keyCode!==35&&t.keyCode!==36)return this[e]+=s==="Left"?-1:1,!0;i=this["findLineBoundary".concat(s)](this[e])}return i!==void 0&&this[e]!==i&&(this[e]=i,!0)}_moveLeft(t,e){return this._move(t,e,"Left")}_moveRight(t,e){return this._move(t,e,"Right")}moveCursorLeftWithoutShift(t){let e=!0;return this._selectionDirection=dt,this.selectionEnd===this.selectionStart&&this.selectionStart!==0&&(e=this._moveLeft(t,"selectionStart")),this.selectionEnd=this.selectionStart,e}moveCursorLeftWithShift(t){return this._selectionDirection===It&&this.selectionStart!==this.selectionEnd?this._moveLeft(t,"selectionEnd"):this.selectionStart!==0?(this._selectionDirection=dt,this._moveLeft(t,"selectionStart")):void 0}moveCursorRight(t){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorLeftOrRight("Right",t)}_moveCursorLeftOrRight(t,e){const s="moveCursor".concat(t).concat(e.shiftKey?"WithShift":"WithoutShift");this._currentCursorOpacity=1,this[s](e)&&(this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea())}moveCursorRightWithShift(t){return this._selectionDirection===dt&&this.selectionStart!==this.selectionEnd?this._moveRight(t,"selectionStart"):this.selectionEnd!==this._text.length?(this._selectionDirection=It,this._moveRight(t,"selectionEnd")):void 0}moveCursorRightWithoutShift(t){let e=!0;return this._selectionDirection=It,this.selectionStart===this.selectionEnd?(e=this._moveRight(t,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,e}}const Kf=a=>!!a.button;class Cw extends Sw{constructor(){super(...arguments),T(this,"draggableTextDelegate",void 0)}initBehavior(){this.on("mousedown",this._mouseDownHandler),this.on("mousedown:before",this._mouseDownHandlerBefore),this.on("mouseup",this.mouseUpHandler),this.on("mousedblclick",this.doubleClickHandler),this.on("tripleclick",this.tripleClickHandler),this.__lastClickTime=+new Date,this.__lastLastClickTime=+new Date,this.__lastPointer={},this.on("mousedown",this.onMouseDown),this.draggableTextDelegate=new ww(this),super.initBehavior()}shouldStartDragging(){return this.draggableTextDelegate.isActive()}onDragStart(t){return this.draggableTextDelegate.onDragStart(t)}canDrop(t){return this.draggableTextDelegate.canDrop(t)}onMouseDown(t){if(!this.canvas)return;this.__newClickTime=+new Date;const e=t.pointer;this.isTripleClick(e)&&(this.fire("tripleclick",t),_f(t.e)),this.__lastLastClickTime=this.__lastClickTime,this.__lastClickTime=this.__newClickTime,this.__lastPointer=e,this.__lastSelected=this.selected&&!this.getActiveControl()}isTripleClick(t){return this.__newClickTime-this.__lastClickTime<500&&this.__lastClickTime-this.__lastLastClickTime<500&&this.__lastPointer.x===t.x&&this.__lastPointer.y===t.y}doubleClickHandler(t){this.isEditing&&this.selectWord(this.getSelectionStartFromPointer(t.e))}tripleClickHandler(t){this.isEditing&&this.selectLine(this.getSelectionStartFromPointer(t.e))}_mouseDownHandler(t){let{e}=t;this.canvas&&this.editable&&!Kf(e)&&!this.getActiveControl()&&(this.draggableTextDelegate.start(e)||(this.canvas.textEditingManager.register(this),this.selected&&(this.inCompositionMode=!1,this.setCursorByClick(e)),this.isEditing&&(this.__selectionStartOnMouseDown=this.selectionStart,this.selectionStart===this.selectionEnd&&this.abortCursorAnimation(),this.renderCursorOrSelection())))}_mouseDownHandlerBefore(t){let{e}=t;this.canvas&&this.editable&&!Kf(e)&&(this.selected=this===this.canvas._activeObject)}mouseUpHandler(t){let{e,transform:s}=t;const i=this.draggableTextDelegate.end(e);if(this.canvas){this.canvas.textEditingManager.unregister(this);const n=this.canvas._activeObject;if(n&&n!==this)return}!this.editable||this.group&&!this.group.interactive||s&&s.actionPerformed||Kf(e)||i||(this.__lastSelected&&!this.getActiveControl()?(this.selected=!1,this.__lastSelected=!1,this.enterEditing(e),this.selectionStart===this.selectionEnd?this.initDelayedCursor(!0):this.renderCursorOrSelection()):this.selected=!0)}setCursorByClick(t){const e=this.getSelectionStartFromPointer(t),s=this.selectionStart,i=this.selectionEnd;t.shiftKey?this.setSelectionStartEndWithShift(s,i,e):(this.selectionStart=e,this.selectionEnd=e),this.isEditing&&(this._fireSelectionChanged(),this._updateTextarea())}getSelectionStartFromPointer(t){const e=this.canvas.getScenePoint(t).transform(Xe(this.calcTransformMatrix())).add(new P(-this._getLeftOffset(),-this._getTopOffset()));let s=0,i=0,n=0;for(let c=0;c<this._textLines.length&&s<=e.y;c++)s+=this.getHeightOfLine(c),n=c,c>0&&(i+=this._textLines[c-1].length+this.missingNewlineOffset(c-1));let r=Math.abs(this._getLineLeftOffset(n));const o=this._textLines[n].length,h=this.__charBounds[n];for(let c=0;c<o;c++){const u=r+h[c].kernedWidth;if(e.x<=u){Math.abs(e.x-u)<=Math.abs(e.x-r)&&i++;break}r=u,i++}return Math.min(this.flipX?o-i:i,this._text.length)}}const yu="moveCursorUp",vu="moveCursorDown",_u="moveCursorLeft",wu="moveCursorRight",xu="exitEditing",Aw=E({selectionStart:0,selectionEnd:0,selectionColor:"rgba(17,119,255,0.3)",isEditing:!1,editable:!0,editingBorderColor:"rgba(102,153,255,0.25)",cursorWidth:2,cursorColor:"",cursorDelay:1e3,cursorDuration:600,caching:!0,hiddenTextareaContainer:null,keysMap:{9:xu,27:xu,33:yu,34:vu,35:wu,36:_u,37:_u,38:yu,39:wu,40:vu},keysMapRtl:{9:xu,27:xu,33:yu,34:vu,35:_u,36:wu,37:wu,38:yu,39:_u,40:vu},ctrlKeysMapDown:{65:"selectAll"},ctrlKeysMapUp:{67:"copy",88:"cut"}},{_selectionDirection:null,_reSpace:/\s|\r?\n/,inCompositionMode:!1});class Gi extends Cw{static getDefaults(){return E(E({},super.getDefaults()),Gi.ownDefaults)}get type(){const t=super.type;return t==="itext"?"i-text":t}constructor(t,e){super(t,E(E({},Gi.ownDefaults),e)),this.initBehavior()}_set(t,e){return this.isEditing&&this._savedProps&&t in this._savedProps?(this._savedProps[t]=e,this):(t==="canvas"&&(this.canvas instanceof Wf&&this.canvas.textEditingManager.remove(this),e instanceof Wf&&e.textEditingManager.add(this)),super._set(t,e))}setSelectionStart(t){t=Math.max(t,0),this._updateAndFire("selectionStart",t)}setSelectionEnd(t){t=Math.min(t,this.text.length),this._updateAndFire("selectionEnd",t)}_updateAndFire(t,e){this[t]!==e&&(this._fireSelectionChanged(),this[t]=e),this._updateTextarea()}_fireSelectionChanged(){this.fire("selection:changed"),this.canvas&&this.canvas.fire("text:selection:changed",{target:this})}initDimensions(){this.isEditing&&this.initDelayedCursor(),super.initDimensions()}getSelectionStyles(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart||0,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.selectionEnd,s=arguments.length>2?arguments[2]:void 0;return super.getSelectionStyles(t,e,s)}setSelectionStyles(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.selectionStart||0,s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.selectionEnd;return super.setSelectionStyles(t,e,s)}get2DCursorLocation(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;return super.get2DCursorLocation(t,e)}render(t){super.render(t),this.cursorOffsetCache={},this.renderCursorOrSelection()}toCanvasElement(t){const e=this.isEditing;this.isEditing=!1;const s=super.toCanvasElement(t);return this.isEditing=e,s}renderCursorOrSelection(){if(!this.isEditing)return;const t=this.clearContextTop(!0);if(!t)return;const e=this._getCursorBoundaries();this.selectionStart!==this.selectionEnd||this.inCompositionMode?this.renderSelection(t,e):this.renderCursor(t,e),this.canvas.contextTopDirty=!0,t.restore()}_getCursorBoundaries(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1?arguments[1]:void 0;const s=this._getLeftOffset(),i=this._getTopOffset(),n=this._getCursorBoundariesOffsets(t,e);return{left:s,top:i,leftOffset:n.left,topOffset:n.top}}_getCursorBoundariesOffsets(t,e){return e?this.__getCursorBoundariesOffsets(t):this.cursorOffsetCache&&"top"in this.cursorOffsetCache?this.cursorOffsetCache:this.cursorOffsetCache=this.__getCursorBoundariesOffsets(t)}__getCursorBoundariesOffsets(t){let e=0,s=0;const{charIndex:i,lineIndex:n}=this.get2DCursorLocation(t);for(let c=0;c<n;c++)e+=this.getHeightOfLine(c);const r=this._getLineLeftOffset(n),o=this.__charBounds[n][i];o&&(s=o.left),this.charSpacing!==0&&i===this._textLines[n].length&&(s-=this._getWidthOfCharSpacing());const h={top:e,left:r+(s>0?s:0)};return this.direction==="rtl"&&(this.textAlign===It||this.textAlign===hi||this.textAlign===Nh?h.left*=-1:this.textAlign===dt||this.textAlign===bu?h.left=r-(s>0?s:0):this.textAlign!==Q&&this.textAlign!==jh||(h.left=r-(s>0?s:0))),h}renderCursorAt(t){this._renderCursor(this.canvas.contextTop,this._getCursorBoundaries(t,!0),t)}renderCursor(t,e){this._renderCursor(t,e,this.selectionStart)}getCursorRenderingData(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.selectionStart,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this._getCursorBoundaries(t);const s=this.get2DCursorLocation(t),i=s.lineIndex,n=s.charIndex>0?s.charIndex-1:0,r=this.getValueOfPropertyAt(i,n,"fontSize"),o=this.getObjectScaling().x*this.canvas.getZoom(),h=this.cursorWidth/o,c=this.getValueOfPropertyAt(i,n,"deltaY"),u=e.topOffset+(1-this._fontSizeFraction)*this.getHeightOfLine(i)/this.lineHeight-r*(1-this._fontSizeFraction);return{color:this.cursorColor||this.getValueOfPropertyAt(i,n,"fill"),opacity:this._currentCursorOpacity,left:e.left+e.leftOffset-h/2,top:u+e.top+c,width:h,height:r}}_renderCursor(t,e,s){const{color:i,opacity:n,left:r,top:o,width:h,height:c}=this.getCursorRenderingData(s,e);t.fillStyle=i,t.globalAlpha=n,t.fillRect(r,o,h,c)}renderSelection(t,e){const s={selectionStart:this.inCompositionMode?this.hiddenTextarea.selectionStart:this.selectionStart,selectionEnd:this.inCompositionMode?this.hiddenTextarea.selectionEnd:this.selectionEnd};this._renderSelection(t,s,e)}renderDragSourceEffect(){const t=this.draggableTextDelegate.getDragStartSelection();this._renderSelection(this.canvas.contextTop,t,this._getCursorBoundaries(t.selectionStart,!0))}renderDropTargetEffect(t){const e=this.getSelectionStartFromPointer(t);this.renderCursorAt(e)}_renderSelection(t,e,s){const i=e.selectionStart,n=e.selectionEnd,r=this.textAlign.includes(hi),o=this.get2DCursorLocation(i),h=this.get2DCursorLocation(n),c=o.lineIndex,u=h.lineIndex,d=o.charIndex<0?0:o.charIndex,f=h.charIndex<0?0:h.charIndex;for(let g=c;g<=u;g++){const p=this._getLineLeftOffset(g)||0;let b=this.getHeightOfLine(g),v=0,_=0,x=0;if(g===c&&(_=this.__charBounds[c][d].left),g>=c&&g<u)x=r&&!this.isEndOfWrapping(g)?this.width:this.getLineWidth(g)||5;else if(g===u)if(f===0)x=this.__charBounds[u][f].left;else{const A=this._getWidthOfCharSpacing();x=this.__charBounds[u][f-1].left+this.__charBounds[u][f-1].width-A}v=b,(this.lineHeight<1||g===u&&this.lineHeight>1)&&(b/=this.lineHeight);let C=s.left+p+_,S=b,k=0;const D=x-_;this.inCompositionMode?(t.fillStyle=this.compositionColor||"black",S=1,k=b):t.fillStyle=this.selectionColor,this.direction==="rtl"&&(this.textAlign===It||this.textAlign===hi||this.textAlign===Nh?C=this.width-C-D:this.textAlign===dt||this.textAlign===bu?C=s.left+p-x:this.textAlign!==Q&&this.textAlign!==jh||(C=s.left+p-x)),t.fillRect(C,s.top+s.topOffset+k,D,S),s.topOffset+=v}}getCurrentCharFontSize(){const t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,"fontSize")}getCurrentCharColor(){const t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,zt)}_getCurrentCharIndex(){const t=this.get2DCursorLocation(this.selectionStart,!0),e=t.charIndex>0?t.charIndex-1:0;return{l:t.lineIndex,c:e}}dispose(){this.exitEditingImpl(),this.draggableTextDelegate.dispose(),super.dispose()}}T(Gi,"ownDefaults",Aw),T(Gi,"type","IText"),N.setClass(Gi),N.setClass(Gi,"i-text");class Ar extends Gi{static getDefaults(){return E(E({},super.getDefaults()),Ar.ownDefaults)}constructor(t,e){super(t,E(E({},Ar.ownDefaults),e))}static createControls(){return{controls:l_()}}initDimensions(){this.initialized&&(this.isEditing&&this.initDelayedCursor(),this._clearCache(),this.dynamicMinWidth=0,this._styleMap=this._generateStyleMap(this._splitText()),this.dynamicMinWidth>this.width&&this._set("width",this.dynamicMinWidth),this.textAlign.includes(hi)&&this.enlargeSpaces(),this.height=this.calcTextHeight())}_generateStyleMap(t){let e=0,s=0,i=0;const n={};for(let r=0;r<t.graphemeLines.length;r++)t.graphemeText[i]===`
57
+ `&&r>0?(s=0,i++,e++):!this.splitByGrapheme&&this._reSpaceAndTab.test(t.graphemeText[i])&&r>0&&(s++,i++),n[r]={line:e,offset:s},i+=t.graphemeLines[r].length,s+=t.graphemeLines[r].length;return n}styleHas(t,e){if(this._styleMap&&!this.isWrapping){const s=this._styleMap[e];s&&(e=s.line)}return super.styleHas(t,e)}isEmptyStyles(t){if(!this.styles)return!0;let e,s=0,i=t+1,n=!1;const r=this._styleMap[t],o=this._styleMap[t+1];r&&(t=r.line,s=r.offset),o&&(i=o.line,n=i===t,e=o.offset);const h=t===void 0?this.styles:{line:this.styles[t]};for(const c in h)for(const u in h[c]){const d=parseInt(u,10);if(d>=s&&(!n||d<e))for(const f in h[c][u])return!1}return!0}_getStyleDeclaration(t,e){if(this._styleMap&&!this.isWrapping){const s=this._styleMap[t];if(!s)return{};t=s.line,e=s.offset+e}return super._getStyleDeclaration(t,e)}_setStyleDeclaration(t,e,s){const i=this._styleMap[t];super._setStyleDeclaration(i.line,i.offset+e,s)}_deleteStyleDeclaration(t,e){const s=this._styleMap[t];super._deleteStyleDeclaration(s.line,s.offset+e)}_getLineStyle(t){const e=this._styleMap[t];return!!this.styles[e.line]}_setLineStyle(t){const e=this._styleMap[t];super._setLineStyle(e.line)}_wrapText(t,e){this.isWrapping=!0;const s=this.getGraphemeDataForRender(t),i=[];for(let n=0;n<s.wordsData.length;n++)i.push(...this._wrapLine(n,e,s));return this.isWrapping=!1,i}getGraphemeDataForRender(t){const e=this.splitByGrapheme,s=e?"":" ";let i=0;return{wordsData:t.map((n,r)=>{let o=0;const h=e?this.graphemeSplit(n):this.wordSplit(n);return h.length===0?[{word:[],width:0}]:h.map(c=>{const u=e?[c]:this.graphemeSplit(c),d=this._measureWord(u,r,o);return i=Math.max(d,i),o+=u.length+s.length,{word:u,width:d}})}),largestWordWidth:i}}_measureWord(t,e){let s,i=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0,n=0;for(let r=0,o=t.length;r<o;r++)n+=this._getGraphemeBox(t[r],e,r+i,s,!0).kernedWidth,s=t[r];return n}wordSplit(t){return t.split(this._wordJoiners)}_wrapLine(t,e,s){let{largestWordWidth:i,wordsData:n}=s,r=arguments.length>3&&arguments[3]!==void 0?arguments[3]:0;const o=this._getWidthOfCharSpacing(),h=this.splitByGrapheme,c=[],u=h?"":" ";let d=0,f=[],g=0,p=0,b=!0;e-=r;const v=Math.max(e,i,this.dynamicMinWidth),_=n[t];let x;for(g=0,x=0;x<_.length;x++){const{word:C,width:S}=_[x];g+=C.length,d+=p+S-o,d>v&&!b?(c.push(f),f=[],d=S,b=!0):d+=o,b||h||f.push(u),f=f.concat(C),p=h?0:this._measureWord([u],t,g),g++,b=!1}return x&&c.push(f),i+r>this.dynamicMinWidth&&(this.dynamicMinWidth=i-o+r),c}isEndOfWrapping(t){return!this._styleMap[t+1]||this._styleMap[t+1].line!==this._styleMap[t].line}missingNewlineOffset(t,e){return this.splitByGrapheme&&!e?this.isEndOfWrapping(t)?1:0:1}_splitTextIntoLines(t){const e=super._splitTextIntoLines(t),s=this._wrapText(e.lines,this.width),i=new Array(s.length);for(let n=0;n<s.length;n++)i[n]=s[n].join("");return e.lines=i,e.graphemeLines=s,e}getMinWidth(){return Math.max(this.minWidth,this.dynamicMinWidth)}_removeExtraneousStyles(){const t=new Map;for(const e in this._styleMap){const s=parseInt(e,10);if(this._textLines[s]){const i=this._styleMap[e].line;t.set("".concat(i),!0)}}for(const e in this.styles)t.has(e)||delete this.styles[e]}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject(["minWidth","splitByGrapheme",...t])}}T(Ar,"type","Textbox"),T(Ar,"textLayoutProperties",[...Gi.textLayoutProperties,"width"]),T(Ar,"ownDefaults",{minWidth:20,dynamicMinWidth:2,lockScalingFlip:!0,noScaleCache:!1,_wordJoiners:/[ \t\r]/,splitByGrapheme:!1}),N.setClass(Ar);class F0 extends uu{shouldPerformLayout(t){return!!t.target.clipPath&&super.shouldPerformLayout(t)}shouldLayoutClipPath(){return!1}calcLayoutResult(t,e){const{target:s}=t,{clipPath:i,group:n}=s;if(!i||!this.shouldPerformLayout(t))return;const{width:r,height:o}=ri(r0(s,i)),h=new P(r,o);if(i.absolutePositioned)return{center:_r(i.getRelativeCenterPoint(),void 0,n?n.calcTransformMatrix():void 0),size:h};{const c=i.getRelativeCenterPoint().transform(s.calcOwnMatrix(),!0);if(this.shouldPerformLayout(t)){const{center:u=new P,correction:d=new P}=this.calcBoundingBox(e,t)||{};return{center:u.add(c),correction:d.subtract(c),size:h}}return{center:s.getRelativeCenterPoint().add(c),size:h}}}}T(F0,"type","clip-path"),N.setClass(F0);class I0 extends uu{getInitialSize(t,e){let{target:s}=t,{size:i}=e;return new P(s.width||i.x,s.height||i.y)}}T(I0,"type","fixed"),N.setClass(I0);class Tw extends Lh{subscribeTargets(t){const e=t.target;t.targets.reduce((s,i)=>(i.parent&&s.add(i.parent),s),new Set).forEach(s=>{s.layoutManager.subscribeTargets({target:s,targets:[e]})})}unsubscribeTargets(t){const e=t.target,s=e.getObjects();t.targets.reduce((i,n)=>(n.parent&&i.add(n.parent),i),new Set).forEach(i=>{!s.some(n=>n.parent===i)&&i.layoutManager.unsubscribeTargets({target:i,targets:[e]})})}}class Tr extends ai{static getDefaults(){return E(E({},super.getDefaults()),Tr.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),Object.assign(this,Tr.ownDefaults),this.setOptions(e);const{left:s,top:i,layoutManager:n}=e;this.groupInit(t,{left:s,top:i,layoutManager:n??new Tw})}_shouldSetNestedCoords(){return!0}__objectSelectionMonitor(){}multiSelectAdd(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];this.multiSelectionStacking==="selection-order"?this.add(...e):e.forEach(i=>{const n=this._objects.findIndex(o=>o.isInFrontOf(i)),r=n===-1?this.size():n;this.insertAt(r,i)})}canEnterGroup(t){return this.getObjects().some(e=>e.isDescendantOf(t)||t.isDescendantOf(e))?(Oi("error","ActiveSelection: circular object trees are not supported, this call has no effect"),!1):super.canEnterGroup(t)}enterGroup(t,e){t.parent&&t.parent===t.group?t.parent._exitGroup(t):t.group&&t.parent!==t.group&&t.group.remove(t),this._enterGroup(t,e)}exitGroup(t,e){this._exitGroup(t,e),t.parent&&t.parent._enterGroup(t,!0)}_onAfterObjectsChange(t,e){super._onAfterObjectsChange(t,e);const s=new Set;e.forEach(i=>{const{parent:n}=i;n&&s.add(n)}),t===Hf?s.forEach(i=>{i._onAfterObjectsChange(lu,e)}):s.forEach(i=>{i._set("dirty",!0)})}onDeselect(){return this.removeAll(),!1}toString(){return"#<ActiveSelection: (".concat(this.complexity(),")>")}shouldCache(){return!1}isOnACache(){return!1}_renderControls(t,e,s){t.save(),t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1;const i=E(E({hasControls:!1},s),{},{forActiveSelection:!0});for(let n=0;n<this._objects.length;n++)this._objects[n]._renderControls(t,i);super._renderControls(t,e),t.restore()}}T(Tr,"type","ActiveSelection"),T(Tr,"ownDefaults",{multiSelectionStacking:"canvas-stacking"}),N.setClass(Tr),N.setClass(Tr,"activeSelection");class Ew{constructor(){T(this,"resources",{})}applyFilters(t,e,s,i,n){const r=n.getContext("2d");if(!r)return;r.drawImage(e,0,0,s,i);const o={sourceWidth:s,sourceHeight:i,imageData:r.getImageData(0,0,s,i),originalEl:e,originalImageData:r.getImageData(0,0,s,i),canvasEl:n,ctx:r,filterBackend:this};t.forEach(c=>{c.applyTo(o)});const{imageData:h}=o;return h.width===s&&h.height===i||(n.width=h.width,n.height=h.height),r.putImageData(h,0,0),o}}class N0{constructor(){let{tileSize:t=ht.textureSize}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};T(this,"aPosition",new Float32Array([0,0,0,1,1,0,1,1])),T(this,"resources",{}),this.tileSize=t,this.setupGLContext(t,t),this.captureGPUInfo()}setupGLContext(t,e){this.dispose(),this.createWebGLCanvas(t,e)}createWebGLCanvas(t,e){const s=Rs({width:t,height:e}),i=s.getContext("webgl",{alpha:!0,premultipliedAlpha:!1,depth:!1,stencil:!1,antialias:!1});i&&(i.clearColor(0,0,0,0),this.canvas=s,this.gl=i)}applyFilters(t,e,s,i,n,r){const o=this.gl,h=n.getContext("2d");if(!o||!h)return;let c;r&&(c=this.getCachedTexture(r,e));const u={originalWidth:e.width||e.naturalWidth||0,originalHeight:e.height||e.naturalHeight||0,sourceWidth:s,sourceHeight:i,destinationWidth:s,destinationHeight:i,context:o,sourceTexture:this.createTexture(o,s,i,c?void 0:e),targetTexture:this.createTexture(o,s,i),originalTexture:c||this.createTexture(o,s,i,c?void 0:e),passes:t.length,webgl:!0,aPosition:this.aPosition,programCache:this.programCache,pass:0,filterBackend:this,targetCanvas:n},d=o.createFramebuffer();return o.bindFramebuffer(o.FRAMEBUFFER,d),t.forEach(f=>{f&&f.applyTo(u)}),function(f){const g=f.targetCanvas,p=g.width,b=g.height,v=f.destinationWidth,_=f.destinationHeight;p===v&&b===_||(g.width=v,g.height=_)}(u),this.copyGLTo2D(o,u),o.bindTexture(o.TEXTURE_2D,null),o.deleteTexture(u.sourceTexture),o.deleteTexture(u.targetTexture),o.deleteFramebuffer(d),h.setTransform(1,0,0,1,0,0),u}dispose(){this.canvas&&(this.canvas=null,this.gl=null),this.clearWebGLCaches()}clearWebGLCaches(){this.programCache={},this.textureCache={}}createTexture(t,e,s,i,n){const{NEAREST:r,TEXTURE_2D:o,RGBA:h,UNSIGNED_BYTE:c,CLAMP_TO_EDGE:u,TEXTURE_MAG_FILTER:d,TEXTURE_MIN_FILTER:f,TEXTURE_WRAP_S:g,TEXTURE_WRAP_T:p}=t,b=t.createTexture();return t.bindTexture(o,b),t.texParameteri(o,d,n||r),t.texParameteri(o,f,n||r),t.texParameteri(o,g,u),t.texParameteri(o,p,u),i?t.texImage2D(o,0,h,h,c,i):t.texImage2D(o,0,h,e,s,0,h,c,null),b}getCachedTexture(t,e,s){const{textureCache:i}=this;if(i[t])return i[t];{const n=this.createTexture(this.gl,e.width,e.height,e,s);return n&&(i[t]=n),n}}evictCachesForKey(t){this.textureCache[t]&&(this.gl.deleteTexture(this.textureCache[t]),delete this.textureCache[t])}copyGLTo2D(t,e){const s=t.canvas,i=e.targetCanvas,n=i.getContext("2d");if(!n)return;n.translate(0,i.height),n.scale(1,-1);const r=s.height-i.height;n.drawImage(s,0,r,i.width,i.height,0,0,i.width,i.height)}copyGLTo2DPutImageData(t,e){const s=e.targetCanvas.getContext("2d"),i=e.destinationWidth,n=e.destinationHeight,r=i*n*4;if(!s)return;const o=new Uint8Array(this.imageBuffer,0,r),h=new Uint8ClampedArray(this.imageBuffer,0,r);t.readPixels(0,0,i,n,t.RGBA,t.UNSIGNED_BYTE,o);const c=new ImageData(h,i,n);s.putImageData(c,0,0)}captureGPUInfo(){if(this.gpuInfo)return this.gpuInfo;const t=this.gl,e={renderer:"",vendor:""};if(!t)return e;const s=t.getExtension("WEBGL_debug_renderer_info");if(s){const i=t.getParameter(s.UNMASKED_RENDERER_WEBGL),n=t.getParameter(s.UNMASKED_VENDOR_WEBGL);i&&(e.renderer=i.toLowerCase()),n&&(e.vendor=n.toLowerCase())}return this.gpuInfo=e,e}}let Qf;function kw(){const{WebGLProbe:a}=ni();return a.queryWebGL(ms()),ht.enableGLFiltering&&a.isSupported(ht.textureSize)?new N0({tileSize:ht.textureSize}):new Ew}function Jf(){return!Qf&&(!(arguments.length>0&&arguments[0]!==void 0)||arguments[0])&&(Qf=kw()),Qf}const Mw=["filters","resizeFilter","src","crossOrigin","type"],j0=["cropX","cropY"];class be extends pe{static getDefaults(){return E(E({},super.getDefaults()),be.ownDefaults)}constructor(t,e){super(),T(this,"_lastScaleX",1),T(this,"_lastScaleY",1),T(this,"_filterScalingX",1),T(this,"_filterScalingY",1),this.filters=[],Object.assign(this,be.ownDefaults),this.setOptions(e),this.cacheKey="texture".concat(En()),this.setElement(typeof t=="string"?(this.canvas&&Ls(this.canvas.getElement())||Vo()).getElementById(t):t,e)}getElement(){return this._element}setElement(t){var e;let s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.removeTexture(this.cacheKey),this.removeTexture("".concat(this.cacheKey,"_filtered")),this._element=t,this._originalElement=t,this._setWidthHeight(s),(e=t.classList)===null||e===void 0||e.add(be.CSS_CANVAS),this.filters.length!==0&&this.applyFilters(),this.resizeFilter&&this.applyResizeFilters()}removeTexture(t){const e=Jf(!1);e instanceof N0&&e.evictCachesForKey(t)}dispose(){super.dispose(),this.removeTexture(this.cacheKey),this.removeTexture("".concat(this.cacheKey,"_filtered")),this._cacheContext=null,["_originalElement","_element","_filteredEl","_cacheCanvas"].forEach(t=>{const e=this[t];e&&ni().dispose(e),this[t]=void 0})}getCrossOrigin(){return this._originalElement&&(this._originalElement.crossOrigin||null)}getOriginalSize(){const t=this.getElement();return t?{width:t.naturalWidth||t.width,height:t.naturalHeight||t.height}:{width:0,height:0}}_stroke(t){if(!this.stroke||this.strokeWidth===0)return;const e=this.width/2,s=this.height/2;t.beginPath(),t.moveTo(-e,-s),t.lineTo(e,-s),t.lineTo(e,s),t.lineTo(-e,s),t.lineTo(-e,-s),t.closePath()}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];const e=[];return this.filters.forEach(s=>{s&&e.push(s.toObject())}),E(E({},super.toObject([...j0,...t])),{},{src:this.getSrc(),crossOrigin:this.getCrossOrigin(),filters:e},this.resizeFilter?{resizeFilter:this.resizeFilter.toObject()}:{})}hasCrop(){return!!this.cropX||!!this.cropY||this.width<this._element.width||this.height<this._element.height}_toSVG(){const t=[],e=this._element,s=-this.width/2,i=-this.height/2;let n=[],r=[],o="",h="";if(!e)return[];if(this.hasCrop()){const c=En();n.push('<clipPath id="imageCrop_'+c+`">
58
58
  `,' <rect x="'+s+'" y="'+i+'" width="'+this.width+'" height="'+this.height+`" />
59
59
  `,`</clipPath>
60
60
  `),o=' clip-path="url(#imageCrop_'+c+')" '}if(this.imageSmoothing||(h=' image-rendering="optimizeSpeed"'),t.push(" <image ","COMMON_PARTS",'xlink:href="'.concat(this.getSvgSrc(!0),'" x="').concat(s-this.cropX,'" y="').concat(i-this.cropY,'" width="').concat(e.width||e.naturalWidth,'" height="').concat(e.height||e.naturalHeight,'"').concat(h).concat(o,`></image>
61
61
  `)),this.stroke||this.strokeDashArray){const c=this.fill;this.fill=null,r=[' <rect x="'.concat(s,'" y="').concat(i,'" width="').concat(this.width,'" height="').concat(this.height,'" style="').concat(this.getSvgStyles(),`" />
62
- `)],this.fill=c}return n=this.paintFirst!==zt?n.concat(r,t):n.concat(t,r),n}getSrc(t){const e=t?this._element:this._originalElement;return e?e.toDataURL?e.toDataURL():this.srcFromAttribute?e.getAttribute("src")||"":e.src:this.src||""}getSvgSrc(t){return this.getSrc(t)}setSrc(t){let{crossOrigin:e,signal:s}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return Th(t,{crossOrigin:e,signal:s}).then(i=>{e!==void 0&&this.set({crossOrigin:e}),this.setElement(i)})}toString(){return'#<Image: { src: "'.concat(this.getSrc(),'" }>')}applyResizeFilters(){const t=this.resizeFilter,e=this.minimumScaleTrigger,s=this.getTotalObjectScaling(),i=s.x,n=s.y,r=this._filteredEl||this._originalElement;if(this.group&&this.set("dirty",!0),!t||i>e&&n>e)return this._element=r,this._filterScalingX=1,this._filterScalingY=1,this._lastScaleX=i,void(this._lastScaleY=n);const o=Rs(r),{width:h,height:c}=r;this._element=o,this._lastScaleX=t.scaleX=i,this._lastScaleY=t.scaleY=n,Jf().applyFilters([t],r,h,c,this._element),this._filterScalingX=o.width/this._originalElement.width,this._filterScalingY=o.height/this._originalElement.height}applyFilters(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.filters||[];if(t=t.filter(n=>n&&!n.isNeutralState()),this.set("dirty",!0),this.removeTexture("".concat(this.cacheKey,"_filtered")),t.length===0)return this._element=this._originalElement,this._filteredEl=void 0,this._filterScalingX=1,void(this._filterScalingY=1);const e=this._originalElement,s=e.naturalWidth||e.width,i=e.naturalHeight||e.height;if(this._element===this._originalElement){const n=Rs({width:s,height:i});this._element=n,this._filteredEl=n}else this._filteredEl&&(this._element=this._filteredEl,this._filteredEl.getContext("2d").clearRect(0,0,s,i),this._lastScaleX=1,this._lastScaleY=1);Jf().applyFilters(t,this._originalElement,s,i,this._element,this.cacheKey),this._originalElement.width===this._element.width&&this._originalElement.height===this._element.height||(this._filterScalingX=this._element.width/this._originalElement.width,this._filterScalingY=this._element.height/this._originalElement.height)}_render(t){t.imageSmoothingEnabled=this.imageSmoothing,this.isMoving!==!0&&this.resizeFilter&&this._needsResize()&&this.applyResizeFilters(),this._stroke(t),this._renderPaintInOrder(t)}drawCacheOnCanvas(t){t.imageSmoothingEnabled=this.imageSmoothing,super.drawCacheOnCanvas(t)}shouldCache(){return this.needsItsOwnCache()}_renderFill(t){const e=this._element;if(!e)return;const s=this._filterScalingX,i=this._filterScalingY,n=this.width,r=this.height,o=Math.max(this.cropX,0),h=Math.max(this.cropY,0),c=e.naturalWidth||e.width,u=e.naturalHeight||e.height,d=o*s,f=h*i,g=Math.min(n*s,c-d),p=Math.min(r*i,u-f),b=-n/2,v=-r/2,_=Math.min(n,c/s-o),x=Math.min(r,u/i-h);e&&t.drawImage(e,d,f,g,p,b,v,_,x)}_needsResize(){const t=this.getTotalObjectScaling();return t.x!==this._lastScaleX||t.y!==this._lastScaleY}_resetWidthHeight(){this.set(this.getOriginalSize())}_setWidthHeight(){let{width:t,height:e}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const s=this.getOriginalSize();this.width=t||s.width,this.height=e||s.height}parsePreserveAspectRatioAttribute(){const t=yf(this.preserveAspectRatio||""),e=this.width,s=this.height,i={width:e,height:s};let n,r=this._element.width,o=this._element.height,h=1,c=1,u=0,d=0,f=0,g=0;return!t||t.alignX===ke&&t.alignY===ke?(h=e/r,c=s/o):(t.meetOrSlice==="meet"&&(h=c=a0(this._element,i),n=(e-r*h)/2,t.alignX==="Min"&&(u=-n),t.alignX==="Max"&&(u=n),n=(s-o*c)/2,t.alignY==="Min"&&(d=-n),t.alignY==="Max"&&(d=n)),t.meetOrSlice==="slice"&&(h=c=h0(this._element,i),n=r-e/h,t.alignX==="Mid"&&(f=n/2),t.alignX==="Max"&&(f=n),n=o-s/c,t.alignY==="Mid"&&(g=n/2),t.alignY==="Max"&&(g=n),r=e/h,o=s/c)),{width:r,height:o,scaleX:h,scaleY:c,offsetLeft:u,offsetTop:d,cropX:f,cropY:g}}static fromObject(t,e){let{filters:s,resizeFilter:i,src:n,crossOrigin:r,type:o}=t,h=Ct(t,Mw);return Promise.all([Th(n,E(E({},e),{},{crossOrigin:r})),s&&qo(s,e),i&&qo([i],e),Eh(h,e)]).then(c=>{let[u,d=[],[f]=[],g={}]=c;return new this(u,E(E({},h),{},{src:n,filters:d,resizeFilter:f},g))})}static fromURL(t){let{crossOrigin:e=null,signal:s}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;return Th(t,{crossOrigin:e,signal:s}).then(n=>new this(n,i))}static async fromElement(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0;const i=Ni(t,this.ATTRIBUTE_NAMES,s);return this.fromURL(i["xlink:href"],e,i).catch(n=>(Oi("log","Unable to parse Image",n),null))}}function Zf(a){if(!Lv.test(a.nodeName))return{};const t=a.getAttribute("viewBox");let e,s,i=1,n=1,r=0,o=0;const h=a.getAttribute("width"),c=a.getAttribute("height"),u=a.getAttribute("x")||0,d=a.getAttribute("y")||0,f=!(t&&Am.test(t)),g=!h||!c||h==="100%"||c==="100%";let p="",b=0,v=0;if(f&&(u||d)&&a.parentNode&&a.parentNode.nodeName!=="#document"&&(p=" translate("+De(u||"0")+" "+De(d||"0")+") ",e=(a.getAttribute("transform")||"")+p,a.setAttribute("transform",e),a.removeAttribute("x"),a.removeAttribute("y")),f&&g)return{width:0,height:0};const _={width:0,height:0};if(f)return _.width=De(h),_.height=De(c),_;const x=t.match(Am);r=-parseFloat(x[1]),o=-parseFloat(x[2]);const C=parseFloat(x[3]),S=parseFloat(x[4]);_.minX=r,_.minY=o,_.viewBoxWidth=C,_.viewBoxHeight=S,g?(_.width=C,_.height=S):(_.width=De(h),_.height=De(c),i=_.width/C,n=_.height/S);const k=yf(a.getAttribute("preserveAspectRatio")||"");if(k.alignX!==ke&&(k.meetOrSlice==="meet"&&(n=i=i>n?n:i),k.meetOrSlice==="slice"&&(n=i=i>n?i:n),b=_.width-C*i,v=_.height-S*i,k.alignX==="Mid"&&(b/=2),k.alignY==="Mid"&&(v/=2),k.alignX==="Min"&&(b=0),k.alignY==="Min"&&(v=0)),i===1&&n===1&&r===0&&o===0&&u===0&&d===0)return _;if((u||d)&&a.parentNode.nodeName!=="#document"&&(p=" translate("+De(u||"0")+" "+De(d||"0")+") "),e=p+" matrix("+i+" 0 0 "+n+" "+(r*i+b)+" "+(o*n+v)+") ",a.nodeName==="svg"){for(s=a.ownerDocument.createElementNS(Cf,"g");a.firstChild;)s.appendChild(a.firstChild);a.appendChild(s)}else s=a,s.removeAttribute("x"),s.removeAttribute("y"),e=s.getAttribute("transform")+e;return s.setAttribute("transform",e),_}A(be,"type","Image"),A(be,"cacheProperties",[...Fi,...j0]),A(be,"ownDefaults",{strokeWidth:0,srcFromAttribute:!1,minimumScaleTrigger:.5,cropX:0,cropY:0,imageSmoothing:!0}),A(be,"CSS_CANVAS","canvas-img"),A(be,"ATTRIBUTE_NAMES",[...Mn,"x","y","width","height","preserveAspectRatio","xlink:href","crossOrigin","image-rendering"]),N.setClass(be),N.setSVGClass(be);const Su=a=>a.tagName.replace("svg:",""),Pw=Jc(["pattern","defs","symbol","metadata","clipPath","mask","desc"]);function B0(a,t){let e,s,i,n,r=[];for(i=0,n=t.length;i<n;i++)e=t[i],s=a.getElementsByTagNameNS("http://www.w3.org/2000/svg",e),r=r.concat(Array.from(s));return r}const Dw=["gradientTransform","x1","x2","y1","y2","gradientUnits","cx","cy","r","fx","fy"],tg="xlink:href";function H0(a,t){var e;const s=((e=t.getAttribute(tg))===null||e===void 0?void 0:e.slice(1))||"",i=a.getElementById(s);if(i&&i.getAttribute(tg)&&H0(a,i),i&&(Dw.forEach(n=>{const r=i.getAttribute(n);!t.hasAttribute(n)&&r&&t.setAttribute(n,r)}),!t.children.length)){const n=i.cloneNode(!0);for(;n.firstChild;)t.appendChild(n.firstChild)}t.removeAttribute(tg)}const Ow=["linearGradient","radialGradient","svg:linearGradient","svg:radialGradient"];function Rw(a){const t=a.getElementsByTagName("style");let e,s;const i={};for(e=0,s=t.length;e<s;e++){const n=(t[e].textContent||"").replace(/\/\*[\s\S]*?\*\//g,"");n.trim()!==""&&n.split("}").filter((r,o,h)=>h.length>1&&r.trim()).forEach(r=>{if((r.match(/{/g)||[]).length>1&&r.trim().startsWith("@"))return;const o=r.split("{"),h={},c=o[1].trim().split(";").filter(function(u){return u.trim()});for(e=0,s=c.length;e<s;e++){const u=c[e].split(":"),d=u[0].trim(),f=u[1].trim();h[d]=f}(r=o[0].trim()).split(",").forEach(u=>{(u=u.replace(/^svg/i,"").trim())!==""&&(i[u]=E(E({},i[u]||{}),h))})})}return i}const G0=a=>N.getSVGClass(Su(a).toLowerCase());class Lw{constructor(t,e,s,i,n){this.elements=t,this.options=e,this.reviver=s,this.regexUrl=/^url\(['"]?#([^'"]+)['"]?\)/g,this.doc=i,this.clipPaths=n,this.gradientDefs=function(r){const o=B0(r,Ow),h={};let c=o.length;for(;c--;){const u=o[c];u.getAttribute("xlink:href")&&H0(r,u);const d=u.getAttribute("id");d&&(h[d]=u)}return h}(i),this.cssRules=Rw(i)}parse(){return Promise.all(this.elements.map(t=>this.createObject(t)))}async createObject(t){const e=G0(t);if(e){const s=await e.fromElement(t,this.options,this.cssRules);return this.resolveGradient(s,t,zt),this.resolveGradient(s,t,Pe),s instanceof be&&s._originalElement?gu(s,s.parsePreserveAspectRatioAttribute()):gu(s),await this.resolveClipPath(s,t),this.reviver&&this.reviver(t,s),s}return null}extractPropertyDefinition(t,e,s){const i=t[e],n=this.regexUrl;if(!n.test(i))return;n.lastIndex=0;const r=n.exec(i)[1];return n.lastIndex=0,s[r]}resolveGradient(t,e,s){const i=this.extractPropertyDefinition(t,s,this.gradientDefs);if(i){const n=e.getAttribute(s+"-opacity"),r=Ih.fromElement(i,t,E(E({},this.options),{},{opacity:n}));t.set(s,r)}}async resolveClipPath(t,e,s){const i=this.extractPropertyDefinition(t,"clipPath",this.clipPaths);if(i){const n=Xe(t.calcTransformMatrix()),r=i[0].parentElement;let o=e;for(;!s&&o.parentElement&&o.getAttribute("clip-path")!==t.clipPath;)o=o.parentElement;o.parentElement.appendChild(r);const h=hu("".concat(o.getAttribute("transform")||""," ").concat(r.getAttribute("originalTransform")||""));r.setAttribute("transform","matrix(".concat(h.join(","),")"));const c=await Promise.all(i.map(x=>G0(x).fromElement(x,this.options,this.cssRules).then(C=>(gu(C),C.fillRule=C.clipRule,delete C.clipRule,C)))),u=c.length===1?c[0]:new ai(c),d=Nt(n,u.calcTransformMatrix());u.clipPath&&await this.resolveClipPath(u,o,r.getAttribute("clip-path")?o:void 0);const{scaleX:f,scaleY:g,angle:p,skewX:b,translateX:v,translateY:_}=br(d);u.set({flipX:!1,flipY:!1}),u.set({scaleX:f,scaleY:g,angle:p,skewX:b,skewY:0}),u.setPositionByOrigin(new P(v,_),Q,Q),t.clipPath=u}else delete t.clipPath}}const z0=a=>Rv.test(Su(a)),eg=()=>({objects:[],elements:[],options:{},allElements:[]});async function Fw(a,t){let{crossOrigin:e,signal:s}=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(s&&s.aborted)return Oi("log",new sf("parseSVGDocument")),eg();const i=a.documentElement;(function(u){const d=B0(u,["use","svg:use"]),f=["x","y","xlink:href","href","transform"];for(const g of d){const p=g.attributes,b={};for(const O of p)O.value&&(b[O.name]=O.value);const v=(b["xlink:href"]||b.href||"").slice(1);if(v==="")return;const _=u.getElementById(v);if(_===null)return;let x=_.cloneNode(!0);const C=x.attributes,S={};for(const O of C)O.value&&(S[O.name]=O.value);const{x:k=0,y:D=0,transform:T=""}=b,M="".concat(T," ").concat(S.transform||""," translate(").concat(k,", ").concat(D,")");if(Zf(x),/^svg$/i.test(x.nodeName)){const O=x.ownerDocument.createElementNS(Cf,"g");Object.entries(S).forEach(R=>{let[L,W]=R;return O.setAttributeNS(Cf,L,W)}),O.append(...x.childNodes),x=O}for(const O of p){if(!O)continue;const{name:R,value:L}=O;if(!f.includes(R))if(R==="style"){const W={};Bf(L,W),Object.entries(S).forEach(G=>{let[at,F]=G;W[at]=F}),Bf(S.style||"",W);const U=Object.entries(W).map(G=>G.join(":")).join(";");x.setAttribute(R,U)}else!S[R]&&x.setAttribute(R,L)}x.setAttribute("transform",M),x.setAttribute("instantiated_by_use","1"),x.removeAttribute("id"),g.parentNode.replaceChild(x,g)}})(a);const n=Array.from(i.getElementsByTagName("*")),r=E(E({},Zf(i)),{},{crossOrigin:e,signal:s}),o=n.filter(u=>(Zf(u),z0(u)&&!function(d){let f=d;for(;f&&(f=f.parentElement);)if(f&&f.nodeName&&Pw.test(Su(f))&&!f.getAttribute("instantiated_by_use"))return!0;return!1}(u)));if(!o||o&&!o.length)return E(E({},eg()),{},{options:r,allElements:n});const h={};return n.filter(u=>Su(u)==="clipPath").forEach(u=>{u.setAttribute("originalTransform",u.getAttribute("transform")||"");const d=u.getAttribute("id");h[d]=Array.from(u.getElementsByTagName("*")).filter(f=>z0(f))}),{objects:await new Lw(o,r,t,a,h).parse(),elements:o,options:r,allElements:n}}function Iw(a,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return new Promise((s,i)=>{_0(a.replace(/^\n\s*/,"").trim(),{onComplete:n=>{const r=n.responseXML;r&&s(r),i()},signal:e.signal})}).then(s=>Fw(s,t,e)).catch(()=>eg())}const Cu=a=>a.webgl!==void 0,sg="precision highp float",Nw=`
62
+ `)],this.fill=c}return n=this.paintFirst!==zt?n.concat(r,t):n.concat(t,r),n}getSrc(t){const e=t?this._element:this._originalElement;return e?e.toDataURL?e.toDataURL():this.srcFromAttribute?e.getAttribute("src")||"":e.src:this.src||""}getSvgSrc(t){return this.getSrc(t)}setSrc(t){let{crossOrigin:e,signal:s}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return Th(t,{crossOrigin:e,signal:s}).then(i=>{e!==void 0&&this.set({crossOrigin:e}),this.setElement(i)})}toString(){return'#<Image: { src: "'.concat(this.getSrc(),'" }>')}applyResizeFilters(){const t=this.resizeFilter,e=this.minimumScaleTrigger,s=this.getTotalObjectScaling(),i=s.x,n=s.y,r=this._filteredEl||this._originalElement;if(this.group&&this.set("dirty",!0),!t||i>e&&n>e)return this._element=r,this._filterScalingX=1,this._filterScalingY=1,this._lastScaleX=i,void(this._lastScaleY=n);const o=Rs(r),{width:h,height:c}=r;this._element=o,this._lastScaleX=t.scaleX=i,this._lastScaleY=t.scaleY=n,Jf().applyFilters([t],r,h,c,this._element),this._filterScalingX=o.width/this._originalElement.width,this._filterScalingY=o.height/this._originalElement.height}applyFilters(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.filters||[];if(t=t.filter(n=>n&&!n.isNeutralState()),this.set("dirty",!0),this.removeTexture("".concat(this.cacheKey,"_filtered")),t.length===0)return this._element=this._originalElement,this._filteredEl=void 0,this._filterScalingX=1,void(this._filterScalingY=1);const e=this._originalElement,s=e.naturalWidth||e.width,i=e.naturalHeight||e.height;if(this._element===this._originalElement){const n=Rs({width:s,height:i});this._element=n,this._filteredEl=n}else this._filteredEl&&(this._element=this._filteredEl,this._filteredEl.getContext("2d").clearRect(0,0,s,i),this._lastScaleX=1,this._lastScaleY=1);Jf().applyFilters(t,this._originalElement,s,i,this._element,this.cacheKey),this._originalElement.width===this._element.width&&this._originalElement.height===this._element.height||(this._filterScalingX=this._element.width/this._originalElement.width,this._filterScalingY=this._element.height/this._originalElement.height)}_render(t){t.imageSmoothingEnabled=this.imageSmoothing,this.isMoving!==!0&&this.resizeFilter&&this._needsResize()&&this.applyResizeFilters(),this._stroke(t),this._renderPaintInOrder(t)}drawCacheOnCanvas(t){t.imageSmoothingEnabled=this.imageSmoothing,super.drawCacheOnCanvas(t)}shouldCache(){return this.needsItsOwnCache()}_renderFill(t){const e=this._element;if(!e)return;const s=this._filterScalingX,i=this._filterScalingY,n=this.width,r=this.height,o=Math.max(this.cropX,0),h=Math.max(this.cropY,0),c=e.naturalWidth||e.width,u=e.naturalHeight||e.height,d=o*s,f=h*i,g=Math.min(n*s,c-d),p=Math.min(r*i,u-f),b=-n/2,v=-r/2,_=Math.min(n,c/s-o),x=Math.min(r,u/i-h);e&&t.drawImage(e,d,f,g,p,b,v,_,x)}_needsResize(){const t=this.getTotalObjectScaling();return t.x!==this._lastScaleX||t.y!==this._lastScaleY}_resetWidthHeight(){this.set(this.getOriginalSize())}_setWidthHeight(){let{width:t,height:e}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const s=this.getOriginalSize();this.width=t||s.width,this.height=e||s.height}parsePreserveAspectRatioAttribute(){const t=yf(this.preserveAspectRatio||""),e=this.width,s=this.height,i={width:e,height:s};let n,r=this._element.width,o=this._element.height,h=1,c=1,u=0,d=0,f=0,g=0;return!t||t.alignX===ke&&t.alignY===ke?(h=e/r,c=s/o):(t.meetOrSlice==="meet"&&(h=c=a0(this._element,i),n=(e-r*h)/2,t.alignX==="Min"&&(u=-n),t.alignX==="Max"&&(u=n),n=(s-o*c)/2,t.alignY==="Min"&&(d=-n),t.alignY==="Max"&&(d=n)),t.meetOrSlice==="slice"&&(h=c=h0(this._element,i),n=r-e/h,t.alignX==="Mid"&&(f=n/2),t.alignX==="Max"&&(f=n),n=o-s/c,t.alignY==="Mid"&&(g=n/2),t.alignY==="Max"&&(g=n),r=e/h,o=s/c)),{width:r,height:o,scaleX:h,scaleY:c,offsetLeft:u,offsetTop:d,cropX:f,cropY:g}}static fromObject(t,e){let{filters:s,resizeFilter:i,src:n,crossOrigin:r,type:o}=t,h=Ct(t,Mw);return Promise.all([Th(n,E(E({},e),{},{crossOrigin:r})),s&&qo(s,e),i&&qo([i],e),Eh(h,e)]).then(c=>{let[u,d=[],[f]=[],g={}]=c;return new this(u,E(E({},h),{},{src:n,filters:d,resizeFilter:f},g))})}static fromURL(t){let{crossOrigin:e=null,signal:s}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;return Th(t,{crossOrigin:e,signal:s}).then(n=>new this(n,i))}static async fromElement(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0;const i=Ni(t,this.ATTRIBUTE_NAMES,s);return this.fromURL(i["xlink:href"],e,i).catch(n=>(Oi("log","Unable to parse Image",n),null))}}function Zf(a){if(!Lv.test(a.nodeName))return{};const t=a.getAttribute("viewBox");let e,s,i=1,n=1,r=0,o=0;const h=a.getAttribute("width"),c=a.getAttribute("height"),u=a.getAttribute("x")||0,d=a.getAttribute("y")||0,f=!(t&&Am.test(t)),g=!h||!c||h==="100%"||c==="100%";let p="",b=0,v=0;if(f&&(u||d)&&a.parentNode&&a.parentNode.nodeName!=="#document"&&(p=" translate("+De(u||"0")+" "+De(d||"0")+") ",e=(a.getAttribute("transform")||"")+p,a.setAttribute("transform",e),a.removeAttribute("x"),a.removeAttribute("y")),f&&g)return{width:0,height:0};const _={width:0,height:0};if(f)return _.width=De(h),_.height=De(c),_;const x=t.match(Am);r=-parseFloat(x[1]),o=-parseFloat(x[2]);const C=parseFloat(x[3]),S=parseFloat(x[4]);_.minX=r,_.minY=o,_.viewBoxWidth=C,_.viewBoxHeight=S,g?(_.width=C,_.height=S):(_.width=De(h),_.height=De(c),i=_.width/C,n=_.height/S);const k=yf(a.getAttribute("preserveAspectRatio")||"");if(k.alignX!==ke&&(k.meetOrSlice==="meet"&&(n=i=i>n?n:i),k.meetOrSlice==="slice"&&(n=i=i>n?i:n),b=_.width-C*i,v=_.height-S*i,k.alignX==="Mid"&&(b/=2),k.alignY==="Mid"&&(v/=2),k.alignX==="Min"&&(b=0),k.alignY==="Min"&&(v=0)),i===1&&n===1&&r===0&&o===0&&u===0&&d===0)return _;if((u||d)&&a.parentNode.nodeName!=="#document"&&(p=" translate("+De(u||"0")+" "+De(d||"0")+") "),e=p+" matrix("+i+" 0 0 "+n+" "+(r*i+b)+" "+(o*n+v)+") ",a.nodeName==="svg"){for(s=a.ownerDocument.createElementNS(Cf,"g");a.firstChild;)s.appendChild(a.firstChild);a.appendChild(s)}else s=a,s.removeAttribute("x"),s.removeAttribute("y"),e=s.getAttribute("transform")+e;return s.setAttribute("transform",e),_}T(be,"type","Image"),T(be,"cacheProperties",[...Fi,...j0]),T(be,"ownDefaults",{strokeWidth:0,srcFromAttribute:!1,minimumScaleTrigger:.5,cropX:0,cropY:0,imageSmoothing:!0}),T(be,"CSS_CANVAS","canvas-img"),T(be,"ATTRIBUTE_NAMES",[...Mn,"x","y","width","height","preserveAspectRatio","xlink:href","crossOrigin","image-rendering"]),N.setClass(be),N.setSVGClass(be);const Su=a=>a.tagName.replace("svg:",""),Pw=Jc(["pattern","defs","symbol","metadata","clipPath","mask","desc"]);function B0(a,t){let e,s,i,n,r=[];for(i=0,n=t.length;i<n;i++)e=t[i],s=a.getElementsByTagNameNS("http://www.w3.org/2000/svg",e),r=r.concat(Array.from(s));return r}const Dw=["gradientTransform","x1","x2","y1","y2","gradientUnits","cx","cy","r","fx","fy"],tg="xlink:href";function H0(a,t){var e;const s=((e=t.getAttribute(tg))===null||e===void 0?void 0:e.slice(1))||"",i=a.getElementById(s);if(i&&i.getAttribute(tg)&&H0(a,i),i&&(Dw.forEach(n=>{const r=i.getAttribute(n);!t.hasAttribute(n)&&r&&t.setAttribute(n,r)}),!t.children.length)){const n=i.cloneNode(!0);for(;n.firstChild;)t.appendChild(n.firstChild)}t.removeAttribute(tg)}const Ow=["linearGradient","radialGradient","svg:linearGradient","svg:radialGradient"];function Rw(a){const t=a.getElementsByTagName("style");let e,s;const i={};for(e=0,s=t.length;e<s;e++){const n=(t[e].textContent||"").replace(/\/\*[\s\S]*?\*\//g,"");n.trim()!==""&&n.split("}").filter((r,o,h)=>h.length>1&&r.trim()).forEach(r=>{if((r.match(/{/g)||[]).length>1&&r.trim().startsWith("@"))return;const o=r.split("{"),h={},c=o[1].trim().split(";").filter(function(u){return u.trim()});for(e=0,s=c.length;e<s;e++){const u=c[e].split(":"),d=u[0].trim(),f=u[1].trim();h[d]=f}(r=o[0].trim()).split(",").forEach(u=>{(u=u.replace(/^svg/i,"").trim())!==""&&(i[u]=E(E({},i[u]||{}),h))})})}return i}const G0=a=>N.getSVGClass(Su(a).toLowerCase());class Lw{constructor(t,e,s,i,n){this.elements=t,this.options=e,this.reviver=s,this.regexUrl=/^url\(['"]?#([^'"]+)['"]?\)/g,this.doc=i,this.clipPaths=n,this.gradientDefs=function(r){const o=B0(r,Ow),h={};let c=o.length;for(;c--;){const u=o[c];u.getAttribute("xlink:href")&&H0(r,u);const d=u.getAttribute("id");d&&(h[d]=u)}return h}(i),this.cssRules=Rw(i)}parse(){return Promise.all(this.elements.map(t=>this.createObject(t)))}async createObject(t){const e=G0(t);if(e){const s=await e.fromElement(t,this.options,this.cssRules);return this.resolveGradient(s,t,zt),this.resolveGradient(s,t,Pe),s instanceof be&&s._originalElement?gu(s,s.parsePreserveAspectRatioAttribute()):gu(s),await this.resolveClipPath(s,t),this.reviver&&this.reviver(t,s),s}return null}extractPropertyDefinition(t,e,s){const i=t[e],n=this.regexUrl;if(!n.test(i))return;n.lastIndex=0;const r=n.exec(i)[1];return n.lastIndex=0,s[r]}resolveGradient(t,e,s){const i=this.extractPropertyDefinition(t,s,this.gradientDefs);if(i){const n=e.getAttribute(s+"-opacity"),r=Ih.fromElement(i,t,E(E({},this.options),{},{opacity:n}));t.set(s,r)}}async resolveClipPath(t,e,s){const i=this.extractPropertyDefinition(t,"clipPath",this.clipPaths);if(i){const n=Xe(t.calcTransformMatrix()),r=i[0].parentElement;let o=e;for(;!s&&o.parentElement&&o.getAttribute("clip-path")!==t.clipPath;)o=o.parentElement;o.parentElement.appendChild(r);const h=hu("".concat(o.getAttribute("transform")||""," ").concat(r.getAttribute("originalTransform")||""));r.setAttribute("transform","matrix(".concat(h.join(","),")"));const c=await Promise.all(i.map(x=>G0(x).fromElement(x,this.options,this.cssRules).then(C=>(gu(C),C.fillRule=C.clipRule,delete C.clipRule,C)))),u=c.length===1?c[0]:new ai(c),d=Nt(n,u.calcTransformMatrix());u.clipPath&&await this.resolveClipPath(u,o,r.getAttribute("clip-path")?o:void 0);const{scaleX:f,scaleY:g,angle:p,skewX:b,translateX:v,translateY:_}=br(d);u.set({flipX:!1,flipY:!1}),u.set({scaleX:f,scaleY:g,angle:p,skewX:b,skewY:0}),u.setPositionByOrigin(new P(v,_),Q,Q),t.clipPath=u}else delete t.clipPath}}const z0=a=>Rv.test(Su(a)),eg=()=>({objects:[],elements:[],options:{},allElements:[]});async function Fw(a,t){let{crossOrigin:e,signal:s}=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(s&&s.aborted)return Oi("log",new sf("parseSVGDocument")),eg();const i=a.documentElement;(function(u){const d=B0(u,["use","svg:use"]),f=["x","y","xlink:href","href","transform"];for(const g of d){const p=g.attributes,b={};for(const O of p)O.value&&(b[O.name]=O.value);const v=(b["xlink:href"]||b.href||"").slice(1);if(v==="")return;const _=u.getElementById(v);if(_===null)return;let x=_.cloneNode(!0);const C=x.attributes,S={};for(const O of C)O.value&&(S[O.name]=O.value);const{x:k=0,y:D=0,transform:A=""}=b,M="".concat(A," ").concat(S.transform||""," translate(").concat(k,", ").concat(D,")");if(Zf(x),/^svg$/i.test(x.nodeName)){const O=x.ownerDocument.createElementNS(Cf,"g");Object.entries(S).forEach(R=>{let[L,V]=R;return O.setAttributeNS(Cf,L,V)}),O.append(...x.childNodes),x=O}for(const O of p){if(!O)continue;const{name:R,value:L}=O;if(!f.includes(R))if(R==="style"){const V={};Bf(L,V),Object.entries(S).forEach(G=>{let[at,F]=G;V[at]=F}),Bf(S.style||"",V);const U=Object.entries(V).map(G=>G.join(":")).join(";");x.setAttribute(R,U)}else!S[R]&&x.setAttribute(R,L)}x.setAttribute("transform",M),x.setAttribute("instantiated_by_use","1"),x.removeAttribute("id"),g.parentNode.replaceChild(x,g)}})(a);const n=Array.from(i.getElementsByTagName("*")),r=E(E({},Zf(i)),{},{crossOrigin:e,signal:s}),o=n.filter(u=>(Zf(u),z0(u)&&!function(d){let f=d;for(;f&&(f=f.parentElement);)if(f&&f.nodeName&&Pw.test(Su(f))&&!f.getAttribute("instantiated_by_use"))return!0;return!1}(u)));if(!o||o&&!o.length)return E(E({},eg()),{},{options:r,allElements:n});const h={};return n.filter(u=>Su(u)==="clipPath").forEach(u=>{u.setAttribute("originalTransform",u.getAttribute("transform")||"");const d=u.getAttribute("id");h[d]=Array.from(u.getElementsByTagName("*")).filter(f=>z0(f))}),{objects:await new Lw(o,r,t,a,h).parse(),elements:o,options:r,allElements:n}}function Iw(a,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return new Promise((s,i)=>{_0(a.replace(/^\n\s*/,"").trim(),{onComplete:n=>{const r=n.responseXML;r&&s(r),i()},signal:e.signal})}).then(s=>Fw(s,t,e)).catch(()=>eg())}const Cu=a=>a.webgl!==void 0,sg="precision highp float",Nw=`
63
63
  `.concat(sg,`;
64
64
  varying vec2 vTexCoord;
65
65
  uniform sampler2D uTexture;
@@ -71,7 +71,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
71
71
  void main() {
72
72
  vTexCoord = aPosition;
73
73
  gl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);
74
- }`}createProgram(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.getFragmentSource(),s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.getVertexSource();const{WebGLProbe:{GLPrecision:i="highp"}}=ni();i!=="highp"&&(e=e.replace(Hw,sg.replace("highp",i)));const n=t.createShader(t.VERTEX_SHADER),r=t.createShader(t.FRAGMENT_SHADER),o=t.createProgram();if(!n||!r||!o)throw new ii("Vertex, fragment shader or program creation error");if(t.shaderSource(n,s),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS))throw new ii("Vertex shader compile error for ".concat(this.type,": ").concat(t.getShaderInfoLog(n)));if(t.shaderSource(r,e),t.compileShader(r),!t.getShaderParameter(r,t.COMPILE_STATUS))throw new ii("Fragment shader compile error for ".concat(this.type,": ").concat(t.getShaderInfoLog(r)));if(t.attachShader(o,n),t.attachShader(o,r),t.linkProgram(o),!t.getProgramParameter(o,t.LINK_STATUS))throw new ii('Shader link error for "'.concat(this.type,'" ').concat(t.getProgramInfoLog(o)));const h=this.getUniformLocations(t,o)||{};return h.uStepW=t.getUniformLocation(o,"uStepW"),h.uStepH=t.getUniformLocation(o,"uStepH"),{program:o,attributeLocations:this.getAttributeLocations(t,o),uniformLocations:h}}getAttributeLocations(t,e){return{aPosition:t.getAttribLocation(e,"aPosition")}}getUniformLocations(t,e){const s=this.constructor.uniformLocations,i={};for(let n=0;n<s.length;n++)i[s[n]]=t.getUniformLocation(e,s[n]);return i}sendAttributeData(t,e,s){const i=e.aPosition,n=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,n),t.enableVertexAttribArray(i),t.vertexAttribPointer(i,2,t.FLOAT,!1,0,0),t.bufferData(t.ARRAY_BUFFER,s,t.STATIC_DRAW)}_setupFrameBuffer(t){const e=t.context;if(t.passes>1){const s=t.destinationWidth,i=t.destinationHeight;t.sourceWidth===s&&t.sourceHeight===i||(e.deleteTexture(t.targetTexture),t.targetTexture=t.filterBackend.createTexture(e,s,i)),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,t.targetTexture,0)}else e.bindFramebuffer(e.FRAMEBUFFER,null),e.finish()}_swapTextures(t){t.passes--,t.pass++;const e=t.targetTexture;t.targetTexture=t.sourceTexture,t.sourceTexture=e}isNeutralState(t){return!1}applyTo(t){Cu(t)?(this._setupFrameBuffer(t),this.applyToWebGL(t),this._swapTextures(t)):this.applyTo2d(t)}applyTo2d(t){}getCacheKey(){return this.type}retrieveShader(t){const e=this.getCacheKey();return t.programCache[e]||(t.programCache[e]=this.createProgram(t.context)),t.programCache[e]}applyToWebGL(t){const e=t.context,s=this.retrieveShader(t);t.pass===0&&t.originalTexture?e.bindTexture(e.TEXTURE_2D,t.originalTexture):e.bindTexture(e.TEXTURE_2D,t.sourceTexture),e.useProgram(s.program),this.sendAttributeData(e,s.attributeLocations,t.aPosition),e.uniform1f(s.uniformLocations.uStepW,1/t.sourceWidth),e.uniform1f(s.uniformLocations.uStepH,1/t.sourceHeight),this.sendUniformData(e,s.uniformLocations),e.viewport(0,0,t.destinationWidth,t.destinationHeight),e.drawArrays(e.TRIANGLE_STRIP,0,4)}bindAdditionalTexture(t,e,s){t.activeTexture(s),t.bindTexture(t.TEXTURE_2D,e),t.activeTexture(t.TEXTURE0)}unbindAdditionalTexture(t,e){t.activeTexture(e),t.bindTexture(t.TEXTURE_2D,null),t.activeTexture(t.TEXTURE0)}sendUniformData(t,e){}createHelpLayer(t){if(!t.helpLayer){const{sourceWidth:e,sourceHeight:s}=t,i=Rs({width:e,height:s});t.helpLayer=i}}toObject(){const t=Object.keys(this.constructor.defaults||{});return E({type:this.type},t.reduce((e,s)=>(e[s]=this[s],e),{}))}toJSON(){return this.toObject()}static async fromObject(t,e){return new this(Ct(t,Bw))}}A($t,"type","BaseFilter"),A($t,"uniformLocations",[]);const Gw={multiply:`gl_FragColor.rgb *= uColor.rgb;
74
+ }`}createProgram(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.getFragmentSource(),s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:this.getVertexSource();const{WebGLProbe:{GLPrecision:i="highp"}}=ni();i!=="highp"&&(e=e.replace(Hw,sg.replace("highp",i)));const n=t.createShader(t.VERTEX_SHADER),r=t.createShader(t.FRAGMENT_SHADER),o=t.createProgram();if(!n||!r||!o)throw new ii("Vertex, fragment shader or program creation error");if(t.shaderSource(n,s),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS))throw new ii("Vertex shader compile error for ".concat(this.type,": ").concat(t.getShaderInfoLog(n)));if(t.shaderSource(r,e),t.compileShader(r),!t.getShaderParameter(r,t.COMPILE_STATUS))throw new ii("Fragment shader compile error for ".concat(this.type,": ").concat(t.getShaderInfoLog(r)));if(t.attachShader(o,n),t.attachShader(o,r),t.linkProgram(o),!t.getProgramParameter(o,t.LINK_STATUS))throw new ii('Shader link error for "'.concat(this.type,'" ').concat(t.getProgramInfoLog(o)));const h=this.getUniformLocations(t,o)||{};return h.uStepW=t.getUniformLocation(o,"uStepW"),h.uStepH=t.getUniformLocation(o,"uStepH"),{program:o,attributeLocations:this.getAttributeLocations(t,o),uniformLocations:h}}getAttributeLocations(t,e){return{aPosition:t.getAttribLocation(e,"aPosition")}}getUniformLocations(t,e){const s=this.constructor.uniformLocations,i={};for(let n=0;n<s.length;n++)i[s[n]]=t.getUniformLocation(e,s[n]);return i}sendAttributeData(t,e,s){const i=e.aPosition,n=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,n),t.enableVertexAttribArray(i),t.vertexAttribPointer(i,2,t.FLOAT,!1,0,0),t.bufferData(t.ARRAY_BUFFER,s,t.STATIC_DRAW)}_setupFrameBuffer(t){const e=t.context;if(t.passes>1){const s=t.destinationWidth,i=t.destinationHeight;t.sourceWidth===s&&t.sourceHeight===i||(e.deleteTexture(t.targetTexture),t.targetTexture=t.filterBackend.createTexture(e,s,i)),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,t.targetTexture,0)}else e.bindFramebuffer(e.FRAMEBUFFER,null),e.finish()}_swapTextures(t){t.passes--,t.pass++;const e=t.targetTexture;t.targetTexture=t.sourceTexture,t.sourceTexture=e}isNeutralState(t){return!1}applyTo(t){Cu(t)?(this._setupFrameBuffer(t),this.applyToWebGL(t),this._swapTextures(t)):this.applyTo2d(t)}applyTo2d(t){}getCacheKey(){return this.type}retrieveShader(t){const e=this.getCacheKey();return t.programCache[e]||(t.programCache[e]=this.createProgram(t.context)),t.programCache[e]}applyToWebGL(t){const e=t.context,s=this.retrieveShader(t);t.pass===0&&t.originalTexture?e.bindTexture(e.TEXTURE_2D,t.originalTexture):e.bindTexture(e.TEXTURE_2D,t.sourceTexture),e.useProgram(s.program),this.sendAttributeData(e,s.attributeLocations,t.aPosition),e.uniform1f(s.uniformLocations.uStepW,1/t.sourceWidth),e.uniform1f(s.uniformLocations.uStepH,1/t.sourceHeight),this.sendUniformData(e,s.uniformLocations),e.viewport(0,0,t.destinationWidth,t.destinationHeight),e.drawArrays(e.TRIANGLE_STRIP,0,4)}bindAdditionalTexture(t,e,s){t.activeTexture(s),t.bindTexture(t.TEXTURE_2D,e),t.activeTexture(t.TEXTURE0)}unbindAdditionalTexture(t,e){t.activeTexture(e),t.bindTexture(t.TEXTURE_2D,null),t.activeTexture(t.TEXTURE0)}sendUniformData(t,e){}createHelpLayer(t){if(!t.helpLayer){const{sourceWidth:e,sourceHeight:s}=t,i=Rs({width:e,height:s});t.helpLayer=i}}toObject(){const t=Object.keys(this.constructor.defaults||{});return E({type:this.type},t.reduce((e,s)=>(e[s]=this[s],e),{}))}toJSON(){return this.toObject()}static async fromObject(t,e){return new this(Ct(t,Bw))}}T($t,"type","BaseFilter"),T($t,"uniformLocations",[]);const Gw={multiply:`gl_FragColor.rgb *= uColor.rgb;
75
75
  `,screen:`gl_FragColor.rgb = 1.0 - (1.0 - gl_FragColor.rgb) * (1.0 - uColor.rgb);
76
76
  `,add:`gl_FragColor.rgb += uColor.rgb;
77
77
  `,difference:`gl_FragColor.rgb = abs(gl_FragColor.rgb - uColor.rgb);
@@ -110,7 +110,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
110
110
  `.concat(Gw[this.mode],`
111
111
  }
112
112
  }
113
- `)}applyTo2d(t){let{imageData:{data:e}}=t;const s=new gt(this.color).getSource(),i=this.alpha,n=s[0]*i,r=s[1]*i,o=s[2]*i,h=1-i;for(let c=0;c<e.length;c+=4){const u=e[c],d=e[c+1],f=e[c+2];let g,p,b;switch(this.mode){case"multiply":g=u*n/255,p=d*r/255,b=f*o/255;break;case"screen":g=255-(255-u)*(255-n)/255,p=255-(255-d)*(255-r)/255,b=255-(255-f)*(255-o)/255;break;case"add":g=u+n,p=d+r,b=f+o;break;case"difference":g=Math.abs(u-n),p=Math.abs(d-r),b=Math.abs(f-o);break;case"subtract":g=u-n,p=d-r,b=f-o;break;case"darken":g=Math.min(u,n),p=Math.min(d,r),b=Math.min(f,o);break;case"lighten":g=Math.max(u,n),p=Math.max(d,r),b=Math.max(f,o);break;case"overlay":g=n<128?2*u*n/255:255-2*(255-u)*(255-n)/255,p=r<128?2*d*r/255:255-2*(255-d)*(255-r)/255,b=o<128?2*f*o/255:255-2*(255-f)*(255-o)/255;break;case"exclusion":g=n+u-2*n*u/255,p=r+d-2*r*d/255,b=o+f-2*o*f/255;break;case"tint":g=n+u*h,p=r+d*h,b=o+f*h}e[c]=g,e[c+1]=p,e[c+2]=b}}sendUniformData(t,e){const s=new gt(this.color).getSource();s[0]=this.alpha*s[0]/255,s[1]=this.alpha*s[1]/255,s[2]=this.alpha*s[2]/255,s[3]=this.alpha,t.uniform4fv(e.uColor,s)}}A(Au,"defaults",{color:"#F95C63",mode:"multiply",alpha:1}),A(Au,"type","BlendColor"),A(Au,"uniformLocations",["uColor"]),N.setClass(Au);const zw={multiply:`
113
+ `)}applyTo2d(t){let{imageData:{data:e}}=t;const s=new gt(this.color).getSource(),i=this.alpha,n=s[0]*i,r=s[1]*i,o=s[2]*i,h=1-i;for(let c=0;c<e.length;c+=4){const u=e[c],d=e[c+1],f=e[c+2];let g,p,b;switch(this.mode){case"multiply":g=u*n/255,p=d*r/255,b=f*o/255;break;case"screen":g=255-(255-u)*(255-n)/255,p=255-(255-d)*(255-r)/255,b=255-(255-f)*(255-o)/255;break;case"add":g=u+n,p=d+r,b=f+o;break;case"difference":g=Math.abs(u-n),p=Math.abs(d-r),b=Math.abs(f-o);break;case"subtract":g=u-n,p=d-r,b=f-o;break;case"darken":g=Math.min(u,n),p=Math.min(d,r),b=Math.min(f,o);break;case"lighten":g=Math.max(u,n),p=Math.max(d,r),b=Math.max(f,o);break;case"overlay":g=n<128?2*u*n/255:255-2*(255-u)*(255-n)/255,p=r<128?2*d*r/255:255-2*(255-d)*(255-r)/255,b=o<128?2*f*o/255:255-2*(255-f)*(255-o)/255;break;case"exclusion":g=n+u-2*n*u/255,p=r+d-2*r*d/255,b=o+f-2*o*f/255;break;case"tint":g=n+u*h,p=r+d*h,b=o+f*h}e[c]=g,e[c+1]=p,e[c+2]=b}}sendUniformData(t,e){const s=new gt(this.color).getSource();s[0]=this.alpha*s[0]/255,s[1]=this.alpha*s[1]/255,s[2]=this.alpha*s[2]/255,s[3]=this.alpha,t.uniform4fv(e.uColor,s)}}T(Au,"defaults",{color:"#F95C63",mode:"multiply",alpha:1}),T(Au,"type","BlendColor"),T(Au,"uniformLocations",["uColor"]),N.setClass(Au);const zw={multiply:`
114
114
  precision highp float;
115
115
  uniform sampler2D uTexture;
116
116
  uniform sampler2D uImage;
@@ -146,7 +146,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
146
146
  vTexCoord2 = (uTransformMatrix * vec3(aPosition, 1.0)).xy;
147
147
  gl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);
148
148
  }
149
- `}applyToWebGL(t){const e=t.context,s=this.createTexture(t.filterBackend,this.image);this.bindAdditionalTexture(e,s,e.TEXTURE1),super.applyToWebGL(t),this.unbindAdditionalTexture(e,e.TEXTURE1)}createTexture(t,e){return t.getCachedTexture(e.cacheKey,e.getElement())}calculateMatrix(){const t=this.image,{width:e,height:s}=t.getElement();return[1/t.scaleX,0,0,0,1/t.scaleY,0,-t.left/e,-t.top/s,1]}applyTo2d(t){let{imageData:{data:e,width:s,height:i},filterBackend:{resources:n}}=t;const r=this.image;n.blendImage||(n.blendImage=ms());const o=n.blendImage,h=o.getContext("2d");o.width!==s||o.height!==i?(o.width=s,o.height=i):h.clearRect(0,0,s,i),h.setTransform(r.scaleX,0,0,r.scaleY,r.left,r.top),h.drawImage(r.getElement(),0,0,s,i);const c=h.getImageData(0,0,s,i).data;for(let u=0;u<e.length;u+=4){const d=e[u],f=e[u+1],g=e[u+2],p=e[u+3],b=c[u],v=c[u+1],_=c[u+2],x=c[u+3];switch(this.mode){case"multiply":e[u]=d*b/255,e[u+1]=f*v/255,e[u+2]=g*_/255,e[u+3]=p*x/255;break;case"mask":e[u+3]=x}}}sendUniformData(t,e){const s=this.calculateMatrix();t.uniform1i(e.uImage,1),t.uniformMatrix3fv(e.uTransformMatrix,!1,s)}toObject(){return E(E({},super.toObject()),{},{image:this.image&&this.image.toObject()})}static async fromObject(t,e){let{type:s,image:i}=t,n=Ct(t,Vw);return be.fromObject(i,e).then(r=>new this(E(E({},n),{},{image:r})))}}A(Tu,"type","BlendImage"),A(Tu,"defaults",{mode:"multiply",alpha:1}),A(Tu,"uniformLocations",["uTransformMatrix","uImage"]),N.setClass(Tu);class Eu extends $t{getFragmentSource(){return`
149
+ `}applyToWebGL(t){const e=t.context,s=this.createTexture(t.filterBackend,this.image);this.bindAdditionalTexture(e,s,e.TEXTURE1),super.applyToWebGL(t),this.unbindAdditionalTexture(e,e.TEXTURE1)}createTexture(t,e){return t.getCachedTexture(e.cacheKey,e.getElement())}calculateMatrix(){const t=this.image,{width:e,height:s}=t.getElement();return[1/t.scaleX,0,0,0,1/t.scaleY,0,-t.left/e,-t.top/s,1]}applyTo2d(t){let{imageData:{data:e,width:s,height:i},filterBackend:{resources:n}}=t;const r=this.image;n.blendImage||(n.blendImage=ms());const o=n.blendImage,h=o.getContext("2d");o.width!==s||o.height!==i?(o.width=s,o.height=i):h.clearRect(0,0,s,i),h.setTransform(r.scaleX,0,0,r.scaleY,r.left,r.top),h.drawImage(r.getElement(),0,0,s,i);const c=h.getImageData(0,0,s,i).data;for(let u=0;u<e.length;u+=4){const d=e[u],f=e[u+1],g=e[u+2],p=e[u+3],b=c[u],v=c[u+1],_=c[u+2],x=c[u+3];switch(this.mode){case"multiply":e[u]=d*b/255,e[u+1]=f*v/255,e[u+2]=g*_/255,e[u+3]=p*x/255;break;case"mask":e[u+3]=x}}}sendUniformData(t,e){const s=this.calculateMatrix();t.uniform1i(e.uImage,1),t.uniformMatrix3fv(e.uTransformMatrix,!1,s)}toObject(){return E(E({},super.toObject()),{},{image:this.image&&this.image.toObject()})}static async fromObject(t,e){let{type:s,image:i}=t,n=Ct(t,Vw);return be.fromObject(i,e).then(r=>new this(E(E({},n),{},{image:r})))}}T(Tu,"type","BlendImage"),T(Tu,"defaults",{mode:"multiply",alpha:1}),T(Tu,"uniformLocations",["uTransformMatrix","uImage"]),N.setClass(Tu);class Eu extends $t{getFragmentSource(){return`
150
150
  precision highp float;
151
151
  uniform sampler2D uTexture;
152
152
  uniform vec2 uDelta;
@@ -169,7 +169,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
169
169
  }
170
170
  gl_FragColor = color / total;
171
171
  }
172
- `}applyTo(t){Cu(t)?(this.aspectRatio=t.sourceWidth/t.sourceHeight,t.passes++,this._setupFrameBuffer(t),this.horizontal=!0,this.applyToWebGL(t),this._swapTextures(t),this._setupFrameBuffer(t),this.horizontal=!1,this.applyToWebGL(t),this._swapTextures(t)):this.applyTo2d(t)}applyTo2d(t){t.imageData=this.simpleBlur(t)}simpleBlur(t){let{ctx:e,imageData:s,filterBackend:{resources:i}}=t;const{width:n,height:r}=s;i.blurLayer1||(i.blurLayer1=ms(),i.blurLayer2=ms());const o=i.blurLayer1,h=i.blurLayer2;o.width===n&&o.height===r||(h.width=o.width=n,h.height=o.height=r);const c=o.getContext("2d"),u=h.getContext("2d"),d=15,f=.06*this.blur*.5;let g,p,b,v;for(c.putImageData(s,0,0),u.clearRect(0,0,n,r),v=-15;v<=d;v++)g=(Math.random()-.5)/4,p=v/d,b=f*p*n+g,u.globalAlpha=1-Math.abs(p),u.drawImage(o,b,g),c.drawImage(h,0,0),u.globalAlpha=1,u.clearRect(0,0,h.width,h.height);for(v=-15;v<=d;v++)g=(Math.random()-.5)/4,p=v/d,b=f*p*r+g,u.globalAlpha=1-Math.abs(p),u.drawImage(o,g,b),c.drawImage(h,0,0),u.globalAlpha=1,u.clearRect(0,0,h.width,h.height);e.drawImage(o,0,0);const _=e.getImageData(0,0,o.width,o.height);return c.globalAlpha=1,c.clearRect(0,0,o.width,o.height),_}sendUniformData(t,e){const s=this.chooseRightDelta();t.uniform2fv(e.uDelta,s)}isNeutralState(){return this.blur===0}chooseRightDelta(){let t=1;const e=[0,0];this.horizontal?this.aspectRatio>1&&(t=1/this.aspectRatio):this.aspectRatio<1&&(t=this.aspectRatio);const s=t*this.blur*.12;return this.horizontal?e[0]=s:e[1]=s,e}}A(Eu,"type","Blur"),A(Eu,"defaults",{blur:0}),A(Eu,"uniformLocations",["uDelta"]),N.setClass(Eu);class ku extends $t{getFragmentSource(){return`
172
+ `}applyTo(t){Cu(t)?(this.aspectRatio=t.sourceWidth/t.sourceHeight,t.passes++,this._setupFrameBuffer(t),this.horizontal=!0,this.applyToWebGL(t),this._swapTextures(t),this._setupFrameBuffer(t),this.horizontal=!1,this.applyToWebGL(t),this._swapTextures(t)):this.applyTo2d(t)}applyTo2d(t){t.imageData=this.simpleBlur(t)}simpleBlur(t){let{ctx:e,imageData:s,filterBackend:{resources:i}}=t;const{width:n,height:r}=s;i.blurLayer1||(i.blurLayer1=ms(),i.blurLayer2=ms());const o=i.blurLayer1,h=i.blurLayer2;o.width===n&&o.height===r||(h.width=o.width=n,h.height=o.height=r);const c=o.getContext("2d"),u=h.getContext("2d"),d=15,f=.06*this.blur*.5;let g,p,b,v;for(c.putImageData(s,0,0),u.clearRect(0,0,n,r),v=-15;v<=d;v++)g=(Math.random()-.5)/4,p=v/d,b=f*p*n+g,u.globalAlpha=1-Math.abs(p),u.drawImage(o,b,g),c.drawImage(h,0,0),u.globalAlpha=1,u.clearRect(0,0,h.width,h.height);for(v=-15;v<=d;v++)g=(Math.random()-.5)/4,p=v/d,b=f*p*r+g,u.globalAlpha=1-Math.abs(p),u.drawImage(o,g,b),c.drawImage(h,0,0),u.globalAlpha=1,u.clearRect(0,0,h.width,h.height);e.drawImage(o,0,0);const _=e.getImageData(0,0,o.width,o.height);return c.globalAlpha=1,c.clearRect(0,0,o.width,o.height),_}sendUniformData(t,e){const s=this.chooseRightDelta();t.uniform2fv(e.uDelta,s)}isNeutralState(){return this.blur===0}chooseRightDelta(){let t=1;const e=[0,0];this.horizontal?this.aspectRatio>1&&(t=1/this.aspectRatio):this.aspectRatio<1&&(t=this.aspectRatio);const s=t*this.blur*.12;return this.horizontal?e[0]=s:e[1]=s,e}}T(Eu,"type","Blur"),T(Eu,"defaults",{blur:0}),T(Eu,"uniformLocations",["uDelta"]),N.setClass(Eu);class ku extends $t{getFragmentSource(){return`
173
173
  precision highp float;
174
174
  uniform sampler2D uTexture;
175
175
  uniform float uBrightness;
@@ -179,7 +179,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
179
179
  color.rgb += uBrightness;
180
180
  gl_FragColor = color;
181
181
  }
182
- `}applyTo2d(t){let{imageData:{data:e}}=t;const s=Math.round(255*this.brightness);for(let i=0;i<e.length;i+=4)e[i]+=s,e[i+1]+=s,e[i+2]+=s}isNeutralState(){return this.brightness===0}sendUniformData(t,e){t.uniform1f(e.uBrightness,this.brightness)}}A(ku,"type","Brightness"),A(ku,"defaults",{brightness:0}),A(ku,"uniformLocations",["uBrightness"]),N.setClass(ku);const V0={matrix:[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],colorsOnly:!0};class na extends $t{getFragmentSource(){return`
182
+ `}applyTo2d(t){let{imageData:{data:e}}=t;const s=Math.round(255*this.brightness);for(let i=0;i<e.length;i+=4)e[i]+=s,e[i+1]+=s,e[i+2]+=s}isNeutralState(){return this.brightness===0}sendUniformData(t,e){t.uniform1f(e.uBrightness,this.brightness)}}T(ku,"type","Brightness"),T(ku,"defaults",{brightness:0}),T(ku,"uniformLocations",["uBrightness"]),N.setClass(ku);const V0={matrix:[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],colorsOnly:!0};class na extends $t{getFragmentSource(){return`
183
183
  precision highp float;
184
184
  uniform sampler2D uTexture;
185
185
  varying vec2 vTexCoord;
@@ -190,7 +190,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
190
190
  color *= uColorMatrix;
191
191
  color += uConstants;
192
192
  gl_FragColor = color;
193
- }`}applyTo2d(t){const e=t.imageData.data,s=this.matrix,i=this.colorsOnly;for(let n=0;n<e.length;n+=4){const r=e[n],o=e[n+1],h=e[n+2];if(e[n]=r*s[0]+o*s[1]+h*s[2]+255*s[4],e[n+1]=r*s[5]+o*s[6]+h*s[7]+255*s[9],e[n+2]=r*s[10]+o*s[11]+h*s[12]+255*s[14],!i){const c=e[n+3];e[n]+=c*s[3],e[n+1]+=c*s[8],e[n+2]+=c*s[13],e[n+3]=r*s[15]+o*s[16]+h*s[17]+c*s[18]+255*s[19]}}}sendUniformData(t,e){const s=this.matrix,i=[s[0],s[1],s[2],s[3],s[5],s[6],s[7],s[8],s[10],s[11],s[12],s[13],s[15],s[16],s[17],s[18]],n=[s[4],s[9],s[14],s[19]];t.uniformMatrix4fv(e.uColorMatrix,!1,i),t.uniform4fv(e.uConstants,n)}toObject(){return E(E({},super.toObject()),{},{matrix:[...this.matrix]})}}function Er(a,t){var e;const s=(A(e=class extends na{toObject(){return{type:this.type,colorsOnly:this.colorsOnly}}},"type",a),A(e,"defaults",{colorsOnly:!1,matrix:t}),e);return N.setClass(s,a),s}A(na,"type","ColorMatrix"),A(na,"defaults",V0),A(na,"uniformLocations",["uColorMatrix","uConstants"]),N.setClass(na),Er("Brownie",[.5997,.34553,-.27082,0,.186,-.0377,.86095,.15059,0,-.1449,.24113,-.07441,.44972,0,-.02965,0,0,0,1,0]),Er("Vintage",[.62793,.32021,-.03965,0,.03784,.02578,.64411,.03259,0,.02926,.0466,-.08512,.52416,0,.02023,0,0,0,1,0]),Er("Kodachrome",[1.12855,-.39673,-.03992,0,.24991,-.16404,1.08352,-.05498,0,.09698,-.16786,-.56034,1.60148,0,.13972,0,0,0,1,0]),Er("Technicolor",[1.91252,-.85453,-.09155,0,.04624,-.30878,1.76589,-.10601,0,-.27589,-.2311,-.75018,1.84759,0,.12137,0,0,0,1,0]),Er("Polaroid",[1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0]),Er("Sepia",[.393,.769,.189,0,0,.349,.686,.168,0,0,.272,.534,.131,0,0,0,0,0,1,0]),Er("BlackWhite",[1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,0,0,0,1,0]);class X0 extends $t{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};super(t),this.subFilters=t.subFilters||[]}applyTo(t){Cu(t)&&(t.passes+=this.subFilters.length-1),this.subFilters.forEach(e=>{e.applyTo(t)})}toObject(){return{type:this.type,subFilters:this.subFilters.map(t=>t.toObject())}}isNeutralState(){return!this.subFilters.some(t=>!t.isNeutralState())}static fromObject(t,e){return Promise.all((t.subFilters||[]).map(s=>N.getClass(s.type).fromObject(s,e))).then(s=>new this({subFilters:s}))}}A(X0,"type","Composed"),N.setClass(X0);class Mu extends $t{getFragmentSource(){return`
193
+ }`}applyTo2d(t){const e=t.imageData.data,s=this.matrix,i=this.colorsOnly;for(let n=0;n<e.length;n+=4){const r=e[n],o=e[n+1],h=e[n+2];if(e[n]=r*s[0]+o*s[1]+h*s[2]+255*s[4],e[n+1]=r*s[5]+o*s[6]+h*s[7]+255*s[9],e[n+2]=r*s[10]+o*s[11]+h*s[12]+255*s[14],!i){const c=e[n+3];e[n]+=c*s[3],e[n+1]+=c*s[8],e[n+2]+=c*s[13],e[n+3]=r*s[15]+o*s[16]+h*s[17]+c*s[18]+255*s[19]}}}sendUniformData(t,e){const s=this.matrix,i=[s[0],s[1],s[2],s[3],s[5],s[6],s[7],s[8],s[10],s[11],s[12],s[13],s[15],s[16],s[17],s[18]],n=[s[4],s[9],s[14],s[19]];t.uniformMatrix4fv(e.uColorMatrix,!1,i),t.uniform4fv(e.uConstants,n)}toObject(){return E(E({},super.toObject()),{},{matrix:[...this.matrix]})}}function Er(a,t){var e;const s=(T(e=class extends na{toObject(){return{type:this.type,colorsOnly:this.colorsOnly}}},"type",a),T(e,"defaults",{colorsOnly:!1,matrix:t}),e);return N.setClass(s,a),s}T(na,"type","ColorMatrix"),T(na,"defaults",V0),T(na,"uniformLocations",["uColorMatrix","uConstants"]),N.setClass(na),Er("Brownie",[.5997,.34553,-.27082,0,.186,-.0377,.86095,.15059,0,-.1449,.24113,-.07441,.44972,0,-.02965,0,0,0,1,0]),Er("Vintage",[.62793,.32021,-.03965,0,.03784,.02578,.64411,.03259,0,.02926,.0466,-.08512,.52416,0,.02023,0,0,0,1,0]),Er("Kodachrome",[1.12855,-.39673,-.03992,0,.24991,-.16404,1.08352,-.05498,0,.09698,-.16786,-.56034,1.60148,0,.13972,0,0,0,1,0]),Er("Technicolor",[1.91252,-.85453,-.09155,0,.04624,-.30878,1.76589,-.10601,0,-.27589,-.2311,-.75018,1.84759,0,.12137,0,0,0,1,0]),Er("Polaroid",[1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0]),Er("Sepia",[.393,.769,.189,0,0,.349,.686,.168,0,0,.272,.534,.131,0,0,0,0,0,1,0]),Er("BlackWhite",[1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,0,0,0,1,0]);class X0 extends $t{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};super(t),this.subFilters=t.subFilters||[]}applyTo(t){Cu(t)&&(t.passes+=this.subFilters.length-1),this.subFilters.forEach(e=>{e.applyTo(t)})}toObject(){return{type:this.type,subFilters:this.subFilters.map(t=>t.toObject())}}isNeutralState(){return!this.subFilters.some(t=>!t.isNeutralState())}static fromObject(t,e){return Promise.all((t.subFilters||[]).map(s=>N.getClass(s.type).fromObject(s,e))).then(s=>new this({subFilters:s}))}}T(X0,"type","Composed"),N.setClass(X0);class Mu extends $t{getFragmentSource(){return`
194
194
  precision highp float;
195
195
  uniform sampler2D uTexture;
196
196
  uniform float uContrast;
@@ -200,7 +200,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
200
200
  float contrastF = 1.015 * (uContrast + 1.0) / (1.0 * (1.015 - uContrast));
201
201
  color.rgb = contrastF * (color.rgb - 0.5) + 0.5;
202
202
  gl_FragColor = color;
203
- }`}isNeutralState(){return this.contrast===0}applyTo2d(t){let{imageData:{data:e}}=t;const s=Math.floor(255*this.contrast),i=259*(s+255)/(255*(259-s));for(let n=0;n<e.length;n+=4)e[n]=i*(e[n]-128)+128,e[n+1]=i*(e[n+1]-128)+128,e[n+2]=i*(e[n+2]-128)+128}sendUniformData(t,e){t.uniform1f(e.uContrast,this.contrast)}}A(Mu,"type","Contrast"),A(Mu,"defaults",{contrast:0}),A(Mu,"uniformLocations",["uContrast"]),N.setClass(Mu);const Xw={Convolute_3_1:`
203
+ }`}isNeutralState(){return this.contrast===0}applyTo2d(t){let{imageData:{data:e}}=t;const s=Math.floor(255*this.contrast),i=259*(s+255)/(255*(259-s));for(let n=0;n<e.length;n+=4)e[n]=i*(e[n]-128)+128,e[n+1]=i*(e[n+1]-128)+128,e[n+2]=i*(e[n+2]-128)+128}sendUniformData(t,e){t.uniform1f(e.uContrast,this.contrast)}}T(Mu,"type","Contrast"),T(Mu,"defaults",{contrast:0}),T(Mu,"uniformLocations",["uContrast"]),N.setClass(Mu);const Xw={Convolute_3_1:`
204
204
  precision highp float;
205
205
  uniform sampler2D uTexture;
206
206
  uniform float uMatrix[9];
@@ -344,7 +344,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
344
344
  gl_FragColor = color;
345
345
  gl_FragColor.a = alpha;
346
346
  }
347
- `};class Pu extends $t{getCacheKey(){return"".concat(this.type,"_").concat(Math.sqrt(this.matrix.length),"_").concat(this.opaque?1:0)}getFragmentSource(){return Xw[this.getCacheKey()]}applyTo2d(t){const e=t.imageData,s=e.data,i=this.matrix,n=Math.round(Math.sqrt(i.length)),r=Math.floor(n/2),o=e.width,h=e.height,c=t.ctx.createImageData(o,h),u=c.data,d=this.opaque?1:0;let f,g,p,b,v,_,x,C,S,k,D,T,M;for(D=0;D<h;D++)for(k=0;k<o;k++){for(v=4*(D*o+k),f=0,g=0,p=0,b=0,M=0;M<n;M++)for(T=0;T<n;T++)x=D+M-r,_=k+T-r,x<0||x>=h||_<0||_>=o||(C=4*(x*o+_),S=i[M*n+T],f+=s[C]*S,g+=s[C+1]*S,p+=s[C+2]*S,d||(b+=s[C+3]*S));u[v]=f,u[v+1]=g,u[v+2]=p,u[v+3]=d?s[v+3]:b}t.imageData=c}sendUniformData(t,e){t.uniform1fv(e.uMatrix,this.matrix)}toObject(){return E(E({},super.toObject()),{},{opaque:this.opaque,matrix:[...this.matrix]})}}A(Pu,"type","Convolute"),A(Pu,"defaults",{opaque:!1,matrix:[0,0,0,0,1,0,0,0,0]}),A(Pu,"uniformLocations",["uMatrix","uOpaque","uHalfSize","uSize"]),N.setClass(Pu);const W0="Gamma";class Du extends $t{getFragmentSource(){return`
347
+ `};class Pu extends $t{getCacheKey(){return"".concat(this.type,"_").concat(Math.sqrt(this.matrix.length),"_").concat(this.opaque?1:0)}getFragmentSource(){return Xw[this.getCacheKey()]}applyTo2d(t){const e=t.imageData,s=e.data,i=this.matrix,n=Math.round(Math.sqrt(i.length)),r=Math.floor(n/2),o=e.width,h=e.height,c=t.ctx.createImageData(o,h),u=c.data,d=this.opaque?1:0;let f,g,p,b,v,_,x,C,S,k,D,A,M;for(D=0;D<h;D++)for(k=0;k<o;k++){for(v=4*(D*o+k),f=0,g=0,p=0,b=0,M=0;M<n;M++)for(A=0;A<n;A++)x=D+M-r,_=k+A-r,x<0||x>=h||_<0||_>=o||(C=4*(x*o+_),S=i[M*n+A],f+=s[C]*S,g+=s[C+1]*S,p+=s[C+2]*S,d||(b+=s[C+3]*S));u[v]=f,u[v+1]=g,u[v+2]=p,u[v+3]=d?s[v+3]:b}t.imageData=c}sendUniformData(t,e){t.uniform1fv(e.uMatrix,this.matrix)}toObject(){return E(E({},super.toObject()),{},{opaque:this.opaque,matrix:[...this.matrix]})}}T(Pu,"type","Convolute"),T(Pu,"defaults",{opaque:!1,matrix:[0,0,0,0,1,0,0,0,0]}),T(Pu,"uniformLocations",["uMatrix","uOpaque","uHalfSize","uSize"]),N.setClass(Pu);const W0="Gamma";class Du extends $t{getFragmentSource(){return`
348
348
  precision highp float;
349
349
  uniform sampler2D uTexture;
350
350
  uniform vec3 uGamma;
@@ -358,7 +358,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
358
358
  gl_FragColor = color;
359
359
  gl_FragColor.rgb *= color.a;
360
360
  }
361
- `}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};super(t),this.gamma=t.gamma||this.constructor.defaults.gamma.concat()}applyTo2d(t){let{imageData:{data:e}}=t;const s=this.gamma,i=1/s[0],n=1/s[1],r=1/s[2];this.rgbValues||(this.rgbValues={r:new Uint8Array(256),g:new Uint8Array(256),b:new Uint8Array(256)});const o=this.rgbValues;for(let h=0;h<256;h++)o.r[h]=255*Math.pow(h/255,i),o.g[h]=255*Math.pow(h/255,n),o.b[h]=255*Math.pow(h/255,r);for(let h=0;h<e.length;h+=4)e[h]=o.r[e[h]],e[h+1]=o.g[e[h+1]],e[h+2]=o.b[e[h+2]]}sendUniformData(t,e){t.uniform3fv(e.uGamma,this.gamma)}isNeutralState(){const{gamma:t}=this;return t[0]===1&&t[1]===1&&t[2]===1}toObject(){return{type:W0,gamma:this.gamma.concat()}}}A(Du,"type",W0),A(Du,"defaults",{gamma:[1,1,1]}),A(Du,"uniformLocations",["uGamma"]),N.setClass(Du);const Ww={average:`
361
+ `}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};super(t),this.gamma=t.gamma||this.constructor.defaults.gamma.concat()}applyTo2d(t){let{imageData:{data:e}}=t;const s=this.gamma,i=1/s[0],n=1/s[1],r=1/s[2];this.rgbValues||(this.rgbValues={r:new Uint8Array(256),g:new Uint8Array(256),b:new Uint8Array(256)});const o=this.rgbValues;for(let h=0;h<256;h++)o.r[h]=255*Math.pow(h/255,i),o.g[h]=255*Math.pow(h/255,n),o.b[h]=255*Math.pow(h/255,r);for(let h=0;h<e.length;h+=4)e[h]=o.r[e[h]],e[h+1]=o.g[e[h+1]],e[h+2]=o.b[e[h+2]]}sendUniformData(t,e){t.uniform3fv(e.uGamma,this.gamma)}isNeutralState(){const{gamma:t}=this;return t[0]===1&&t[1]===1&&t[2]===1}toObject(){return{type:W0,gamma:this.gamma.concat()}}}T(Du,"type",W0),T(Du,"defaults",{gamma:[1,1,1]}),T(Du,"uniformLocations",["uGamma"]),N.setClass(Du);const Ww={average:`
362
362
  precision highp float;
363
363
  uniform sampler2D uTexture;
364
364
  varying vec2 vTexCoord;
@@ -387,7 +387,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
387
387
  float average = 0.21 * col.r + 0.72 * col.g + 0.07 * col.b;
388
388
  gl_FragColor = vec4(average, average, average, col.a);
389
389
  }
390
- `};class Ou extends $t{applyTo2d(t){let{imageData:{data:e}}=t;for(let s,i=0;i<e.length;i+=4){const n=e[i],r=e[i+1],o=e[i+2];switch(this.mode){case"average":s=(n+r+o)/3;break;case"lightness":s=(Math.min(n,r,o)+Math.max(n,r,o))/2;break;case"luminosity":s=.21*n+.72*r+.07*o}e[i+2]=e[i+1]=e[i]=s}}getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return Ww[this.mode]}sendUniformData(t,e){t.uniform1i(e.uMode,1)}isNeutralState(){return!1}}A(Ou,"type","Grayscale"),A(Ou,"defaults",{mode:"average"}),A(Ou,"uniformLocations",["uMode"]),N.setClass(Ou);const Uw=E(E({},V0),{},{rotation:0});class ig extends na{calculateMatrix(){const t=this.rotation*Math.PI,e=Ds(t),s=Os(t),i=1/3,n=Math.sqrt(i)*s,r=1-e;this.matrix=[e+r/3,i*r-n,i*r+n,0,0,i*r+n,e+i*r,i*r-n,0,0,i*r-n,i*r+n,e+i*r,0,0,0,0,0,1,0]}isNeutralState(){return this.rotation===0}applyTo(t){this.calculateMatrix(),super.applyTo(t)}toObject(){return{type:this.type,rotation:this.rotation}}}A(ig,"type","HueRotation"),A(ig,"defaults",Uw),N.setClass(ig);class Ru extends $t{applyTo2d(t){let{imageData:{data:e}}=t;for(let s=0;s<e.length;s+=4)e[s]=255-e[s],e[s+1]=255-e[s+1],e[s+2]=255-e[s+2],this.alpha&&(e[s+3]=255-e[s+3])}getFragmentSource(){return`
390
+ `};class Ou extends $t{applyTo2d(t){let{imageData:{data:e}}=t;for(let s,i=0;i<e.length;i+=4){const n=e[i],r=e[i+1],o=e[i+2];switch(this.mode){case"average":s=(n+r+o)/3;break;case"lightness":s=(Math.min(n,r,o)+Math.max(n,r,o))/2;break;case"luminosity":s=.21*n+.72*r+.07*o}e[i+2]=e[i+1]=e[i]=s}}getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return Ww[this.mode]}sendUniformData(t,e){t.uniform1i(e.uMode,1)}isNeutralState(){return!1}}T(Ou,"type","Grayscale"),T(Ou,"defaults",{mode:"average"}),T(Ou,"uniformLocations",["uMode"]),N.setClass(Ou);const Uw=E(E({},V0),{},{rotation:0});class ig extends na{calculateMatrix(){const t=this.rotation*Math.PI,e=Ds(t),s=Os(t),i=1/3,n=Math.sqrt(i)*s,r=1-e;this.matrix=[e+r/3,i*r-n,i*r+n,0,0,i*r+n,e+i*r,i*r-n,0,0,i*r-n,i*r+n,e+i*r,0,0,0,0,0,1,0]}isNeutralState(){return this.rotation===0}applyTo(t){this.calculateMatrix(),super.applyTo(t)}toObject(){return{type:this.type,rotation:this.rotation}}}T(ig,"type","HueRotation"),T(ig,"defaults",Uw),N.setClass(ig);class Ru extends $t{applyTo2d(t){let{imageData:{data:e}}=t;for(let s=0;s<e.length;s+=4)e[s]=255-e[s],e[s+1]=255-e[s+1],e[s+2]=255-e[s+2],this.alpha&&(e[s+3]=255-e[s+3])}getFragmentSource(){return`
391
391
  precision highp float;
392
392
  uniform sampler2D uTexture;
393
393
  uniform int uInvert;
@@ -405,7 +405,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
405
405
  gl_FragColor = color;
406
406
  }
407
407
  }
408
- `}isNeutralState(){return!this.invert}sendUniformData(t,e){t.uniform1i(e.uInvert,Number(this.invert)),t.uniform1i(e.uAlpha,Number(this.alpha))}}A(Ru,"type","Invert"),A(Ru,"defaults",{alpha:!1,invert:!0}),A(Ru,"uniformLocations",["uInvert","uAlpha"]),N.setClass(Ru);class Lu extends $t{getFragmentSource(){return`
408
+ `}isNeutralState(){return!this.invert}sendUniformData(t,e){t.uniform1i(e.uInvert,Number(this.invert)),t.uniform1i(e.uAlpha,Number(this.alpha))}}T(Ru,"type","Invert"),T(Ru,"defaults",{alpha:!1,invert:!0}),T(Ru,"uniformLocations",["uInvert","uAlpha"]),N.setClass(Ru);class Lu extends $t{getFragmentSource(){return`
409
409
  precision highp float;
410
410
  uniform sampler2D uTexture;
411
411
  uniform float uStepH;
@@ -420,7 +420,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
420
420
  color.rgb += (0.5 - rand(vTexCoord, uSeed, 0.1 / uStepH)) * uNoise;
421
421
  gl_FragColor = color;
422
422
  }
423
- `}applyTo2d(t){let{imageData:{data:e}}=t;const s=this.noise;for(let i=0;i<e.length;i+=4){const n=(.5-Math.random())*s;e[i]+=n,e[i+1]+=n,e[i+2]+=n}}sendUniformData(t,e){t.uniform1f(e.uNoise,this.noise/255),t.uniform1f(e.uSeed,Math.random())}isNeutralState(){return this.noise===0}}A(Lu,"type","Noise"),A(Lu,"defaults",{noise:0}),A(Lu,"uniformLocations",["uNoise","uSeed"]),N.setClass(Lu);class Fu extends $t{applyTo2d(t){let{imageData:{data:e,width:s,height:i}}=t;for(let n=0;n<i;n+=this.blocksize)for(let r=0;r<s;r+=this.blocksize){const o=4*n*s+4*r,h=e[o],c=e[o+1],u=e[o+2],d=e[o+3];for(let f=n;f<Math.min(n+this.blocksize,i);f++)for(let g=r;g<Math.min(r+this.blocksize,s);g++){const p=4*f*s+4*g;e[p]=h,e[p+1]=c,e[p+2]=u,e[p+3]=d}}}isNeutralState(){return this.blocksize===1}getFragmentSource(){return`
423
+ `}applyTo2d(t){let{imageData:{data:e}}=t;const s=this.noise;for(let i=0;i<e.length;i+=4){const n=(.5-Math.random())*s;e[i]+=n,e[i+1]+=n,e[i+2]+=n}}sendUniformData(t,e){t.uniform1f(e.uNoise,this.noise/255),t.uniform1f(e.uSeed,Math.random())}isNeutralState(){return this.noise===0}}T(Lu,"type","Noise"),T(Lu,"defaults",{noise:0}),T(Lu,"uniformLocations",["uNoise","uSeed"]),N.setClass(Lu);class Fu extends $t{applyTo2d(t){let{imageData:{data:e,width:s,height:i}}=t;for(let n=0;n<i;n+=this.blocksize)for(let r=0;r<s;r+=this.blocksize){const o=4*n*s+4*r,h=e[o],c=e[o+1],u=e[o+2],d=e[o+3];for(let f=n;f<Math.min(n+this.blocksize,i);f++)for(let g=r;g<Math.min(r+this.blocksize,s);g++){const p=4*f*s+4*g;e[p]=h,e[p+1]=c,e[p+2]=u,e[p+3]=d}}}isNeutralState(){return this.blocksize===1}getFragmentSource(){return`
424
424
  precision highp float;
425
425
  uniform sampler2D uTexture;
426
426
  uniform float uBlocksize;
@@ -438,7 +438,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
438
438
  vec4 color = texture2D(uTexture, squareCoords);
439
439
  gl_FragColor = color;
440
440
  }
441
- `}sendUniformData(t,e){t.uniform1f(e.uBlocksize,this.blocksize)}}A(Fu,"type","Pixelate"),A(Fu,"defaults",{blocksize:4}),A(Fu,"uniformLocations",["uBlocksize"]),N.setClass(Fu);class Iu extends $t{getFragmentSource(){return`
441
+ `}sendUniformData(t,e){t.uniform1f(e.uBlocksize,this.blocksize)}}T(Fu,"type","Pixelate"),T(Fu,"defaults",{blocksize:4}),T(Fu,"uniformLocations",["uBlocksize"]),N.setClass(Fu);class Iu extends $t{getFragmentSource(){return`
442
442
  precision highp float;
443
443
  uniform sampler2D uTexture;
444
444
  uniform vec4 uLow;
@@ -450,7 +450,7 @@ void main() {
450
450
  gl_FragColor.a = 0.0;
451
451
  }
452
452
  }
453
- `}applyTo2d(t){let{imageData:{data:e}}=t;const s=255*this.distance,i=new gt(this.color).getSource(),n=[i[0]-s,i[1]-s,i[2]-s],r=[i[0]+s,i[1]+s,i[2]+s];for(let o=0;o<e.length;o+=4){const h=e[o],c=e[o+1],u=e[o+2];h>n[0]&&c>n[1]&&u>n[2]&&h<r[0]&&c<r[1]&&u<r[2]&&(e[o+3]=0)}}sendUniformData(t,e){const s=new gt(this.color).getSource(),i=this.distance,n=[0+s[0]/255-i,0+s[1]/255-i,0+s[2]/255-i,1],r=[s[0]/255+i,s[1]/255+i,s[2]/255+i,1];t.uniform4fv(e.uLow,n),t.uniform4fv(e.uHigh,r)}}A(Iu,"type","RemoveColor"),A(Iu,"defaults",{color:"#FFFFFF",distance:.02,useAlpha:!1}),A(Iu,"uniformLocations",["uLow","uHigh"]),N.setClass(Iu);class Nu extends $t{sendUniformData(t,e){t.uniform2fv(e.uDelta,this.horizontal?[1/this.width,0]:[0,1/this.height]),t.uniform1fv(e.uTaps,this.taps)}getFilterWindow(){const t=this.tempScale;return Math.ceil(this.lanczosLobes/t)}getCacheKey(){const t=this.getFilterWindow();return"".concat(this.type,"_").concat(t)}getFragmentSource(){const t=this.getFilterWindow();return this.generateShader(t)}getTaps(){const t=this.lanczosCreate(this.lanczosLobes),e=this.tempScale,s=this.getFilterWindow(),i=new Array(s);for(let n=1;n<=s;n++)i[n-1]=t(n*e);return i}generateShader(t){const e=new Array(t);for(let s=1;s<=t;s++)e[s-1]="".concat(s,".0 * uDelta");return`
453
+ `}applyTo2d(t){let{imageData:{data:e}}=t;const s=255*this.distance,i=new gt(this.color).getSource(),n=[i[0]-s,i[1]-s,i[2]-s],r=[i[0]+s,i[1]+s,i[2]+s];for(let o=0;o<e.length;o+=4){const h=e[o],c=e[o+1],u=e[o+2];h>n[0]&&c>n[1]&&u>n[2]&&h<r[0]&&c<r[1]&&u<r[2]&&(e[o+3]=0)}}sendUniformData(t,e){const s=new gt(this.color).getSource(),i=this.distance,n=[0+s[0]/255-i,0+s[1]/255-i,0+s[2]/255-i,1],r=[s[0]/255+i,s[1]/255+i,s[2]/255+i,1];t.uniform4fv(e.uLow,n),t.uniform4fv(e.uHigh,r)}}T(Iu,"type","RemoveColor"),T(Iu,"defaults",{color:"#FFFFFF",distance:.02,useAlpha:!1}),T(Iu,"uniformLocations",["uLow","uHigh"]),N.setClass(Iu);class Nu extends $t{sendUniformData(t,e){t.uniform2fv(e.uDelta,this.horizontal?[1/this.width,0]:[0,1/this.height]),t.uniform1fv(e.uTaps,this.taps)}getFilterWindow(){const t=this.tempScale;return Math.ceil(this.lanczosLobes/t)}getCacheKey(){const t=this.getFilterWindow();return"".concat(this.type,"_").concat(t)}getFragmentSource(){const t=this.getFilterWindow();return this.generateShader(t)}getTaps(){const t=this.lanczosCreate(this.lanczosLobes),e=this.tempScale,s=this.getFilterWindow(),i=new Array(s);for(let n=1;n<=s;n++)i[n-1]=t(n*e);return i}generateShader(t){const e=new Array(t);for(let s=1;s<=t;s++)e[s-1]="".concat(s,".0 * uDelta");return`
454
454
  precision highp float;
455
455
  uniform sampler2D uTexture;
456
456
  uniform vec2 uDelta;
@@ -466,7 +466,7 @@ void main() {
466
466
  `),`
467
467
  gl_FragColor = color / sum;
468
468
  }
469
- `)}applyToForWebgl(t){t.passes++,this.width=t.sourceWidth,this.horizontal=!0,this.dW=Math.round(this.width*this.scaleX),this.dH=t.sourceHeight,this.tempScale=this.dW/this.width,this.taps=this.getTaps(),t.destinationWidth=this.dW,super.applyTo(t),t.sourceWidth=t.destinationWidth,this.height=t.sourceHeight,this.horizontal=!1,this.dH=Math.round(this.height*this.scaleY),this.tempScale=this.dH/this.height,this.taps=this.getTaps(),t.destinationHeight=this.dH,super.applyTo(t),t.sourceHeight=t.destinationHeight}applyTo(t){Cu(t)?this.applyToForWebgl(t):this.applyTo2d(t)}isNeutralState(){return this.scaleX===1&&this.scaleY===1}lanczosCreate(t){return e=>{if(e>=t||e<=-t)return 0;if(e<11920929e-14&&e>-11920929e-14)return 1;const s=(e*=Math.PI)/t;return Math.sin(e)/e*Math.sin(s)/s}}applyTo2d(t){const e=t.imageData,s=this.scaleX,i=this.scaleY;this.rcpScaleX=1/s,this.rcpScaleY=1/i;const n=e.width,r=e.height,o=Math.round(n*s),h=Math.round(r*i);let c;c=this.resizeType==="sliceHack"?this.sliceByTwo(t,n,r,o,h):this.resizeType==="hermite"?this.hermiteFastResize(t,n,r,o,h):this.resizeType==="bilinear"?this.bilinearFiltering(t,n,r,o,h):this.resizeType==="lanczos"?this.lanczosResize(t,n,r,o,h):new ImageData(o,h),t.imageData=c}sliceByTwo(t,e,s,i,n){const r=t.imageData,o=.5;let h=!1,c=!1,u=e*o,d=s*o;const f=t.filterBackend.resources;let g=0,p=0;const b=e;let v=0;f.sliceByTwo||(f.sliceByTwo=ms());const _=f.sliceByTwo;(_.width<1.5*e||_.height<s)&&(_.width=1.5*e,_.height=s);const x=_.getContext("2d");for(x.clearRect(0,0,1.5*e,s),x.putImageData(r,0,0),i=Math.floor(i),n=Math.floor(n);!h||!c;)e=u,s=d,i<Math.floor(u*o)?u=Math.floor(u*o):(u=i,h=!0),n<Math.floor(d*o)?d=Math.floor(d*o):(d=n,c=!0),x.drawImage(_,g,p,e,s,b,v,u,d),g=b,p=v,v+=d;return x.getImageData(g,p,i,n)}lanczosResize(t,e,s,i,n){const r=t.imageData.data,o=t.ctx.createImageData(i,n),h=o.data,c=this.lanczosCreate(this.lanczosLobes),u=this.rcpScaleX,d=this.rcpScaleY,f=2/this.rcpScaleX,g=2/this.rcpScaleY,p=Math.ceil(u*this.lanczosLobes/2),b=Math.ceil(d*this.lanczosLobes/2),v={},_={x:0,y:0},x={x:0,y:0};return function C(S){let k,D,T,M,O,R,L,W,U,G,at;for(_.x=(S+.5)*u,x.x=Math.floor(_.x),k=0;k<n;k++){for(_.y=(k+.5)*d,x.y=Math.floor(_.y),O=0,R=0,L=0,W=0,U=0,D=x.x-p;D<=x.x+p;D++)if(!(D<0||D>=e)){G=Math.floor(1e3*Math.abs(D-_.x)),v[G]||(v[G]={});for(let F=x.y-b;F<=x.y+b;F++)F<0||F>=s||(at=Math.floor(1e3*Math.abs(F-_.y)),v[G][at]||(v[G][at]=c(Math.sqrt(Math.pow(G*f,2)+Math.pow(at*g,2))/1e3)),T=v[G][at],T>0&&(M=4*(F*e+D),O+=T,R+=T*r[M],L+=T*r[M+1],W+=T*r[M+2],U+=T*r[M+3]))}M=4*(k*i+S),h[M]=R/O,h[M+1]=L/O,h[M+2]=W/O,h[M+3]=U/O}return++S<i?C(S):o}(0)}bilinearFiltering(t,e,s,i,n){let r,o,h,c,u,d,f,g,p,b,v,_,x,C=0;const S=this.rcpScaleX,k=this.rcpScaleY,D=4*(e-1),T=t.imageData.data,M=t.ctx.createImageData(i,n),O=M.data;for(f=0;f<n;f++)for(g=0;g<i;g++)for(u=Math.floor(S*g),d=Math.floor(k*f),p=S*g-u,b=k*f-d,x=4*(d*e+u),v=0;v<4;v++)r=T[x+v],o=T[x+4+v],h=T[x+D+v],c=T[x+D+4+v],_=r*(1-p)*(1-b)+o*p*(1-b)+h*b*(1-p)+c*p*b,O[C++]=_;return M}hermiteFastResize(t,e,s,i,n){const r=this.rcpScaleX,o=this.rcpScaleY,h=Math.ceil(r/2),c=Math.ceil(o/2),u=t.imageData.data,d=t.ctx.createImageData(i,n),f=d.data;for(let g=0;g<n;g++)for(let p=0;p<i;p++){const b=4*(p+g*i);let v=0,_=0,x=0,C=0,S=0,k=0,D=0;const T=(g+.5)*o;for(let M=Math.floor(g*o);M<(g+1)*o;M++){const O=Math.abs(T-(M+.5))/c,R=(p+.5)*r,L=O*O;for(let W=Math.floor(p*r);W<(p+1)*r;W++){let U=Math.abs(R-(W+.5))/h;const G=Math.sqrt(L+U*U);G>1&&G<-1||(v=2*G*G*G-3*G*G+1,v>0&&(U=4*(W+M*e),D+=v*u[U+3],x+=v,u[U+3]<255&&(v=v*u[U+3]/250),C+=v*u[U],S+=v*u[U+1],k+=v*u[U+2],_+=v))}}f[b]=C/_,f[b+1]=S/_,f[b+2]=k/_,f[b+3]=D/x}return d}}A(Nu,"type","Resize"),A(Nu,"defaults",{resizeType:"hermite",scaleX:1,scaleY:1,lanczosLobes:3}),A(Nu,"uniformLocations",["uDelta","uTaps"]),N.setClass(Nu);class ju extends $t{getFragmentSource(){return`
469
+ `)}applyToForWebgl(t){t.passes++,this.width=t.sourceWidth,this.horizontal=!0,this.dW=Math.round(this.width*this.scaleX),this.dH=t.sourceHeight,this.tempScale=this.dW/this.width,this.taps=this.getTaps(),t.destinationWidth=this.dW,super.applyTo(t),t.sourceWidth=t.destinationWidth,this.height=t.sourceHeight,this.horizontal=!1,this.dH=Math.round(this.height*this.scaleY),this.tempScale=this.dH/this.height,this.taps=this.getTaps(),t.destinationHeight=this.dH,super.applyTo(t),t.sourceHeight=t.destinationHeight}applyTo(t){Cu(t)?this.applyToForWebgl(t):this.applyTo2d(t)}isNeutralState(){return this.scaleX===1&&this.scaleY===1}lanczosCreate(t){return e=>{if(e>=t||e<=-t)return 0;if(e<11920929e-14&&e>-11920929e-14)return 1;const s=(e*=Math.PI)/t;return Math.sin(e)/e*Math.sin(s)/s}}applyTo2d(t){const e=t.imageData,s=this.scaleX,i=this.scaleY;this.rcpScaleX=1/s,this.rcpScaleY=1/i;const n=e.width,r=e.height,o=Math.round(n*s),h=Math.round(r*i);let c;c=this.resizeType==="sliceHack"?this.sliceByTwo(t,n,r,o,h):this.resizeType==="hermite"?this.hermiteFastResize(t,n,r,o,h):this.resizeType==="bilinear"?this.bilinearFiltering(t,n,r,o,h):this.resizeType==="lanczos"?this.lanczosResize(t,n,r,o,h):new ImageData(o,h),t.imageData=c}sliceByTwo(t,e,s,i,n){const r=t.imageData,o=.5;let h=!1,c=!1,u=e*o,d=s*o;const f=t.filterBackend.resources;let g=0,p=0;const b=e;let v=0;f.sliceByTwo||(f.sliceByTwo=ms());const _=f.sliceByTwo;(_.width<1.5*e||_.height<s)&&(_.width=1.5*e,_.height=s);const x=_.getContext("2d");for(x.clearRect(0,0,1.5*e,s),x.putImageData(r,0,0),i=Math.floor(i),n=Math.floor(n);!h||!c;)e=u,s=d,i<Math.floor(u*o)?u=Math.floor(u*o):(u=i,h=!0),n<Math.floor(d*o)?d=Math.floor(d*o):(d=n,c=!0),x.drawImage(_,g,p,e,s,b,v,u,d),g=b,p=v,v+=d;return x.getImageData(g,p,i,n)}lanczosResize(t,e,s,i,n){const r=t.imageData.data,o=t.ctx.createImageData(i,n),h=o.data,c=this.lanczosCreate(this.lanczosLobes),u=this.rcpScaleX,d=this.rcpScaleY,f=2/this.rcpScaleX,g=2/this.rcpScaleY,p=Math.ceil(u*this.lanczosLobes/2),b=Math.ceil(d*this.lanczosLobes/2),v={},_={x:0,y:0},x={x:0,y:0};return function C(S){let k,D,A,M,O,R,L,V,U,G,at;for(_.x=(S+.5)*u,x.x=Math.floor(_.x),k=0;k<n;k++){for(_.y=(k+.5)*d,x.y=Math.floor(_.y),O=0,R=0,L=0,V=0,U=0,D=x.x-p;D<=x.x+p;D++)if(!(D<0||D>=e)){G=Math.floor(1e3*Math.abs(D-_.x)),v[G]||(v[G]={});for(let F=x.y-b;F<=x.y+b;F++)F<0||F>=s||(at=Math.floor(1e3*Math.abs(F-_.y)),v[G][at]||(v[G][at]=c(Math.sqrt(Math.pow(G*f,2)+Math.pow(at*g,2))/1e3)),A=v[G][at],A>0&&(M=4*(F*e+D),O+=A,R+=A*r[M],L+=A*r[M+1],V+=A*r[M+2],U+=A*r[M+3]))}M=4*(k*i+S),h[M]=R/O,h[M+1]=L/O,h[M+2]=V/O,h[M+3]=U/O}return++S<i?C(S):o}(0)}bilinearFiltering(t,e,s,i,n){let r,o,h,c,u,d,f,g,p,b,v,_,x,C=0;const S=this.rcpScaleX,k=this.rcpScaleY,D=4*(e-1),A=t.imageData.data,M=t.ctx.createImageData(i,n),O=M.data;for(f=0;f<n;f++)for(g=0;g<i;g++)for(u=Math.floor(S*g),d=Math.floor(k*f),p=S*g-u,b=k*f-d,x=4*(d*e+u),v=0;v<4;v++)r=A[x+v],o=A[x+4+v],h=A[x+D+v],c=A[x+D+4+v],_=r*(1-p)*(1-b)+o*p*(1-b)+h*b*(1-p)+c*p*b,O[C++]=_;return M}hermiteFastResize(t,e,s,i,n){const r=this.rcpScaleX,o=this.rcpScaleY,h=Math.ceil(r/2),c=Math.ceil(o/2),u=t.imageData.data,d=t.ctx.createImageData(i,n),f=d.data;for(let g=0;g<n;g++)for(let p=0;p<i;p++){const b=4*(p+g*i);let v=0,_=0,x=0,C=0,S=0,k=0,D=0;const A=(g+.5)*o;for(let M=Math.floor(g*o);M<(g+1)*o;M++){const O=Math.abs(A-(M+.5))/c,R=(p+.5)*r,L=O*O;for(let V=Math.floor(p*r);V<(p+1)*r;V++){let U=Math.abs(R-(V+.5))/h;const G=Math.sqrt(L+U*U);G>1&&G<-1||(v=2*G*G*G-3*G*G+1,v>0&&(U=4*(V+M*e),D+=v*u[U+3],x+=v,u[U+3]<255&&(v=v*u[U+3]/250),C+=v*u[U],S+=v*u[U+1],k+=v*u[U+2],_+=v))}}f[b]=C/_,f[b+1]=S/_,f[b+2]=k/_,f[b+3]=D/x}return d}}T(Nu,"type","Resize"),T(Nu,"defaults",{resizeType:"hermite",scaleX:1,scaleY:1,lanczosLobes:3}),T(Nu,"uniformLocations",["uDelta","uTaps"]),N.setClass(Nu);class ju extends $t{getFragmentSource(){return`
470
470
  precision highp float;
471
471
  uniform sampler2D uTexture;
472
472
  uniform float uSaturation;
@@ -480,7 +480,7 @@ void main() {
480
480
  color.b += rgbMax != color.b ? (rgbMax - color.b) * uSaturation : 0.00;
481
481
  gl_FragColor = color;
482
482
  }
483
- `}applyTo2d(t){let{imageData:{data:e}}=t;const s=-this.saturation;for(let i=0;i<e.length;i+=4){const n=e[i],r=e[i+1],o=e[i+2],h=Math.max(n,r,o);e[i]+=h!==n?(h-n)*s:0,e[i+1]+=h!==r?(h-r)*s:0,e[i+2]+=h!==o?(h-o)*s:0}}sendUniformData(t,e){t.uniform1f(e.uSaturation,-this.saturation)}isNeutralState(){return this.saturation===0}}A(ju,"type","Saturation"),A(ju,"defaults",{saturation:0}),A(ju,"uniformLocations",["uSaturation"]),N.setClass(ju);class Bu extends $t{getFragmentSource(){return`
483
+ `}applyTo2d(t){let{imageData:{data:e}}=t;const s=-this.saturation;for(let i=0;i<e.length;i+=4){const n=e[i],r=e[i+1],o=e[i+2],h=Math.max(n,r,o);e[i]+=h!==n?(h-n)*s:0,e[i+1]+=h!==r?(h-r)*s:0,e[i+2]+=h!==o?(h-o)*s:0}}sendUniformData(t,e){t.uniform1f(e.uSaturation,-this.saturation)}isNeutralState(){return this.saturation===0}}T(ju,"type","Saturation"),T(ju,"defaults",{saturation:0}),T(ju,"uniformLocations",["uSaturation"]),N.setClass(ju);class Bu extends $t{getFragmentSource(){return`
484
484
  precision highp float;
485
485
  uniform sampler2D uTexture;
486
486
  uniform float uVibrance;
@@ -495,15 +495,15 @@ void main() {
495
495
  color.b += max != color.b ? (max - color.b) * amt : 0.00;
496
496
  gl_FragColor = color;
497
497
  }
498
- `}applyTo2d(t){let{imageData:{data:e}}=t;const s=-this.vibrance;for(let i=0;i<e.length;i+=4){const n=e[i],r=e[i+1],o=e[i+2],h=Math.max(n,r,o),c=(n+r+o)/3,u=2*Math.abs(h-c)/255*s;e[i]+=h!==n?(h-n)*u:0,e[i+1]+=h!==r?(h-r)*u:0,e[i+2]+=h!==o?(h-o)*u:0}}sendUniformData(t,e){t.uniform1f(e.uVibrance,-this.vibrance)}isNeutralState(){return this.vibrance===0}}A(Bu,"type","Vibrance"),A(Bu,"defaults",{vibrance:0}),A(Bu,"uniformLocations",["uVibrance"]),N.setClass(Bu);var Bh={};Bh.d=(a,t)=>{for(var e in t)Bh.o(t,e)&&!Bh.o(a,e)&&Object.defineProperty(a,e,{enumerable:!0,get:t[e]})},Bh.o=(a,t)=>Object.prototype.hasOwnProperty.call(a,t);var K=globalThis.pdfjsLib={};Bh.d(K,{AbortException:()=>Rn,AnnotationEditorLayer:()=>Hg,AnnotationEditorParamsType:()=>ot,AnnotationEditorType:()=>Z,AnnotationEditorUIManager:()=>Mr,AnnotationLayer:()=>GS,AnnotationMode:()=>Dn,ColorPicker:()=>nd,DOMSVGFactory:()=>Pg,DrawLayer:()=>Gg,FeatureTest:()=>Re,GlobalWorkerOptions:()=>Vi,ImageKind:()=>Hu,InvalidPDFException:()=>ag,MissingPDFException:()=>Gh,OPS:()=>Hs,OutputScale:()=>mg,PDFDataRangeTransport:()=>Tb,PDFDateString:()=>gg,PDFWorker:()=>aa,PasswordResponses:()=>Kw,PermissionFlag:()=>qw,PixelsPerInch:()=>Ln,RenderingCancelledException:()=>dg,TextLayer:()=>Yh,TouchManager:()=>Ku,UnexpectedResponseException:()=>Xu,Util:()=>X,VerbosityLevel:()=>Gu,XfaLayer:()=>Pb,build:()=>wS,createValidAbsoluteUrl:()=>tx,fetchData:()=>Uu,getDocument:()=>dS,getFilenameFromUrl:()=>lx,getPdfFilenameFromUrl:()=>cx,getXfaPageViewport:()=>ux,isDataScheme:()=>Yu,isPdfFile:()=>fg,noContextMenu:()=>Gs,normalizeUnicode:()=>ox,setLayerDimensions:()=>kr,shadow:()=>st,stopEvent:()=>es,version:()=>_S});const ye=typeof process=="object"&&process+""=="[object process]"&&!process.versions.nw&&!(process.versions.electron&&process.type&&process.type!=="browser"),U0=[1,0,0,1,0,0],ng=[.001,0,0,.001,0,0],Yw=1e7,rg=1.35,ts={ANY:1,DISPLAY:2,PRINT:4,ANNOTATIONS_FORMS:16,ANNOTATIONS_STORAGE:32,ANNOTATIONS_DISABLE:64,IS_EDITING:128,OPLIST:256},Dn={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},$w="pdfjs_internal_editor_",Z={DISABLE:-1,NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15},ot={RESIZE:1,CREATE:2,FREETEXT_SIZE:11,FREETEXT_COLOR:12,FREETEXT_OPACITY:13,INK_COLOR:21,INK_THICKNESS:22,INK_OPACITY:23,HIGHLIGHT_COLOR:31,HIGHLIGHT_DEFAULT_COLOR:32,HIGHLIGHT_THICKNESS:33,HIGHLIGHT_FREE:34,HIGHLIGHT_SHOW_ALL:35,DRAW_STEP:41},qw={PRINT:4,MODIFY_CONTENTS:8,COPY:16,MODIFY_ANNOTATIONS:32,FILL_INTERACTIVE_FORMS:256,COPY_FOR_ACCESSIBILITY:512,ASSEMBLE:1024,PRINT_HIGH_QUALITY:2048},ve={FILL:0,STROKE:1,FILL_STROKE:2,INVISIBLE:3,FILL_STROKE_MASK:3,ADD_TO_PATH_FLAG:4},Hu={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},qt={TEXT:1,LINK:2,FREETEXT:3,LINE:4,SQUARE:5,CIRCLE:6,POLYGON:7,POLYLINE:8,HIGHLIGHT:9,UNDERLINE:10,SQUIGGLY:11,STRIKEOUT:12,STAMP:13,CARET:14,INK:15,POPUP:16,FILEATTACHMENT:17,WIDGET:20},Hh={SOLID:1,DASHED:2,BEVELED:3,INSET:4,UNDERLINE:5},Gu={ERRORS:0,WARNINGS:1,INFOS:5},Hs={dependency:1,setLineWidth:2,setLineCap:3,setLineJoin:4,setMiterLimit:5,setDash:6,setRenderingIntent:7,setFlatness:8,setGState:9,save:10,restore:11,transform:12,moveTo:13,lineTo:14,curveTo:15,curveTo2:16,curveTo3:17,closePath:18,rectangle:19,stroke:20,closeStroke:21,fill:22,eoFill:23,fillStroke:24,eoFillStroke:25,closeFillStroke:26,closeEOFillStroke:27,endPath:28,clip:29,eoClip:30,beginText:31,endText:32,setCharSpacing:33,setWordSpacing:34,setHScale:35,setLeading:36,setFont:37,setTextRenderingMode:38,setTextRise:39,moveText:40,setLeadingMoveText:41,setTextMatrix:42,nextLine:43,showText:44,showSpacedText:45,nextLineShowText:46,nextLineSetSpacingShowText:47,setCharWidth:48,setCharWidthAndBounds:49,setStrokeColorSpace:50,setFillColorSpace:51,setStrokeColor:52,setStrokeColorN:53,setFillColor:54,setFillColorN:55,setStrokeGray:56,setFillGray:57,setStrokeRGBColor:58,setFillRGBColor:59,setStrokeCMYKColor:60,setFillCMYKColor:61,shadingFill:62,beginInlineImage:63,beginImageData:64,endInlineImage:65,paintXObject:66,markPoint:67,markPointProps:68,beginMarkedContent:69,beginMarkedContentProps:70,endMarkedContent:71,beginCompat:72,endCompat:73,paintFormXObjectBegin:74,paintFormXObjectEnd:75,beginGroup:76,endGroup:77,beginAnnotation:80,endAnnotation:81,paintImageMaskXObject:83,paintImageMaskXObjectGroup:84,paintImageXObject:85,paintInlineImageXObject:86,paintInlineImageXObjectGroup:87,paintImageXObjectRepeat:88,paintImageMaskXObjectRepeat:89,paintSolidColorImageMask:90,constructPath:91,setStrokeTransparent:92,setFillTransparent:93},Kw={NEED_PASSWORD:1,INCORRECT_PASSWORD:2};let zu=Gu.WARNINGS;function Qw(a){Number.isInteger(a)&&(zu=a)}function Jw(){return zu}function Vu(a){zu>=Gu.INFOS&&console.log(`Info: ${a}`)}function tt(a){zu>=Gu.WARNINGS&&console.log(`Warning: ${a}`)}function vt(a){throw new Error(a)}function Xt(a,t){a||vt(t)}function Zw(a){switch(a==null?void 0:a.protocol){case"http:":case"https:":case"ftp:":case"mailto:":case"tel:":return!0;default:return!1}}function tx(a,t=null,e=null){if(!a)return null;try{if(e&&typeof a=="string"){if(e.addDefaultProtocol&&a.startsWith("www.")){const i=a.match(/\./g);(i==null?void 0:i.length)>=2&&(a=`http://${a}`)}if(e.tryConvertEncoding)try{a=rx(a)}catch{}}const s=t?new URL(a,t):new URL(a);if(Zw(s))return s}catch{}return null}function st(a,t,e,s=!1){return Object.defineProperty(a,t,{value:e,enumerable:!s,configurable:!0,writable:!1}),e}const On=function(){function t(e,s){this.message=e,this.name=s}return t.prototype=new Error,t.constructor=t,t}();class Y0 extends On{constructor(t,e){super(t,"PasswordException"),this.code=e}}class og extends On{constructor(t,e){super(t,"UnknownErrorException"),this.details=e}}class ag extends On{constructor(t){super(t,"InvalidPDFException")}}class Gh extends On{constructor(t){super(t,"MissingPDFException")}}class Xu extends On{constructor(t,e){super(t,"UnexpectedResponseException"),this.status=e}}class ex extends On{constructor(t){super(t,"FormatError")}}class Rn extends On{constructor(t){super(t,"AbortException")}}function $0(a){(typeof a!="object"||(a==null?void 0:a.length)===void 0)&&vt("Invalid argument for bytesToString");const t=a.length,e=8192;if(t<e)return String.fromCharCode.apply(null,a);const s=[];for(let i=0;i<t;i+=e){const n=Math.min(i+e,t),r=a.subarray(i,n);s.push(String.fromCharCode.apply(null,r))}return s.join("")}function Wu(a){typeof a!="string"&&vt("Invalid argument for stringToBytes");const t=a.length,e=new Uint8Array(t);for(let s=0;s<t;++s)e[s]=a.charCodeAt(s)&255;return e}function sx(a){return String.fromCharCode(a>>24&255,a>>16&255,a>>8&255,a&255)}function hg(a){const t=Object.create(null);for(const[e,s]of a)t[e]=s;return t}function ix(){const a=new Uint8Array(4);return a[0]=1,new Uint32Array(a.buffer,0,1)[0]===1}function nx(){try{return new Function(""),!0}catch{return!1}}class Re{static get isLittleEndian(){return st(this,"isLittleEndian",ix())}static get isEvalSupported(){return st(this,"isEvalSupported",nx())}static get isOffscreenCanvasSupported(){return st(this,"isOffscreenCanvasSupported",typeof OffscreenCanvas<"u")}static get isImageDecoderSupported(){return st(this,"isImageDecoderSupported",typeof ImageDecoder<"u")}static get platform(){return typeof navigator<"u"&&typeof(navigator==null?void 0:navigator.platform)=="string"?st(this,"platform",{isMac:navigator.platform.includes("Mac"),isWindows:navigator.platform.includes("Win"),isFirefox:typeof(navigator==null?void 0:navigator.userAgent)=="string"&&navigator.userAgent.includes("Firefox")}):st(this,"platform",{isMac:!1,isWindows:!1,isFirefox:!1})}static get isCSSRoundSupported(){var t,e;return st(this,"isCSSRoundSupported",(e=(t=globalThis.CSS)==null?void 0:t.supports)==null?void 0:e.call(t,"width: round(1.5px, 1px)"))}}const lg=Array.from(Array(256).keys(),a=>a.toString(16).padStart(2,"0"));class X{static makeHexColor(t,e,s){return`#${lg[t]}${lg[e]}${lg[s]}`}static scaleMinMax(t,e){let s;t[0]?(t[0]<0&&(s=e[0],e[0]=e[2],e[2]=s),e[0]*=t[0],e[2]*=t[0],t[3]<0&&(s=e[1],e[1]=e[3],e[3]=s),e[1]*=t[3],e[3]*=t[3]):(s=e[0],e[0]=e[1],e[1]=s,s=e[2],e[2]=e[3],e[3]=s,t[1]<0&&(s=e[1],e[1]=e[3],e[3]=s),e[1]*=t[1],e[3]*=t[1],t[2]<0&&(s=e[0],e[0]=e[2],e[2]=s),e[0]*=t[2],e[2]*=t[2]),e[0]+=t[4],e[1]+=t[5],e[2]+=t[4],e[3]+=t[5]}static transform(t,e){return[t[0]*e[0]+t[2]*e[1],t[1]*e[0]+t[3]*e[1],t[0]*e[2]+t[2]*e[3],t[1]*e[2]+t[3]*e[3],t[0]*e[4]+t[2]*e[5]+t[4],t[1]*e[4]+t[3]*e[5]+t[5]]}static applyTransform(t,e){const s=t[0]*e[0]+t[1]*e[2]+e[4],i=t[0]*e[1]+t[1]*e[3]+e[5];return[s,i]}static applyInverseTransform(t,e){const s=e[0]*e[3]-e[1]*e[2],i=(t[0]*e[3]-t[1]*e[2]+e[2]*e[5]-e[4]*e[3])/s,n=(-t[0]*e[1]+t[1]*e[0]+e[4]*e[1]-e[5]*e[0])/s;return[i,n]}static getAxialAlignedBoundingBox(t,e){const s=this.applyTransform(t,e),i=this.applyTransform(t.slice(2,4),e),n=this.applyTransform([t[0],t[3]],e),r=this.applyTransform([t[2],t[1]],e);return[Math.min(s[0],i[0],n[0],r[0]),Math.min(s[1],i[1],n[1],r[1]),Math.max(s[0],i[0],n[0],r[0]),Math.max(s[1],i[1],n[1],r[1])]}static inverseTransform(t){const e=t[0]*t[3]-t[1]*t[2];return[t[3]/e,-t[1]/e,-t[2]/e,t[0]/e,(t[2]*t[5]-t[4]*t[3])/e,(t[4]*t[1]-t[5]*t[0])/e]}static singularValueDecompose2dScale(t){const e=[t[0],t[2],t[1],t[3]],s=t[0]*e[0]+t[1]*e[2],i=t[0]*e[1]+t[1]*e[3],n=t[2]*e[0]+t[3]*e[2],r=t[2]*e[1]+t[3]*e[3],o=(s+r)/2,h=Math.sqrt((s+r)**2-4*(s*r-n*i))/2,c=o+h||1,u=o-h||1;return[Math.sqrt(c),Math.sqrt(u)]}static normalizeRect(t){const e=t.slice(0);return t[0]>t[2]&&(e[0]=t[2],e[2]=t[0]),t[1]>t[3]&&(e[1]=t[3],e[3]=t[1]),e}static intersect(t,e){const s=Math.max(Math.min(t[0],t[2]),Math.min(e[0],e[2])),i=Math.min(Math.max(t[0],t[2]),Math.max(e[0],e[2]));if(s>i)return null;const n=Math.max(Math.min(t[1],t[3]),Math.min(e[1],e[3])),r=Math.min(Math.max(t[1],t[3]),Math.max(e[1],e[3]));return n>r?null:[s,n,i,r]}static bezierBoundingBox(t,e,s,i,n,r,o,h,c){return c?(c[0]=Math.min(c[0],t,o),c[1]=Math.min(c[1],e,h),c[2]=Math.max(c[2],t,o),c[3]=Math.max(c[3],e,h)):c=[Math.min(t,o),Math.min(e,h),Math.max(t,o),Math.max(e,h)],w(this,Xi,qg).call(this,t,s,n,o,e,i,r,h,3*(-t+3*(s-n)+o),6*(t-2*s+n),3*(s-t),c),w(this,Xi,qg).call(this,t,s,n,o,e,i,r,h,3*(-e+3*(i-r)+h),6*(e-2*i+r),3*(i-e),c),c}}Xi=new WeakSet,Ed=function(t,e,s,i,n,r,o,h,c,u){if(c<=0||c>=1)return;const d=1-c,f=c*c,g=f*c,p=d*(d*(d*t+3*c*e)+3*f*s)+g*i,b=d*(d*(d*n+3*c*r)+3*f*o)+g*h;u[0]=Math.min(u[0],p),u[1]=Math.min(u[1],b),u[2]=Math.max(u[2],p),u[3]=Math.max(u[3],b)},qg=function(t,e,s,i,n,r,o,h,c,u,d,f){if(Math.abs(c)<1e-12){Math.abs(u)>=1e-12&&w(this,Xi,Ed).call(this,t,e,s,i,n,r,o,h,-d/u,f);return}const g=u**2-4*d*c;if(g<0)return;const p=Math.sqrt(g),b=2*c;w(this,Xi,Ed).call(this,t,e,s,i,n,r,o,h,(-u+p)/b,f),w(this,Xi,Ed).call(this,t,e,s,i,n,r,o,h,(-u-p)/b,f)},y(X,Xi);function rx(a){return decodeURIComponent(escape(a))}let cg=null,q0=null;function ox(a){return cg||(cg=/([\u00a0\u00b5\u037e\u0eb3\u2000-\u200a\u202f\u2126\ufb00-\ufb04\ufb06\ufb20-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufba1\ufba4-\ufba9\ufbae-\ufbb1\ufbd3-\ufbdc\ufbde-\ufbe7\ufbea-\ufbf8\ufbfc-\ufbfd\ufc00-\ufc5d\ufc64-\ufcf1\ufcf5-\ufd3d\ufd88\ufdf4\ufdfa-\ufdfb\ufe71\ufe77\ufe79\ufe7b\ufe7d]+)|(\ufb05+)/gu,q0=new Map([["ſt","ſt"]])),a.replaceAll(cg,(t,e,s)=>e?e.normalize("NFKC"):q0.get(s))}function ax(){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();const a=new Uint8Array(32);return crypto.getRandomValues(a),$0(a)}const ug="pdfjs_internal_id_";function hx(a){return Uint8Array.prototype.toBase64?a.toBase64():btoa($0(a))}typeof Promise.try!="function"&&(Promise.try=function(a,...t){return new Promise(e=>{e(a(...t))})});const zi="http://www.w3.org/2000/svg",Or=class Or{};$(Or,"CSS",96),$(Or,"PDF",72),$(Or,"PDF_TO_CSS_UNITS",Or.CSS/Or.PDF);let Ln=Or;async function Uu(a,t="text"){if(Vh(a,document.baseURI)){const e=await fetch(a);if(!e.ok)throw new Error(e.statusText);switch(t){case"arraybuffer":return e.arrayBuffer();case"blob":return e.blob();case"json":return e.json()}return e.text()}return new Promise((e,s)=>{const i=new XMLHttpRequest;i.open("GET",a,!0),i.responseType=t,i.onreadystatechange=()=>{if(i.readyState===XMLHttpRequest.DONE){if(i.status===200||i.status===0){switch(t){case"arraybuffer":case"blob":case"json":e(i.response);return}e(i.responseText);return}s(new Error(i.statusText))}},i.send(null)})}class zh{constructor({viewBox:t,userUnit:e,scale:s,rotation:i,offsetX:n=0,offsetY:r=0,dontFlip:o=!1}){this.viewBox=t,this.userUnit=e,this.scale=s,this.rotation=i,this.offsetX=n,this.offsetY=r,s*=e;const h=(t[2]+t[0])/2,c=(t[3]+t[1])/2;let u,d,f,g;switch(i%=360,i<0&&(i+=360),i){case 180:u=-1,d=0,f=0,g=1;break;case 90:u=0,d=1,f=1,g=0;break;case 270:u=0,d=-1,f=-1,g=0;break;case 0:u=1,d=0,f=0,g=-1;break;default:throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.")}o&&(f=-f,g=-g);let p,b,v,_;u===0?(p=Math.abs(c-t[1])*s+n,b=Math.abs(h-t[0])*s+r,v=(t[3]-t[1])*s,_=(t[2]-t[0])*s):(p=Math.abs(h-t[0])*s+n,b=Math.abs(c-t[1])*s+r,v=(t[2]-t[0])*s,_=(t[3]-t[1])*s),this.transform=[u*s,d*s,f*s,g*s,p-u*s*h-f*s*c,b-d*s*h-g*s*c],this.width=v,this.height=_}get rawDims(){const{userUnit:t,viewBox:e}=this,s=e.map(i=>i*t);return st(this,"rawDims",{pageWidth:s[2]-s[0],pageHeight:s[3]-s[1],pageX:s[0],pageY:s[1]})}clone({scale:t=this.scale,rotation:e=this.rotation,offsetX:s=this.offsetX,offsetY:i=this.offsetY,dontFlip:n=!1}={}){return new zh({viewBox:this.viewBox.slice(),userUnit:this.userUnit,scale:t,rotation:e,offsetX:s,offsetY:i,dontFlip:n})}convertToViewportPoint(t,e){return X.applyTransform([t,e],this.transform)}convertToViewportRectangle(t){const e=X.applyTransform([t[0],t[1]],this.transform),s=X.applyTransform([t[2],t[3]],this.transform);return[e[0],e[1],s[0],s[1]]}convertToPdfPoint(t,e){return X.applyInverseTransform([t,e],this.transform)}}class dg extends On{constructor(t,e=0){super(t,"RenderingCancelledException"),this.extraDelay=e}}function Yu(a){const t=a.length;let e=0;for(;e<t&&a[e].trim()==="";)e++;return a.substring(e,e+5).toLowerCase()==="data:"}function fg(a){return typeof a=="string"&&/\.pdf$/i.test(a)}function lx(a){return[a]=a.split(/[#?]/,1),a.substring(a.lastIndexOf("/")+1)}function cx(a,t="document.pdf"){if(typeof a!="string")return t;if(Yu(a))return tt('getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.'),t;const e=/^(?:(?:[^:]+:)?\/\/[^/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/,s=/[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i,i=e.exec(a);let n=s.exec(i[1])||s.exec(i[2])||s.exec(i[3]);if(n&&(n=n[0],n.includes("%")))try{n=s.exec(decodeURIComponent(n))[0]}catch{}return n||t}class K0{constructor(){$(this,"started",Object.create(null));$(this,"times",[])}time(t){t in this.started&&tt(`Timer is already running for ${t}`),this.started[t]=Date.now()}timeEnd(t){t in this.started||tt(`Timer has not been started for ${t}`),this.times.push({name:t,start:this.started[t],end:Date.now()}),delete this.started[t]}toString(){const t=[];let e=0;for(const{name:s}of this.times)e=Math.max(s.length,e);for(const{name:s,start:i,end:n}of this.times)t.push(`${s.padEnd(e)} ${n-i}ms
499
- `);return t.join("")}}function Vh(a,t){try{const{protocol:e}=t?new URL(a,t):new URL(a);return e==="http:"||e==="https:"}catch{return!1}}function Gs(a){a.preventDefault()}function es(a){a.preventDefault(),a.stopPropagation()}class gg{static toDateObject(t){if(!t||typeof t!="string")return null;l(this,Jh)||m(this,Jh,new RegExp("^D:(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?([Z|+|-])?(\\d{2})?'?(\\d{2})?'?"));const e=l(this,Jh).exec(t);if(!e)return null;const s=parseInt(e[1],10);let i=parseInt(e[2],10);i=i>=1&&i<=12?i-1:0;let n=parseInt(e[3],10);n=n>=1&&n<=31?n:1;let r=parseInt(e[4],10);r=r>=0&&r<=23?r:0;let o=parseInt(e[5],10);o=o>=0&&o<=59?o:0;let h=parseInt(e[6],10);h=h>=0&&h<=59?h:0;const c=e[7]||"Z";let u=parseInt(e[8],10);u=u>=0&&u<=23?u:0;let d=parseInt(e[9],10)||0;return d=d>=0&&d<=59?d:0,c==="-"?(r+=u,o+=d):c==="+"&&(r-=u,o-=d),new Date(Date.UTC(s,i,n,r,o,h))}}Jh=new WeakMap,y(gg,Jh);function ux(a,{scale:t=1,rotation:e=0}){const{width:s,height:i}=a.attributes.style,n=[0,0,parseInt(s),parseInt(i)];return new zh({viewBox:n,userUnit:1,scale:t,rotation:e})}function pg(a){if(a.startsWith("#")){const t=parseInt(a.slice(1),16);return[(t&16711680)>>16,(t&65280)>>8,t&255]}return a.startsWith("rgb(")?a.slice(4,-1).split(",").map(t=>parseInt(t)):a.startsWith("rgba(")?a.slice(5,-1).split(",").map(t=>parseInt(t)).slice(0,3):(tt(`Not a valid color format: "${a}"`),[0,0,0])}function dx(a){const t=document.createElement("span");t.style.visibility="hidden",document.body.append(t);for(const e of a.keys()){t.style.color=e;const s=window.getComputedStyle(t).color;a.set(e,pg(s))}t.remove()}function Tt(a){const{a:t,b:e,c:s,d:i,e:n,f:r}=a.getTransform();return[t,e,s,i,n,r]}function li(a){const{a:t,b:e,c:s,d:i,e:n,f:r}=a.getTransform().invertSelf();return[t,e,s,i,n,r]}function kr(a,t,e=!1,s=!0){if(t instanceof zh){const{pageWidth:i,pageHeight:n}=t.rawDims,{style:r}=a,o=Re.isCSSRoundSupported,h=`var(--scale-factor) * ${i}px`,c=`var(--scale-factor) * ${n}px`,u=o?`round(down, ${h}, var(--scale-round-x, 1px))`:`calc(${h})`,d=o?`round(down, ${c}, var(--scale-round-y, 1px))`:`calc(${c})`;!e||t.rotation%180===0?(r.width=u,r.height=d):(r.width=d,r.height=u)}s&&a.setAttribute("data-main-rotation",t.rotation)}class mg{constructor(){const t=window.devicePixelRatio||1;this.sx=t,this.sy=t}get scaled(){return this.sx!==1||this.sy!==1}get symmetric(){return this.sx===this.sy}}const Wi=class Wi{constructor(t){y(this,Le);y(this,In,null);y(this,Rr,null);y(this,zs);y(this,Lr,null);y(this,Zh,null);m(this,zs,t),l(Wi,tl)||m(Wi,tl,Object.freeze({freetext:"pdfjs-editor-remove-freetext-button",highlight:"pdfjs-editor-remove-highlight-button",ink:"pdfjs-editor-remove-ink-button",stamp:"pdfjs-editor-remove-stamp-button"}))}render(){const t=m(this,In,document.createElement("div"));t.classList.add("editToolbar","hidden"),t.setAttribute("role","toolbar");const e=l(this,zs)._uiManager._signal;t.addEventListener("contextmenu",Gs,{signal:e}),t.addEventListener("pointerdown",w(Wi,ad,$b),{signal:e});const s=m(this,Lr,document.createElement("div"));s.className="buttons",t.append(s);const i=l(this,zs).toolbarPosition;if(i){const{style:n}=t,r=l(this,zs)._uiManager.direction==="ltr"?1-i[0]:i[0];n.insetInlineEnd=`${100*r}%`,n.top=`calc(${100*i[1]}% + var(--editor-toolbar-vert-offset))`}return w(this,Le,Qb).call(this),t}get div(){return l(this,In)}hide(){var t;l(this,In).classList.add("hidden"),(t=l(this,Rr))==null||t.hideDropdown()}show(){var t;l(this,In).classList.remove("hidden"),(t=l(this,Zh))==null||t.shown()}async addAltText(t){const e=await t.render();w(this,Le,kd).call(this,e),l(this,Lr).prepend(e,l(this,Le,Kg)),m(this,Zh,t)}addColorPicker(t){m(this,Rr,t);const e=t.renderButton();w(this,Le,kd).call(this,e),l(this,Lr).prepend(e,l(this,Le,Kg))}remove(){var t;l(this,In).remove(),(t=l(this,Rr))==null||t.destroy(),m(this,Rr,null)}};In=new WeakMap,Rr=new WeakMap,zs=new WeakMap,Lr=new WeakMap,Zh=new WeakMap,tl=new WeakMap,ad=new WeakSet,$b=function(t){t.stopPropagation()},Le=new WeakSet,qb=function(t){l(this,zs)._focusEventsAllowed=!1,es(t)},Kb=function(t){l(this,zs)._focusEventsAllowed=!0,es(t)},kd=function(t){const e=l(this,zs)._uiManager._signal;t.addEventListener("focusin",w(this,Le,qb).bind(this),{capture:!0,signal:e}),t.addEventListener("focusout",w(this,Le,Kb).bind(this),{capture:!0,signal:e}),t.addEventListener("contextmenu",Gs,{signal:e})},Qb=function(){const{editorType:t,_uiManager:e}=l(this,zs),s=document.createElement("button");s.className="delete",s.tabIndex=0,s.setAttribute("data-l10n-id",l(Wi,tl)[t]),w(this,Le,kd).call(this,s),s.addEventListener("click",i=>{e.delete()},{signal:e._signal}),l(this,Lr).append(s)},Kg=function(){const t=document.createElement("div");return t.className="divider",t},y(Wi,ad),y(Wi,tl,null);let bg=Wi;class fx{constructor(t){y(this,Nn);y(this,el,null);y(this,Fr,null);y(this,Ir);m(this,Ir,t)}show(t,e,s){const[i,n]=w(this,Nn,Zb).call(this,e,s),{style:r}=l(this,Fr)||m(this,Fr,w(this,Nn,Jb).call(this));t.append(l(this,Fr)),r.insetInlineEnd=`${100*i}%`,r.top=`calc(${100*n}% + var(--editor-toolbar-vert-offset))`}hide(){l(this,Fr).remove()}}el=new WeakMap,Fr=new WeakMap,Ir=new WeakMap,Nn=new WeakSet,Jb=function(){const t=m(this,Fr,document.createElement("div"));t.className="editToolbar",t.setAttribute("role","toolbar"),t.addEventListener("contextmenu",Gs,{signal:l(this,Ir)._signal});const e=m(this,el,document.createElement("div"));return e.className="buttons",t.append(e),w(this,Nn,ty).call(this),t},Zb=function(t,e){let s=0,i=0;for(const n of t){const r=n.y+n.height;if(r<s)continue;const o=n.x+(e?n.width:0);if(r>s){i=o,s=r;continue}e?o>i&&(i=o):o<i&&(i=o)}return[e?1-i:i,s]},ty=function(){const t=document.createElement("button");t.className="highlightButton",t.tabIndex=0,t.setAttribute("data-l10n-id","pdfjs-highlight-floating-button1");const e=document.createElement("span");t.append(e),e.className="visuallyHidden",e.setAttribute("data-l10n-id","pdfjs-highlight-floating-button-label");const s=l(this,Ir)._signal;t.addEventListener("contextmenu",Gs,{signal:s}),t.addEventListener("click",()=>{l(this,Ir).highlightSelection("floating_button")},{signal:s}),l(this,el).append(t)};function $u(a,t,e){for(const s of e)t.addEventListener(s,a[s].bind(a))}class gx{constructor(){y(this,hd,0)}get id(){return`${$w}${Ge(this,hd)._++}`}}hd=new WeakMap;const zg=class zg{constructor(){y(this,la);y(this,ha,ax());y(this,sl,0);y(this,we,null)}static get _isSVGFittingCanvas(){const t='data:image/svg+xml;charset=UTF-8,<svg viewBox="0 0 1 1" width="1" height="1" xmlns="http://www.w3.org/2000/svg"><rect width="1" height="1" style="fill:red;"/></svg>',s=new OffscreenCanvas(1,3).getContext("2d",{willReadFrequently:!0}),i=new Image;i.src=t;const n=i.decode().then(()=>(s.drawImage(i,0,0,1,1,0,0,1,3),new Uint32Array(s.getImageData(0,0,1,1).data.buffer)[0]===0));return st(this,"_isSVGFittingCanvas",n)}async getFromFile(t){const{lastModified:e,name:s,size:i,type:n}=t;return w(this,la,Md).call(this,`${e}_${s}_${i}_${n}`,t)}async getFromUrl(t){return w(this,la,Md).call(this,t,t)}async getFromBlob(t,e){const s=await e;return w(this,la,Md).call(this,t,s)}async getFromId(t){l(this,we)||m(this,we,new Map);const e=l(this,we).get(t);if(!e)return null;if(e.bitmap)return e.refCounter+=1,e;if(e.file)return this.getFromFile(e.file);if(e.blobPromise){const{blobPromise:s}=e;return delete e.blobPromise,this.getFromBlob(e.id,s)}return this.getFromUrl(e.url)}getFromCanvas(t,e){l(this,we)||m(this,we,new Map);let s=l(this,we).get(t);if(s!=null&&s.bitmap)return s.refCounter+=1,s;const i=new OffscreenCanvas(e.width,e.height);return i.getContext("2d").drawImage(e,0,0),s={bitmap:i.transferToImageBitmap(),id:`image_${l(this,ha)}_${Ge(this,sl)._++}`,refCounter:1,isSvg:!1},l(this,we).set(t,s),l(this,we).set(s.id,s),s}getSvgUrl(t){const e=l(this,we).get(t);return e!=null&&e.isSvg?e.svgUrl:null}deleteId(t){var i;l(this,we)||m(this,we,new Map);const e=l(this,we).get(t);if(!e||(e.refCounter-=1,e.refCounter!==0))return;const{bitmap:s}=e;if(!e.url&&!e.file){const n=new OffscreenCanvas(s.width,s.height);n.getContext("bitmaprenderer").transferFromImageBitmap(s),e.blobPromise=n.convertToBlob()}(i=s.close)==null||i.call(s),e.bitmap=null}isValidId(t){return t.startsWith(`image_${l(this,ha)}_`)}};ha=new WeakMap,sl=new WeakMap,we=new WeakMap,la=new WeakSet,Md=async function(t,e){l(this,we)||m(this,we,new Map);let s=l(this,we).get(t);if(s===null)return null;if(s!=null&&s.bitmap)return s.refCounter+=1,s;try{s||(s={bitmap:null,id:`image_${l(this,ha)}_${Ge(this,sl)._++}`,refCounter:0,isSvg:!1});let i;if(typeof e=="string"?(s.url=e,i=await Uu(e,"blob")):e instanceof File?i=s.file=e:e instanceof Blob&&(i=e),i.type==="image/svg+xml"){const n=zg._isSVGFittingCanvas,r=new FileReader,o=new Image,h=new Promise((c,u)=>{o.onload=()=>{s.bitmap=o,s.isSvg=!0,c()},r.onload=async()=>{const d=s.svgUrl=r.result;o.src=await n?`${d}#svgView(preserveAspectRatio(none))`:d},o.onerror=r.onerror=u});r.readAsDataURL(i),await h}else s.bitmap=await createImageBitmap(i);s.refCounter=1}catch(i){tt(i),s=null}return l(this,we).set(t,s),s&&l(this,we).set(s.id,s),s};let yg=zg;class px{constructor(t=128){y(this,Bt,[]);y(this,jn,!1);y(this,il);y(this,Dt,-1);m(this,il,t)}add({cmd:t,undo:e,post:s,mustExec:i,type:n=NaN,overwriteIfSameType:r=!1,keepUndo:o=!1}){if(i&&t(),l(this,jn))return;const h={cmd:t,undo:e,post:s,type:n};if(l(this,Dt)===-1){l(this,Bt).length>0&&(l(this,Bt).length=0),m(this,Dt,0),l(this,Bt).push(h);return}if(r&&l(this,Bt)[l(this,Dt)].type===n){o&&(h.undo=l(this,Bt)[l(this,Dt)].undo),l(this,Bt)[l(this,Dt)]=h;return}const c=l(this,Dt)+1;c===l(this,il)?l(this,Bt).splice(0,1):(m(this,Dt,c),c<l(this,Bt).length&&l(this,Bt).splice(c)),l(this,Bt).push(h)}undo(){if(l(this,Dt)===-1)return;m(this,jn,!0);const{undo:t,post:e}=l(this,Bt)[l(this,Dt)];t(),e==null||e(),m(this,jn,!1),m(this,Dt,l(this,Dt)-1)}redo(){if(l(this,Dt)<l(this,Bt).length-1){m(this,Dt,l(this,Dt)+1),m(this,jn,!0);const{cmd:t,post:e}=l(this,Bt)[l(this,Dt)];t(),e==null||e(),m(this,jn,!1)}}hasSomethingToUndo(){return l(this,Dt)!==-1}hasSomethingToRedo(){return l(this,Dt)<l(this,Bt).length-1}cleanType(t){if(l(this,Dt)!==-1){for(let e=l(this,Dt);e>=0;e--)if(l(this,Bt)[e].type!==t){l(this,Bt).splice(e+1,l(this,Dt)-e),m(this,Dt,e);return}l(this,Bt).length=0,m(this,Dt,-1)}}destroy(){m(this,Bt,null)}}Bt=new WeakMap,jn=new WeakMap,il=new WeakMap,Dt=new WeakMap;class Xh{constructor(t){y(this,ld);this.buffer=[],this.callbacks=new Map,this.allKeys=new Set;const{isMac:e}=Re.platform;for(const[s,i,n={}]of t)for(const r of s){const o=r.startsWith("mac+");e&&o?(this.callbacks.set(r.slice(4),{callback:i,options:n}),this.allKeys.add(r.split("+").at(-1))):!e&&!o&&(this.callbacks.set(r,{callback:i,options:n}),this.allKeys.add(r.split("+").at(-1)))}}exec(t,e){if(!this.allKeys.has(e.key))return;const s=this.callbacks.get(w(this,ld,ey).call(this,e));if(!s)return;const{callback:i,options:{bubbles:n=!1,args:r=[],checker:o=null}}=s;o&&!o(t,e)||(i.bind(t,...r,e)(),n||es(e))}}ld=new WeakSet,ey=function(t){t.altKey&&this.buffer.push("alt"),t.ctrlKey&&this.buffer.push("ctrl"),t.metaKey&&this.buffer.push("meta"),t.shiftKey&&this.buffer.push("shift"),this.buffer.push(t.key);const e=this.buffer.join("+");return this.buffer.length=0,e};const cd=class cd{get _colors(){const t=new Map([["CanvasText",null],["Canvas",null]]);return dx(t),st(this,"_colors",t)}convert(t){const e=pg(t);if(!window.matchMedia("(forced-colors: active)").matches)return e;for(const[s,i]of this._colors)if(i.every((n,r)=>n===e[r]))return cd._colorsMapping.get(s);return e}getHexCode(t){const e=this._colors.get(t);return e?X.makeHexColor(...e):t}};$(cd,"_colorsMapping",new Map([["CanvasText",[0,0,0]],["Canvas",[255,255,255]]]));let vg=cd;const ma=class ma{constructor(t,e,s,i,n,r,o,h,c,u,d,f,g){y(this,I);y(this,ca,new AbortController);y(this,ss,null);y(this,Kt,new Map);y(this,ae,new Map);y(this,ua,null);y(this,Ui,null);y(this,da,null);y(this,ws,new px);y(this,Bn,null);y(this,Nr,null);y(this,fa,0);y(this,jr,new Set);y(this,ui,null);y(this,Vs,null);y(this,Br,new Set);$(this,"_editorUndoBar",null);y(this,nl,!1);y(this,rl,!1);y(this,ga,!1);y(this,ol,null);y(this,di,null);y(this,Hn,null);y(this,pa,null);y(this,Gn,!1);y(this,fi,null);y(this,ud,new gx);y(this,zn,!1);y(this,al,!1);y(this,Vn,null);y(this,Hr,null);y(this,hl,null);y(this,ll,null);y(this,ee,Z.NONE);y(this,pt,new Set);y(this,Yi,null);y(this,Gr,null);y(this,cl,null);y(this,ul,{isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1});y(this,Xn,[0,0]);y(this,gi,null);y(this,$i,null);y(this,dl,null);y(this,xs,null);const p=this._signal=l(this,ca).signal;m(this,$i,t),m(this,dl,e),m(this,ua,s),this._eventBus=i,i._on("editingaction",this.onEditingAction.bind(this),{signal:p}),i._on("pagechanging",this.onPageChanging.bind(this),{signal:p}),i._on("scalechanging",this.onScaleChanging.bind(this),{signal:p}),i._on("rotationchanging",this.onRotationChanging.bind(this),{signal:p}),i._on("setpreference",this.onSetPreference.bind(this),{signal:p}),i._on("switchannotationeditorparams",b=>this.updateParams(b.type,b.value),{signal:p}),w(this,I,ny).call(this),w(this,I,hy).call(this),w(this,I,Jg).call(this),m(this,Ui,n.annotationStorage),m(this,ol,n.filterFactory),m(this,Gr,r),m(this,pa,o||null),m(this,nl,h),m(this,rl,c),m(this,ga,u),m(this,ll,d||null),this.viewParameters={realScale:Ln.PDF_TO_CSS_UNITS,rotation:0},this.isShiftKeyDown=!1,this._editorUndoBar=f||null,this._supportsPinchToZoom=g!==!1}static get _keyboardManager(){const t=ma.prototype,e=r=>l(r,$i).contains(document.activeElement)&&document.activeElement.tagName!=="BUTTON"&&r.hasSomethingToControl(),s=(r,{target:o})=>{if(o instanceof HTMLInputElement){const{type:h}=o;return h!=="text"&&h!=="number"}return!0},i=this.TRANSLATE_SMALL,n=this.TRANSLATE_BIG;return st(this,"_keyboardManager",new Xh([[["ctrl+a","mac+meta+a"],t.selectAll,{checker:s}],[["ctrl+z","mac+meta+z"],t.undo,{checker:s}],[["ctrl+y","ctrl+shift+z","mac+meta+shift+z","ctrl+shift+Z","mac+meta+shift+Z"],t.redo,{checker:s}],[["Backspace","alt+Backspace","ctrl+Backspace","shift+Backspace","mac+Backspace","mac+alt+Backspace","mac+ctrl+Backspace","Delete","ctrl+Delete","shift+Delete","mac+Delete"],t.delete,{checker:s}],[["Enter","mac+Enter"],t.addNewEditorFromKeyboard,{checker:(r,{target:o})=>!(o instanceof HTMLButtonElement)&&l(r,$i).contains(o)&&!r.isEnterHandled}],[[" ","mac+ "],t.addNewEditorFromKeyboard,{checker:(r,{target:o})=>!(o instanceof HTMLButtonElement)&&l(r,$i).contains(document.activeElement)}],[["Escape","mac+Escape"],t.unselectAll],[["ArrowLeft","mac+ArrowLeft"],t.translateSelectedEditors,{args:[-i,0],checker:e}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],t.translateSelectedEditors,{args:[-n,0],checker:e}],[["ArrowRight","mac+ArrowRight"],t.translateSelectedEditors,{args:[i,0],checker:e}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],t.translateSelectedEditors,{args:[n,0],checker:e}],[["ArrowUp","mac+ArrowUp"],t.translateSelectedEditors,{args:[0,-i],checker:e}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],t.translateSelectedEditors,{args:[0,-n],checker:e}],[["ArrowDown","mac+ArrowDown"],t.translateSelectedEditors,{args:[0,i],checker:e}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],t.translateSelectedEditors,{args:[0,n],checker:e}]]))}destroy(){var t,e,s,i,n;(t=l(this,xs))==null||t.resolve(),m(this,xs,null),(e=l(this,ca))==null||e.abort(),m(this,ca,null),this._signal=null;for(const r of l(this,ae).values())r.destroy();l(this,ae).clear(),l(this,Kt).clear(),l(this,Br).clear(),m(this,ss,null),l(this,pt).clear(),l(this,ws).destroy(),(s=l(this,ua))==null||s.destroy(),(i=l(this,fi))==null||i.hide(),m(this,fi,null),l(this,di)&&(clearTimeout(l(this,di)),m(this,di,null)),l(this,gi)&&(clearTimeout(l(this,gi)),m(this,gi,null)),(n=this._editorUndoBar)==null||n.destroy()}combinedSignal(t){return AbortSignal.any([this._signal,t.signal])}get mlManager(){return l(this,ll)}get useNewAltTextFlow(){return l(this,rl)}get useNewAltTextWhenAddingImage(){return l(this,ga)}get hcmFilter(){return st(this,"hcmFilter",l(this,Gr)?l(this,ol).addHCMFilter(l(this,Gr).foreground,l(this,Gr).background):"none")}get direction(){return st(this,"direction",getComputedStyle(l(this,$i)).direction)}get highlightColors(){return st(this,"highlightColors",l(this,pa)?new Map(l(this,pa).split(",").map(t=>t.split("=").map(e=>e.trim()))):null)}get highlightColorNames(){return st(this,"highlightColorNames",this.highlightColors?new Map(Array.from(this.highlightColors,t=>t.reverse())):null)}setCurrentDrawingSession(t){t?(this.unselectAll(),this.disableUserSelect(!0)):this.disableUserSelect(!1),m(this,Nr,t)}setMainHighlightColorPicker(t){m(this,hl,t)}editAltText(t,e=!1){var s;(s=l(this,ua))==null||s.editAltText(this,t,e)}switchToMode(t,e){this._eventBus.on("annotationeditormodechanged",e,{once:!0,signal:this._signal}),this._eventBus.dispatch("showannotationeditorui",{source:this,mode:t})}setPreference(t,e){this._eventBus.dispatch("setpreference",{source:this,name:t,value:e})}onSetPreference({name:t,value:e}){switch(t){case"enableNewAltTextWhenAddingImage":m(this,ga,e);break}}onPageChanging({pageNumber:t}){m(this,fa,t-1)}focusMainContainer(){l(this,$i).focus()}findParent(t,e){for(const s of l(this,ae).values()){const{x:i,y:n,width:r,height:o}=s.div.getBoundingClientRect();if(t>=i&&t<=i+r&&e>=n&&e<=n+o)return s}return null}disableUserSelect(t=!1){l(this,dl).classList.toggle("noUserSelect",t)}addShouldRescale(t){l(this,Br).add(t)}removeShouldRescale(t){l(this,Br).delete(t)}onScaleChanging({scale:t}){var e;this.commitOrRemove(),this.viewParameters.realScale=t*Ln.PDF_TO_CSS_UNITS;for(const s of l(this,Br))s.onScaleChanging();(e=l(this,Nr))==null||e.onScaleChanging()}onRotationChanging({pagesRotation:t}){this.commitOrRemove(),this.viewParameters.rotation=t}highlightSelection(t=""){const e=document.getSelection();if(!e||e.isCollapsed)return;const{anchorNode:s,anchorOffset:i,focusNode:n,focusOffset:r}=e,o=e.toString(),c=w(this,I,Pd).call(this,e).closest(".textLayer"),u=this.getSelectionBoxes(c);if(!u)return;e.empty();const d=w(this,I,Qg).call(this,c),f=l(this,ee)===Z.NONE,g=()=>{d==null||d.createAndAddNewEditor({x:0,y:0},!1,{methodOfCreation:t,boxes:u,anchorNode:s,anchorOffset:i,focusNode:n,focusOffset:r,text:o}),f&&this.showAllEditors("highlight",!0,!0)};if(f){this.switchToMode(Z.HIGHLIGHT,g);return}g()}addToAnnotationStorage(t){!t.isEmpty()&&l(this,Ui)&&!l(this,Ui).has(t.id)&&l(this,Ui).setValue(t.id,t)}blur(){if(this.isShiftKeyDown=!1,l(this,Gn)&&(m(this,Gn,!1),w(this,I,Dd).call(this,"main_toolbar")),!this.hasSelection)return;const{activeElement:t}=document;for(const e of l(this,pt))if(e.div.contains(t)){m(this,Hr,[e,t]),e._focusEventsAllowed=!1;break}}focus(){if(!l(this,Hr))return;const[t,e]=l(this,Hr);m(this,Hr,null),e.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this._signal}),e.focus()}addEditListeners(){w(this,I,Jg).call(this),w(this,I,Zg).call(this)}removeEditListeners(){w(this,I,ay).call(this),w(this,I,tp).call(this)}dragOver(t){for(const{type:e}of t.dataTransfer.items)for(const s of l(this,Vs))if(s.isHandlingMimeForPasting(e)){t.dataTransfer.dropEffect="copy",t.preventDefault();return}}drop(t){for(const e of t.dataTransfer.items)for(const s of l(this,Vs))if(s.isHandlingMimeForPasting(e.type)){s.paste(e,this.currentLayer),t.preventDefault();return}}copy(t){var s;if(t.preventDefault(),(s=l(this,ss))==null||s.commitOrRemove(),!this.hasSelection)return;const e=[];for(const i of l(this,pt)){const n=i.serialize(!0);n&&e.push(n)}e.length!==0&&t.clipboardData.setData("application/pdfjs",JSON.stringify(e))}cut(t){this.copy(t),this.delete()}async paste(t){t.preventDefault();const{clipboardData:e}=t;for(const n of e.items)for(const r of l(this,Vs))if(r.isHandlingMimeForPasting(n.type)){r.paste(n,this.currentLayer);return}let s=e.getData("application/pdfjs");if(!s)return;try{s=JSON.parse(s)}catch(n){tt(`paste: "${n.message}".`);return}if(!Array.isArray(s))return;this.unselectAll();const i=this.currentLayer;try{const n=[];for(const h of s){const c=await i.deserialize(h);if(!c)return;n.push(c)}const r=()=>{for(const h of n)w(this,I,ep).call(this,h);w(this,I,sp).call(this,n)},o=()=>{for(const h of n)h.remove()};this.addCommands({cmd:r,undo:o,mustExec:!0})}catch(n){tt(`paste: "${n.message}".`)}}keydown(t){!this.isShiftKeyDown&&t.key==="Shift"&&(this.isShiftKeyDown=!0),l(this,ee)!==Z.NONE&&!this.isEditorHandlingKeyboard&&ma._keyboardManager.exec(this,t)}keyup(t){this.isShiftKeyDown&&t.key==="Shift"&&(this.isShiftKeyDown=!1,l(this,Gn)&&(m(this,Gn,!1),w(this,I,Dd).call(this,"main_toolbar")))}onEditingAction({name:t}){switch(t){case"undo":case"redo":case"delete":case"selectAll":this[t]();break;case"highlightSelection":this.highlightSelection("context_menu");break}}setEditingState(t){t?(w(this,I,ry).call(this),w(this,I,Zg).call(this),w(this,I,ze).call(this,{isEditing:l(this,ee)!==Z.NONE,isEmpty:w(this,I,Cc).call(this),hasSomethingToUndo:l(this,ws).hasSomethingToUndo(),hasSomethingToRedo:l(this,ws).hasSomethingToRedo(),hasSelectedEditor:!1})):(w(this,I,oy).call(this),w(this,I,tp).call(this),w(this,I,ze).call(this,{isEditing:!1}),this.disableUserSelect(!1))}registerEditorTypes(t){if(!l(this,Vs)){m(this,Vs,t);for(const e of l(this,Vs))w(this,I,xn).call(this,e.defaultPropertiesToUpdate)}}getId(){return l(this,ud).id}get currentLayer(){return l(this,ae).get(l(this,fa))}getLayer(t){return l(this,ae).get(t)}get currentPageIndex(){return l(this,fa)}addLayer(t){l(this,ae).set(t.pageIndex,t),l(this,zn)?t.enable():t.disable()}removeLayer(t){l(this,ae).delete(t.pageIndex)}async updateMode(t,e=null,s=!1){var i;if(l(this,ee)!==t&&!(l(this,xs)&&(await l(this,xs).promise,!l(this,xs)))){if(m(this,xs,Promise.withResolvers()),m(this,ee,t),t===Z.NONE){this.setEditingState(!1),w(this,I,cy).call(this),(i=this._editorUndoBar)==null||i.hide(),l(this,xs).resolve();return}this.setEditingState(!0),await w(this,I,ly).call(this),this.unselectAll();for(const n of l(this,ae).values())n.updateMode(t);if(!e){s&&this.addNewEditorFromKeyboard(),l(this,xs).resolve();return}for(const n of l(this,Kt).values())n.annotationElementId===e?(this.setSelected(n),n.enterInEditMode()):n.unselect();l(this,xs).resolve()}}addNewEditorFromKeyboard(){this.currentLayer.canCreateNewEmptyEditor()&&this.currentLayer.addNewEditor()}updateToolbar(t){t!==l(this,ee)&&this._eventBus.dispatch("switchannotationeditormode",{source:this,mode:t})}updateParams(t,e){var s;if(l(this,Vs)){switch(t){case ot.CREATE:this.currentLayer.addNewEditor();return;case ot.HIGHLIGHT_DEFAULT_COLOR:(s=l(this,hl))==null||s.updateColor(e);break;case ot.HIGHLIGHT_SHOW_ALL:this._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:{type:"highlight",action:"toggle_visibility"}}}),(l(this,cl)||m(this,cl,new Map)).set(t,e),this.showAllEditors("highlight",e);break}for(const i of l(this,pt))i.updateParams(t,e);for(const i of l(this,Vs))i.updateDefaultParams(t,e)}}showAllEditors(t,e,s=!1){var n;for(const r of l(this,Kt).values())r.editorType===t&&r.show(e);(((n=l(this,cl))==null?void 0:n.get(ot.HIGHLIGHT_SHOW_ALL))??!0)!==e&&w(this,I,xn).call(this,[[ot.HIGHLIGHT_SHOW_ALL,e]])}enableWaiting(t=!1){if(l(this,al)!==t){m(this,al,t);for(const e of l(this,ae).values())t?e.disableClick():e.enableClick(),e.div.classList.toggle("waiting",t)}}getEditors(t){const e=[];for(const s of l(this,Kt).values())s.pageIndex===t&&e.push(s);return e}getEditor(t){return l(this,Kt).get(t)}addEditor(t){l(this,Kt).set(t.id,t)}removeEditor(t){var e;t.div.contains(document.activeElement)&&(l(this,di)&&clearTimeout(l(this,di)),m(this,di,setTimeout(()=>{this.focusMainContainer(),m(this,di,null)},0))),l(this,Kt).delete(t.id),this.unselect(t),(!t.annotationElementId||!l(this,jr).has(t.annotationElementId))&&((e=l(this,Ui))==null||e.remove(t.id))}addDeletedAnnotationElement(t){l(this,jr).add(t.annotationElementId),this.addChangedExistingAnnotation(t),t.deleted=!0}isDeletedAnnotationElement(t){return l(this,jr).has(t)}removeDeletedAnnotationElement(t){l(this,jr).delete(t.annotationElementId),this.removeChangedExistingAnnotation(t),t.deleted=!1}setActiveEditor(t){l(this,ss)!==t&&(m(this,ss,t),t&&w(this,I,xn).call(this,t.propertiesToUpdate))}updateUI(t){l(this,I,uy)===t&&w(this,I,xn).call(this,t.propertiesToUpdate)}updateUIForDefaultProperties(t){w(this,I,xn).call(this,t.defaultPropertiesToUpdate)}toggleSelected(t){if(l(this,pt).has(t)){l(this,pt).delete(t),t.unselect(),w(this,I,ze).call(this,{hasSelectedEditor:this.hasSelection});return}l(this,pt).add(t),t.select(),w(this,I,xn).call(this,t.propertiesToUpdate),w(this,I,ze).call(this,{hasSelectedEditor:!0})}setSelected(t){var e;(e=l(this,Nr))==null||e.commitOrRemove();for(const s of l(this,pt))s!==t&&s.unselect();l(this,pt).clear(),l(this,pt).add(t),t.select(),w(this,I,xn).call(this,t.propertiesToUpdate),w(this,I,ze).call(this,{hasSelectedEditor:!0})}isSelected(t){return l(this,pt).has(t)}get firstSelectedEditor(){return l(this,pt).values().next().value}unselect(t){t.unselect(),l(this,pt).delete(t),w(this,I,ze).call(this,{hasSelectedEditor:this.hasSelection})}get hasSelection(){return l(this,pt).size!==0}get isEnterHandled(){return l(this,pt).size===1&&this.firstSelectedEditor.isEnterHandled}undo(){var t;l(this,ws).undo(),w(this,I,ze).call(this,{hasSomethingToUndo:l(this,ws).hasSomethingToUndo(),hasSomethingToRedo:!0,isEmpty:w(this,I,Cc).call(this)}),(t=this._editorUndoBar)==null||t.hide()}redo(){l(this,ws).redo(),w(this,I,ze).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:l(this,ws).hasSomethingToRedo(),isEmpty:w(this,I,Cc).call(this)})}addCommands(t){l(this,ws).add(t),w(this,I,ze).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:!1,isEmpty:w(this,I,Cc).call(this)})}cleanUndoStack(t){l(this,ws).cleanType(t)}delete(){var n;this.commitOrRemove();const t=(n=this.currentLayer)==null?void 0:n.endDrawingSession(!0);if(!this.hasSelection&&!t)return;const e=t?[t]:[...l(this,pt)],s=()=>{var r;(r=this._editorUndoBar)==null||r.show(i,e.length===1?e[0].editorType:e.length);for(const o of e)o.remove()},i=()=>{for(const r of e)w(this,I,ep).call(this,r)};this.addCommands({cmd:s,undo:i,mustExec:!0})}commitOrRemove(){var t;(t=l(this,ss))==null||t.commitOrRemove()}hasSomethingToControl(){return l(this,ss)||this.hasSelection}selectAll(){for(const t of l(this,pt))t.commit();w(this,I,sp).call(this,l(this,Kt).values())}unselectAll(){var t;if(!(l(this,ss)&&(l(this,ss).commitOrRemove(),l(this,ee)!==Z.NONE))&&!((t=l(this,Nr))!=null&&t.commitOrRemove())&&this.hasSelection){for(const e of l(this,pt))e.unselect();l(this,pt).clear(),w(this,I,ze).call(this,{hasSelectedEditor:!1})}}translateSelectedEditors(t,e,s=!1){if(s||this.commitOrRemove(),!this.hasSelection)return;l(this,Xn)[0]+=t,l(this,Xn)[1]+=e;const[i,n]=l(this,Xn),r=[...l(this,pt)],o=1e3;l(this,gi)&&clearTimeout(l(this,gi)),m(this,gi,setTimeout(()=>{m(this,gi,null),l(this,Xn)[0]=l(this,Xn)[1]=0,this.addCommands({cmd:()=>{for(const h of r)l(this,Kt).has(h.id)&&h.translateInPage(i,n)},undo:()=>{for(const h of r)l(this,Kt).has(h.id)&&h.translateInPage(-i,-n)},mustExec:!1})},o));for(const h of r)h.translateInPage(t,e)}setUpDragSession(){if(this.hasSelection){this.disableUserSelect(!0),m(this,ui,new Map);for(const t of l(this,pt))l(this,ui).set(t,{savedX:t.x,savedY:t.y,savedPageIndex:t.pageIndex,newX:0,newY:0,newPageIndex:-1})}}endDragSession(){if(!l(this,ui))return!1;this.disableUserSelect(!1);const t=l(this,ui);m(this,ui,null);let e=!1;for(const[{x:i,y:n,pageIndex:r},o]of t)o.newX=i,o.newY=n,o.newPageIndex=r,e||(e=i!==o.savedX||n!==o.savedY||r!==o.savedPageIndex);if(!e)return!1;const s=(i,n,r,o)=>{if(l(this,Kt).has(i.id)){const h=l(this,ae).get(o);h?i._setParentAndPosition(h,n,r):(i.pageIndex=o,i.x=n,i.y=r)}};return this.addCommands({cmd:()=>{for(const[i,{newX:n,newY:r,newPageIndex:o}]of t)s(i,n,r,o)},undo:()=>{for(const[i,{savedX:n,savedY:r,savedPageIndex:o}]of t)s(i,n,r,o)},mustExec:!0}),!0}dragSelectedEditors(t,e){if(l(this,ui))for(const s of l(this,ui).keys())s.drag(t,e)}rebuild(t){if(t.parent===null){const e=this.getLayer(t.pageIndex);e?(e.changeParent(t),e.addOrRebuild(t)):(this.addEditor(t),this.addToAnnotationStorage(t),t.rebuild())}else t.parent.addOrRebuild(t)}get isEditorHandlingKeyboard(){var t;return((t=this.getActive())==null?void 0:t.shouldGetKeyboardEvents())||l(this,pt).size===1&&this.firstSelectedEditor.shouldGetKeyboardEvents()}isActive(t){return l(this,ss)===t}getActive(){return l(this,ss)}getMode(){return l(this,ee)}get imageManager(){return st(this,"imageManager",new yg)}getSelectionBoxes(t){if(!t)return null;const e=document.getSelection();for(let c=0,u=e.rangeCount;c<u;c++)if(!t.contains(e.getRangeAt(c).commonAncestorContainer))return null;const{x:s,y:i,width:n,height:r}=t.getBoundingClientRect();let o;switch(t.getAttribute("data-main-rotation")){case"90":o=(c,u,d,f)=>({x:(u-i)/r,y:1-(c+d-s)/n,width:f/r,height:d/n});break;case"180":o=(c,u,d,f)=>({x:1-(c+d-s)/n,y:1-(u+f-i)/r,width:d/n,height:f/r});break;case"270":o=(c,u,d,f)=>({x:1-(u+f-i)/r,y:(c-s)/n,width:f/r,height:d/n});break;default:o=(c,u,d,f)=>({x:(c-s)/n,y:(u-i)/r,width:d/n,height:f/r});break}const h=[];for(let c=0,u=e.rangeCount;c<u;c++){const d=e.getRangeAt(c);if(!d.collapsed)for(const{x:f,y:g,width:p,height:b}of d.getClientRects())p===0||b===0||h.push(o(f,g,p,b))}return h.length===0?null:h}addChangedExistingAnnotation({annotationElementId:t,id:e}){(l(this,da)||m(this,da,new Map)).set(t,e)}removeChangedExistingAnnotation({annotationElementId:t}){var e;(e=l(this,da))==null||e.delete(t)}renderAnnotationElement(t){var i;const e=(i=l(this,da))==null?void 0:i.get(t.data.id);if(!e)return;const s=l(this,Ui).getRawValue(e);s&&(l(this,ee)===Z.NONE&&!s.hasBeenModified||s.renderAnnotationElement(t))}};ca=new WeakMap,ss=new WeakMap,Kt=new WeakMap,ae=new WeakMap,ua=new WeakMap,Ui=new WeakMap,da=new WeakMap,ws=new WeakMap,Bn=new WeakMap,Nr=new WeakMap,fa=new WeakMap,jr=new WeakMap,ui=new WeakMap,Vs=new WeakMap,Br=new WeakMap,nl=new WeakMap,rl=new WeakMap,ga=new WeakMap,ol=new WeakMap,di=new WeakMap,Hn=new WeakMap,pa=new WeakMap,Gn=new WeakMap,fi=new WeakMap,ud=new WeakMap,zn=new WeakMap,al=new WeakMap,Vn=new WeakMap,Hr=new WeakMap,hl=new WeakMap,ll=new WeakMap,ee=new WeakMap,pt=new WeakMap,Yi=new WeakMap,Gr=new WeakMap,cl=new WeakMap,ul=new WeakMap,Xn=new WeakMap,gi=new WeakMap,$i=new WeakMap,dl=new WeakMap,xs=new WeakMap,I=new WeakSet,Pd=function({anchorNode:t}){return t.nodeType===Node.TEXT_NODE?t.parentElement:t},Qg=function(t){const{currentLayer:e}=this;if(e.hasTextLayer(t))return e;for(const s of l(this,ae).values())if(s.hasTextLayer(t))return s;return null},sy=function(){const t=document.getSelection();if(!t||t.isCollapsed)return;const s=w(this,I,Pd).call(this,t).closest(".textLayer"),i=this.getSelectionBoxes(s);i&&(l(this,fi)||m(this,fi,new fx(this)),l(this,fi).show(s,i,this.direction==="ltr"))},iy=function(){var n,r,o;const t=document.getSelection();if(!t||t.isCollapsed){l(this,Yi)&&((n=l(this,fi))==null||n.hide(),m(this,Yi,null),w(this,I,ze).call(this,{hasSelectedText:!1}));return}const{anchorNode:e}=t;if(e===l(this,Yi))return;const i=w(this,I,Pd).call(this,t).closest(".textLayer");if(!i){l(this,Yi)&&((r=l(this,fi))==null||r.hide(),m(this,Yi,null),w(this,I,ze).call(this,{hasSelectedText:!1}));return}if((o=l(this,fi))==null||o.hide(),m(this,Yi,e),w(this,I,ze).call(this,{hasSelectedText:!0}),!(l(this,ee)!==Z.HIGHLIGHT&&l(this,ee)!==Z.NONE)&&(l(this,ee)===Z.HIGHLIGHT&&this.showAllEditors("highlight",!0,!0),m(this,Gn,this.isShiftKeyDown),!this.isShiftKeyDown)){const h=l(this,ee)===Z.HIGHLIGHT?w(this,I,Qg).call(this,i):null;h==null||h.toggleDrawing();const c=new AbortController,u=this.combinedSignal(c),d=f=>{f.type==="pointerup"&&f.button!==0||(c.abort(),h==null||h.toggleDrawing(!0),f.type==="pointerup"&&w(this,I,Dd).call(this,"main_toolbar"))};window.addEventListener("pointerup",d,{signal:u}),window.addEventListener("blur",d,{signal:u})}},Dd=function(t=""){l(this,ee)===Z.HIGHLIGHT?this.highlightSelection(t):l(this,nl)&&w(this,I,sy).call(this)},ny=function(){document.addEventListener("selectionchange",w(this,I,iy).bind(this),{signal:this._signal})},ry=function(){if(l(this,Hn))return;m(this,Hn,new AbortController);const t=this.combinedSignal(l(this,Hn));window.addEventListener("focus",this.focus.bind(this),{signal:t}),window.addEventListener("blur",this.blur.bind(this),{signal:t})},oy=function(){var t;(t=l(this,Hn))==null||t.abort(),m(this,Hn,null)},Jg=function(){if(l(this,Vn))return;m(this,Vn,new AbortController);const t=this.combinedSignal(l(this,Vn));window.addEventListener("keydown",this.keydown.bind(this),{signal:t}),window.addEventListener("keyup",this.keyup.bind(this),{signal:t})},ay=function(){var t;(t=l(this,Vn))==null||t.abort(),m(this,Vn,null)},Zg=function(){if(l(this,Bn))return;m(this,Bn,new AbortController);const t=this.combinedSignal(l(this,Bn));document.addEventListener("copy",this.copy.bind(this),{signal:t}),document.addEventListener("cut",this.cut.bind(this),{signal:t}),document.addEventListener("paste",this.paste.bind(this),{signal:t})},tp=function(){var t;(t=l(this,Bn))==null||t.abort(),m(this,Bn,null)},hy=function(){const t=this._signal;document.addEventListener("dragover",this.dragOver.bind(this),{signal:t}),document.addEventListener("drop",this.drop.bind(this),{signal:t})},ze=function(t){Object.entries(t).some(([s,i])=>l(this,ul)[s]!==i)&&(this._eventBus.dispatch("annotationeditorstateschanged",{source:this,details:Object.assign(l(this,ul),t)}),l(this,ee)===Z.HIGHLIGHT&&t.hasSelectedEditor===!1&&w(this,I,xn).call(this,[[ot.HIGHLIGHT_FREE,!0]]))},xn=function(t){this._eventBus.dispatch("annotationeditorparamschanged",{source:this,details:t})},ly=async function(){if(!l(this,zn)){m(this,zn,!0);const t=[];for(const e of l(this,ae).values())t.push(e.enable());await Promise.all(t);for(const e of l(this,Kt).values())e.enable()}},cy=function(){if(this.unselectAll(),l(this,zn)){m(this,zn,!1);for(const t of l(this,ae).values())t.disable();for(const t of l(this,Kt).values())t.disable()}},ep=function(t){const e=l(this,ae).get(t.pageIndex);e?e.addOrRebuild(t):(this.addEditor(t),this.addToAnnotationStorage(t))},uy=function(){let t=null;for(t of l(this,pt));return t},Cc=function(){if(l(this,Kt).size===0)return!0;if(l(this,Kt).size===1)for(const t of l(this,Kt).values())return t.isEmpty();return!1},sp=function(t){for(const e of l(this,pt))e.unselect();l(this,pt).clear();for(const e of t)e.isEmpty()||(l(this,pt).add(e),e.select());w(this,I,ze).call(this,{hasSelectedEditor:this.hasSelection})},$(ma,"TRANSLATE_SMALL",1),$(ma,"TRANSLATE_BIG",10);let Mr=ma;const Fe=class Fe{constructor(t){y(this,Ws);y(this,se,null);y(this,pi,!1);y(this,Xs,null);y(this,ba,null);y(this,mi,null);y(this,is,null);y(this,ya,!1);y(this,bi,null);y(this,$e,null);y(this,qi,null);y(this,zr,null);y(this,yi,!1);m(this,$e,t),m(this,yi,t._uiManager.useNewAltTextFlow),l(Fe,Wn)||m(Fe,Wn,Object.freeze({added:"pdfjs-editor-new-alt-text-added-button","added-label":"pdfjs-editor-new-alt-text-added-button-label",missing:"pdfjs-editor-new-alt-text-missing-button","missing-label":"pdfjs-editor-new-alt-text-missing-button-label",review:"pdfjs-editor-new-alt-text-to-review-button","review-label":"pdfjs-editor-new-alt-text-to-review-button-label"}))}static initialize(t){Fe._l10n??(Fe._l10n=t)}async render(){const t=m(this,Xs,document.createElement("button"));t.className="altText",t.tabIndex="0";const e=m(this,ba,document.createElement("span"));t.append(e),l(this,yi)?(t.classList.add("new"),t.setAttribute("data-l10n-id",l(Fe,Wn).missing),e.setAttribute("data-l10n-id",l(Fe,Wn)["missing-label"])):(t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button"),e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button-label"));const s=l(this,$e)._uiManager._signal;t.addEventListener("contextmenu",Gs,{signal:s}),t.addEventListener("pointerdown",n=>n.stopPropagation(),{signal:s});const i=n=>{n.preventDefault(),l(this,$e)._uiManager.editAltText(l(this,$e)),l(this,yi)&&l(this,$e)._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_clicked",data:{label:l(this,Ws,Ac)}})};return t.addEventListener("click",i,{capture:!0,signal:s}),t.addEventListener("keydown",n=>{n.target===t&&n.key==="Enter"&&(m(this,ya,!0),i(n))},{signal:s}),await w(this,Ws,Od).call(this),t}finish(){l(this,Xs)&&(l(this,Xs).focus({focusVisible:l(this,ya)}),m(this,ya,!1))}isEmpty(){return l(this,yi)?l(this,se)===null:!l(this,se)&&!l(this,pi)}hasData(){return l(this,yi)?l(this,se)!==null||!!l(this,qi):this.isEmpty()}get guessedText(){return l(this,qi)}async setGuessedText(t){l(this,se)===null&&(m(this,qi,t),m(this,zr,await Fe._l10n.get("pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer",{generatedAltText:t})),w(this,Ws,Od).call(this))}toggleAltTextBadge(t=!1){var e;if(!l(this,yi)||l(this,se)){(e=l(this,bi))==null||e.remove(),m(this,bi,null);return}if(!l(this,bi)){const s=m(this,bi,document.createElement("div"));s.className="noAltTextBadge",l(this,$e).div.append(s)}l(this,bi).classList.toggle("hidden",!t)}serialize(t){let e=l(this,se);return!t&&l(this,qi)===e&&(e=l(this,zr)),{altText:e,decorative:l(this,pi),guessedText:l(this,qi),textWithDisclaimer:l(this,zr)}}get data(){return{altText:l(this,se),decorative:l(this,pi)}}set data({altText:t,decorative:e,guessedText:s,textWithDisclaimer:i,cancel:n=!1}){s&&(m(this,qi,s),m(this,zr,i)),!(l(this,se)===t&&l(this,pi)===e)&&(n||(m(this,se,t),m(this,pi,e)),w(this,Ws,Od).call(this))}toggle(t=!1){l(this,Xs)&&(!t&&l(this,is)&&(clearTimeout(l(this,is)),m(this,is,null)),l(this,Xs).disabled=!t)}shown(){l(this,$e)._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_displayed",data:{label:l(this,Ws,Ac)}})}destroy(){var t,e;(t=l(this,Xs))==null||t.remove(),m(this,Xs,null),m(this,ba,null),m(this,mi,null),(e=l(this,bi))==null||e.remove(),m(this,bi,null)}};se=new WeakMap,pi=new WeakMap,Xs=new WeakMap,ba=new WeakMap,mi=new WeakMap,is=new WeakMap,ya=new WeakMap,bi=new WeakMap,$e=new WeakMap,qi=new WeakMap,zr=new WeakMap,yi=new WeakMap,Wn=new WeakMap,Ws=new WeakSet,Ac=function(){return l(this,se)&&"added"||l(this,se)===null&&this.guessedText&&"review"||"missing"},Od=async function(){var i,n,r;const t=l(this,Xs);if(!t)return;if(l(this,yi)){if(t.classList.toggle("done",!!l(this,se)),t.setAttribute("data-l10n-id",l(Fe,Wn)[l(this,Ws,Ac)]),(i=l(this,ba))==null||i.setAttribute("data-l10n-id",l(Fe,Wn)[`${l(this,Ws,Ac)}-label`]),!l(this,se)){(n=l(this,mi))==null||n.remove();return}}else{if(!l(this,se)&&!l(this,pi)){t.classList.remove("done"),(r=l(this,mi))==null||r.remove();return}t.classList.add("done"),t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-edit-button")}let e=l(this,mi);if(!e){m(this,mi,e=document.createElement("span")),e.className="tooltip",e.setAttribute("role","tooltip"),e.id=`alt-text-tooltip-${l(this,$e).id}`;const o=100,h=l(this,$e)._uiManager._signal;h.addEventListener("abort",()=>{clearTimeout(l(this,is)),m(this,is,null)},{once:!0}),t.addEventListener("mouseenter",()=>{m(this,is,setTimeout(()=>{m(this,is,null),l(this,mi).classList.add("show"),l(this,$e)._reportTelemetry({action:"alt_text_tooltip"})},o))},{signal:h}),t.addEventListener("mouseleave",()=>{var c;l(this,is)&&(clearTimeout(l(this,is)),m(this,is,null)),(c=l(this,mi))==null||c.classList.remove("show")},{signal:h})}l(this,pi)?e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-decorative-tooltip"):(e.removeAttribute("data-l10n-id"),e.textContent=l(this,se)),e.parentNode||t.append(e);const s=l(this,$e).getImageForAltText();s==null||s.setAttribute("aria-describedby",e.id)},y(Fe,Wn,null),$(Fe,"_l10n",null);let qu=Fe;const Vg=class Vg{constructor({container:t,isPinchingDisabled:e=null,isPinchingStopped:s=null,onPinchStart:i=null,onPinching:n=null,onPinchEnd:r=null,signal:o}){y(this,Qi);y(this,fl);y(this,Vr,!1);y(this,gl,null);y(this,pl);y(this,ml);y(this,bl);y(this,yl);y(this,va);y(this,Ki,null);y(this,Xr);y(this,Un,null);m(this,fl,t),m(this,gl,s),m(this,pl,e),m(this,ml,i),m(this,bl,n),m(this,yl,r),m(this,Xr,new AbortController),m(this,va,AbortSignal.any([o,l(this,Xr).signal])),t.addEventListener("touchstart",w(this,Qi,dy).bind(this),{passive:!1,signal:l(this,va)})}get MIN_TOUCH_DISTANCE_TO_PINCH(){return st(this,"MIN_TOUCH_DISTANCE_TO_PINCH",35/(window.devicePixelRatio||1))}destroy(){var t;(t=l(this,Xr))==null||t.abort(),m(this,Xr,null)}};fl=new WeakMap,Vr=new WeakMap,gl=new WeakMap,pl=new WeakMap,ml=new WeakMap,bl=new WeakMap,yl=new WeakMap,va=new WeakMap,Ki=new WeakMap,Xr=new WeakMap,Un=new WeakMap,Qi=new WeakSet,dy=function(t){var i,n,r;if((i=l(this,pl))!=null&&i.call(this)||t.touches.length<2)return;if(!l(this,Un)){m(this,Un,new AbortController);const o=AbortSignal.any([l(this,va),l(this,Un).signal]),h=l(this,fl),c={signal:o,passive:!1};h.addEventListener("touchmove",w(this,Qi,fy).bind(this),c),h.addEventListener("touchend",w(this,Qi,ip).bind(this),c),h.addEventListener("touchcancel",w(this,Qi,ip).bind(this),c),(n=l(this,ml))==null||n.call(this)}if(es(t),t.touches.length!==2||(r=l(this,gl))!=null&&r.call(this)){m(this,Ki,null);return}let[e,s]=t.touches;e.identifier>s.identifier&&([e,s]=[s,e]),m(this,Ki,{touch0X:e.screenX,touch0Y:e.screenY,touch1X:s.screenX,touch1Y:s.screenY})},fy=function(t){var S;if(!l(this,Ki)||t.touches.length!==2)return;let[e,s]=t.touches;e.identifier>s.identifier&&([e,s]=[s,e]);const{screenX:i,screenY:n}=e,{screenX:r,screenY:o}=s,h=l(this,Ki),{touch0X:c,touch0Y:u,touch1X:d,touch1Y:f}=h,g=d-c,p=f-u,b=r-i,v=o-n,_=Math.hypot(b,v)||1,x=Math.hypot(g,p)||1;if(!l(this,Vr)&&Math.abs(x-_)<=Vg.MIN_TOUCH_DISTANCE_TO_PINCH)return;if(h.touch0X=i,h.touch0Y=n,h.touch1X=r,h.touch1Y=o,t.preventDefault(),!l(this,Vr)){m(this,Vr,!0);return}const C=[(i+r)/2,(n+o)/2];(S=l(this,bl))==null||S.call(this,C,x,_)},ip=function(t){var e;l(this,Un).abort(),m(this,Un,null),(e=l(this,yl))==null||e.call(this),l(this,Ki)&&(t.preventDefault(),m(this,Ki,null),m(this,Vr,!1))};let Ku=Vg;const et=class et{constructor(t){y(this,Y);y(this,Wr,null);y(this,Us,null);y(this,xt,null);y(this,_a,!1);y(this,Yn,null);y(this,vl,"");y(this,Ur,!1);y(this,he,null);y(this,Yr,null);y(this,Ji,null);y(this,$n,null);y(this,_l,"");y(this,$r,!1);y(this,ns,null);y(this,wl,!1);y(this,qr,!1);y(this,Zi,!1);y(this,vi,null);y(this,wa,0);y(this,xa,0);y(this,Ss,null);y(this,Kr,null);$(this,"_editToolbar",null);$(this,"_initialOptions",Object.create(null));$(this,"_initialData",null);$(this,"_isVisible",!0);$(this,"_uiManager",null);$(this,"_focusEventsAllowed",!0);y(this,xl,!1);y(this,dd,et._zIndex++);this.parent=t.parent,this.id=t.id,this.width=this.height=null,this.pageIndex=t.parent.pageIndex,this.name=t.name,this.div=null,this._uiManager=t.uiManager,this.annotationElementId=null,this._willKeepAspectRatio=!1,this._initialOptions.isCentered=t.isCentered,this._structTreeParentId=null;const{rotation:e,rawDims:{pageWidth:s,pageHeight:i,pageX:n,pageY:r}}=this.parent.viewport;this.rotation=e,this.pageRotation=(360+e-this._uiManager.viewParameters.rotation)%360,this.pageDimensions=[s,i],this.pageTranslation=[n,r];const[o,h]=this.parentDimensions;this.x=t.x/o,this.y=t.y/h,this.isAttachedToDOM=!1,this.deleted=!1}static get _resizerKeyboardManager(){const t=et.prototype._resizeWithKeyboard,e=Mr.TRANSLATE_SMALL,s=Mr.TRANSLATE_BIG;return st(this,"_resizerKeyboardManager",new Xh([[["ArrowLeft","mac+ArrowLeft"],t,{args:[-e,0]}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],t,{args:[-s,0]}],[["ArrowRight","mac+ArrowRight"],t,{args:[e,0]}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],t,{args:[s,0]}],[["ArrowUp","mac+ArrowUp"],t,{args:[0,-e]}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],t,{args:[0,-s]}],[["ArrowDown","mac+ArrowDown"],t,{args:[0,e]}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],t,{args:[0,s]}],[["Escape","mac+Escape"],et.prototype._stopResizingWithKeyboard]]))}get editorType(){return Object.getPrototypeOf(this).constructor._type}static get isDrawer(){return!1}static get _defaultLineColor(){return st(this,"_defaultLineColor",this._colorManager.getHexCode("CanvasText"))}static deleteAnnotationElement(t){const e=new mx({id:t.parent.getNextId(),parent:t.parent,uiManager:t._uiManager});e.annotationElementId=t.annotationElementId,e.deleted=!0,e._uiManager.addToAnnotationStorage(e)}static initialize(t,e){if(et._l10n??(et._l10n=t),et._l10nResizer||(et._l10nResizer=Object.freeze({topLeft:"pdfjs-editor-resizer-top-left",topMiddle:"pdfjs-editor-resizer-top-middle",topRight:"pdfjs-editor-resizer-top-right",middleRight:"pdfjs-editor-resizer-middle-right",bottomRight:"pdfjs-editor-resizer-bottom-right",bottomMiddle:"pdfjs-editor-resizer-bottom-middle",bottomLeft:"pdfjs-editor-resizer-bottom-left",middleLeft:"pdfjs-editor-resizer-middle-left"})),et._borderLineWidth!==-1)return;const s=getComputedStyle(document.documentElement);et._borderLineWidth=parseFloat(s.getPropertyValue("--outline-width"))||0}static updateDefaultParams(t,e){}static get defaultPropertiesToUpdate(){return[]}static isHandlingMimeForPasting(t){return!1}static paste(t,e){vt("Not implemented")}get propertiesToUpdate(){return[]}get _isDraggable(){return l(this,xl)}set _isDraggable(t){var e;m(this,xl,t),(e=this.div)==null||e.classList.toggle("draggable",t)}get isEnterHandled(){return!0}center(){const[t,e]=this.pageDimensions;switch(this.parentRotation){case 90:this.x-=this.height*e/(t*2),this.y+=this.width*t/(e*2);break;case 180:this.x+=this.width/2,this.y+=this.height/2;break;case 270:this.x+=this.height*e/(t*2),this.y-=this.width*t/(e*2);break;default:this.x-=this.width/2,this.y-=this.height/2;break}this.fixAndSetPosition()}addCommands(t){this._uiManager.addCommands(t)}get currentLayer(){return this._uiManager.currentLayer}setInBackground(){this.div.style.zIndex=0}setInForeground(){this.div.style.zIndex=l(this,dd)}setParent(t){t!==null?(this.pageIndex=t.pageIndex,this.pageDimensions=t.pageDimensions):w(this,Y,Tc).call(this),this.parent=t}focusin(t){this._focusEventsAllowed&&(l(this,$r)?m(this,$r,!1):this.parent.setSelected(this))}focusout(t){var s;if(!this._focusEventsAllowed||!this.isAttachedToDOM)return;const e=t.relatedTarget;e!=null&&e.closest(`#${this.id}`)||(t.preventDefault(),(s=this.parent)!=null&&s.isMultipleSelection||this.commitOrRemove())}commitOrRemove(){this.isEmpty()?this.remove():this.commit()}commit(){this.addToAnnotationStorage()}addToAnnotationStorage(){this._uiManager.addToAnnotationStorage(this)}setAt(t,e,s,i){const[n,r]=this.parentDimensions;[s,i]=this.screenToPageTranslation(s,i),this.x=(t+s)/n,this.y=(e+i)/r,this.fixAndSetPosition()}translate(t,e){w(this,Y,np).call(this,this.parentDimensions,t,e)}translateInPage(t,e){l(this,ns)||m(this,ns,[this.x,this.y,this.width,this.height]),w(this,Y,np).call(this,this.pageDimensions,t,e),this.div.scrollIntoView({block:"nearest"})}drag(t,e){l(this,ns)||m(this,ns,[this.x,this.y,this.width,this.height]);const{div:s,parentDimensions:[i,n]}=this;if(this.x+=t/i,this.y+=e/n,this.parent&&(this.x<0||this.x>1||this.y<0||this.y>1)){const{x:d,y:f}=this.div.getBoundingClientRect();this.parent.findNewParent(this,d,f)&&(this.x-=Math.floor(this.x),this.y-=Math.floor(this.y))}let{x:r,y:o}=this;const[h,c]=this.getBaseTranslation();r+=h,o+=c;const{style:u}=s;u.left=`${(100*r).toFixed(2)}%`,u.top=`${(100*o).toFixed(2)}%`,this._onTranslating(r,o),s.scrollIntoView({block:"nearest"})}_onTranslating(t,e){}_onTranslated(t,e){}get _hasBeenMoved(){return!!l(this,ns)&&(l(this,ns)[0]!==this.x||l(this,ns)[1]!==this.y)}get _hasBeenResized(){return!!l(this,ns)&&(l(this,ns)[2]!==this.width||l(this,ns)[3]!==this.height)}getBaseTranslation(){const[t,e]=this.parentDimensions,{_borderLineWidth:s}=et,i=s/t,n=s/e;switch(this.rotation){case 90:return[-i,n];case 180:return[i,n];case 270:return[i,-n];default:return[-i,-n]}}get _mustFixPosition(){return!0}fixAndSetPosition(t=this.rotation){const{div:{style:e},pageDimensions:[s,i]}=this;let{x:n,y:r,width:o,height:h}=this;if(o*=s,h*=i,n*=s,r*=i,this._mustFixPosition)switch(t){case 0:n=Math.max(0,Math.min(s-o,n)),r=Math.max(0,Math.min(i-h,r));break;case 90:n=Math.max(0,Math.min(s-h,n)),r=Math.min(i,Math.max(o,r));break;case 180:n=Math.min(s,Math.max(o,n)),r=Math.min(i,Math.max(h,r));break;case 270:n=Math.min(s,Math.max(h,n)),r=Math.max(0,Math.min(i-o,r));break}this.x=n/=s,this.y=r/=i;const[c,u]=this.getBaseTranslation();n+=c,r+=u,e.left=`${(100*n).toFixed(2)}%`,e.top=`${(100*r).toFixed(2)}%`,this.moveInDOM()}screenToPageTranslation(t,e){var s;return w(s=et,Sl,rp).call(s,t,e,this.parentRotation)}pageTranslationToScreen(t,e){var s;return w(s=et,Sl,rp).call(s,t,e,360-this.parentRotation)}get parentScale(){return this._uiManager.viewParameters.realScale}get parentRotation(){return(this._uiManager.viewParameters.rotation+this.pageRotation)%360}get parentDimensions(){const{parentScale:t,pageDimensions:[e,s]}=this;return[e*t,s*t]}setDims(t,e){const[s,i]=this.parentDimensions,{style:n}=this.div;n.width=`${(100*t/s).toFixed(2)}%`,l(this,Ur)||(n.height=`${(100*e/i).toFixed(2)}%`)}fixDims(){const{style:t}=this.div,{height:e,width:s}=t,i=s.endsWith("%"),n=!l(this,Ur)&&e.endsWith("%");if(i&&n)return;const[r,o]=this.parentDimensions;i||(t.width=`${(100*parseFloat(s)/r).toFixed(2)}%`),!l(this,Ur)&&!n&&(t.height=`${(100*parseFloat(e)/o).toFixed(2)}%`)}getInitialTranslation(){return[0,0]}_onResized(){}static _round(t){return Math.round(t*1e4)/1e4}_onResizing(){}altTextFinish(){var t;(t=l(this,xt))==null||t.finish()}async addEditToolbar(){return this._editToolbar||l(this,qr)?this._editToolbar:(this._editToolbar=new bg(this),this.div.append(this._editToolbar.render()),l(this,xt)&&await this._editToolbar.addAltText(l(this,xt)),this._editToolbar)}removeEditToolbar(){var t;this._editToolbar&&(this._editToolbar.remove(),this._editToolbar=null,(t=l(this,xt))==null||t.destroy())}addContainer(t){var s;const e=(s=this._editToolbar)==null?void 0:s.div;e?e.before(t):this.div.append(t)}getClientDimensions(){return this.div.getBoundingClientRect()}async addAltTextButton(){l(this,xt)||(qu.initialize(et._l10n),m(this,xt,new qu(this)),l(this,Wr)&&(l(this,xt).data=l(this,Wr),m(this,Wr,null)),await this.addEditToolbar())}get altTextData(){var t;return(t=l(this,xt))==null?void 0:t.data}set altTextData(t){l(this,xt)&&(l(this,xt).data=t)}get guessedAltText(){var t;return(t=l(this,xt))==null?void 0:t.guessedText}async setGuessedAltText(t){var e;await((e=l(this,xt))==null?void 0:e.setGuessedText(t))}serializeAltText(t){var e;return(e=l(this,xt))==null?void 0:e.serialize(t)}hasAltText(){return!!l(this,xt)&&!l(this,xt).isEmpty()}hasAltTextData(){var t;return((t=l(this,xt))==null?void 0:t.hasData())??!1}render(){var n;this.div=document.createElement("div"),this.div.setAttribute("data-editor-rotation",(360-this.rotation)%360),this.div.className=this.name,this.div.setAttribute("id",this.id),this.div.tabIndex=l(this,_a)?-1:0,this._isVisible||this.div.classList.add("hidden"),this.setInForeground(),w(this,Y,lp).call(this);const[t,e]=this.parentDimensions;this.parentRotation%180!==0&&(this.div.style.maxWidth=`${(100*e/t).toFixed(2)}%`,this.div.style.maxHeight=`${(100*t/e).toFixed(2)}%`);const[s,i]=this.getInitialTranslation();return this.translate(s,i),$u(this,this.div,["pointerdown"]),this.isResizable&&this._uiManager._supportsPinchToZoom&&(l(this,Kr)||m(this,Kr,new Ku({container:this.div,isPinchingDisabled:()=>!this.isSelected,onPinchStart:w(this,Y,my).bind(this),onPinching:w(this,Y,by).bind(this),onPinchEnd:w(this,Y,yy).bind(this),signal:this._uiManager._signal}))),(n=this._uiManager._editorUndoBar)==null||n.hide(),this.div}pointerdown(t){const{isMac:e}=Re.platform;if(t.button!==0||t.ctrlKey&&e){t.preventDefault();return}if(m(this,$r,!0),this._isDraggable){w(this,Y,vy).call(this,t);return}w(this,Y,hp).call(this,t)}get isSelected(){return this._uiManager.isSelected(this)}_onStartDragging(){}_onStopDragging(){}moveInDOM(){l(this,vi)&&clearTimeout(l(this,vi)),m(this,vi,setTimeout(()=>{var t;m(this,vi,null),(t=this.parent)==null||t.moveEditorInDOM(this)},0))}_setParentAndPosition(t,e,s){t.changeParent(this),this.x=e,this.y=s,this.fixAndSetPosition(),this._onTranslated()}getRect(t,e,s=this.rotation){const i=this.parentScale,[n,r]=this.pageDimensions,[o,h]=this.pageTranslation,c=t/i,u=e/i,d=this.x*n,f=this.y*r,g=this.width*n,p=this.height*r;switch(s){case 0:return[d+c+o,r-f-u-p+h,d+c+g+o,r-f-u+h];case 90:return[d+u+o,r-f+c+h,d+u+p+o,r-f+c+g+h];case 180:return[d-c-g+o,r-f+u+h,d-c+o,r-f+u+p+h];case 270:return[d-u-p+o,r-f-c-g+h,d-u+o,r-f-c+h];default:throw new Error("Invalid rotation")}}getRectInCurrentCoords(t,e){const[s,i,n,r]=t,o=n-s,h=r-i;switch(this.rotation){case 0:return[s,e-r,o,h];case 90:return[s,e-i,h,o];case 180:return[n,e-i,o,h];case 270:return[n,e-r,h,o];default:throw new Error("Invalid rotation")}}onceAdded(t){}isEmpty(){return!1}enableEditMode(){m(this,qr,!0)}disableEditMode(){m(this,qr,!1)}isInEditMode(){return l(this,qr)}shouldGetKeyboardEvents(){return l(this,Zi)}needsToBeRebuilt(){return this.div&&!this.isAttachedToDOM}get isOnScreen(){const{top:t,left:e,bottom:s,right:i}=this.getClientDimensions(),{innerHeight:n,innerWidth:r}=window;return e<r&&i>0&&t<n&&s>0}rebuild(){w(this,Y,lp).call(this)}rotate(t){}resize(){}serializeDeleted(){var t;return{id:this.annotationElementId,deleted:!0,pageIndex:this.pageIndex,popupRef:((t=this._initialData)==null?void 0:t.popupRef)||""}}serialize(t=!1,e=null){vt("An editor must be serializable")}static async deserialize(t,e,s){const i=new this.prototype.constructor({parent:e,id:e.getNextId(),uiManager:s});i.rotation=t.rotation,m(i,Wr,t.accessibilityData);const[n,r]=i.pageDimensions,[o,h,c,u]=i.getRectInCurrentCoords(t.rect,r);return i.x=o/n,i.y=h/r,i.width=c/n,i.height=u/r,i}get hasBeenModified(){return!!this.annotationElementId&&(this.deleted||this.serialize()!==null)}remove(){var t,e;if((t=l(this,$n))==null||t.abort(),m(this,$n,null),this.isEmpty()||this.commit(),this.parent?this.parent.remove(this):this._uiManager.removeEditor(this),l(this,vi)&&(clearTimeout(l(this,vi)),m(this,vi,null)),w(this,Y,Tc).call(this),this.removeEditToolbar(),l(this,Ss)){for(const s of l(this,Ss).values())clearTimeout(s);m(this,Ss,null)}this.parent=null,(e=l(this,Kr))==null||e.destroy(),m(this,Kr,null)}get isResizable(){return!1}makeResizable(){this.isResizable&&(w(this,Y,gy).call(this),l(this,he).classList.remove("hidden"),$u(this,this.div,["keydown"]))}get toolbarPosition(){return null}keydown(t){if(!this.isResizable||t.target!==this.div||t.key!=="Enter")return;this._uiManager.setSelected(this),m(this,Ji,{savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height});const e=l(this,he).children;if(!l(this,Us)){m(this,Us,Array.from(e));const r=w(this,Y,_y).bind(this),o=w(this,Y,wy).bind(this),h=this._uiManager._signal;for(const c of l(this,Us)){const u=c.getAttribute("data-resizer-name");c.setAttribute("role","spinbutton"),c.addEventListener("keydown",r,{signal:h}),c.addEventListener("blur",o,{signal:h}),c.addEventListener("focus",w(this,Y,xy).bind(this,u),{signal:h}),c.setAttribute("data-l10n-id",et._l10nResizer[u])}}const s=l(this,Us)[0];let i=0;for(const r of e){if(r===s)break;i++}const n=(360-this.rotation+this.parentRotation)%360/90*(l(this,Us).length/4);if(n!==i){if(n<i)for(let o=0;o<i-n;o++)l(this,he).append(l(this,he).firstChild);else if(n>i)for(let o=0;o<n-i;o++)l(this,he).firstChild.before(l(this,he).lastChild);let r=0;for(const o of e){const c=l(this,Us)[r++].getAttribute("data-resizer-name");o.setAttribute("data-l10n-id",et._l10nResizer[c])}}w(this,Y,cp).call(this,0),m(this,Zi,!0),l(this,he).firstChild.focus({focusVisible:!0}),t.preventDefault(),t.stopImmediatePropagation()}_resizeWithKeyboard(t,e){l(this,Zi)&&w(this,Y,ap).call(this,l(this,_l),{deltaX:t,deltaY:e,fromKeyboard:!0})}_stopResizingWithKeyboard(){w(this,Y,Tc).call(this),this.div.focus()}select(){var t,e,s;if(this.makeResizable(),(t=this.div)==null||t.classList.add("selectedEditor"),!this._editToolbar){this.addEditToolbar().then(()=>{var i,n;(i=this.div)!=null&&i.classList.contains("selectedEditor")&&((n=this._editToolbar)==null||n.show())});return}(e=this._editToolbar)==null||e.show(),(s=l(this,xt))==null||s.toggleAltTextBadge(!1)}unselect(){var t,e,s,i,n;(t=l(this,he))==null||t.classList.add("hidden"),(e=this.div)==null||e.classList.remove("selectedEditor"),(s=this.div)!=null&&s.contains(document.activeElement)&&this._uiManager.currentLayer.div.focus({preventScroll:!0}),(i=this._editToolbar)==null||i.hide(),(n=l(this,xt))==null||n.toggleAltTextBadge(!0)}updateParams(t,e){}disableEditing(){}enableEditing(){}enterInEditMode(){}getImageForAltText(){return null}get contentDiv(){return this.div}get isEditing(){return l(this,wl)}set isEditing(t){m(this,wl,t),this.parent&&(t?(this.parent.setSelected(this),this.parent.setActiveEditor(this)):this.parent.setActiveEditor(null))}setAspectRatio(t,e){m(this,Ur,!0);const s=t/e,{style:i}=this.div;i.aspectRatio=s,i.height="auto"}static get MIN_SIZE(){return 16}static canCreateNewEmptyEditor(){return!0}get telemetryInitialData(){return{action:"added"}}get telemetryFinalData(){return null}_reportTelemetry(t,e=!1){if(e){l(this,Ss)||m(this,Ss,new Map);const{action:s}=t;let i=l(this,Ss).get(s);i&&clearTimeout(i),i=setTimeout(()=>{this._reportTelemetry(t),l(this,Ss).delete(s),l(this,Ss).size===0&&m(this,Ss,null)},et._telemetryTimeout),l(this,Ss).set(s,i);return}t.type||(t.type=this.editorType),this._uiManager._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:t}})}show(t=this._isVisible){this.div.classList.toggle("hidden",!t),this._isVisible=t}enable(){this.div&&(this.div.tabIndex=0),m(this,_a,!1)}disable(){this.div&&(this.div.tabIndex=-1),m(this,_a,!0)}renderAnnotationElement(t){let e=t.container.querySelector(".annotationContent");if(!e)e=document.createElement("div"),e.classList.add("annotationContent",this.editorType),t.container.prepend(e);else if(e.nodeName==="CANVAS"){const s=e;e=document.createElement("div"),e.classList.add("annotationContent",this.editorType),s.before(e)}return e}resetAnnotationElement(t){const{firstChild:e}=t.container;(e==null?void 0:e.nodeName)==="DIV"&&e.classList.contains("annotationContent")&&e.remove()}};Wr=new WeakMap,Us=new WeakMap,xt=new WeakMap,_a=new WeakMap,Yn=new WeakMap,vl=new WeakMap,Ur=new WeakMap,he=new WeakMap,Yr=new WeakMap,Ji=new WeakMap,$n=new WeakMap,_l=new WeakMap,$r=new WeakMap,ns=new WeakMap,wl=new WeakMap,qr=new WeakMap,Zi=new WeakMap,vi=new WeakMap,wa=new WeakMap,xa=new WeakMap,Ss=new WeakMap,Kr=new WeakMap,xl=new WeakMap,dd=new WeakMap,Y=new WeakSet,np=function([t,e],s,i){[s,i]=this.screenToPageTranslation(s,i),this.x+=s/t,this.y+=i/e,this._onTranslating(this.x,this.y),this.fixAndSetPosition()},Sl=new WeakSet,rp=function(t,e,s){switch(s){case 90:return[e,-t];case 180:return[-t,-e];case 270:return[-e,t];default:return[t,e]}},Rd=function(t){switch(t){case 90:{const[e,s]=this.pageDimensions;return[0,-e/s,s/e,0]}case 180:return[-1,0,0,-1];case 270:{const[e,s]=this.pageDimensions;return[0,e/s,-s/e,0]}default:return[1,0,0,1]}},gy=function(){if(l(this,he))return;m(this,he,document.createElement("div")),l(this,he).classList.add("resizers");const t=this._willKeepAspectRatio?["topLeft","topRight","bottomRight","bottomLeft"]:["topLeft","topMiddle","topRight","middleRight","bottomRight","bottomMiddle","bottomLeft","middleLeft"],e=this._uiManager._signal;for(const s of t){const i=document.createElement("div");l(this,he).append(i),i.classList.add("resizer",s),i.setAttribute("data-resizer-name",s),i.addEventListener("pointerdown",w(this,Y,py).bind(this,s),{signal:e}),i.addEventListener("contextmenu",Gs,{signal:e}),i.tabIndex=-1}this.div.prepend(l(this,he))},py=function(t,e){var u;e.preventDefault();const{isMac:s}=Re.platform;if(e.button!==0||e.ctrlKey&&s)return;(u=l(this,xt))==null||u.toggle(!1);const i=this._isDraggable;this._isDraggable=!1,m(this,Yr,[e.screenX,e.screenY]);const n=new AbortController,r=this._uiManager.combinedSignal(n);this.parent.togglePointerEvents(!1),window.addEventListener("pointermove",w(this,Y,ap).bind(this,t),{passive:!0,capture:!0,signal:r}),window.addEventListener("touchmove",es,{passive:!1,signal:r}),window.addEventListener("contextmenu",Gs,{signal:r}),m(this,Ji,{savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height});const o=this.parent.div.style.cursor,h=this.div.style.cursor;this.div.style.cursor=this.parent.div.style.cursor=window.getComputedStyle(e.target).cursor;const c=()=>{var d;n.abort(),this.parent.togglePointerEvents(!0),(d=l(this,xt))==null||d.toggle(!0),this._isDraggable=i,this.parent.div.style.cursor=o,this.div.style.cursor=h,w(this,Y,Ld).call(this)};window.addEventListener("pointerup",c,{signal:r}),window.addEventListener("blur",c,{signal:r})},op=function(t,e,s,i){this.width=s,this.height=i,this.x=t,this.y=e;const[n,r]=this.parentDimensions;this.setDims(n*s,r*i),this.fixAndSetPosition(),this._onResized()},Ld=function(){if(!l(this,Ji))return;const{savedX:t,savedY:e,savedWidth:s,savedHeight:i}=l(this,Ji);m(this,Ji,null);const n=this.x,r=this.y,o=this.width,h=this.height;n===t&&r===e&&o===s&&h===i||this.addCommands({cmd:w(this,Y,op).bind(this,n,r,o,h),undo:w(this,Y,op).bind(this,t,e,s,i),mustExec:!0})},ap=function(t,e){const[s,i]=this.parentDimensions,n=this.x,r=this.y,o=this.width,h=this.height,c=et.MIN_SIZE/s,u=et.MIN_SIZE/i,d=w(this,Y,Rd).call(this,this.rotation),f=(F,z)=>[d[0]*F+d[2]*z,d[1]*F+d[3]*z],g=w(this,Y,Rd).call(this,360-this.rotation),p=(F,z)=>[g[0]*F+g[2]*z,g[1]*F+g[3]*z];let b,v,_=!1,x=!1;switch(t){case"topLeft":_=!0,b=(F,z)=>[0,0],v=(F,z)=>[F,z];break;case"topMiddle":b=(F,z)=>[F/2,0],v=(F,z)=>[F/2,z];break;case"topRight":_=!0,b=(F,z)=>[F,0],v=(F,z)=>[0,z];break;case"middleRight":x=!0,b=(F,z)=>[F,z/2],v=(F,z)=>[0,z/2];break;case"bottomRight":_=!0,b=(F,z)=>[F,z],v=(F,z)=>[0,0];break;case"bottomMiddle":b=(F,z)=>[F/2,z],v=(F,z)=>[F/2,0];break;case"bottomLeft":_=!0,b=(F,z)=>[0,z],v=(F,z)=>[F,0];break;case"middleLeft":x=!0,b=(F,z)=>[0,z/2],v=(F,z)=>[F,z/2];break}const C=b(o,h),S=v(o,h);let k=f(...S);const D=et._round(n+k[0]),T=et._round(r+k[1]);let M=1,O=1,R,L;if(e.fromKeyboard)({deltaX:R,deltaY:L}=e);else{const{screenX:F,screenY:z}=e,[rt,Gt]=l(this,Yr);[R,L]=this.screenToPageTranslation(F-rt,z-Gt),l(this,Yr)[0]=F,l(this,Yr)[1]=z}if([R,L]=p(R/s,L/i),_){const F=Math.hypot(o,h);M=O=Math.max(Math.min(Math.hypot(S[0]-C[0]-R,S[1]-C[1]-L)/F,1/o,1/h),c/o,u/h)}else x?M=Math.max(c,Math.min(1,Math.abs(S[0]-C[0]-R)))/o:O=Math.max(u,Math.min(1,Math.abs(S[1]-C[1]-L)))/h;const W=et._round(o*M),U=et._round(h*O);k=f(...v(W,U));const G=D-k[0],at=T-k[1];l(this,ns)||m(this,ns,[this.x,this.y,this.width,this.height]),this.width=W,this.height=U,this.x=G,this.y=at,this.setDims(s*W,i*U),this.fixAndSetPosition(),this._onResizing()},my=function(){var t;m(this,Ji,{savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height}),(t=l(this,xt))==null||t.toggle(!1),this.parent.togglePointerEvents(!1)},by=function(t,e,s){let n=.7*(s/e)+1-.7;if(n===1)return;const r=w(this,Y,Rd).call(this,this.rotation),o=(D,T)=>[r[0]*D+r[2]*T,r[1]*D+r[3]*T],[h,c]=this.parentDimensions,u=this.x,d=this.y,f=this.width,g=this.height,p=et.MIN_SIZE/h,b=et.MIN_SIZE/c;n=Math.max(Math.min(n,1/f,1/g),p/f,b/g);const v=et._round(f*n),_=et._round(g*n);if(v===f&&_===g)return;l(this,ns)||m(this,ns,[u,d,f,g]);const x=o(f/2,g/2),C=et._round(u+x[0]),S=et._round(d+x[1]),k=o(v/2,_/2);this.x=C-k[0],this.y=S-k[1],this.width=v,this.height=_,this.setDims(h*v,c*_),this.fixAndSetPosition(),this._onResizing()},yy=function(){var t;(t=l(this,xt))==null||t.toggle(!0),this.parent.togglePointerEvents(!0),w(this,Y,Ld).call(this)},hp=function(t){const{isMac:e}=Re.platform;t.ctrlKey&&!e||t.shiftKey||t.metaKey&&e?this.parent.toggleSelected(this):this.parent.setSelected(this)},vy=function(t){const{isSelected:e}=this;this._uiManager.setUpDragSession();let s=!1;const i=new AbortController,n=this._uiManager.combinedSignal(i),r={capture:!0,passive:!1,signal:n},o=c=>{i.abort(),m(this,Yn,null),m(this,$r,!1),this._uiManager.endDragSession()||w(this,Y,hp).call(this,c),s&&this._onStopDragging()};e&&(m(this,wa,t.clientX),m(this,xa,t.clientY),m(this,Yn,t.pointerId),m(this,vl,t.pointerType),window.addEventListener("pointermove",c=>{s||(s=!0,this._onStartDragging());const{clientX:u,clientY:d,pointerId:f}=c;if(f!==l(this,Yn)){es(c);return}const[g,p]=this.screenToPageTranslation(u-l(this,wa),d-l(this,xa));m(this,wa,u),m(this,xa,d),this._uiManager.dragSelectedEditors(g,p)},r),window.addEventListener("touchmove",es,r),window.addEventListener("pointerdown",c=>{c.pointerType===l(this,vl)&&(l(this,Kr)||c.isPrimary)&&o(c),es(c)},r));const h=c=>{if(!l(this,Yn)||l(this,Yn)===c.pointerId){o(c);return}es(c)};window.addEventListener("pointerup",h,{signal:n}),window.addEventListener("blur",h,{signal:n})},lp=function(){if(l(this,$n)||!this.div)return;m(this,$n,new AbortController);const t=this._uiManager.combinedSignal(l(this,$n));this.div.addEventListener("focusin",this.focusin.bind(this),{signal:t}),this.div.addEventListener("focusout",this.focusout.bind(this),{signal:t})},_y=function(t){et._resizerKeyboardManager.exec(this,t)},wy=function(t){var e;l(this,Zi)&&((e=t.relatedTarget)==null?void 0:e.parentNode)!==l(this,he)&&w(this,Y,Tc).call(this)},xy=function(t){m(this,_l,l(this,Zi)?t:"")},cp=function(t){if(l(this,Us))for(const e of l(this,Us))e.tabIndex=t},Tc=function(){m(this,Zi,!1),w(this,Y,cp).call(this,-1),w(this,Y,Ld).call(this)},y(et,Sl),$(et,"_l10n",null),$(et,"_l10nResizer",null),$(et,"_borderLineWidth",-1),$(et,"_colorManager",new vg),$(et,"_zIndex",1),$(et,"_telemetryTimeout",1e3);let Pt=et;class mx extends Pt{constructor(t){super(t),this.annotationElementId=t.annotationElementId,this.deleted=!0}serialize(){return this.serializeDeleted()}}const Q0=3285377520,vs=4294901760,ci=65535;class J0{constructor(t){this.h1=t?t&4294967295:Q0,this.h2=t?t&4294967295:Q0}update(t){let e,s;if(typeof t=="string"){e=new Uint8Array(t.length*2),s=0;for(let b=0,v=t.length;b<v;b++){const _=t.charCodeAt(b);_<=255?e[s++]=_:(e[s++]=_>>>8,e[s++]=_&255)}}else if(ArrayBuffer.isView(t))e=t.slice(),s=e.byteLength;else throw new Error("Invalid data format, must be a string or TypedArray.");const i=s>>2,n=s-i*4,r=new Uint32Array(e.buffer,0,i);let o=0,h=0,c=this.h1,u=this.h2;const d=3432918353,f=461845907,g=d&ci,p=f&ci;for(let b=0;b<i;b++)b&1?(o=r[b],o=o*d&vs|o*g&ci,o=o<<15|o>>>17,o=o*f&vs|o*p&ci,c^=o,c=c<<13|c>>>19,c=c*5+3864292196):(h=r[b],h=h*d&vs|h*g&ci,h=h<<15|h>>>17,h=h*f&vs|h*p&ci,u^=h,u=u<<13|u>>>19,u=u*5+3864292196);switch(o=0,n){case 3:o^=e[i*4+2]<<16;case 2:o^=e[i*4+1]<<8;case 1:o^=e[i*4],o=o*d&vs|o*g&ci,o=o<<15|o>>>17,o=o*f&vs|o*p&ci,i&1?c^=o:u^=o}this.h1=c,this.h2=u}hexdigest(){let t=this.h1,e=this.h2;return t^=e>>>1,t=t*3981806797&vs|t*36045&ci,e=e*4283543511&vs|((e<<16|t>>>16)*2950163797&vs)>>>16,t^=e>>>1,t=t*444984403&vs|t*60499&ci,e=e*3301882366&vs|((e<<16|t>>>16)*3120437893&vs)>>>16,t^=e>>>1,(t>>>0).toString(16).padStart(8,"0")+(e>>>0).toString(16).padStart(8,"0")}}const _g=Object.freeze({map:null,hash:"",transfer:void 0});class wg{constructor(){y(this,fd);y(this,Qr,!1);y(this,Jr,null);y(this,ie,new Map);this.onSetModified=null,this.onResetModified=null,this.onAnnotationEditor=null}getValue(t,e){const s=l(this,ie).get(t);return s===void 0?e:Object.assign(e,s)}getRawValue(t){return l(this,ie).get(t)}remove(t){if(l(this,ie).delete(t),l(this,ie).size===0&&this.resetModified(),typeof this.onAnnotationEditor=="function"){for(const e of l(this,ie).values())if(e instanceof Pt)return;this.onAnnotationEditor(null)}}setValue(t,e){const s=l(this,ie).get(t);let i=!1;if(s!==void 0)for(const[n,r]of Object.entries(e))s[n]!==r&&(i=!0,s[n]=r);else i=!0,l(this,ie).set(t,e);i&&w(this,fd,Sy).call(this),e instanceof Pt&&typeof this.onAnnotationEditor=="function"&&this.onAnnotationEditor(e.constructor._type)}has(t){return l(this,ie).has(t)}getAll(){return l(this,ie).size>0?hg(l(this,ie)):null}setAll(t){for(const[e,s]of Object.entries(t))this.setValue(e,s)}get size(){return l(this,ie).size}resetModified(){l(this,Qr)&&(m(this,Qr,!1),typeof this.onResetModified=="function"&&this.onResetModified())}get print(){return new Z0(this)}get serializable(){if(l(this,ie).size===0)return _g;const t=new Map,e=new J0,s=[],i=Object.create(null);let n=!1;for(const[r,o]of l(this,ie)){const h=o instanceof Pt?o.serialize(!1,i):o;h&&(t.set(r,h),e.update(`${r}:${JSON.stringify(h)}`),n||(n=!!h.bitmap))}if(n)for(const r of t.values())r.bitmap&&s.push(r.bitmap);return t.size>0?{map:t,hash:e.hexdigest(),transfer:s}:_g}get editorStats(){let t=null;const e=new Map;for(const s of l(this,ie).values()){if(!(s instanceof Pt))continue;const i=s.telemetryFinalData;if(!i)continue;const{type:n}=i;e.has(n)||e.set(n,Object.getPrototypeOf(s).constructor),t||(t=Object.create(null));const r=t[n]||(t[n]=new Map);for(const[o,h]of Object.entries(i)){if(o==="type")continue;let c=r.get(o);c||(c=new Map,r.set(o,c));const u=c.get(h)??0;c.set(h,u+1)}}for(const[s,i]of e)t[s]=i.computeTelemetryFinalData(t[s]);return t}resetModifiedIds(){m(this,Jr,null)}get modifiedIds(){if(l(this,Jr))return l(this,Jr);const t=[];for(const e of l(this,ie).values())!(e instanceof Pt)||!e.annotationElementId||!e.serialize()||t.push(e.annotationElementId);return m(this,Jr,{ids:new Set(t),hash:t.join(",")})}}Qr=new WeakMap,Jr=new WeakMap,ie=new WeakMap,fd=new WeakSet,Sy=function(){l(this,Qr)||(m(this,Qr,!0),typeof this.onSetModified=="function"&&this.onSetModified())};class Z0 extends wg{constructor(e){super();y(this,Cl);const{map:s,hash:i,transfer:n}=e.serializable,r=structuredClone(s,n?{transfer:n}:null);m(this,Cl,{map:r,hash:i,transfer:n})}get print(){vt("Should not call PrintAnnotationStorage.print")}get serializable(){return l(this,Cl)}get modifiedIds(){return st(this,"modifiedIds",{ids:new Set,hash:""})}}Cl=new WeakMap;class bx{constructor({ownerDocument:t=globalThis.document,styleElement:e=null}){y(this,Sa,new Set);this._document=t,this.nativeFontFaces=new Set,this.styleElement=null,this.loadingRequests=[],this.loadTestFontId=0}addNativeFontFace(t){this.nativeFontFaces.add(t),this._document.fonts.add(t)}removeNativeFontFace(t){this.nativeFontFaces.delete(t),this._document.fonts.delete(t)}insertRule(t){this.styleElement||(this.styleElement=this._document.createElement("style"),this._document.documentElement.getElementsByTagName("head")[0].append(this.styleElement));const e=this.styleElement.sheet;e.insertRule(t,e.cssRules.length)}clear(){for(const t of this.nativeFontFaces)this._document.fonts.delete(t);this.nativeFontFaces.clear(),l(this,Sa).clear(),this.styleElement&&(this.styleElement.remove(),this.styleElement=null)}async loadSystemFont({systemFontInfo:t,_inspectFont:e}){if(!(!t||l(this,Sa).has(t.loadedName))){if(Xt(!this.disableFontFace,"loadSystemFont shouldn't be called when `disableFontFace` is set."),this.isFontLoadingAPISupported){const{loadedName:s,src:i,style:n}=t,r=new FontFace(s,i,n);this.addNativeFontFace(r);try{await r.load(),l(this,Sa).add(s),e==null||e(t)}catch{tt(`Cannot load system font: ${t.baseFontName}, installing it could help to improve PDF rendering.`),this.removeNativeFontFace(r)}return}vt("Not implemented: loadSystemFont without the Font Loading API.")}}async bind(t){if(t.attached||t.missingFile&&!t.systemFontInfo)return;if(t.attached=!0,t.systemFontInfo){await this.loadSystemFont(t);return}if(this.isFontLoadingAPISupported){const s=t.createNativeFontFace();if(s){this.addNativeFontFace(s);try{await s.loaded}catch(i){throw tt(`Failed to load font '${s.family}': '${i}'.`),t.disableFontFace=!0,i}}return}const e=t.createFontFaceRule();if(e){if(this.insertRule(e),this.isSyncFontLoadingSupported)return;await new Promise(s=>{const i=this._queueLoadingCallback(s);this._prepareFontLoadEvent(t,i)})}}get isFontLoadingAPISupported(){var e;const t=!!((e=this._document)!=null&&e.fonts);return st(this,"isFontLoadingAPISupported",t)}get isSyncFontLoadingSupported(){let t=!1;return(ye||typeof navigator<"u"&&typeof(navigator==null?void 0:navigator.userAgent)=="string"&&/Mozilla\/5.0.*?rv:\d+.*? Gecko/.test(navigator.userAgent))&&(t=!0),st(this,"isSyncFontLoadingSupported",t)}_queueLoadingCallback(t){function e(){for(Xt(!i.done,"completeRequest() cannot be called twice."),i.done=!0;s.length>0&&s[0].done;){const n=s.shift();setTimeout(n.callback,0)}}const{loadingRequests:s}=this,i={done:!1,complete:e,callback:t};return s.push(i),i}get _loadTestFont(){const t=atob("T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQAABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwAAAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbmFtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAAAADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6AABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAAMQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAAAAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAAAAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQAAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMAAQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAAEAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgcA/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQAAAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAgABAAAAAAAAAAAD6AAAAAAAAA==");return st(this,"_loadTestFont",t)}_prepareFontLoadEvent(t,e){function s(S,k){return S.charCodeAt(k)<<24|S.charCodeAt(k+1)<<16|S.charCodeAt(k+2)<<8|S.charCodeAt(k+3)&255}function i(S,k,D,T){const M=S.substring(0,k),O=S.substring(k+D);return M+T+O}let n,r;const o=this._document.createElement("canvas");o.width=1,o.height=1;const h=o.getContext("2d");let c=0;function u(S,k){if(++c>30){tt("Load test font never loaded."),k();return}if(h.font="30px "+S,h.fillText(".",0,20),h.getImageData(0,0,1,1).data[3]>0){k();return}setTimeout(u.bind(null,S,k))}const d=`lt${Date.now()}${this.loadTestFontId++}`;let f=this._loadTestFont;f=i(f,976,d.length,d);const p=16,b=1482184792;let v=s(f,p);for(n=0,r=d.length-3;n<r;n+=4)v=v-b+s(d,n)|0;n<d.length&&(v=v-b+s(d+"XXX",n)|0),f=i(f,p,4,sx(v));const _=`url(data:font/opentype;base64,${btoa(f)});`,x=`@font-face {font-family:"${d}";src:${_}}`;this.insertRule(x);const C=this._document.createElement("div");C.style.visibility="hidden",C.style.width=C.style.height="10px",C.style.position="absolute",C.style.top=C.style.left="0px";for(const S of[t.loadedName,d]){const k=this._document.createElement("span");k.textContent="Hi",k.style.fontFamily=S,C.append(k)}this._document.body.append(C),u(d,()=>{C.remove(),e.complete()})}}Sa=new WeakMap;class yx{constructor(t,{disableFontFace:e=!1,fontExtraProperties:s=!1,inspectFont:i=null}){this.compiledGlyphs=Object.create(null);for(const n in t)this[n]=t[n];this.disableFontFace=e===!0,this.fontExtraProperties=s===!0,this._inspectFont=i}createNativeFontFace(){var e;if(!this.data||this.disableFontFace)return null;let t;if(!this.cssFontInfo)t=new FontFace(this.loadedName,this.data,{});else{const s={weight:this.cssFontInfo.fontWeight};this.cssFontInfo.italicAngle&&(s.style=`oblique ${this.cssFontInfo.italicAngle}deg`),t=new FontFace(this.cssFontInfo.fontFamily,this.data,s)}return(e=this._inspectFont)==null||e.call(this,this),t}createFontFaceRule(){var s;if(!this.data||this.disableFontFace)return null;const t=`url(data:${this.mimetype};base64,${hx(this.data)});`;let e;if(!this.cssFontInfo)e=`@font-face {font-family:"${this.loadedName}";src:${t}}`;else{let i=`font-weight: ${this.cssFontInfo.fontWeight};`;this.cssFontInfo.italicAngle&&(i+=`font-style: oblique ${this.cssFontInfo.italicAngle}deg;`),e=`@font-face {font-family:"${this.cssFontInfo.fontFamily}";${i}src:${t}}`}return(s=this._inspectFont)==null||s.call(this,this,t),e}getPathGenerator(t,e){if(this.compiledGlyphs[e]!==void 0)return this.compiledGlyphs[e];const s=this.loadedName+"_path_"+e;let i;try{i=t.get(s)}catch(r){tt(`getPathGenerator - ignoring character: "${r}".`)}const n=new Path2D(i||"");return this.fontExtraProperties||t.delete(s),this.compiledGlyphs[e]=n}}const Qu={DATA:1,ERROR:2},Wt={CANCEL:1,CANCEL_COMPLETE:2,CLOSE:3,ENQUEUE:4,ERROR:5,PULL:6,PULL_COMPLETE:7,START_COMPLETE:8};function tb(){}function We(a){if(a instanceof Rn||a instanceof ag||a instanceof Gh||a instanceof Y0||a instanceof Xu||a instanceof og)return a;switch(a instanceof Error||typeof a=="object"&&a!==null||vt('wrapReason: Expected "reason" to be a (possibly cloned) Error.'),a.name){case"AbortException":return new Rn(a.message);case"InvalidPDFException":return new ag(a.message);case"MissingPDFException":return new Gh(a.message);case"PasswordException":return new Y0(a.message,a.code);case"UnexpectedResponseException":return new Xu(a.message,a.status);case"UnknownErrorException":return new og(a.message,a.details)}return new og(a.message,a.toString())}class Wh{constructor(t,e,s){y(this,Cs);y(this,Ca,new AbortController);this.sourceName=t,this.targetName=e,this.comObj=s,this.callbackId=1,this.streamId=1,this.streamSinks=Object.create(null),this.streamControllers=Object.create(null),this.callbackCapabilities=Object.create(null),this.actionHandler=Object.create(null),s.addEventListener("message",w(this,Cs,Cy).bind(this),{signal:l(this,Ca).signal})}on(t,e){const s=this.actionHandler;if(s[t])throw new Error(`There is already an actionName called "${t}"`);s[t]=e}send(t,e,s){this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:t,data:e},s)}sendWithPromise(t,e,s){const i=this.callbackId++,n=Promise.withResolvers();this.callbackCapabilities[i]=n;try{this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:t,callbackId:i,data:e},s)}catch(r){n.reject(r)}return n.promise}sendWithStream(t,e,s,i){const n=this.streamId++,r=this.sourceName,o=this.targetName,h=this.comObj;return new ReadableStream({start:c=>{const u=Promise.withResolvers();return this.streamControllers[n]={controller:c,startCall:u,pullCall:null,cancelCall:null,isClosed:!1},h.postMessage({sourceName:r,targetName:o,action:t,streamId:n,data:e,desiredSize:c.desiredSize},i),u.promise},pull:c=>{const u=Promise.withResolvers();return this.streamControllers[n].pullCall=u,h.postMessage({sourceName:r,targetName:o,stream:Wt.PULL,streamId:n,desiredSize:c.desiredSize}),u.promise},cancel:c=>{Xt(c instanceof Error,"cancel must have a valid reason");const u=Promise.withResolvers();return this.streamControllers[n].cancelCall=u,this.streamControllers[n].isClosed=!0,h.postMessage({sourceName:r,targetName:o,stream:Wt.CANCEL,streamId:n,reason:We(c)}),u.promise}},s)}destroy(){var t;(t=l(this,Ca))==null||t.abort(),m(this,Ca,null)}}Ca=new WeakMap,Cs=new WeakSet,Cy=function({data:t}){if(t.targetName!==this.sourceName)return;if(t.stream){w(this,Cs,Ty).call(this,t);return}if(t.callback){const s=t.callbackId,i=this.callbackCapabilities[s];if(!i)throw new Error(`Cannot resolve callback ${s}`);if(delete this.callbackCapabilities[s],t.callback===Qu.DATA)i.resolve(t.data);else if(t.callback===Qu.ERROR)i.reject(We(t.reason));else throw new Error("Unexpected callback case");return}const e=this.actionHandler[t.action];if(!e)throw new Error(`Unknown action from worker: ${t.action}`);if(t.callbackId){const s=this.sourceName,i=t.sourceName,n=this.comObj;Promise.try(e,t.data).then(function(r){n.postMessage({sourceName:s,targetName:i,callback:Qu.DATA,callbackId:t.callbackId,data:r})},function(r){n.postMessage({sourceName:s,targetName:i,callback:Qu.ERROR,callbackId:t.callbackId,reason:We(r)})});return}if(t.streamId){w(this,Cs,Ay).call(this,t);return}e(t.data)},Ay=function(t){const e=t.streamId,s=this.sourceName,i=t.sourceName,n=this.comObj,r=this,o=this.actionHandler[t.action],h={enqueue(c,u=1,d){if(this.isCancelled)return;const f=this.desiredSize;this.desiredSize-=u,f>0&&this.desiredSize<=0&&(this.sinkCapability=Promise.withResolvers(),this.ready=this.sinkCapability.promise),n.postMessage({sourceName:s,targetName:i,stream:Wt.ENQUEUE,streamId:e,chunk:c},d)},close(){this.isCancelled||(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:Wt.CLOSE,streamId:e}),delete r.streamSinks[e])},error(c){Xt(c instanceof Error,"error must have a valid reason"),!this.isCancelled&&(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:Wt.ERROR,streamId:e,reason:We(c)}))},sinkCapability:Promise.withResolvers(),onPull:null,onCancel:null,isCancelled:!1,desiredSize:t.desiredSize,ready:null};h.sinkCapability.resolve(),h.ready=h.sinkCapability.promise,this.streamSinks[e]=h,Promise.try(o,t.data,h).then(function(){n.postMessage({sourceName:s,targetName:i,stream:Wt.START_COMPLETE,streamId:e,success:!0})},function(c){n.postMessage({sourceName:s,targetName:i,stream:Wt.START_COMPLETE,streamId:e,reason:We(c)})})},Ty=function(t){const e=t.streamId,s=this.sourceName,i=t.sourceName,n=this.comObj,r=this.streamControllers[e],o=this.streamSinks[e];switch(t.stream){case Wt.START_COMPLETE:t.success?r.startCall.resolve():r.startCall.reject(We(t.reason));break;case Wt.PULL_COMPLETE:t.success?r.pullCall.resolve():r.pullCall.reject(We(t.reason));break;case Wt.PULL:if(!o){n.postMessage({sourceName:s,targetName:i,stream:Wt.PULL_COMPLETE,streamId:e,success:!0});break}o.desiredSize<=0&&t.desiredSize>0&&o.sinkCapability.resolve(),o.desiredSize=t.desiredSize,Promise.try(o.onPull||tb).then(function(){n.postMessage({sourceName:s,targetName:i,stream:Wt.PULL_COMPLETE,streamId:e,success:!0})},function(c){n.postMessage({sourceName:s,targetName:i,stream:Wt.PULL_COMPLETE,streamId:e,reason:We(c)})});break;case Wt.ENQUEUE:if(Xt(r,"enqueue should have stream controller"),r.isClosed)break;r.controller.enqueue(t.chunk);break;case Wt.CLOSE:if(Xt(r,"close should have stream controller"),r.isClosed)break;r.isClosed=!0,r.controller.close(),w(this,Cs,Fd).call(this,r,e);break;case Wt.ERROR:Xt(r,"error should have stream controller"),r.controller.error(We(t.reason)),w(this,Cs,Fd).call(this,r,e);break;case Wt.CANCEL_COMPLETE:t.success?r.cancelCall.resolve():r.cancelCall.reject(We(t.reason)),w(this,Cs,Fd).call(this,r,e);break;case Wt.CANCEL:if(!o)break;const h=We(t.reason);Promise.try(o.onCancel||tb,h).then(function(){n.postMessage({sourceName:s,targetName:i,stream:Wt.CANCEL_COMPLETE,streamId:e,success:!0})},function(c){n.postMessage({sourceName:s,targetName:i,stream:Wt.CANCEL_COMPLETE,streamId:e,reason:We(c)})}),o.sinkCapability.reject(h),o.isCancelled=!0,delete this.streamSinks[e];break;default:throw new Error("Unexpected stream case")}},Fd=async function(t,e){var s,i,n;await Promise.allSettled([(s=t.startCall)==null?void 0:s.promise,(i=t.pullCall)==null?void 0:i.promise,(n=t.cancelCall)==null?void 0:n.promise]),delete this.streamControllers[e]};class eb{constructor({enableHWA:t=!1}){y(this,Al,!1);m(this,Al,t)}create(t,e){if(t<=0||e<=0)throw new Error("Invalid canvas size");const s=this._createCanvas(t,e);return{canvas:s,context:s.getContext("2d",{willReadFrequently:!l(this,Al)})}}reset(t,e,s){if(!t.canvas)throw new Error("Canvas is not specified");if(e<=0||s<=0)throw new Error("Invalid canvas size");t.canvas.width=e,t.canvas.height=s}destroy(t){if(!t.canvas)throw new Error("Canvas is not specified");t.canvas.width=0,t.canvas.height=0,t.canvas=null,t.context=null}_createCanvas(t,e){vt("Abstract method `_createCanvas` called.")}}Al=new WeakMap;class vx extends eb{constructor({ownerDocument:t=globalThis.document,enableHWA:e=!1}){super({enableHWA:e}),this._document=t}_createCanvas(t,e){const s=this._document.createElement("canvas");return s.width=t,s.height=e,s}}class sb{constructor({baseUrl:t=null,isCompressed:e=!0}){this.baseUrl=t,this.isCompressed=e}async fetch({name:t}){if(!this.baseUrl)throw new Error("Ensure that the `cMapUrl` and `cMapPacked` API parameters are provided.");if(!t)throw new Error("CMap name must be specified.");const e=this.baseUrl+t+(this.isCompressed?".bcmap":"");return this._fetch(e).then(s=>({cMapData:s,isCompressed:this.isCompressed})).catch(s=>{throw new Error(`Unable to load ${this.isCompressed?"binary ":""}CMap at: ${e}`)})}async _fetch(t){vt("Abstract method `_fetch` called.")}}class ib extends sb{async _fetch(t){const e=await Uu(t,this.isCompressed?"arraybuffer":"text");return e instanceof ArrayBuffer?new Uint8Array(e):Wu(e)}}class nb{addFilter(t){return"none"}addHCMFilter(t,e){return"none"}addAlphaFilter(t){return"none"}addLuminosityFilter(t){return"none"}addHighlightHCMFilter(t,e,s,i,n){return"none"}destroy(t=!1){}}class _x extends nb{constructor({docId:e,ownerDocument:s=globalThis.document}){super();y(this,j);y(this,Zr);y(this,Aa);y(this,tn);y(this,en);y(this,xe);y(this,to);y(this,eo,0);m(this,en,e),m(this,xe,s)}addFilter(e){if(!e)return"none";let s=l(this,j,Te).get(e);if(s)return s;const[i,n,r]=w(this,j,Id).call(this,e),o=e.length===1?i:`${i}${n}${r}`;if(s=l(this,j,Te).get(o),s)return l(this,j,Te).set(e,s),s;const h=`g_${l(this,en)}_transfer_map_${Ge(this,eo)._++}`,c=w(this,j,bh).call(this,h);l(this,j,Te).set(e,c),l(this,j,Te).set(o,c);const u=w(this,j,yh).call(this,h);return w(this,j,Mc).call(this,i,n,r,u),c}addHCMFilter(e,s){var p;const i=`${e}-${s}`,n="base";let r=l(this,j,Ec).get(n);if((r==null?void 0:r.key)===i||(r?((p=r.filter)==null||p.remove(),r.key=i,r.url="none",r.filter=null):(r={key:i,url:"none",filter:null},l(this,j,Ec).set(n,r)),!e||!s))return r.url;const o=w(this,j,Pc).call(this,e);e=X.makeHexColor(...o);const h=w(this,j,Pc).call(this,s);if(s=X.makeHexColor(...h),l(this,j,mh).style.color="",e==="#000000"&&s==="#ffffff"||e===s)return r.url;const c=new Array(256);for(let b=0;b<=255;b++){const v=b/255;c[b]=v<=.03928?v/12.92:((v+.055)/1.055)**2.4}const u=c.join(","),d=`g_${l(this,en)}_hcm_filter`,f=r.filter=w(this,j,yh).call(this,d);w(this,j,Mc).call(this,u,u,u,f),w(this,j,up).call(this,f);const g=(b,v)=>{const _=o[b]/255,x=h[b]/255,C=new Array(v+1);for(let S=0;S<=v;S++)C[S]=_+S/v*(x-_);return C.join(",")};return w(this,j,Mc).call(this,g(0,5),g(1,5),g(2,5),f),r.url=w(this,j,bh).call(this,d),r.url}addAlphaFilter(e){let s=l(this,j,Te).get(e);if(s)return s;const[i]=w(this,j,Id).call(this,[e]),n=`alpha_${i}`;if(s=l(this,j,Te).get(n),s)return l(this,j,Te).set(e,s),s;const r=`g_${l(this,en)}_alpha_map_${Ge(this,eo)._++}`,o=w(this,j,bh).call(this,r);l(this,j,Te).set(e,o),l(this,j,Te).set(n,o);const h=w(this,j,yh).call(this,r);return w(this,j,dp).call(this,i,h),o}addLuminosityFilter(e){let s=l(this,j,Te).get(e||"luminosity");if(s)return s;let i,n;if(e?([i]=w(this,j,Id).call(this,[e]),n=`luminosity_${i}`):n="luminosity",s=l(this,j,Te).get(n),s)return l(this,j,Te).set(e,s),s;const r=`g_${l(this,en)}_luminosity_map_${Ge(this,eo)._++}`,o=w(this,j,bh).call(this,r);l(this,j,Te).set(e,o),l(this,j,Te).set(n,o);const h=w(this,j,yh).call(this,r);return w(this,j,Ey).call(this,h),e&&w(this,j,dp).call(this,i,h),o}addHighlightHCMFilter(e,s,i,n,r){var x;const o=`${s}-${i}-${n}-${r}`;let h=l(this,j,Ec).get(e);if((h==null?void 0:h.key)===o||(h?((x=h.filter)==null||x.remove(),h.key=o,h.url="none",h.filter=null):(h={key:o,url:"none",filter:null},l(this,j,Ec).set(e,h)),!s||!i))return h.url;const[c,u]=[s,i].map(w(this,j,Pc).bind(this));let d=Math.round(.2126*c[0]+.7152*c[1]+.0722*c[2]),f=Math.round(.2126*u[0]+.7152*u[1]+.0722*u[2]),[g,p]=[n,r].map(w(this,j,Pc).bind(this));f<d&&([d,f,g,p]=[f,d,p,g]),l(this,j,mh).style.color="";const b=(C,S,k)=>{const D=new Array(256),T=(f-d)/k,M=C/255,O=(S-C)/(255*k);let R=0;for(let L=0;L<=k;L++){const W=Math.round(d+L*T),U=M+L*O;for(let G=R;G<=W;G++)D[G]=U;R=W+1}for(let L=R;L<256;L++)D[L]=D[R-1];return D.join(",")},v=`g_${l(this,en)}_hcm_${e}_filter`,_=h.filter=w(this,j,yh).call(this,v);return w(this,j,up).call(this,_),w(this,j,Mc).call(this,b(g[0],p[0],5),b(g[1],p[1],5),b(g[2],p[2],5),_),h.url=w(this,j,bh).call(this,v),h.url}destroy(e=!1){var s,i,n,r;e&&((s=l(this,to))!=null&&s.size)||((i=l(this,tn))==null||i.parentNode.parentNode.remove(),m(this,tn,null),(n=l(this,Aa))==null||n.clear(),m(this,Aa,null),(r=l(this,to))==null||r.clear(),m(this,to,null),m(this,eo,0))}}Zr=new WeakMap,Aa=new WeakMap,tn=new WeakMap,en=new WeakMap,xe=new WeakMap,to=new WeakMap,eo=new WeakMap,j=new WeakSet,Te=function(){return l(this,Aa)||m(this,Aa,new Map)},Ec=function(){return l(this,to)||m(this,to,new Map)},mh=function(){if(!l(this,tn)){const e=l(this,xe).createElement("div"),{style:s}=e;s.visibility="hidden",s.contain="strict",s.width=s.height=0,s.position="absolute",s.top=s.left=0,s.zIndex=-1;const i=l(this,xe).createElementNS(zi,"svg");i.setAttribute("width",0),i.setAttribute("height",0),m(this,tn,l(this,xe).createElementNS(zi,"defs")),e.append(i),i.append(l(this,tn)),l(this,xe).body.append(e)}return l(this,tn)},Id=function(e){if(e.length===1){const c=e[0],u=new Array(256);for(let f=0;f<256;f++)u[f]=c[f]/255;const d=u.join(",");return[d,d,d]}const[s,i,n]=e,r=new Array(256),o=new Array(256),h=new Array(256);for(let c=0;c<256;c++)r[c]=s[c]/255,o[c]=i[c]/255,h[c]=n[c]/255;return[r.join(","),o.join(","),h.join(",")]},bh=function(e){if(l(this,Zr)===void 0){m(this,Zr,"");const s=l(this,xe).URL;s!==l(this,xe).baseURI&&(Yu(s)?tt('#createUrl: ignore "data:"-URL for performance reasons.'):m(this,Zr,s.split("#",1)[0]))}return`url(${l(this,Zr)}#${e})`},Ey=function(e){const s=l(this,xe).createElementNS(zi,"feColorMatrix");s.setAttribute("type","matrix"),s.setAttribute("values","0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3 0.59 0.11 0 0"),e.append(s)},up=function(e){const s=l(this,xe).createElementNS(zi,"feColorMatrix");s.setAttribute("type","matrix"),s.setAttribute("values","0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0 0 0 1 0"),e.append(s)},yh=function(e){const s=l(this,xe).createElementNS(zi,"filter");return s.setAttribute("color-interpolation-filters","sRGB"),s.setAttribute("id",e),l(this,j,mh).append(s),s},kc=function(e,s,i){const n=l(this,xe).createElementNS(zi,s);n.setAttribute("type","discrete"),n.setAttribute("tableValues",i),e.append(n)},Mc=function(e,s,i,n){const r=l(this,xe).createElementNS(zi,"feComponentTransfer");n.append(r),w(this,j,kc).call(this,r,"feFuncR",e),w(this,j,kc).call(this,r,"feFuncG",s),w(this,j,kc).call(this,r,"feFuncB",i)},dp=function(e,s){const i=l(this,xe).createElementNS(zi,"feComponentTransfer");s.append(i),w(this,j,kc).call(this,i,"feFuncA",e)},Pc=function(e){return l(this,j,mh).style.color=e,pg(getComputedStyle(l(this,j,mh)).getPropertyValue("color"))};class rb{constructor({baseUrl:t=null}){this.baseUrl=t}async fetch({filename:t}){if(!this.baseUrl)throw new Error("Ensure that the `standardFontDataUrl` API parameter is provided.");if(!t)throw new Error("Font filename must be specified.");const e=`${this.baseUrl}${t}`;return this._fetch(e).catch(s=>{throw new Error(`Unable to load font data at: ${e}`)})}async _fetch(t){vt("Abstract method `_fetch` called.")}}class ob extends rb{async _fetch(t){const e=await Uu(t,"arraybuffer");return new Uint8Array(e)}}ye&&tt("Please use the `legacy` build in Node.js environments.");async function ab(a){const e=await process.getBuiltinModule("fs").promises.readFile(a);return new Uint8Array(e)}class wx extends nb{}class xx extends eb{_createCanvas(t,e){return process.getBuiltinModule("module").createRequire(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:_t&&_t.tagName.toUpperCase()==="SCRIPT"&&_t.src||new URL("pdf-canvas.umd.js",document.baseURI).href)("@napi-rs/canvas").createCanvas(t,e)}}class Sx extends sb{async _fetch(t){return ab(t)}}class Cx extends rb{async _fetch(t){return ab(t)}}const _e={FILL:"Fill",STROKE:"Stroke",SHADING:"Shading"};function xg(a,t){if(!t)return;const e=t[2]-t[0],s=t[3]-t[1],i=new Path2D;i.rect(t[0],t[1],e,s),a.clip(i)}class Sg{getPattern(){vt("Abstract method `getPattern` called.")}}class Ax extends Sg{constructor(t){super(),this._type=t[1],this._bbox=t[2],this._colorStops=t[3],this._p0=t[4],this._p1=t[5],this._r0=t[6],this._r1=t[7],this.matrix=null}_createGradient(t){let e;this._type==="axial"?e=t.createLinearGradient(this._p0[0],this._p0[1],this._p1[0],this._p1[1]):this._type==="radial"&&(e=t.createRadialGradient(this._p0[0],this._p0[1],this._r0,this._p1[0],this._p1[1],this._r1));for(const s of this._colorStops)e.addColorStop(s[0],s[1]);return e}getPattern(t,e,s,i){let n;if(i===_e.STROKE||i===_e.FILL){const r=e.current.getClippedPathBoundingBox(i,Tt(t))||[0,0,0,0],o=Math.ceil(r[2]-r[0])||1,h=Math.ceil(r[3]-r[1])||1,c=e.cachedCanvases.getCanvas("pattern",o,h),u=c.context;u.clearRect(0,0,u.canvas.width,u.canvas.height),u.beginPath(),u.rect(0,0,u.canvas.width,u.canvas.height),u.translate(-r[0],-r[1]),s=X.transform(s,[1,0,0,1,r[0],r[1]]),u.transform(...e.baseTransform),this.matrix&&u.transform(...this.matrix),xg(u,this._bbox),u.fillStyle=this._createGradient(u),u.fill(),n=t.createPattern(c.canvas,"no-repeat");const d=new DOMMatrix(s);n.setTransform(d)}else xg(t,this._bbox),n=this._createGradient(t);return n}}function Cg(a,t,e,s,i,n,r,o){const h=t.coords,c=t.colors,u=a.data,d=a.width*4;let f;h[e+1]>h[s+1]&&(f=e,e=s,s=f,f=n,n=r,r=f),h[s+1]>h[i+1]&&(f=s,s=i,i=f,f=r,r=o,o=f),h[e+1]>h[s+1]&&(f=e,e=s,s=f,f=n,n=r,r=f);const g=(h[e]+t.offsetX)*t.scaleX,p=(h[e+1]+t.offsetY)*t.scaleY,b=(h[s]+t.offsetX)*t.scaleX,v=(h[s+1]+t.offsetY)*t.scaleY,_=(h[i]+t.offsetX)*t.scaleX,x=(h[i+1]+t.offsetY)*t.scaleY;if(p>=x)return;const C=c[n],S=c[n+1],k=c[n+2],D=c[r],T=c[r+1],M=c[r+2],O=c[o],R=c[o+1],L=c[o+2],W=Math.round(p),U=Math.round(x);let G,at,F,z,rt,Gt,te,fe;for(let Yt=W;Yt<=U;Yt++){if(Yt<v){const ft=Yt<p?0:(p-Yt)/(p-v);G=g-(g-b)*ft,at=C-(C-D)*ft,F=S-(S-T)*ft,z=k-(k-M)*ft}else{let ft;Yt>x?ft=1:v===x?ft=0:ft=(v-Yt)/(v-x),G=b-(b-_)*ft,at=D-(D-O)*ft,F=T-(T-R)*ft,z=M-(M-L)*ft}let St;Yt<p?St=0:Yt>x?St=1:St=(p-Yt)/(p-x),rt=g-(g-_)*St,Gt=C-(C-O)*St,te=S-(S-R)*St,fe=k-(k-L)*St;const He=Math.round(Math.min(G,rt)),Mi=Math.round(Math.max(G,rt));let Ft=d*Yt+He*4;for(let ft=He;ft<=Mi;ft++)St=(G-ft)/(G-rt),St<0?St=0:St>1&&(St=1),u[Ft++]=at-(at-Gt)*St|0,u[Ft++]=F-(F-te)*St|0,u[Ft++]=z-(z-fe)*St|0,u[Ft++]=255}}function Tx(a,t,e){const s=t.coords,i=t.colors;let n,r;switch(t.type){case"lattice":const o=t.verticesPerRow,h=Math.floor(s.length/o)-1,c=o-1;for(n=0;n<h;n++){let u=n*o;for(let d=0;d<c;d++,u++)Cg(a,e,s[u],s[u+1],s[u+o],i[u],i[u+1],i[u+o]),Cg(a,e,s[u+o+1],s[u+1],s[u+o],i[u+o+1],i[u+1],i[u+o])}break;case"triangles":for(n=0,r=s.length;n<r;n+=3)Cg(a,e,s[n],s[n+1],s[n+2],i[n],i[n+1],i[n+2]);break;default:throw new Error("illegal figure")}}class Ex extends Sg{constructor(t){super(),this._coords=t[2],this._colors=t[3],this._figures=t[4],this._bounds=t[5],this._bbox=t[7],this._background=t[8],this.matrix=null}_createMeshCanvas(t,e,s){const o=Math.floor(this._bounds[0]),h=Math.floor(this._bounds[1]),c=Math.ceil(this._bounds[2])-o,u=Math.ceil(this._bounds[3])-h,d=Math.min(Math.ceil(Math.abs(c*t[0]*1.1)),3e3),f=Math.min(Math.ceil(Math.abs(u*t[1]*1.1)),3e3),g=c/d,p=u/f,b={coords:this._coords,colors:this._colors,offsetX:-o,offsetY:-h,scaleX:1/g,scaleY:1/p},v=d+2*2,_=f+2*2,x=s.getCanvas("mesh",v,_),C=x.context,S=C.createImageData(d,f);if(e){const D=S.data;for(let T=0,M=D.length;T<M;T+=4)D[T]=e[0],D[T+1]=e[1],D[T+2]=e[2],D[T+3]=255}for(const D of this._figures)Tx(S,D,b);return C.putImageData(S,2,2),{canvas:x.canvas,offsetX:o-2*g,offsetY:h-2*p,scaleX:g,scaleY:p}}getPattern(t,e,s,i){xg(t,this._bbox);let n;if(i===_e.SHADING)n=X.singularValueDecompose2dScale(Tt(t));else if(n=X.singularValueDecompose2dScale(e.baseTransform),this.matrix){const o=X.singularValueDecompose2dScale(this.matrix);n=[n[0]*o[0],n[1]*o[1]]}const r=this._createMeshCanvas(n,i===_e.SHADING?null:this._background,e.cachedCanvases);return i!==_e.SHADING&&(t.setTransform(...e.baseTransform),this.matrix&&t.transform(...this.matrix)),t.translate(r.offsetX,r.offsetY),t.scale(r.scaleX,r.scaleY),t.createPattern(r.canvas,"no-repeat")}}class kx extends Sg{getPattern(){return"hotpink"}}function Mx(a){switch(a[0]){case"RadialAxial":return new Ax(a);case"Mesh":return new Ex(a);case"Dummy":return new kx}throw new Error(`Unknown IR type: ${a[0]}`)}const hb={COLORED:1,UNCOLORED:2},gd=class gd{constructor(t,e,s,i,n){this.operatorList=t[2],this.matrix=t[3],this.bbox=t[4],this.xstep=t[5],this.ystep=t[6],this.paintType=t[7],this.tilingType=t[8],this.color=e,this.ctx=s,this.canvasGraphicsFactory=i,this.baseTransform=n}createPatternCanvas(t){const{bbox:e,operatorList:s,paintType:i,tilingType:n,color:r,canvasGraphicsFactory:o}=this;let{xstep:h,ystep:c}=this;h=Math.abs(h),c=Math.abs(c),Vu("TilingType: "+n);const u=e[0],d=e[1],f=e[2],g=e[3],p=f-u,b=g-d,v=X.singularValueDecompose2dScale(this.matrix),_=X.singularValueDecompose2dScale(this.baseTransform),x=v[0]*_[0],C=v[1]*_[1];let S=p,k=b,D=!1,T=!1;const M=Math.ceil(h*x),O=Math.ceil(c*C),R=Math.ceil(p*x),L=Math.ceil(b*C);M>=R?S=h:D=!0,O>=L?k=c:T=!0;const W=this.getSizeAndScale(S,this.ctx.canvas.width,x),U=this.getSizeAndScale(k,this.ctx.canvas.height,C),G=t.cachedCanvases.getCanvas("pattern",W.size,U.size),at=G.context,F=o.createCanvasGraphics(at);if(F.groupLevel=t.groupLevel,this.setFillAndStrokeStyleToContext(F,i,r),at.translate(-W.scale*u,-U.scale*d),F.transform(W.scale,0,0,U.scale,0,0),at.save(),this.clipBbox(F,u,d,f,g),F.baseTransform=Tt(F.ctx),F.executeOperatorList(s),F.endDrawing(),at.restore(),D||T){const z=G.canvas;D&&(S=h),T&&(k=c);const rt=this.getSizeAndScale(S,this.ctx.canvas.width,x),Gt=this.getSizeAndScale(k,this.ctx.canvas.height,C),te=rt.size,fe=Gt.size,Yt=t.cachedCanvases.getCanvas("pattern-workaround",te,fe),St=Yt.context,He=D?Math.floor(p/h):0,Mi=T?Math.floor(b/c):0;for(let Ft=0;Ft<=He;Ft++)for(let ft=0;ft<=Mi;ft++)St.drawImage(z,te*Ft,fe*ft,te,fe,0,0,te,fe);return{canvas:Yt.canvas,scaleX:rt.scale,scaleY:Gt.scale,offsetX:u,offsetY:d}}return{canvas:G.canvas,scaleX:W.scale,scaleY:U.scale,offsetX:u,offsetY:d}}getSizeAndScale(t,e,s){const i=Math.max(gd.MAX_PATTERN_SIZE,e);let n=Math.ceil(t*s);return n>=i?n=i:s=n/t,{scale:s,size:n}}clipBbox(t,e,s,i,n){const r=i-e,o=n-s;t.ctx.rect(e,s,r,o),t.current.updateRectMinMax(Tt(t.ctx),[e,s,i,n]),t.clip(),t.endPath()}setFillAndStrokeStyleToContext(t,e,s){const i=t.ctx,n=t.current;switch(e){case hb.COLORED:const r=this.ctx;i.fillStyle=r.fillStyle,i.strokeStyle=r.strokeStyle,n.fillColor=r.fillStyle,n.strokeColor=r.strokeStyle;break;case hb.UNCOLORED:const o=X.makeHexColor(s[0],s[1],s[2]);i.fillStyle=o,i.strokeStyle=o,n.fillColor=o,n.strokeColor=o;break;default:throw new ex(`Unsupported paint type: ${e}`)}}getPattern(t,e,s,i){let n=s;i!==_e.SHADING&&(n=X.transform(n,e.baseTransform),this.matrix&&(n=X.transform(n,this.matrix)));const r=this.createPatternCanvas(e);let o=new DOMMatrix(n);o=o.translate(r.offsetX,r.offsetY),o=o.scale(1/r.scaleX,1/r.scaleY);const h=t.createPattern(r.canvas,"repeat");return h.setTransform(o),h}};$(gd,"MAX_PATTERN_SIZE",3e3);let Ag=gd;function Px({src:a,srcPos:t=0,dest:e,width:s,height:i,nonBlackColor:n=4294967295,inverseDecode:r=!1}){const o=Re.isLittleEndian?4278190080:255,[h,c]=r?[n,o]:[o,n],u=s>>3,d=s&7,f=a.length;e=new Uint32Array(e.buffer);let g=0;for(let p=0;p<i;p++){for(const v=t+u;t<v;t++){const _=t<f?a[t]:255;e[g++]=_&128?c:h,e[g++]=_&64?c:h,e[g++]=_&32?c:h,e[g++]=_&16?c:h,e[g++]=_&8?c:h,e[g++]=_&4?c:h,e[g++]=_&2?c:h,e[g++]=_&1?c:h}if(d===0)continue;const b=t<f?a[t++]:255;for(let v=0;v<d;v++)e[g++]=b&1<<7-v?c:h}return{srcPos:t,destPos:g}}const lb=16,cb=100,Dx=15,ub=10,db=1e3,Ue=16;function Ox(a,t){if(a._removeMirroring)throw new Error("Context is already forwarding operations.");a.__originalSave=a.save,a.__originalRestore=a.restore,a.__originalRotate=a.rotate,a.__originalScale=a.scale,a.__originalTranslate=a.translate,a.__originalTransform=a.transform,a.__originalSetTransform=a.setTransform,a.__originalResetTransform=a.resetTransform,a.__originalClip=a.clip,a.__originalMoveTo=a.moveTo,a.__originalLineTo=a.lineTo,a.__originalBezierCurveTo=a.bezierCurveTo,a.__originalRect=a.rect,a.__originalClosePath=a.closePath,a.__originalBeginPath=a.beginPath,a._removeMirroring=()=>{a.save=a.__originalSave,a.restore=a.__originalRestore,a.rotate=a.__originalRotate,a.scale=a.__originalScale,a.translate=a.__originalTranslate,a.transform=a.__originalTransform,a.setTransform=a.__originalSetTransform,a.resetTransform=a.__originalResetTransform,a.clip=a.__originalClip,a.moveTo=a.__originalMoveTo,a.lineTo=a.__originalLineTo,a.bezierCurveTo=a.__originalBezierCurveTo,a.rect=a.__originalRect,a.closePath=a.__originalClosePath,a.beginPath=a.__originalBeginPath,delete a._removeMirroring},a.save=function(){t.save(),this.__originalSave()},a.restore=function(){t.restore(),this.__originalRestore()},a.translate=function(s,i){t.translate(s,i),this.__originalTranslate(s,i)},a.scale=function(s,i){t.scale(s,i),this.__originalScale(s,i)},a.transform=function(s,i,n,r,o,h){t.transform(s,i,n,r,o,h),this.__originalTransform(s,i,n,r,o,h)},a.setTransform=function(s,i,n,r,o,h){t.setTransform(s,i,n,r,o,h),this.__originalSetTransform(s,i,n,r,o,h)},a.resetTransform=function(){t.resetTransform(),this.__originalResetTransform()},a.rotate=function(s){t.rotate(s),this.__originalRotate(s)},a.clip=function(s){t.clip(s),this.__originalClip(s)},a.moveTo=function(e,s){t.moveTo(e,s),this.__originalMoveTo(e,s)},a.lineTo=function(e,s){t.lineTo(e,s),this.__originalLineTo(e,s)},a.bezierCurveTo=function(e,s,i,n,r,o){t.bezierCurveTo(e,s,i,n,r,o),this.__originalBezierCurveTo(e,s,i,n,r,o)},a.rect=function(e,s,i,n){t.rect(e,s,i,n),this.__originalRect(e,s,i,n)},a.closePath=function(){t.closePath(),this.__originalClosePath()},a.beginPath=function(){t.beginPath(),this.__originalBeginPath()}}class Rx{constructor(t){this.canvasFactory=t,this.cache=Object.create(null)}getCanvas(t,e,s){let i;return this.cache[t]!==void 0?(i=this.cache[t],this.canvasFactory.reset(i,e,s)):(i=this.canvasFactory.create(e,s),this.cache[t]=i),i}delete(t){delete this.cache[t]}clear(){for(const t in this.cache){const e=this.cache[t];this.canvasFactory.destroy(e),delete this.cache[t]}}}function Ju(a,t,e,s,i,n,r,o,h,c){const[u,d,f,g,p,b]=Tt(a);if(d===0&&f===0){const x=r*u+p,C=Math.round(x),S=o*g+b,k=Math.round(S),D=(r+h)*u+p,T=Math.abs(Math.round(D)-C)||1,M=(o+c)*g+b,O=Math.abs(Math.round(M)-k)||1;return a.setTransform(Math.sign(u),0,0,Math.sign(g),C,k),a.drawImage(t,e,s,i,n,0,0,T,O),a.setTransform(u,d,f,g,p,b),[T,O]}if(u===0&&g===0){const x=o*f+p,C=Math.round(x),S=r*d+b,k=Math.round(S),D=(o+c)*f+p,T=Math.abs(Math.round(D)-C)||1,M=(r+h)*d+b,O=Math.abs(Math.round(M)-k)||1;return a.setTransform(0,Math.sign(d),Math.sign(f),0,C,k),a.drawImage(t,e,s,i,n,0,0,O,T),a.setTransform(u,d,f,g,p,b),[O,T]}a.drawImage(t,e,s,i,n,r,o,h,c);const v=Math.hypot(u,d),_=Math.hypot(f,g);return[v*h,_*c]}function Lx(a){const{width:t,height:e}=a;if(t>db||e>db)return null;const s=1e3,i=new Uint8Array([0,2,4,0,1,0,5,4,8,10,0,8,0,2,1,0]),n=t+1;let r=new Uint8Array(n*(e+1)),o,h,c;const u=t+7&-8;let d=new Uint8Array(u*e),f=0;for(const _ of a.data){let x=128;for(;x>0;)d[f++]=_&x?0:255,x>>=1}let g=0;for(f=0,d[f]!==0&&(r[0]=1,++g),h=1;h<t;h++)d[f]!==d[f+1]&&(r[h]=d[f]?2:1,++g),f++;for(d[f]!==0&&(r[h]=2,++g),o=1;o<e;o++){f=o*u,c=o*n,d[f-u]!==d[f]&&(r[c]=d[f]?1:8,++g);let _=(d[f]?4:0)+(d[f-u]?8:0);for(h=1;h<t;h++)_=(_>>2)+(d[f+1]?4:0)+(d[f-u+1]?8:0),i[_]&&(r[c+h]=i[_],++g),f++;if(d[f-u]!==d[f]&&(r[c+h]=d[f]?2:4,++g),g>s)return null}for(f=u*(e-1),c=o*n,d[f]!==0&&(r[c]=8,++g),h=1;h<t;h++)d[f]!==d[f+1]&&(r[c+h]=d[f]?4:8,++g),f++;if(d[f]!==0&&(r[c+h]=4,++g),g>s)return null;const p=new Int32Array([0,n,-1,0,-n,0,0,0,1]),b=new Path2D;for(o=0;g&&o<=e;o++){let _=o*n;const x=_+t;for(;_<x&&!r[_];)_++;if(_===x)continue;b.moveTo(_%n,o);const C=_;let S=r[_];do{const k=p[S];do _+=k;while(!r[_]);const D=r[_];D!==5&&D!==10?(S=D,r[_]=0):(S=D&51*S>>4,r[_]&=S>>2|S<<2),b.lineTo(_%n,_/n|0),r[_]||--g}while(C!==_);--o}return d=null,r=null,function(_){_.save(),_.scale(1/t,-1/e),_.translate(0,-e),_.fill(b),_.beginPath(),_.restore()}}class fb{constructor(t,e){this.alphaIsShape=!1,this.fontSize=0,this.fontSizeScale=1,this.textMatrix=U0,this.textMatrixScale=1,this.fontMatrix=ng,this.leading=0,this.x=0,this.y=0,this.lineX=0,this.lineY=0,this.charSpacing=0,this.wordSpacing=0,this.textHScale=1,this.textRenderingMode=ve.FILL,this.textRise=0,this.fillColor="#000000",this.strokeColor="#000000",this.patternFill=!1,this.patternStroke=!1,this.fillAlpha=1,this.strokeAlpha=1,this.lineWidth=1,this.activeSMask=null,this.transferMaps="none",this.startNewPathAndClipBox([0,0,t,e])}clone(){const t=Object.create(this);return t.clipBox=this.clipBox.slice(),t}setCurrentPoint(t,e){this.x=t,this.y=e}updatePathMinMax(t,e,s){[e,s]=X.applyTransform([e,s],t),this.minX=Math.min(this.minX,e),this.minY=Math.min(this.minY,s),this.maxX=Math.max(this.maxX,e),this.maxY=Math.max(this.maxY,s)}updateRectMinMax(t,e){const s=X.applyTransform(e,t),i=X.applyTransform(e.slice(2),t),n=X.applyTransform([e[0],e[3]],t),r=X.applyTransform([e[2],e[1]],t);this.minX=Math.min(this.minX,s[0],i[0],n[0],r[0]),this.minY=Math.min(this.minY,s[1],i[1],n[1],r[1]),this.maxX=Math.max(this.maxX,s[0],i[0],n[0],r[0]),this.maxY=Math.max(this.maxY,s[1],i[1],n[1],r[1])}updateScalingPathMinMax(t,e){X.scaleMinMax(t,e),this.minX=Math.min(this.minX,e[0]),this.minY=Math.min(this.minY,e[1]),this.maxX=Math.max(this.maxX,e[2]),this.maxY=Math.max(this.maxY,e[3])}updateCurvePathMinMax(t,e,s,i,n,r,o,h,c,u){const d=X.bezierBoundingBox(e,s,i,n,r,o,h,c,u);u||this.updateRectMinMax(t,d)}getPathBoundingBox(t=_e.FILL,e=null){const s=[this.minX,this.minY,this.maxX,this.maxY];if(t===_e.STROKE){e||vt("Stroke bounding box must include transform.");const i=X.singularValueDecompose2dScale(e),n=i[0]*this.lineWidth/2,r=i[1]*this.lineWidth/2;s[0]-=n,s[1]-=r,s[2]+=n,s[3]+=r}return s}updateClipFromPath(){const t=X.intersect(this.clipBox,this.getPathBoundingBox());this.startNewPathAndClipBox(t||[0,0,0,0])}isEmptyClip(){return this.minX===1/0}startNewPathAndClipBox(t){this.clipBox=t,this.minX=1/0,this.minY=1/0,this.maxX=0,this.maxY=0}getClippedPathBoundingBox(t=_e.FILL,e=null){return X.intersect(this.clipBox,this.getPathBoundingBox(t,e))}}function gb(a,t){if(t instanceof ImageData){a.putImageData(t,0,0);return}const e=t.height,s=t.width,i=e%Ue,n=(e-i)/Ue,r=i===0?n:n+1,o=a.createImageData(s,Ue);let h=0,c;const u=t.data,d=o.data;let f,g,p,b;if(t.kind===Hu.GRAYSCALE_1BPP){const v=u.byteLength,_=new Uint32Array(d.buffer,0,d.byteLength>>2),x=_.length,C=s+7>>3,S=4294967295,k=Re.isLittleEndian?4278190080:255;for(f=0;f<r;f++){for(p=f<n?Ue:i,c=0,g=0;g<p;g++){const D=v-h;let T=0;const M=D>C?s:D*8-7,O=M&-8;let R=0,L=0;for(;T<O;T+=8)L=u[h++],_[c++]=L&128?S:k,_[c++]=L&64?S:k,_[c++]=L&32?S:k,_[c++]=L&16?S:k,_[c++]=L&8?S:k,_[c++]=L&4?S:k,_[c++]=L&2?S:k,_[c++]=L&1?S:k;for(;T<M;T++)R===0&&(L=u[h++],R=128),_[c++]=L&R?S:k,R>>=1}for(;c<x;)_[c++]=0;a.putImageData(o,0,f*Ue)}}else if(t.kind===Hu.RGBA_32BPP){for(g=0,b=s*Ue*4,f=0;f<n;f++)d.set(u.subarray(h,h+b)),h+=b,a.putImageData(o,0,g),g+=Ue;f<r&&(b=s*i*4,d.set(u.subarray(h,h+b)),a.putImageData(o,0,g))}else if(t.kind===Hu.RGB_24BPP)for(p=Ue,b=s*p,f=0;f<r;f++){for(f>=n&&(p=i,b=s*p),c=0,g=b;g--;)d[c++]=u[h++],d[c++]=u[h++],d[c++]=u[h++],d[c++]=255;a.putImageData(o,0,f*Ue)}else throw new Error(`bad image kind: ${t.kind}`)}function pb(a,t){if(t.bitmap){a.drawImage(t.bitmap,0,0);return}const e=t.height,s=t.width,i=e%Ue,n=(e-i)/Ue,r=i===0?n:n+1,o=a.createImageData(s,Ue);let h=0;const c=t.data,u=o.data;for(let d=0;d<r;d++){const f=d<n?Ue:i;({srcPos:h}=Px({src:c,srcPos:h,dest:u,width:s,height:f,nonBlackColor:0})),a.putImageData(o,0,d*Ue)}}function Uh(a,t){const e=["strokeStyle","fillStyle","fillRule","globalAlpha","lineWidth","lineCap","lineJoin","miterLimit","globalCompositeOperation","font","filter"];for(const s of e)a[s]!==void 0&&(t[s]=a[s]);a.setLineDash!==void 0&&(t.setLineDash(a.getLineDash()),t.lineDashOffset=a.lineDashOffset)}function Zu(a){if(a.strokeStyle=a.fillStyle="#000000",a.fillRule="nonzero",a.globalAlpha=1,a.lineWidth=1,a.lineCap="butt",a.lineJoin="miter",a.miterLimit=10,a.globalCompositeOperation="source-over",a.font="10px sans-serif",a.setLineDash!==void 0&&(a.setLineDash([]),a.lineDashOffset=0),!ye){const{filter:t}=a;t!=="none"&&t!==""&&(a.filter="none")}}function mb(a,t){if(t)return!0;const e=X.singularValueDecompose2dScale(a);e[0]=Math.fround(e[0]),e[1]=Math.fround(e[1]);const s=Math.fround((globalThis.devicePixelRatio||1)*Ln.PDF_TO_CSS_UNITS);return e[0]<=s&&e[1]<=s}const Fx=["butt","round","square"],Ix=["miter","round","bevel"],Nx={},bb={},Xg=class Xg{constructor(t,e,s,i,n,{optionalContentConfig:r,markedContentStack:o=null},h,c){y(this,Ys);this.ctx=t,this.current=new fb(this.ctx.canvas.width,this.ctx.canvas.height),this.stateStack=[],this.pendingClip=null,this.pendingEOFill=!1,this.res=null,this.xobjs=null,this.commonObjs=e,this.objs=s,this.canvasFactory=i,this.filterFactory=n,this.groupStack=[],this.processingType3=null,this.baseTransform=null,this.baseTransformStack=[],this.groupLevel=0,this.smaskStack=[],this.smaskCounter=0,this.tempSMask=null,this.suspendedCtx=null,this.contentVisible=!0,this.markedContentStack=o||[],this.optionalContentConfig=r,this.cachedCanvases=new Rx(this.canvasFactory),this.cachedPatterns=new Map,this.annotationCanvasMap=h,this.viewportScale=1,this.outputScaleX=1,this.outputScaleY=1,this.pageColors=c,this._cachedScaleForStroking=[-1,0],this._cachedGetSinglePixelWidth=null,this._cachedBitmapsMap=new Map}getObject(t,e=null){return typeof t=="string"?t.startsWith("g_")?this.commonObjs.get(t):this.objs.get(t):e}beginDrawing({transform:t,viewport:e,transparency:s=!1,background:i=null}){const n=this.ctx.canvas.width,r=this.ctx.canvas.height,o=this.ctx.fillStyle;if(this.ctx.fillStyle=i||"#ffffff",this.ctx.fillRect(0,0,n,r),this.ctx.fillStyle=o,s){const h=this.cachedCanvases.getCanvas("transparent",n,r);this.compositeCtx=this.ctx,this.transparentCanvas=h.canvas,this.ctx=h.context,this.ctx.save(),this.ctx.transform(...Tt(this.compositeCtx))}this.ctx.save(),Zu(this.ctx),t&&(this.ctx.transform(...t),this.outputScaleX=t[0],this.outputScaleY=t[0]),this.ctx.transform(...e.transform),this.viewportScale=e.scale,this.baseTransform=Tt(this.ctx)}executeOperatorList(t,e,s,i){const n=t.argsArray,r=t.fnArray;let o=e||0;const h=n.length;if(h===o)return o;const c=h-o>ub&&typeof s=="function",u=c?Date.now()+Dx:0;let d=0;const f=this.commonObjs,g=this.objs;let p;for(;;){if(i!==void 0&&o===i.nextBreakPoint)return i.breakIt(o,s),o;if(p=r[o],p!==Hs.dependency)this[p].apply(this,n[o]);else for(const b of n[o]){const v=b.startsWith("g_")?f:g;if(!v.has(b))return v.get(b,s),o}if(o++,o===h)return o;if(c&&++d>ub){if(Date.now()>u)return s(),o;d=0}}}endDrawing(){w(this,Ys,fp).call(this),this.cachedCanvases.clear(),this.cachedPatterns.clear();for(const t of this._cachedBitmapsMap.values()){for(const e of t.values())typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement&&(e.width=e.height=0);t.clear()}this._cachedBitmapsMap.clear(),w(this,Ys,gp).call(this)}_scaleImage(t,e){const s=t.width??t.displayWidth,i=t.height??t.displayHeight;let n=Math.max(Math.hypot(e[0],e[1]),1),r=Math.max(Math.hypot(e[2],e[3]),1),o=s,h=i,c="prescale1",u,d;for(;n>2&&o>1||r>2&&h>1;){let f=o,g=h;n>2&&o>1&&(f=o>=16384?Math.floor(o/2)-1||1:Math.ceil(o/2),n/=o/f),r>2&&h>1&&(g=h>=16384?Math.floor(h/2)-1||1:Math.ceil(h)/2,r/=h/g),u=this.cachedCanvases.getCanvas(c,f,g),d=u.context,d.clearRect(0,0,f,g),d.drawImage(t,0,0,o,h,0,0,f,g),t=u.canvas,o=f,h=g,c=c==="prescale1"?"prescale2":"prescale1"}return{img:t,paintWidth:o,paintHeight:h}}_createMaskCanvas(t){const e=this.ctx,{width:s,height:i}=t,n=this.current.fillColor,r=this.current.patternFill,o=Tt(e);let h,c,u,d;if((t.bitmap||t.data)&&t.count>1){const M=t.bitmap||t.data.buffer;c=JSON.stringify(r?o:[o.slice(0,4),n]),h=this._cachedBitmapsMap.get(M),h||(h=new Map,this._cachedBitmapsMap.set(M,h));const O=h.get(c);if(O&&!r){const R=Math.round(Math.min(o[0],o[2])+o[4]),L=Math.round(Math.min(o[1],o[3])+o[5]);return{canvas:O,offsetX:R,offsetY:L}}u=O}u||(d=this.cachedCanvases.getCanvas("maskCanvas",s,i),pb(d.context,t));let f=X.transform(o,[1/s,0,0,-1/i,0,0]);f=X.transform(f,[1,0,0,1,0,-i]);const[g,p,b,v]=X.getAxialAlignedBoundingBox([0,0,s,i],f),_=Math.round(b-g)||1,x=Math.round(v-p)||1,C=this.cachedCanvases.getCanvas("fillCanvas",_,x),S=C.context,k=g,D=p;S.translate(-k,-D),S.transform(...f),u||(u=this._scaleImage(d.canvas,li(S)),u=u.img,h&&r&&h.set(c,u)),S.imageSmoothingEnabled=mb(Tt(S),t.interpolate),Ju(S,u,0,0,u.width,u.height,0,0,s,i),S.globalCompositeOperation="source-in";const T=X.transform(li(S),[1,0,0,1,-k,-D]);return S.fillStyle=r?n.getPattern(e,this,T,_e.FILL):n,S.fillRect(0,0,s,i),h&&!r&&(this.cachedCanvases.delete("fillCanvas"),h.set(c,C.canvas)),{canvas:C.canvas,offsetX:Math.round(k),offsetY:Math.round(D)}}setLineWidth(t){t!==this.current.lineWidth&&(this._cachedScaleForStroking[0]=-1),this.current.lineWidth=t,this.ctx.lineWidth=t}setLineCap(t){this.ctx.lineCap=Fx[t]}setLineJoin(t){this.ctx.lineJoin=Ix[t]}setMiterLimit(t){this.ctx.miterLimit=t}setDash(t,e){const s=this.ctx;s.setLineDash!==void 0&&(s.setLineDash(t),s.lineDashOffset=e)}setRenderingIntent(t){}setFlatness(t){}setGState(t){for(const[e,s]of t)switch(e){case"LW":this.setLineWidth(s);break;case"LC":this.setLineCap(s);break;case"LJ":this.setLineJoin(s);break;case"ML":this.setMiterLimit(s);break;case"D":this.setDash(s[0],s[1]);break;case"RI":this.setRenderingIntent(s);break;case"FL":this.setFlatness(s);break;case"Font":this.setFont(s[0],s[1]);break;case"CA":this.current.strokeAlpha=s;break;case"ca":this.current.fillAlpha=s,this.ctx.globalAlpha=s;break;case"BM":this.ctx.globalCompositeOperation=s;break;case"SMask":this.current.activeSMask=s?this.tempSMask:null,this.tempSMask=null,this.checkSMaskState();break;case"TR":this.ctx.filter=this.current.transferMaps=this.filterFactory.addFilter(s);break}}get inSMaskMode(){return!!this.suspendedCtx}checkSMaskState(){const t=this.inSMaskMode;this.current.activeSMask&&!t?this.beginSMaskMode():!this.current.activeSMask&&t&&this.endSMaskMode()}beginSMaskMode(){if(this.inSMaskMode)throw new Error("beginSMaskMode called while already in smask mode");const t=this.ctx.canvas.width,e=this.ctx.canvas.height,s="smaskGroupAt"+this.groupLevel,i=this.cachedCanvases.getCanvas(s,t,e);this.suspendedCtx=this.ctx,this.ctx=i.context;const n=this.ctx;n.setTransform(...Tt(this.suspendedCtx)),Uh(this.suspendedCtx,n),Ox(n,this.suspendedCtx),this.setGState([["BM","source-over"],["ca",1],["CA",1]])}endSMaskMode(){if(!this.inSMaskMode)throw new Error("endSMaskMode called while not in smask mode");this.ctx._removeMirroring(),Uh(this.ctx,this.suspendedCtx),this.ctx=this.suspendedCtx,this.suspendedCtx=null}compose(t){if(!this.current.activeSMask)return;t?(t[0]=Math.floor(t[0]),t[1]=Math.floor(t[1]),t[2]=Math.ceil(t[2]),t[3]=Math.ceil(t[3])):t=[0,0,this.ctx.canvas.width,this.ctx.canvas.height];const e=this.current.activeSMask,s=this.suspendedCtx;this.composeSMask(s,e,this.ctx,t),this.ctx.save(),this.ctx.setTransform(1,0,0,1,0,0),this.ctx.clearRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height),this.ctx.restore()}composeSMask(t,e,s,i){const n=i[0],r=i[1],o=i[2]-n,h=i[3]-r;o===0||h===0||(this.genericComposeSMask(e.context,s,o,h,e.subtype,e.backdrop,e.transferMap,n,r,e.offsetX,e.offsetY),t.save(),t.globalAlpha=1,t.globalCompositeOperation="source-over",t.setTransform(1,0,0,1,0,0),t.drawImage(s.canvas,0,0),t.restore())}genericComposeSMask(t,e,s,i,n,r,o,h,c,u,d){let f=t.canvas,g=h-u,p=c-d;if(r){const v=X.makeHexColor(...r);if(g<0||p<0||g+s>f.width||p+i>f.height){const _=this.cachedCanvases.getCanvas("maskExtension",s,i),x=_.context;x.drawImage(f,-g,-p),x.globalCompositeOperation="destination-atop",x.fillStyle=v,x.fillRect(0,0,s,i),x.globalCompositeOperation="source-over",f=_.canvas,g=p=0}else{t.save(),t.globalAlpha=1,t.setTransform(1,0,0,1,0,0);const _=new Path2D;_.rect(g,p,s,i),t.clip(_),t.globalCompositeOperation="destination-atop",t.fillStyle=v,t.fillRect(g,p,s,i),t.restore()}}e.save(),e.globalAlpha=1,e.setTransform(1,0,0,1,0,0),n==="Alpha"&&o?e.filter=this.filterFactory.addAlphaFilter(o):n==="Luminosity"&&(e.filter=this.filterFactory.addLuminosityFilter(o));const b=new Path2D;b.rect(h,c,s,i),e.clip(b),e.globalCompositeOperation="destination-in",e.drawImage(f,g,p,s,i,h,c,s,i),e.restore()}save(){this.inSMaskMode?(Uh(this.ctx,this.suspendedCtx),this.suspendedCtx.save()):this.ctx.save();const t=this.current;this.stateStack.push(t),this.current=t.clone()}restore(){this.stateStack.length===0&&this.inSMaskMode&&this.endSMaskMode(),this.stateStack.length!==0&&(this.current=this.stateStack.pop(),this.inSMaskMode?(this.suspendedCtx.restore(),Uh(this.suspendedCtx,this.ctx)):this.ctx.restore(),this.checkSMaskState(),this.pendingClip=null,this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null)}transform(t,e,s,i,n,r){this.ctx.transform(t,e,s,i,n,r),this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null}constructPath(t,e,s){const i=this.ctx,n=this.current;let r=n.x,o=n.y,h,c;const u=Tt(i),d=u[0]===0&&u[3]===0||u[1]===0&&u[2]===0,f=d?s.slice(0):null;for(let g=0,p=0,b=t.length;g<b;g++)switch(t[g]|0){case Hs.rectangle:r=e[p++],o=e[p++];const v=e[p++],_=e[p++],x=r+v,C=o+_;i.moveTo(r,o),v===0||_===0?i.lineTo(x,C):(i.lineTo(x,o),i.lineTo(x,C),i.lineTo(r,C)),d||n.updateRectMinMax(u,[r,o,x,C]),i.closePath();break;case Hs.moveTo:r=e[p++],o=e[p++],i.moveTo(r,o),d||n.updatePathMinMax(u,r,o);break;case Hs.lineTo:r=e[p++],o=e[p++],i.lineTo(r,o),d||n.updatePathMinMax(u,r,o);break;case Hs.curveTo:h=r,c=o,r=e[p+4],o=e[p+5],i.bezierCurveTo(e[p],e[p+1],e[p+2],e[p+3],r,o),n.updateCurvePathMinMax(u,h,c,e[p],e[p+1],e[p+2],e[p+3],r,o,f),p+=6;break;case Hs.curveTo2:h=r,c=o,i.bezierCurveTo(r,o,e[p],e[p+1],e[p+2],e[p+3]),n.updateCurvePathMinMax(u,h,c,r,o,e[p],e[p+1],e[p+2],e[p+3],f),r=e[p+2],o=e[p+3],p+=4;break;case Hs.curveTo3:h=r,c=o,r=e[p+2],o=e[p+3],i.bezierCurveTo(e[p],e[p+1],r,o,r,o),n.updateCurvePathMinMax(u,h,c,e[p],e[p+1],r,o,r,o,f),p+=4;break;case Hs.closePath:i.closePath();break}d&&n.updateScalingPathMinMax(u,f),n.setCurrentPoint(r,o)}closePath(){this.ctx.closePath()}stroke(t=!0){const e=this.ctx,s=this.current.strokeColor;e.globalAlpha=this.current.strokeAlpha,this.contentVisible&&(typeof s=="object"&&(s!=null&&s.getPattern)?(e.save(),e.strokeStyle=s.getPattern(e,this,li(e),_e.STROKE),this.rescaleAndStroke(!1),e.restore()):this.rescaleAndStroke(!0)),t&&this.consumePath(this.current.getClippedPathBoundingBox()),e.globalAlpha=this.current.fillAlpha}closeStroke(){this.closePath(),this.stroke()}fill(t=!0){const e=this.ctx,s=this.current.fillColor,i=this.current.patternFill;let n=!1;i&&(e.save(),e.fillStyle=s.getPattern(e,this,li(e),_e.FILL),n=!0);const r=this.current.getClippedPathBoundingBox();this.contentVisible&&r!==null&&(this.pendingEOFill?(e.fill("evenodd"),this.pendingEOFill=!1):e.fill()),n&&e.restore(),t&&this.consumePath(r)}eoFill(){this.pendingEOFill=!0,this.fill()}fillStroke(){this.fill(!1),this.stroke(!1),this.consumePath()}eoFillStroke(){this.pendingEOFill=!0,this.fillStroke()}closeFillStroke(){this.closePath(),this.fillStroke()}closeEOFillStroke(){this.pendingEOFill=!0,this.closePath(),this.fillStroke()}endPath(){this.consumePath()}clip(){this.pendingClip=Nx}eoClip(){this.pendingClip=bb}beginText(){this.current.textMatrix=U0,this.current.textMatrixScale=1,this.current.x=this.current.lineX=0,this.current.y=this.current.lineY=0}endText(){const t=this.pendingTextPaths,e=this.ctx;if(t===void 0){e.beginPath();return}const s=new Path2D,i=e.getTransform().invertSelf();for(const{transform:n,x:r,y:o,fontSize:h,path:c}of t)s.addPath(c,new DOMMatrix(n).preMultiplySelf(i).translate(r,o).scale(h,-h));e.clip(s),e.beginPath(),delete this.pendingTextPaths}setCharSpacing(t){this.current.charSpacing=t}setWordSpacing(t){this.current.wordSpacing=t}setHScale(t){this.current.textHScale=t/100}setLeading(t){this.current.leading=-t}setFont(t,e){var u;const s=this.commonObjs.get(t),i=this.current;if(!s)throw new Error(`Can't find font for ${t}`);if(i.fontMatrix=s.fontMatrix||ng,(i.fontMatrix[0]===0||i.fontMatrix[3]===0)&&tt("Invalid font matrix for font "+t),e<0?(e=-e,i.fontDirection=-1):i.fontDirection=1,this.current.font=s,this.current.fontSize=e,s.isType3Font)return;const n=s.loadedName||"sans-serif",r=((u=s.systemFontInfo)==null?void 0:u.css)||`"${n}", ${s.fallbackName}`;let o="normal";s.black?o="900":s.bold&&(o="bold");const h=s.italic?"italic":"normal";let c=e;e<lb?c=lb:e>cb&&(c=cb),this.current.fontSizeScale=e/c,this.ctx.font=`${h} ${o} ${c}px ${r}`}setTextRenderingMode(t){this.current.textRenderingMode=t}setTextRise(t){this.current.textRise=t}moveText(t,e){this.current.x=this.current.lineX+=t,this.current.y=this.current.lineY+=e}setLeadingMoveText(t,e){this.setLeading(-e),this.moveText(t,e)}setTextMatrix(t,e,s,i,n,r){this.current.textMatrix=[t,e,s,i,n,r],this.current.textMatrixScale=Math.hypot(t,e),this.current.x=this.current.lineX=0,this.current.y=this.current.lineY=0}nextLine(){this.moveText(0,this.current.leading)}paintChar(t,e,s,i,n){const r=this.ctx,o=this.current,h=o.font,c=o.textRenderingMode,u=o.fontSize/o.fontSizeScale,d=c&ve.FILL_STROKE_MASK,f=!!(c&ve.ADD_TO_PATH_FLAG),g=o.patternFill&&!h.missingFile,p=o.patternStroke&&!h.missingFile;let b;if((h.disableFontFace||f||g||p)&&(b=h.getPathGenerator(this.commonObjs,t)),h.disableFontFace||g||p){if(r.save(),r.translate(e,s),r.scale(u,-u),d===ve.FILL||d===ve.FILL_STROKE)if(i){const v=r.getTransform();r.setTransform(...i),r.fill(w(this,Ys,pp).call(this,b,v,i))}else r.fill(b);if(d===ve.STROKE||d===ve.FILL_STROKE)if(n){const v=r.getTransform();r.setTransform(...n),r.stroke(w(this,Ys,pp).call(this,b,v,n))}else r.lineWidth/=u,r.stroke(b);r.restore()}else(d===ve.FILL||d===ve.FILL_STROKE)&&r.fillText(t,e,s),(d===ve.STROKE||d===ve.FILL_STROKE)&&r.strokeText(t,e,s);f&&(this.pendingTextPaths||(this.pendingTextPaths=[])).push({transform:Tt(r),x:e,y:s,fontSize:u,path:b})}get isFontSubpixelAAEnabled(){const{context:t}=this.cachedCanvases.getCanvas("isFontSubpixelAAEnabled",10,10);t.scale(1.5,1),t.fillText("I",0,10);const e=t.getImageData(0,0,10,10).data;let s=!1;for(let i=3;i<e.length;i+=4)if(e[i]>0&&e[i]<255){s=!0;break}return st(this,"isFontSubpixelAAEnabled",s)}showText(t){const e=this.current,s=e.font;if(s.isType3Font)return this.showType3Text(t);const i=e.fontSize;if(i===0)return;const n=this.ctx,r=e.fontSizeScale,o=e.charSpacing,h=e.wordSpacing,c=e.fontDirection,u=e.textHScale*c,d=t.length,f=s.vertical,g=f?1:-1,p=s.defaultVMetrics,b=i*e.fontMatrix[0],v=e.textRenderingMode===ve.FILL&&!s.disableFontFace&&!e.patternFill;n.save(),n.transform(...e.textMatrix),n.translate(e.x,e.y+e.textRise),c>0?n.scale(u,-1):n.scale(u,1);let _,x;if(e.patternFill){n.save();const T=e.fillColor.getPattern(n,this,li(n),_e.FILL);_=Tt(n),n.restore(),n.fillStyle=T}if(e.patternStroke){n.save();const T=e.strokeColor.getPattern(n,this,li(n),_e.STROKE);x=Tt(n),n.restore(),n.strokeStyle=T}let C=e.lineWidth;const S=e.textMatrixScale;if(S===0||C===0){const T=e.textRenderingMode&ve.FILL_STROKE_MASK;(T===ve.STROKE||T===ve.FILL_STROKE)&&(C=this.getSinglePixelWidth())}else C/=S;if(r!==1&&(n.scale(r,r),C/=r),n.lineWidth=C,s.isInvalidPDFjsFont){const T=[];let M=0;for(const O of t)T.push(O.unicode),M+=O.width;n.fillText(T.join(""),0,0),e.x+=M*b*u,n.restore(),this.compose();return}let k=0,D;for(D=0;D<d;++D){const T=t[D];if(typeof T=="number"){k+=g*T*i/1e3;continue}let M=!1;const O=(T.isSpace?h:0)+o,R=T.fontChar,L=T.accent;let W,U,G=T.width;if(f){const F=T.vmetric||p,z=-(T.vmetric?F[1]:G*.5)*b,rt=F[2]*b;G=F?-F[0]:G,W=z/r,U=(k+rt)/r}else W=k/r,U=0;if(s.remeasure&&G>0){const F=n.measureText(R).width*1e3/i*r;if(G<F&&this.isFontSubpixelAAEnabled){const z=G/F;M=!0,n.save(),n.scale(z,1),W/=z}else G!==F&&(W+=(G-F)/2e3*i/r)}if(this.contentVisible&&(T.isInFont||s.missingFile)){if(v&&!L)n.fillText(R,W,U);else if(this.paintChar(R,W,U,_,x),L){const F=W+i*L.offset.x/r,z=U-i*L.offset.y/r;this.paintChar(L.fontChar,F,z,_,x)}}const at=f?G*b-O*c:G*b+O*c;k+=at,M&&n.restore()}f?e.y-=k:e.x+=k*u,n.restore(),this.compose()}showType3Text(t){const e=this.ctx,s=this.current,i=s.font,n=s.fontSize,r=s.fontDirection,o=i.vertical?1:-1,h=s.charSpacing,c=s.wordSpacing,u=s.textHScale*r,d=s.fontMatrix||ng,f=t.length,g=s.textRenderingMode===ve.INVISIBLE;let p,b,v,_;if(!(g||n===0)){for(this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null,e.save(),e.transform(...s.textMatrix),e.translate(s.x,s.y),e.scale(u,r),p=0;p<f;++p){if(b=t[p],typeof b=="number"){_=o*b*n/1e3,this.ctx.translate(_,0),s.x+=_*u;continue}const x=(b.isSpace?c:0)+h,C=i.charProcOperatorList[b.operatorListId];if(!C){tt(`Type3 character "${b.operatorListId}" is not available.`);continue}this.contentVisible&&(this.processingType3=b,this.save(),e.scale(n,n),e.transform(...d),this.executeOperatorList(C),this.restore()),v=X.applyTransform([b.width,0],d)[0]*n+x,e.translate(v,0),s.x+=v*u}e.restore(),this.processingType3=null}}setCharWidth(t,e){}setCharWidthAndBounds(t,e,s,i,n,r){this.ctx.rect(s,i,n-s,r-i),this.ctx.clip(),this.endPath()}getColorN_Pattern(t){let e;if(t[0]==="TilingPattern"){const s=t[1],i=this.baseTransform||Tt(this.ctx),n={createCanvasGraphics:r=>new Xg(r,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:this.optionalContentConfig,markedContentStack:this.markedContentStack})};e=new Ag(t,s,this.ctx,n,i)}else e=this._getPattern(t[1],t[2]);return e}setStrokeColorN(){this.current.strokeColor=this.getColorN_Pattern(arguments),this.current.patternStroke=!0}setFillColorN(){this.current.fillColor=this.getColorN_Pattern(arguments),this.current.patternFill=!0}setStrokeRGBColor(t,e,s){this.ctx.strokeStyle=this.current.strokeColor=X.makeHexColor(t,e,s),this.current.patternStroke=!1}setStrokeTransparent(){this.ctx.strokeStyle=this.current.strokeColor="transparent",this.current.patternStroke=!1}setFillRGBColor(t,e,s){this.ctx.fillStyle=this.current.fillColor=X.makeHexColor(t,e,s),this.current.patternFill=!1}setFillTransparent(){this.ctx.fillStyle=this.current.fillColor="transparent",this.current.patternFill=!1}_getPattern(t,e=null){let s;return this.cachedPatterns.has(t)?s=this.cachedPatterns.get(t):(s=Mx(this.getObject(t)),this.cachedPatterns.set(t,s)),e&&(s.matrix=e),s}shadingFill(t){if(!this.contentVisible)return;const e=this.ctx;this.save();const s=this._getPattern(t);e.fillStyle=s.getPattern(e,this,li(e),_e.SHADING);const i=li(e);if(i){const{width:n,height:r}=e.canvas,[o,h,c,u]=X.getAxialAlignedBoundingBox([0,0,n,r],i);this.ctx.fillRect(o,h,c-o,u-h)}else this.ctx.fillRect(-1e10,-1e10,2e10,2e10);this.compose(this.current.getClippedPathBoundingBox()),this.restore()}beginInlineImage(){vt("Should not call beginInlineImage")}beginImageData(){vt("Should not call beginImageData")}paintFormXObjectBegin(t,e){if(this.contentVisible&&(this.save(),this.baseTransformStack.push(this.baseTransform),t&&this.transform(...t),this.baseTransform=Tt(this.ctx),e)){const s=e[2]-e[0],i=e[3]-e[1];this.ctx.rect(e[0],e[1],s,i),this.current.updateRectMinMax(Tt(this.ctx),e),this.clip(),this.endPath()}}paintFormXObjectEnd(){this.contentVisible&&(this.restore(),this.baseTransform=this.baseTransformStack.pop())}beginGroup(t){if(!this.contentVisible)return;this.save(),this.inSMaskMode&&(this.endSMaskMode(),this.current.activeSMask=null);const e=this.ctx;t.isolated||Vu("TODO: Support non-isolated groups."),t.knockout&&tt("Knockout groups not supported.");const s=Tt(e);if(t.matrix&&e.transform(...t.matrix),!t.bbox)throw new Error("Bounding box is required.");let i=X.getAxialAlignedBoundingBox(t.bbox,Tt(e));const n=[0,0,e.canvas.width,e.canvas.height];i=X.intersect(i,n)||[0,0,0,0];const r=Math.floor(i[0]),o=Math.floor(i[1]),h=Math.max(Math.ceil(i[2])-r,1),c=Math.max(Math.ceil(i[3])-o,1);this.current.startNewPathAndClipBox([0,0,h,c]);let u="groupAt"+this.groupLevel;t.smask&&(u+="_smask_"+this.smaskCounter++%2);const d=this.cachedCanvases.getCanvas(u,h,c),f=d.context;f.translate(-r,-o),f.transform(...s),t.smask?this.smaskStack.push({canvas:d.canvas,context:f,offsetX:r,offsetY:o,subtype:t.smask.subtype,backdrop:t.smask.backdrop,transferMap:t.smask.transferMap||null,startTransformInverse:null}):(e.setTransform(1,0,0,1,0,0),e.translate(r,o),e.save()),Uh(e,f),this.ctx=f,this.setGState([["BM","source-over"],["ca",1],["CA",1]]),this.groupStack.push(e),this.groupLevel++}endGroup(t){if(!this.contentVisible)return;this.groupLevel--;const e=this.ctx,s=this.groupStack.pop();if(this.ctx=s,this.ctx.imageSmoothingEnabled=!1,t.smask)this.tempSMask=this.smaskStack.pop(),this.restore();else{this.ctx.restore();const i=Tt(this.ctx);this.restore(),this.ctx.save(),this.ctx.setTransform(...i);const n=X.getAxialAlignedBoundingBox([0,0,e.canvas.width,e.canvas.height],i);this.ctx.drawImage(e.canvas,0,0),this.ctx.restore(),this.compose(n)}}beginAnnotation(t,e,s,i,n){if(w(this,Ys,fp).call(this),Zu(this.ctx),this.ctx.save(),this.save(),this.baseTransform&&this.ctx.setTransform(...this.baseTransform),e){const r=e[2]-e[0],o=e[3]-e[1];if(n&&this.annotationCanvasMap){s=s.slice(),s[4]-=e[0],s[5]-=e[1],e=e.slice(),e[0]=e[1]=0,e[2]=r,e[3]=o;const[h,c]=X.singularValueDecompose2dScale(Tt(this.ctx)),{viewportScale:u}=this,d=Math.ceil(r*this.outputScaleX*u),f=Math.ceil(o*this.outputScaleY*u);this.annotationCanvas=this.canvasFactory.create(d,f);const{canvas:g,context:p}=this.annotationCanvas;this.annotationCanvasMap.set(t,g),this.annotationCanvas.savedCtx=this.ctx,this.ctx=p,this.ctx.save(),this.ctx.setTransform(h,0,0,-c,0,o*c),Zu(this.ctx)}else Zu(this.ctx),this.endPath(),this.ctx.rect(e[0],e[1],r,o),this.ctx.clip(),this.ctx.beginPath()}this.current=new fb(this.ctx.canvas.width,this.ctx.canvas.height),this.transform(...s),this.transform(...i)}endAnnotation(){this.annotationCanvas&&(this.ctx.restore(),w(this,Ys,gp).call(this),this.ctx=this.annotationCanvas.savedCtx,delete this.annotationCanvas.savedCtx,delete this.annotationCanvas)}paintImageMaskXObject(t){if(!this.contentVisible)return;const e=t.count;t=this.getObject(t.data,t),t.count=e;const s=this.ctx,i=this.processingType3;if(i&&(i.compiled===void 0&&(i.compiled=Lx(t)),i.compiled)){i.compiled(s);return}const n=this._createMaskCanvas(t),r=n.canvas;s.save(),s.setTransform(1,0,0,1,0,0),s.drawImage(r,n.offsetX,n.offsetY),s.restore(),this.compose()}paintImageMaskXObjectRepeat(t,e,s=0,i=0,n,r){if(!this.contentVisible)return;t=this.getObject(t.data,t);const o=this.ctx;o.save();const h=Tt(o);o.transform(e,s,i,n,0,0);const c=this._createMaskCanvas(t);o.setTransform(1,0,0,1,c.offsetX-h[4],c.offsetY-h[5]);for(let u=0,d=r.length;u<d;u+=2){const f=X.transform(h,[e,s,i,n,r[u],r[u+1]]),[g,p]=X.applyTransform([0,0],f);o.drawImage(c.canvas,g,p)}o.restore(),this.compose()}paintImageMaskXObjectGroup(t){if(!this.contentVisible)return;const e=this.ctx,s=this.current.fillColor,i=this.current.patternFill;for(const n of t){const{data:r,width:o,height:h,transform:c}=n,u=this.cachedCanvases.getCanvas("maskCanvas",o,h),d=u.context;d.save();const f=this.getObject(r,n);pb(d,f),d.globalCompositeOperation="source-in",d.fillStyle=i?s.getPattern(d,this,li(e),_e.FILL):s,d.fillRect(0,0,o,h),d.restore(),e.save(),e.transform(...c),e.scale(1,-1),Ju(e,u.canvas,0,0,o,h,0,-1,1,1),e.restore()}this.compose()}paintImageXObject(t){if(!this.contentVisible)return;const e=this.getObject(t);if(!e){tt("Dependent image isn't ready yet");return}this.paintInlineImageXObject(e)}paintImageXObjectRepeat(t,e,s,i){if(!this.contentVisible)return;const n=this.getObject(t);if(!n){tt("Dependent image isn't ready yet");return}const r=n.width,o=n.height,h=[];for(let c=0,u=i.length;c<u;c+=2)h.push({transform:[e,0,0,s,i[c],i[c+1]],x:0,y:0,w:r,h:o});this.paintInlineImageXObjectGroup(n,h)}applyTransferMapsToCanvas(t){return this.current.transferMaps!=="none"&&(t.filter=this.current.transferMaps,t.drawImage(t.canvas,0,0),t.filter="none"),t.canvas}applyTransferMapsToBitmap(t){if(this.current.transferMaps==="none")return t.bitmap;const{bitmap:e,width:s,height:i}=t,n=this.cachedCanvases.getCanvas("inlineImage",s,i),r=n.context;return r.filter=this.current.transferMaps,r.drawImage(e,0,0),r.filter="none",n.canvas}paintInlineImageXObject(t){if(!this.contentVisible)return;const e=t.width,s=t.height,i=this.ctx;if(this.save(),!ye){const{filter:o}=i;o!=="none"&&o!==""&&(i.filter="none")}i.scale(1/e,-1/s);let n;if(t.bitmap)n=this.applyTransferMapsToBitmap(t);else if(typeof HTMLElement=="function"&&t instanceof HTMLElement||!t.data)n=t;else{const h=this.cachedCanvases.getCanvas("inlineImage",e,s).context;gb(h,t),n=this.applyTransferMapsToCanvas(h)}const r=this._scaleImage(n,li(i));i.imageSmoothingEnabled=mb(Tt(i),t.interpolate),Ju(i,r.img,0,0,r.paintWidth,r.paintHeight,0,-s,e,s),this.compose(),this.restore()}paintInlineImageXObjectGroup(t,e){if(!this.contentVisible)return;const s=this.ctx;let i;if(t.bitmap)i=t.bitmap;else{const n=t.width,r=t.height,h=this.cachedCanvases.getCanvas("inlineImage",n,r).context;gb(h,t),i=this.applyTransferMapsToCanvas(h)}for(const n of e)s.save(),s.transform(...n.transform),s.scale(1,-1),Ju(s,i,n.x,n.y,n.w,n.h,0,-1,1,1),s.restore();this.compose()}paintSolidColorImageMask(){this.contentVisible&&(this.ctx.fillRect(0,0,1,1),this.compose())}markPoint(t){}markPointProps(t,e){}beginMarkedContent(t){this.markedContentStack.push({visible:!0})}beginMarkedContentProps(t,e){t==="OC"?this.markedContentStack.push({visible:this.optionalContentConfig.isVisible(e)}):this.markedContentStack.push({visible:!0}),this.contentVisible=this.isContentVisible()}endMarkedContent(){this.markedContentStack.pop(),this.contentVisible=this.isContentVisible()}beginCompat(){}endCompat(){}consumePath(t){const e=this.current.isEmptyClip();this.pendingClip&&this.current.updateClipFromPath(),this.pendingClip||this.compose(t);const s=this.ctx;this.pendingClip&&(e||(this.pendingClip===bb?s.clip("evenodd"):s.clip()),this.pendingClip=null),this.current.startNewPathAndClipBox(this.current.clipBox),s.beginPath()}getSinglePixelWidth(){if(!this._cachedGetSinglePixelWidth){const t=Tt(this.ctx);if(t[1]===0&&t[2]===0)this._cachedGetSinglePixelWidth=1/Math.min(Math.abs(t[0]),Math.abs(t[3]));else{const e=Math.abs(t[0]*t[3]-t[2]*t[1]),s=Math.hypot(t[0],t[2]),i=Math.hypot(t[1],t[3]);this._cachedGetSinglePixelWidth=Math.max(s,i)/e}}return this._cachedGetSinglePixelWidth}getScaleForStroking(){if(this._cachedScaleForStroking[0]===-1){const{lineWidth:t}=this.current,{a:e,b:s,c:i,d:n}=this.ctx.getTransform();let r,o;if(s===0&&i===0){const h=Math.abs(e),c=Math.abs(n);if(h===c)if(t===0)r=o=1/h;else{const u=h*t;r=o=u<1?1/u:1}else if(t===0)r=1/h,o=1/c;else{const u=h*t,d=c*t;r=u<1?1/u:1,o=d<1?1/d:1}}else{const h=Math.abs(e*n-s*i),c=Math.hypot(e,s),u=Math.hypot(i,n);if(t===0)r=u/h,o=c/h;else{const d=t*h;r=u>d?u/d:1,o=c>d?c/d:1}}this._cachedScaleForStroking[0]=r,this._cachedScaleForStroking[1]=o}return this._cachedScaleForStroking}rescaleAndStroke(t){const{ctx:e}=this,{lineWidth:s}=this.current,[i,n]=this.getScaleForStroking();if(e.lineWidth=s||1,i===1&&n===1){e.stroke();return}const r=e.getLineDash();if(t&&e.save(),e.scale(i,n),r.length>0){const o=Math.max(i,n);e.setLineDash(r.map(h=>h/o)),e.lineDashOffset/=o}e.stroke(),t&&e.restore()}isContentVisible(){for(let t=this.markedContentStack.length-1;t>=0;t--)if(!this.markedContentStack[t].visible)return!1;return!0}};Ys=new WeakSet,fp=function(){for(;this.stateStack.length||this.inSMaskMode;)this.restore();this.current.activeSMask=null,this.ctx.restore(),this.transparentCanvas&&(this.ctx=this.compositeCtx,this.ctx.save(),this.ctx.setTransform(1,0,0,1,0,0),this.ctx.drawImage(this.transparentCanvas,0,0),this.ctx.restore(),this.transparentCanvas=null)},gp=function(){if(this.pageColors){const t=this.filterFactory.addHCMFilter(this.pageColors.foreground,this.pageColors.background);if(t!=="none"){const e=this.ctx.filter;this.ctx.filter=t,this.ctx.drawImage(this.ctx.canvas,0,0),this.ctx.filter=e}}},pp=function(t,e,s){const i=new Path2D;return i.addPath(t,new DOMMatrix(s).invertSelf().multiplySelf(e)),i};let ra=Xg;for(const a in Hs)ra.prototype[a]!==void 0&&(ra.prototype[Hs[a]]=ra.prototype[a]);class Vi{static get workerPort(){return l(this,Tl)}static set workerPort(t){if(!(typeof Worker<"u"&&t instanceof Worker)&&t!==null)throw new Error("Invalid `workerPort` type.");m(this,Tl,t)}static get workerSrc(){return l(this,El)}static set workerSrc(t){if(typeof t!="string")throw new Error("Invalid `workerSrc` type.");m(this,El,t)}}Tl=new WeakMap,El=new WeakMap,y(Vi,Tl,null),y(Vi,El,"");class jx{constructor({parsedData:t,rawData:e}){y(this,so);y(this,kl);m(this,so,t),m(this,kl,e)}getRaw(){return l(this,kl)}get(t){return l(this,so).get(t)??null}getAll(){return hg(l(this,so))}has(t){return l(this,so).has(t)}}so=new WeakMap,kl=new WeakMap;const oa=Symbol("INTERNAL");class Bx{constructor(t,{name:e,intent:s,usage:i,rbGroups:n}){y(this,Ml,!1);y(this,Pl,!1);y(this,Dl,!1);y(this,Ta,!0);m(this,Ml,!!(t&ts.DISPLAY)),m(this,Pl,!!(t&ts.PRINT)),this.name=e,this.intent=s,this.usage=i,this.rbGroups=n}get visible(){if(l(this,Dl))return l(this,Ta);if(!l(this,Ta))return!1;const{print:t,view:e}=this.usage;return l(this,Ml)?(e==null?void 0:e.viewState)!=="OFF":l(this,Pl)?(t==null?void 0:t.printState)!=="OFF":!0}_setVisible(t,e,s=!1){t!==oa&&vt("Internal method `_setVisible` called."),m(this,Dl,s),m(this,Ta,e)}}Ml=new WeakMap,Pl=new WeakMap,Dl=new WeakMap,Ta=new WeakMap;class Hx{constructor(t,e=ts.DISPLAY){y(this,Ol);y(this,qn,null);y(this,mt,new Map);y(this,Ea,null);y(this,ka,null);if(this.renderingIntent=e,this.name=null,this.creator=null,t!==null){this.name=t.name,this.creator=t.creator,m(this,ka,t.order);for(const s of t.groups)l(this,mt).set(s.id,new Bx(e,s));if(t.baseState==="OFF")for(const s of l(this,mt).values())s._setVisible(oa,!1);for(const s of t.on)l(this,mt).get(s)._setVisible(oa,!0);for(const s of t.off)l(this,mt).get(s)._setVisible(oa,!1);m(this,Ea,this.getHash())}}isVisible(t){if(l(this,mt).size===0)return!0;if(!t)return Vu("Optional content group not defined."),!0;if(t.type==="OCG")return l(this,mt).has(t.id)?l(this,mt).get(t.id).visible:(tt(`Optional content group not found: ${t.id}`),!0);if(t.type==="OCMD"){if(t.expression)return w(this,Ol,mp).call(this,t.expression);if(!t.policy||t.policy==="AnyOn"){for(const e of t.ids){if(!l(this,mt).has(e))return tt(`Optional content group not found: ${e}`),!0;if(l(this,mt).get(e).visible)return!0}return!1}else if(t.policy==="AllOn"){for(const e of t.ids){if(!l(this,mt).has(e))return tt(`Optional content group not found: ${e}`),!0;if(!l(this,mt).get(e).visible)return!1}return!0}else if(t.policy==="AnyOff"){for(const e of t.ids){if(!l(this,mt).has(e))return tt(`Optional content group not found: ${e}`),!0;if(!l(this,mt).get(e).visible)return!0}return!1}else if(t.policy==="AllOff"){for(const e of t.ids){if(!l(this,mt).has(e))return tt(`Optional content group not found: ${e}`),!0;if(l(this,mt).get(e).visible)return!1}return!0}return tt(`Unknown optional content policy ${t.policy}.`),!0}return tt(`Unknown group type ${t.type}.`),!0}setVisibility(t,e=!0,s=!0){var n;const i=l(this,mt).get(t);if(!i){tt(`Optional content group not found: ${t}`);return}if(s&&e&&i.rbGroups.length)for(const r of i.rbGroups)for(const o of r)o!==t&&((n=l(this,mt).get(o))==null||n._setVisible(oa,!1,!0));i._setVisible(oa,!!e,!0),m(this,qn,null)}setOCGState({state:t,preserveRB:e}){let s;for(const i of t){switch(i){case"ON":case"OFF":case"Toggle":s=i;continue}const n=l(this,mt).get(i);if(n)switch(s){case"ON":this.setVisibility(i,!0,e);break;case"OFF":this.setVisibility(i,!1,e);break;case"Toggle":this.setVisibility(i,!n.visible,e);break}}m(this,qn,null)}get hasInitialVisibility(){return l(this,Ea)===null||this.getHash()===l(this,Ea)}getOrder(){return l(this,mt).size?l(this,ka)?l(this,ka).slice():[...l(this,mt).keys()]:null}getGroups(){return l(this,mt).size>0?hg(l(this,mt)):null}getGroup(t){return l(this,mt).get(t)||null}getHash(){if(l(this,qn)!==null)return l(this,qn);const t=new J0;for(const[e,s]of l(this,mt))t.update(`${e}:${s.visible}`);return m(this,qn,t.hexdigest())}}qn=new WeakMap,mt=new WeakMap,Ea=new WeakMap,ka=new WeakMap,Ol=new WeakSet,mp=function(t){const e=t.length;if(e<2)return!0;const s=t[0];for(let i=1;i<e;i++){const n=t[i];let r;if(Array.isArray(n))r=w(this,Ol,mp).call(this,n);else if(l(this,mt).has(n))r=l(this,mt).get(n).visible;else return tt(`Optional content group not found: ${n}`),!0;switch(s){case"And":if(!r)return!1;break;case"Or":if(r)return!0;break;case"Not":return!r;default:return!0}}return s==="And"};class Gx{constructor(t,{disableRange:e=!1,disableStream:s=!1}){Xt(t,'PDFDataTransportStream - missing required "pdfDataRangeTransport" argument.');const{length:i,initialData:n,progressiveDone:r,contentDispositionFilename:o}=t;if(this._queuedChunks=[],this._progressiveDone=r,this._contentDispositionFilename=o,(n==null?void 0:n.length)>0){const h=n instanceof Uint8Array&&n.byteLength===n.buffer.byteLength?n.buffer:new Uint8Array(n).buffer;this._queuedChunks.push(h)}this._pdfDataRangeTransport=t,this._isStreamingSupported=!s,this._isRangeSupported=!e,this._contentLength=i,this._fullRequestReader=null,this._rangeReaders=[],t.addRangeListener((h,c)=>{this._onReceiveData({begin:h,chunk:c})}),t.addProgressListener((h,c)=>{this._onProgress({loaded:h,total:c})}),t.addProgressiveReadListener(h=>{this._onReceiveData({chunk:h})}),t.addProgressiveDoneListener(()=>{this._onProgressiveDone()}),t.transportReady()}_onReceiveData({begin:t,chunk:e}){const s=e instanceof Uint8Array&&e.byteLength===e.buffer.byteLength?e.buffer:new Uint8Array(e).buffer;if(t===void 0)this._fullRequestReader?this._fullRequestReader._enqueue(s):this._queuedChunks.push(s);else{const i=this._rangeReaders.some(function(n){return n._begin!==t?!1:(n._enqueue(s),!0)});Xt(i,"_onReceiveData - no `PDFDataTransportStreamRangeReader` instance found.")}}get _progressiveDataLength(){var t;return((t=this._fullRequestReader)==null?void 0:t._loaded)??0}_onProgress(t){var e,s,i,n;t.total===void 0?(s=(e=this._rangeReaders[0])==null?void 0:e.onProgress)==null||s.call(e,{loaded:t.loaded}):(n=(i=this._fullRequestReader)==null?void 0:i.onProgress)==null||n.call(i,{loaded:t.loaded,total:t.total})}_onProgressiveDone(){var t;(t=this._fullRequestReader)==null||t.progressiveDone(),this._progressiveDone=!0}_removeRangeReader(t){const e=this._rangeReaders.indexOf(t);e>=0&&this._rangeReaders.splice(e,1)}getFullReader(){Xt(!this._fullRequestReader,"PDFDataTransportStream.getFullReader can only be called once.");const t=this._queuedChunks;return this._queuedChunks=null,new zx(this,t,this._progressiveDone,this._contentDispositionFilename)}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new Vx(this,t,e);return this._pdfDataRangeTransport.requestDataRange(t,e),this._rangeReaders.push(s),s}cancelAllRequests(t){var e;(e=this._fullRequestReader)==null||e.cancel(t);for(const s of this._rangeReaders.slice(0))s.cancel(t);this._pdfDataRangeTransport.abort()}}class zx{constructor(t,e,s=!1,i=null){this._stream=t,this._done=s||!1,this._filename=fg(i)?i:null,this._queuedChunks=e||[],this._loaded=0;for(const n of this._queuedChunks)this._loaded+=n.byteLength;this._requests=[],this._headersReady=Promise.resolve(),t._fullRequestReader=this,this.onProgress=null}_enqueue(t){this._done||(this._requests.length>0?this._requests.shift().resolve({value:t,done:!1}):this._queuedChunks.push(t),this._loaded+=t.byteLength)}get headersReady(){return this._headersReady}get filename(){return this._filename}get isRangeSupported(){return this._stream._isRangeSupported}get isStreamingSupported(){return this._stream._isStreamingSupported}get contentLength(){return this._stream._contentLength}async read(){if(this._queuedChunks.length>0)return{value:this._queuedChunks.shift(),done:!1};if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0;for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0}progressiveDone(){this._done||(this._done=!0)}}class Vx{constructor(t,e,s){this._stream=t,this._begin=e,this._end=s,this._queuedChunk=null,this._requests=[],this._done=!1,this.onProgress=null}_enqueue(t){if(!this._done){if(this._requests.length===0)this._queuedChunk=t;else{this._requests.shift().resolve({value:t,done:!1});for(const s of this._requests)s.resolve({value:void 0,done:!0});this._requests.length=0}this._done=!0,this._stream._removeRangeReader(this)}}get isStreamingSupported(){return!1}async read(){if(this._queuedChunk){const e=this._queuedChunk;return this._queuedChunk=null,{value:e,done:!1}}if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0;for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0,this._stream._removeRangeReader(this)}}function Xx(a){let t=!0,e=s("filename\\*","i").exec(a);if(e){e=e[1];let u=o(e);return u=unescape(u),u=h(u),u=c(u),n(u)}if(e=r(a),e){const u=c(e);return n(u)}if(e=s("filename","i").exec(a),e){e=e[1];let u=o(e);return u=c(u),n(u)}function s(u,d){return new RegExp("(?:^|;)\\s*"+u+'\\s*=\\s*([^";\\s][^;\\s]*|"(?:[^"\\\\]|\\\\"?)+"?)',d)}function i(u,d){if(u){if(!/^[\x00-\xFF]+$/.test(d))return d;try{const f=new TextDecoder(u,{fatal:!0}),g=Wu(d);d=f.decode(g),t=!1}catch{}}return d}function n(u){return t&&/[\x80-\xff]/.test(u)&&(u=i("utf-8",u),t&&(u=i("iso-8859-1",u))),u}function r(u){const d=[];let f;const g=s("filename\\*((?!0\\d)\\d+)(\\*?)","ig");for(;(f=g.exec(u))!==null;){let[,b,v,_]=f;if(b=parseInt(b,10),b in d){if(b===0)break;continue}d[b]=[v,_]}const p=[];for(let b=0;b<d.length&&b in d;++b){let[v,_]=d[b];_=o(_),v&&(_=unescape(_),b===0&&(_=h(_))),p.push(_)}return p.join("")}function o(u){if(u.startsWith('"')){const d=u.slice(1).split('\\"');for(let f=0;f<d.length;++f){const g=d[f].indexOf('"');g!==-1&&(d[f]=d[f].slice(0,g),d.length=f+1),d[f]=d[f].replaceAll(/\\(.)/g,"$1")}u=d.join('"')}return u}function h(u){const d=u.indexOf("'");if(d===-1)return u;const f=u.slice(0,d),p=u.slice(d+1).replace(/^[^']*'/,"");return i(f,p)}function c(u){return!u.startsWith("=?")||/[\x00-\x19\x80-\xff]/.test(u)?u:u.replaceAll(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g,function(d,f,g,p){if(g==="q"||g==="Q")return p=p.replaceAll("_"," "),p=p.replaceAll(/=([0-9a-fA-F]{2})/g,function(b,v){return String.fromCharCode(parseInt(v,16))}),i(f,p);try{p=atob(p)}catch{}return i(f,p)})}return""}function yb(a,t){const e=new Headers;if(!a||!t||typeof t!="object")return e;for(const s in t){const i=t[s];i!==void 0&&e.append(s,i)}return e}function td(a){try{return new URL(a).origin}catch{}return null}function vb({responseHeaders:a,isHttp:t,rangeChunkSize:e,disableRange:s}){const i={allowRangeRequests:!1,suggestedLength:void 0},n=parseInt(a.get("Content-Length"),10);return!Number.isInteger(n)||(i.suggestedLength=n,n<=2*e)||s||!t||a.get("Accept-Ranges")!=="bytes"||(a.get("Content-Encoding")||"identity")!=="identity"||(i.allowRangeRequests=!0),i}function _b(a){const t=a.get("Content-Disposition");if(t){let e=Xx(t);if(e.includes("%"))try{e=decodeURIComponent(e)}catch{}if(fg(e))return e}return null}function ed(a,t){return a===404||a===0&&t.startsWith("file:")?new Gh('Missing PDF "'+t+'".'):new Xu(`Unexpected server response (${a}) while retrieving PDF "${t}".`,a)}function wb(a){return a===200||a===206}function xb(a,t,e){return{method:"GET",headers:a,signal:e.signal,mode:"cors",credentials:t?"include":"same-origin",redirect:"follow"}}function Sb(a){return a instanceof Uint8Array?a.buffer:a instanceof ArrayBuffer?a:(tt(`getArrayBuffer - unexpected data format: ${a}`),new Uint8Array(a).buffer)}class Cb{constructor(t){$(this,"_responseOrigin",null);this.source=t,this.isHttp=/^https?:/i.test(t.url),this.headers=yb(this.isHttp,t.httpHeaders),this._fullRequestReader=null,this._rangeRequestReaders=[]}get _progressiveDataLength(){var t;return((t=this._fullRequestReader)==null?void 0:t._loaded)??0}getFullReader(){return Xt(!this._fullRequestReader,"PDFFetchStream.getFullReader can only be called once."),this._fullRequestReader=new Wx(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new Ux(this,t,e);return this._rangeRequestReaders.push(s),s}cancelAllRequests(t){var e;(e=this._fullRequestReader)==null||e.cancel(t);for(const s of this._rangeRequestReaders.slice(0))s.cancel(t)}}class Wx{constructor(t){this._stream=t,this._reader=null,this._loaded=0,this._filename=null;const e=t.source;this._withCredentials=e.withCredentials||!1,this._contentLength=e.length,this._headersCapability=Promise.withResolvers(),this._disableRange=e.disableRange||!1,this._rangeChunkSize=e.rangeChunkSize,!this._rangeChunkSize&&!this._disableRange&&(this._disableRange=!0),this._abortController=new AbortController,this._isStreamingSupported=!e.disableStream,this._isRangeSupported=!e.disableRange;const s=new Headers(t.headers),i=e.url;fetch(i,xb(s,this._withCredentials,this._abortController)).then(n=>{if(t._responseOrigin=td(n.url),!wb(n.status))throw ed(n.status,i);this._reader=n.body.getReader(),this._headersCapability.resolve();const r=n.headers,{allowRangeRequests:o,suggestedLength:h}=vb({responseHeaders:r,isHttp:t.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});this._isRangeSupported=o,this._contentLength=h||this._contentLength,this._filename=_b(r),!this._isStreamingSupported&&this._isRangeSupported&&this.cancel(new Rn("Streaming is disabled."))}).catch(this._headersCapability.reject),this.onProgress=null}get headersReady(){return this._headersCapability.promise}get filename(){return this._filename}get contentLength(){return this._contentLength}get isRangeSupported(){return this._isRangeSupported}get isStreamingSupported(){return this._isStreamingSupported}async read(){var s;await this._headersCapability.promise;const{value:t,done:e}=await this._reader.read();return e?{value:t,done:e}:(this._loaded+=t.byteLength,(s=this.onProgress)==null||s.call(this,{loaded:this._loaded,total:this._contentLength}),{value:Sb(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}class Ux{constructor(t,e,s){this._stream=t,this._reader=null,this._loaded=0;const i=t.source;this._withCredentials=i.withCredentials||!1,this._readCapability=Promise.withResolvers(),this._isStreamingSupported=!i.disableStream,this._abortController=new AbortController;const n=new Headers(t.headers);n.append("Range",`bytes=${e}-${s-1}`);const r=i.url;fetch(r,xb(n,this._withCredentials,this._abortController)).then(o=>{const h=td(o.url);if(h!==t._responseOrigin)throw new Error(`Expected range response-origin "${h}" to match "${t._responseOrigin}".`);if(!wb(o.status))throw ed(o.status,r);this._readCapability.resolve(),this._reader=o.body.getReader()}).catch(this._readCapability.reject),this.onProgress=null}get isStreamingSupported(){return this._isStreamingSupported}async read(){var s;await this._readCapability.promise;const{value:t,done:e}=await this._reader.read();return e?{value:t,done:e}:(this._loaded+=t.byteLength,(s=this.onProgress)==null||s.call(this,{loaded:this._loaded}),{value:Sb(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}const Tg=200,Eg=206;function Yx(a){const t=a.response;return typeof t!="string"?t:Wu(t).buffer}class $x{constructor({url:t,httpHeaders:e,withCredentials:s}){$(this,"_responseOrigin",null);this.url=t,this.isHttp=/^https?:/i.test(t),this.headers=yb(this.isHttp,e),this.withCredentials=s||!1,this.currXhrId=0,this.pendingRequests=Object.create(null)}request(t){const e=new XMLHttpRequest,s=this.currXhrId++,i=this.pendingRequests[s]={xhr:e};e.open("GET",this.url),e.withCredentials=this.withCredentials;for(const[n,r]of this.headers)e.setRequestHeader(n,r);return this.isHttp&&"begin"in t&&"end"in t?(e.setRequestHeader("Range",`bytes=${t.begin}-${t.end-1}`),i.expectedStatus=Eg):i.expectedStatus=Tg,e.responseType="arraybuffer",Xt(t.onError,"Expected `onError` callback to be provided."),e.onerror=()=>{t.onError(e.status)},e.onreadystatechange=this.onStateChange.bind(this,s),e.onprogress=this.onProgress.bind(this,s),i.onHeadersReceived=t.onHeadersReceived,i.onDone=t.onDone,i.onError=t.onError,i.onProgress=t.onProgress,e.send(null),s}onProgress(t,e){var i;const s=this.pendingRequests[t];s&&((i=s.onProgress)==null||i.call(s,e))}onStateChange(t,e){const s=this.pendingRequests[t];if(!s)return;const i=s.xhr;if(i.readyState>=2&&s.onHeadersReceived&&(s.onHeadersReceived(),delete s.onHeadersReceived),i.readyState!==4||!(t in this.pendingRequests))return;if(delete this.pendingRequests[t],i.status===0&&this.isHttp){s.onError(i.status);return}const n=i.status||Tg;if(!(n===Tg&&s.expectedStatus===Eg)&&n!==s.expectedStatus){s.onError(i.status);return}const o=Yx(i);if(n===Eg){const h=i.getResponseHeader("Content-Range"),c=/bytes (\d+)-(\d+)\/(\d+)/.exec(h);c?s.onDone({begin:parseInt(c[1],10),chunk:o}):(tt('Missing or invalid "Content-Range" header.'),s.onError(0))}else o?s.onDone({begin:0,chunk:o}):s.onError(i.status)}getRequestXhr(t){return this.pendingRequests[t].xhr}isPendingRequest(t){return t in this.pendingRequests}abortRequest(t){const e=this.pendingRequests[t].xhr;delete this.pendingRequests[t],e.abort()}}class qx{constructor(t){this._source=t,this._manager=new $x(t),this._rangeChunkSize=t.rangeChunkSize,this._fullRequestReader=null,this._rangeRequestReaders=[]}_onRangeRequestReaderClosed(t){const e=this._rangeRequestReaders.indexOf(t);e>=0&&this._rangeRequestReaders.splice(e,1)}getFullReader(){return Xt(!this._fullRequestReader,"PDFNetworkStream.getFullReader can only be called once."),this._fullRequestReader=new Kx(this._manager,this._source),this._fullRequestReader}getRangeReader(t,e){const s=new Qx(this._manager,t,e);return s.onClosed=this._onRangeRequestReaderClosed.bind(this),this._rangeRequestReaders.push(s),s}cancelAllRequests(t){var e;(e=this._fullRequestReader)==null||e.cancel(t);for(const s of this._rangeRequestReaders.slice(0))s.cancel(t)}}class Kx{constructor(t,e){this._manager=t,this._url=e.url,this._fullRequestId=t.request({onHeadersReceived:this._onHeadersReceived.bind(this),onDone:this._onDone.bind(this),onError:this._onError.bind(this),onProgress:this._onProgress.bind(this)}),this._headersCapability=Promise.withResolvers(),this._disableRange=e.disableRange||!1,this._contentLength=e.length,this._rangeChunkSize=e.rangeChunkSize,!this._rangeChunkSize&&!this._disableRange&&(this._disableRange=!0),this._isStreamingSupported=!1,this._isRangeSupported=!1,this._cachedChunks=[],this._requests=[],this._done=!1,this._storedError=void 0,this._filename=null,this.onProgress=null}_onHeadersReceived(){const t=this._fullRequestId,e=this._manager.getRequestXhr(t);this._manager._responseOrigin=td(e.responseURL);const s=e.getAllResponseHeaders(),i=new Headers(s?s.trimStart().replace(/[^\S ]+$/,"").split(/[\r\n]+/).map(o=>{const[h,...c]=o.split(": ");return[h,c.join(": ")]}):[]),{allowRangeRequests:n,suggestedLength:r}=vb({responseHeaders:i,isHttp:this._manager.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});n&&(this._isRangeSupported=!0),this._contentLength=r||this._contentLength,this._filename=_b(i),this._isRangeSupported&&this._manager.abortRequest(t),this._headersCapability.resolve()}_onDone(t){if(t&&(this._requests.length>0?this._requests.shift().resolve({value:t.chunk,done:!1}):this._cachedChunks.push(t.chunk)),this._done=!0,!(this._cachedChunks.length>0)){for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0}}_onError(t){this._storedError=ed(t,this._url),this._headersCapability.reject(this._storedError);for(const e of this._requests)e.reject(this._storedError);this._requests.length=0,this._cachedChunks.length=0}_onProgress(t){var e;(e=this.onProgress)==null||e.call(this,{loaded:t.loaded,total:t.lengthComputable?t.total:this._contentLength})}get filename(){return this._filename}get isRangeSupported(){return this._isRangeSupported}get isStreamingSupported(){return this._isStreamingSupported}get contentLength(){return this._contentLength}get headersReady(){return this._headersCapability.promise}async read(){if(await this._headersCapability.promise,this._storedError)throw this._storedError;if(this._cachedChunks.length>0)return{value:this._cachedChunks.shift(),done:!1};if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0,this._headersCapability.reject(t);for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0,this._manager.isPendingRequest(this._fullRequestId)&&this._manager.abortRequest(this._fullRequestId),this._fullRequestReader=null}}class Qx{constructor(t,e,s){this._manager=t,this._url=t.url,this._requestId=t.request({begin:e,end:s,onHeadersReceived:this._onHeadersReceived.bind(this),onDone:this._onDone.bind(this),onError:this._onError.bind(this),onProgress:this._onProgress.bind(this)}),this._requests=[],this._queuedChunk=null,this._done=!1,this._storedError=void 0,this.onProgress=null,this.onClosed=null}_onHeadersReceived(){var e;const t=td((e=this._manager.getRequestXhr(this._requestId))==null?void 0:e.responseURL);t!==this._manager._responseOrigin&&(this._storedError=new Error(`Expected range response-origin "${t}" to match "${this._manager._responseOrigin}".`),this._onError(0))}_close(){var t;(t=this.onClosed)==null||t.call(this,this)}_onDone(t){const e=t.chunk;this._requests.length>0?this._requests.shift().resolve({value:e,done:!1}):this._queuedChunk=e,this._done=!0;for(const s of this._requests)s.resolve({value:void 0,done:!0});this._requests.length=0,this._close()}_onError(t){this._storedError??(this._storedError=ed(t,this._url));for(const e of this._requests)e.reject(this._storedError);this._requests.length=0,this._queuedChunk=null}_onProgress(t){var e;this.isStreamingSupported||(e=this.onProgress)==null||e.call(this,{loaded:t.loaded})}get isStreamingSupported(){return!1}async read(){if(this._storedError)throw this._storedError;if(this._queuedChunk!==null){const e=this._queuedChunk;return this._queuedChunk=null,{value:e,done:!1}}if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0;for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0,this._manager.isPendingRequest(this._requestId)&&this._manager.abortRequest(this._requestId),this._close()}}const Jx=/^[a-z][a-z0-9\-+.]+:/i;function Zx(a){if(Jx.test(a))return new URL(a);const t=process.getBuiltinModule("url");return new URL(t.pathToFileURL(a))}class tS{constructor(t){this.source=t,this.url=Zx(t.url),Xt(this.url.protocol==="file:","PDFNodeStream only supports file:// URLs."),this._fullRequestReader=null,this._rangeRequestReaders=[]}get _progressiveDataLength(){var t;return((t=this._fullRequestReader)==null?void 0:t._loaded)??0}getFullReader(){return Xt(!this._fullRequestReader,"PDFNodeStream.getFullReader can only be called once."),this._fullRequestReader=new eS(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new sS(this,t,e);return this._rangeRequestReaders.push(s),s}cancelAllRequests(t){var e;(e=this._fullRequestReader)==null||e.cancel(t);for(const s of this._rangeRequestReaders.slice(0))s.cancel(t)}}class eS{constructor(t){this._url=t.url,this._done=!1,this._storedError=null,this.onProgress=null;const e=t.source;this._contentLength=e.length,this._loaded=0,this._filename=null,this._disableRange=e.disableRange||!1,this._rangeChunkSize=e.rangeChunkSize,!this._rangeChunkSize&&!this._disableRange&&(this._disableRange=!0),this._isStreamingSupported=!e.disableStream,this._isRangeSupported=!e.disableRange,this._readableStream=null,this._readCapability=Promise.withResolvers(),this._headersCapability=Promise.withResolvers();const s=process.getBuiltinModule("fs");s.promises.lstat(this._url).then(i=>{this._contentLength=i.size,this._setReadableStream(s.createReadStream(this._url)),this._headersCapability.resolve()},i=>{i.code==="ENOENT"&&(i=new Gh(`Missing PDF "${this._url}".`)),this._storedError=i,this._headersCapability.reject(i)})}get headersReady(){return this._headersCapability.promise}get filename(){return this._filename}get contentLength(){return this._contentLength}get isRangeSupported(){return this._isRangeSupported}get isStreamingSupported(){return this._isStreamingSupported}async read(){var s;if(await this._readCapability.promise,this._done)return{value:void 0,done:!0};if(this._storedError)throw this._storedError;const t=this._readableStream.read();return t===null?(this._readCapability=Promise.withResolvers(),this.read()):(this._loaded+=t.length,(s=this.onProgress)==null||s.call(this,{loaded:this._loaded,total:this._contentLength}),{value:new Uint8Array(t).buffer,done:!1})}cancel(t){if(!this._readableStream){this._error(t);return}this._readableStream.destroy(t)}_error(t){this._storedError=t,this._readCapability.resolve()}_setReadableStream(t){this._readableStream=t,t.on("readable",()=>{this._readCapability.resolve()}),t.on("end",()=>{t.destroy(),this._done=!0,this._readCapability.resolve()}),t.on("error",e=>{this._error(e)}),!this._isStreamingSupported&&this._isRangeSupported&&this._error(new Rn("streaming is disabled")),this._storedError&&this._readableStream.destroy(this._storedError)}}class sS{constructor(t,e,s){this._url=t.url,this._done=!1,this._storedError=null,this.onProgress=null,this._loaded=0,this._readableStream=null,this._readCapability=Promise.withResolvers();const i=t.source;this._isStreamingSupported=!i.disableStream;const n=process.getBuiltinModule("fs");this._setReadableStream(n.createReadStream(this._url,{start:e,end:s-1}))}get isStreamingSupported(){return this._isStreamingSupported}async read(){var s;if(await this._readCapability.promise,this._done)return{value:void 0,done:!0};if(this._storedError)throw this._storedError;const t=this._readableStream.read();return t===null?(this._readCapability=Promise.withResolvers(),this.read()):(this._loaded+=t.length,(s=this.onProgress)==null||s.call(this,{loaded:this._loaded}),{value:new Uint8Array(t).buffer,done:!1})}cancel(t){if(!this._readableStream){this._error(t);return}this._readableStream.destroy(t)}_error(t){this._storedError=t,this._readCapability.resolve()}_setReadableStream(t){this._readableStream=t,t.on("readable",()=>{this._readCapability.resolve()}),t.on("end",()=>{t.destroy(),this._done=!0,this._readCapability.resolve()}),t.on("error",e=>{this._error(e)}),this._storedError&&this._readableStream.destroy(this._storedError)}}const iS=1e5,Ye=30,nS=.8,Qt=class Qt{constructor({textContentSource:t,container:e,viewport:s}){y(this,nn);y(this,Kn,Promise.withResolvers());y(this,qe,null);y(this,Rl,!1);y(this,Ll,!!((Ub=globalThis.FontInspector)!=null&&Ub.enabled));y(this,io,null);y(this,sn,null);y(this,Fl,0);y(this,Il,0);y(this,no,null);y(this,Ma,null);y(this,Pa,0);y(this,Qn,0);y(this,Da,Object.create(null));y(this,Nl,[]);y(this,Oa,null);y(this,ro,[]);y(this,jl,new WeakMap);y(this,Bl,null);var h;if(t instanceof ReadableStream)m(this,Oa,t);else if(typeof t=="object")m(this,Oa,new ReadableStream({start(c){c.enqueue(t),c.close()}}));else throw new Error('No "textContentSource" parameter specified.');m(this,qe,m(this,Ma,e)),m(this,Qn,s.scale*(globalThis.devicePixelRatio||1)),m(this,Pa,s.rotation),m(this,sn,{div:null,properties:null,ctx:null});const{pageWidth:i,pageHeight:n,pageX:r,pageY:o}=s.rawDims;m(this,Bl,[1,0,0,-1,-r,o+n]),m(this,Il,i),m(this,Fl,n),w(h=Qt,rs,Py).call(h),kr(e,s),l(this,Kn).promise.finally(()=>{l(Qt,Ra).delete(this),m(this,sn,null),m(this,Da,null)}).catch(()=>{})}static get fontFamilyMap(){const{isWindows:t,isFirefox:e}=Re.platform;return st(this,"fontFamilyMap",new Map([["sans-serif",`${t&&e?"Calibri, ":""}sans-serif`],["monospace",`${t&&e?"Lucida Console, ":""}monospace`]]))}render(){const t=()=>{l(this,no).read().then(({value:e,done:s})=>{if(s){l(this,Kn).resolve();return}l(this,io)??m(this,io,e.lang),Object.assign(l(this,Da),e.styles),w(this,nn,ky).call(this,e.items),t()},l(this,Kn).reject)};return m(this,no,l(this,Oa).getReader()),l(Qt,Ra).add(this),t(),l(this,Kn).promise}update({viewport:t,onBefore:e=null}){var n;const s=t.scale*(globalThis.devicePixelRatio||1),i=t.rotation;if(i!==l(this,Pa)&&(e==null||e(),m(this,Pa,i),kr(l(this,Ma),{rotation:i})),s!==l(this,Qn)){e==null||e(),m(this,Qn,s);const r={div:null,properties:null,ctx:w(n=Qt,rs,Nd).call(n,l(this,io))};for(const o of l(this,ro))r.properties=l(this,jl).get(o),r.div=o,w(this,nn,bp).call(this,r)}}cancel(){var e;const t=new Rn("TextLayer task cancelled.");(e=l(this,no))==null||e.cancel(t).catch(()=>{}),m(this,no,null),l(this,Kn).reject(t)}get textDivs(){return l(this,ro)}get textContentItemsStr(){return l(this,Nl)}static cleanup(){if(!(l(this,Ra).size>0)){l(this,oo).clear();for(const{canvas:t}of l(this,ao).values())t.remove();l(this,ao).clear()}}};Kn=new WeakMap,qe=new WeakMap,Rl=new WeakMap,Ll=new WeakMap,io=new WeakMap,sn=new WeakMap,Fl=new WeakMap,Il=new WeakMap,no=new WeakMap,Ma=new WeakMap,Pa=new WeakMap,Qn=new WeakMap,Da=new WeakMap,Nl=new WeakMap,Oa=new WeakMap,ro=new WeakMap,jl=new WeakMap,Bl=new WeakMap,oo=new WeakMap,ao=new WeakMap,Hl=new WeakMap,Jn=new WeakMap,Ra=new WeakMap,nn=new WeakSet,ky=function(t){var i,n;if(l(this,Rl))return;(n=l(this,sn)).ctx??(n.ctx=w(i=Qt,rs,Nd).call(i,l(this,io)));const e=l(this,ro),s=l(this,Nl);for(const r of t){if(e.length>iS){tt("Ignoring additional textDivs for performance reasons."),m(this,Rl,!0);return}if(r.str===void 0){if(r.type==="beginMarkedContentProps"||r.type==="beginMarkedContent"){const o=l(this,qe);m(this,qe,document.createElement("span")),l(this,qe).classList.add("markedContent"),r.id!==null&&l(this,qe).setAttribute("id",`${r.id}`),o.append(l(this,qe))}else r.type==="endMarkedContent"&&m(this,qe,l(this,qe).parentNode);continue}s.push(r.str),w(this,nn,My).call(this,r)}},My=function(t){var b;const e=document.createElement("span"),s={angle:0,canvasWidth:0,hasText:t.str!=="",hasEOL:t.hasEOL,fontSize:0};l(this,ro).push(e);const i=X.transform(l(this,Bl),t.transform);let n=Math.atan2(i[1],i[0]);const r=l(this,Da)[t.fontName];r.vertical&&(n+=Math.PI/2);let o=l(this,Ll)&&r.fontSubstitution||r.fontFamily;o=Qt.fontFamilyMap.get(o)||o;const h=Math.hypot(i[2],i[3]),c=h*w(b=Qt,rs,Dy).call(b,o,l(this,io));let u,d;n===0?(u=i[4],d=i[5]-c):(u=i[4]+c*Math.sin(n),d=i[5]-c*Math.cos(n));const f="calc(var(--scale-factor)*",g=e.style;l(this,qe)===l(this,Ma)?(g.left=`${(100*u/l(this,Il)).toFixed(2)}%`,g.top=`${(100*d/l(this,Fl)).toFixed(2)}%`):(g.left=`${f}${u.toFixed(2)}px)`,g.top=`${f}${d.toFixed(2)}px)`),g.fontSize=`${f}${(l(Qt,Jn)*h).toFixed(2)}px)`,g.fontFamily=o,s.fontSize=h,e.setAttribute("role","presentation"),e.textContent=t.str,e.dir=t.dir,l(this,Ll)&&(e.dataset.fontName=r.fontSubstitutionLoadedName||t.fontName),n!==0&&(s.angle=n*(180/Math.PI));let p=!1;if(t.str.length>1)p=!0;else if(t.str!==" "&&t.transform[0]!==t.transform[3]){const v=Math.abs(t.transform[0]),_=Math.abs(t.transform[3]);v!==_&&Math.max(v,_)/Math.min(v,_)>1.5&&(p=!0)}if(p&&(s.canvasWidth=r.vertical?t.height:t.width),l(this,jl).set(e,s),l(this,sn).div=e,l(this,sn).properties=s,w(this,nn,bp).call(this,l(this,sn)),s.hasText&&l(this,qe).append(e),s.hasEOL){const v=document.createElement("br");v.setAttribute("role","presentation"),l(this,qe).append(v)}},bp=function(t){var o;const{div:e,properties:s,ctx:i}=t,{style:n}=e;let r="";if(l(Qt,Jn)>1&&(r=`scale(${1/l(Qt,Jn)})`),s.canvasWidth!==0&&s.hasText){const{fontFamily:h}=n,{canvasWidth:c,fontSize:u}=s;w(o=Qt,rs,yp).call(o,i,u*l(this,Qn),h);const{width:d}=i.measureText(e.textContent);d>0&&(r=`scaleX(${c*l(this,Qn)/d}) ${r}`)}s.angle!==0&&(r=`rotate(${s.angle}deg) ${r}`),r.length>0&&(n.transform=r)},rs=new WeakSet,Nd=function(t=null){let e=l(this,ao).get(t||(t=""));if(!e){const s=document.createElement("canvas");s.className="hiddenCanvasElement",s.lang=t,document.body.append(s),e=s.getContext("2d",{alpha:!1,willReadFrequently:!0}),l(this,ao).set(t,e),l(this,Hl).set(e,{size:0,family:""})}return e},yp=function(t,e,s){const i=l(this,Hl).get(t);e===i.size&&s===i.family||(t.font=`${e}px ${s}`,i.size=e,i.family=s)},Py=function(){if(l(this,Jn)!==null)return;const t=document.createElement("div");t.style.opacity=0,t.style.lineHeight=1,t.style.fontSize="1px",t.style.position="absolute",t.textContent="X",document.body.append(t),m(this,Jn,t.getBoundingClientRect().height),t.remove()},Dy=function(t,e){const s=l(this,oo).get(t);if(s)return s;const i=w(this,rs,Nd).call(this,e);i.canvas.width=i.canvas.height=Ye,w(this,rs,yp).call(this,i,Ye,t);const n=i.measureText("");let r=n.fontBoundingBoxAscent,o=Math.abs(n.fontBoundingBoxDescent);if(r){const u=r/(r+o);return l(this,oo).set(t,u),i.canvas.width=i.canvas.height=0,u}i.strokeStyle="red",i.clearRect(0,0,Ye,Ye),i.strokeText("g",0,0);let h=i.getImageData(0,0,Ye,Ye).data;o=0;for(let u=h.length-1-3;u>=0;u-=4)if(h[u]>0){o=Math.ceil(u/4/Ye);break}i.clearRect(0,0,Ye,Ye),i.strokeText("A",0,Ye),h=i.getImageData(0,0,Ye,Ye).data,r=0;for(let u=0,d=h.length;u<d;u+=4)if(h[u]>0){r=Ye-Math.floor(u/4/Ye);break}i.canvas.width=i.canvas.height=0;const c=r?r/(r+o):nS;return l(this,oo).set(t,c),c},y(Qt,rs),y(Qt,oo,new Map),y(Qt,ao,new Map),y(Qt,Hl,new WeakMap),y(Qt,Jn,null),y(Qt,Ra,new Set);let Yh=Qt;class $h{static textContent(t){const e=[],s={items:e,styles:Object.create(null)};function i(n){var h;if(!n)return;let r=null;const o=n.name;if(o==="#text")r=n.value;else if($h.shouldBuildText(o))(h=n==null?void 0:n.attributes)!=null&&h.textContent?r=n.attributes.textContent:n.value&&(r=n.value);else return;if(r!==null&&e.push({str:r}),!!n.children)for(const c of n.children)i(c)}return i(t),s}static shouldBuildText(t){return!(t==="textarea"||t==="input"||t==="option"||t==="select")}}const rS=65536,oS=100,aS=5e3,hS=ye?xx:vx,lS=ye?Sx:ib,cS=ye?wx:_x,uS=ye?Cx:ob;function dS(a={}){typeof a=="string"||a instanceof URL?a={url:a}:(a instanceof ArrayBuffer||ArrayBuffer.isView(a))&&(a={data:a});const t=new kg,{docId:e}=t,s=a.url?fS(a.url):null,i=a.data?gS(a.data):null,n=a.httpHeaders||null,r=a.withCredentials===!0,o=a.password??null,h=a.range instanceof Tb?a.range:null,c=Number.isInteger(a.rangeChunkSize)&&a.rangeChunkSize>0?a.rangeChunkSize:rS;let u=a.worker instanceof aa?a.worker:null;const d=a.verbosity,f=typeof a.docBaseUrl=="string"&&!Yu(a.docBaseUrl)?a.docBaseUrl:null,g=typeof a.cMapUrl=="string"?a.cMapUrl:null,p=a.cMapPacked!==!1,b=a.CMapReaderFactory||lS,v=typeof a.standardFontDataUrl=="string"?a.standardFontDataUrl:null,_=a.StandardFontDataFactory||uS,x=a.stopAtErrors!==!0,C=Number.isInteger(a.maxImageSize)&&a.maxImageSize>-1?a.maxImageSize:-1,S=a.isEvalSupported!==!1,k=typeof a.isOffscreenCanvasSupported=="boolean"?a.isOffscreenCanvasSupported:!ye,D=typeof a.isImageDecoderSupported=="boolean"?a.isImageDecoderSupported:!ye&&(Re.platform.isFirefox||!globalThis.chrome),T=Number.isInteger(a.canvasMaxAreaInBytes)?a.canvasMaxAreaInBytes:-1,M=typeof a.disableFontFace=="boolean"?a.disableFontFace:ye,O=a.fontExtraProperties===!0,R=a.enableXfa===!0,L=a.ownerDocument||globalThis.document,W=a.disableRange===!0,U=a.disableStream===!0,G=a.disableAutoFetch===!0,at=a.pdfBug===!0,F=a.CanvasFactory||hS,z=a.FilterFactory||cS,rt=a.enableHWA===!0,Gt=h?h.length:a.length??NaN,te=typeof a.useSystemFonts=="boolean"?a.useSystemFonts:!ye&&!M,fe=typeof a.useWorkerFetch=="boolean"?a.useWorkerFetch:b===ib&&_===ob&&g&&v&&Vh(g,document.baseURI)&&Vh(v,document.baseURI),Yt=null;Qw(d);const St={canvasFactory:new F({ownerDocument:L,enableHWA:rt}),filterFactory:new z({docId:e,ownerDocument:L}),cMapReaderFactory:fe?null:new b({baseUrl:g,isCompressed:p}),standardFontDataFactory:fe?null:new _({baseUrl:v})};if(!u){const Ft={verbosity:d,port:Vi.workerPort};u=Ft.port?aa.fromPort(Ft):new aa(Ft),t._worker=u}const He={docId:e,apiVersion:"4.10.38",data:i,password:o,disableAutoFetch:G,rangeChunkSize:c,length:Gt,docBaseUrl:f,enableXfa:R,evaluatorOptions:{maxImageSize:C,disableFontFace:M,ignoreErrors:x,isEvalSupported:S,isOffscreenCanvasSupported:k,isImageDecoderSupported:D,canvasMaxAreaInBytes:T,fontExtraProperties:O,useSystemFonts:te,cMapUrl:fe?g:null,standardFontDataUrl:fe?v:null}},Mi={disableFontFace:M,fontExtraProperties:O,ownerDocument:L,pdfBug:at,styleElement:Yt,loadingParams:{disableAutoFetch:G,enableXfa:R}};return u.promise.then(function(){if(t.destroyed)throw new Error("Loading aborted");if(u.destroyed)throw new Error("Worker was destroyed");const Ft=u.messageHandler.sendWithPromise("GetDocRequest",He,i?[i.buffer]:null);let ft;if(h)ft=new Gx(h,{disableRange:W,disableStream:U});else if(!i){if(!s)throw new Error("getDocument - no `url` parameter provided.");let fr;if(ye)if(Vh(s)){if(typeof fetch>"u"||typeof Response>"u"||!("body"in Response.prototype))throw new Error("getDocument - the Fetch API was disabled in Node.js, see `--no-experimental-fetch`.");fr=Cb}else fr=tS;else fr=Vh(s)?Cb:qx;ft=new fr({url:s,length:Gt,httpHeaders:n,withCredentials:r,rangeChunkSize:c,disableRange:W,disableStream:U})}return Ft.then(fr=>{if(t.destroyed)throw new Error("Loading aborted");if(u.destroyed)throw new Error("Worker was destroyed");const ph=new Wh(e,fr,u.port),Pi=new yS(ph,t,ft,Mi,St);t._transport=Pi,ph.send("Ready",null)})}).catch(t._capability.reject),t}function fS(a){if(a instanceof URL)return a.href;try{return new URL(a,window.location).href}catch{if(ye&&typeof a=="string")return a}throw new Error("Invalid PDF url data: either string or URL-object is expected in the url property.")}function gS(a){if(ye&&typeof Buffer<"u"&&a instanceof Buffer)throw new Error("Please provide binary data as `Uint8Array`, rather than `Buffer`.");if(a instanceof Uint8Array&&a.byteLength===a.buffer.byteLength)return a;if(typeof a=="string")return Wu(a);if(a instanceof ArrayBuffer||ArrayBuffer.isView(a)||typeof a=="object"&&!isNaN(a==null?void 0:a.length))return new Uint8Array(a);throw new Error("Invalid PDF binary data: either TypedArray, string, or array-like object is expected in the data property.")}function Ab(a){return typeof a=="object"&&Number.isInteger(a==null?void 0:a.num)&&a.num>=0&&Number.isInteger(a==null?void 0:a.gen)&&a.gen>=0}const md=class md{constructor(){this._capability=Promise.withResolvers(),this._transport=null,this._worker=null,this.docId=`d${Ge(md,pd)._++}`,this.destroyed=!1,this.onPassword=null,this.onProgress=null}get promise(){return this._capability.promise}async destroy(){var t,e,s,i;this.destroyed=!0;try{(t=this._worker)!=null&&t.port&&(this._worker._pendingDestroy=!0),await((e=this._transport)==null?void 0:e.destroy())}catch(n){throw(s=this._worker)!=null&&s.port&&delete this._worker._pendingDestroy,n}this._transport=null,(i=this._worker)==null||i.destroy(),this._worker=null}};pd=new WeakMap,y(md,pd,0);let kg=md;class Tb{constructor(t,e,s=!1,i=null){this.length=t,this.initialData=e,this.progressiveDone=s,this.contentDispositionFilename=i,this._rangeListeners=[],this._progressListeners=[],this._progressiveReadListeners=[],this._progressiveDoneListeners=[],this._readyCapability=Promise.withResolvers()}addRangeListener(t){this._rangeListeners.push(t)}addProgressListener(t){this._progressListeners.push(t)}addProgressiveReadListener(t){this._progressiveReadListeners.push(t)}addProgressiveDoneListener(t){this._progressiveDoneListeners.push(t)}onDataRange(t,e){for(const s of this._rangeListeners)s(t,e)}onDataProgress(t,e){this._readyCapability.promise.then(()=>{for(const s of this._progressListeners)s(t,e)})}onDataProgressiveRead(t){this._readyCapability.promise.then(()=>{for(const e of this._progressiveReadListeners)e(t)})}onDataProgressiveDone(){this._readyCapability.promise.then(()=>{for(const t of this._progressiveDoneListeners)t()})}transportReady(){this._readyCapability.resolve()}requestDataRange(t,e){vt("Abstract method PDFDataRangeTransport.requestDataRange")}abort(){}}class pS{constructor(t,e){this._pdfInfo=t,this._transport=e}get annotationStorage(){return this._transport.annotationStorage}get canvasFactory(){return this._transport.canvasFactory}get filterFactory(){return this._transport.filterFactory}get numPages(){return this._pdfInfo.numPages}get fingerprints(){return this._pdfInfo.fingerprints}get isPureXfa(){return st(this,"isPureXfa",!!this._transport._htmlForXfa)}get allXfaHtml(){return this._transport._htmlForXfa}getPage(t){return this._transport.getPage(t)}getPageIndex(t){return this._transport.getPageIndex(t)}getDestinations(){return this._transport.getDestinations()}getDestination(t){return this._transport.getDestination(t)}getPageLabels(){return this._transport.getPageLabels()}getPageLayout(){return this._transport.getPageLayout()}getPageMode(){return this._transport.getPageMode()}getViewerPreferences(){return this._transport.getViewerPreferences()}getOpenAction(){return this._transport.getOpenAction()}getAttachments(){return this._transport.getAttachments()}getJSActions(){return this._transport.getDocJSActions()}getOutline(){return this._transport.getOutline()}getOptionalContentConfig({intent:t="display"}={}){const{renderingIntent:e}=this._transport.getRenderingIntent(t);return this._transport.getOptionalContentConfig(e)}getPermissions(){return this._transport.getPermissions()}getMetadata(){return this._transport.getMetadata()}getMarkInfo(){return this._transport.getMarkInfo()}getData(){return this._transport.getData()}saveDocument(){return this._transport.saveDocument()}getDownloadInfo(){return this._transport.downloadInfoCapability.promise}cleanup(t=!1){return this._transport.startCleanup(t||this.isPureXfa)}destroy(){return this.loadingTask.destroy()}cachedPageNumber(t){return this._transport.cachedPageNumber(t)}get loadingParams(){return this._transport.loadingParams}get loadingTask(){return this._transport.loadingTask}getFieldObjects(){return this._transport.getFieldObjects()}hasJSActions(){return this._transport.hasJSActions()}getCalculationOrderIds(){return this._transport.getCalculationOrderIds()}}class mS{constructor(t,e,s,i=!1){y(this,As);y(this,Zn,null);y(this,rn,!1);this._pageIndex=t,this._pageInfo=e,this._transport=s,this._stats=i?new K0:null,this._pdfBug=i,this.commonObjs=s.commonObjs,this.objs=new Eb,this._maybeCleanupAfterRender=!1,this._intentStates=new Map,this.destroyed=!1}get pageNumber(){return this._pageIndex+1}get rotate(){return this._pageInfo.rotate}get ref(){return this._pageInfo.ref}get userUnit(){return this._pageInfo.userUnit}get view(){return this._pageInfo.view}getViewport({scale:t,rotation:e=this.rotate,offsetX:s=0,offsetY:i=0,dontFlip:n=!1}={}){return new zh({viewBox:this.view,userUnit:this.userUnit,scale:t,rotation:e,offsetX:s,offsetY:i,dontFlip:n})}getAnnotations({intent:t="display"}={}){const{renderingIntent:e}=this._transport.getRenderingIntent(t);return this._transport.getAnnotations(this._pageIndex,e)}getJSActions(){return this._transport.getPageJSActions(this._pageIndex)}get filterFactory(){return this._transport.filterFactory}get isPureXfa(){return st(this,"isPureXfa",!!this._transport._htmlForXfa)}async getXfa(){var t;return((t=this._transport._htmlForXfa)==null?void 0:t.children[this._pageIndex])||null}render({canvasContext:t,viewport:e,intent:s="display",annotationMode:i=Dn.ENABLE,transform:n=null,background:r=null,optionalContentConfigPromise:o=null,annotationCanvasMap:h=null,pageColors:c=null,printAnnotationStorage:u=null,isEditing:d=!1}){var S,k;(S=this._stats)==null||S.time("Overall");const f=this._transport.getRenderingIntent(s,i,u,d),{renderingIntent:g,cacheKey:p}=f;m(this,rn,!1),w(this,As,jd).call(this),o||(o=this._transport.getOptionalContentConfig(g));let b=this._intentStates.get(p);b||(b=Object.create(null),this._intentStates.set(p,b)),b.streamReaderCancelTimeout&&(clearTimeout(b.streamReaderCancelTimeout),b.streamReaderCancelTimeout=null);const v=!!(g&ts.PRINT);b.displayReadyCapability||(b.displayReadyCapability=Promise.withResolvers(),b.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},(k=this._stats)==null||k.time("Page Request"),this._pumpOperatorList(f));const _=D=>{var T;b.renderTasks.delete(x),(this._maybeCleanupAfterRender||v)&&m(this,rn,!0),w(this,As,vh).call(this,!v),D?(x.capability.reject(D),this._abortOperatorList({intentState:b,reason:D instanceof Error?D:new Error(D)})):x.capability.resolve(),this._stats&&(this._stats.timeEnd("Rendering"),this._stats.timeEnd("Overall"),(T=globalThis.Stats)!=null&&T.enabled&&globalThis.Stats.add(this.pageNumber,this._stats))},x=new Mg({callback:_,params:{canvasContext:t,viewport:e,transform:n,background:r},objs:this.objs,commonObjs:this.commonObjs,annotationCanvasMap:h,operatorList:b.operatorList,pageIndex:this._pageIndex,canvasFactory:this._transport.canvasFactory,filterFactory:this._transport.filterFactory,useRequestAnimationFrame:!v,pdfBug:this._pdfBug,pageColors:c});(b.renderTasks||(b.renderTasks=new Set)).add(x);const C=x.task;return Promise.all([b.displayReadyCapability.promise,o]).then(([D,T])=>{var M;if(this.destroyed){_();return}if((M=this._stats)==null||M.time("Rendering"),!(T.renderingIntent&g))throw new Error("Must use the same `intent`-argument when calling the `PDFPageProxy.render` and `PDFDocumentProxy.getOptionalContentConfig` methods.");x.initializeGraphics({transparency:D,optionalContentConfig:T}),x.operatorListChanged()}).catch(_),C}getOperatorList({intent:t="display",annotationMode:e=Dn.ENABLE,printAnnotationStorage:s=null,isEditing:i=!1}={}){var c;function n(){o.operatorList.lastChunk&&(o.opListReadCapability.resolve(o.operatorList),o.renderTasks.delete(h))}const r=this._transport.getRenderingIntent(t,e,s,i,!0);let o=this._intentStates.get(r.cacheKey);o||(o=Object.create(null),this._intentStates.set(r.cacheKey,o));let h;return o.opListReadCapability||(h=Object.create(null),h.operatorListChanged=n,o.opListReadCapability=Promise.withResolvers(),(o.renderTasks||(o.renderTasks=new Set)).add(h),o.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},(c=this._stats)==null||c.time("Page Request"),this._pumpOperatorList(r)),o.opListReadCapability.promise}streamTextContent({includeMarkedContent:t=!1,disableNormalization:e=!1}={}){return this._transport.messageHandler.sendWithStream("GetTextContent",{pageIndex:this._pageIndex,includeMarkedContent:t===!0,disableNormalization:e===!0},{highWaterMark:100,size(i){return i.items.length}})}getTextContent(t={}){if(this._transport._htmlForXfa)return this.getXfa().then(s=>$h.textContent(s));const e=this.streamTextContent(t);return new Promise(function(s,i){function n(){r.read().then(function({value:h,done:c}){if(c){s(o);return}o.lang??(o.lang=h.lang),Object.assign(o.styles,h.styles),o.items.push(...h.items),n()},i)}const r=e.getReader(),o={items:[],styles:Object.create(null),lang:null};n()})}getStructTree(){return this._transport.getStructTree(this._pageIndex)}_destroy(){this.destroyed=!0;const t=[];for(const e of this._intentStates.values())if(this._abortOperatorList({intentState:e,reason:new Error("Page was destroyed."),force:!0}),!e.opListReadCapability)for(const s of e.renderTasks)t.push(s.completed),s.cancel();return this.objs.clear(),m(this,rn,!1),w(this,As,jd).call(this),Promise.all(t)}cleanup(t=!1){m(this,rn,!0);const e=w(this,As,vh).call(this,!1);return t&&e&&this._stats&&(this._stats=new K0),e}_startRenderPage(t,e){var i,n;const s=this._intentStates.get(e);s&&((i=this._stats)==null||i.timeEnd("Page Request"),(n=s.displayReadyCapability)==null||n.resolve(t))}_renderPageChunk(t,e){for(let s=0,i=t.length;s<i;s++)e.operatorList.fnArray.push(t.fnArray[s]),e.operatorList.argsArray.push(t.argsArray[s]);e.operatorList.lastChunk=t.lastChunk,e.operatorList.separateAnnots=t.separateAnnots;for(const s of e.renderTasks)s.operatorListChanged();t.lastChunk&&w(this,As,vh).call(this,!0)}_pumpOperatorList({renderingIntent:t,cacheKey:e,annotationStorageSerializable:s,modifiedIds:i}){const{map:n,transfer:r}=s,h=this._transport.messageHandler.sendWithStream("GetOperatorList",{pageIndex:this._pageIndex,intent:t,cacheKey:e,annotationStorage:n,modifiedIds:i},r).getReader(),c=this._intentStates.get(e);c.streamReader=h;const u=()=>{h.read().then(({value:d,done:f})=>{if(f){c.streamReader=null;return}this._transport.destroyed||(this._renderPageChunk(d,c),u())},d=>{if(c.streamReader=null,!this._transport.destroyed){if(c.operatorList){c.operatorList.lastChunk=!0;for(const f of c.renderTasks)f.operatorListChanged();w(this,As,vh).call(this,!0)}if(c.displayReadyCapability)c.displayReadyCapability.reject(d);else if(c.opListReadCapability)c.opListReadCapability.reject(d);else throw d}})};u()}_abortOperatorList({intentState:t,reason:e,force:s=!1}){if(t.streamReader){if(t.streamReaderCancelTimeout&&(clearTimeout(t.streamReaderCancelTimeout),t.streamReaderCancelTimeout=null),!s){if(t.renderTasks.size>0)return;if(e instanceof dg){let i=oS;e.extraDelay>0&&e.extraDelay<1e3&&(i+=e.extraDelay),t.streamReaderCancelTimeout=setTimeout(()=>{t.streamReaderCancelTimeout=null,this._abortOperatorList({intentState:t,reason:e,force:!0})},i);return}}if(t.streamReader.cancel(new Rn(e.message)).catch(()=>{}),t.streamReader=null,!this._transport.destroyed){for(const[i,n]of this._intentStates)if(n===t){this._intentStates.delete(i);break}this.cleanup()}}}get stats(){return this._stats}}Zn=new WeakMap,rn=new WeakMap,As=new WeakSet,vh=function(t=!1){if(w(this,As,jd).call(this),!l(this,rn)||this.destroyed)return!1;if(t)return m(this,Zn,setTimeout(()=>{m(this,Zn,null),w(this,As,vh).call(this,!1)},aS)),!1;for(const{renderTasks:e,operatorList:s}of this._intentStates.values())if(e.size>0||!s.lastChunk)return!1;return this._intentStates.clear(),this.objs.clear(),m(this,rn,!1),!0},jd=function(){l(this,Zn)&&(clearTimeout(l(this,Zn)),m(this,Zn,null))};class bS{constructor(){y(this,on,new Map);y(this,bd,Promise.resolve())}postMessage(t,e){const s={data:structuredClone(t,e?{transfer:e}:null)};l(this,bd).then(()=>{for(const[i]of l(this,on))i.call(this,s)})}addEventListener(t,e,s=null){let i=null;if((s==null?void 0:s.signal)instanceof AbortSignal){const{signal:n}=s;if(n.aborted){tt("LoopbackPort - cannot use an `aborted` signal.");return}const r=()=>this.removeEventListener(t,e);i=()=>n.removeEventListener("abort",r),n.addEventListener("abort",r)}l(this,on).set(e,i)}removeEventListener(t,e){const s=l(this,on).get(e);s==null||s(),l(this,on).delete(e)}terminate(){for(const[,t]of l(this,on))t==null||t();l(this,on).clear()}}on=new WeakMap,bd=new WeakMap;const Et=class Et{constructor({name:t=null,port:e=null,verbosity:s=Jw()}={}){y(this,La);var i;if(this.name=t,this.destroyed=!1,this.verbosity=s,this._readyCapability=Promise.withResolvers(),this._port=null,this._webWorker=null,this._messageHandler=null,e){if((i=l(Et,lo))!=null&&i.has(e))throw new Error("Cannot use more than one PDFWorker per port.");(l(Et,lo)||m(Et,lo,new WeakMap)).set(e,this),this._initializeFromPort(e);return}this._initialize()}get promise(){return this._readyCapability.promise}get port(){return this._port}get messageHandler(){return this._messageHandler}_initializeFromPort(t){this._port=t,this._messageHandler=new Wh("main","worker",t),this._messageHandler.on("ready",function(){}),w(this,La,Bd).call(this)}_initialize(){if(l(Et,ho)||l(Et,Fa,Hd)){this._setupFakeWorker();return}let{workerSrc:t}=Et;try{Et._isSameOrigin(window.location.href,t)||(t=Et._createCDNWrapper(new URL(t,window.location).href));const e=new Worker(t,{type:"module"}),s=new Wh("main","worker",e),i=()=>{n.abort(),s.destroy(),e.terminate(),this.destroyed?this._readyCapability.reject(new Error("Worker was destroyed")):this._setupFakeWorker()},n=new AbortController;e.addEventListener("error",()=>{this._webWorker||i()},{signal:n.signal}),s.on("test",o=>{if(n.abort(),this.destroyed||!o){i();return}this._messageHandler=s,this._port=e,this._webWorker=e,w(this,La,Bd).call(this)}),s.on("ready",o=>{if(n.abort(),this.destroyed){i();return}try{r()}catch{this._setupFakeWorker()}});const r=()=>{const o=new Uint8Array;s.send("test",o,[o.buffer])};r();return}catch{Vu("The worker has been disabled.")}this._setupFakeWorker()}_setupFakeWorker(){l(Et,ho)||(tt("Setting up fake worker."),m(Et,ho,!0)),Et._setupFakeWorkerGlobal.then(t=>{if(this.destroyed){this._readyCapability.reject(new Error("Worker was destroyed"));return}const e=new bS;this._port=e;const s=`fake${Ge(Et,yd)._++}`,i=new Wh(s+"_worker",s,e);t.setup(i,e),this._messageHandler=new Wh(s,s+"_worker",e),w(this,La,Bd).call(this)}).catch(t=>{this._readyCapability.reject(new Error(`Setting up fake worker failed: "${t.message}".`))})}destroy(){var t,e,s;this.destroyed=!0,(t=this._webWorker)==null||t.terminate(),this._webWorker=null,(e=l(Et,lo))==null||e.delete(this._port),this._port=null,(s=this._messageHandler)==null||s.destroy(),this._messageHandler=null}static fromPort(t){var s;if(!(t!=null&&t.port))throw new Error("PDFWorker.fromPort - invalid method signature.");const e=(s=l(this,lo))==null?void 0:s.get(t.port);if(e){if(e._pendingDestroy)throw new Error("PDFWorker.fromPort - the worker is being destroyed.\nPlease remember to await `PDFDocumentLoadingTask.destroy()`-calls.");return e}return new Et(t)}static get workerSrc(){if(Vi.workerSrc)return Vi.workerSrc;throw new Error('No "GlobalWorkerOptions.workerSrc" specified.')}static get _setupFakeWorkerGlobal(){return st(this,"_setupFakeWorkerGlobal",(async()=>l(this,Fa,Hd)?l(this,Fa,Hd):(await import(this.workerSrc)).WorkerMessageHandler)())}};yd=new WeakMap,ho=new WeakMap,lo=new WeakMap,La=new WeakSet,Bd=function(){this._readyCapability.resolve(),this._messageHandler.send("configure",{verbosity:this.verbosity})},Fa=new WeakSet,Hd=function(){var t;try{return((t=globalThis.pdfjsWorker)==null?void 0:t.WorkerMessageHandler)||null}catch{return null}},y(Et,Fa),y(Et,yd,0),y(Et,ho,!1),y(Et,lo),ye&&(m(Et,ho,!0),Vi.workerSrc||(Vi.workerSrc="./pdf.worker.mjs")),Et._isSameOrigin=(t,e)=>{let s;try{if(s=new URL(t),!s.origin||s.origin==="null")return!1}catch{return!1}const i=new URL(e,s);return s.origin===i.origin},Et._createCDNWrapper=t=>{const e=`await import("${t}");`;return URL.createObjectURL(new Blob([e],{type:"text/javascript"}))};let aa=Et;class yS{constructor(t,e,s,i,n){y(this,co);y(this,an,new Map);y(this,_i,new Map);y(this,Ia,new Map);y(this,Na,new Map);y(this,hn,null);this.messageHandler=t,this.loadingTask=e,this.commonObjs=new Eb,this.fontLoader=new bx({ownerDocument:i.ownerDocument,styleElement:i.styleElement}),this.loadingParams=i.loadingParams,this._params=i,this.canvasFactory=n.canvasFactory,this.filterFactory=n.filterFactory,this.cMapReaderFactory=n.cMapReaderFactory,this.standardFontDataFactory=n.standardFontDataFactory,this.destroyed=!1,this.destroyCapability=null,this._networkStream=s,this._fullReader=null,this._lastProgress=null,this.downloadInfoCapability=Promise.withResolvers(),this.setupMessageHandler()}get annotationStorage(){return st(this,"annotationStorage",new wg)}getRenderingIntent(t,e=Dn.ENABLE,s=null,i=!1,n=!1){let r=ts.DISPLAY,o=_g;switch(t){case"any":r=ts.ANY;break;case"display":break;case"print":r=ts.PRINT;break;default:tt(`getRenderingIntent - invalid intent: ${t}`)}const h=r&ts.PRINT&&s instanceof Z0?s:this.annotationStorage;switch(e){case Dn.DISABLE:r+=ts.ANNOTATIONS_DISABLE;break;case Dn.ENABLE:break;case Dn.ENABLE_FORMS:r+=ts.ANNOTATIONS_FORMS;break;case Dn.ENABLE_STORAGE:r+=ts.ANNOTATIONS_STORAGE,o=h.serializable;break;default:tt(`getRenderingIntent - invalid annotationMode: ${e}`)}i&&(r+=ts.IS_EDITING),n&&(r+=ts.OPLIST);const{ids:c,hash:u}=h.modifiedIds,d=[r,o.hash,u];return{renderingIntent:r,cacheKey:d.join("_"),annotationStorageSerializable:o,modifiedIds:c}}destroy(){var s;if(this.destroyCapability)return this.destroyCapability.promise;this.destroyed=!0,this.destroyCapability=Promise.withResolvers(),(s=l(this,hn))==null||s.reject(new Error("Worker was destroyed during onPassword callback"));const t=[];for(const i of l(this,_i).values())t.push(i._destroy());l(this,_i).clear(),l(this,Ia).clear(),l(this,Na).clear(),this.hasOwnProperty("annotationStorage")&&this.annotationStorage.resetModified();const e=this.messageHandler.sendWithPromise("Terminate",null);return t.push(e),Promise.all(t).then(()=>{var i,n;this.commonObjs.clear(),this.fontLoader.clear(),l(this,an).clear(),this.filterFactory.destroy(),Yh.cleanup(),(i=this._networkStream)==null||i.cancelAllRequests(new Rn("Worker was terminated.")),(n=this.messageHandler)==null||n.destroy(),this.messageHandler=null,this.destroyCapability.resolve()},this.destroyCapability.reject),this.destroyCapability.promise}setupMessageHandler(){const{messageHandler:t,loadingTask:e}=this;t.on("GetReader",(s,i)=>{Xt(this._networkStream,"GetReader - no `IPDFStream` instance available."),this._fullReader=this._networkStream.getFullReader(),this._fullReader.onProgress=n=>{this._lastProgress={loaded:n.loaded,total:n.total}},i.onPull=()=>{this._fullReader.read().then(function({value:n,done:r}){if(r){i.close();return}Xt(n instanceof ArrayBuffer,"GetReader - expected an ArrayBuffer."),i.enqueue(new Uint8Array(n),1,[n])}).catch(n=>{i.error(n)})},i.onCancel=n=>{this._fullReader.cancel(n),i.ready.catch(r=>{if(!this.destroyed)throw r})}}),t.on("ReaderHeadersReady",async s=>{var o;await this._fullReader.headersReady;const{isStreamingSupported:i,isRangeSupported:n,contentLength:r}=this._fullReader;return(!i||!n)&&(this._lastProgress&&((o=e.onProgress)==null||o.call(e,this._lastProgress)),this._fullReader.onProgress=h=>{var c;(c=e.onProgress)==null||c.call(e,{loaded:h.loaded,total:h.total})}),{isStreamingSupported:i,isRangeSupported:n,contentLength:r}}),t.on("GetRangeReader",(s,i)=>{Xt(this._networkStream,"GetRangeReader - no `IPDFStream` instance available.");const n=this._networkStream.getRangeReader(s.begin,s.end);if(!n){i.close();return}i.onPull=()=>{n.read().then(function({value:r,done:o}){if(o){i.close();return}Xt(r instanceof ArrayBuffer,"GetRangeReader - expected an ArrayBuffer."),i.enqueue(new Uint8Array(r),1,[r])}).catch(r=>{i.error(r)})},i.onCancel=r=>{n.cancel(r),i.ready.catch(o=>{if(!this.destroyed)throw o})}}),t.on("GetDoc",({pdfInfo:s})=>{this._numPages=s.numPages,this._htmlForXfa=s.htmlForXfa,delete s.htmlForXfa,e._capability.resolve(new pS(s,this))}),t.on("DocException",s=>{e._capability.reject(We(s))}),t.on("PasswordRequest",s=>{m(this,hn,Promise.withResolvers());try{if(!e.onPassword)throw We(s);const i=n=>{n instanceof Error?l(this,hn).reject(n):l(this,hn).resolve({password:n})};e.onPassword(i,s.code)}catch(i){l(this,hn).reject(i)}return l(this,hn).promise}),t.on("DataLoaded",s=>{var i;(i=e.onProgress)==null||i.call(e,{loaded:s.length,total:s.length}),this.downloadInfoCapability.resolve(s)}),t.on("StartRenderPage",s=>{if(this.destroyed)return;l(this,_i).get(s.pageIndex)._startRenderPage(s.transparency,s.cacheKey)}),t.on("commonobj",([s,i,n])=>{var r;if(this.destroyed||this.commonObjs.has(s))return null;switch(i){case"Font":const{disableFontFace:o,fontExtraProperties:h,pdfBug:c}=this._params;if("error"in n){const g=n.error;tt(`Error during font loading: ${g}`),this.commonObjs.resolve(s,g);break}const u=c&&((r=globalThis.FontInspector)!=null&&r.enabled)?(g,p)=>globalThis.FontInspector.fontAdded(g,p):null,d=new yx(n,{disableFontFace:o,fontExtraProperties:h,inspectFont:u});this.fontLoader.bind(d).catch(()=>t.sendWithPromise("FontFallback",{id:s})).finally(()=>{!h&&d.data&&(d.data=null),this.commonObjs.resolve(s,d)});break;case"CopyLocalImage":const{imageRef:f}=n;Xt(f,"The imageRef must be defined.");for(const g of l(this,_i).values())for(const[,p]of g.objs)if((p==null?void 0:p.ref)===f)return p.dataLen?(this.commonObjs.resolve(s,structuredClone(p)),p.dataLen):null;break;case"FontPath":case"Image":case"Pattern":this.commonObjs.resolve(s,n);break;default:throw new Error(`Got unknown common object type ${i}`)}return null}),t.on("obj",([s,i,n,r])=>{var h;if(this.destroyed)return;const o=l(this,_i).get(i);if(!o.objs.has(s)){if(o._intentStates.size===0){(h=r==null?void 0:r.bitmap)==null||h.close();return}switch(n){case"Image":o.objs.resolve(s,r),(r==null?void 0:r.dataLen)>Yw&&(o._maybeCleanupAfterRender=!0);break;case"Pattern":o.objs.resolve(s,r);break;default:throw new Error(`Got unknown object type ${n}`)}}}),t.on("DocProgress",s=>{var i;this.destroyed||(i=e.onProgress)==null||i.call(e,{loaded:s.loaded,total:s.total})}),t.on("FetchBuiltInCMap",async s=>{if(this.destroyed)throw new Error("Worker was destroyed.");if(!this.cMapReaderFactory)throw new Error("CMapReaderFactory not initialized, see the `useWorkerFetch` parameter.");return this.cMapReaderFactory.fetch(s)}),t.on("FetchStandardFontData",async s=>{if(this.destroyed)throw new Error("Worker was destroyed.");if(!this.standardFontDataFactory)throw new Error("StandardFontDataFactory not initialized, see the `useWorkerFetch` parameter.");return this.standardFontDataFactory.fetch(s)})}getData(){return this.messageHandler.sendWithPromise("GetData",null)}saveDocument(){var s;this.annotationStorage.size<=0&&tt("saveDocument called while `annotationStorage` is empty, please use the getData-method instead.");const{map:t,transfer:e}=this.annotationStorage.serializable;return this.messageHandler.sendWithPromise("SaveDocument",{isPureXfa:!!this._htmlForXfa,numPages:this._numPages,annotationStorage:t,filename:((s=this._fullReader)==null?void 0:s.filename)??null},e).finally(()=>{this.annotationStorage.resetModified()})}getPage(t){if(!Number.isInteger(t)||t<=0||t>this._numPages)return Promise.reject(new Error("Invalid page request."));const e=t-1,s=l(this,Ia).get(e);if(s)return s;const i=this.messageHandler.sendWithPromise("GetPage",{pageIndex:e}).then(n=>{if(this.destroyed)throw new Error("Transport destroyed");n.refStr&&l(this,Na).set(n.refStr,t);const r=new mS(e,n,this,this._params.pdfBug);return l(this,_i).set(e,r),r});return l(this,Ia).set(e,i),i}getPageIndex(t){return Ab(t)?this.messageHandler.sendWithPromise("GetPageIndex",{num:t.num,gen:t.gen}):Promise.reject(new Error("Invalid pageIndex request."))}getAnnotations(t,e){return this.messageHandler.sendWithPromise("GetAnnotations",{pageIndex:t,intent:e})}getFieldObjects(){return w(this,co,Dc).call(this,"GetFieldObjects")}hasJSActions(){return w(this,co,Dc).call(this,"HasJSActions")}getCalculationOrderIds(){return this.messageHandler.sendWithPromise("GetCalculationOrderIds",null)}getDestinations(){return this.messageHandler.sendWithPromise("GetDestinations",null)}getDestination(t){return typeof t!="string"?Promise.reject(new Error("Invalid destination request.")):this.messageHandler.sendWithPromise("GetDestination",{id:t})}getPageLabels(){return this.messageHandler.sendWithPromise("GetPageLabels",null)}getPageLayout(){return this.messageHandler.sendWithPromise("GetPageLayout",null)}getPageMode(){return this.messageHandler.sendWithPromise("GetPageMode",null)}getViewerPreferences(){return this.messageHandler.sendWithPromise("GetViewerPreferences",null)}getOpenAction(){return this.messageHandler.sendWithPromise("GetOpenAction",null)}getAttachments(){return this.messageHandler.sendWithPromise("GetAttachments",null)}getDocJSActions(){return w(this,co,Dc).call(this,"GetDocJSActions")}getPageJSActions(t){return this.messageHandler.sendWithPromise("GetPageJSActions",{pageIndex:t})}getStructTree(t){return this.messageHandler.sendWithPromise("GetStructTree",{pageIndex:t})}getOutline(){return this.messageHandler.sendWithPromise("GetOutline",null)}getOptionalContentConfig(t){return w(this,co,Dc).call(this,"GetOptionalContentConfig").then(e=>new Hx(e,t))}getPermissions(){return this.messageHandler.sendWithPromise("GetPermissions",null)}getMetadata(){const t="GetMetadata",e=l(this,an).get(t);if(e)return e;const s=this.messageHandler.sendWithPromise(t,null).then(i=>{var n,r;return{info:i[0],metadata:i[1]?new jx(i[1]):null,contentDispositionFilename:((n=this._fullReader)==null?void 0:n.filename)??null,contentLength:((r=this._fullReader)==null?void 0:r.contentLength)??null}});return l(this,an).set(t,s),s}getMarkInfo(){return this.messageHandler.sendWithPromise("GetMarkInfo",null)}async startCleanup(t=!1){if(!this.destroyed){await this.messageHandler.sendWithPromise("Cleanup",null);for(const e of l(this,_i).values())if(!e.cleanup())throw new Error(`startCleanup: Page ${e.pageNumber} is currently rendering.`);this.commonObjs.clear(),t||this.fontLoader.clear(),l(this,an).clear(),this.filterFactory.destroy(!0),Yh.cleanup()}}cachedPageNumber(t){if(!Ab(t))return null;const e=t.gen===0?`${t.num}R`:`${t.num}R${t.gen}`;return l(this,Na).get(e)??null}}an=new WeakMap,_i=new WeakMap,Ia=new WeakMap,Na=new WeakMap,hn=new WeakMap,co=new WeakSet,Dc=function(t,e=null){const s=l(this,an).get(t);if(s)return s;const i=this.messageHandler.sendWithPromise(t,e);return l(this,an).set(t,i),i};const qh=Symbol("INITIAL_DATA");class Eb{constructor(){y(this,Gl);y(this,os,Object.create(null))}get(t,e=null){if(e){const i=w(this,Gl,vp).call(this,t);return i.promise.then(()=>e(i.data)),null}const s=l(this,os)[t];if(!s||s.data===qh)throw new Error(`Requesting object that isn't resolved yet ${t}.`);return s.data}has(t){const e=l(this,os)[t];return!!e&&e.data!==qh}delete(t){const e=l(this,os)[t];return!e||e.data===qh?!1:(delete l(this,os)[t],!0)}resolve(t,e=null){const s=w(this,Gl,vp).call(this,t);s.data=e,s.resolve()}clear(){var t;for(const e in l(this,os)){const{data:s}=l(this,os)[e];(t=s==null?void 0:s.bitmap)==null||t.close()}m(this,os,Object.create(null))}*[Symbol.iterator](){for(const t in l(this,os)){const{data:e}=l(this,os)[t];e!==qh&&(yield[t,e])}}}os=new WeakMap,Gl=new WeakSet,vp=function(t){var e;return(e=l(this,os))[t]||(e[t]={...Promise.withResolvers(),data:qh})};class vS{constructor(t){y(this,tr,null);m(this,tr,t),this.onContinue=null}get promise(){return l(this,tr).capability.promise}cancel(t=0){l(this,tr).cancel(null,t)}get separateAnnots(){const{separateAnnots:t}=l(this,tr).operatorList;if(!t)return!1;const{annotationCanvasMap:e}=l(this,tr);return t.form||t.canvas&&(e==null?void 0:e.size)>0}}tr=new WeakMap;const fo=class fo{constructor({callback:t,params:e,objs:s,commonObjs:i,annotationCanvasMap:n,operatorList:r,pageIndex:o,canvasFactory:h,filterFactory:c,useRequestAnimationFrame:u=!1,pdfBug:d=!1,pageColors:f=null}){y(this,er,null);this.callback=t,this.params=e,this.objs=s,this.commonObjs=i,this.annotationCanvasMap=n,this.operatorListIdx=null,this.operatorList=r,this._pageIndex=o,this.canvasFactory=h,this.filterFactory=c,this._pdfBug=d,this.pageColors=f,this.running=!1,this.graphicsReadyCallback=null,this.graphicsReady=!1,this._useRequestAnimationFrame=u===!0&&typeof window<"u",this.cancelled=!1,this.capability=Promise.withResolvers(),this.task=new vS(this),this._cancelBound=this.cancel.bind(this),this._continueBound=this._continue.bind(this),this._scheduleNextBound=this._scheduleNext.bind(this),this._nextBound=this._next.bind(this),this._canvas=e.canvasContext.canvas}get completed(){return this.capability.promise.catch(function(){})}initializeGraphics({transparency:t=!1,optionalContentConfig:e}){var o,h;if(this.cancelled)return;if(this._canvas){if(l(fo,uo).has(this._canvas))throw new Error("Cannot use the same canvas during multiple render() operations. Use different canvas or ensure previous operations were cancelled or completed.");l(fo,uo).add(this._canvas)}this._pdfBug&&((o=globalThis.StepperManager)!=null&&o.enabled)&&(this.stepper=globalThis.StepperManager.create(this._pageIndex),this.stepper.init(this.operatorList),this.stepper.nextBreakPoint=this.stepper.getNextBreakPoint());const{canvasContext:s,viewport:i,transform:n,background:r}=this.params;this.gfx=new ra(s,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:e},this.annotationCanvasMap,this.pageColors),this.gfx.beginDrawing({transform:n,viewport:i,transparency:t,background:r}),this.operatorListIdx=0,this.graphicsReady=!0,(h=this.graphicsReadyCallback)==null||h.call(this)}cancel(t=null,e=0){var s;this.running=!1,this.cancelled=!0,(s=this.gfx)==null||s.endDrawing(),l(this,er)&&(window.cancelAnimationFrame(l(this,er)),m(this,er,null)),l(fo,uo).delete(this._canvas),this.callback(t||new dg(`Rendering cancelled, page ${this._pageIndex+1}`,e))}operatorListChanged(){var t;if(!this.graphicsReady){this.graphicsReadyCallback||(this.graphicsReadyCallback=this._continueBound);return}(t=this.stepper)==null||t.updateOperatorList(this.operatorList),!this.running&&this._continue()}_continue(){this.running=!0,!this.cancelled&&(this.task.onContinue?this.task.onContinue(this._scheduleNextBound):this._scheduleNext())}_scheduleNext(){this._useRequestAnimationFrame?m(this,er,window.requestAnimationFrame(()=>{m(this,er,null),this._nextBound().catch(this._cancelBound)})):Promise.resolve().then(this._nextBound).catch(this._cancelBound)}async _next(){this.cancelled||(this.operatorListIdx=this.gfx.executeOperatorList(this.operatorList,this.operatorListIdx,this._continueBound,this.stepper),this.operatorListIdx===this.operatorList.argsArray.length&&(this.running=!1,this.operatorList.lastChunk&&(this.gfx.endDrawing(),l(fo,uo).delete(this._canvas),this.callback())))}};er=new WeakMap,uo=new WeakMap,y(fo,uo,new WeakSet);let Mg=fo;const _S="4.10.38",wS="f9bea397f";function kb(a){return Math.floor(Math.max(0,Math.min(1,a))*255).toString(16).padStart(2,"0")}function Kh(a){return Math.max(0,Math.min(255,255*a))}class Mb{static CMYK_G([t,e,s,i]){return["G",1-Math.min(1,.3*t+.59*s+.11*e+i)]}static G_CMYK([t]){return["CMYK",0,0,0,1-t]}static G_RGB([t]){return["RGB",t,t,t]}static G_rgb([t]){return t=Kh(t),[t,t,t]}static G_HTML([t]){const e=kb(t);return`#${e}${e}${e}`}static RGB_G([t,e,s]){return["G",.3*t+.59*e+.11*s]}static RGB_rgb(t){return t.map(Kh)}static RGB_HTML(t){return`#${t.map(kb).join("")}`}static T_HTML(){return"#00000000"}static T_rgb(){return[null]}static CMYK_RGB([t,e,s,i]){return["RGB",1-Math.min(1,t+i),1-Math.min(1,s+i),1-Math.min(1,e+i)]}static CMYK_rgb([t,e,s,i]){return[Kh(1-Math.min(1,t+i)),Kh(1-Math.min(1,s+i)),Kh(1-Math.min(1,e+i))]}static CMYK_HTML(t){const e=this.CMYK_RGB(t).slice(1);return this.RGB_HTML(e)}static RGB_CMYK([t,e,s]){const i=1-t,n=1-e,r=1-s,o=Math.min(i,n,r);return["CMYK",i,n,r,o]}}class xS{create(t,e,s=!1){if(t<=0||e<=0)throw new Error("Invalid SVG dimensions");const i=this._createSVG("svg:svg");return i.setAttribute("version","1.1"),s||(i.setAttribute("width",`${t}px`),i.setAttribute("height",`${e}px`)),i.setAttribute("preserveAspectRatio","none"),i.setAttribute("viewBox",`0 0 ${t} ${e}`),i}createElement(t){if(typeof t!="string")throw new Error("Invalid SVG element type");return this._createSVG(t)}_createSVG(t){vt("Abstract method `_createSVG` called.")}}class Pg extends xS{_createSVG(t){return document.createElementNS(zi,t)}}class Pb{static setupStorage(t,e,s,i,n){const r=i.getValue(e,{value:null});switch(s.name){case"textarea":if(r.value!==null&&(t.textContent=r.value),n==="print")break;t.addEventListener("input",o=>{i.setValue(e,{value:o.target.value})});break;case"input":if(s.attributes.type==="radio"||s.attributes.type==="checkbox"){if(r.value===s.attributes.xfaOn?t.setAttribute("checked",!0):r.value===s.attributes.xfaOff&&t.removeAttribute("checked"),n==="print")break;t.addEventListener("change",o=>{i.setValue(e,{value:o.target.checked?o.target.getAttribute("xfaOn"):o.target.getAttribute("xfaOff")})})}else{if(r.value!==null&&t.setAttribute("value",r.value),n==="print")break;t.addEventListener("input",o=>{i.setValue(e,{value:o.target.value})})}break;case"select":if(r.value!==null){t.setAttribute("value",r.value);for(const o of s.children)o.attributes.value===r.value?o.attributes.selected=!0:o.attributes.hasOwnProperty("selected")&&delete o.attributes.selected}t.addEventListener("input",o=>{const h=o.target.options,c=h.selectedIndex===-1?"":h[h.selectedIndex].value;i.setValue(e,{value:c})});break}}static setAttributes({html:t,element:e,storage:s=null,intent:i,linkService:n}){const{attributes:r}=e,o=t instanceof HTMLAnchorElement;r.type==="radio"&&(r.name=`${r.name}-${i}`);for(const[h,c]of Object.entries(r))if(c!=null)switch(h){case"class":c.length&&t.setAttribute(h,c.join(" "));break;case"dataId":break;case"id":t.setAttribute("data-element-id",c);break;case"style":Object.assign(t.style,c);break;case"textContent":t.textContent=c;break;default:(!o||h!=="href"&&h!=="newWindow")&&t.setAttribute(h,c)}o&&n.addLinkAttributes(t,r.href,r.newWindow),s&&r.dataId&&this.setupStorage(t,r.dataId,e,s)}static render(t){var d,f;const e=t.annotationStorage,s=t.linkService,i=t.xfaHtml,n=t.intent||"display",r=document.createElement(i.name);i.attributes&&this.setAttributes({html:r,element:i,intent:n,linkService:s});const o=n!=="richText",h=t.div;if(h.append(r),t.viewport){const g=`matrix(${t.viewport.transform.join(",")})`;h.style.transform=g}o&&h.setAttribute("class","xfaLayer xfaFont");const c=[];if(i.children.length===0){if(i.value){const g=document.createTextNode(i.value);r.append(g),o&&$h.shouldBuildText(i.name)&&c.push(g)}return{textDivs:c}}const u=[[i,-1,r]];for(;u.length>0;){const[g,p,b]=u.at(-1);if(p+1===g.children.length){u.pop();continue}const v=g.children[++u.at(-1)[1]];if(v===null)continue;const{name:_}=v;if(_==="#text"){const C=document.createTextNode(v.value);c.push(C),b.append(C);continue}const x=(d=v==null?void 0:v.attributes)!=null&&d.xmlns?document.createElementNS(v.attributes.xmlns,_):document.createElement(_);if(b.append(x),v.attributes&&this.setAttributes({html:x,element:v,storage:e,intent:n,linkService:s}),((f=v.children)==null?void 0:f.length)>0)u.push([v,-1,x]);else if(v.value){const C=document.createTextNode(v.value);o&&$h.shouldBuildText(_)&&c.push(C),x.append(C)}}for(const g of h.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea"))g.setAttribute("readOnly",!0);return{textDivs:c}}static update(t){const e=`matrix(${t.viewport.transform.join(",")})`;t.div.style.transform=e,t.div.hidden=!1}}const Qh=1e3,SS=9,Pr=new WeakSet;function Fn(a){return{width:a[2]-a[0],height:a[3]-a[1]}}class CS{static create(t){switch(t.data.annotationType){case qt.LINK:return new Db(t);case qt.TEXT:return new AS(t);case qt.WIDGET:switch(t.data.fieldType){case"Tx":return new TS(t);case"Btn":return t.data.radioButton?new Ob(t):t.data.checkBox?new kS(t):new MS(t);case"Ch":return new PS(t);case"Sig":return new ES(t)}return new Dr(t);case qt.POPUP:return new Dg(t);case qt.FREETEXT:return new Rb(t);case qt.LINE:return new OS(t);case qt.SQUARE:return new RS(t);case qt.CIRCLE:return new LS(t);case qt.POLYLINE:return new Lb(t);case qt.CARET:return new IS(t);case qt.INK:return new Og(t);case qt.POLYGON:return new FS(t);case qt.HIGHLIGHT:return new Fb(t);case qt.UNDERLINE:return new NS(t);case qt.SQUIGGLY:return new jS(t);case qt.STRIKEOUT:return new BS(t);case qt.STAMP:return new Ib(t);case qt.FILEATTACHMENT:return new HS(t);default:return new jt(t)}}}const Wg=class Wg{constructor(t,{isRenderable:e=!1,ignoreBorder:s=!1,createQuadrilaterals:i=!1}={}){y(this,zl);y(this,go,null);y(this,ja,!1);y(this,Ba,null);this.isRenderable=e,this.data=t.data,this.layer=t.layer,this.linkService=t.linkService,this.downloadManager=t.downloadManager,this.imageResourcesPath=t.imageResourcesPath,this.renderForms=t.renderForms,this.svgFactory=t.svgFactory,this.annotationStorage=t.annotationStorage,this.enableScripting=t.enableScripting,this.hasJSActions=t.hasJSActions,this._fieldObjects=t.fieldObjects,this.parent=t.parent,e&&(this.container=this._createContainer(s)),i&&this._createQuadrilaterals()}static _hasPopupData({titleObj:t,contentsObj:e,richText:s}){return!!(t!=null&&t.str||e!=null&&e.str||s!=null&&s.str)}get _isEditable(){return this.data.isEditable}get hasPopupData(){return Wg._hasPopupData(this.data)}updateEdited(t){var s;if(!this.container)return;l(this,go)||m(this,go,{rect:this.data.rect.slice(0)});const{rect:e}=t;e&&w(this,zl,_p).call(this,e),(s=l(this,Ba))==null||s.popup.updateEdited(t)}resetEdited(){var t;l(this,go)&&(w(this,zl,_p).call(this,l(this,go).rect),(t=l(this,Ba))==null||t.popup.resetEdited(),m(this,go,null))}_createContainer(t){const{data:e,parent:{page:s,viewport:i}}=this,n=document.createElement("section");n.setAttribute("data-annotation-id",e.id),this instanceof Dr||(n.tabIndex=Qh);const{style:r}=n;if(r.zIndex=this.parent.zIndex++,e.alternativeText&&(n.title=e.alternativeText),e.noRotate&&n.classList.add("norotate"),!e.rect||this instanceof Dg){const{rotation:b}=e;return!e.hasOwnCanvas&&b!==0&&this.setRotation(b,n),n}const{width:o,height:h}=Fn(e.rect);if(!t&&e.borderStyle.width>0){r.borderWidth=`${e.borderStyle.width}px`;const b=e.borderStyle.horizontalCornerRadius,v=e.borderStyle.verticalCornerRadius;if(b>0||v>0){const x=`calc(${b}px * var(--scale-factor)) / calc(${v}px * var(--scale-factor))`;r.borderRadius=x}else if(this instanceof Ob){const x=`calc(${o}px * var(--scale-factor)) / calc(${h}px * var(--scale-factor))`;r.borderRadius=x}switch(e.borderStyle.style){case Hh.SOLID:r.borderStyle="solid";break;case Hh.DASHED:r.borderStyle="dashed";break;case Hh.BEVELED:tt("Unimplemented border style: beveled");break;case Hh.INSET:tt("Unimplemented border style: inset");break;case Hh.UNDERLINE:r.borderBottomStyle="solid";break}const _=e.borderColor||null;_?(m(this,ja,!0),r.borderColor=X.makeHexColor(_[0]|0,_[1]|0,_[2]|0)):r.borderWidth=0}const c=X.normalizeRect([e.rect[0],s.view[3]-e.rect[1]+s.view[1],e.rect[2],s.view[3]-e.rect[3]+s.view[1]]),{pageWidth:u,pageHeight:d,pageX:f,pageY:g}=i.rawDims;r.left=`${100*(c[0]-f)/u}%`,r.top=`${100*(c[1]-g)/d}%`;const{rotation:p}=e;return e.hasOwnCanvas||p===0?(r.width=`${100*o/u}%`,r.height=`${100*h/d}%`):this.setRotation(p,n),n}setRotation(t,e=this.container){if(!this.data.rect)return;const{pageWidth:s,pageHeight:i}=this.parent.viewport.rawDims,{width:n,height:r}=Fn(this.data.rect);let o,h;t%180===0?(o=100*n/s,h=100*r/i):(o=100*r/s,h=100*n/i),e.style.width=`${o}%`,e.style.height=`${h}%`,e.setAttribute("data-main-rotation",(360-t)%360)}get _commonActions(){const t=(e,s,i)=>{const n=i.detail[e],r=n[0],o=n.slice(1);i.target.style[s]=Mb[`${r}_HTML`](o),this.annotationStorage.setValue(this.data.id,{[s]:Mb[`${r}_rgb`](o)})};return st(this,"_commonActions",{display:e=>{const{display:s}=e.detail,i=s%2===1;this.container.style.visibility=i?"hidden":"visible",this.annotationStorage.setValue(this.data.id,{noView:i,noPrint:s===1||s===2})},print:e=>{this.annotationStorage.setValue(this.data.id,{noPrint:!e.detail.print})},hidden:e=>{const{hidden:s}=e.detail;this.container.style.visibility=s?"hidden":"visible",this.annotationStorage.setValue(this.data.id,{noPrint:s,noView:s})},focus:e=>{setTimeout(()=>e.target.focus({preventScroll:!1}),0)},userName:e=>{e.target.title=e.detail.userName},readonly:e=>{e.target.disabled=e.detail.readonly},required:e=>{this._setRequired(e.target,e.detail.required)},bgColor:e=>{t("bgColor","backgroundColor",e)},fillColor:e=>{t("fillColor","backgroundColor",e)},fgColor:e=>{t("fgColor","color",e)},textColor:e=>{t("textColor","color",e)},borderColor:e=>{t("borderColor","borderColor",e)},strokeColor:e=>{t("strokeColor","borderColor",e)},rotation:e=>{const s=e.detail.rotation;this.setRotation(s),this.annotationStorage.setValue(this.data.id,{rotation:s})}})}_dispatchEventFromSandbox(t,e){const s=this._commonActions;for(const i of Object.keys(e.detail)){const n=t[i]||s[i];n==null||n(e)}}_setDefaultPropertiesFromJS(t){if(!this.enableScripting)return;const e=this.annotationStorage.getRawValue(this.data.id);if(!e)return;const s=this._commonActions;for(const[i,n]of Object.entries(e)){const r=s[i];if(r){const o={detail:{[i]:n},target:t};r(o),delete e[i]}}}_createQuadrilaterals(){if(!this.container)return;const{quadPoints:t}=this.data;if(!t)return;const[e,s,i,n]=this.data.rect.map(b=>Math.fround(b));if(t.length===8){const[b,v,_,x]=t.subarray(2,6);if(i===b&&n===v&&e===_&&s===x)return}const{style:r}=this.container;let o;if(l(this,ja)){const{borderColor:b,borderWidth:v}=r;r.borderWidth=0,o=["url('data:image/svg+xml;utf8,",'<svg xmlns="http://www.w3.org/2000/svg"',' preserveAspectRatio="none" viewBox="0 0 1 1">',`<g fill="transparent" stroke="${b}" stroke-width="${v}">`],this.container.classList.add("hasBorder")}const h=i-e,c=n-s,{svgFactory:u}=this,d=u.createElement("svg");d.classList.add("quadrilateralsContainer"),d.setAttribute("width",0),d.setAttribute("height",0);const f=u.createElement("defs");d.append(f);const g=u.createElement("clipPath"),p=`clippath_${this.data.id}`;g.setAttribute("id",p),g.setAttribute("clipPathUnits","objectBoundingBox"),f.append(g);for(let b=2,v=t.length;b<v;b+=8){const _=t[b],x=t[b+1],C=t[b+2],S=t[b+3],k=u.createElement("rect"),D=(C-e)/h,T=(n-x)/c,M=(_-C)/h,O=(x-S)/c;k.setAttribute("x",D),k.setAttribute("y",T),k.setAttribute("width",M),k.setAttribute("height",O),g.append(k),o==null||o.push(`<rect vector-effect="non-scaling-stroke" x="${D}" y="${T}" width="${M}" height="${O}"/>`)}l(this,ja)&&(o.push("</g></svg>')"),r.backgroundImage=o.join("")),this.container.append(d),this.container.style.clipPath=`url(#${p})`}_createPopup(){const{data:t}=this,e=m(this,Ba,new Dg({data:{color:t.color,titleObj:t.titleObj,modificationDate:t.modificationDate,contentsObj:t.contentsObj,richText:t.richText,parentRect:t.rect,borderStyle:0,id:`popup_${t.id}`,rotation:t.rotation},parent:this.parent,elements:[this]}));this.parent.div.append(e.render())}render(){vt("Abstract method `AnnotationElement.render` called")}_getElementsByName(t,e=null){const s=[];if(this._fieldObjects){const i=this._fieldObjects[t];if(i)for(const{page:n,id:r,exportValues:o}of i){if(n===-1||r===e)continue;const h=typeof o=="string"?o:null,c=document.querySelector(`[data-element-id="${r}"]`);if(c&&!Pr.has(c)){tt(`_getElementsByName - element not allowed: ${r}`);continue}s.push({id:r,exportValue:h,domElement:c})}return s}for(const i of document.getElementsByName(t)){const{exportValue:n}=i,r=i.getAttribute("data-element-id");r!==e&&Pr.has(i)&&s.push({id:r,exportValue:n,domElement:i})}return s}show(){var t;this.container&&(this.container.hidden=!1),(t=this.popup)==null||t.maybeShow()}hide(){var t;this.container&&(this.container.hidden=!0),(t=this.popup)==null||t.forceHide()}getElementsToTriggerPopup(){return this.container}addHighlightArea(){const t=this.getElementsToTriggerPopup();if(Array.isArray(t))for(const e of t)e.classList.add("highlightArea");else t.classList.add("highlightArea")}_editOnDoubleClick(){if(!this._isEditable)return;const{annotationEditorType:t,data:{id:e}}=this;this.container.addEventListener("dblclick",()=>{var s;(s=this.linkService.eventBus)==null||s.dispatch("switchannotationeditormode",{source:this,mode:t,editId:e})})}};go=new WeakMap,ja=new WeakMap,Ba=new WeakMap,zl=new WeakSet,_p=function(t){const{container:{style:e},data:{rect:s,rotation:i},parent:{viewport:{rawDims:{pageWidth:n,pageHeight:r,pageX:o,pageY:h}}}}=this;s==null||s.splice(0,4,...t);const{width:c,height:u}=Fn(t);e.left=`${100*(t[0]-o)/n}%`,e.top=`${100*(r-t[3]+h)/r}%`,i===0?(e.width=`${100*c/n}%`,e.height=`${100*u/r}%`):this.setRotation(i)};let jt=Wg;class Db extends jt{constructor(e,s=null){super(e,{isRenderable:!0,ignoreBorder:!!(s!=null&&s.ignoreBorder),createQuadrilaterals:!0});y(this,as);this.isTooltipOnly=e.data.isTooltipOnly}render(){const{data:e,linkService:s}=this,i=document.createElement("a");i.setAttribute("data-element-id",e.id);let n=!1;return e.url?(s.addLinkAttributes(i,e.url,e.newWindow),n=!0):e.action?(this._bindNamedAction(i,e.action),n=!0):e.attachment?(w(this,as,Oy).call(this,i,e.attachment,e.attachmentDest),n=!0):e.setOCGState?(w(this,as,Ry).call(this,i,e.setOCGState),n=!0):e.dest?(this._bindLink(i,e.dest),n=!0):(e.actions&&(e.actions.Action||e.actions["Mouse Up"]||e.actions["Mouse Down"])&&this.enableScripting&&this.hasJSActions&&(this._bindJSAction(i,e),n=!0),e.resetForm?(this._bindResetFormAction(i,e.resetForm),n=!0):this.isTooltipOnly&&!n&&(this._bindLink(i,""),n=!0)),this.container.classList.add("linkAnnotation"),n&&this.container.append(i),this.container}_bindLink(e,s){e.href=this.linkService.getDestinationHash(s),e.onclick=()=>(s&&this.linkService.goToDestination(s),!1),(s||s==="")&&w(this,as,Ho).call(this)}_bindNamedAction(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeNamedAction(s),!1),w(this,as,Ho).call(this)}_bindJSAction(e,s){e.href=this.linkService.getAnchorUrl("");const i=new Map([["Action","onclick"],["Mouse Up","onmouseup"],["Mouse Down","onmousedown"]]);for(const n of Object.keys(s.actions)){const r=i.get(n);r&&(e[r]=()=>{var o;return(o=this.linkService.eventBus)==null||o.dispatch("dispatcheventinsandbox",{source:this,detail:{id:s.id,name:n}}),!1})}e.onclick||(e.onclick=()=>!1),w(this,as,Ho).call(this)}_bindResetFormAction(e,s){const i=e.onclick;if(i||(e.href=this.linkService.getAnchorUrl("")),w(this,as,Ho).call(this),!this._fieldObjects){tt('_bindResetFormAction - "resetForm" action not supported, ensure that the `fieldObjects` parameter is provided.'),i||(e.onclick=()=>!1);return}e.onclick=()=>{var d;i==null||i();const{fields:n,refs:r,include:o}=s,h=[];if(n.length!==0||r.length!==0){const f=new Set(r);for(const g of n){const p=this._fieldObjects[g]||[];for(const{id:b}of p)f.add(b)}for(const g of Object.values(this._fieldObjects))for(const p of g)f.has(p.id)===o&&h.push(p)}else for(const f of Object.values(this._fieldObjects))h.push(...f);const c=this.annotationStorage,u=[];for(const f of h){const{id:g}=f;switch(u.push(g),f.type){case"text":{const b=f.defaultValue||"";c.setValue(g,{value:b});break}case"checkbox":case"radiobutton":{const b=f.defaultValue===f.exportValues;c.setValue(g,{value:b});break}case"combobox":case"listbox":{const b=f.defaultValue||"";c.setValue(g,{value:b});break}default:continue}const p=document.querySelector(`[data-element-id="${g}"]`);if(p){if(!Pr.has(p)){tt(`_bindResetFormAction - element not allowed: ${g}`);continue}}else continue;p.dispatchEvent(new Event("resetform"))}return this.enableScripting&&((d=this.linkService.eventBus)==null||d.dispatch("dispatcheventinsandbox",{source:this,detail:{id:"app",ids:u,name:"ResetForm"}})),!1}}}as=new WeakSet,Ho=function(){this.container.setAttribute("data-internal-link","")},Oy=function(e,s,i=null){e.href=this.linkService.getAnchorUrl(""),s.description&&(e.title=s.description),e.onclick=()=>{var n;return(n=this.downloadManager)==null||n.openOrDownloadData(s.content,s.filename,i),!1},w(this,as,Ho).call(this)},Ry=function(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeSetOCGState(s),!1),w(this,as,Ho).call(this)};class AS extends jt{constructor(t){super(t,{isRenderable:!0})}render(){this.container.classList.add("textAnnotation");const t=document.createElement("img");return t.src=this.imageResourcesPath+"annotation-"+this.data.name.toLowerCase()+".svg",t.setAttribute("data-l10n-id","pdfjs-text-annotation-type"),t.setAttribute("data-l10n-args",JSON.stringify({type:this.data.name})),!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.append(t),this.container}}class Dr extends jt{render(){return this.container}showElementAndHideCanvas(t){var e;this.data.hasOwnCanvas&&(((e=t.previousSibling)==null?void 0:e.nodeName)==="CANVAS"&&(t.previousSibling.hidden=!0),t.hidden=!1)}_getKeyModifier(t){return Re.platform.isMac?t.metaKey:t.ctrlKey}_setEventListener(t,e,s,i,n){s.includes("mouse")?t.addEventListener(s,r=>{var o;(o=this.linkService.eventBus)==null||o.dispatch("dispatcheventinsandbox",{source:this,detail:{id:this.data.id,name:i,value:n(r),shift:r.shiftKey,modifier:this._getKeyModifier(r)}})}):t.addEventListener(s,r=>{var o;if(s==="blur"){if(!e.focused||!r.relatedTarget)return;e.focused=!1}else if(s==="focus"){if(e.focused)return;e.focused=!0}n&&((o=this.linkService.eventBus)==null||o.dispatch("dispatcheventinsandbox",{source:this,detail:{id:this.data.id,name:i,value:n(r)}}))})}_setEventListeners(t,e,s,i){var n,r,o;for(const[h,c]of s)(c==="Action"||(n=this.data.actions)!=null&&n[c])&&((c==="Focus"||c==="Blur")&&(e||(e={focused:!1})),this._setEventListener(t,e,h,c,i),c==="Focus"&&!((r=this.data.actions)!=null&&r.Blur)?this._setEventListener(t,e,"blur","Blur",null):c==="Blur"&&!((o=this.data.actions)!=null&&o.Focus)&&this._setEventListener(t,e,"focus","Focus",null))}_setBackgroundColor(t){const e=this.data.backgroundColor||null;t.style.backgroundColor=e===null?"transparent":X.makeHexColor(e[0],e[1],e[2])}_setTextStyle(t){const e=["left","center","right"],{fontColor:s}=this.data.defaultAppearanceData,i=this.data.defaultAppearanceData.fontSize||SS,n=t.style;let r;const o=2,h=c=>Math.round(10*c)/10;if(this.data.multiLine){const c=Math.abs(this.data.rect[3]-this.data.rect[1]-o),u=Math.round(c/(rg*i))||1,d=c/u;r=Math.min(i,h(d/rg))}else{const c=Math.abs(this.data.rect[3]-this.data.rect[1]-o);r=Math.min(i,h(c/rg))}n.fontSize=`calc(${r}px * var(--scale-factor))`,n.color=X.makeHexColor(s[0],s[1],s[2]),this.data.textAlignment!==null&&(n.textAlign=e[this.data.textAlignment])}_setRequired(t,e){e?t.setAttribute("required",!0):t.removeAttribute("required"),t.setAttribute("aria-required",e)}}class TS extends Dr{constructor(t){const e=t.renderForms||t.data.hasOwnCanvas||!t.data.hasAppearance&&!!t.data.fieldValue;super(t,{isRenderable:e})}setPropertyOnSiblings(t,e,s,i){const n=this.annotationStorage;for(const r of this._getElementsByName(t.name,t.id))r.domElement&&(r.domElement[e]=s),n.setValue(r.id,{[i]:s})}render(){var i,n;const t=this.annotationStorage,e=this.data.id;this.container.classList.add("textWidgetAnnotation");let s=null;if(this.renderForms){const r=t.getValue(e,{value:this.data.fieldValue});let o=r.value||"";const h=t.getValue(e,{charLimit:this.data.maxLen}).charLimit;h&&o.length>h&&(o=o.slice(0,h));let c=r.formattedValue||((i=this.data.textContent)==null?void 0:i.join(`
500
- `))||null;c&&this.data.comb&&(c=c.replaceAll(/\s+/g,""));const u={userValue:o,formattedValue:c,lastCommittedValue:null,commitKey:1,focused:!1};this.data.multiLine?(s=document.createElement("textarea"),s.textContent=c??o,this.data.doNotScroll&&(s.style.overflowY="hidden")):(s=document.createElement("input"),s.type="text",s.setAttribute("value",c??o),this.data.doNotScroll&&(s.style.overflowX="hidden")),this.data.hasOwnCanvas&&(s.hidden=!0),Pr.add(s),s.setAttribute("data-element-id",e),s.disabled=this.data.readOnly,s.name=this.data.fieldName,s.tabIndex=Qh,this._setRequired(s,this.data.required),h&&(s.maxLength=h),s.addEventListener("input",f=>{t.setValue(e,{value:f.target.value}),this.setPropertyOnSiblings(s,"value",f.target.value,"value"),u.formattedValue=null}),s.addEventListener("resetform",f=>{const g=this.data.defaultFieldValue??"";s.value=u.userValue=g,u.formattedValue=null});let d=f=>{const{formattedValue:g}=u;g!=null&&(f.target.value=g),f.target.scrollLeft=0};if(this.enableScripting&&this.hasJSActions){s.addEventListener("focus",g=>{var b;if(u.focused)return;const{target:p}=g;u.userValue&&(p.value=u.userValue),u.lastCommittedValue=p.value,u.commitKey=1,(b=this.data.actions)!=null&&b.Focus||(u.focused=!0)}),s.addEventListener("updatefromsandbox",g=>{this.showElementAndHideCanvas(g.target);const p={value(b){u.userValue=b.detail.value??"",t.setValue(e,{value:u.userValue.toString()}),b.target.value=u.userValue},formattedValue(b){const{formattedValue:v}=b.detail;u.formattedValue=v,v!=null&&b.target!==document.activeElement&&(b.target.value=v),t.setValue(e,{formattedValue:v})},selRange(b){b.target.setSelectionRange(...b.detail.selRange)},charLimit:b=>{var C;const{charLimit:v}=b.detail,{target:_}=b;if(v===0){_.removeAttribute("maxLength");return}_.setAttribute("maxLength",v);let x=u.userValue;!x||x.length<=v||(x=x.slice(0,v),_.value=u.userValue=x,t.setValue(e,{value:x}),(C=this.linkService.eventBus)==null||C.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:x,willCommit:!0,commitKey:1,selStart:_.selectionStart,selEnd:_.selectionEnd}}))}};this._dispatchEventFromSandbox(p,g)}),s.addEventListener("keydown",g=>{var v;u.commitKey=1;let p=-1;if(g.key==="Escape"?p=0:g.key==="Enter"&&!this.data.multiLine?p=2:g.key==="Tab"&&(u.commitKey=3),p===-1)return;const{value:b}=g.target;u.lastCommittedValue!==b&&(u.lastCommittedValue=b,u.userValue=b,(v=this.linkService.eventBus)==null||v.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:b,willCommit:!0,commitKey:p,selStart:g.target.selectionStart,selEnd:g.target.selectionEnd}}))});const f=d;d=null,s.addEventListener("blur",g=>{var b,v;if(!u.focused||!g.relatedTarget)return;(b=this.data.actions)!=null&&b.Blur||(u.focused=!1);const{value:p}=g.target;u.userValue=p,u.lastCommittedValue!==p&&((v=this.linkService.eventBus)==null||v.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:p,willCommit:!0,commitKey:u.commitKey,selStart:g.target.selectionStart,selEnd:g.target.selectionEnd}})),f(g)}),(n=this.data.actions)!=null&&n.Keystroke&&s.addEventListener("beforeinput",g=>{var k;u.lastCommittedValue=null;const{data:p,target:b}=g,{value:v,selectionStart:_,selectionEnd:x}=b;let C=_,S=x;switch(g.inputType){case"deleteWordBackward":{const D=v.substring(0,_).match(/\w*[^\w]*$/);D&&(C-=D[0].length);break}case"deleteWordForward":{const D=v.substring(_).match(/^[^\w]*\w*/);D&&(S+=D[0].length);break}case"deleteContentBackward":_===x&&(C-=1);break;case"deleteContentForward":_===x&&(S+=1);break}g.preventDefault(),(k=this.linkService.eventBus)==null||k.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:v,change:p||"",willCommit:!1,selStart:C,selEnd:S}})}),this._setEventListeners(s,u,[["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],g=>g.target.value)}if(d&&s.addEventListener("blur",d),this.data.comb){const g=(this.data.rect[2]-this.data.rect[0])/h;s.classList.add("comb"),s.style.letterSpacing=`calc(${g}px * var(--scale-factor) - 1ch)`}}else s=document.createElement("div"),s.textContent=this.data.fieldValue,s.style.verticalAlign="middle",s.style.display="table-cell",this.data.hasOwnCanvas&&(s.hidden=!0);return this._setTextStyle(s),this._setBackgroundColor(s),this._setDefaultPropertiesFromJS(s),this.container.append(s),this.container}}class ES extends Dr{constructor(t){super(t,{isRenderable:!!t.data.hasOwnCanvas})}}class kS extends Dr{constructor(t){super(t,{isRenderable:t.renderForms})}render(){const t=this.annotationStorage,e=this.data,s=e.id;let i=t.getValue(s,{value:e.exportValue===e.fieldValue}).value;typeof i=="string"&&(i=i!=="Off",t.setValue(s,{value:i})),this.container.classList.add("buttonWidgetAnnotation","checkBox");const n=document.createElement("input");return Pr.add(n),n.setAttribute("data-element-id",s),n.disabled=e.readOnly,this._setRequired(n,this.data.required),n.type="checkbox",n.name=e.fieldName,i&&n.setAttribute("checked",!0),n.setAttribute("exportValue",e.exportValue),n.tabIndex=Qh,n.addEventListener("change",r=>{const{name:o,checked:h}=r.target;for(const c of this._getElementsByName(o,s)){const u=h&&c.exportValue===e.exportValue;c.domElement&&(c.domElement.checked=u),t.setValue(c.id,{value:u})}t.setValue(s,{value:h})}),n.addEventListener("resetform",r=>{const o=e.defaultFieldValue||"Off";r.target.checked=o===e.exportValue}),this.enableScripting&&this.hasJSActions&&(n.addEventListener("updatefromsandbox",r=>{const o={value(h){h.target.checked=h.detail.value!=="Off",t.setValue(s,{value:h.target.checked})}};this._dispatchEventFromSandbox(o,r)}),this._setEventListeners(n,null,[["change","Validate"],["change","Action"],["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],r=>r.target.checked)),this._setBackgroundColor(n),this._setDefaultPropertiesFromJS(n),this.container.append(n),this.container}}class Ob extends Dr{constructor(t){super(t,{isRenderable:t.renderForms})}render(){this.container.classList.add("buttonWidgetAnnotation","radioButton");const t=this.annotationStorage,e=this.data,s=e.id;let i=t.getValue(s,{value:e.fieldValue===e.buttonValue}).value;if(typeof i=="string"&&(i=i!==e.buttonValue,t.setValue(s,{value:i})),i)for(const r of this._getElementsByName(e.fieldName,s))t.setValue(r.id,{value:!1});const n=document.createElement("input");if(Pr.add(n),n.setAttribute("data-element-id",s),n.disabled=e.readOnly,this._setRequired(n,this.data.required),n.type="radio",n.name=e.fieldName,i&&n.setAttribute("checked",!0),n.tabIndex=Qh,n.addEventListener("change",r=>{const{name:o,checked:h}=r.target;for(const c of this._getElementsByName(o,s))t.setValue(c.id,{value:!1});t.setValue(s,{value:h})}),n.addEventListener("resetform",r=>{const o=e.defaultFieldValue;r.target.checked=o!=null&&o===e.buttonValue}),this.enableScripting&&this.hasJSActions){const r=e.buttonValue;n.addEventListener("updatefromsandbox",o=>{const h={value:c=>{const u=r===c.detail.value;for(const d of this._getElementsByName(c.target.name)){const f=u&&d.id===s;d.domElement&&(d.domElement.checked=f),t.setValue(d.id,{value:f})}}};this._dispatchEventFromSandbox(h,o)}),this._setEventListeners(n,null,[["change","Validate"],["change","Action"],["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],o=>o.target.checked)}return this._setBackgroundColor(n),this._setDefaultPropertiesFromJS(n),this.container.append(n),this.container}}class MS extends Db{constructor(t){super(t,{ignoreBorder:t.data.hasAppearance})}render(){const t=super.render();t.classList.add("buttonWidgetAnnotation","pushButton");const e=t.lastChild;return this.enableScripting&&this.hasJSActions&&e&&(this._setDefaultPropertiesFromJS(e),e.addEventListener("updatefromsandbox",s=>{this._dispatchEventFromSandbox({},s)})),t}}class PS extends Dr{constructor(t){super(t,{isRenderable:t.renderForms})}render(){this.container.classList.add("choiceWidgetAnnotation");const t=this.annotationStorage,e=this.data.id,s=t.getValue(e,{value:this.data.fieldValue}),i=document.createElement("select");Pr.add(i),i.setAttribute("data-element-id",e),i.disabled=this.data.readOnly,this._setRequired(i,this.data.required),i.name=this.data.fieldName,i.tabIndex=Qh;let n=this.data.combo&&this.data.options.length>0;this.data.combo||(i.size=this.data.options.length,this.data.multiSelect&&(i.multiple=!0)),i.addEventListener("resetform",u=>{const d=this.data.defaultFieldValue;for(const f of i.options)f.selected=f.value===d});for(const u of this.data.options){const d=document.createElement("option");d.textContent=u.displayValue,d.value=u.exportValue,s.value.includes(u.exportValue)&&(d.setAttribute("selected",!0),n=!1),i.append(d)}let r=null;if(n){const u=document.createElement("option");u.value=" ",u.setAttribute("hidden",!0),u.setAttribute("selected",!0),i.prepend(u),r=()=>{u.remove(),i.removeEventListener("input",r),r=null},i.addEventListener("input",r)}const o=u=>{const d=u?"value":"textContent",{options:f,multiple:g}=i;return g?Array.prototype.filter.call(f,p=>p.selected).map(p=>p[d]):f.selectedIndex===-1?null:f[f.selectedIndex][d]};let h=o(!1);const c=u=>{const d=u.target.options;return Array.prototype.map.call(d,f=>({displayValue:f.textContent,exportValue:f.value}))};return this.enableScripting&&this.hasJSActions?(i.addEventListener("updatefromsandbox",u=>{const d={value(f){r==null||r();const g=f.detail.value,p=new Set(Array.isArray(g)?g:[g]);for(const b of i.options)b.selected=p.has(b.value);t.setValue(e,{value:o(!0)}),h=o(!1)},multipleSelection(f){i.multiple=!0},remove(f){const g=i.options,p=f.detail.remove;g[p].selected=!1,i.remove(p),g.length>0&&Array.prototype.findIndex.call(g,v=>v.selected)===-1&&(g[0].selected=!0),t.setValue(e,{value:o(!0),items:c(f)}),h=o(!1)},clear(f){for(;i.length!==0;)i.remove(0);t.setValue(e,{value:null,items:[]}),h=o(!1)},insert(f){const{index:g,displayValue:p,exportValue:b}=f.detail.insert,v=i.children[g],_=document.createElement("option");_.textContent=p,_.value=b,v?v.before(_):i.append(_),t.setValue(e,{value:o(!0),items:c(f)}),h=o(!1)},items(f){const{items:g}=f.detail;for(;i.length!==0;)i.remove(0);for(const p of g){const{displayValue:b,exportValue:v}=p,_=document.createElement("option");_.textContent=b,_.value=v,i.append(_)}i.options.length>0&&(i.options[0].selected=!0),t.setValue(e,{value:o(!0),items:c(f)}),h=o(!1)},indices(f){const g=new Set(f.detail.indices);for(const p of f.target.options)p.selected=g.has(p.index);t.setValue(e,{value:o(!0)}),h=o(!1)},editable(f){f.target.disabled=!f.detail.editable}};this._dispatchEventFromSandbox(d,u)}),i.addEventListener("input",u=>{var g;const d=o(!0),f=o(!1);t.setValue(e,{value:d}),u.preventDefault(),(g=this.linkService.eventBus)==null||g.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:h,change:f,changeEx:d,willCommit:!1,commitKey:1,keyDown:!1}})}),this._setEventListeners(i,null,[["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"],["input","Action"],["input","Validate"]],u=>u.target.value)):i.addEventListener("input",function(u){t.setValue(e,{value:o(!0)})}),this.data.combo&&this._setTextStyle(i),this._setBackgroundColor(i),this._setDefaultPropertiesFromJS(i),this.container.append(i),this.container}}class Dg extends jt{constructor(t){const{data:e,elements:s}=t;super(t,{isRenderable:jt._hasPopupData(e)}),this.elements=s,this.popup=null}render(){this.container.classList.add("popupAnnotation");const t=this.popup=new DS({container:this.container,color:this.data.color,titleObj:this.data.titleObj,modificationDate:this.data.modificationDate,contentsObj:this.data.contentsObj,richText:this.data.richText,rect:this.data.rect,parentRect:this.data.parentRect||null,parent:this.parent,elements:this.elements,open:this.data.open}),e=[];for(const s of this.elements)s.popup=t,s.container.ariaHasPopup="dialog",e.push(s.data.id),s.addHighlightArea();return this.container.setAttribute("aria-controls",e.map(s=>`${ug}${s}`).join(",")),this.container}}class DS{constructor({container:t,color:e,elements:s,titleObj:i,modificationDate:n,contentsObj:r,richText:o,parent:h,rect:c,parentRect:u,open:d}){y(this,bt);y(this,Ha,w(this,bt,Iy).bind(this));y(this,vd,w(this,bt,xp).bind(this));y(this,_d,w(this,bt,Vd).bind(this));y(this,Ga,w(this,bt,zd).bind(this));y(this,po,null);y(this,Lt,null);y(this,ln,null);y(this,za,null);y(this,Vl,null);y(this,Xl,null);y(this,Va,null);y(this,cn,!1);y(this,$s,null);y(this,un,null);y(this,Wl,null);y(this,dn,null);y(this,Ul,null);y(this,mo,null);y(this,bo,!1);var f;m(this,Lt,t),m(this,Ul,i),m(this,ln,r),m(this,dn,o),m(this,Xl,h),m(this,po,e),m(this,Wl,c),m(this,Va,u),m(this,Vl,s),m(this,za,gg.toDateObject(n)),this.trigger=s.flatMap(g=>g.getElementsToTriggerPopup());for(const g of this.trigger)g.addEventListener("click",l(this,Ga)),g.addEventListener("mouseenter",l(this,_d)),g.addEventListener("mouseleave",l(this,vd)),g.classList.add("popupTriggerArea");for(const g of s)(f=g.container)==null||f.addEventListener("keydown",l(this,Ha));l(this,Lt).hidden=!0,d&&w(this,bt,zd).call(this)}render(){if(l(this,$s))return;const t=m(this,$s,document.createElement("div"));if(t.className="popup",l(this,po)){const n=t.style.outlineColor=X.makeHexColor(...l(this,po));CSS.supports("background-color","color-mix(in srgb, red 30%, white)")?t.style.backgroundColor=`color-mix(in srgb, ${n} 30%, white)`:t.style.backgroundColor=X.makeHexColor(...l(this,po).map(o=>Math.floor(.7*(255-o)+o)))}const e=document.createElement("span");e.className="header";const s=document.createElement("h1");if(e.append(s),{dir:s.dir,str:s.textContent}=l(this,Ul),t.append(e),l(this,za)){const n=document.createElement("span");n.classList.add("popupDate"),n.setAttribute("data-l10n-id","pdfjs-annotation-date-time-string"),n.setAttribute("data-l10n-args",JSON.stringify({dateObj:l(this,za).valueOf()})),e.append(n)}const i=l(this,bt,Gd);if(i)Pb.render({xfaHtml:i,intent:"richText",div:t}),t.lastChild.classList.add("richText","popupContent");else{const n=this._formatContents(l(this,ln));t.append(n)}l(this,Lt).append(t)}_formatContents({str:t,dir:e}){const s=document.createElement("p");s.classList.add("popupContent"),s.dir=e;const i=t.split(/(?:\r\n?|\n)/);for(let n=0,r=i.length;n<r;++n){const o=i[n];s.append(document.createTextNode(o)),n<r-1&&s.append(document.createElement("br"))}return s}updateEdited({rect:t,popupContent:e}){var s;l(this,mo)||m(this,mo,{contentsObj:l(this,ln),richText:l(this,dn)}),t&&m(this,un,null),e&&(m(this,dn,w(this,bt,Fy).call(this,e)),m(this,ln,null)),(s=l(this,$s))==null||s.remove(),m(this,$s,null)}resetEdited(){var t;l(this,mo)&&({contentsObj:Ge(this,ln)._,richText:Ge(this,dn)._}=l(this,mo),m(this,mo,null),(t=l(this,$s))==null||t.remove(),m(this,$s,null),m(this,un,null))}forceHide(){m(this,bo,this.isVisible),l(this,bo)&&(l(this,Lt).hidden=!0)}maybeShow(){l(this,bo)&&(l(this,$s)||w(this,bt,Vd).call(this),m(this,bo,!1),l(this,Lt).hidden=!1)}get isVisible(){return l(this,Lt).hidden===!1}}Ha=new WeakMap,vd=new WeakMap,_d=new WeakMap,Ga=new WeakMap,po=new WeakMap,Lt=new WeakMap,ln=new WeakMap,za=new WeakMap,Vl=new WeakMap,Xl=new WeakMap,Va=new WeakMap,cn=new WeakMap,$s=new WeakMap,un=new WeakMap,Wl=new WeakMap,dn=new WeakMap,Ul=new WeakMap,mo=new WeakMap,bo=new WeakMap,bt=new WeakSet,Gd=function(){const t=l(this,dn),e=l(this,ln);return t!=null&&t.str&&(!(e!=null&&e.str)||e.str===t.str)&&l(this,dn).html||null},wp=function(){var t,e,s;return((s=(e=(t=l(this,bt,Gd))==null?void 0:t.attributes)==null?void 0:e.style)==null?void 0:s.fontSize)||0},Ly=function(){var t,e,s;return((s=(e=(t=l(this,bt,Gd))==null?void 0:t.attributes)==null?void 0:e.style)==null?void 0:s.color)||null},Fy=function(t){const e=[],s={str:t,html:{name:"div",attributes:{dir:"auto"},children:[{name:"p",children:e}]}},i={style:{color:l(this,bt,Ly),fontSize:l(this,bt,wp)?`calc(${l(this,bt,wp)}px * var(--scale-factor))`:""}};for(const n of t.split(`
501
- `))e.push({name:"span",value:n,attributes:i});return s},Iy=function(t){t.altKey||t.shiftKey||t.ctrlKey||t.metaKey||(t.key==="Enter"||t.key==="Escape"&&l(this,cn))&&w(this,bt,zd).call(this)},Ny=function(){if(l(this,un)!==null)return;const{page:{view:t},viewport:{rawDims:{pageWidth:e,pageHeight:s,pageX:i,pageY:n}}}=l(this,Xl);let r=!!l(this,Va),o=r?l(this,Va):l(this,Wl);for(const p of l(this,Vl))if(!o||X.intersect(p.data.rect,o)!==null){o=p.data.rect,r=!0;break}const h=X.normalizeRect([o[0],t[3]-o[1]+t[1],o[2],t[3]-o[3]+t[1]]),u=r?o[2]-o[0]+5:0,d=h[0]+u,f=h[1];m(this,un,[100*(d-i)/e,100*(f-n)/s]);const{style:g}=l(this,Lt);g.left=`${l(this,un)[0]}%`,g.top=`${l(this,un)[1]}%`},zd=function(){m(this,cn,!l(this,cn)),l(this,cn)?(w(this,bt,Vd).call(this),l(this,Lt).addEventListener("click",l(this,Ga)),l(this,Lt).addEventListener("keydown",l(this,Ha))):(w(this,bt,xp).call(this),l(this,Lt).removeEventListener("click",l(this,Ga)),l(this,Lt).removeEventListener("keydown",l(this,Ha)))},Vd=function(){l(this,$s)||this.render(),this.isVisible?l(this,cn)&&l(this,Lt).classList.add("focused"):(w(this,bt,Ny).call(this),l(this,Lt).hidden=!1,l(this,Lt).style.zIndex=parseInt(l(this,Lt).style.zIndex)+1e3)},xp=function(){l(this,Lt).classList.remove("focused"),!(l(this,cn)||!this.isVisible)&&(l(this,Lt).hidden=!0,l(this,Lt).style.zIndex=parseInt(l(this,Lt).style.zIndex)-1e3)};class Rb extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.textContent=t.data.textContent,this.textPosition=t.data.textPosition,this.annotationEditorType=Z.FREETEXT}render(){if(this.container.classList.add("freeTextAnnotation"),this.textContent){const t=document.createElement("div");t.classList.add("annotationTextContent"),t.setAttribute("role","comment");for(const e of this.textContent){const s=document.createElement("span");s.textContent=e,t.append(s)}this.container.append(t)}return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this._editOnDoubleClick(),this.container}}class OS extends jt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});y(this,Yl,null)}render(){this.container.classList.add("lineAnnotation");const e=this.data,{width:s,height:i}=Fn(e.rect),n=this.svgFactory.create(s,i,!0),r=m(this,Yl,this.svgFactory.createElement("svg:line"));return r.setAttribute("x1",e.rect[2]-e.lineCoordinates[0]),r.setAttribute("y1",e.rect[3]-e.lineCoordinates[1]),r.setAttribute("x2",e.rect[2]-e.lineCoordinates[2]),r.setAttribute("y2",e.rect[3]-e.lineCoordinates[3]),r.setAttribute("stroke-width",e.borderStyle.width||1),r.setAttribute("stroke","transparent"),r.setAttribute("fill","transparent"),n.append(r),this.container.append(n),!e.popupRef&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return l(this,Yl)}addHighlightArea(){this.container.classList.add("highlightArea")}}Yl=new WeakMap;class RS extends jt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});y(this,$l,null)}render(){this.container.classList.add("squareAnnotation");const e=this.data,{width:s,height:i}=Fn(e.rect),n=this.svgFactory.create(s,i,!0),r=e.borderStyle.width,o=m(this,$l,this.svgFactory.createElement("svg:rect"));return o.setAttribute("x",r/2),o.setAttribute("y",r/2),o.setAttribute("width",s-r),o.setAttribute("height",i-r),o.setAttribute("stroke-width",r||1),o.setAttribute("stroke","transparent"),o.setAttribute("fill","transparent"),n.append(o),this.container.append(n),!e.popupRef&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return l(this,$l)}addHighlightArea(){this.container.classList.add("highlightArea")}}$l=new WeakMap;class LS extends jt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});y(this,ql,null)}render(){this.container.classList.add("circleAnnotation");const e=this.data,{width:s,height:i}=Fn(e.rect),n=this.svgFactory.create(s,i,!0),r=e.borderStyle.width,o=m(this,ql,this.svgFactory.createElement("svg:ellipse"));return o.setAttribute("cx",s/2),o.setAttribute("cy",i/2),o.setAttribute("rx",s/2-r/2),o.setAttribute("ry",i/2-r/2),o.setAttribute("stroke-width",r||1),o.setAttribute("stroke","transparent"),o.setAttribute("fill","transparent"),n.append(o),this.container.append(n),!e.popupRef&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return l(this,ql)}addHighlightArea(){this.container.classList.add("highlightArea")}}ql=new WeakMap;class Lb extends jt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});y(this,Kl,null);this.containerClassName="polylineAnnotation",this.svgElementName="svg:polyline"}render(){this.container.classList.add(this.containerClassName);const{data:{rect:e,vertices:s,borderStyle:i,popupRef:n}}=this;if(!s)return this.container;const{width:r,height:o}=Fn(e),h=this.svgFactory.create(r,o,!0);let c=[];for(let d=0,f=s.length;d<f;d+=2){const g=s[d]-e[0],p=e[3]-s[d+1];c.push(`${g},${p}`)}c=c.join(" ");const u=m(this,Kl,this.svgFactory.createElement(this.svgElementName));return u.setAttribute("points",c),u.setAttribute("stroke-width",i.width||1),u.setAttribute("stroke","transparent"),u.setAttribute("fill","transparent"),h.append(u),this.container.append(h),!n&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return l(this,Kl)}addHighlightArea(){this.container.classList.add("highlightArea")}}Kl=new WeakMap;class FS extends Lb{constructor(t){super(t),this.containerClassName="polygonAnnotation",this.svgElementName="svg:polygon"}}class IS extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){return this.container.classList.add("caretAnnotation"),!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container}}class Og extends jt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});y(this,Jl);y(this,Ql,null);y(this,yo,[]);this.containerClassName="inkAnnotation",this.svgElementName="svg:polyline",this.annotationEditorType=this.data.it==="InkHighlight"?Z.HIGHLIGHT:Z.INK}render(){this.container.classList.add(this.containerClassName);const{data:{rect:e,rotation:s,inkLists:i,borderStyle:n,popupRef:r}}=this,{transform:o,width:h,height:c}=w(this,Jl,Sp).call(this,s,e),u=this.svgFactory.create(h,c,!0),d=m(this,Ql,this.svgFactory.createElement("svg:g"));u.append(d),d.setAttribute("stroke-width",n.width||1),d.setAttribute("stroke-linecap","round"),d.setAttribute("stroke-linejoin","round"),d.setAttribute("stroke-miterlimit",10),d.setAttribute("stroke","transparent"),d.setAttribute("fill","transparent"),d.setAttribute("transform",o);for(let f=0,g=i.length;f<g;f++){const p=this.svgFactory.createElement(this.svgElementName);l(this,yo).push(p),p.setAttribute("points",i[f].join(",")),d.append(p)}return!r&&this.hasPopupData&&this._createPopup(),this.container.append(u),this._editOnDoubleClick(),this.container}updateEdited(e){super.updateEdited(e);const{thickness:s,points:i,rect:n}=e,r=l(this,Ql);if(s>=0&&r.setAttribute("stroke-width",s||1),i)for(let o=0,h=l(this,yo).length;o<h;o++)l(this,yo)[o].setAttribute("points",i[o].join(","));if(n){const{transform:o,width:h,height:c}=w(this,Jl,Sp).call(this,this.data.rotation,n);r.parentElement.setAttribute("viewBox",`0 0 ${h} ${c}`),r.setAttribute("transform",o)}}getElementsToTriggerPopup(){return l(this,yo)}addHighlightArea(){this.container.classList.add("highlightArea")}}Ql=new WeakMap,yo=new WeakMap,Jl=new WeakSet,Sp=function(e,s){switch(e){case 90:return{transform:`rotate(90) translate(${-s[0]},${s[1]}) scale(1,-1)`,width:s[3]-s[1],height:s[2]-s[0]};case 180:return{transform:`rotate(180) translate(${-s[2]},${s[1]}) scale(1,-1)`,width:s[2]-s[0],height:s[3]-s[1]};case 270:return{transform:`rotate(270) translate(${-s[2]},${s[3]}) scale(1,-1)`,width:s[3]-s[1],height:s[2]-s[0]};default:return{transform:`translate(${-s[0]},${s[3]}) scale(1,-1)`,width:s[2]-s[0],height:s[3]-s[1]}}};class Fb extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0}),this.annotationEditorType=Z.HIGHLIGHT}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("highlightAnnotation"),this._editOnDoubleClick(),this.container}}class NS extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("underlineAnnotation"),this.container}}class jS extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("squigglyAnnotation"),this.container}}class BS extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("strikeoutAnnotation"),this.container}}class Ib extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.annotationEditorType=Z.STAMP}render(){return this.container.classList.add("stampAnnotation"),this.container.setAttribute("role","img"),!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this._editOnDoubleClick(),this.container}}class HS extends jt{constructor(e){var i;super(e,{isRenderable:!0});y(this,tc);y(this,Zl,null);const{file:s}=this.data;this.filename=s.filename,this.content=s.content,(i=this.linkService.eventBus)==null||i.dispatch("fileattachmentannotation",{source:this,...s})}render(){this.container.classList.add("fileAttachmentAnnotation");const{container:e,data:s}=this;let i;s.hasAppearance||s.fillAlpha===0?i=document.createElement("div"):(i=document.createElement("img"),i.src=`${this.imageResourcesPath}annotation-${/paperclip/i.test(s.name)?"paperclip":"pushpin"}.svg`,s.fillAlpha&&s.fillAlpha<1&&(i.style=`filter: opacity(${Math.round(s.fillAlpha*100)}%);`)),i.addEventListener("dblclick",w(this,tc,Cp).bind(this)),m(this,Zl,i);const{isMac:n}=Re.platform;return e.addEventListener("keydown",r=>{r.key==="Enter"&&(n?r.metaKey:r.ctrlKey)&&w(this,tc,Cp).call(this)}),!s.popupRef&&this.hasPopupData?this._createPopup():i.classList.add("popupTriggerArea"),e.append(i),e}getElementsToTriggerPopup(){return l(this,Zl)}addHighlightArea(){this.container.classList.add("highlightArea")}}Zl=new WeakMap,tc=new WeakSet,Cp=function(){var e;(e=this.downloadManager)==null||e.openOrDownloadData(this.content,this.filename)};class GS{constructor({div:t,accessibilityManager:e,annotationCanvasMap:s,annotationEditorUIManager:i,page:n,viewport:r,structTreeLayer:o}){y(this,wo);y(this,ec,null);y(this,vo,null);y(this,_o,new Map);y(this,sc,null);this.div=t,m(this,ec,e),m(this,vo,s),m(this,sc,o||null),this.page=n,this.viewport=r,this.zIndex=0,this._annotationEditorUIManager=i}hasEditableAnnotations(){return l(this,_o).size>0}async render(t){var r;const{annotations:e}=t,s=this.div;kr(s,this.viewport);const i=new Map,n={data:null,layer:s,linkService:t.linkService,downloadManager:t.downloadManager,imageResourcesPath:t.imageResourcesPath||"",renderForms:t.renderForms!==!1,svgFactory:new Pg,annotationStorage:t.annotationStorage||new wg,enableScripting:t.enableScripting===!0,hasJSActions:t.hasJSActions,fieldObjects:t.fieldObjects,parent:this,elements:null};for(const o of e){if(o.noHTML)continue;const h=o.annotationType===qt.POPUP;if(h){const d=i.get(o.id);if(!d)continue;n.elements=d}else{const{width:d,height:f}=Fn(o.rect);if(d<=0||f<=0)continue}n.data=o;const c=CS.create(n);if(!c.isRenderable)continue;if(!h&&o.popupRef){const d=i.get(o.popupRef);d?d.push(c):i.set(o.popupRef,[c])}const u=c.render();o.hidden&&(u.style.visibility="hidden"),await w(this,wo,jy).call(this,u,o.id),c._isEditable&&(l(this,_o).set(c.data.id,c),(r=this._annotationEditorUIManager)==null||r.renderAnnotationElement(c))}w(this,wo,Ap).call(this)}update({viewport:t}){const e=this.div;this.viewport=t,kr(e,{rotation:t.rotation}),w(this,wo,Ap).call(this),e.hidden=!1}getEditableAnnotations(){return Array.from(l(this,_o).values())}getEditableAnnotation(t){return l(this,_o).get(t)}}ec=new WeakMap,vo=new WeakMap,_o=new WeakMap,sc=new WeakMap,wo=new WeakSet,jy=async function(t,e){var r,o;const s=t.firstChild||t,i=s.id=`${ug}${e}`,n=await((r=l(this,sc))==null?void 0:r.getAriaAttributes(i));if(n)for(const[h,c]of n)s.setAttribute(h,c);this.div.append(t),(o=l(this,ec))==null||o.moveElementInDOM(this.div,t,s,!1)},Ap=function(){if(!l(this,vo))return;const t=this.div;for(const[e,s]of l(this,vo)){const i=t.querySelector(`[data-annotation-id="${e}"]`);if(!i)continue;s.className="annotationContent";const{firstChild:n}=i;n?n.nodeName==="CANVAS"?n.replaceWith(s):n.classList.contains("annotationContent")?n.after(s):n.before(s):i.append(s)}l(this,vo).clear()};const sd=/\r\n?|\n/g,wt=class wt extends Pt{constructor(e){super({...e,name:"freeTextEditor"});y(this,Ut);y(this,qs);y(this,hs,"");y(this,ic,`${this.id}-editor`);y(this,xo,null);y(this,ls);m(this,qs,e.color||wt._defaultColor||Pt._defaultLineColor),m(this,ls,e.fontSize||wt._defaultFontSize)}static get _keyboardManager(){const e=wt.prototype,s=r=>r.isEmpty(),i=Mr.TRANSLATE_SMALL,n=Mr.TRANSLATE_BIG;return st(this,"_keyboardManager",new Xh([[["ctrl+s","mac+meta+s","ctrl+p","mac+meta+p"],e.commitOrRemove,{bubbles:!0}],[["ctrl+Enter","mac+meta+Enter","Escape","mac+Escape"],e.commitOrRemove],[["ArrowLeft","mac+ArrowLeft"],e._translateEmpty,{args:[-i,0],checker:s}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],e._translateEmpty,{args:[-n,0],checker:s}],[["ArrowRight","mac+ArrowRight"],e._translateEmpty,{args:[i,0],checker:s}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],e._translateEmpty,{args:[n,0],checker:s}],[["ArrowUp","mac+ArrowUp"],e._translateEmpty,{args:[0,-i],checker:s}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],e._translateEmpty,{args:[0,-n],checker:s}],[["ArrowDown","mac+ArrowDown"],e._translateEmpty,{args:[0,i],checker:s}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],e._translateEmpty,{args:[0,n],checker:s}]]))}static initialize(e,s){Pt.initialize(e,s);const i=getComputedStyle(document.documentElement);this._internalPadding=parseFloat(i.getPropertyValue("--freetext-padding"))}static updateDefaultParams(e,s){switch(e){case ot.FREETEXT_SIZE:wt._defaultFontSize=s;break;case ot.FREETEXT_COLOR:wt._defaultColor=s;break}}updateParams(e,s){switch(e){case ot.FREETEXT_SIZE:w(this,Ut,By).call(this,s);break;case ot.FREETEXT_COLOR:w(this,Ut,Hy).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[ot.FREETEXT_SIZE,wt._defaultFontSize],[ot.FREETEXT_COLOR,wt._defaultColor||Pt._defaultLineColor]]}get propertiesToUpdate(){return[[ot.FREETEXT_SIZE,l(this,ls)],[ot.FREETEXT_COLOR,l(this,qs)]]}_translateEmpty(e,s){this._uiManager.translateSelectedEditors(e,s,!0)}getInitialTranslation(){const e=this.parentScale;return[-wt._internalPadding*e,-(wt._internalPadding+l(this,ls))*e]}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.isAttachedToDOM||this.parent.add(this)))}enableEditMode(){if(this.isInEditMode())return;this.parent.setEditingState(!1),this.parent.updateToolbar(Z.FREETEXT),super.enableEditMode(),this.overlayDiv.classList.remove("enabled"),this.editorDiv.contentEditable=!0,this._isDraggable=!1,this.div.removeAttribute("aria-activedescendant"),m(this,xo,new AbortController);const e=this._uiManager.combinedSignal(l(this,xo));this.editorDiv.addEventListener("keydown",this.editorDivKeydown.bind(this),{signal:e}),this.editorDiv.addEventListener("focus",this.editorDivFocus.bind(this),{signal:e}),this.editorDiv.addEventListener("blur",this.editorDivBlur.bind(this),{signal:e}),this.editorDiv.addEventListener("input",this.editorDivInput.bind(this),{signal:e}),this.editorDiv.addEventListener("paste",this.editorDivPaste.bind(this),{signal:e})}disableEditMode(){var e;this.isInEditMode()&&(this.parent.setEditingState(!0),super.disableEditMode(),this.overlayDiv.classList.add("enabled"),this.editorDiv.contentEditable=!1,this.div.setAttribute("aria-activedescendant",l(this,ic)),this._isDraggable=!0,(e=l(this,xo))==null||e.abort(),m(this,xo,null),this.div.focus({preventScroll:!0}),this.isEditing=!1,this.parent.div.classList.add("freetextEditing"))}focusin(e){this._focusEventsAllowed&&(super.focusin(e),e.target!==this.editorDiv&&this.editorDiv.focus())}onceAdded(e){var s;this.width||(this.enableEditMode(),e&&this.editorDiv.focus(),(s=this._initialOptions)!=null&&s.isCentered&&this.center(),this._initialOptions=null)}isEmpty(){return!this.editorDiv||this.editorDiv.innerText.trim()===""}remove(){this.isEditing=!1,this.parent&&(this.parent.setEditingState(!0),this.parent.div.classList.add("freetextEditing")),super.remove()}commit(){if(!this.isInEditMode())return;super.commit(),this.disableEditMode();const e=l(this,hs),s=m(this,hs,w(this,Ut,Gy).call(this).trimEnd());if(e===s)return;const i=n=>{if(m(this,hs,n),!n){this.remove();return}w(this,Ut,Ud).call(this),this._uiManager.rebuild(this),w(this,Ut,Xd).call(this)};this.addCommands({cmd:()=>{i(s)},undo:()=>{i(e)},mustExec:!1}),w(this,Ut,Xd).call(this)}shouldGetKeyboardEvents(){return this.isInEditMode()}enterInEditMode(){this.enableEditMode(),this.editorDiv.focus()}dblclick(e){this.enterInEditMode()}keydown(e){e.target===this.div&&e.key==="Enter"&&(this.enterInEditMode(),e.preventDefault())}editorDivKeydown(e){wt._keyboardManager.exec(this,e)}editorDivFocus(e){this.isEditing=!0}editorDivBlur(e){this.isEditing=!1}editorDivInput(e){this.parent.div.classList.toggle("freetextEditing",this.isEmpty())}disableEditing(){this.editorDiv.setAttribute("role","comment"),this.editorDiv.removeAttribute("aria-multiline")}enableEditing(){this.editorDiv.setAttribute("role","textbox"),this.editorDiv.setAttribute("aria-multiline",!0)}render(){if(this.div)return this.div;let e,s;this.width&&(e=this.x,s=this.y),super.render(),this.editorDiv=document.createElement("div"),this.editorDiv.className="internal",this.editorDiv.setAttribute("id",l(this,ic)),this.editorDiv.setAttribute("data-l10n-id","pdfjs-free-text2"),this.editorDiv.setAttribute("data-l10n-attrs","default-content"),this.enableEditing(),this.editorDiv.contentEditable=!0;const{style:i}=this.editorDiv;if(i.fontSize=`calc(${l(this,ls)}px * var(--scale-factor))`,i.color=l(this,qs),this.div.append(this.editorDiv),this.overlayDiv=document.createElement("div"),this.overlayDiv.classList.add("overlay","enabled"),this.div.append(this.overlayDiv),$u(this,this.div,["dblclick","keydown"]),this.width){const[n,r]=this.parentDimensions;if(this.annotationElementId){const{position:o}=this._initialData;let[h,c]=this.getInitialTranslation();[h,c]=this.pageTranslationToScreen(h,c);const[u,d]=this.pageDimensions,[f,g]=this.pageTranslation;let p,b;switch(this.rotation){case 0:p=e+(o[0]-f)/u,b=s+this.height-(o[1]-g)/d;break;case 90:p=e+(o[0]-f)/u,b=s-(o[1]-g)/d,[h,c]=[c,-h];break;case 180:p=e-this.width+(o[0]-f)/u,b=s-(o[1]-g)/d,[h,c]=[-h,-c];break;case 270:p=e+(o[0]-f-this.height*d)/u,b=s+(o[1]-g-this.width*u)/d,[h,c]=[-c,h];break}this.setAt(p*n,b*r,h,c)}else this.setAt(e*n,s*r,this.width*n,this.height*r);w(this,Ut,Ud).call(this),this._isDraggable=!0,this.editorDiv.contentEditable=!1}else this._isDraggable=!1,this.editorDiv.contentEditable=!0;return this.div}editorDivPaste(e){var p,b,v;const s=e.clipboardData||window.clipboardData,{types:i}=s;if(i.length===1&&i[0]==="text/plain")return;e.preventDefault();const n=w(p=wt,fn,Tp).call(p,s.getData("text")||"").replaceAll(sd,`
498
+ `}applyTo2d(t){let{imageData:{data:e}}=t;const s=-this.vibrance;for(let i=0;i<e.length;i+=4){const n=e[i],r=e[i+1],o=e[i+2],h=Math.max(n,r,o),c=(n+r+o)/3,u=2*Math.abs(h-c)/255*s;e[i]+=h!==n?(h-n)*u:0,e[i+1]+=h!==r?(h-r)*u:0,e[i+2]+=h!==o?(h-o)*u:0}}sendUniformData(t,e){t.uniform1f(e.uVibrance,-this.vibrance)}isNeutralState(){return this.vibrance===0}}T(Bu,"type","Vibrance"),T(Bu,"defaults",{vibrance:0}),T(Bu,"uniformLocations",["uVibrance"]),N.setClass(Bu);var Bh={};Bh.d=(a,t)=>{for(var e in t)Bh.o(t,e)&&!Bh.o(a,e)&&Object.defineProperty(a,e,{enumerable:!0,get:t[e]})},Bh.o=(a,t)=>Object.prototype.hasOwnProperty.call(a,t);var K=globalThis.pdfjsLib={};Bh.d(K,{AbortException:()=>Rn,AnnotationEditorLayer:()=>Hg,AnnotationEditorParamsType:()=>ot,AnnotationEditorType:()=>Z,AnnotationEditorUIManager:()=>Mr,AnnotationLayer:()=>GS,AnnotationMode:()=>Dn,ColorPicker:()=>nd,DOMSVGFactory:()=>Pg,DrawLayer:()=>Gg,FeatureTest:()=>Re,GlobalWorkerOptions:()=>Vi,ImageKind:()=>Hu,InvalidPDFException:()=>ag,MissingPDFException:()=>Gh,OPS:()=>Hs,OutputScale:()=>mg,PDFDataRangeTransport:()=>Tb,PDFDateString:()=>gg,PDFWorker:()=>aa,PasswordResponses:()=>Kw,PermissionFlag:()=>qw,PixelsPerInch:()=>Ln,RenderingCancelledException:()=>dg,TextLayer:()=>Yh,TouchManager:()=>Ku,UnexpectedResponseException:()=>Xu,Util:()=>W,VerbosityLevel:()=>Gu,XfaLayer:()=>Pb,build:()=>wS,createValidAbsoluteUrl:()=>tx,fetchData:()=>Uu,getDocument:()=>dS,getFilenameFromUrl:()=>lx,getPdfFilenameFromUrl:()=>cx,getXfaPageViewport:()=>ux,isDataScheme:()=>Yu,isPdfFile:()=>fg,noContextMenu:()=>Gs,normalizeUnicode:()=>ox,setLayerDimensions:()=>kr,shadow:()=>st,stopEvent:()=>es,version:()=>_S});const ye=typeof process=="object"&&process+""=="[object process]"&&!process.versions.nw&&!(process.versions.electron&&process.type&&process.type!=="browser"),U0=[1,0,0,1,0,0],ng=[.001,0,0,.001,0,0],Yw=1e7,rg=1.35,ts={ANY:1,DISPLAY:2,PRINT:4,ANNOTATIONS_FORMS:16,ANNOTATIONS_STORAGE:32,ANNOTATIONS_DISABLE:64,IS_EDITING:128,OPLIST:256},Dn={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},$w="pdfjs_internal_editor_",Z={DISABLE:-1,NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15},ot={RESIZE:1,CREATE:2,FREETEXT_SIZE:11,FREETEXT_COLOR:12,FREETEXT_OPACITY:13,INK_COLOR:21,INK_THICKNESS:22,INK_OPACITY:23,HIGHLIGHT_COLOR:31,HIGHLIGHT_DEFAULT_COLOR:32,HIGHLIGHT_THICKNESS:33,HIGHLIGHT_FREE:34,HIGHLIGHT_SHOW_ALL:35,DRAW_STEP:41},qw={PRINT:4,MODIFY_CONTENTS:8,COPY:16,MODIFY_ANNOTATIONS:32,FILL_INTERACTIVE_FORMS:256,COPY_FOR_ACCESSIBILITY:512,ASSEMBLE:1024,PRINT_HIGH_QUALITY:2048},ve={FILL:0,STROKE:1,FILL_STROKE:2,INVISIBLE:3,FILL_STROKE_MASK:3,ADD_TO_PATH_FLAG:4},Hu={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},qt={TEXT:1,LINK:2,FREETEXT:3,LINE:4,SQUARE:5,CIRCLE:6,POLYGON:7,POLYLINE:8,HIGHLIGHT:9,UNDERLINE:10,SQUIGGLY:11,STRIKEOUT:12,STAMP:13,CARET:14,INK:15,POPUP:16,FILEATTACHMENT:17,WIDGET:20},Hh={SOLID:1,DASHED:2,BEVELED:3,INSET:4,UNDERLINE:5},Gu={ERRORS:0,WARNINGS:1,INFOS:5},Hs={dependency:1,setLineWidth:2,setLineCap:3,setLineJoin:4,setMiterLimit:5,setDash:6,setRenderingIntent:7,setFlatness:8,setGState:9,save:10,restore:11,transform:12,moveTo:13,lineTo:14,curveTo:15,curveTo2:16,curveTo3:17,closePath:18,rectangle:19,stroke:20,closeStroke:21,fill:22,eoFill:23,fillStroke:24,eoFillStroke:25,closeFillStroke:26,closeEOFillStroke:27,endPath:28,clip:29,eoClip:30,beginText:31,endText:32,setCharSpacing:33,setWordSpacing:34,setHScale:35,setLeading:36,setFont:37,setTextRenderingMode:38,setTextRise:39,moveText:40,setLeadingMoveText:41,setTextMatrix:42,nextLine:43,showText:44,showSpacedText:45,nextLineShowText:46,nextLineSetSpacingShowText:47,setCharWidth:48,setCharWidthAndBounds:49,setStrokeColorSpace:50,setFillColorSpace:51,setStrokeColor:52,setStrokeColorN:53,setFillColor:54,setFillColorN:55,setStrokeGray:56,setFillGray:57,setStrokeRGBColor:58,setFillRGBColor:59,setStrokeCMYKColor:60,setFillCMYKColor:61,shadingFill:62,beginInlineImage:63,beginImageData:64,endInlineImage:65,paintXObject:66,markPoint:67,markPointProps:68,beginMarkedContent:69,beginMarkedContentProps:70,endMarkedContent:71,beginCompat:72,endCompat:73,paintFormXObjectBegin:74,paintFormXObjectEnd:75,beginGroup:76,endGroup:77,beginAnnotation:80,endAnnotation:81,paintImageMaskXObject:83,paintImageMaskXObjectGroup:84,paintImageXObject:85,paintInlineImageXObject:86,paintInlineImageXObjectGroup:87,paintImageXObjectRepeat:88,paintImageMaskXObjectRepeat:89,paintSolidColorImageMask:90,constructPath:91,setStrokeTransparent:92,setFillTransparent:93},Kw={NEED_PASSWORD:1,INCORRECT_PASSWORD:2};let zu=Gu.WARNINGS;function Qw(a){Number.isInteger(a)&&(zu=a)}function Jw(){return zu}function Vu(a){zu>=Gu.INFOS&&console.log(`Info: ${a}`)}function tt(a){zu>=Gu.WARNINGS&&console.log(`Warning: ${a}`)}function vt(a){throw new Error(a)}function Xt(a,t){a||vt(t)}function Zw(a){switch(a==null?void 0:a.protocol){case"http:":case"https:":case"ftp:":case"mailto:":case"tel:":return!0;default:return!1}}function tx(a,t=null,e=null){if(!a)return null;try{if(e&&typeof a=="string"){if(e.addDefaultProtocol&&a.startsWith("www.")){const i=a.match(/\./g);(i==null?void 0:i.length)>=2&&(a=`http://${a}`)}if(e.tryConvertEncoding)try{a=rx(a)}catch{}}const s=t?new URL(a,t):new URL(a);if(Zw(s))return s}catch{}return null}function st(a,t,e,s=!1){return Object.defineProperty(a,t,{value:e,enumerable:!s,configurable:!0,writable:!1}),e}const On=function(){function t(e,s){this.message=e,this.name=s}return t.prototype=new Error,t.constructor=t,t}();class Y0 extends On{constructor(t,e){super(t,"PasswordException"),this.code=e}}class og extends On{constructor(t,e){super(t,"UnknownErrorException"),this.details=e}}class ag extends On{constructor(t){super(t,"InvalidPDFException")}}class Gh extends On{constructor(t){super(t,"MissingPDFException")}}class Xu extends On{constructor(t,e){super(t,"UnexpectedResponseException"),this.status=e}}class ex extends On{constructor(t){super(t,"FormatError")}}class Rn extends On{constructor(t){super(t,"AbortException")}}function $0(a){(typeof a!="object"||(a==null?void 0:a.length)===void 0)&&vt("Invalid argument for bytesToString");const t=a.length,e=8192;if(t<e)return String.fromCharCode.apply(null,a);const s=[];for(let i=0;i<t;i+=e){const n=Math.min(i+e,t),r=a.subarray(i,n);s.push(String.fromCharCode.apply(null,r))}return s.join("")}function Wu(a){typeof a!="string"&&vt("Invalid argument for stringToBytes");const t=a.length,e=new Uint8Array(t);for(let s=0;s<t;++s)e[s]=a.charCodeAt(s)&255;return e}function sx(a){return String.fromCharCode(a>>24&255,a>>16&255,a>>8&255,a&255)}function hg(a){const t=Object.create(null);for(const[e,s]of a)t[e]=s;return t}function ix(){const a=new Uint8Array(4);return a[0]=1,new Uint32Array(a.buffer,0,1)[0]===1}function nx(){try{return new Function(""),!0}catch{return!1}}class Re{static get isLittleEndian(){return st(this,"isLittleEndian",ix())}static get isEvalSupported(){return st(this,"isEvalSupported",nx())}static get isOffscreenCanvasSupported(){return st(this,"isOffscreenCanvasSupported",typeof OffscreenCanvas<"u")}static get isImageDecoderSupported(){return st(this,"isImageDecoderSupported",typeof ImageDecoder<"u")}static get platform(){return typeof navigator<"u"&&typeof(navigator==null?void 0:navigator.platform)=="string"?st(this,"platform",{isMac:navigator.platform.includes("Mac"),isWindows:navigator.platform.includes("Win"),isFirefox:typeof(navigator==null?void 0:navigator.userAgent)=="string"&&navigator.userAgent.includes("Firefox")}):st(this,"platform",{isMac:!1,isWindows:!1,isFirefox:!1})}static get isCSSRoundSupported(){var t,e;return st(this,"isCSSRoundSupported",(e=(t=globalThis.CSS)==null?void 0:t.supports)==null?void 0:e.call(t,"width: round(1.5px, 1px)"))}}const lg=Array.from(Array(256).keys(),a=>a.toString(16).padStart(2,"0"));class W{static makeHexColor(t,e,s){return`#${lg[t]}${lg[e]}${lg[s]}`}static scaleMinMax(t,e){let s;t[0]?(t[0]<0&&(s=e[0],e[0]=e[2],e[2]=s),e[0]*=t[0],e[2]*=t[0],t[3]<0&&(s=e[1],e[1]=e[3],e[3]=s),e[1]*=t[3],e[3]*=t[3]):(s=e[0],e[0]=e[1],e[1]=s,s=e[2],e[2]=e[3],e[3]=s,t[1]<0&&(s=e[1],e[1]=e[3],e[3]=s),e[1]*=t[1],e[3]*=t[1],t[2]<0&&(s=e[0],e[0]=e[2],e[2]=s),e[0]*=t[2],e[2]*=t[2]),e[0]+=t[4],e[1]+=t[5],e[2]+=t[4],e[3]+=t[5]}static transform(t,e){return[t[0]*e[0]+t[2]*e[1],t[1]*e[0]+t[3]*e[1],t[0]*e[2]+t[2]*e[3],t[1]*e[2]+t[3]*e[3],t[0]*e[4]+t[2]*e[5]+t[4],t[1]*e[4]+t[3]*e[5]+t[5]]}static applyTransform(t,e){const s=t[0]*e[0]+t[1]*e[2]+e[4],i=t[0]*e[1]+t[1]*e[3]+e[5];return[s,i]}static applyInverseTransform(t,e){const s=e[0]*e[3]-e[1]*e[2],i=(t[0]*e[3]-t[1]*e[2]+e[2]*e[5]-e[4]*e[3])/s,n=(-t[0]*e[1]+t[1]*e[0]+e[4]*e[1]-e[5]*e[0])/s;return[i,n]}static getAxialAlignedBoundingBox(t,e){const s=this.applyTransform(t,e),i=this.applyTransform(t.slice(2,4),e),n=this.applyTransform([t[0],t[3]],e),r=this.applyTransform([t[2],t[1]],e);return[Math.min(s[0],i[0],n[0],r[0]),Math.min(s[1],i[1],n[1],r[1]),Math.max(s[0],i[0],n[0],r[0]),Math.max(s[1],i[1],n[1],r[1])]}static inverseTransform(t){const e=t[0]*t[3]-t[1]*t[2];return[t[3]/e,-t[1]/e,-t[2]/e,t[0]/e,(t[2]*t[5]-t[4]*t[3])/e,(t[4]*t[1]-t[5]*t[0])/e]}static singularValueDecompose2dScale(t){const e=[t[0],t[2],t[1],t[3]],s=t[0]*e[0]+t[1]*e[2],i=t[0]*e[1]+t[1]*e[3],n=t[2]*e[0]+t[3]*e[2],r=t[2]*e[1]+t[3]*e[3],o=(s+r)/2,h=Math.sqrt((s+r)**2-4*(s*r-n*i))/2,c=o+h||1,u=o-h||1;return[Math.sqrt(c),Math.sqrt(u)]}static normalizeRect(t){const e=t.slice(0);return t[0]>t[2]&&(e[0]=t[2],e[2]=t[0]),t[1]>t[3]&&(e[1]=t[3],e[3]=t[1]),e}static intersect(t,e){const s=Math.max(Math.min(t[0],t[2]),Math.min(e[0],e[2])),i=Math.min(Math.max(t[0],t[2]),Math.max(e[0],e[2]));if(s>i)return null;const n=Math.max(Math.min(t[1],t[3]),Math.min(e[1],e[3])),r=Math.min(Math.max(t[1],t[3]),Math.max(e[1],e[3]));return n>r?null:[s,n,i,r]}static bezierBoundingBox(t,e,s,i,n,r,o,h,c){return c?(c[0]=Math.min(c[0],t,o),c[1]=Math.min(c[1],e,h),c[2]=Math.max(c[2],t,o),c[3]=Math.max(c[3],e,h)):c=[Math.min(t,o),Math.min(e,h),Math.max(t,o),Math.max(e,h)],w(this,Xi,qg).call(this,t,s,n,o,e,i,r,h,3*(-t+3*(s-n)+o),6*(t-2*s+n),3*(s-t),c),w(this,Xi,qg).call(this,t,s,n,o,e,i,r,h,3*(-e+3*(i-r)+h),6*(e-2*i+r),3*(i-e),c),c}}Xi=new WeakSet,Ed=function(t,e,s,i,n,r,o,h,c,u){if(c<=0||c>=1)return;const d=1-c,f=c*c,g=f*c,p=d*(d*(d*t+3*c*e)+3*f*s)+g*i,b=d*(d*(d*n+3*c*r)+3*f*o)+g*h;u[0]=Math.min(u[0],p),u[1]=Math.min(u[1],b),u[2]=Math.max(u[2],p),u[3]=Math.max(u[3],b)},qg=function(t,e,s,i,n,r,o,h,c,u,d,f){if(Math.abs(c)<1e-12){Math.abs(u)>=1e-12&&w(this,Xi,Ed).call(this,t,e,s,i,n,r,o,h,-d/u,f);return}const g=u**2-4*d*c;if(g<0)return;const p=Math.sqrt(g),b=2*c;w(this,Xi,Ed).call(this,t,e,s,i,n,r,o,h,(-u+p)/b,f),w(this,Xi,Ed).call(this,t,e,s,i,n,r,o,h,(-u-p)/b,f)},y(W,Xi);function rx(a){return decodeURIComponent(escape(a))}let cg=null,q0=null;function ox(a){return cg||(cg=/([\u00a0\u00b5\u037e\u0eb3\u2000-\u200a\u202f\u2126\ufb00-\ufb04\ufb06\ufb20-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufba1\ufba4-\ufba9\ufbae-\ufbb1\ufbd3-\ufbdc\ufbde-\ufbe7\ufbea-\ufbf8\ufbfc-\ufbfd\ufc00-\ufc5d\ufc64-\ufcf1\ufcf5-\ufd3d\ufd88\ufdf4\ufdfa-\ufdfb\ufe71\ufe77\ufe79\ufe7b\ufe7d]+)|(\ufb05+)/gu,q0=new Map([["ſt","ſt"]])),a.replaceAll(cg,(t,e,s)=>e?e.normalize("NFKC"):q0.get(s))}function ax(){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();const a=new Uint8Array(32);return crypto.getRandomValues(a),$0(a)}const ug="pdfjs_internal_id_";function hx(a){return Uint8Array.prototype.toBase64?a.toBase64():btoa($0(a))}typeof Promise.try!="function"&&(Promise.try=function(a,...t){return new Promise(e=>{e(a(...t))})});const zi="http://www.w3.org/2000/svg",Or=class Or{};$(Or,"CSS",96),$(Or,"PDF",72),$(Or,"PDF_TO_CSS_UNITS",Or.CSS/Or.PDF);let Ln=Or;async function Uu(a,t="text"){if(Vh(a,document.baseURI)){const e=await fetch(a);if(!e.ok)throw new Error(e.statusText);switch(t){case"arraybuffer":return e.arrayBuffer();case"blob":return e.blob();case"json":return e.json()}return e.text()}return new Promise((e,s)=>{const i=new XMLHttpRequest;i.open("GET",a,!0),i.responseType=t,i.onreadystatechange=()=>{if(i.readyState===XMLHttpRequest.DONE){if(i.status===200||i.status===0){switch(t){case"arraybuffer":case"blob":case"json":e(i.response);return}e(i.responseText);return}s(new Error(i.statusText))}},i.send(null)})}class zh{constructor({viewBox:t,userUnit:e,scale:s,rotation:i,offsetX:n=0,offsetY:r=0,dontFlip:o=!1}){this.viewBox=t,this.userUnit=e,this.scale=s,this.rotation=i,this.offsetX=n,this.offsetY=r,s*=e;const h=(t[2]+t[0])/2,c=(t[3]+t[1])/2;let u,d,f,g;switch(i%=360,i<0&&(i+=360),i){case 180:u=-1,d=0,f=0,g=1;break;case 90:u=0,d=1,f=1,g=0;break;case 270:u=0,d=-1,f=-1,g=0;break;case 0:u=1,d=0,f=0,g=-1;break;default:throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.")}o&&(f=-f,g=-g);let p,b,v,_;u===0?(p=Math.abs(c-t[1])*s+n,b=Math.abs(h-t[0])*s+r,v=(t[3]-t[1])*s,_=(t[2]-t[0])*s):(p=Math.abs(h-t[0])*s+n,b=Math.abs(c-t[1])*s+r,v=(t[2]-t[0])*s,_=(t[3]-t[1])*s),this.transform=[u*s,d*s,f*s,g*s,p-u*s*h-f*s*c,b-d*s*h-g*s*c],this.width=v,this.height=_}get rawDims(){const{userUnit:t,viewBox:e}=this,s=e.map(i=>i*t);return st(this,"rawDims",{pageWidth:s[2]-s[0],pageHeight:s[3]-s[1],pageX:s[0],pageY:s[1]})}clone({scale:t=this.scale,rotation:e=this.rotation,offsetX:s=this.offsetX,offsetY:i=this.offsetY,dontFlip:n=!1}={}){return new zh({viewBox:this.viewBox.slice(),userUnit:this.userUnit,scale:t,rotation:e,offsetX:s,offsetY:i,dontFlip:n})}convertToViewportPoint(t,e){return W.applyTransform([t,e],this.transform)}convertToViewportRectangle(t){const e=W.applyTransform([t[0],t[1]],this.transform),s=W.applyTransform([t[2],t[3]],this.transform);return[e[0],e[1],s[0],s[1]]}convertToPdfPoint(t,e){return W.applyInverseTransform([t,e],this.transform)}}class dg extends On{constructor(t,e=0){super(t,"RenderingCancelledException"),this.extraDelay=e}}function Yu(a){const t=a.length;let e=0;for(;e<t&&a[e].trim()==="";)e++;return a.substring(e,e+5).toLowerCase()==="data:"}function fg(a){return typeof a=="string"&&/\.pdf$/i.test(a)}function lx(a){return[a]=a.split(/[#?]/,1),a.substring(a.lastIndexOf("/")+1)}function cx(a,t="document.pdf"){if(typeof a!="string")return t;if(Yu(a))return tt('getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.'),t;const e=/^(?:(?:[^:]+:)?\/\/[^/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/,s=/[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i,i=e.exec(a);let n=s.exec(i[1])||s.exec(i[2])||s.exec(i[3]);if(n&&(n=n[0],n.includes("%")))try{n=s.exec(decodeURIComponent(n))[0]}catch{}return n||t}class K0{constructor(){$(this,"started",Object.create(null));$(this,"times",[])}time(t){t in this.started&&tt(`Timer is already running for ${t}`),this.started[t]=Date.now()}timeEnd(t){t in this.started||tt(`Timer has not been started for ${t}`),this.times.push({name:t,start:this.started[t],end:Date.now()}),delete this.started[t]}toString(){const t=[];let e=0;for(const{name:s}of this.times)e=Math.max(s.length,e);for(const{name:s,start:i,end:n}of this.times)t.push(`${s.padEnd(e)} ${n-i}ms
499
+ `);return t.join("")}}function Vh(a,t){try{const{protocol:e}=t?new URL(a,t):new URL(a);return e==="http:"||e==="https:"}catch{return!1}}function Gs(a){a.preventDefault()}function es(a){a.preventDefault(),a.stopPropagation()}class gg{static toDateObject(t){if(!t||typeof t!="string")return null;l(this,Jh)||m(this,Jh,new RegExp("^D:(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?([Z|+|-])?(\\d{2})?'?(\\d{2})?'?"));const e=l(this,Jh).exec(t);if(!e)return null;const s=parseInt(e[1],10);let i=parseInt(e[2],10);i=i>=1&&i<=12?i-1:0;let n=parseInt(e[3],10);n=n>=1&&n<=31?n:1;let r=parseInt(e[4],10);r=r>=0&&r<=23?r:0;let o=parseInt(e[5],10);o=o>=0&&o<=59?o:0;let h=parseInt(e[6],10);h=h>=0&&h<=59?h:0;const c=e[7]||"Z";let u=parseInt(e[8],10);u=u>=0&&u<=23?u:0;let d=parseInt(e[9],10)||0;return d=d>=0&&d<=59?d:0,c==="-"?(r+=u,o+=d):c==="+"&&(r-=u,o-=d),new Date(Date.UTC(s,i,n,r,o,h))}}Jh=new WeakMap,y(gg,Jh);function ux(a,{scale:t=1,rotation:e=0}){const{width:s,height:i}=a.attributes.style,n=[0,0,parseInt(s),parseInt(i)];return new zh({viewBox:n,userUnit:1,scale:t,rotation:e})}function pg(a){if(a.startsWith("#")){const t=parseInt(a.slice(1),16);return[(t&16711680)>>16,(t&65280)>>8,t&255]}return a.startsWith("rgb(")?a.slice(4,-1).split(",").map(t=>parseInt(t)):a.startsWith("rgba(")?a.slice(5,-1).split(",").map(t=>parseInt(t)).slice(0,3):(tt(`Not a valid color format: "${a}"`),[0,0,0])}function dx(a){const t=document.createElement("span");t.style.visibility="hidden",document.body.append(t);for(const e of a.keys()){t.style.color=e;const s=window.getComputedStyle(t).color;a.set(e,pg(s))}t.remove()}function Tt(a){const{a:t,b:e,c:s,d:i,e:n,f:r}=a.getTransform();return[t,e,s,i,n,r]}function li(a){const{a:t,b:e,c:s,d:i,e:n,f:r}=a.getTransform().invertSelf();return[t,e,s,i,n,r]}function kr(a,t,e=!1,s=!0){if(t instanceof zh){const{pageWidth:i,pageHeight:n}=t.rawDims,{style:r}=a,o=Re.isCSSRoundSupported,h=`var(--scale-factor) * ${i}px`,c=`var(--scale-factor) * ${n}px`,u=o?`round(down, ${h}, var(--scale-round-x, 1px))`:`calc(${h})`,d=o?`round(down, ${c}, var(--scale-round-y, 1px))`:`calc(${c})`;!e||t.rotation%180===0?(r.width=u,r.height=d):(r.width=d,r.height=u)}s&&a.setAttribute("data-main-rotation",t.rotation)}class mg{constructor(){const t=window.devicePixelRatio||1;this.sx=t,this.sy=t}get scaled(){return this.sx!==1||this.sy!==1}get symmetric(){return this.sx===this.sy}}const Wi=class Wi{constructor(t){y(this,Le);y(this,In,null);y(this,Rr,null);y(this,zs);y(this,Lr,null);y(this,Zh,null);m(this,zs,t),l(Wi,tl)||m(Wi,tl,Object.freeze({freetext:"pdfjs-editor-remove-freetext-button",highlight:"pdfjs-editor-remove-highlight-button",ink:"pdfjs-editor-remove-ink-button",stamp:"pdfjs-editor-remove-stamp-button"}))}render(){const t=m(this,In,document.createElement("div"));t.classList.add("editToolbar","hidden"),t.setAttribute("role","toolbar");const e=l(this,zs)._uiManager._signal;t.addEventListener("contextmenu",Gs,{signal:e}),t.addEventListener("pointerdown",w(Wi,ad,$b),{signal:e});const s=m(this,Lr,document.createElement("div"));s.className="buttons",t.append(s);const i=l(this,zs).toolbarPosition;if(i){const{style:n}=t,r=l(this,zs)._uiManager.direction==="ltr"?1-i[0]:i[0];n.insetInlineEnd=`${100*r}%`,n.top=`calc(${100*i[1]}% + var(--editor-toolbar-vert-offset))`}return w(this,Le,Qb).call(this),t}get div(){return l(this,In)}hide(){var t;l(this,In).classList.add("hidden"),(t=l(this,Rr))==null||t.hideDropdown()}show(){var t;l(this,In).classList.remove("hidden"),(t=l(this,Zh))==null||t.shown()}async addAltText(t){const e=await t.render();w(this,Le,kd).call(this,e),l(this,Lr).prepend(e,l(this,Le,Kg)),m(this,Zh,t)}addColorPicker(t){m(this,Rr,t);const e=t.renderButton();w(this,Le,kd).call(this,e),l(this,Lr).prepend(e,l(this,Le,Kg))}remove(){var t;l(this,In).remove(),(t=l(this,Rr))==null||t.destroy(),m(this,Rr,null)}};In=new WeakMap,Rr=new WeakMap,zs=new WeakMap,Lr=new WeakMap,Zh=new WeakMap,tl=new WeakMap,ad=new WeakSet,$b=function(t){t.stopPropagation()},Le=new WeakSet,qb=function(t){l(this,zs)._focusEventsAllowed=!1,es(t)},Kb=function(t){l(this,zs)._focusEventsAllowed=!0,es(t)},kd=function(t){const e=l(this,zs)._uiManager._signal;t.addEventListener("focusin",w(this,Le,qb).bind(this),{capture:!0,signal:e}),t.addEventListener("focusout",w(this,Le,Kb).bind(this),{capture:!0,signal:e}),t.addEventListener("contextmenu",Gs,{signal:e})},Qb=function(){const{editorType:t,_uiManager:e}=l(this,zs),s=document.createElement("button");s.className="delete",s.tabIndex=0,s.setAttribute("data-l10n-id",l(Wi,tl)[t]),w(this,Le,kd).call(this,s),s.addEventListener("click",i=>{e.delete()},{signal:e._signal}),l(this,Lr).append(s)},Kg=function(){const t=document.createElement("div");return t.className="divider",t},y(Wi,ad),y(Wi,tl,null);let bg=Wi;class fx{constructor(t){y(this,Nn);y(this,el,null);y(this,Fr,null);y(this,Ir);m(this,Ir,t)}show(t,e,s){const[i,n]=w(this,Nn,Zb).call(this,e,s),{style:r}=l(this,Fr)||m(this,Fr,w(this,Nn,Jb).call(this));t.append(l(this,Fr)),r.insetInlineEnd=`${100*i}%`,r.top=`calc(${100*n}% + var(--editor-toolbar-vert-offset))`}hide(){l(this,Fr).remove()}}el=new WeakMap,Fr=new WeakMap,Ir=new WeakMap,Nn=new WeakSet,Jb=function(){const t=m(this,Fr,document.createElement("div"));t.className="editToolbar",t.setAttribute("role","toolbar"),t.addEventListener("contextmenu",Gs,{signal:l(this,Ir)._signal});const e=m(this,el,document.createElement("div"));return e.className="buttons",t.append(e),w(this,Nn,ty).call(this),t},Zb=function(t,e){let s=0,i=0;for(const n of t){const r=n.y+n.height;if(r<s)continue;const o=n.x+(e?n.width:0);if(r>s){i=o,s=r;continue}e?o>i&&(i=o):o<i&&(i=o)}return[e?1-i:i,s]},ty=function(){const t=document.createElement("button");t.className="highlightButton",t.tabIndex=0,t.setAttribute("data-l10n-id","pdfjs-highlight-floating-button1");const e=document.createElement("span");t.append(e),e.className="visuallyHidden",e.setAttribute("data-l10n-id","pdfjs-highlight-floating-button-label");const s=l(this,Ir)._signal;t.addEventListener("contextmenu",Gs,{signal:s}),t.addEventListener("click",()=>{l(this,Ir).highlightSelection("floating_button")},{signal:s}),l(this,el).append(t)};function $u(a,t,e){for(const s of e)t.addEventListener(s,a[s].bind(a))}class gx{constructor(){y(this,hd,0)}get id(){return`${$w}${Ge(this,hd)._++}`}}hd=new WeakMap;const zg=class zg{constructor(){y(this,la);y(this,ha,ax());y(this,sl,0);y(this,we,null)}static get _isSVGFittingCanvas(){const t='data:image/svg+xml;charset=UTF-8,<svg viewBox="0 0 1 1" width="1" height="1" xmlns="http://www.w3.org/2000/svg"><rect width="1" height="1" style="fill:red;"/></svg>',s=new OffscreenCanvas(1,3).getContext("2d",{willReadFrequently:!0}),i=new Image;i.src=t;const n=i.decode().then(()=>(s.drawImage(i,0,0,1,1,0,0,1,3),new Uint32Array(s.getImageData(0,0,1,1).data.buffer)[0]===0));return st(this,"_isSVGFittingCanvas",n)}async getFromFile(t){const{lastModified:e,name:s,size:i,type:n}=t;return w(this,la,Md).call(this,`${e}_${s}_${i}_${n}`,t)}async getFromUrl(t){return w(this,la,Md).call(this,t,t)}async getFromBlob(t,e){const s=await e;return w(this,la,Md).call(this,t,s)}async getFromId(t){l(this,we)||m(this,we,new Map);const e=l(this,we).get(t);if(!e)return null;if(e.bitmap)return e.refCounter+=1,e;if(e.file)return this.getFromFile(e.file);if(e.blobPromise){const{blobPromise:s}=e;return delete e.blobPromise,this.getFromBlob(e.id,s)}return this.getFromUrl(e.url)}getFromCanvas(t,e){l(this,we)||m(this,we,new Map);let s=l(this,we).get(t);if(s!=null&&s.bitmap)return s.refCounter+=1,s;const i=new OffscreenCanvas(e.width,e.height);return i.getContext("2d").drawImage(e,0,0),s={bitmap:i.transferToImageBitmap(),id:`image_${l(this,ha)}_${Ge(this,sl)._++}`,refCounter:1,isSvg:!1},l(this,we).set(t,s),l(this,we).set(s.id,s),s}getSvgUrl(t){const e=l(this,we).get(t);return e!=null&&e.isSvg?e.svgUrl:null}deleteId(t){var i;l(this,we)||m(this,we,new Map);const e=l(this,we).get(t);if(!e||(e.refCounter-=1,e.refCounter!==0))return;const{bitmap:s}=e;if(!e.url&&!e.file){const n=new OffscreenCanvas(s.width,s.height);n.getContext("bitmaprenderer").transferFromImageBitmap(s),e.blobPromise=n.convertToBlob()}(i=s.close)==null||i.call(s),e.bitmap=null}isValidId(t){return t.startsWith(`image_${l(this,ha)}_`)}};ha=new WeakMap,sl=new WeakMap,we=new WeakMap,la=new WeakSet,Md=async function(t,e){l(this,we)||m(this,we,new Map);let s=l(this,we).get(t);if(s===null)return null;if(s!=null&&s.bitmap)return s.refCounter+=1,s;try{s||(s={bitmap:null,id:`image_${l(this,ha)}_${Ge(this,sl)._++}`,refCounter:0,isSvg:!1});let i;if(typeof e=="string"?(s.url=e,i=await Uu(e,"blob")):e instanceof File?i=s.file=e:e instanceof Blob&&(i=e),i.type==="image/svg+xml"){const n=zg._isSVGFittingCanvas,r=new FileReader,o=new Image,h=new Promise((c,u)=>{o.onload=()=>{s.bitmap=o,s.isSvg=!0,c()},r.onload=async()=>{const d=s.svgUrl=r.result;o.src=await n?`${d}#svgView(preserveAspectRatio(none))`:d},o.onerror=r.onerror=u});r.readAsDataURL(i),await h}else s.bitmap=await createImageBitmap(i);s.refCounter=1}catch(i){tt(i),s=null}return l(this,we).set(t,s),s&&l(this,we).set(s.id,s),s};let yg=zg;class px{constructor(t=128){y(this,Bt,[]);y(this,jn,!1);y(this,il);y(this,Dt,-1);m(this,il,t)}add({cmd:t,undo:e,post:s,mustExec:i,type:n=NaN,overwriteIfSameType:r=!1,keepUndo:o=!1}){if(i&&t(),l(this,jn))return;const h={cmd:t,undo:e,post:s,type:n};if(l(this,Dt)===-1){l(this,Bt).length>0&&(l(this,Bt).length=0),m(this,Dt,0),l(this,Bt).push(h);return}if(r&&l(this,Bt)[l(this,Dt)].type===n){o&&(h.undo=l(this,Bt)[l(this,Dt)].undo),l(this,Bt)[l(this,Dt)]=h;return}const c=l(this,Dt)+1;c===l(this,il)?l(this,Bt).splice(0,1):(m(this,Dt,c),c<l(this,Bt).length&&l(this,Bt).splice(c)),l(this,Bt).push(h)}undo(){if(l(this,Dt)===-1)return;m(this,jn,!0);const{undo:t,post:e}=l(this,Bt)[l(this,Dt)];t(),e==null||e(),m(this,jn,!1),m(this,Dt,l(this,Dt)-1)}redo(){if(l(this,Dt)<l(this,Bt).length-1){m(this,Dt,l(this,Dt)+1),m(this,jn,!0);const{cmd:t,post:e}=l(this,Bt)[l(this,Dt)];t(),e==null||e(),m(this,jn,!1)}}hasSomethingToUndo(){return l(this,Dt)!==-1}hasSomethingToRedo(){return l(this,Dt)<l(this,Bt).length-1}cleanType(t){if(l(this,Dt)!==-1){for(let e=l(this,Dt);e>=0;e--)if(l(this,Bt)[e].type!==t){l(this,Bt).splice(e+1,l(this,Dt)-e),m(this,Dt,e);return}l(this,Bt).length=0,m(this,Dt,-1)}}destroy(){m(this,Bt,null)}}Bt=new WeakMap,jn=new WeakMap,il=new WeakMap,Dt=new WeakMap;class Xh{constructor(t){y(this,ld);this.buffer=[],this.callbacks=new Map,this.allKeys=new Set;const{isMac:e}=Re.platform;for(const[s,i,n={}]of t)for(const r of s){const o=r.startsWith("mac+");e&&o?(this.callbacks.set(r.slice(4),{callback:i,options:n}),this.allKeys.add(r.split("+").at(-1))):!e&&!o&&(this.callbacks.set(r,{callback:i,options:n}),this.allKeys.add(r.split("+").at(-1)))}}exec(t,e){if(!this.allKeys.has(e.key))return;const s=this.callbacks.get(w(this,ld,ey).call(this,e));if(!s)return;const{callback:i,options:{bubbles:n=!1,args:r=[],checker:o=null}}=s;o&&!o(t,e)||(i.bind(t,...r,e)(),n||es(e))}}ld=new WeakSet,ey=function(t){t.altKey&&this.buffer.push("alt"),t.ctrlKey&&this.buffer.push("ctrl"),t.metaKey&&this.buffer.push("meta"),t.shiftKey&&this.buffer.push("shift"),this.buffer.push(t.key);const e=this.buffer.join("+");return this.buffer.length=0,e};const cd=class cd{get _colors(){const t=new Map([["CanvasText",null],["Canvas",null]]);return dx(t),st(this,"_colors",t)}convert(t){const e=pg(t);if(!window.matchMedia("(forced-colors: active)").matches)return e;for(const[s,i]of this._colors)if(i.every((n,r)=>n===e[r]))return cd._colorsMapping.get(s);return e}getHexCode(t){const e=this._colors.get(t);return e?W.makeHexColor(...e):t}};$(cd,"_colorsMapping",new Map([["CanvasText",[0,0,0]],["Canvas",[255,255,255]]]));let vg=cd;const ma=class ma{constructor(t,e,s,i,n,r,o,h,c,u,d,f,g){y(this,I);y(this,ca,new AbortController);y(this,ss,null);y(this,Kt,new Map);y(this,ae,new Map);y(this,ua,null);y(this,Ui,null);y(this,da,null);y(this,ws,new px);y(this,Bn,null);y(this,Nr,null);y(this,fa,0);y(this,jr,new Set);y(this,ui,null);y(this,Vs,null);y(this,Br,new Set);$(this,"_editorUndoBar",null);y(this,nl,!1);y(this,rl,!1);y(this,ga,!1);y(this,ol,null);y(this,di,null);y(this,Hn,null);y(this,pa,null);y(this,Gn,!1);y(this,fi,null);y(this,ud,new gx);y(this,zn,!1);y(this,al,!1);y(this,Vn,null);y(this,Hr,null);y(this,hl,null);y(this,ll,null);y(this,ee,Z.NONE);y(this,pt,new Set);y(this,Yi,null);y(this,Gr,null);y(this,cl,null);y(this,ul,{isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1});y(this,Xn,[0,0]);y(this,gi,null);y(this,$i,null);y(this,dl,null);y(this,xs,null);const p=this._signal=l(this,ca).signal;m(this,$i,t),m(this,dl,e),m(this,ua,s),this._eventBus=i,i._on("editingaction",this.onEditingAction.bind(this),{signal:p}),i._on("pagechanging",this.onPageChanging.bind(this),{signal:p}),i._on("scalechanging",this.onScaleChanging.bind(this),{signal:p}),i._on("rotationchanging",this.onRotationChanging.bind(this),{signal:p}),i._on("setpreference",this.onSetPreference.bind(this),{signal:p}),i._on("switchannotationeditorparams",b=>this.updateParams(b.type,b.value),{signal:p}),w(this,I,ny).call(this),w(this,I,hy).call(this),w(this,I,Jg).call(this),m(this,Ui,n.annotationStorage),m(this,ol,n.filterFactory),m(this,Gr,r),m(this,pa,o||null),m(this,nl,h),m(this,rl,c),m(this,ga,u),m(this,ll,d||null),this.viewParameters={realScale:Ln.PDF_TO_CSS_UNITS,rotation:0},this.isShiftKeyDown=!1,this._editorUndoBar=f||null,this._supportsPinchToZoom=g!==!1}static get _keyboardManager(){const t=ma.prototype,e=r=>l(r,$i).contains(document.activeElement)&&document.activeElement.tagName!=="BUTTON"&&r.hasSomethingToControl(),s=(r,{target:o})=>{if(o instanceof HTMLInputElement){const{type:h}=o;return h!=="text"&&h!=="number"}return!0},i=this.TRANSLATE_SMALL,n=this.TRANSLATE_BIG;return st(this,"_keyboardManager",new Xh([[["ctrl+a","mac+meta+a"],t.selectAll,{checker:s}],[["ctrl+z","mac+meta+z"],t.undo,{checker:s}],[["ctrl+y","ctrl+shift+z","mac+meta+shift+z","ctrl+shift+Z","mac+meta+shift+Z"],t.redo,{checker:s}],[["Backspace","alt+Backspace","ctrl+Backspace","shift+Backspace","mac+Backspace","mac+alt+Backspace","mac+ctrl+Backspace","Delete","ctrl+Delete","shift+Delete","mac+Delete"],t.delete,{checker:s}],[["Enter","mac+Enter"],t.addNewEditorFromKeyboard,{checker:(r,{target:o})=>!(o instanceof HTMLButtonElement)&&l(r,$i).contains(o)&&!r.isEnterHandled}],[[" ","mac+ "],t.addNewEditorFromKeyboard,{checker:(r,{target:o})=>!(o instanceof HTMLButtonElement)&&l(r,$i).contains(document.activeElement)}],[["Escape","mac+Escape"],t.unselectAll],[["ArrowLeft","mac+ArrowLeft"],t.translateSelectedEditors,{args:[-i,0],checker:e}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],t.translateSelectedEditors,{args:[-n,0],checker:e}],[["ArrowRight","mac+ArrowRight"],t.translateSelectedEditors,{args:[i,0],checker:e}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],t.translateSelectedEditors,{args:[n,0],checker:e}],[["ArrowUp","mac+ArrowUp"],t.translateSelectedEditors,{args:[0,-i],checker:e}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],t.translateSelectedEditors,{args:[0,-n],checker:e}],[["ArrowDown","mac+ArrowDown"],t.translateSelectedEditors,{args:[0,i],checker:e}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],t.translateSelectedEditors,{args:[0,n],checker:e}]]))}destroy(){var t,e,s,i,n;(t=l(this,xs))==null||t.resolve(),m(this,xs,null),(e=l(this,ca))==null||e.abort(),m(this,ca,null),this._signal=null;for(const r of l(this,ae).values())r.destroy();l(this,ae).clear(),l(this,Kt).clear(),l(this,Br).clear(),m(this,ss,null),l(this,pt).clear(),l(this,ws).destroy(),(s=l(this,ua))==null||s.destroy(),(i=l(this,fi))==null||i.hide(),m(this,fi,null),l(this,di)&&(clearTimeout(l(this,di)),m(this,di,null)),l(this,gi)&&(clearTimeout(l(this,gi)),m(this,gi,null)),(n=this._editorUndoBar)==null||n.destroy()}combinedSignal(t){return AbortSignal.any([this._signal,t.signal])}get mlManager(){return l(this,ll)}get useNewAltTextFlow(){return l(this,rl)}get useNewAltTextWhenAddingImage(){return l(this,ga)}get hcmFilter(){return st(this,"hcmFilter",l(this,Gr)?l(this,ol).addHCMFilter(l(this,Gr).foreground,l(this,Gr).background):"none")}get direction(){return st(this,"direction",getComputedStyle(l(this,$i)).direction)}get highlightColors(){return st(this,"highlightColors",l(this,pa)?new Map(l(this,pa).split(",").map(t=>t.split("=").map(e=>e.trim()))):null)}get highlightColorNames(){return st(this,"highlightColorNames",this.highlightColors?new Map(Array.from(this.highlightColors,t=>t.reverse())):null)}setCurrentDrawingSession(t){t?(this.unselectAll(),this.disableUserSelect(!0)):this.disableUserSelect(!1),m(this,Nr,t)}setMainHighlightColorPicker(t){m(this,hl,t)}editAltText(t,e=!1){var s;(s=l(this,ua))==null||s.editAltText(this,t,e)}switchToMode(t,e){this._eventBus.on("annotationeditormodechanged",e,{once:!0,signal:this._signal}),this._eventBus.dispatch("showannotationeditorui",{source:this,mode:t})}setPreference(t,e){this._eventBus.dispatch("setpreference",{source:this,name:t,value:e})}onSetPreference({name:t,value:e}){switch(t){case"enableNewAltTextWhenAddingImage":m(this,ga,e);break}}onPageChanging({pageNumber:t}){m(this,fa,t-1)}focusMainContainer(){l(this,$i).focus()}findParent(t,e){for(const s of l(this,ae).values()){const{x:i,y:n,width:r,height:o}=s.div.getBoundingClientRect();if(t>=i&&t<=i+r&&e>=n&&e<=n+o)return s}return null}disableUserSelect(t=!1){l(this,dl).classList.toggle("noUserSelect",t)}addShouldRescale(t){l(this,Br).add(t)}removeShouldRescale(t){l(this,Br).delete(t)}onScaleChanging({scale:t}){var e;this.commitOrRemove(),this.viewParameters.realScale=t*Ln.PDF_TO_CSS_UNITS;for(const s of l(this,Br))s.onScaleChanging();(e=l(this,Nr))==null||e.onScaleChanging()}onRotationChanging({pagesRotation:t}){this.commitOrRemove(),this.viewParameters.rotation=t}highlightSelection(t=""){const e=document.getSelection();if(!e||e.isCollapsed)return;const{anchorNode:s,anchorOffset:i,focusNode:n,focusOffset:r}=e,o=e.toString(),c=w(this,I,Pd).call(this,e).closest(".textLayer"),u=this.getSelectionBoxes(c);if(!u)return;e.empty();const d=w(this,I,Qg).call(this,c),f=l(this,ee)===Z.NONE,g=()=>{d==null||d.createAndAddNewEditor({x:0,y:0},!1,{methodOfCreation:t,boxes:u,anchorNode:s,anchorOffset:i,focusNode:n,focusOffset:r,text:o}),f&&this.showAllEditors("highlight",!0,!0)};if(f){this.switchToMode(Z.HIGHLIGHT,g);return}g()}addToAnnotationStorage(t){!t.isEmpty()&&l(this,Ui)&&!l(this,Ui).has(t.id)&&l(this,Ui).setValue(t.id,t)}blur(){if(this.isShiftKeyDown=!1,l(this,Gn)&&(m(this,Gn,!1),w(this,I,Dd).call(this,"main_toolbar")),!this.hasSelection)return;const{activeElement:t}=document;for(const e of l(this,pt))if(e.div.contains(t)){m(this,Hr,[e,t]),e._focusEventsAllowed=!1;break}}focus(){if(!l(this,Hr))return;const[t,e]=l(this,Hr);m(this,Hr,null),e.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this._signal}),e.focus()}addEditListeners(){w(this,I,Jg).call(this),w(this,I,Zg).call(this)}removeEditListeners(){w(this,I,ay).call(this),w(this,I,tp).call(this)}dragOver(t){for(const{type:e}of t.dataTransfer.items)for(const s of l(this,Vs))if(s.isHandlingMimeForPasting(e)){t.dataTransfer.dropEffect="copy",t.preventDefault();return}}drop(t){for(const e of t.dataTransfer.items)for(const s of l(this,Vs))if(s.isHandlingMimeForPasting(e.type)){s.paste(e,this.currentLayer),t.preventDefault();return}}copy(t){var s;if(t.preventDefault(),(s=l(this,ss))==null||s.commitOrRemove(),!this.hasSelection)return;const e=[];for(const i of l(this,pt)){const n=i.serialize(!0);n&&e.push(n)}e.length!==0&&t.clipboardData.setData("application/pdfjs",JSON.stringify(e))}cut(t){this.copy(t),this.delete()}async paste(t){t.preventDefault();const{clipboardData:e}=t;for(const n of e.items)for(const r of l(this,Vs))if(r.isHandlingMimeForPasting(n.type)){r.paste(n,this.currentLayer);return}let s=e.getData("application/pdfjs");if(!s)return;try{s=JSON.parse(s)}catch(n){tt(`paste: "${n.message}".`);return}if(!Array.isArray(s))return;this.unselectAll();const i=this.currentLayer;try{const n=[];for(const h of s){const c=await i.deserialize(h);if(!c)return;n.push(c)}const r=()=>{for(const h of n)w(this,I,ep).call(this,h);w(this,I,sp).call(this,n)},o=()=>{for(const h of n)h.remove()};this.addCommands({cmd:r,undo:o,mustExec:!0})}catch(n){tt(`paste: "${n.message}".`)}}keydown(t){!this.isShiftKeyDown&&t.key==="Shift"&&(this.isShiftKeyDown=!0),l(this,ee)!==Z.NONE&&!this.isEditorHandlingKeyboard&&ma._keyboardManager.exec(this,t)}keyup(t){this.isShiftKeyDown&&t.key==="Shift"&&(this.isShiftKeyDown=!1,l(this,Gn)&&(m(this,Gn,!1),w(this,I,Dd).call(this,"main_toolbar")))}onEditingAction({name:t}){switch(t){case"undo":case"redo":case"delete":case"selectAll":this[t]();break;case"highlightSelection":this.highlightSelection("context_menu");break}}setEditingState(t){t?(w(this,I,ry).call(this),w(this,I,Zg).call(this),w(this,I,ze).call(this,{isEditing:l(this,ee)!==Z.NONE,isEmpty:w(this,I,Cc).call(this),hasSomethingToUndo:l(this,ws).hasSomethingToUndo(),hasSomethingToRedo:l(this,ws).hasSomethingToRedo(),hasSelectedEditor:!1})):(w(this,I,oy).call(this),w(this,I,tp).call(this),w(this,I,ze).call(this,{isEditing:!1}),this.disableUserSelect(!1))}registerEditorTypes(t){if(!l(this,Vs)){m(this,Vs,t);for(const e of l(this,Vs))w(this,I,xn).call(this,e.defaultPropertiesToUpdate)}}getId(){return l(this,ud).id}get currentLayer(){return l(this,ae).get(l(this,fa))}getLayer(t){return l(this,ae).get(t)}get currentPageIndex(){return l(this,fa)}addLayer(t){l(this,ae).set(t.pageIndex,t),l(this,zn)?t.enable():t.disable()}removeLayer(t){l(this,ae).delete(t.pageIndex)}async updateMode(t,e=null,s=!1){var i;if(l(this,ee)!==t&&!(l(this,xs)&&(await l(this,xs).promise,!l(this,xs)))){if(m(this,xs,Promise.withResolvers()),m(this,ee,t),t===Z.NONE){this.setEditingState(!1),w(this,I,cy).call(this),(i=this._editorUndoBar)==null||i.hide(),l(this,xs).resolve();return}this.setEditingState(!0),await w(this,I,ly).call(this),this.unselectAll();for(const n of l(this,ae).values())n.updateMode(t);if(!e){s&&this.addNewEditorFromKeyboard(),l(this,xs).resolve();return}for(const n of l(this,Kt).values())n.annotationElementId===e?(this.setSelected(n),n.enterInEditMode()):n.unselect();l(this,xs).resolve()}}addNewEditorFromKeyboard(){this.currentLayer.canCreateNewEmptyEditor()&&this.currentLayer.addNewEditor()}updateToolbar(t){t!==l(this,ee)&&this._eventBus.dispatch("switchannotationeditormode",{source:this,mode:t})}updateParams(t,e){var s;if(l(this,Vs)){switch(t){case ot.CREATE:this.currentLayer.addNewEditor();return;case ot.HIGHLIGHT_DEFAULT_COLOR:(s=l(this,hl))==null||s.updateColor(e);break;case ot.HIGHLIGHT_SHOW_ALL:this._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:{type:"highlight",action:"toggle_visibility"}}}),(l(this,cl)||m(this,cl,new Map)).set(t,e),this.showAllEditors("highlight",e);break}for(const i of l(this,pt))i.updateParams(t,e);for(const i of l(this,Vs))i.updateDefaultParams(t,e)}}showAllEditors(t,e,s=!1){var n;for(const r of l(this,Kt).values())r.editorType===t&&r.show(e);(((n=l(this,cl))==null?void 0:n.get(ot.HIGHLIGHT_SHOW_ALL))??!0)!==e&&w(this,I,xn).call(this,[[ot.HIGHLIGHT_SHOW_ALL,e]])}enableWaiting(t=!1){if(l(this,al)!==t){m(this,al,t);for(const e of l(this,ae).values())t?e.disableClick():e.enableClick(),e.div.classList.toggle("waiting",t)}}getEditors(t){const e=[];for(const s of l(this,Kt).values())s.pageIndex===t&&e.push(s);return e}getEditor(t){return l(this,Kt).get(t)}addEditor(t){l(this,Kt).set(t.id,t)}removeEditor(t){var e;t.div.contains(document.activeElement)&&(l(this,di)&&clearTimeout(l(this,di)),m(this,di,setTimeout(()=>{this.focusMainContainer(),m(this,di,null)},0))),l(this,Kt).delete(t.id),this.unselect(t),(!t.annotationElementId||!l(this,jr).has(t.annotationElementId))&&((e=l(this,Ui))==null||e.remove(t.id))}addDeletedAnnotationElement(t){l(this,jr).add(t.annotationElementId),this.addChangedExistingAnnotation(t),t.deleted=!0}isDeletedAnnotationElement(t){return l(this,jr).has(t)}removeDeletedAnnotationElement(t){l(this,jr).delete(t.annotationElementId),this.removeChangedExistingAnnotation(t),t.deleted=!1}setActiveEditor(t){l(this,ss)!==t&&(m(this,ss,t),t&&w(this,I,xn).call(this,t.propertiesToUpdate))}updateUI(t){l(this,I,uy)===t&&w(this,I,xn).call(this,t.propertiesToUpdate)}updateUIForDefaultProperties(t){w(this,I,xn).call(this,t.defaultPropertiesToUpdate)}toggleSelected(t){if(l(this,pt).has(t)){l(this,pt).delete(t),t.unselect(),w(this,I,ze).call(this,{hasSelectedEditor:this.hasSelection});return}l(this,pt).add(t),t.select(),w(this,I,xn).call(this,t.propertiesToUpdate),w(this,I,ze).call(this,{hasSelectedEditor:!0})}setSelected(t){var e;(e=l(this,Nr))==null||e.commitOrRemove();for(const s of l(this,pt))s!==t&&s.unselect();l(this,pt).clear(),l(this,pt).add(t),t.select(),w(this,I,xn).call(this,t.propertiesToUpdate),w(this,I,ze).call(this,{hasSelectedEditor:!0})}isSelected(t){return l(this,pt).has(t)}get firstSelectedEditor(){return l(this,pt).values().next().value}unselect(t){t.unselect(),l(this,pt).delete(t),w(this,I,ze).call(this,{hasSelectedEditor:this.hasSelection})}get hasSelection(){return l(this,pt).size!==0}get isEnterHandled(){return l(this,pt).size===1&&this.firstSelectedEditor.isEnterHandled}undo(){var t;l(this,ws).undo(),w(this,I,ze).call(this,{hasSomethingToUndo:l(this,ws).hasSomethingToUndo(),hasSomethingToRedo:!0,isEmpty:w(this,I,Cc).call(this)}),(t=this._editorUndoBar)==null||t.hide()}redo(){l(this,ws).redo(),w(this,I,ze).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:l(this,ws).hasSomethingToRedo(),isEmpty:w(this,I,Cc).call(this)})}addCommands(t){l(this,ws).add(t),w(this,I,ze).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:!1,isEmpty:w(this,I,Cc).call(this)})}cleanUndoStack(t){l(this,ws).cleanType(t)}delete(){var n;this.commitOrRemove();const t=(n=this.currentLayer)==null?void 0:n.endDrawingSession(!0);if(!this.hasSelection&&!t)return;const e=t?[t]:[...l(this,pt)],s=()=>{var r;(r=this._editorUndoBar)==null||r.show(i,e.length===1?e[0].editorType:e.length);for(const o of e)o.remove()},i=()=>{for(const r of e)w(this,I,ep).call(this,r)};this.addCommands({cmd:s,undo:i,mustExec:!0})}commitOrRemove(){var t;(t=l(this,ss))==null||t.commitOrRemove()}hasSomethingToControl(){return l(this,ss)||this.hasSelection}selectAll(){for(const t of l(this,pt))t.commit();w(this,I,sp).call(this,l(this,Kt).values())}unselectAll(){var t;if(!(l(this,ss)&&(l(this,ss).commitOrRemove(),l(this,ee)!==Z.NONE))&&!((t=l(this,Nr))!=null&&t.commitOrRemove())&&this.hasSelection){for(const e of l(this,pt))e.unselect();l(this,pt).clear(),w(this,I,ze).call(this,{hasSelectedEditor:!1})}}translateSelectedEditors(t,e,s=!1){if(s||this.commitOrRemove(),!this.hasSelection)return;l(this,Xn)[0]+=t,l(this,Xn)[1]+=e;const[i,n]=l(this,Xn),r=[...l(this,pt)],o=1e3;l(this,gi)&&clearTimeout(l(this,gi)),m(this,gi,setTimeout(()=>{m(this,gi,null),l(this,Xn)[0]=l(this,Xn)[1]=0,this.addCommands({cmd:()=>{for(const h of r)l(this,Kt).has(h.id)&&h.translateInPage(i,n)},undo:()=>{for(const h of r)l(this,Kt).has(h.id)&&h.translateInPage(-i,-n)},mustExec:!1})},o));for(const h of r)h.translateInPage(t,e)}setUpDragSession(){if(this.hasSelection){this.disableUserSelect(!0),m(this,ui,new Map);for(const t of l(this,pt))l(this,ui).set(t,{savedX:t.x,savedY:t.y,savedPageIndex:t.pageIndex,newX:0,newY:0,newPageIndex:-1})}}endDragSession(){if(!l(this,ui))return!1;this.disableUserSelect(!1);const t=l(this,ui);m(this,ui,null);let e=!1;for(const[{x:i,y:n,pageIndex:r},o]of t)o.newX=i,o.newY=n,o.newPageIndex=r,e||(e=i!==o.savedX||n!==o.savedY||r!==o.savedPageIndex);if(!e)return!1;const s=(i,n,r,o)=>{if(l(this,Kt).has(i.id)){const h=l(this,ae).get(o);h?i._setParentAndPosition(h,n,r):(i.pageIndex=o,i.x=n,i.y=r)}};return this.addCommands({cmd:()=>{for(const[i,{newX:n,newY:r,newPageIndex:o}]of t)s(i,n,r,o)},undo:()=>{for(const[i,{savedX:n,savedY:r,savedPageIndex:o}]of t)s(i,n,r,o)},mustExec:!0}),!0}dragSelectedEditors(t,e){if(l(this,ui))for(const s of l(this,ui).keys())s.drag(t,e)}rebuild(t){if(t.parent===null){const e=this.getLayer(t.pageIndex);e?(e.changeParent(t),e.addOrRebuild(t)):(this.addEditor(t),this.addToAnnotationStorage(t),t.rebuild())}else t.parent.addOrRebuild(t)}get isEditorHandlingKeyboard(){var t;return((t=this.getActive())==null?void 0:t.shouldGetKeyboardEvents())||l(this,pt).size===1&&this.firstSelectedEditor.shouldGetKeyboardEvents()}isActive(t){return l(this,ss)===t}getActive(){return l(this,ss)}getMode(){return l(this,ee)}get imageManager(){return st(this,"imageManager",new yg)}getSelectionBoxes(t){if(!t)return null;const e=document.getSelection();for(let c=0,u=e.rangeCount;c<u;c++)if(!t.contains(e.getRangeAt(c).commonAncestorContainer))return null;const{x:s,y:i,width:n,height:r}=t.getBoundingClientRect();let o;switch(t.getAttribute("data-main-rotation")){case"90":o=(c,u,d,f)=>({x:(u-i)/r,y:1-(c+d-s)/n,width:f/r,height:d/n});break;case"180":o=(c,u,d,f)=>({x:1-(c+d-s)/n,y:1-(u+f-i)/r,width:d/n,height:f/r});break;case"270":o=(c,u,d,f)=>({x:1-(u+f-i)/r,y:(c-s)/n,width:f/r,height:d/n});break;default:o=(c,u,d,f)=>({x:(c-s)/n,y:(u-i)/r,width:d/n,height:f/r});break}const h=[];for(let c=0,u=e.rangeCount;c<u;c++){const d=e.getRangeAt(c);if(!d.collapsed)for(const{x:f,y:g,width:p,height:b}of d.getClientRects())p===0||b===0||h.push(o(f,g,p,b))}return h.length===0?null:h}addChangedExistingAnnotation({annotationElementId:t,id:e}){(l(this,da)||m(this,da,new Map)).set(t,e)}removeChangedExistingAnnotation({annotationElementId:t}){var e;(e=l(this,da))==null||e.delete(t)}renderAnnotationElement(t){var i;const e=(i=l(this,da))==null?void 0:i.get(t.data.id);if(!e)return;const s=l(this,Ui).getRawValue(e);s&&(l(this,ee)===Z.NONE&&!s.hasBeenModified||s.renderAnnotationElement(t))}};ca=new WeakMap,ss=new WeakMap,Kt=new WeakMap,ae=new WeakMap,ua=new WeakMap,Ui=new WeakMap,da=new WeakMap,ws=new WeakMap,Bn=new WeakMap,Nr=new WeakMap,fa=new WeakMap,jr=new WeakMap,ui=new WeakMap,Vs=new WeakMap,Br=new WeakMap,nl=new WeakMap,rl=new WeakMap,ga=new WeakMap,ol=new WeakMap,di=new WeakMap,Hn=new WeakMap,pa=new WeakMap,Gn=new WeakMap,fi=new WeakMap,ud=new WeakMap,zn=new WeakMap,al=new WeakMap,Vn=new WeakMap,Hr=new WeakMap,hl=new WeakMap,ll=new WeakMap,ee=new WeakMap,pt=new WeakMap,Yi=new WeakMap,Gr=new WeakMap,cl=new WeakMap,ul=new WeakMap,Xn=new WeakMap,gi=new WeakMap,$i=new WeakMap,dl=new WeakMap,xs=new WeakMap,I=new WeakSet,Pd=function({anchorNode:t}){return t.nodeType===Node.TEXT_NODE?t.parentElement:t},Qg=function(t){const{currentLayer:e}=this;if(e.hasTextLayer(t))return e;for(const s of l(this,ae).values())if(s.hasTextLayer(t))return s;return null},sy=function(){const t=document.getSelection();if(!t||t.isCollapsed)return;const s=w(this,I,Pd).call(this,t).closest(".textLayer"),i=this.getSelectionBoxes(s);i&&(l(this,fi)||m(this,fi,new fx(this)),l(this,fi).show(s,i,this.direction==="ltr"))},iy=function(){var n,r,o;const t=document.getSelection();if(!t||t.isCollapsed){l(this,Yi)&&((n=l(this,fi))==null||n.hide(),m(this,Yi,null),w(this,I,ze).call(this,{hasSelectedText:!1}));return}const{anchorNode:e}=t;if(e===l(this,Yi))return;const i=w(this,I,Pd).call(this,t).closest(".textLayer");if(!i){l(this,Yi)&&((r=l(this,fi))==null||r.hide(),m(this,Yi,null),w(this,I,ze).call(this,{hasSelectedText:!1}));return}if((o=l(this,fi))==null||o.hide(),m(this,Yi,e),w(this,I,ze).call(this,{hasSelectedText:!0}),!(l(this,ee)!==Z.HIGHLIGHT&&l(this,ee)!==Z.NONE)&&(l(this,ee)===Z.HIGHLIGHT&&this.showAllEditors("highlight",!0,!0),m(this,Gn,this.isShiftKeyDown),!this.isShiftKeyDown)){const h=l(this,ee)===Z.HIGHLIGHT?w(this,I,Qg).call(this,i):null;h==null||h.toggleDrawing();const c=new AbortController,u=this.combinedSignal(c),d=f=>{f.type==="pointerup"&&f.button!==0||(c.abort(),h==null||h.toggleDrawing(!0),f.type==="pointerup"&&w(this,I,Dd).call(this,"main_toolbar"))};window.addEventListener("pointerup",d,{signal:u}),window.addEventListener("blur",d,{signal:u})}},Dd=function(t=""){l(this,ee)===Z.HIGHLIGHT?this.highlightSelection(t):l(this,nl)&&w(this,I,sy).call(this)},ny=function(){document.addEventListener("selectionchange",w(this,I,iy).bind(this),{signal:this._signal})},ry=function(){if(l(this,Hn))return;m(this,Hn,new AbortController);const t=this.combinedSignal(l(this,Hn));window.addEventListener("focus",this.focus.bind(this),{signal:t}),window.addEventListener("blur",this.blur.bind(this),{signal:t})},oy=function(){var t;(t=l(this,Hn))==null||t.abort(),m(this,Hn,null)},Jg=function(){if(l(this,Vn))return;m(this,Vn,new AbortController);const t=this.combinedSignal(l(this,Vn));window.addEventListener("keydown",this.keydown.bind(this),{signal:t}),window.addEventListener("keyup",this.keyup.bind(this),{signal:t})},ay=function(){var t;(t=l(this,Vn))==null||t.abort(),m(this,Vn,null)},Zg=function(){if(l(this,Bn))return;m(this,Bn,new AbortController);const t=this.combinedSignal(l(this,Bn));document.addEventListener("copy",this.copy.bind(this),{signal:t}),document.addEventListener("cut",this.cut.bind(this),{signal:t}),document.addEventListener("paste",this.paste.bind(this),{signal:t})},tp=function(){var t;(t=l(this,Bn))==null||t.abort(),m(this,Bn,null)},hy=function(){const t=this._signal;document.addEventListener("dragover",this.dragOver.bind(this),{signal:t}),document.addEventListener("drop",this.drop.bind(this),{signal:t})},ze=function(t){Object.entries(t).some(([s,i])=>l(this,ul)[s]!==i)&&(this._eventBus.dispatch("annotationeditorstateschanged",{source:this,details:Object.assign(l(this,ul),t)}),l(this,ee)===Z.HIGHLIGHT&&t.hasSelectedEditor===!1&&w(this,I,xn).call(this,[[ot.HIGHLIGHT_FREE,!0]]))},xn=function(t){this._eventBus.dispatch("annotationeditorparamschanged",{source:this,details:t})},ly=async function(){if(!l(this,zn)){m(this,zn,!0);const t=[];for(const e of l(this,ae).values())t.push(e.enable());await Promise.all(t);for(const e of l(this,Kt).values())e.enable()}},cy=function(){if(this.unselectAll(),l(this,zn)){m(this,zn,!1);for(const t of l(this,ae).values())t.disable();for(const t of l(this,Kt).values())t.disable()}},ep=function(t){const e=l(this,ae).get(t.pageIndex);e?e.addOrRebuild(t):(this.addEditor(t),this.addToAnnotationStorage(t))},uy=function(){let t=null;for(t of l(this,pt));return t},Cc=function(){if(l(this,Kt).size===0)return!0;if(l(this,Kt).size===1)for(const t of l(this,Kt).values())return t.isEmpty();return!1},sp=function(t){for(const e of l(this,pt))e.unselect();l(this,pt).clear();for(const e of t)e.isEmpty()||(l(this,pt).add(e),e.select());w(this,I,ze).call(this,{hasSelectedEditor:this.hasSelection})},$(ma,"TRANSLATE_SMALL",1),$(ma,"TRANSLATE_BIG",10);let Mr=ma;const Fe=class Fe{constructor(t){y(this,Ws);y(this,se,null);y(this,pi,!1);y(this,Xs,null);y(this,ba,null);y(this,mi,null);y(this,is,null);y(this,ya,!1);y(this,bi,null);y(this,$e,null);y(this,qi,null);y(this,zr,null);y(this,yi,!1);m(this,$e,t),m(this,yi,t._uiManager.useNewAltTextFlow),l(Fe,Wn)||m(Fe,Wn,Object.freeze({added:"pdfjs-editor-new-alt-text-added-button","added-label":"pdfjs-editor-new-alt-text-added-button-label",missing:"pdfjs-editor-new-alt-text-missing-button","missing-label":"pdfjs-editor-new-alt-text-missing-button-label",review:"pdfjs-editor-new-alt-text-to-review-button","review-label":"pdfjs-editor-new-alt-text-to-review-button-label"}))}static initialize(t){Fe._l10n??(Fe._l10n=t)}async render(){const t=m(this,Xs,document.createElement("button"));t.className="altText",t.tabIndex="0";const e=m(this,ba,document.createElement("span"));t.append(e),l(this,yi)?(t.classList.add("new"),t.setAttribute("data-l10n-id",l(Fe,Wn).missing),e.setAttribute("data-l10n-id",l(Fe,Wn)["missing-label"])):(t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button"),e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button-label"));const s=l(this,$e)._uiManager._signal;t.addEventListener("contextmenu",Gs,{signal:s}),t.addEventListener("pointerdown",n=>n.stopPropagation(),{signal:s});const i=n=>{n.preventDefault(),l(this,$e)._uiManager.editAltText(l(this,$e)),l(this,yi)&&l(this,$e)._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_clicked",data:{label:l(this,Ws,Ac)}})};return t.addEventListener("click",i,{capture:!0,signal:s}),t.addEventListener("keydown",n=>{n.target===t&&n.key==="Enter"&&(m(this,ya,!0),i(n))},{signal:s}),await w(this,Ws,Od).call(this),t}finish(){l(this,Xs)&&(l(this,Xs).focus({focusVisible:l(this,ya)}),m(this,ya,!1))}isEmpty(){return l(this,yi)?l(this,se)===null:!l(this,se)&&!l(this,pi)}hasData(){return l(this,yi)?l(this,se)!==null||!!l(this,qi):this.isEmpty()}get guessedText(){return l(this,qi)}async setGuessedText(t){l(this,se)===null&&(m(this,qi,t),m(this,zr,await Fe._l10n.get("pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer",{generatedAltText:t})),w(this,Ws,Od).call(this))}toggleAltTextBadge(t=!1){var e;if(!l(this,yi)||l(this,se)){(e=l(this,bi))==null||e.remove(),m(this,bi,null);return}if(!l(this,bi)){const s=m(this,bi,document.createElement("div"));s.className="noAltTextBadge",l(this,$e).div.append(s)}l(this,bi).classList.toggle("hidden",!t)}serialize(t){let e=l(this,se);return!t&&l(this,qi)===e&&(e=l(this,zr)),{altText:e,decorative:l(this,pi),guessedText:l(this,qi),textWithDisclaimer:l(this,zr)}}get data(){return{altText:l(this,se),decorative:l(this,pi)}}set data({altText:t,decorative:e,guessedText:s,textWithDisclaimer:i,cancel:n=!1}){s&&(m(this,qi,s),m(this,zr,i)),!(l(this,se)===t&&l(this,pi)===e)&&(n||(m(this,se,t),m(this,pi,e)),w(this,Ws,Od).call(this))}toggle(t=!1){l(this,Xs)&&(!t&&l(this,is)&&(clearTimeout(l(this,is)),m(this,is,null)),l(this,Xs).disabled=!t)}shown(){l(this,$e)._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_displayed",data:{label:l(this,Ws,Ac)}})}destroy(){var t,e;(t=l(this,Xs))==null||t.remove(),m(this,Xs,null),m(this,ba,null),m(this,mi,null),(e=l(this,bi))==null||e.remove(),m(this,bi,null)}};se=new WeakMap,pi=new WeakMap,Xs=new WeakMap,ba=new WeakMap,mi=new WeakMap,is=new WeakMap,ya=new WeakMap,bi=new WeakMap,$e=new WeakMap,qi=new WeakMap,zr=new WeakMap,yi=new WeakMap,Wn=new WeakMap,Ws=new WeakSet,Ac=function(){return l(this,se)&&"added"||l(this,se)===null&&this.guessedText&&"review"||"missing"},Od=async function(){var i,n,r;const t=l(this,Xs);if(!t)return;if(l(this,yi)){if(t.classList.toggle("done",!!l(this,se)),t.setAttribute("data-l10n-id",l(Fe,Wn)[l(this,Ws,Ac)]),(i=l(this,ba))==null||i.setAttribute("data-l10n-id",l(Fe,Wn)[`${l(this,Ws,Ac)}-label`]),!l(this,se)){(n=l(this,mi))==null||n.remove();return}}else{if(!l(this,se)&&!l(this,pi)){t.classList.remove("done"),(r=l(this,mi))==null||r.remove();return}t.classList.add("done"),t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-edit-button")}let e=l(this,mi);if(!e){m(this,mi,e=document.createElement("span")),e.className="tooltip",e.setAttribute("role","tooltip"),e.id=`alt-text-tooltip-${l(this,$e).id}`;const o=100,h=l(this,$e)._uiManager._signal;h.addEventListener("abort",()=>{clearTimeout(l(this,is)),m(this,is,null)},{once:!0}),t.addEventListener("mouseenter",()=>{m(this,is,setTimeout(()=>{m(this,is,null),l(this,mi).classList.add("show"),l(this,$e)._reportTelemetry({action:"alt_text_tooltip"})},o))},{signal:h}),t.addEventListener("mouseleave",()=>{var c;l(this,is)&&(clearTimeout(l(this,is)),m(this,is,null)),(c=l(this,mi))==null||c.classList.remove("show")},{signal:h})}l(this,pi)?e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-decorative-tooltip"):(e.removeAttribute("data-l10n-id"),e.textContent=l(this,se)),e.parentNode||t.append(e);const s=l(this,$e).getImageForAltText();s==null||s.setAttribute("aria-describedby",e.id)},y(Fe,Wn,null),$(Fe,"_l10n",null);let qu=Fe;const Vg=class Vg{constructor({container:t,isPinchingDisabled:e=null,isPinchingStopped:s=null,onPinchStart:i=null,onPinching:n=null,onPinchEnd:r=null,signal:o}){y(this,Qi);y(this,fl);y(this,Vr,!1);y(this,gl,null);y(this,pl);y(this,ml);y(this,bl);y(this,yl);y(this,va);y(this,Ki,null);y(this,Xr);y(this,Un,null);m(this,fl,t),m(this,gl,s),m(this,pl,e),m(this,ml,i),m(this,bl,n),m(this,yl,r),m(this,Xr,new AbortController),m(this,va,AbortSignal.any([o,l(this,Xr).signal])),t.addEventListener("touchstart",w(this,Qi,dy).bind(this),{passive:!1,signal:l(this,va)})}get MIN_TOUCH_DISTANCE_TO_PINCH(){return st(this,"MIN_TOUCH_DISTANCE_TO_PINCH",35/(window.devicePixelRatio||1))}destroy(){var t;(t=l(this,Xr))==null||t.abort(),m(this,Xr,null)}};fl=new WeakMap,Vr=new WeakMap,gl=new WeakMap,pl=new WeakMap,ml=new WeakMap,bl=new WeakMap,yl=new WeakMap,va=new WeakMap,Ki=new WeakMap,Xr=new WeakMap,Un=new WeakMap,Qi=new WeakSet,dy=function(t){var i,n,r;if((i=l(this,pl))!=null&&i.call(this)||t.touches.length<2)return;if(!l(this,Un)){m(this,Un,new AbortController);const o=AbortSignal.any([l(this,va),l(this,Un).signal]),h=l(this,fl),c={signal:o,passive:!1};h.addEventListener("touchmove",w(this,Qi,fy).bind(this),c),h.addEventListener("touchend",w(this,Qi,ip).bind(this),c),h.addEventListener("touchcancel",w(this,Qi,ip).bind(this),c),(n=l(this,ml))==null||n.call(this)}if(es(t),t.touches.length!==2||(r=l(this,gl))!=null&&r.call(this)){m(this,Ki,null);return}let[e,s]=t.touches;e.identifier>s.identifier&&([e,s]=[s,e]),m(this,Ki,{touch0X:e.screenX,touch0Y:e.screenY,touch1X:s.screenX,touch1Y:s.screenY})},fy=function(t){var S;if(!l(this,Ki)||t.touches.length!==2)return;let[e,s]=t.touches;e.identifier>s.identifier&&([e,s]=[s,e]);const{screenX:i,screenY:n}=e,{screenX:r,screenY:o}=s,h=l(this,Ki),{touch0X:c,touch0Y:u,touch1X:d,touch1Y:f}=h,g=d-c,p=f-u,b=r-i,v=o-n,_=Math.hypot(b,v)||1,x=Math.hypot(g,p)||1;if(!l(this,Vr)&&Math.abs(x-_)<=Vg.MIN_TOUCH_DISTANCE_TO_PINCH)return;if(h.touch0X=i,h.touch0Y=n,h.touch1X=r,h.touch1Y=o,t.preventDefault(),!l(this,Vr)){m(this,Vr,!0);return}const C=[(i+r)/2,(n+o)/2];(S=l(this,bl))==null||S.call(this,C,x,_)},ip=function(t){var e;l(this,Un).abort(),m(this,Un,null),(e=l(this,yl))==null||e.call(this),l(this,Ki)&&(t.preventDefault(),m(this,Ki,null),m(this,Vr,!1))};let Ku=Vg;const et=class et{constructor(t){y(this,Y);y(this,Wr,null);y(this,Us,null);y(this,xt,null);y(this,_a,!1);y(this,Yn,null);y(this,vl,"");y(this,Ur,!1);y(this,he,null);y(this,Yr,null);y(this,Ji,null);y(this,$n,null);y(this,_l,"");y(this,$r,!1);y(this,ns,null);y(this,wl,!1);y(this,qr,!1);y(this,Zi,!1);y(this,vi,null);y(this,wa,0);y(this,xa,0);y(this,Ss,null);y(this,Kr,null);$(this,"_editToolbar",null);$(this,"_initialOptions",Object.create(null));$(this,"_initialData",null);$(this,"_isVisible",!0);$(this,"_uiManager",null);$(this,"_focusEventsAllowed",!0);y(this,xl,!1);y(this,dd,et._zIndex++);this.parent=t.parent,this.id=t.id,this.width=this.height=null,this.pageIndex=t.parent.pageIndex,this.name=t.name,this.div=null,this._uiManager=t.uiManager,this.annotationElementId=null,this._willKeepAspectRatio=!1,this._initialOptions.isCentered=t.isCentered,this._structTreeParentId=null;const{rotation:e,rawDims:{pageWidth:s,pageHeight:i,pageX:n,pageY:r}}=this.parent.viewport;this.rotation=e,this.pageRotation=(360+e-this._uiManager.viewParameters.rotation)%360,this.pageDimensions=[s,i],this.pageTranslation=[n,r];const[o,h]=this.parentDimensions;this.x=t.x/o,this.y=t.y/h,this.isAttachedToDOM=!1,this.deleted=!1}static get _resizerKeyboardManager(){const t=et.prototype._resizeWithKeyboard,e=Mr.TRANSLATE_SMALL,s=Mr.TRANSLATE_BIG;return st(this,"_resizerKeyboardManager",new Xh([[["ArrowLeft","mac+ArrowLeft"],t,{args:[-e,0]}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],t,{args:[-s,0]}],[["ArrowRight","mac+ArrowRight"],t,{args:[e,0]}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],t,{args:[s,0]}],[["ArrowUp","mac+ArrowUp"],t,{args:[0,-e]}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],t,{args:[0,-s]}],[["ArrowDown","mac+ArrowDown"],t,{args:[0,e]}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],t,{args:[0,s]}],[["Escape","mac+Escape"],et.prototype._stopResizingWithKeyboard]]))}get editorType(){return Object.getPrototypeOf(this).constructor._type}static get isDrawer(){return!1}static get _defaultLineColor(){return st(this,"_defaultLineColor",this._colorManager.getHexCode("CanvasText"))}static deleteAnnotationElement(t){const e=new mx({id:t.parent.getNextId(),parent:t.parent,uiManager:t._uiManager});e.annotationElementId=t.annotationElementId,e.deleted=!0,e._uiManager.addToAnnotationStorage(e)}static initialize(t,e){if(et._l10n??(et._l10n=t),et._l10nResizer||(et._l10nResizer=Object.freeze({topLeft:"pdfjs-editor-resizer-top-left",topMiddle:"pdfjs-editor-resizer-top-middle",topRight:"pdfjs-editor-resizer-top-right",middleRight:"pdfjs-editor-resizer-middle-right",bottomRight:"pdfjs-editor-resizer-bottom-right",bottomMiddle:"pdfjs-editor-resizer-bottom-middle",bottomLeft:"pdfjs-editor-resizer-bottom-left",middleLeft:"pdfjs-editor-resizer-middle-left"})),et._borderLineWidth!==-1)return;const s=getComputedStyle(document.documentElement);et._borderLineWidth=parseFloat(s.getPropertyValue("--outline-width"))||0}static updateDefaultParams(t,e){}static get defaultPropertiesToUpdate(){return[]}static isHandlingMimeForPasting(t){return!1}static paste(t,e){vt("Not implemented")}get propertiesToUpdate(){return[]}get _isDraggable(){return l(this,xl)}set _isDraggable(t){var e;m(this,xl,t),(e=this.div)==null||e.classList.toggle("draggable",t)}get isEnterHandled(){return!0}center(){const[t,e]=this.pageDimensions;switch(this.parentRotation){case 90:this.x-=this.height*e/(t*2),this.y+=this.width*t/(e*2);break;case 180:this.x+=this.width/2,this.y+=this.height/2;break;case 270:this.x+=this.height*e/(t*2),this.y-=this.width*t/(e*2);break;default:this.x-=this.width/2,this.y-=this.height/2;break}this.fixAndSetPosition()}addCommands(t){this._uiManager.addCommands(t)}get currentLayer(){return this._uiManager.currentLayer}setInBackground(){this.div.style.zIndex=0}setInForeground(){this.div.style.zIndex=l(this,dd)}setParent(t){t!==null?(this.pageIndex=t.pageIndex,this.pageDimensions=t.pageDimensions):w(this,Y,Tc).call(this),this.parent=t}focusin(t){this._focusEventsAllowed&&(l(this,$r)?m(this,$r,!1):this.parent.setSelected(this))}focusout(t){var s;if(!this._focusEventsAllowed||!this.isAttachedToDOM)return;const e=t.relatedTarget;e!=null&&e.closest(`#${this.id}`)||(t.preventDefault(),(s=this.parent)!=null&&s.isMultipleSelection||this.commitOrRemove())}commitOrRemove(){this.isEmpty()?this.remove():this.commit()}commit(){this.addToAnnotationStorage()}addToAnnotationStorage(){this._uiManager.addToAnnotationStorage(this)}setAt(t,e,s,i){const[n,r]=this.parentDimensions;[s,i]=this.screenToPageTranslation(s,i),this.x=(t+s)/n,this.y=(e+i)/r,this.fixAndSetPosition()}translate(t,e){w(this,Y,np).call(this,this.parentDimensions,t,e)}translateInPage(t,e){l(this,ns)||m(this,ns,[this.x,this.y,this.width,this.height]),w(this,Y,np).call(this,this.pageDimensions,t,e),this.div.scrollIntoView({block:"nearest"})}drag(t,e){l(this,ns)||m(this,ns,[this.x,this.y,this.width,this.height]);const{div:s,parentDimensions:[i,n]}=this;if(this.x+=t/i,this.y+=e/n,this.parent&&(this.x<0||this.x>1||this.y<0||this.y>1)){const{x:d,y:f}=this.div.getBoundingClientRect();this.parent.findNewParent(this,d,f)&&(this.x-=Math.floor(this.x),this.y-=Math.floor(this.y))}let{x:r,y:o}=this;const[h,c]=this.getBaseTranslation();r+=h,o+=c;const{style:u}=s;u.left=`${(100*r).toFixed(2)}%`,u.top=`${(100*o).toFixed(2)}%`,this._onTranslating(r,o),s.scrollIntoView({block:"nearest"})}_onTranslating(t,e){}_onTranslated(t,e){}get _hasBeenMoved(){return!!l(this,ns)&&(l(this,ns)[0]!==this.x||l(this,ns)[1]!==this.y)}get _hasBeenResized(){return!!l(this,ns)&&(l(this,ns)[2]!==this.width||l(this,ns)[3]!==this.height)}getBaseTranslation(){const[t,e]=this.parentDimensions,{_borderLineWidth:s}=et,i=s/t,n=s/e;switch(this.rotation){case 90:return[-i,n];case 180:return[i,n];case 270:return[i,-n];default:return[-i,-n]}}get _mustFixPosition(){return!0}fixAndSetPosition(t=this.rotation){const{div:{style:e},pageDimensions:[s,i]}=this;let{x:n,y:r,width:o,height:h}=this;if(o*=s,h*=i,n*=s,r*=i,this._mustFixPosition)switch(t){case 0:n=Math.max(0,Math.min(s-o,n)),r=Math.max(0,Math.min(i-h,r));break;case 90:n=Math.max(0,Math.min(s-h,n)),r=Math.min(i,Math.max(o,r));break;case 180:n=Math.min(s,Math.max(o,n)),r=Math.min(i,Math.max(h,r));break;case 270:n=Math.min(s,Math.max(h,n)),r=Math.max(0,Math.min(i-o,r));break}this.x=n/=s,this.y=r/=i;const[c,u]=this.getBaseTranslation();n+=c,r+=u,e.left=`${(100*n).toFixed(2)}%`,e.top=`${(100*r).toFixed(2)}%`,this.moveInDOM()}screenToPageTranslation(t,e){var s;return w(s=et,Sl,rp).call(s,t,e,this.parentRotation)}pageTranslationToScreen(t,e){var s;return w(s=et,Sl,rp).call(s,t,e,360-this.parentRotation)}get parentScale(){return this._uiManager.viewParameters.realScale}get parentRotation(){return(this._uiManager.viewParameters.rotation+this.pageRotation)%360}get parentDimensions(){const{parentScale:t,pageDimensions:[e,s]}=this;return[e*t,s*t]}setDims(t,e){const[s,i]=this.parentDimensions,{style:n}=this.div;n.width=`${(100*t/s).toFixed(2)}%`,l(this,Ur)||(n.height=`${(100*e/i).toFixed(2)}%`)}fixDims(){const{style:t}=this.div,{height:e,width:s}=t,i=s.endsWith("%"),n=!l(this,Ur)&&e.endsWith("%");if(i&&n)return;const[r,o]=this.parentDimensions;i||(t.width=`${(100*parseFloat(s)/r).toFixed(2)}%`),!l(this,Ur)&&!n&&(t.height=`${(100*parseFloat(e)/o).toFixed(2)}%`)}getInitialTranslation(){return[0,0]}_onResized(){}static _round(t){return Math.round(t*1e4)/1e4}_onResizing(){}altTextFinish(){var t;(t=l(this,xt))==null||t.finish()}async addEditToolbar(){return this._editToolbar||l(this,qr)?this._editToolbar:(this._editToolbar=new bg(this),this.div.append(this._editToolbar.render()),l(this,xt)&&await this._editToolbar.addAltText(l(this,xt)),this._editToolbar)}removeEditToolbar(){var t;this._editToolbar&&(this._editToolbar.remove(),this._editToolbar=null,(t=l(this,xt))==null||t.destroy())}addContainer(t){var s;const e=(s=this._editToolbar)==null?void 0:s.div;e?e.before(t):this.div.append(t)}getClientDimensions(){return this.div.getBoundingClientRect()}async addAltTextButton(){l(this,xt)||(qu.initialize(et._l10n),m(this,xt,new qu(this)),l(this,Wr)&&(l(this,xt).data=l(this,Wr),m(this,Wr,null)),await this.addEditToolbar())}get altTextData(){var t;return(t=l(this,xt))==null?void 0:t.data}set altTextData(t){l(this,xt)&&(l(this,xt).data=t)}get guessedAltText(){var t;return(t=l(this,xt))==null?void 0:t.guessedText}async setGuessedAltText(t){var e;await((e=l(this,xt))==null?void 0:e.setGuessedText(t))}serializeAltText(t){var e;return(e=l(this,xt))==null?void 0:e.serialize(t)}hasAltText(){return!!l(this,xt)&&!l(this,xt).isEmpty()}hasAltTextData(){var t;return((t=l(this,xt))==null?void 0:t.hasData())??!1}render(){var n;this.div=document.createElement("div"),this.div.setAttribute("data-editor-rotation",(360-this.rotation)%360),this.div.className=this.name,this.div.setAttribute("id",this.id),this.div.tabIndex=l(this,_a)?-1:0,this._isVisible||this.div.classList.add("hidden"),this.setInForeground(),w(this,Y,lp).call(this);const[t,e]=this.parentDimensions;this.parentRotation%180!==0&&(this.div.style.maxWidth=`${(100*e/t).toFixed(2)}%`,this.div.style.maxHeight=`${(100*t/e).toFixed(2)}%`);const[s,i]=this.getInitialTranslation();return this.translate(s,i),$u(this,this.div,["pointerdown"]),this.isResizable&&this._uiManager._supportsPinchToZoom&&(l(this,Kr)||m(this,Kr,new Ku({container:this.div,isPinchingDisabled:()=>!this.isSelected,onPinchStart:w(this,Y,my).bind(this),onPinching:w(this,Y,by).bind(this),onPinchEnd:w(this,Y,yy).bind(this),signal:this._uiManager._signal}))),(n=this._uiManager._editorUndoBar)==null||n.hide(),this.div}pointerdown(t){const{isMac:e}=Re.platform;if(t.button!==0||t.ctrlKey&&e){t.preventDefault();return}if(m(this,$r,!0),this._isDraggable){w(this,Y,vy).call(this,t);return}w(this,Y,hp).call(this,t)}get isSelected(){return this._uiManager.isSelected(this)}_onStartDragging(){}_onStopDragging(){}moveInDOM(){l(this,vi)&&clearTimeout(l(this,vi)),m(this,vi,setTimeout(()=>{var t;m(this,vi,null),(t=this.parent)==null||t.moveEditorInDOM(this)},0))}_setParentAndPosition(t,e,s){t.changeParent(this),this.x=e,this.y=s,this.fixAndSetPosition(),this._onTranslated()}getRect(t,e,s=this.rotation){const i=this.parentScale,[n,r]=this.pageDimensions,[o,h]=this.pageTranslation,c=t/i,u=e/i,d=this.x*n,f=this.y*r,g=this.width*n,p=this.height*r;switch(s){case 0:return[d+c+o,r-f-u-p+h,d+c+g+o,r-f-u+h];case 90:return[d+u+o,r-f+c+h,d+u+p+o,r-f+c+g+h];case 180:return[d-c-g+o,r-f+u+h,d-c+o,r-f+u+p+h];case 270:return[d-u-p+o,r-f-c-g+h,d-u+o,r-f-c+h];default:throw new Error("Invalid rotation")}}getRectInCurrentCoords(t,e){const[s,i,n,r]=t,o=n-s,h=r-i;switch(this.rotation){case 0:return[s,e-r,o,h];case 90:return[s,e-i,h,o];case 180:return[n,e-i,o,h];case 270:return[n,e-r,h,o];default:throw new Error("Invalid rotation")}}onceAdded(t){}isEmpty(){return!1}enableEditMode(){m(this,qr,!0)}disableEditMode(){m(this,qr,!1)}isInEditMode(){return l(this,qr)}shouldGetKeyboardEvents(){return l(this,Zi)}needsToBeRebuilt(){return this.div&&!this.isAttachedToDOM}get isOnScreen(){const{top:t,left:e,bottom:s,right:i}=this.getClientDimensions(),{innerHeight:n,innerWidth:r}=window;return e<r&&i>0&&t<n&&s>0}rebuild(){w(this,Y,lp).call(this)}rotate(t){}resize(){}serializeDeleted(){var t;return{id:this.annotationElementId,deleted:!0,pageIndex:this.pageIndex,popupRef:((t=this._initialData)==null?void 0:t.popupRef)||""}}serialize(t=!1,e=null){vt("An editor must be serializable")}static async deserialize(t,e,s){const i=new this.prototype.constructor({parent:e,id:e.getNextId(),uiManager:s});i.rotation=t.rotation,m(i,Wr,t.accessibilityData);const[n,r]=i.pageDimensions,[o,h,c,u]=i.getRectInCurrentCoords(t.rect,r);return i.x=o/n,i.y=h/r,i.width=c/n,i.height=u/r,i}get hasBeenModified(){return!!this.annotationElementId&&(this.deleted||this.serialize()!==null)}remove(){var t,e;if((t=l(this,$n))==null||t.abort(),m(this,$n,null),this.isEmpty()||this.commit(),this.parent?this.parent.remove(this):this._uiManager.removeEditor(this),l(this,vi)&&(clearTimeout(l(this,vi)),m(this,vi,null)),w(this,Y,Tc).call(this),this.removeEditToolbar(),l(this,Ss)){for(const s of l(this,Ss).values())clearTimeout(s);m(this,Ss,null)}this.parent=null,(e=l(this,Kr))==null||e.destroy(),m(this,Kr,null)}get isResizable(){return!1}makeResizable(){this.isResizable&&(w(this,Y,gy).call(this),l(this,he).classList.remove("hidden"),$u(this,this.div,["keydown"]))}get toolbarPosition(){return null}keydown(t){if(!this.isResizable||t.target!==this.div||t.key!=="Enter")return;this._uiManager.setSelected(this),m(this,Ji,{savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height});const e=l(this,he).children;if(!l(this,Us)){m(this,Us,Array.from(e));const r=w(this,Y,_y).bind(this),o=w(this,Y,wy).bind(this),h=this._uiManager._signal;for(const c of l(this,Us)){const u=c.getAttribute("data-resizer-name");c.setAttribute("role","spinbutton"),c.addEventListener("keydown",r,{signal:h}),c.addEventListener("blur",o,{signal:h}),c.addEventListener("focus",w(this,Y,xy).bind(this,u),{signal:h}),c.setAttribute("data-l10n-id",et._l10nResizer[u])}}const s=l(this,Us)[0];let i=0;for(const r of e){if(r===s)break;i++}const n=(360-this.rotation+this.parentRotation)%360/90*(l(this,Us).length/4);if(n!==i){if(n<i)for(let o=0;o<i-n;o++)l(this,he).append(l(this,he).firstChild);else if(n>i)for(let o=0;o<n-i;o++)l(this,he).firstChild.before(l(this,he).lastChild);let r=0;for(const o of e){const c=l(this,Us)[r++].getAttribute("data-resizer-name");o.setAttribute("data-l10n-id",et._l10nResizer[c])}}w(this,Y,cp).call(this,0),m(this,Zi,!0),l(this,he).firstChild.focus({focusVisible:!0}),t.preventDefault(),t.stopImmediatePropagation()}_resizeWithKeyboard(t,e){l(this,Zi)&&w(this,Y,ap).call(this,l(this,_l),{deltaX:t,deltaY:e,fromKeyboard:!0})}_stopResizingWithKeyboard(){w(this,Y,Tc).call(this),this.div.focus()}select(){var t,e,s;if(this.makeResizable(),(t=this.div)==null||t.classList.add("selectedEditor"),!this._editToolbar){this.addEditToolbar().then(()=>{var i,n;(i=this.div)!=null&&i.classList.contains("selectedEditor")&&((n=this._editToolbar)==null||n.show())});return}(e=this._editToolbar)==null||e.show(),(s=l(this,xt))==null||s.toggleAltTextBadge(!1)}unselect(){var t,e,s,i,n;(t=l(this,he))==null||t.classList.add("hidden"),(e=this.div)==null||e.classList.remove("selectedEditor"),(s=this.div)!=null&&s.contains(document.activeElement)&&this._uiManager.currentLayer.div.focus({preventScroll:!0}),(i=this._editToolbar)==null||i.hide(),(n=l(this,xt))==null||n.toggleAltTextBadge(!0)}updateParams(t,e){}disableEditing(){}enableEditing(){}enterInEditMode(){}getImageForAltText(){return null}get contentDiv(){return this.div}get isEditing(){return l(this,wl)}set isEditing(t){m(this,wl,t),this.parent&&(t?(this.parent.setSelected(this),this.parent.setActiveEditor(this)):this.parent.setActiveEditor(null))}setAspectRatio(t,e){m(this,Ur,!0);const s=t/e,{style:i}=this.div;i.aspectRatio=s,i.height="auto"}static get MIN_SIZE(){return 16}static canCreateNewEmptyEditor(){return!0}get telemetryInitialData(){return{action:"added"}}get telemetryFinalData(){return null}_reportTelemetry(t,e=!1){if(e){l(this,Ss)||m(this,Ss,new Map);const{action:s}=t;let i=l(this,Ss).get(s);i&&clearTimeout(i),i=setTimeout(()=>{this._reportTelemetry(t),l(this,Ss).delete(s),l(this,Ss).size===0&&m(this,Ss,null)},et._telemetryTimeout),l(this,Ss).set(s,i);return}t.type||(t.type=this.editorType),this._uiManager._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:t}})}show(t=this._isVisible){this.div.classList.toggle("hidden",!t),this._isVisible=t}enable(){this.div&&(this.div.tabIndex=0),m(this,_a,!1)}disable(){this.div&&(this.div.tabIndex=-1),m(this,_a,!0)}renderAnnotationElement(t){let e=t.container.querySelector(".annotationContent");if(!e)e=document.createElement("div"),e.classList.add("annotationContent",this.editorType),t.container.prepend(e);else if(e.nodeName==="CANVAS"){const s=e;e=document.createElement("div"),e.classList.add("annotationContent",this.editorType),s.before(e)}return e}resetAnnotationElement(t){const{firstChild:e}=t.container;(e==null?void 0:e.nodeName)==="DIV"&&e.classList.contains("annotationContent")&&e.remove()}};Wr=new WeakMap,Us=new WeakMap,xt=new WeakMap,_a=new WeakMap,Yn=new WeakMap,vl=new WeakMap,Ur=new WeakMap,he=new WeakMap,Yr=new WeakMap,Ji=new WeakMap,$n=new WeakMap,_l=new WeakMap,$r=new WeakMap,ns=new WeakMap,wl=new WeakMap,qr=new WeakMap,Zi=new WeakMap,vi=new WeakMap,wa=new WeakMap,xa=new WeakMap,Ss=new WeakMap,Kr=new WeakMap,xl=new WeakMap,dd=new WeakMap,Y=new WeakSet,np=function([t,e],s,i){[s,i]=this.screenToPageTranslation(s,i),this.x+=s/t,this.y+=i/e,this._onTranslating(this.x,this.y),this.fixAndSetPosition()},Sl=new WeakSet,rp=function(t,e,s){switch(s){case 90:return[e,-t];case 180:return[-t,-e];case 270:return[-e,t];default:return[t,e]}},Rd=function(t){switch(t){case 90:{const[e,s]=this.pageDimensions;return[0,-e/s,s/e,0]}case 180:return[-1,0,0,-1];case 270:{const[e,s]=this.pageDimensions;return[0,e/s,-s/e,0]}default:return[1,0,0,1]}},gy=function(){if(l(this,he))return;m(this,he,document.createElement("div")),l(this,he).classList.add("resizers");const t=this._willKeepAspectRatio?["topLeft","topRight","bottomRight","bottomLeft"]:["topLeft","topMiddle","topRight","middleRight","bottomRight","bottomMiddle","bottomLeft","middleLeft"],e=this._uiManager._signal;for(const s of t){const i=document.createElement("div");l(this,he).append(i),i.classList.add("resizer",s),i.setAttribute("data-resizer-name",s),i.addEventListener("pointerdown",w(this,Y,py).bind(this,s),{signal:e}),i.addEventListener("contextmenu",Gs,{signal:e}),i.tabIndex=-1}this.div.prepend(l(this,he))},py=function(t,e){var u;e.preventDefault();const{isMac:s}=Re.platform;if(e.button!==0||e.ctrlKey&&s)return;(u=l(this,xt))==null||u.toggle(!1);const i=this._isDraggable;this._isDraggable=!1,m(this,Yr,[e.screenX,e.screenY]);const n=new AbortController,r=this._uiManager.combinedSignal(n);this.parent.togglePointerEvents(!1),window.addEventListener("pointermove",w(this,Y,ap).bind(this,t),{passive:!0,capture:!0,signal:r}),window.addEventListener("touchmove",es,{passive:!1,signal:r}),window.addEventListener("contextmenu",Gs,{signal:r}),m(this,Ji,{savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height});const o=this.parent.div.style.cursor,h=this.div.style.cursor;this.div.style.cursor=this.parent.div.style.cursor=window.getComputedStyle(e.target).cursor;const c=()=>{var d;n.abort(),this.parent.togglePointerEvents(!0),(d=l(this,xt))==null||d.toggle(!0),this._isDraggable=i,this.parent.div.style.cursor=o,this.div.style.cursor=h,w(this,Y,Ld).call(this)};window.addEventListener("pointerup",c,{signal:r}),window.addEventListener("blur",c,{signal:r})},op=function(t,e,s,i){this.width=s,this.height=i,this.x=t,this.y=e;const[n,r]=this.parentDimensions;this.setDims(n*s,r*i),this.fixAndSetPosition(),this._onResized()},Ld=function(){if(!l(this,Ji))return;const{savedX:t,savedY:e,savedWidth:s,savedHeight:i}=l(this,Ji);m(this,Ji,null);const n=this.x,r=this.y,o=this.width,h=this.height;n===t&&r===e&&o===s&&h===i||this.addCommands({cmd:w(this,Y,op).bind(this,n,r,o,h),undo:w(this,Y,op).bind(this,t,e,s,i),mustExec:!0})},ap=function(t,e){const[s,i]=this.parentDimensions,n=this.x,r=this.y,o=this.width,h=this.height,c=et.MIN_SIZE/s,u=et.MIN_SIZE/i,d=w(this,Y,Rd).call(this,this.rotation),f=(F,z)=>[d[0]*F+d[2]*z,d[1]*F+d[3]*z],g=w(this,Y,Rd).call(this,360-this.rotation),p=(F,z)=>[g[0]*F+g[2]*z,g[1]*F+g[3]*z];let b,v,_=!1,x=!1;switch(t){case"topLeft":_=!0,b=(F,z)=>[0,0],v=(F,z)=>[F,z];break;case"topMiddle":b=(F,z)=>[F/2,0],v=(F,z)=>[F/2,z];break;case"topRight":_=!0,b=(F,z)=>[F,0],v=(F,z)=>[0,z];break;case"middleRight":x=!0,b=(F,z)=>[F,z/2],v=(F,z)=>[0,z/2];break;case"bottomRight":_=!0,b=(F,z)=>[F,z],v=(F,z)=>[0,0];break;case"bottomMiddle":b=(F,z)=>[F/2,z],v=(F,z)=>[F/2,0];break;case"bottomLeft":_=!0,b=(F,z)=>[0,z],v=(F,z)=>[F,0];break;case"middleLeft":x=!0,b=(F,z)=>[0,z/2],v=(F,z)=>[F,z/2];break}const C=b(o,h),S=v(o,h);let k=f(...S);const D=et._round(n+k[0]),A=et._round(r+k[1]);let M=1,O=1,R,L;if(e.fromKeyboard)({deltaX:R,deltaY:L}=e);else{const{screenX:F,screenY:z}=e,[rt,Gt]=l(this,Yr);[R,L]=this.screenToPageTranslation(F-rt,z-Gt),l(this,Yr)[0]=F,l(this,Yr)[1]=z}if([R,L]=p(R/s,L/i),_){const F=Math.hypot(o,h);M=O=Math.max(Math.min(Math.hypot(S[0]-C[0]-R,S[1]-C[1]-L)/F,1/o,1/h),c/o,u/h)}else x?M=Math.max(c,Math.min(1,Math.abs(S[0]-C[0]-R)))/o:O=Math.max(u,Math.min(1,Math.abs(S[1]-C[1]-L)))/h;const V=et._round(o*M),U=et._round(h*O);k=f(...v(V,U));const G=D-k[0],at=A-k[1];l(this,ns)||m(this,ns,[this.x,this.y,this.width,this.height]),this.width=V,this.height=U,this.x=G,this.y=at,this.setDims(s*V,i*U),this.fixAndSetPosition(),this._onResizing()},my=function(){var t;m(this,Ji,{savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height}),(t=l(this,xt))==null||t.toggle(!1),this.parent.togglePointerEvents(!1)},by=function(t,e,s){let n=.7*(s/e)+1-.7;if(n===1)return;const r=w(this,Y,Rd).call(this,this.rotation),o=(D,A)=>[r[0]*D+r[2]*A,r[1]*D+r[3]*A],[h,c]=this.parentDimensions,u=this.x,d=this.y,f=this.width,g=this.height,p=et.MIN_SIZE/h,b=et.MIN_SIZE/c;n=Math.max(Math.min(n,1/f,1/g),p/f,b/g);const v=et._round(f*n),_=et._round(g*n);if(v===f&&_===g)return;l(this,ns)||m(this,ns,[u,d,f,g]);const x=o(f/2,g/2),C=et._round(u+x[0]),S=et._round(d+x[1]),k=o(v/2,_/2);this.x=C-k[0],this.y=S-k[1],this.width=v,this.height=_,this.setDims(h*v,c*_),this.fixAndSetPosition(),this._onResizing()},yy=function(){var t;(t=l(this,xt))==null||t.toggle(!0),this.parent.togglePointerEvents(!0),w(this,Y,Ld).call(this)},hp=function(t){const{isMac:e}=Re.platform;t.ctrlKey&&!e||t.shiftKey||t.metaKey&&e?this.parent.toggleSelected(this):this.parent.setSelected(this)},vy=function(t){const{isSelected:e}=this;this._uiManager.setUpDragSession();let s=!1;const i=new AbortController,n=this._uiManager.combinedSignal(i),r={capture:!0,passive:!1,signal:n},o=c=>{i.abort(),m(this,Yn,null),m(this,$r,!1),this._uiManager.endDragSession()||w(this,Y,hp).call(this,c),s&&this._onStopDragging()};e&&(m(this,wa,t.clientX),m(this,xa,t.clientY),m(this,Yn,t.pointerId),m(this,vl,t.pointerType),window.addEventListener("pointermove",c=>{s||(s=!0,this._onStartDragging());const{clientX:u,clientY:d,pointerId:f}=c;if(f!==l(this,Yn)){es(c);return}const[g,p]=this.screenToPageTranslation(u-l(this,wa),d-l(this,xa));m(this,wa,u),m(this,xa,d),this._uiManager.dragSelectedEditors(g,p)},r),window.addEventListener("touchmove",es,r),window.addEventListener("pointerdown",c=>{c.pointerType===l(this,vl)&&(l(this,Kr)||c.isPrimary)&&o(c),es(c)},r));const h=c=>{if(!l(this,Yn)||l(this,Yn)===c.pointerId){o(c);return}es(c)};window.addEventListener("pointerup",h,{signal:n}),window.addEventListener("blur",h,{signal:n})},lp=function(){if(l(this,$n)||!this.div)return;m(this,$n,new AbortController);const t=this._uiManager.combinedSignal(l(this,$n));this.div.addEventListener("focusin",this.focusin.bind(this),{signal:t}),this.div.addEventListener("focusout",this.focusout.bind(this),{signal:t})},_y=function(t){et._resizerKeyboardManager.exec(this,t)},wy=function(t){var e;l(this,Zi)&&((e=t.relatedTarget)==null?void 0:e.parentNode)!==l(this,he)&&w(this,Y,Tc).call(this)},xy=function(t){m(this,_l,l(this,Zi)?t:"")},cp=function(t){if(l(this,Us))for(const e of l(this,Us))e.tabIndex=t},Tc=function(){m(this,Zi,!1),w(this,Y,cp).call(this,-1),w(this,Y,Ld).call(this)},y(et,Sl),$(et,"_l10n",null),$(et,"_l10nResizer",null),$(et,"_borderLineWidth",-1),$(et,"_colorManager",new vg),$(et,"_zIndex",1),$(et,"_telemetryTimeout",1e3);let Pt=et;class mx extends Pt{constructor(t){super(t),this.annotationElementId=t.annotationElementId,this.deleted=!0}serialize(){return this.serializeDeleted()}}const Q0=3285377520,vs=4294901760,ci=65535;class J0{constructor(t){this.h1=t?t&4294967295:Q0,this.h2=t?t&4294967295:Q0}update(t){let e,s;if(typeof t=="string"){e=new Uint8Array(t.length*2),s=0;for(let b=0,v=t.length;b<v;b++){const _=t.charCodeAt(b);_<=255?e[s++]=_:(e[s++]=_>>>8,e[s++]=_&255)}}else if(ArrayBuffer.isView(t))e=t.slice(),s=e.byteLength;else throw new Error("Invalid data format, must be a string or TypedArray.");const i=s>>2,n=s-i*4,r=new Uint32Array(e.buffer,0,i);let o=0,h=0,c=this.h1,u=this.h2;const d=3432918353,f=461845907,g=d&ci,p=f&ci;for(let b=0;b<i;b++)b&1?(o=r[b],o=o*d&vs|o*g&ci,o=o<<15|o>>>17,o=o*f&vs|o*p&ci,c^=o,c=c<<13|c>>>19,c=c*5+3864292196):(h=r[b],h=h*d&vs|h*g&ci,h=h<<15|h>>>17,h=h*f&vs|h*p&ci,u^=h,u=u<<13|u>>>19,u=u*5+3864292196);switch(o=0,n){case 3:o^=e[i*4+2]<<16;case 2:o^=e[i*4+1]<<8;case 1:o^=e[i*4],o=o*d&vs|o*g&ci,o=o<<15|o>>>17,o=o*f&vs|o*p&ci,i&1?c^=o:u^=o}this.h1=c,this.h2=u}hexdigest(){let t=this.h1,e=this.h2;return t^=e>>>1,t=t*3981806797&vs|t*36045&ci,e=e*4283543511&vs|((e<<16|t>>>16)*2950163797&vs)>>>16,t^=e>>>1,t=t*444984403&vs|t*60499&ci,e=e*3301882366&vs|((e<<16|t>>>16)*3120437893&vs)>>>16,t^=e>>>1,(t>>>0).toString(16).padStart(8,"0")+(e>>>0).toString(16).padStart(8,"0")}}const _g=Object.freeze({map:null,hash:"",transfer:void 0});class wg{constructor(){y(this,fd);y(this,Qr,!1);y(this,Jr,null);y(this,ie,new Map);this.onSetModified=null,this.onResetModified=null,this.onAnnotationEditor=null}getValue(t,e){const s=l(this,ie).get(t);return s===void 0?e:Object.assign(e,s)}getRawValue(t){return l(this,ie).get(t)}remove(t){if(l(this,ie).delete(t),l(this,ie).size===0&&this.resetModified(),typeof this.onAnnotationEditor=="function"){for(const e of l(this,ie).values())if(e instanceof Pt)return;this.onAnnotationEditor(null)}}setValue(t,e){const s=l(this,ie).get(t);let i=!1;if(s!==void 0)for(const[n,r]of Object.entries(e))s[n]!==r&&(i=!0,s[n]=r);else i=!0,l(this,ie).set(t,e);i&&w(this,fd,Sy).call(this),e instanceof Pt&&typeof this.onAnnotationEditor=="function"&&this.onAnnotationEditor(e.constructor._type)}has(t){return l(this,ie).has(t)}getAll(){return l(this,ie).size>0?hg(l(this,ie)):null}setAll(t){for(const[e,s]of Object.entries(t))this.setValue(e,s)}get size(){return l(this,ie).size}resetModified(){l(this,Qr)&&(m(this,Qr,!1),typeof this.onResetModified=="function"&&this.onResetModified())}get print(){return new Z0(this)}get serializable(){if(l(this,ie).size===0)return _g;const t=new Map,e=new J0,s=[],i=Object.create(null);let n=!1;for(const[r,o]of l(this,ie)){const h=o instanceof Pt?o.serialize(!1,i):o;h&&(t.set(r,h),e.update(`${r}:${JSON.stringify(h)}`),n||(n=!!h.bitmap))}if(n)for(const r of t.values())r.bitmap&&s.push(r.bitmap);return t.size>0?{map:t,hash:e.hexdigest(),transfer:s}:_g}get editorStats(){let t=null;const e=new Map;for(const s of l(this,ie).values()){if(!(s instanceof Pt))continue;const i=s.telemetryFinalData;if(!i)continue;const{type:n}=i;e.has(n)||e.set(n,Object.getPrototypeOf(s).constructor),t||(t=Object.create(null));const r=t[n]||(t[n]=new Map);for(const[o,h]of Object.entries(i)){if(o==="type")continue;let c=r.get(o);c||(c=new Map,r.set(o,c));const u=c.get(h)??0;c.set(h,u+1)}}for(const[s,i]of e)t[s]=i.computeTelemetryFinalData(t[s]);return t}resetModifiedIds(){m(this,Jr,null)}get modifiedIds(){if(l(this,Jr))return l(this,Jr);const t=[];for(const e of l(this,ie).values())!(e instanceof Pt)||!e.annotationElementId||!e.serialize()||t.push(e.annotationElementId);return m(this,Jr,{ids:new Set(t),hash:t.join(",")})}}Qr=new WeakMap,Jr=new WeakMap,ie=new WeakMap,fd=new WeakSet,Sy=function(){l(this,Qr)||(m(this,Qr,!0),typeof this.onSetModified=="function"&&this.onSetModified())};class Z0 extends wg{constructor(e){super();y(this,Cl);const{map:s,hash:i,transfer:n}=e.serializable,r=structuredClone(s,n?{transfer:n}:null);m(this,Cl,{map:r,hash:i,transfer:n})}get print(){vt("Should not call PrintAnnotationStorage.print")}get serializable(){return l(this,Cl)}get modifiedIds(){return st(this,"modifiedIds",{ids:new Set,hash:""})}}Cl=new WeakMap;class bx{constructor({ownerDocument:t=globalThis.document,styleElement:e=null}){y(this,Sa,new Set);this._document=t,this.nativeFontFaces=new Set,this.styleElement=null,this.loadingRequests=[],this.loadTestFontId=0}addNativeFontFace(t){this.nativeFontFaces.add(t),this._document.fonts.add(t)}removeNativeFontFace(t){this.nativeFontFaces.delete(t),this._document.fonts.delete(t)}insertRule(t){this.styleElement||(this.styleElement=this._document.createElement("style"),this._document.documentElement.getElementsByTagName("head")[0].append(this.styleElement));const e=this.styleElement.sheet;e.insertRule(t,e.cssRules.length)}clear(){for(const t of this.nativeFontFaces)this._document.fonts.delete(t);this.nativeFontFaces.clear(),l(this,Sa).clear(),this.styleElement&&(this.styleElement.remove(),this.styleElement=null)}async loadSystemFont({systemFontInfo:t,_inspectFont:e}){if(!(!t||l(this,Sa).has(t.loadedName))){if(Xt(!this.disableFontFace,"loadSystemFont shouldn't be called when `disableFontFace` is set."),this.isFontLoadingAPISupported){const{loadedName:s,src:i,style:n}=t,r=new FontFace(s,i,n);this.addNativeFontFace(r);try{await r.load(),l(this,Sa).add(s),e==null||e(t)}catch{tt(`Cannot load system font: ${t.baseFontName}, installing it could help to improve PDF rendering.`),this.removeNativeFontFace(r)}return}vt("Not implemented: loadSystemFont without the Font Loading API.")}}async bind(t){if(t.attached||t.missingFile&&!t.systemFontInfo)return;if(t.attached=!0,t.systemFontInfo){await this.loadSystemFont(t);return}if(this.isFontLoadingAPISupported){const s=t.createNativeFontFace();if(s){this.addNativeFontFace(s);try{await s.loaded}catch(i){throw tt(`Failed to load font '${s.family}': '${i}'.`),t.disableFontFace=!0,i}}return}const e=t.createFontFaceRule();if(e){if(this.insertRule(e),this.isSyncFontLoadingSupported)return;await new Promise(s=>{const i=this._queueLoadingCallback(s);this._prepareFontLoadEvent(t,i)})}}get isFontLoadingAPISupported(){var e;const t=!!((e=this._document)!=null&&e.fonts);return st(this,"isFontLoadingAPISupported",t)}get isSyncFontLoadingSupported(){let t=!1;return(ye||typeof navigator<"u"&&typeof(navigator==null?void 0:navigator.userAgent)=="string"&&/Mozilla\/5.0.*?rv:\d+.*? Gecko/.test(navigator.userAgent))&&(t=!0),st(this,"isSyncFontLoadingSupported",t)}_queueLoadingCallback(t){function e(){for(Xt(!i.done,"completeRequest() cannot be called twice."),i.done=!0;s.length>0&&s[0].done;){const n=s.shift();setTimeout(n.callback,0)}}const{loadingRequests:s}=this,i={done:!1,complete:e,callback:t};return s.push(i),i}get _loadTestFont(){const t=atob("T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQAABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwAAAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbmFtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAAAADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6AABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAAMQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAAAAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAAAAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQAAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMAAQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAAEAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgcA/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQAAAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAgABAAAAAAAAAAAD6AAAAAAAAA==");return st(this,"_loadTestFont",t)}_prepareFontLoadEvent(t,e){function s(S,k){return S.charCodeAt(k)<<24|S.charCodeAt(k+1)<<16|S.charCodeAt(k+2)<<8|S.charCodeAt(k+3)&255}function i(S,k,D,A){const M=S.substring(0,k),O=S.substring(k+D);return M+A+O}let n,r;const o=this._document.createElement("canvas");o.width=1,o.height=1;const h=o.getContext("2d");let c=0;function u(S,k){if(++c>30){tt("Load test font never loaded."),k();return}if(h.font="30px "+S,h.fillText(".",0,20),h.getImageData(0,0,1,1).data[3]>0){k();return}setTimeout(u.bind(null,S,k))}const d=`lt${Date.now()}${this.loadTestFontId++}`;let f=this._loadTestFont;f=i(f,976,d.length,d);const p=16,b=1482184792;let v=s(f,p);for(n=0,r=d.length-3;n<r;n+=4)v=v-b+s(d,n)|0;n<d.length&&(v=v-b+s(d+"XXX",n)|0),f=i(f,p,4,sx(v));const _=`url(data:font/opentype;base64,${btoa(f)});`,x=`@font-face {font-family:"${d}";src:${_}}`;this.insertRule(x);const C=this._document.createElement("div");C.style.visibility="hidden",C.style.width=C.style.height="10px",C.style.position="absolute",C.style.top=C.style.left="0px";for(const S of[t.loadedName,d]){const k=this._document.createElement("span");k.textContent="Hi",k.style.fontFamily=S,C.append(k)}this._document.body.append(C),u(d,()=>{C.remove(),e.complete()})}}Sa=new WeakMap;class yx{constructor(t,{disableFontFace:e=!1,fontExtraProperties:s=!1,inspectFont:i=null}){this.compiledGlyphs=Object.create(null);for(const n in t)this[n]=t[n];this.disableFontFace=e===!0,this.fontExtraProperties=s===!0,this._inspectFont=i}createNativeFontFace(){var e;if(!this.data||this.disableFontFace)return null;let t;if(!this.cssFontInfo)t=new FontFace(this.loadedName,this.data,{});else{const s={weight:this.cssFontInfo.fontWeight};this.cssFontInfo.italicAngle&&(s.style=`oblique ${this.cssFontInfo.italicAngle}deg`),t=new FontFace(this.cssFontInfo.fontFamily,this.data,s)}return(e=this._inspectFont)==null||e.call(this,this),t}createFontFaceRule(){var s;if(!this.data||this.disableFontFace)return null;const t=`url(data:${this.mimetype};base64,${hx(this.data)});`;let e;if(!this.cssFontInfo)e=`@font-face {font-family:"${this.loadedName}";src:${t}}`;else{let i=`font-weight: ${this.cssFontInfo.fontWeight};`;this.cssFontInfo.italicAngle&&(i+=`font-style: oblique ${this.cssFontInfo.italicAngle}deg;`),e=`@font-face {font-family:"${this.cssFontInfo.fontFamily}";${i}src:${t}}`}return(s=this._inspectFont)==null||s.call(this,this,t),e}getPathGenerator(t,e){if(this.compiledGlyphs[e]!==void 0)return this.compiledGlyphs[e];const s=this.loadedName+"_path_"+e;let i;try{i=t.get(s)}catch(r){tt(`getPathGenerator - ignoring character: "${r}".`)}const n=new Path2D(i||"");return this.fontExtraProperties||t.delete(s),this.compiledGlyphs[e]=n}}const Qu={DATA:1,ERROR:2},Wt={CANCEL:1,CANCEL_COMPLETE:2,CLOSE:3,ENQUEUE:4,ERROR:5,PULL:6,PULL_COMPLETE:7,START_COMPLETE:8};function tb(){}function We(a){if(a instanceof Rn||a instanceof ag||a instanceof Gh||a instanceof Y0||a instanceof Xu||a instanceof og)return a;switch(a instanceof Error||typeof a=="object"&&a!==null||vt('wrapReason: Expected "reason" to be a (possibly cloned) Error.'),a.name){case"AbortException":return new Rn(a.message);case"InvalidPDFException":return new ag(a.message);case"MissingPDFException":return new Gh(a.message);case"PasswordException":return new Y0(a.message,a.code);case"UnexpectedResponseException":return new Xu(a.message,a.status);case"UnknownErrorException":return new og(a.message,a.details)}return new og(a.message,a.toString())}class Wh{constructor(t,e,s){y(this,Cs);y(this,Ca,new AbortController);this.sourceName=t,this.targetName=e,this.comObj=s,this.callbackId=1,this.streamId=1,this.streamSinks=Object.create(null),this.streamControllers=Object.create(null),this.callbackCapabilities=Object.create(null),this.actionHandler=Object.create(null),s.addEventListener("message",w(this,Cs,Cy).bind(this),{signal:l(this,Ca).signal})}on(t,e){const s=this.actionHandler;if(s[t])throw new Error(`There is already an actionName called "${t}"`);s[t]=e}send(t,e,s){this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:t,data:e},s)}sendWithPromise(t,e,s){const i=this.callbackId++,n=Promise.withResolvers();this.callbackCapabilities[i]=n;try{this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:t,callbackId:i,data:e},s)}catch(r){n.reject(r)}return n.promise}sendWithStream(t,e,s,i){const n=this.streamId++,r=this.sourceName,o=this.targetName,h=this.comObj;return new ReadableStream({start:c=>{const u=Promise.withResolvers();return this.streamControllers[n]={controller:c,startCall:u,pullCall:null,cancelCall:null,isClosed:!1},h.postMessage({sourceName:r,targetName:o,action:t,streamId:n,data:e,desiredSize:c.desiredSize},i),u.promise},pull:c=>{const u=Promise.withResolvers();return this.streamControllers[n].pullCall=u,h.postMessage({sourceName:r,targetName:o,stream:Wt.PULL,streamId:n,desiredSize:c.desiredSize}),u.promise},cancel:c=>{Xt(c instanceof Error,"cancel must have a valid reason");const u=Promise.withResolvers();return this.streamControllers[n].cancelCall=u,this.streamControllers[n].isClosed=!0,h.postMessage({sourceName:r,targetName:o,stream:Wt.CANCEL,streamId:n,reason:We(c)}),u.promise}},s)}destroy(){var t;(t=l(this,Ca))==null||t.abort(),m(this,Ca,null)}}Ca=new WeakMap,Cs=new WeakSet,Cy=function({data:t}){if(t.targetName!==this.sourceName)return;if(t.stream){w(this,Cs,Ty).call(this,t);return}if(t.callback){const s=t.callbackId,i=this.callbackCapabilities[s];if(!i)throw new Error(`Cannot resolve callback ${s}`);if(delete this.callbackCapabilities[s],t.callback===Qu.DATA)i.resolve(t.data);else if(t.callback===Qu.ERROR)i.reject(We(t.reason));else throw new Error("Unexpected callback case");return}const e=this.actionHandler[t.action];if(!e)throw new Error(`Unknown action from worker: ${t.action}`);if(t.callbackId){const s=this.sourceName,i=t.sourceName,n=this.comObj;Promise.try(e,t.data).then(function(r){n.postMessage({sourceName:s,targetName:i,callback:Qu.DATA,callbackId:t.callbackId,data:r})},function(r){n.postMessage({sourceName:s,targetName:i,callback:Qu.ERROR,callbackId:t.callbackId,reason:We(r)})});return}if(t.streamId){w(this,Cs,Ay).call(this,t);return}e(t.data)},Ay=function(t){const e=t.streamId,s=this.sourceName,i=t.sourceName,n=this.comObj,r=this,o=this.actionHandler[t.action],h={enqueue(c,u=1,d){if(this.isCancelled)return;const f=this.desiredSize;this.desiredSize-=u,f>0&&this.desiredSize<=0&&(this.sinkCapability=Promise.withResolvers(),this.ready=this.sinkCapability.promise),n.postMessage({sourceName:s,targetName:i,stream:Wt.ENQUEUE,streamId:e,chunk:c},d)},close(){this.isCancelled||(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:Wt.CLOSE,streamId:e}),delete r.streamSinks[e])},error(c){Xt(c instanceof Error,"error must have a valid reason"),!this.isCancelled&&(this.isCancelled=!0,n.postMessage({sourceName:s,targetName:i,stream:Wt.ERROR,streamId:e,reason:We(c)}))},sinkCapability:Promise.withResolvers(),onPull:null,onCancel:null,isCancelled:!1,desiredSize:t.desiredSize,ready:null};h.sinkCapability.resolve(),h.ready=h.sinkCapability.promise,this.streamSinks[e]=h,Promise.try(o,t.data,h).then(function(){n.postMessage({sourceName:s,targetName:i,stream:Wt.START_COMPLETE,streamId:e,success:!0})},function(c){n.postMessage({sourceName:s,targetName:i,stream:Wt.START_COMPLETE,streamId:e,reason:We(c)})})},Ty=function(t){const e=t.streamId,s=this.sourceName,i=t.sourceName,n=this.comObj,r=this.streamControllers[e],o=this.streamSinks[e];switch(t.stream){case Wt.START_COMPLETE:t.success?r.startCall.resolve():r.startCall.reject(We(t.reason));break;case Wt.PULL_COMPLETE:t.success?r.pullCall.resolve():r.pullCall.reject(We(t.reason));break;case Wt.PULL:if(!o){n.postMessage({sourceName:s,targetName:i,stream:Wt.PULL_COMPLETE,streamId:e,success:!0});break}o.desiredSize<=0&&t.desiredSize>0&&o.sinkCapability.resolve(),o.desiredSize=t.desiredSize,Promise.try(o.onPull||tb).then(function(){n.postMessage({sourceName:s,targetName:i,stream:Wt.PULL_COMPLETE,streamId:e,success:!0})},function(c){n.postMessage({sourceName:s,targetName:i,stream:Wt.PULL_COMPLETE,streamId:e,reason:We(c)})});break;case Wt.ENQUEUE:if(Xt(r,"enqueue should have stream controller"),r.isClosed)break;r.controller.enqueue(t.chunk);break;case Wt.CLOSE:if(Xt(r,"close should have stream controller"),r.isClosed)break;r.isClosed=!0,r.controller.close(),w(this,Cs,Fd).call(this,r,e);break;case Wt.ERROR:Xt(r,"error should have stream controller"),r.controller.error(We(t.reason)),w(this,Cs,Fd).call(this,r,e);break;case Wt.CANCEL_COMPLETE:t.success?r.cancelCall.resolve():r.cancelCall.reject(We(t.reason)),w(this,Cs,Fd).call(this,r,e);break;case Wt.CANCEL:if(!o)break;const h=We(t.reason);Promise.try(o.onCancel||tb,h).then(function(){n.postMessage({sourceName:s,targetName:i,stream:Wt.CANCEL_COMPLETE,streamId:e,success:!0})},function(c){n.postMessage({sourceName:s,targetName:i,stream:Wt.CANCEL_COMPLETE,streamId:e,reason:We(c)})}),o.sinkCapability.reject(h),o.isCancelled=!0,delete this.streamSinks[e];break;default:throw new Error("Unexpected stream case")}},Fd=async function(t,e){var s,i,n;await Promise.allSettled([(s=t.startCall)==null?void 0:s.promise,(i=t.pullCall)==null?void 0:i.promise,(n=t.cancelCall)==null?void 0:n.promise]),delete this.streamControllers[e]};class eb{constructor({enableHWA:t=!1}){y(this,Al,!1);m(this,Al,t)}create(t,e){if(t<=0||e<=0)throw new Error("Invalid canvas size");const s=this._createCanvas(t,e);return{canvas:s,context:s.getContext("2d",{willReadFrequently:!l(this,Al)})}}reset(t,e,s){if(!t.canvas)throw new Error("Canvas is not specified");if(e<=0||s<=0)throw new Error("Invalid canvas size");t.canvas.width=e,t.canvas.height=s}destroy(t){if(!t.canvas)throw new Error("Canvas is not specified");t.canvas.width=0,t.canvas.height=0,t.canvas=null,t.context=null}_createCanvas(t,e){vt("Abstract method `_createCanvas` called.")}}Al=new WeakMap;class vx extends eb{constructor({ownerDocument:t=globalThis.document,enableHWA:e=!1}){super({enableHWA:e}),this._document=t}_createCanvas(t,e){const s=this._document.createElement("canvas");return s.width=t,s.height=e,s}}class sb{constructor({baseUrl:t=null,isCompressed:e=!0}){this.baseUrl=t,this.isCompressed=e}async fetch({name:t}){if(!this.baseUrl)throw new Error("Ensure that the `cMapUrl` and `cMapPacked` API parameters are provided.");if(!t)throw new Error("CMap name must be specified.");const e=this.baseUrl+t+(this.isCompressed?".bcmap":"");return this._fetch(e).then(s=>({cMapData:s,isCompressed:this.isCompressed})).catch(s=>{throw new Error(`Unable to load ${this.isCompressed?"binary ":""}CMap at: ${e}`)})}async _fetch(t){vt("Abstract method `_fetch` called.")}}class ib extends sb{async _fetch(t){const e=await Uu(t,this.isCompressed?"arraybuffer":"text");return e instanceof ArrayBuffer?new Uint8Array(e):Wu(e)}}class nb{addFilter(t){return"none"}addHCMFilter(t,e){return"none"}addAlphaFilter(t){return"none"}addLuminosityFilter(t){return"none"}addHighlightHCMFilter(t,e,s,i,n){return"none"}destroy(t=!1){}}class _x extends nb{constructor({docId:e,ownerDocument:s=globalThis.document}){super();y(this,j);y(this,Zr);y(this,Aa);y(this,tn);y(this,en);y(this,xe);y(this,to);y(this,eo,0);m(this,en,e),m(this,xe,s)}addFilter(e){if(!e)return"none";let s=l(this,j,Te).get(e);if(s)return s;const[i,n,r]=w(this,j,Id).call(this,e),o=e.length===1?i:`${i}${n}${r}`;if(s=l(this,j,Te).get(o),s)return l(this,j,Te).set(e,s),s;const h=`g_${l(this,en)}_transfer_map_${Ge(this,eo)._++}`,c=w(this,j,bh).call(this,h);l(this,j,Te).set(e,c),l(this,j,Te).set(o,c);const u=w(this,j,yh).call(this,h);return w(this,j,Mc).call(this,i,n,r,u),c}addHCMFilter(e,s){var p;const i=`${e}-${s}`,n="base";let r=l(this,j,Ec).get(n);if((r==null?void 0:r.key)===i||(r?((p=r.filter)==null||p.remove(),r.key=i,r.url="none",r.filter=null):(r={key:i,url:"none",filter:null},l(this,j,Ec).set(n,r)),!e||!s))return r.url;const o=w(this,j,Pc).call(this,e);e=W.makeHexColor(...o);const h=w(this,j,Pc).call(this,s);if(s=W.makeHexColor(...h),l(this,j,mh).style.color="",e==="#000000"&&s==="#ffffff"||e===s)return r.url;const c=new Array(256);for(let b=0;b<=255;b++){const v=b/255;c[b]=v<=.03928?v/12.92:((v+.055)/1.055)**2.4}const u=c.join(","),d=`g_${l(this,en)}_hcm_filter`,f=r.filter=w(this,j,yh).call(this,d);w(this,j,Mc).call(this,u,u,u,f),w(this,j,up).call(this,f);const g=(b,v)=>{const _=o[b]/255,x=h[b]/255,C=new Array(v+1);for(let S=0;S<=v;S++)C[S]=_+S/v*(x-_);return C.join(",")};return w(this,j,Mc).call(this,g(0,5),g(1,5),g(2,5),f),r.url=w(this,j,bh).call(this,d),r.url}addAlphaFilter(e){let s=l(this,j,Te).get(e);if(s)return s;const[i]=w(this,j,Id).call(this,[e]),n=`alpha_${i}`;if(s=l(this,j,Te).get(n),s)return l(this,j,Te).set(e,s),s;const r=`g_${l(this,en)}_alpha_map_${Ge(this,eo)._++}`,o=w(this,j,bh).call(this,r);l(this,j,Te).set(e,o),l(this,j,Te).set(n,o);const h=w(this,j,yh).call(this,r);return w(this,j,dp).call(this,i,h),o}addLuminosityFilter(e){let s=l(this,j,Te).get(e||"luminosity");if(s)return s;let i,n;if(e?([i]=w(this,j,Id).call(this,[e]),n=`luminosity_${i}`):n="luminosity",s=l(this,j,Te).get(n),s)return l(this,j,Te).set(e,s),s;const r=`g_${l(this,en)}_luminosity_map_${Ge(this,eo)._++}`,o=w(this,j,bh).call(this,r);l(this,j,Te).set(e,o),l(this,j,Te).set(n,o);const h=w(this,j,yh).call(this,r);return w(this,j,Ey).call(this,h),e&&w(this,j,dp).call(this,i,h),o}addHighlightHCMFilter(e,s,i,n,r){var x;const o=`${s}-${i}-${n}-${r}`;let h=l(this,j,Ec).get(e);if((h==null?void 0:h.key)===o||(h?((x=h.filter)==null||x.remove(),h.key=o,h.url="none",h.filter=null):(h={key:o,url:"none",filter:null},l(this,j,Ec).set(e,h)),!s||!i))return h.url;const[c,u]=[s,i].map(w(this,j,Pc).bind(this));let d=Math.round(.2126*c[0]+.7152*c[1]+.0722*c[2]),f=Math.round(.2126*u[0]+.7152*u[1]+.0722*u[2]),[g,p]=[n,r].map(w(this,j,Pc).bind(this));f<d&&([d,f,g,p]=[f,d,p,g]),l(this,j,mh).style.color="";const b=(C,S,k)=>{const D=new Array(256),A=(f-d)/k,M=C/255,O=(S-C)/(255*k);let R=0;for(let L=0;L<=k;L++){const V=Math.round(d+L*A),U=M+L*O;for(let G=R;G<=V;G++)D[G]=U;R=V+1}for(let L=R;L<256;L++)D[L]=D[R-1];return D.join(",")},v=`g_${l(this,en)}_hcm_${e}_filter`,_=h.filter=w(this,j,yh).call(this,v);return w(this,j,up).call(this,_),w(this,j,Mc).call(this,b(g[0],p[0],5),b(g[1],p[1],5),b(g[2],p[2],5),_),h.url=w(this,j,bh).call(this,v),h.url}destroy(e=!1){var s,i,n,r;e&&((s=l(this,to))!=null&&s.size)||((i=l(this,tn))==null||i.parentNode.parentNode.remove(),m(this,tn,null),(n=l(this,Aa))==null||n.clear(),m(this,Aa,null),(r=l(this,to))==null||r.clear(),m(this,to,null),m(this,eo,0))}}Zr=new WeakMap,Aa=new WeakMap,tn=new WeakMap,en=new WeakMap,xe=new WeakMap,to=new WeakMap,eo=new WeakMap,j=new WeakSet,Te=function(){return l(this,Aa)||m(this,Aa,new Map)},Ec=function(){return l(this,to)||m(this,to,new Map)},mh=function(){if(!l(this,tn)){const e=l(this,xe).createElement("div"),{style:s}=e;s.visibility="hidden",s.contain="strict",s.width=s.height=0,s.position="absolute",s.top=s.left=0,s.zIndex=-1;const i=l(this,xe).createElementNS(zi,"svg");i.setAttribute("width",0),i.setAttribute("height",0),m(this,tn,l(this,xe).createElementNS(zi,"defs")),e.append(i),i.append(l(this,tn)),l(this,xe).body.append(e)}return l(this,tn)},Id=function(e){if(e.length===1){const c=e[0],u=new Array(256);for(let f=0;f<256;f++)u[f]=c[f]/255;const d=u.join(",");return[d,d,d]}const[s,i,n]=e,r=new Array(256),o=new Array(256),h=new Array(256);for(let c=0;c<256;c++)r[c]=s[c]/255,o[c]=i[c]/255,h[c]=n[c]/255;return[r.join(","),o.join(","),h.join(",")]},bh=function(e){if(l(this,Zr)===void 0){m(this,Zr,"");const s=l(this,xe).URL;s!==l(this,xe).baseURI&&(Yu(s)?tt('#createUrl: ignore "data:"-URL for performance reasons.'):m(this,Zr,s.split("#",1)[0]))}return`url(${l(this,Zr)}#${e})`},Ey=function(e){const s=l(this,xe).createElementNS(zi,"feColorMatrix");s.setAttribute("type","matrix"),s.setAttribute("values","0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3 0.59 0.11 0 0"),e.append(s)},up=function(e){const s=l(this,xe).createElementNS(zi,"feColorMatrix");s.setAttribute("type","matrix"),s.setAttribute("values","0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0 0 0 1 0"),e.append(s)},yh=function(e){const s=l(this,xe).createElementNS(zi,"filter");return s.setAttribute("color-interpolation-filters","sRGB"),s.setAttribute("id",e),l(this,j,mh).append(s),s},kc=function(e,s,i){const n=l(this,xe).createElementNS(zi,s);n.setAttribute("type","discrete"),n.setAttribute("tableValues",i),e.append(n)},Mc=function(e,s,i,n){const r=l(this,xe).createElementNS(zi,"feComponentTransfer");n.append(r),w(this,j,kc).call(this,r,"feFuncR",e),w(this,j,kc).call(this,r,"feFuncG",s),w(this,j,kc).call(this,r,"feFuncB",i)},dp=function(e,s){const i=l(this,xe).createElementNS(zi,"feComponentTransfer");s.append(i),w(this,j,kc).call(this,i,"feFuncA",e)},Pc=function(e){return l(this,j,mh).style.color=e,pg(getComputedStyle(l(this,j,mh)).getPropertyValue("color"))};class rb{constructor({baseUrl:t=null}){this.baseUrl=t}async fetch({filename:t}){if(!this.baseUrl)throw new Error("Ensure that the `standardFontDataUrl` API parameter is provided.");if(!t)throw new Error("Font filename must be specified.");const e=`${this.baseUrl}${t}`;return this._fetch(e).catch(s=>{throw new Error(`Unable to load font data at: ${e}`)})}async _fetch(t){vt("Abstract method `_fetch` called.")}}class ob extends rb{async _fetch(t){const e=await Uu(t,"arraybuffer");return new Uint8Array(e)}}ye&&tt("Please use the `legacy` build in Node.js environments.");async function ab(a){const e=await process.getBuiltinModule("fs").promises.readFile(a);return new Uint8Array(e)}class wx extends nb{}class xx extends eb{_createCanvas(t,e){return process.getBuiltinModule("module").createRequire(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:_t&&_t.tagName.toUpperCase()==="SCRIPT"&&_t.src||new URL("pdf-canvas.umd.js",document.baseURI).href)("@napi-rs/canvas").createCanvas(t,e)}}class Sx extends sb{async _fetch(t){return ab(t)}}class Cx extends rb{async _fetch(t){return ab(t)}}const _e={FILL:"Fill",STROKE:"Stroke",SHADING:"Shading"};function xg(a,t){if(!t)return;const e=t[2]-t[0],s=t[3]-t[1],i=new Path2D;i.rect(t[0],t[1],e,s),a.clip(i)}class Sg{getPattern(){vt("Abstract method `getPattern` called.")}}class Ax extends Sg{constructor(t){super(),this._type=t[1],this._bbox=t[2],this._colorStops=t[3],this._p0=t[4],this._p1=t[5],this._r0=t[6],this._r1=t[7],this.matrix=null}_createGradient(t){let e;this._type==="axial"?e=t.createLinearGradient(this._p0[0],this._p0[1],this._p1[0],this._p1[1]):this._type==="radial"&&(e=t.createRadialGradient(this._p0[0],this._p0[1],this._r0,this._p1[0],this._p1[1],this._r1));for(const s of this._colorStops)e.addColorStop(s[0],s[1]);return e}getPattern(t,e,s,i){let n;if(i===_e.STROKE||i===_e.FILL){const r=e.current.getClippedPathBoundingBox(i,Tt(t))||[0,0,0,0],o=Math.ceil(r[2]-r[0])||1,h=Math.ceil(r[3]-r[1])||1,c=e.cachedCanvases.getCanvas("pattern",o,h),u=c.context;u.clearRect(0,0,u.canvas.width,u.canvas.height),u.beginPath(),u.rect(0,0,u.canvas.width,u.canvas.height),u.translate(-r[0],-r[1]),s=W.transform(s,[1,0,0,1,r[0],r[1]]),u.transform(...e.baseTransform),this.matrix&&u.transform(...this.matrix),xg(u,this._bbox),u.fillStyle=this._createGradient(u),u.fill(),n=t.createPattern(c.canvas,"no-repeat");const d=new DOMMatrix(s);n.setTransform(d)}else xg(t,this._bbox),n=this._createGradient(t);return n}}function Cg(a,t,e,s,i,n,r,o){const h=t.coords,c=t.colors,u=a.data,d=a.width*4;let f;h[e+1]>h[s+1]&&(f=e,e=s,s=f,f=n,n=r,r=f),h[s+1]>h[i+1]&&(f=s,s=i,i=f,f=r,r=o,o=f),h[e+1]>h[s+1]&&(f=e,e=s,s=f,f=n,n=r,r=f);const g=(h[e]+t.offsetX)*t.scaleX,p=(h[e+1]+t.offsetY)*t.scaleY,b=(h[s]+t.offsetX)*t.scaleX,v=(h[s+1]+t.offsetY)*t.scaleY,_=(h[i]+t.offsetX)*t.scaleX,x=(h[i+1]+t.offsetY)*t.scaleY;if(p>=x)return;const C=c[n],S=c[n+1],k=c[n+2],D=c[r],A=c[r+1],M=c[r+2],O=c[o],R=c[o+1],L=c[o+2],V=Math.round(p),U=Math.round(x);let G,at,F,z,rt,Gt,te,fe;for(let Yt=V;Yt<=U;Yt++){if(Yt<v){const ft=Yt<p?0:(p-Yt)/(p-v);G=g-(g-b)*ft,at=C-(C-D)*ft,F=S-(S-A)*ft,z=k-(k-M)*ft}else{let ft;Yt>x?ft=1:v===x?ft=0:ft=(v-Yt)/(v-x),G=b-(b-_)*ft,at=D-(D-O)*ft,F=A-(A-R)*ft,z=M-(M-L)*ft}let St;Yt<p?St=0:Yt>x?St=1:St=(p-Yt)/(p-x),rt=g-(g-_)*St,Gt=C-(C-O)*St,te=S-(S-R)*St,fe=k-(k-L)*St;const He=Math.round(Math.min(G,rt)),Mi=Math.round(Math.max(G,rt));let Ft=d*Yt+He*4;for(let ft=He;ft<=Mi;ft++)St=(G-ft)/(G-rt),St<0?St=0:St>1&&(St=1),u[Ft++]=at-(at-Gt)*St|0,u[Ft++]=F-(F-te)*St|0,u[Ft++]=z-(z-fe)*St|0,u[Ft++]=255}}function Tx(a,t,e){const s=t.coords,i=t.colors;let n,r;switch(t.type){case"lattice":const o=t.verticesPerRow,h=Math.floor(s.length/o)-1,c=o-1;for(n=0;n<h;n++){let u=n*o;for(let d=0;d<c;d++,u++)Cg(a,e,s[u],s[u+1],s[u+o],i[u],i[u+1],i[u+o]),Cg(a,e,s[u+o+1],s[u+1],s[u+o],i[u+o+1],i[u+1],i[u+o])}break;case"triangles":for(n=0,r=s.length;n<r;n+=3)Cg(a,e,s[n],s[n+1],s[n+2],i[n],i[n+1],i[n+2]);break;default:throw new Error("illegal figure")}}class Ex extends Sg{constructor(t){super(),this._coords=t[2],this._colors=t[3],this._figures=t[4],this._bounds=t[5],this._bbox=t[7],this._background=t[8],this.matrix=null}_createMeshCanvas(t,e,s){const o=Math.floor(this._bounds[0]),h=Math.floor(this._bounds[1]),c=Math.ceil(this._bounds[2])-o,u=Math.ceil(this._bounds[3])-h,d=Math.min(Math.ceil(Math.abs(c*t[0]*1.1)),3e3),f=Math.min(Math.ceil(Math.abs(u*t[1]*1.1)),3e3),g=c/d,p=u/f,b={coords:this._coords,colors:this._colors,offsetX:-o,offsetY:-h,scaleX:1/g,scaleY:1/p},v=d+2*2,_=f+2*2,x=s.getCanvas("mesh",v,_),C=x.context,S=C.createImageData(d,f);if(e){const D=S.data;for(let A=0,M=D.length;A<M;A+=4)D[A]=e[0],D[A+1]=e[1],D[A+2]=e[2],D[A+3]=255}for(const D of this._figures)Tx(S,D,b);return C.putImageData(S,2,2),{canvas:x.canvas,offsetX:o-2*g,offsetY:h-2*p,scaleX:g,scaleY:p}}getPattern(t,e,s,i){xg(t,this._bbox);let n;if(i===_e.SHADING)n=W.singularValueDecompose2dScale(Tt(t));else if(n=W.singularValueDecompose2dScale(e.baseTransform),this.matrix){const o=W.singularValueDecompose2dScale(this.matrix);n=[n[0]*o[0],n[1]*o[1]]}const r=this._createMeshCanvas(n,i===_e.SHADING?null:this._background,e.cachedCanvases);return i!==_e.SHADING&&(t.setTransform(...e.baseTransform),this.matrix&&t.transform(...this.matrix)),t.translate(r.offsetX,r.offsetY),t.scale(r.scaleX,r.scaleY),t.createPattern(r.canvas,"no-repeat")}}class kx extends Sg{getPattern(){return"hotpink"}}function Mx(a){switch(a[0]){case"RadialAxial":return new Ax(a);case"Mesh":return new Ex(a);case"Dummy":return new kx}throw new Error(`Unknown IR type: ${a[0]}`)}const hb={COLORED:1,UNCOLORED:2},gd=class gd{constructor(t,e,s,i,n){this.operatorList=t[2],this.matrix=t[3],this.bbox=t[4],this.xstep=t[5],this.ystep=t[6],this.paintType=t[7],this.tilingType=t[8],this.color=e,this.ctx=s,this.canvasGraphicsFactory=i,this.baseTransform=n}createPatternCanvas(t){const{bbox:e,operatorList:s,paintType:i,tilingType:n,color:r,canvasGraphicsFactory:o}=this;let{xstep:h,ystep:c}=this;h=Math.abs(h),c=Math.abs(c),Vu("TilingType: "+n);const u=e[0],d=e[1],f=e[2],g=e[3],p=f-u,b=g-d,v=W.singularValueDecompose2dScale(this.matrix),_=W.singularValueDecompose2dScale(this.baseTransform),x=v[0]*_[0],C=v[1]*_[1];let S=p,k=b,D=!1,A=!1;const M=Math.ceil(h*x),O=Math.ceil(c*C),R=Math.ceil(p*x),L=Math.ceil(b*C);M>=R?S=h:D=!0,O>=L?k=c:A=!0;const V=this.getSizeAndScale(S,this.ctx.canvas.width,x),U=this.getSizeAndScale(k,this.ctx.canvas.height,C),G=t.cachedCanvases.getCanvas("pattern",V.size,U.size),at=G.context,F=o.createCanvasGraphics(at);if(F.groupLevel=t.groupLevel,this.setFillAndStrokeStyleToContext(F,i,r),at.translate(-V.scale*u,-U.scale*d),F.transform(V.scale,0,0,U.scale,0,0),at.save(),this.clipBbox(F,u,d,f,g),F.baseTransform=Tt(F.ctx),F.executeOperatorList(s),F.endDrawing(),at.restore(),D||A){const z=G.canvas;D&&(S=h),A&&(k=c);const rt=this.getSizeAndScale(S,this.ctx.canvas.width,x),Gt=this.getSizeAndScale(k,this.ctx.canvas.height,C),te=rt.size,fe=Gt.size,Yt=t.cachedCanvases.getCanvas("pattern-workaround",te,fe),St=Yt.context,He=D?Math.floor(p/h):0,Mi=A?Math.floor(b/c):0;for(let Ft=0;Ft<=He;Ft++)for(let ft=0;ft<=Mi;ft++)St.drawImage(z,te*Ft,fe*ft,te,fe,0,0,te,fe);return{canvas:Yt.canvas,scaleX:rt.scale,scaleY:Gt.scale,offsetX:u,offsetY:d}}return{canvas:G.canvas,scaleX:V.scale,scaleY:U.scale,offsetX:u,offsetY:d}}getSizeAndScale(t,e,s){const i=Math.max(gd.MAX_PATTERN_SIZE,e);let n=Math.ceil(t*s);return n>=i?n=i:s=n/t,{scale:s,size:n}}clipBbox(t,e,s,i,n){const r=i-e,o=n-s;t.ctx.rect(e,s,r,o),t.current.updateRectMinMax(Tt(t.ctx),[e,s,i,n]),t.clip(),t.endPath()}setFillAndStrokeStyleToContext(t,e,s){const i=t.ctx,n=t.current;switch(e){case hb.COLORED:const r=this.ctx;i.fillStyle=r.fillStyle,i.strokeStyle=r.strokeStyle,n.fillColor=r.fillStyle,n.strokeColor=r.strokeStyle;break;case hb.UNCOLORED:const o=W.makeHexColor(s[0],s[1],s[2]);i.fillStyle=o,i.strokeStyle=o,n.fillColor=o,n.strokeColor=o;break;default:throw new ex(`Unsupported paint type: ${e}`)}}getPattern(t,e,s,i){let n=s;i!==_e.SHADING&&(n=W.transform(n,e.baseTransform),this.matrix&&(n=W.transform(n,this.matrix)));const r=this.createPatternCanvas(e);let o=new DOMMatrix(n);o=o.translate(r.offsetX,r.offsetY),o=o.scale(1/r.scaleX,1/r.scaleY);const h=t.createPattern(r.canvas,"repeat");return h.setTransform(o),h}};$(gd,"MAX_PATTERN_SIZE",3e3);let Ag=gd;function Px({src:a,srcPos:t=0,dest:e,width:s,height:i,nonBlackColor:n=4294967295,inverseDecode:r=!1}){const o=Re.isLittleEndian?4278190080:255,[h,c]=r?[n,o]:[o,n],u=s>>3,d=s&7,f=a.length;e=new Uint32Array(e.buffer);let g=0;for(let p=0;p<i;p++){for(const v=t+u;t<v;t++){const _=t<f?a[t]:255;e[g++]=_&128?c:h,e[g++]=_&64?c:h,e[g++]=_&32?c:h,e[g++]=_&16?c:h,e[g++]=_&8?c:h,e[g++]=_&4?c:h,e[g++]=_&2?c:h,e[g++]=_&1?c:h}if(d===0)continue;const b=t<f?a[t++]:255;for(let v=0;v<d;v++)e[g++]=b&1<<7-v?c:h}return{srcPos:t,destPos:g}}const lb=16,cb=100,Dx=15,ub=10,db=1e3,Ue=16;function Ox(a,t){if(a._removeMirroring)throw new Error("Context is already forwarding operations.");a.__originalSave=a.save,a.__originalRestore=a.restore,a.__originalRotate=a.rotate,a.__originalScale=a.scale,a.__originalTranslate=a.translate,a.__originalTransform=a.transform,a.__originalSetTransform=a.setTransform,a.__originalResetTransform=a.resetTransform,a.__originalClip=a.clip,a.__originalMoveTo=a.moveTo,a.__originalLineTo=a.lineTo,a.__originalBezierCurveTo=a.bezierCurveTo,a.__originalRect=a.rect,a.__originalClosePath=a.closePath,a.__originalBeginPath=a.beginPath,a._removeMirroring=()=>{a.save=a.__originalSave,a.restore=a.__originalRestore,a.rotate=a.__originalRotate,a.scale=a.__originalScale,a.translate=a.__originalTranslate,a.transform=a.__originalTransform,a.setTransform=a.__originalSetTransform,a.resetTransform=a.__originalResetTransform,a.clip=a.__originalClip,a.moveTo=a.__originalMoveTo,a.lineTo=a.__originalLineTo,a.bezierCurveTo=a.__originalBezierCurveTo,a.rect=a.__originalRect,a.closePath=a.__originalClosePath,a.beginPath=a.__originalBeginPath,delete a._removeMirroring},a.save=function(){t.save(),this.__originalSave()},a.restore=function(){t.restore(),this.__originalRestore()},a.translate=function(s,i){t.translate(s,i),this.__originalTranslate(s,i)},a.scale=function(s,i){t.scale(s,i),this.__originalScale(s,i)},a.transform=function(s,i,n,r,o,h){t.transform(s,i,n,r,o,h),this.__originalTransform(s,i,n,r,o,h)},a.setTransform=function(s,i,n,r,o,h){t.setTransform(s,i,n,r,o,h),this.__originalSetTransform(s,i,n,r,o,h)},a.resetTransform=function(){t.resetTransform(),this.__originalResetTransform()},a.rotate=function(s){t.rotate(s),this.__originalRotate(s)},a.clip=function(s){t.clip(s),this.__originalClip(s)},a.moveTo=function(e,s){t.moveTo(e,s),this.__originalMoveTo(e,s)},a.lineTo=function(e,s){t.lineTo(e,s),this.__originalLineTo(e,s)},a.bezierCurveTo=function(e,s,i,n,r,o){t.bezierCurveTo(e,s,i,n,r,o),this.__originalBezierCurveTo(e,s,i,n,r,o)},a.rect=function(e,s,i,n){t.rect(e,s,i,n),this.__originalRect(e,s,i,n)},a.closePath=function(){t.closePath(),this.__originalClosePath()},a.beginPath=function(){t.beginPath(),this.__originalBeginPath()}}class Rx{constructor(t){this.canvasFactory=t,this.cache=Object.create(null)}getCanvas(t,e,s){let i;return this.cache[t]!==void 0?(i=this.cache[t],this.canvasFactory.reset(i,e,s)):(i=this.canvasFactory.create(e,s),this.cache[t]=i),i}delete(t){delete this.cache[t]}clear(){for(const t in this.cache){const e=this.cache[t];this.canvasFactory.destroy(e),delete this.cache[t]}}}function Ju(a,t,e,s,i,n,r,o,h,c){const[u,d,f,g,p,b]=Tt(a);if(d===0&&f===0){const x=r*u+p,C=Math.round(x),S=o*g+b,k=Math.round(S),D=(r+h)*u+p,A=Math.abs(Math.round(D)-C)||1,M=(o+c)*g+b,O=Math.abs(Math.round(M)-k)||1;return a.setTransform(Math.sign(u),0,0,Math.sign(g),C,k),a.drawImage(t,e,s,i,n,0,0,A,O),a.setTransform(u,d,f,g,p,b),[A,O]}if(u===0&&g===0){const x=o*f+p,C=Math.round(x),S=r*d+b,k=Math.round(S),D=(o+c)*f+p,A=Math.abs(Math.round(D)-C)||1,M=(r+h)*d+b,O=Math.abs(Math.round(M)-k)||1;return a.setTransform(0,Math.sign(d),Math.sign(f),0,C,k),a.drawImage(t,e,s,i,n,0,0,O,A),a.setTransform(u,d,f,g,p,b),[O,A]}a.drawImage(t,e,s,i,n,r,o,h,c);const v=Math.hypot(u,d),_=Math.hypot(f,g);return[v*h,_*c]}function Lx(a){const{width:t,height:e}=a;if(t>db||e>db)return null;const s=1e3,i=new Uint8Array([0,2,4,0,1,0,5,4,8,10,0,8,0,2,1,0]),n=t+1;let r=new Uint8Array(n*(e+1)),o,h,c;const u=t+7&-8;let d=new Uint8Array(u*e),f=0;for(const _ of a.data){let x=128;for(;x>0;)d[f++]=_&x?0:255,x>>=1}let g=0;for(f=0,d[f]!==0&&(r[0]=1,++g),h=1;h<t;h++)d[f]!==d[f+1]&&(r[h]=d[f]?2:1,++g),f++;for(d[f]!==0&&(r[h]=2,++g),o=1;o<e;o++){f=o*u,c=o*n,d[f-u]!==d[f]&&(r[c]=d[f]?1:8,++g);let _=(d[f]?4:0)+(d[f-u]?8:0);for(h=1;h<t;h++)_=(_>>2)+(d[f+1]?4:0)+(d[f-u+1]?8:0),i[_]&&(r[c+h]=i[_],++g),f++;if(d[f-u]!==d[f]&&(r[c+h]=d[f]?2:4,++g),g>s)return null}for(f=u*(e-1),c=o*n,d[f]!==0&&(r[c]=8,++g),h=1;h<t;h++)d[f]!==d[f+1]&&(r[c+h]=d[f]?4:8,++g),f++;if(d[f]!==0&&(r[c+h]=4,++g),g>s)return null;const p=new Int32Array([0,n,-1,0,-n,0,0,0,1]),b=new Path2D;for(o=0;g&&o<=e;o++){let _=o*n;const x=_+t;for(;_<x&&!r[_];)_++;if(_===x)continue;b.moveTo(_%n,o);const C=_;let S=r[_];do{const k=p[S];do _+=k;while(!r[_]);const D=r[_];D!==5&&D!==10?(S=D,r[_]=0):(S=D&51*S>>4,r[_]&=S>>2|S<<2),b.lineTo(_%n,_/n|0),r[_]||--g}while(C!==_);--o}return d=null,r=null,function(_){_.save(),_.scale(1/t,-1/e),_.translate(0,-e),_.fill(b),_.beginPath(),_.restore()}}class fb{constructor(t,e){this.alphaIsShape=!1,this.fontSize=0,this.fontSizeScale=1,this.textMatrix=U0,this.textMatrixScale=1,this.fontMatrix=ng,this.leading=0,this.x=0,this.y=0,this.lineX=0,this.lineY=0,this.charSpacing=0,this.wordSpacing=0,this.textHScale=1,this.textRenderingMode=ve.FILL,this.textRise=0,this.fillColor="#000000",this.strokeColor="#000000",this.patternFill=!1,this.patternStroke=!1,this.fillAlpha=1,this.strokeAlpha=1,this.lineWidth=1,this.activeSMask=null,this.transferMaps="none",this.startNewPathAndClipBox([0,0,t,e])}clone(){const t=Object.create(this);return t.clipBox=this.clipBox.slice(),t}setCurrentPoint(t,e){this.x=t,this.y=e}updatePathMinMax(t,e,s){[e,s]=W.applyTransform([e,s],t),this.minX=Math.min(this.minX,e),this.minY=Math.min(this.minY,s),this.maxX=Math.max(this.maxX,e),this.maxY=Math.max(this.maxY,s)}updateRectMinMax(t,e){const s=W.applyTransform(e,t),i=W.applyTransform(e.slice(2),t),n=W.applyTransform([e[0],e[3]],t),r=W.applyTransform([e[2],e[1]],t);this.minX=Math.min(this.minX,s[0],i[0],n[0],r[0]),this.minY=Math.min(this.minY,s[1],i[1],n[1],r[1]),this.maxX=Math.max(this.maxX,s[0],i[0],n[0],r[0]),this.maxY=Math.max(this.maxY,s[1],i[1],n[1],r[1])}updateScalingPathMinMax(t,e){W.scaleMinMax(t,e),this.minX=Math.min(this.minX,e[0]),this.minY=Math.min(this.minY,e[1]),this.maxX=Math.max(this.maxX,e[2]),this.maxY=Math.max(this.maxY,e[3])}updateCurvePathMinMax(t,e,s,i,n,r,o,h,c,u){const d=W.bezierBoundingBox(e,s,i,n,r,o,h,c,u);u||this.updateRectMinMax(t,d)}getPathBoundingBox(t=_e.FILL,e=null){const s=[this.minX,this.minY,this.maxX,this.maxY];if(t===_e.STROKE){e||vt("Stroke bounding box must include transform.");const i=W.singularValueDecompose2dScale(e),n=i[0]*this.lineWidth/2,r=i[1]*this.lineWidth/2;s[0]-=n,s[1]-=r,s[2]+=n,s[3]+=r}return s}updateClipFromPath(){const t=W.intersect(this.clipBox,this.getPathBoundingBox());this.startNewPathAndClipBox(t||[0,0,0,0])}isEmptyClip(){return this.minX===1/0}startNewPathAndClipBox(t){this.clipBox=t,this.minX=1/0,this.minY=1/0,this.maxX=0,this.maxY=0}getClippedPathBoundingBox(t=_e.FILL,e=null){return W.intersect(this.clipBox,this.getPathBoundingBox(t,e))}}function gb(a,t){if(t instanceof ImageData){a.putImageData(t,0,0);return}const e=t.height,s=t.width,i=e%Ue,n=(e-i)/Ue,r=i===0?n:n+1,o=a.createImageData(s,Ue);let h=0,c;const u=t.data,d=o.data;let f,g,p,b;if(t.kind===Hu.GRAYSCALE_1BPP){const v=u.byteLength,_=new Uint32Array(d.buffer,0,d.byteLength>>2),x=_.length,C=s+7>>3,S=4294967295,k=Re.isLittleEndian?4278190080:255;for(f=0;f<r;f++){for(p=f<n?Ue:i,c=0,g=0;g<p;g++){const D=v-h;let A=0;const M=D>C?s:D*8-7,O=M&-8;let R=0,L=0;for(;A<O;A+=8)L=u[h++],_[c++]=L&128?S:k,_[c++]=L&64?S:k,_[c++]=L&32?S:k,_[c++]=L&16?S:k,_[c++]=L&8?S:k,_[c++]=L&4?S:k,_[c++]=L&2?S:k,_[c++]=L&1?S:k;for(;A<M;A++)R===0&&(L=u[h++],R=128),_[c++]=L&R?S:k,R>>=1}for(;c<x;)_[c++]=0;a.putImageData(o,0,f*Ue)}}else if(t.kind===Hu.RGBA_32BPP){for(g=0,b=s*Ue*4,f=0;f<n;f++)d.set(u.subarray(h,h+b)),h+=b,a.putImageData(o,0,g),g+=Ue;f<r&&(b=s*i*4,d.set(u.subarray(h,h+b)),a.putImageData(o,0,g))}else if(t.kind===Hu.RGB_24BPP)for(p=Ue,b=s*p,f=0;f<r;f++){for(f>=n&&(p=i,b=s*p),c=0,g=b;g--;)d[c++]=u[h++],d[c++]=u[h++],d[c++]=u[h++],d[c++]=255;a.putImageData(o,0,f*Ue)}else throw new Error(`bad image kind: ${t.kind}`)}function pb(a,t){if(t.bitmap){a.drawImage(t.bitmap,0,0);return}const e=t.height,s=t.width,i=e%Ue,n=(e-i)/Ue,r=i===0?n:n+1,o=a.createImageData(s,Ue);let h=0;const c=t.data,u=o.data;for(let d=0;d<r;d++){const f=d<n?Ue:i;({srcPos:h}=Px({src:c,srcPos:h,dest:u,width:s,height:f,nonBlackColor:0})),a.putImageData(o,0,d*Ue)}}function Uh(a,t){const e=["strokeStyle","fillStyle","fillRule","globalAlpha","lineWidth","lineCap","lineJoin","miterLimit","globalCompositeOperation","font","filter"];for(const s of e)a[s]!==void 0&&(t[s]=a[s]);a.setLineDash!==void 0&&(t.setLineDash(a.getLineDash()),t.lineDashOffset=a.lineDashOffset)}function Zu(a){if(a.strokeStyle=a.fillStyle="#000000",a.fillRule="nonzero",a.globalAlpha=1,a.lineWidth=1,a.lineCap="butt",a.lineJoin="miter",a.miterLimit=10,a.globalCompositeOperation="source-over",a.font="10px sans-serif",a.setLineDash!==void 0&&(a.setLineDash([]),a.lineDashOffset=0),!ye){const{filter:t}=a;t!=="none"&&t!==""&&(a.filter="none")}}function mb(a,t){if(t)return!0;const e=W.singularValueDecompose2dScale(a);e[0]=Math.fround(e[0]),e[1]=Math.fround(e[1]);const s=Math.fround((globalThis.devicePixelRatio||1)*Ln.PDF_TO_CSS_UNITS);return e[0]<=s&&e[1]<=s}const Fx=["butt","round","square"],Ix=["miter","round","bevel"],Nx={},bb={},Xg=class Xg{constructor(t,e,s,i,n,{optionalContentConfig:r,markedContentStack:o=null},h,c){y(this,Ys);this.ctx=t,this.current=new fb(this.ctx.canvas.width,this.ctx.canvas.height),this.stateStack=[],this.pendingClip=null,this.pendingEOFill=!1,this.res=null,this.xobjs=null,this.commonObjs=e,this.objs=s,this.canvasFactory=i,this.filterFactory=n,this.groupStack=[],this.processingType3=null,this.baseTransform=null,this.baseTransformStack=[],this.groupLevel=0,this.smaskStack=[],this.smaskCounter=0,this.tempSMask=null,this.suspendedCtx=null,this.contentVisible=!0,this.markedContentStack=o||[],this.optionalContentConfig=r,this.cachedCanvases=new Rx(this.canvasFactory),this.cachedPatterns=new Map,this.annotationCanvasMap=h,this.viewportScale=1,this.outputScaleX=1,this.outputScaleY=1,this.pageColors=c,this._cachedScaleForStroking=[-1,0],this._cachedGetSinglePixelWidth=null,this._cachedBitmapsMap=new Map}getObject(t,e=null){return typeof t=="string"?t.startsWith("g_")?this.commonObjs.get(t):this.objs.get(t):e}beginDrawing({transform:t,viewport:e,transparency:s=!1,background:i=null}){const n=this.ctx.canvas.width,r=this.ctx.canvas.height,o=this.ctx.fillStyle;if(this.ctx.fillStyle=i||"#ffffff",this.ctx.fillRect(0,0,n,r),this.ctx.fillStyle=o,s){const h=this.cachedCanvases.getCanvas("transparent",n,r);this.compositeCtx=this.ctx,this.transparentCanvas=h.canvas,this.ctx=h.context,this.ctx.save(),this.ctx.transform(...Tt(this.compositeCtx))}this.ctx.save(),Zu(this.ctx),t&&(this.ctx.transform(...t),this.outputScaleX=t[0],this.outputScaleY=t[0]),this.ctx.transform(...e.transform),this.viewportScale=e.scale,this.baseTransform=Tt(this.ctx)}executeOperatorList(t,e,s,i){const n=t.argsArray,r=t.fnArray;let o=e||0;const h=n.length;if(h===o)return o;const c=h-o>ub&&typeof s=="function",u=c?Date.now()+Dx:0;let d=0;const f=this.commonObjs,g=this.objs;let p;for(;;){if(i!==void 0&&o===i.nextBreakPoint)return i.breakIt(o,s),o;if(p=r[o],p!==Hs.dependency)this[p].apply(this,n[o]);else for(const b of n[o]){const v=b.startsWith("g_")?f:g;if(!v.has(b))return v.get(b,s),o}if(o++,o===h)return o;if(c&&++d>ub){if(Date.now()>u)return s(),o;d=0}}}endDrawing(){w(this,Ys,fp).call(this),this.cachedCanvases.clear(),this.cachedPatterns.clear();for(const t of this._cachedBitmapsMap.values()){for(const e of t.values())typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement&&(e.width=e.height=0);t.clear()}this._cachedBitmapsMap.clear(),w(this,Ys,gp).call(this)}_scaleImage(t,e){const s=t.width??t.displayWidth,i=t.height??t.displayHeight;let n=Math.max(Math.hypot(e[0],e[1]),1),r=Math.max(Math.hypot(e[2],e[3]),1),o=s,h=i,c="prescale1",u,d;for(;n>2&&o>1||r>2&&h>1;){let f=o,g=h;n>2&&o>1&&(f=o>=16384?Math.floor(o/2)-1||1:Math.ceil(o/2),n/=o/f),r>2&&h>1&&(g=h>=16384?Math.floor(h/2)-1||1:Math.ceil(h)/2,r/=h/g),u=this.cachedCanvases.getCanvas(c,f,g),d=u.context,d.clearRect(0,0,f,g),d.drawImage(t,0,0,o,h,0,0,f,g),t=u.canvas,o=f,h=g,c=c==="prescale1"?"prescale2":"prescale1"}return{img:t,paintWidth:o,paintHeight:h}}_createMaskCanvas(t){const e=this.ctx,{width:s,height:i}=t,n=this.current.fillColor,r=this.current.patternFill,o=Tt(e);let h,c,u,d;if((t.bitmap||t.data)&&t.count>1){const M=t.bitmap||t.data.buffer;c=JSON.stringify(r?o:[o.slice(0,4),n]),h=this._cachedBitmapsMap.get(M),h||(h=new Map,this._cachedBitmapsMap.set(M,h));const O=h.get(c);if(O&&!r){const R=Math.round(Math.min(o[0],o[2])+o[4]),L=Math.round(Math.min(o[1],o[3])+o[5]);return{canvas:O,offsetX:R,offsetY:L}}u=O}u||(d=this.cachedCanvases.getCanvas("maskCanvas",s,i),pb(d.context,t));let f=W.transform(o,[1/s,0,0,-1/i,0,0]);f=W.transform(f,[1,0,0,1,0,-i]);const[g,p,b,v]=W.getAxialAlignedBoundingBox([0,0,s,i],f),_=Math.round(b-g)||1,x=Math.round(v-p)||1,C=this.cachedCanvases.getCanvas("fillCanvas",_,x),S=C.context,k=g,D=p;S.translate(-k,-D),S.transform(...f),u||(u=this._scaleImage(d.canvas,li(S)),u=u.img,h&&r&&h.set(c,u)),S.imageSmoothingEnabled=mb(Tt(S),t.interpolate),Ju(S,u,0,0,u.width,u.height,0,0,s,i),S.globalCompositeOperation="source-in";const A=W.transform(li(S),[1,0,0,1,-k,-D]);return S.fillStyle=r?n.getPattern(e,this,A,_e.FILL):n,S.fillRect(0,0,s,i),h&&!r&&(this.cachedCanvases.delete("fillCanvas"),h.set(c,C.canvas)),{canvas:C.canvas,offsetX:Math.round(k),offsetY:Math.round(D)}}setLineWidth(t){t!==this.current.lineWidth&&(this._cachedScaleForStroking[0]=-1),this.current.lineWidth=t,this.ctx.lineWidth=t}setLineCap(t){this.ctx.lineCap=Fx[t]}setLineJoin(t){this.ctx.lineJoin=Ix[t]}setMiterLimit(t){this.ctx.miterLimit=t}setDash(t,e){const s=this.ctx;s.setLineDash!==void 0&&(s.setLineDash(t),s.lineDashOffset=e)}setRenderingIntent(t){}setFlatness(t){}setGState(t){for(const[e,s]of t)switch(e){case"LW":this.setLineWidth(s);break;case"LC":this.setLineCap(s);break;case"LJ":this.setLineJoin(s);break;case"ML":this.setMiterLimit(s);break;case"D":this.setDash(s[0],s[1]);break;case"RI":this.setRenderingIntent(s);break;case"FL":this.setFlatness(s);break;case"Font":this.setFont(s[0],s[1]);break;case"CA":this.current.strokeAlpha=s;break;case"ca":this.current.fillAlpha=s,this.ctx.globalAlpha=s;break;case"BM":this.ctx.globalCompositeOperation=s;break;case"SMask":this.current.activeSMask=s?this.tempSMask:null,this.tempSMask=null,this.checkSMaskState();break;case"TR":this.ctx.filter=this.current.transferMaps=this.filterFactory.addFilter(s);break}}get inSMaskMode(){return!!this.suspendedCtx}checkSMaskState(){const t=this.inSMaskMode;this.current.activeSMask&&!t?this.beginSMaskMode():!this.current.activeSMask&&t&&this.endSMaskMode()}beginSMaskMode(){if(this.inSMaskMode)throw new Error("beginSMaskMode called while already in smask mode");const t=this.ctx.canvas.width,e=this.ctx.canvas.height,s="smaskGroupAt"+this.groupLevel,i=this.cachedCanvases.getCanvas(s,t,e);this.suspendedCtx=this.ctx,this.ctx=i.context;const n=this.ctx;n.setTransform(...Tt(this.suspendedCtx)),Uh(this.suspendedCtx,n),Ox(n,this.suspendedCtx),this.setGState([["BM","source-over"],["ca",1],["CA",1]])}endSMaskMode(){if(!this.inSMaskMode)throw new Error("endSMaskMode called while not in smask mode");this.ctx._removeMirroring(),Uh(this.ctx,this.suspendedCtx),this.ctx=this.suspendedCtx,this.suspendedCtx=null}compose(t){if(!this.current.activeSMask)return;t?(t[0]=Math.floor(t[0]),t[1]=Math.floor(t[1]),t[2]=Math.ceil(t[2]),t[3]=Math.ceil(t[3])):t=[0,0,this.ctx.canvas.width,this.ctx.canvas.height];const e=this.current.activeSMask,s=this.suspendedCtx;this.composeSMask(s,e,this.ctx,t),this.ctx.save(),this.ctx.setTransform(1,0,0,1,0,0),this.ctx.clearRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height),this.ctx.restore()}composeSMask(t,e,s,i){const n=i[0],r=i[1],o=i[2]-n,h=i[3]-r;o===0||h===0||(this.genericComposeSMask(e.context,s,o,h,e.subtype,e.backdrop,e.transferMap,n,r,e.offsetX,e.offsetY),t.save(),t.globalAlpha=1,t.globalCompositeOperation="source-over",t.setTransform(1,0,0,1,0,0),t.drawImage(s.canvas,0,0),t.restore())}genericComposeSMask(t,e,s,i,n,r,o,h,c,u,d){let f=t.canvas,g=h-u,p=c-d;if(r){const v=W.makeHexColor(...r);if(g<0||p<0||g+s>f.width||p+i>f.height){const _=this.cachedCanvases.getCanvas("maskExtension",s,i),x=_.context;x.drawImage(f,-g,-p),x.globalCompositeOperation="destination-atop",x.fillStyle=v,x.fillRect(0,0,s,i),x.globalCompositeOperation="source-over",f=_.canvas,g=p=0}else{t.save(),t.globalAlpha=1,t.setTransform(1,0,0,1,0,0);const _=new Path2D;_.rect(g,p,s,i),t.clip(_),t.globalCompositeOperation="destination-atop",t.fillStyle=v,t.fillRect(g,p,s,i),t.restore()}}e.save(),e.globalAlpha=1,e.setTransform(1,0,0,1,0,0),n==="Alpha"&&o?e.filter=this.filterFactory.addAlphaFilter(o):n==="Luminosity"&&(e.filter=this.filterFactory.addLuminosityFilter(o));const b=new Path2D;b.rect(h,c,s,i),e.clip(b),e.globalCompositeOperation="destination-in",e.drawImage(f,g,p,s,i,h,c,s,i),e.restore()}save(){this.inSMaskMode?(Uh(this.ctx,this.suspendedCtx),this.suspendedCtx.save()):this.ctx.save();const t=this.current;this.stateStack.push(t),this.current=t.clone()}restore(){this.stateStack.length===0&&this.inSMaskMode&&this.endSMaskMode(),this.stateStack.length!==0&&(this.current=this.stateStack.pop(),this.inSMaskMode?(this.suspendedCtx.restore(),Uh(this.suspendedCtx,this.ctx)):this.ctx.restore(),this.checkSMaskState(),this.pendingClip=null,this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null)}transform(t,e,s,i,n,r){this.ctx.transform(t,e,s,i,n,r),this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null}constructPath(t,e,s){const i=this.ctx,n=this.current;let r=n.x,o=n.y,h,c;const u=Tt(i),d=u[0]===0&&u[3]===0||u[1]===0&&u[2]===0,f=d?s.slice(0):null;for(let g=0,p=0,b=t.length;g<b;g++)switch(t[g]|0){case Hs.rectangle:r=e[p++],o=e[p++];const v=e[p++],_=e[p++],x=r+v,C=o+_;i.moveTo(r,o),v===0||_===0?i.lineTo(x,C):(i.lineTo(x,o),i.lineTo(x,C),i.lineTo(r,C)),d||n.updateRectMinMax(u,[r,o,x,C]),i.closePath();break;case Hs.moveTo:r=e[p++],o=e[p++],i.moveTo(r,o),d||n.updatePathMinMax(u,r,o);break;case Hs.lineTo:r=e[p++],o=e[p++],i.lineTo(r,o),d||n.updatePathMinMax(u,r,o);break;case Hs.curveTo:h=r,c=o,r=e[p+4],o=e[p+5],i.bezierCurveTo(e[p],e[p+1],e[p+2],e[p+3],r,o),n.updateCurvePathMinMax(u,h,c,e[p],e[p+1],e[p+2],e[p+3],r,o,f),p+=6;break;case Hs.curveTo2:h=r,c=o,i.bezierCurveTo(r,o,e[p],e[p+1],e[p+2],e[p+3]),n.updateCurvePathMinMax(u,h,c,r,o,e[p],e[p+1],e[p+2],e[p+3],f),r=e[p+2],o=e[p+3],p+=4;break;case Hs.curveTo3:h=r,c=o,r=e[p+2],o=e[p+3],i.bezierCurveTo(e[p],e[p+1],r,o,r,o),n.updateCurvePathMinMax(u,h,c,e[p],e[p+1],r,o,r,o,f),p+=4;break;case Hs.closePath:i.closePath();break}d&&n.updateScalingPathMinMax(u,f),n.setCurrentPoint(r,o)}closePath(){this.ctx.closePath()}stroke(t=!0){const e=this.ctx,s=this.current.strokeColor;e.globalAlpha=this.current.strokeAlpha,this.contentVisible&&(typeof s=="object"&&(s!=null&&s.getPattern)?(e.save(),e.strokeStyle=s.getPattern(e,this,li(e),_e.STROKE),this.rescaleAndStroke(!1),e.restore()):this.rescaleAndStroke(!0)),t&&this.consumePath(this.current.getClippedPathBoundingBox()),e.globalAlpha=this.current.fillAlpha}closeStroke(){this.closePath(),this.stroke()}fill(t=!0){const e=this.ctx,s=this.current.fillColor,i=this.current.patternFill;let n=!1;i&&(e.save(),e.fillStyle=s.getPattern(e,this,li(e),_e.FILL),n=!0);const r=this.current.getClippedPathBoundingBox();this.contentVisible&&r!==null&&(this.pendingEOFill?(e.fill("evenodd"),this.pendingEOFill=!1):e.fill()),n&&e.restore(),t&&this.consumePath(r)}eoFill(){this.pendingEOFill=!0,this.fill()}fillStroke(){this.fill(!1),this.stroke(!1),this.consumePath()}eoFillStroke(){this.pendingEOFill=!0,this.fillStroke()}closeFillStroke(){this.closePath(),this.fillStroke()}closeEOFillStroke(){this.pendingEOFill=!0,this.closePath(),this.fillStroke()}endPath(){this.consumePath()}clip(){this.pendingClip=Nx}eoClip(){this.pendingClip=bb}beginText(){this.current.textMatrix=U0,this.current.textMatrixScale=1,this.current.x=this.current.lineX=0,this.current.y=this.current.lineY=0}endText(){const t=this.pendingTextPaths,e=this.ctx;if(t===void 0){e.beginPath();return}const s=new Path2D,i=e.getTransform().invertSelf();for(const{transform:n,x:r,y:o,fontSize:h,path:c}of t)s.addPath(c,new DOMMatrix(n).preMultiplySelf(i).translate(r,o).scale(h,-h));e.clip(s),e.beginPath(),delete this.pendingTextPaths}setCharSpacing(t){this.current.charSpacing=t}setWordSpacing(t){this.current.wordSpacing=t}setHScale(t){this.current.textHScale=t/100}setLeading(t){this.current.leading=-t}setFont(t,e){var u;const s=this.commonObjs.get(t),i=this.current;if(!s)throw new Error(`Can't find font for ${t}`);if(i.fontMatrix=s.fontMatrix||ng,(i.fontMatrix[0]===0||i.fontMatrix[3]===0)&&tt("Invalid font matrix for font "+t),e<0?(e=-e,i.fontDirection=-1):i.fontDirection=1,this.current.font=s,this.current.fontSize=e,s.isType3Font)return;const n=s.loadedName||"sans-serif",r=((u=s.systemFontInfo)==null?void 0:u.css)||`"${n}", ${s.fallbackName}`;let o="normal";s.black?o="900":s.bold&&(o="bold");const h=s.italic?"italic":"normal";let c=e;e<lb?c=lb:e>cb&&(c=cb),this.current.fontSizeScale=e/c,this.ctx.font=`${h} ${o} ${c}px ${r}`}setTextRenderingMode(t){this.current.textRenderingMode=t}setTextRise(t){this.current.textRise=t}moveText(t,e){this.current.x=this.current.lineX+=t,this.current.y=this.current.lineY+=e}setLeadingMoveText(t,e){this.setLeading(-e),this.moveText(t,e)}setTextMatrix(t,e,s,i,n,r){this.current.textMatrix=[t,e,s,i,n,r],this.current.textMatrixScale=Math.hypot(t,e),this.current.x=this.current.lineX=0,this.current.y=this.current.lineY=0}nextLine(){this.moveText(0,this.current.leading)}paintChar(t,e,s,i,n){const r=this.ctx,o=this.current,h=o.font,c=o.textRenderingMode,u=o.fontSize/o.fontSizeScale,d=c&ve.FILL_STROKE_MASK,f=!!(c&ve.ADD_TO_PATH_FLAG),g=o.patternFill&&!h.missingFile,p=o.patternStroke&&!h.missingFile;let b;if((h.disableFontFace||f||g||p)&&(b=h.getPathGenerator(this.commonObjs,t)),h.disableFontFace||g||p){if(r.save(),r.translate(e,s),r.scale(u,-u),d===ve.FILL||d===ve.FILL_STROKE)if(i){const v=r.getTransform();r.setTransform(...i),r.fill(w(this,Ys,pp).call(this,b,v,i))}else r.fill(b);if(d===ve.STROKE||d===ve.FILL_STROKE)if(n){const v=r.getTransform();r.setTransform(...n),r.stroke(w(this,Ys,pp).call(this,b,v,n))}else r.lineWidth/=u,r.stroke(b);r.restore()}else(d===ve.FILL||d===ve.FILL_STROKE)&&r.fillText(t,e,s),(d===ve.STROKE||d===ve.FILL_STROKE)&&r.strokeText(t,e,s);f&&(this.pendingTextPaths||(this.pendingTextPaths=[])).push({transform:Tt(r),x:e,y:s,fontSize:u,path:b})}get isFontSubpixelAAEnabled(){const{context:t}=this.cachedCanvases.getCanvas("isFontSubpixelAAEnabled",10,10);t.scale(1.5,1),t.fillText("I",0,10);const e=t.getImageData(0,0,10,10).data;let s=!1;for(let i=3;i<e.length;i+=4)if(e[i]>0&&e[i]<255){s=!0;break}return st(this,"isFontSubpixelAAEnabled",s)}showText(t){const e=this.current,s=e.font;if(s.isType3Font)return this.showType3Text(t);const i=e.fontSize;if(i===0)return;const n=this.ctx,r=e.fontSizeScale,o=e.charSpacing,h=e.wordSpacing,c=e.fontDirection,u=e.textHScale*c,d=t.length,f=s.vertical,g=f?1:-1,p=s.defaultVMetrics,b=i*e.fontMatrix[0],v=e.textRenderingMode===ve.FILL&&!s.disableFontFace&&!e.patternFill;n.save(),n.transform(...e.textMatrix),n.translate(e.x,e.y+e.textRise),c>0?n.scale(u,-1):n.scale(u,1);let _,x;if(e.patternFill){n.save();const A=e.fillColor.getPattern(n,this,li(n),_e.FILL);_=Tt(n),n.restore(),n.fillStyle=A}if(e.patternStroke){n.save();const A=e.strokeColor.getPattern(n,this,li(n),_e.STROKE);x=Tt(n),n.restore(),n.strokeStyle=A}let C=e.lineWidth;const S=e.textMatrixScale;if(S===0||C===0){const A=e.textRenderingMode&ve.FILL_STROKE_MASK;(A===ve.STROKE||A===ve.FILL_STROKE)&&(C=this.getSinglePixelWidth())}else C/=S;if(r!==1&&(n.scale(r,r),C/=r),n.lineWidth=C,s.isInvalidPDFjsFont){const A=[];let M=0;for(const O of t)A.push(O.unicode),M+=O.width;n.fillText(A.join(""),0,0),e.x+=M*b*u,n.restore(),this.compose();return}let k=0,D;for(D=0;D<d;++D){const A=t[D];if(typeof A=="number"){k+=g*A*i/1e3;continue}let M=!1;const O=(A.isSpace?h:0)+o,R=A.fontChar,L=A.accent;let V,U,G=A.width;if(f){const F=A.vmetric||p,z=-(A.vmetric?F[1]:G*.5)*b,rt=F[2]*b;G=F?-F[0]:G,V=z/r,U=(k+rt)/r}else V=k/r,U=0;if(s.remeasure&&G>0){const F=n.measureText(R).width*1e3/i*r;if(G<F&&this.isFontSubpixelAAEnabled){const z=G/F;M=!0,n.save(),n.scale(z,1),V/=z}else G!==F&&(V+=(G-F)/2e3*i/r)}if(this.contentVisible&&(A.isInFont||s.missingFile)){if(v&&!L)n.fillText(R,V,U);else if(this.paintChar(R,V,U,_,x),L){const F=V+i*L.offset.x/r,z=U-i*L.offset.y/r;this.paintChar(L.fontChar,F,z,_,x)}}const at=f?G*b-O*c:G*b+O*c;k+=at,M&&n.restore()}f?e.y-=k:e.x+=k*u,n.restore(),this.compose()}showType3Text(t){const e=this.ctx,s=this.current,i=s.font,n=s.fontSize,r=s.fontDirection,o=i.vertical?1:-1,h=s.charSpacing,c=s.wordSpacing,u=s.textHScale*r,d=s.fontMatrix||ng,f=t.length,g=s.textRenderingMode===ve.INVISIBLE;let p,b,v,_;if(!(g||n===0)){for(this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null,e.save(),e.transform(...s.textMatrix),e.translate(s.x,s.y),e.scale(u,r),p=0;p<f;++p){if(b=t[p],typeof b=="number"){_=o*b*n/1e3,this.ctx.translate(_,0),s.x+=_*u;continue}const x=(b.isSpace?c:0)+h,C=i.charProcOperatorList[b.operatorListId];if(!C){tt(`Type3 character "${b.operatorListId}" is not available.`);continue}this.contentVisible&&(this.processingType3=b,this.save(),e.scale(n,n),e.transform(...d),this.executeOperatorList(C),this.restore()),v=W.applyTransform([b.width,0],d)[0]*n+x,e.translate(v,0),s.x+=v*u}e.restore(),this.processingType3=null}}setCharWidth(t,e){}setCharWidthAndBounds(t,e,s,i,n,r){this.ctx.rect(s,i,n-s,r-i),this.ctx.clip(),this.endPath()}getColorN_Pattern(t){let e;if(t[0]==="TilingPattern"){const s=t[1],i=this.baseTransform||Tt(this.ctx),n={createCanvasGraphics:r=>new Xg(r,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:this.optionalContentConfig,markedContentStack:this.markedContentStack})};e=new Ag(t,s,this.ctx,n,i)}else e=this._getPattern(t[1],t[2]);return e}setStrokeColorN(){this.current.strokeColor=this.getColorN_Pattern(arguments),this.current.patternStroke=!0}setFillColorN(){this.current.fillColor=this.getColorN_Pattern(arguments),this.current.patternFill=!0}setStrokeRGBColor(t,e,s){this.ctx.strokeStyle=this.current.strokeColor=W.makeHexColor(t,e,s),this.current.patternStroke=!1}setStrokeTransparent(){this.ctx.strokeStyle=this.current.strokeColor="transparent",this.current.patternStroke=!1}setFillRGBColor(t,e,s){this.ctx.fillStyle=this.current.fillColor=W.makeHexColor(t,e,s),this.current.patternFill=!1}setFillTransparent(){this.ctx.fillStyle=this.current.fillColor="transparent",this.current.patternFill=!1}_getPattern(t,e=null){let s;return this.cachedPatterns.has(t)?s=this.cachedPatterns.get(t):(s=Mx(this.getObject(t)),this.cachedPatterns.set(t,s)),e&&(s.matrix=e),s}shadingFill(t){if(!this.contentVisible)return;const e=this.ctx;this.save();const s=this._getPattern(t);e.fillStyle=s.getPattern(e,this,li(e),_e.SHADING);const i=li(e);if(i){const{width:n,height:r}=e.canvas,[o,h,c,u]=W.getAxialAlignedBoundingBox([0,0,n,r],i);this.ctx.fillRect(o,h,c-o,u-h)}else this.ctx.fillRect(-1e10,-1e10,2e10,2e10);this.compose(this.current.getClippedPathBoundingBox()),this.restore()}beginInlineImage(){vt("Should not call beginInlineImage")}beginImageData(){vt("Should not call beginImageData")}paintFormXObjectBegin(t,e){if(this.contentVisible&&(this.save(),this.baseTransformStack.push(this.baseTransform),t&&this.transform(...t),this.baseTransform=Tt(this.ctx),e)){const s=e[2]-e[0],i=e[3]-e[1];this.ctx.rect(e[0],e[1],s,i),this.current.updateRectMinMax(Tt(this.ctx),e),this.clip(),this.endPath()}}paintFormXObjectEnd(){this.contentVisible&&(this.restore(),this.baseTransform=this.baseTransformStack.pop())}beginGroup(t){if(!this.contentVisible)return;this.save(),this.inSMaskMode&&(this.endSMaskMode(),this.current.activeSMask=null);const e=this.ctx;t.isolated||Vu("TODO: Support non-isolated groups."),t.knockout&&tt("Knockout groups not supported.");const s=Tt(e);if(t.matrix&&e.transform(...t.matrix),!t.bbox)throw new Error("Bounding box is required.");let i=W.getAxialAlignedBoundingBox(t.bbox,Tt(e));const n=[0,0,e.canvas.width,e.canvas.height];i=W.intersect(i,n)||[0,0,0,0];const r=Math.floor(i[0]),o=Math.floor(i[1]),h=Math.max(Math.ceil(i[2])-r,1),c=Math.max(Math.ceil(i[3])-o,1);this.current.startNewPathAndClipBox([0,0,h,c]);let u="groupAt"+this.groupLevel;t.smask&&(u+="_smask_"+this.smaskCounter++%2);const d=this.cachedCanvases.getCanvas(u,h,c),f=d.context;f.translate(-r,-o),f.transform(...s),t.smask?this.smaskStack.push({canvas:d.canvas,context:f,offsetX:r,offsetY:o,subtype:t.smask.subtype,backdrop:t.smask.backdrop,transferMap:t.smask.transferMap||null,startTransformInverse:null}):(e.setTransform(1,0,0,1,0,0),e.translate(r,o),e.save()),Uh(e,f),this.ctx=f,this.setGState([["BM","source-over"],["ca",1],["CA",1]]),this.groupStack.push(e),this.groupLevel++}endGroup(t){if(!this.contentVisible)return;this.groupLevel--;const e=this.ctx,s=this.groupStack.pop();if(this.ctx=s,this.ctx.imageSmoothingEnabled=!1,t.smask)this.tempSMask=this.smaskStack.pop(),this.restore();else{this.ctx.restore();const i=Tt(this.ctx);this.restore(),this.ctx.save(),this.ctx.setTransform(...i);const n=W.getAxialAlignedBoundingBox([0,0,e.canvas.width,e.canvas.height],i);this.ctx.drawImage(e.canvas,0,0),this.ctx.restore(),this.compose(n)}}beginAnnotation(t,e,s,i,n){if(w(this,Ys,fp).call(this),Zu(this.ctx),this.ctx.save(),this.save(),this.baseTransform&&this.ctx.setTransform(...this.baseTransform),e){const r=e[2]-e[0],o=e[3]-e[1];if(n&&this.annotationCanvasMap){s=s.slice(),s[4]-=e[0],s[5]-=e[1],e=e.slice(),e[0]=e[1]=0,e[2]=r,e[3]=o;const[h,c]=W.singularValueDecompose2dScale(Tt(this.ctx)),{viewportScale:u}=this,d=Math.ceil(r*this.outputScaleX*u),f=Math.ceil(o*this.outputScaleY*u);this.annotationCanvas=this.canvasFactory.create(d,f);const{canvas:g,context:p}=this.annotationCanvas;this.annotationCanvasMap.set(t,g),this.annotationCanvas.savedCtx=this.ctx,this.ctx=p,this.ctx.save(),this.ctx.setTransform(h,0,0,-c,0,o*c),Zu(this.ctx)}else Zu(this.ctx),this.endPath(),this.ctx.rect(e[0],e[1],r,o),this.ctx.clip(),this.ctx.beginPath()}this.current=new fb(this.ctx.canvas.width,this.ctx.canvas.height),this.transform(...s),this.transform(...i)}endAnnotation(){this.annotationCanvas&&(this.ctx.restore(),w(this,Ys,gp).call(this),this.ctx=this.annotationCanvas.savedCtx,delete this.annotationCanvas.savedCtx,delete this.annotationCanvas)}paintImageMaskXObject(t){if(!this.contentVisible)return;const e=t.count;t=this.getObject(t.data,t),t.count=e;const s=this.ctx,i=this.processingType3;if(i&&(i.compiled===void 0&&(i.compiled=Lx(t)),i.compiled)){i.compiled(s);return}const n=this._createMaskCanvas(t),r=n.canvas;s.save(),s.setTransform(1,0,0,1,0,0),s.drawImage(r,n.offsetX,n.offsetY),s.restore(),this.compose()}paintImageMaskXObjectRepeat(t,e,s=0,i=0,n,r){if(!this.contentVisible)return;t=this.getObject(t.data,t);const o=this.ctx;o.save();const h=Tt(o);o.transform(e,s,i,n,0,0);const c=this._createMaskCanvas(t);o.setTransform(1,0,0,1,c.offsetX-h[4],c.offsetY-h[5]);for(let u=0,d=r.length;u<d;u+=2){const f=W.transform(h,[e,s,i,n,r[u],r[u+1]]),[g,p]=W.applyTransform([0,0],f);o.drawImage(c.canvas,g,p)}o.restore(),this.compose()}paintImageMaskXObjectGroup(t){if(!this.contentVisible)return;const e=this.ctx,s=this.current.fillColor,i=this.current.patternFill;for(const n of t){const{data:r,width:o,height:h,transform:c}=n,u=this.cachedCanvases.getCanvas("maskCanvas",o,h),d=u.context;d.save();const f=this.getObject(r,n);pb(d,f),d.globalCompositeOperation="source-in",d.fillStyle=i?s.getPattern(d,this,li(e),_e.FILL):s,d.fillRect(0,0,o,h),d.restore(),e.save(),e.transform(...c),e.scale(1,-1),Ju(e,u.canvas,0,0,o,h,0,-1,1,1),e.restore()}this.compose()}paintImageXObject(t){if(!this.contentVisible)return;const e=this.getObject(t);if(!e){tt("Dependent image isn't ready yet");return}this.paintInlineImageXObject(e)}paintImageXObjectRepeat(t,e,s,i){if(!this.contentVisible)return;const n=this.getObject(t);if(!n){tt("Dependent image isn't ready yet");return}const r=n.width,o=n.height,h=[];for(let c=0,u=i.length;c<u;c+=2)h.push({transform:[e,0,0,s,i[c],i[c+1]],x:0,y:0,w:r,h:o});this.paintInlineImageXObjectGroup(n,h)}applyTransferMapsToCanvas(t){return this.current.transferMaps!=="none"&&(t.filter=this.current.transferMaps,t.drawImage(t.canvas,0,0),t.filter="none"),t.canvas}applyTransferMapsToBitmap(t){if(this.current.transferMaps==="none")return t.bitmap;const{bitmap:e,width:s,height:i}=t,n=this.cachedCanvases.getCanvas("inlineImage",s,i),r=n.context;return r.filter=this.current.transferMaps,r.drawImage(e,0,0),r.filter="none",n.canvas}paintInlineImageXObject(t){if(!this.contentVisible)return;const e=t.width,s=t.height,i=this.ctx;if(this.save(),!ye){const{filter:o}=i;o!=="none"&&o!==""&&(i.filter="none")}i.scale(1/e,-1/s);let n;if(t.bitmap)n=this.applyTransferMapsToBitmap(t);else if(typeof HTMLElement=="function"&&t instanceof HTMLElement||!t.data)n=t;else{const h=this.cachedCanvases.getCanvas("inlineImage",e,s).context;gb(h,t),n=this.applyTransferMapsToCanvas(h)}const r=this._scaleImage(n,li(i));i.imageSmoothingEnabled=mb(Tt(i),t.interpolate),Ju(i,r.img,0,0,r.paintWidth,r.paintHeight,0,-s,e,s),this.compose(),this.restore()}paintInlineImageXObjectGroup(t,e){if(!this.contentVisible)return;const s=this.ctx;let i;if(t.bitmap)i=t.bitmap;else{const n=t.width,r=t.height,h=this.cachedCanvases.getCanvas("inlineImage",n,r).context;gb(h,t),i=this.applyTransferMapsToCanvas(h)}for(const n of e)s.save(),s.transform(...n.transform),s.scale(1,-1),Ju(s,i,n.x,n.y,n.w,n.h,0,-1,1,1),s.restore();this.compose()}paintSolidColorImageMask(){this.contentVisible&&(this.ctx.fillRect(0,0,1,1),this.compose())}markPoint(t){}markPointProps(t,e){}beginMarkedContent(t){this.markedContentStack.push({visible:!0})}beginMarkedContentProps(t,e){t==="OC"?this.markedContentStack.push({visible:this.optionalContentConfig.isVisible(e)}):this.markedContentStack.push({visible:!0}),this.contentVisible=this.isContentVisible()}endMarkedContent(){this.markedContentStack.pop(),this.contentVisible=this.isContentVisible()}beginCompat(){}endCompat(){}consumePath(t){const e=this.current.isEmptyClip();this.pendingClip&&this.current.updateClipFromPath(),this.pendingClip||this.compose(t);const s=this.ctx;this.pendingClip&&(e||(this.pendingClip===bb?s.clip("evenodd"):s.clip()),this.pendingClip=null),this.current.startNewPathAndClipBox(this.current.clipBox),s.beginPath()}getSinglePixelWidth(){if(!this._cachedGetSinglePixelWidth){const t=Tt(this.ctx);if(t[1]===0&&t[2]===0)this._cachedGetSinglePixelWidth=1/Math.min(Math.abs(t[0]),Math.abs(t[3]));else{const e=Math.abs(t[0]*t[3]-t[2]*t[1]),s=Math.hypot(t[0],t[2]),i=Math.hypot(t[1],t[3]);this._cachedGetSinglePixelWidth=Math.max(s,i)/e}}return this._cachedGetSinglePixelWidth}getScaleForStroking(){if(this._cachedScaleForStroking[0]===-1){const{lineWidth:t}=this.current,{a:e,b:s,c:i,d:n}=this.ctx.getTransform();let r,o;if(s===0&&i===0){const h=Math.abs(e),c=Math.abs(n);if(h===c)if(t===0)r=o=1/h;else{const u=h*t;r=o=u<1?1/u:1}else if(t===0)r=1/h,o=1/c;else{const u=h*t,d=c*t;r=u<1?1/u:1,o=d<1?1/d:1}}else{const h=Math.abs(e*n-s*i),c=Math.hypot(e,s),u=Math.hypot(i,n);if(t===0)r=u/h,o=c/h;else{const d=t*h;r=u>d?u/d:1,o=c>d?c/d:1}}this._cachedScaleForStroking[0]=r,this._cachedScaleForStroking[1]=o}return this._cachedScaleForStroking}rescaleAndStroke(t){const{ctx:e}=this,{lineWidth:s}=this.current,[i,n]=this.getScaleForStroking();if(e.lineWidth=s||1,i===1&&n===1){e.stroke();return}const r=e.getLineDash();if(t&&e.save(),e.scale(i,n),r.length>0){const o=Math.max(i,n);e.setLineDash(r.map(h=>h/o)),e.lineDashOffset/=o}e.stroke(),t&&e.restore()}isContentVisible(){for(let t=this.markedContentStack.length-1;t>=0;t--)if(!this.markedContentStack[t].visible)return!1;return!0}};Ys=new WeakSet,fp=function(){for(;this.stateStack.length||this.inSMaskMode;)this.restore();this.current.activeSMask=null,this.ctx.restore(),this.transparentCanvas&&(this.ctx=this.compositeCtx,this.ctx.save(),this.ctx.setTransform(1,0,0,1,0,0),this.ctx.drawImage(this.transparentCanvas,0,0),this.ctx.restore(),this.transparentCanvas=null)},gp=function(){if(this.pageColors){const t=this.filterFactory.addHCMFilter(this.pageColors.foreground,this.pageColors.background);if(t!=="none"){const e=this.ctx.filter;this.ctx.filter=t,this.ctx.drawImage(this.ctx.canvas,0,0),this.ctx.filter=e}}},pp=function(t,e,s){const i=new Path2D;return i.addPath(t,new DOMMatrix(s).invertSelf().multiplySelf(e)),i};let ra=Xg;for(const a in Hs)ra.prototype[a]!==void 0&&(ra.prototype[Hs[a]]=ra.prototype[a]);class Vi{static get workerPort(){return l(this,Tl)}static set workerPort(t){if(!(typeof Worker<"u"&&t instanceof Worker)&&t!==null)throw new Error("Invalid `workerPort` type.");m(this,Tl,t)}static get workerSrc(){return l(this,El)}static set workerSrc(t){if(typeof t!="string")throw new Error("Invalid `workerSrc` type.");m(this,El,t)}}Tl=new WeakMap,El=new WeakMap,y(Vi,Tl,null),y(Vi,El,"");class jx{constructor({parsedData:t,rawData:e}){y(this,so);y(this,kl);m(this,so,t),m(this,kl,e)}getRaw(){return l(this,kl)}get(t){return l(this,so).get(t)??null}getAll(){return hg(l(this,so))}has(t){return l(this,so).has(t)}}so=new WeakMap,kl=new WeakMap;const oa=Symbol("INTERNAL");class Bx{constructor(t,{name:e,intent:s,usage:i,rbGroups:n}){y(this,Ml,!1);y(this,Pl,!1);y(this,Dl,!1);y(this,Ta,!0);m(this,Ml,!!(t&ts.DISPLAY)),m(this,Pl,!!(t&ts.PRINT)),this.name=e,this.intent=s,this.usage=i,this.rbGroups=n}get visible(){if(l(this,Dl))return l(this,Ta);if(!l(this,Ta))return!1;const{print:t,view:e}=this.usage;return l(this,Ml)?(e==null?void 0:e.viewState)!=="OFF":l(this,Pl)?(t==null?void 0:t.printState)!=="OFF":!0}_setVisible(t,e,s=!1){t!==oa&&vt("Internal method `_setVisible` called."),m(this,Dl,s),m(this,Ta,e)}}Ml=new WeakMap,Pl=new WeakMap,Dl=new WeakMap,Ta=new WeakMap;class Hx{constructor(t,e=ts.DISPLAY){y(this,Ol);y(this,qn,null);y(this,mt,new Map);y(this,Ea,null);y(this,ka,null);if(this.renderingIntent=e,this.name=null,this.creator=null,t!==null){this.name=t.name,this.creator=t.creator,m(this,ka,t.order);for(const s of t.groups)l(this,mt).set(s.id,new Bx(e,s));if(t.baseState==="OFF")for(const s of l(this,mt).values())s._setVisible(oa,!1);for(const s of t.on)l(this,mt).get(s)._setVisible(oa,!0);for(const s of t.off)l(this,mt).get(s)._setVisible(oa,!1);m(this,Ea,this.getHash())}}isVisible(t){if(l(this,mt).size===0)return!0;if(!t)return Vu("Optional content group not defined."),!0;if(t.type==="OCG")return l(this,mt).has(t.id)?l(this,mt).get(t.id).visible:(tt(`Optional content group not found: ${t.id}`),!0);if(t.type==="OCMD"){if(t.expression)return w(this,Ol,mp).call(this,t.expression);if(!t.policy||t.policy==="AnyOn"){for(const e of t.ids){if(!l(this,mt).has(e))return tt(`Optional content group not found: ${e}`),!0;if(l(this,mt).get(e).visible)return!0}return!1}else if(t.policy==="AllOn"){for(const e of t.ids){if(!l(this,mt).has(e))return tt(`Optional content group not found: ${e}`),!0;if(!l(this,mt).get(e).visible)return!1}return!0}else if(t.policy==="AnyOff"){for(const e of t.ids){if(!l(this,mt).has(e))return tt(`Optional content group not found: ${e}`),!0;if(!l(this,mt).get(e).visible)return!0}return!1}else if(t.policy==="AllOff"){for(const e of t.ids){if(!l(this,mt).has(e))return tt(`Optional content group not found: ${e}`),!0;if(l(this,mt).get(e).visible)return!1}return!0}return tt(`Unknown optional content policy ${t.policy}.`),!0}return tt(`Unknown group type ${t.type}.`),!0}setVisibility(t,e=!0,s=!0){var n;const i=l(this,mt).get(t);if(!i){tt(`Optional content group not found: ${t}`);return}if(s&&e&&i.rbGroups.length)for(const r of i.rbGroups)for(const o of r)o!==t&&((n=l(this,mt).get(o))==null||n._setVisible(oa,!1,!0));i._setVisible(oa,!!e,!0),m(this,qn,null)}setOCGState({state:t,preserveRB:e}){let s;for(const i of t){switch(i){case"ON":case"OFF":case"Toggle":s=i;continue}const n=l(this,mt).get(i);if(n)switch(s){case"ON":this.setVisibility(i,!0,e);break;case"OFF":this.setVisibility(i,!1,e);break;case"Toggle":this.setVisibility(i,!n.visible,e);break}}m(this,qn,null)}get hasInitialVisibility(){return l(this,Ea)===null||this.getHash()===l(this,Ea)}getOrder(){return l(this,mt).size?l(this,ka)?l(this,ka).slice():[...l(this,mt).keys()]:null}getGroups(){return l(this,mt).size>0?hg(l(this,mt)):null}getGroup(t){return l(this,mt).get(t)||null}getHash(){if(l(this,qn)!==null)return l(this,qn);const t=new J0;for(const[e,s]of l(this,mt))t.update(`${e}:${s.visible}`);return m(this,qn,t.hexdigest())}}qn=new WeakMap,mt=new WeakMap,Ea=new WeakMap,ka=new WeakMap,Ol=new WeakSet,mp=function(t){const e=t.length;if(e<2)return!0;const s=t[0];for(let i=1;i<e;i++){const n=t[i];let r;if(Array.isArray(n))r=w(this,Ol,mp).call(this,n);else if(l(this,mt).has(n))r=l(this,mt).get(n).visible;else return tt(`Optional content group not found: ${n}`),!0;switch(s){case"And":if(!r)return!1;break;case"Or":if(r)return!0;break;case"Not":return!r;default:return!0}}return s==="And"};class Gx{constructor(t,{disableRange:e=!1,disableStream:s=!1}){Xt(t,'PDFDataTransportStream - missing required "pdfDataRangeTransport" argument.');const{length:i,initialData:n,progressiveDone:r,contentDispositionFilename:o}=t;if(this._queuedChunks=[],this._progressiveDone=r,this._contentDispositionFilename=o,(n==null?void 0:n.length)>0){const h=n instanceof Uint8Array&&n.byteLength===n.buffer.byteLength?n.buffer:new Uint8Array(n).buffer;this._queuedChunks.push(h)}this._pdfDataRangeTransport=t,this._isStreamingSupported=!s,this._isRangeSupported=!e,this._contentLength=i,this._fullRequestReader=null,this._rangeReaders=[],t.addRangeListener((h,c)=>{this._onReceiveData({begin:h,chunk:c})}),t.addProgressListener((h,c)=>{this._onProgress({loaded:h,total:c})}),t.addProgressiveReadListener(h=>{this._onReceiveData({chunk:h})}),t.addProgressiveDoneListener(()=>{this._onProgressiveDone()}),t.transportReady()}_onReceiveData({begin:t,chunk:e}){const s=e instanceof Uint8Array&&e.byteLength===e.buffer.byteLength?e.buffer:new Uint8Array(e).buffer;if(t===void 0)this._fullRequestReader?this._fullRequestReader._enqueue(s):this._queuedChunks.push(s);else{const i=this._rangeReaders.some(function(n){return n._begin!==t?!1:(n._enqueue(s),!0)});Xt(i,"_onReceiveData - no `PDFDataTransportStreamRangeReader` instance found.")}}get _progressiveDataLength(){var t;return((t=this._fullRequestReader)==null?void 0:t._loaded)??0}_onProgress(t){var e,s,i,n;t.total===void 0?(s=(e=this._rangeReaders[0])==null?void 0:e.onProgress)==null||s.call(e,{loaded:t.loaded}):(n=(i=this._fullRequestReader)==null?void 0:i.onProgress)==null||n.call(i,{loaded:t.loaded,total:t.total})}_onProgressiveDone(){var t;(t=this._fullRequestReader)==null||t.progressiveDone(),this._progressiveDone=!0}_removeRangeReader(t){const e=this._rangeReaders.indexOf(t);e>=0&&this._rangeReaders.splice(e,1)}getFullReader(){Xt(!this._fullRequestReader,"PDFDataTransportStream.getFullReader can only be called once.");const t=this._queuedChunks;return this._queuedChunks=null,new zx(this,t,this._progressiveDone,this._contentDispositionFilename)}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new Vx(this,t,e);return this._pdfDataRangeTransport.requestDataRange(t,e),this._rangeReaders.push(s),s}cancelAllRequests(t){var e;(e=this._fullRequestReader)==null||e.cancel(t);for(const s of this._rangeReaders.slice(0))s.cancel(t);this._pdfDataRangeTransport.abort()}}class zx{constructor(t,e,s=!1,i=null){this._stream=t,this._done=s||!1,this._filename=fg(i)?i:null,this._queuedChunks=e||[],this._loaded=0;for(const n of this._queuedChunks)this._loaded+=n.byteLength;this._requests=[],this._headersReady=Promise.resolve(),t._fullRequestReader=this,this.onProgress=null}_enqueue(t){this._done||(this._requests.length>0?this._requests.shift().resolve({value:t,done:!1}):this._queuedChunks.push(t),this._loaded+=t.byteLength)}get headersReady(){return this._headersReady}get filename(){return this._filename}get isRangeSupported(){return this._stream._isRangeSupported}get isStreamingSupported(){return this._stream._isStreamingSupported}get contentLength(){return this._stream._contentLength}async read(){if(this._queuedChunks.length>0)return{value:this._queuedChunks.shift(),done:!1};if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0;for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0}progressiveDone(){this._done||(this._done=!0)}}class Vx{constructor(t,e,s){this._stream=t,this._begin=e,this._end=s,this._queuedChunk=null,this._requests=[],this._done=!1,this.onProgress=null}_enqueue(t){if(!this._done){if(this._requests.length===0)this._queuedChunk=t;else{this._requests.shift().resolve({value:t,done:!1});for(const s of this._requests)s.resolve({value:void 0,done:!0});this._requests.length=0}this._done=!0,this._stream._removeRangeReader(this)}}get isStreamingSupported(){return!1}async read(){if(this._queuedChunk){const e=this._queuedChunk;return this._queuedChunk=null,{value:e,done:!1}}if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0;for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0,this._stream._removeRangeReader(this)}}function Xx(a){let t=!0,e=s("filename\\*","i").exec(a);if(e){e=e[1];let u=o(e);return u=unescape(u),u=h(u),u=c(u),n(u)}if(e=r(a),e){const u=c(e);return n(u)}if(e=s("filename","i").exec(a),e){e=e[1];let u=o(e);return u=c(u),n(u)}function s(u,d){return new RegExp("(?:^|;)\\s*"+u+'\\s*=\\s*([^";\\s][^;\\s]*|"(?:[^"\\\\]|\\\\"?)+"?)',d)}function i(u,d){if(u){if(!/^[\x00-\xFF]+$/.test(d))return d;try{const f=new TextDecoder(u,{fatal:!0}),g=Wu(d);d=f.decode(g),t=!1}catch{}}return d}function n(u){return t&&/[\x80-\xff]/.test(u)&&(u=i("utf-8",u),t&&(u=i("iso-8859-1",u))),u}function r(u){const d=[];let f;const g=s("filename\\*((?!0\\d)\\d+)(\\*?)","ig");for(;(f=g.exec(u))!==null;){let[,b,v,_]=f;if(b=parseInt(b,10),b in d){if(b===0)break;continue}d[b]=[v,_]}const p=[];for(let b=0;b<d.length&&b in d;++b){let[v,_]=d[b];_=o(_),v&&(_=unescape(_),b===0&&(_=h(_))),p.push(_)}return p.join("")}function o(u){if(u.startsWith('"')){const d=u.slice(1).split('\\"');for(let f=0;f<d.length;++f){const g=d[f].indexOf('"');g!==-1&&(d[f]=d[f].slice(0,g),d.length=f+1),d[f]=d[f].replaceAll(/\\(.)/g,"$1")}u=d.join('"')}return u}function h(u){const d=u.indexOf("'");if(d===-1)return u;const f=u.slice(0,d),p=u.slice(d+1).replace(/^[^']*'/,"");return i(f,p)}function c(u){return!u.startsWith("=?")||/[\x00-\x19\x80-\xff]/.test(u)?u:u.replaceAll(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g,function(d,f,g,p){if(g==="q"||g==="Q")return p=p.replaceAll("_"," "),p=p.replaceAll(/=([0-9a-fA-F]{2})/g,function(b,v){return String.fromCharCode(parseInt(v,16))}),i(f,p);try{p=atob(p)}catch{}return i(f,p)})}return""}function yb(a,t){const e=new Headers;if(!a||!t||typeof t!="object")return e;for(const s in t){const i=t[s];i!==void 0&&e.append(s,i)}return e}function td(a){try{return new URL(a).origin}catch{}return null}function vb({responseHeaders:a,isHttp:t,rangeChunkSize:e,disableRange:s}){const i={allowRangeRequests:!1,suggestedLength:void 0},n=parseInt(a.get("Content-Length"),10);return!Number.isInteger(n)||(i.suggestedLength=n,n<=2*e)||s||!t||a.get("Accept-Ranges")!=="bytes"||(a.get("Content-Encoding")||"identity")!=="identity"||(i.allowRangeRequests=!0),i}function _b(a){const t=a.get("Content-Disposition");if(t){let e=Xx(t);if(e.includes("%"))try{e=decodeURIComponent(e)}catch{}if(fg(e))return e}return null}function ed(a,t){return a===404||a===0&&t.startsWith("file:")?new Gh('Missing PDF "'+t+'".'):new Xu(`Unexpected server response (${a}) while retrieving PDF "${t}".`,a)}function wb(a){return a===200||a===206}function xb(a,t,e){return{method:"GET",headers:a,signal:e.signal,mode:"cors",credentials:t?"include":"same-origin",redirect:"follow"}}function Sb(a){return a instanceof Uint8Array?a.buffer:a instanceof ArrayBuffer?a:(tt(`getArrayBuffer - unexpected data format: ${a}`),new Uint8Array(a).buffer)}class Cb{constructor(t){$(this,"_responseOrigin",null);this.source=t,this.isHttp=/^https?:/i.test(t.url),this.headers=yb(this.isHttp,t.httpHeaders),this._fullRequestReader=null,this._rangeRequestReaders=[]}get _progressiveDataLength(){var t;return((t=this._fullRequestReader)==null?void 0:t._loaded)??0}getFullReader(){return Xt(!this._fullRequestReader,"PDFFetchStream.getFullReader can only be called once."),this._fullRequestReader=new Wx(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new Ux(this,t,e);return this._rangeRequestReaders.push(s),s}cancelAllRequests(t){var e;(e=this._fullRequestReader)==null||e.cancel(t);for(const s of this._rangeRequestReaders.slice(0))s.cancel(t)}}class Wx{constructor(t){this._stream=t,this._reader=null,this._loaded=0,this._filename=null;const e=t.source;this._withCredentials=e.withCredentials||!1,this._contentLength=e.length,this._headersCapability=Promise.withResolvers(),this._disableRange=e.disableRange||!1,this._rangeChunkSize=e.rangeChunkSize,!this._rangeChunkSize&&!this._disableRange&&(this._disableRange=!0),this._abortController=new AbortController,this._isStreamingSupported=!e.disableStream,this._isRangeSupported=!e.disableRange;const s=new Headers(t.headers),i=e.url;fetch(i,xb(s,this._withCredentials,this._abortController)).then(n=>{if(t._responseOrigin=td(n.url),!wb(n.status))throw ed(n.status,i);this._reader=n.body.getReader(),this._headersCapability.resolve();const r=n.headers,{allowRangeRequests:o,suggestedLength:h}=vb({responseHeaders:r,isHttp:t.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});this._isRangeSupported=o,this._contentLength=h||this._contentLength,this._filename=_b(r),!this._isStreamingSupported&&this._isRangeSupported&&this.cancel(new Rn("Streaming is disabled."))}).catch(this._headersCapability.reject),this.onProgress=null}get headersReady(){return this._headersCapability.promise}get filename(){return this._filename}get contentLength(){return this._contentLength}get isRangeSupported(){return this._isRangeSupported}get isStreamingSupported(){return this._isStreamingSupported}async read(){var s;await this._headersCapability.promise;const{value:t,done:e}=await this._reader.read();return e?{value:t,done:e}:(this._loaded+=t.byteLength,(s=this.onProgress)==null||s.call(this,{loaded:this._loaded,total:this._contentLength}),{value:Sb(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}class Ux{constructor(t,e,s){this._stream=t,this._reader=null,this._loaded=0;const i=t.source;this._withCredentials=i.withCredentials||!1,this._readCapability=Promise.withResolvers(),this._isStreamingSupported=!i.disableStream,this._abortController=new AbortController;const n=new Headers(t.headers);n.append("Range",`bytes=${e}-${s-1}`);const r=i.url;fetch(r,xb(n,this._withCredentials,this._abortController)).then(o=>{const h=td(o.url);if(h!==t._responseOrigin)throw new Error(`Expected range response-origin "${h}" to match "${t._responseOrigin}".`);if(!wb(o.status))throw ed(o.status,r);this._readCapability.resolve(),this._reader=o.body.getReader()}).catch(this._readCapability.reject),this.onProgress=null}get isStreamingSupported(){return this._isStreamingSupported}async read(){var s;await this._readCapability.promise;const{value:t,done:e}=await this._reader.read();return e?{value:t,done:e}:(this._loaded+=t.byteLength,(s=this.onProgress)==null||s.call(this,{loaded:this._loaded}),{value:Sb(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}const Tg=200,Eg=206;function Yx(a){const t=a.response;return typeof t!="string"?t:Wu(t).buffer}class $x{constructor({url:t,httpHeaders:e,withCredentials:s}){$(this,"_responseOrigin",null);this.url=t,this.isHttp=/^https?:/i.test(t),this.headers=yb(this.isHttp,e),this.withCredentials=s||!1,this.currXhrId=0,this.pendingRequests=Object.create(null)}request(t){const e=new XMLHttpRequest,s=this.currXhrId++,i=this.pendingRequests[s]={xhr:e};e.open("GET",this.url),e.withCredentials=this.withCredentials;for(const[n,r]of this.headers)e.setRequestHeader(n,r);return this.isHttp&&"begin"in t&&"end"in t?(e.setRequestHeader("Range",`bytes=${t.begin}-${t.end-1}`),i.expectedStatus=Eg):i.expectedStatus=Tg,e.responseType="arraybuffer",Xt(t.onError,"Expected `onError` callback to be provided."),e.onerror=()=>{t.onError(e.status)},e.onreadystatechange=this.onStateChange.bind(this,s),e.onprogress=this.onProgress.bind(this,s),i.onHeadersReceived=t.onHeadersReceived,i.onDone=t.onDone,i.onError=t.onError,i.onProgress=t.onProgress,e.send(null),s}onProgress(t,e){var i;const s=this.pendingRequests[t];s&&((i=s.onProgress)==null||i.call(s,e))}onStateChange(t,e){const s=this.pendingRequests[t];if(!s)return;const i=s.xhr;if(i.readyState>=2&&s.onHeadersReceived&&(s.onHeadersReceived(),delete s.onHeadersReceived),i.readyState!==4||!(t in this.pendingRequests))return;if(delete this.pendingRequests[t],i.status===0&&this.isHttp){s.onError(i.status);return}const n=i.status||Tg;if(!(n===Tg&&s.expectedStatus===Eg)&&n!==s.expectedStatus){s.onError(i.status);return}const o=Yx(i);if(n===Eg){const h=i.getResponseHeader("Content-Range"),c=/bytes (\d+)-(\d+)\/(\d+)/.exec(h);c?s.onDone({begin:parseInt(c[1],10),chunk:o}):(tt('Missing or invalid "Content-Range" header.'),s.onError(0))}else o?s.onDone({begin:0,chunk:o}):s.onError(i.status)}getRequestXhr(t){return this.pendingRequests[t].xhr}isPendingRequest(t){return t in this.pendingRequests}abortRequest(t){const e=this.pendingRequests[t].xhr;delete this.pendingRequests[t],e.abort()}}class qx{constructor(t){this._source=t,this._manager=new $x(t),this._rangeChunkSize=t.rangeChunkSize,this._fullRequestReader=null,this._rangeRequestReaders=[]}_onRangeRequestReaderClosed(t){const e=this._rangeRequestReaders.indexOf(t);e>=0&&this._rangeRequestReaders.splice(e,1)}getFullReader(){return Xt(!this._fullRequestReader,"PDFNetworkStream.getFullReader can only be called once."),this._fullRequestReader=new Kx(this._manager,this._source),this._fullRequestReader}getRangeReader(t,e){const s=new Qx(this._manager,t,e);return s.onClosed=this._onRangeRequestReaderClosed.bind(this),this._rangeRequestReaders.push(s),s}cancelAllRequests(t){var e;(e=this._fullRequestReader)==null||e.cancel(t);for(const s of this._rangeRequestReaders.slice(0))s.cancel(t)}}class Kx{constructor(t,e){this._manager=t,this._url=e.url,this._fullRequestId=t.request({onHeadersReceived:this._onHeadersReceived.bind(this),onDone:this._onDone.bind(this),onError:this._onError.bind(this),onProgress:this._onProgress.bind(this)}),this._headersCapability=Promise.withResolvers(),this._disableRange=e.disableRange||!1,this._contentLength=e.length,this._rangeChunkSize=e.rangeChunkSize,!this._rangeChunkSize&&!this._disableRange&&(this._disableRange=!0),this._isStreamingSupported=!1,this._isRangeSupported=!1,this._cachedChunks=[],this._requests=[],this._done=!1,this._storedError=void 0,this._filename=null,this.onProgress=null}_onHeadersReceived(){const t=this._fullRequestId,e=this._manager.getRequestXhr(t);this._manager._responseOrigin=td(e.responseURL);const s=e.getAllResponseHeaders(),i=new Headers(s?s.trimStart().replace(/[^\S ]+$/,"").split(/[\r\n]+/).map(o=>{const[h,...c]=o.split(": ");return[h,c.join(": ")]}):[]),{allowRangeRequests:n,suggestedLength:r}=vb({responseHeaders:i,isHttp:this._manager.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});n&&(this._isRangeSupported=!0),this._contentLength=r||this._contentLength,this._filename=_b(i),this._isRangeSupported&&this._manager.abortRequest(t),this._headersCapability.resolve()}_onDone(t){if(t&&(this._requests.length>0?this._requests.shift().resolve({value:t.chunk,done:!1}):this._cachedChunks.push(t.chunk)),this._done=!0,!(this._cachedChunks.length>0)){for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0}}_onError(t){this._storedError=ed(t,this._url),this._headersCapability.reject(this._storedError);for(const e of this._requests)e.reject(this._storedError);this._requests.length=0,this._cachedChunks.length=0}_onProgress(t){var e;(e=this.onProgress)==null||e.call(this,{loaded:t.loaded,total:t.lengthComputable?t.total:this._contentLength})}get filename(){return this._filename}get isRangeSupported(){return this._isRangeSupported}get isStreamingSupported(){return this._isStreamingSupported}get contentLength(){return this._contentLength}get headersReady(){return this._headersCapability.promise}async read(){if(await this._headersCapability.promise,this._storedError)throw this._storedError;if(this._cachedChunks.length>0)return{value:this._cachedChunks.shift(),done:!1};if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0,this._headersCapability.reject(t);for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0,this._manager.isPendingRequest(this._fullRequestId)&&this._manager.abortRequest(this._fullRequestId),this._fullRequestReader=null}}class Qx{constructor(t,e,s){this._manager=t,this._url=t.url,this._requestId=t.request({begin:e,end:s,onHeadersReceived:this._onHeadersReceived.bind(this),onDone:this._onDone.bind(this),onError:this._onError.bind(this),onProgress:this._onProgress.bind(this)}),this._requests=[],this._queuedChunk=null,this._done=!1,this._storedError=void 0,this.onProgress=null,this.onClosed=null}_onHeadersReceived(){var e;const t=td((e=this._manager.getRequestXhr(this._requestId))==null?void 0:e.responseURL);t!==this._manager._responseOrigin&&(this._storedError=new Error(`Expected range response-origin "${t}" to match "${this._manager._responseOrigin}".`),this._onError(0))}_close(){var t;(t=this.onClosed)==null||t.call(this,this)}_onDone(t){const e=t.chunk;this._requests.length>0?this._requests.shift().resolve({value:e,done:!1}):this._queuedChunk=e,this._done=!0;for(const s of this._requests)s.resolve({value:void 0,done:!0});this._requests.length=0,this._close()}_onError(t){this._storedError??(this._storedError=ed(t,this._url));for(const e of this._requests)e.reject(this._storedError);this._requests.length=0,this._queuedChunk=null}_onProgress(t){var e;this.isStreamingSupported||(e=this.onProgress)==null||e.call(this,{loaded:t.loaded})}get isStreamingSupported(){return!1}async read(){if(this._storedError)throw this._storedError;if(this._queuedChunk!==null){const e=this._queuedChunk;return this._queuedChunk=null,{value:e,done:!1}}if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0;for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0,this._manager.isPendingRequest(this._requestId)&&this._manager.abortRequest(this._requestId),this._close()}}const Jx=/^[a-z][a-z0-9\-+.]+:/i;function Zx(a){if(Jx.test(a))return new URL(a);const t=process.getBuiltinModule("url");return new URL(t.pathToFileURL(a))}class tS{constructor(t){this.source=t,this.url=Zx(t.url),Xt(this.url.protocol==="file:","PDFNodeStream only supports file:// URLs."),this._fullRequestReader=null,this._rangeRequestReaders=[]}get _progressiveDataLength(){var t;return((t=this._fullRequestReader)==null?void 0:t._loaded)??0}getFullReader(){return Xt(!this._fullRequestReader,"PDFNodeStream.getFullReader can only be called once."),this._fullRequestReader=new eS(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new sS(this,t,e);return this._rangeRequestReaders.push(s),s}cancelAllRequests(t){var e;(e=this._fullRequestReader)==null||e.cancel(t);for(const s of this._rangeRequestReaders.slice(0))s.cancel(t)}}class eS{constructor(t){this._url=t.url,this._done=!1,this._storedError=null,this.onProgress=null;const e=t.source;this._contentLength=e.length,this._loaded=0,this._filename=null,this._disableRange=e.disableRange||!1,this._rangeChunkSize=e.rangeChunkSize,!this._rangeChunkSize&&!this._disableRange&&(this._disableRange=!0),this._isStreamingSupported=!e.disableStream,this._isRangeSupported=!e.disableRange,this._readableStream=null,this._readCapability=Promise.withResolvers(),this._headersCapability=Promise.withResolvers();const s=process.getBuiltinModule("fs");s.promises.lstat(this._url).then(i=>{this._contentLength=i.size,this._setReadableStream(s.createReadStream(this._url)),this._headersCapability.resolve()},i=>{i.code==="ENOENT"&&(i=new Gh(`Missing PDF "${this._url}".`)),this._storedError=i,this._headersCapability.reject(i)})}get headersReady(){return this._headersCapability.promise}get filename(){return this._filename}get contentLength(){return this._contentLength}get isRangeSupported(){return this._isRangeSupported}get isStreamingSupported(){return this._isStreamingSupported}async read(){var s;if(await this._readCapability.promise,this._done)return{value:void 0,done:!0};if(this._storedError)throw this._storedError;const t=this._readableStream.read();return t===null?(this._readCapability=Promise.withResolvers(),this.read()):(this._loaded+=t.length,(s=this.onProgress)==null||s.call(this,{loaded:this._loaded,total:this._contentLength}),{value:new Uint8Array(t).buffer,done:!1})}cancel(t){if(!this._readableStream){this._error(t);return}this._readableStream.destroy(t)}_error(t){this._storedError=t,this._readCapability.resolve()}_setReadableStream(t){this._readableStream=t,t.on("readable",()=>{this._readCapability.resolve()}),t.on("end",()=>{t.destroy(),this._done=!0,this._readCapability.resolve()}),t.on("error",e=>{this._error(e)}),!this._isStreamingSupported&&this._isRangeSupported&&this._error(new Rn("streaming is disabled")),this._storedError&&this._readableStream.destroy(this._storedError)}}class sS{constructor(t,e,s){this._url=t.url,this._done=!1,this._storedError=null,this.onProgress=null,this._loaded=0,this._readableStream=null,this._readCapability=Promise.withResolvers();const i=t.source;this._isStreamingSupported=!i.disableStream;const n=process.getBuiltinModule("fs");this._setReadableStream(n.createReadStream(this._url,{start:e,end:s-1}))}get isStreamingSupported(){return this._isStreamingSupported}async read(){var s;if(await this._readCapability.promise,this._done)return{value:void 0,done:!0};if(this._storedError)throw this._storedError;const t=this._readableStream.read();return t===null?(this._readCapability=Promise.withResolvers(),this.read()):(this._loaded+=t.length,(s=this.onProgress)==null||s.call(this,{loaded:this._loaded}),{value:new Uint8Array(t).buffer,done:!1})}cancel(t){if(!this._readableStream){this._error(t);return}this._readableStream.destroy(t)}_error(t){this._storedError=t,this._readCapability.resolve()}_setReadableStream(t){this._readableStream=t,t.on("readable",()=>{this._readCapability.resolve()}),t.on("end",()=>{t.destroy(),this._done=!0,this._readCapability.resolve()}),t.on("error",e=>{this._error(e)}),this._storedError&&this._readableStream.destroy(this._storedError)}}const iS=1e5,Ye=30,nS=.8,Qt=class Qt{constructor({textContentSource:t,container:e,viewport:s}){y(this,nn);y(this,Kn,Promise.withResolvers());y(this,qe,null);y(this,Rl,!1);y(this,Ll,!!((Ub=globalThis.FontInspector)!=null&&Ub.enabled));y(this,io,null);y(this,sn,null);y(this,Fl,0);y(this,Il,0);y(this,no,null);y(this,Ma,null);y(this,Pa,0);y(this,Qn,0);y(this,Da,Object.create(null));y(this,Nl,[]);y(this,Oa,null);y(this,ro,[]);y(this,jl,new WeakMap);y(this,Bl,null);var h;if(t instanceof ReadableStream)m(this,Oa,t);else if(typeof t=="object")m(this,Oa,new ReadableStream({start(c){c.enqueue(t),c.close()}}));else throw new Error('No "textContentSource" parameter specified.');m(this,qe,m(this,Ma,e)),m(this,Qn,s.scale*(globalThis.devicePixelRatio||1)),m(this,Pa,s.rotation),m(this,sn,{div:null,properties:null,ctx:null});const{pageWidth:i,pageHeight:n,pageX:r,pageY:o}=s.rawDims;m(this,Bl,[1,0,0,-1,-r,o+n]),m(this,Il,i),m(this,Fl,n),w(h=Qt,rs,Py).call(h),kr(e,s),l(this,Kn).promise.finally(()=>{l(Qt,Ra).delete(this),m(this,sn,null),m(this,Da,null)}).catch(()=>{})}static get fontFamilyMap(){const{isWindows:t,isFirefox:e}=Re.platform;return st(this,"fontFamilyMap",new Map([["sans-serif",`${t&&e?"Calibri, ":""}sans-serif`],["monospace",`${t&&e?"Lucida Console, ":""}monospace`]]))}render(){const t=()=>{l(this,no).read().then(({value:e,done:s})=>{if(s){l(this,Kn).resolve();return}l(this,io)??m(this,io,e.lang),Object.assign(l(this,Da),e.styles),w(this,nn,ky).call(this,e.items),t()},l(this,Kn).reject)};return m(this,no,l(this,Oa).getReader()),l(Qt,Ra).add(this),t(),l(this,Kn).promise}update({viewport:t,onBefore:e=null}){var n;const s=t.scale*(globalThis.devicePixelRatio||1),i=t.rotation;if(i!==l(this,Pa)&&(e==null||e(),m(this,Pa,i),kr(l(this,Ma),{rotation:i})),s!==l(this,Qn)){e==null||e(),m(this,Qn,s);const r={div:null,properties:null,ctx:w(n=Qt,rs,Nd).call(n,l(this,io))};for(const o of l(this,ro))r.properties=l(this,jl).get(o),r.div=o,w(this,nn,bp).call(this,r)}}cancel(){var e;const t=new Rn("TextLayer task cancelled.");(e=l(this,no))==null||e.cancel(t).catch(()=>{}),m(this,no,null),l(this,Kn).reject(t)}get textDivs(){return l(this,ro)}get textContentItemsStr(){return l(this,Nl)}static cleanup(){if(!(l(this,Ra).size>0)){l(this,oo).clear();for(const{canvas:t}of l(this,ao).values())t.remove();l(this,ao).clear()}}};Kn=new WeakMap,qe=new WeakMap,Rl=new WeakMap,Ll=new WeakMap,io=new WeakMap,sn=new WeakMap,Fl=new WeakMap,Il=new WeakMap,no=new WeakMap,Ma=new WeakMap,Pa=new WeakMap,Qn=new WeakMap,Da=new WeakMap,Nl=new WeakMap,Oa=new WeakMap,ro=new WeakMap,jl=new WeakMap,Bl=new WeakMap,oo=new WeakMap,ao=new WeakMap,Hl=new WeakMap,Jn=new WeakMap,Ra=new WeakMap,nn=new WeakSet,ky=function(t){var i,n;if(l(this,Rl))return;(n=l(this,sn)).ctx??(n.ctx=w(i=Qt,rs,Nd).call(i,l(this,io)));const e=l(this,ro),s=l(this,Nl);for(const r of t){if(e.length>iS){tt("Ignoring additional textDivs for performance reasons."),m(this,Rl,!0);return}if(r.str===void 0){if(r.type==="beginMarkedContentProps"||r.type==="beginMarkedContent"){const o=l(this,qe);m(this,qe,document.createElement("span")),l(this,qe).classList.add("markedContent"),r.id!==null&&l(this,qe).setAttribute("id",`${r.id}`),o.append(l(this,qe))}else r.type==="endMarkedContent"&&m(this,qe,l(this,qe).parentNode);continue}s.push(r.str),w(this,nn,My).call(this,r)}},My=function(t){var b;const e=document.createElement("span"),s={angle:0,canvasWidth:0,hasText:t.str!=="",hasEOL:t.hasEOL,fontSize:0};l(this,ro).push(e);const i=W.transform(l(this,Bl),t.transform);let n=Math.atan2(i[1],i[0]);const r=l(this,Da)[t.fontName];r.vertical&&(n+=Math.PI/2);let o=l(this,Ll)&&r.fontSubstitution||r.fontFamily;o=Qt.fontFamilyMap.get(o)||o;const h=Math.hypot(i[2],i[3]),c=h*w(b=Qt,rs,Dy).call(b,o,l(this,io));let u,d;n===0?(u=i[4],d=i[5]-c):(u=i[4]+c*Math.sin(n),d=i[5]-c*Math.cos(n));const f="calc(var(--scale-factor)*",g=e.style;l(this,qe)===l(this,Ma)?(g.left=`${(100*u/l(this,Il)).toFixed(2)}%`,g.top=`${(100*d/l(this,Fl)).toFixed(2)}%`):(g.left=`${f}${u.toFixed(2)}px)`,g.top=`${f}${d.toFixed(2)}px)`),g.fontSize=`${f}${(l(Qt,Jn)*h).toFixed(2)}px)`,g.fontFamily=o,s.fontSize=h,e.setAttribute("role","presentation"),e.textContent=t.str,e.dir=t.dir,l(this,Ll)&&(e.dataset.fontName=r.fontSubstitutionLoadedName||t.fontName),n!==0&&(s.angle=n*(180/Math.PI));let p=!1;if(t.str.length>1)p=!0;else if(t.str!==" "&&t.transform[0]!==t.transform[3]){const v=Math.abs(t.transform[0]),_=Math.abs(t.transform[3]);v!==_&&Math.max(v,_)/Math.min(v,_)>1.5&&(p=!0)}if(p&&(s.canvasWidth=r.vertical?t.height:t.width),l(this,jl).set(e,s),l(this,sn).div=e,l(this,sn).properties=s,w(this,nn,bp).call(this,l(this,sn)),s.hasText&&l(this,qe).append(e),s.hasEOL){const v=document.createElement("br");v.setAttribute("role","presentation"),l(this,qe).append(v)}},bp=function(t){var o;const{div:e,properties:s,ctx:i}=t,{style:n}=e;let r="";if(l(Qt,Jn)>1&&(r=`scale(${1/l(Qt,Jn)})`),s.canvasWidth!==0&&s.hasText){const{fontFamily:h}=n,{canvasWidth:c,fontSize:u}=s;w(o=Qt,rs,yp).call(o,i,u*l(this,Qn),h);const{width:d}=i.measureText(e.textContent);d>0&&(r=`scaleX(${c*l(this,Qn)/d}) ${r}`)}s.angle!==0&&(r=`rotate(${s.angle}deg) ${r}`),r.length>0&&(n.transform=r)},rs=new WeakSet,Nd=function(t=null){let e=l(this,ao).get(t||(t=""));if(!e){const s=document.createElement("canvas");s.className="hiddenCanvasElement",s.lang=t,document.body.append(s),e=s.getContext("2d",{alpha:!1,willReadFrequently:!0}),l(this,ao).set(t,e),l(this,Hl).set(e,{size:0,family:""})}return e},yp=function(t,e,s){const i=l(this,Hl).get(t);e===i.size&&s===i.family||(t.font=`${e}px ${s}`,i.size=e,i.family=s)},Py=function(){if(l(this,Jn)!==null)return;const t=document.createElement("div");t.style.opacity=0,t.style.lineHeight=1,t.style.fontSize="1px",t.style.position="absolute",t.textContent="X",document.body.append(t),m(this,Jn,t.getBoundingClientRect().height),t.remove()},Dy=function(t,e){const s=l(this,oo).get(t);if(s)return s;const i=w(this,rs,Nd).call(this,e);i.canvas.width=i.canvas.height=Ye,w(this,rs,yp).call(this,i,Ye,t);const n=i.measureText("");let r=n.fontBoundingBoxAscent,o=Math.abs(n.fontBoundingBoxDescent);if(r){const u=r/(r+o);return l(this,oo).set(t,u),i.canvas.width=i.canvas.height=0,u}i.strokeStyle="red",i.clearRect(0,0,Ye,Ye),i.strokeText("g",0,0);let h=i.getImageData(0,0,Ye,Ye).data;o=0;for(let u=h.length-1-3;u>=0;u-=4)if(h[u]>0){o=Math.ceil(u/4/Ye);break}i.clearRect(0,0,Ye,Ye),i.strokeText("A",0,Ye),h=i.getImageData(0,0,Ye,Ye).data,r=0;for(let u=0,d=h.length;u<d;u+=4)if(h[u]>0){r=Ye-Math.floor(u/4/Ye);break}i.canvas.width=i.canvas.height=0;const c=r?r/(r+o):nS;return l(this,oo).set(t,c),c},y(Qt,rs),y(Qt,oo,new Map),y(Qt,ao,new Map),y(Qt,Hl,new WeakMap),y(Qt,Jn,null),y(Qt,Ra,new Set);let Yh=Qt;class $h{static textContent(t){const e=[],s={items:e,styles:Object.create(null)};function i(n){var h;if(!n)return;let r=null;const o=n.name;if(o==="#text")r=n.value;else if($h.shouldBuildText(o))(h=n==null?void 0:n.attributes)!=null&&h.textContent?r=n.attributes.textContent:n.value&&(r=n.value);else return;if(r!==null&&e.push({str:r}),!!n.children)for(const c of n.children)i(c)}return i(t),s}static shouldBuildText(t){return!(t==="textarea"||t==="input"||t==="option"||t==="select")}}const rS=65536,oS=100,aS=5e3,hS=ye?xx:vx,lS=ye?Sx:ib,cS=ye?wx:_x,uS=ye?Cx:ob;function dS(a={}){typeof a=="string"||a instanceof URL?a={url:a}:(a instanceof ArrayBuffer||ArrayBuffer.isView(a))&&(a={data:a});const t=new kg,{docId:e}=t,s=a.url?fS(a.url):null,i=a.data?gS(a.data):null,n=a.httpHeaders||null,r=a.withCredentials===!0,o=a.password??null,h=a.range instanceof Tb?a.range:null,c=Number.isInteger(a.rangeChunkSize)&&a.rangeChunkSize>0?a.rangeChunkSize:rS;let u=a.worker instanceof aa?a.worker:null;const d=a.verbosity,f=typeof a.docBaseUrl=="string"&&!Yu(a.docBaseUrl)?a.docBaseUrl:null,g=typeof a.cMapUrl=="string"?a.cMapUrl:null,p=a.cMapPacked!==!1,b=a.CMapReaderFactory||lS,v=typeof a.standardFontDataUrl=="string"?a.standardFontDataUrl:null,_=a.StandardFontDataFactory||uS,x=a.stopAtErrors!==!0,C=Number.isInteger(a.maxImageSize)&&a.maxImageSize>-1?a.maxImageSize:-1,S=a.isEvalSupported!==!1,k=typeof a.isOffscreenCanvasSupported=="boolean"?a.isOffscreenCanvasSupported:!ye,D=typeof a.isImageDecoderSupported=="boolean"?a.isImageDecoderSupported:!ye&&(Re.platform.isFirefox||!globalThis.chrome),A=Number.isInteger(a.canvasMaxAreaInBytes)?a.canvasMaxAreaInBytes:-1,M=typeof a.disableFontFace=="boolean"?a.disableFontFace:ye,O=a.fontExtraProperties===!0,R=a.enableXfa===!0,L=a.ownerDocument||globalThis.document,V=a.disableRange===!0,U=a.disableStream===!0,G=a.disableAutoFetch===!0,at=a.pdfBug===!0,F=a.CanvasFactory||hS,z=a.FilterFactory||cS,rt=a.enableHWA===!0,Gt=h?h.length:a.length??NaN,te=typeof a.useSystemFonts=="boolean"?a.useSystemFonts:!ye&&!M,fe=typeof a.useWorkerFetch=="boolean"?a.useWorkerFetch:b===ib&&_===ob&&g&&v&&Vh(g,document.baseURI)&&Vh(v,document.baseURI),Yt=null;Qw(d);const St={canvasFactory:new F({ownerDocument:L,enableHWA:rt}),filterFactory:new z({docId:e,ownerDocument:L}),cMapReaderFactory:fe?null:new b({baseUrl:g,isCompressed:p}),standardFontDataFactory:fe?null:new _({baseUrl:v})};if(!u){const Ft={verbosity:d,port:Vi.workerPort};u=Ft.port?aa.fromPort(Ft):new aa(Ft),t._worker=u}const He={docId:e,apiVersion:"4.10.38",data:i,password:o,disableAutoFetch:G,rangeChunkSize:c,length:Gt,docBaseUrl:f,enableXfa:R,evaluatorOptions:{maxImageSize:C,disableFontFace:M,ignoreErrors:x,isEvalSupported:S,isOffscreenCanvasSupported:k,isImageDecoderSupported:D,canvasMaxAreaInBytes:A,fontExtraProperties:O,useSystemFonts:te,cMapUrl:fe?g:null,standardFontDataUrl:fe?v:null}},Mi={disableFontFace:M,fontExtraProperties:O,ownerDocument:L,pdfBug:at,styleElement:Yt,loadingParams:{disableAutoFetch:G,enableXfa:R}};return u.promise.then(function(){if(t.destroyed)throw new Error("Loading aborted");if(u.destroyed)throw new Error("Worker was destroyed");const Ft=u.messageHandler.sendWithPromise("GetDocRequest",He,i?[i.buffer]:null);let ft;if(h)ft=new Gx(h,{disableRange:V,disableStream:U});else if(!i){if(!s)throw new Error("getDocument - no `url` parameter provided.");let fr;if(ye)if(Vh(s)){if(typeof fetch>"u"||typeof Response>"u"||!("body"in Response.prototype))throw new Error("getDocument - the Fetch API was disabled in Node.js, see `--no-experimental-fetch`.");fr=Cb}else fr=tS;else fr=Vh(s)?Cb:qx;ft=new fr({url:s,length:Gt,httpHeaders:n,withCredentials:r,rangeChunkSize:c,disableRange:V,disableStream:U})}return Ft.then(fr=>{if(t.destroyed)throw new Error("Loading aborted");if(u.destroyed)throw new Error("Worker was destroyed");const ph=new Wh(e,fr,u.port),Pi=new yS(ph,t,ft,Mi,St);t._transport=Pi,ph.send("Ready",null)})}).catch(t._capability.reject),t}function fS(a){if(a instanceof URL)return a.href;try{return new URL(a,window.location).href}catch{if(ye&&typeof a=="string")return a}throw new Error("Invalid PDF url data: either string or URL-object is expected in the url property.")}function gS(a){if(ye&&typeof Buffer<"u"&&a instanceof Buffer)throw new Error("Please provide binary data as `Uint8Array`, rather than `Buffer`.");if(a instanceof Uint8Array&&a.byteLength===a.buffer.byteLength)return a;if(typeof a=="string")return Wu(a);if(a instanceof ArrayBuffer||ArrayBuffer.isView(a)||typeof a=="object"&&!isNaN(a==null?void 0:a.length))return new Uint8Array(a);throw new Error("Invalid PDF binary data: either TypedArray, string, or array-like object is expected in the data property.")}function Ab(a){return typeof a=="object"&&Number.isInteger(a==null?void 0:a.num)&&a.num>=0&&Number.isInteger(a==null?void 0:a.gen)&&a.gen>=0}const md=class md{constructor(){this._capability=Promise.withResolvers(),this._transport=null,this._worker=null,this.docId=`d${Ge(md,pd)._++}`,this.destroyed=!1,this.onPassword=null,this.onProgress=null}get promise(){return this._capability.promise}async destroy(){var t,e,s,i;this.destroyed=!0;try{(t=this._worker)!=null&&t.port&&(this._worker._pendingDestroy=!0),await((e=this._transport)==null?void 0:e.destroy())}catch(n){throw(s=this._worker)!=null&&s.port&&delete this._worker._pendingDestroy,n}this._transport=null,(i=this._worker)==null||i.destroy(),this._worker=null}};pd=new WeakMap,y(md,pd,0);let kg=md;class Tb{constructor(t,e,s=!1,i=null){this.length=t,this.initialData=e,this.progressiveDone=s,this.contentDispositionFilename=i,this._rangeListeners=[],this._progressListeners=[],this._progressiveReadListeners=[],this._progressiveDoneListeners=[],this._readyCapability=Promise.withResolvers()}addRangeListener(t){this._rangeListeners.push(t)}addProgressListener(t){this._progressListeners.push(t)}addProgressiveReadListener(t){this._progressiveReadListeners.push(t)}addProgressiveDoneListener(t){this._progressiveDoneListeners.push(t)}onDataRange(t,e){for(const s of this._rangeListeners)s(t,e)}onDataProgress(t,e){this._readyCapability.promise.then(()=>{for(const s of this._progressListeners)s(t,e)})}onDataProgressiveRead(t){this._readyCapability.promise.then(()=>{for(const e of this._progressiveReadListeners)e(t)})}onDataProgressiveDone(){this._readyCapability.promise.then(()=>{for(const t of this._progressiveDoneListeners)t()})}transportReady(){this._readyCapability.resolve()}requestDataRange(t,e){vt("Abstract method PDFDataRangeTransport.requestDataRange")}abort(){}}class pS{constructor(t,e){this._pdfInfo=t,this._transport=e}get annotationStorage(){return this._transport.annotationStorage}get canvasFactory(){return this._transport.canvasFactory}get filterFactory(){return this._transport.filterFactory}get numPages(){return this._pdfInfo.numPages}get fingerprints(){return this._pdfInfo.fingerprints}get isPureXfa(){return st(this,"isPureXfa",!!this._transport._htmlForXfa)}get allXfaHtml(){return this._transport._htmlForXfa}getPage(t){return this._transport.getPage(t)}getPageIndex(t){return this._transport.getPageIndex(t)}getDestinations(){return this._transport.getDestinations()}getDestination(t){return this._transport.getDestination(t)}getPageLabels(){return this._transport.getPageLabels()}getPageLayout(){return this._transport.getPageLayout()}getPageMode(){return this._transport.getPageMode()}getViewerPreferences(){return this._transport.getViewerPreferences()}getOpenAction(){return this._transport.getOpenAction()}getAttachments(){return this._transport.getAttachments()}getJSActions(){return this._transport.getDocJSActions()}getOutline(){return this._transport.getOutline()}getOptionalContentConfig({intent:t="display"}={}){const{renderingIntent:e}=this._transport.getRenderingIntent(t);return this._transport.getOptionalContentConfig(e)}getPermissions(){return this._transport.getPermissions()}getMetadata(){return this._transport.getMetadata()}getMarkInfo(){return this._transport.getMarkInfo()}getData(){return this._transport.getData()}saveDocument(){return this._transport.saveDocument()}getDownloadInfo(){return this._transport.downloadInfoCapability.promise}cleanup(t=!1){return this._transport.startCleanup(t||this.isPureXfa)}destroy(){return this.loadingTask.destroy()}cachedPageNumber(t){return this._transport.cachedPageNumber(t)}get loadingParams(){return this._transport.loadingParams}get loadingTask(){return this._transport.loadingTask}getFieldObjects(){return this._transport.getFieldObjects()}hasJSActions(){return this._transport.hasJSActions()}getCalculationOrderIds(){return this._transport.getCalculationOrderIds()}}class mS{constructor(t,e,s,i=!1){y(this,As);y(this,Zn,null);y(this,rn,!1);this._pageIndex=t,this._pageInfo=e,this._transport=s,this._stats=i?new K0:null,this._pdfBug=i,this.commonObjs=s.commonObjs,this.objs=new Eb,this._maybeCleanupAfterRender=!1,this._intentStates=new Map,this.destroyed=!1}get pageNumber(){return this._pageIndex+1}get rotate(){return this._pageInfo.rotate}get ref(){return this._pageInfo.ref}get userUnit(){return this._pageInfo.userUnit}get view(){return this._pageInfo.view}getViewport({scale:t,rotation:e=this.rotate,offsetX:s=0,offsetY:i=0,dontFlip:n=!1}={}){return new zh({viewBox:this.view,userUnit:this.userUnit,scale:t,rotation:e,offsetX:s,offsetY:i,dontFlip:n})}getAnnotations({intent:t="display"}={}){const{renderingIntent:e}=this._transport.getRenderingIntent(t);return this._transport.getAnnotations(this._pageIndex,e)}getJSActions(){return this._transport.getPageJSActions(this._pageIndex)}get filterFactory(){return this._transport.filterFactory}get isPureXfa(){return st(this,"isPureXfa",!!this._transport._htmlForXfa)}async getXfa(){var t;return((t=this._transport._htmlForXfa)==null?void 0:t.children[this._pageIndex])||null}render({canvasContext:t,viewport:e,intent:s="display",annotationMode:i=Dn.ENABLE,transform:n=null,background:r=null,optionalContentConfigPromise:o=null,annotationCanvasMap:h=null,pageColors:c=null,printAnnotationStorage:u=null,isEditing:d=!1}){var S,k;(S=this._stats)==null||S.time("Overall");const f=this._transport.getRenderingIntent(s,i,u,d),{renderingIntent:g,cacheKey:p}=f;m(this,rn,!1),w(this,As,jd).call(this),o||(o=this._transport.getOptionalContentConfig(g));let b=this._intentStates.get(p);b||(b=Object.create(null),this._intentStates.set(p,b)),b.streamReaderCancelTimeout&&(clearTimeout(b.streamReaderCancelTimeout),b.streamReaderCancelTimeout=null);const v=!!(g&ts.PRINT);b.displayReadyCapability||(b.displayReadyCapability=Promise.withResolvers(),b.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},(k=this._stats)==null||k.time("Page Request"),this._pumpOperatorList(f));const _=D=>{var A;b.renderTasks.delete(x),(this._maybeCleanupAfterRender||v)&&m(this,rn,!0),w(this,As,vh).call(this,!v),D?(x.capability.reject(D),this._abortOperatorList({intentState:b,reason:D instanceof Error?D:new Error(D)})):x.capability.resolve(),this._stats&&(this._stats.timeEnd("Rendering"),this._stats.timeEnd("Overall"),(A=globalThis.Stats)!=null&&A.enabled&&globalThis.Stats.add(this.pageNumber,this._stats))},x=new Mg({callback:_,params:{canvasContext:t,viewport:e,transform:n,background:r},objs:this.objs,commonObjs:this.commonObjs,annotationCanvasMap:h,operatorList:b.operatorList,pageIndex:this._pageIndex,canvasFactory:this._transport.canvasFactory,filterFactory:this._transport.filterFactory,useRequestAnimationFrame:!v,pdfBug:this._pdfBug,pageColors:c});(b.renderTasks||(b.renderTasks=new Set)).add(x);const C=x.task;return Promise.all([b.displayReadyCapability.promise,o]).then(([D,A])=>{var M;if(this.destroyed){_();return}if((M=this._stats)==null||M.time("Rendering"),!(A.renderingIntent&g))throw new Error("Must use the same `intent`-argument when calling the `PDFPageProxy.render` and `PDFDocumentProxy.getOptionalContentConfig` methods.");x.initializeGraphics({transparency:D,optionalContentConfig:A}),x.operatorListChanged()}).catch(_),C}getOperatorList({intent:t="display",annotationMode:e=Dn.ENABLE,printAnnotationStorage:s=null,isEditing:i=!1}={}){var c;function n(){o.operatorList.lastChunk&&(o.opListReadCapability.resolve(o.operatorList),o.renderTasks.delete(h))}const r=this._transport.getRenderingIntent(t,e,s,i,!0);let o=this._intentStates.get(r.cacheKey);o||(o=Object.create(null),this._intentStates.set(r.cacheKey,o));let h;return o.opListReadCapability||(h=Object.create(null),h.operatorListChanged=n,o.opListReadCapability=Promise.withResolvers(),(o.renderTasks||(o.renderTasks=new Set)).add(h),o.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},(c=this._stats)==null||c.time("Page Request"),this._pumpOperatorList(r)),o.opListReadCapability.promise}streamTextContent({includeMarkedContent:t=!1,disableNormalization:e=!1}={}){return this._transport.messageHandler.sendWithStream("GetTextContent",{pageIndex:this._pageIndex,includeMarkedContent:t===!0,disableNormalization:e===!0},{highWaterMark:100,size(i){return i.items.length}})}getTextContent(t={}){if(this._transport._htmlForXfa)return this.getXfa().then(s=>$h.textContent(s));const e=this.streamTextContent(t);return new Promise(function(s,i){function n(){r.read().then(function({value:h,done:c}){if(c){s(o);return}o.lang??(o.lang=h.lang),Object.assign(o.styles,h.styles),o.items.push(...h.items),n()},i)}const r=e.getReader(),o={items:[],styles:Object.create(null),lang:null};n()})}getStructTree(){return this._transport.getStructTree(this._pageIndex)}_destroy(){this.destroyed=!0;const t=[];for(const e of this._intentStates.values())if(this._abortOperatorList({intentState:e,reason:new Error("Page was destroyed."),force:!0}),!e.opListReadCapability)for(const s of e.renderTasks)t.push(s.completed),s.cancel();return this.objs.clear(),m(this,rn,!1),w(this,As,jd).call(this),Promise.all(t)}cleanup(t=!1){m(this,rn,!0);const e=w(this,As,vh).call(this,!1);return t&&e&&this._stats&&(this._stats=new K0),e}_startRenderPage(t,e){var i,n;const s=this._intentStates.get(e);s&&((i=this._stats)==null||i.timeEnd("Page Request"),(n=s.displayReadyCapability)==null||n.resolve(t))}_renderPageChunk(t,e){for(let s=0,i=t.length;s<i;s++)e.operatorList.fnArray.push(t.fnArray[s]),e.operatorList.argsArray.push(t.argsArray[s]);e.operatorList.lastChunk=t.lastChunk,e.operatorList.separateAnnots=t.separateAnnots;for(const s of e.renderTasks)s.operatorListChanged();t.lastChunk&&w(this,As,vh).call(this,!0)}_pumpOperatorList({renderingIntent:t,cacheKey:e,annotationStorageSerializable:s,modifiedIds:i}){const{map:n,transfer:r}=s,h=this._transport.messageHandler.sendWithStream("GetOperatorList",{pageIndex:this._pageIndex,intent:t,cacheKey:e,annotationStorage:n,modifiedIds:i},r).getReader(),c=this._intentStates.get(e);c.streamReader=h;const u=()=>{h.read().then(({value:d,done:f})=>{if(f){c.streamReader=null;return}this._transport.destroyed||(this._renderPageChunk(d,c),u())},d=>{if(c.streamReader=null,!this._transport.destroyed){if(c.operatorList){c.operatorList.lastChunk=!0;for(const f of c.renderTasks)f.operatorListChanged();w(this,As,vh).call(this,!0)}if(c.displayReadyCapability)c.displayReadyCapability.reject(d);else if(c.opListReadCapability)c.opListReadCapability.reject(d);else throw d}})};u()}_abortOperatorList({intentState:t,reason:e,force:s=!1}){if(t.streamReader){if(t.streamReaderCancelTimeout&&(clearTimeout(t.streamReaderCancelTimeout),t.streamReaderCancelTimeout=null),!s){if(t.renderTasks.size>0)return;if(e instanceof dg){let i=oS;e.extraDelay>0&&e.extraDelay<1e3&&(i+=e.extraDelay),t.streamReaderCancelTimeout=setTimeout(()=>{t.streamReaderCancelTimeout=null,this._abortOperatorList({intentState:t,reason:e,force:!0})},i);return}}if(t.streamReader.cancel(new Rn(e.message)).catch(()=>{}),t.streamReader=null,!this._transport.destroyed){for(const[i,n]of this._intentStates)if(n===t){this._intentStates.delete(i);break}this.cleanup()}}}get stats(){return this._stats}}Zn=new WeakMap,rn=new WeakMap,As=new WeakSet,vh=function(t=!1){if(w(this,As,jd).call(this),!l(this,rn)||this.destroyed)return!1;if(t)return m(this,Zn,setTimeout(()=>{m(this,Zn,null),w(this,As,vh).call(this,!1)},aS)),!1;for(const{renderTasks:e,operatorList:s}of this._intentStates.values())if(e.size>0||!s.lastChunk)return!1;return this._intentStates.clear(),this.objs.clear(),m(this,rn,!1),!0},jd=function(){l(this,Zn)&&(clearTimeout(l(this,Zn)),m(this,Zn,null))};class bS{constructor(){y(this,on,new Map);y(this,bd,Promise.resolve())}postMessage(t,e){const s={data:structuredClone(t,e?{transfer:e}:null)};l(this,bd).then(()=>{for(const[i]of l(this,on))i.call(this,s)})}addEventListener(t,e,s=null){let i=null;if((s==null?void 0:s.signal)instanceof AbortSignal){const{signal:n}=s;if(n.aborted){tt("LoopbackPort - cannot use an `aborted` signal.");return}const r=()=>this.removeEventListener(t,e);i=()=>n.removeEventListener("abort",r),n.addEventListener("abort",r)}l(this,on).set(e,i)}removeEventListener(t,e){const s=l(this,on).get(e);s==null||s(),l(this,on).delete(e)}terminate(){for(const[,t]of l(this,on))t==null||t();l(this,on).clear()}}on=new WeakMap,bd=new WeakMap;const Et=class Et{constructor({name:t=null,port:e=null,verbosity:s=Jw()}={}){y(this,La);var i;if(this.name=t,this.destroyed=!1,this.verbosity=s,this._readyCapability=Promise.withResolvers(),this._port=null,this._webWorker=null,this._messageHandler=null,e){if((i=l(Et,lo))!=null&&i.has(e))throw new Error("Cannot use more than one PDFWorker per port.");(l(Et,lo)||m(Et,lo,new WeakMap)).set(e,this),this._initializeFromPort(e);return}this._initialize()}get promise(){return this._readyCapability.promise}get port(){return this._port}get messageHandler(){return this._messageHandler}_initializeFromPort(t){this._port=t,this._messageHandler=new Wh("main","worker",t),this._messageHandler.on("ready",function(){}),w(this,La,Bd).call(this)}_initialize(){if(l(Et,ho)||l(Et,Fa,Hd)){this._setupFakeWorker();return}let{workerSrc:t}=Et;try{Et._isSameOrigin(window.location.href,t)||(t=Et._createCDNWrapper(new URL(t,window.location).href));const e=new Worker(t,{type:"module"}),s=new Wh("main","worker",e),i=()=>{n.abort(),s.destroy(),e.terminate(),this.destroyed?this._readyCapability.reject(new Error("Worker was destroyed")):this._setupFakeWorker()},n=new AbortController;e.addEventListener("error",()=>{this._webWorker||i()},{signal:n.signal}),s.on("test",o=>{if(n.abort(),this.destroyed||!o){i();return}this._messageHandler=s,this._port=e,this._webWorker=e,w(this,La,Bd).call(this)}),s.on("ready",o=>{if(n.abort(),this.destroyed){i();return}try{r()}catch{this._setupFakeWorker()}});const r=()=>{const o=new Uint8Array;s.send("test",o,[o.buffer])};r();return}catch{Vu("The worker has been disabled.")}this._setupFakeWorker()}_setupFakeWorker(){l(Et,ho)||(tt("Setting up fake worker."),m(Et,ho,!0)),Et._setupFakeWorkerGlobal.then(t=>{if(this.destroyed){this._readyCapability.reject(new Error("Worker was destroyed"));return}const e=new bS;this._port=e;const s=`fake${Ge(Et,yd)._++}`,i=new Wh(s+"_worker",s,e);t.setup(i,e),this._messageHandler=new Wh(s,s+"_worker",e),w(this,La,Bd).call(this)}).catch(t=>{this._readyCapability.reject(new Error(`Setting up fake worker failed: "${t.message}".`))})}destroy(){var t,e,s;this.destroyed=!0,(t=this._webWorker)==null||t.terminate(),this._webWorker=null,(e=l(Et,lo))==null||e.delete(this._port),this._port=null,(s=this._messageHandler)==null||s.destroy(),this._messageHandler=null}static fromPort(t){var s;if(!(t!=null&&t.port))throw new Error("PDFWorker.fromPort - invalid method signature.");const e=(s=l(this,lo))==null?void 0:s.get(t.port);if(e){if(e._pendingDestroy)throw new Error("PDFWorker.fromPort - the worker is being destroyed.\nPlease remember to await `PDFDocumentLoadingTask.destroy()`-calls.");return e}return new Et(t)}static get workerSrc(){if(Vi.workerSrc)return Vi.workerSrc;throw new Error('No "GlobalWorkerOptions.workerSrc" specified.')}static get _setupFakeWorkerGlobal(){return st(this,"_setupFakeWorkerGlobal",(async()=>l(this,Fa,Hd)?l(this,Fa,Hd):(await import(this.workerSrc)).WorkerMessageHandler)())}};yd=new WeakMap,ho=new WeakMap,lo=new WeakMap,La=new WeakSet,Bd=function(){this._readyCapability.resolve(),this._messageHandler.send("configure",{verbosity:this.verbosity})},Fa=new WeakSet,Hd=function(){var t;try{return((t=globalThis.pdfjsWorker)==null?void 0:t.WorkerMessageHandler)||null}catch{return null}},y(Et,Fa),y(Et,yd,0),y(Et,ho,!1),y(Et,lo),ye&&(m(Et,ho,!0),Vi.workerSrc||(Vi.workerSrc="./pdf.worker.mjs")),Et._isSameOrigin=(t,e)=>{let s;try{if(s=new URL(t),!s.origin||s.origin==="null")return!1}catch{return!1}const i=new URL(e,s);return s.origin===i.origin},Et._createCDNWrapper=t=>{const e=`await import("${t}");`;return URL.createObjectURL(new Blob([e],{type:"text/javascript"}))};let aa=Et;class yS{constructor(t,e,s,i,n){y(this,co);y(this,an,new Map);y(this,_i,new Map);y(this,Ia,new Map);y(this,Na,new Map);y(this,hn,null);this.messageHandler=t,this.loadingTask=e,this.commonObjs=new Eb,this.fontLoader=new bx({ownerDocument:i.ownerDocument,styleElement:i.styleElement}),this.loadingParams=i.loadingParams,this._params=i,this.canvasFactory=n.canvasFactory,this.filterFactory=n.filterFactory,this.cMapReaderFactory=n.cMapReaderFactory,this.standardFontDataFactory=n.standardFontDataFactory,this.destroyed=!1,this.destroyCapability=null,this._networkStream=s,this._fullReader=null,this._lastProgress=null,this.downloadInfoCapability=Promise.withResolvers(),this.setupMessageHandler()}get annotationStorage(){return st(this,"annotationStorage",new wg)}getRenderingIntent(t,e=Dn.ENABLE,s=null,i=!1,n=!1){let r=ts.DISPLAY,o=_g;switch(t){case"any":r=ts.ANY;break;case"display":break;case"print":r=ts.PRINT;break;default:tt(`getRenderingIntent - invalid intent: ${t}`)}const h=r&ts.PRINT&&s instanceof Z0?s:this.annotationStorage;switch(e){case Dn.DISABLE:r+=ts.ANNOTATIONS_DISABLE;break;case Dn.ENABLE:break;case Dn.ENABLE_FORMS:r+=ts.ANNOTATIONS_FORMS;break;case Dn.ENABLE_STORAGE:r+=ts.ANNOTATIONS_STORAGE,o=h.serializable;break;default:tt(`getRenderingIntent - invalid annotationMode: ${e}`)}i&&(r+=ts.IS_EDITING),n&&(r+=ts.OPLIST);const{ids:c,hash:u}=h.modifiedIds,d=[r,o.hash,u];return{renderingIntent:r,cacheKey:d.join("_"),annotationStorageSerializable:o,modifiedIds:c}}destroy(){var s;if(this.destroyCapability)return this.destroyCapability.promise;this.destroyed=!0,this.destroyCapability=Promise.withResolvers(),(s=l(this,hn))==null||s.reject(new Error("Worker was destroyed during onPassword callback"));const t=[];for(const i of l(this,_i).values())t.push(i._destroy());l(this,_i).clear(),l(this,Ia).clear(),l(this,Na).clear(),this.hasOwnProperty("annotationStorage")&&this.annotationStorage.resetModified();const e=this.messageHandler.sendWithPromise("Terminate",null);return t.push(e),Promise.all(t).then(()=>{var i,n;this.commonObjs.clear(),this.fontLoader.clear(),l(this,an).clear(),this.filterFactory.destroy(),Yh.cleanup(),(i=this._networkStream)==null||i.cancelAllRequests(new Rn("Worker was terminated.")),(n=this.messageHandler)==null||n.destroy(),this.messageHandler=null,this.destroyCapability.resolve()},this.destroyCapability.reject),this.destroyCapability.promise}setupMessageHandler(){const{messageHandler:t,loadingTask:e}=this;t.on("GetReader",(s,i)=>{Xt(this._networkStream,"GetReader - no `IPDFStream` instance available."),this._fullReader=this._networkStream.getFullReader(),this._fullReader.onProgress=n=>{this._lastProgress={loaded:n.loaded,total:n.total}},i.onPull=()=>{this._fullReader.read().then(function({value:n,done:r}){if(r){i.close();return}Xt(n instanceof ArrayBuffer,"GetReader - expected an ArrayBuffer."),i.enqueue(new Uint8Array(n),1,[n])}).catch(n=>{i.error(n)})},i.onCancel=n=>{this._fullReader.cancel(n),i.ready.catch(r=>{if(!this.destroyed)throw r})}}),t.on("ReaderHeadersReady",async s=>{var o;await this._fullReader.headersReady;const{isStreamingSupported:i,isRangeSupported:n,contentLength:r}=this._fullReader;return(!i||!n)&&(this._lastProgress&&((o=e.onProgress)==null||o.call(e,this._lastProgress)),this._fullReader.onProgress=h=>{var c;(c=e.onProgress)==null||c.call(e,{loaded:h.loaded,total:h.total})}),{isStreamingSupported:i,isRangeSupported:n,contentLength:r}}),t.on("GetRangeReader",(s,i)=>{Xt(this._networkStream,"GetRangeReader - no `IPDFStream` instance available.");const n=this._networkStream.getRangeReader(s.begin,s.end);if(!n){i.close();return}i.onPull=()=>{n.read().then(function({value:r,done:o}){if(o){i.close();return}Xt(r instanceof ArrayBuffer,"GetRangeReader - expected an ArrayBuffer."),i.enqueue(new Uint8Array(r),1,[r])}).catch(r=>{i.error(r)})},i.onCancel=r=>{n.cancel(r),i.ready.catch(o=>{if(!this.destroyed)throw o})}}),t.on("GetDoc",({pdfInfo:s})=>{this._numPages=s.numPages,this._htmlForXfa=s.htmlForXfa,delete s.htmlForXfa,e._capability.resolve(new pS(s,this))}),t.on("DocException",s=>{e._capability.reject(We(s))}),t.on("PasswordRequest",s=>{m(this,hn,Promise.withResolvers());try{if(!e.onPassword)throw We(s);const i=n=>{n instanceof Error?l(this,hn).reject(n):l(this,hn).resolve({password:n})};e.onPassword(i,s.code)}catch(i){l(this,hn).reject(i)}return l(this,hn).promise}),t.on("DataLoaded",s=>{var i;(i=e.onProgress)==null||i.call(e,{loaded:s.length,total:s.length}),this.downloadInfoCapability.resolve(s)}),t.on("StartRenderPage",s=>{if(this.destroyed)return;l(this,_i).get(s.pageIndex)._startRenderPage(s.transparency,s.cacheKey)}),t.on("commonobj",([s,i,n])=>{var r;if(this.destroyed||this.commonObjs.has(s))return null;switch(i){case"Font":const{disableFontFace:o,fontExtraProperties:h,pdfBug:c}=this._params;if("error"in n){const g=n.error;tt(`Error during font loading: ${g}`),this.commonObjs.resolve(s,g);break}const u=c&&((r=globalThis.FontInspector)!=null&&r.enabled)?(g,p)=>globalThis.FontInspector.fontAdded(g,p):null,d=new yx(n,{disableFontFace:o,fontExtraProperties:h,inspectFont:u});this.fontLoader.bind(d).catch(()=>t.sendWithPromise("FontFallback",{id:s})).finally(()=>{!h&&d.data&&(d.data=null),this.commonObjs.resolve(s,d)});break;case"CopyLocalImage":const{imageRef:f}=n;Xt(f,"The imageRef must be defined.");for(const g of l(this,_i).values())for(const[,p]of g.objs)if((p==null?void 0:p.ref)===f)return p.dataLen?(this.commonObjs.resolve(s,structuredClone(p)),p.dataLen):null;break;case"FontPath":case"Image":case"Pattern":this.commonObjs.resolve(s,n);break;default:throw new Error(`Got unknown common object type ${i}`)}return null}),t.on("obj",([s,i,n,r])=>{var h;if(this.destroyed)return;const o=l(this,_i).get(i);if(!o.objs.has(s)){if(o._intentStates.size===0){(h=r==null?void 0:r.bitmap)==null||h.close();return}switch(n){case"Image":o.objs.resolve(s,r),(r==null?void 0:r.dataLen)>Yw&&(o._maybeCleanupAfterRender=!0);break;case"Pattern":o.objs.resolve(s,r);break;default:throw new Error(`Got unknown object type ${n}`)}}}),t.on("DocProgress",s=>{var i;this.destroyed||(i=e.onProgress)==null||i.call(e,{loaded:s.loaded,total:s.total})}),t.on("FetchBuiltInCMap",async s=>{if(this.destroyed)throw new Error("Worker was destroyed.");if(!this.cMapReaderFactory)throw new Error("CMapReaderFactory not initialized, see the `useWorkerFetch` parameter.");return this.cMapReaderFactory.fetch(s)}),t.on("FetchStandardFontData",async s=>{if(this.destroyed)throw new Error("Worker was destroyed.");if(!this.standardFontDataFactory)throw new Error("StandardFontDataFactory not initialized, see the `useWorkerFetch` parameter.");return this.standardFontDataFactory.fetch(s)})}getData(){return this.messageHandler.sendWithPromise("GetData",null)}saveDocument(){var s;this.annotationStorage.size<=0&&tt("saveDocument called while `annotationStorage` is empty, please use the getData-method instead.");const{map:t,transfer:e}=this.annotationStorage.serializable;return this.messageHandler.sendWithPromise("SaveDocument",{isPureXfa:!!this._htmlForXfa,numPages:this._numPages,annotationStorage:t,filename:((s=this._fullReader)==null?void 0:s.filename)??null},e).finally(()=>{this.annotationStorage.resetModified()})}getPage(t){if(!Number.isInteger(t)||t<=0||t>this._numPages)return Promise.reject(new Error("Invalid page request."));const e=t-1,s=l(this,Ia).get(e);if(s)return s;const i=this.messageHandler.sendWithPromise("GetPage",{pageIndex:e}).then(n=>{if(this.destroyed)throw new Error("Transport destroyed");n.refStr&&l(this,Na).set(n.refStr,t);const r=new mS(e,n,this,this._params.pdfBug);return l(this,_i).set(e,r),r});return l(this,Ia).set(e,i),i}getPageIndex(t){return Ab(t)?this.messageHandler.sendWithPromise("GetPageIndex",{num:t.num,gen:t.gen}):Promise.reject(new Error("Invalid pageIndex request."))}getAnnotations(t,e){return this.messageHandler.sendWithPromise("GetAnnotations",{pageIndex:t,intent:e})}getFieldObjects(){return w(this,co,Dc).call(this,"GetFieldObjects")}hasJSActions(){return w(this,co,Dc).call(this,"HasJSActions")}getCalculationOrderIds(){return this.messageHandler.sendWithPromise("GetCalculationOrderIds",null)}getDestinations(){return this.messageHandler.sendWithPromise("GetDestinations",null)}getDestination(t){return typeof t!="string"?Promise.reject(new Error("Invalid destination request.")):this.messageHandler.sendWithPromise("GetDestination",{id:t})}getPageLabels(){return this.messageHandler.sendWithPromise("GetPageLabels",null)}getPageLayout(){return this.messageHandler.sendWithPromise("GetPageLayout",null)}getPageMode(){return this.messageHandler.sendWithPromise("GetPageMode",null)}getViewerPreferences(){return this.messageHandler.sendWithPromise("GetViewerPreferences",null)}getOpenAction(){return this.messageHandler.sendWithPromise("GetOpenAction",null)}getAttachments(){return this.messageHandler.sendWithPromise("GetAttachments",null)}getDocJSActions(){return w(this,co,Dc).call(this,"GetDocJSActions")}getPageJSActions(t){return this.messageHandler.sendWithPromise("GetPageJSActions",{pageIndex:t})}getStructTree(t){return this.messageHandler.sendWithPromise("GetStructTree",{pageIndex:t})}getOutline(){return this.messageHandler.sendWithPromise("GetOutline",null)}getOptionalContentConfig(t){return w(this,co,Dc).call(this,"GetOptionalContentConfig").then(e=>new Hx(e,t))}getPermissions(){return this.messageHandler.sendWithPromise("GetPermissions",null)}getMetadata(){const t="GetMetadata",e=l(this,an).get(t);if(e)return e;const s=this.messageHandler.sendWithPromise(t,null).then(i=>{var n,r;return{info:i[0],metadata:i[1]?new jx(i[1]):null,contentDispositionFilename:((n=this._fullReader)==null?void 0:n.filename)??null,contentLength:((r=this._fullReader)==null?void 0:r.contentLength)??null}});return l(this,an).set(t,s),s}getMarkInfo(){return this.messageHandler.sendWithPromise("GetMarkInfo",null)}async startCleanup(t=!1){if(!this.destroyed){await this.messageHandler.sendWithPromise("Cleanup",null);for(const e of l(this,_i).values())if(!e.cleanup())throw new Error(`startCleanup: Page ${e.pageNumber} is currently rendering.`);this.commonObjs.clear(),t||this.fontLoader.clear(),l(this,an).clear(),this.filterFactory.destroy(!0),Yh.cleanup()}}cachedPageNumber(t){if(!Ab(t))return null;const e=t.gen===0?`${t.num}R`:`${t.num}R${t.gen}`;return l(this,Na).get(e)??null}}an=new WeakMap,_i=new WeakMap,Ia=new WeakMap,Na=new WeakMap,hn=new WeakMap,co=new WeakSet,Dc=function(t,e=null){const s=l(this,an).get(t);if(s)return s;const i=this.messageHandler.sendWithPromise(t,e);return l(this,an).set(t,i),i};const qh=Symbol("INITIAL_DATA");class Eb{constructor(){y(this,Gl);y(this,os,Object.create(null))}get(t,e=null){if(e){const i=w(this,Gl,vp).call(this,t);return i.promise.then(()=>e(i.data)),null}const s=l(this,os)[t];if(!s||s.data===qh)throw new Error(`Requesting object that isn't resolved yet ${t}.`);return s.data}has(t){const e=l(this,os)[t];return!!e&&e.data!==qh}delete(t){const e=l(this,os)[t];return!e||e.data===qh?!1:(delete l(this,os)[t],!0)}resolve(t,e=null){const s=w(this,Gl,vp).call(this,t);s.data=e,s.resolve()}clear(){var t;for(const e in l(this,os)){const{data:s}=l(this,os)[e];(t=s==null?void 0:s.bitmap)==null||t.close()}m(this,os,Object.create(null))}*[Symbol.iterator](){for(const t in l(this,os)){const{data:e}=l(this,os)[t];e!==qh&&(yield[t,e])}}}os=new WeakMap,Gl=new WeakSet,vp=function(t){var e;return(e=l(this,os))[t]||(e[t]={...Promise.withResolvers(),data:qh})};class vS{constructor(t){y(this,tr,null);m(this,tr,t),this.onContinue=null}get promise(){return l(this,tr).capability.promise}cancel(t=0){l(this,tr).cancel(null,t)}get separateAnnots(){const{separateAnnots:t}=l(this,tr).operatorList;if(!t)return!1;const{annotationCanvasMap:e}=l(this,tr);return t.form||t.canvas&&(e==null?void 0:e.size)>0}}tr=new WeakMap;const fo=class fo{constructor({callback:t,params:e,objs:s,commonObjs:i,annotationCanvasMap:n,operatorList:r,pageIndex:o,canvasFactory:h,filterFactory:c,useRequestAnimationFrame:u=!1,pdfBug:d=!1,pageColors:f=null}){y(this,er,null);this.callback=t,this.params=e,this.objs=s,this.commonObjs=i,this.annotationCanvasMap=n,this.operatorListIdx=null,this.operatorList=r,this._pageIndex=o,this.canvasFactory=h,this.filterFactory=c,this._pdfBug=d,this.pageColors=f,this.running=!1,this.graphicsReadyCallback=null,this.graphicsReady=!1,this._useRequestAnimationFrame=u===!0&&typeof window<"u",this.cancelled=!1,this.capability=Promise.withResolvers(),this.task=new vS(this),this._cancelBound=this.cancel.bind(this),this._continueBound=this._continue.bind(this),this._scheduleNextBound=this._scheduleNext.bind(this),this._nextBound=this._next.bind(this),this._canvas=e.canvasContext.canvas}get completed(){return this.capability.promise.catch(function(){})}initializeGraphics({transparency:t=!1,optionalContentConfig:e}){var o,h;if(this.cancelled)return;if(this._canvas){if(l(fo,uo).has(this._canvas))throw new Error("Cannot use the same canvas during multiple render() operations. Use different canvas or ensure previous operations were cancelled or completed.");l(fo,uo).add(this._canvas)}this._pdfBug&&((o=globalThis.StepperManager)!=null&&o.enabled)&&(this.stepper=globalThis.StepperManager.create(this._pageIndex),this.stepper.init(this.operatorList),this.stepper.nextBreakPoint=this.stepper.getNextBreakPoint());const{canvasContext:s,viewport:i,transform:n,background:r}=this.params;this.gfx=new ra(s,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:e},this.annotationCanvasMap,this.pageColors),this.gfx.beginDrawing({transform:n,viewport:i,transparency:t,background:r}),this.operatorListIdx=0,this.graphicsReady=!0,(h=this.graphicsReadyCallback)==null||h.call(this)}cancel(t=null,e=0){var s;this.running=!1,this.cancelled=!0,(s=this.gfx)==null||s.endDrawing(),l(this,er)&&(window.cancelAnimationFrame(l(this,er)),m(this,er,null)),l(fo,uo).delete(this._canvas),this.callback(t||new dg(`Rendering cancelled, page ${this._pageIndex+1}`,e))}operatorListChanged(){var t;if(!this.graphicsReady){this.graphicsReadyCallback||(this.graphicsReadyCallback=this._continueBound);return}(t=this.stepper)==null||t.updateOperatorList(this.operatorList),!this.running&&this._continue()}_continue(){this.running=!0,!this.cancelled&&(this.task.onContinue?this.task.onContinue(this._scheduleNextBound):this._scheduleNext())}_scheduleNext(){this._useRequestAnimationFrame?m(this,er,window.requestAnimationFrame(()=>{m(this,er,null),this._nextBound().catch(this._cancelBound)})):Promise.resolve().then(this._nextBound).catch(this._cancelBound)}async _next(){this.cancelled||(this.operatorListIdx=this.gfx.executeOperatorList(this.operatorList,this.operatorListIdx,this._continueBound,this.stepper),this.operatorListIdx===this.operatorList.argsArray.length&&(this.running=!1,this.operatorList.lastChunk&&(this.gfx.endDrawing(),l(fo,uo).delete(this._canvas),this.callback())))}};er=new WeakMap,uo=new WeakMap,y(fo,uo,new WeakSet);let Mg=fo;const _S="4.10.38",wS="f9bea397f";function kb(a){return Math.floor(Math.max(0,Math.min(1,a))*255).toString(16).padStart(2,"0")}function Kh(a){return Math.max(0,Math.min(255,255*a))}class Mb{static CMYK_G([t,e,s,i]){return["G",1-Math.min(1,.3*t+.59*s+.11*e+i)]}static G_CMYK([t]){return["CMYK",0,0,0,1-t]}static G_RGB([t]){return["RGB",t,t,t]}static G_rgb([t]){return t=Kh(t),[t,t,t]}static G_HTML([t]){const e=kb(t);return`#${e}${e}${e}`}static RGB_G([t,e,s]){return["G",.3*t+.59*e+.11*s]}static RGB_rgb(t){return t.map(Kh)}static RGB_HTML(t){return`#${t.map(kb).join("")}`}static T_HTML(){return"#00000000"}static T_rgb(){return[null]}static CMYK_RGB([t,e,s,i]){return["RGB",1-Math.min(1,t+i),1-Math.min(1,s+i),1-Math.min(1,e+i)]}static CMYK_rgb([t,e,s,i]){return[Kh(1-Math.min(1,t+i)),Kh(1-Math.min(1,s+i)),Kh(1-Math.min(1,e+i))]}static CMYK_HTML(t){const e=this.CMYK_RGB(t).slice(1);return this.RGB_HTML(e)}static RGB_CMYK([t,e,s]){const i=1-t,n=1-e,r=1-s,o=Math.min(i,n,r);return["CMYK",i,n,r,o]}}class xS{create(t,e,s=!1){if(t<=0||e<=0)throw new Error("Invalid SVG dimensions");const i=this._createSVG("svg:svg");return i.setAttribute("version","1.1"),s||(i.setAttribute("width",`${t}px`),i.setAttribute("height",`${e}px`)),i.setAttribute("preserveAspectRatio","none"),i.setAttribute("viewBox",`0 0 ${t} ${e}`),i}createElement(t){if(typeof t!="string")throw new Error("Invalid SVG element type");return this._createSVG(t)}_createSVG(t){vt("Abstract method `_createSVG` called.")}}class Pg extends xS{_createSVG(t){return document.createElementNS(zi,t)}}class Pb{static setupStorage(t,e,s,i,n){const r=i.getValue(e,{value:null});switch(s.name){case"textarea":if(r.value!==null&&(t.textContent=r.value),n==="print")break;t.addEventListener("input",o=>{i.setValue(e,{value:o.target.value})});break;case"input":if(s.attributes.type==="radio"||s.attributes.type==="checkbox"){if(r.value===s.attributes.xfaOn?t.setAttribute("checked",!0):r.value===s.attributes.xfaOff&&t.removeAttribute("checked"),n==="print")break;t.addEventListener("change",o=>{i.setValue(e,{value:o.target.checked?o.target.getAttribute("xfaOn"):o.target.getAttribute("xfaOff")})})}else{if(r.value!==null&&t.setAttribute("value",r.value),n==="print")break;t.addEventListener("input",o=>{i.setValue(e,{value:o.target.value})})}break;case"select":if(r.value!==null){t.setAttribute("value",r.value);for(const o of s.children)o.attributes.value===r.value?o.attributes.selected=!0:o.attributes.hasOwnProperty("selected")&&delete o.attributes.selected}t.addEventListener("input",o=>{const h=o.target.options,c=h.selectedIndex===-1?"":h[h.selectedIndex].value;i.setValue(e,{value:c})});break}}static setAttributes({html:t,element:e,storage:s=null,intent:i,linkService:n}){const{attributes:r}=e,o=t instanceof HTMLAnchorElement;r.type==="radio"&&(r.name=`${r.name}-${i}`);for(const[h,c]of Object.entries(r))if(c!=null)switch(h){case"class":c.length&&t.setAttribute(h,c.join(" "));break;case"dataId":break;case"id":t.setAttribute("data-element-id",c);break;case"style":Object.assign(t.style,c);break;case"textContent":t.textContent=c;break;default:(!o||h!=="href"&&h!=="newWindow")&&t.setAttribute(h,c)}o&&n.addLinkAttributes(t,r.href,r.newWindow),s&&r.dataId&&this.setupStorage(t,r.dataId,e,s)}static render(t){var d,f;const e=t.annotationStorage,s=t.linkService,i=t.xfaHtml,n=t.intent||"display",r=document.createElement(i.name);i.attributes&&this.setAttributes({html:r,element:i,intent:n,linkService:s});const o=n!=="richText",h=t.div;if(h.append(r),t.viewport){const g=`matrix(${t.viewport.transform.join(",")})`;h.style.transform=g}o&&h.setAttribute("class","xfaLayer xfaFont");const c=[];if(i.children.length===0){if(i.value){const g=document.createTextNode(i.value);r.append(g),o&&$h.shouldBuildText(i.name)&&c.push(g)}return{textDivs:c}}const u=[[i,-1,r]];for(;u.length>0;){const[g,p,b]=u.at(-1);if(p+1===g.children.length){u.pop();continue}const v=g.children[++u.at(-1)[1]];if(v===null)continue;const{name:_}=v;if(_==="#text"){const C=document.createTextNode(v.value);c.push(C),b.append(C);continue}const x=(d=v==null?void 0:v.attributes)!=null&&d.xmlns?document.createElementNS(v.attributes.xmlns,_):document.createElement(_);if(b.append(x),v.attributes&&this.setAttributes({html:x,element:v,storage:e,intent:n,linkService:s}),((f=v.children)==null?void 0:f.length)>0)u.push([v,-1,x]);else if(v.value){const C=document.createTextNode(v.value);o&&$h.shouldBuildText(_)&&c.push(C),x.append(C)}}for(const g of h.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea"))g.setAttribute("readOnly",!0);return{textDivs:c}}static update(t){const e=`matrix(${t.viewport.transform.join(",")})`;t.div.style.transform=e,t.div.hidden=!1}}const Qh=1e3,SS=9,Pr=new WeakSet;function Fn(a){return{width:a[2]-a[0],height:a[3]-a[1]}}class CS{static create(t){switch(t.data.annotationType){case qt.LINK:return new Db(t);case qt.TEXT:return new AS(t);case qt.WIDGET:switch(t.data.fieldType){case"Tx":return new TS(t);case"Btn":return t.data.radioButton?new Ob(t):t.data.checkBox?new kS(t):new MS(t);case"Ch":return new PS(t);case"Sig":return new ES(t)}return new Dr(t);case qt.POPUP:return new Dg(t);case qt.FREETEXT:return new Rb(t);case qt.LINE:return new OS(t);case qt.SQUARE:return new RS(t);case qt.CIRCLE:return new LS(t);case qt.POLYLINE:return new Lb(t);case qt.CARET:return new IS(t);case qt.INK:return new Og(t);case qt.POLYGON:return new FS(t);case qt.HIGHLIGHT:return new Fb(t);case qt.UNDERLINE:return new NS(t);case qt.SQUIGGLY:return new jS(t);case qt.STRIKEOUT:return new BS(t);case qt.STAMP:return new Ib(t);case qt.FILEATTACHMENT:return new HS(t);default:return new jt(t)}}}const Wg=class Wg{constructor(t,{isRenderable:e=!1,ignoreBorder:s=!1,createQuadrilaterals:i=!1}={}){y(this,zl);y(this,go,null);y(this,ja,!1);y(this,Ba,null);this.isRenderable=e,this.data=t.data,this.layer=t.layer,this.linkService=t.linkService,this.downloadManager=t.downloadManager,this.imageResourcesPath=t.imageResourcesPath,this.renderForms=t.renderForms,this.svgFactory=t.svgFactory,this.annotationStorage=t.annotationStorage,this.enableScripting=t.enableScripting,this.hasJSActions=t.hasJSActions,this._fieldObjects=t.fieldObjects,this.parent=t.parent,e&&(this.container=this._createContainer(s)),i&&this._createQuadrilaterals()}static _hasPopupData({titleObj:t,contentsObj:e,richText:s}){return!!(t!=null&&t.str||e!=null&&e.str||s!=null&&s.str)}get _isEditable(){return this.data.isEditable}get hasPopupData(){return Wg._hasPopupData(this.data)}updateEdited(t){var s;if(!this.container)return;l(this,go)||m(this,go,{rect:this.data.rect.slice(0)});const{rect:e}=t;e&&w(this,zl,_p).call(this,e),(s=l(this,Ba))==null||s.popup.updateEdited(t)}resetEdited(){var t;l(this,go)&&(w(this,zl,_p).call(this,l(this,go).rect),(t=l(this,Ba))==null||t.popup.resetEdited(),m(this,go,null))}_createContainer(t){const{data:e,parent:{page:s,viewport:i}}=this,n=document.createElement("section");n.setAttribute("data-annotation-id",e.id),this instanceof Dr||(n.tabIndex=Qh);const{style:r}=n;if(r.zIndex=this.parent.zIndex++,e.alternativeText&&(n.title=e.alternativeText),e.noRotate&&n.classList.add("norotate"),!e.rect||this instanceof Dg){const{rotation:b}=e;return!e.hasOwnCanvas&&b!==0&&this.setRotation(b,n),n}const{width:o,height:h}=Fn(e.rect);if(!t&&e.borderStyle.width>0){r.borderWidth=`${e.borderStyle.width}px`;const b=e.borderStyle.horizontalCornerRadius,v=e.borderStyle.verticalCornerRadius;if(b>0||v>0){const x=`calc(${b}px * var(--scale-factor)) / calc(${v}px * var(--scale-factor))`;r.borderRadius=x}else if(this instanceof Ob){const x=`calc(${o}px * var(--scale-factor)) / calc(${h}px * var(--scale-factor))`;r.borderRadius=x}switch(e.borderStyle.style){case Hh.SOLID:r.borderStyle="solid";break;case Hh.DASHED:r.borderStyle="dashed";break;case Hh.BEVELED:tt("Unimplemented border style: beveled");break;case Hh.INSET:tt("Unimplemented border style: inset");break;case Hh.UNDERLINE:r.borderBottomStyle="solid";break}const _=e.borderColor||null;_?(m(this,ja,!0),r.borderColor=W.makeHexColor(_[0]|0,_[1]|0,_[2]|0)):r.borderWidth=0}const c=W.normalizeRect([e.rect[0],s.view[3]-e.rect[1]+s.view[1],e.rect[2],s.view[3]-e.rect[3]+s.view[1]]),{pageWidth:u,pageHeight:d,pageX:f,pageY:g}=i.rawDims;r.left=`${100*(c[0]-f)/u}%`,r.top=`${100*(c[1]-g)/d}%`;const{rotation:p}=e;return e.hasOwnCanvas||p===0?(r.width=`${100*o/u}%`,r.height=`${100*h/d}%`):this.setRotation(p,n),n}setRotation(t,e=this.container){if(!this.data.rect)return;const{pageWidth:s,pageHeight:i}=this.parent.viewport.rawDims,{width:n,height:r}=Fn(this.data.rect);let o,h;t%180===0?(o=100*n/s,h=100*r/i):(o=100*r/s,h=100*n/i),e.style.width=`${o}%`,e.style.height=`${h}%`,e.setAttribute("data-main-rotation",(360-t)%360)}get _commonActions(){const t=(e,s,i)=>{const n=i.detail[e],r=n[0],o=n.slice(1);i.target.style[s]=Mb[`${r}_HTML`](o),this.annotationStorage.setValue(this.data.id,{[s]:Mb[`${r}_rgb`](o)})};return st(this,"_commonActions",{display:e=>{const{display:s}=e.detail,i=s%2===1;this.container.style.visibility=i?"hidden":"visible",this.annotationStorage.setValue(this.data.id,{noView:i,noPrint:s===1||s===2})},print:e=>{this.annotationStorage.setValue(this.data.id,{noPrint:!e.detail.print})},hidden:e=>{const{hidden:s}=e.detail;this.container.style.visibility=s?"hidden":"visible",this.annotationStorage.setValue(this.data.id,{noPrint:s,noView:s})},focus:e=>{setTimeout(()=>e.target.focus({preventScroll:!1}),0)},userName:e=>{e.target.title=e.detail.userName},readonly:e=>{e.target.disabled=e.detail.readonly},required:e=>{this._setRequired(e.target,e.detail.required)},bgColor:e=>{t("bgColor","backgroundColor",e)},fillColor:e=>{t("fillColor","backgroundColor",e)},fgColor:e=>{t("fgColor","color",e)},textColor:e=>{t("textColor","color",e)},borderColor:e=>{t("borderColor","borderColor",e)},strokeColor:e=>{t("strokeColor","borderColor",e)},rotation:e=>{const s=e.detail.rotation;this.setRotation(s),this.annotationStorage.setValue(this.data.id,{rotation:s})}})}_dispatchEventFromSandbox(t,e){const s=this._commonActions;for(const i of Object.keys(e.detail)){const n=t[i]||s[i];n==null||n(e)}}_setDefaultPropertiesFromJS(t){if(!this.enableScripting)return;const e=this.annotationStorage.getRawValue(this.data.id);if(!e)return;const s=this._commonActions;for(const[i,n]of Object.entries(e)){const r=s[i];if(r){const o={detail:{[i]:n},target:t};r(o),delete e[i]}}}_createQuadrilaterals(){if(!this.container)return;const{quadPoints:t}=this.data;if(!t)return;const[e,s,i,n]=this.data.rect.map(b=>Math.fround(b));if(t.length===8){const[b,v,_,x]=t.subarray(2,6);if(i===b&&n===v&&e===_&&s===x)return}const{style:r}=this.container;let o;if(l(this,ja)){const{borderColor:b,borderWidth:v}=r;r.borderWidth=0,o=["url('data:image/svg+xml;utf8,",'<svg xmlns="http://www.w3.org/2000/svg"',' preserveAspectRatio="none" viewBox="0 0 1 1">',`<g fill="transparent" stroke="${b}" stroke-width="${v}">`],this.container.classList.add("hasBorder")}const h=i-e,c=n-s,{svgFactory:u}=this,d=u.createElement("svg");d.classList.add("quadrilateralsContainer"),d.setAttribute("width",0),d.setAttribute("height",0);const f=u.createElement("defs");d.append(f);const g=u.createElement("clipPath"),p=`clippath_${this.data.id}`;g.setAttribute("id",p),g.setAttribute("clipPathUnits","objectBoundingBox"),f.append(g);for(let b=2,v=t.length;b<v;b+=8){const _=t[b],x=t[b+1],C=t[b+2],S=t[b+3],k=u.createElement("rect"),D=(C-e)/h,A=(n-x)/c,M=(_-C)/h,O=(x-S)/c;k.setAttribute("x",D),k.setAttribute("y",A),k.setAttribute("width",M),k.setAttribute("height",O),g.append(k),o==null||o.push(`<rect vector-effect="non-scaling-stroke" x="${D}" y="${A}" width="${M}" height="${O}"/>`)}l(this,ja)&&(o.push("</g></svg>')"),r.backgroundImage=o.join("")),this.container.append(d),this.container.style.clipPath=`url(#${p})`}_createPopup(){const{data:t}=this,e=m(this,Ba,new Dg({data:{color:t.color,titleObj:t.titleObj,modificationDate:t.modificationDate,contentsObj:t.contentsObj,richText:t.richText,parentRect:t.rect,borderStyle:0,id:`popup_${t.id}`,rotation:t.rotation},parent:this.parent,elements:[this]}));this.parent.div.append(e.render())}render(){vt("Abstract method `AnnotationElement.render` called")}_getElementsByName(t,e=null){const s=[];if(this._fieldObjects){const i=this._fieldObjects[t];if(i)for(const{page:n,id:r,exportValues:o}of i){if(n===-1||r===e)continue;const h=typeof o=="string"?o:null,c=document.querySelector(`[data-element-id="${r}"]`);if(c&&!Pr.has(c)){tt(`_getElementsByName - element not allowed: ${r}`);continue}s.push({id:r,exportValue:h,domElement:c})}return s}for(const i of document.getElementsByName(t)){const{exportValue:n}=i,r=i.getAttribute("data-element-id");r!==e&&Pr.has(i)&&s.push({id:r,exportValue:n,domElement:i})}return s}show(){var t;this.container&&(this.container.hidden=!1),(t=this.popup)==null||t.maybeShow()}hide(){var t;this.container&&(this.container.hidden=!0),(t=this.popup)==null||t.forceHide()}getElementsToTriggerPopup(){return this.container}addHighlightArea(){const t=this.getElementsToTriggerPopup();if(Array.isArray(t))for(const e of t)e.classList.add("highlightArea");else t.classList.add("highlightArea")}_editOnDoubleClick(){if(!this._isEditable)return;const{annotationEditorType:t,data:{id:e}}=this;this.container.addEventListener("dblclick",()=>{var s;(s=this.linkService.eventBus)==null||s.dispatch("switchannotationeditormode",{source:this,mode:t,editId:e})})}};go=new WeakMap,ja=new WeakMap,Ba=new WeakMap,zl=new WeakSet,_p=function(t){const{container:{style:e},data:{rect:s,rotation:i},parent:{viewport:{rawDims:{pageWidth:n,pageHeight:r,pageX:o,pageY:h}}}}=this;s==null||s.splice(0,4,...t);const{width:c,height:u}=Fn(t);e.left=`${100*(t[0]-o)/n}%`,e.top=`${100*(r-t[3]+h)/r}%`,i===0?(e.width=`${100*c/n}%`,e.height=`${100*u/r}%`):this.setRotation(i)};let jt=Wg;class Db extends jt{constructor(e,s=null){super(e,{isRenderable:!0,ignoreBorder:!!(s!=null&&s.ignoreBorder),createQuadrilaterals:!0});y(this,as);this.isTooltipOnly=e.data.isTooltipOnly}render(){const{data:e,linkService:s}=this,i=document.createElement("a");i.setAttribute("data-element-id",e.id);let n=!1;return e.url?(s.addLinkAttributes(i,e.url,e.newWindow),n=!0):e.action?(this._bindNamedAction(i,e.action),n=!0):e.attachment?(w(this,as,Oy).call(this,i,e.attachment,e.attachmentDest),n=!0):e.setOCGState?(w(this,as,Ry).call(this,i,e.setOCGState),n=!0):e.dest?(this._bindLink(i,e.dest),n=!0):(e.actions&&(e.actions.Action||e.actions["Mouse Up"]||e.actions["Mouse Down"])&&this.enableScripting&&this.hasJSActions&&(this._bindJSAction(i,e),n=!0),e.resetForm?(this._bindResetFormAction(i,e.resetForm),n=!0):this.isTooltipOnly&&!n&&(this._bindLink(i,""),n=!0)),this.container.classList.add("linkAnnotation"),n&&this.container.append(i),this.container}_bindLink(e,s){e.href=this.linkService.getDestinationHash(s),e.onclick=()=>(s&&this.linkService.goToDestination(s),!1),(s||s==="")&&w(this,as,Ho).call(this)}_bindNamedAction(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeNamedAction(s),!1),w(this,as,Ho).call(this)}_bindJSAction(e,s){e.href=this.linkService.getAnchorUrl("");const i=new Map([["Action","onclick"],["Mouse Up","onmouseup"],["Mouse Down","onmousedown"]]);for(const n of Object.keys(s.actions)){const r=i.get(n);r&&(e[r]=()=>{var o;return(o=this.linkService.eventBus)==null||o.dispatch("dispatcheventinsandbox",{source:this,detail:{id:s.id,name:n}}),!1})}e.onclick||(e.onclick=()=>!1),w(this,as,Ho).call(this)}_bindResetFormAction(e,s){const i=e.onclick;if(i||(e.href=this.linkService.getAnchorUrl("")),w(this,as,Ho).call(this),!this._fieldObjects){tt('_bindResetFormAction - "resetForm" action not supported, ensure that the `fieldObjects` parameter is provided.'),i||(e.onclick=()=>!1);return}e.onclick=()=>{var d;i==null||i();const{fields:n,refs:r,include:o}=s,h=[];if(n.length!==0||r.length!==0){const f=new Set(r);for(const g of n){const p=this._fieldObjects[g]||[];for(const{id:b}of p)f.add(b)}for(const g of Object.values(this._fieldObjects))for(const p of g)f.has(p.id)===o&&h.push(p)}else for(const f of Object.values(this._fieldObjects))h.push(...f);const c=this.annotationStorage,u=[];for(const f of h){const{id:g}=f;switch(u.push(g),f.type){case"text":{const b=f.defaultValue||"";c.setValue(g,{value:b});break}case"checkbox":case"radiobutton":{const b=f.defaultValue===f.exportValues;c.setValue(g,{value:b});break}case"combobox":case"listbox":{const b=f.defaultValue||"";c.setValue(g,{value:b});break}default:continue}const p=document.querySelector(`[data-element-id="${g}"]`);if(p){if(!Pr.has(p)){tt(`_bindResetFormAction - element not allowed: ${g}`);continue}}else continue;p.dispatchEvent(new Event("resetform"))}return this.enableScripting&&((d=this.linkService.eventBus)==null||d.dispatch("dispatcheventinsandbox",{source:this,detail:{id:"app",ids:u,name:"ResetForm"}})),!1}}}as=new WeakSet,Ho=function(){this.container.setAttribute("data-internal-link","")},Oy=function(e,s,i=null){e.href=this.linkService.getAnchorUrl(""),s.description&&(e.title=s.description),e.onclick=()=>{var n;return(n=this.downloadManager)==null||n.openOrDownloadData(s.content,s.filename,i),!1},w(this,as,Ho).call(this)},Ry=function(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeSetOCGState(s),!1),w(this,as,Ho).call(this)};class AS extends jt{constructor(t){super(t,{isRenderable:!0})}render(){this.container.classList.add("textAnnotation");const t=document.createElement("img");return t.src=this.imageResourcesPath+"annotation-"+this.data.name.toLowerCase()+".svg",t.setAttribute("data-l10n-id","pdfjs-text-annotation-type"),t.setAttribute("data-l10n-args",JSON.stringify({type:this.data.name})),!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.append(t),this.container}}class Dr extends jt{render(){return this.container}showElementAndHideCanvas(t){var e;this.data.hasOwnCanvas&&(((e=t.previousSibling)==null?void 0:e.nodeName)==="CANVAS"&&(t.previousSibling.hidden=!0),t.hidden=!1)}_getKeyModifier(t){return Re.platform.isMac?t.metaKey:t.ctrlKey}_setEventListener(t,e,s,i,n){s.includes("mouse")?t.addEventListener(s,r=>{var o;(o=this.linkService.eventBus)==null||o.dispatch("dispatcheventinsandbox",{source:this,detail:{id:this.data.id,name:i,value:n(r),shift:r.shiftKey,modifier:this._getKeyModifier(r)}})}):t.addEventListener(s,r=>{var o;if(s==="blur"){if(!e.focused||!r.relatedTarget)return;e.focused=!1}else if(s==="focus"){if(e.focused)return;e.focused=!0}n&&((o=this.linkService.eventBus)==null||o.dispatch("dispatcheventinsandbox",{source:this,detail:{id:this.data.id,name:i,value:n(r)}}))})}_setEventListeners(t,e,s,i){var n,r,o;for(const[h,c]of s)(c==="Action"||(n=this.data.actions)!=null&&n[c])&&((c==="Focus"||c==="Blur")&&(e||(e={focused:!1})),this._setEventListener(t,e,h,c,i),c==="Focus"&&!((r=this.data.actions)!=null&&r.Blur)?this._setEventListener(t,e,"blur","Blur",null):c==="Blur"&&!((o=this.data.actions)!=null&&o.Focus)&&this._setEventListener(t,e,"focus","Focus",null))}_setBackgroundColor(t){const e=this.data.backgroundColor||null;t.style.backgroundColor=e===null?"transparent":W.makeHexColor(e[0],e[1],e[2])}_setTextStyle(t){const e=["left","center","right"],{fontColor:s}=this.data.defaultAppearanceData,i=this.data.defaultAppearanceData.fontSize||SS,n=t.style;let r;const o=2,h=c=>Math.round(10*c)/10;if(this.data.multiLine){const c=Math.abs(this.data.rect[3]-this.data.rect[1]-o),u=Math.round(c/(rg*i))||1,d=c/u;r=Math.min(i,h(d/rg))}else{const c=Math.abs(this.data.rect[3]-this.data.rect[1]-o);r=Math.min(i,h(c/rg))}n.fontSize=`calc(${r}px * var(--scale-factor))`,n.color=W.makeHexColor(s[0],s[1],s[2]),this.data.textAlignment!==null&&(n.textAlign=e[this.data.textAlignment])}_setRequired(t,e){e?t.setAttribute("required",!0):t.removeAttribute("required"),t.setAttribute("aria-required",e)}}class TS extends Dr{constructor(t){const e=t.renderForms||t.data.hasOwnCanvas||!t.data.hasAppearance&&!!t.data.fieldValue;super(t,{isRenderable:e})}setPropertyOnSiblings(t,e,s,i){const n=this.annotationStorage;for(const r of this._getElementsByName(t.name,t.id))r.domElement&&(r.domElement[e]=s),n.setValue(r.id,{[i]:s})}render(){var i,n;const t=this.annotationStorage,e=this.data.id;this.container.classList.add("textWidgetAnnotation");let s=null;if(this.renderForms){const r=t.getValue(e,{value:this.data.fieldValue});let o=r.value||"";const h=t.getValue(e,{charLimit:this.data.maxLen}).charLimit;h&&o.length>h&&(o=o.slice(0,h));let c=r.formattedValue||((i=this.data.textContent)==null?void 0:i.join(`
500
+ `))||null;c&&this.data.comb&&(c=c.replaceAll(/\s+/g,""));const u={userValue:o,formattedValue:c,lastCommittedValue:null,commitKey:1,focused:!1};this.data.multiLine?(s=document.createElement("textarea"),s.textContent=c??o,this.data.doNotScroll&&(s.style.overflowY="hidden")):(s=document.createElement("input"),s.type="text",s.setAttribute("value",c??o),this.data.doNotScroll&&(s.style.overflowX="hidden")),this.data.hasOwnCanvas&&(s.hidden=!0),Pr.add(s),s.setAttribute("data-element-id",e),s.disabled=this.data.readOnly,s.name=this.data.fieldName,s.tabIndex=Qh,this._setRequired(s,this.data.required),h&&(s.maxLength=h),s.addEventListener("input",f=>{t.setValue(e,{value:f.target.value}),this.setPropertyOnSiblings(s,"value",f.target.value,"value"),u.formattedValue=null}),s.addEventListener("resetform",f=>{const g=this.data.defaultFieldValue??"";s.value=u.userValue=g,u.formattedValue=null});let d=f=>{const{formattedValue:g}=u;g!=null&&(f.target.value=g),f.target.scrollLeft=0};if(this.enableScripting&&this.hasJSActions){s.addEventListener("focus",g=>{var b;if(u.focused)return;const{target:p}=g;u.userValue&&(p.value=u.userValue),u.lastCommittedValue=p.value,u.commitKey=1,(b=this.data.actions)!=null&&b.Focus||(u.focused=!0)}),s.addEventListener("updatefromsandbox",g=>{this.showElementAndHideCanvas(g.target);const p={value(b){u.userValue=b.detail.value??"",t.setValue(e,{value:u.userValue.toString()}),b.target.value=u.userValue},formattedValue(b){const{formattedValue:v}=b.detail;u.formattedValue=v,v!=null&&b.target!==document.activeElement&&(b.target.value=v),t.setValue(e,{formattedValue:v})},selRange(b){b.target.setSelectionRange(...b.detail.selRange)},charLimit:b=>{var C;const{charLimit:v}=b.detail,{target:_}=b;if(v===0){_.removeAttribute("maxLength");return}_.setAttribute("maxLength",v);let x=u.userValue;!x||x.length<=v||(x=x.slice(0,v),_.value=u.userValue=x,t.setValue(e,{value:x}),(C=this.linkService.eventBus)==null||C.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:x,willCommit:!0,commitKey:1,selStart:_.selectionStart,selEnd:_.selectionEnd}}))}};this._dispatchEventFromSandbox(p,g)}),s.addEventListener("keydown",g=>{var v;u.commitKey=1;let p=-1;if(g.key==="Escape"?p=0:g.key==="Enter"&&!this.data.multiLine?p=2:g.key==="Tab"&&(u.commitKey=3),p===-1)return;const{value:b}=g.target;u.lastCommittedValue!==b&&(u.lastCommittedValue=b,u.userValue=b,(v=this.linkService.eventBus)==null||v.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:b,willCommit:!0,commitKey:p,selStart:g.target.selectionStart,selEnd:g.target.selectionEnd}}))});const f=d;d=null,s.addEventListener("blur",g=>{var b,v;if(!u.focused||!g.relatedTarget)return;(b=this.data.actions)!=null&&b.Blur||(u.focused=!1);const{value:p}=g.target;u.userValue=p,u.lastCommittedValue!==p&&((v=this.linkService.eventBus)==null||v.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:p,willCommit:!0,commitKey:u.commitKey,selStart:g.target.selectionStart,selEnd:g.target.selectionEnd}})),f(g)}),(n=this.data.actions)!=null&&n.Keystroke&&s.addEventListener("beforeinput",g=>{var k;u.lastCommittedValue=null;const{data:p,target:b}=g,{value:v,selectionStart:_,selectionEnd:x}=b;let C=_,S=x;switch(g.inputType){case"deleteWordBackward":{const D=v.substring(0,_).match(/\w*[^\w]*$/);D&&(C-=D[0].length);break}case"deleteWordForward":{const D=v.substring(_).match(/^[^\w]*\w*/);D&&(S+=D[0].length);break}case"deleteContentBackward":_===x&&(C-=1);break;case"deleteContentForward":_===x&&(S+=1);break}g.preventDefault(),(k=this.linkService.eventBus)==null||k.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:v,change:p||"",willCommit:!1,selStart:C,selEnd:S}})}),this._setEventListeners(s,u,[["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],g=>g.target.value)}if(d&&s.addEventListener("blur",d),this.data.comb){const g=(this.data.rect[2]-this.data.rect[0])/h;s.classList.add("comb"),s.style.letterSpacing=`calc(${g}px * var(--scale-factor) - 1ch)`}}else s=document.createElement("div"),s.textContent=this.data.fieldValue,s.style.verticalAlign="middle",s.style.display="table-cell",this.data.hasOwnCanvas&&(s.hidden=!0);return this._setTextStyle(s),this._setBackgroundColor(s),this._setDefaultPropertiesFromJS(s),this.container.append(s),this.container}}class ES extends Dr{constructor(t){super(t,{isRenderable:!!t.data.hasOwnCanvas})}}class kS extends Dr{constructor(t){super(t,{isRenderable:t.renderForms})}render(){const t=this.annotationStorage,e=this.data,s=e.id;let i=t.getValue(s,{value:e.exportValue===e.fieldValue}).value;typeof i=="string"&&(i=i!=="Off",t.setValue(s,{value:i})),this.container.classList.add("buttonWidgetAnnotation","checkBox");const n=document.createElement("input");return Pr.add(n),n.setAttribute("data-element-id",s),n.disabled=e.readOnly,this._setRequired(n,this.data.required),n.type="checkbox",n.name=e.fieldName,i&&n.setAttribute("checked",!0),n.setAttribute("exportValue",e.exportValue),n.tabIndex=Qh,n.addEventListener("change",r=>{const{name:o,checked:h}=r.target;for(const c of this._getElementsByName(o,s)){const u=h&&c.exportValue===e.exportValue;c.domElement&&(c.domElement.checked=u),t.setValue(c.id,{value:u})}t.setValue(s,{value:h})}),n.addEventListener("resetform",r=>{const o=e.defaultFieldValue||"Off";r.target.checked=o===e.exportValue}),this.enableScripting&&this.hasJSActions&&(n.addEventListener("updatefromsandbox",r=>{const o={value(h){h.target.checked=h.detail.value!=="Off",t.setValue(s,{value:h.target.checked})}};this._dispatchEventFromSandbox(o,r)}),this._setEventListeners(n,null,[["change","Validate"],["change","Action"],["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],r=>r.target.checked)),this._setBackgroundColor(n),this._setDefaultPropertiesFromJS(n),this.container.append(n),this.container}}class Ob extends Dr{constructor(t){super(t,{isRenderable:t.renderForms})}render(){this.container.classList.add("buttonWidgetAnnotation","radioButton");const t=this.annotationStorage,e=this.data,s=e.id;let i=t.getValue(s,{value:e.fieldValue===e.buttonValue}).value;if(typeof i=="string"&&(i=i!==e.buttonValue,t.setValue(s,{value:i})),i)for(const r of this._getElementsByName(e.fieldName,s))t.setValue(r.id,{value:!1});const n=document.createElement("input");if(Pr.add(n),n.setAttribute("data-element-id",s),n.disabled=e.readOnly,this._setRequired(n,this.data.required),n.type="radio",n.name=e.fieldName,i&&n.setAttribute("checked",!0),n.tabIndex=Qh,n.addEventListener("change",r=>{const{name:o,checked:h}=r.target;for(const c of this._getElementsByName(o,s))t.setValue(c.id,{value:!1});t.setValue(s,{value:h})}),n.addEventListener("resetform",r=>{const o=e.defaultFieldValue;r.target.checked=o!=null&&o===e.buttonValue}),this.enableScripting&&this.hasJSActions){const r=e.buttonValue;n.addEventListener("updatefromsandbox",o=>{const h={value:c=>{const u=r===c.detail.value;for(const d of this._getElementsByName(c.target.name)){const f=u&&d.id===s;d.domElement&&(d.domElement.checked=f),t.setValue(d.id,{value:f})}}};this._dispatchEventFromSandbox(h,o)}),this._setEventListeners(n,null,[["change","Validate"],["change","Action"],["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],o=>o.target.checked)}return this._setBackgroundColor(n),this._setDefaultPropertiesFromJS(n),this.container.append(n),this.container}}class MS extends Db{constructor(t){super(t,{ignoreBorder:t.data.hasAppearance})}render(){const t=super.render();t.classList.add("buttonWidgetAnnotation","pushButton");const e=t.lastChild;return this.enableScripting&&this.hasJSActions&&e&&(this._setDefaultPropertiesFromJS(e),e.addEventListener("updatefromsandbox",s=>{this._dispatchEventFromSandbox({},s)})),t}}class PS extends Dr{constructor(t){super(t,{isRenderable:t.renderForms})}render(){this.container.classList.add("choiceWidgetAnnotation");const t=this.annotationStorage,e=this.data.id,s=t.getValue(e,{value:this.data.fieldValue}),i=document.createElement("select");Pr.add(i),i.setAttribute("data-element-id",e),i.disabled=this.data.readOnly,this._setRequired(i,this.data.required),i.name=this.data.fieldName,i.tabIndex=Qh;let n=this.data.combo&&this.data.options.length>0;this.data.combo||(i.size=this.data.options.length,this.data.multiSelect&&(i.multiple=!0)),i.addEventListener("resetform",u=>{const d=this.data.defaultFieldValue;for(const f of i.options)f.selected=f.value===d});for(const u of this.data.options){const d=document.createElement("option");d.textContent=u.displayValue,d.value=u.exportValue,s.value.includes(u.exportValue)&&(d.setAttribute("selected",!0),n=!1),i.append(d)}let r=null;if(n){const u=document.createElement("option");u.value=" ",u.setAttribute("hidden",!0),u.setAttribute("selected",!0),i.prepend(u),r=()=>{u.remove(),i.removeEventListener("input",r),r=null},i.addEventListener("input",r)}const o=u=>{const d=u?"value":"textContent",{options:f,multiple:g}=i;return g?Array.prototype.filter.call(f,p=>p.selected).map(p=>p[d]):f.selectedIndex===-1?null:f[f.selectedIndex][d]};let h=o(!1);const c=u=>{const d=u.target.options;return Array.prototype.map.call(d,f=>({displayValue:f.textContent,exportValue:f.value}))};return this.enableScripting&&this.hasJSActions?(i.addEventListener("updatefromsandbox",u=>{const d={value(f){r==null||r();const g=f.detail.value,p=new Set(Array.isArray(g)?g:[g]);for(const b of i.options)b.selected=p.has(b.value);t.setValue(e,{value:o(!0)}),h=o(!1)},multipleSelection(f){i.multiple=!0},remove(f){const g=i.options,p=f.detail.remove;g[p].selected=!1,i.remove(p),g.length>0&&Array.prototype.findIndex.call(g,v=>v.selected)===-1&&(g[0].selected=!0),t.setValue(e,{value:o(!0),items:c(f)}),h=o(!1)},clear(f){for(;i.length!==0;)i.remove(0);t.setValue(e,{value:null,items:[]}),h=o(!1)},insert(f){const{index:g,displayValue:p,exportValue:b}=f.detail.insert,v=i.children[g],_=document.createElement("option");_.textContent=p,_.value=b,v?v.before(_):i.append(_),t.setValue(e,{value:o(!0),items:c(f)}),h=o(!1)},items(f){const{items:g}=f.detail;for(;i.length!==0;)i.remove(0);for(const p of g){const{displayValue:b,exportValue:v}=p,_=document.createElement("option");_.textContent=b,_.value=v,i.append(_)}i.options.length>0&&(i.options[0].selected=!0),t.setValue(e,{value:o(!0),items:c(f)}),h=o(!1)},indices(f){const g=new Set(f.detail.indices);for(const p of f.target.options)p.selected=g.has(p.index);t.setValue(e,{value:o(!0)}),h=o(!1)},editable(f){f.target.disabled=!f.detail.editable}};this._dispatchEventFromSandbox(d,u)}),i.addEventListener("input",u=>{var g;const d=o(!0),f=o(!1);t.setValue(e,{value:d}),u.preventDefault(),(g=this.linkService.eventBus)==null||g.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:h,change:f,changeEx:d,willCommit:!1,commitKey:1,keyDown:!1}})}),this._setEventListeners(i,null,[["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"],["input","Action"],["input","Validate"]],u=>u.target.value)):i.addEventListener("input",function(u){t.setValue(e,{value:o(!0)})}),this.data.combo&&this._setTextStyle(i),this._setBackgroundColor(i),this._setDefaultPropertiesFromJS(i),this.container.append(i),this.container}}class Dg extends jt{constructor(t){const{data:e,elements:s}=t;super(t,{isRenderable:jt._hasPopupData(e)}),this.elements=s,this.popup=null}render(){this.container.classList.add("popupAnnotation");const t=this.popup=new DS({container:this.container,color:this.data.color,titleObj:this.data.titleObj,modificationDate:this.data.modificationDate,contentsObj:this.data.contentsObj,richText:this.data.richText,rect:this.data.rect,parentRect:this.data.parentRect||null,parent:this.parent,elements:this.elements,open:this.data.open}),e=[];for(const s of this.elements)s.popup=t,s.container.ariaHasPopup="dialog",e.push(s.data.id),s.addHighlightArea();return this.container.setAttribute("aria-controls",e.map(s=>`${ug}${s}`).join(",")),this.container}}class DS{constructor({container:t,color:e,elements:s,titleObj:i,modificationDate:n,contentsObj:r,richText:o,parent:h,rect:c,parentRect:u,open:d}){y(this,bt);y(this,Ha,w(this,bt,Iy).bind(this));y(this,vd,w(this,bt,xp).bind(this));y(this,_d,w(this,bt,Vd).bind(this));y(this,Ga,w(this,bt,zd).bind(this));y(this,po,null);y(this,Lt,null);y(this,ln,null);y(this,za,null);y(this,Vl,null);y(this,Xl,null);y(this,Va,null);y(this,cn,!1);y(this,$s,null);y(this,un,null);y(this,Wl,null);y(this,dn,null);y(this,Ul,null);y(this,mo,null);y(this,bo,!1);var f;m(this,Lt,t),m(this,Ul,i),m(this,ln,r),m(this,dn,o),m(this,Xl,h),m(this,po,e),m(this,Wl,c),m(this,Va,u),m(this,Vl,s),m(this,za,gg.toDateObject(n)),this.trigger=s.flatMap(g=>g.getElementsToTriggerPopup());for(const g of this.trigger)g.addEventListener("click",l(this,Ga)),g.addEventListener("mouseenter",l(this,_d)),g.addEventListener("mouseleave",l(this,vd)),g.classList.add("popupTriggerArea");for(const g of s)(f=g.container)==null||f.addEventListener("keydown",l(this,Ha));l(this,Lt).hidden=!0,d&&w(this,bt,zd).call(this)}render(){if(l(this,$s))return;const t=m(this,$s,document.createElement("div"));if(t.className="popup",l(this,po)){const n=t.style.outlineColor=W.makeHexColor(...l(this,po));CSS.supports("background-color","color-mix(in srgb, red 30%, white)")?t.style.backgroundColor=`color-mix(in srgb, ${n} 30%, white)`:t.style.backgroundColor=W.makeHexColor(...l(this,po).map(o=>Math.floor(.7*(255-o)+o)))}const e=document.createElement("span");e.className="header";const s=document.createElement("h1");if(e.append(s),{dir:s.dir,str:s.textContent}=l(this,Ul),t.append(e),l(this,za)){const n=document.createElement("span");n.classList.add("popupDate"),n.setAttribute("data-l10n-id","pdfjs-annotation-date-time-string"),n.setAttribute("data-l10n-args",JSON.stringify({dateObj:l(this,za).valueOf()})),e.append(n)}const i=l(this,bt,Gd);if(i)Pb.render({xfaHtml:i,intent:"richText",div:t}),t.lastChild.classList.add("richText","popupContent");else{const n=this._formatContents(l(this,ln));t.append(n)}l(this,Lt).append(t)}_formatContents({str:t,dir:e}){const s=document.createElement("p");s.classList.add("popupContent"),s.dir=e;const i=t.split(/(?:\r\n?|\n)/);for(let n=0,r=i.length;n<r;++n){const o=i[n];s.append(document.createTextNode(o)),n<r-1&&s.append(document.createElement("br"))}return s}updateEdited({rect:t,popupContent:e}){var s;l(this,mo)||m(this,mo,{contentsObj:l(this,ln),richText:l(this,dn)}),t&&m(this,un,null),e&&(m(this,dn,w(this,bt,Fy).call(this,e)),m(this,ln,null)),(s=l(this,$s))==null||s.remove(),m(this,$s,null)}resetEdited(){var t;l(this,mo)&&({contentsObj:Ge(this,ln)._,richText:Ge(this,dn)._}=l(this,mo),m(this,mo,null),(t=l(this,$s))==null||t.remove(),m(this,$s,null),m(this,un,null))}forceHide(){m(this,bo,this.isVisible),l(this,bo)&&(l(this,Lt).hidden=!0)}maybeShow(){l(this,bo)&&(l(this,$s)||w(this,bt,Vd).call(this),m(this,bo,!1),l(this,Lt).hidden=!1)}get isVisible(){return l(this,Lt).hidden===!1}}Ha=new WeakMap,vd=new WeakMap,_d=new WeakMap,Ga=new WeakMap,po=new WeakMap,Lt=new WeakMap,ln=new WeakMap,za=new WeakMap,Vl=new WeakMap,Xl=new WeakMap,Va=new WeakMap,cn=new WeakMap,$s=new WeakMap,un=new WeakMap,Wl=new WeakMap,dn=new WeakMap,Ul=new WeakMap,mo=new WeakMap,bo=new WeakMap,bt=new WeakSet,Gd=function(){const t=l(this,dn),e=l(this,ln);return t!=null&&t.str&&(!(e!=null&&e.str)||e.str===t.str)&&l(this,dn).html||null},wp=function(){var t,e,s;return((s=(e=(t=l(this,bt,Gd))==null?void 0:t.attributes)==null?void 0:e.style)==null?void 0:s.fontSize)||0},Ly=function(){var t,e,s;return((s=(e=(t=l(this,bt,Gd))==null?void 0:t.attributes)==null?void 0:e.style)==null?void 0:s.color)||null},Fy=function(t){const e=[],s={str:t,html:{name:"div",attributes:{dir:"auto"},children:[{name:"p",children:e}]}},i={style:{color:l(this,bt,Ly),fontSize:l(this,bt,wp)?`calc(${l(this,bt,wp)}px * var(--scale-factor))`:""}};for(const n of t.split(`
501
+ `))e.push({name:"span",value:n,attributes:i});return s},Iy=function(t){t.altKey||t.shiftKey||t.ctrlKey||t.metaKey||(t.key==="Enter"||t.key==="Escape"&&l(this,cn))&&w(this,bt,zd).call(this)},Ny=function(){if(l(this,un)!==null)return;const{page:{view:t},viewport:{rawDims:{pageWidth:e,pageHeight:s,pageX:i,pageY:n}}}=l(this,Xl);let r=!!l(this,Va),o=r?l(this,Va):l(this,Wl);for(const p of l(this,Vl))if(!o||W.intersect(p.data.rect,o)!==null){o=p.data.rect,r=!0;break}const h=W.normalizeRect([o[0],t[3]-o[1]+t[1],o[2],t[3]-o[3]+t[1]]),u=r?o[2]-o[0]+5:0,d=h[0]+u,f=h[1];m(this,un,[100*(d-i)/e,100*(f-n)/s]);const{style:g}=l(this,Lt);g.left=`${l(this,un)[0]}%`,g.top=`${l(this,un)[1]}%`},zd=function(){m(this,cn,!l(this,cn)),l(this,cn)?(w(this,bt,Vd).call(this),l(this,Lt).addEventListener("click",l(this,Ga)),l(this,Lt).addEventListener("keydown",l(this,Ha))):(w(this,bt,xp).call(this),l(this,Lt).removeEventListener("click",l(this,Ga)),l(this,Lt).removeEventListener("keydown",l(this,Ha)))},Vd=function(){l(this,$s)||this.render(),this.isVisible?l(this,cn)&&l(this,Lt).classList.add("focused"):(w(this,bt,Ny).call(this),l(this,Lt).hidden=!1,l(this,Lt).style.zIndex=parseInt(l(this,Lt).style.zIndex)+1e3)},xp=function(){l(this,Lt).classList.remove("focused"),!(l(this,cn)||!this.isVisible)&&(l(this,Lt).hidden=!0,l(this,Lt).style.zIndex=parseInt(l(this,Lt).style.zIndex)-1e3)};class Rb extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.textContent=t.data.textContent,this.textPosition=t.data.textPosition,this.annotationEditorType=Z.FREETEXT}render(){if(this.container.classList.add("freeTextAnnotation"),this.textContent){const t=document.createElement("div");t.classList.add("annotationTextContent"),t.setAttribute("role","comment");for(const e of this.textContent){const s=document.createElement("span");s.textContent=e,t.append(s)}this.container.append(t)}return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this._editOnDoubleClick(),this.container}}class OS extends jt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});y(this,Yl,null)}render(){this.container.classList.add("lineAnnotation");const e=this.data,{width:s,height:i}=Fn(e.rect),n=this.svgFactory.create(s,i,!0),r=m(this,Yl,this.svgFactory.createElement("svg:line"));return r.setAttribute("x1",e.rect[2]-e.lineCoordinates[0]),r.setAttribute("y1",e.rect[3]-e.lineCoordinates[1]),r.setAttribute("x2",e.rect[2]-e.lineCoordinates[2]),r.setAttribute("y2",e.rect[3]-e.lineCoordinates[3]),r.setAttribute("stroke-width",e.borderStyle.width||1),r.setAttribute("stroke","transparent"),r.setAttribute("fill","transparent"),n.append(r),this.container.append(n),!e.popupRef&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return l(this,Yl)}addHighlightArea(){this.container.classList.add("highlightArea")}}Yl=new WeakMap;class RS extends jt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});y(this,$l,null)}render(){this.container.classList.add("squareAnnotation");const e=this.data,{width:s,height:i}=Fn(e.rect),n=this.svgFactory.create(s,i,!0),r=e.borderStyle.width,o=m(this,$l,this.svgFactory.createElement("svg:rect"));return o.setAttribute("x",r/2),o.setAttribute("y",r/2),o.setAttribute("width",s-r),o.setAttribute("height",i-r),o.setAttribute("stroke-width",r||1),o.setAttribute("stroke","transparent"),o.setAttribute("fill","transparent"),n.append(o),this.container.append(n),!e.popupRef&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return l(this,$l)}addHighlightArea(){this.container.classList.add("highlightArea")}}$l=new WeakMap;class LS extends jt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});y(this,ql,null)}render(){this.container.classList.add("circleAnnotation");const e=this.data,{width:s,height:i}=Fn(e.rect),n=this.svgFactory.create(s,i,!0),r=e.borderStyle.width,o=m(this,ql,this.svgFactory.createElement("svg:ellipse"));return o.setAttribute("cx",s/2),o.setAttribute("cy",i/2),o.setAttribute("rx",s/2-r/2),o.setAttribute("ry",i/2-r/2),o.setAttribute("stroke-width",r||1),o.setAttribute("stroke","transparent"),o.setAttribute("fill","transparent"),n.append(o),this.container.append(n),!e.popupRef&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return l(this,ql)}addHighlightArea(){this.container.classList.add("highlightArea")}}ql=new WeakMap;class Lb extends jt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});y(this,Kl,null);this.containerClassName="polylineAnnotation",this.svgElementName="svg:polyline"}render(){this.container.classList.add(this.containerClassName);const{data:{rect:e,vertices:s,borderStyle:i,popupRef:n}}=this;if(!s)return this.container;const{width:r,height:o}=Fn(e),h=this.svgFactory.create(r,o,!0);let c=[];for(let d=0,f=s.length;d<f;d+=2){const g=s[d]-e[0],p=e[3]-s[d+1];c.push(`${g},${p}`)}c=c.join(" ");const u=m(this,Kl,this.svgFactory.createElement(this.svgElementName));return u.setAttribute("points",c),u.setAttribute("stroke-width",i.width||1),u.setAttribute("stroke","transparent"),u.setAttribute("fill","transparent"),h.append(u),this.container.append(h),!n&&this.hasPopupData&&this._createPopup(),this.container}getElementsToTriggerPopup(){return l(this,Kl)}addHighlightArea(){this.container.classList.add("highlightArea")}}Kl=new WeakMap;class FS extends Lb{constructor(t){super(t),this.containerClassName="polygonAnnotation",this.svgElementName="svg:polygon"}}class IS extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){return this.container.classList.add("caretAnnotation"),!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container}}class Og extends jt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});y(this,Jl);y(this,Ql,null);y(this,yo,[]);this.containerClassName="inkAnnotation",this.svgElementName="svg:polyline",this.annotationEditorType=this.data.it==="InkHighlight"?Z.HIGHLIGHT:Z.INK}render(){this.container.classList.add(this.containerClassName);const{data:{rect:e,rotation:s,inkLists:i,borderStyle:n,popupRef:r}}=this,{transform:o,width:h,height:c}=w(this,Jl,Sp).call(this,s,e),u=this.svgFactory.create(h,c,!0),d=m(this,Ql,this.svgFactory.createElement("svg:g"));u.append(d),d.setAttribute("stroke-width",n.width||1),d.setAttribute("stroke-linecap","round"),d.setAttribute("stroke-linejoin","round"),d.setAttribute("stroke-miterlimit",10),d.setAttribute("stroke","transparent"),d.setAttribute("fill","transparent"),d.setAttribute("transform",o);for(let f=0,g=i.length;f<g;f++){const p=this.svgFactory.createElement(this.svgElementName);l(this,yo).push(p),p.setAttribute("points",i[f].join(",")),d.append(p)}return!r&&this.hasPopupData&&this._createPopup(),this.container.append(u),this._editOnDoubleClick(),this.container}updateEdited(e){super.updateEdited(e);const{thickness:s,points:i,rect:n}=e,r=l(this,Ql);if(s>=0&&r.setAttribute("stroke-width",s||1),i)for(let o=0,h=l(this,yo).length;o<h;o++)l(this,yo)[o].setAttribute("points",i[o].join(","));if(n){const{transform:o,width:h,height:c}=w(this,Jl,Sp).call(this,this.data.rotation,n);r.parentElement.setAttribute("viewBox",`0 0 ${h} ${c}`),r.setAttribute("transform",o)}}getElementsToTriggerPopup(){return l(this,yo)}addHighlightArea(){this.container.classList.add("highlightArea")}}Ql=new WeakMap,yo=new WeakMap,Jl=new WeakSet,Sp=function(e,s){switch(e){case 90:return{transform:`rotate(90) translate(${-s[0]},${s[1]}) scale(1,-1)`,width:s[3]-s[1],height:s[2]-s[0]};case 180:return{transform:`rotate(180) translate(${-s[2]},${s[1]}) scale(1,-1)`,width:s[2]-s[0],height:s[3]-s[1]};case 270:return{transform:`rotate(270) translate(${-s[2]},${s[3]}) scale(1,-1)`,width:s[3]-s[1],height:s[2]-s[0]};default:return{transform:`translate(${-s[0]},${s[3]}) scale(1,-1)`,width:s[2]-s[0],height:s[3]-s[1]}}};class Fb extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0}),this.annotationEditorType=Z.HIGHLIGHT}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("highlightAnnotation"),this._editOnDoubleClick(),this.container}}class NS extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("underlineAnnotation"),this.container}}class jS extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("squigglyAnnotation"),this.container}}class BS extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("strikeoutAnnotation"),this.container}}class Ib extends jt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.annotationEditorType=Z.STAMP}render(){return this.container.classList.add("stampAnnotation"),this.container.setAttribute("role","img"),!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this._editOnDoubleClick(),this.container}}class HS extends jt{constructor(e){var i;super(e,{isRenderable:!0});y(this,tc);y(this,Zl,null);const{file:s}=this.data;this.filename=s.filename,this.content=s.content,(i=this.linkService.eventBus)==null||i.dispatch("fileattachmentannotation",{source:this,...s})}render(){this.container.classList.add("fileAttachmentAnnotation");const{container:e,data:s}=this;let i;s.hasAppearance||s.fillAlpha===0?i=document.createElement("div"):(i=document.createElement("img"),i.src=`${this.imageResourcesPath}annotation-${/paperclip/i.test(s.name)?"paperclip":"pushpin"}.svg`,s.fillAlpha&&s.fillAlpha<1&&(i.style=`filter: opacity(${Math.round(s.fillAlpha*100)}%);`)),i.addEventListener("dblclick",w(this,tc,Cp).bind(this)),m(this,Zl,i);const{isMac:n}=Re.platform;return e.addEventListener("keydown",r=>{r.key==="Enter"&&(n?r.metaKey:r.ctrlKey)&&w(this,tc,Cp).call(this)}),!s.popupRef&&this.hasPopupData?this._createPopup():i.classList.add("popupTriggerArea"),e.append(i),e}getElementsToTriggerPopup(){return l(this,Zl)}addHighlightArea(){this.container.classList.add("highlightArea")}}Zl=new WeakMap,tc=new WeakSet,Cp=function(){var e;(e=this.downloadManager)==null||e.openOrDownloadData(this.content,this.filename)};class GS{constructor({div:t,accessibilityManager:e,annotationCanvasMap:s,annotationEditorUIManager:i,page:n,viewport:r,structTreeLayer:o}){y(this,wo);y(this,ec,null);y(this,vo,null);y(this,_o,new Map);y(this,sc,null);this.div=t,m(this,ec,e),m(this,vo,s),m(this,sc,o||null),this.page=n,this.viewport=r,this.zIndex=0,this._annotationEditorUIManager=i}hasEditableAnnotations(){return l(this,_o).size>0}async render(t){var r;const{annotations:e}=t,s=this.div;kr(s,this.viewport);const i=new Map,n={data:null,layer:s,linkService:t.linkService,downloadManager:t.downloadManager,imageResourcesPath:t.imageResourcesPath||"",renderForms:t.renderForms!==!1,svgFactory:new Pg,annotationStorage:t.annotationStorage||new wg,enableScripting:t.enableScripting===!0,hasJSActions:t.hasJSActions,fieldObjects:t.fieldObjects,parent:this,elements:null};for(const o of e){if(o.noHTML)continue;const h=o.annotationType===qt.POPUP;if(h){const d=i.get(o.id);if(!d)continue;n.elements=d}else{const{width:d,height:f}=Fn(o.rect);if(d<=0||f<=0)continue}n.data=o;const c=CS.create(n);if(!c.isRenderable)continue;if(!h&&o.popupRef){const d=i.get(o.popupRef);d?d.push(c):i.set(o.popupRef,[c])}const u=c.render();o.hidden&&(u.style.visibility="hidden"),await w(this,wo,jy).call(this,u,o.id),c._isEditable&&(l(this,_o).set(c.data.id,c),(r=this._annotationEditorUIManager)==null||r.renderAnnotationElement(c))}w(this,wo,Ap).call(this)}update({viewport:t}){const e=this.div;this.viewport=t,kr(e,{rotation:t.rotation}),w(this,wo,Ap).call(this),e.hidden=!1}getEditableAnnotations(){return Array.from(l(this,_o).values())}getEditableAnnotation(t){return l(this,_o).get(t)}}ec=new WeakMap,vo=new WeakMap,_o=new WeakMap,sc=new WeakMap,wo=new WeakSet,jy=async function(t,e){var r,o;const s=t.firstChild||t,i=s.id=`${ug}${e}`,n=await((r=l(this,sc))==null?void 0:r.getAriaAttributes(i));if(n)for(const[h,c]of n)s.setAttribute(h,c);this.div.append(t),(o=l(this,ec))==null||o.moveElementInDOM(this.div,t,s,!1)},Ap=function(){if(!l(this,vo))return;const t=this.div;for(const[e,s]of l(this,vo)){const i=t.querySelector(`[data-annotation-id="${e}"]`);if(!i)continue;s.className="annotationContent";const{firstChild:n}=i;n?n.nodeName==="CANVAS"?n.replaceWith(s):n.classList.contains("annotationContent")?n.after(s):n.before(s):i.append(s)}l(this,vo).clear()};const sd=/\r\n?|\n/g,wt=class wt extends Pt{constructor(e){super({...e,name:"freeTextEditor"});y(this,Ut);y(this,qs);y(this,hs,"");y(this,ic,`${this.id}-editor`);y(this,xo,null);y(this,ls);m(this,qs,e.color||wt._defaultColor||Pt._defaultLineColor),m(this,ls,e.fontSize||wt._defaultFontSize)}static get _keyboardManager(){const e=wt.prototype,s=r=>r.isEmpty(),i=Mr.TRANSLATE_SMALL,n=Mr.TRANSLATE_BIG;return st(this,"_keyboardManager",new Xh([[["ctrl+s","mac+meta+s","ctrl+p","mac+meta+p"],e.commitOrRemove,{bubbles:!0}],[["ctrl+Enter","mac+meta+Enter","Escape","mac+Escape"],e.commitOrRemove],[["ArrowLeft","mac+ArrowLeft"],e._translateEmpty,{args:[-i,0],checker:s}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],e._translateEmpty,{args:[-n,0],checker:s}],[["ArrowRight","mac+ArrowRight"],e._translateEmpty,{args:[i,0],checker:s}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],e._translateEmpty,{args:[n,0],checker:s}],[["ArrowUp","mac+ArrowUp"],e._translateEmpty,{args:[0,-i],checker:s}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],e._translateEmpty,{args:[0,-n],checker:s}],[["ArrowDown","mac+ArrowDown"],e._translateEmpty,{args:[0,i],checker:s}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],e._translateEmpty,{args:[0,n],checker:s}]]))}static initialize(e,s){Pt.initialize(e,s);const i=getComputedStyle(document.documentElement);this._internalPadding=parseFloat(i.getPropertyValue("--freetext-padding"))}static updateDefaultParams(e,s){switch(e){case ot.FREETEXT_SIZE:wt._defaultFontSize=s;break;case ot.FREETEXT_COLOR:wt._defaultColor=s;break}}updateParams(e,s){switch(e){case ot.FREETEXT_SIZE:w(this,Ut,By).call(this,s);break;case ot.FREETEXT_COLOR:w(this,Ut,Hy).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[ot.FREETEXT_SIZE,wt._defaultFontSize],[ot.FREETEXT_COLOR,wt._defaultColor||Pt._defaultLineColor]]}get propertiesToUpdate(){return[[ot.FREETEXT_SIZE,l(this,ls)],[ot.FREETEXT_COLOR,l(this,qs)]]}_translateEmpty(e,s){this._uiManager.translateSelectedEditors(e,s,!0)}getInitialTranslation(){const e=this.parentScale;return[-wt._internalPadding*e,-(wt._internalPadding+l(this,ls))*e]}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.isAttachedToDOM||this.parent.add(this)))}enableEditMode(){if(this.isInEditMode())return;this.parent.setEditingState(!1),this.parent.updateToolbar(Z.FREETEXT),super.enableEditMode(),this.overlayDiv.classList.remove("enabled"),this.editorDiv.contentEditable=!0,this._isDraggable=!1,this.div.removeAttribute("aria-activedescendant"),m(this,xo,new AbortController);const e=this._uiManager.combinedSignal(l(this,xo));this.editorDiv.addEventListener("keydown",this.editorDivKeydown.bind(this),{signal:e}),this.editorDiv.addEventListener("focus",this.editorDivFocus.bind(this),{signal:e}),this.editorDiv.addEventListener("blur",this.editorDivBlur.bind(this),{signal:e}),this.editorDiv.addEventListener("input",this.editorDivInput.bind(this),{signal:e}),this.editorDiv.addEventListener("paste",this.editorDivPaste.bind(this),{signal:e})}disableEditMode(){var e;this.isInEditMode()&&(this.parent.setEditingState(!0),super.disableEditMode(),this.overlayDiv.classList.add("enabled"),this.editorDiv.contentEditable=!1,this.div.setAttribute("aria-activedescendant",l(this,ic)),this._isDraggable=!0,(e=l(this,xo))==null||e.abort(),m(this,xo,null),this.div.focus({preventScroll:!0}),this.isEditing=!1,this.parent.div.classList.add("freetextEditing"))}focusin(e){this._focusEventsAllowed&&(super.focusin(e),e.target!==this.editorDiv&&this.editorDiv.focus())}onceAdded(e){var s;this.width||(this.enableEditMode(),e&&this.editorDiv.focus(),(s=this._initialOptions)!=null&&s.isCentered&&this.center(),this._initialOptions=null)}isEmpty(){return!this.editorDiv||this.editorDiv.innerText.trim()===""}remove(){this.isEditing=!1,this.parent&&(this.parent.setEditingState(!0),this.parent.div.classList.add("freetextEditing")),super.remove()}commit(){if(!this.isInEditMode())return;super.commit(),this.disableEditMode();const e=l(this,hs),s=m(this,hs,w(this,Ut,Gy).call(this).trimEnd());if(e===s)return;const i=n=>{if(m(this,hs,n),!n){this.remove();return}w(this,Ut,Ud).call(this),this._uiManager.rebuild(this),w(this,Ut,Xd).call(this)};this.addCommands({cmd:()=>{i(s)},undo:()=>{i(e)},mustExec:!1}),w(this,Ut,Xd).call(this)}shouldGetKeyboardEvents(){return this.isInEditMode()}enterInEditMode(){this.enableEditMode(),this.editorDiv.focus()}dblclick(e){this.enterInEditMode()}keydown(e){e.target===this.div&&e.key==="Enter"&&(this.enterInEditMode(),e.preventDefault())}editorDivKeydown(e){wt._keyboardManager.exec(this,e)}editorDivFocus(e){this.isEditing=!0}editorDivBlur(e){this.isEditing=!1}editorDivInput(e){this.parent.div.classList.toggle("freetextEditing",this.isEmpty())}disableEditing(){this.editorDiv.setAttribute("role","comment"),this.editorDiv.removeAttribute("aria-multiline")}enableEditing(){this.editorDiv.setAttribute("role","textbox"),this.editorDiv.setAttribute("aria-multiline",!0)}render(){if(this.div)return this.div;let e,s;this.width&&(e=this.x,s=this.y),super.render(),this.editorDiv=document.createElement("div"),this.editorDiv.className="internal",this.editorDiv.setAttribute("id",l(this,ic)),this.editorDiv.setAttribute("data-l10n-id","pdfjs-free-text2"),this.editorDiv.setAttribute("data-l10n-attrs","default-content"),this.enableEditing(),this.editorDiv.contentEditable=!0;const{style:i}=this.editorDiv;if(i.fontSize=`calc(${l(this,ls)}px * var(--scale-factor))`,i.color=l(this,qs),this.div.append(this.editorDiv),this.overlayDiv=document.createElement("div"),this.overlayDiv.classList.add("overlay","enabled"),this.div.append(this.overlayDiv),$u(this,this.div,["dblclick","keydown"]),this.width){const[n,r]=this.parentDimensions;if(this.annotationElementId){const{position:o}=this._initialData;let[h,c]=this.getInitialTranslation();[h,c]=this.pageTranslationToScreen(h,c);const[u,d]=this.pageDimensions,[f,g]=this.pageTranslation;let p,b;switch(this.rotation){case 0:p=e+(o[0]-f)/u,b=s+this.height-(o[1]-g)/d;break;case 90:p=e+(o[0]-f)/u,b=s-(o[1]-g)/d,[h,c]=[c,-h];break;case 180:p=e-this.width+(o[0]-f)/u,b=s-(o[1]-g)/d,[h,c]=[-h,-c];break;case 270:p=e+(o[0]-f-this.height*d)/u,b=s+(o[1]-g-this.width*u)/d,[h,c]=[-c,h];break}this.setAt(p*n,b*r,h,c)}else this.setAt(e*n,s*r,this.width*n,this.height*r);w(this,Ut,Ud).call(this),this._isDraggable=!0,this.editorDiv.contentEditable=!1}else this._isDraggable=!1,this.editorDiv.contentEditable=!0;return this.div}editorDivPaste(e){var p,b,v;const s=e.clipboardData||window.clipboardData,{types:i}=s;if(i.length===1&&i[0]==="text/plain")return;e.preventDefault();const n=w(p=wt,fn,Tp).call(p,s.getData("text")||"").replaceAll(sd,`
502
502
  `);if(!n)return;const r=window.getSelection();if(!r.rangeCount)return;this.editorDiv.normalize(),r.deleteFromDocument();const o=r.getRangeAt(0);if(!n.includes(`
503
503
  `)){o.insertNode(document.createTextNode(n)),this.editorDiv.normalize(),r.collapseToStart();return}const{startContainer:h,startOffset:c}=o,u=[],d=[];if(h.nodeType===Node.TEXT_NODE){const _=h.parentElement;if(d.push(h.nodeValue.slice(c).replaceAll(sd,"")),_!==this.editorDiv){let x=u;for(const C of this.editorDiv.childNodes){if(C===_){x=d;continue}x.push(w(b=wt,fn,Wd).call(b,C))}}u.push(h.nodeValue.slice(0,c).replaceAll(sd,""))}else if(h===this.editorDiv){let _=u,x=0;for(const C of this.editorDiv.childNodes)x++===c&&(_=d),_.push(w(v=wt,fn,Wd).call(v,C))}m(this,hs,`${u.join(`
504
504
  `)}${n}${d.join(`
505
505
  `)}`),w(this,Ut,Ud).call(this);const f=new Range;let g=u.reduce((_,x)=>_+x.length,0);for(const{firstChild:_}of this.editorDiv.childNodes)if(_.nodeType===Node.TEXT_NODE){const x=_.nodeValue.length;if(g<=x){f.setStart(_,g),f.setEnd(_,g);break}g-=x}r.removeAllRanges(),r.addRange(f)}get contentDiv(){return this.editorDiv}static async deserialize(e,s,i){var o;let n=null;if(e instanceof Rb){const{data:{defaultAppearanceData:{fontSize:h,fontColor:c},rect:u,rotation:d,id:f,popupRef:g},textContent:p,textPosition:b,parent:{page:{pageNumber:v}}}=e;if(!p||p.length===0)return null;n=e={annotationType:Z.FREETEXT,color:Array.from(c),fontSize:h,value:p.join(`
506
- `),position:b,pageIndex:v-1,rect:u.slice(0),rotation:d,id:f,deleted:!1,popupRef:g}}const r=await super.deserialize(e,s,i);return m(r,ls,e.fontSize),m(r,qs,X.makeHexColor(...e.color)),m(r,hs,w(o=wt,fn,Tp).call(o,e.value)),r.annotationElementId=e.id||null,r._initialData=n,r}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const s=wt._internalPadding*this.parentScale,i=this.getRect(s,s),n=Pt._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:l(this,qs)),r={annotationType:Z.FREETEXT,color:n,fontSize:l(this,ls),value:w(this,Ut,zy).call(this),pageIndex:this.pageIndex,rect:i,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?r:this.annotationElementId&&!w(this,Ut,Vy).call(this,r)?null:(r.id=this.annotationElementId,r)}renderAnnotationElement(e){const s=super.renderAnnotationElement(e);if(this.deleted)return s;const{style:i}=s;i.fontSize=`calc(${l(this,ls)}px * var(--scale-factor))`,i.color=l(this,qs),s.replaceChildren();for(const r of l(this,hs).split(`
506
+ `),position:b,pageIndex:v-1,rect:u.slice(0),rotation:d,id:f,deleted:!1,popupRef:g}}const r=await super.deserialize(e,s,i);return m(r,ls,e.fontSize),m(r,qs,W.makeHexColor(...e.color)),m(r,hs,w(o=wt,fn,Tp).call(o,e.value)),r.annotationElementId=e.id||null,r._initialData=n,r}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const s=wt._internalPadding*this.parentScale,i=this.getRect(s,s),n=Pt._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:l(this,qs)),r={annotationType:Z.FREETEXT,color:n,fontSize:l(this,ls),value:w(this,Ut,zy).call(this),pageIndex:this.pageIndex,rect:i,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?r:this.annotationElementId&&!w(this,Ut,Vy).call(this,r)?null:(r.id=this.annotationElementId,r)}renderAnnotationElement(e){const s=super.renderAnnotationElement(e);if(this.deleted)return s;const{style:i}=s;i.fontSize=`calc(${l(this,ls)}px * var(--scale-factor))`,i.color=l(this,qs),s.replaceChildren();for(const r of l(this,hs).split(`
507
507
  `)){const o=document.createElement("div");o.append(r?document.createTextNode(r):document.createElement("br")),s.append(o)}const n=wt._internalPadding*this.parentScale;return e.updateEdited({rect:this.getRect(n,n),popupContent:l(this,hs)}),s}resetAnnotationElement(e){super.resetAnnotationElement(e),e.resetEdited()}};qs=new WeakMap,hs=new WeakMap,ic=new WeakMap,xo=new WeakMap,ls=new WeakMap,Ut=new WeakSet,By=function(e){const s=n=>{this.editorDiv.style.fontSize=`calc(${n}px * var(--scale-factor))`,this.translate(0,-(n-l(this,ls))*this.parentScale),m(this,ls,n),w(this,Ut,Xd).call(this)},i=l(this,ls);this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:ot.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})},Hy=function(e){const s=n=>{m(this,qs,this.editorDiv.style.color=n)},i=l(this,qs);this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:ot.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})},Gy=function(){var i;const e=[];this.editorDiv.normalize();let s=null;for(const n of this.editorDiv.childNodes)(s==null?void 0:s.nodeType)===Node.TEXT_NODE&&n.nodeName==="BR"||(e.push(w(i=wt,fn,Wd).call(i,n)),s=n);return e.join(`
508
508
  `)},Xd=function(){const[e,s]=this.parentDimensions;let i;if(this.isAttachedToDOM)i=this.div.getBoundingClientRect();else{const{currentLayer:n,div:r}=this,o=r.style.display,h=r.classList.contains("hidden");r.classList.remove("hidden"),r.style.display="hidden",n.div.append(this.div),i=r.getBoundingClientRect(),r.remove(),r.style.display=o,r.classList.toggle("hidden",h)}this.rotation%180===this.parentRotation%180?(this.width=i.width/e,this.height=i.height/s):(this.width=i.height/e,this.height=i.width/s),this.fixAndSetPosition()},fn=new WeakSet,Wd=function(e){return(e.nodeType===Node.TEXT_NODE?e.nodeValue:e.innerText).replaceAll(sd,"")},Ud=function(){if(this.editorDiv.replaceChildren(),!!l(this,hs))for(const e of l(this,hs).split(`
509
- `)){const s=document.createElement("div");s.append(e?document.createTextNode(e):document.createElement("br")),this.editorDiv.append(s)}},zy=function(){return l(this,hs).replaceAll(" "," ")},Tp=function(e){return e.replaceAll(" "," ")},Vy=function(e){const{value:s,fontSize:i,color:n,pageIndex:r}=this._initialData;return this._hasBeenMoved||e.value!==s||e.fontSize!==i||e.color.some((o,h)=>o!==n[h])||e.pageIndex!==r},y(wt,fn),$(wt,"_freeTextDefaultContent",""),$(wt,"_internalPadding",0),$(wt,"_defaultColor",null),$(wt,"_defaultFontSize",10),$(wt,"_type","freetext"),$(wt,"_editorType",Z.FREETEXT);let Rg=wt;class B{toSVGPath(){vt("Abstract method `toSVGPath` must be implemented.")}get box(){vt("Abstract getter `box` must be implemented.")}serialize(t,e){vt("Abstract method `serialize` must be implemented.")}static _rescale(t,e,s,i,n,r){r||(r=new Float32Array(t.length));for(let o=0,h=t.length;o<h;o+=2)r[o]=e+t[o]*i,r[o+1]=s+t[o+1]*n;return r}static _rescaleAndSwap(t,e,s,i,n,r){r||(r=new Float32Array(t.length));for(let o=0,h=t.length;o<h;o+=2)r[o]=e+t[o+1]*i,r[o+1]=s+t[o]*n;return r}static _translate(t,e,s,i){i||(i=new Float32Array(t.length));for(let n=0,r=t.length;n<r;n+=2)i[n]=e+t[n],i[n+1]=s+t[n+1];return i}static svgRound(t){return Math.round(t*1e4)}static _normalizePoint(t,e,s,i,n){switch(n){case 90:return[1-e/s,t/i];case 180:return[1-t/s,1-e/i];case 270:return[e/s,1-t/i];default:return[t/s,e/i]}}static _normalizePagePoint(t,e,s){switch(s){case 90:return[1-e,t];case 180:return[1-t,1-e];case 270:return[e,1-t];default:return[t,e]}}static createBezierPoints(t,e,s,i,n,r){return[(t+5*s)/6,(e+5*i)/6,(5*s+n)/6,(5*i+r)/6,(s+n)/2,(i+r)/2]}}$(B,"PRECISION",1e-4);const gn=class gn{constructor({x:t,y:e},s,i,n,r,o=0){y(this,Jt);y(this,cs);y(this,Ks,[]);y(this,Xa);y(this,Wa);y(this,wi,[]);y(this,it,new Float32Array(18));y(this,So);y(this,Co);y(this,nc);y(this,rc);y(this,Ua);y(this,Ya);y(this,sr,[]);m(this,cs,s),m(this,Ya,n*i),m(this,Wa,r),l(this,it).set([NaN,NaN,NaN,NaN,t,e],6),m(this,Xa,o),m(this,rc,l(gn,oc)*i),m(this,nc,l(gn,xd)*i),m(this,Ua,i),l(this,sr).push(t,e)}isEmpty(){return isNaN(l(this,it)[8])}add({x:t,y:e}){var O;m(this,So,t),m(this,Co,e);const[s,i,n,r]=l(this,cs);let[o,h,c,u]=l(this,it).subarray(8,12);const d=t-c,f=e-u,g=Math.hypot(d,f);if(g<l(this,nc))return!1;const p=g-l(this,rc),b=p/g,v=b*d,_=b*f;let x=o,C=h;o=c,h=u,c+=v,u+=_,(O=l(this,sr))==null||O.push(t,e);const S=-_/p,k=v/p,D=S*l(this,Ya),T=k*l(this,Ya);return l(this,it).set(l(this,it).subarray(2,8),0),l(this,it).set([c+D,u+T],4),l(this,it).set(l(this,it).subarray(14,18),12),l(this,it).set([c-D,u-T],16),isNaN(l(this,it)[6])?(l(this,wi).length===0&&(l(this,it).set([o+D,h+T],2),l(this,wi).push(NaN,NaN,NaN,NaN,(o+D-s)/n,(h+T-i)/r),l(this,it).set([o-D,h-T],14),l(this,Ks).push(NaN,NaN,NaN,NaN,(o-D-s)/n,(h-T-i)/r)),l(this,it).set([x,C,o,h,c,u],6),!this.isEmpty()):(l(this,it).set([x,C,o,h,c,u],6),Math.abs(Math.atan2(C-h,x-o)-Math.atan2(_,v))<Math.PI/2?([o,h,c,u]=l(this,it).subarray(2,6),l(this,wi).push(NaN,NaN,NaN,NaN,((o+c)/2-s)/n,((h+u)/2-i)/r),[o,h,x,C]=l(this,it).subarray(14,18),l(this,Ks).push(NaN,NaN,NaN,NaN,((x+o)/2-s)/n,((C+h)/2-i)/r),!0):([x,C,o,h,c,u]=l(this,it).subarray(0,6),l(this,wi).push(((x+5*o)/6-s)/n,((C+5*h)/6-i)/r,((5*o+c)/6-s)/n,((5*h+u)/6-i)/r,((o+c)/2-s)/n,((h+u)/2-i)/r),[c,u,o,h,x,C]=l(this,it).subarray(12,18),l(this,Ks).push(((x+5*o)/6-s)/n,((C+5*h)/6-i)/r,((5*o+c)/6-s)/n,((5*h+u)/6-i)/r,((o+c)/2-s)/n,((h+u)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";const t=l(this,wi),e=l(this,Ks);if(isNaN(l(this,it)[6])&&!this.isEmpty())return w(this,Jt,Xy).call(this);const s=[];s.push(`M${t[4]} ${t[5]}`);for(let i=6;i<t.length;i+=6)isNaN(t[i])?s.push(`L${t[i+4]} ${t[i+5]}`):s.push(`C${t[i]} ${t[i+1]} ${t[i+2]} ${t[i+3]} ${t[i+4]} ${t[i+5]}`);w(this,Jt,Uy).call(this,s);for(let i=e.length-6;i>=6;i-=6)isNaN(e[i])?s.push(`L${e[i+4]} ${e[i+5]}`):s.push(`C${e[i]} ${e[i+1]} ${e[i+2]} ${e[i+3]} ${e[i+4]} ${e[i+5]}`);return w(this,Jt,Wy).call(this,s),s.join(" ")}newFreeDrawOutline(t,e,s,i,n,r){return new Nb(t,e,s,i,n,r)}getOutlines(){var d;const t=l(this,wi),e=l(this,Ks),s=l(this,it),[i,n,r,o]=l(this,cs),h=new Float32Array((((d=l(this,sr))==null?void 0:d.length)??0)+2);for(let f=0,g=h.length-2;f<g;f+=2)h[f]=(l(this,sr)[f]-i)/r,h[f+1]=(l(this,sr)[f+1]-n)/o;if(h[h.length-2]=(l(this,So)-i)/r,h[h.length-1]=(l(this,Co)-n)/o,isNaN(s[6])&&!this.isEmpty())return w(this,Jt,Yy).call(this,h);const c=new Float32Array(l(this,wi).length+24+l(this,Ks).length);let u=t.length;for(let f=0;f<u;f+=2){if(isNaN(t[f])){c[f]=c[f+1]=NaN;continue}c[f]=t[f],c[f+1]=t[f+1]}u=w(this,Jt,qy).call(this,c,u);for(let f=e.length-6;f>=6;f-=6)for(let g=0;g<6;g+=2){if(isNaN(e[f+g])){c[u]=c[u+1]=NaN,u+=2;continue}c[u]=e[f+g],c[u+1]=e[f+g+1],u+=2}return w(this,Jt,$y).call(this,c,u),this.newFreeDrawOutline(c,h,l(this,cs),l(this,Ua),l(this,Xa),l(this,Wa))}};cs=new WeakMap,Ks=new WeakMap,Xa=new WeakMap,Wa=new WeakMap,wi=new WeakMap,it=new WeakMap,So=new WeakMap,Co=new WeakMap,nc=new WeakMap,rc=new WeakMap,Ua=new WeakMap,Ya=new WeakMap,sr=new WeakMap,oc=new WeakMap,wd=new WeakMap,xd=new WeakMap,Jt=new WeakSet,Oc=function(){const t=l(this,it).subarray(4,6),e=l(this,it).subarray(16,18),[s,i,n,r]=l(this,cs);return[(l(this,So)+(t[0]-e[0])/2-s)/n,(l(this,Co)+(t[1]-e[1])/2-i)/r,(l(this,So)+(e[0]-t[0])/2-s)/n,(l(this,Co)+(e[1]-t[1])/2-i)/r]},Xy=function(){const[t,e,s,i]=l(this,cs),[n,r,o,h]=w(this,Jt,Oc).call(this);return`M${(l(this,it)[2]-t)/s} ${(l(this,it)[3]-e)/i} L${(l(this,it)[4]-t)/s} ${(l(this,it)[5]-e)/i} L${n} ${r} L${o} ${h} L${(l(this,it)[16]-t)/s} ${(l(this,it)[17]-e)/i} L${(l(this,it)[14]-t)/s} ${(l(this,it)[15]-e)/i} Z`},Wy=function(t){const e=l(this,Ks);t.push(`L${e[4]} ${e[5]} Z`)},Uy=function(t){const[e,s,i,n]=l(this,cs),r=l(this,it).subarray(4,6),o=l(this,it).subarray(16,18),[h,c,u,d]=w(this,Jt,Oc).call(this);t.push(`L${(r[0]-e)/i} ${(r[1]-s)/n} L${h} ${c} L${u} ${d} L${(o[0]-e)/i} ${(o[1]-s)/n}`)},Yy=function(t){const e=l(this,it),[s,i,n,r]=l(this,cs),[o,h,c,u]=w(this,Jt,Oc).call(this),d=new Float32Array(36);return d.set([NaN,NaN,NaN,NaN,(e[2]-s)/n,(e[3]-i)/r,NaN,NaN,NaN,NaN,(e[4]-s)/n,(e[5]-i)/r,NaN,NaN,NaN,NaN,o,h,NaN,NaN,NaN,NaN,c,u,NaN,NaN,NaN,NaN,(e[16]-s)/n,(e[17]-i)/r,NaN,NaN,NaN,NaN,(e[14]-s)/n,(e[15]-i)/r],0),this.newFreeDrawOutline(d,t,l(this,cs),l(this,Ua),l(this,Xa),l(this,Wa))},$y=function(t,e){const s=l(this,Ks);return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6},qy=function(t,e){const s=l(this,it).subarray(4,6),i=l(this,it).subarray(16,18),[n,r,o,h]=l(this,cs),[c,u,d,f]=w(this,Jt,Oc).call(this);return t.set([NaN,NaN,NaN,NaN,(s[0]-n)/o,(s[1]-r)/h,NaN,NaN,NaN,NaN,c,u,NaN,NaN,NaN,NaN,d,f,NaN,NaN,NaN,NaN,(i[0]-n)/o,(i[1]-r)/h],e),e+=24},y(gn,oc,8),y(gn,wd,2),y(gn,xd,l(gn,oc)+l(gn,wd));let id=gn;class Nb extends B{constructor(e,s,i,n,r,o){super();y(this,Sd);y(this,$a);y(this,Ao,new Float32Array(4));y(this,pn);y(this,ac);y(this,us);y(this,hc);y(this,Ht);m(this,Ht,e),m(this,us,s),m(this,$a,i),m(this,hc,n),m(this,pn,r),m(this,ac,o),this.lastPoint=[NaN,NaN],w(this,Sd,Ky).call(this,o);const[h,c,u,d]=l(this,Ao);for(let f=0,g=e.length;f<g;f+=2)e[f]=(e[f]-h)/u,e[f+1]=(e[f+1]-c)/d;for(let f=0,g=s.length;f<g;f+=2)s[f]=(s[f]-h)/u,s[f+1]=(s[f+1]-c)/d}toSVGPath(){const e=[`M${l(this,Ht)[4]} ${l(this,Ht)[5]}`];for(let s=6,i=l(this,Ht).length;s<i;s+=6){if(isNaN(l(this,Ht)[s])){e.push(`L${l(this,Ht)[s+4]} ${l(this,Ht)[s+5]}`);continue}e.push(`C${l(this,Ht)[s]} ${l(this,Ht)[s+1]} ${l(this,Ht)[s+2]} ${l(this,Ht)[s+3]} ${l(this,Ht)[s+4]} ${l(this,Ht)[s+5]}`)}return e.push("Z"),e.join(" ")}serialize([e,s,i,n],r){const o=i-e,h=n-s;let c,u;switch(r){case 0:c=B._rescale(l(this,Ht),e,n,o,-h),u=B._rescale(l(this,us),e,n,o,-h);break;case 90:c=B._rescaleAndSwap(l(this,Ht),e,s,o,h),u=B._rescaleAndSwap(l(this,us),e,s,o,h);break;case 180:c=B._rescale(l(this,Ht),i,s,-o,h),u=B._rescale(l(this,us),i,s,-o,h);break;case 270:c=B._rescaleAndSwap(l(this,Ht),i,n,-o,-h),u=B._rescaleAndSwap(l(this,us),i,n,-o,-h);break}return{outline:Array.from(c),points:[Array.from(u)]}}get box(){return l(this,Ao)}newOutliner(e,s,i,n,r,o=0){return new id(e,s,i,n,r,o)}getNewOutline(e,s){const[i,n,r,o]=l(this,Ao),[h,c,u,d]=l(this,$a),f=r*u,g=o*d,p=i*u+h,b=n*d+c,v=this.newOutliner({x:l(this,us)[0]*f+p,y:l(this,us)[1]*g+b},l(this,$a),l(this,hc),e,l(this,ac),s??l(this,pn));for(let _=2;_<l(this,us).length;_+=2)v.add({x:l(this,us)[_]*f+p,y:l(this,us)[_+1]*g+b});return v.getOutlines()}}$a=new WeakMap,Ao=new WeakMap,pn=new WeakMap,ac=new WeakMap,us=new WeakMap,hc=new WeakMap,Ht=new WeakMap,Sd=new WeakSet,Ky=function(e){const s=l(this,Ht);let i=s[4],n=s[5],r=i,o=n,h=i,c=n,u=i,d=n;const f=e?Math.max:Math.min;for(let p=6,b=s.length;p<b;p+=6){if(isNaN(s[p]))r=Math.min(r,s[p+4]),o=Math.min(o,s[p+5]),h=Math.max(h,s[p+4]),c=Math.max(c,s[p+5]),d<s[p+5]?(u=s[p+4],d=s[p+5]):d===s[p+5]&&(u=f(u,s[p+4]));else{const v=X.bezierBoundingBox(i,n,...s.slice(p,p+6));r=Math.min(r,v[0]),o=Math.min(o,v[1]),h=Math.max(h,v[2]),c=Math.max(c,v[3]),d<v[3]?(u=v[2],d=v[3]):d===v[3]&&(u=f(u,v[2]))}i=s[p+4],n=s[p+5]}const g=l(this,Ao);g[0]=r-l(this,pn),g[1]=o-l(this,pn),g[2]=h-r+2*l(this,pn),g[3]=c-o+2*l(this,pn),this.lastPoint=[u,d]};class Lg{constructor(t,e=0,s=0,i=!0){y(this,Ie);y(this,lc);y(this,cc);y(this,ir,[]);y(this,Qs,[]);let n=1/0,r=-1/0,o=1/0,h=-1/0;const c=10**-4;for(const{x:v,y:_,width:x,height:C}of t){const S=Math.floor((v-e)/c)*c,k=Math.ceil((v+x+e)/c)*c,D=Math.floor((_-e)/c)*c,T=Math.ceil((_+C+e)/c)*c,M=[S,D,T,!0],O=[k,D,T,!1];l(this,ir).push(M,O),n=Math.min(n,S),r=Math.max(r,k),o=Math.min(o,D),h=Math.max(h,T)}const u=r-n+2*s,d=h-o+2*s,f=n-s,g=o-s,p=l(this,ir).at(i?-1:-2),b=[p[0],p[2]];for(const v of l(this,ir)){const[_,x,C]=v;v[0]=(_-f)/u,v[1]=(x-g)/d,v[2]=(C-g)/d}m(this,lc,new Float32Array([f,g,u,d])),m(this,cc,b)}getOutlines(){l(this,ir).sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);const t=[];for(const e of l(this,ir))e[3]?(t.push(...w(this,Ie,Ep).call(this,e)),w(this,Ie,Jy).call(this,e)):(w(this,Ie,Zy).call(this,e),t.push(...w(this,Ie,Ep).call(this,e)));return w(this,Ie,Qy).call(this,t)}}lc=new WeakMap,cc=new WeakMap,ir=new WeakMap,Qs=new WeakMap,Ie=new WeakSet,Qy=function(t){const e=[],s=new Set;for(const r of t){const[o,h,c]=r;e.push([o,h,r],[o,c,r])}e.sort((r,o)=>r[1]-o[1]||r[0]-o[0]);for(let r=0,o=e.length;r<o;r+=2){const h=e[r][2],c=e[r+1][2];h.push(c),c.push(h),s.add(h),s.add(c)}const i=[];let n;for(;s.size>0;){const r=s.values().next().value;let[o,h,c,u,d]=r;s.delete(r);let f=o,g=h;for(n=[o,c],i.push(n);;){let p;if(s.has(u))p=u;else if(s.has(d))p=d;else break;s.delete(p),[o,h,c,u,d]=p,f!==o&&(n.push(f,g,o,g===h?h:c),f=o),g=g===h?c:h}n.push(f,g)}return new zS(i,l(this,lc),l(this,cc))},Yd=function(t){const e=l(this,Qs);let s=0,i=e.length-1;for(;s<=i;){const n=s+i>>1,r=e[n][0];if(r===t)return n;r<t?s=n+1:i=n-1}return i+1},Jy=function([,t,e]){const s=w(this,Ie,Yd).call(this,t);l(this,Qs).splice(s,0,[t,e])},Zy=function([,t,e]){const s=w(this,Ie,Yd).call(this,t);for(let i=s;i<l(this,Qs).length;i++){const[n,r]=l(this,Qs)[i];if(n!==t)break;if(n===t&&r===e){l(this,Qs).splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=l(this,Qs)[i];if(n!==t)break;if(n===t&&r===e){l(this,Qs).splice(i,1);return}}},Ep=function(t){const[e,s,i]=t,n=[[e,s,i]],r=w(this,Ie,Yd).call(this,i);for(let o=0;o<r;o++){const[h,c]=l(this,Qs)[o];for(let u=0,d=n.length;u<d;u++){const[,f,g]=n[u];if(!(c<=f||g<=h)){if(f>=h){if(g>c)n[u][1]=c;else{if(d===1)return[];n.splice(u,1),u--,d--}continue}n[u][2]=h,g>c&&n.push([e,c,g])}}}return n};class zS extends B{constructor(e,s,i){super();y(this,uc);y(this,qa);m(this,qa,e),m(this,uc,s),this.lastPoint=i}toSVGPath(){const e=[];for(const s of l(this,qa)){let[i,n]=s;e.push(`M${i} ${n}`);for(let r=2;r<s.length;r+=2){const o=s[r],h=s[r+1];o===i?(e.push(`V${h}`),n=h):h===n&&(e.push(`H${o}`),i=o)}e.push("Z")}return e.join(" ")}serialize([e,s,i,n],r){const o=[],h=i-e,c=n-s;for(const u of l(this,qa)){const d=new Array(u.length);for(let f=0;f<u.length;f+=2)d[f]=e+u[f]*h,d[f+1]=n-u[f+1]*c;o.push(d)}return o}get box(){return l(this,uc)}get classNamesForOutlining(){return["highlightOutline"]}}uc=new WeakMap,qa=new WeakMap;class Fg extends id{newFreeDrawOutline(t,e,s,i,n,r){return new VS(t,e,s,i,n,r)}}class VS extends Nb{newOutliner(t,e,s,i,n,r=0){return new Fg(t,e,s,i,n,r)}}const Ke=class Ke{constructor({editor:t=null,uiManager:e=null}){y(this,yt);y(this,Js,null);y(this,To,null);y(this,Ka);y(this,Zt,null);y(this,dc,!1);y(this,Qa,!1);y(this,fc,null);y(this,gc);y(this,nr,null);y(this,Zs,null);y(this,Ja);var s;t?(m(this,Qa,!1),m(this,Ja,ot.HIGHLIGHT_COLOR),m(this,fc,t)):(m(this,Qa,!0),m(this,Ja,ot.HIGHLIGHT_DEFAULT_COLOR)),m(this,Zs,(t==null?void 0:t._uiManager)||e),m(this,gc,l(this,Zs)._eventBus),m(this,Ka,(t==null?void 0:t.color)||((s=l(this,Zs))==null?void 0:s.highlightColors.values().next().value)||"#FFFF98"),l(Ke,pc)||m(Ke,pc,Object.freeze({blue:"pdfjs-editor-colorpicker-blue",green:"pdfjs-editor-colorpicker-green",pink:"pdfjs-editor-colorpicker-pink",red:"pdfjs-editor-colorpicker-red",yellow:"pdfjs-editor-colorpicker-yellow"}))}static get _keyboardManager(){return st(this,"_keyboardManager",new Xh([[["Escape","mac+Escape"],Ke.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],Ke.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],Ke.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],Ke.prototype._moveToPrevious],[["Home","mac+Home"],Ke.prototype._moveToBeginning],[["End","mac+End"],Ke.prototype._moveToEnd]]))}renderButton(){const t=m(this,Js,document.createElement("button"));t.className="colorPicker",t.tabIndex="0",t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-button"),t.setAttribute("aria-haspopup",!0);const e=l(this,Zs)._signal;t.addEventListener("click",w(this,yt,Go).bind(this),{signal:e}),t.addEventListener("keydown",w(this,yt,Pp).bind(this),{signal:e});const s=m(this,To,document.createElement("span"));return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=l(this,Ka),t.append(s),t}renderMainDropdown(){const t=m(this,Zt,w(this,yt,kp).call(this));return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}_colorSelectFromKeyboard(t){if(t.target===l(this,Js)){w(this,yt,Go).call(this,t);return}const e=t.target.getAttribute("data-color");e&&w(this,yt,Mp).call(this,e,t)}_moveToNext(t){var e,s;if(!l(this,yt,gr)){w(this,yt,Go).call(this,t);return}if(t.target===l(this,Js)){(e=l(this,Zt).firstChild)==null||e.focus();return}(s=t.target.nextSibling)==null||s.focus()}_moveToPrevious(t){var e,s;if(t.target===((e=l(this,Zt))==null?void 0:e.firstChild)||t.target===l(this,Js)){l(this,yt,gr)&&this._hideDropdownFromKeyboard();return}l(this,yt,gr)||w(this,yt,Go).call(this,t),(s=t.target.previousSibling)==null||s.focus()}_moveToBeginning(t){var e;if(!l(this,yt,gr)){w(this,yt,Go).call(this,t);return}(e=l(this,Zt).firstChild)==null||e.focus()}_moveToEnd(t){var e;if(!l(this,yt,gr)){w(this,yt,Go).call(this,t);return}(e=l(this,Zt).lastChild)==null||e.focus()}hideDropdown(){var t,e;(t=l(this,Zt))==null||t.classList.add("hidden"),(e=l(this,nr))==null||e.abort(),m(this,nr,null)}_hideDropdownFromKeyboard(){var t;if(!l(this,Qa)){if(!l(this,yt,gr)){(t=l(this,fc))==null||t.unselect();return}this.hideDropdown(),l(this,Js).focus({preventScroll:!0,focusVisible:l(this,dc)})}}updateColor(t){if(l(this,To)&&(l(this,To).style.backgroundColor=t),!l(this,Zt))return;const e=l(this,Zs).highlightColors.values();for(const s of l(this,Zt).children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){var t,e;(t=l(this,Js))==null||t.remove(),m(this,Js,null),m(this,To,null),(e=l(this,Zt))==null||e.remove(),m(this,Zt,null)}};Js=new WeakMap,To=new WeakMap,Ka=new WeakMap,Zt=new WeakMap,dc=new WeakMap,Qa=new WeakMap,fc=new WeakMap,gc=new WeakMap,nr=new WeakMap,Zs=new WeakMap,Ja=new WeakMap,pc=new WeakMap,yt=new WeakSet,kp=function(){const t=document.createElement("div"),e=l(this,Zs)._signal;t.addEventListener("contextmenu",Gs,{signal:e}),t.className="dropdown",t.role="listbox",t.setAttribute("aria-multiselectable",!1),t.setAttribute("aria-orientation","vertical"),t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown");for(const[s,i]of l(this,Zs).highlightColors){const n=document.createElement("button");n.tabIndex="0",n.role="option",n.setAttribute("data-color",i),n.title=s,n.setAttribute("data-l10n-id",l(Ke,pc)[s]);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===l(this,Ka)),n.addEventListener("click",w(this,yt,Mp).bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",w(this,yt,Pp).bind(this),{signal:e}),t},Mp=function(t,e){e.stopPropagation(),l(this,gc).dispatch("switchannotationeditorparams",{source:this,type:l(this,Ja),value:t})},Pp=function(t){Ke._keyboardManager.exec(this,t)},Go=function(t){if(l(this,yt,gr)){this.hideDropdown();return}if(m(this,dc,t.detail===0),l(this,nr)||(m(this,nr,new AbortController),window.addEventListener("pointerdown",w(this,yt,tv).bind(this),{signal:l(this,Zs).combinedSignal(l(this,nr))})),l(this,Zt)){l(this,Zt).classList.remove("hidden");return}const e=m(this,Zt,w(this,yt,kp).call(this));l(this,Js).append(e)},tv=function(t){var e;(e=l(this,Zt))!=null&&e.contains(t.target)||this.hideDropdown()},gr=function(){return l(this,Zt)&&!l(this,Zt).classList.contains("hidden")},y(Ke,pc,null);let nd=Ke;const ut=class ut extends Pt{constructor(e){super({...e,name:"highlightEditor"});y(this,J);y(this,Za,null);y(this,mc,0);y(this,mn);y(this,Eo,null);y(this,th,null);y(this,Qe,null);y(this,bc,null);y(this,yc,0);y(this,ko,null);y(this,Ts,null);y(this,ds,null);y(this,le,!1);y(this,eh,null);y(this,bn);y(this,Se,null);y(this,sh,"");y(this,Es);y(this,vc,"");this.color=e.color||ut._defaultColor,m(this,Es,e.thickness||ut._defaultThickness),m(this,bn,e.opacity||ut._defaultOpacity),m(this,mn,e.boxes||null),m(this,vc,e.methodOfCreation||""),m(this,sh,e.text||""),this._isDraggable=!1,e.highlightId>-1?(m(this,le,!0),w(this,J,$d).call(this,e),w(this,J,zo).call(this)):l(this,mn)&&(m(this,Za,e.anchorNode),m(this,mc,e.anchorOffset),m(this,bc,e.focusNode),m(this,yc,e.focusOffset),w(this,J,Dp).call(this),w(this,J,zo).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const e=ut.prototype;return st(this,"_keyboardManager",new Xh([[["ArrowLeft","mac+ArrowLeft"],e._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],e._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],e._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],e._moveCaret,{args:[3]}]]))}get telemetryInitialData(){return{action:"added",type:l(this,le)?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:l(this,Es),methodOfCreation:l(this,vc)}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.highlightColorNames.get(this.color)}}static computeTelemetryFinalData(e){return{numberOfColors:e.get("color").size}}static initialize(e,s){var i;Pt.initialize(e,s),ut._defaultColor||(ut._defaultColor=((i=s.highlightColors)==null?void 0:i.values().next().value)||"#fff066")}static updateDefaultParams(e,s){switch(e){case ot.HIGHLIGHT_DEFAULT_COLOR:ut._defaultColor=s;break;case ot.HIGHLIGHT_THICKNESS:ut._defaultThickness=s;break}}translateInPage(e,s){}get toolbarPosition(){return l(this,eh)}updateParams(e,s){switch(e){case ot.HIGHLIGHT_COLOR:w(this,J,ev).call(this,s);break;case ot.HIGHLIGHT_THICKNESS:w(this,J,sv).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[ot.HIGHLIGHT_DEFAULT_COLOR,ut._defaultColor],[ot.HIGHLIGHT_THICKNESS,ut._defaultThickness]]}get propertiesToUpdate(){return[[ot.HIGHLIGHT_COLOR,this.color||ut._defaultColor],[ot.HIGHLIGHT_THICKNESS,l(this,Es)||ut._defaultThickness],[ot.HIGHLIGHT_FREE,l(this,le)]]}async addEditToolbar(){const e=await super.addEditToolbar();return e?(this._uiManager.highlightColors&&(m(this,th,new nd({editor:this})),e.addColorPicker(l(this,th))),e):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(w(this,J,Rc).call(this))}getBaseTranslation(){return[0,0]}getRect(e,s){return super.getRect(e,s,w(this,J,Rc).call(this))}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),e&&this.div.focus()}remove(){w(this,J,Op).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,J,zo).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?w(this,J,Op).call(this):e&&(w(this,J,zo).call(this,e),s=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),this.show(this._isVisible),s&&this.select()}rotate(e){var n,r,o;const{drawLayer:s}=this.parent;let i;l(this,le)?(e=(e-this.rotation+360)%360,i=w(n=ut,ks,_h).call(n,l(this,Ts).box,e)):i=w(r=ut,ks,_h).call(r,[this.x,this.y,this.width,this.height],e),s.updateProperties(l(this,ds),{bbox:i,root:{"data-main-rotation":e}}),s.updateProperties(l(this,Se),{bbox:w(o=ut,ks,_h).call(o,l(this,Qe).box,e),root:{"data-main-rotation":e}})}render(){if(this.div)return this.div;const e=super.render();l(this,sh)&&(e.setAttribute("aria-label",l(this,sh)),e.setAttribute("role","mark")),l(this,le)?e.classList.add("free"):this.div.addEventListener("keydown",w(this,J,nv).bind(this),{signal:this._uiManager._signal});const s=m(this,ko,document.createElement("div"));e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",s.style.clipPath=l(this,Eo);const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),$u(this,l(this,ko),["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Se),{rootClass:{hovered:!0}})}pointerleave(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Se),{rootClass:{hovered:!1}})}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:w(this,J,qd).call(this,!0);break;case 1:case 3:w(this,J,qd).call(this,!1);break}}select(){var e;super.select(),l(this,Se)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Se),{rootClass:{hovered:!1,selected:!0}}))}unselect(){var e;super.unselect(),l(this,Se)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Se),{rootClass:{selected:!1}}),l(this,le)||w(this,J,qd).call(this,!1))}get _mustFixPosition(){return!l(this,le)}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.updateProperties(l(this,ds),{rootClass:{hidden:!e}}),this.parent.drawLayer.updateProperties(l(this,Se),{rootClass:{hidden:!e}}))}static startHighlighting(e,s,{target:i,x:n,y:r}){const{x:o,y:h,width:c,height:u}=i.getBoundingClientRect(),d=new AbortController,f=e.combinedSignal(d),g=p=>{d.abort(),w(this,ks,hv).call(this,e,p)};window.addEventListener("blur",g,{signal:f}),window.addEventListener("pointerup",g,{signal:f}),window.addEventListener("pointerdown",es,{capture:!0,passive:!1,signal:f}),window.addEventListener("contextmenu",Gs,{signal:f}),i.addEventListener("pointermove",w(this,ks,av).bind(this,e),{signal:f}),this._freeHighlight=new Fg({x:n,y:r},[o,h,c,u],e.scale,this._defaultThickness/2,s,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0)}static async deserialize(e,s,i){var b,v,_,x;let n=null;if(e instanceof Fb){const{data:{quadPoints:C,rect:S,rotation:k,id:D,color:T,opacity:M,popupRef:O},parent:{page:{pageNumber:R}}}=e;n=e={annotationType:Z.HIGHLIGHT,color:Array.from(T),opacity:M,quadPoints:C,boxes:null,pageIndex:R-1,rect:S.slice(0),rotation:k,id:D,deleted:!1,popupRef:O}}else if(e instanceof Og){const{data:{inkLists:C,rect:S,rotation:k,id:D,color:T,borderStyle:{rawWidth:M},popupRef:O},parent:{page:{pageNumber:R}}}=e;n=e={annotationType:Z.HIGHLIGHT,color:Array.from(T),thickness:M,inkLists:C,boxes:null,pageIndex:R-1,rect:S.slice(0),rotation:k,id:D,deleted:!1,popupRef:O}}const{color:r,quadPoints:o,inkLists:h,opacity:c}=e,u=await super.deserialize(e,s,i);u.color=X.makeHexColor(...r),m(u,bn,c||1),h&&m(u,Es,e.thickness),u.annotationElementId=e.id||null,u._initialData=n;const[d,f]=u.pageDimensions,[g,p]=u.pageTranslation;if(o){const C=m(u,mn,[]);for(let S=0;S<o.length;S+=8)C.push({x:(o[S]-g)/d,y:1-(o[S+1]-p)/f,width:(o[S+2]-o[S])/d,height:(o[S+1]-o[S+5])/f});w(b=u,J,Dp).call(b),w(v=u,J,zo).call(v),u.rotate(u.rotation)}else if(h){m(u,le,!0);const C=h[0],S={x:C[0]-g,y:f-(C[1]-p)},k=new Fg(S,[0,0,d,f],1,l(u,Es)/2,!0,.001);for(let M=0,O=C.length;M<O;M+=2)S.x=C[M]-g,S.y=f-(C[M+1]-p),k.add(S);const{id:D,clipPathId:T}=s.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:u.color,"fill-opacity":u._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:k.toSVGPath()}},!0,!0);w(_=u,J,$d).call(_,{highlightOutlines:k.getOutlines(),highlightId:D,clipPathId:T}),w(x=u,J,zo).call(x)}return u}serialize(e=!1){if(this.isEmpty()||e)return null;if(this.deleted)return this.serializeDeleted();const s=this.getRect(0,0),i=Pt._colorManager.convert(this.color),n={annotationType:Z.HIGHLIGHT,color:i,opacity:l(this,bn),thickness:l(this,Es),quadPoints:w(this,J,rv).call(this),outlines:w(this,J,ov).call(this,s),pageIndex:this.pageIndex,rect:s,rotation:w(this,J,Rc).call(this),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!w(this,J,lv).call(this,n)?null:(n.id=this.annotationElementId,n)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};Za=new WeakMap,mc=new WeakMap,mn=new WeakMap,Eo=new WeakMap,th=new WeakMap,Qe=new WeakMap,bc=new WeakMap,yc=new WeakMap,ko=new WeakMap,Ts=new WeakMap,ds=new WeakMap,le=new WeakMap,eh=new WeakMap,bn=new WeakMap,Se=new WeakMap,sh=new WeakMap,Es=new WeakMap,vc=new WeakMap,J=new WeakSet,Dp=function(){const e=new Lg(l(this,mn),.001);m(this,Ts,e.getOutlines()),[this.x,this.y,this.width,this.height]=l(this,Ts).box;const s=new Lg(l(this,mn),.0025,.001,this._uiManager.direction==="ltr");m(this,Qe,s.getOutlines());const{lastPoint:i}=l(this,Qe);m(this,eh,[(i[0]-this.x)/this.width,(i[1]-this.y)/this.height])},$d=function({highlightOutlines:e,highlightId:s,clipPathId:i}){var d,f;if(m(this,Ts,e),m(this,Qe,e.getNewOutline(l(this,Es)/2+1.5,.0025)),s>=0)m(this,ds,s),m(this,Eo,i),this.parent.drawLayer.finalizeDraw(s,{bbox:e.box,path:{d:e.toSVGPath()}}),m(this,Se,this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:l(this,Qe).box,path:{d:l(this,Qe).toSVGPath()}},!0));else if(this.parent){const g=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(l(this,ds),{bbox:w(d=ut,ks,_h).call(d,l(this,Ts).box,(g-this.rotation+360)%360),path:{d:e.toSVGPath()}}),this.parent.drawLayer.updateProperties(l(this,Se),{bbox:w(f=ut,ks,_h).call(f,l(this,Qe).box,g),path:{d:l(this,Qe).toSVGPath()}})}const[r,o,h,c]=e.box;switch(this.rotation){case 0:this.x=r,this.y=o,this.width=h,this.height=c;break;case 90:{const[g,p]=this.parentDimensions;this.x=o,this.y=1-r,this.width=h*p/g,this.height=c*g/p;break}case 180:this.x=1-r,this.y=1-o,this.width=h,this.height=c;break;case 270:{const[g,p]=this.parentDimensions;this.x=1-o,this.y=r,this.width=h*p/g,this.height=c*g/p;break}}const{lastPoint:u}=l(this,Qe);m(this,eh,[(u[0]-r)/h,(u[1]-o)/c])},ev=function(e){const s=(r,o)=>{var h,c;this.color=r,m(this,bn,o),(h=this.parent)==null||h.drawLayer.updateProperties(l(this,ds),{root:{fill:r,"fill-opacity":o}}),(c=l(this,th))==null||c.updateColor(r)},i=this.color,n=l(this,bn);this.addCommands({cmd:s.bind(this,e,ut._defaultOpacity),undo:s.bind(this,i,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:ot.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(e)},!0)},sv=function(e){const s=l(this,Es),i=n=>{m(this,Es,n),w(this,J,iv).call(this,n)};this.addCommands({cmd:i.bind(this,e),undo:i.bind(this,s),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:ot.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)},iv=function(e){if(!l(this,le))return;w(this,J,$d).call(this,{highlightOutlines:l(this,Ts).getNewOutline(e/2)}),this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)},Op=function(){l(this,ds)===null||!this.parent||(this.parent.drawLayer.remove(l(this,ds)),m(this,ds,null),this.parent.drawLayer.remove(l(this,Se)),m(this,Se,null))},zo=function(e=this.parent){l(this,ds)===null&&({id:Ge(this,ds)._,clipPathId:Ge(this,Eo)._}=e.drawLayer.draw({bbox:l(this,Ts).box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":l(this,bn)},rootClass:{highlight:!0,free:l(this,le)},path:{d:l(this,Ts).toSVGPath()}},!1,!0),m(this,Se,e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:l(this,le)},bbox:l(this,Qe).box,path:{d:l(this,Qe).toSVGPath()}},l(this,le))),l(this,ko)&&(l(this,ko).style.clipPath=l(this,Eo)))},ks=new WeakSet,_h=function([e,s,i,n],r){switch(r){case 90:return[1-s-n,e,n,i];case 180:return[1-e-i,1-s-n,i,n];case 270:return[s,1-e-i,n,i]}return[e,s,i,n]},nv=function(e){ut._keyboardManager.exec(this,e)},qd=function(e){if(!l(this,Za))return;const s=window.getSelection();e?s.setPosition(l(this,Za),l(this,mc)):s.setPosition(l(this,bc),l(this,yc))},Rc=function(){return l(this,le)?this.rotation:0},rv=function(){if(l(this,le))return null;const[e,s]=this.pageDimensions,[i,n]=this.pageTranslation,r=l(this,mn),o=new Float32Array(r.length*8);let h=0;for(const{x:c,y:u,width:d,height:f}of r){const g=c*e+i,p=(1-u)*s+n;o[h]=o[h+4]=g,o[h+1]=o[h+3]=p,o[h+2]=o[h+6]=g+d*e,o[h+5]=o[h+7]=p-f*s,h+=8}return o},ov=function(e){return l(this,Ts).serialize(e,w(this,J,Rc).call(this))},av=function(e,s){this._freeHighlight.add(s)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})},hv=function(e,s){this._freeHighlight.isEmpty()?e.drawLayer.remove(this._freeHighlightId):e.createAndAddNewEditor(s,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:"main_toolbar"}),this._freeHighlightId=-1,this._freeHighlight=null,this._freeHighlightClipId=""},lv=function(e){const{color:s}=this._initialData;return e.color.some((i,n)=>i!==s[n])},y(ut,ks),$(ut,"_defaultColor",null),$(ut,"_defaultOpacity",1),$(ut,"_defaultThickness",12),$(ut,"_type","highlight"),$(ut,"_editorType",Z.HIGHLIGHT),$(ut,"_freeHighlightId",-1),$(ut,"_freeHighlight",null),$(ut,"_freeHighlightClipId","");let rd=ut;class XS{constructor(){y(this,Mo,Object.create(null))}updateProperty(t,e){this[t]=e,this.updateSVGProperty(t,e)}updateProperties(t){if(t)for(const[e,s]of Object.entries(t))this.updateProperty(e,s)}updateSVGProperty(t,e){l(this,Mo)[t]=e}toSVGProperties(){const t=l(this,Mo);return m(this,Mo,Object.create(null)),{root:t}}reset(){m(this,Mo,Object.create(null))}updateAll(t=this){this.updateProperties(t)}clone(){vt("Not implemented")}}Mo=new WeakMap;const H=class H extends Pt{constructor(e){super(e);y(this,lt);y(this,fs,null);y(this,ih);$(this,"_drawId",null);m(this,ih,e.mustBeCommitted||!1),e.drawOutlines&&(w(this,lt,Rp).call(this,e),w(this,lt,Lc).call(this))}static _mergeSVGProperties(e,s){const i=new Set(Object.keys(e));for(const[n,r]of Object.entries(s))i.has(n)?Object.assign(e[n],r):e[n]=r;return e}static getDefaultDrawingOptions(e){vt("Not implemented")}static get typesMap(){vt("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(e,s){const i=this.typesMap.get(e);i&&this._defaultDrawingOptions.updateProperty(i,s),this._currentParent&&(l(H,ne).updateProperty(i,s),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(e,s){const i=this.constructor.typesMap.get(e);i&&this._updateProperty(e,i,s)}static get defaultPropertiesToUpdate(){const e=[],s=this._defaultDrawingOptions;for(const[i,n]of this.typesMap)e.push([i,s[n]]);return e}get propertiesToUpdate(){const e=[],{_drawingOptions:s}=this;for(const[i,n]of this.constructor.typesMap)e.push([i,s[n]]);return e}_updateProperty(e,s,i){const n=this._drawingOptions,r=n[s],o=h=>{var u;n.updateProperty(s,h);const c=l(this,fs).updateProperty(s,h);c&&w(this,lt,Fc).call(this,c),(u=this.parent)==null||u.drawLayer.updateProperties(this._drawId,n.toSVGProperties())};this.addCommands({cmd:o.bind(this,i),undo:o.bind(this,r),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:e,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,H._mergeSVGProperties(l(this,fs).getPathResizingSVGProperties(w(this,lt,Kd).call(this)),{bbox:w(this,lt,wh).call(this)}))}_onResized(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,H._mergeSVGProperties(l(this,fs).getPathResizedSVGProperties(w(this,lt,Kd).call(this)),{bbox:w(this,lt,wh).call(this)}))}_onTranslating(e,s){var i;(i=this.parent)==null||i.drawLayer.updateProperties(this._drawId,{bbox:w(this,lt,wh).call(this,e,s)})}_onTranslated(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,H._mergeSVGProperties(l(this,fs).getPathTranslatedSVGProperties(w(this,lt,Kd).call(this),this.parentDimensions),{bbox:w(this,lt,wh).call(this)}))}_onStartDragging(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}commit(){super.commit(),this.disableEditMode(),this.disableEditing()}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),this._isDraggable=!0,l(this,ih)&&(m(this,ih,!1),this.commit(),this.parent.setSelected(this),e&&this.isOnScreen&&this.div.focus())}remove(){w(this,lt,Fp).call(this),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,lt,Lc).call(this),w(this,lt,Fc).call(this,l(this,fs).box),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?(this._uiManager.removeShouldRescale(this),w(this,lt,Fp).call(this)):e&&(this._uiManager.addShouldRescale(this),w(this,lt,Lc).call(this,e),s=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),s&&this.select()}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,H._mergeSVGProperties({bbox:w(this,lt,wh).call(this)},l(this,fs).updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&w(this,lt,Fc).call(this,l(this,fs).updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;const e=super.render();e.classList.add("draw");const s=document.createElement("div");e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal";const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),this._uiManager.addShouldRescale(this),this.disableEditing(),e}static createDrawerInstance(e,s,i,n,r){vt("Not implemented")}static startDrawing(e,s,i,n){var v;const{target:r,offsetX:o,offsetY:h,pointerId:c,pointerType:u}=n;if(l(H,or)&&l(H,or)!==u)return;const{viewport:{rotation:d}}=e,{width:f,height:g}=r.getBoundingClientRect(),p=m(H,Po,new AbortController),b=e.combinedSignal(p);if(l(H,rr)||m(H,rr,c),l(H,or)??m(H,or,u),window.addEventListener("pointerup",_=>{var x;l(H,rr)===_.pointerId?this._endDraw(_):(x=l(H,ar))==null||x.delete(_.pointerId)},{signal:b}),window.addEventListener("pointercancel",_=>{var x;l(H,rr)===_.pointerId?this._currentParent.endDrawingSession():(x=l(H,ar))==null||x.delete(_.pointerId)},{signal:b}),window.addEventListener("pointerdown",_=>{l(H,or)===_.pointerType&&((l(H,ar)||m(H,ar,new Set)).add(_.pointerId),l(H,ne).isCancellable()&&(l(H,ne).removeLastElement(),l(H,ne).isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:b}),window.addEventListener("contextmenu",Gs,{signal:b}),r.addEventListener("pointermove",this._drawMove.bind(this),{signal:b}),r.addEventListener("touchmove",_=>{_.timeStamp===l(H,Oo)&&es(_)},{signal:b}),e.toggleDrawing(),(v=s._editorUndoBar)==null||v.hide(),l(H,ne)){e.drawLayer.updateProperties(this._currentDrawId,l(H,ne).startNew(o,h,f,g,d));return}s.updateUIForDefaultProperties(this),m(H,ne,this.createDrawerInstance(o,h,f,g,d)),m(H,Do,this.getDefaultDrawingOptions()),this._currentParent=e,{id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties(l(H,Do).toSVGProperties(),l(H,ne).defaultSVGProperties),!0,!1)}static _drawMove(e){var r;if(m(H,Oo,-1),!l(H,ne))return;const{offsetX:s,offsetY:i,pointerId:n}=e;if(l(H,rr)===n){if(((r=l(H,ar))==null?void 0:r.size)>=1){this._endDraw(e);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,l(H,ne).add(s,i)),m(H,Oo,e.timeStamp),es(e)}}static _cleanup(e){e&&(this._currentDrawId=-1,this._currentParent=null,m(H,ne,null),m(H,Do,null),m(H,or,null),m(H,Oo,NaN)),l(H,Po)&&(l(H,Po).abort(),m(H,Po,null),m(H,rr,NaN),m(H,ar,null))}static _endDraw(e){const s=this._currentParent;if(s){if(s.toggleDrawing(!0),this._cleanup(!1),e&&s.drawLayer.updateProperties(this._currentDrawId,l(H,ne).end(e.offsetX,e.offsetY)),this.supportMultipleDrawings){const i=l(H,ne),n=this._currentDrawId,r=i.getLastElement();s.addCommands({cmd:()=>{s.drawLayer.updateProperties(n,i.setLastElement(r))},undo:()=>{s.drawLayer.updateProperties(n,i.removeLastElement())},mustExec:!1,type:ot.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(e){const s=this._currentParent;if(!s)return null;if(s.toggleDrawing(!0),s.cleanUndoStack(ot.DRAW_STEP),!l(H,ne).isEmpty()){const{pageDimensions:[i,n],scale:r}=s,o=s.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:l(H,ne).getOutlines(i*r,n*r,r,this._INNER_MARGIN),drawingOptions:l(H,Do),mustBeCommitted:!e});return this._cleanup(!0),o}return s.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(e){}static deserializeDraw(e,s,i,n,r,o){vt("Not implemented")}static async deserialize(e,s,i){var d,f;const{rawDims:{pageWidth:n,pageHeight:r,pageX:o,pageY:h}}=s.viewport,c=this.deserializeDraw(o,h,n,r,this._INNER_MARGIN,e),u=await super.deserialize(e,s,i);return u.createDrawingOptions(e),w(d=u,lt,Rp).call(d,{drawOutlines:c}),w(f=u,lt,Lc).call(f),u.onScaleChanging(),u.rotate(),u}serializeDraw(e){const[s,i]=this.pageTranslation,[n,r]=this.pageDimensions;return l(this,fs).serialize([s,i,n,r],e)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};fs=new WeakMap,ih=new WeakMap,ne=new WeakMap,Po=new WeakMap,Do=new WeakMap,rr=new WeakMap,or=new WeakMap,ar=new WeakMap,Oo=new WeakMap,lt=new WeakSet,Rp=function({drawOutlines:e,drawId:s,drawingOptions:i}){m(this,fs,e),this._drawingOptions||(this._drawingOptions=i),s>=0?(this._drawId=s,this.parent.drawLayer.finalizeDraw(s,e.defaultProperties)):this._drawId=w(this,lt,Lp).call(this,e,this.parent),w(this,lt,Fc).call(this,e.box)},Lp=function(e,s){const{id:i}=s.drawLayer.draw(H._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return i},Fp=function(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())},Lc=function(e=this.parent){if(!(this._drawId!==null&&this.parent===e)){if(this._drawId!==null){this.parent.drawLayer.updateParent(this._drawId,e.drawLayer);return}this._drawingOptions.updateAll(),this._drawId=w(this,lt,Lp).call(this,l(this,fs),e)}},cv=function([e,s,i,n]){const{parentDimensions:[r,o],rotation:h}=this;switch(h){case 90:return[s,1-e,i*(o/r),n*(r/o)];case 180:return[1-e,1-s,i,n];case 270:return[1-s,e,i*(o/r),n*(r/o)];default:return[e,s,i,n]}},Kd=function(){const{x:e,y:s,width:i,height:n,parentDimensions:[r,o],rotation:h}=this;switch(h){case 90:return[1-s,e,i*(r/o),n*(o/r)];case 180:return[1-e,1-s,i,n];case 270:return[s,1-e,i*(r/o),n*(o/r)];default:return[e,s,i,n]}},Fc=function(e){if([this.x,this.y,this.width,this.height]=w(this,lt,cv).call(this,e),this.div){this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)}this._onResized()},wh=function(){const{x:e,y:s,width:i,height:n,rotation:r,parentRotation:o,parentDimensions:[h,c]}=this;switch((r*4+o)/90){case 1:return[1-s-n,e,n,i];case 2:return[1-e-i,1-s-n,i,n];case 3:return[s,1-e-i,n,i];case 4:return[e,s-i*(h/c),n*(c/h),i*(h/c)];case 5:return[1-s,e,i*(h/c),n*(c/h)];case 6:return[1-e-n*(c/h),1-s,n*(c/h),i*(h/c)];case 7:return[s-i*(h/c),1-e-n*(c/h),i*(h/c),n*(c/h)];case 8:return[e-i,s-n,i,n];case 9:return[1-s,e-i,n,i];case 10:return[1-e,1-s,i,n];case 11:return[s-n,1-e,n,i];case 12:return[e-n*(c/h),s,n*(c/h),i*(h/c)];case 13:return[1-s-i*(h/c),e-n*(c/h),i*(h/c),n*(c/h)];case 14:return[1-e,1-s-i*(h/c),n*(c/h),i*(h/c)];case 15:return[s,1-e,i*(h/c),n*(c/h)];default:return[e,s,i,n]}},$(H,"_currentDrawId",-1),$(H,"_currentParent",null),y(H,ne,null),y(H,Po,null),y(H,Do,null),y(H,rr,NaN),y(H,or,null),y(H,ar,null),y(H,Oo,NaN),$(H,"_INNER_MARGIN",3);let Ig=H;class WS{constructor(t,e,s,i,n,r){y(this,rh);y(this,xi,new Float64Array(6));y(this,re);y(this,oe);y(this,Ro);y(this,nh);y(this,Ne);y(this,ce,"");y(this,Ms,0);y(this,Lo,new od);y(this,Fo);y(this,Io);m(this,Fo,s),m(this,Io,i),m(this,Ro,n),m(this,nh,r),[t,e]=w(this,rh,Qd).call(this,t,e);const o=m(this,re,[NaN,NaN,NaN,NaN,t,e]);m(this,Ne,[t,e]),m(this,oe,[{line:o,points:l(this,Ne)}]),l(this,xi).set(o,0)}updateProperty(t,e){t==="stroke-width"&&m(this,nh,e)}isEmpty(){return!l(this,oe)||l(this,oe).length===0}isCancellable(){return l(this,Ne).length<=10}add(t,e){[t,e]=w(this,rh,Qd).call(this,t,e);const[s,i,n,r]=l(this,xi).subarray(2,6),o=t-n,h=e-r;return Math.hypot(l(this,Fo)*o,l(this,Io)*h)<=2?null:(l(this,Ne).push(t,e),isNaN(s)?(l(this,xi).set([n,r,t,e],2),l(this,re).push(NaN,NaN,NaN,NaN,t,e),{path:{d:this.toSVGPath()}}):(isNaN(l(this,xi)[0])&&l(this,re).splice(6,6),l(this,xi).set([s,i,n,r,t,e],0),l(this,re).push(...B.createBezierPoints(s,i,n,r,t,e)),{path:{d:this.toSVGPath()}}))}end(t,e){const s=this.add(t,e);return s||(l(this,Ne).length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,s,i,n){m(this,Fo,s),m(this,Io,i),m(this,Ro,n),[t,e]=w(this,rh,Qd).call(this,t,e);const r=m(this,re,[NaN,NaN,NaN,NaN,t,e]);m(this,Ne,[t,e]);const o=l(this,oe).at(-1);return o&&(o.line=new Float32Array(o.line),o.points=new Float32Array(o.points)),l(this,oe).push({line:r,points:l(this,Ne)}),l(this,xi).set(r,0),m(this,Ms,0),this.toSVGPath(),null}getLastElement(){return l(this,oe).at(-1)}setLastElement(t){return l(this,oe)?(l(this,oe).push(t),m(this,re,t.line),m(this,Ne,t.points),m(this,Ms,0),{path:{d:this.toSVGPath()}}):l(this,Lo).setLastElement(t)}removeLastElement(){if(!l(this,oe))return l(this,Lo).removeLastElement();l(this,oe).pop(),m(this,ce,"");for(let t=0,e=l(this,oe).length;t<e;t++){const{line:s,points:i}=l(this,oe)[t];m(this,re,s),m(this,Ne,i),m(this,Ms,0),this.toSVGPath()}return{path:{d:l(this,ce)}}}toSVGPath(){const t=B.svgRound(l(this,re)[4]),e=B.svgRound(l(this,re)[5]);if(l(this,Ne).length===2)return m(this,ce,`${l(this,ce)} M ${t} ${e} Z`),l(this,ce);if(l(this,Ne).length<=6){const i=l(this,ce).lastIndexOf("M");m(this,ce,`${l(this,ce).slice(0,i)} M ${t} ${e}`),m(this,Ms,6)}if(l(this,Ne).length===4){const i=B.svgRound(l(this,re)[10]),n=B.svgRound(l(this,re)[11]);return m(this,ce,`${l(this,ce)} L ${i} ${n}`),m(this,Ms,12),l(this,ce)}const s=[];l(this,Ms)===0&&(s.push(`M ${t} ${e}`),m(this,Ms,6));for(let i=l(this,Ms),n=l(this,re).length;i<n;i+=6){const[r,o,h,c,u,d]=l(this,re).slice(i,i+6).map(B.svgRound);s.push(`C${r} ${o} ${h} ${c} ${u} ${d}`)}return m(this,ce,l(this,ce)+s.join(" ")),m(this,Ms,l(this,re).length),l(this,ce)}getOutlines(t,e,s,i){const n=l(this,oe).at(-1);return n.line=new Float32Array(n.line),n.points=new Float32Array(n.points),l(this,Lo).build(l(this,oe),t,e,s,l(this,Ro),l(this,nh),i),m(this,xi,null),m(this,re,null),m(this,oe,null),m(this,ce,null),l(this,Lo)}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}xi=new WeakMap,re=new WeakMap,oe=new WeakMap,Ro=new WeakMap,nh=new WeakMap,Ne=new WeakMap,ce=new WeakMap,Ms=new WeakMap,Lo=new WeakMap,Fo=new WeakMap,Io=new WeakMap,rh=new WeakSet,Qd=function(t,e){return B._normalizePoint(t,e,l(this,Fo),l(this,Io),l(this,Ro))};const Ug=class Ug extends B{constructor(){super(...arguments);y(this,ue);y(this,je);y(this,_c,0);y(this,wc);y(this,gs);y(this,Si);y(this,Ci);y(this,oh);y(this,ah);y(this,hh)}build(e,s,i,n,r,o,h){m(this,Si,s),m(this,Ci,i),m(this,oh,n),m(this,ah,r),m(this,hh,o),m(this,wc,h??0),m(this,gs,e),w(this,ue,dv).call(this)}setLastElement(e){return l(this,gs).push(e),{path:{d:this.toSVGPath()}}}removeLastElement(){return l(this,gs).pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const e=[];for(const{line:s}of l(this,gs)){if(e.push(`M${B.svgRound(s[4])} ${B.svgRound(s[5])}`),s.length===6){e.push("Z");continue}if(s.length===12){e.push(`L${B.svgRound(s[10])} ${B.svgRound(s[11])}`);continue}for(let i=6,n=s.length;i<n;i+=6){const[r,o,h,c,u,d]=s.subarray(i,i+6).map(B.svgRound);e.push(`C${r} ${o} ${h} ${c} ${u} ${d}`)}}return e.join("")}serialize([e,s,i,n],r){const o=[],h=[],[c,u,d,f]=w(this,ue,uv).call(this);let g,p,b,v,_,x,C,S,k;switch(l(this,ah)){case 0:k=B._rescale,g=e,p=s+n,b=i,v=-n,_=e+c*i,x=s+(1-u-f)*n,C=e+(c+d)*i,S=s+(1-u)*n;break;case 90:k=B._rescaleAndSwap,g=e,p=s,b=i,v=n,_=e+u*i,x=s+c*n,C=e+(u+f)*i,S=s+(c+d)*n;break;case 180:k=B._rescale,g=e+i,p=s,b=-i,v=n,_=e+(1-c-d)*i,x=s+u*n,C=e+(1-c)*i,S=s+(u+f)*n;break;case 270:k=B._rescaleAndSwap,g=e+i,p=s+n,b=-i,v=-n,_=e+(1-u-f)*i,x=s+(1-c-d)*n,C=e+(1-u)*i,S=s+(1-c)*n;break}for(const{line:D,points:T}of l(this,gs))o.push(k(D,g,p,b,v,r?new Array(D.length):null)),h.push(k(T,g,p,b,v,r?new Array(T.length):null));return{lines:o,points:h,rect:[_,x,C,S]}}static deserialize(e,s,i,n,r,{paths:{lines:o,points:h},rotation:c,thickness:u}){const d=[];let f,g,p,b,v;switch(c){case 0:v=B._rescale,f=-e/i,g=s/n+1,p=1/i,b=-1/n;break;case 90:v=B._rescaleAndSwap,f=-s/n,g=-e/i,p=1/n,b=1/i;break;case 180:v=B._rescale,f=e/i+1,g=-s/n,p=-1/i,b=1/n;break;case 270:v=B._rescaleAndSwap,f=s/n+1,g=e/i+1,p=-1/n,b=-1/i;break}if(!o){o=[];for(const x of h){const C=x.length;if(C===2){o.push(new Float32Array([NaN,NaN,NaN,NaN,x[0],x[1]]));continue}if(C===4){o.push(new Float32Array([NaN,NaN,NaN,NaN,x[0],x[1],NaN,NaN,NaN,NaN,x[2],x[3]]));continue}const S=new Float32Array(3*(C-2));o.push(S);let[k,D,T,M]=x.subarray(0,4);S.set([NaN,NaN,NaN,NaN,k,D],0);for(let O=4;O<C;O+=2){const R=x[O],L=x[O+1];S.set(B.createBezierPoints(k,D,T,M,R,L),(O-2)*3),[k,D,T,M]=[T,M,R,L]}}}for(let x=0,C=o.length;x<C;x++)d.push({line:v(o[x].map(S=>S??NaN),f,g,p,b),points:v(h[x].map(S=>S??NaN),f,g,p,b)});const _=new Ug;return _.build(d,i,n,1,c,u,r),_}get box(){return l(this,je)}updateProperty(e,s){return e==="stroke-width"?w(this,ue,fv).call(this,s):null}updateParentDimensions([e,s],i){const[n,r]=w(this,ue,Sn).call(this);m(this,Si,e),m(this,Ci,s),m(this,oh,i);const[o,h]=w(this,ue,Sn).call(this),c=o-n,u=h-r,d=l(this,je);return d[0]-=c,d[1]-=u,d[2]+=2*c,d[3]+=2*u,d}updateRotation(e){return m(this,_c,e),{path:{transform:this.rotationTransform}}}get viewBox(){return l(this,je).map(B.svgRound).join(" ")}get defaultProperties(){const[e,s]=l(this,je);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${B.svgRound(e)} ${B.svgRound(s)}`}}}get rotationTransform(){const[,,e,s]=l(this,je);let i=0,n=0,r=0,o=0,h=0,c=0;switch(l(this,_c)){case 90:n=s/e,r=-e/s,h=e;break;case 180:i=-1,o=-1,h=e,c=s;break;case 270:n=-s/e,r=e/s,c=s;break;default:return""}return`matrix(${i} ${n} ${r} ${o} ${B.svgRound(h)} ${B.svgRound(c)})`}getPathResizingSVGProperties([e,s,i,n]){const[r,o]=w(this,ue,Sn).call(this),[h,c,u,d]=l(this,je);if(Math.abs(u-r)<=B.PRECISION||Math.abs(d-o)<=B.PRECISION){const v=e+i/2-(h+u/2),_=s+n/2-(c+d/2);return{path:{"transform-origin":`${B.svgRound(e)} ${B.svgRound(s)}`,transform:`${this.rotationTransform} translate(${v} ${_})`}}}const f=(i-2*r)/(u-2*r),g=(n-2*o)/(d-2*o),p=u/i,b=d/n;return{path:{"transform-origin":`${B.svgRound(h)} ${B.svgRound(c)}`,transform:`${this.rotationTransform} scale(${p} ${b}) translate(${B.svgRound(r)} ${B.svgRound(o)}) scale(${f} ${g}) translate(${B.svgRound(-r)} ${B.svgRound(-o)})`}}}getPathResizedSVGProperties([e,s,i,n]){const[r,o]=w(this,ue,Sn).call(this),h=l(this,je),[c,u,d,f]=h;if(h[0]=e,h[1]=s,h[2]=i,h[3]=n,Math.abs(d-r)<=B.PRECISION||Math.abs(f-o)<=B.PRECISION){const _=e+i/2-(c+d/2),x=s+n/2-(u+f/2);for(const{line:C,points:S}of l(this,gs))B._translate(C,_,x,C),B._translate(S,_,x,S);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${B.svgRound(e)} ${B.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const g=(i-2*r)/(d-2*r),p=(n-2*o)/(f-2*o),b=-g*(c+r)+e+r,v=-p*(u+o)+s+o;if(g!==1||p!==1||b!==0||v!==0)for(const{line:_,points:x}of l(this,gs))B._rescale(_,b,v,g,p,_),B._rescale(x,b,v,g,p,x);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${B.svgRound(e)} ${B.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,s],i){const[n,r]=i,o=l(this,je),h=e-o[0],c=s-o[1];if(l(this,Si)===n&&l(this,Ci)===r)for(const{line:u,points:d}of l(this,gs))B._translate(u,h,c,u),B._translate(d,h,c,d);else{const u=l(this,Si)/n,d=l(this,Ci)/r;m(this,Si,n),m(this,Ci,r);for(const{line:f,points:g}of l(this,gs))B._rescale(f,h,c,u,d,f),B._rescale(g,h,c,u,d,g);o[2]*=u,o[3]*=d}return o[0]=e,o[1]=s,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${B.svgRound(e)} ${B.svgRound(s)}`}}}get defaultSVGProperties(){const e=l(this,je);return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${B.svgRound(e[0])} ${B.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}};je=new WeakMap,_c=new WeakMap,wc=new WeakMap,gs=new WeakMap,Si=new WeakMap,Ci=new WeakMap,oh=new WeakMap,ah=new WeakMap,hh=new WeakMap,ue=new WeakSet,Sn=function(e=l(this,hh)){const s=l(this,wc)+e/2*l(this,oh);return l(this,ah)%180===0?[s/l(this,Si),s/l(this,Ci)]:[s/l(this,Ci),s/l(this,Si)]},uv=function(){const[e,s,i,n]=l(this,je),[r,o]=w(this,ue,Sn).call(this,0);return[e+r,s+o,i-2*r,n-2*o]},dv=function(){const e=m(this,je,new Float32Array([1/0,1/0,-1/0,-1/0]));for(const{line:n}of l(this,gs)){if(n.length<=12){for(let h=4,c=n.length;h<c;h+=6){const[u,d]=n.subarray(h,h+2);e[0]=Math.min(e[0],u),e[1]=Math.min(e[1],d),e[2]=Math.max(e[2],u),e[3]=Math.max(e[3],d)}continue}let r=n[4],o=n[5];for(let h=6,c=n.length;h<c;h+=6){const[u,d,f,g,p,b]=n.subarray(h,h+6);X.bezierBoundingBox(r,o,u,d,f,g,p,b,e),r=p,o=b}}const[s,i]=w(this,ue,Sn).call(this);e[0]=Math.min(1,Math.max(0,e[0]-s)),e[1]=Math.min(1,Math.max(0,e[1]-i)),e[2]=Math.min(1,Math.max(0,e[2]+s)),e[3]=Math.min(1,Math.max(0,e[3]+i)),e[2]-=e[0],e[3]-=e[1]},fv=function(e){const[s,i]=w(this,ue,Sn).call(this);m(this,hh,e);const[n,r]=w(this,ue,Sn).call(this),[o,h]=[n-s,r-i],c=l(this,je);return c[0]-=o,c[1]-=h,c[2]+=2*o,c[3]+=2*h,c};let od=Ug;const Yg=class Yg extends XS{constructor(e){super();y(this,lh);m(this,lh,e),super.updateProperties({fill:"none",stroke:Pt._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(e,s){e==="stroke-width"&&(s??(s=this["stroke-width"]),s*=l(this,lh).realScale),super.updateSVGProperty(e,s)}clone(){const e=new Yg(l(this,lh));return e.updateAll(this),e}};lh=new WeakMap;let Ng=Yg;const ch=class ch extends Ig{constructor(e){super({...e,name:"inkEditor"});y(this,Cd);this._willKeepAspectRatio=!0}static initialize(e,s){Pt.initialize(e,s),this._defaultDrawingOptions=new Ng(s.viewParameters)}static getDefaultDrawingOptions(e){const s=this._defaultDrawingOptions.clone();return s.updateProperties(e),s}static get supportMultipleDrawings(){return!0}static get typesMap(){return st(this,"typesMap",new Map([[ot.INK_THICKNESS,"stroke-width"],[ot.INK_COLOR,"stroke"],[ot.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(e,s,i,n,r){return new WS(e,s,i,n,r,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(e,s,i,n,r,o){return od.deserialize(e,s,i,n,r,o)}static async deserialize(e,s,i){let n=null;if(e instanceof Og){const{data:{inkLists:o,rect:h,rotation:c,id:u,color:d,opacity:f,borderStyle:{rawWidth:g},popupRef:p},parent:{page:{pageNumber:b}}}=e;n=e={annotationType:Z.INK,color:Array.from(d),thickness:g,opacity:f,paths:{points:o},boxes:null,pageIndex:b-1,rect:h.slice(0),rotation:c,id:u,deleted:!1,popupRef:p}}const r=await super.deserialize(e,s,i);return r.annotationElementId=e.id||null,r._initialData=n,r}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();const{_drawId:e,_drawingOptions:s,parent:i}=this;s.updateSVGProperty("stroke-width"),i.drawLayer.updateProperties(e,s.toSVGProperties())}static onScaleChangingWhenDrawing(){const e=this._currentParent;e&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),e.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:e,thickness:s,opacity:i}){this._drawingOptions=ch.getDefaultDrawingOptions({stroke:X.makeHexColor(...e),"stroke-width":s,"stroke-opacity":i})}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:s,points:i,rect:n}=this.serializeDraw(e),{_drawingOptions:{stroke:r,"stroke-opacity":o,"stroke-width":h}}=this,c={annotationType:Z.INK,color:Pt._colorManager.convert(r),opacity:o,thickness:h,paths:{lines:s,points:i},pageIndex:this.pageIndex,rect:n,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?c:this.annotationElementId&&!w(this,Cd,gv).call(this,c)?null:(c.id=this.annotationElementId,c)}renderAnnotationElement(e){const{points:s,rect:i}=this.serializeDraw(!1);return e.updateEdited({rect:i,thickness:this._drawingOptions["stroke-width"],points:s}),null}};Cd=new WeakSet,gv=function(e){const{color:s,thickness:i,opacity:n,pageIndex:r}=this._initialData;return this._hasBeenMoved||this._hasBeenResized||e.color.some((o,h)=>o!==s[h])||e.thickness!==i||e.opacity!==n||e.pageIndex!==r},$(ch,"_type","ink"),$(ch,"_editorType",Z.INK),$(ch,"_defaultDrawingOptions",null);let jg=ch;const xc=class xc extends Pt{constructor(e){super({...e,name:"stampEditor"});y(this,ct);y(this,Ot,null);y(this,de,null);y(this,hr,null);y(this,yn,null);y(this,lr,null);y(this,uh,"");y(this,Ai,null);y(this,Ti,null);y(this,ps,!1);y(this,dh,!1);m(this,yn,e.bitmapUrl),m(this,lr,e.bitmapFile)}static initialize(e,s){Pt.initialize(e,s)}static get supportedTypes(){return st(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(s=>`image/${s}`))}static get supportedTypesStr(){return st(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(e){return this.supportedTypes.includes(e)}static paste(e,s){s.pasteEditor(Z.STAMP,{bitmapFile:e.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){var e;return{type:"stamp",hasAltText:!!((e=this.altTextData)!=null&&e.altText)}}static computeTelemetryFinalData(e){const s=e.get("hasAltText");return{hasAltText:s.get(!0)??0,hasNoAltText:s.get(!1)??0}}async mlGuessAltText(e=null,s=!0){if(this.hasAltTextData())return null;const{mlManager:i}=this._uiManager;if(!i)throw new Error("No ML.");if(!await i.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:n,width:r,height:o}=e||this.copyCanvas(null,null,!0).imageData,h=await i.guess({name:"altText",request:{data:n,width:r,height:o,channels:n.length/(r*o)}});if(!h)throw new Error("No response from the AI service.");if(h.error)throw new Error("Error from the AI service.");if(h.cancel)return null;if(!h.output)throw new Error("No valid response from the AI service.");const c=h.output;return await this.setGuessedAltText(c),s&&!this.hasAltTextData()&&(this.altTextData={alt:c,decorative:!1}),c}remove(){var e;l(this,de)&&(m(this,Ot,null),this._uiManager.imageManager.deleteId(l(this,de)),(e=l(this,Ai))==null||e.remove(),m(this,Ai,null),l(this,Ti)&&(clearTimeout(l(this,Ti)),m(this,Ti,null))),super.remove()}rebuild(){if(!this.parent){l(this,de)&&w(this,ct,Jd).call(this);return}super.rebuild(),this.div!==null&&(l(this,de)&&l(this,Ai)===null&&w(this,ct,Jd).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(e){this._isDraggable=!0,e&&this.div.focus()}isEmpty(){return!(l(this,hr)||l(this,Ot)||l(this,yn)||l(this,lr)||l(this,de))}get isResizable(){return!0}render(){if(this.div)return this.div;let e,s;if(this.width&&(e=this.x,s=this.y),super.render(),this.div.hidden=!0,this.div.setAttribute("role","figure"),this.addAltTextButton(),l(this,Ot)?w(this,ct,Ip).call(this):w(this,ct,Jd).call(this),this.width&&!this.annotationElementId){const[i,n]=this.parentDimensions;this.setAt(e*i,s*n,this.width*i,this.height*n)}return this._uiManager.addShouldRescale(this),this.div}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;l(this,Ti)!==null&&clearTimeout(l(this,Ti)),m(this,Ti,setTimeout(()=>{m(this,Ti,null),w(this,ct,Np).call(this)},200))}copyCanvas(e,s,i=!1){var g;e||(e=224);const{width:n,height:r}=l(this,Ot),o=new mg;let h=l(this,Ot),c=n,u=r,d=null;if(s){if(n>s||r>s){const M=Math.min(s/n,s/r);c=Math.floor(n*M),u=Math.floor(r*M)}d=document.createElement("canvas");const p=d.width=Math.ceil(c*o.sx),b=d.height=Math.ceil(u*o.sy);l(this,ps)||(h=w(this,ct,Zd).call(this,p,b));const v=d.getContext("2d");v.filter=this._uiManager.hcmFilter;let _="white",x="#cfcfd8";this._uiManager.hcmFilter!=="none"?x="black":(g=window.matchMedia)!=null&&g.call(window,"(prefers-color-scheme: dark)").matches&&(_="#8f8f9d",x="#42414d");const C=15,S=C*o.sx,k=C*o.sy,D=new OffscreenCanvas(S*2,k*2),T=D.getContext("2d");T.fillStyle=_,T.fillRect(0,0,S*2,k*2),T.fillStyle=x,T.fillRect(0,0,S,k),T.fillRect(S,k,S,k),v.fillStyle=v.createPattern(D,"repeat"),v.fillRect(0,0,p,b),v.drawImage(h,0,0,h.width,h.height,0,0,p,b)}let f=null;if(i){let p,b;if(o.symmetric&&h.width<e&&h.height<e)p=h.width,b=h.height;else if(h=l(this,Ot),n>e||r>e){const x=Math.min(e/n,e/r);p=Math.floor(n*x),b=Math.floor(r*x),l(this,ps)||(h=w(this,ct,Zd).call(this,p,b))}const _=new OffscreenCanvas(p,b).getContext("2d",{willReadFrequently:!0});_.drawImage(h,0,0,h.width,h.height,0,0,p,b),f={width:p,height:b,data:_.getImageData(0,0,p,b).data}}return{canvas:d,width:c,height:u,imageData:f}}getImageForAltText(){return l(this,Ai)}static async deserialize(e,s,i){var b;let n=null;if(e instanceof Ib){const{data:{rect:v,rotation:_,id:x,structParent:C,popupRef:S},container:k,parent:{page:{pageNumber:D}}}=e,T=k.querySelector("canvas"),M=i.imageManager.getFromCanvas(k.id,T);T.remove();const O=((b=await s._structTree.getAriaAttributes(`${ug}${x}`))==null?void 0:b.get("aria-label"))||"";n=e={annotationType:Z.STAMP,bitmapId:M.id,bitmap:M.bitmap,pageIndex:D-1,rect:v.slice(0),rotation:_,id:x,deleted:!1,accessibilityData:{decorative:!1,altText:O},isSvg:!1,structParent:C,popupRef:S}}const r=await super.deserialize(e,s,i),{rect:o,bitmap:h,bitmapUrl:c,bitmapId:u,isSvg:d,accessibilityData:f}=e;u&&i.imageManager.isValidId(u)?(m(r,de,u),h&&m(r,Ot,h)):m(r,yn,c),m(r,ps,d);const[g,p]=r.pageDimensions;return r.width=(o[2]-o[0])/g,r.height=(o[3]-o[1])/p,r.annotationElementId=e.id||null,f&&(r.altTextData=f),r._initialData=n,m(r,dh,!!n),r}serialize(e=!1,s=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const i={annotationType:Z.STAMP,bitmapId:l(this,de),pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:l(this,ps),structTreeParentId:this._structTreeParentId};if(e)return i.bitmapUrl=w(this,ct,tf).call(this,!0),i.accessibilityData=this.serializeAltText(!0),i;const{decorative:n,altText:r}=this.serializeAltText(!1);if(!n&&r&&(i.accessibilityData={type:"Figure",alt:r}),this.annotationElementId){const h=w(this,ct,pv).call(this,i);if(h.isSame)return null;h.isSameAltText?delete i.accessibilityData:i.accessibilityData.structParent=this._initialData.structParent??-1}if(i.id=this.annotationElementId,s===null)return i;s.stamps||(s.stamps=new Map);const o=l(this,ps)?(i.rect[2]-i.rect[0])*(i.rect[3]-i.rect[1]):null;if(!s.stamps.has(l(this,de)))s.stamps.set(l(this,de),{area:o,serialized:i}),i.bitmap=w(this,ct,tf).call(this,!1);else if(l(this,ps)){const h=s.stamps.get(l(this,de));o>h.area&&(h.area=o,h.serialized.bitmap.close(),h.serialized.bitmap=w(this,ct,tf).call(this,!1))}return i}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}};Ot=new WeakMap,de=new WeakMap,hr=new WeakMap,yn=new WeakMap,lr=new WeakMap,uh=new WeakMap,Ai=new WeakMap,Ti=new WeakMap,ps=new WeakMap,dh=new WeakMap,ct=new WeakSet,Ic=function(e,s=!1){if(!e){this.remove();return}m(this,Ot,e.bitmap),s||(m(this,de,e.id),m(this,ps,e.isSvg)),e.file&&m(this,uh,e.file.name),w(this,ct,Ip).call(this)},Nc=function(){if(m(this,hr,null),this._uiManager.enableWaiting(!1),!!l(this,Ai)){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Ot)){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Ot)){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}},Jd=function(){if(l(this,de)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(l(this,de)).then(i=>w(this,ct,Ic).call(this,i,!0)).finally(()=>w(this,ct,Nc).call(this));return}if(l(this,yn)){const i=l(this,yn);m(this,yn,null),this._uiManager.enableWaiting(!0),m(this,hr,this._uiManager.imageManager.getFromUrl(i).then(n=>w(this,ct,Ic).call(this,n)).finally(()=>w(this,ct,Nc).call(this)));return}if(l(this,lr)){const i=l(this,lr);m(this,lr,null),this._uiManager.enableWaiting(!0),m(this,hr,this._uiManager.imageManager.getFromFile(i).then(n=>w(this,ct,Ic).call(this,n)).finally(()=>w(this,ct,Nc).call(this)));return}const e=document.createElement("input");e.type="file",e.accept=xc.supportedTypesStr;const s=this._uiManager._signal;m(this,hr,new Promise(i=>{e.addEventListener("change",async()=>{if(!e.files||e.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const n=await this._uiManager.imageManager.getFromFile(e.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),w(this,ct,Ic).call(this,n)}i()},{signal:s}),e.addEventListener("cancel",()=>{this.remove(),i()},{signal:s})}).finally(()=>w(this,ct,Nc).call(this))),e.click()},Ip=function(){var d;const{div:e}=this;let{width:s,height:i}=l(this,Ot);const[n,r]=this.pageDimensions,o=.75;if(this.width)s=this.width*n,i=this.height*r;else if(s>o*n||i>o*r){const f=Math.min(o*n/s,o*r/i);s*=f,i*=f}const[h,c]=this.parentDimensions;this.setDims(s*h/n,i*c/r),this._uiManager.enableWaiting(!1);const u=m(this,Ai,document.createElement("canvas"));u.setAttribute("role","img"),this.addContainer(u),this.width=s/n,this.height=i/r,(d=this._initialOptions)!=null&&d.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(e.hidden=!1),w(this,ct,Np).call(this),l(this,dh)||(this.parent.addUndoableEditor(this),m(this,dh,!0)),this._reportTelemetry({action:"inserted_image"}),l(this,uh)&&u.setAttribute("aria-label",l(this,uh))},Zd=function(e,s){const{width:i,height:n}=l(this,Ot);let r=i,o=n,h=l(this,Ot);for(;r>2*e||o>2*s;){const c=r,u=o;r>2*e&&(r=r>=16384?Math.floor(r/2)-1:Math.ceil(r/2)),o>2*s&&(o=o>=16384?Math.floor(o/2)-1:Math.ceil(o/2));const d=new OffscreenCanvas(r,o);d.getContext("2d").drawImage(h,0,0,c,u,0,0,r,o),h=d.transferToImageBitmap()}return h},Np=function(){const[e,s]=this.parentDimensions,{width:i,height:n}=this,r=new mg,o=Math.ceil(i*e*r.sx),h=Math.ceil(n*s*r.sy),c=l(this,Ai);if(!c||c.width===o&&c.height===h)return;c.width=o,c.height=h;const u=l(this,ps)?l(this,Ot):w(this,ct,Zd).call(this,o,h),d=c.getContext("2d");d.filter=this._uiManager.hcmFilter,d.drawImage(u,0,0,u.width,u.height,0,0,o,h)},tf=function(e){if(e){if(l(this,ps)){const n=this._uiManager.imageManager.getSvgUrl(l(this,de));if(n)return n}const s=document.createElement("canvas");return{width:s.width,height:s.height}=l(this,Ot),s.getContext("2d").drawImage(l(this,Ot),0,0),s.toDataURL()}if(l(this,ps)){const[s,i]=this.pageDimensions,n=Math.round(this.width*s*Ln.PDF_TO_CSS_UNITS),r=Math.round(this.height*i*Ln.PDF_TO_CSS_UNITS),o=new OffscreenCanvas(n,r);return o.getContext("2d").drawImage(l(this,Ot),0,0,l(this,Ot).width,l(this,Ot).height,0,0,n,r),o.transferToImageBitmap()}return structuredClone(l(this,Ot))},pv=function(e){var o;const{pageIndex:s,accessibilityData:{altText:i}}=this._initialData,n=e.pageIndex===s,r=(((o=e.accessibilityData)==null?void 0:o.alt)||"")===i;return{isSame:!this._hasBeenMoved&&!this._hasBeenResized&&n&&r,isSameAltText:r}},$(xc,"_type","stamp"),$(xc,"_editorType",Z.STAMP);let Bg=xc;const ei=class ei{constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:o,textLayer:h,viewport:c,l10n:u}){y(this,kt);y(this,No);y(this,fh,!1);y(this,Ei,null);y(this,cr,null);y(this,vn,null);y(this,Ps,new Map);y(this,ur,!1);y(this,gh,!1);y(this,jo,!1);y(this,ti,null);y(this,_n,null);y(this,Ce,null);y(this,wn,null);y(this,V);const d=[...l(ei,dr).values()];if(!ei._initialized){ei._initialized=!0;for(const f of d)f.initialize(u,t)}t.registerEditorTypes(d),m(this,V,t),this.pageIndex=e,this.div=s,m(this,No,n),m(this,Ei,r),this.viewport=c,m(this,Ce,h),this.drawLayer=o,this._structTree=i,l(this,V).addLayer(this)}get isEmpty(){return l(this,Ps).size===0}get isInvisible(){return this.isEmpty&&l(this,V).getMode()===Z.NONE}updateToolbar(t){l(this,V).updateToolbar(t)}updateMode(t=l(this,V).getMode()){switch(w(this,kt,ef).call(this),t){case Z.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case Z.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case Z.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);const{classList:e}=this.div;for(const s of l(ei,dr).values())e.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){var e;return t===((e=l(this,Ce))==null?void 0:e.div)}setEditingState(t){l(this,V).setEditingState(t)}addCommands(t){l(this,V).addCommands(t)}cleanUndoStack(t){l(this,V).cleanUndoStack(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){var e;(e=l(this,Ei))==null||e.div.classList.toggle("disabled",!t)}async enable(){m(this,jo,!0),this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const s of l(this,Ps).values())s.enableEditing(),s.show(!0),s.annotationElementId&&(l(this,V).removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!l(this,Ei)){m(this,jo,!1);return}const e=l(this,Ei).getEditableAnnotations();for(const s of e){if(s.hide(),l(this,V).isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;const i=await this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}m(this,jo,!1)}disable(){var i;m(this,gh,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,e=new Map;for(const n of l(this,Ps).values())if(n.disableEditing(),!!n.annotationElementId){if(n.serialize()!==null){t.set(n.annotationElementId,n);continue}else e.set(n.annotationElementId,n);(i=this.getEditableAnnotation(n.annotationElementId))==null||i.show(),n.remove()}if(l(this,Ei)){const n=l(this,Ei).getEditableAnnotations();for(const r of n){const{id:o}=r.data;if(l(this,V).isDeletedAnnotationElement(o))continue;let h=e.get(o);if(h){h.resetAnnotationElement(r),h.show(!1),r.show();continue}h=t.get(o),h&&(l(this,V).addChangedExistingAnnotation(h),h.renderAnnotationElement(r)&&h.show(!1)),r.show()}}w(this,kt,ef).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const n of l(ei,dr).values())s.remove(`${n._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),m(this,gh,!1)}getEditableAnnotation(t){var e;return((e=l(this,Ei))==null?void 0:e.getEditableAnnotation(t))||null}setActiveEditor(t){l(this,V).getActive()!==t&&l(this,V).setActiveEditor(t)}enableTextSelection(){var t;if(this.div.tabIndex=-1,(t=l(this,Ce))!=null&&t.div&&!l(this,wn)){m(this,wn,new AbortController);const e=l(this,V).combinedSignal(l(this,wn));l(this,Ce).div.addEventListener("pointerdown",w(this,kt,mv).bind(this),{signal:e}),l(this,Ce).div.classList.add("highlighting")}}disableTextSelection(){var t;this.div.tabIndex=0,(t=l(this,Ce))!=null&&t.div&&l(this,wn)&&(l(this,wn).abort(),m(this,wn,null),l(this,Ce).div.classList.remove("highlighting"))}enableClick(){if(l(this,cr))return;m(this,cr,new AbortController);const t=l(this,V).combinedSignal(l(this,cr));this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t});const e=this.pointerup.bind(this);this.div.addEventListener("pointerup",e,{signal:t}),this.div.addEventListener("pointercancel",e,{signal:t})}disableClick(){var t;(t=l(this,cr))==null||t.abort(),m(this,cr,null)}attach(t){l(this,Ps).set(t.id,t);const{annotationElementId:e}=t;e&&l(this,V).isDeletedAnnotationElement(e)&&l(this,V).removeDeletedAnnotationElement(t)}detach(t){var e;l(this,Ps).delete(t.id),(e=l(this,No))==null||e.removePointerInTextLayer(t.contentDiv),!l(this,gh)&&t.annotationElementId&&l(this,V).addDeletedAnnotationElement(t)}remove(t){this.detach(t),l(this,V).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){var e;t.parent!==this&&(t.parent&&t.annotationElementId&&(l(this,V).addDeletedAnnotationElement(t.annotationElementId),Pt.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),(e=t.parent)==null||e.detach(t),t.setParent(this),t.div&&t.isAttachedToDOM&&(t.div.remove(),this.div.append(t.div)))}add(t){if(!(t.parent===this&&t.isAttachedToDOM)){if(this.changeParent(t),l(this,V).addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!l(this,jo)),l(this,V).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var s;if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!l(this,vn)&&(t._focusEventsAllowed=!1,m(this,vn,setTimeout(()=>{m(this,vn,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:l(this,V)._signal}),e.focus())},0))),t._structTreeParentId=(s=l(this,No))==null?void 0:s.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){t.needsToBeRebuilt()?(t.parent||(t.parent=this),t.rebuild(),t.show()):this.add(t)}addUndoableEditor(t){const e=()=>t._uiManager.rebuild(t),s=()=>{t.remove()};this.addCommands({cmd:e,undo:s,mustExec:!1})}getNextId(){return l(this,V).getId()}combinedSignal(t){return l(this,V).combinedSignal(t)}canCreateNewEmptyEditor(){var t;return(t=l(this,kt,Di))==null?void 0:t.canCreateNewEmptyEditor()}pasteEditor(t,e){l(this,V).updateToolbar(t),l(this,V).updateMode(t);const{offsetX:s,offsetY:i}=w(this,kt,Bp).call(this),n=this.getNextId(),r=w(this,kt,jp).call(this,{parent:this,id:n,x:s,y:i,uiManager:l(this,V),isCentered:!0,...e});r&&this.add(r)}async deserialize(t){var e;return await((e=l(ei,dr).get(t.annotationType??t.annotationEditorType))==null?void 0:e.deserialize(t,this,l(this,V)))||null}createAndAddNewEditor(t,e,s={}){const i=this.getNextId(),n=w(this,kt,jp).call(this,{parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:l(this,V),isCentered:e,...s});return n&&this.add(n),n}addNewEditor(){this.createAndAddNewEditor(w(this,kt,Bp).call(this),!0)}setSelected(t){l(this,V).setSelected(t)}toggleSelected(t){l(this,V).toggleSelected(t)}unselect(t){l(this,V).unselect(t)}pointerup(t){var s;const{isMac:e}=Re.platform;if(!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&l(this,ur)&&(m(this,ur,!1),!((s=l(this,kt,Di))!=null&&s.isDrawer&&l(this,kt,Di).supportMultipleDrawings))){if(!l(this,fh)){m(this,fh,!0);return}if(l(this,V).getMode()===Z.STAMP){l(this,V).unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){var i;if(l(this,V).getMode()===Z.HIGHLIGHT&&this.enableTextSelection(),l(this,ur)){m(this,ur,!1);return}const{isMac:e}=Re.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;if(m(this,ur,!0),(i=l(this,kt,Di))!=null&&i.isDrawer){this.startDrawingSession(t);return}const s=l(this,V).getActive();m(this,fh,!s||s.isEmpty())}startDrawingSession(t){if(this.div.focus(),l(this,ti)){l(this,kt,Di).startDrawing(this,l(this,V),!1,t);return}l(this,V).setCurrentDrawingSession(this),m(this,ti,new AbortController);const e=l(this,V).combinedSignal(l(this,ti));this.div.addEventListener("blur",({relatedTarget:s})=>{s&&!this.div.contains(s)&&(m(this,_n,null),this.commitOrRemove())},{signal:e}),l(this,kt,Di).startDrawing(this,l(this,V),!1,t)}pause(t){if(t){const{activeElement:e}=document;this.div.contains(e)&&m(this,_n,e);return}l(this,_n)&&setTimeout(()=>{var e;(e=l(this,_n))==null||e.focus(),m(this,_n,null)},0)}endDrawingSession(t=!1){return l(this,ti)?(l(this,V).setCurrentDrawingSession(null),l(this,ti).abort(),m(this,ti,null),m(this,_n,null),l(this,kt,Di).endDrawing(t)):null}findNewParent(t,e,s){const i=l(this,V).findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}commitOrRemove(){return l(this,ti)?(this.endDrawingSession(),!0):!1}onScaleChanging(){l(this,ti)&&l(this,kt,Di).onScaleChangingWhenDrawing(this)}destroy(){var t,e;this.commitOrRemove(),((t=l(this,V).getActive())==null?void 0:t.parent)===this&&(l(this,V).commitOrRemove(),l(this,V).setActiveEditor(null)),l(this,vn)&&(clearTimeout(l(this,vn)),m(this,vn,null));for(const s of l(this,Ps).values())(e=l(this,No))==null||e.removePointerInTextLayer(s.contentDiv),s.setParent(null),s.isAttachedToDOM=!1,s.div.remove();this.div=null,l(this,Ps).clear(),l(this,V).removeLayer(this)}render({viewport:t}){this.viewport=t,kr(this.div,t);for(const e of l(this,V).getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){l(this,V).commitOrRemove(),w(this,kt,ef).call(this);const e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,kr(this.div,{rotation:s}),e!==s)for(const i of l(this,Ps).values())i.rotate(s)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return l(this,V).viewParameters.realScale}};No=new WeakMap,fh=new WeakMap,Ei=new WeakMap,cr=new WeakMap,vn=new WeakMap,Ps=new WeakMap,ur=new WeakMap,gh=new WeakMap,jo=new WeakMap,ti=new WeakMap,_n=new WeakMap,Ce=new WeakMap,wn=new WeakMap,V=new WeakMap,dr=new WeakMap,kt=new WeakSet,mv=function(t){l(this,V).unselectAll();const{target:e}=t;if(e===l(this,Ce).div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&l(this,Ce).div.contains(e)){const{isMac:s}=Re.platform;if(t.button!==0||t.ctrlKey&&s)return;l(this,V).showAllEditors("highlight",!0,!0),l(this,Ce).div.classList.add("free"),this.toggleDrawing(),rd.startHighlighting(this,l(this,V).direction==="ltr",{target:l(this,Ce).div,x:t.x,y:t.y}),l(this,Ce).div.addEventListener("pointerup",()=>{l(this,Ce).div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:l(this,V)._signal}),t.preventDefault()}},Di=function(){return l(ei,dr).get(l(this,V).getMode())},jp=function(t){const e=l(this,kt,Di);return e?new e.prototype.constructor(t):null},Bp=function(){const{x:t,y:e,width:s,height:i}=this.div.getBoundingClientRect(),n=Math.max(0,t),r=Math.max(0,e),o=Math.min(window.innerWidth,t+s),h=Math.min(window.innerHeight,e+i),c=(n+o)/2-t,u=(r+h)/2-e,[d,f]=this.viewport.rotation%180===0?[c,u]:[u,c];return{offsetX:d,offsetY:f}},ef=function(){for(const t of l(this,Ps).values())t.isEmpty()&&t.remove()},$(ei,"_initialized",!1),y(ei,dr,new Map([Rg,jg,Bg,rd].map(t=>[t._editorType,t])));let Hg=ei;const Ae=class Ae{constructor({pageIndex:t}){y(this,ki);y(this,si,null);y(this,Sc,0);y(this,Be,new Map);y(this,Bo,new Map);this.pageIndex=t}setParent(t){if(!l(this,si)){m(this,si,t);return}if(l(this,si)!==t){if(l(this,Be).size>0)for(const e of l(this,Be).values())e.remove(),t.append(e);m(this,si,t)}}static get _svgFactory(){return st(this,"_svgFactory",new Pg)}draw(t,e=!1,s=!1){const i=Ge(this,Sc)._++,n=w(this,ki,Hp).call(this),r=Ae._svgFactory.createElement("defs");n.append(r);const o=Ae._svgFactory.createElement("path");r.append(o);const h=`path_p${this.pageIndex}_${i}`;o.setAttribute("id",h),o.setAttribute("vector-effect","non-scaling-stroke"),e&&l(this,Bo).set(i,o);const c=s?w(this,ki,yv).call(this,r,h):null,u=Ae._svgFactory.createElement("use");return n.append(u),u.setAttribute("href",`#${h}`),this.updateProperties(n,t),l(this,Be).set(i,n),{id:i,clipPathId:`url(#${c})`}}drawOutline(t,e){const s=Ge(this,Sc)._++,i=w(this,ki,Hp).call(this),n=Ae._svgFactory.createElement("defs");i.append(n);const r=Ae._svgFactory.createElement("path");n.append(r);const o=`path_p${this.pageIndex}_${s}`;r.setAttribute("id",o),r.setAttribute("vector-effect","non-scaling-stroke");let h;if(e){const d=Ae._svgFactory.createElement("mask");n.append(d),h=`mask_p${this.pageIndex}_${s}`,d.setAttribute("id",h),d.setAttribute("maskUnits","objectBoundingBox");const f=Ae._svgFactory.createElement("rect");d.append(f),f.setAttribute("width","1"),f.setAttribute("height","1"),f.setAttribute("fill","white");const g=Ae._svgFactory.createElement("use");d.append(g),g.setAttribute("href",`#${o}`),g.setAttribute("stroke","none"),g.setAttribute("fill","black"),g.setAttribute("fill-rule","nonzero"),g.classList.add("mask")}const c=Ae._svgFactory.createElement("use");i.append(c),c.setAttribute("href",`#${o}`),h&&c.setAttribute("mask",`url(#${h})`);const u=c.cloneNode();return i.append(u),c.classList.add("mainOutline"),u.classList.add("secondaryOutline"),this.updateProperties(i,t),l(this,Be).set(s,i),s}finalizeDraw(t,e){l(this,Bo).delete(t),this.updateProperties(t,e)}updateProperties(t,e){var h;if(!e)return;const{root:s,bbox:i,rootClass:n,path:r}=e,o=typeof t=="number"?l(this,Be).get(t):t;if(o){if(s&&w(this,ki,Gp).call(this,o,s),i&&w(h=Ae,Ad,bv).call(h,o,i),n){const{classList:c}=o;for(const[u,d]of Object.entries(n))c.toggle(u,d)}if(r){const u=o.firstChild.firstChild;w(this,ki,Gp).call(this,u,r)}}}updateParent(t,e){if(e===this)return;const s=l(this,Be).get(t);s&&(l(e,si).append(s),l(this,Be).delete(t),l(e,Be).set(t,s))}remove(t){l(this,Bo).delete(t),l(this,si)!==null&&(l(this,Be).get(t).remove(),l(this,Be).delete(t))}destroy(){m(this,si,null);for(const t of l(this,Be).values())t.remove();l(this,Be).clear(),l(this,Bo).clear()}};si=new WeakMap,Sc=new WeakMap,Be=new WeakMap,Bo=new WeakMap,Ad=new WeakSet,bv=function(t,[e,s,i,n]){const{style:r}=t;r.top=`${100*s}%`,r.left=`${100*e}%`,r.width=`${100*i}%`,r.height=`${100*n}%`},ki=new WeakSet,Hp=function(){const t=Ae._svgFactory.create(1,1,!0);return l(this,si).append(t),t.setAttribute("aria-hidden",!0),t},yv=function(t,e){const s=Ae._svgFactory.createElement("clipPath");t.append(s);const i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=Ae._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i},Gp=function(t,e){for(const[s,i]of Object.entries(e))i===null?t.removeAttribute(s):t.setAttribute(s,i)},y(Ae,Ad);let Gg=Ae;globalThis.pdfjsTestingUtils={HighlightOutliner:Lg},K.AbortException,K.AnnotationEditorLayer,K.AnnotationEditorParamsType,K.AnnotationEditorType,K.AnnotationEditorUIManager,K.AnnotationLayer,K.AnnotationMode,K.ColorPicker,K.DOMSVGFactory,K.DrawLayer,K.FeatureTest;var US=K.GlobalWorkerOptions;K.ImageKind,K.InvalidPDFException,K.MissingPDFException,K.OPS,K.OutputScale,K.PDFDataRangeTransport,K.PDFDateString,K.PDFWorker,K.PasswordResponses,K.PermissionFlag,K.PixelsPerInch,K.RenderingCancelledException,K.TextLayer,K.TouchManager,K.UnexpectedResponseException,K.Util,K.VerbosityLevel,K.XfaLayer,K.build,K.createValidAbsoluteUrl,K.fetchData;var YS=K.getDocument;K.getFilenameFromUrl,K.getPdfFilenameFromUrl,K.getXfaPageViewport,K.isDataScheme,K.isPdfFile,K.noContextMenu,K.normalizeUnicode,K.setLayerDimensions,K.shadow,K.stopEvent,K.version;const $S={"pdfjs-dist":"4.10.38"};function qS(a){return new Promise((t,e)=>{const s=new FileReader;s.addEventListener("load",()=>t(s.result)),s.addEventListener("error",e),s.readAsDataURL(a)})}const KS=$S["pdfjs-dist"].replace("^","");US.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${KS}/pdf.worker.min.mjs`;async function QS(a){const t="data:application/pdf;base64,",e=await qS(a);if(typeof e=="string")return window.atob(e.slice(t.length))}function JS(a,t){return YS({data:a,password:t}).promise}const ZS="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2040%2040'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3ccircle%20cx='20'%20cy='20'%20r='10.75'%20stroke='currentColor'%20stroke-width='2.5'/%3e%3cpath%20d='M16%2024L23.7782%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3cpath%20d='M24%2024L16.2218%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3c/svg%3e";function tC(a){return new URL(Object.assign({"../assets/close.svg":ZS})[`../assets/${a}`],typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:_t&&_t.tagName.toUpperCase()==="SCRIPT"&&_t.src||new URL("pdf-canvas.umd.js",document.baseURI).href).href}function eC(a){return new Promise((t,e)=>{const s=window.URL.createObjectURL(a),i=new Image;i.src=s,i.addEventListener("load",async()=>{window.URL.revokeObjectURL(s),t(await sC(i))}),i.addEventListener("error",n=>{window.URL.revokeObjectURL(s),e(n)})})}function sC(a){return new Promise(t=>{const e=document.createElement("canvas"),s=e.getContext("2d"),{naturalWidth:i,naturalHeight:n}=a;e.width=i,e.height=n,s==null||s.drawImage(a,0,0,i,n),t(e.toDataURL("image/jpeg",.8))})}let jb=null;function iC(){const a=document.createElement("div");a.style.width="1in",document.body.append(a);const t=a.offsetWidth;return a.remove(),t}function nC(){const a=jb??iC();return jb=a,a/72}function rC(a,t=500){if(typeof a!="function")throw new TypeError("The first argument is not a function.");let e=null;return function(...s){e&&clearTimeout(e),e=setTimeout(()=>{e=null,a.apply(this,s)},t)}}const _s=new Map;function oC(a){const t=new Wf(a);return _s.set(a,t),t}function aC(a,t){const e=Date.now();return{PDFId:`${a.name}-${e}`,name:a.name.replace(/.pdf/,""),updateDate:e,PDFBase64:t}}function hC(a,t){const e=a.getViewport({scale:t}),s=document.createElement("canvas"),i=s.getContext("2d"),n=nC()/window.devicePixelRatio;s.width=Math.floor(e.width*n),s.height=Math.floor(e.height*n);const r={canvasContext:i,viewport:e,transform:[n,0,0,n,0,0]},o=a.render(r);return{canvas:s,renderTask:o}}async function lC(a,t,e){const s=a||tC("close.svg"),{objects:i,options:n}=await Iw(s),r=i.filter(h=>h!==null),o=K_.groupSVGElements(r,n);return r.forEach(h=>{h.stroke=t}),o.hoverCursor="pointer",o.stroke=`${t}-${e}`,o}function cC(a,t){if(!_s.get(a))return;const s=1/3,i=bC(t,s);Hb(a,i,s)}async function uC(a,t){const e=await eC(t),s=Date.now(),n={PDFId:`${t.name}${s}`,name:t.name.replace(/.png|.jpg|.jpeg/,""),updateDate:s,PDFBase64:e};return Bb(a,{url:e}),{...n,pages:1}}async function Bb(a,{url:t,scale:e=.5}){if(!_s.get(a))return;const i=await be.fromURL(t);i.scale(e),Hb(a,i,e)}function Hb(a,t,e){const s=_s.get(a);s&&(s.setWidth(t.width*e),s.setHeight(t.height*e),s.backgroundImage=t,s.renderAll())}function dC(a,t){if(!t)return;const{oCoords:e}=a;if(!e)return;const{x:s,y:i}=e.tl.touchCorner.tl,{height:n,width:r,scaleY:o,scaleX:h}=t;t.top=i-n*o/2,t.left=s-r*h/2,t.setCoords()}function fC(a,t,e){!e||!a||(e.scale(1/t),dC(a,e))}function gC(a,t,e){a&&(a.borderScaleFactor=1/t,a.cornerSize=6*(1/t),a.touchCornerSize=24*(1/t),a.cornerStrokeColor=e.stroke,a.setCoords())}function pC(a){const t=_s.get(a);t&&(t.discardActiveObject(),t.renderAll())}function mC(a){const t=_s.get(a);t&&(t.clear(),_s.delete(a))}function bC(a,t){return new be(a,{scaleX:t,scaleY:t})}function Gb(a,t){if(!t)return;const{left:e,top:s,scaleX:i,scaleY:n,width:r,height:o}=a,h=t.x*r*i,c=t.y*o*n;a.set({left:e-h,top:s-c})}function zb(a,t,e){var n;const s=a.type,i={"application/pdf":yC,"image/png":Xb,"image/jpeg":Xb};return((n=i[s])==null?void 0:n.call(i,a,t,e))??Promise.reject(new Error(`Unsupported ${s} file type.`))}async function yC(a,t,e){const s=await QS(a);if(!s)return;const i=aC(a,s);try{const n=await Vb({page:1,PDFBase64:s,scale:.8,password:t},e);return{...i,pages:n}}catch(n){return Promise.reject(n)}}async function Vb({page:a,PDFBase64:t,scale:e,password:s},i){try{const n=await JS(t,s),r=await n.getPage(a),{renderTask:o,canvas:h}=hC(r,e);return o.promise.then(()=>(i&&cC(i,h),n.numPages))}catch(n){return Promise.reject(n)}}async function Xb(a,t,e){if(e)return await uC(e,a)}const vC={top:100,left:50,scaleX:.5,scaleY:.5,borderColor:"black",cornerStrokeColor:"black",cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},_C={top:100,left:50,fontFamily:"helvetica",borderColor:"black",cornerStrokeColor:"black",scaleX:.7,scaleY:.7,cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},wC={stroke:"#000",hoverStroke:"#B7EC5D",src:""};function Wb(a){const{id:t="",pointerDown:e,pointerMove:s,pointerUp:i}=a||{};let n=null,r=null,o=1,h={...wC};function c(){if(!t||_s.has(t))return;const T=oC(t);return T.on("selection:cleared",()=>S(T)),e&&T.on("mouse:down",e),s&&T.on("mouse:move",s),i&&T.on("mouse:up",i),T}function u(T,M){return zb(T,M,t)}function d(T){return Vb(T,t)}async function f({url:T,scale:M=.5}){await Bb(t,{url:T,scale:M})}async function g(T,M,O){const R=_s.get(t);if(!R)return;const L=await be.fromURL(T,{},{...vC,...M});Gb(L,O),R.add(L),b(R,L),R.setActiveObject(L)}function p(T,M,O){const R=_s.get(t);if(!R)return;const L=new me(T,{..._C,...M});Gb(L,O),R.add(L),b(R,L),R.setActiveObject(L)}function b(T,M){M.on("selected",O=>v({canvas:T,target:O.target})),M.on("modified",O=>v({canvas:T,target:O.target})),M.on("scaling",()=>S(T)),M.on("moving",()=>S(T)),M.on("rotating",()=>S(T))}async function v({canvas:T,target:M,stroke:O=h.stroke,uuid:R=Date.now()}){if((n==null?void 0:n.stroke)===`${O}-${R}`)return;const L=await lC(h.src,O,R);S(T),n=L,r=M,_(T,M,R),x(o,!0),T.add(L)}function _(T,M,O){n&&(n.on("selected",()=>{T.remove(M),S(T)}),n.on("mouseover",()=>{v({canvas:T,target:M,stroke:h.hoverStroke,uuid:O})}),n.on("mouseout",()=>{v({canvas:T,target:M,stroke:h.stroke,uuid:O})}))}function x(T,M=!1){const O=_s.get(t);o=T,O&&(gC(r,T,h),fC(r,T,n),!M&&O.renderAll())}function C(T){if(!T)return;h={...h,...T};const M=_s.get(t);!n||!r||!M||v({target:r,canvas:M})}function S(T){n&&(T.remove(n),n=r=null)}function k(){pC(t)}function D(){mC(t)}return{createCanvas:c,loadFile:u,specifyPage:d,renderImage:f,addFabric:g,addTextFabric:p,clearActive:k,deleteCanvas:D,scaleFabric:x,setCloseSvgOptions:C}}function xC(a){let t=0;const e=rC(()=>{t!==window.innerWidth&&(t=window.innerWidth,a())});q.onMounted(()=>{window.addEventListener("resize",e)}),q.onBeforeUnmount(()=>{window.removeEventListener("resize",e)})}const SC=q.defineComponent({__name:"pdf-canvas",props:{file:{},page:{default:1},canvasId:{default:"PDF-canvas"},fileZoom:{default:1},fileScale:{default:1},canvasScale:{default:1},canvasClass:{default:""},isDrop:{type:Boolean,default:!1},password:{},dropTextOptions:{},dropImageOptions:{},closeSvgOptions:{},manualReload:{type:Boolean},onDestroy:{type:Function,default:q.onBeforeUnmount}},emits:["loaded","reload","pointerDown","pointerMove","pointerUp"],setup(a,{expose:t,emit:e}){const s=a,i=e,{onDestroy:n}=s,r=q.ref(null),o=`${s.canvasId}-${s.page-1}`,h=q.computed(()=>s.fileZoom*s.canvasScale),{createCanvas:c,specifyPage:u,addFabric:d,addTextFabric:f,renderImage:g,clearActive:p,deleteCanvas:b,scaleFabric:v,setCloseSvgOptions:_}=Wb({id:o,pointerDown:T=>i("pointerDown",T),pointerMove:T=>i("pointerMove",T),pointerUp:T=>i("pointerUp",T)});x(),xC(D);async function x(){const{file:T,page:M,fileScale:O}=s;window.requestAnimationFrame(async()=>{if(await q.nextTick(),c(),T.PDFBase64.startsWith("data:image")||T.canvas){const{canvas:R}=T,L=R?7:3,W=R!=null&&R.length?R[M-1]:T.PDFBase64;g({url:W,scale:O/L}),i("loaded");return}await u({page:M,PDFBase64:T.PDFBase64,scale:O,password:s.password}),i("loaded")})}function C(T){if(!s.isDrop||!T.dataTransfer)return;const{dataTransfer:M,offsetX:O,offsetY:R}=T,L=M.getData("text/plain"),W=M.getData("text/uri-list"),U=M.getData("custom/offset"),G=U?JSON.parse(U):null,at={top:R,left:O},F={x:(G==null?void 0:G.offsetX)??0,y:(G==null?void 0:G.offsetY)??0};W?S(W,at,F):L&&k(L,at,F)}function S(T,M,O){d(T,{...s.dropImageOptions,...M},O)}function k(T,M,O){f(T,{...s.dropTextOptions,...M},O)}function D(){s.manualReload||x(),i("reload")}return q.watch([()=>s.fileScale,()=>s.page,()=>s.file,()=>s.password],D),q.watch(h,T=>v(T),{immediate:!0}),q.watch(()=>s.closeSvgOptions,_,{immediate:!0}),n(b),t({reload:x,addImage:S,addText:k,clearActive:p,deleteCanvas:b,canvasRef:r}),(T,M)=>(q.openBlock(),q.createElementBlock("div",{style:q.normalizeStyle({transform:`scale(${h.value})`}),onDragover:M[0]||(M[0]=q.withModifiers(()=>{},["stop","prevent"])),onDragenter:M[1]||(M[1]=q.withModifiers(()=>{},["stop","prevent"])),onDrop:q.withModifiers(C,["stop","prevent"])},[q.createElementVNode("canvas",{id:o,ref_key:"canvasRef",ref:r,class:q.normalizeClass(T.canvasClass)},null,2)],36))}});nt.default=SC,nt.loadFile=zb,nt.useFabric=Wb,Object.defineProperties(nt,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
509
+ `)){const s=document.createElement("div");s.append(e?document.createTextNode(e):document.createElement("br")),this.editorDiv.append(s)}},zy=function(){return l(this,hs).replaceAll(" "," ")},Tp=function(e){return e.replaceAll(" "," ")},Vy=function(e){const{value:s,fontSize:i,color:n,pageIndex:r}=this._initialData;return this._hasBeenMoved||e.value!==s||e.fontSize!==i||e.color.some((o,h)=>o!==n[h])||e.pageIndex!==r},y(wt,fn),$(wt,"_freeTextDefaultContent",""),$(wt,"_internalPadding",0),$(wt,"_defaultColor",null),$(wt,"_defaultFontSize",10),$(wt,"_type","freetext"),$(wt,"_editorType",Z.FREETEXT);let Rg=wt;class B{toSVGPath(){vt("Abstract method `toSVGPath` must be implemented.")}get box(){vt("Abstract getter `box` must be implemented.")}serialize(t,e){vt("Abstract method `serialize` must be implemented.")}static _rescale(t,e,s,i,n,r){r||(r=new Float32Array(t.length));for(let o=0,h=t.length;o<h;o+=2)r[o]=e+t[o]*i,r[o+1]=s+t[o+1]*n;return r}static _rescaleAndSwap(t,e,s,i,n,r){r||(r=new Float32Array(t.length));for(let o=0,h=t.length;o<h;o+=2)r[o]=e+t[o+1]*i,r[o+1]=s+t[o]*n;return r}static _translate(t,e,s,i){i||(i=new Float32Array(t.length));for(let n=0,r=t.length;n<r;n+=2)i[n]=e+t[n],i[n+1]=s+t[n+1];return i}static svgRound(t){return Math.round(t*1e4)}static _normalizePoint(t,e,s,i,n){switch(n){case 90:return[1-e/s,t/i];case 180:return[1-t/s,1-e/i];case 270:return[e/s,1-t/i];default:return[t/s,e/i]}}static _normalizePagePoint(t,e,s){switch(s){case 90:return[1-e,t];case 180:return[1-t,1-e];case 270:return[e,1-t];default:return[t,e]}}static createBezierPoints(t,e,s,i,n,r){return[(t+5*s)/6,(e+5*i)/6,(5*s+n)/6,(5*i+r)/6,(s+n)/2,(i+r)/2]}}$(B,"PRECISION",1e-4);const gn=class gn{constructor({x:t,y:e},s,i,n,r,o=0){y(this,Jt);y(this,cs);y(this,Ks,[]);y(this,Xa);y(this,Wa);y(this,wi,[]);y(this,it,new Float32Array(18));y(this,So);y(this,Co);y(this,nc);y(this,rc);y(this,Ua);y(this,Ya);y(this,sr,[]);m(this,cs,s),m(this,Ya,n*i),m(this,Wa,r),l(this,it).set([NaN,NaN,NaN,NaN,t,e],6),m(this,Xa,o),m(this,rc,l(gn,oc)*i),m(this,nc,l(gn,xd)*i),m(this,Ua,i),l(this,sr).push(t,e)}isEmpty(){return isNaN(l(this,it)[8])}add({x:t,y:e}){var O;m(this,So,t),m(this,Co,e);const[s,i,n,r]=l(this,cs);let[o,h,c,u]=l(this,it).subarray(8,12);const d=t-c,f=e-u,g=Math.hypot(d,f);if(g<l(this,nc))return!1;const p=g-l(this,rc),b=p/g,v=b*d,_=b*f;let x=o,C=h;o=c,h=u,c+=v,u+=_,(O=l(this,sr))==null||O.push(t,e);const S=-_/p,k=v/p,D=S*l(this,Ya),A=k*l(this,Ya);return l(this,it).set(l(this,it).subarray(2,8),0),l(this,it).set([c+D,u+A],4),l(this,it).set(l(this,it).subarray(14,18),12),l(this,it).set([c-D,u-A],16),isNaN(l(this,it)[6])?(l(this,wi).length===0&&(l(this,it).set([o+D,h+A],2),l(this,wi).push(NaN,NaN,NaN,NaN,(o+D-s)/n,(h+A-i)/r),l(this,it).set([o-D,h-A],14),l(this,Ks).push(NaN,NaN,NaN,NaN,(o-D-s)/n,(h-A-i)/r)),l(this,it).set([x,C,o,h,c,u],6),!this.isEmpty()):(l(this,it).set([x,C,o,h,c,u],6),Math.abs(Math.atan2(C-h,x-o)-Math.atan2(_,v))<Math.PI/2?([o,h,c,u]=l(this,it).subarray(2,6),l(this,wi).push(NaN,NaN,NaN,NaN,((o+c)/2-s)/n,((h+u)/2-i)/r),[o,h,x,C]=l(this,it).subarray(14,18),l(this,Ks).push(NaN,NaN,NaN,NaN,((x+o)/2-s)/n,((C+h)/2-i)/r),!0):([x,C,o,h,c,u]=l(this,it).subarray(0,6),l(this,wi).push(((x+5*o)/6-s)/n,((C+5*h)/6-i)/r,((5*o+c)/6-s)/n,((5*h+u)/6-i)/r,((o+c)/2-s)/n,((h+u)/2-i)/r),[c,u,o,h,x,C]=l(this,it).subarray(12,18),l(this,Ks).push(((x+5*o)/6-s)/n,((C+5*h)/6-i)/r,((5*o+c)/6-s)/n,((5*h+u)/6-i)/r,((o+c)/2-s)/n,((h+u)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";const t=l(this,wi),e=l(this,Ks);if(isNaN(l(this,it)[6])&&!this.isEmpty())return w(this,Jt,Xy).call(this);const s=[];s.push(`M${t[4]} ${t[5]}`);for(let i=6;i<t.length;i+=6)isNaN(t[i])?s.push(`L${t[i+4]} ${t[i+5]}`):s.push(`C${t[i]} ${t[i+1]} ${t[i+2]} ${t[i+3]} ${t[i+4]} ${t[i+5]}`);w(this,Jt,Uy).call(this,s);for(let i=e.length-6;i>=6;i-=6)isNaN(e[i])?s.push(`L${e[i+4]} ${e[i+5]}`):s.push(`C${e[i]} ${e[i+1]} ${e[i+2]} ${e[i+3]} ${e[i+4]} ${e[i+5]}`);return w(this,Jt,Wy).call(this,s),s.join(" ")}newFreeDrawOutline(t,e,s,i,n,r){return new Nb(t,e,s,i,n,r)}getOutlines(){var d;const t=l(this,wi),e=l(this,Ks),s=l(this,it),[i,n,r,o]=l(this,cs),h=new Float32Array((((d=l(this,sr))==null?void 0:d.length)??0)+2);for(let f=0,g=h.length-2;f<g;f+=2)h[f]=(l(this,sr)[f]-i)/r,h[f+1]=(l(this,sr)[f+1]-n)/o;if(h[h.length-2]=(l(this,So)-i)/r,h[h.length-1]=(l(this,Co)-n)/o,isNaN(s[6])&&!this.isEmpty())return w(this,Jt,Yy).call(this,h);const c=new Float32Array(l(this,wi).length+24+l(this,Ks).length);let u=t.length;for(let f=0;f<u;f+=2){if(isNaN(t[f])){c[f]=c[f+1]=NaN;continue}c[f]=t[f],c[f+1]=t[f+1]}u=w(this,Jt,qy).call(this,c,u);for(let f=e.length-6;f>=6;f-=6)for(let g=0;g<6;g+=2){if(isNaN(e[f+g])){c[u]=c[u+1]=NaN,u+=2;continue}c[u]=e[f+g],c[u+1]=e[f+g+1],u+=2}return w(this,Jt,$y).call(this,c,u),this.newFreeDrawOutline(c,h,l(this,cs),l(this,Ua),l(this,Xa),l(this,Wa))}};cs=new WeakMap,Ks=new WeakMap,Xa=new WeakMap,Wa=new WeakMap,wi=new WeakMap,it=new WeakMap,So=new WeakMap,Co=new WeakMap,nc=new WeakMap,rc=new WeakMap,Ua=new WeakMap,Ya=new WeakMap,sr=new WeakMap,oc=new WeakMap,wd=new WeakMap,xd=new WeakMap,Jt=new WeakSet,Oc=function(){const t=l(this,it).subarray(4,6),e=l(this,it).subarray(16,18),[s,i,n,r]=l(this,cs);return[(l(this,So)+(t[0]-e[0])/2-s)/n,(l(this,Co)+(t[1]-e[1])/2-i)/r,(l(this,So)+(e[0]-t[0])/2-s)/n,(l(this,Co)+(e[1]-t[1])/2-i)/r]},Xy=function(){const[t,e,s,i]=l(this,cs),[n,r,o,h]=w(this,Jt,Oc).call(this);return`M${(l(this,it)[2]-t)/s} ${(l(this,it)[3]-e)/i} L${(l(this,it)[4]-t)/s} ${(l(this,it)[5]-e)/i} L${n} ${r} L${o} ${h} L${(l(this,it)[16]-t)/s} ${(l(this,it)[17]-e)/i} L${(l(this,it)[14]-t)/s} ${(l(this,it)[15]-e)/i} Z`},Wy=function(t){const e=l(this,Ks);t.push(`L${e[4]} ${e[5]} Z`)},Uy=function(t){const[e,s,i,n]=l(this,cs),r=l(this,it).subarray(4,6),o=l(this,it).subarray(16,18),[h,c,u,d]=w(this,Jt,Oc).call(this);t.push(`L${(r[0]-e)/i} ${(r[1]-s)/n} L${h} ${c} L${u} ${d} L${(o[0]-e)/i} ${(o[1]-s)/n}`)},Yy=function(t){const e=l(this,it),[s,i,n,r]=l(this,cs),[o,h,c,u]=w(this,Jt,Oc).call(this),d=new Float32Array(36);return d.set([NaN,NaN,NaN,NaN,(e[2]-s)/n,(e[3]-i)/r,NaN,NaN,NaN,NaN,(e[4]-s)/n,(e[5]-i)/r,NaN,NaN,NaN,NaN,o,h,NaN,NaN,NaN,NaN,c,u,NaN,NaN,NaN,NaN,(e[16]-s)/n,(e[17]-i)/r,NaN,NaN,NaN,NaN,(e[14]-s)/n,(e[15]-i)/r],0),this.newFreeDrawOutline(d,t,l(this,cs),l(this,Ua),l(this,Xa),l(this,Wa))},$y=function(t,e){const s=l(this,Ks);return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6},qy=function(t,e){const s=l(this,it).subarray(4,6),i=l(this,it).subarray(16,18),[n,r,o,h]=l(this,cs),[c,u,d,f]=w(this,Jt,Oc).call(this);return t.set([NaN,NaN,NaN,NaN,(s[0]-n)/o,(s[1]-r)/h,NaN,NaN,NaN,NaN,c,u,NaN,NaN,NaN,NaN,d,f,NaN,NaN,NaN,NaN,(i[0]-n)/o,(i[1]-r)/h],e),e+=24},y(gn,oc,8),y(gn,wd,2),y(gn,xd,l(gn,oc)+l(gn,wd));let id=gn;class Nb extends B{constructor(e,s,i,n,r,o){super();y(this,Sd);y(this,$a);y(this,Ao,new Float32Array(4));y(this,pn);y(this,ac);y(this,us);y(this,hc);y(this,Ht);m(this,Ht,e),m(this,us,s),m(this,$a,i),m(this,hc,n),m(this,pn,r),m(this,ac,o),this.lastPoint=[NaN,NaN],w(this,Sd,Ky).call(this,o);const[h,c,u,d]=l(this,Ao);for(let f=0,g=e.length;f<g;f+=2)e[f]=(e[f]-h)/u,e[f+1]=(e[f+1]-c)/d;for(let f=0,g=s.length;f<g;f+=2)s[f]=(s[f]-h)/u,s[f+1]=(s[f+1]-c)/d}toSVGPath(){const e=[`M${l(this,Ht)[4]} ${l(this,Ht)[5]}`];for(let s=6,i=l(this,Ht).length;s<i;s+=6){if(isNaN(l(this,Ht)[s])){e.push(`L${l(this,Ht)[s+4]} ${l(this,Ht)[s+5]}`);continue}e.push(`C${l(this,Ht)[s]} ${l(this,Ht)[s+1]} ${l(this,Ht)[s+2]} ${l(this,Ht)[s+3]} ${l(this,Ht)[s+4]} ${l(this,Ht)[s+5]}`)}return e.push("Z"),e.join(" ")}serialize([e,s,i,n],r){const o=i-e,h=n-s;let c,u;switch(r){case 0:c=B._rescale(l(this,Ht),e,n,o,-h),u=B._rescale(l(this,us),e,n,o,-h);break;case 90:c=B._rescaleAndSwap(l(this,Ht),e,s,o,h),u=B._rescaleAndSwap(l(this,us),e,s,o,h);break;case 180:c=B._rescale(l(this,Ht),i,s,-o,h),u=B._rescale(l(this,us),i,s,-o,h);break;case 270:c=B._rescaleAndSwap(l(this,Ht),i,n,-o,-h),u=B._rescaleAndSwap(l(this,us),i,n,-o,-h);break}return{outline:Array.from(c),points:[Array.from(u)]}}get box(){return l(this,Ao)}newOutliner(e,s,i,n,r,o=0){return new id(e,s,i,n,r,o)}getNewOutline(e,s){const[i,n,r,o]=l(this,Ao),[h,c,u,d]=l(this,$a),f=r*u,g=o*d,p=i*u+h,b=n*d+c,v=this.newOutliner({x:l(this,us)[0]*f+p,y:l(this,us)[1]*g+b},l(this,$a),l(this,hc),e,l(this,ac),s??l(this,pn));for(let _=2;_<l(this,us).length;_+=2)v.add({x:l(this,us)[_]*f+p,y:l(this,us)[_+1]*g+b});return v.getOutlines()}}$a=new WeakMap,Ao=new WeakMap,pn=new WeakMap,ac=new WeakMap,us=new WeakMap,hc=new WeakMap,Ht=new WeakMap,Sd=new WeakSet,Ky=function(e){const s=l(this,Ht);let i=s[4],n=s[5],r=i,o=n,h=i,c=n,u=i,d=n;const f=e?Math.max:Math.min;for(let p=6,b=s.length;p<b;p+=6){if(isNaN(s[p]))r=Math.min(r,s[p+4]),o=Math.min(o,s[p+5]),h=Math.max(h,s[p+4]),c=Math.max(c,s[p+5]),d<s[p+5]?(u=s[p+4],d=s[p+5]):d===s[p+5]&&(u=f(u,s[p+4]));else{const v=W.bezierBoundingBox(i,n,...s.slice(p,p+6));r=Math.min(r,v[0]),o=Math.min(o,v[1]),h=Math.max(h,v[2]),c=Math.max(c,v[3]),d<v[3]?(u=v[2],d=v[3]):d===v[3]&&(u=f(u,v[2]))}i=s[p+4],n=s[p+5]}const g=l(this,Ao);g[0]=r-l(this,pn),g[1]=o-l(this,pn),g[2]=h-r+2*l(this,pn),g[3]=c-o+2*l(this,pn),this.lastPoint=[u,d]};class Lg{constructor(t,e=0,s=0,i=!0){y(this,Ie);y(this,lc);y(this,cc);y(this,ir,[]);y(this,Qs,[]);let n=1/0,r=-1/0,o=1/0,h=-1/0;const c=10**-4;for(const{x:v,y:_,width:x,height:C}of t){const S=Math.floor((v-e)/c)*c,k=Math.ceil((v+x+e)/c)*c,D=Math.floor((_-e)/c)*c,A=Math.ceil((_+C+e)/c)*c,M=[S,D,A,!0],O=[k,D,A,!1];l(this,ir).push(M,O),n=Math.min(n,S),r=Math.max(r,k),o=Math.min(o,D),h=Math.max(h,A)}const u=r-n+2*s,d=h-o+2*s,f=n-s,g=o-s,p=l(this,ir).at(i?-1:-2),b=[p[0],p[2]];for(const v of l(this,ir)){const[_,x,C]=v;v[0]=(_-f)/u,v[1]=(x-g)/d,v[2]=(C-g)/d}m(this,lc,new Float32Array([f,g,u,d])),m(this,cc,b)}getOutlines(){l(this,ir).sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);const t=[];for(const e of l(this,ir))e[3]?(t.push(...w(this,Ie,Ep).call(this,e)),w(this,Ie,Jy).call(this,e)):(w(this,Ie,Zy).call(this,e),t.push(...w(this,Ie,Ep).call(this,e)));return w(this,Ie,Qy).call(this,t)}}lc=new WeakMap,cc=new WeakMap,ir=new WeakMap,Qs=new WeakMap,Ie=new WeakSet,Qy=function(t){const e=[],s=new Set;for(const r of t){const[o,h,c]=r;e.push([o,h,r],[o,c,r])}e.sort((r,o)=>r[1]-o[1]||r[0]-o[0]);for(let r=0,o=e.length;r<o;r+=2){const h=e[r][2],c=e[r+1][2];h.push(c),c.push(h),s.add(h),s.add(c)}const i=[];let n;for(;s.size>0;){const r=s.values().next().value;let[o,h,c,u,d]=r;s.delete(r);let f=o,g=h;for(n=[o,c],i.push(n);;){let p;if(s.has(u))p=u;else if(s.has(d))p=d;else break;s.delete(p),[o,h,c,u,d]=p,f!==o&&(n.push(f,g,o,g===h?h:c),f=o),g=g===h?c:h}n.push(f,g)}return new zS(i,l(this,lc),l(this,cc))},Yd=function(t){const e=l(this,Qs);let s=0,i=e.length-1;for(;s<=i;){const n=s+i>>1,r=e[n][0];if(r===t)return n;r<t?s=n+1:i=n-1}return i+1},Jy=function([,t,e]){const s=w(this,Ie,Yd).call(this,t);l(this,Qs).splice(s,0,[t,e])},Zy=function([,t,e]){const s=w(this,Ie,Yd).call(this,t);for(let i=s;i<l(this,Qs).length;i++){const[n,r]=l(this,Qs)[i];if(n!==t)break;if(n===t&&r===e){l(this,Qs).splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=l(this,Qs)[i];if(n!==t)break;if(n===t&&r===e){l(this,Qs).splice(i,1);return}}},Ep=function(t){const[e,s,i]=t,n=[[e,s,i]],r=w(this,Ie,Yd).call(this,i);for(let o=0;o<r;o++){const[h,c]=l(this,Qs)[o];for(let u=0,d=n.length;u<d;u++){const[,f,g]=n[u];if(!(c<=f||g<=h)){if(f>=h){if(g>c)n[u][1]=c;else{if(d===1)return[];n.splice(u,1),u--,d--}continue}n[u][2]=h,g>c&&n.push([e,c,g])}}}return n};class zS extends B{constructor(e,s,i){super();y(this,uc);y(this,qa);m(this,qa,e),m(this,uc,s),this.lastPoint=i}toSVGPath(){const e=[];for(const s of l(this,qa)){let[i,n]=s;e.push(`M${i} ${n}`);for(let r=2;r<s.length;r+=2){const o=s[r],h=s[r+1];o===i?(e.push(`V${h}`),n=h):h===n&&(e.push(`H${o}`),i=o)}e.push("Z")}return e.join(" ")}serialize([e,s,i,n],r){const o=[],h=i-e,c=n-s;for(const u of l(this,qa)){const d=new Array(u.length);for(let f=0;f<u.length;f+=2)d[f]=e+u[f]*h,d[f+1]=n-u[f+1]*c;o.push(d)}return o}get box(){return l(this,uc)}get classNamesForOutlining(){return["highlightOutline"]}}uc=new WeakMap,qa=new WeakMap;class Fg extends id{newFreeDrawOutline(t,e,s,i,n,r){return new VS(t,e,s,i,n,r)}}class VS extends Nb{newOutliner(t,e,s,i,n,r=0){return new Fg(t,e,s,i,n,r)}}const Ke=class Ke{constructor({editor:t=null,uiManager:e=null}){y(this,yt);y(this,Js,null);y(this,To,null);y(this,Ka);y(this,Zt,null);y(this,dc,!1);y(this,Qa,!1);y(this,fc,null);y(this,gc);y(this,nr,null);y(this,Zs,null);y(this,Ja);var s;t?(m(this,Qa,!1),m(this,Ja,ot.HIGHLIGHT_COLOR),m(this,fc,t)):(m(this,Qa,!0),m(this,Ja,ot.HIGHLIGHT_DEFAULT_COLOR)),m(this,Zs,(t==null?void 0:t._uiManager)||e),m(this,gc,l(this,Zs)._eventBus),m(this,Ka,(t==null?void 0:t.color)||((s=l(this,Zs))==null?void 0:s.highlightColors.values().next().value)||"#FFFF98"),l(Ke,pc)||m(Ke,pc,Object.freeze({blue:"pdfjs-editor-colorpicker-blue",green:"pdfjs-editor-colorpicker-green",pink:"pdfjs-editor-colorpicker-pink",red:"pdfjs-editor-colorpicker-red",yellow:"pdfjs-editor-colorpicker-yellow"}))}static get _keyboardManager(){return st(this,"_keyboardManager",new Xh([[["Escape","mac+Escape"],Ke.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],Ke.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],Ke.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],Ke.prototype._moveToPrevious],[["Home","mac+Home"],Ke.prototype._moveToBeginning],[["End","mac+End"],Ke.prototype._moveToEnd]]))}renderButton(){const t=m(this,Js,document.createElement("button"));t.className="colorPicker",t.tabIndex="0",t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-button"),t.setAttribute("aria-haspopup",!0);const e=l(this,Zs)._signal;t.addEventListener("click",w(this,yt,Go).bind(this),{signal:e}),t.addEventListener("keydown",w(this,yt,Pp).bind(this),{signal:e});const s=m(this,To,document.createElement("span"));return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=l(this,Ka),t.append(s),t}renderMainDropdown(){const t=m(this,Zt,w(this,yt,kp).call(this));return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}_colorSelectFromKeyboard(t){if(t.target===l(this,Js)){w(this,yt,Go).call(this,t);return}const e=t.target.getAttribute("data-color");e&&w(this,yt,Mp).call(this,e,t)}_moveToNext(t){var e,s;if(!l(this,yt,gr)){w(this,yt,Go).call(this,t);return}if(t.target===l(this,Js)){(e=l(this,Zt).firstChild)==null||e.focus();return}(s=t.target.nextSibling)==null||s.focus()}_moveToPrevious(t){var e,s;if(t.target===((e=l(this,Zt))==null?void 0:e.firstChild)||t.target===l(this,Js)){l(this,yt,gr)&&this._hideDropdownFromKeyboard();return}l(this,yt,gr)||w(this,yt,Go).call(this,t),(s=t.target.previousSibling)==null||s.focus()}_moveToBeginning(t){var e;if(!l(this,yt,gr)){w(this,yt,Go).call(this,t);return}(e=l(this,Zt).firstChild)==null||e.focus()}_moveToEnd(t){var e;if(!l(this,yt,gr)){w(this,yt,Go).call(this,t);return}(e=l(this,Zt).lastChild)==null||e.focus()}hideDropdown(){var t,e;(t=l(this,Zt))==null||t.classList.add("hidden"),(e=l(this,nr))==null||e.abort(),m(this,nr,null)}_hideDropdownFromKeyboard(){var t;if(!l(this,Qa)){if(!l(this,yt,gr)){(t=l(this,fc))==null||t.unselect();return}this.hideDropdown(),l(this,Js).focus({preventScroll:!0,focusVisible:l(this,dc)})}}updateColor(t){if(l(this,To)&&(l(this,To).style.backgroundColor=t),!l(this,Zt))return;const e=l(this,Zs).highlightColors.values();for(const s of l(this,Zt).children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){var t,e;(t=l(this,Js))==null||t.remove(),m(this,Js,null),m(this,To,null),(e=l(this,Zt))==null||e.remove(),m(this,Zt,null)}};Js=new WeakMap,To=new WeakMap,Ka=new WeakMap,Zt=new WeakMap,dc=new WeakMap,Qa=new WeakMap,fc=new WeakMap,gc=new WeakMap,nr=new WeakMap,Zs=new WeakMap,Ja=new WeakMap,pc=new WeakMap,yt=new WeakSet,kp=function(){const t=document.createElement("div"),e=l(this,Zs)._signal;t.addEventListener("contextmenu",Gs,{signal:e}),t.className="dropdown",t.role="listbox",t.setAttribute("aria-multiselectable",!1),t.setAttribute("aria-orientation","vertical"),t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown");for(const[s,i]of l(this,Zs).highlightColors){const n=document.createElement("button");n.tabIndex="0",n.role="option",n.setAttribute("data-color",i),n.title=s,n.setAttribute("data-l10n-id",l(Ke,pc)[s]);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===l(this,Ka)),n.addEventListener("click",w(this,yt,Mp).bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",w(this,yt,Pp).bind(this),{signal:e}),t},Mp=function(t,e){e.stopPropagation(),l(this,gc).dispatch("switchannotationeditorparams",{source:this,type:l(this,Ja),value:t})},Pp=function(t){Ke._keyboardManager.exec(this,t)},Go=function(t){if(l(this,yt,gr)){this.hideDropdown();return}if(m(this,dc,t.detail===0),l(this,nr)||(m(this,nr,new AbortController),window.addEventListener("pointerdown",w(this,yt,tv).bind(this),{signal:l(this,Zs).combinedSignal(l(this,nr))})),l(this,Zt)){l(this,Zt).classList.remove("hidden");return}const e=m(this,Zt,w(this,yt,kp).call(this));l(this,Js).append(e)},tv=function(t){var e;(e=l(this,Zt))!=null&&e.contains(t.target)||this.hideDropdown()},gr=function(){return l(this,Zt)&&!l(this,Zt).classList.contains("hidden")},y(Ke,pc,null);let nd=Ke;const ut=class ut extends Pt{constructor(e){super({...e,name:"highlightEditor"});y(this,J);y(this,Za,null);y(this,mc,0);y(this,mn);y(this,Eo,null);y(this,th,null);y(this,Qe,null);y(this,bc,null);y(this,yc,0);y(this,ko,null);y(this,Ts,null);y(this,ds,null);y(this,le,!1);y(this,eh,null);y(this,bn);y(this,Se,null);y(this,sh,"");y(this,Es);y(this,vc,"");this.color=e.color||ut._defaultColor,m(this,Es,e.thickness||ut._defaultThickness),m(this,bn,e.opacity||ut._defaultOpacity),m(this,mn,e.boxes||null),m(this,vc,e.methodOfCreation||""),m(this,sh,e.text||""),this._isDraggable=!1,e.highlightId>-1?(m(this,le,!0),w(this,J,$d).call(this,e),w(this,J,zo).call(this)):l(this,mn)&&(m(this,Za,e.anchorNode),m(this,mc,e.anchorOffset),m(this,bc,e.focusNode),m(this,yc,e.focusOffset),w(this,J,Dp).call(this),w(this,J,zo).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const e=ut.prototype;return st(this,"_keyboardManager",new Xh([[["ArrowLeft","mac+ArrowLeft"],e._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],e._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],e._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],e._moveCaret,{args:[3]}]]))}get telemetryInitialData(){return{action:"added",type:l(this,le)?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:l(this,Es),methodOfCreation:l(this,vc)}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.highlightColorNames.get(this.color)}}static computeTelemetryFinalData(e){return{numberOfColors:e.get("color").size}}static initialize(e,s){var i;Pt.initialize(e,s),ut._defaultColor||(ut._defaultColor=((i=s.highlightColors)==null?void 0:i.values().next().value)||"#fff066")}static updateDefaultParams(e,s){switch(e){case ot.HIGHLIGHT_DEFAULT_COLOR:ut._defaultColor=s;break;case ot.HIGHLIGHT_THICKNESS:ut._defaultThickness=s;break}}translateInPage(e,s){}get toolbarPosition(){return l(this,eh)}updateParams(e,s){switch(e){case ot.HIGHLIGHT_COLOR:w(this,J,ev).call(this,s);break;case ot.HIGHLIGHT_THICKNESS:w(this,J,sv).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[ot.HIGHLIGHT_DEFAULT_COLOR,ut._defaultColor],[ot.HIGHLIGHT_THICKNESS,ut._defaultThickness]]}get propertiesToUpdate(){return[[ot.HIGHLIGHT_COLOR,this.color||ut._defaultColor],[ot.HIGHLIGHT_THICKNESS,l(this,Es)||ut._defaultThickness],[ot.HIGHLIGHT_FREE,l(this,le)]]}async addEditToolbar(){const e=await super.addEditToolbar();return e?(this._uiManager.highlightColors&&(m(this,th,new nd({editor:this})),e.addColorPicker(l(this,th))),e):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(w(this,J,Rc).call(this))}getBaseTranslation(){return[0,0]}getRect(e,s){return super.getRect(e,s,w(this,J,Rc).call(this))}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),e&&this.div.focus()}remove(){w(this,J,Op).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,J,zo).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?w(this,J,Op).call(this):e&&(w(this,J,zo).call(this,e),s=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),this.show(this._isVisible),s&&this.select()}rotate(e){var n,r,o;const{drawLayer:s}=this.parent;let i;l(this,le)?(e=(e-this.rotation+360)%360,i=w(n=ut,ks,_h).call(n,l(this,Ts).box,e)):i=w(r=ut,ks,_h).call(r,[this.x,this.y,this.width,this.height],e),s.updateProperties(l(this,ds),{bbox:i,root:{"data-main-rotation":e}}),s.updateProperties(l(this,Se),{bbox:w(o=ut,ks,_h).call(o,l(this,Qe).box,e),root:{"data-main-rotation":e}})}render(){if(this.div)return this.div;const e=super.render();l(this,sh)&&(e.setAttribute("aria-label",l(this,sh)),e.setAttribute("role","mark")),l(this,le)?e.classList.add("free"):this.div.addEventListener("keydown",w(this,J,nv).bind(this),{signal:this._uiManager._signal});const s=m(this,ko,document.createElement("div"));e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",s.style.clipPath=l(this,Eo);const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),$u(this,l(this,ko),["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Se),{rootClass:{hovered:!0}})}pointerleave(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Se),{rootClass:{hovered:!1}})}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:w(this,J,qd).call(this,!0);break;case 1:case 3:w(this,J,qd).call(this,!1);break}}select(){var e;super.select(),l(this,Se)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Se),{rootClass:{hovered:!1,selected:!0}}))}unselect(){var e;super.unselect(),l(this,Se)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Se),{rootClass:{selected:!1}}),l(this,le)||w(this,J,qd).call(this,!1))}get _mustFixPosition(){return!l(this,le)}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.updateProperties(l(this,ds),{rootClass:{hidden:!e}}),this.parent.drawLayer.updateProperties(l(this,Se),{rootClass:{hidden:!e}}))}static startHighlighting(e,s,{target:i,x:n,y:r}){const{x:o,y:h,width:c,height:u}=i.getBoundingClientRect(),d=new AbortController,f=e.combinedSignal(d),g=p=>{d.abort(),w(this,ks,hv).call(this,e,p)};window.addEventListener("blur",g,{signal:f}),window.addEventListener("pointerup",g,{signal:f}),window.addEventListener("pointerdown",es,{capture:!0,passive:!1,signal:f}),window.addEventListener("contextmenu",Gs,{signal:f}),i.addEventListener("pointermove",w(this,ks,av).bind(this,e),{signal:f}),this._freeHighlight=new Fg({x:n,y:r},[o,h,c,u],e.scale,this._defaultThickness/2,s,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0)}static async deserialize(e,s,i){var b,v,_,x;let n=null;if(e instanceof Fb){const{data:{quadPoints:C,rect:S,rotation:k,id:D,color:A,opacity:M,popupRef:O},parent:{page:{pageNumber:R}}}=e;n=e={annotationType:Z.HIGHLIGHT,color:Array.from(A),opacity:M,quadPoints:C,boxes:null,pageIndex:R-1,rect:S.slice(0),rotation:k,id:D,deleted:!1,popupRef:O}}else if(e instanceof Og){const{data:{inkLists:C,rect:S,rotation:k,id:D,color:A,borderStyle:{rawWidth:M},popupRef:O},parent:{page:{pageNumber:R}}}=e;n=e={annotationType:Z.HIGHLIGHT,color:Array.from(A),thickness:M,inkLists:C,boxes:null,pageIndex:R-1,rect:S.slice(0),rotation:k,id:D,deleted:!1,popupRef:O}}const{color:r,quadPoints:o,inkLists:h,opacity:c}=e,u=await super.deserialize(e,s,i);u.color=W.makeHexColor(...r),m(u,bn,c||1),h&&m(u,Es,e.thickness),u.annotationElementId=e.id||null,u._initialData=n;const[d,f]=u.pageDimensions,[g,p]=u.pageTranslation;if(o){const C=m(u,mn,[]);for(let S=0;S<o.length;S+=8)C.push({x:(o[S]-g)/d,y:1-(o[S+1]-p)/f,width:(o[S+2]-o[S])/d,height:(o[S+1]-o[S+5])/f});w(b=u,J,Dp).call(b),w(v=u,J,zo).call(v),u.rotate(u.rotation)}else if(h){m(u,le,!0);const C=h[0],S={x:C[0]-g,y:f-(C[1]-p)},k=new Fg(S,[0,0,d,f],1,l(u,Es)/2,!0,.001);for(let M=0,O=C.length;M<O;M+=2)S.x=C[M]-g,S.y=f-(C[M+1]-p),k.add(S);const{id:D,clipPathId:A}=s.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:u.color,"fill-opacity":u._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:k.toSVGPath()}},!0,!0);w(_=u,J,$d).call(_,{highlightOutlines:k.getOutlines(),highlightId:D,clipPathId:A}),w(x=u,J,zo).call(x)}return u}serialize(e=!1){if(this.isEmpty()||e)return null;if(this.deleted)return this.serializeDeleted();const s=this.getRect(0,0),i=Pt._colorManager.convert(this.color),n={annotationType:Z.HIGHLIGHT,color:i,opacity:l(this,bn),thickness:l(this,Es),quadPoints:w(this,J,rv).call(this),outlines:w(this,J,ov).call(this,s),pageIndex:this.pageIndex,rect:s,rotation:w(this,J,Rc).call(this),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!w(this,J,lv).call(this,n)?null:(n.id=this.annotationElementId,n)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};Za=new WeakMap,mc=new WeakMap,mn=new WeakMap,Eo=new WeakMap,th=new WeakMap,Qe=new WeakMap,bc=new WeakMap,yc=new WeakMap,ko=new WeakMap,Ts=new WeakMap,ds=new WeakMap,le=new WeakMap,eh=new WeakMap,bn=new WeakMap,Se=new WeakMap,sh=new WeakMap,Es=new WeakMap,vc=new WeakMap,J=new WeakSet,Dp=function(){const e=new Lg(l(this,mn),.001);m(this,Ts,e.getOutlines()),[this.x,this.y,this.width,this.height]=l(this,Ts).box;const s=new Lg(l(this,mn),.0025,.001,this._uiManager.direction==="ltr");m(this,Qe,s.getOutlines());const{lastPoint:i}=l(this,Qe);m(this,eh,[(i[0]-this.x)/this.width,(i[1]-this.y)/this.height])},$d=function({highlightOutlines:e,highlightId:s,clipPathId:i}){var d,f;if(m(this,Ts,e),m(this,Qe,e.getNewOutline(l(this,Es)/2+1.5,.0025)),s>=0)m(this,ds,s),m(this,Eo,i),this.parent.drawLayer.finalizeDraw(s,{bbox:e.box,path:{d:e.toSVGPath()}}),m(this,Se,this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:l(this,Qe).box,path:{d:l(this,Qe).toSVGPath()}},!0));else if(this.parent){const g=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(l(this,ds),{bbox:w(d=ut,ks,_h).call(d,l(this,Ts).box,(g-this.rotation+360)%360),path:{d:e.toSVGPath()}}),this.parent.drawLayer.updateProperties(l(this,Se),{bbox:w(f=ut,ks,_h).call(f,l(this,Qe).box,g),path:{d:l(this,Qe).toSVGPath()}})}const[r,o,h,c]=e.box;switch(this.rotation){case 0:this.x=r,this.y=o,this.width=h,this.height=c;break;case 90:{const[g,p]=this.parentDimensions;this.x=o,this.y=1-r,this.width=h*p/g,this.height=c*g/p;break}case 180:this.x=1-r,this.y=1-o,this.width=h,this.height=c;break;case 270:{const[g,p]=this.parentDimensions;this.x=1-o,this.y=r,this.width=h*p/g,this.height=c*g/p;break}}const{lastPoint:u}=l(this,Qe);m(this,eh,[(u[0]-r)/h,(u[1]-o)/c])},ev=function(e){const s=(r,o)=>{var h,c;this.color=r,m(this,bn,o),(h=this.parent)==null||h.drawLayer.updateProperties(l(this,ds),{root:{fill:r,"fill-opacity":o}}),(c=l(this,th))==null||c.updateColor(r)},i=this.color,n=l(this,bn);this.addCommands({cmd:s.bind(this,e,ut._defaultOpacity),undo:s.bind(this,i,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:ot.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(e)},!0)},sv=function(e){const s=l(this,Es),i=n=>{m(this,Es,n),w(this,J,iv).call(this,n)};this.addCommands({cmd:i.bind(this,e),undo:i.bind(this,s),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:ot.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)},iv=function(e){if(!l(this,le))return;w(this,J,$d).call(this,{highlightOutlines:l(this,Ts).getNewOutline(e/2)}),this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)},Op=function(){l(this,ds)===null||!this.parent||(this.parent.drawLayer.remove(l(this,ds)),m(this,ds,null),this.parent.drawLayer.remove(l(this,Se)),m(this,Se,null))},zo=function(e=this.parent){l(this,ds)===null&&({id:Ge(this,ds)._,clipPathId:Ge(this,Eo)._}=e.drawLayer.draw({bbox:l(this,Ts).box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":l(this,bn)},rootClass:{highlight:!0,free:l(this,le)},path:{d:l(this,Ts).toSVGPath()}},!1,!0),m(this,Se,e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:l(this,le)},bbox:l(this,Qe).box,path:{d:l(this,Qe).toSVGPath()}},l(this,le))),l(this,ko)&&(l(this,ko).style.clipPath=l(this,Eo)))},ks=new WeakSet,_h=function([e,s,i,n],r){switch(r){case 90:return[1-s-n,e,n,i];case 180:return[1-e-i,1-s-n,i,n];case 270:return[s,1-e-i,n,i]}return[e,s,i,n]},nv=function(e){ut._keyboardManager.exec(this,e)},qd=function(e){if(!l(this,Za))return;const s=window.getSelection();e?s.setPosition(l(this,Za),l(this,mc)):s.setPosition(l(this,bc),l(this,yc))},Rc=function(){return l(this,le)?this.rotation:0},rv=function(){if(l(this,le))return null;const[e,s]=this.pageDimensions,[i,n]=this.pageTranslation,r=l(this,mn),o=new Float32Array(r.length*8);let h=0;for(const{x:c,y:u,width:d,height:f}of r){const g=c*e+i,p=(1-u)*s+n;o[h]=o[h+4]=g,o[h+1]=o[h+3]=p,o[h+2]=o[h+6]=g+d*e,o[h+5]=o[h+7]=p-f*s,h+=8}return o},ov=function(e){return l(this,Ts).serialize(e,w(this,J,Rc).call(this))},av=function(e,s){this._freeHighlight.add(s)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})},hv=function(e,s){this._freeHighlight.isEmpty()?e.drawLayer.remove(this._freeHighlightId):e.createAndAddNewEditor(s,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:"main_toolbar"}),this._freeHighlightId=-1,this._freeHighlight=null,this._freeHighlightClipId=""},lv=function(e){const{color:s}=this._initialData;return e.color.some((i,n)=>i!==s[n])},y(ut,ks),$(ut,"_defaultColor",null),$(ut,"_defaultOpacity",1),$(ut,"_defaultThickness",12),$(ut,"_type","highlight"),$(ut,"_editorType",Z.HIGHLIGHT),$(ut,"_freeHighlightId",-1),$(ut,"_freeHighlight",null),$(ut,"_freeHighlightClipId","");let rd=ut;class XS{constructor(){y(this,Mo,Object.create(null))}updateProperty(t,e){this[t]=e,this.updateSVGProperty(t,e)}updateProperties(t){if(t)for(const[e,s]of Object.entries(t))this.updateProperty(e,s)}updateSVGProperty(t,e){l(this,Mo)[t]=e}toSVGProperties(){const t=l(this,Mo);return m(this,Mo,Object.create(null)),{root:t}}reset(){m(this,Mo,Object.create(null))}updateAll(t=this){this.updateProperties(t)}clone(){vt("Not implemented")}}Mo=new WeakMap;const H=class H extends Pt{constructor(e){super(e);y(this,lt);y(this,fs,null);y(this,ih);$(this,"_drawId",null);m(this,ih,e.mustBeCommitted||!1),e.drawOutlines&&(w(this,lt,Rp).call(this,e),w(this,lt,Lc).call(this))}static _mergeSVGProperties(e,s){const i=new Set(Object.keys(e));for(const[n,r]of Object.entries(s))i.has(n)?Object.assign(e[n],r):e[n]=r;return e}static getDefaultDrawingOptions(e){vt("Not implemented")}static get typesMap(){vt("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(e,s){const i=this.typesMap.get(e);i&&this._defaultDrawingOptions.updateProperty(i,s),this._currentParent&&(l(H,ne).updateProperty(i,s),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(e,s){const i=this.constructor.typesMap.get(e);i&&this._updateProperty(e,i,s)}static get defaultPropertiesToUpdate(){const e=[],s=this._defaultDrawingOptions;for(const[i,n]of this.typesMap)e.push([i,s[n]]);return e}get propertiesToUpdate(){const e=[],{_drawingOptions:s}=this;for(const[i,n]of this.constructor.typesMap)e.push([i,s[n]]);return e}_updateProperty(e,s,i){const n=this._drawingOptions,r=n[s],o=h=>{var u;n.updateProperty(s,h);const c=l(this,fs).updateProperty(s,h);c&&w(this,lt,Fc).call(this,c),(u=this.parent)==null||u.drawLayer.updateProperties(this._drawId,n.toSVGProperties())};this.addCommands({cmd:o.bind(this,i),undo:o.bind(this,r),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:e,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,H._mergeSVGProperties(l(this,fs).getPathResizingSVGProperties(w(this,lt,Kd).call(this)),{bbox:w(this,lt,wh).call(this)}))}_onResized(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,H._mergeSVGProperties(l(this,fs).getPathResizedSVGProperties(w(this,lt,Kd).call(this)),{bbox:w(this,lt,wh).call(this)}))}_onTranslating(e,s){var i;(i=this.parent)==null||i.drawLayer.updateProperties(this._drawId,{bbox:w(this,lt,wh).call(this,e,s)})}_onTranslated(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,H._mergeSVGProperties(l(this,fs).getPathTranslatedSVGProperties(w(this,lt,Kd).call(this),this.parentDimensions),{bbox:w(this,lt,wh).call(this)}))}_onStartDragging(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}commit(){super.commit(),this.disableEditMode(),this.disableEditing()}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),this._isDraggable=!0,l(this,ih)&&(m(this,ih,!1),this.commit(),this.parent.setSelected(this),e&&this.isOnScreen&&this.div.focus())}remove(){w(this,lt,Fp).call(this),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,lt,Lc).call(this),w(this,lt,Fc).call(this,l(this,fs).box),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?(this._uiManager.removeShouldRescale(this),w(this,lt,Fp).call(this)):e&&(this._uiManager.addShouldRescale(this),w(this,lt,Lc).call(this,e),s=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),s&&this.select()}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,H._mergeSVGProperties({bbox:w(this,lt,wh).call(this)},l(this,fs).updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&w(this,lt,Fc).call(this,l(this,fs).updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;const e=super.render();e.classList.add("draw");const s=document.createElement("div");e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal";const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),this._uiManager.addShouldRescale(this),this.disableEditing(),e}static createDrawerInstance(e,s,i,n,r){vt("Not implemented")}static startDrawing(e,s,i,n){var v;const{target:r,offsetX:o,offsetY:h,pointerId:c,pointerType:u}=n;if(l(H,or)&&l(H,or)!==u)return;const{viewport:{rotation:d}}=e,{width:f,height:g}=r.getBoundingClientRect(),p=m(H,Po,new AbortController),b=e.combinedSignal(p);if(l(H,rr)||m(H,rr,c),l(H,or)??m(H,or,u),window.addEventListener("pointerup",_=>{var x;l(H,rr)===_.pointerId?this._endDraw(_):(x=l(H,ar))==null||x.delete(_.pointerId)},{signal:b}),window.addEventListener("pointercancel",_=>{var x;l(H,rr)===_.pointerId?this._currentParent.endDrawingSession():(x=l(H,ar))==null||x.delete(_.pointerId)},{signal:b}),window.addEventListener("pointerdown",_=>{l(H,or)===_.pointerType&&((l(H,ar)||m(H,ar,new Set)).add(_.pointerId),l(H,ne).isCancellable()&&(l(H,ne).removeLastElement(),l(H,ne).isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:b}),window.addEventListener("contextmenu",Gs,{signal:b}),r.addEventListener("pointermove",this._drawMove.bind(this),{signal:b}),r.addEventListener("touchmove",_=>{_.timeStamp===l(H,Oo)&&es(_)},{signal:b}),e.toggleDrawing(),(v=s._editorUndoBar)==null||v.hide(),l(H,ne)){e.drawLayer.updateProperties(this._currentDrawId,l(H,ne).startNew(o,h,f,g,d));return}s.updateUIForDefaultProperties(this),m(H,ne,this.createDrawerInstance(o,h,f,g,d)),m(H,Do,this.getDefaultDrawingOptions()),this._currentParent=e,{id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties(l(H,Do).toSVGProperties(),l(H,ne).defaultSVGProperties),!0,!1)}static _drawMove(e){var r;if(m(H,Oo,-1),!l(H,ne))return;const{offsetX:s,offsetY:i,pointerId:n}=e;if(l(H,rr)===n){if(((r=l(H,ar))==null?void 0:r.size)>=1){this._endDraw(e);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,l(H,ne).add(s,i)),m(H,Oo,e.timeStamp),es(e)}}static _cleanup(e){e&&(this._currentDrawId=-1,this._currentParent=null,m(H,ne,null),m(H,Do,null),m(H,or,null),m(H,Oo,NaN)),l(H,Po)&&(l(H,Po).abort(),m(H,Po,null),m(H,rr,NaN),m(H,ar,null))}static _endDraw(e){const s=this._currentParent;if(s){if(s.toggleDrawing(!0),this._cleanup(!1),e&&s.drawLayer.updateProperties(this._currentDrawId,l(H,ne).end(e.offsetX,e.offsetY)),this.supportMultipleDrawings){const i=l(H,ne),n=this._currentDrawId,r=i.getLastElement();s.addCommands({cmd:()=>{s.drawLayer.updateProperties(n,i.setLastElement(r))},undo:()=>{s.drawLayer.updateProperties(n,i.removeLastElement())},mustExec:!1,type:ot.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(e){const s=this._currentParent;if(!s)return null;if(s.toggleDrawing(!0),s.cleanUndoStack(ot.DRAW_STEP),!l(H,ne).isEmpty()){const{pageDimensions:[i,n],scale:r}=s,o=s.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:l(H,ne).getOutlines(i*r,n*r,r,this._INNER_MARGIN),drawingOptions:l(H,Do),mustBeCommitted:!e});return this._cleanup(!0),o}return s.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(e){}static deserializeDraw(e,s,i,n,r,o){vt("Not implemented")}static async deserialize(e,s,i){var d,f;const{rawDims:{pageWidth:n,pageHeight:r,pageX:o,pageY:h}}=s.viewport,c=this.deserializeDraw(o,h,n,r,this._INNER_MARGIN,e),u=await super.deserialize(e,s,i);return u.createDrawingOptions(e),w(d=u,lt,Rp).call(d,{drawOutlines:c}),w(f=u,lt,Lc).call(f),u.onScaleChanging(),u.rotate(),u}serializeDraw(e){const[s,i]=this.pageTranslation,[n,r]=this.pageDimensions;return l(this,fs).serialize([s,i,n,r],e)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};fs=new WeakMap,ih=new WeakMap,ne=new WeakMap,Po=new WeakMap,Do=new WeakMap,rr=new WeakMap,or=new WeakMap,ar=new WeakMap,Oo=new WeakMap,lt=new WeakSet,Rp=function({drawOutlines:e,drawId:s,drawingOptions:i}){m(this,fs,e),this._drawingOptions||(this._drawingOptions=i),s>=0?(this._drawId=s,this.parent.drawLayer.finalizeDraw(s,e.defaultProperties)):this._drawId=w(this,lt,Lp).call(this,e,this.parent),w(this,lt,Fc).call(this,e.box)},Lp=function(e,s){const{id:i}=s.drawLayer.draw(H._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return i},Fp=function(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())},Lc=function(e=this.parent){if(!(this._drawId!==null&&this.parent===e)){if(this._drawId!==null){this.parent.drawLayer.updateParent(this._drawId,e.drawLayer);return}this._drawingOptions.updateAll(),this._drawId=w(this,lt,Lp).call(this,l(this,fs),e)}},cv=function([e,s,i,n]){const{parentDimensions:[r,o],rotation:h}=this;switch(h){case 90:return[s,1-e,i*(o/r),n*(r/o)];case 180:return[1-e,1-s,i,n];case 270:return[1-s,e,i*(o/r),n*(r/o)];default:return[e,s,i,n]}},Kd=function(){const{x:e,y:s,width:i,height:n,parentDimensions:[r,o],rotation:h}=this;switch(h){case 90:return[1-s,e,i*(r/o),n*(o/r)];case 180:return[1-e,1-s,i,n];case 270:return[s,1-e,i*(r/o),n*(o/r)];default:return[e,s,i,n]}},Fc=function(e){if([this.x,this.y,this.width,this.height]=w(this,lt,cv).call(this,e),this.div){this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)}this._onResized()},wh=function(){const{x:e,y:s,width:i,height:n,rotation:r,parentRotation:o,parentDimensions:[h,c]}=this;switch((r*4+o)/90){case 1:return[1-s-n,e,n,i];case 2:return[1-e-i,1-s-n,i,n];case 3:return[s,1-e-i,n,i];case 4:return[e,s-i*(h/c),n*(c/h),i*(h/c)];case 5:return[1-s,e,i*(h/c),n*(c/h)];case 6:return[1-e-n*(c/h),1-s,n*(c/h),i*(h/c)];case 7:return[s-i*(h/c),1-e-n*(c/h),i*(h/c),n*(c/h)];case 8:return[e-i,s-n,i,n];case 9:return[1-s,e-i,n,i];case 10:return[1-e,1-s,i,n];case 11:return[s-n,1-e,n,i];case 12:return[e-n*(c/h),s,n*(c/h),i*(h/c)];case 13:return[1-s-i*(h/c),e-n*(c/h),i*(h/c),n*(c/h)];case 14:return[1-e,1-s-i*(h/c),n*(c/h),i*(h/c)];case 15:return[s,1-e,i*(h/c),n*(c/h)];default:return[e,s,i,n]}},$(H,"_currentDrawId",-1),$(H,"_currentParent",null),y(H,ne,null),y(H,Po,null),y(H,Do,null),y(H,rr,NaN),y(H,or,null),y(H,ar,null),y(H,Oo,NaN),$(H,"_INNER_MARGIN",3);let Ig=H;class WS{constructor(t,e,s,i,n,r){y(this,rh);y(this,xi,new Float64Array(6));y(this,re);y(this,oe);y(this,Ro);y(this,nh);y(this,Ne);y(this,ce,"");y(this,Ms,0);y(this,Lo,new od);y(this,Fo);y(this,Io);m(this,Fo,s),m(this,Io,i),m(this,Ro,n),m(this,nh,r),[t,e]=w(this,rh,Qd).call(this,t,e);const o=m(this,re,[NaN,NaN,NaN,NaN,t,e]);m(this,Ne,[t,e]),m(this,oe,[{line:o,points:l(this,Ne)}]),l(this,xi).set(o,0)}updateProperty(t,e){t==="stroke-width"&&m(this,nh,e)}isEmpty(){return!l(this,oe)||l(this,oe).length===0}isCancellable(){return l(this,Ne).length<=10}add(t,e){[t,e]=w(this,rh,Qd).call(this,t,e);const[s,i,n,r]=l(this,xi).subarray(2,6),o=t-n,h=e-r;return Math.hypot(l(this,Fo)*o,l(this,Io)*h)<=2?null:(l(this,Ne).push(t,e),isNaN(s)?(l(this,xi).set([n,r,t,e],2),l(this,re).push(NaN,NaN,NaN,NaN,t,e),{path:{d:this.toSVGPath()}}):(isNaN(l(this,xi)[0])&&l(this,re).splice(6,6),l(this,xi).set([s,i,n,r,t,e],0),l(this,re).push(...B.createBezierPoints(s,i,n,r,t,e)),{path:{d:this.toSVGPath()}}))}end(t,e){const s=this.add(t,e);return s||(l(this,Ne).length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,s,i,n){m(this,Fo,s),m(this,Io,i),m(this,Ro,n),[t,e]=w(this,rh,Qd).call(this,t,e);const r=m(this,re,[NaN,NaN,NaN,NaN,t,e]);m(this,Ne,[t,e]);const o=l(this,oe).at(-1);return o&&(o.line=new Float32Array(o.line),o.points=new Float32Array(o.points)),l(this,oe).push({line:r,points:l(this,Ne)}),l(this,xi).set(r,0),m(this,Ms,0),this.toSVGPath(),null}getLastElement(){return l(this,oe).at(-1)}setLastElement(t){return l(this,oe)?(l(this,oe).push(t),m(this,re,t.line),m(this,Ne,t.points),m(this,Ms,0),{path:{d:this.toSVGPath()}}):l(this,Lo).setLastElement(t)}removeLastElement(){if(!l(this,oe))return l(this,Lo).removeLastElement();l(this,oe).pop(),m(this,ce,"");for(let t=0,e=l(this,oe).length;t<e;t++){const{line:s,points:i}=l(this,oe)[t];m(this,re,s),m(this,Ne,i),m(this,Ms,0),this.toSVGPath()}return{path:{d:l(this,ce)}}}toSVGPath(){const t=B.svgRound(l(this,re)[4]),e=B.svgRound(l(this,re)[5]);if(l(this,Ne).length===2)return m(this,ce,`${l(this,ce)} M ${t} ${e} Z`),l(this,ce);if(l(this,Ne).length<=6){const i=l(this,ce).lastIndexOf("M");m(this,ce,`${l(this,ce).slice(0,i)} M ${t} ${e}`),m(this,Ms,6)}if(l(this,Ne).length===4){const i=B.svgRound(l(this,re)[10]),n=B.svgRound(l(this,re)[11]);return m(this,ce,`${l(this,ce)} L ${i} ${n}`),m(this,Ms,12),l(this,ce)}const s=[];l(this,Ms)===0&&(s.push(`M ${t} ${e}`),m(this,Ms,6));for(let i=l(this,Ms),n=l(this,re).length;i<n;i+=6){const[r,o,h,c,u,d]=l(this,re).slice(i,i+6).map(B.svgRound);s.push(`C${r} ${o} ${h} ${c} ${u} ${d}`)}return m(this,ce,l(this,ce)+s.join(" ")),m(this,Ms,l(this,re).length),l(this,ce)}getOutlines(t,e,s,i){const n=l(this,oe).at(-1);return n.line=new Float32Array(n.line),n.points=new Float32Array(n.points),l(this,Lo).build(l(this,oe),t,e,s,l(this,Ro),l(this,nh),i),m(this,xi,null),m(this,re,null),m(this,oe,null),m(this,ce,null),l(this,Lo)}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}xi=new WeakMap,re=new WeakMap,oe=new WeakMap,Ro=new WeakMap,nh=new WeakMap,Ne=new WeakMap,ce=new WeakMap,Ms=new WeakMap,Lo=new WeakMap,Fo=new WeakMap,Io=new WeakMap,rh=new WeakSet,Qd=function(t,e){return B._normalizePoint(t,e,l(this,Fo),l(this,Io),l(this,Ro))};const Ug=class Ug extends B{constructor(){super(...arguments);y(this,ue);y(this,je);y(this,_c,0);y(this,wc);y(this,gs);y(this,Si);y(this,Ci);y(this,oh);y(this,ah);y(this,hh)}build(e,s,i,n,r,o,h){m(this,Si,s),m(this,Ci,i),m(this,oh,n),m(this,ah,r),m(this,hh,o),m(this,wc,h??0),m(this,gs,e),w(this,ue,dv).call(this)}setLastElement(e){return l(this,gs).push(e),{path:{d:this.toSVGPath()}}}removeLastElement(){return l(this,gs).pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const e=[];for(const{line:s}of l(this,gs)){if(e.push(`M${B.svgRound(s[4])} ${B.svgRound(s[5])}`),s.length===6){e.push("Z");continue}if(s.length===12){e.push(`L${B.svgRound(s[10])} ${B.svgRound(s[11])}`);continue}for(let i=6,n=s.length;i<n;i+=6){const[r,o,h,c,u,d]=s.subarray(i,i+6).map(B.svgRound);e.push(`C${r} ${o} ${h} ${c} ${u} ${d}`)}}return e.join("")}serialize([e,s,i,n],r){const o=[],h=[],[c,u,d,f]=w(this,ue,uv).call(this);let g,p,b,v,_,x,C,S,k;switch(l(this,ah)){case 0:k=B._rescale,g=e,p=s+n,b=i,v=-n,_=e+c*i,x=s+(1-u-f)*n,C=e+(c+d)*i,S=s+(1-u)*n;break;case 90:k=B._rescaleAndSwap,g=e,p=s,b=i,v=n,_=e+u*i,x=s+c*n,C=e+(u+f)*i,S=s+(c+d)*n;break;case 180:k=B._rescale,g=e+i,p=s,b=-i,v=n,_=e+(1-c-d)*i,x=s+u*n,C=e+(1-c)*i,S=s+(u+f)*n;break;case 270:k=B._rescaleAndSwap,g=e+i,p=s+n,b=-i,v=-n,_=e+(1-u-f)*i,x=s+(1-c-d)*n,C=e+(1-u)*i,S=s+(1-c)*n;break}for(const{line:D,points:A}of l(this,gs))o.push(k(D,g,p,b,v,r?new Array(D.length):null)),h.push(k(A,g,p,b,v,r?new Array(A.length):null));return{lines:o,points:h,rect:[_,x,C,S]}}static deserialize(e,s,i,n,r,{paths:{lines:o,points:h},rotation:c,thickness:u}){const d=[];let f,g,p,b,v;switch(c){case 0:v=B._rescale,f=-e/i,g=s/n+1,p=1/i,b=-1/n;break;case 90:v=B._rescaleAndSwap,f=-s/n,g=-e/i,p=1/n,b=1/i;break;case 180:v=B._rescale,f=e/i+1,g=-s/n,p=-1/i,b=1/n;break;case 270:v=B._rescaleAndSwap,f=s/n+1,g=e/i+1,p=-1/n,b=-1/i;break}if(!o){o=[];for(const x of h){const C=x.length;if(C===2){o.push(new Float32Array([NaN,NaN,NaN,NaN,x[0],x[1]]));continue}if(C===4){o.push(new Float32Array([NaN,NaN,NaN,NaN,x[0],x[1],NaN,NaN,NaN,NaN,x[2],x[3]]));continue}const S=new Float32Array(3*(C-2));o.push(S);let[k,D,A,M]=x.subarray(0,4);S.set([NaN,NaN,NaN,NaN,k,D],0);for(let O=4;O<C;O+=2){const R=x[O],L=x[O+1];S.set(B.createBezierPoints(k,D,A,M,R,L),(O-2)*3),[k,D,A,M]=[A,M,R,L]}}}for(let x=0,C=o.length;x<C;x++)d.push({line:v(o[x].map(S=>S??NaN),f,g,p,b),points:v(h[x].map(S=>S??NaN),f,g,p,b)});const _=new Ug;return _.build(d,i,n,1,c,u,r),_}get box(){return l(this,je)}updateProperty(e,s){return e==="stroke-width"?w(this,ue,fv).call(this,s):null}updateParentDimensions([e,s],i){const[n,r]=w(this,ue,Sn).call(this);m(this,Si,e),m(this,Ci,s),m(this,oh,i);const[o,h]=w(this,ue,Sn).call(this),c=o-n,u=h-r,d=l(this,je);return d[0]-=c,d[1]-=u,d[2]+=2*c,d[3]+=2*u,d}updateRotation(e){return m(this,_c,e),{path:{transform:this.rotationTransform}}}get viewBox(){return l(this,je).map(B.svgRound).join(" ")}get defaultProperties(){const[e,s]=l(this,je);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${B.svgRound(e)} ${B.svgRound(s)}`}}}get rotationTransform(){const[,,e,s]=l(this,je);let i=0,n=0,r=0,o=0,h=0,c=0;switch(l(this,_c)){case 90:n=s/e,r=-e/s,h=e;break;case 180:i=-1,o=-1,h=e,c=s;break;case 270:n=-s/e,r=e/s,c=s;break;default:return""}return`matrix(${i} ${n} ${r} ${o} ${B.svgRound(h)} ${B.svgRound(c)})`}getPathResizingSVGProperties([e,s,i,n]){const[r,o]=w(this,ue,Sn).call(this),[h,c,u,d]=l(this,je);if(Math.abs(u-r)<=B.PRECISION||Math.abs(d-o)<=B.PRECISION){const v=e+i/2-(h+u/2),_=s+n/2-(c+d/2);return{path:{"transform-origin":`${B.svgRound(e)} ${B.svgRound(s)}`,transform:`${this.rotationTransform} translate(${v} ${_})`}}}const f=(i-2*r)/(u-2*r),g=(n-2*o)/(d-2*o),p=u/i,b=d/n;return{path:{"transform-origin":`${B.svgRound(h)} ${B.svgRound(c)}`,transform:`${this.rotationTransform} scale(${p} ${b}) translate(${B.svgRound(r)} ${B.svgRound(o)}) scale(${f} ${g}) translate(${B.svgRound(-r)} ${B.svgRound(-o)})`}}}getPathResizedSVGProperties([e,s,i,n]){const[r,o]=w(this,ue,Sn).call(this),h=l(this,je),[c,u,d,f]=h;if(h[0]=e,h[1]=s,h[2]=i,h[3]=n,Math.abs(d-r)<=B.PRECISION||Math.abs(f-o)<=B.PRECISION){const _=e+i/2-(c+d/2),x=s+n/2-(u+f/2);for(const{line:C,points:S}of l(this,gs))B._translate(C,_,x,C),B._translate(S,_,x,S);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${B.svgRound(e)} ${B.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const g=(i-2*r)/(d-2*r),p=(n-2*o)/(f-2*o),b=-g*(c+r)+e+r,v=-p*(u+o)+s+o;if(g!==1||p!==1||b!==0||v!==0)for(const{line:_,points:x}of l(this,gs))B._rescale(_,b,v,g,p,_),B._rescale(x,b,v,g,p,x);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${B.svgRound(e)} ${B.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,s],i){const[n,r]=i,o=l(this,je),h=e-o[0],c=s-o[1];if(l(this,Si)===n&&l(this,Ci)===r)for(const{line:u,points:d}of l(this,gs))B._translate(u,h,c,u),B._translate(d,h,c,d);else{const u=l(this,Si)/n,d=l(this,Ci)/r;m(this,Si,n),m(this,Ci,r);for(const{line:f,points:g}of l(this,gs))B._rescale(f,h,c,u,d,f),B._rescale(g,h,c,u,d,g);o[2]*=u,o[3]*=d}return o[0]=e,o[1]=s,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${B.svgRound(e)} ${B.svgRound(s)}`}}}get defaultSVGProperties(){const e=l(this,je);return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${B.svgRound(e[0])} ${B.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}};je=new WeakMap,_c=new WeakMap,wc=new WeakMap,gs=new WeakMap,Si=new WeakMap,Ci=new WeakMap,oh=new WeakMap,ah=new WeakMap,hh=new WeakMap,ue=new WeakSet,Sn=function(e=l(this,hh)){const s=l(this,wc)+e/2*l(this,oh);return l(this,ah)%180===0?[s/l(this,Si),s/l(this,Ci)]:[s/l(this,Ci),s/l(this,Si)]},uv=function(){const[e,s,i,n]=l(this,je),[r,o]=w(this,ue,Sn).call(this,0);return[e+r,s+o,i-2*r,n-2*o]},dv=function(){const e=m(this,je,new Float32Array([1/0,1/0,-1/0,-1/0]));for(const{line:n}of l(this,gs)){if(n.length<=12){for(let h=4,c=n.length;h<c;h+=6){const[u,d]=n.subarray(h,h+2);e[0]=Math.min(e[0],u),e[1]=Math.min(e[1],d),e[2]=Math.max(e[2],u),e[3]=Math.max(e[3],d)}continue}let r=n[4],o=n[5];for(let h=6,c=n.length;h<c;h+=6){const[u,d,f,g,p,b]=n.subarray(h,h+6);W.bezierBoundingBox(r,o,u,d,f,g,p,b,e),r=p,o=b}}const[s,i]=w(this,ue,Sn).call(this);e[0]=Math.min(1,Math.max(0,e[0]-s)),e[1]=Math.min(1,Math.max(0,e[1]-i)),e[2]=Math.min(1,Math.max(0,e[2]+s)),e[3]=Math.min(1,Math.max(0,e[3]+i)),e[2]-=e[0],e[3]-=e[1]},fv=function(e){const[s,i]=w(this,ue,Sn).call(this);m(this,hh,e);const[n,r]=w(this,ue,Sn).call(this),[o,h]=[n-s,r-i],c=l(this,je);return c[0]-=o,c[1]-=h,c[2]+=2*o,c[3]+=2*h,c};let od=Ug;const Yg=class Yg extends XS{constructor(e){super();y(this,lh);m(this,lh,e),super.updateProperties({fill:"none",stroke:Pt._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(e,s){e==="stroke-width"&&(s??(s=this["stroke-width"]),s*=l(this,lh).realScale),super.updateSVGProperty(e,s)}clone(){const e=new Yg(l(this,lh));return e.updateAll(this),e}};lh=new WeakMap;let Ng=Yg;const ch=class ch extends Ig{constructor(e){super({...e,name:"inkEditor"});y(this,Cd);this._willKeepAspectRatio=!0}static initialize(e,s){Pt.initialize(e,s),this._defaultDrawingOptions=new Ng(s.viewParameters)}static getDefaultDrawingOptions(e){const s=this._defaultDrawingOptions.clone();return s.updateProperties(e),s}static get supportMultipleDrawings(){return!0}static get typesMap(){return st(this,"typesMap",new Map([[ot.INK_THICKNESS,"stroke-width"],[ot.INK_COLOR,"stroke"],[ot.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(e,s,i,n,r){return new WS(e,s,i,n,r,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(e,s,i,n,r,o){return od.deserialize(e,s,i,n,r,o)}static async deserialize(e,s,i){let n=null;if(e instanceof Og){const{data:{inkLists:o,rect:h,rotation:c,id:u,color:d,opacity:f,borderStyle:{rawWidth:g},popupRef:p},parent:{page:{pageNumber:b}}}=e;n=e={annotationType:Z.INK,color:Array.from(d),thickness:g,opacity:f,paths:{points:o},boxes:null,pageIndex:b-1,rect:h.slice(0),rotation:c,id:u,deleted:!1,popupRef:p}}const r=await super.deserialize(e,s,i);return r.annotationElementId=e.id||null,r._initialData=n,r}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();const{_drawId:e,_drawingOptions:s,parent:i}=this;s.updateSVGProperty("stroke-width"),i.drawLayer.updateProperties(e,s.toSVGProperties())}static onScaleChangingWhenDrawing(){const e=this._currentParent;e&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),e.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:e,thickness:s,opacity:i}){this._drawingOptions=ch.getDefaultDrawingOptions({stroke:W.makeHexColor(...e),"stroke-width":s,"stroke-opacity":i})}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:s,points:i,rect:n}=this.serializeDraw(e),{_drawingOptions:{stroke:r,"stroke-opacity":o,"stroke-width":h}}=this,c={annotationType:Z.INK,color:Pt._colorManager.convert(r),opacity:o,thickness:h,paths:{lines:s,points:i},pageIndex:this.pageIndex,rect:n,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?c:this.annotationElementId&&!w(this,Cd,gv).call(this,c)?null:(c.id=this.annotationElementId,c)}renderAnnotationElement(e){const{points:s,rect:i}=this.serializeDraw(!1);return e.updateEdited({rect:i,thickness:this._drawingOptions["stroke-width"],points:s}),null}};Cd=new WeakSet,gv=function(e){const{color:s,thickness:i,opacity:n,pageIndex:r}=this._initialData;return this._hasBeenMoved||this._hasBeenResized||e.color.some((o,h)=>o!==s[h])||e.thickness!==i||e.opacity!==n||e.pageIndex!==r},$(ch,"_type","ink"),$(ch,"_editorType",Z.INK),$(ch,"_defaultDrawingOptions",null);let jg=ch;const xc=class xc extends Pt{constructor(e){super({...e,name:"stampEditor"});y(this,ct);y(this,Ot,null);y(this,de,null);y(this,hr,null);y(this,yn,null);y(this,lr,null);y(this,uh,"");y(this,Ai,null);y(this,Ti,null);y(this,ps,!1);y(this,dh,!1);m(this,yn,e.bitmapUrl),m(this,lr,e.bitmapFile)}static initialize(e,s){Pt.initialize(e,s)}static get supportedTypes(){return st(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(s=>`image/${s}`))}static get supportedTypesStr(){return st(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(e){return this.supportedTypes.includes(e)}static paste(e,s){s.pasteEditor(Z.STAMP,{bitmapFile:e.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){var e;return{type:"stamp",hasAltText:!!((e=this.altTextData)!=null&&e.altText)}}static computeTelemetryFinalData(e){const s=e.get("hasAltText");return{hasAltText:s.get(!0)??0,hasNoAltText:s.get(!1)??0}}async mlGuessAltText(e=null,s=!0){if(this.hasAltTextData())return null;const{mlManager:i}=this._uiManager;if(!i)throw new Error("No ML.");if(!await i.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:n,width:r,height:o}=e||this.copyCanvas(null,null,!0).imageData,h=await i.guess({name:"altText",request:{data:n,width:r,height:o,channels:n.length/(r*o)}});if(!h)throw new Error("No response from the AI service.");if(h.error)throw new Error("Error from the AI service.");if(h.cancel)return null;if(!h.output)throw new Error("No valid response from the AI service.");const c=h.output;return await this.setGuessedAltText(c),s&&!this.hasAltTextData()&&(this.altTextData={alt:c,decorative:!1}),c}remove(){var e;l(this,de)&&(m(this,Ot,null),this._uiManager.imageManager.deleteId(l(this,de)),(e=l(this,Ai))==null||e.remove(),m(this,Ai,null),l(this,Ti)&&(clearTimeout(l(this,Ti)),m(this,Ti,null))),super.remove()}rebuild(){if(!this.parent){l(this,de)&&w(this,ct,Jd).call(this);return}super.rebuild(),this.div!==null&&(l(this,de)&&l(this,Ai)===null&&w(this,ct,Jd).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(e){this._isDraggable=!0,e&&this.div.focus()}isEmpty(){return!(l(this,hr)||l(this,Ot)||l(this,yn)||l(this,lr)||l(this,de))}get isResizable(){return!0}render(){if(this.div)return this.div;let e,s;if(this.width&&(e=this.x,s=this.y),super.render(),this.div.hidden=!0,this.div.setAttribute("role","figure"),this.addAltTextButton(),l(this,Ot)?w(this,ct,Ip).call(this):w(this,ct,Jd).call(this),this.width&&!this.annotationElementId){const[i,n]=this.parentDimensions;this.setAt(e*i,s*n,this.width*i,this.height*n)}return this._uiManager.addShouldRescale(this),this.div}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;l(this,Ti)!==null&&clearTimeout(l(this,Ti)),m(this,Ti,setTimeout(()=>{m(this,Ti,null),w(this,ct,Np).call(this)},200))}copyCanvas(e,s,i=!1){var g;e||(e=224);const{width:n,height:r}=l(this,Ot),o=new mg;let h=l(this,Ot),c=n,u=r,d=null;if(s){if(n>s||r>s){const M=Math.min(s/n,s/r);c=Math.floor(n*M),u=Math.floor(r*M)}d=document.createElement("canvas");const p=d.width=Math.ceil(c*o.sx),b=d.height=Math.ceil(u*o.sy);l(this,ps)||(h=w(this,ct,Zd).call(this,p,b));const v=d.getContext("2d");v.filter=this._uiManager.hcmFilter;let _="white",x="#cfcfd8";this._uiManager.hcmFilter!=="none"?x="black":(g=window.matchMedia)!=null&&g.call(window,"(prefers-color-scheme: dark)").matches&&(_="#8f8f9d",x="#42414d");const C=15,S=C*o.sx,k=C*o.sy,D=new OffscreenCanvas(S*2,k*2),A=D.getContext("2d");A.fillStyle=_,A.fillRect(0,0,S*2,k*2),A.fillStyle=x,A.fillRect(0,0,S,k),A.fillRect(S,k,S,k),v.fillStyle=v.createPattern(D,"repeat"),v.fillRect(0,0,p,b),v.drawImage(h,0,0,h.width,h.height,0,0,p,b)}let f=null;if(i){let p,b;if(o.symmetric&&h.width<e&&h.height<e)p=h.width,b=h.height;else if(h=l(this,Ot),n>e||r>e){const x=Math.min(e/n,e/r);p=Math.floor(n*x),b=Math.floor(r*x),l(this,ps)||(h=w(this,ct,Zd).call(this,p,b))}const _=new OffscreenCanvas(p,b).getContext("2d",{willReadFrequently:!0});_.drawImage(h,0,0,h.width,h.height,0,0,p,b),f={width:p,height:b,data:_.getImageData(0,0,p,b).data}}return{canvas:d,width:c,height:u,imageData:f}}getImageForAltText(){return l(this,Ai)}static async deserialize(e,s,i){var b;let n=null;if(e instanceof Ib){const{data:{rect:v,rotation:_,id:x,structParent:C,popupRef:S},container:k,parent:{page:{pageNumber:D}}}=e,A=k.querySelector("canvas"),M=i.imageManager.getFromCanvas(k.id,A);A.remove();const O=((b=await s._structTree.getAriaAttributes(`${ug}${x}`))==null?void 0:b.get("aria-label"))||"";n=e={annotationType:Z.STAMP,bitmapId:M.id,bitmap:M.bitmap,pageIndex:D-1,rect:v.slice(0),rotation:_,id:x,deleted:!1,accessibilityData:{decorative:!1,altText:O},isSvg:!1,structParent:C,popupRef:S}}const r=await super.deserialize(e,s,i),{rect:o,bitmap:h,bitmapUrl:c,bitmapId:u,isSvg:d,accessibilityData:f}=e;u&&i.imageManager.isValidId(u)?(m(r,de,u),h&&m(r,Ot,h)):m(r,yn,c),m(r,ps,d);const[g,p]=r.pageDimensions;return r.width=(o[2]-o[0])/g,r.height=(o[3]-o[1])/p,r.annotationElementId=e.id||null,f&&(r.altTextData=f),r._initialData=n,m(r,dh,!!n),r}serialize(e=!1,s=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const i={annotationType:Z.STAMP,bitmapId:l(this,de),pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:l(this,ps),structTreeParentId:this._structTreeParentId};if(e)return i.bitmapUrl=w(this,ct,tf).call(this,!0),i.accessibilityData=this.serializeAltText(!0),i;const{decorative:n,altText:r}=this.serializeAltText(!1);if(!n&&r&&(i.accessibilityData={type:"Figure",alt:r}),this.annotationElementId){const h=w(this,ct,pv).call(this,i);if(h.isSame)return null;h.isSameAltText?delete i.accessibilityData:i.accessibilityData.structParent=this._initialData.structParent??-1}if(i.id=this.annotationElementId,s===null)return i;s.stamps||(s.stamps=new Map);const o=l(this,ps)?(i.rect[2]-i.rect[0])*(i.rect[3]-i.rect[1]):null;if(!s.stamps.has(l(this,de)))s.stamps.set(l(this,de),{area:o,serialized:i}),i.bitmap=w(this,ct,tf).call(this,!1);else if(l(this,ps)){const h=s.stamps.get(l(this,de));o>h.area&&(h.area=o,h.serialized.bitmap.close(),h.serialized.bitmap=w(this,ct,tf).call(this,!1))}return i}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}};Ot=new WeakMap,de=new WeakMap,hr=new WeakMap,yn=new WeakMap,lr=new WeakMap,uh=new WeakMap,Ai=new WeakMap,Ti=new WeakMap,ps=new WeakMap,dh=new WeakMap,ct=new WeakSet,Ic=function(e,s=!1){if(!e){this.remove();return}m(this,Ot,e.bitmap),s||(m(this,de,e.id),m(this,ps,e.isSvg)),e.file&&m(this,uh,e.file.name),w(this,ct,Ip).call(this)},Nc=function(){if(m(this,hr,null),this._uiManager.enableWaiting(!1),!!l(this,Ai)){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Ot)){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Ot)){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}},Jd=function(){if(l(this,de)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(l(this,de)).then(i=>w(this,ct,Ic).call(this,i,!0)).finally(()=>w(this,ct,Nc).call(this));return}if(l(this,yn)){const i=l(this,yn);m(this,yn,null),this._uiManager.enableWaiting(!0),m(this,hr,this._uiManager.imageManager.getFromUrl(i).then(n=>w(this,ct,Ic).call(this,n)).finally(()=>w(this,ct,Nc).call(this)));return}if(l(this,lr)){const i=l(this,lr);m(this,lr,null),this._uiManager.enableWaiting(!0),m(this,hr,this._uiManager.imageManager.getFromFile(i).then(n=>w(this,ct,Ic).call(this,n)).finally(()=>w(this,ct,Nc).call(this)));return}const e=document.createElement("input");e.type="file",e.accept=xc.supportedTypesStr;const s=this._uiManager._signal;m(this,hr,new Promise(i=>{e.addEventListener("change",async()=>{if(!e.files||e.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const n=await this._uiManager.imageManager.getFromFile(e.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}}),w(this,ct,Ic).call(this,n)}i()},{signal:s}),e.addEventListener("cancel",()=>{this.remove(),i()},{signal:s})}).finally(()=>w(this,ct,Nc).call(this))),e.click()},Ip=function(){var d;const{div:e}=this;let{width:s,height:i}=l(this,Ot);const[n,r]=this.pageDimensions,o=.75;if(this.width)s=this.width*n,i=this.height*r;else if(s>o*n||i>o*r){const f=Math.min(o*n/s,o*r/i);s*=f,i*=f}const[h,c]=this.parentDimensions;this.setDims(s*h/n,i*c/r),this._uiManager.enableWaiting(!1);const u=m(this,Ai,document.createElement("canvas"));u.setAttribute("role","img"),this.addContainer(u),this.width=s/n,this.height=i/r,(d=this._initialOptions)!=null&&d.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,(!this._uiManager.useNewAltTextWhenAddingImage||!this._uiManager.useNewAltTextFlow||this.annotationElementId)&&(e.hidden=!1),w(this,ct,Np).call(this),l(this,dh)||(this.parent.addUndoableEditor(this),m(this,dh,!0)),this._reportTelemetry({action:"inserted_image"}),l(this,uh)&&u.setAttribute("aria-label",l(this,uh))},Zd=function(e,s){const{width:i,height:n}=l(this,Ot);let r=i,o=n,h=l(this,Ot);for(;r>2*e||o>2*s;){const c=r,u=o;r>2*e&&(r=r>=16384?Math.floor(r/2)-1:Math.ceil(r/2)),o>2*s&&(o=o>=16384?Math.floor(o/2)-1:Math.ceil(o/2));const d=new OffscreenCanvas(r,o);d.getContext("2d").drawImage(h,0,0,c,u,0,0,r,o),h=d.transferToImageBitmap()}return h},Np=function(){const[e,s]=this.parentDimensions,{width:i,height:n}=this,r=new mg,o=Math.ceil(i*e*r.sx),h=Math.ceil(n*s*r.sy),c=l(this,Ai);if(!c||c.width===o&&c.height===h)return;c.width=o,c.height=h;const u=l(this,ps)?l(this,Ot):w(this,ct,Zd).call(this,o,h),d=c.getContext("2d");d.filter=this._uiManager.hcmFilter,d.drawImage(u,0,0,u.width,u.height,0,0,o,h)},tf=function(e){if(e){if(l(this,ps)){const n=this._uiManager.imageManager.getSvgUrl(l(this,de));if(n)return n}const s=document.createElement("canvas");return{width:s.width,height:s.height}=l(this,Ot),s.getContext("2d").drawImage(l(this,Ot),0,0),s.toDataURL()}if(l(this,ps)){const[s,i]=this.pageDimensions,n=Math.round(this.width*s*Ln.PDF_TO_CSS_UNITS),r=Math.round(this.height*i*Ln.PDF_TO_CSS_UNITS),o=new OffscreenCanvas(n,r);return o.getContext("2d").drawImage(l(this,Ot),0,0,l(this,Ot).width,l(this,Ot).height,0,0,n,r),o.transferToImageBitmap()}return structuredClone(l(this,Ot))},pv=function(e){var o;const{pageIndex:s,accessibilityData:{altText:i}}=this._initialData,n=e.pageIndex===s,r=(((o=e.accessibilityData)==null?void 0:o.alt)||"")===i;return{isSame:!this._hasBeenMoved&&!this._hasBeenResized&&n&&r,isSameAltText:r}},$(xc,"_type","stamp"),$(xc,"_editorType",Z.STAMP);let Bg=xc;const ei=class ei{constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:o,textLayer:h,viewport:c,l10n:u}){y(this,kt);y(this,No);y(this,fh,!1);y(this,Ei,null);y(this,cr,null);y(this,vn,null);y(this,Ps,new Map);y(this,ur,!1);y(this,gh,!1);y(this,jo,!1);y(this,ti,null);y(this,_n,null);y(this,Ce,null);y(this,wn,null);y(this,X);const d=[...l(ei,dr).values()];if(!ei._initialized){ei._initialized=!0;for(const f of d)f.initialize(u,t)}t.registerEditorTypes(d),m(this,X,t),this.pageIndex=e,this.div=s,m(this,No,n),m(this,Ei,r),this.viewport=c,m(this,Ce,h),this.drawLayer=o,this._structTree=i,l(this,X).addLayer(this)}get isEmpty(){return l(this,Ps).size===0}get isInvisible(){return this.isEmpty&&l(this,X).getMode()===Z.NONE}updateToolbar(t){l(this,X).updateToolbar(t)}updateMode(t=l(this,X).getMode()){switch(w(this,kt,ef).call(this),t){case Z.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case Z.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case Z.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);const{classList:e}=this.div;for(const s of l(ei,dr).values())e.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){var e;return t===((e=l(this,Ce))==null?void 0:e.div)}setEditingState(t){l(this,X).setEditingState(t)}addCommands(t){l(this,X).addCommands(t)}cleanUndoStack(t){l(this,X).cleanUndoStack(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){var e;(e=l(this,Ei))==null||e.div.classList.toggle("disabled",!t)}async enable(){m(this,jo,!0),this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const s of l(this,Ps).values())s.enableEditing(),s.show(!0),s.annotationElementId&&(l(this,X).removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!l(this,Ei)){m(this,jo,!1);return}const e=l(this,Ei).getEditableAnnotations();for(const s of e){if(s.hide(),l(this,X).isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;const i=await this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}m(this,jo,!1)}disable(){var i;m(this,gh,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,e=new Map;for(const n of l(this,Ps).values())if(n.disableEditing(),!!n.annotationElementId){if(n.serialize()!==null){t.set(n.annotationElementId,n);continue}else e.set(n.annotationElementId,n);(i=this.getEditableAnnotation(n.annotationElementId))==null||i.show(),n.remove()}if(l(this,Ei)){const n=l(this,Ei).getEditableAnnotations();for(const r of n){const{id:o}=r.data;if(l(this,X).isDeletedAnnotationElement(o))continue;let h=e.get(o);if(h){h.resetAnnotationElement(r),h.show(!1),r.show();continue}h=t.get(o),h&&(l(this,X).addChangedExistingAnnotation(h),h.renderAnnotationElement(r)&&h.show(!1)),r.show()}}w(this,kt,ef).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const n of l(ei,dr).values())s.remove(`${n._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),m(this,gh,!1)}getEditableAnnotation(t){var e;return((e=l(this,Ei))==null?void 0:e.getEditableAnnotation(t))||null}setActiveEditor(t){l(this,X).getActive()!==t&&l(this,X).setActiveEditor(t)}enableTextSelection(){var t;if(this.div.tabIndex=-1,(t=l(this,Ce))!=null&&t.div&&!l(this,wn)){m(this,wn,new AbortController);const e=l(this,X).combinedSignal(l(this,wn));l(this,Ce).div.addEventListener("pointerdown",w(this,kt,mv).bind(this),{signal:e}),l(this,Ce).div.classList.add("highlighting")}}disableTextSelection(){var t;this.div.tabIndex=0,(t=l(this,Ce))!=null&&t.div&&l(this,wn)&&(l(this,wn).abort(),m(this,wn,null),l(this,Ce).div.classList.remove("highlighting"))}enableClick(){if(l(this,cr))return;m(this,cr,new AbortController);const t=l(this,X).combinedSignal(l(this,cr));this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t});const e=this.pointerup.bind(this);this.div.addEventListener("pointerup",e,{signal:t}),this.div.addEventListener("pointercancel",e,{signal:t})}disableClick(){var t;(t=l(this,cr))==null||t.abort(),m(this,cr,null)}attach(t){l(this,Ps).set(t.id,t);const{annotationElementId:e}=t;e&&l(this,X).isDeletedAnnotationElement(e)&&l(this,X).removeDeletedAnnotationElement(t)}detach(t){var e;l(this,Ps).delete(t.id),(e=l(this,No))==null||e.removePointerInTextLayer(t.contentDiv),!l(this,gh)&&t.annotationElementId&&l(this,X).addDeletedAnnotationElement(t)}remove(t){this.detach(t),l(this,X).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){var e;t.parent!==this&&(t.parent&&t.annotationElementId&&(l(this,X).addDeletedAnnotationElement(t.annotationElementId),Pt.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),(e=t.parent)==null||e.detach(t),t.setParent(this),t.div&&t.isAttachedToDOM&&(t.div.remove(),this.div.append(t.div)))}add(t){if(!(t.parent===this&&t.isAttachedToDOM)){if(this.changeParent(t),l(this,X).addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!l(this,jo)),l(this,X).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var s;if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!l(this,vn)&&(t._focusEventsAllowed=!1,m(this,vn,setTimeout(()=>{m(this,vn,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:l(this,X)._signal}),e.focus())},0))),t._structTreeParentId=(s=l(this,No))==null?void 0:s.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){t.needsToBeRebuilt()?(t.parent||(t.parent=this),t.rebuild(),t.show()):this.add(t)}addUndoableEditor(t){const e=()=>t._uiManager.rebuild(t),s=()=>{t.remove()};this.addCommands({cmd:e,undo:s,mustExec:!1})}getNextId(){return l(this,X).getId()}combinedSignal(t){return l(this,X).combinedSignal(t)}canCreateNewEmptyEditor(){var t;return(t=l(this,kt,Di))==null?void 0:t.canCreateNewEmptyEditor()}pasteEditor(t,e){l(this,X).updateToolbar(t),l(this,X).updateMode(t);const{offsetX:s,offsetY:i}=w(this,kt,Bp).call(this),n=this.getNextId(),r=w(this,kt,jp).call(this,{parent:this,id:n,x:s,y:i,uiManager:l(this,X),isCentered:!0,...e});r&&this.add(r)}async deserialize(t){var e;return await((e=l(ei,dr).get(t.annotationType??t.annotationEditorType))==null?void 0:e.deserialize(t,this,l(this,X)))||null}createAndAddNewEditor(t,e,s={}){const i=this.getNextId(),n=w(this,kt,jp).call(this,{parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:l(this,X),isCentered:e,...s});return n&&this.add(n),n}addNewEditor(){this.createAndAddNewEditor(w(this,kt,Bp).call(this),!0)}setSelected(t){l(this,X).setSelected(t)}toggleSelected(t){l(this,X).toggleSelected(t)}unselect(t){l(this,X).unselect(t)}pointerup(t){var s;const{isMac:e}=Re.platform;if(!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&l(this,ur)&&(m(this,ur,!1),!((s=l(this,kt,Di))!=null&&s.isDrawer&&l(this,kt,Di).supportMultipleDrawings))){if(!l(this,fh)){m(this,fh,!0);return}if(l(this,X).getMode()===Z.STAMP){l(this,X).unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){var i;if(l(this,X).getMode()===Z.HIGHLIGHT&&this.enableTextSelection(),l(this,ur)){m(this,ur,!1);return}const{isMac:e}=Re.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;if(m(this,ur,!0),(i=l(this,kt,Di))!=null&&i.isDrawer){this.startDrawingSession(t);return}const s=l(this,X).getActive();m(this,fh,!s||s.isEmpty())}startDrawingSession(t){if(this.div.focus(),l(this,ti)){l(this,kt,Di).startDrawing(this,l(this,X),!1,t);return}l(this,X).setCurrentDrawingSession(this),m(this,ti,new AbortController);const e=l(this,X).combinedSignal(l(this,ti));this.div.addEventListener("blur",({relatedTarget:s})=>{s&&!this.div.contains(s)&&(m(this,_n,null),this.commitOrRemove())},{signal:e}),l(this,kt,Di).startDrawing(this,l(this,X),!1,t)}pause(t){if(t){const{activeElement:e}=document;this.div.contains(e)&&m(this,_n,e);return}l(this,_n)&&setTimeout(()=>{var e;(e=l(this,_n))==null||e.focus(),m(this,_n,null)},0)}endDrawingSession(t=!1){return l(this,ti)?(l(this,X).setCurrentDrawingSession(null),l(this,ti).abort(),m(this,ti,null),m(this,_n,null),l(this,kt,Di).endDrawing(t)):null}findNewParent(t,e,s){const i=l(this,X).findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}commitOrRemove(){return l(this,ti)?(this.endDrawingSession(),!0):!1}onScaleChanging(){l(this,ti)&&l(this,kt,Di).onScaleChangingWhenDrawing(this)}destroy(){var t,e;this.commitOrRemove(),((t=l(this,X).getActive())==null?void 0:t.parent)===this&&(l(this,X).commitOrRemove(),l(this,X).setActiveEditor(null)),l(this,vn)&&(clearTimeout(l(this,vn)),m(this,vn,null));for(const s of l(this,Ps).values())(e=l(this,No))==null||e.removePointerInTextLayer(s.contentDiv),s.setParent(null),s.isAttachedToDOM=!1,s.div.remove();this.div=null,l(this,Ps).clear(),l(this,X).removeLayer(this)}render({viewport:t}){this.viewport=t,kr(this.div,t);for(const e of l(this,X).getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){l(this,X).commitOrRemove(),w(this,kt,ef).call(this);const e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,kr(this.div,{rotation:s}),e!==s)for(const i of l(this,Ps).values())i.rotate(s)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return l(this,X).viewParameters.realScale}};No=new WeakMap,fh=new WeakMap,Ei=new WeakMap,cr=new WeakMap,vn=new WeakMap,Ps=new WeakMap,ur=new WeakMap,gh=new WeakMap,jo=new WeakMap,ti=new WeakMap,_n=new WeakMap,Ce=new WeakMap,wn=new WeakMap,X=new WeakMap,dr=new WeakMap,kt=new WeakSet,mv=function(t){l(this,X).unselectAll();const{target:e}=t;if(e===l(this,Ce).div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&l(this,Ce).div.contains(e)){const{isMac:s}=Re.platform;if(t.button!==0||t.ctrlKey&&s)return;l(this,X).showAllEditors("highlight",!0,!0),l(this,Ce).div.classList.add("free"),this.toggleDrawing(),rd.startHighlighting(this,l(this,X).direction==="ltr",{target:l(this,Ce).div,x:t.x,y:t.y}),l(this,Ce).div.addEventListener("pointerup",()=>{l(this,Ce).div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:l(this,X)._signal}),t.preventDefault()}},Di=function(){return l(ei,dr).get(l(this,X).getMode())},jp=function(t){const e=l(this,kt,Di);return e?new e.prototype.constructor(t):null},Bp=function(){const{x:t,y:e,width:s,height:i}=this.div.getBoundingClientRect(),n=Math.max(0,t),r=Math.max(0,e),o=Math.min(window.innerWidth,t+s),h=Math.min(window.innerHeight,e+i),c=(n+o)/2-t,u=(r+h)/2-e,[d,f]=this.viewport.rotation%180===0?[c,u]:[u,c];return{offsetX:d,offsetY:f}},ef=function(){for(const t of l(this,Ps).values())t.isEmpty()&&t.remove()},$(ei,"_initialized",!1),y(ei,dr,new Map([Rg,jg,Bg,rd].map(t=>[t._editorType,t])));let Hg=ei;const Ae=class Ae{constructor({pageIndex:t}){y(this,ki);y(this,si,null);y(this,Sc,0);y(this,Be,new Map);y(this,Bo,new Map);this.pageIndex=t}setParent(t){if(!l(this,si)){m(this,si,t);return}if(l(this,si)!==t){if(l(this,Be).size>0)for(const e of l(this,Be).values())e.remove(),t.append(e);m(this,si,t)}}static get _svgFactory(){return st(this,"_svgFactory",new Pg)}draw(t,e=!1,s=!1){const i=Ge(this,Sc)._++,n=w(this,ki,Hp).call(this),r=Ae._svgFactory.createElement("defs");n.append(r);const o=Ae._svgFactory.createElement("path");r.append(o);const h=`path_p${this.pageIndex}_${i}`;o.setAttribute("id",h),o.setAttribute("vector-effect","non-scaling-stroke"),e&&l(this,Bo).set(i,o);const c=s?w(this,ki,yv).call(this,r,h):null,u=Ae._svgFactory.createElement("use");return n.append(u),u.setAttribute("href",`#${h}`),this.updateProperties(n,t),l(this,Be).set(i,n),{id:i,clipPathId:`url(#${c})`}}drawOutline(t,e){const s=Ge(this,Sc)._++,i=w(this,ki,Hp).call(this),n=Ae._svgFactory.createElement("defs");i.append(n);const r=Ae._svgFactory.createElement("path");n.append(r);const o=`path_p${this.pageIndex}_${s}`;r.setAttribute("id",o),r.setAttribute("vector-effect","non-scaling-stroke");let h;if(e){const d=Ae._svgFactory.createElement("mask");n.append(d),h=`mask_p${this.pageIndex}_${s}`,d.setAttribute("id",h),d.setAttribute("maskUnits","objectBoundingBox");const f=Ae._svgFactory.createElement("rect");d.append(f),f.setAttribute("width","1"),f.setAttribute("height","1"),f.setAttribute("fill","white");const g=Ae._svgFactory.createElement("use");d.append(g),g.setAttribute("href",`#${o}`),g.setAttribute("stroke","none"),g.setAttribute("fill","black"),g.setAttribute("fill-rule","nonzero"),g.classList.add("mask")}const c=Ae._svgFactory.createElement("use");i.append(c),c.setAttribute("href",`#${o}`),h&&c.setAttribute("mask",`url(#${h})`);const u=c.cloneNode();return i.append(u),c.classList.add("mainOutline"),u.classList.add("secondaryOutline"),this.updateProperties(i,t),l(this,Be).set(s,i),s}finalizeDraw(t,e){l(this,Bo).delete(t),this.updateProperties(t,e)}updateProperties(t,e){var h;if(!e)return;const{root:s,bbox:i,rootClass:n,path:r}=e,o=typeof t=="number"?l(this,Be).get(t):t;if(o){if(s&&w(this,ki,Gp).call(this,o,s),i&&w(h=Ae,Ad,bv).call(h,o,i),n){const{classList:c}=o;for(const[u,d]of Object.entries(n))c.toggle(u,d)}if(r){const u=o.firstChild.firstChild;w(this,ki,Gp).call(this,u,r)}}}updateParent(t,e){if(e===this)return;const s=l(this,Be).get(t);s&&(l(e,si).append(s),l(this,Be).delete(t),l(e,Be).set(t,s))}remove(t){l(this,Bo).delete(t),l(this,si)!==null&&(l(this,Be).get(t).remove(),l(this,Be).delete(t))}destroy(){m(this,si,null);for(const t of l(this,Be).values())t.remove();l(this,Be).clear(),l(this,Bo).clear()}};si=new WeakMap,Sc=new WeakMap,Be=new WeakMap,Bo=new WeakMap,Ad=new WeakSet,bv=function(t,[e,s,i,n]){const{style:r}=t;r.top=`${100*s}%`,r.left=`${100*e}%`,r.width=`${100*i}%`,r.height=`${100*n}%`},ki=new WeakSet,Hp=function(){const t=Ae._svgFactory.create(1,1,!0);return l(this,si).append(t),t.setAttribute("aria-hidden",!0),t},yv=function(t,e){const s=Ae._svgFactory.createElement("clipPath");t.append(s);const i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=Ae._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i},Gp=function(t,e){for(const[s,i]of Object.entries(e))i===null?t.removeAttribute(s):t.setAttribute(s,i)},y(Ae,Ad);let Gg=Ae;globalThis.pdfjsTestingUtils={HighlightOutliner:Lg},K.AbortException,K.AnnotationEditorLayer,K.AnnotationEditorParamsType,K.AnnotationEditorType,K.AnnotationEditorUIManager,K.AnnotationLayer,K.AnnotationMode,K.ColorPicker,K.DOMSVGFactory,K.DrawLayer,K.FeatureTest;var US=K.GlobalWorkerOptions;K.ImageKind,K.InvalidPDFException,K.MissingPDFException,K.OPS,K.OutputScale,K.PDFDataRangeTransport,K.PDFDateString,K.PDFWorker,K.PasswordResponses,K.PermissionFlag,K.PixelsPerInch,K.RenderingCancelledException,K.TextLayer,K.TouchManager,K.UnexpectedResponseException,K.Util,K.VerbosityLevel,K.XfaLayer,K.build,K.createValidAbsoluteUrl,K.fetchData;var YS=K.getDocument;K.getFilenameFromUrl,K.getPdfFilenameFromUrl,K.getXfaPageViewport,K.isDataScheme,K.isPdfFile,K.noContextMenu,K.normalizeUnicode,K.setLayerDimensions,K.shadow,K.stopEvent,K.version;const $S={"pdfjs-dist":"4.10.38"};function qS(a){return new Promise((t,e)=>{const s=new FileReader;s.addEventListener("load",()=>t(s.result)),s.addEventListener("error",e),s.readAsDataURL(a)})}const KS=$S["pdfjs-dist"].replace("^","");US.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${KS}/pdf.worker.min.mjs`;async function QS(a){const t="data:application/pdf;base64,",e=await qS(a);if(typeof e=="string")return window.atob(e.slice(t.length))}function JS(a,t){return YS({data:a,password:t}).promise}const ZS="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2040%2040'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3ccircle%20cx='20'%20cy='20'%20r='10.75'%20stroke='currentColor'%20stroke-width='2.5'/%3e%3cpath%20d='M16%2024L23.7782%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3cpath%20d='M24%2024L16.2218%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3c/svg%3e";function tC(a){return new URL(Object.assign({"../assets/close.svg":ZS})[`../assets/${a}`],typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:_t&&_t.tagName.toUpperCase()==="SCRIPT"&&_t.src||new URL("pdf-canvas.umd.js",document.baseURI).href).href}function eC(a){return new Promise((t,e)=>{const s=window.URL.createObjectURL(a),i=new Image;i.src=s,i.addEventListener("load",async()=>{window.URL.revokeObjectURL(s),t(await sC(i))}),i.addEventListener("error",n=>{window.URL.revokeObjectURL(s),e(n)})})}function sC(a){return new Promise(t=>{const e=document.createElement("canvas"),s=e.getContext("2d"),{naturalWidth:i,naturalHeight:n}=a;e.width=i,e.height=n,s==null||s.drawImage(a,0,0,i,n),t(e.toDataURL("image/jpeg",.8))})}let jb=null;function iC(){const a=document.createElement("div");a.style.width="1in",document.body.append(a);const t=a.offsetWidth;return a.remove(),t}function nC(){const a=jb??iC();return jb=a,a/72}function rC(a,t=500){if(typeof a!="function")throw new TypeError("The first argument is not a function.");let e=null;return function(...s){e&&clearTimeout(e),e=setTimeout(()=>{e=null,a.apply(this,s)},t)}}const _s=new Map;function oC(a){const t=new Wf(a);return _s.set(a,t),t}function aC(a,t){const e=Date.now();return{PDFId:`${a.name}-${e}`,name:a.name.replace(/.pdf/,""),updateDate:e,PDFBase64:t}}function hC(a,t){const e=a.getViewport({scale:t}),s=document.createElement("canvas"),i=s.getContext("2d"),n=nC()/window.devicePixelRatio;s.width=Math.floor(e.width*n),s.height=Math.floor(e.height*n);const r={canvasContext:i,viewport:e,transform:[n,0,0,n,0,0]},o=a.render(r);return{canvas:s,renderTask:o}}async function lC(a,t,e){const s=a||tC("close.svg"),{objects:i,options:n}=await Iw(s),r=i.filter(h=>h!==null),o=K_.groupSVGElements(r,n);return r.forEach(h=>{h.stroke=t}),o.hoverCursor="pointer",o.stroke=`${t}-${e}`,o}function cC(a,t){if(!_s.get(a))return;const s=1/3,i=bC(t,s);Hb(a,i,s)}async function uC(a,t){const e=await eC(t),s=Date.now(),n={PDFId:`${t.name}${s}`,name:t.name.replace(/.png|.jpg|.jpeg/,""),updateDate:s,PDFBase64:e};return Bb(a,{url:e}),{...n,pages:1}}async function Bb(a,{url:t,scale:e=.5}){if(!_s.get(a))return;const i=await be.fromURL(t);i.scale(e),Hb(a,i,e)}function Hb(a,t,e){const s=_s.get(a);s&&(s.setWidth(t.width*e),s.setHeight(t.height*e),s.backgroundImage=t,s.renderAll())}function dC(a,t){if(!t)return;const{oCoords:e}=a;if(!e)return;const{x:s,y:i}=e.tl.touchCorner.tl,{height:n,width:r,scaleY:o,scaleX:h}=t;t.top=i-n*o/2,t.left=s-r*h/2,t.setCoords()}function fC(a,t,e){!e||!a||(e.scale(1/t),dC(a,e))}function gC(a,t,e){a&&(a.borderScaleFactor=1/t,a.cornerSize=6*(1/t),a.touchCornerSize=24*(1/t),a.cornerStrokeColor=e.stroke,a.setCoords())}function pC(a){const t=_s.get(a);t&&(t.discardActiveObject(),t.renderAll())}function mC(a){const t=_s.get(a);t&&(t.clear(),_s.delete(a))}function bC(a,t){return new be(a,{scaleX:t,scaleY:t})}function Gb(a,t){if(!t)return;const{left:e,top:s,scaleX:i,scaleY:n,width:r,height:o}=a,h=t.x*r*i,c=t.y*o*n;a.set({left:e-h,top:s-c})}function zb(a,t,e){var n;const s=a.type,i={"application/pdf":yC,"image/png":Xb,"image/jpeg":Xb};return((n=i[s])==null?void 0:n.call(i,a,t,e))??Promise.reject(new Error(`Unsupported ${s} file type.`))}async function yC(a,t,e){const s=await QS(a);if(!s)return;const i=aC(a,s);try{const n=await Vb({page:1,PDFBase64:s,scale:.8,password:t},e);return{...i,pages:n}}catch(n){return Promise.reject(n)}}async function Vb({page:a,PDFBase64:t,scale:e,password:s},i){try{const n=await JS(t,s),r=await n.getPage(a),{renderTask:o,canvas:h}=hC(r,e);return o.promise.then(()=>(i&&cC(i,h),n.numPages))}catch(n){return Promise.reject(n)}}async function Xb(a,t,e){if(e)return await uC(e,a)}const vC={top:100,left:50,scaleX:.5,scaleY:.5,borderColor:"black",cornerStrokeColor:"black",cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},_C={top:100,left:50,fontFamily:"helvetica",borderColor:"black",cornerStrokeColor:"black",scaleX:.7,scaleY:.7,cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},wC={stroke:"#000",hoverStroke:"#B7EC5D",src:""};function Wb(a){const{id:t="",pointerDown:e,pointerMove:s,pointerUp:i}=a||{};let n=null,r=null,o=1,h={...wC};function c(){if(!t||_s.has(t))return;const A=oC(t);return A.on("selection:cleared",()=>S(A)),e&&A.on("mouse:down",e),s&&A.on("mouse:move",s),i&&A.on("mouse:up",i),A}function u(A,M){return zb(A,M,t)}function d(A){return Vb(A,t)}async function f({url:A,scale:M=.5}){await Bb(t,{url:A,scale:M})}async function g(A,M,O){const R=_s.get(t);if(!R)return;const L=await be.fromURL(A,{},{...vC,...M});Gb(L,O),R.add(L),b(R,L),R.setActiveObject(L)}function p(A,M,O){const R=_s.get(t);if(!R)return;const L=new me(A,{..._C,...M});Gb(L,O),R.add(L),b(R,L),R.setActiveObject(L)}function b(A,M){M.on("selected",O=>v({canvas:A,target:O.target})),M.on("modified",O=>v({canvas:A,target:O.target})),M.on("scaling",()=>S(A)),M.on("moving",()=>S(A)),M.on("rotating",()=>S(A))}async function v({canvas:A,target:M,stroke:O=h.stroke,uuid:R=Date.now()}){if(A.getActiveObjects().length>1||(n==null?void 0:n.stroke)===`${O}-${R}`)return;const V=await lC(h.src,O,R);S(A),n=V,r=M,_(A,M,R),x(o,!0),A.add(V)}function _(A,M,O){n&&(n.on("selected",()=>{A.remove(M),S(A)}),n.on("mouseover",()=>{v({canvas:A,target:M,stroke:h.hoverStroke,uuid:O})}),n.on("mouseout",()=>{v({canvas:A,target:M,stroke:h.stroke,uuid:O})}))}function x(A,M=!1){const O=_s.get(t);o=A,O&&(gC(r,A,h),fC(r,A,n),!M&&O.renderAll())}function C(A){if(!A)return;h={...h,...A};const M=_s.get(t);!n||!r||!M||v({target:r,canvas:M})}function S(A){n&&(A.remove(n),n=r=null)}function k(){pC(t)}function D(){mC(t)}return{createCanvas:c,loadFile:u,specifyPage:d,renderImage:f,addFabric:g,addTextFabric:p,clearActive:k,deleteCanvas:D,scaleFabric:x,setCloseSvgOptions:C}}function xC(a){let t=0;const e=rC(()=>{t!==window.innerWidth&&(t=window.innerWidth,a())});q.onMounted(()=>{window.addEventListener("resize",e)}),q.onBeforeUnmount(()=>{window.removeEventListener("resize",e)})}const SC=q.defineComponent({__name:"pdf-canvas",props:{file:{},page:{default:1},canvasId:{default:"PDF-canvas"},fileZoom:{default:1},fileScale:{default:1},canvasScale:{default:1},canvasClass:{default:""},isDrop:{type:Boolean,default:!1},password:{},dropTextOptions:{},dropImageOptions:{},closeSvgOptions:{},manualReload:{type:Boolean},onDestroy:{type:Function,default:q.onBeforeUnmount}},emits:["loaded","reload","pointerDown","pointerMove","pointerUp"],setup(a,{expose:t,emit:e}){const s=a,i=e,{onDestroy:n}=s,r=q.ref(null),o=`${s.canvasId}-${s.page-1}`,h=q.computed(()=>s.fileZoom*s.canvasScale),{createCanvas:c,specifyPage:u,addFabric:d,addTextFabric:f,renderImage:g,clearActive:p,deleteCanvas:b,scaleFabric:v,setCloseSvgOptions:_}=Wb({id:o,pointerDown:A=>i("pointerDown",A),pointerMove:A=>i("pointerMove",A),pointerUp:A=>i("pointerUp",A)});x(),xC(D);async function x(){const{file:A,page:M,fileScale:O}=s;window.requestAnimationFrame(async()=>{if(await q.nextTick(),c(),A.PDFBase64.startsWith("data:image")||A.canvas){const{canvas:R}=A,L=R?7:3,V=R!=null&&R.length?R[M-1]:A.PDFBase64;g({url:V,scale:O/L}),i("loaded");return}await u({page:M,PDFBase64:A.PDFBase64,scale:O,password:s.password}),i("loaded")})}function C(A){if(!s.isDrop||!A.dataTransfer)return;const{dataTransfer:M,offsetX:O,offsetY:R}=A,L=M.getData("text/plain"),V=M.getData("text/uri-list"),U=M.getData("custom/offset"),G=U?JSON.parse(U):null,at={top:R,left:O},F={x:(G==null?void 0:G.offsetX)??0,y:(G==null?void 0:G.offsetY)??0};V?S(V,at,F):L&&k(L,at,F)}function S(A,M,O){d(A,{...s.dropImageOptions,...M},O)}function k(A,M,O){f(A,{...s.dropTextOptions,...M},O)}function D(){s.manualReload||x(),i("reload")}return q.watch([()=>s.fileScale,()=>s.page,()=>s.file,()=>s.password],D),q.watch(h,A=>v(A),{immediate:!0}),q.watch(()=>s.closeSvgOptions,_,{immediate:!0}),n(b),t({reload:x,addImage:S,addText:k,clearActive:p,deleteCanvas:b,canvasRef:r}),(A,M)=>(q.openBlock(),q.createElementBlock("div",{style:q.normalizeStyle({transform:`scale(${h.value})`}),onDragover:M[0]||(M[0]=q.withModifiers(()=>{},["prevent"])),onDragenter:M[1]||(M[1]=q.withModifiers(()=>{},["prevent"])),onDrop:q.withModifiers(C,["stop","prevent"])},[q.createElementVNode("canvas",{id:o,ref_key:"canvasRef",ref:r,class:q.normalizeClass(A.canvasClass)},null,2)],36))}});nt.default=SC,nt.loadFile=zb,nt.useFabric=Wb,Object.defineProperties(nt,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});