@component-hook/pdf-canvas 1.1.1 → 1.1.2

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,32 +1,32 @@
1
- (function(ot,K){typeof exports=="object"&&typeof module<"u"?K(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],K):(ot=typeof globalThis<"u"?globalThis:ot||self,K(ot["pdf-canvas"]={},ot.Vue))})(this,function(ot,K){"use strict";var kC=Object.defineProperty;var Kb=ot=>{throw TypeError(ot)};var MC=(ot,K,Mt)=>K in ot?kC(ot,K,{enumerable:!0,configurable:!0,writable:!0,value:Mt}):ot[K]=Mt;var $=(ot,K,Mt)=>MC(ot,typeof K!="symbol"?K+"":K,Mt),$g=(ot,K,Mt)=>K.has(ot)||Kb("Cannot "+Mt);var l=(ot,K,Mt)=>($g(ot,K,"read from private field"),Mt?Mt.call(ot):K.get(ot)),_=(ot,K,Mt)=>K.has(ot)?Kb("Cannot add the same private member more than once"):K instanceof WeakSet?K.add(ot):K.set(ot,Mt),m=(ot,K,Mt,Xo)=>($g(ot,K,"write to private field"),Xo?Xo.call(ot,Mt):K.set(ot,Mt),Mt),w=(ot,K,Mt)=>($g(ot,K,"access private method"),Mt);var ze=(ot,K,Mt,Xo)=>({set _(sf){m(ot,K,sf,Mt)},get _(){return l(ot,K,Xo)}});var Wi,Ed,qg,Zh,In,Lr,Vs,Fr,tl,el,ad,Qb,Le,Jb,Zb,kd,tv,Kg,sl,Ir,Nr,Nn,ev,sv,iv,hd,ca,il,we,ua,Md,Ht,jn,nl,Dt,ld,nv,da,ns,Kt,ae,fa,Yi,ga,Ss,Bn,jr,pa,Br,di,Xs,Hr,rl,ol,ma,al,fi,Hn,ba,zn,gi,ud,Gn,hl,Vn,zr,ll,cl,ee,pt,$i,Gr,ul,dl,Xn,pi,qi,fl,Cs,B,Pd,Qg,rv,ov,Od,av,hv,lv,Jg,cv,Zg,tp,uv,Ge,Sn,dv,fv,ep,gv,Ac,sp,se,mi,Ws,ya,bi,rs,_a,vi,qe,Ki,Vr,yi,Wn,Us,Tc,Dd,gl,Xr,pl,ml,bl,vl,yl,wa,Qi,Wr,Un,Ji,pv,mv,ip,Ur,Ys,xt,xa,Yn,_l,Yr,he,$r,Zi,$n,wl,qr,os,xl,Kr,tn,_i,Sa,Ca,As,Qr,Sl,dd,Y,np,Cl,rp,Rd,bv,vv,op,Ld,ap,yv,_v,wv,hp,xv,lp,Sv,Cv,Av,cp,Ec,Jr,Zr,ie,fd,Tv,Al,Aa,Ta,Ts,Ev,kv,Mv,Fd,Tl,to,Ea,en,sn,xe,eo,so,G,Te,kc,vh,Id,yh,Pv,up,_h,Mc,Pc,dp,Oc,$s,fp,gp,pp,El,kl,io,Ml,Pl,Ol,Dl,ka,qn,mt,Ma,Pa,Rl,mp,qb,Kn,Ke,Ll,Fl,no,nn,Il,Nl,ro,Oa,Da,Qn,Ra,jl,La,oo,Bl,Hl,ao,ho,zl,Jn,Fa,rn,Ov,Dv,bp,as,Nd,vp,Rv,Lv,pd,Zn,on,Es,wh,jd,an,bd,vd,lo,co,Ia,Bd,Na,Hd,hn,wi,ja,Ba,ln,uo,Dc,hs,Gl,yp,tr,er,fo,po,Ha,za,Vl,_p,ls,zo,Fv,Iv,Ga,yd,_d,Va,mo,Ft,cn,Xa,Xl,Wl,Wa,un,qs,dn,Ul,fn,Yl,bo,vo,bt,zd,wp,Nv,jv,Bv,Hv,Gd,Vd,xp,$l,ql,Kl,Ql,Jl,yo,Zl,Sp,tc,ec,Cp,sc,_o,wo,ic,xo,zv,Ap,Ks,cs,nc,So,us,Ut,Gv,Vv,Xv,Xd,gn,Wd,Ud,Wv,Tp,Uv,ds,Qs,Ua,Ya,xi,rt,Co,Ao,rc,oc,$a,qa,sr,ac,wd,xd,Jt,Rc,Yv,$v,qv,Kv,Qv,Jv,Ka,To,mn,hc,fs,lc,zt,Sd,Zv,cc,uc,ir,Js,Ie,ty,Yd,ey,sy,Ep,dc,Qa,Zs,Eo,Ja,Zt,fc,Za,gc,pc,nr,ti,th,mc,vt,kp,Mp,Pp,Go,iy,gr,eh,bc,bn,ko,sh,Je,vc,yc,Mo,ks,gs,le,ih,vn,Se,nh,Ms,_c,Z,Op,$d,ny,ry,oy,Dp,Vo,Ps,xh,ay,qd,Lc,hy,ly,cy,uy,dy,Po,ps,rh,ne,Oo,Do,rr,or,ar,Ro,ht,Rp,Lp,Fp,Fc,fy,Kd,Ic,Sh,Si,re,oe,Lo,oh,Ne,ce,Os,Fo,Io,No,ah,Qd,je,wc,xc,ms,Ci,Ai,hh,lh,ch,ue,Cn,gy,py,my,uh,Cd,by,Rt,de,hr,yn,lr,fh,Ti,Ei,bs,gh,lt,Nc,jc,Jd,Ip,Zd,Np,tf,vy,jo,ph,ki,cr,_n,Ds,ur,mh,Bo,ei,wn,Ce,xn,W,dr,Et,yy,Di,jp,Bp,ef,ii,Cc,Be,Ho,Ad,_y,Mi,Hp,wy,zp;var Mt=typeof document<"u"?document.currentScript:null;const Xo="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",sf={top:100,left:50,scaleX:.5,scaleY:.5,borderColor:"black",cornerStrokeColor:"black",cornerSize:6,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},xy={top:100,left:50,fontFamily:"helvetica",borderColor:"black",cornerStrokeColor:"black",scaleX:.7,scaleY:.7,cornerSize:6,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},Sy={borderColor:"black",cornerStrokeColor:"black",cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},Cy={stroke:"#000",hoverStroke:"#B7EC5D",src:Xo},Ay=["borderColor","cornerStrokeColor","cornerSize","_cornerSize","selectionBackgroundColor"];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 Gp(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 A(a){for(var t=1;t<arguments.length;t++){var e=arguments[t]!=null?arguments[t]:{};t%2?Gp(Object(e),!0).forEach(function(s){T(a,s,e[s])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(e)):Gp(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 An(a,t){return t||(t=a.slice(0)),Object.freeze(Object.defineProperties(a,{raw:{value:Object.freeze(t)}}))}class Vp{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 ct=new class extends Vp{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=A(A({},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 Vp,e=(a==null?void 0:a.reduce((s,i)=>(s[i]=t[i],s),{}))||t;this.configure(e)}},Ri=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 ni extends Error{constructor(t,e){super("fabric: ".concat(t),e)}}class nf extends ni{constructor(t){super("".concat(t," 'options.signal' is in 'aborted' state"))}}class Ty{}class Ey extends Ty{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(),Ri("log","WebGL: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const ky={};let Xp;const ri=()=>Xp||(Xp={document,window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new Ey,dispose(){},copyPasteData:ky}),Wo=()=>ri().document,Bc=()=>ri().window,Wp=()=>{var a;return Math.max((a=ct.devicePixelRatio)!==null&&a!==void 0?a:Bc().devicePixelRatio,1)},Ch=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}=ct,e=Math.sqrt(t*a);return[Math.floor(e),Math.floor(t/e)]}},rf="6.6.4";function pr(){}const Tn=Math.PI/2,Li=2*Math.PI,of=Math.PI/180,Ee=Object.freeze([1,0,0,1,0,0]),af=16,En=.4477152502,J="center",dt="left",Ve="top",hf="bottom",Nt="right",ke="none",lf=/\r?\n/,Up="moving",Hc="scaling",Yp="rotating",cf="rotate",$p="skewing",Ah="resizing",My="modifyPoly",Py="modifyPath",zc="changed",Gc="scale",Me="scaleX",Ze="scaleY",Uo="skewX",Yo="skewY",Gt="fill",Pe="stroke",Vc="modified",$o="json",uf="svg",z=new class{constructor(){this[$o]=new Map,this[uf]=new Map}has(a){return this[$o].has(a)}getClass(a){const t=this[$o].get(a);if(!t)throw new ni("No class registered for ".concat(a));return t}setClass(a,t){t?this[$o].set(t,a):(this[$o].set(a.type,a),this[$o].set(a.type.toLowerCase(),a))}getSVGClass(a){return this[uf].get(a)}setSVGClass(a,t){this[uf].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 Oy{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},Rs=a=>{if(a===0)return 1;switch(Math.abs(a)/Tn){case 1:case 3:return 0;case 2:return-1}return Math.cos(a)},Ls=a=>{if(a===0)return 0;const t=a/Tn,e=Math.sign(a);switch(t){case 1:return e;case 2:return 0;case 3:return-e}return Math.sin(a)};class k{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 k(this.x+t.x,this.y+t.y)}addEquals(t){return this.x+=t.x,this.y+=t.y,this}scalarAdd(t){return new k(this.x+t,this.y+t)}scalarAddEquals(t){return this.x+=t,this.y+=t,this}subtract(t){return new k(this.x-t.x,this.y-t.y)}subtractEquals(t){return this.x-=t.x,this.y-=t.y,this}scalarSubtract(t){return new k(this.x-t,this.y-t)}scalarSubtractEquals(t){return this.x-=t,this.y-=t,this}multiply(t){return new k(this.x*t.x,this.y*t.y)}scalarMultiply(t){return new k(this.x*t,this.y*t)}scalarMultiplyEquals(t){return this.x*=t,this.y*=t,this}divide(t){return new k(this.x/t.x,this.y/t.y)}scalarDivide(t){return new k(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 k(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 k(Math.min(this.x,t.x),Math.min(this.y,t.y))}max(t){return new k(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 k(this.x,this.y)}rotate(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:df;const s=Ls(t),i=Rs(t),n=this.subtract(e);return new k(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 k(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 df=new k(0,0),Wc=a=>!!a&&Array.isArray(a._objects);function qp(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 k(i,n),d=u.add(new k(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 Kp extends Oy{_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 Th(a){return Bc().requestAnimationFrame(a)}function Qp(a){return Bc().cancelAnimationFrame(a)}let Dy=0;const kn=()=>Dy++,vs=()=>{const a=Wo().createElement("canvas");if(!a||a.getContext===void 0)throw new ni("Failed to create `canvas` element");return a},Jp=()=>Wo().createElement("img"),ts=a=>{const t=vs();return t.width=a.width,t.height=a.height,t},ff=(a,t,e)=>a.toDataURL("image/".concat(t),e),gf=(a,t,e)=>new Promise((s,i)=>{a.toBlob(s,"image/".concat(t),e)}),Lt=a=>a*of,oi=a=>a/of,Zp=a=>a.every((t,e)=>t===Ee[e]),ge=(a,t,e)=>new k(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 k(a[4],a[5]).transform(e,!0);return e[4]=-s,e[5]=-i,e},jt=(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?jt(s,e,t):s||e,void 0)||Ee.concat(),tm=a=>{let[t,e]=a;return Math.atan2(e,t)},br=a=>{const t=tm(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:oi(t),scaleX:s,scaleY:i,skewX:oi(n),skewY:0,translateX:a[4]||0,translateY:a[5]||0}},qo=function(a){return[1,0,0,1,a,arguments.length>1&&arguments[1]!==void 0?arguments[1]:0]};function vr(){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=Lt(a),i=Rs(s),n=Ls(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]},em=a=>Math.tan(Lt(a)),pf=a=>[1,0,em(a),1,0,0],mf=a=>[1,em(a),0,1,0,0],Eh=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=jt(o,pf(n),!0)),r&&(o=jt(o,mf(r),!0)),o},sm=a=>{const{translateX:t=0,translateY:e=0,angle:s=0}=a;let i=qo(t,e);s&&(i=jt(i,vr({angle:s})));const n=Eh(a);return Zp(n)||(i=jt(i,n)),i},kh=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 nf("loadImage"));const n=Jp();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 ni("Error loading ".concat(n.src)))},e&&(n.crossOrigin=e),n.src=a):o()})},Ko=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=>z.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)})})},Mh=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&&z.has(o.type)?Ko([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),{})},bf=(a,t)=>Object.keys(a).reduce((e,s)=>(t(a[s],s,a)&&(e[s]=a[s]),e),{}),wt=(a,t)=>parseFloat(Number(a).toFixed(t)),Qo=a=>"matrix("+a.map(t=>wt(t,ct.NUM_FRACTION_DIGITS)).join(" ")+")",ys=a=>!!a&&a.toLive!==void 0,im=a=>!!a&&typeof a.toObject=="function",nm=a=>!!a&&a.offsetX!==void 0&&"source"in a,_r=a=>!!a&&"multiSelectionStacking"in a;function rm(a){const t=a&&Fs(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 Fs=a=>a.ownerDocument||null,om=a=>{var t;return((t=a.ownerDocument)===null||t===void 0?void 0:t.defaultView)||null},am=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 hm(a){return a.onselectstart!==void 0&&(a.onselectstart=()=>!1),a.style.userSelect=ke,a}class lm{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&&Wo().getElementById(t)||vs();var s;if(e.hasAttribute("data-fabric"))throw new ni("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;am(s,i,t,e)}setCSSDimensions(t){vf(this.lower.el,t)}calcOffset(){return function(t){var e;const s=t&&Fs(t),i={left:0,top:0};if(!s)return i;const n=((e=om(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=rm(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(){ri().dispose(this.lower.el),delete this.lower}}const Ry={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 qp(Kp){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 lm(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&&(Ri("warn",`Canvas is trying to add an object that belongs to a different canvas.
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?Wp():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=A({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 k(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 k(-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=Th(()=>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 k(o.x,r.y),bl:new k(r.x,o.y),br:o}}cancelRequestedRender(){this.nextRenderHandle&&(Qp(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=ys(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 k(this.width/2,this.height/2)}centerObjectH(t){return this._centerObject(t,new k(this.getCenterPoint().x,t.getCenterPoint().y))}centerObjectV(t){return this._centerObject(t,new k(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 k(this.getVpCenter().x,t.getCenterPoint().y))}viewportCenterObjectV(t){return this._centerObject(t,new k(t.getCenterPoint().x,this.getVpCenter().y))}getVpCenter(){return ge(this.getCenterPoint(),Xe(this.viewportTransform))}_centerObject(t,e){t.setXY(e,J,J),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 A(A(A({version:rf},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 ys(r)?r.excludeFromExport||(s.background=r.toObject(e)):r&&(s.background=r),ys(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,`)" >
1
+ (function(ot,K){typeof exports=="object"&&typeof module<"u"?K(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],K):(ot=typeof globalThis<"u"?globalThis:ot||self,K(ot["pdf-canvas"]={},ot.Vue))})(this,function(ot,K){"use strict";var LC=Object.defineProperty;var ev=ot=>{throw TypeError(ot)};var FC=(ot,K,Mt)=>K in ot?LC(ot,K,{enumerable:!0,configurable:!0,writable:!0,value:Mt}):ot[K]=Mt;var q=(ot,K,Mt)=>FC(ot,typeof K!="symbol"?K+"":K,Mt),Qg=(ot,K,Mt)=>K.has(ot)||ev("Cannot "+Mt);var l=(ot,K,Mt)=>(Qg(ot,K,"read from private field"),Mt?Mt.call(ot):K.get(ot)),_=(ot,K,Mt)=>K.has(ot)?ev("Cannot add the same private member more than once"):K instanceof WeakSet?K.add(ot):K.set(ot,Mt),m=(ot,K,Mt,Wo)=>(Qg(ot,K,"write to private field"),Wo?Wo.call(ot,Mt):K.set(ot,Mt),Mt),w=(ot,K,Mt)=>(Qg(ot,K,"access private method"),Mt);var ze=(ot,K,Mt,Wo)=>({set _(rf){m(ot,K,rf,Mt)},get _(){return l(ot,K,Wo)}});var Ui,Md,Jg,sl,In,Fr,Gs,Ir,il,nl,ld,sv,Le,iv,nv,Pd,rv,Zg,rl,Nr,jr,Nn,ov,av,hv,cd,ua,ol,we,da,Od,Ht,jn,al,Dt,ud,lv,fa,ns,Kt,ae,ga,$i,pa,xs,Bn,Br,ma,Hr,fi,Vs,zr,hl,ll,ba,cl,gi,Hn,va,zn,pi,fd,Gn,ul,Vn,Gr,dl,fl,ee,pt,qi,Vr,gl,pl,Xn,mi,Ki,ml,Ss,H,Dd,tp,cv,uv,Rd,dv,fv,gv,ep,pv,sp,ip,mv,Ge,Cn,bv,vv,np,yv,kc,rp,se,bi,Xs,_a,vi,rs,wa,yi,qe,Qi,Xr,_i,Wn,Ws,Mc,Ld,bl,Wr,vl,yl,_l,wl,xl,xa,Ji,Ur,Un,Zi,_v,wv,op,Yr,Us,xt,Sa,Yn,Sl,$r,he,qr,tn,$n,Cl,Kr,os,Al,Qr,en,wi,Ca,Aa,Cs,Jr,Tl,gd,$,ap,El,hp,Fd,xv,Sv,lp,Id,cp,Cv,Av,Tv,up,Ev,dp,kv,Mv,Pv,fp,Pc,Zr,to,ie,pd,Ov,kl,Ta,Ea,As,Dv,Rv,Lv,Nd,Ml,eo,ka,sn,nn,xe,so,io,G,Te,Oc,yh,jd,_h,Fv,gp,wh,Dc,Rc,pp,Lc,Ys,mp,bp,vp,Pl,Ol,no,Dl,Rl,Ll,Fl,Ma,qn,mt,Pa,Oa,Il,yp,tv,Kn,Ke,Nl,jl,ro,rn,Bl,Hl,oo,Da,Ra,Qn,La,zl,Fa,ao,Gl,Vl,ho,lo,Xl,Jn,Ia,on,Iv,Nv,_p,as,Bd,wp,jv,Bv,bd,Zn,an,Ts,xh,Hd,hn,yd,_d,co,uo,Na,zd,ja,Gd,ln,xi,Ba,Ha,cn,fo,Fc,hs,Wl,xp,tr,er,go,mo,za,Ga,Ul,Sp,ls,Go,Hv,zv,Va,wd,xd,Xa,bo,Ft,un,Wa,Yl,$l,Ua,dn,$s,fn,ql,gn,Kl,vo,yo,bt,Vd,Cp,Gv,Vv,Xv,Wv,Xd,Wd,Ap,Ql,Jl,Zl,tc,ec,_o,sc,Tp,ic,nc,Ep,rc,wo,xo,oc,So,Uv,kp,qs,cs,ac,Co,us,Ut,Yv,$v,qv,Ud,pn,Yd,$d,Kv,Mp,Qv,ds,Ks,Ya,$a,Si,rt,Ao,To,hc,lc,qa,Ka,sr,cc,Sd,Cd,Jt,Ic,Jv,Zv,ty,ey,sy,iy,Qa,Eo,bn,uc,fs,dc,zt,Ad,ny,fc,gc,ir,Qs,Ie,ry,qd,oy,ay,Pp,pc,Ja,Js,ko,Za,Zt,mc,th,bc,vc,nr,Zs,eh,yc,vt,Op,Dp,Rp,Vo,hy,gr,sh,_c,vn,Mo,ih,Je,wc,xc,Po,Es,gs,le,nh,yn,Se,rh,ks,Sc,tt,Lp,Kd,ly,cy,uy,Fp,Xo,Ms,Sh,dy,Qd,Nc,fy,gy,py,my,by,Oo,ps,oh,ne,Do,Ro,rr,or,ar,Lo,lt,Ip,Np,jp,jc,vy,Jd,Bc,Ch,Ci,re,oe,Fo,ah,Ne,ce,Ps,Io,No,jo,hh,Zd,je,Cc,Ac,ms,Ai,Ti,lh,ch,uh,ue,An,yy,_y,wy,dh,Td,xy,Rt,de,hr,_n,lr,gh,Ei,ki,bs,ph,ct,Hc,zc,tf,Bp,ef,Hp,sf,Sy,Bo,mh,Mi,cr,wn,Os,ur,bh,Ho,ti,xn,Ce,Sn,W,dr,Et,Cy,Ri,zp,Gp,nf,si,Ec,Be,zo,Ed,Ay,Pi,Vp,Ty,Xp;var Mt=typeof document<"u"?document.currentScript:null;const Wo="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",rf={top:100,left:50,scaleX:.5,scaleY:.5,borderColor:"black",cornerStrokeColor:"black",cornerSize:6,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},Ey={top:100,left:50,fontFamily:"helvetica",borderColor:"black",cornerStrokeColor:"black",scaleX:.7,scaleY:.7,cornerSize:6,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},ky={borderColor:"black",cornerStrokeColor:"black",cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},My={stroke:"#000",hoverStroke:"#B7EC5D",src:Wo},Py=["borderColor","cornerStrokeColor","cornerSize","_cornerSize","selectionBackgroundColor"];function E(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 Wp(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 T(a){for(var t=1;t<arguments.length;t++){var e=arguments[t]!=null?arguments[t]:{};t%2?Wp(Object(e),!0).forEach(function(s){E(a,s,e[s])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(e)):Wp(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 ii(a,t){return t||(t=a.slice(0)),Object.freeze(Object.defineProperties(a,{raw:{value:Object.freeze(t)}}))}class Up{constructor(){E(this,"browserShadowBlurConstant",1),E(this,"DPI",96),E(this,"devicePixelRatio",typeof window<"u"?window.devicePixelRatio:1),E(this,"perfLimitSizeTotal",2097152),E(this,"maxCacheSideLimit",4096),E(this,"minCacheSideLimit",256),E(this,"disableStyleCopyPaste",!1),E(this,"enableGLFiltering",!0),E(this,"textureSize",4096),E(this,"forceGLPutImageData",!1),E(this,"cachesBoundsOfCurve",!1),E(this,"fontPaths",{}),E(this,"NUM_FRACTION_DIGITS",4)}}const ht=new class extends Up{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=T(T({},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 Up,e=(a==null?void 0:a.reduce((s,i)=>(s[i]=t[i],s),{}))||t;this.configure(e)}},Li=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 ni extends Error{constructor(t,e){super("fabric: ".concat(t),e)}}class of extends ni{constructor(t){super("".concat(t," 'options.signal' is in 'aborted' state"))}}class Oy{}class Dy extends Oy{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(),Li("log","WebGL: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const Ry={};let Yp;const ri=()=>Yp||(Yp={document,window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new Dy,dispose(){},copyPasteData:Ry}),Uo=()=>ri().document,Ah=()=>ri().window,$p=()=>{var a;return Math.max((a=ht.devicePixelRatio)!==null&&a!==void 0?a:Ah().devicePixelRatio,1)},Th=new class{constructor(){E(this,"charWidthsCache",{}),E(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)]}},af="6.7.0";function pr(){}const Tn=Math.PI/2,Fi=2*Math.PI,hf=Math.PI/180,Ee=Object.freeze([1,0,0,1,0,0]),lf=16,En=.4477152502,J="center",dt="left",Ve="top",cf="bottom",Nt="right",ke="none",uf=/\r?\n/,qp="moving",Gc="scaling",Kp="rotating",df="rotate",Qp="skewing",Eh="resizing",Ly="modifyPoly",Fy="modifyPath",Vc="changed",Xc="scale",Me="scaleX",Ze="scaleY",Yo="skewX",$o="skewY",Gt="fill",Pe="stroke",Wc="modified",qo="json",ff="svg",z=new class{constructor(){this[qo]=new Map,this[ff]=new Map}has(a){return this[qo].has(a)}getClass(a){const t=this[qo].get(a);if(!t)throw new ni("No class registered for ".concat(a));return t}setClass(a,t){t?this[qo].set(t,a):(this[qo].set(a.type,a),this[qo].set(a.type.toLowerCase(),a))}getSVGClass(a){return this[ff].get(a)}setSVGClass(a,t){this[ff].set(t??a.type.toLowerCase(),a)}},Uc=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 Iy{constructor(){E(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)/Tn){case 1:case 3:return 0;case 2:return-1}return Math.cos(a)},Rs=a=>{if(a===0)return 0;const t=a/Tn,e=Math.sign(a);switch(t){case 1:return e;case 2:return 0;case 3:return-e}return Math.sin(a)};class M{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 M(this.x+t.x,this.y+t.y)}addEquals(t){return this.x+=t.x,this.y+=t.y,this}scalarAdd(t){return new M(this.x+t,this.y+t)}scalarAddEquals(t){return this.x+=t,this.y+=t,this}subtract(t){return new M(this.x-t.x,this.y-t.y)}subtractEquals(t){return this.x-=t.x,this.y-=t.y,this}scalarSubtract(t){return new M(this.x-t,this.y-t)}scalarSubtractEquals(t){return this.x-=t,this.y-=t,this}multiply(t){return new M(this.x*t.x,this.y*t.y)}scalarMultiply(t){return new M(this.x*t,this.y*t)}scalarMultiplyEquals(t){return this.x*=t,this.y*=t,this}divide(t){return new M(this.x/t.x,this.y/t.y)}scalarDivide(t){return new M(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 M(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 M(Math.min(this.x,t.x),Math.min(this.y,t.y))}max(t){return new M(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 M(this.x,this.y)}rotate(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:gf;const s=Rs(t),i=Ds(t),n=this.subtract(e);return new M(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 M(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 gf=new M(0,0),Yc=a=>!!a&&Array.isArray(a._objects);function Jp(a){class t extends a{constructor(){super(...arguments),E(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 M(i,n),d=u.add(new M(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 Zp extends Iy{_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 kh(a){return Ah().requestAnimationFrame(a)}function tm(a){return Ah().cancelAnimationFrame(a)}let Ny=0;const kn=()=>Ny++,oi=()=>{const a=Uo().createElement("canvas");if(!a||a.getContext===void 0)throw new ni("Failed to create `canvas` element");return a},em=()=>Uo().createElement("img"),ts=a=>{const t=oi();return t.width=a.width,t.height=a.height,t},pf=(a,t,e)=>a.toDataURL("image/".concat(t),e),mf=(a,t,e)=>new Promise((s,i)=>{a.toBlob(s,"image/".concat(t),e)}),Lt=a=>a*hf,ai=a=>a/hf,sm=a=>a.every((t,e)=>t===Ee[e]),ge=(a,t,e)=>new M(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 M(a[4],a[5]).transform(e,!0);return e[4]=-s,e[5]=-i,e},jt=(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]],$c=(a,t)=>a.reduceRight((e,s)=>s&&e?jt(s,e,t):s||e,void 0)||Ee.concat(),im=a=>{let[t,e]=a;return Math.atan2(e,t)},br=a=>{const t=im(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:ai(t),scaleX:s,scaleY:i,skewX:ai(n),skewY:0,translateX:a[4]||0,translateY:a[5]||0}},Ko=function(a){return[1,0,0,1,a,arguments.length>1&&arguments[1]!==void 0?arguments[1]:0]};function vr(){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=Lt(a),i=Ds(s),n=Rs(s);return[i,n,-n,i,t?t-(i*t-n*e):0,e?e-(n*t+i*e):0]}const qc=function(a){return[a,0,0,arguments.length>1&&arguments[1]!==void 0?arguments[1]:a,0,0]},nm=a=>Math.tan(Lt(a)),bf=a=>[1,0,nm(a),1,0,0],vf=a=>[1,nm(a),0,1,0,0],Mh=a=>{let{scaleX:t=1,scaleY:e=1,flipX:s=!1,flipY:i=!1,skewX:n=0,skewY:r=0}=a,o=qc(s?-t:t,i?-e:e);return n&&(o=jt(o,bf(n),!0)),r&&(o=jt(o,vf(r),!0)),o},rm=a=>{const{translateX:t=0,translateY:e=0,angle:s=0}=a;let i=Ko(t,e);s&&(i=jt(i,vr({angle:s})));const n=Mh(a);return sm(n)||(i=jt(i,n)),i},Ph=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 of("loadImage"));const n=em();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 ni("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=>z.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)})})},Oh=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&&z.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),{})},yf=(a,t)=>Object.keys(a).reduce((e,s)=>(t(a[s],s,a)&&(e[s]=a[s]),e),{}),yt=(a,t)=>parseFloat(Number(a).toFixed(t)),Jo=a=>"matrix("+a.map(t=>yt(t,ht.NUM_FRACTION_DIGITS)).join(" ")+")",vs=a=>!!a&&a.toLive!==void 0,om=a=>!!a&&typeof a.toObject=="function",am=a=>!!a&&a.offsetX!==void 0&&"source"in a,_r=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))},_f=(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){E(this,"_originalCanvasStyle",void 0),E(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&&Uo().getElementById(t)||oi();var s;if(e.hasAttribute("data-fabric"))throw new ni("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){_f(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(){ri().dispose(this.lower.el),delete this.lower}}const jy={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 Dh extends Jp(Zp){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 Dh.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&&(Li("warn",`Canvas is trying to add an object that belongs to a different canvas.
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?$p():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=T({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 M(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 M(-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=kh(()=>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 M(o.x,r.y),bl:new M(r.x,o.y),br:o}}cancelRequestedRender(){this.nextRenderHandle&&(tm(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=vs(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 M(this.width/2,this.height/2)}centerObjectH(t){return this._centerObject(t,new M(this.getCenterPoint().x,t.getCenterPoint().y))}centerObjectV(t){return this._centerObject(t,new M(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 M(this.getVpCenter().x,t.getCenterPoint().y))}viewportCenterObjectV(t){return this._centerObject(t,new M(t.getCenterPoint().x,this.getVpCenter().y))}getVpCenter(){return ge(this.getCenterPoint(),Xe(this.viewportTransform))}_centerObject(t,e){t.setXY(e,J,J),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 T(T(T({version:af},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 vs(r)?r.excludeFromExport||(s.background=r.toObject(e)):r&&(s.background=r),vs(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" ?>
6
6
  `,'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" ',`"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
7
- `)}_setSVGHeader(t,e){const s=e.width||"".concat(this.width),i=e.height||"".concat(this.height),n=ct.NUM_FRACTION_DIGITS,r=e.viewBox;let o;if(r)o='viewBox="'.concat(r.x," ").concat(r.y," ").concat(r.width," ").concat(r.height,'" ');else if(this.svgViewportTransformation){const h=this.viewportTransform;o='viewBox="'.concat(wt(-h[4]/h[0],n)," ").concat(wt(-h[5]/h[3],n)," ").concat(wt(this.width/h[0],n)," ").concat(wt(this.height/h[3],n),'" ')}else o='viewBox="0 0 '.concat(this.width," ").concat(this.height,'" ');t.push("<svg ",'xmlns="http://www.w3.org/2000/svg" ','xmlns:xlink="http://www.w3.org/1999/xlink" ','version="1.1" ','width="',s,'" ','height="',i,'" ',o,`xml:space="preserve">
8
- `,"<desc>Created with Fabric.js ",rf,`</desc>
7
+ `)}_setSVGHeader(t,e){const s=e.width||"".concat(this.width),i=e.height||"".concat(this.height),n=ht.NUM_FRACTION_DIGITS,r=e.viewBox;let o;if(r)o='viewBox="'.concat(r.x," ").concat(r.y," ").concat(r.width," ").concat(r.height,'" ');else if(this.svgViewportTransformation){const h=this.viewportTransform;o='viewBox="'.concat(yt(-h[4]/h[0],n)," ").concat(yt(-h[5]/h[3],n)," ").concat(yt(this.width/h[0],n)," ").concat(yt(this.height/h[3],n),'" ')}else o='viewBox="0 0 '.concat(this.width," ").concat(this.height,'" ');t.push("<svg ",'xmlns="http://www.w3.org/2000/svg" ','xmlns:xlink="http://www.w3.org/1999/xlink" ','version="1.1" ','width="',s,'" ','height="',i,'" ',o,`xml:space="preserve">
8
+ `,"<desc>Created with Fabric.js ",af,`</desc>
9
9
  `,`<defs>
10
10
  `,this.createSVGFontFacesMarkup(),this.createSVGRefElementsMarkup(),this.createSVGClipPathMarkup(e),`</defs>
11
11
  `)}createSVGClipPathMarkup(t){const e=this.clipPath;return e?(e.clipPathId="CLIPPATH_".concat(kn()),'<clipPath id="'.concat(e.clipPathId,`" >
12
12
  `).concat(e.toClipPathSVG(t.reviver),`</clipPath>
13
- `)):""}createSVGRefElementsMarkup(){return["background","overlay"].map(t=>{const e=this["".concat(t,"Color")];if(ys(e)){const s=this["".concat(t,"Vpt")],i=this.viewportTransform,n={isType:()=>!1,width:this.width/(s?i[0]:1),height:this.height/(s?i[3]:1)};return e.toSVG(n,{additionalTransform:s?Qo(i):""})}}).join("")}createSVGFontFacesMarkup(){const t=[],e={},s=ct.fontPaths;this._objects.forEach(function n(r){t.push(r),Wc(r)&&r._objects.forEach(n)}),t.forEach(n=>{if(!(r=n)||typeof r._renderText!="function")return;var r;const{styles:o,fontFamily:h}=n;!e[h]&&s[h]&&(e[h]=!0,o&&Object.values(o).forEach(c=>{Object.values(c).forEach(u=>{let{fontFamily:d=""}=u;!e[d]&&s[d]&&(e[d]=!0)})}))});const i=Object.keys(e).map(n=>` @font-face {
13
+ `)):""}createSVGRefElementsMarkup(){return["background","overlay"].map(t=>{const e=this["".concat(t,"Color")];if(vs(e)){const s=this["".concat(t,"Vpt")],i=this.viewportTransform,n={isType:()=>!1,width:this.width/(s?i[0]:1),height:this.height/(s?i[3]:1)};return e.toSVG(n,{additionalTransform:s?Jo(i):""})}}).join("")}createSVGFontFacesMarkup(){const t=[],e={},s=ht.fontPaths;this._objects.forEach(function n(r){t.push(r),Yc(r)&&r._objects.forEach(n)}),t.forEach(n=>{if(!(r=n)||typeof r._renderText!="function")return;var r;const{styles:o,fontFamily:h}=n;!e[h]&&s[h]&&(e[h]=!0,o&&Object.values(o).forEach(c=>{Object.values(c).forEach(u=>{let{fontFamily:d=""}=u;!e[d]&&s[d]&&(e[d]=!0)})}))});const i=Object.keys(e).map(n=>` @font-face {
14
14
  font-family: '`.concat(n,`';
15
15
  src: url('`).concat(s[n],`');
16
16
  }
17
17
  `)).join("");return i?` <style type="text/css"><![CDATA[
18
18
  `.concat(i,`]]></style>
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(ys(s)){const i=s.repeat||"",n=this.width,r=this.height,o=this["".concat(e,"Vpt")]?Qo(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"||!nm(s)?n:s.source.width,'" height="').concat(i!=="repeat-x"&&i!=="no-repeat"||!nm(s)?r:s.source.height,'" fill="url(#SVGID_').concat(s.id,`)"></rect>
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(vs(s)){const i=s.repeat||"",n=this.width,r=this.height,o=this["".concat(e,"Vpt")]?Jo(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 ni("`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([Ko(n,{reviver:e,signal:s}),Mh({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=ts(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 ff(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 gf(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,y=ts({width:o,height:h}),x=r?this._objects.filter(S=>r(S)):this._objects;return this.enableRetinaScaling=!1,this.viewportTransform=b,this.width=o,this.height=h,this.skipControlsDrawing=!0,this.calcViewportBoundaries(),this.renderCanvas(y.getContext("2d"),x),this.viewportTransform=p,this.width=u,this.height=d,this.calcViewportBoundaries(),this.enableRetinaScaling=v,this.skipControlsDrawing=f,y}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",Ry);const Ly=["touchstart","touchmove","touchend"],cm=a=>{const t=rm(a.target),e=function(s){const i=s.changedTouches;return i&&i[0]?i[0]:s}(a);return new k(e.clientX+t.left,e.clientY+t.top)},$c=a=>Ly.includes(a.type)||a.pointerType==="touch",um=a=>{a.preventDefault(),a.stopPropagation()},ai=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}},Fy=["translateX","translateY","scaleX","scaleY"],dm=(a,t)=>Jo(a,jt(t,a.calcOwnMatrix())),Jo=(a,t)=>{const e=br(t),{translateX:s,translateY:i,scaleX:n,scaleY:r}=e,o=Ct(e,Fy),h=new k(s,i);a.flipX=!1,a.flipY=!1,Object.assign(a,o),a.set({scaleX:n,scaleY:r}),a.setPositionByOrigin(h,J,J)},fm=a=>{a.scaleX=1,a.scaleY=1,a.skewX=0,a.skewY=0,a.flipX=!1,a.flipY=!1,a.rotate(0)},yf=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}),qc=(a,t,e)=>{const s=a/2,i=t/2,n=[new k(-s,-i),new k(s,-i),new k(-s,i),new k(s,i)].map(o=>o.transform(e)),r=ai(n);return new k(r.width,r.height)},Oh=function(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:Ee;return jt(Xe(arguments.length>1&&arguments[1]!==void 0?arguments[1]:Ee),a)},wr=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(Oh(t,e))},gm=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(Oh(t,e),!0)},_f=(a,t,e)=>{const s=Oh(t,e);return Jo(a,jt(s,a.calcOwnMatrix())),s},pm=(a,t)=>{var e;const{transform:{target:s}}=t;(e=s.canvas)===null||e===void 0||e.fire("object:".concat(a),A(A({},t),{},{target:s})),s.fire(a,t)},Iy={left:-.5,top:-.5,center:0,bottom:.5,right:.5},Vt=a=>typeof a=="string"?Iy[a]:a-.5,Kc="not-allowed";function mm(a){return Vt(a.originX)===Vt(J)&&Vt(a.originY)===Vt(J)}function bm(a){return .5-Vt(a)}const Is=(a,t)=>a[t],vm=(a,t,e,s)=>({e:a,transform:t,pointer:new k(e,s)});function ym(a,t){const e=a.getTotalAngle()+oi(Math.atan2(t.y,t.x))+360;return Math.round(e%360/45)}function wf(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(),y=p!==void 0&&b!==void 0?f.translateToGivenOrigin(v,J,J,p,b):new k(f.left,f.top);return(f.angle?g.rotate(-Lt(f.angle),v):g).subtract(y)}(r,new k(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 Ny=(a,t,e,s)=>{const{target:i,offsetX:n,offsetY:r}=t,o=e-n,h=s-r,c=!Is(i,"lockMovementX")&&i.left!==o,u=!Is(i,"lockMovementY")&&i.top!==h;return c&&i.set(dt,o),u&&i.set(Ve,h),(c||u)&&pm(Up,vm(a,t,e,s)),c||u},_m={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"},xf=(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),wm=(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]},xm=function(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"1";return parseFloat(a)/(a.endsWith("%")?100:1)},Qc=a=>Math.min(Math.round(a),255).toString(16).toUpperCase().padStart(2,"0"),Sm=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 _m&&(t=_m[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]=wm(...this.getSource());return"hsl(".concat(t,",").concat(e,"%,").concat(s,"%)")}toHsla(){const[t,e,s,i]=wm(...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(Qc(t)).concat(Qc(e)).concat(Qc(s)).concat(Qc(Math.round(255*i)))}getAlpha(){return this.getSource()[3]}setAlpha(t){return this._source[3]=t,this}toGrayscale(){return this.setSource(Sm(this.getSource())),this}toBlackWhite(t){const[e,,,s]=Sm(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,xm(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=xf(u,c,s+1/3),o=xf(u,c,s),h=xf(u,c,s-1/3)}return[Math.round(255*r),Math.round(255*o),Math.round(255*h),xm(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")?oi(s):e.includes("turn")?360*s:s}}const Oe=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:af;const e=/\D{0,2}$/.exec(a),s=parseFloat(a),i=ct.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}},Sf=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}},Dh=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,'" '):"")};class Cm{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=Dh(Gt,this.fill);return[Dh(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(Qo(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(kn()),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 ni("`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}),Oh({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=ts(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 pf(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 mf(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],y=this.enableRetinaScaling,v=ts({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(v.getContext("2d"),x),this.viewportTransform=p,this.width=u,this.height=d,this.calcViewportBoundaries(),this.enableRetinaScaling=y,this.skipControlsDrawing=f,v}dispose(){return!this.disposed&&this.elements.cleanupDOM({width:this.width,height:this.height}),Uc.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," }>")}}E(Dh,"ownDefaults",jy);const By=["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 M(e.clientX+t.left,e.clientY+t.top)},Kc=a=>By.includes(a.type)||a.pointerType==="touch",gm=a=>{a.preventDefault(),a.stopPropagation()},hi=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}},Hy=["translateX","translateY","scaleX","scaleY"],pm=(a,t)=>Zo(a,jt(t,a.calcOwnMatrix())),Zo=(a,t)=>{const e=br(t),{translateX:s,translateY:i,scaleX:n,scaleY:r}=e,o=Ct(e,Hy),h=new M(s,i);a.flipX=!1,a.flipY=!1,Object.assign(a,o),a.set({scaleX:n,scaleY:r}),a.setPositionByOrigin(h,J,J)},mm=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}),Qc=(a,t,e)=>{const s=a/2,i=t/2,n=[new M(-s,-i),new M(s,-i),new M(-s,i),new M(s,i)].map(o=>o.transform(e)),r=hi(n);return new M(r.width,r.height)},Rh=function(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:Ee;return jt(Xe(arguments.length>1&&arguments[1]!==void 0?arguments[1]:Ee),a)},wr=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(Rh(t,e))},bm=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(Rh(t,e),!0)},xf=(a,t,e)=>{const s=Rh(t,e);return Zo(a,jt(s,a.calcOwnMatrix())),s},vm=(a,t)=>{var e;const{transform:{target:s}}=t;(e=s.canvas)===null||e===void 0||e.fire("object:".concat(a),T(T({},t),{},{target:s})),s.fire(a,t)},zy={left:-.5,top:-.5,center:0,bottom:.5,right:.5},Vt=a=>typeof a=="string"?zy[a]:a-.5,Jc="not-allowed";function ym(a){return Vt(a.originX)===Vt(J)&&Vt(a.originY)===Vt(J)}function _m(a){return .5-Vt(a)}const Fs=(a,t)=>a[t],wm=(a,t,e,s)=>({e:a,transform:t,pointer:new M(e,s)});function xm(a,t){const e=a.getTotalAngle()+ai(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 y=f.getRelativeCenterPoint(),v=p!==void 0&&b!==void 0?f.translateToGivenOrigin(y,J,J,p,b):new M(f.left,f.top);return(f.angle?g.rotate(-Lt(f.angle),y):g).subtract(v)}(r,new M(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 Gy=(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)&&vm(qp,wm(a,t,e,s)),c||u},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"},Cf=(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),Cm=(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]},Am=function(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"1";return parseFloat(a)/(a.endsWith("%")?100:1)},Zc=a=>Math.min(Math.round(a),255).toString(16).toUpperCase().padStart(2,"0"),Tm=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(E(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]=Cm(...this.getSource());return"hsl(".concat(t,",").concat(e,"%,").concat(s,"%)")}toHsla(){const[t,e,s,i]=Cm(...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(Zc(t)).concat(Zc(e)).concat(Zc(s)).concat(Zc(Math.round(255*i)))}getAlpha(){return this.getSource()[3]}setAlpha(t){return this._source[3]=t,this}toGrayscale(){return this.setSource(Tm(this.getSource())),this}toBlackWhite(t){const[e,,,s]=Tm(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,Am(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=Cf(u,c,s+1/3),o=Cf(u,c,s),h=Cf(u,c,s-1/3)}return[Math.round(255*r),Math.round(255*o),Math.round(255*h),Am(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")?ai(s):e.includes("turn")?360*s:s}}const Oe=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:lf;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}},Af=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}},Lh=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,'" '):"")};class Em{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=Lh(Gt,this.fill);return[Lh(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(Jo(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 y;h&&(h.clipPathId="CLIPPATH_".concat(kn()),y='<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(),` >
25
- `);const y=[r,c,e?"":this.addPaintOrder()," ",n?'transform="'.concat(n,'" '):""].join("");return t[b]=y,ys(f)&&p.push(f.toSVG(this)),ys(d)&&p.push(d.toSVG(this)),g&&p.push(g.toSVG(this)),h&&p.push(v),p.push(t.join("")),p.push(`</g>
25
+ `);const v=[r,c,e?"":this.addPaintOrder()," ",n?'transform="'.concat(n,'" '):""].join("");return t[b]=v,vs(f)&&p.push(f.toSVG(this)),vs(d)&&p.push(d.toSVG(this)),g&&p.push(g.toSVG(this)),h&&p.push(y),p.push(t.join("")),p.push(`</g>
26
26
  `),u&&p.push(`</g>
27
- `),s?s(p.join("")):p.join("")}addPaintOrder(){return this.paintFirst!==Gt?' paint-order="'.concat(this.paintFirst,'" '):""}}function Jc(a){return new RegExp("^("+a.join("|")+")\\b","i")}var Am;const Ns=String.raw(Am||(Am=An(["(?:[-+]?(?:d*.d+|d+.?)(?:[eE][-+]?d+)?)"],["(?:[-+]?(?:\\d*\\.\\d+|\\d+\\.?)(?:[eE][-+]?\\d+)?)"]))),Cf="http://www.w3.org/2000/svg",jy=new RegExp("(normal|italic)?\\s*(normal|small-caps)?\\s*(normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900)?\\s*("+Ns+"(?:px|cm|mm|em|pt|pc|in)*)(?:\\/(normal|"+Ns+"))?\\s+(.*)"),By={cx:dt,x:dt,r:"radius",cy:Ve,y:Ve,display:"visible",visibility:"visible",transform:"transformMatrix","fill-opacity":"fillOpacity","fill-rule":"fillRule","font-family":"fontFamily","font-size":"fontSize","font-style":"fontStyle","font-weight":"fontWeight","letter-spacing":"charSpacing","paint-order":"paintFirst","stroke-dasharray":"strokeDashArray","stroke-dashoffset":"strokeDashOffset","stroke-linecap":"strokeLineCap","stroke-linejoin":"strokeLineJoin","stroke-miterlimit":"strokeMiterLimit","stroke-opacity":"strokeOpacity","stroke-width":"strokeWidth","text-decoration":"textDecoration","text-anchor":"textAnchor",opacity:"opacity","clip-path":"clipPath","clip-rule":"clipRule","vector-effect":"strokeUniform","image-rendering":"imageSmoothing"},Af="font-size",Tf="clip-path",Hy=Jc(["path","circle","polygon","polyline","ellipse","rect","line","image","text"]),zy=Jc(["symbol","image","marker","pattern","view","svg"]),Tm=Jc(["symbol","g","a","svg","clipPath","defs"]),Em=new RegExp("^\\s*("+Ns+"+)\\s*,?\\s*("+Ns+"+)\\s*,?\\s*("+Ns+"+)\\s*,?\\s*("+Ns+"+)\\s*$"),Gy=new k(1,0),km=new k,Ef=(a,t)=>a.rotate(t),Zc=(a,t)=>new k(t).subtract(a),tu=a=>a.distanceFrom(km),eu=(a,t)=>Math.atan2(Zo(a,t),Pm(a,t)),Mm=a=>eu(Gy,a),su=a=>a.eq(km)?a:a.scalarDivide(tu(a)),kf=function(a){let t=!(arguments.length>1&&arguments[1]!==void 0)||arguments[1];return su(new k(-a.y,a.x).scalarMultiply(t?1:-1))},Zo=(a,t)=>a.x*t.y-a.y*t.x,Pm=(a,t)=>a.x*t.x+a.y*t.y,Mf=(a,t,e)=>{if(a.eq(t)||a.eq(e))return!0;const s=Zo(t,e),i=Zo(t,a),n=Zo(e,a);return s>=0?i>=0&&n<=0:!(i<=0&&n>=0)},Om="(-?\\d+(?:\\.\\d*)?(?:px)?(?:\\s?|$))?",Dm=new RegExp("(?:\\s|^)"+Om+Om+"("+Ns+"?(?:px)?)?(?:\\s?|$)(?:$|\\s)");class Fi{constructor(t){const e=typeof t=="string"?Fi.parseShadow(t):t;Object.assign(this,Fi.ownDefaults,e),this.id=kn()}static parseShadow(t){const e=t.trim(),[,s=0,i=0,n=0]=(Dm.exec(e)||[]).map(r=>parseFloat(r)||0);return{color:(e.replace(Dm,"")||"rgb(0,0,0)").trim(),offsetX:s,offsetY:i,blur:n}}toString(){return[this.offsetX,this.offsetY,this.blur,this.color].join("px ")}toSVG(t){const e=Ef(new k(this.offsetX,this.offsetY),Lt(-t.angle)),s=new gt(this.color);let i=40,n=40;return t.width&&t.height&&(i=100*wt((Math.abs(e.x)+this.blur)/t.width,ct.NUM_FRACTION_DIGITS)+20,n=100*wt((Math.abs(e.y)+this.blur)/t.height,ct.NUM_FRACTION_DIGITS)+20),t.flipX&&(e.x*=-1),t.flipY&&(e.y*=-1),'<filter id="SVGID_'.concat(this.id,'" y="-').concat(n,'%" height="').concat(100+2*n,'%" x="-').concat(i,'%" width="').concat(100+2*i,`%" >
28
- <feGaussianBlur in="SourceAlpha" stdDeviation="`).concat(wt(this.blur?this.blur/2:0,ct.NUM_FRACTION_DIGITS),`"></feGaussianBlur>
29
- <feOffset dx="`).concat(wt(e.x,ct.NUM_FRACTION_DIGITS),'" dy="').concat(wt(e.y,ct.NUM_FRACTION_DIGITS),`" result="oBlur" ></feOffset>
27
+ `),s?s(p.join("")):p.join("")}addPaintOrder(){return this.paintFirst!==Gt?' paint-order="'.concat(this.paintFirst,'" '):""}}function tu(a){return new RegExp("^("+a.join("|")+")\\b","i")}const xr="textDecorationThickness",km=["fontSize","fontWeight","fontFamily","fontStyle"],Mm=["underline","overline","linethrough"],Pm=[...km,"lineHeight","text","charSpacing","textAlign","styles","path","pathStartOffset","pathSide","pathAlign"],Om=[...Pm,...Mm,"textBackgroundColor","direction",xr],Vy=[...km,...Mm,Pe,"strokeWidth",Gt,"deltaY","textBackgroundColor",xr],Xy={_reNewline:uf,_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,textBackgroundColor:"",stroke:null,shadow:null,path:void 0,pathStartOffset:0,pathSide:dt,pathAlign:"baseline",charSpacing:0,deltaY:0,direction:"ltr",CACHE_FONT_SIZE:400,MIN_TEXT_WIDTH:2,superscript:{size:.6,baseline:-.35},subscript:{size:.6,baseline:.11},_fontSizeFraction:.222,offsets:{underline:.1,linethrough:-.28167,overline:-.81333},_fontSizeMult:1.13,[xr]:66.667},li="justify",eu="justify-left",Fh="justify-right",Ih="justify-center";var Dm,Rm,Lm;const Is=String.raw(Dm||(Dm=ii(["[-+]?(?:d*.d+|d+.?)(?:[eE][-+]?d+)?"],["[-+]?(?:\\d*\\.\\d+|\\d+\\.?)(?:[eE][-+]?\\d+)?"]))),Tf=String.raw(Rm||(Rm=ii(["(?:s*,?s+|s*,s*)"],["(?:\\s*,?\\s+|\\s*,\\s*)"]))),Ef="http://www.w3.org/2000/svg",Wy=new RegExp("(normal|italic)?\\s*(normal|small-caps)?\\s*(normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900)?\\s*("+Is+"(?:px|cm|mm|em|pt|pc|in)*)(?:\\/(normal|"+Is+"))?\\s+(.*)"),Uy={cx:dt,x:dt,r:"radius",cy:Ve,y:Ve,display:"visible",visibility:"visible",transform:"transformMatrix","fill-opacity":"fillOpacity","fill-rule":"fillRule","font-family":"fontFamily","font-size":"fontSize","font-style":"fontStyle","font-weight":"fontWeight","letter-spacing":"charSpacing","paint-order":"paintFirst","stroke-dasharray":"strokeDashArray","stroke-dashoffset":"strokeDashOffset","stroke-linecap":"strokeLineCap","stroke-linejoin":"strokeLineJoin","stroke-miterlimit":"strokeMiterLimit","stroke-opacity":"strokeOpacity","stroke-width":"strokeWidth","text-decoration":"textDecoration","text-anchor":"textAnchor",opacity:"opacity","clip-path":"clipPath","clip-rule":"clipRule","vector-effect":"strokeUniform","image-rendering":"imageSmoothing","text-decoration-thickness":xr},kf="font-size",Mf="clip-path",Yy=tu(["path","circle","polygon","polyline","ellipse","rect","line","image","text"]),$y=tu(["symbol","image","marker","pattern","view","svg"]),Fm=tu(["symbol","g","a","svg","clipPath","defs"]),Im=new RegExp(String.raw(Lm||(Lm=ii(["^s*(",")","(",")","(",")","(",")s*$"],["^\\s*(",")","(",")","(",")","(",")\\s*$"])),Is,Tf,Is,Tf,Is,Tf,Is)),qy=new M(1,0),Nm=new M,Pf=(a,t)=>a.rotate(t),su=(a,t)=>new M(t).subtract(a),iu=a=>a.distanceFrom(Nm),nu=(a,t)=>Math.atan2(ta(a,t),Bm(a,t)),jm=a=>nu(qy,a),ru=a=>a.eq(Nm)?a:a.scalarDivide(iu(a)),Of=function(a){let t=!(arguments.length>1&&arguments[1]!==void 0)||arguments[1];return ru(new M(-a.y,a.x).scalarMultiply(t?1:-1))},ta=(a,t)=>a.x*t.y-a.y*t.x,Bm=(a,t)=>a.x*t.x+a.y*t.y,Df=(a,t,e)=>{if(a.eq(t)||a.eq(e))return!0;const s=ta(t,e),i=ta(t,a),n=ta(e,a);return s>=0?i>=0&&n<=0:!(i<=0&&n>=0)},Hm="(-?\\d+(?:\\.\\d*)?(?:px)?(?:\\s?|$))?",zm=new RegExp("(?:\\s|^)"+Hm+Hm+"("+Is+"?(?:px)?)?(?:\\s?|$)(?:$|\\s)");class Ii{constructor(t){const e=typeof t=="string"?Ii.parseShadow(t):t;Object.assign(this,Ii.ownDefaults,e),this.id=kn()}static parseShadow(t){const e=t.trim(),[,s=0,i=0,n=0]=(zm.exec(e)||[]).map(r=>parseFloat(r)||0);return{color:(e.replace(zm,"")||"rgb(0,0,0)").trim(),offsetX:s,offsetY:i,blur:n}}toString(){return[this.offsetX,this.offsetY,this.blur,this.color].join("px ")}toSVG(t){const e=Pf(new M(this.offsetX,this.offsetY),Lt(-t.angle)),s=new gt(this.color);let i=40,n=40;return t.width&&t.height&&(i=100*yt((Math.abs(e.x)+this.blur)/t.width,ht.NUM_FRACTION_DIGITS)+20,n=100*yt((Math.abs(e.y)+this.blur)/t.height,ht.NUM_FRACTION_DIGITS)+20),t.flipX&&(e.x*=-1),t.flipY&&(e.y*=-1),'<filter id="SVGID_'.concat(this.id,'" y="-').concat(n,'%" height="').concat(100+2*n,'%" x="-').concat(i,'%" width="').concat(100+2*i,`%" >
28
+ <feGaussianBlur in="SourceAlpha" stdDeviation="`).concat(yt(this.blur?this.blur/2:0,ht.NUM_FRACTION_DIGITS),`"></feGaussianBlur>
29
+ <feOffset dx="`).concat(yt(e.x,ht.NUM_FRACTION_DIGITS),'" dy="').concat(yt(e.y,ht.NUM_FRACTION_DIGITS),`" result="oBlur" ></feOffset>
30
30
  <feFlood flood-color="`).concat(s.toRgb(),'" flood-opacity="').concat(s.getAlpha(),`"/>
31
31
  <feComposite in2="oBlur" operator="in" />
32
32
  <feMerge>
@@ -34,44 +34,44 @@ 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=Fi.ownDefaults;return this.includeDefaultValues?t:bf(t,(s,i)=>s!==e[i])}static async fromObject(t){return new this(t)}}T(Fi,"ownDefaults",{color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1}),T(Fi,"type","shadow"),z.setClass(Fi,"shadow");const xr=(a,t,e)=>Math.max(a,Math.min(t,e)),Vy=[Ve,dt,Me,Ze,"flipX","flipY","originX","originY","angle","opacity","globalCompositeOperation","shadow","visible",Uo,Yo],Ii=[Gt,Pe,"strokeWidth","strokeDashArray","width","height","paintFirst","strokeUniform","strokeLineCap","strokeDashOffset","strokeLineJoin","strokeMiterLimit","backgroundColor","clipPath"],Xy={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:Gt,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/Li*Math.asin(1):e/Li*Math.asin(t/a),{a,c:t,p:e,s}),Rm=(a,t,e,s,i)=>a*Math.pow(2,10*(s-=1))*Math.sin((s*i-t)*Li/e),Lm=(a,t,e,s)=>-e*Math.cos(a/s*Tn)+e+t,Of=(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,Fm=(a,t,e,s)=>e-Of(s-a,0,e,s)+t;var Wy=Object.freeze({__proto__:null,defaultEasing:Lm,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:Fm,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-Rm(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*Fm(2*a,0,e,s)+t:.5*Of(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*Rm(r,o,h,a,s)+t:r*Math.pow(2,-10*(a-=1))*Math.sin((a*s-o)*Li/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*Tn)+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:Of,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)*Li/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*Tn)+t});const Uy=()=>!1;class Df{constructor(t){let{startValue:e,byValue:s,duration:i=500,delay:n=0,easing:r=Lm,onStart:o=pr,onChange:h=pr,onComplete:c=pr,abort:u=Uy,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(()=>Th(t),this.delay):Th(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),Th(this.tick)))}register(){Xc.push(this)}unregister(){Xc.remove(this)}abort(){this._state="aborted",this.unregister()}}const Yy=["startValue","endValue"];class $y extends Df{constructor(t){let{startValue:e=0,endValue:s=100}=t;super(A(A({},Ct(t,Yy)),{},{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 qy=["startValue","endValue"];class Ky extends Df{constructor(t){let{startValue:e=[0],endValue:s=[100]}=t;super(A(A({},Ct(t,qy)),{},{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 Qy=["startValue","endValue","easing","onChange","onComplete","abort"],Jy=(a,t,e,s)=>t+e*(1-Math.cos(a/s*Tn)),Rf=a=>a&&((t,e,s)=>a(new gt(t).toRgba(),e,s));class Zy extends Df{constructor(t){let{startValue:e,endValue:s,easing:i=Jy,onChange:n,onComplete:r,abort:o}=t,h=Ct(t,Qy);const c=new gt(e).getSource(),u=new gt(s).getSource();super(A(A({},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),xr(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 Ky(a):new $y(a);return t.start(),t}function Im(a){const t=new Zy(a);return t.start(),t}class Pt{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 k(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,y=p/b;return(n||0<=v&&v<=1)&&(r||0<=y&&y<=1)?new Pt("Intersection").append(new k(t.x+v*o,t.y+v*h)):new Pt}if(g===0||p===0){const v=n||r||Pt.isPointContained(t,s,i)||Pt.isPointContained(e,s,i)||Pt.isPointContained(s,t,e)||Pt.isPointContained(i,t,e);return new Pt(v?"Coincident":void 0)}return new Pt("Parallel")}static intersectSegmentLine(t,e,s,i){return Pt.intersectLineLine(t,e,s,i,!1,!0)}static intersectSegmentSegment(t,e,s,i){return Pt.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 Pt,r=s.length;for(let o,h,c,u=0;u<r;u++){if(o=s[u],h=s[(u+1)%r],c=Pt.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 Pt.intersectLinePolygon(t,e,s,!1)}static intersectPolygonPolygon(t,e){const s=new Pt,i=t.length,n=[];for(let r=0;r<i;r++){const o=t[r],h=t[(r+1)%i],c=Pt.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 Pt("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 k(n.x,i.y),o=new k(i.x,n.y);return Pt.intersectPolygonPolygon(t,[i,r,n,o])}}class t_ extends Kp{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 k(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 Pt.intersectPolygonRectangle(this.getCoords(),t,e).status==="Intersection"}intersectsWithObject(t){const e=Pt.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 Pt.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 ai(this.getCoords())}getScaledWidth(){return this._getTransformedDimensions().x}getScaledHeight(){return this._getTransformedDimensions().y}scale(t){this._set(Me,t),this._set(Ze,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?oi(tm(this.calcTransformMatrix())):this.angle}getViewportTransform(){var t;return((t=this.canvas)===null||t===void 0?void 0:t.viewportTransform)||Ee.concat()}calcACoords(){const t=vr({angle:this.angle}),{x:e,y:s}=this.getRelativeCenterPoint(),i=qo(e,s),n=jt(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=jt(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=sm(i);return this.ownMatrixCache={key:t,value:n},n}_getNonTransformedDimensions(){return new k(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=A({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 k(r*e.scaleX,o*e.scaleY):qc(r,o,Eh(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 k(r,o)}translateToCenterPoint(t,e,s){if(e===J&&s===J)return t;const i=this.translateToGivenOrigin(t,e,s,J,J);return this.angle?i.rotate(Lt(this.angle),t):i}translateToOriginPoint(t,e,s){const i=this.translateToGivenOrigin(t,J,J,e,s);return this.angle?i.rotate(Lt(this.angle),t):i}getCenterPoint(){const t=this.getRelativeCenterPoint();return this.group?ge(t,this.group.calcTransformMatrix()):t}getRelativeCenterPoint(){return this.translateToCenterPoint(new k(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 e_=["type"],s_=["extraParam"];let Ni=class Td extends t_{static getDefaults(){return Td.ownDefaults}get type(){const t=this.constructor.type;return t==="FabricObject"?"object":t.toLowerCase()}set type(t){Ri("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=vs(),this._cacheContext=this._cacheCanvas.getContext("2d"),this._updateCacheCanvas(),this.dirty=!0}_limitCacheSize(t){const e=t.width,s=t.height,i=ct.maxCacheSideLimit,n=ct.minCacheSideLimit;if(e<=i&&s<=i&&e*s<=ct.perfLimitSizeTotal)return e<n&&(t.width=n),s<n&&(t.height=n),t;const r=e/s,[o,h]=Ch.limitDimsByArea(r),c=xr(n,o,i),u=xr(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 k(Math.abs(this.scaleX),Math.abs(this.scaleY));const t=br(this.calcTransformMatrix());return new k(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!==Ze||(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 Fi||(e=new Fi(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=ts(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,ys(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&&(ys(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 k(1,1):this.getObjectScaling();t.shadowColor=e.color,t.shadowBlur=e.blur*ct.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(!ys(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=ts({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 k(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(z.getClass("image"))(e)}toCanvasElement(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const e=yf(this),s=this.group,i=this.shadow,n=Math.abs,r=t.enableRetinaScaling?Wp():1,o=(t.multiplier||1)*r,h=t.canvasProvider||(x=>new Ph(x,{enableRetinaScaling:!1,renderOnAddRemove:!1,skipOffscreen:!1}));delete this.group,t.withoutTransform&&fm(this),t.withoutShadow&&(this.shadow=null),t.viewportTransform&&_f(this,this.getViewportTransform()),this.setCoords();const c=vs(),u=this.getBoundingRect(),d=this.shadow,f=new k;if(d){const x=d.blur,S=d.nonScaling?new k(1,1):this.getObjectScaling();f.x=2*Math.round(n(d.offsetX)+x)*n(S.x),f.y=2*Math.round(n(d.offsetY)+x)*n(S.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 k(b.width/2,b.height/2),J,J);const v=this.canvas;b._objects=[this],this.set("canvas",b),this.setCoords();const y=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(),y}toDataURL(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return ff(this.toCanvasElement(t),t.format||"png",t.quality||1)}toBlob(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return gf(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=J,this.originY=J,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&&ri().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=A(A({},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?Im(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=ct.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:y,strokeLineJoin:x,strokeUniform:S,strokeMiterLimit:C,scaleX:E,scaleY:P,angle:M,flipX:O,flipY:R,opacity:L,visible:N,backgroundColor:D,fillRule:F,paintFirst:j,globalCompositeOperation:q,skewX:I,skewY:H}=this;i&&!i.excludeFromExport&&(e=i.toObject(t.concat("inverted","absolutePositioned")));const it=te=>wt(te,s),kt=A(A({},yr(this,t)),{},{type:this.constructor.type,version:rf,originX:d,originY:f,left:it(c),top:it(u),width:it(g),height:it(p),fill:im(n)?n.toObject():n,stroke:im(r)?r.toObject():r,strokeWidth:it(b),strokeDashArray:h&&h.concat(),strokeLineCap:v,strokeDashOffset:y,strokeLineJoin:x,strokeUniform:S,strokeMiterLimit:it(C),scaleX:it(E),scaleY:it(P),angle:it(M),flipX:O,flipY:R,opacity:it(L),shadow:o&&o.toObject(),visible:N,backgroundColor:D,fillRule:F,paintFirst:j,globalCompositeOperation:q,skewX:it(I),skewY:it(H)},e?{clipPath:e}:null);return this.includeDefaultValues?kt:this._removeDefaultValues(kt)}toDatalessObject(t){return this.toObject(t)}_removeDefaultValues(t){const e=this.constructor.getDefaults(),s=Object.keys(e).length>0?e:Object.getPrototypeOf(this);return bf(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,e_),s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{extraParam:i}=s,n=Ct(s,s_);return Mh(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(Ni,"stateProperties",Vy),T(Ni,"cacheProperties",Ii),T(Ni,"ownDefaults",Xy),T(Ni,"type","FabricObject"),T(Ni,"colorProperties",[Gt,Pe,"backgroundColor"]),T(Ni,"customProperties",[]),z.setClass(Ni),z.setClass(Ni,"object");const ta=(a,t,e)=>(s,i,n,r)=>{const o=t(s,i,n,r);return o&&pm(a,A(A({},vm(s,i,n,r)),e)),o};function ea(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 Nm=ta(Ah,ea((a,t,e,s)=>{const i=wf(t,t.originX,t.originY,e,s);if(Vt(t.originX)===Vt(J)||Vt(t.originX)===Vt(Nt)&&i.x<0||Vt(t.originX)===Vt(dt)&&i.x>0){const{target:n}=t,r=n.strokeWidth/(n.strokeUniform?n.scaleX:1),o=mm(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 i_(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:Gt,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,Li,!1),a[h](),c&&a.stroke(),a.restore()}function n_(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:Gt,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(Lt(f)),a["".concat(h,"Rect")](-u,-d,n,r),c&&a.strokeRect(-u,-d,n,r),a.restore()}class js{constructor(t){T(this,"visible",!0),T(this,"actionName",Gc),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)&&Pt.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 k(this.x*t.x+this.offsetX,this.y*t.y+this.offsetY).transform(e)}calcCornerCoords(t,e,s,i,n,r){const o=Uc([qo(s,i),vr({angle:t}),Yc((n?this.touchSizeX:this.sizeX)||e,(n?this.touchSizeY:this.sizeY)||e)]);return{tl:new k(-.5,-.5).transform(o),tr:new k(.5,-.5).transform(o),br:new k(.5,.5).transform(o),bl:new k(-.5,.5).transform(o)}}render(t,e,s,i,n){((i=i||{}).cornerStyle||n.cornerStyle)==="circle"?i_.call(this,t,e,s,i,n):n_.call(this,t,e,s,i,n)}}const r_=(a,t,e)=>e.lockRotation?Kc:t.cursorStyle,o_=ta(Yp,ea((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(Is(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=oi(f-d+o);if(i.snapAngle&&i.snapAngle>0){const b=i.snapAngle,v=i.snapThreshold||b,y=Math.ceil(g/b)*b,x=Math.floor(g/b)*b;Math.abs(g-x)<v?g=x:Math.abs(g-y)<v&&(g=y)}g<0&&(g=360+g),g%=360;const p=i.angle!==g;return i.angle=g,p}));function jm(a,t){const e=t.canvas,s=a[e.uniScaleKey];return e.uniformScaling&&!s||!e.uniformScaling&&s}function Bm(a,t,e){const s=Is(a,"lockScalingX"),i=Is(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 a_=["e","se","s","sw","w","nw","n","ne","e"],Rh=(a,t,e)=>{const s=jm(a,e);if(Bm(e,t.x!==0&&t.y===0?"x":t.x===0&&t.y!==0?"y":"",s))return Kc;const i=ym(e,t);return"".concat(a_[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=jm(a,n);let h,c,u,d,f,g;if(Bm(n,r,o))return!1;if(t.gestureScale)c=t.scaleX*t.gestureScale,u=t.scaleY*t.gestureScale;else{if(h=wf(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),Is(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:y}=t,x=v/(Math.abs(d.x*y.scaleX/n.scaleX)+Math.abs(d.y*y.scaleY/n.scaleY));c=y.scaleX*x,u=y.scaleY*x}else c=Math.abs(h.x*n.scaleX/d.x),u=Math.abs(h.y*n.scaleY/d.y);mm(t)&&(c*=2,u*=2),t.signX!==f&&r!=="y"&&(t.originX=bm(t.originX),c*=-1,t.signX=f),t.signY!==g&&r!=="x"&&(t.originY=bm(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(Ze,u)):(!Is(n,"lockScalingX")&&n.set(Me,c),!Is(n,"lockScalingY")&&n.set(Ze,u)),p!==n.scaleX||b!==n.scaleY}const iu=ta(Hc,ea((a,t,e,s)=>Ff(a,t,e,s))),h_=ta(Hc,ea((a,t,e,s)=>Ff(a,t,e,s,{by:"x"}))),l_=ta(Hc,ea((a,t,e,s)=>Ff(a,t,e,s,{by:"y"}))),c_=["target","ex","ey","skewingSide"],If={x:{counterAxis:"y",scale:Me,skew:Uo,lockSkewing:"lockSkewingX",origin:"originX",flip:"flipX"},y:{counterAxis:"x",scale:Ze,skew:Yo,lockSkewing:"lockSkewingY",origin:"originY",flip:"flipY"}},u_=["ns","nesw","ew","nwse"],d_=(a,t,e)=>{if(t.x!==0&&Is(e,"lockSkewingY")||t.y!==0&&Is(e,"lockSkewingX"))return Kc;const s=ym(e,t)%4;return"".concat(u_[s],"-resize")};function Hm(a,t,e,s,i){const{target:n}=e,{counterAxis:r,origin:o,lockSkewing:h,skew:c,flip:u}=If[a];if(Is(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&&wf(e,J,J,s,i)[a]>0||n[c]>0?1:-1)*p)+.5;return ta($p,ea((y,x,S,C)=>function(E,P,M){let{target:O,ex:R,ey:L,skewingSide:N}=P,D=Ct(P,c_);const{skew:F}=If[E],j=M.subtract(new k(R,L)).divide(new k(O.scaleX,O.scaleY))[E],q=O[F],I=D[F],H=Math.tan(Lt(I)),it=E==="y"?O._getTransformedDimensions({scaleX:1,scaleY:1,skewX:0}).x:O._getTransformedDimensions({scaleX:1,scaleY:1}).y,kt=2*j*N/Math.max(it,1)+H,te=oi(Math.atan(kt));O.set(F,te);const fe=q!==O[F];if(fe&&E==="y"){const{skewX:Yt,scaleX:St}=O,He=O._getTransformedDimensions({skewY:q}),Pi=O._getTransformedDimensions(),It=Yt!==0?He.x/Pi.x:1;It!==1&&O.set(Me,It*St)}return fe}(a,x,new k(S,C))))(t,A(A({},e),{},{[o]:b,skewingSide:p}),s,i)}const f_=(a,t,e,s)=>Hm("x",a,t,e,s),g_=(a,t,e,s)=>Hm("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?Uo:Ze:t.y===0?s?Yo:Me:""},sa=(a,t,e)=>nu(a,e)?d_(0,t,e):Rh(a,t,e),zm=(a,t,e,s)=>nu(a,t.target)?g_(a,t,e,s):h_(a,t,e,s),Gm=(a,t,e,s)=>nu(a,t.target)?f_(a,t,e,s):l_(a,t,e,s),Vm=()=>({ml:new js({x:-.5,y:0,cursorStyleHandler:sa,actionHandler:zm,getActionName:ru}),mr:new js({x:.5,y:0,cursorStyleHandler:sa,actionHandler:zm,getActionName:ru}),mb:new js({x:0,y:.5,cursorStyleHandler:sa,actionHandler:Gm,getActionName:ru}),mt:new js({x:0,y:-.5,cursorStyleHandler:sa,actionHandler:Gm,getActionName:ru}),tl:new js({x:-.5,y:-.5,cursorStyleHandler:Rh,actionHandler:iu}),tr:new js({x:.5,y:-.5,cursorStyleHandler:Rh,actionHandler:iu}),bl:new js({x:-.5,y:.5,cursorStyleHandler:Rh,actionHandler:iu}),br:new js({x:.5,y:.5,cursorStyleHandler:Rh,actionHandler:iu}),mtr:new js({x:0,y:-.5,actionHandler:o_,cursorStyleHandler:r_,offsetY:-40,withConnection:!0,actionName:cf})}),p_=()=>({mr:new js({x:.5,y:0,actionHandler:Nm,cursorStyleHandler:sa,actionName:Ah}),ml:new js({x:-.5,y:0,actionHandler:Nm,cursorStyleHandler:sa,actionName:Ah})}),m_=()=>A(A({},Vm()),p_());class Lh extends Ni{static getDefaults(){return A(A({},super.getDefaults()),Lh.ownDefaults)}constructor(t){super(),Object.assign(this,this.constructor.createControls(),Lh.ownDefaults),this.setOptions(t)}static createControls(){return{controls:Vm()}}_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(Gc))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=qo(e.x,e.y),i=vr({angle:this.getTotalAngle()-(this.group&&this.flipX?180:0)}),n=jt(s,i),r=jt(t,n),o=jt(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(Lt(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=A({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=A({hasBorders:s,hasControls:i},e),r=this.getViewportTransform(),o=n.hasBorders,h=n.hasControls,c=jt(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(Lt(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=qc(this.width,this.height,Eh(e)),r=this.isStrokeAccountedForInDimensions()?df:(this.strokeUniform?new k().scalarAdd(this.canvas?this.canvas.getZoom():1):new k(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=A({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 Xm(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(Lh,"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 Lh{}Xm(pe,[Cm]),z.setClass(pe),z.setClass(pe,"object");const Wm=(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 Um{constructor(t){this.options=t,this.strokeProjectionMagnitude=this.options.strokeWidth/2,this.scale=new k(this.options.scaleX,this.options.scaleY),this.strokeUniformScalar=this.options.strokeUniform?new k(1/this.options.scaleX,1/this.options.scaleY):new k(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 k(t);return e.y+=e.x*Math.tan(Lt(this.options.skewY)),e.x+=e.y*Math.tan(Lt(this.options.skewX)),e}scaleUnitVector(t,e){return t.multiply(this.strokeUniformScalar).scalarMultiply(e)}}const b_=new k;class ia extends Um{static getOrthogonalRotationFactor(t,e){const s=e?eu(t,e):Mm(t);return Math.abs(s)<Tn?-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 k(t),this.B=new k(e),this.C=new k(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(b_)?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=ia.getOrthogonalRotationFactor(n,this.bisector);return this.scaleUnitVector(n,s*r)}projectBevel(){const t=[];return(this.alpha%Li==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 k(ia.getOrthogonalRotationFactor(this.bisector),ia.getOrthogonalRotationFactor(new k(this.bisector.y,this.bisector.x)));return[new k(1,0).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(i),new k(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 k(Math.tan(Lt(i)),Math.tan(Lt(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 k(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 k(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%Li==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=Zo(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 Ym extends Um{constructor(t,e,s){super(s),this.A=new k(t),this.T=new k(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 k(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 ia(this.A,this.T,this.T,this.options).projectRound());return t}projectSquare(){const t=[];if(this.A.eq(this.T)){const e=new k(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 $m=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 k(r)),n),[new k(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 Ym(n,n,t).project()):!e||r!==0&&r!==o.length-1?s.push(...new ia(n,h,c,t).project()):s.push(...new Ym(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]=A({},a[e][s])})}),t},qm=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=v_(a,s))!==!1&&t.push(e);return t},v_=(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 y_=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:qm,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)},Km=(a,t)=>{const e=t.split(`
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(lf),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]=A({},a[n].style),i===a[n].end-1&&n++)}return s},Mn=["display","transform",Gt,"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 Jm(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 __(a,t){let e=!0;const s=Jm(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=Jm(i=i.parentElement,r);return n.length===0}(a,t)),s&&e&&t.length===0}const w_=a=>{var t;return(t=By[a])!==null&&t!==void 0?t:a},x_=new RegExp("(".concat(Ns,")"),"gi"),S_=a=>a.replace(x_," $1 ").replace(/,/gi," ").replace(/\s+/gi," ");var Zm,t0,e0,s0,i0,n0,r0;const De="(".concat(Ns,")"),C_=String.raw(Zm||(Zm=An(["(skewX)(",")"],["(skewX)\\(","\\)"])),De),A_=String.raw(t0||(t0=An(["(skewY)(",")"],["(skewY)\\(","\\)"])),De),T_=String.raw(e0||(e0=An(["(rotate)(","(?: "," ",")?)"],["(rotate)\\(","(?: "," ",")?\\)"])),De,De,De),E_=String.raw(s0||(s0=An(["(scale)(","(?: ",")?)"],["(scale)\\(","(?: ",")?\\)"])),De,De),k_=String.raw(i0||(i0=An(["(translate)(","(?: ",")?)"],["(translate)\\(","(?: ",")?\\)"])),De,De),M_=String.raw(n0||(n0=An(["(matrix)("," "," "," "," "," ",")"],["(matrix)\\("," "," "," "," "," ","\\)"])),De,De,De,De,De,De),jf="(?:".concat(M_,"|").concat(k_,"|").concat(T_,"|").concat(E_,"|").concat(C_,"|").concat(A_,")"),P_="(?:".concat(jf,"*)"),O_=String.raw(r0||(r0=An(["^s*(?:","?)s*$"],["^\\s*(?:","?)\\s*$"])),P_),D_=new RegExp(O_),R_=new RegExp(jf),L_=new RegExp(jf,"g");function hu(a){const t=[];if(!(a=S_(a).replace(/\s*([()])\s*/gi,"$1"))||a&&!D_.test(a))return[...Ee];for(const e of a.matchAll(L_)){const s=R_.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=qo(h,c);break;case cf:i=vr({angle:h},{x:c,y:u});break;case Gc:i=Yc(h,c);break;case Uo:i=pf(h);break;case Yo:i=mf(h);break;case"matrix":i=[h,c,u,d,f,g]}t.push(i)}return Uc(t)}function F_(a,t,e,s){const i=Array.isArray(t);let n,r=t;if(a!==Gt&&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?jt(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"?Nt:J;else if(a==="charSpacing")n=Oe(t,s)/s*1e3;else if(a==="paintFirst"){const o=t.indexOf(Gt),h=t.indexOf(Pe);r=Gt,(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(Oe):Oe(t,s)}}else r="";return!i&&isNaN(n)?r:n}function I_(a,t){const e=a.match(jy);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=Oe(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 N_(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 j_={stroke:"strokeOpacity",fill:"fillOpacity"};function ji(a,t,e){if(!a)return{};let s,i={},n=af;a.parentNode&&Tm.test(a.parentNode.nodeName)&&(i=ji(a.parentElement,t,e),i.fontSize&&(s=n=Oe(i.fontSize)));const r=A(A(A({},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)__(c,f.split(" "))&&(d=A(A({},d),u[f]));return d}(a,e)),N_(a));r[Tf]&&a.setAttribute(Tf,r[Tf]),r[Af]&&(s=Oe(r[Af],n),r[Af]="".concat(s));const o={};for(const c in r){const u=w_(c),d=F_(u,r[c],i,s);o[u]=d}o&&o.font&&I_(o.font,o);const h=A(A({},i),o);return Tm.test(a.nodeName)?h:function(c){const u=pe.getDefaults();return Object.entries(j_).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(wt(p.getAlpha()*c[g],2)).toRgba()}),c}(h)}const B_=["left","top","width","height","visible"],o0=["rx","ry"];class hi extends pe{static getDefaults(){return A(A({},super.getDefaults()),hi.ownDefaults)}constructor(t){super(),Object.assign(this,hi.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-En*r,n,i+e,n+En*o,i+e,n+o),t.lineTo(i+e,n+s-o),h&&t.bezierCurveTo(i+e,n+s-En*o,i+e-En*r,n+s,i+e-r,n+s),t.lineTo(i+r,n+s),h&&t.bezierCurveTo(i+En*r,n+s,i,n+s-En*o,i,n+s-o),t.lineTo(i,n+o),h&&t.bezierCurveTo(i,n+En*o,i+En*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([...o0,...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=ji(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:r=0,width:o=0,height:h=0,visible:c=!0}=i,u=Ct(i,B_);return new this(A(A(A({},e),u),{},{left:n,top:r,width:o,height:h,visible:!!(c&&o&&h)}))}}T(hi,"type","Rect"),T(hi,"cacheProperties",[...Ii,...o0]),T(hi,"ownDefaults",{rx:0,ry:0}),T(hi,"ATTRIBUTE_NAMES",[...Mn,"x","y","rx","ry","width","height"]),z.setClass(hi),z.setSVGClass(hi);const Bi="initialization",lu="added",Hf="removed",cu="imperative",a0=(a,t)=>{const{strokeUniform:e,strokeWidth:s,width:i,height:n,group:r}=t,o=r&&r!==a?Oh(r.calcTransformMatrix(),a.calcTransformMatrix()):null,h=o?t.getRelativeCenterPoint().transform(o):t.getRelativeCenterPoint(),c=!t.isStrokeAccountedForInDimensions(),u=e&&c?gm(new k(s,s),void 0,a.calcTransformMatrix()):df,d=!e&&c?s:0,f=qc(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===Bi||e===cu||!!s&&i!==s}shouldLayoutClipPath(t){let{type:e,target:{clipPath:s}}=t;return e!==Bi&&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}=ai(t.map(d=>a0(i,d)).reduce((d,f)=>d.concat(f),[])),c=new k(o,h),u=new k(n,r).add(c.scalarDivide(2));if(s===Bi){const d=this.getInitialSize(e,{size:c,center:u});return{center:u,relativeCorrection:new k(0,0),size:d}}return{center:u.transform(i.calcOwnMatrix()),size:c}}}T(uu,"type","strategy");class zf extends uu{shouldPerformLayout(t){return!0}}T(zf,"type","fit-content"),z.setClass(zf);const H_=["strategy"],z_=["target","strategy","bubbles","prevStrategy"],h0="layoutManager";class Fh{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:new zf;T(this,"strategy",void 0),this.strategy=t,this._subscriptions=new Map}performLayout(t){const e=A(A({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,Up,Ah,Yp,Hc,$p,zc,My,Py].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===Bi||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,H_);e.forEachObject(r=>r.layoutManager&&r.layoutManager.performLayout(A(A({},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===Bi?new k:e.getRelativeCenterPoint(),{center:o,correction:h=new k,relativeCorrection:c=new k}=n,u=r.subtract(o).add(h).transform(i===Bi?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===Bi?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,J,J),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,z_),{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(A(A({},o),{},{target:c}))),s.set("dirty",!0)}dispose(){const{_subscriptions:t}=this;t.forEach(e=>e.forEach(s=>s())),t.clear()}toObject(){return{type:h0,strategy:this.strategy.constructor.type}}toJSON(){return this.toObject()}}z.setClass(Fh,h0);const G_=["type","objects","layoutManager"];class V_ extends Fh{performLayout(){}}class _s extends qp(pe){static getDefaults(){return A(A({},super.getDefaults()),_s.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,_s.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 Fh,this.layoutManager.performLayout({type:Bi,target:this,targets:[...t],x:e.left,y:e.top})}canEnterGroup(t){return t===this||this.isDescendantOf(t)?(Ri("error","Group: circular object trees are not supported, this call has no effect"),!1):this._objects.indexOf(t)===-1||(Ri("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&&Jo(t,jt(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||(Jo(t,jt(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(A({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 A(A(A({},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=hi.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",` >
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=Ii.ownDefaults;return this.includeDefaultValues?t:yf(t,(s,i)=>s!==e[i])}static async fromObject(t){return new this(t)}}E(Ii,"ownDefaults",{color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1}),E(Ii,"type","shadow"),z.setClass(Ii,"shadow");const Sr=(a,t,e)=>Math.max(a,Math.min(t,e)),Ky=[Ve,dt,Me,Ze,"flipX","flipY","originX","originY","angle","opacity","globalCompositeOperation","shadow","visible",Yo,$o],Ni=[Gt,Pe,"strokeWidth","strokeDashArray","width","height","paintFirst","strokeUniform","strokeLineCap","strokeDashOffset","strokeLineJoin","strokeMiterLimit","backgroundColor","clipPath"],Qy={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:Gt,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},Rf=(a,t,e,s)=>(a<Math.abs(t)?(a=t,s=e/4):s=t===0&&a===0?e/Fi*Math.asin(1):e/Fi*Math.asin(t/a),{a,c:t,p:e,s}),Gm=(a,t,e,s,i)=>a*Math.pow(2,10*(s-=1))*Math.sin((s*i-t)*Fi/e),Vm=(a,t,e,s)=>-e*Math.cos(a/s*Tn)+e+t,Lf=(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,Xm=(a,t,e,s)=>e-Lf(s-a,0,e,s)+t;var Jy=Object.freeze({__proto__:null,defaultEasing:Vm,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:Xm,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}=Rf(i,e,n,1.70158);return-Gm(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*Xm(2*a,0,e,s)+t:.5*Lf(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}=Rf(i,e,n,1.70158);return a<1?-.5*Gm(r,o,h,a,s)+t:r*Math.pow(2,-10*(a-=1))*Math.sin((a*s-o)*Fi/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*Tn)+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:Lf,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}=Rf(i,e,n,1.70158);return r*2**(-10*a)*Math.sin((a*s-o)*Fi/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*Tn)+t});const Zy=()=>!1;class Ff{constructor(t){let{startValue:e,byValue:s,duration:i=500,delay:n=0,easing:r=Vm,onStart:o=pr,onChange:h=pr,onComplete:c=pr,abort:u=Zy,target:d}=t;E(this,"_state","pending"),E(this,"durationProgress",0),E(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(()=>kh(t),this.delay):kh(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),kh(this.tick)))}register(){Uc.push(this)}unregister(){Uc.remove(this)}abort(){this._state="aborted",this.unregister()}}const t_=["startValue","endValue"];class e_ extends Ff{constructor(t){let{startValue:e=0,endValue:s=100}=t;super(T(T({},Ct(t,t_)),{},{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 s_=["startValue","endValue"];class i_ extends Ff{constructor(t){let{startValue:e=[0],endValue:s=[100]}=t;super(T(T({},Ct(t,s_)),{},{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 n_=["startValue","endValue","easing","onChange","onComplete","abort"],r_=(a,t,e,s)=>t+e*(1-Math.cos(a/s*Tn)),If=a=>a&&((t,e,s)=>a(new gt(t).toRgba(),e,s));class o_ extends Ff{constructor(t){let{startValue:e,endValue:s,easing:i=r_,onChange:n,onComplete:r,abort:o}=t,h=Ct(t,n_);const c=new gt(e).getSource(),u=new gt(s).getSource();super(T(T({},h),{},{startValue:c,byValue:u.map((d,f)=>d-c[f]),easing:i,onChange:If(n),onComplete:If(r),abort:If(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),Sr(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 Nf(a){const t=(e=>Array.isArray(e.startValue)||Array.isArray(e.endValue))(a)?new i_(a):new e_(a);return t.start(),t}function Wm(a){const t=new o_(a);return t.start(),t}class Pt{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=su(e,s),r=su(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 M(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 y=g/b,v=p/b;return(n||0<=y&&y<=1)&&(r||0<=v&&v<=1)?new Pt("Intersection").append(new M(t.x+y*o,t.y+y*h)):new Pt}if(g===0||p===0){const y=n||r||Pt.isPointContained(t,s,i)||Pt.isPointContained(e,s,i)||Pt.isPointContained(s,t,e)||Pt.isPointContained(i,t,e);return new Pt(y?"Coincident":void 0)}return new Pt("Parallel")}static intersectSegmentLine(t,e,s,i){return Pt.intersectLineLine(t,e,s,i,!1,!0)}static intersectSegmentSegment(t,e,s,i){return Pt.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 Pt,r=s.length;for(let o,h,c,u=0;u<r;u++){if(o=s[u],h=s[(u+1)%r],c=Pt.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 Pt.intersectLinePolygon(t,e,s,!1)}static intersectPolygonPolygon(t,e){const s=new Pt,i=t.length,n=[];for(let r=0;r<i;r++){const o=t[r],h=t[(r+1)%i],c=Pt.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 Pt("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 M(n.x,i.y),o=new M(i.x,n.y);return Pt.intersectPolygonPolygon(t,[i,r,n,o])}}class a_ extends Zp{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 M(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 Pt.intersectPolygonRectangle(this.getCoords(),t,e).status==="Intersection"}intersectsWithObject(t){const e=Pt.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 Pt.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 hi(this.getCoords())}getScaledWidth(){return this._getTransformedDimensions().x}getScaledHeight(){return this._getTransformedDimensions().y}scale(t){this._set(Me,t),this._set(Ze,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?ai(im(this.calcTransformMatrix())):this.angle}getViewportTransform(){var t;return((t=this.canvas)===null||t===void 0?void 0:t.viewportTransform)||Ee.concat()}calcACoords(){const t=vr({angle:this.angle}),{x:e,y:s}=this.getRelativeCenterPoint(),i=Ko(e,s),n=jt(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=jt(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=rm(i);return this.ownMatrixCache={key:t,value:n},n}_getNonTransformedDimensions(){return new M(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=T({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 M(r*e.scaleX,o*e.scaleY):Qc(r,o,Mh(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 M(r,o)}translateToCenterPoint(t,e,s){if(e===J&&s===J)return t;const i=this.translateToGivenOrigin(t,e,s,J,J);return this.angle?i.rotate(Lt(this.angle),t):i}translateToOriginPoint(t,e,s){const i=this.translateToGivenOrigin(t,J,J,e,s);return this.angle?i.rotate(Lt(this.angle),t):i}getCenterPoint(){const t=this.getRelativeCenterPoint();return this.group?ge(t,this.group.calcTransformMatrix()):t}getRelativeCenterPoint(){return this.translateToCenterPoint(new M(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 h_=["type"],l_=["extraParam"];let ji=class kd extends a_{static getDefaults(){return kd.ownDefaults}get type(){const t=this.constructor.type;return t==="FabricObject"?"object":t.toLowerCase()}set type(t){Li("warn","Setting type has no effect",t)}constructor(t){super(),E(this,"_cacheContext",null),Object.assign(this,kd.ownDefaults),this.setOptions(t)}_createCacheCanvas(){this._cacheCanvas=oi(),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]=Th.limitDimsByArea(r),c=Sr(n,o,i),u=Sr(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 M(Math.abs(this.scaleX),Math.abs(this.scaleY));const t=br(this.calcTransformMatrix());return new M(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!==Ze||(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 Ii||(e=new Ii(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=ts(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,vs(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&&(vs(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 M(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(!vs(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=ts({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 M(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(z.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?$p():1,o=(t.multiplier||1)*r,h=t.canvasProvider||(x=>new Dh(x,{enableRetinaScaling:!1,renderOnAddRemove:!1,skipOffscreen:!1}));delete this.group,t.withoutTransform&&mm(this),t.withoutShadow&&(this.shadow=null),t.viewportTransform&&xf(this,this.getViewportTransform()),this.setCoords();const c=oi(),u=this.getBoundingRect(),d=this.shadow,f=new M;if(d){const x=d.blur,C=d.nonScaling?new M(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 M(b.width/2,b.height/2),J,J);const y=this.canvas;b._objects=[this],this.set("canvas",b),this.setCoords();const v=b.toCanvasElement(o||1,t);return this.set("canvas",y),this.shadow=i,s&&(this.group=s),this.set(e),this.setCoords(),b._objects=[],b.destroy(),v}toDataURL(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return pf(this.toCanvasElement(t),t.format||"png",t.quality||1)}toBlob(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return mf(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=J,this.originY=J,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(){Uc.cancelByTarget(this),this.off(),this._set("canvas",void 0),this._cacheCanvas&&ri().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=T(T({},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,y)=>(y===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?Wm(u):Nf(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(kd.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:y,strokeDashOffset:v,strokeLineJoin:x,strokeUniform:C,strokeMiterLimit:S,scaleX:A,scaleY:k,angle:P,flipX:O,flipY:R,opacity:F,visible:j,backgroundColor:D,fillRule:I,paintFirst:N,globalCompositeOperation:Y,skewX:L,skewY:B}=this;i&&!i.excludeFromExport&&(e=i.toObject(t.concat("inverted","absolutePositioned")));const Z=te=>yt(te,s),kt=T(T({},yr(this,t)),{},{type:this.constructor.type,version:af,originX:d,originY:f,left:Z(c),top:Z(u),width:Z(g),height:Z(p),fill:om(n)?n.toObject():n,stroke:om(r)?r.toObject():r,strokeWidth:Z(b),strokeDashArray:h&&h.concat(),strokeLineCap:y,strokeDashOffset:v,strokeLineJoin:x,strokeUniform:C,strokeMiterLimit:Z(S),scaleX:Z(A),scaleY:Z(k),angle:Z(P),flipX:O,flipY:R,opacity:Z(F),shadow:o&&o.toObject(),visible:j,backgroundColor:D,fillRule:I,paintFirst:N,globalCompositeOperation:Y,skewX:Z(L),skewY:Z(B)},e?{clipPath:e}:null);return this.includeDefaultValues?kt:this._removeDefaultValues(kt)}toDatalessObject(t){return this.toObject(t)}_removeDefaultValues(t){const e=this.constructor.getDefaults(),s=Object.keys(e).length>0?e:Object.getPrototypeOf(this);return yf(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,h_),s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},{extraParam:i}=s,n=Ct(s,l_);return Oh(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)}};E(ji,"stateProperties",Ky),E(ji,"cacheProperties",Ni),E(ji,"ownDefaults",Qy),E(ji,"type","FabricObject"),E(ji,"colorProperties",[Gt,Pe,"backgroundColor"]),E(ji,"customProperties",[]),z.setClass(ji),z.setClass(ji,"object");const ea=(a,t,e)=>(s,i,n,r)=>{const o=t(s,i,n,r);return o&&vm(a,T(T({},wm(s,i,n,r)),e)),o};function sa(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 Um=ea(Eh,sa((a,t,e,s)=>{const i=Sf(t,t.originX,t.originY,e,s);if(Vt(t.originX)===Vt(J)||Vt(t.originX)===Vt(Nt)&&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 c_(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:Gt,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,Fi,!1),a[h](),c&&a.stroke(),a.restore()}function u_(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:Gt,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(Lt(f)),a["".concat(h,"Rect")](-u,-d,n,r),c&&a.strokeRect(-u,-d,n,r),a.restore()}class Ns{constructor(t){E(this,"visible",!0),E(this,"actionName",Xc),E(this,"angle",0),E(this,"x",0),E(this,"y",0),E(this,"offsetX",0),E(this,"offsetY",0),E(this,"sizeX",0),E(this,"sizeY",0),E(this,"touchSizeX",0),E(this,"touchSizeY",0),E(this,"cursorStyle","crosshair"),E(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)&&Pt.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 M(this.x*t.x+this.offsetX,this.y*t.y+this.offsetY).transform(e)}calcCornerCoords(t,e,s,i,n,r){const o=$c([Ko(s,i),vr({angle:t}),qc((n?this.touchSizeX:this.sizeX)||e,(n?this.touchSizeY:this.sizeY)||e)]);return{tl:new M(-.5,-.5).transform(o),tr:new M(.5,-.5).transform(o),br:new M(.5,.5).transform(o),bl:new M(-.5,.5).transform(o)}}render(t,e,s,i,n){((i=i||{}).cornerStyle||n.cornerStyle)==="circle"?c_.call(this,t,e,s,i,n):u_.call(this,t,e,s,i,n)}}const d_=(a,t,e)=>e.lockRotation?Jc:t.cursorStyle,f_=ea(Kp,sa((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=ai(f-d+o);if(i.snapAngle&&i.snapAngle>0){const b=i.snapAngle,y=i.snapThreshold||b,v=Math.ceil(g/b)*b,x=Math.floor(g/b)*b;Math.abs(g-x)<y?g=x:Math.abs(g-v)<y&&(g=v)}g<0&&(g=360+g),g%=360;const p=i.angle!==g;return i.angle=g,p}));function Ym(a,t){const e=t.canvas,s=a[e.uniScaleKey];return e.uniformScaling&&!s||!e.uniformScaling&&s}function $m(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 g_=["e","se","s","sw","w","nw","n","ne","e"],Nh=(a,t,e)=>{const s=Ym(a,e);if($m(e,t.x!==0&&t.y===0?"x":t.x===0&&t.y!==0?"y":"",s))return Jc;const i=xm(e,t);return"".concat(g_[i],"-resize")};function jf(a,t,e,s){let i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{};const n=t.target,r=i.by,o=Ym(a,n);let h,c,u,d,f,g;if($m(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 y=Math.abs(h.x)+Math.abs(h.y),{original:v}=t,x=y/(Math.abs(d.x*v.scaleX/n.scaleX)+Math.abs(d.y*v.scaleY/n.scaleY));c=v.scaleX*x,u=v.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=_m(t.originX),c*=-1,t.signX=f),t.signY!==g&&r!=="x"&&(t.originY=_m(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(Ze,u)):(!Fs(n,"lockScalingX")&&n.set(Me,c),!Fs(n,"lockScalingY")&&n.set(Ze,u)),p!==n.scaleX||b!==n.scaleY}const ou=ea(Gc,sa((a,t,e,s)=>jf(a,t,e,s))),p_=ea(Gc,sa((a,t,e,s)=>jf(a,t,e,s,{by:"x"}))),m_=ea(Gc,sa((a,t,e,s)=>jf(a,t,e,s,{by:"y"}))),b_=["target","ex","ey","skewingSide"],Bf={x:{counterAxis:"y",scale:Me,skew:Yo,lockSkewing:"lockSkewingX",origin:"originX",flip:"flipX"},y:{counterAxis:"x",scale:Ze,skew:$o,lockSkewing:"lockSkewingY",origin:"originY",flip:"flipY"}},v_=["ns","nesw","ew","nwse"],y_=(a,t,e)=>{if(t.x!==0&&Fs(e,"lockSkewingY")||t.y!==0&&Fs(e,"lockSkewingX"))return Jc;const s=xm(e,t)%4;return"".concat(v_[s],"-resize")};function qm(a,t,e,s,i){const{target:n}=e,{counterAxis:r,origin:o,lockSkewing:h,skew:c,flip:u}=Bf[a];if(Fs(n,h))return!1;const{origin:d,flip:f}=Bf[r],g=Vt(e[d])*(n[f]?-1:1),p=-Math.sign(g)*(n[u]?-1:1),b=.5*-((n[c]===0&&Sf(e,J,J,s,i)[a]>0||n[c]>0?1:-1)*p)+.5;return ea(Qp,sa((v,x,C,S)=>function(A,k,P){let{target:O,ex:R,ey:F,skewingSide:j}=k,D=Ct(k,b_);const{skew:I}=Bf[A],N=P.subtract(new M(R,F)).divide(new M(O.scaleX,O.scaleY))[A],Y=O[I],L=D[I],B=Math.tan(Lt(L)),Z=A==="y"?O._getTransformedDimensions({scaleX:1,scaleY:1,skewX:0}).x:O._getTransformedDimensions({scaleX:1,scaleY:1}).y,kt=2*N*j/Math.max(Z,1)+B,te=ai(Math.atan(kt));O.set(I,te);const fe=Y!==O[I];if(fe&&A==="y"){const{skewX:Yt,scaleX:St}=O,He=O._getTransformedDimensions({skewY:Y}),Oi=O._getTransformedDimensions(),It=Yt!==0?He.x/Oi.x:1;It!==1&&O.set(Me,It*St)}return fe}(a,x,new M(C,S))))(t,T(T({},e),{},{[o]:b,skewingSide:p}),s,i)}const __=(a,t,e,s)=>qm("x",a,t,e,s),w_=(a,t,e,s)=>qm("y",a,t,e,s);function au(a,t){return a[t.canvas.altActionKey]}const hu=(a,t,e)=>{const s=au(a,e);return t.x===0?s?Yo:Ze:t.y===0?s?$o:Me:""},ia=(a,t,e)=>au(a,e)?y_(0,t,e):Nh(a,t,e),Km=(a,t,e,s)=>au(a,t.target)?w_(a,t,e,s):p_(a,t,e,s),Qm=(a,t,e,s)=>au(a,t.target)?__(a,t,e,s):m_(a,t,e,s),Jm=()=>({ml:new Ns({x:-.5,y:0,cursorStyleHandler:ia,actionHandler:Km,getActionName:hu}),mr:new Ns({x:.5,y:0,cursorStyleHandler:ia,actionHandler:Km,getActionName:hu}),mb:new Ns({x:0,y:.5,cursorStyleHandler:ia,actionHandler:Qm,getActionName:hu}),mt:new Ns({x:0,y:-.5,cursorStyleHandler:ia,actionHandler:Qm,getActionName:hu}),tl:new Ns({x:-.5,y:-.5,cursorStyleHandler:Nh,actionHandler:ou}),tr:new Ns({x:.5,y:-.5,cursorStyleHandler:Nh,actionHandler:ou}),bl:new Ns({x:-.5,y:.5,cursorStyleHandler:Nh,actionHandler:ou}),br:new Ns({x:.5,y:.5,cursorStyleHandler:Nh,actionHandler:ou}),mtr:new Ns({x:0,y:-.5,actionHandler:f_,cursorStyleHandler:d_,offsetY:-40,withConnection:!0,actionName:df})}),x_=()=>({mr:new Ns({x:.5,y:0,actionHandler:Um,cursorStyleHandler:ia,actionName:Eh}),ml:new Ns({x:-.5,y:0,actionHandler:Um,cursorStyleHandler:ia,actionName:Eh})}),S_=()=>T(T({},Jm()),x_());class jh extends ji{static getDefaults(){return T(T({},super.getDefaults()),jh.ownDefaults)}constructor(t){super(),Object.assign(this,this.constructor.createControls(),jh.ownDefaults),this.setOptions(t)}static createControls(){return{controls:Jm()}}_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(Xc))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=Ko(e.x,e.y),i=vr({angle:this.getTotalAngle()-(this.group&&this.flipX?180:0)}),n=jt(s,i),r=jt(t,n),o=jt(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(Lt(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=T({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=T({hasBorders:s,hasControls:i},e),r=this.getViewportTransform(),o=n.hasBorders,h=n.hasControls,c=jt(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(Lt(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=Qc(this.width,this.height,Mh(e)),r=this.isStrokeAccountedForInDimensions()?gf:(this.strokeUniform?new M().scalarAdd(this.canvas?this.canvas.getZoom():1):new M(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=T({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}E(jh,"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 jh{}Zm(pe,[Em]),z.setClass(pe),z.setClass(pe,"object");const t0=(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 e0{constructor(t){this.options=t,this.strokeProjectionMagnitude=this.options.strokeWidth/2,this.scale=new M(this.options.scaleX,this.options.scaleY),this.strokeUniformScalar=this.options.strokeUniform?new M(1/this.options.scaleX,1/this.options.scaleY):new M(1,1)}createSideVector(t,e){const s=su(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 M(t);return e.y+=e.x*Math.tan(Lt(this.options.skewY)),e.x+=e.y*Math.tan(Lt(this.options.skewX)),e}scaleUnitVector(t,e){return t.multiply(this.strokeUniformScalar).scalarMultiply(e)}}const C_=new M;class na extends e0{static getOrthogonalRotationFactor(t,e){const s=e?nu(t,e):jm(t);return Math.abs(s)<Tn?-1:1}constructor(t,e,s,i){super(i),E(this,"AB",void 0),E(this,"AC",void 0),E(this,"alpha",void 0),E(this,"bisector",void 0),this.A=new M(t),this.B=new M(e),this.C=new M(s),this.AB=this.createSideVector(this.A,this.B),this.AC=this.createSideVector(this.A,this.C),this.alpha=nu(this.AB,this.AC),this.bisector=ru(Pf(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=Of(i),r=na.getOrthogonalRotationFactor(n,this.bisector);return this.scaleUnitVector(n,s*r)}projectBevel(){const t=[];return(this.alpha%Fi==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?iu(this.scaleUnitVector(this.bisector,this.options.strokeMiterLimit)):this.options.strokeMiterLimit;return iu(i)/this.strokeProjectionMagnitude<=n&&t.push(this.applySkew(this.A.add(i))),t.push(...this.projectBevel()),t}projectRoundNoSkew(t,e){const s=[],i=new M(na.getOrthogonalRotationFactor(this.bisector),na.getOrthogonalRotationFactor(new M(this.bisector.y,this.bisector.x)));return[new M(1,0).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(i),new M(0,1).scalarMultiply(this.strokeProjectionMagnitude).multiply(this.strokeUniformScalar).multiply(i)].forEach(n=>{Df(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 M(Math.tan(Lt(i)),Math.tan(Lt(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 M(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 M(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=>{Df(b,t,e)&&s.push(this.applySkew(this.A).add(b))}),s}projectRound(){const t=[];t.push(...this.projectBevel());const e=this.alpha%Fi==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=ta(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 s0 extends e0{constructor(t,e,s){super(s),this.A=new M(t),this.T=new M(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(Of(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 M(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 na(this.A,this.T,this.T,this.options).projectRound());return t}projectSquare(){const t=[];if(this.A.eq(this.T)){const e=new M(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(ru(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 i0=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 M(r)),n),[new M(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 s0(n,n,t).project()):!e||r!==0&&r!==o.length-1?s.push(...new na(n,h,c,t).project()):s.push(...new s0(n,r===0?c:h,t).project())}),s},Hf=a=>{const t={};return Object.keys(a).forEach(e=>{t[e]={},Object.keys(a[e]).forEach(s=>{t[e][s]=T({},a[e][s])})}),t},n0=a=>a.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/'/g,"&apos;").replace(/</g,"&lt;").replace(/>/g,"&gt;");let Bh;const lu=a=>{if(Bh||Bh||(Bh="Intl"in Ah()&&"Segmenter"in Intl&&new Intl.Segmenter(void 0,{granularity:"grapheme"})),Bh){const t=Bh.segment(a);return Array.from(t).map(e=>{let{segment:s}=e;return s})}return A_(a)},A_=a=>{const t=[];for(let e,s=0;s<a.length;s++)(e=T_(a,s))!==!1&&t.push(e);return t},T_=(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 E_=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:n0,graphemeSplit:lu});const cu=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.textDecorationThickness!==t.textDecorationThickness||a.textBackgroundColor!==t.textBackgroundColor||a.deltaY!==t.deltaY||e&&(a.overline!==t.overline||a.underline!==t.underline||a.linethrough!==t.linethrough)},r0=(a,t)=>{const e=t.split(`
38
+ `),s=[];let i=-1,n={};a=Hf(a);for(let r=0;r<e.length;r++){const o=lu(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&&(cu(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},o0=(a,t)=>{if(!Array.isArray(a))return Hf(a);const e=t.split(uf),s={};let i=-1,n=0;for(let r=0;r<e.length;r++){const o=lu(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]=T({},a[n].style),i===a[n].end-1&&n++)}return s},Mn=["display","transform",Gt,"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 a0(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 k_(a,t){let e=!0;const s=a0(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=a0(i=i.parentElement,r);return n.length===0}(a,t)),s&&e&&t.length===0}const M_=a=>{var t;return(t=Uy[a])!==null&&t!==void 0?t:a},P_=new RegExp("(".concat(Is,")"),"gi"),O_=a=>a.replace(P_," $1 ").replace(/,/gi," ").replace(/\s+/gi," ");var h0,l0,c0,u0,d0,f0,g0;const De="(".concat(Is,")"),D_=String.raw(h0||(h0=ii(["(skewX)(",")"],["(skewX)\\(","\\)"])),De),R_=String.raw(l0||(l0=ii(["(skewY)(",")"],["(skewY)\\(","\\)"])),De),L_=String.raw(c0||(c0=ii(["(rotate)(","(?: "," ",")?)"],["(rotate)\\(","(?: "," ",")?\\)"])),De,De,De),F_=String.raw(u0||(u0=ii(["(scale)(","(?: ",")?)"],["(scale)\\(","(?: ",")?\\)"])),De,De),I_=String.raw(d0||(d0=ii(["(translate)(","(?: ",")?)"],["(translate)\\(","(?: ",")?\\)"])),De,De),N_=String.raw(f0||(f0=ii(["(matrix)("," "," "," "," "," ",")"],["(matrix)\\("," "," "," "," "," ","\\)"])),De,De,De,De,De,De),zf="(?:".concat(N_,"|").concat(I_,"|").concat(L_,"|").concat(F_,"|").concat(D_,"|").concat(R_,")"),j_="(?:".concat(zf,"*)"),B_=String.raw(g0||(g0=ii(["^s*(?:","?)s*$"],["^\\s*(?:","?)\\s*$"])),j_),H_=new RegExp(B_),z_=new RegExp(zf),G_=new RegExp(zf,"g");function uu(a){const t=[];if(!(a=O_(a).replace(/\s*([()])\s*/gi,"$1"))||a&&!H_.test(a))return[...Ee];for(const e of a.matchAll(G_)){const s=z_.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=Ko(h,c);break;case df:i=vr({angle:h},{x:c,y:u});break;case Xc:i=qc(h,c);break;case Yo:i=bf(h);break;case $o:i=vf(h);break;case"matrix":i=[h,c,u,d,f,g]}t.push(i)}return $c(t)}function V_(a,t,e,s){const i=Array.isArray(t);let n,r=t;if(a!==Gt&&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?jt(e.transformMatrix,uu(t)):uu(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"?Nt:J;else if(a==="charSpacing"||a===xr)n=Oe(t,s)/s*1e3;else if(a==="paintFirst"){const o=t.indexOf(Gt),h=t.indexOf(Pe);r=Gt,(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(Oe):Oe(t,s)}}else r="";return!i&&isNaN(n)?r:n}function X_(a,t){const e=a.match(Wy);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=Oe(n)),o&&(t.fontFamily=o),r&&(t.lineHeight=r==="normal"?1:r)}function Gf(a,t){a.replace(/;\s*$/,"").split(";").forEach(e=>{if(!e)return;const[s,i]=e.split(":");t[s.trim().toLowerCase()]=i.trim()})}function W_(a){const t={},e=a.getAttribute("style");return e&&(typeof e=="string"?Gf(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 U_={stroke:"strokeOpacity",fill:"fillOpacity"};function Bi(a,t,e){if(!a)return{};let s,i={},n=lf;a.parentNode&&Fm.test(a.parentNode.nodeName)&&(i=Bi(a.parentElement,t,e),i.fontSize&&(s=n=Oe(i.fontSize)));const r=T(T(T({},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)k_(c,f.split(" "))&&(d=T(T({},d),u[f]));return d}(a,e)),W_(a));r[Mf]&&a.setAttribute(Mf,r[Mf]),r[kf]&&(s=Oe(r[kf],n),r[kf]="".concat(s));const o={};for(const c in r){const u=M_(c),d=V_(u,r[c],i,s);o[u]=d}o&&o.font&&X_(o.font,o);const h=T(T({},i),o);return Fm.test(a.nodeName)?h:function(c){const u=pe.getDefaults();return Object.entries(U_).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(yt(p.getAlpha()*c[g],2)).toRgba()}),c}(h)}const Y_=["left","top","width","height","visible"],p0=["rx","ry"];class ci extends pe{static getDefaults(){return T(T({},super.getDefaults()),ci.ownDefaults)}constructor(t){super(),Object.assign(this,ci.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-En*r,n,i+e,n+En*o,i+e,n+o),t.lineTo(i+e,n+s-o),h&&t.bezierCurveTo(i+e,n+s-En*o,i+e-En*r,n+s,i+e-r,n+s),t.lineTo(i+r,n+s),h&&t.bezierCurveTo(i+En*r,n+s,i,n+s-En*o,i,n+s-o),t.lineTo(i,n+o),h&&t.bezierCurveTo(i,n+En*o,i+En*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([...p0,...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=Bi(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:r=0,width:o=0,height:h=0,visible:c=!0}=i,u=Ct(i,Y_);return new this(T(T(T({},e),u),{},{left:n,top:r,width:o,height:h,visible:!!(c&&o&&h)}))}}E(ci,"type","Rect"),E(ci,"cacheProperties",[...Ni,...p0]),E(ci,"ownDefaults",{rx:0,ry:0}),E(ci,"ATTRIBUTE_NAMES",[...Mn,"x","y","rx","ry","width","height"]),z.setClass(ci),z.setSVGClass(ci);const Hi="initialization",du="added",Vf="removed",fu="imperative",m0=(a,t)=>{const{strokeUniform:e,strokeWidth:s,width:i,height:n,group:r}=t,o=r&&r!==a?Rh(r.calcTransformMatrix(),a.calcTransformMatrix()):null,h=o?t.getRelativeCenterPoint().transform(o):t.getRelativeCenterPoint(),c=!t.isStrokeAccountedForInDimensions(),u=e&&c?bm(new M(s,s),void 0,a.calcTransformMatrix()):gf,d=!e&&c?s:0,f=Qc(i+d,n+d,$c([o,t.calcOwnMatrix()],!0)).add(u).scalarDivide(2);return[h.subtract(f),h.add(f)]};class gu{calcLayoutResult(t,e){if(this.shouldPerformLayout(t))return this.calcBoundingBox(e,t)}shouldPerformLayout(t){let{type:e,prevStrategy:s,strategy:i}=t;return e===Hi||e===fu||!!s&&i!==s}shouldLayoutClipPath(t){let{type:e,target:{clipPath:s}}=t;return e!==Hi&&s&&!s.absolutePositioned}getInitialSize(t,e){return e.size}calcBoundingBox(t,e){const{type:s,target:i}=e;if(s===fu&&e.overrides)return e.overrides;if(t.length===0)return;const{left:n,top:r,width:o,height:h}=hi(t.map(d=>m0(i,d)).reduce((d,f)=>d.concat(f),[])),c=new M(o,h),u=new M(n,r).add(c.scalarDivide(2));if(s===Hi){const d=this.getInitialSize(e,{size:c,center:u});return{center:u,relativeCorrection:new M(0,0),size:d}}return{center:u.transform(i.calcOwnMatrix()),size:c}}}E(gu,"type","strategy");class Xf extends gu{shouldPerformLayout(t){return!0}}E(Xf,"type","fit-content"),z.setClass(Xf);const $_=["strategy"],q_=["target","strategy","bubbles","prevStrategy"],b0="layoutManager";class Hh{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:new Xf;E(this,"strategy",void 0),this.strategy=t,this._subscriptions=new Map}performLayout(t){const e=T(T({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[Wc,qp,Eh,Kp,Gc,Qp,Vc,Ly,Fy].map(i=>t.on(i,n=>this.performLayout(i===Wc?{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===Hi||s===du?this.subscribeTargets(t):s===Vf&&this.unsubscribeTargets(t),e.fire("layout:before",{context:t}),i&&i.fire("object:layout:before",{target:e,context:t}),s===fu&&t.deep){const n=Ct(t,$_);e.forEachObject(r=>r.layoutManager&&r.layoutManager.performLayout(T(T({},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===Hi?new M:e.getRelativeCenterPoint(),{center:o,correction:h=new M,relativeCorrection:c=new M}=n,u=r.subtract(o).add(h).transform(i===Hi?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===Hi?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,J,J),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,q_),{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(T(T({},o),{},{target:c}))),s.set("dirty",!0)}dispose(){const{_subscriptions:t}=this;t.forEach(e=>e.forEach(s=>s())),t.clear()}toObject(){return{type:b0,strategy:this.strategy.constructor.type}}toJSON(){return this.toObject()}}z.setClass(Hh,b0);const K_=["type","objects","layoutManager"];class Q_ extends Hh{performLayout(){}}class ys extends Jp(pe){static getDefaults(){return T(T({},super.getDefaults()),ys.ownDefaults)}constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),E(this,"_activeObjects",[]),E(this,"__objectSelectionTracker",void 0),E(this,"__objectSelectionDisposer",void 0),Object.assign(this,ys.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 Hh,this.layoutManager.performLayout({type:Hi,target:this,targets:[...t],x:e.left,y:e.top})}canEnterGroup(t){return t===this||this.isDescendantOf(t)?(Li("error","Group: circular object trees are not supported, this call has no effect"),!1):this._objects.indexOf(t)===-1||(Li("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(du,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(du,n),r}remove(){const t=super.remove(...arguments);return this._onAfterObjectsChange(Vf,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&&Zo(t,jt(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||(Zo(t,jt(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(T({target:this,type:fu},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 T(T(T({},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=ci.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,G_);return Promise.all([Ko(i,e),Mh(r,e)]).then(o=>{let[h,c]=o;const u=new this(h,A(A(A({},r),c),{},{layoutManager:new V_}));if(n){const d=z.getClass(n.type),f=z.getClass(n.strategy);u.layoutManager=new d(new f)}else u.layoutManager=new Fh;return u.layoutManager.subscribeTargets({type:Bi,target:u,targets:u.getObjects()}),u.setCoords(),u})}}T(_s,"type","Group"),T(_s,"ownDefaults",{strokeWidth:0,subTargetCheck:!1,interactive:!1}),z.setClass(_s);const l0=(a,t)=>Math.min(t.width/a.width,t.height/a.height),c0=(a,t)=>Math.max(t.width/a.width,t.height/a.height),Gf="\\s*,?\\s*",Ih="".concat(Gf,"(").concat(Ns,")"),X_="".concat(Ih).concat(Ih).concat(Ih).concat(Gf,"([01])").concat(Gf,"([01])").concat(Ih).concat(Ih),W_={m:"l",M:"L"},U_=(a,t,e,s,i,n,r,o,h,c,u)=>{const d=Rs(a),f=Ls(a),g=Rs(t),p=Ls(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]},u0=(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(ct.cachesBoundsOfCurve&&(h=[...arguments].join(),Ch.boundsOfCurveCache[h]))return Ch.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 C=0;C<2;++C){if(C>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 R=-b/g;0<R&&R<1&&d.push(R);continue}const E=g*g-4*b*p;if(E<0)continue;const P=c(E),M=(-g+P)/(2*p);0<M&&M<1&&d.push(M);const O=(-g-P)/(2*p);0<O&&O<1&&d.push(O)}let v=d.length;const y=v,x=f0(a,t,e,s,i,n,r,o);for(;v--;){const{x:C,y:E}=x(d[v]);f[0][v]=C,f[1][v]=E}f[0][y]=a,f[1][y]=t,f[0][y+1]=r,f[1][y+1]=o;const S=[new k(Math.min(...f[0]),Math.min(...f[1])),new k(Math.max(...f[0]),Math.max(...f[1]))];return ct.cachesBoundsOfCurve&&(Ch.boundsOfCurveCache[h]=S),S}const Y_=(a,t,e)=>{let[s,i,n,r,o,h,c,u]=e;const d=((f,g,p,b,v,y,x)=>{if(p===0||b===0)return[];let S=0,C=0,E=0;const P=Math.PI,M=x*of,O=Ls(M),R=Rs(M),L=.5*(-R*f-O*g),N=.5*(-R*g+O*f),D=p**2,F=b**2,j=N**2,q=L**2,I=D*F-D*j-F*q;let H=Math.abs(p),it=Math.abs(b);if(I<0){const Oi=Math.sqrt(1-I/(D*F));H*=Oi,it*=Oi}else E=(v===y?-1:1)*Math.sqrt(I/(D*j+F*q));const kt=E*H*N/it,te=-E*it*L/H,fe=R*kt-O*te+.5*f,Yt=O*kt+R*te+.5*g;let St=u0(1,0,(L-kt)/H,(N-te)/it),He=u0((L-kt)/H,(N-te)/it,(-L-kt)/H,(-N-te)/it);y===0&&He>0?He-=2*P:y===1&&He<0&&(He+=2*P);const Pi=Math.ceil(Math.abs(He/P*2)),It=[],ft=He/Pi,fr=8/3*Math.sin(ft/4)*Math.sin(ft/4)/Math.sin(ft/2);let bh=St+ft;for(let Oi=0;Oi<Pi;Oi++)It[Oi]=U_(St,bh,R,O,H,it,fe,Yt,fr,S,C),S=It[Oi][5],C=It[Oi][6],St=bh,bh+=ft;return It})(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},d0=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":Y_(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),f0=(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 k(r*c+i*u+e*d+a*f,o*c+n*u+s*d+t*f)},g0=a=>a**2,p0=a=>2*a*(1-a),m0=a=>(1-a)**2,$_=(a,t,e,s,i,n,r,o)=>h=>{const c=g0(h),u=p0(h),d=m0(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)},q_=(a,t,e,s,i,n)=>r=>{const o=g0(r),h=p0(r),c=m0(r);return new k(i*o+e*h+a*c,n*o+s*h+t*c)},K_=(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)},b0=(a,t,e)=>{let s=new k(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},Q_=(a,t)=>{let e,s=0,i=0,n={x:a.x,y:a.y},r=A({},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 A(A({},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=f0(i,n,c[1],c[2],c[3],c[4],c[5],c[6]),e=u,e.iterator=t,e.angleFinder=$_(i,n,c[1],c[2],c[3],c[4],c[5],c[6]),e.length=b0(t,i,n),i=c[5],n=c[6];break;case"Q":t=q_(i,n,c[1],c[2],c[3],c[4]),e=u,e.iterator=t,e.angleFinder=K_(i,n,c[1],c[2],c[3],c[4]),e.length=b0(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},v0=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 A(A({},new k(i.x,i.y).lerp(new k(i.destX,i.destY),n)),{},{angle:Math.atan2(i.destY-i.y,i.destX-i.x)});case"L":return A(A({},new k(i.x,i.y).lerp(new k(r[1],r[2]),n)),{},{angle:Math.atan2(r[2]-i.y,r[1]-i.x)});case"C":case"Q":return Q_(i,t)}},J_=new RegExp("[mzlhvcsqta][^mzlhvcsqta]*","gi"),y0=new RegExp(X_,"g"),Z_=new RegExp(Ns,"gi"),tw={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},_0=a=>{var t;const e=[],s=(t=a.match(J_))!==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=tw[n.toLowerCase()];let o=[];if(n==="a"||n==="A"){y0.lastIndex=0;for(let h=null;h=y0.exec(i);)o.push(...h.slice(1))}else o=i.match(Z_)||[];for(let h=0;h<o.length;h+=r){const c=new Array(r),u=W_[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},ew=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,e=new k(a[0]),s=new k(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},w0=(a,t)=>a.map(e=>e.map((s,i)=>i===0||t===void 0?s:wt(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 sw=(a,t)=>Math.floor(Math.random()*(t-a+1))+a;function x0(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 nf("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(Ze,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,J,J)};var iw=Object.freeze({__proto__:null,addTransformToObject:dm,animate:Lf,animateColor:Im,applyTransformToObject:Jo,calcAngleBetweenVectors:eu,calcDimensionsMatrix:Eh,calcPlaneChangeMatrix:Oh,calcVectorRotation:Mm,cancelAnimFrame:Qp,capValue:xr,composeMatrix:sm,copyCanvasElement:a=>{var t;const e=ts(a);return(t=e.getContext("2d"))===null||t===void 0||t.drawImage(a,0,0),e},cos:Rs,createCanvasElement:vs,createImage:Jp,createRotateMatrix:vr,createScaleMatrix:Yc,createSkewXMatrix:pf,createSkewYMatrix:mf,createTranslateMatrix:qo,createVector:Zc,crossProduct:Zo,degreesToRadians:Lt,dotProduct:Pm,ease:Wy,enlivenObjectEnlivables:Mh,enlivenObjects:Ko,findScaleToCover:c0,findScaleToFit:l0,getBoundsOfCurve:Vf,getOrthonormalVector:kf,getPathSegmentsInfo:Xf,getPointOnPath:v0,getPointer:cm,getRandomInt:sw,getRegularPolygonPath:(a,t)=>{const e=2*Math.PI/a;let s=-Tn;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 k(Rs(r),Ls(r)).scalarMultiply(t);i[n]=[n===0?"M":"L",o,h]}return i[a]=["Z"],i},getSmoothPathFromPoints:ew,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 _s(a,t),hasStyleChanged:au,invertTransform:Xe,isBetweenVectors:Mf,isIdentityMatrix:Zp,isTouchEvent:$c,isTransparent:Wm,joinPath:w0,loadImage:kh,magnitude:tu,makeBoundingBoxFromPoints:ai,makePathSimpler:d0,matrixToSVG:Qo,mergeClipPaths:(a,t)=>{var e;let s=a,i=t;s.inverted&&!i.inverted&&(s=t,i=a),_f(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 _s([s],{clipPath:i,inverted:n})},multiplyTransformMatrices:jt,multiplyTransformMatrixArray:Uc,parsePath:_0,parsePreserveAspectRatioAttribute:Sf,parseUnit:Oe,pick:yr,projectStrokeOnPoints:$m,qrDecompose:br,radiansToDegrees:oi,removeFromArray:mr,removeTransformFromObject:(a,t)=>{const e=Xe(t),s=jt(e,a.calcOwnMatrix());Jo(a,s)},removeTransformMatrixForSvgParsing:gu,request:x0,requestAnimFrame:Th,resetObjectTransform:fm,rotatePoint:(a,t,e)=>a.rotate(e,t),rotateVector:Ef,saveObjectTransform:yf,sendObjectToPlane:_f,sendPointToPlane:wr,sendVectorToPlane:gm,setStyle:fu,sin:Ls,sizeAfterTransform:qc,string:y_,stylesFromArray:Qm,stylesToArray:Km,toBlob:gf,toDataURL:ff,toFixed:wt,transformPath:(a,t,e)=>(e&&(t=jt(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 nw extends lm{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=vs();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=Wo().createElement("div");return t.setAttribute("data-fabric","wrapper"),fu(t,{position:"relative"}),hm(t),t}applyCanvasStyle(t,e){const{styles:s,allowTouchScrolling:i}=e;fu(t,A(A({},s),{},{"touch-action":i?"manipulation":ke})),hm(t)}setDimensions(t,e){super.setDimensions(t,e);const{el:s,ctx:i}=this.upper;am(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(),ri().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 A(A({},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 nw(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 Wm(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===Gc||e===Me||e===Ze||e===Ah?i=this.centeredScaling||t.centeredScaling:e===cf&&(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=Nt:["mr","tr","br"].includes(e)&&(s.x=dt),["tl","mt","tr"].includes(e)?s.y=hf:["bl","mb","br"].includes(e)&&(s.y=Ve)),s}_setupCurrentTransform(t,e,s){var i;const n=e.group?wr(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):Ny,c=((g,p,b,v)=>{if(!p||!g)return"drag";const y=v.controls[p];return y.getActionName(b,y,v)})(s,r,t,e),u=t[this.centeredKey],d=this._shouldCenterTransform(e,c,u)?{x:J,y:J}: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:Lt(e.angle),width:e.width,height:e.height,shiftKey:t.shiftKey,altKey:u,original:A(A({},yf(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 k(e,s).transform(this.viewportTransform),o=new k(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,$c(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=Rs(u)*n,f=Ls(u)*n,g=d+f,p=d-f;s=[new k(r.x-p,r.y-g),new k(o.x+g,o.y-p),new k(h.x+p,h.y+g),new k(c.x-g,c.y+p)]}return Pt.isPointInPolygon(e,s)}_checkTarget(t,e){return!!(t&&t.visible&&t.evented&&this._pointIsInObjectSelectionArea(t,wr(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=cm(t),r=i.width||0,o=i.height||0;r&&o||(Ve in i&&hf in i&&(o=Math.abs(i.top-i.bottom)),Nt 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=wr(n,void 0,this.viewportTransform));const h=this.getRetinaScaling();h!==1&&(n.x/=h,n.y/=h);const c=r===0||o===0?new k(1,1):new k(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=vs(),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 _r(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,_r(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),_r(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;_r(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&&_r(e)&&this._activeObject===e){const s=yr(t,["angle","flipX","flipY",dt,Me,Ze,Uo,Yo,Ve]);return dm(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 rw{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 ow=["target","oldTarget","fireCanvas","e"],es={passive:!1},na=(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)},ws=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)},aw={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 rw(this)),["_onMouseDown","_onTouchStart","_onMouseMove","_onMouseUp","_onTouchEnd","_onResize","_onMouseWheel","_onMouseOut","_onMouseEnter","_onContextMenu","_onClick","_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(om(s),"resize",this._onResize),t(s,i+"down",this._onMouseDown),t(s,"".concat(i,"move"),this._onMouseMove,es),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,"click",this._onClick),t(s,"dblclick",this._onClick),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,es)}removeListeners(){this.addOrRemove(ws,"remove");const t=this._getEventPrefix(),e=Fs(this.upperCanvasEl);ws(e,"".concat(t,"up"),this._onMouseUp),ws(e,"touchend",this._onTouchEnd,es),ws(e,"".concat(t,"move"),this._onMouseMove,es),ws(e,"touchmove",this._onMouseMove,es),clearTimeout(this._willAddMouseDown)}_onMouseWheel(t){this.__onMouseWheel(t)}_onMouseOut(t){const e=this._hoveredTarget,s=A({e:t},na(this,t));this.fire("mouse:out",A(A({},s),{},{target:e})),this._hoveredTarget=void 0,e&&e.fire("mouseout",A({},s)),this._hoveredTargets.forEach(i=>{this.fire("mouse:out",A(A({},s),{},{target:i})),i&&i.fire("mouseout",A({},s))}),this._hoveredTargets=[]}_onMouseEnter(t){this._currentTransform||this.findTarget(t)||(this.fire("mouse:over",A({e:t},na(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)}um(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};ws(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",A({e:t,target:e,subTargets:s,dragSource:this._dragSource},na(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&&um(t),this._basicEventHandler("contextmenu",i),!1}_onClick(t){const e=t.detail;e>3||e<2||(this._cacheTransformEventData(t),e==2&&t.type==="dblclick"&&this._handleEvent(t,"dblclick"),e==3&&this._handleEvent(t,"tripleclick"),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=Fs(i);Pn(r,"touchend",this._onTouchEnd,es),e&&Pn(r,"touchmove",this._onMouseMove,es),ws(i,"".concat(n,"down"),this._onMouseDown)}_onMouseDown(t){this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();ws(e,"".concat(s,"move"),this._onMouseMove,es);const i=Fs(e);Pn(i,"".concat(s,"up"),this._onMouseUp),Pn(i,"".concat(s,"move"),this._onMouseMove,es)}_onTouchEnd(t){if(t.touches.length>0)return;this.__onMouseUp(t),this._resetTransformEventData(),delete this.mainTouchId;const e=this._getEventPrefix(),s=Fs(this.upperCanvasEl);ws(s,"touchend",this._onTouchEnd,es),ws(s,"touchmove",this._onMouseMove,es),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=Fs(this.upperCanvasEl);ws(i,"".concat(s,"up"),this._onMouseUp),ws(i,"".concat(s,"move"),this._onMouseMove,es),Pn(e,"".concat(s,"move"),this._onMouseMove,es)}}_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),$c(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,s){const i=this._target,n=this.targets||[],r=A(A(A({e:t,target:i,subTargets:n},na(this,t)),{},{transform:this._currentTransform},e==="up:before"||e==="up"?{isClick:this._isClick,currentTarget:this.findTarget(t),currentSubTargets:this.targets}:{}),e==="down:before"||e==="down"?s:{});this.fire("mouse:".concat(e),r),i&&i.fire("mouse".concat(e),r);for(let o=0;o<n.length;o++)n[o]!==i&&n[o].fire("mouse".concat(e),r)}_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",{alreadySelected:!1})}_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,s=!!e&&e===this._activeObject;const{button:i}=t;if(i)return(this.fireMiddleClick&&i===1||this.fireRightClick&&i===2)&&this._handleEvent(t,"down",{alreadySelected:s}),void this._resetTransformEventData();if(this.isDrawingMode)return void this._onMouseDownInDrawingMode(t);if(!this._isMainEvent(t)||this._currentTransform)return;let n=this._shouldRender(e),r=!1;if(this.handleMultiSelection(t,e)?(e=this._activeObject,r=!0,n=!0):this._shouldClearSelection(t,e)&&this.discardActiveObject(t),this.selection&&(!e||!e.selectable&&!e.isEditing&&e!==this._activeObject)){const o=this.getScenePoint(t);this._groupSelector={x:o.x,y:o.y,deltaY:0,deltaX:0}}if(s=!!e&&e===this._activeObject,e){e.selectable&&e.activeOn==="down"&&this.setActiveObject(e,t);const o=e.findControl(this.getViewportPoint(t),$c(t));if(e===this._activeObject&&(o||!r)){this._setupCurrentTransform(t,e,s);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)}}n&&(this._objectsToRender=void 0),this._handleEvent(t,"down",{alreadySelected:s}),n&&this.requestRenderAll()}_resetTransformEventData(){this._target=this._pointer=this._absolutePointer=void 0}_cacheTransformEventData(t){this._resetTransformEventData(),this._pointer=this.getViewportPoint(t),this._absolutePointer=wr(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",A(A({},e),{},{target:t,oldTarget:s,fireCanvas:!0}));for(let o=0;o<r;o++)this.fireSyntheticInOutEvents("drag",A(A({},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,ow);const{targetIn:h,targetOut:c,canvasIn:u,canvasOut:d}=aw[t],f=i!==s;if(i&&f){const g=A(A({},o),{},{e:r,target:i,nextTarget:s},na(this,r));n&&this.fire(d,g),i.fire(c,g)}if(s&&f){const g=A(A({},o),{},{e:r,target:s,previousTarget:i},na(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?wr(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=_r(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=_r(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(z.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 k(e,s),o=r.add(new k(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=z.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 S0={x1:0,y1:0,x2:0,y2:0},hw=A(A({},S0),{},{r1:0,r2:0}),ra=(a,t)=>isNaN(a)&&typeof t=="number"?t:a,lw=/^(\d+\.\d+)%|(\d+)%$/;function C0(a){return a&&lw.test(a)}function A0(a,t){const e=typeof a=="number"?a:typeof a=="string"?parseFloat(a)/(C0(a)?100:1):NaN;return xr(0,ra(e,t),1)}const cw=/\s*;\s*/,uw=/\s*:\s*/;function dw(a,t){let e,s;const i=a.getAttribute("style");if(i){const r=i.split(cw);r[r.length-1]===""&&r.pop();for(let o=r.length;o--;){const[h,c]=r[o].split(uw).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:A0(a.getAttribute("offset"),0),color:n.toRgb(),opacity:ra(parseFloat(s||a.getAttribute("stop-opacity")||""),1)*n.getAlpha()*t}}function fw(a,t){const e=[],s=a.getElementsByTagName("stop"),i=A0(t,1);for(let n=s.length;n--;)e.push(dw(s[n],i));return e}function T0(a){return a.nodeName==="linearGradient"||a.nodeName==="LINEARGRADIENT"?"linear":"radial"}function E0(a){return a.getAttribute("gradientUnits")==="userSpaceOnUse"?"pixels":"percentage"}function Bs(a,t){return a.getAttribute(t)}function gw(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"&&C0(u)&&(i*=.01,o==="pixels"&&(c!=="x1"&&c!=="x2"&&c!=="r2"||(i*=n),c!=="y1"&&c!=="y2"||(i*=r)))),h[c]=i,h},{})}(T0(a)==="linear"?function(e){return{x1:Bs(e,"x1")||0,y1:Bs(e,"y1")||0,x2:Bs(e,"x2")||"100%",y2:Bs(e,"y2")||0}}(a):function(e){return{x1:Bs(e,"fx")||Bs(e,"cx")||"50%",y1:Bs(e,"fy")||Bs(e,"cy")||"50%",r1:0,x2:Bs(e,"cx")||"50%",y2:Bs(e,"cy")||"50%",r2:Bs(e,"r")||"50%"}}(a),A(A({},t),{},{gradientUnits:E0(a)}))}class Nh{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:A(A({},e==="radial"?hw:S0),i),colorStops:n,offsetX:r,offsetY:o,gradientTransform:h,id:c?"".concat(c,"_").concat(kn()):kn()})}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 A(A({},yr(this,t)),{},{type:this.type,coords:A({},this.coords),colorStops:this.colorStops.map(e=>A({},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=>A({},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(Qo(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
- `)}else if(this.type==="radial"){const{x1:d,y1:f,x2:g,y2:p,r1:b,r2:v}=this.coords,y=b>v;s.push("<radialGradient ",u,' cx="',y?d:g,'" cy="',y?f:p,'" r="',y?b:v,'" fx="',y?g:d,'" fy="',y?p:f,`">
43
- `),y&&(r.reverse(),r.forEach(S=>{S.offset=1-S.offset}));const x=Math.min(b,v);if(x>0){const S=x/Math.max(b,v);r.forEach(C=>{C.offset+=S*(1-C.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:";",`"/>
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,K_);return Promise.all([Qo(i,e),Oh(r,e)]).then(o=>{let[h,c]=o;const u=new this(h,T(T(T({},r),c),{},{layoutManager:new Q_}));if(n){const d=z.getClass(n.type),f=z.getClass(n.strategy);u.layoutManager=new d(new f)}else u.layoutManager=new Hh;return u.layoutManager.subscribeTargets({type:Hi,target:u,targets:u.getObjects()}),u.setCoords(),u})}}E(ys,"type","Group"),E(ys,"ownDefaults",{strokeWidth:0,subTargetCheck:!1,interactive:!1}),z.setClass(ys);const v0=(a,t)=>Math.min(t.width/a.width,t.height/a.height),y0=(a,t)=>Math.max(t.width/a.width,t.height/a.height),Wf="\\s*,?\\s*",zh="".concat(Wf,"(").concat(Is,")"),J_="".concat(zh).concat(zh).concat(zh).concat(Wf,"([01])").concat(Wf,"([01])").concat(zh).concat(zh),Z_={m:"l",M:"L"},tw=(a,t,e,s,i,n,r,o,h,c,u)=>{const d=Ds(a),f=Rs(a),g=Ds(t),p=Rs(t),b=e*i*g-s*n*p+r,y=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),y+h*(s*i*p-e*n*g),b,y]},_0=(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 Uf(a,t,e,s,i,n,r,o){let h;if(ht.cachesBoundsOfCurve&&(h=[...arguments].join(),Th.boundsOfCurveCache[h]))return Th.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 R=-b/g;0<R&&R<1&&d.push(R);continue}const A=g*g-4*b*p;if(A<0)continue;const k=c(A),P=(-g+k)/(2*p);0<P&&P<1&&d.push(P);const O=(-g-k)/(2*p);0<O&&O<1&&d.push(O)}let y=d.length;const v=y,x=x0(a,t,e,s,i,n,r,o);for(;y--;){const{x:S,y:A}=x(d[y]);f[0][y]=S,f[1][y]=A}f[0][v]=a,f[1][v]=t,f[0][v+1]=r,f[1][v+1]=o;const C=[new M(Math.min(...f[0]),Math.min(...f[1])),new M(Math.max(...f[0]),Math.max(...f[1]))];return ht.cachesBoundsOfCurve&&(Th.boundsOfCurveCache[h]=C),C}const ew=(a,t,e)=>{let[s,i,n,r,o,h,c,u]=e;const d=((f,g,p,b,y,v,x)=>{if(p===0||b===0)return[];let C=0,S=0,A=0;const k=Math.PI,P=x*hf,O=Rs(P),R=Ds(P),F=.5*(-R*f-O*g),j=.5*(-R*g+O*f),D=p**2,I=b**2,N=j**2,Y=F**2,L=D*I-D*N-I*Y;let B=Math.abs(p),Z=Math.abs(b);if(L<0){const Di=Math.sqrt(1-L/(D*I));B*=Di,Z*=Di}else A=(y===v?-1:1)*Math.sqrt(L/(D*N+I*Y));const kt=A*B*j/Z,te=-A*Z*F/B,fe=R*kt-O*te+.5*f,Yt=O*kt+R*te+.5*g;let St=_0(1,0,(F-kt)/B,(j-te)/Z),He=_0((F-kt)/B,(j-te)/Z,(-F-kt)/B,(-j-te)/Z);v===0&&He>0?He-=2*k:v===1&&He<0&&(He+=2*k);const Oi=Math.ceil(Math.abs(He/k*2)),It=[],ft=He/Oi,fr=8/3*Math.sin(ft/4)*Math.sin(ft/4)/Math.sin(ft/2);let vh=St+ft;for(let Di=0;Di<Oi;Di++)It[Di]=tw(St,vh,R,O,B,Z,fe,Yt,fr,C,S),C=It[Di][5],S=It[Di][6],St=vh,vh+=ft;return It})(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},w0=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":ew(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},pu=(a,t,e,s)=>Math.sqrt((e-a)**2+(s-t)**2),x0=(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 M(r*c+i*u+e*d+a*f,o*c+n*u+s*d+t*f)},S0=a=>a**2,C0=a=>2*a*(1-a),A0=a=>(1-a)**2,sw=(a,t,e,s,i,n,r,o)=>h=>{const c=S0(h),u=C0(h),d=A0(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)},iw=(a,t,e,s,i,n)=>r=>{const o=S0(r),h=C0(r),c=A0(r);return new M(i*o+e*h+a*c,n*o+s*h+t*c)},nw=(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)},T0=(a,t,e)=>{let s=new M(t,e),i=0;for(let n=1;n<=100;n+=1){const r=a(n/100);i+=pu(s.x,s.y,r.x,r.y),s=r}return i},rw=(a,t)=>{let e,s=0,i=0,n={x:a.x,y:a.y},r=T({},n),o=.01,h=0;const c=a.iterator,u=a.angleFinder;for(;i<t&&o>1e-4;)r=c(s),h=s,e=pu(n.x,n.y,r.x,r.y),e+i>t?(s-=o,o/=2):(n=r,s+=o,i+=e);return T(T({},r),{},{angle:u(h)})},Yf=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=pu(i,n,c[1],c[2]),i=c[1],n=c[2];break;case"C":t=x0(i,n,c[1],c[2],c[3],c[4],c[5],c[6]),e=u,e.iterator=t,e.angleFinder=sw(i,n,c[1],c[2],c[3],c[4],c[5],c[6]),e.length=T0(t,i,n),i=c[5],n=c[6];break;case"Q":t=iw(i,n,c[1],c[2],c[3],c[4]),e=u,e.iterator=t,e.angleFinder=nw(i,n,c[1],c[2],c[3],c[4]),e.length=T0(t,i,n),i=c[3],n=c[4];break;case"Z":e=u,e.destX=r,e.destY=o,e.length=pu(i,n,r,o),i=r,n=o}s+=e.length,h.push(e)}return h.push({length:s,x:i,y:n}),h},E0=function(a,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Yf(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 T(T({},new M(i.x,i.y).lerp(new M(i.destX,i.destY),n)),{},{angle:Math.atan2(i.destY-i.y,i.destX-i.x)});case"L":return T(T({},new M(i.x,i.y).lerp(new M(r[1],r[2]),n)),{},{angle:Math.atan2(r[2]-i.y,r[1]-i.x)});case"C":case"Q":return rw(i,t)}},ow=new RegExp("[mzlhvcsqta][^mzlhvcsqta]*","gi"),k0=new RegExp(J_,"g"),aw=new RegExp(Is,"gi"),hw={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},M0=a=>{var t;const e=[],s=(t=a.match(ow))!==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=hw[n.toLowerCase()];let o=[];if(n==="a"||n==="A"){k0.lastIndex=0;for(let h=null;h=k0.exec(i);)o.push(...h.slice(1))}else o=i.match(aw)||[];for(let h=0;h<o.length;h+=r){const c=new Array(r),u=Z_[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},lw=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,e=new M(a[0]),s=new M(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},P0=(a,t)=>a.map(e=>e.map((s,i)=>i===0||t===void 0?s:yt(s,t)).join(" ")).join(" ");function mu(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 cw=(a,t)=>Math.floor(Math.random()*(t-a+1))+a;function O0(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const e=t.onComplete||pr,s=new(Ah()).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 of("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 bu=(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(Ze,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,J,J)};var uw=Object.freeze({__proto__:null,addTransformToObject:pm,animate:Nf,animateColor:Wm,applyTransformToObject:Zo,calcAngleBetweenVectors:nu,calcDimensionsMatrix:Mh,calcPlaneChangeMatrix:Rh,calcVectorRotation:jm,cancelAnimFrame:tm,capValue:Sr,composeMatrix:rm,copyCanvasElement:a=>{var t;const e=ts(a);return(t=e.getContext("2d"))===null||t===void 0||t.drawImage(a,0,0),e},cos:Ds,createCanvasElement:oi,createImage:em,createRotateMatrix:vr,createScaleMatrix:qc,createSkewXMatrix:bf,createSkewYMatrix:vf,createTranslateMatrix:Ko,createVector:su,crossProduct:ta,degreesToRadians:Lt,dotProduct:Bm,ease:Jy,enlivenObjectEnlivables:Oh,enlivenObjects:Qo,findScaleToCover:y0,findScaleToFit:v0,getBoundsOfCurve:Uf,getOrthonormalVector:Of,getPathSegmentsInfo:Yf,getPointOnPath:E0,getPointer:fm,getRandomInt:cw,getRegularPolygonPath:(a,t)=>{const e=2*Math.PI/a;let s=-Tn;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 M(Ds(r),Rs(r)).scalarMultiply(t);i[n]=[n===0?"M":"L",o,h]}return i[a]=["Z"],i},getSmoothPathFromPoints:lw,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:ru,groupSVGElements:(a,t)=>a&&a.length===1?a[0]:new ys(a,t),hasStyleChanged:cu,invertTransform:Xe,isBetweenVectors:Df,isIdentityMatrix:sm,isTouchEvent:Kc,isTransparent:t0,joinPath:P0,loadImage:Ph,magnitude:iu,makeBoundingBoxFromPoints:hi,makePathSimpler:w0,matrixToSVG:Jo,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 ys([s],{clipPath:i,inverted:n})},multiplyTransformMatrices:jt,multiplyTransformMatrixArray:$c,parsePath:M0,parsePreserveAspectRatioAttribute:Af,parseUnit:Oe,pick:yr,projectStrokeOnPoints:i0,qrDecompose:br,radiansToDegrees:ai,removeFromArray:mr,removeTransformFromObject:(a,t)=>{const e=Xe(t),s=jt(e,a.calcOwnMatrix());Zo(a,s)},removeTransformMatrixForSvgParsing:bu,request:O0,requestAnimFrame:kh,resetObjectTransform:mm,rotatePoint:(a,t,e)=>a.rotate(e,t),rotateVector:Pf,saveObjectTransform:wf,sendObjectToPlane:xf,sendPointToPlane:wr,sendVectorToPlane:bm,setStyle:mu,sin:Rs,sizeAfterTransform:Qc,string:E_,stylesFromArray:o0,stylesToArray:r0,toBlob:mf,toDataURL:pf,toFixed:yt,transformPath:(a,t,e)=>(e&&(t=jt(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 dw extends dm{constructor(t){let{allowTouchScrolling:e=!1,containerClass:s=""}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(t),E(this,"upper",void 0),E(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=oi();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=Uo().createElement("div");return t.setAttribute("data-fabric","wrapper"),mu(t,{position:"relative"}),um(t),t}applyCanvasStyle(t,e){const{styles:s,allowTouchScrolling:i}=e;mu(t,T(T({},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),_f(this.upper.el,t),_f(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(),ri().dispose(this.upper.el),delete this.upper,delete this.container}}class vu extends Dh{constructor(){super(...arguments),E(this,"targets",[]),E(this,"_hoveredTargets",[]),E(this,"_objectsToRender",void 0),E(this,"_currentTransform",null),E(this,"_groupSelector",null),E(this,"contextTopDirty",!1)}static getDefaults(){return T(T({},super.getDefaults()),vu.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 dw(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 t0(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===Xc||e===Me||e===Ze||e===Eh?i=this.centeredScaling||t.centeredScaling:e===df&&(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=Nt:["mr","tr","br"].includes(e)&&(s.x=dt),["tl","mt","tr"].includes(e)?s.y=cf:["bl","mb","br"].includes(e)&&(s.y=Ve)),s}_setupCurrentTransform(t,e,s){var i;const n=e.group?wr(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):Gy,c=((g,p,b,y)=>{if(!p||!g)return"drag";const v=y.controls[p];return v.getActionName(b,v,y)})(s,r,t,e),u=t[this.centeredKey],d=this._shouldCenterTransform(e,c,u)?{x:J,y:J}: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:Lt(e.angle),width:e.width,height:e.height,shiftKey:t.shiftKey,altKey:u,original:T(T({},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 M(e,s).transform(this.viewportTransform),o=new M(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,Kc(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=Rs(u)*n,g=d+f,p=d-f;s=[new M(r.x-p,r.y-g),new M(o.x+g,o.y-p),new M(h.x+p,h.y+g),new M(c.x-g,c.y+p)]}return Pt.isPointInPolygon(e,s)}_checkTarget(t,e){return!!(t&&t.visible&&t.evented&&this._pointIsInObjectSelectionArea(t,wr(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(Yc(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&&Yc(s)&&s.interactive&&this.targets[0]){const i=this.targets;for(let n=i.length-1;n>0;n--){const r=i[n];if(!Yc(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&&cf in i&&(o=Math.abs(i.top-i.bottom)),Nt 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=wr(n,void 0,this.viewportTransform));const h=this.getRetinaScaling();h!==1&&(n.x/=h,n.y/=h);const c=r===0||o===0?new M(1,1):new M(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=oi(),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 _r(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,_r(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),_r(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(Wc,i))}setViewportTransform(t){super.setViewportTransform(t);const e=this._activeObject;e&&e.setCoords()}destroy(){const t=this._activeObject;_r(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&&_r(e)&&this._activeObject===e){const s=yr(t,["angle","flipX","flipY",dt,Me,Ze,Yo,$o,Ve]);return pm(t,e.calcOwnMatrix()),s}return{}}_setSVGObject(t,e,s){const i=this._realizeGroupTransformOnObject(e);super._setSVGObject(t,e,s),e.set(i)}}E(vu,"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 fw{constructor(t){E(this,"targets",[]),E(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 gw=["target","oldTarget","fireCanvas","e"],es={passive:!1},ra=(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)},_s=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)},pw={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 $f extends vu{constructor(t){super(t,arguments.length>1&&arguments[1]!==void 0?arguments[1]:{}),E(this,"_isClick",void 0),E(this,"textEditingManager",new fw(this)),["_onMouseDown","_onTouchStart","_onMouseMove","_onMouseUp","_onTouchEnd","_onResize","_onMouseWheel","_onMouseOut","_onMouseEnter","_onContextMenu","_onClick","_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,es),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,"click",this._onClick),t(s,"dblclick",this._onClick),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,es)}removeListeners(){this.addOrRemove(_s,"remove");const t=this._getEventPrefix(),e=Ls(this.upperCanvasEl);_s(e,"".concat(t,"up"),this._onMouseUp),_s(e,"touchend",this._onTouchEnd,es),_s(e,"".concat(t,"move"),this._onMouseMove,es),_s(e,"touchmove",this._onMouseMove,es),clearTimeout(this._willAddMouseDown)}_onMouseWheel(t){this.__onMouseWheel(t)}_onMouseOut(t){const e=this._hoveredTarget,s=T({e:t},ra(this,t));this.fire("mouse:out",T(T({},s),{},{target:e})),this._hoveredTarget=void 0,e&&e.fire("mouseout",T({},s)),this._hoveredTargets.forEach(i=>{this.fire("mouse:out",T(T({},s),{},{target:i})),i&&i.fire("mouseout",T({},s))}),this._hoveredTargets=[]}_onMouseEnter(t){this._currentTransform||this.findTarget(t)||(this.fire("mouse:over",T({e:t},ra(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)}gm(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};_s(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",T({e:t,target:e,subTargets:s,dragSource:this._dragSource},ra(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&&gm(t),this._basicEventHandler("contextmenu",i),!1}_onClick(t){const e=t.detail;e>3||e<2||(this._cacheTransformEventData(t),e==2&&t.type==="dblclick"&&this._handleEvent(t,"dblclick"),e==3&&this._handleEvent(t,"tripleclick"),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,es),e&&Pn(r,"touchmove",this._onMouseMove,es),_s(i,"".concat(n,"down"),this._onMouseDown)}_onMouseDown(t){this.__onMouseDown(t),this._resetTransformEventData();const e=this.upperCanvasEl,s=this._getEventPrefix();_s(e,"".concat(s,"move"),this._onMouseMove,es);const i=Ls(e);Pn(i,"".concat(s,"up"),this._onMouseUp),Pn(i,"".concat(s,"move"),this._onMouseMove,es)}_onTouchEnd(t){if(t.touches.length>0)return;this.__onMouseUp(t),this._resetTransformEventData(),delete this.mainTouchId;const e=this._getEventPrefix(),s=Ls(this.upperCanvasEl);_s(s,"touchend",this._onTouchEnd,es),_s(s,"touchmove",this._onMouseMove,es),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);_s(i,"".concat(s,"up"),this._onMouseUp),_s(i,"".concat(s,"move"),this._onMouseMove,es),Pn(e,"".concat(s,"move"),this._onMouseMove,es)}}_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),Kc(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,s){const i=this._target,n=this.targets||[],r=T(T(T({e:t,target:i,subTargets:n},ra(this,t)),{},{transform:this._currentTransform},e==="up:before"||e==="up"?{isClick:this._isClick,currentTarget:this.findTarget(t),currentSubTargets:this.targets}:{}),e==="down:before"||e==="down"?s:{});this.fire("mouse:".concat(e),r),i&&i.fire("mouse".concat(e),r);for(let o=0;o<n.length;o++)n[o]!==i&&n[o].fire("mouse".concat(e),r)}_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",{alreadySelected:!1})}_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,s=!!e&&e===this._activeObject;const{button:i}=t;if(i)return(this.fireMiddleClick&&i===1||this.fireRightClick&&i===2)&&this._handleEvent(t,"down",{alreadySelected:s}),void this._resetTransformEventData();if(this.isDrawingMode)return void this._onMouseDownInDrawingMode(t);if(!this._isMainEvent(t)||this._currentTransform)return;let n=this._shouldRender(e),r=!1;if(this.handleMultiSelection(t,e)?(e=this._activeObject,r=!0,n=!0):this._shouldClearSelection(t,e)&&this.discardActiveObject(t),this.selection&&(!e||!e.selectable&&!e.isEditing&&e!==this._activeObject)){const o=this.getScenePoint(t);this._groupSelector={x:o.x,y:o.y,deltaY:0,deltaX:0}}if(s=!!e&&e===this._activeObject,e){e.selectable&&e.activeOn==="down"&&this.setActiveObject(e,t);const o=e.findControl(this.getViewportPoint(t),Kc(t));if(e===this._activeObject&&(o||!r)){this._setupCurrentTransform(t,e,s);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)}}n&&(this._objectsToRender=void 0),this._handleEvent(t,"down",{alreadySelected:s}),n&&this.requestRenderAll()}_resetTransformEventData(){this._target=this._pointer=this._absolutePointer=void 0}_cacheTransformEventData(t){this._resetTransformEventData(),this._pointer=this.getViewportPoint(t),this._absolutePointer=wr(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",T(T({},e),{},{target:t,oldTarget:s,fireCanvas:!0}));for(let o=0;o<r;o++)this.fireSyntheticInOutEvents("drag",T(T({},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,gw);const{targetIn:h,targetOut:c,canvasIn:u,canvasOut:d}=pw[t],f=i!==s;if(i&&f){const g=T(T({},o),{},{e:r,target:i,nextTarget:s},ra(this,r));n&&this.fire(d,g),i.fire(c,g)}if(s&&f){const g=T(T({},o),{},{e:r,target:s,previousTarget:i},ra(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?wr(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=_r(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=_r(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(z.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 M(e,s),o=r.add(new M(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=z.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 D0={x1:0,y1:0,x2:0,y2:0},mw=T(T({},D0),{},{r1:0,r2:0}),oa=(a,t)=>isNaN(a)&&typeof t=="number"?t:a,bw=/^(\d+\.\d+)%|(\d+)%$/;function R0(a){return a&&bw.test(a)}function L0(a,t){const e=typeof a=="number"?a:typeof a=="string"?parseFloat(a)/(R0(a)?100:1):NaN;return Sr(0,oa(e,t),1)}const vw=/\s*;\s*/,yw=/\s*:\s*/;function _w(a,t){let e,s;const i=a.getAttribute("style");if(i){const r=i.split(vw);r[r.length-1]===""&&r.pop();for(let o=r.length;o--;){const[h,c]=r[o].split(yw).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:L0(a.getAttribute("offset"),0),color:n.toRgb(),opacity:oa(parseFloat(s||a.getAttribute("stop-opacity")||""),1)*n.getAlpha()*t}}function ww(a,t){const e=[],s=a.getElementsByTagName("stop"),i=L0(t,1);for(let n=s.length;n--;)e.push(_w(s[n],i));return e}function F0(a){return a.nodeName==="linearGradient"||a.nodeName==="LINEARGRADIENT"?"linear":"radial"}function I0(a){return a.getAttribute("gradientUnits")==="userSpaceOnUse"?"pixels":"percentage"}function js(a,t){return a.getAttribute(t)}function xw(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"&&R0(u)&&(i*=.01,o==="pixels"&&(c!=="x1"&&c!=="x2"&&c!=="r2"||(i*=n),c!=="y1"&&c!=="y2"||(i*=r)))),h[c]=i,h},{})}(F0(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),T(T({},t),{},{gradientUnits:I0(a)}))}class Gh{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:T(T({},e==="radial"?mw:D0),i),colorStops:n,offsetX:r,offsetY:o,gradientTransform:h,id:c?"".concat(c,"_").concat(kn()):kn()})}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 T(T({},yr(this,t)),{},{type:this.type,coords:T({},this.coords),colorStops:this.colorStops.map(e=>T({},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=>T({},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(Jo(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
+ `)}else if(this.type==="radial"){const{x1:d,y1:f,x2:g,y2:p,r1:b,r2:y}=this.coords,v=b>y;s.push("<radialGradient ",u,' cx="',v?d:g,'" cy="',v?f:p,'" r="',v?b:y,'" fx="',v?g:d,'" fy="',v?p:f,`">
43
+ `),v&&(r.reverse(),r.forEach(C=>{C.offset=1-C.offset}));const x=Math.min(b,y);if(x>0){const C=x/Math.max(b,y);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(A(A({},t),{},{colorStops:e?e.map(i=>A({},i)):void 0,gradientTransform:s?[...s]:void 0}))}static fromElement(t,e,s){const i=E0(t),n=e._findCenterFromElement();return new this(A({id:t.getAttribute("id")||void 0,type:T0(t),coords:gw(t,{width:s.viewBoxWidth||s.width,height:s.viewBoxHeight||s.height}),colorStops:fw(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(Nh,"type","Gradient"),z.setClass(Nh,"gradient"),z.setClass(Nh,"linear"),z.setClass(Nh,"radial");const pw=["type","source","patternTransform"];class Uf{get type(){return"pattern"}set type(t){Ri("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=kn(),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 A(A({},yr(this,t)),{},{type:"pattern",source:this.sourceToString(),repeat:e,crossOrigin:s,offsetX:wt(this.offsetX,ct.NUM_FRACTION_DIGITS),offsetY:wt(this.offsetY,ct.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=ra(this.offsetX/e,0),h=ra(this.offsetY/s,0),c=n==="repeat-y"||n==="no-repeat"?1+Math.abs(o||0):ra(i.width/e,0),u=n==="repeat-x"||n==="no-repeat"?1+Math.abs(h||0):ra(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,pw);const o=await kh(i,A(A({},e),{},{crossOrigin:r.crossOrigin}));return new this(A(A({},r),{},{patternTransform:n&&n.slice(0),source:o}))}}T(Uf,"type","Pattern"),z.setClass(Uf),z.setClass(Uf,"pattern");const mw=["path","left","top"],bw=["d"];class Sr 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,mw);super(),Object.assign(this,Sr.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=d0(Array.isArray(t)?t:_0(t)),this.setBoundingBox(e)}_findCenterFromElement(){const t=this._calcBoundsFromPath();return new k(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 A(A({},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=w0(this.path,ct.NUM_FRACTION_DIGITS);return["<path ","COMMON_PARTS",'d="'.concat(t,`" stroke-linecap="round" />
47
- `)]}_getOffsetTransform(){const t=ct.NUM_FRACTION_DIGITS;return" translate(".concat(wt(-this.pathOffset.x,t),", ").concat(wt(-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,J,J)}_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 ai(t)}_calcDimensions(){const t=this._calcBoundsFromPath();return A(A({},t),{},{pathOffset:new k(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=ji(t,this.ATTRIBUTE_NAMES,s),{d:n}=i;return new this(n,A(A(A({},Ct(i,bw)),e),{},{left:void 0,top:void 0}))}}T(Sr,"type","Path"),T(Sr,"cacheProperties",[...Ii,"path","fillRule"]),T(Sr,"ATTRIBUTE_NAMES",[...Mn,"d"]),z.setClass(Sr),z.setSVGClass(Sr);const vw=["left","top","radius"],k0=["radius","startAngle","endAngle","counterClockwise"];class Hi extends pe{static getDefaults(){return A(A({},super.getDefaults()),Hi.ownDefaults)}constructor(t){super(),Object.assign(this,Hi.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,Lt(this.startAngle),Lt(this.endAngle),this.counterClockwise),this._renderPaintInOrder(t)}getRadiusX(){return this.get("radius")*this.get(Me)}getRadiusY(){return this.get("radius")*this.get(Ze)}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([...k0,...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
- `];{const{radius:e}=this,s=Lt(this.startAngle),i=Lt(this.endAngle),n=Rs(s)*e,r=Ls(s)*e,o=Rs(i)*e,h=Ls(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=ji(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:r=0,radius:o=0}=i;return new this(A(A({},Ct(i,vw)),{},{radius:o,left:n-o,top:r-o}))}static fromObject(t){return super._fromObject(t)}}T(Hi,"type","Circle"),T(Hi,"cacheProperties",[...Ii,...k0]),T(Hi,"ownDefaults",{radius:0,startAngle:0,endAngle:360,counterClockwise:!1}),T(Hi,"ATTRIBUTE_NAMES",["cx","cy","r",...Mn]),z.setClass(Hi),z.setSVGClass(Hi);const yw=["x1","y1","x2","y2"],_w=["x1","y1","x2","y2"],Yf=["x1","x2","y1","y2"];class Cr 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,Cr.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}=ai([{x:t,y:e},{x:s,y:i}]),c=new k(n+o/2,r+h/2);this.setPositionByOrigin(c,J,J)}_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;ys(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 k((this.x1+this.x2)/2,(this.y1+this.y2)/2)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return A(A({},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=ji(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,yw))}static fromObject(t){let{x1:e,y1:s,x2:i,y2:n}=t,r=Ct(t,_w);return this._fromObject(A(A({},r),{},{points:[e,s,i,n]}),{extraParam:"points"})}}T(Cr,"type","Line"),T(Cr,"cacheProperties",[...Ii,...Yf]),T(Cr,"ATTRIBUTE_NAMES",Mn.concat(Yf)),z.setClass(Cr),z.setSVGClass(Cr);class Ar extends pe{static getDefaults(){return A(A({},super.getDefaults()),Ar.ownDefaults)}constructor(t){super(),Object.assign(this,Ar.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(Ar,"type","Triangle"),T(Ar,"ownDefaults",{width:100,height:100}),z.setClass(Ar),z.setSVGClass(Ar);const M0=["rx","ry"];class zi extends pe{static getDefaults(){return A(A({},super.getDefaults()),zi.ownDefaults)}constructor(t){super(),Object.assign(this,zi.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(Ze)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject([...M0,...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,Li,!1),t.restore(),this._renderPaintInOrder(t)}static async fromElement(t,e,s){const i=ji(t,this.ATTRIBUTE_NAMES,s);return i.left=(i.left||0)-i.rx,i.top=(i.top||0)-i.ry,new this(i)}}function ww(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(zi,"type","Ellipse"),T(zi,"cacheProperties",[...Ii,...M0]),T(zi,"ownDefaults",{rx:0,ry:0}),T(zi,"ATTRIBUTE_NAMES",[...Mn,"cx","cy","rx","ry"]),z.setClass(zi),z.setSVGClass(zi);const xw=["left","top"],P0={exactBoundingBox:!1};class Hs extends pe{static getDefaults(){return A(A({},super.getDefaults()),Hs.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,Hs.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 $m(this.points,t,this.isOpen())}_calcDimensions(t){t=A({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 k,strokeOffset:new k,strokeDiff:new k};const s=ai(e),i=Eh(A(A({},t),{},{scaleX:1,scaleY:1})),n=ai(this.points.map(c=>ge(c,i,!0))),r=new k(this.scaleX,this.scaleY);let o=s.left+s.width/2,h=s.top+s.height/2;return this.exactBoundingBox&&(o-=h*Math.tan(Lt(this.skewX)),h-=o*Math.tan(Lt(this.skewY))),A(A({},s),{},{pathOffset:new k(o,h),strokeOffset:new k(n.left,n.top).subtract(new k(s.left,s.top)).multiply(r),strokeDiff:new k(s.width,s.height).subtract(new k(n.width,n.height)).multiply(r)})}_findCenterFromElement(){const t=ai(this.points);return new k(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 k(e+i/2,s+n/2),J,J)}isStrokeAccountedForInDimensions(){return this.exactBoundingBox}_getNonTransformedDimensions(){return this.exactBoundingBox?new k(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 k((e=t.width)!==null&&e!==void 0?e:o,(s=t.height)!==null&&s!==void 0?s:h)}else{var i,n;r=new k((i=t.width)!==null&&i!==void 0?i:this.width,(n=t.height)!==null&&n!==void 0?n:this.height)}return r.multiply(new k(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===Ze)&&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 A(A({},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=ct.NUM_FRACTION_DIGITS;for(let n=0,r=this.points.length;n<r;n++)t.push(wt(this.points[n].x-e,i),",",wt(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(ww(t.getAttribute("points")),A(A({},Ct(ji(t,this.ATTRIBUTE_NAMES,s),xw)),e))}static fromObject(t){return this._fromObject(t,{extraParam:"points"})}}T(Hs,"ownDefaults",P0),T(Hs,"type","Polyline"),T(Hs,"layoutProperties",[Uo,Yo,"strokeLineCap","strokeLineJoin","strokeMiterLimit","strokeWidth","strokeUniform","points"]),T(Hs,"cacheProperties",[...Ii,"points"]),T(Hs,"ATTRIBUTE_NAMES",[...Mn]),z.setClass(Hs),z.setSVGClass(Hs);class mu extends Hs{isOpen(){return!1}}T(mu,"ownDefaults",P0),T(mu,"type","Polygon"),z.setClass(mu),z.setSVGClass(mu);const O0=["fontSize","fontWeight","fontFamily","fontStyle"],D0=["underline","overline","linethrough"],R0=[...O0,"lineHeight","text","charSpacing","textAlign","styles","path","pathStartOffset","pathSide","pathAlign"],L0=[...R0,...D0,"textBackgroundColor","direction"],Sw=[...O0,...D0,Pe,"strokeWidth",Gt,"deltaY","textBackgroundColor"],Cw={_reNewline:lf,_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},li="justify",bu="justify-left",jh="justify-right",Bh="justify-center";class F0 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=bf(A(A({},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 A(A({},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(F0,"_styleProperties",Sw);const Aw=/ +/g,Tw=/"/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]:ct.NUM_FRACTION_DIGITS;const f=Dh(Gt,n,!1),[g,p,b,v]=[o,h,c,u].map(y=>wt(y,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 Ew=["textAnchor","textDecoration","dx","dy","top","left","fontSize","strokeWidth"];let qf;class me extends F0{static getDefaults(){return A(A({},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(li)&&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===li||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 J:t.textBaseline="middle";break;case"ascender":t.textBaseline=Ve;break;case"descender":t.textBaseline=hf}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=Ch.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=ts({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===Nt,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 J:u=(d-i)/2;break;case Nt: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=v0(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===Nt?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(Gt))&&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(li),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,y,x,S="",C=0;if(e.save(),g!==this.direction&&(e.canvas.setAttribute("dir",d?"ltr":"rtl"),e.direction=d?"ltr":"rtl",e.textAlign=d?dt:Nt),n-=o*this._fontSizeFraction/this.lineHeight,u)return this._renderChar(t,e,r,0,s.join(""),i,n),void e.restore();for(let E=0,P=s.length-1;E<=P;E++)y=E===P||this.charSpacing||c,S+=s[E],v=this.__charBounds[r][E],C===0?(i+=f*(v.kernedWidth-v.width),C+=v.width):C+=v.kernedWidth,h&&!y&&this._reSpaceAndTab.test(s[E])&&(y=!0),y||(p=p||this.getCompleteStyleDeclaration(r,E),b=this.getCompleteStyleDeclaration(r,E+1),y=au(p,b,!1)),y&&(c?(e.save(),e.translate(v.renderLeft,v.renderTop),e.rotate(v.angle),this._renderChar(t,e,r,E,S,-C/2,0),e.restore()):(x=i,this._renderChar(t,e,r,E,S,x,n)),S="",p=b,i+=f*C,C=0);e.restore()}_applyPatternGradientTransformText(t){const e=this.width+this.strokeWidth,s=this.height+this.strokeWidth,i=ts({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 ys(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===li||i===Bh&&!r||i===jh&&!r||i===bu&&!r?0:(i===J&&(o=s/2),i===Nt&&(o=s),i===Bh&&(o=s/2),i===jh&&(o=s),n==="rtl"&&(i===Nt||i===li||i===jh?o=0:i===dt||i===bu?o=-s:i!==J&&i!==Bh||(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,y=0,x=this.getValueOfPropertyAt(h,0,e),S=this.getValueOfPropertyAt(h,0,Gt);const C=s+f*(1-this._fontSizeFraction);let E=this.getHeightOfChar(h,0),P=this.getValueOfPropertyAt(h,0,"deltaY");for(let O=0,R=d.length;O<R;O++){const L=this.__charBounds[h][O];p=this.getValueOfPropertyAt(h,O,e),b=this.getValueOfPropertyAt(h,O,Gt);const N=this.getHeightOfChar(h,O),D=this.getValueOfPropertyAt(h,O,"deltaY");if(n&&p&&b)t.save(),t.fillStyle=S,t.translate(L.renderLeft,L.renderTop),t.rotate(L.angle),t.fillRect(-L.kernedWidth/2,o*N+D,L.kernedWidth,this.fontSize/15),t.restore();else if((p!==x||b!==S||N!==E||D!==P)&&y>0){let F=i+g+v;this.direction==="rtl"&&(F=this.width-F-y),x&&S&&(t.fillStyle=S,t.fillRect(F,C+o*E+P,y,this.fontSize/15)),v=L.left,y=L.width,x=p,S=b,E=N,P=D}else y+=L.kernedWidth}let M=i+g+v;this.direction==="rtl"&&(M=this.width-M-y),t.fillStyle=b,p&&b&&t.fillRect(M,C+o*E+P,y-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 A(A({},super.toObject([...L0,...t])),{},{styles:Km(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=ji(t,me.ATTRIBUTE_NAMES,s),n=A(A({},e),i),{textAnchor:r=dt,textDecoration:o="",dx:h=0,dy:c=0,top:u=0,left:d=0,fontSize:f=af,strokeWidth:g=1}=n,p=Ct(n,Ew),b=new this((t.textContent||"").replace(/^\s+|\s+$|\n+/g,"").replace(/\s+/g," "),A({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,y=((b.height+b.strokeWidth)*b.lineHeight-b.height)*v,x=b.getScaledHeight()+y;let S=0;return r===J&&(S=b.getScaledWidth()/2),r===Nt&&(S=b.getScaledWidth()),b.set({left:b.left-S,top:b.top-(x-b.fontSize*(.07+b._fontSizeFraction))/b.lineHeight,strokeWidth:g}),b}static fromObject(t){return this._fromObject(A(A({},t),{},{styles:Qm(t.styles||{},t.text)}),{extraParam:"text"})}}T(me,"textLayoutProperties",R0),T(me,"cacheProperties",[...Ii,...L0]),T(me,"ownDefaults",Cw),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")),Xm(me,[class extends Cm{_toSVG(){const a=this._getSVGLeftTopOffsets(),t=this._getSVGTextAndBg(a.textTop,a.textLeft);return this._wrapSVGTextAndBg(t)}toSVG(a){const t=this._createBaseSVGMarkup(this._toSVG(),{reviver:a,noStyle:!0,withShadow:!0}),e=this.path;return e?t+e._createBaseSVGMarkup(e._toSVG(),{reviver:a,withShadow:!0,additionalTransform:Qo(this.calcOwnMatrix())}):t}_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(Tw,"'"),'" '):"",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,i){const n=ct.NUM_FRACTION_DIGITS,r=this.getSvgSpanStyles(t,a!==a.trim()||!!a.match(Aw)),o=r?'style="'.concat(r,'"'):"",h=t.deltaY,c=h?' dy="'.concat(wt(h,n),'" '):"",{angle:u,renderLeft:d,renderTop:f,width:g}=i;let p="";if(d!==void 0){const b=g/2;u&&(p=' rotate="'.concat(wt(oi(u),n),'"'));const v=vr({angle:oi(u)});v[4]=d,v[5]=f;const y=new k(-b,0).transform(v);e=y.x,s=y.y}return'<tspan x="'.concat(wt(e,n),'" y="').concat(wt(s,n),'" ').concat(c).concat(p).concat(o,">").concat(qm(a),"</tspan>")}_setSVGTextLineText(a,t,e,s){const i=this.getHeightOfLine(t),n=this.textAlign.includes(li),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||this.path,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,c)),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?Dh(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?Dh(Gt,n):"",c?"baseline-shift: ".concat(-c,"; "):"",t?"white-space: pre; ":""].join("")}getSvgTextDecoration(a){return["overline","underline","line-through"].filter(t=>a[t.replace("-","")]).join(" ")}}]),z.setClass(me),z.setSVGClass(me);class kw{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 k(r.flipX?-1:1,r.flipY?-1:1),c=r._getCursorBoundaries(i),u=new k(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 k(g.left,g.top)),b=o.viewportTransform,v=p.add(d).transform(b,!0),y=r.backgroundColor,x=Nf(r.styles);r.backgroundColor="";const S={stroke:"transparent",fill:"transparent",textBackgroundColor:"transparent"};r.setSelectionStyles(S,0,i),r.setSelectionStyles(S,n,r.text.length),r.dirty=!0;const C=r.toCanvasElement({enableRetinaScaling:o.enableRetinaScaling,viewportTransform:!0});r.backgroundColor=y,r.styles=x,r.dirty=!0,fu(C,{position:"fixed",left:"".concat(-C.width,"px"),border:ke,width:"".concat(C.width/f,"px"),height:"".concat(C.height/f,"px")}),this.__dragImageDisposer&&this.__dragImageDisposer(),this.__dragImageDisposer=()=>{C.remove()},Fs(t.target||this.target.hiddenTextarea).body.appendChild(C),(s=t.dataTransfer)===null||s===void 0||s.setDragImage(C,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=A({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(zc,{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(zc,{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 I0=/[ \n\.,;!\?\-]/;class Mw 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}cmdAll(){this.selectAll(),this.renderCursorOrSelection()}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||!lf.test(s[t-1]))?t-1:t,n=s[i];for(;i>0&&i<s.length&&!I0.test(n);)i+=e,n=s[i];return e===-1&&I0.test(n)&&i++,i}selectWord(t){var e;t=(e=t)!==null&&e!==void 0?e:this.selectionStart;const s=this.searchWordBoundary(t,-1),i=Math.max(s,this.searchWordBoundary(t,1));this.selectionStart=s,this.selectionEnd=i,this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()}selectLine(t){var e;t=(e=t)!==null&&e!==void 0?e:this.selectionStart;const s=this.findLineBoundaryLeft(t),i=this.findLineBoundaryRight(t);this.selectionStart=s,this.selectionEnd=i,this._fireSelectionChanged(),this._updateTextarea()}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;Fs(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 k(e.left+o,e.top+e.topOffset+r).transform(this.calcTransformMatrix()).transform(this.canvas.viewportTransform).multiply(new k(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:A({},i[s-1])}:c?this.styles[t+s]={0:A({},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?A({},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]=A({},i[s]));return}if(!n)return;const o=n[e?e-1:1];for(;o&&s--;)this.styles[t][e+s]=A({},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===Nt&&(this._selectionDirection=dt,this.selectionEnd=t),this.selectionStart=s):s>t&&s<e?this._selectionDirection===Nt?this.selectionEnd=s:this.selectionStart=s:(e===t?this._selectionDirection=Nt:this._selectionDirection===dt&&(this._selectionDirection=Nt,this.selectionStart=e),this.selectionEnd=s)}}class Pw extends Mw{initHiddenTextarea(){const t=this.canvas&&Fs(this.canvas.getElement())||Wo(),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,{value:s,selectionStart:i,selectionEnd:n}=this.hiddenTextarea;if(this.fromPaste=!1,t&&t.stopPropagation(),!this.isEditing)return;const r=()=>{this.updateFromTextArea(),this.fire(zc),this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll())};if(this.hiddenTextarea.value==="")return this.styles={},void r();const o=this._splitTextIntoLines(s).graphemeText,h=this._text.length,c=o.length,u=this.selectionStart,d=this.selectionEnd,f=u!==d;let g,p,b,v,y=c-h;const x=this.fromStringToGraphemeSelection(i,n,s),S=u>x.selectionStart;f?(p=this._text.slice(u,d),y+=d-u):c<h&&(p=S?this._text.slice(d+y,d):this._text.slice(u,u-y));const C=o.slice(x.selectionEnd-y,x.selectionEnd);if(p&&p.length&&(C.length&&(g=this.getSelectionStyles(u,u+1,!1),g=C.map(()=>g[0])),f?(b=u,v=d):S?(b=d-p.length,v=d):(b=d,v=d+p.length),this.removeStyleFromTo(b,v)),C.length){const{copyPasteData:E}=ri();e&&C.join("")===E.copiedText&&!ct.disableStyleCopyPaste&&(g=E.copiedTextStyle),this.insertNewStyleBlock(C,u,g)}r()}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}=ri();t.copiedText=this.getSelectedText(),ct.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===Nt);if(e.shiftKey?this.moveCursorWithShift(s):this.moveCursorWithoutShift(s),s!==0){const i=this.text.length;this.selectionStart=xr(0,this.selectionStart,i),this.selectionEnd=xr(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===Nt&&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=Nt,this._moveRight(t,"selectionEnd")):void 0}moveCursorRightWithoutShift(t){let e=!0;return this._selectionDirection=Nt,this.selectionStart===this.selectionEnd?(e=this._moveRight(t,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,e}}const N0=a=>!!a.button;class Ow extends Pw{constructor(){super(...arguments),T(this,"draggableTextDelegate",void 0)}initBehavior(){this.on("mousedown",this._mouseDownHandler),this.on("mouseup",this.mouseUpHandler),this.on("mousedblclick",this.doubleClickHandler),this.on("mousetripleclick",this.tripleClickHandler),this.draggableTextDelegate=new kw(this),super.initBehavior()}shouldStartDragging(){return this.draggableTextDelegate.isActive()}onDragStart(t){return this.draggableTextDelegate.onDragStart(t)}canDrop(t){return this.draggableTextDelegate.canDrop(t)}doubleClickHandler(t){this.isEditing&&(this.selectWord(this.getSelectionStartFromPointer(t.e)),this.renderCursorOrSelection())}tripleClickHandler(t){this.isEditing&&(this.selectLine(this.getSelectionStartFromPointer(t.e)),this.renderCursorOrSelection())}_mouseDownHandler(t){let{e,alreadySelected:s}=t;this.canvas&&this.editable&&!N0(e)&&!this.getActiveControl()&&(this.draggableTextDelegate.start(e)||(this.canvas.textEditingManager.register(this),s&&(this.inCompositionMode=!1,this.setCursorByClick(e)),this.isEditing&&(this.__selectionStartOnMouseDown=this.selectionStart,this.selectionStart===this.selectionEnd&&this.abortCursorAnimation(),this.renderCursorOrSelection()),this.selected||(this.selected=s||this.isEditing)))}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||N0(e)||i||this.selected&&!this.getActiveControl()&&(this.enterEditing(e),this.selectionStart===this.selectionEnd?this.initDelayedCursor(!0):this.renderCursorOrSelection())}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 k(-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 vu="moveCursorUp",yu="moveCursorDown",_u="moveCursorLeft",wu="moveCursorRight",xu="exitEditing",j0=(a,t)=>{const e=t.getRetinaScaling();a.setTransform(e,0,0,e,0,0);const s=t.viewportTransform;a.transform(s[0],s[1],s[2],s[3],s[4],s[5])},Dw=A({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:vu,34:yu,35:wu,36:_u,37:_u,38:vu,39:wu,40:yu},keysMapRtl:{9:xu,27:xu,33:vu,34:yu,35:_u,36:wu,37:wu,38:vu,39:_u,40:yu},ctrlKeysMapDown:{65:"cmdAll"},ctrlKeysMapUp:{67:"copy",88:"cut"}},{_selectionDirection:null,_reSpace:/\s|\r?\n/,inCompositionMode:!1});class Gi extends Ow{static getDefaults(){return A(A({},super.getDefaults()),Gi.ownDefaults)}get type(){const t=super.type;return t==="itext"?"i-text":t}constructor(t,e){super(t,A(A({},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||!this.canvas)return;const t=this.clearContextTop(!0);if(!t)return;const e=this._getCursorBoundaries(),s=this.findAncestorsWithClipPath(),i=s.length>0;let n,r=t;if(i){n=ts(t.canvas),r=n.getContext("2d"),j0(r,this.canvas);const o=this.calcTransformMatrix();r.transform(o[0],o[1],o[2],o[3],o[4],o[5])}if(this.selectionStart!==this.selectionEnd||this.inCompositionMode?this.renderSelection(r,e):this.renderCursor(r,e),i)for(const o of s){const h=o.clipPath,c=ts(t.canvas),u=c.getContext("2d");if(j0(u,this.canvas),!h.absolutePositioned){const d=o.calcTransformMatrix();u.transform(d[0],d[1],d[2],d[3],d[4],d[5])}h.transform(u),h.drawObject(u,!0,{}),this.drawClipPathOnCache(r,h,c)}i&&(t.setTransform(1,0,0,1,0,0),t.drawImage(n,0,0)),this.canvas.contextTopDirty=!0,t.restore()}findAncestorsWithClipPath(){const t=[];let e=this;for(;e;)e.clipPath&&t.push(e),e=e.parent;return t}_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===Nt||this.textAlign===li||this.textAlign===jh?h.left*=-1:this.textAlign===dt||this.textAlign===bu?h.left=r-(s>0?s:0):this.textAlign!==J&&this.textAlign!==Bh||(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(li),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,y=0,x=0;if(g===c&&(y=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 M=this._getWidthOfCharSpacing();x=this.__charBounds[u][f-1].left+this.__charBounds[u][f-1].width-M}v=b,(this.lineHeight<1||g===u&&this.lineHeight>1)&&(b/=this.lineHeight);let S=s.left+p+y,C=b,E=0;const P=x-y;this.inCompositionMode?(t.fillStyle=this.compositionColor||"black",C=1,E=b):t.fillStyle=this.selectionColor,this.direction==="rtl"&&(this.textAlign===Nt||this.textAlign===li||this.textAlign===jh?S=this.width-S-P:this.textAlign===dt||this.textAlign===bu?S=s.left+p-x:this.textAlign!==J&&this.textAlign!==Bh||(S=s.left+p-x)),t.fillRect(S,s.top+s.topOffset+E,P,C),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,Gt)}_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",Dw),T(Gi,"type","IText"),z.setClass(Gi),z.setClass(Gi,"i-text");class Tr extends Gi{static getDefaults(){return A(A({},super.getDefaults()),Tr.ownDefaults)}constructor(t,e){super(t,A(A({},Tr.ownDefaults),e))}static createControls(){return{controls:m_()}}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(li)&&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),y=n[t];let x;for(g=0,x=0;x<y.length;x++){const{word:S,width:C}=y[x];g+=S.length,d+=p+C-o,d>v&&!b?(c.push(f),f=[],d=C,b=!0):d+=o,b||h||f.push(u),f=f.concat(S),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(Tr,"type","Textbox"),T(Tr,"textLayoutProperties",[...Gi.textLayoutProperties,"width"]),T(Tr,"ownDefaults",{minWidth:20,dynamicMinWidth:2,lockScalingFlip:!0,noScaleCache:!1,_wordJoiners:/[ \t\r]/,splitByGrapheme:!1}),z.setClass(Tr);class B0 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}=ai(a0(s,i)),h=new k(r,o);if(i.absolutePositioned)return{center:wr(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 k,correction:d=new k}=this.calcBoundingBox(e,t)||{};return{center:u.add(c),correction:d.subtract(c),size:h}}return{center:s.getRelativeCenterPoint().add(c),size:h}}}}T(B0,"type","clip-path"),z.setClass(B0);class H0 extends uu{getInitialSize(t,e){let{target:s}=t,{size:i}=e;return new k(s.width||i.x,s.height||i.y)}}T(H0,"type","fixed"),z.setClass(H0);class Rw extends Fh{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 Er extends _s{static getDefaults(){return A(A({},super.getDefaults()),Er.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,Er.ownDefaults),this.setOptions(e);const{left:s,top:i,layoutManager:n}=e;this.groupInit(t,{left:s,top:i,layoutManager:n??new Rw})}_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))?(Ri("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=A(A({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(Er,"type","ActiveSelection"),T(Er,"ownDefaults",{multiSelectionStacking:"canvas-stacking"}),z.setClass(Er),z.setClass(Er,"activeSelection");class Lw{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 z0{constructor(){let{tileSize:t=ct.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=ts({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,y=f.destinationHeight;p===v&&b===y||(g.width=v,g.height=y)}(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 Kf;function Fw(){const{WebGLProbe:a}=ri();return a.queryWebGL(vs()),ct.enableGLFiltering&&a.isSupported(ct.textureSize)?new z0({tileSize:ct.textureSize}):new Lw}function Qf(){return!Kf&&(!(arguments.length>0&&arguments[0]!==void 0)||arguments[0])&&(Kf=Fw()),Kf}const Iw=["filters","resizeFilter","src","crossOrigin","type"],G0=["cropX","cropY"];class be extends pe{static getDefaults(){return A(A({},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(kn()),this.setElement(typeof t=="string"?(this.canvas&&Fs(this.canvas.getElement())||Wo()).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=Qf(!1);e instanceof z0&&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&&ri().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())}),A(A({},super.toObject([...G0,...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=kn();n.push('<clipPath id="imageCrop_'+c+`">
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(T(T({},t),{},{colorStops:e?e.map(i=>T({},i)):void 0,gradientTransform:s?[...s]:void 0}))}static fromElement(t,e,s){const i=I0(t),n=e._findCenterFromElement();return new this(T({id:t.getAttribute("id")||void 0,type:F0(t),coords:xw(t,{width:s.viewBoxWidth||s.width,height:s.viewBoxHeight||s.height}),colorStops:ww(t,s.opacity),gradientUnits:i,gradientTransform:uu(t.getAttribute("gradientTransform")||"")},i==="pixels"?{offsetX:e.width/2-n.x,offsetY:e.height/2-n.y}:{offsetX:0,offsetY:0}))}}E(Gh,"type","Gradient"),z.setClass(Gh,"gradient"),z.setClass(Gh,"linear"),z.setClass(Gh,"radial");const Sw=["type","source","patternTransform"];class qf{get type(){return"pattern"}set type(t){Li("warn","Setting type has no effect",t)}constructor(t){E(this,"repeat","repeat"),E(this,"offsetX",0),E(this,"offsetY",0),E(this,"crossOrigin",""),this.id=kn(),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 T(T({},yr(this,t)),{},{type:"pattern",source:this.sourceToString(),repeat:e,crossOrigin:s,offsetX:yt(this.offsetX,ht.NUM_FRACTION_DIGITS),offsetY:yt(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=oa(this.offsetX/e,0),h=oa(this.offsetY/s,0),c=n==="repeat-y"||n==="no-repeat"?1+Math.abs(o||0):oa(i.width/e,0),u=n==="repeat-x"||n==="no-repeat"?1+Math.abs(h||0):oa(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,Sw);const o=await Ph(i,T(T({},e),{},{crossOrigin:r.crossOrigin}));return new this(T(T({},r),{},{patternTransform:n&&n.slice(0),source:o}))}}E(qf,"type","Pattern"),z.setClass(qf),z.setClass(qf,"pattern");const Cw=["path","left","top"],Aw=["d"];class Cr 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,Cw);super(),Object.assign(this,Cr.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=w0(Array.isArray(t)?t:M0(t)),this.setBoundingBox(e)}_findCenterFromElement(){const t=this._calcBoundsFromPath();return new M(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 T(T({},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=P0(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(yt(-this.pathOffset.x,t),", ").concat(yt(-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,J,J)}_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(...Uf(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(...Uf(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 hi(t)}_calcDimensions(){const t=this._calcBoundsFromPath();return T(T({},t),{},{pathOffset:new M(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=Bi(t,this.ATTRIBUTE_NAMES,s),{d:n}=i;return new this(n,T(T(T({},Ct(i,Aw)),e),{},{left:void 0,top:void 0}))}}E(Cr,"type","Path"),E(Cr,"cacheProperties",[...Ni,"path","fillRule"]),E(Cr,"ATTRIBUTE_NAMES",[...Mn,"d"]),z.setClass(Cr),z.setSVGClass(Cr);const Tw=["left","top","radius"],N0=["radius","startAngle","endAngle","counterClockwise"];class zi extends pe{static getDefaults(){return T(T({},super.getDefaults()),zi.ownDefaults)}constructor(t){super(),Object.assign(this,zi.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,Lt(this.startAngle),Lt(this.endAngle),this.counterClockwise),this._renderPaintInOrder(t)}getRadiusX(){return this.get("radius")*this.get(Me)}getRadiusY(){return this.get("radius")*this.get(Ze)}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([...N0,...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
+ `];{const{radius:e}=this,s=Lt(this.startAngle),i=Lt(this.endAngle),n=Ds(s)*e,r=Rs(s)*e,o=Ds(i)*e,h=Rs(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=Bi(t,this.ATTRIBUTE_NAMES,s),{left:n=0,top:r=0,radius:o=0}=i;return new this(T(T({},Ct(i,Tw)),{},{radius:o,left:n-o,top:r-o}))}static fromObject(t){return super._fromObject(t)}}E(zi,"type","Circle"),E(zi,"cacheProperties",[...Ni,...N0]),E(zi,"ownDefaults",{radius:0,startAngle:0,endAngle:360,counterClockwise:!1}),E(zi,"ATTRIBUTE_NAMES",["cx","cy","r",...Mn]),z.setClass(zi),z.setSVGClass(zi);const Ew=["x1","y1","x2","y2"],kw=["x1","y1","x2","y2"],Kf=["x1","x2","y1","y2"];class Ar 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,Ar.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}=hi([{x:t,y:e},{x:s,y:i}]),c=new M(n+o/2,r+h/2);this.setPositionByOrigin(c,J,J)}_set(t,e){return super._set(t,e),Kf.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;vs(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 M((this.x1+this.x2)/2,(this.y1+this.y2)/2)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return T(T({},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=Bi(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,Ew))}static fromObject(t){let{x1:e,y1:s,x2:i,y2:n}=t,r=Ct(t,kw);return this._fromObject(T(T({},r),{},{points:[e,s,i,n]}),{extraParam:"points"})}}E(Ar,"type","Line"),E(Ar,"cacheProperties",[...Ni,...Kf]),E(Ar,"ATTRIBUTE_NAMES",Mn.concat(Kf)),z.setClass(Ar),z.setSVGClass(Ar);class Tr extends pe{static getDefaults(){return T(T({},super.getDefaults()),Tr.ownDefaults)}constructor(t){super(),Object.assign(this,Tr.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),'" />']}}E(Tr,"type","Triangle"),E(Tr,"ownDefaults",{width:100,height:100}),z.setClass(Tr),z.setSVGClass(Tr);const j0=["rx","ry"];class Gi extends pe{static getDefaults(){return T(T({},super.getDefaults()),Gi.ownDefaults)}constructor(t){super(),Object.assign(this,Gi.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(Ze)}toObject(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return super.toObject([...j0,...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,Fi,!1),t.restore(),this._renderPaintInOrder(t)}static async fromElement(t,e,s){const i=Bi(t,this.ATTRIBUTE_NAMES,s);return i.left=(i.left||0)-i.rx,i.top=(i.top||0)-i.ry,new this(i)}}function Mw(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}E(Gi,"type","Ellipse"),E(Gi,"cacheProperties",[...Ni,...j0]),E(Gi,"ownDefaults",{rx:0,ry:0}),E(Gi,"ATTRIBUTE_NAMES",[...Mn,"cx","cy","rx","ry"]),z.setClass(Gi),z.setSVGClass(Gi);const Pw=["left","top"],B0={exactBoundingBox:!1};class Bs extends pe{static getDefaults(){return T(T({},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(),E(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 i0(this.points,t,this.isOpen())}_calcDimensions(t){t=T({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 M,strokeOffset:new M,strokeDiff:new M};const s=hi(e),i=Mh(T(T({},t),{},{scaleX:1,scaleY:1})),n=hi(this.points.map(c=>ge(c,i,!0))),r=new M(this.scaleX,this.scaleY);let o=s.left+s.width/2,h=s.top+s.height/2;return this.exactBoundingBox&&(o-=h*Math.tan(Lt(this.skewX)),h-=o*Math.tan(Lt(this.skewY))),T(T({},s),{},{pathOffset:new M(o,h),strokeOffset:new M(n.left,n.top).subtract(new M(s.left,s.top)).multiply(r),strokeDiff:new M(s.width,s.height).subtract(new M(n.width,n.height)).multiply(r)})}_findCenterFromElement(){const t=hi(this.points);return new M(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 M(e+i/2,s+n/2),J,J)}isStrokeAccountedForInDimensions(){return this.exactBoundingBox}_getNonTransformedDimensions(){return this.exactBoundingBox?new M(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 M((e=t.width)!==null&&e!==void 0?e:o,(s=t.height)!==null&&s!==void 0?s:h)}else{var i,n;r=new M((i=t.width)!==null&&i!==void 0?i:this.width,(n=t.height)!==null&&n!==void 0?n:this.height)}return r.multiply(new M(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===Ze)&&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 T(T({},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(yt(this.points[n].x-e,i),",",yt(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(Mw(t.getAttribute("points")),T(T({},Ct(Bi(t,this.ATTRIBUTE_NAMES,s),Pw)),e))}static fromObject(t){return this._fromObject(t,{extraParam:"points"})}}E(Bs,"ownDefaults",B0),E(Bs,"type","Polyline"),E(Bs,"layoutProperties",[Yo,$o,"strokeLineCap","strokeLineJoin","strokeMiterLimit","strokeWidth","strokeUniform","points"]),E(Bs,"cacheProperties",[...Ni,"points"]),E(Bs,"ATTRIBUTE_NAMES",[...Mn]),z.setClass(Bs),z.setSVGClass(Bs);class yu extends Bs{isOpen(){return!1}}E(yu,"ownDefaults",B0),E(yu,"type","Polygon"),z.setClass(yu),z.setSVGClass(yu);class H0 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=yf(T(T({},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 T(T({},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]}}E(H0,"_styleProperties",Vy);const Ow=/ +/g,Dw=/"/g;function Qf(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=Lh(Gt,n,!1),[g,p,b,y]=[o,h,c,u].map(v=>yt(v,d));return"<rect ".concat(f,' x="').concat(g,'" y="').concat(p,'" width="').concat(b,'" height="').concat(y,'"></rect>')}(a,{left:t,top:e,width:s,height:i}),`
53
+ `)}const Rw=["textAnchor","textDecoration","dx","dy","top","left","fontSize","strokeWidth"];let Jf;class me extends H0{static getDefaults(){return T(T({},super.getDefaults()),me.ownDefaults)}constructor(t,e){super(),E(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=Yf(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(li)&&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===li||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 J:t.textBaseline="middle";break;case"ascender":t.textBaseline=Ve;break;case"descender":t.textBaseline=cf}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 y=this.__charBounds[n][b];d=this.getValueOfPropertyAt(n,b,"textBackgroundColor"),this.path?(t.save(),t.translate(y.renderLeft,y.renderTop),t.rotate(y.angle),t.fillStyle=d,d&&t.fillRect(-y.width/2,-o/this.lineHeight*(1-this._fontSizeFraction),y.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=y.left,f=y.width,p=d):f+=y.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=Th.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 Jf||(Jf=ts({width:0,height:0}).getContext("2d")),Jf}();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===Nt,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 J:u=(d-i)/2;break;case Nt: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=E0(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===Nt?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(Gt))&&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(li),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,y,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:Nt),n-=o*this._fontSizeFraction/this.lineHeight,u)return this._renderChar(t,e,r,0,s.join(""),i,n),void e.restore();for(let A=0,k=s.length-1;A<=k;A++)v=A===k||this.charSpacing||c,C+=s[A],y=this.__charBounds[r][A],S===0?(i+=f*(y.kernedWidth-y.width),S+=y.width):S+=y.kernedWidth,h&&!v&&this._reSpaceAndTab.test(s[A])&&(v=!0),v||(p=p||this.getCompleteStyleDeclaration(r,A),b=this.getCompleteStyleDeclaration(r,A+1),v=cu(p,b,!1)),v&&(c?(e.save(),e.translate(y.renderLeft,y.renderTop),e.rotate(y.angle),this._renderChar(t,e,r,A,C,-S/2,0),e.restore()):(x=i,this._renderChar(t,e,r,A,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=ts({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 vs(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===li||i===Ih&&!r||i===Fh&&!r||i===eu&&!r?0:(i===J&&(o=s/2),i===Nt&&(o=s),i===Ih&&(o=s/2),i===Fh&&(o=s),n==="rtl"&&(i===Nt||i===li||i===Fh?o=0:i===dt||i===eu?o=-s:i!==J&&i!==Ih||(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=e==="linethrough"?.5:e==="overline"?1:0,h=this.offsets[e];for(let c=0,u=this._textLines.length;c<u;c++){const d=this.getHeightOfLine(c);if(!this[e]&&!this.styleHas(e,c)){s+=d;continue}const f=this._textLines[c],g=d/this.lineHeight,p=this._getLineLeftOffset(c);let b=0,y=0,v=this.getValueOfPropertyAt(c,0,e),x=this.getValueOfPropertyAt(c,0,Gt),C=this.getValueOfPropertyAt(c,0,xr),S=v,A=x,k=C;const P=s+g*(1-this._fontSizeFraction);let O=this.getHeightOfChar(c,0),R=this.getValueOfPropertyAt(c,0,"deltaY");for(let D=0,I=f.length;D<I;D++){const N=this.__charBounds[c][D];S=this.getValueOfPropertyAt(c,D,e),A=this.getValueOfPropertyAt(c,D,Gt),k=this.getValueOfPropertyAt(c,D,xr);const Y=this.getHeightOfChar(c,D),L=this.getValueOfPropertyAt(c,D,"deltaY");if(n&&S&&A){const B=this.fontSize*k/1e3;t.save(),t.fillStyle=x,t.translate(N.renderLeft,N.renderTop),t.rotate(N.angle),t.fillRect(-N.kernedWidth/2,h*Y+L-o*B,N.kernedWidth,B),t.restore()}else if((S!==v||A!==x||Y!==O||k!==C||L!==R)&&y>0){const B=this.fontSize*C/1e3;let Z=i+p+b;this.direction==="rtl"&&(Z=this.width-Z-y),v&&x&&C&&(t.fillStyle=x,t.fillRect(Z,P+h*O+R-o*B,y,B)),b=N.left,y=N.width,v=S,C=k,x=A,O=Y,R=L}else y+=N.kernedWidth}let F=i+p+b;this.direction==="rtl"&&(F=this.width-F-y),t.fillStyle=A;const j=this.fontSize*k/1e3;S&&A&&k&&t.fillRect(F,P+h*O+R-o*j,y-r,j),s+=d}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 lu(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 T(T({},super.toObject([...Om,...t])),{},{styles:r0(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=Bi(t,me.ATTRIBUTE_NAMES,s),n=T(T({},e),i),{textAnchor:r=dt,textDecoration:o="",dx:h=0,dy:c=0,top:u=0,left:d=0,fontSize:f=lf,strokeWidth:g=1}=n,p=Ct(n,Rw),b=new this((t.textContent||"").replace(/^\s+|\s+$|\n+/g,"").replace(/\s+/g," "),T({left:d+h,top:u+c,underline:o.includes("underline"),overline:o.includes("overline"),linethrough:o.includes("line-through"),strokeWidth:0,fontSize:f},p)),y=b.getScaledHeight()/b.height,v=((b.height+b.strokeWidth)*b.lineHeight-b.height)*y,x=b.getScaledHeight()+v;let C=0;return r===J&&(C=b.getScaledWidth()/2),r===Nt&&(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(T(T({},t),{},{styles:o0(t.styles||{},t.text)}),{extraParam:"text"})}}E(me,"textLayoutProperties",Pm),E(me,"cacheProperties",[...Ni,...Om]),E(me,"ownDefaults",Xy),E(me,"type","Text"),E(me,"genericFonts",["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","math","emoji","fangsong"]),E(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 Em{_toSVG(){const a=this._getSVGLeftTopOffsets(),t=this._getSVGTextAndBg(a.textTop,a.textLeft);return this._wrapSVGTextAndBg(t)}toSVG(a){const t=this._createBaseSVGMarkup(this._toSVG(),{reviver:a,noStyle:!0,withShadow:!0}),e=this.path;return e?t+e._createBaseSVGMarkup(e._toSVG(),{reviver:a,withShadow:!0,additionalTransform:Jo(this.calcOwnMatrix())}):t}_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" ','font-family="'.concat(this.fontFamily.replace(Dw,"'"),'" '),'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(...Qf(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,i){const n=ht.NUM_FRACTION_DIGITS,r=this.getSvgSpanStyles(t,a!==a.trim()||!!a.match(Ow)),o=r?'style="'.concat(r,'"'):"",h=t.deltaY,c=h?' dy="'.concat(yt(h,n),'" '):"",{angle:u,renderLeft:d,renderTop:f,width:g}=i;let p="";if(d!==void 0){const b=g/2;u&&(p=' rotate="'.concat(yt(ai(u),n),'"'));const y=vr({angle:ai(u)});y[4]=d,y[5]=f;const v=new M(-b,0).transform(y);e=v.x,s=v.y}return'<tspan x="'.concat(yt(e,n),'" y="').concat(yt(s,n),'" ').concat(c).concat(p).concat(o,">").concat(n0(a),"</tspan>")}_setSVGTextLineText(a,t,e,s){const i=this.getHeightOfLine(t),n=this.textAlign.includes(li),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||this.path,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=cu(o,h,!0)),d&&(u=this._getStyleDeclaration(t,p),a.push(this._createTextCharSpan(f,u,e,s,c)),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(...Qf(c,e+h,s,o,n)),h=d,o=f,c=r):o+=g}r&&a.push(...Qf(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)," text-decoration-thickness: ").concat(yt(this.textDecorationThickness*this.getObjectScaling().y/10,ht.NUM_FRACTION_DIGITS),"%; white-space: pre;")}getSvgSpanStyles(a,t){const{fontFamily:e,strokeWidth:s,stroke:i,fill:n,fontSize:r,fontStyle:o,fontWeight:h,deltaY:c,textDecorationThickness:u,linethrough:d,overline:f,underline:g}=a,p=this.getSvgTextDecoration({underline:g??this.underline,overline:f??this.overline,linethrough:d??this.linethrough}),b=u||this.textDecorationThickness;return[i?Lh(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,"; "):"",p?"text-decoration: ".concat(p,"; text-decoration-thickness: ").concat(yt(b*this.getObjectScaling().y/10,ht.NUM_FRACTION_DIGITS),"%; "):"",n?Lh(Gt,n):"",c?"baseline-shift: ".concat(-c,"; "):"",t?"white-space: pre; ":""].join("")}getSvgTextDecoration(a){return["overline","underline","line-through"].filter(t=>a[t.replace("-","")]).join(" ")}}]),z.setClass(me),z.setSVGClass(me);class Lw{constructor(t){E(this,"target",void 0),E(this,"__mouseDownInPlace",!1),E(this,"__dragStartFired",!1),E(this,"__isDraggingOver",!1),E(this,"__dragStartSelection",void 0),E(this,"__dragImageDisposer",void 0),E(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 M(r.flipX?-1:1,r.flipY?-1:1),c=r._getCursorBoundaries(i),u=new M(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 M(g.left,g.top)),b=o.viewportTransform,y=p.add(d).transform(b,!0),v=r.backgroundColor,x=Hf(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=v,r.styles=x,r.dirty=!0,mu(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,y.x,y.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=T({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(Vc,{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(Vc,{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 z0=/[ \n\.,;!\?\-]/;class Fw extends me{constructor(){super(...arguments),E(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 Nf({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}cmdAll(){this.selectAll(),this.renderCursorOrSelection()}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||!uf.test(s[t-1]))?t-1:t,n=s[i];for(;i>0&&i<s.length&&!z0.test(n);)i+=e,n=s[i];return e===-1&&z0.test(n)&&i++,i}selectWord(t){var e;t=(e=t)!==null&&e!==void 0?e:this.selectionStart;const s=this.searchWordBoundary(t,-1),i=Math.max(s,this.searchWordBoundary(t,1));this.selectionStart=s,this.selectionEnd=i,this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()}selectLine(t){var e;t=(e=t)!==null&&e!==void 0?e:this.selectionStart;const s=this.findLineBoundaryLeft(t),i=this.findLineBoundaryRight(t);this.selectionStart=s,this.selectionEnd=i,this._fireSelectionChanged(),this._updateTextarea()}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 M(e.left+o,e.top+e.topOffset+r).transform(this.calcTransformMatrix()).transform(this.canvas.viewportTransform).multiply(new M(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(Wc),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:T({},i[s-1])}:c?this.styles[t+s]={0:T({},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?T({},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]=T({},i[s]));return}if(!n)return;const o=n[e?e-1:1];for(;o&&s--;)this.styles[t][e+s]=T({},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===Nt&&(this._selectionDirection=dt,this.selectionEnd=t),this.selectionStart=s):s>t&&s<e?this._selectionDirection===Nt?this.selectionEnd=s:this.selectionStart=s:(e===t?this._selectionDirection=Nt:this._selectionDirection===dt&&(this._selectionDirection=Nt,this.selectionStart=e),this.selectionEnd=s)}}class Iw extends Fw{initHiddenTextarea(){const t=this.canvas&&Ls(this.canvas.getElement())||Uo(),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,{value:s,selectionStart:i,selectionEnd:n}=this.hiddenTextarea;if(this.fromPaste=!1,t&&t.stopPropagation(),!this.isEditing)return;const r=()=>{this.updateFromTextArea(),this.fire(Vc),this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll())};if(this.hiddenTextarea.value==="")return this.styles={},void r();const o=this._splitTextIntoLines(s).graphemeText,h=this._text.length,c=o.length,u=this.selectionStart,d=this.selectionEnd,f=u!==d;let g,p,b,y,v=c-h;const x=this.fromStringToGraphemeSelection(i,n,s),C=u>x.selectionStart;f?(p=this._text.slice(u,d),v+=d-u):c<h&&(p=C?this._text.slice(d+v,d):this._text.slice(u,u-v));const S=o.slice(x.selectionEnd-v,x.selectionEnd);if(p&&p.length&&(S.length&&(g=this.getSelectionStyles(u,u+1,!1),g=S.map(()=>g[0])),f?(b=u,y=d):C?(b=d-p.length,y=d):(b=d,y=d+p.length),this.removeStyleFromTo(b,y)),S.length){const{copyPasteData:A}=ri();e&&S.join("")===A.copiedText&&!ht.disableStyleCopyPaste&&(g=A.copiedTextStyle),this.insertNewStyleBlock(S,u,g)}r()}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}=ri();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===Nt);if(e.shiftKey?this.moveCursorWithShift(s):this.moveCursorWithoutShift(s),s!==0){const i=this.text.length;this.selectionStart=Sr(0,this.selectionStart,i),this.selectionEnd=Sr(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===Nt&&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=Nt,this._moveRight(t,"selectionEnd")):void 0}moveCursorRightWithoutShift(t){let e=!0;return this._selectionDirection=Nt,this.selectionStart===this.selectionEnd?(e=this._moveRight(t,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,e}}const G0=a=>!!a.button;class Nw extends Iw{constructor(){super(...arguments),E(this,"draggableTextDelegate",void 0)}initBehavior(){this.on("mousedown",this._mouseDownHandler),this.on("mouseup",this.mouseUpHandler),this.on("mousedblclick",this.doubleClickHandler),this.on("mousetripleclick",this.tripleClickHandler),this.draggableTextDelegate=new Lw(this),super.initBehavior()}shouldStartDragging(){return this.draggableTextDelegate.isActive()}onDragStart(t){return this.draggableTextDelegate.onDragStart(t)}canDrop(t){return this.draggableTextDelegate.canDrop(t)}doubleClickHandler(t){this.isEditing&&(this.selectWord(this.getSelectionStartFromPointer(t.e)),this.renderCursorOrSelection())}tripleClickHandler(t){this.isEditing&&(this.selectLine(this.getSelectionStartFromPointer(t.e)),this.renderCursorOrSelection())}_mouseDownHandler(t){let{e,alreadySelected:s}=t;this.canvas&&this.editable&&!G0(e)&&!this.getActiveControl()&&(this.draggableTextDelegate.start(e)||(this.canvas.textEditingManager.register(this),s&&(this.inCompositionMode=!1,this.setCursorByClick(e)),this.isEditing&&(this.__selectionStartOnMouseDown=this.selectionStart,this.selectionStart===this.selectionEnd&&this.abortCursorAnimation(),this.renderCursorOrSelection()),this.selected||(this.selected=s||this.isEditing)))}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||G0(e)||i||this.selected&&!this.getActiveControl()&&(this.enterEditing(e),this.selectionStart===this.selectionEnd?this.initDelayedCursor(!0):this.renderCursorOrSelection())}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 M(-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 _u="moveCursorUp",wu="moveCursorDown",xu="moveCursorLeft",Su="moveCursorRight",Cu="exitEditing",V0=(a,t)=>{const e=t.getRetinaScaling();a.setTransform(e,0,0,e,0,0);const s=t.viewportTransform;a.transform(s[0],s[1],s[2],s[3],s[4],s[5])},jw=T({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:Cu,27:Cu,33:_u,34:wu,35:Su,36:xu,37:xu,38:_u,39:Su,40:wu},keysMapRtl:{9:Cu,27:Cu,33:_u,34:wu,35:xu,36:Su,37:Su,38:_u,39:xu,40:wu},ctrlKeysMapDown:{65:"cmdAll"},ctrlKeysMapUp:{67:"copy",88:"cut"}},{_selectionDirection:null,_reSpace:/\s|\r?\n/,inCompositionMode:!1});class Vi extends Nw{static getDefaults(){return T(T({},super.getDefaults()),Vi.ownDefaults)}get type(){const t=super.type;return t==="itext"?"i-text":t}constructor(t,e){super(t,T(T({},Vi.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 $f&&this.canvas.textEditingManager.remove(this),e instanceof $f&&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||!this.canvas)return;const t=this.clearContextTop(!0);if(!t)return;const e=this._getCursorBoundaries(),s=this.findAncestorsWithClipPath(),i=s.length>0;let n,r=t;if(i){n=ts(t.canvas),r=n.getContext("2d"),V0(r,this.canvas);const o=this.calcTransformMatrix();r.transform(o[0],o[1],o[2],o[3],o[4],o[5])}if(this.selectionStart!==this.selectionEnd||this.inCompositionMode?this.renderSelection(r,e):this.renderCursor(r,e),i)for(const o of s){const h=o.clipPath,c=ts(t.canvas),u=c.getContext("2d");if(V0(u,this.canvas),!h.absolutePositioned){const d=o.calcTransformMatrix();u.transform(d[0],d[1],d[2],d[3],d[4],d[5])}h.transform(u),h.drawObject(u,!0,{}),this.drawClipPathOnCache(r,h,c)}i&&(t.setTransform(1,0,0,1,0,0),t.drawImage(n,0,0)),this.canvas.contextTopDirty=!0,t.restore()}findAncestorsWithClipPath(){const t=[];let e=this;for(;e;)e.clipPath&&t.push(e),e=e.parent;return t}_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===Nt||this.textAlign===li||this.textAlign===Fh?h.left*=-1:this.textAlign===dt||this.textAlign===eu?h.left=r-(s>0?s:0):this.textAlign!==J&&this.textAlign!==Ih||(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(li),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),y=0,v=0,x=0;if(g===c&&(v=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 P=this._getWidthOfCharSpacing();x=this.__charBounds[u][f-1].left+this.__charBounds[u][f-1].width-P}y=b,(this.lineHeight<1||g===u&&this.lineHeight>1)&&(b/=this.lineHeight);let C=s.left+p+v,S=b,A=0;const k=x-v;this.inCompositionMode?(t.fillStyle=this.compositionColor||"black",S=1,A=b):t.fillStyle=this.selectionColor,this.direction==="rtl"&&(this.textAlign===Nt||this.textAlign===li||this.textAlign===Fh?C=this.width-C-k:this.textAlign===dt||this.textAlign===eu?C=s.left+p-x:this.textAlign!==J&&this.textAlign!==Ih||(C=s.left+p-x)),t.fillRect(C,s.top+s.topOffset+A,k,S),s.topOffset+=y}}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,Gt)}_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()}}E(Vi,"ownDefaults",jw),E(Vi,"type","IText"),z.setClass(Vi),z.setClass(Vi,"i-text");class Er extends Vi{static getDefaults(){return T(T({},super.getDefaults()),Er.ownDefaults)}constructor(t,e){super(t,T(T({},Er.ownDefaults),e))}static createControls(){return{controls:S_()}}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(li)&&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 y=Math.max(e,i,this.dynamicMinWidth),v=n[t];let x;for(g=0,x=0;x<v.length;x++){const{word:C,width:S}=v[x];g+=C.length,d+=p+S-o,d>y&&!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])}}E(Er,"type","Textbox"),E(Er,"textLayoutProperties",[...Vi.textLayoutProperties,"width"]),E(Er,"ownDefaults",{minWidth:20,dynamicMinWidth:2,lockScalingFlip:!0,noScaleCache:!1,_wordJoiners:/[ \t\r]/,splitByGrapheme:!1}),z.setClass(Er);class X0 extends gu{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}=hi(m0(s,i)),h=new M(r,o);if(i.absolutePositioned)return{center:wr(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 M,correction:d=new M}=this.calcBoundingBox(e,t)||{};return{center:u.add(c),correction:d.subtract(c),size:h}}return{center:s.getRelativeCenterPoint().add(c),size:h}}}}E(X0,"type","clip-path"),z.setClass(X0);class W0 extends gu{getInitialSize(t,e){let{target:s}=t,{size:i}=e;return new M(s.width||i.x,s.height||i.y)}}E(W0,"type","fixed"),z.setClass(W0);class Bw extends Hh{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 kr extends ys{static getDefaults(){return T(T({},super.getDefaults()),kr.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,kr.ownDefaults),this.setOptions(e);const{left:s,top:i,layoutManager:n}=e;this.groupInit(t,{left:s,top:i,layoutManager:n??new Bw})}_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))?(Li("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===Vf?s.forEach(i=>{i._onAfterObjectsChange(du,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=T(T({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()}}E(kr,"type","ActiveSelection"),E(kr,"ownDefaults",{multiSelectionStacking:"canvas-stacking"}),z.setClass(kr),z.setClass(kr,"activeSelection");class Hw{constructor(){E(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 U0{constructor(){let{tileSize:t=ht.textureSize}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};E(this,"aPosition",new Float32Array([0,0,0,1,1,0,1,1])),E(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=ts({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,y=f.destinationWidth,v=f.destinationHeight;p===y&&b===v||(g.width=y,g.height=v)}(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 Zf;function zw(){const{WebGLProbe:a}=ri();return a.queryWebGL(oi()),ht.enableGLFiltering&&a.isSupported(ht.textureSize)?new U0({tileSize:ht.textureSize}):new Hw}function tg(){return!Zf&&(!(arguments.length>0&&arguments[0]!==void 0)||arguments[0])&&(Zf=zw()),Zf}const Gw=["filters","resizeFilter","src","crossOrigin","type"],Y0=["cropX","cropY"];class be extends pe{static getDefaults(){return T(T({},super.getDefaults()),be.ownDefaults)}constructor(t,e){super(),E(this,"_lastScaleX",1),E(this,"_lastScaleY",1),E(this,"_filterScalingX",1),E(this,"_filterScalingY",1),this.filters=[],Object.assign(this,be.ownDefaults),this.setOptions(e),this.cacheKey="texture".concat(kn()),this.setElement(typeof t=="string"?(this.canvas&&Ls(this.canvas.getElement())||Uo()).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=tg(!1);e instanceof U0&&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&&ri().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())}),T(T({},super.toObject([...Y0,...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=kn();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!==Gt?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 kh(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=ts(r),{width:h,height:c}=r;this._element=o,this._lastScaleX=t.scaleX=i,this._lastScaleY=t.scaleY=n,Qf().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=ts({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);Qf().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,y=Math.min(n,c/s-o),x=Math.min(r,u/i-h);e&&t.drawImage(e,d,f,g,p,b,v,y,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=Sf(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=l0(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=c0(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,Iw);return Promise.all([kh(n,A(A({},e),{},{crossOrigin:r})),s&&Ko(s,e),i&&Ko([i],e),Mh(h,e)]).then(c=>{let[u,d=[],[f]=[],g={}]=c;return new this(u,A(A({},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 kh(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=ji(t,this.ATTRIBUTE_NAMES,s);return this.fromURL(i["xlink:href"]||i.href,e,i).catch(n=>(Ri("log","Unable to parse Image",n),null))}}function Jf(a){if(!zy.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&&Em.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("+Oe(u||"0")+" "+Oe(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 y={width:0,height:0};if(f)return y.width=Oe(h),y.height=Oe(c),y;const x=t.match(Em);r=-parseFloat(x[1]),o=-parseFloat(x[2]);const S=parseFloat(x[3]),C=parseFloat(x[4]);y.minX=r,y.minY=o,y.viewBoxWidth=S,y.viewBoxHeight=C,g?(y.width=S,y.height=C):(y.width=Oe(h),y.height=Oe(c),i=y.width/S,n=y.height/C);const E=Sf(a.getAttribute("preserveAspectRatio")||"");if(E.alignX!==ke&&(E.meetOrSlice==="meet"&&(n=i=i>n?n:i),E.meetOrSlice==="slice"&&(n=i=i>n?i:n),b=y.width-S*i,v=y.height-C*i,E.alignX==="Mid"&&(b/=2),E.alignY==="Mid"&&(v/=2),E.alignX==="Min"&&(b=0),E.alignY==="Min"&&(v=0)),i===1&&n===1&&r===0&&o===0&&u===0&&d===0)return y;if((u||d)&&a.parentNode.nodeName!=="#document"&&(p=" translate("+Oe(u||"0")+" "+Oe(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),y}T(be,"type","Image"),T(be,"cacheProperties",[...Ii,...G0]),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","href","crossOrigin","image-rendering"]),z.setClass(be),z.setSVGClass(be);const Su=a=>a.tagName.replace("svg:",""),Nw=Jc(["pattern","defs","symbol","metadata","clipPath","mask","desc"]);function V0(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 jw=["gradientTransform","x1","x2","y1","y2","gradientUnits","cx","cy","r","fx","fy"],Zf="xlink:href";function X0(a,t){var e;const s=((e=t.getAttribute(Zf))===null||e===void 0?void 0:e.slice(1))||"",i=a.getElementById(s);if(i&&i.getAttribute(Zf)&&X0(a,i),i&&(jw.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(Zf)}const Bw=["linearGradient","radialGradient","svg:linearGradient","svg:radialGradient"];function Hw(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]=A(A({},i[u]||{}),h))})})}return i}const W0=a=>z.getSVGClass(Su(a).toLowerCase());class zw{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=V0(r,Bw),h={};let c=o.length;for(;c--;){const u=o[c];u.getAttribute("xlink:href")&&X0(r,u);const d=u.getAttribute("id");d&&(h[d]=u)}return h}(i),this.cssRules=Hw(i)}parse(){return Promise.all(this.elements.map(t=>this.createObject(t)))}async createObject(t){const e=W0(t);if(e){const s=await e.fromElement(t,this.options,this.cssRules);return this.resolveGradient(s,t,Gt),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=Nh.fromElement(i,t,A(A({},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=>W0(x).fromElement(x,this.options,this.cssRules).then(S=>(gu(S),S.fillRule=S.clipRule,delete S.clipRule,S)))),u=c.length===1?c[0]:new _s(c),d=jt(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:y}=br(d);u.set({flipX:!1,flipY:!1}),u.set({scaleX:f,scaleY:g,angle:p,skewX:b,skewY:0}),u.setPositionByOrigin(new k(v,y),J,J),t.clipPath=u}else delete t.clipPath}}const U0=a=>Hy.test(Su(a)),tg=()=>({objects:[],elements:[],options:{},allElements:[]});async function Gw(a,t){let{crossOrigin:e,signal:s}=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(s&&s.aborted)return Ri("log",new nf("parseSVGDocument")),tg();const i=a.documentElement;(function(u){const d=V0(u,["use","svg:use"]),f=["x","y","xlink:href","href","transform"];for(const g of d){const p=g.attributes,b={};for(const R of p)R.value&&(b[R.name]=R.value);const v=(b["xlink:href"]||b.href||"").slice(1);if(v==="")return;const y=u.getElementById(v);if(y===null)return;let x=y.cloneNode(!0);const S=x.attributes,C={};for(const R of S)R.value&&(C[R.name]=R.value);const{x:E=0,y:P=0,transform:M=""}=b,O="".concat(M," ").concat(C.transform||""," translate(").concat(E,", ").concat(P,")");if(Jf(x),/^svg$/i.test(x.nodeName)){const R=x.ownerDocument.createElementNS(Cf,"g");Object.entries(C).forEach(L=>{let[N,D]=L;return R.setAttributeNS(Cf,N,D)}),R.append(...x.childNodes),x=R}for(const R of p){if(!R)continue;const{name:L,value:N}=R;if(!f.includes(L))if(L==="style"){const D={};Bf(N,D),Object.entries(C).forEach(j=>{let[q,I]=j;D[q]=I}),Bf(C.style||"",D);const F=Object.entries(D).map(j=>j.join(":")).join(";");x.setAttribute(L,F)}else!C[L]&&x.setAttribute(L,N)}x.setAttribute("transform",O),x.setAttribute("instantiated_by_use","1"),x.removeAttribute("id"),g.parentNode.replaceChild(x,g)}})(a);const n=Array.from(i.getElementsByTagName("*")),r=A(A({},Jf(i)),{},{crossOrigin:e,signal:s}),o=n.filter(u=>(Jf(u),U0(u)&&!function(d){let f=d;for(;f&&(f=f.parentElement);)if(f&&f.nodeName&&Nw.test(Su(f))&&!f.getAttribute("instantiated_by_use"))return!0;return!1}(u)));if(!o||o&&!o.length)return A(A({},tg()),{},{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=>U0(f))}),{objects:await new zw(o,r,t,a,h).parse(),elements:o,options:r,allElements:n}}function Vw(a,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return new Promise((s,i)=>{x0(a.replace(/^\n\s*/,"").trim(),{onComplete:n=>{const r=n.responseXML;r&&s(r),i()},signal:e.signal})}).then(s=>Gw(s,t,e)).catch(()=>tg())}const Cu=a=>a.webgl!==void 0,eg="precision highp float",Xw=`
63
- `.concat(eg,`;
62
+ `)],this.fill=c}return n=this.paintFirst!==Gt?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 Ph(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=ts(r),{width:h,height:c}=r;this._element=o,this._lastScaleX=t.scaleX=i,this._lastScaleY=t.scaleY=n,tg().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=ts({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);tg().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,y=-r/2,v=Math.min(n,c/s-o),x=Math.min(r,u/i-h);e&&t.drawImage(e,d,f,g,p,b,y,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=Af(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=v0(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=y0(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,Gw);return Promise.all([Ph(n,T(T({},e),{},{crossOrigin:r})),s&&Qo(s,e),i&&Qo([i],e),Oh(h,e)]).then(c=>{let[u,d=[],[f]=[],g={}]=c;return new this(u,T(T({},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 Ph(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=Bi(t,this.ATTRIBUTE_NAMES,s);return this.fromURL(i["xlink:href"]||i.href,e,i).catch(n=>(Li("log","Unable to parse Image",n),null))}}function eg(a){if(!$y.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&&Im.test(t)),g=!h||!c||h==="100%"||c==="100%";let p="",b=0,y=0;if(f&&(u||d)&&a.parentNode&&a.parentNode.nodeName!=="#document"&&(p=" translate("+Oe(u||"0")+" "+Oe(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 v={width:0,height:0};if(f)return v.width=Oe(h),v.height=Oe(c),v;const x=t.match(Im);r=-parseFloat(x[1]),o=-parseFloat(x[2]);const C=parseFloat(x[3]),S=parseFloat(x[4]);v.minX=r,v.minY=o,v.viewBoxWidth=C,v.viewBoxHeight=S,g?(v.width=C,v.height=S):(v.width=Oe(h),v.height=Oe(c),i=v.width/C,n=v.height/S);const A=Af(a.getAttribute("preserveAspectRatio")||"");if(A.alignX!==ke&&(A.meetOrSlice==="meet"&&(n=i=i>n?n:i),A.meetOrSlice==="slice"&&(n=i=i>n?i:n),b=v.width-C*i,y=v.height-S*i,A.alignX==="Mid"&&(b/=2),A.alignY==="Mid"&&(y/=2),A.alignX==="Min"&&(b=0),A.alignY==="Min"&&(y=0)),i===1&&n===1&&r===0&&o===0&&u===0&&d===0)return v;if((u||d)&&a.parentNode.nodeName!=="#document"&&(p=" translate("+Oe(u||"0")+" "+Oe(d||"0")+") "),e=p+" matrix("+i+" 0 0 "+n+" "+(r*i+b)+" "+(o*n+y)+") ",a.nodeName==="svg"){for(s=a.ownerDocument.createElementNS(Ef,"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),v}E(be,"type","Image"),E(be,"cacheProperties",[...Ni,...Y0]),E(be,"ownDefaults",{strokeWidth:0,srcFromAttribute:!1,minimumScaleTrigger:.5,cropX:0,cropY:0,imageSmoothing:!0}),E(be,"CSS_CANVAS","canvas-img"),E(be,"ATTRIBUTE_NAMES",[...Mn,"x","y","width","height","preserveAspectRatio","xlink:href","href","crossOrigin","image-rendering"]),z.setClass(be),z.setSVGClass(be);const Au=a=>a.tagName.replace("svg:",""),Vw=tu(["pattern","defs","symbol","metadata","clipPath","mask","desc"]);function $0(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 Xw=["gradientTransform","x1","x2","y1","y2","gradientUnits","cx","cy","r","fx","fy"],sg="xlink:href";function q0(a,t){var e;const s=((e=t.getAttribute(sg))===null||e===void 0?void 0:e.slice(1))||"",i=a.getElementById(s);if(i&&i.getAttribute(sg)&&q0(a,i),i&&(Xw.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(sg)}const Ww=["linearGradient","radialGradient","svg:linearGradient","svg:radialGradient"];function Uw(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]=T(T({},i[u]||{}),h))})})}return i}const K0=a=>z.getSVGClass(Au(a).toLowerCase());class Yw{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=$0(r,Ww),h={};let c=o.length;for(;c--;){const u=o[c];u.getAttribute("xlink:href")&&q0(r,u);const d=u.getAttribute("id");d&&(h[d]=u)}return h}(i),this.cssRules=Uw(i)}parse(){return Promise.all(this.elements.map(t=>this.createObject(t)))}async createObject(t){const e=K0(t);if(e){const s=await e.fromElement(t,this.options,this.cssRules);return this.resolveGradient(s,t,Gt),this.resolveGradient(s,t,Pe),s instanceof be&&s._originalElement?bu(s,s.parsePreserveAspectRatioAttribute()):bu(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=Gh.fromElement(i,t,T(T({},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=uu("".concat(o.getAttribute("transform")||""," ").concat(r.getAttribute("originalTransform")||""));r.setAttribute("transform","matrix(".concat(h.join(","),")"));const c=await Promise.all(i.map(x=>K0(x).fromElement(x,this.options,this.cssRules).then(C=>(bu(C),C.fillRule=C.clipRule,delete C.clipRule,C)))),u=c.length===1?c[0]:new ys(c),d=jt(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:y,translateY:v}=br(d);u.set({flipX:!1,flipY:!1}),u.set({scaleX:f,scaleY:g,angle:p,skewX:b,skewY:0}),u.setPositionByOrigin(new M(y,v),J,J),t.clipPath=u}else delete t.clipPath}}const Q0=a=>Yy.test(Au(a)),ig=()=>({objects:[],elements:[],options:{},allElements:[]});async function $w(a,t){let{crossOrigin:e,signal:s}=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(s&&s.aborted)return Li("log",new of("parseSVGDocument")),ig();const i=a.documentElement;(function(u){const d=$0(u,["use","svg:use"]),f=["x","y","xlink:href","href","transform"];for(const g of d){const p=g.attributes,b={};for(const R of p)R.value&&(b[R.name]=R.value);const y=(b["xlink:href"]||b.href||"").slice(1);if(y==="")return;const v=u.getElementById(y);if(v===null)return;let x=v.cloneNode(!0);const C=x.attributes,S={};for(const R of C)R.value&&(S[R.name]=R.value);const{x:A=0,y:k=0,transform:P=""}=b,O="".concat(P," ").concat(S.transform||""," translate(").concat(A,", ").concat(k,")");if(eg(x),/^svg$/i.test(x.nodeName)){const R=x.ownerDocument.createElementNS(Ef,"g");Object.entries(S).forEach(F=>{let[j,D]=F;return R.setAttributeNS(Ef,j,D)}),R.append(...x.childNodes),x=R}for(const R of p){if(!R)continue;const{name:F,value:j}=R;if(!f.includes(F))if(F==="style"){const D={};Gf(j,D),Object.entries(S).forEach(N=>{let[Y,L]=N;D[Y]=L}),Gf(S.style||"",D);const I=Object.entries(D).map(N=>N.join(":")).join(";");x.setAttribute(F,I)}else!S[F]&&x.setAttribute(F,j)}x.setAttribute("transform",O),x.setAttribute("instantiated_by_use","1"),x.removeAttribute("id"),g.parentNode.replaceChild(x,g)}})(a);const n=Array.from(i.getElementsByTagName("*")),r=T(T({},eg(i)),{},{crossOrigin:e,signal:s}),o=n.filter(u=>(eg(u),Q0(u)&&!function(d){let f=d;for(;f&&(f=f.parentElement);)if(f&&f.nodeName&&Vw.test(Au(f))&&!f.getAttribute("instantiated_by_use"))return!0;return!1}(u)));if(!o||o&&!o.length)return T(T({},ig()),{},{options:r,allElements:n});const h={};return n.filter(u=>Au(u)==="clipPath").forEach(u=>{u.setAttribute("originalTransform",u.getAttribute("transform")||"");const d=u.getAttribute("id");h[d]=Array.from(u.getElementsByTagName("*")).filter(f=>Q0(f))}),{objects:await new Yw(o,r,t,a,h).parse(),elements:o,options:r,allElements:n}}function qw(a,t){let e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return new Promise((s,i)=>{O0(a.replace(/^\n\s*/,"").trim(),{onComplete:n=>{const r=n.responseXML;r&&s(r),i()},signal:e.signal})}).then(s=>$w(s,t,e)).catch(()=>ig())}const Tu=a=>a.webgl!==void 0,ng="precision highp float",Kw=`
63
+ `.concat(ng,`;
64
64
  varying vec2 vTexCoord;
65
65
  uniform sampler2D uTexture;
66
66
  void main() {
67
67
  gl_FragColor = texture2D(uTexture, vTexCoord);
68
- }`),Ww=["type"],Uw=["type"],Yw=new RegExp(eg,"g");class $t{get type(){return this.constructor.type}constructor(){let t=Ct(arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},Ww);Object.assign(this,this.constructor.defaults,t)}getFragmentSource(){return Xw}getVertexSource(){return`
68
+ }`),Qw=["type"],Jw=["type"],Zw=new RegExp(ng,"g");class $t{get type(){return this.constructor.type}constructor(){let t=Ct(arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},Qw);Object.assign(this,this.constructor.defaults,t)}getFragmentSource(){return Kw}getVertexSource(){return`
69
69
  attribute vec2 aPosition;
70
70
  varying vec2 vTexCoord;
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"}}=ri();i!=="highp"&&(e=e.replace(Yw,eg.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 ni("Vertex, fragment shader or program creation error");if(t.shaderSource(n,s),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS))throw new ni("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 ni("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 ni('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=ts({width:e,height:s});t.helpLayer=i}}toObject(){const t=Object.keys(this.constructor.defaults||{});return A({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,Uw))}}T($t,"type","BaseFilter"),T($t,"uniformLocations",[]);const $w={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"}}=ri();i!=="highp"&&(e=e.replace(Zw,ng.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 ni("Vertex, fragment shader or program creation error");if(t.shaderSource(n,s),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS))throw new ni("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 ni("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 ni('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){Tu(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=ts({width:e,height:s});t.helpLayer=i}}toObject(){const t=Object.keys(this.constructor.defaults||{});return T({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,Jw))}}E($t,"type","BaseFilter"),E($t,"uniformLocations",[]);const tx={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);
@@ -98,7 +98,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
98
98
  `,tint:`
99
99
  gl_FragColor.rgb *= (1.0 - uColor.a);
100
100
  gl_FragColor.rgb += uColor.rgb;
101
- `};class Au extends $t{getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return`
101
+ `};class Eu extends $t{getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return`
102
102
  precision highp float;
103
103
  uniform sampler2D uTexture;
104
104
  uniform vec4 uColor;
@@ -107,10 +107,10 @@ Resulting to default behavior: removing object from previous canvas and adding t
107
107
  vec4 color = texture2D(uTexture, vTexCoord);
108
108
  gl_FragColor = color;
109
109
  if (color.a > 0.0) {
110
- `.concat($w[this.mode],`
110
+ `.concat(tx[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)}}T(Au,"defaults",{color:"#F95C63",mode:"multiply",alpha:1}),T(Au,"type","BlendColor"),T(Au,"uniformLocations",["uColor"]),z.setClass(Au);const qw={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)}}E(Eu,"defaults",{color:"#F95C63",mode:"multiply",alpha:1}),E(Eu,"type","BlendColor"),E(Eu,"uniformLocations",["uColor"]),z.setClass(Eu);const ex={multiply:`
114
114
  precision highp float;
115
115
  uniform sampler2D uTexture;
116
116
  uniform sampler2D uImage;
@@ -136,7 +136,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
136
136
  color.a = color2.a;
137
137
  gl_FragColor = color;
138
138
  }
139
- `},Kw=["type","image"];class Tu extends $t{getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return qw[this.mode]}getVertexSource(){return`
139
+ `},sx=["type","image"];class ku extends $t{getCacheKey(){return"".concat(this.type,"_").concat(this.mode)}getFragmentSource(){return ex[this.mode]}getVertexSource(){return`
140
140
  attribute vec2 aPosition;
141
141
  varying vec2 vTexCoord;
142
142
  varying vec2 vTexCoord2;
@@ -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=vs());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],y=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*y/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 A(A({},super.toObject()),{},{image:this.image&&this.image.toObject()})}static async fromObject(t,e){let{type:s,image:i}=t,n=Ct(t,Kw);return be.fromObject(i,e).then(r=>new this(A(A({},n),{},{image:r})))}}T(Tu,"type","BlendImage"),T(Tu,"defaults",{mode:"multiply",alpha:1}),T(Tu,"uniformLocations",["uTransformMatrix","uImage"]),z.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=oi());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],y=c[u+1],v=c[u+2],x=c[u+3];switch(this.mode){case"multiply":e[u]=d*b/255,e[u+1]=f*y/255,e[u+2]=g*v/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 T(T({},super.toObject()),{},{image:this.image&&this.image.toObject()})}static async fromObject(t,e){let{type:s,image:i}=t,n=Ct(t,sx);return be.fromObject(i,e).then(r=>new this(T(T({},n),{},{image:r})))}}E(ku,"type","BlendImage"),E(ku,"defaults",{mode:"multiply",alpha:1}),E(ku,"uniformLocations",["uTransformMatrix","uImage"]),z.setClass(ku);class Mu extends $t{getFragmentSource(){return`
150
150
  precision highp float;
151
151
  uniform sampler2D uTexture;
152
152
  uniform vec2 uDelta;
@@ -159,17 +159,23 @@ Resulting to default behavior: removing object from previous canvas and adding t
159
159
  }
160
160
  void main() {
161
161
  vec4 color = vec4(0.0);
162
- float total = 0.0;
162
+ float totalC = 0.0;
163
+ float totalA = 0.0;
163
164
  float offset = random(v3offset);
164
165
  for (float t = -nSamples; t <= nSamples; t++) {
165
166
  float percent = (t + offset - 0.5) / nSamples;
167
+ vec4 sample = texture2D(uTexture, vTexCoord + uDelta * percent);
166
168
  float weight = 1.0 - abs(percent);
167
- color += texture2D(uTexture, vTexCoord + uDelta * percent) * weight;
168
- total += weight;
169
+ float alpha = weight * sample.a;
170
+ color.rgb += sample.rgb * alpha;
171
+ color.a += alpha;
172
+ totalA += weight;
173
+ totalC += alpha;
169
174
  }
170
- gl_FragColor = color / total;
175
+ gl_FragColor.rgb = color.rgb / totalC;
176
+ gl_FragColor.a = color.a / totalA;
171
177
  }
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=vs(),i.blurLayer2=vs());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 y=e.getImageData(0,0,o.width,o.height);return c.globalAlpha=1,c.clearRect(0,0,o.width,o.height),y}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"]),z.setClass(Eu);class ku extends $t{getFragmentSource(){return`
178
+ `}applyTo(t){Tu(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){let{imageData:{data:e,width:s,height:i}}=t;this.aspectRatio=s/i,this.horizontal=!0;let n=this.getBlurValue()*s;const r=new Uint8ClampedArray(e),o=15,h=4*s;for(let c=0;c<e.length;c+=4){let u=0,d=0,f=0,g=0,p=0;const b=c-c%h,y=b+h;for(let v=-14;v<o;v++){const x=v/o,C=4*Math.floor(n*x),S=1-Math.abs(x);let A=c+C;A<b?A=b:A>y&&(A=y);const k=e[A+3]*S;u+=e[A]*k,d+=e[A+1]*k,f+=e[A+2]*k,g+=k,p+=S}r[c]=u/g,r[c+1]=d/g,r[c+2]=f/g,r[c+3]=g/p}this.horizontal=!1,n=this.getBlurValue()*i;for(let c=0;c<r.length;c+=4){let u=0,d=0,f=0,g=0,p=0;const b=c%h,y=r.length-h+b;for(let v=-14;v<o;v++){const x=v/o,C=Math.floor(n*x)*h,S=1-Math.abs(x);let A=c+C;A<b?A=b:A>y&&(A=y);const k=r[A+3]*S;u+=r[A]*k,d+=r[A+1]*k,f+=r[A+2]*k,g+=k,p+=S}e[c]=u/g,e[c+1]=d/g,e[c+2]=f/g,e[c+3]=g/p}}sendUniformData(t,e){const s=this.chooseRightDelta();t.uniform2fv(e.uDelta,s)}isNeutralState(){return this.blur===0}getBlurValue(){let t=1;const{horizontal:e,aspectRatio:s}=this;return e?s>1&&(t=1/s):s<1&&(t=s),t*this.blur*.12}chooseRightDelta(){const t=this.getBlurValue();return this.horizontal?[t,0]:[0,t]}}E(Mu,"type","Blur"),E(Mu,"defaults",{blur:0}),E(Mu,"uniformLocations",["uDelta"]),z.setClass(Mu);class Pu extends $t{getFragmentSource(){return`
173
179
  precision highp float;
174
180
  uniform sampler2D uTexture;
175
181
  uniform float uBrightness;
@@ -179,7 +185,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
179
185
  color.rgb += uBrightness;
180
186
  gl_FragColor = color;
181
187
  }
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"]),z.setClass(ku);const Y0={matrix:[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],colorsOnly:!0};class oa extends $t{getFragmentSource(){return`
188
+ `}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)}}E(Pu,"type","Brightness"),E(Pu,"defaults",{brightness:0}),E(Pu,"uniformLocations",["uBrightness"]),z.setClass(Pu);const J0={matrix:[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],colorsOnly:!0};class aa extends $t{getFragmentSource(){return`
183
189
  precision highp float;
184
190
  uniform sampler2D uTexture;
185
191
  varying vec2 vTexCoord;
@@ -190,7 +196,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
190
196
  color *= uColorMatrix;
191
197
  color += uConstants;
192
198
  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 A(A({},super.toObject()),{},{matrix:[...this.matrix]})}}function kr(a,t){var e;const s=(T(e=class extends oa{toObject(){return{type:this.type,colorsOnly:this.colorsOnly}}},"type",a),T(e,"defaults",{colorsOnly:!1,matrix:t}),e);return z.setClass(s,a),s}T(oa,"type","ColorMatrix"),T(oa,"defaults",Y0),T(oa,"uniformLocations",["uColorMatrix","uConstants"]),z.setClass(oa),kr("Brownie",[.5997,.34553,-.27082,0,.186,-.0377,.86095,.15059,0,-.1449,.24113,-.07441,.44972,0,-.02965,0,0,0,1,0]),kr("Vintage",[.62793,.32021,-.03965,0,.03784,.02578,.64411,.03259,0,.02926,.0466,-.08512,.52416,0,.02023,0,0,0,1,0]),kr("Kodachrome",[1.12855,-.39673,-.03992,0,.24991,-.16404,1.08352,-.05498,0,.09698,-.16786,-.56034,1.60148,0,.13972,0,0,0,1,0]),kr("Technicolor",[1.91252,-.85453,-.09155,0,.04624,-.30878,1.76589,-.10601,0,-.27589,-.2311,-.75018,1.84759,0,.12137,0,0,0,1,0]),kr("Polaroid",[1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0]),kr("Sepia",[.393,.769,.189,0,0,.349,.686,.168,0,0,.272,.534,.131,0,0,0,0,0,1,0]),kr("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 $0 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=>z.getClass(s.type).fromObject(s,e))).then(s=>new this({subFilters:s}))}}T($0,"type","Composed"),z.setClass($0);class Mu extends $t{getFragmentSource(){return`
199
+ }`}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 T(T({},super.toObject()),{},{matrix:[...this.matrix]})}}function Mr(a,t){var e;const s=(E(e=class extends aa{toObject(){return{type:this.type,colorsOnly:this.colorsOnly}}},"type",a),E(e,"defaults",{colorsOnly:!1,matrix:t}),e);return z.setClass(s,a),s}E(aa,"type","ColorMatrix"),E(aa,"defaults",J0),E(aa,"uniformLocations",["uColorMatrix","uConstants"]),z.setClass(aa),Mr("Brownie",[.5997,.34553,-.27082,0,.186,-.0377,.86095,.15059,0,-.1449,.24113,-.07441,.44972,0,-.02965,0,0,0,1,0]),Mr("Vintage",[.62793,.32021,-.03965,0,.03784,.02578,.64411,.03259,0,.02926,.0466,-.08512,.52416,0,.02023,0,0,0,1,0]),Mr("Kodachrome",[1.12855,-.39673,-.03992,0,.24991,-.16404,1.08352,-.05498,0,.09698,-.16786,-.56034,1.60148,0,.13972,0,0,0,1,0]),Mr("Technicolor",[1.91252,-.85453,-.09155,0,.04624,-.30878,1.76589,-.10601,0,-.27589,-.2311,-.75018,1.84759,0,.12137,0,0,0,1,0]),Mr("Polaroid",[1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0]),Mr("Sepia",[.393,.769,.189,0,0,.349,.686,.168,0,0,.272,.534,.131,0,0,0,0,0,1,0]),Mr("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 Z0 extends $t{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};super(t),this.subFilters=t.subFilters||[]}applyTo(t){Tu(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=>z.getClass(s.type).fromObject(s,e))).then(s=>new this({subFilters:s}))}}E(Z0,"type","Composed"),z.setClass(Z0);class Ou extends $t{getFragmentSource(){return`
194
200
  precision highp float;
195
201
  uniform sampler2D uTexture;
196
202
  uniform float uContrast;
@@ -200,7 +206,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
200
206
  float contrastF = 1.015 * (uContrast + 1.0) / (1.0 * (1.015 - uContrast));
201
207
  color.rgb = contrastF * (color.rgb - 0.5) + 0.5;
202
208
  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)}}T(Mu,"type","Contrast"),T(Mu,"defaults",{contrast:0}),T(Mu,"uniformLocations",["uContrast"]),z.setClass(Mu);const Qw={Convolute_3_1:`
209
+ }`}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)}}E(Ou,"type","Contrast"),E(Ou,"defaults",{contrast:0}),E(Ou,"uniformLocations",["uContrast"]),z.setClass(Ou);const ix={Convolute_3_1:`
204
210
  precision highp float;
205
211
  uniform sampler2D uTexture;
206
212
  uniform float uMatrix[9];
@@ -344,7 +350,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
344
350
  gl_FragColor = color;
345
351
  gl_FragColor.a = alpha;
346
352
  }
347
- `};class Pu extends $t{getCacheKey(){return"".concat(this.type,"_").concat(Math.sqrt(this.matrix.length),"_").concat(this.opaque?1:0)}getFragmentSource(){return Qw[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,y,x,S,C,E,P,M,O;for(P=0;P<h;P++)for(E=0;E<o;E++){for(v=4*(P*o+E),f=0,g=0,p=0,b=0,O=0;O<n;O++)for(M=0;M<n;M++)x=P+O-r,y=E+M-r,x<0||x>=h||y<0||y>=o||(S=4*(x*o+y),C=i[O*n+M],f+=s[S]*C,g+=s[S+1]*C,p+=s[S+2]*C,d||(b+=s[S+3]*C));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 A(A({},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"]),z.setClass(Pu);const q0="Gamma";class Ou extends $t{getFragmentSource(){return`
353
+ `};class Du extends $t{getCacheKey(){return"".concat(this.type,"_").concat(Math.sqrt(this.matrix.length),"_").concat(this.opaque?1:0)}getFragmentSource(){return ix[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,y,v,x,C,S,A,k,P,O;for(k=0;k<h;k++)for(A=0;A<o;A++){for(y=4*(k*o+A),f=0,g=0,p=0,b=0,O=0;O<n;O++)for(P=0;P<n;P++)x=k+O-r,v=A+P-r,x<0||x>=h||v<0||v>=o||(C=4*(x*o+v),S=i[O*n+P],f+=s[C]*S,g+=s[C+1]*S,p+=s[C+2]*S,d||(b+=s[C+3]*S));u[y]=f,u[y+1]=g,u[y+2]=p,u[y+3]=d?s[y+3]:b}t.imageData=c}sendUniformData(t,e){t.uniform1fv(e.uMatrix,this.matrix)}toObject(){return T(T({},super.toObject()),{},{opaque:this.opaque,matrix:[...this.matrix]})}}E(Du,"type","Convolute"),E(Du,"defaults",{opaque:!1,matrix:[0,0,0,0,1,0,0,0,0]}),E(Du,"uniformLocations",["uMatrix","uOpaque","uHalfSize","uSize"]),z.setClass(Du);const tb="Gamma";class Ru extends $t{getFragmentSource(){return`
348
354
  precision highp float;
349
355
  uniform sampler2D uTexture;
350
356
  uniform vec3 uGamma;
@@ -358,7 +364,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
358
364
  gl_FragColor = color;
359
365
  gl_FragColor.rgb *= color.a;
360
366
  }
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:q0,gamma:this.gamma.concat()}}}T(Ou,"type",q0),T(Ou,"defaults",{gamma:[1,1,1]}),T(Ou,"uniformLocations",["uGamma"]),z.setClass(Ou);const Jw={average:`
367
+ `}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:tb,gamma:this.gamma.concat()}}}E(Ru,"type",tb),E(Ru,"defaults",{gamma:[1,1,1]}),E(Ru,"uniformLocations",["uGamma"]),z.setClass(Ru);const nx={average:`
362
368
  precision highp float;
363
369
  uniform sampler2D uTexture;
364
370
  varying vec2 vTexCoord;
@@ -387,7 +393,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
387
393
  float average = 0.21 * col.r + 0.72 * col.g + 0.07 * col.b;
388
394
  gl_FragColor = vec4(average, average, average, col.a);
389
395
  }
390
- `};class Du 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 Jw[this.mode]}sendUniformData(t,e){t.uniform1i(e.uMode,1)}isNeutralState(){return!1}}T(Du,"type","Grayscale"),T(Du,"defaults",{mode:"average"}),T(Du,"uniformLocations",["uMode"]),z.setClass(Du);const Zw=A(A({},Y0),{},{rotation:0});class sg extends oa{calculateMatrix(){const t=this.rotation*Math.PI,e=Rs(t),s=Ls(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(sg,"type","HueRotation"),T(sg,"defaults",Zw),z.setClass(sg);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`
396
+ `};class Lu 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 nx[this.mode]}sendUniformData(t,e){t.uniform1i(e.uMode,1)}isNeutralState(){return!1}}E(Lu,"type","Grayscale"),E(Lu,"defaults",{mode:"average"}),E(Lu,"uniformLocations",["uMode"]),z.setClass(Lu);const rx=T(T({},J0),{},{rotation:0});class rg extends aa{calculateMatrix(){const t=this.rotation*Math.PI,e=Ds(t),s=Rs(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}}}E(rg,"type","HueRotation"),E(rg,"defaults",rx),z.setClass(rg);class Fu 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
397
  precision highp float;
392
398
  uniform sampler2D uTexture;
393
399
  uniform int uInvert;
@@ -405,7 +411,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
405
411
  gl_FragColor = color;
406
412
  }
407
413
  }
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"]),z.setClass(Ru);class Lu extends $t{getFragmentSource(){return`
414
+ `}isNeutralState(){return!this.invert}sendUniformData(t,e){t.uniform1i(e.uInvert,Number(this.invert)),t.uniform1i(e.uAlpha,Number(this.alpha))}}E(Fu,"type","Invert"),E(Fu,"defaults",{alpha:!1,invert:!0}),E(Fu,"uniformLocations",["uInvert","uAlpha"]),z.setClass(Fu);class Iu extends $t{getFragmentSource(){return`
409
415
  precision highp float;
410
416
  uniform sampler2D uTexture;
411
417
  uniform float uStepH;
@@ -420,7 +426,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
420
426
  color.rgb += (0.5 - rand(vTexCoord, uSeed, 0.1 / uStepH)) * uNoise;
421
427
  gl_FragColor = color;
422
428
  }
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"]),z.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`
429
+ `}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}}E(Iu,"type","Noise"),E(Iu,"defaults",{noise:0}),E(Iu,"uniformLocations",["uNoise","uSeed"]),z.setClass(Iu);class Nu 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
430
  precision highp float;
425
431
  uniform sampler2D uTexture;
426
432
  uniform float uBlocksize;
@@ -438,7 +444,7 @@ Resulting to default behavior: removing object from previous canvas and adding t
438
444
  vec4 color = texture2D(uTexture, squareCoords);
439
445
  gl_FragColor = color;
440
446
  }
441
- `}sendUniformData(t,e){t.uniform1f(e.uBlocksize,this.blocksize)}}T(Fu,"type","Pixelate"),T(Fu,"defaults",{blocksize:4}),T(Fu,"uniformLocations",["uBlocksize"]),z.setClass(Fu);class Iu extends $t{getFragmentSource(){return`
447
+ `}sendUniformData(t,e){t.uniform1f(e.uBlocksize,this.blocksize)}}E(Nu,"type","Pixelate"),E(Nu,"defaults",{blocksize:4}),E(Nu,"uniformLocations",["uBlocksize"]),z.setClass(Nu);class ju extends $t{getFragmentSource(){return`
442
448
  precision highp float;
443
449
  uniform sampler2D uTexture;
444
450
  uniform vec4 uLow;
@@ -450,7 +456,7 @@ void main() {
450
456
  gl_FragColor.a = 0.0;
451
457
  }
452
458
  }
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"]),z.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`
459
+ `}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)}}E(ju,"type","RemoveColor"),E(ju,"defaults",{color:"#FFFFFF",distance:.02,useAlpha:!1}),E(ju,"uniformLocations",["uLow","uHigh"]),z.setClass(ju);class Bu 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
460
  precision highp float;
455
461
  uniform sampler2D uTexture;
456
462
  uniform vec2 uDelta;
@@ -466,7 +472,7 @@ void main() {
466
472
  `),`
467
473
  gl_FragColor = color / sum;
468
474
  }
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=vs());const y=f.sliceByTwo;(y.width<1.5*e||y.height<s)&&(y.width=1.5*e,y.height=s);const x=y.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(y,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={},y={x:0,y:0},x={x:0,y:0};return function S(C){let E,P,M,O,R,L,N,D,F,j,q;for(y.x=(C+.5)*u,x.x=Math.floor(y.x),E=0;E<n;E++){for(y.y=(E+.5)*d,x.y=Math.floor(y.y),R=0,L=0,N=0,D=0,F=0,P=x.x-p;P<=x.x+p;P++)if(!(P<0||P>=e)){j=Math.floor(1e3*Math.abs(P-y.x)),v[j]||(v[j]={});for(let I=x.y-b;I<=x.y+b;I++)I<0||I>=s||(q=Math.floor(1e3*Math.abs(I-y.y)),v[j][q]||(v[j][q]=c(Math.sqrt(Math.pow(j*f,2)+Math.pow(q*g,2))/1e3)),M=v[j][q],M>0&&(O=4*(I*e+P),R+=M,L+=M*r[O],N+=M*r[O+1],D+=M*r[O+2],F+=M*r[O+3]))}O=4*(E*i+C),h[O]=L/R,h[O+1]=N/R,h[O+2]=D/R,h[O+3]=F/R}return++C<i?S(C):o}(0)}bilinearFiltering(t,e,s,i,n){let r,o,h,c,u,d,f,g,p,b,v,y,x,S=0;const C=this.rcpScaleX,E=this.rcpScaleY,P=4*(e-1),M=t.imageData.data,O=t.ctx.createImageData(i,n),R=O.data;for(f=0;f<n;f++)for(g=0;g<i;g++)for(u=Math.floor(C*g),d=Math.floor(E*f),p=C*g-u,b=E*f-d,x=4*(d*e+u),v=0;v<4;v++)r=M[x+v],o=M[x+4+v],h=M[x+P+v],c=M[x+P+4+v],y=r*(1-p)*(1-b)+o*p*(1-b)+h*b*(1-p)+c*p*b,R[S++]=y;return O}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,y=0,x=0,S=0,C=0,E=0,P=0;const M=(g+.5)*o;for(let O=Math.floor(g*o);O<(g+1)*o;O++){const R=Math.abs(M-(O+.5))/c,L=(p+.5)*r,N=R*R;for(let D=Math.floor(p*r);D<(p+1)*r;D++){let F=Math.abs(L-(D+.5))/h;const j=Math.sqrt(N+F*F);j>1&&j<-1||(v=2*j*j*j-3*j*j+1,v>0&&(F=4*(D+O*e),P+=v*u[F+3],x+=v,u[F+3]<255&&(v=v*u[F+3]/250),S+=v*u[F],C+=v*u[F+1],E+=v*u[F+2],y+=v))}}f[b]=S/y,f[b+1]=C/y,f[b+2]=E/y,f[b+3]=P/x}return d}}T(Nu,"type","Resize"),T(Nu,"defaults",{resizeType:"hermite",scaleX:1,scaleY:1,lanczosLobes:3}),T(Nu,"uniformLocations",["uDelta","uTaps"]),z.setClass(Nu);class ju extends $t{getFragmentSource(){return`
475
+ `)}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){Tu(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 y=0;f.sliceByTwo||(f.sliceByTwo=oi());const v=f.sliceByTwo;(v.width<1.5*e||v.height<s)&&(v.width=1.5*e,v.height=s);const x=v.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(v,g,p,e,s,b,y,u,d),g=b,p=y,y+=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),y={},v={x:0,y:0},x={x:0,y:0};return function C(S){let A,k,P,O,R,F,j,D,I,N,Y;for(v.x=(S+.5)*u,x.x=Math.floor(v.x),A=0;A<n;A++){for(v.y=(A+.5)*d,x.y=Math.floor(v.y),R=0,F=0,j=0,D=0,I=0,k=x.x-p;k<=x.x+p;k++)if(!(k<0||k>=e)){N=Math.floor(1e3*Math.abs(k-v.x)),y[N]||(y[N]={});for(let L=x.y-b;L<=x.y+b;L++)L<0||L>=s||(Y=Math.floor(1e3*Math.abs(L-v.y)),y[N][Y]||(y[N][Y]=c(Math.sqrt(Math.pow(N*f,2)+Math.pow(Y*g,2))/1e3)),P=y[N][Y],P>0&&(O=4*(L*e+k),R+=P,F+=P*r[O],j+=P*r[O+1],D+=P*r[O+2],I+=P*r[O+3]))}O=4*(A*i+S),h[O]=F/R,h[O+1]=j/R,h[O+2]=D/R,h[O+3]=I/R}return++S<i?C(S):o}(0)}bilinearFiltering(t,e,s,i,n){let r,o,h,c,u,d,f,g,p,b,y,v,x,C=0;const S=this.rcpScaleX,A=this.rcpScaleY,k=4*(e-1),P=t.imageData.data,O=t.ctx.createImageData(i,n),R=O.data;for(f=0;f<n;f++)for(g=0;g<i;g++)for(u=Math.floor(S*g),d=Math.floor(A*f),p=S*g-u,b=A*f-d,x=4*(d*e+u),y=0;y<4;y++)r=P[x+y],o=P[x+4+y],h=P[x+k+y],c=P[x+k+4+y],v=r*(1-p)*(1-b)+o*p*(1-b)+h*b*(1-p)+c*p*b,R[C++]=v;return O}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 y=0,v=0,x=0,C=0,S=0,A=0,k=0;const P=(g+.5)*o;for(let O=Math.floor(g*o);O<(g+1)*o;O++){const R=Math.abs(P-(O+.5))/c,F=(p+.5)*r,j=R*R;for(let D=Math.floor(p*r);D<(p+1)*r;D++){let I=Math.abs(F-(D+.5))/h;const N=Math.sqrt(j+I*I);N>1&&N<-1||(y=2*N*N*N-3*N*N+1,y>0&&(I=4*(D+O*e),k+=y*u[I+3],x+=y,u[I+3]<255&&(y=y*u[I+3]/250),C+=y*u[I],S+=y*u[I+1],A+=y*u[I+2],v+=y))}}f[b]=C/v,f[b+1]=S/v,f[b+2]=A/v,f[b+3]=k/x}return d}}E(Bu,"type","Resize"),E(Bu,"defaults",{resizeType:"hermite",scaleX:1,scaleY:1,lanczosLobes:3}),E(Bu,"uniformLocations",["uDelta","uTaps"]),z.setClass(Bu);class Hu extends $t{getFragmentSource(){return`
470
476
  precision highp float;
471
477
  uniform sampler2D uTexture;
472
478
  uniform float uSaturation;
@@ -480,7 +486,7 @@ void main() {
480
486
  color.b += rgbMax != color.b ? (rgbMax - color.b) * uSaturation : 0.00;
481
487
  gl_FragColor = color;
482
488
  }
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"]),z.setClass(ju);class Bu extends $t{getFragmentSource(){return`
489
+ `}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}}E(Hu,"type","Saturation"),E(Hu,"defaults",{saturation:0}),E(Hu,"uniformLocations",["uSaturation"]),z.setClass(Hu);class zu extends $t{getFragmentSource(){return`
484
490
  precision highp float;
485
491
  uniform sampler2D uTexture;
486
492
  uniform float uVibrance;
@@ -495,15 +501,15 @@ void main() {
495
501
  color.b += max != color.b ? (max - color.b) * amt : 0.00;
496
502
  gl_FragColor = color;
497
503
  }
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"]),z.setClass(Bu);let K0=null;function tx(){const a=document.createElement("div");a.style.width="1in",document.body.append(a);const t=a.offsetWidth;return a.remove(),t}function ex(){const a=K0??tx();return K0=a,a/72}function sx(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)}}function ix(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 nx(i))}),i.addEventListener("error",n=>{window.URL.revokeObjectURL(s),e(n)})})}function nx(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))})}var Hh={};Hh.d=(a,t)=>{for(var e in t)Hh.o(t,e)&&!Hh.o(a,e)&&Object.defineProperty(a,e,{enumerable:!0,get:t[e]})},Hh.o=(a,t)=>Object.prototype.hasOwnProperty.call(a,t);var Q=globalThis.pdfjsLib={};Hh.d(Q,{AbortException:()=>Rn,AnnotationEditorLayer:()=>Bg,AnnotationEditorParamsType:()=>at,AnnotationEditorType:()=>tt,AnnotationEditorUIManager:()=>Pr,AnnotationLayer:()=>ZS,AnnotationMode:()=>On,ColorPicker:()=>nd,DOMSVGFactory:()=>Mg,DrawLayer:()=>Hg,FeatureTest:()=>Re,GlobalWorkerOptions:()=>Xi,ImageKind:()=>Hu,InvalidPDFException:()=>og,MissingPDFException:()=>Gh,OPS:()=>zs,OutputScale:()=>pg,PDFDataRangeTransport:()=>Ob,PDFDateString:()=>fg,PDFWorker:()=>la,PasswordResponses:()=>hx,PermissionFlag:()=>ax,PixelsPerInch:()=>Ln,RenderingCancelledException:()=>ug,TextLayer:()=>$h,TouchManager:()=>Ku,UnexpectedResponseException:()=>Xu,Util:()=>U,VerbosityLevel:()=>zu,XfaLayer:()=>Fb,build:()=>RS,createValidAbsoluteUrl:()=>dx,fetchData:()=>Uu,getDocument:()=>CS,getFilenameFromUrl:()=>wx,getPdfFilenameFromUrl:()=>xx,getXfaPageViewport:()=>Sx,isDataScheme:()=>Yu,isPdfFile:()=>dg,noContextMenu:()=>Gs,normalizeUnicode:()=>vx,setLayerDimensions:()=>Mr,shadow:()=>nt,stopEvent:()=>is,version:()=>DS});const ve=typeof process=="object"&&process+""=="[object process]"&&!process.versions.nw&&!(process.versions.electron&&process.type&&process.type!=="browser"),Q0=[1,0,0,1,0,0],ig=[.001,0,0,.001,0,0],rx=1e7,ng=1.35,ss={ANY:1,DISPLAY:2,PRINT:4,ANNOTATIONS_FORMS:16,ANNOTATIONS_STORAGE:32,ANNOTATIONS_DISABLE:64,IS_EDITING:128,OPLIST:256},On={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},ox="pdfjs_internal_editor_",tt={DISABLE:-1,NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15},at={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},ax={PRINT:4,MODIFY_CONTENTS:8,COPY:16,MODIFY_ANNOTATIONS:32,FILL_INTERACTIVE_FORMS:256,COPY_FOR_ACCESSIBILITY:512,ASSEMBLE:1024,PRINT_HIGH_QUALITY:2048},ye={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},zh={SOLID:1,DASHED:2,BEVELED:3,INSET:4,UNDERLINE:5},zu={ERRORS:0,WARNINGS:1,INFOS:5},zs={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},hx={NEED_PASSWORD:1,INCORRECT_PASSWORD:2};let Gu=zu.WARNINGS;function lx(a){Number.isInteger(a)&&(Gu=a)}function cx(){return Gu}function Vu(a){Gu>=zu.INFOS&&console.log(`Info: ${a}`)}function et(a){Gu>=zu.WARNINGS&&console.log(`Warning: ${a}`)}function yt(a){throw new Error(a)}function Xt(a,t){a||yt(t)}function ux(a){switch(a==null?void 0:a.protocol){case"http:":case"https:":case"ftp:":case"mailto:":case"tel:":return!0;default:return!1}}function dx(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=bx(a)}catch{}}const s=t?new URL(a,t):new URL(a);if(ux(s))return s}catch{}return null}function nt(a,t,e,s=!1){return Object.defineProperty(a,t,{value:e,enumerable:!s,configurable:!0,writable:!1}),e}const Dn=function(){function t(e,s){this.message=e,this.name=s}return t.prototype=new Error,t.constructor=t,t}();class J0 extends Dn{constructor(t,e){super(t,"PasswordException"),this.code=e}}class rg extends Dn{constructor(t,e){super(t,"UnknownErrorException"),this.details=e}}class og extends Dn{constructor(t){super(t,"InvalidPDFException")}}class Gh extends Dn{constructor(t){super(t,"MissingPDFException")}}class Xu extends Dn{constructor(t,e){super(t,"UnexpectedResponseException"),this.status=e}}class fx extends Dn{constructor(t){super(t,"FormatError")}}class Rn extends Dn{constructor(t){super(t,"AbortException")}}function Z0(a){(typeof a!="object"||(a==null?void 0:a.length)===void 0)&&yt("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"&&yt("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 gx(a){return String.fromCharCode(a>>24&255,a>>16&255,a>>8&255,a&255)}function ag(a){const t=Object.create(null);for(const[e,s]of a)t[e]=s;return t}function px(){const a=new Uint8Array(4);return a[0]=1,new Uint32Array(a.buffer,0,1)[0]===1}function mx(){try{return new Function(""),!0}catch{return!1}}class Re{static get isLittleEndian(){return nt(this,"isLittleEndian",px())}static get isEvalSupported(){return nt(this,"isEvalSupported",mx())}static get isOffscreenCanvasSupported(){return nt(this,"isOffscreenCanvasSupported",typeof OffscreenCanvas<"u")}static get isImageDecoderSupported(){return nt(this,"isImageDecoderSupported",typeof ImageDecoder<"u")}static get platform(){return typeof navigator<"u"&&typeof(navigator==null?void 0:navigator.platform)=="string"?nt(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")}):nt(this,"platform",{isMac:!1,isWindows:!1,isFirefox:!1})}static get isCSSRoundSupported(){var t,e;return nt(this,"isCSSRoundSupported",(e=(t=globalThis.CSS)==null?void 0:t.supports)==null?void 0:e.call(t,"width: round(1.5px, 1px)"))}}const hg=Array.from(Array(256).keys(),a=>a.toString(16).padStart(2,"0"));class U{static makeHexColor(t,e,s){return`#${hg[t]}${hg[e]}${hg[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,Wi,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,Wi,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}}Wi=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,Wi,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,Wi,Ed).call(this,t,e,s,i,n,r,o,h,(-u+p)/b,f),w(this,Wi,Ed).call(this,t,e,s,i,n,r,o,h,(-u-p)/b,f)},_(U,Wi);function bx(a){return decodeURIComponent(escape(a))}let lg=null,tb=null;function vx(a){return lg||(lg=/([\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,tb=new Map([["ſt","ſt"]])),a.replaceAll(lg,(t,e,s)=>e?e.normalize("NFKC"):tb.get(s))}function yx(){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();const a=new Uint8Array(32);return crypto.getRandomValues(a),Z0(a)}const cg="pdfjs_internal_id_";function _x(a){return Uint8Array.prototype.toBase64?a.toBase64():btoa(Z0(a))}typeof Promise.try!="function"&&(Promise.try=function(a,...t){return new Promise(e=>{e(a(...t))})});const Vi="http://www.w3.org/2000/svg",Rr=class Rr{};$(Rr,"CSS",96),$(Rr,"PDF",72),$(Rr,"PDF_TO_CSS_UNITS",Rr.CSS/Rr.PDF);let Ln=Rr;async function Uu(a,t="text"){if(Xh(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 Vh{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,y;u===0?(p=Math.abs(c-t[1])*s+n,b=Math.abs(h-t[0])*s+r,v=(t[3]-t[1])*s,y=(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,y=(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=y}get rawDims(){const{userUnit:t,viewBox:e}=this,s=e.map(i=>i*t);return nt(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 Vh({viewBox:this.viewBox.slice(),userUnit:this.userUnit,scale:t,rotation:e,offsetX:s,offsetY:i,dontFlip:n})}convertToViewportPoint(t,e){return U.applyTransform([t,e],this.transform)}convertToViewportRectangle(t){const e=U.applyTransform([t[0],t[1]],this.transform),s=U.applyTransform([t[2],t[3]],this.transform);return[e[0],e[1],s[0],s[1]]}convertToPdfPoint(t,e){return U.applyInverseTransform([t,e],this.transform)}}class ug extends Dn{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 dg(a){return typeof a=="string"&&/\.pdf$/i.test(a)}function wx(a){return[a]=a.split(/[#?]/,1),a.substring(a.lastIndexOf("/")+1)}function xx(a,t="document.pdf"){if(typeof a!="string")return t;if(Yu(a))return et('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 eb{constructor(){$(this,"started",Object.create(null));$(this,"times",[])}time(t){t in this.started&&et(`Timer is already running for ${t}`),this.started[t]=Date.now()}timeEnd(t){t in this.started||et(`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 Xh(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 is(a){a.preventDefault(),a.stopPropagation()}class fg{static toDateObject(t){if(!t||typeof t!="string")return null;l(this,Zh)||m(this,Zh,new RegExp("^D:(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?([Z|+|-])?(\\d{2})?'?(\\d{2})?'?"));const e=l(this,Zh).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))}}Zh=new WeakMap,_(fg,Zh);function Sx(a,{scale:t=1,rotation:e=0}){const{width:s,height:i}=a.attributes.style,n=[0,0,parseInt(s),parseInt(i)];return new Vh({viewBox:n,userUnit:1,scale:t,rotation:e})}function gg(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):(et(`Not a valid color format: "${a}"`),[0,0,0])}function Cx(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,gg(s))}t.remove()}function At(a){const{a:t,b:e,c:s,d:i,e:n,f:r}=a.getTransform();return[t,e,s,i,n,r]}function ci(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 Mr(a,t,e=!1,s=!0){if(t instanceof Vh){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 pg{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 Ui=class Ui{constructor(t){_(this,Le);_(this,In,null);_(this,Lr,null);_(this,Vs);_(this,Fr,null);_(this,tl,null);m(this,Vs,t),l(Ui,el)||m(Ui,el,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,Vs)._uiManager._signal;t.addEventListener("contextmenu",Gs,{signal:e}),t.addEventListener("pointerdown",w(Ui,ad,Qb),{signal:e});const s=m(this,Fr,document.createElement("div"));s.className="buttons",t.append(s);const i=l(this,Vs).toolbarPosition;if(i){const{style:n}=t,r=l(this,Vs)._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,tv).call(this),t}get div(){return l(this,In)}hide(){var t;l(this,In).classList.add("hidden"),(t=l(this,Lr))==null||t.hideDropdown()}show(){var t;l(this,In).classList.remove("hidden"),(t=l(this,tl))==null||t.shown()}async addAltText(t){const e=await t.render();w(this,Le,kd).call(this,e),l(this,Fr).prepend(e,l(this,Le,Kg)),m(this,tl,t)}addColorPicker(t){m(this,Lr,t);const e=t.renderButton();w(this,Le,kd).call(this,e),l(this,Fr).prepend(e,l(this,Le,Kg))}remove(){var t;l(this,In).remove(),(t=l(this,Lr))==null||t.destroy(),m(this,Lr,null)}};In=new WeakMap,Lr=new WeakMap,Vs=new WeakMap,Fr=new WeakMap,tl=new WeakMap,el=new WeakMap,ad=new WeakSet,Qb=function(t){t.stopPropagation()},Le=new WeakSet,Jb=function(t){l(this,Vs)._focusEventsAllowed=!1,is(t)},Zb=function(t){l(this,Vs)._focusEventsAllowed=!0,is(t)},kd=function(t){const e=l(this,Vs)._uiManager._signal;t.addEventListener("focusin",w(this,Le,Jb).bind(this),{capture:!0,signal:e}),t.addEventListener("focusout",w(this,Le,Zb).bind(this),{capture:!0,signal:e}),t.addEventListener("contextmenu",Gs,{signal:e})},tv=function(){const{editorType:t,_uiManager:e}=l(this,Vs),s=document.createElement("button");s.className="delete",s.tabIndex=0,s.setAttribute("data-l10n-id",l(Ui,el)[t]),w(this,Le,kd).call(this,s),s.addEventListener("click",i=>{e.delete()},{signal:e._signal}),l(this,Fr).append(s)},Kg=function(){const t=document.createElement("div");return t.className="divider",t},_(Ui,ad),_(Ui,el,null);let mg=Ui;class Ax{constructor(t){_(this,Nn);_(this,sl,null);_(this,Ir,null);_(this,Nr);m(this,Nr,t)}show(t,e,s){const[i,n]=w(this,Nn,sv).call(this,e,s),{style:r}=l(this,Ir)||m(this,Ir,w(this,Nn,ev).call(this));t.append(l(this,Ir)),r.insetInlineEnd=`${100*i}%`,r.top=`calc(${100*n}% + var(--editor-toolbar-vert-offset))`}hide(){l(this,Ir).remove()}}sl=new WeakMap,Ir=new WeakMap,Nr=new WeakMap,Nn=new WeakSet,ev=function(){const t=m(this,Ir,document.createElement("div"));t.className="editToolbar",t.setAttribute("role","toolbar"),t.addEventListener("contextmenu",Gs,{signal:l(this,Nr)._signal});const e=m(this,sl,document.createElement("div"));return e.className="buttons",t.append(e),w(this,Nn,iv).call(this),t},sv=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]},iv=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,Nr)._signal;t.addEventListener("contextmenu",Gs,{signal:s}),t.addEventListener("click",()=>{l(this,Nr).highlightSelection("floating_button")},{signal:s}),l(this,sl).append(t)};function $u(a,t,e){for(const s of e)t.addEventListener(s,a[s].bind(a))}class Tx{constructor(){_(this,hd,0)}get id(){return`${ox}${ze(this,hd)._++}`}}hd=new WeakMap;const Gg=class Gg{constructor(){_(this,ua);_(this,ca,yx());_(this,il,0);_(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 nt(this,"_isSVGFittingCanvas",n)}async getFromFile(t){const{lastModified:e,name:s,size:i,type:n}=t;return w(this,ua,Md).call(this,`${e}_${s}_${i}_${n}`,t)}async getFromUrl(t){return w(this,ua,Md).call(this,t,t)}async getFromBlob(t,e){const s=await e;return w(this,ua,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,ca)}_${ze(this,il)._++}`,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,ca)}_`)}};ca=new WeakMap,il=new WeakMap,we=new WeakMap,ua=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,ca)}_${ze(this,il)._++}`,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=Gg._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){et(i),s=null}return l(this,we).set(t,s),s&&l(this,we).set(s.id,s),s};let bg=Gg;class Ex{constructor(t=128){_(this,Ht,[]);_(this,jn,!1);_(this,nl);_(this,Dt,-1);m(this,nl,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,Ht).length>0&&(l(this,Ht).length=0),m(this,Dt,0),l(this,Ht).push(h);return}if(r&&l(this,Ht)[l(this,Dt)].type===n){o&&(h.undo=l(this,Ht)[l(this,Dt)].undo),l(this,Ht)[l(this,Dt)]=h;return}const c=l(this,Dt)+1;c===l(this,nl)?l(this,Ht).splice(0,1):(m(this,Dt,c),c<l(this,Ht).length&&l(this,Ht).splice(c)),l(this,Ht).push(h)}undo(){if(l(this,Dt)===-1)return;m(this,jn,!0);const{undo:t,post:e}=l(this,Ht)[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,Ht).length-1){m(this,Dt,l(this,Dt)+1),m(this,jn,!0);const{cmd:t,post:e}=l(this,Ht)[l(this,Dt)];t(),e==null||e(),m(this,jn,!1)}}hasSomethingToUndo(){return l(this,Dt)!==-1}hasSomethingToRedo(){return l(this,Dt)<l(this,Ht).length-1}cleanType(t){if(l(this,Dt)!==-1){for(let e=l(this,Dt);e>=0;e--)if(l(this,Ht)[e].type!==t){l(this,Ht).splice(e+1,l(this,Dt)-e),m(this,Dt,e);return}l(this,Ht).length=0,m(this,Dt,-1)}}destroy(){m(this,Ht,null)}}Ht=new WeakMap,jn=new WeakMap,nl=new WeakMap,Dt=new WeakMap;class Wh{constructor(t){_(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,nv).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||is(e))}}ld=new WeakSet,nv=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 Cx(t),nt(this,"_colors",t)}convert(t){const e=gg(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?U.makeHexColor(...e):t}};$(cd,"_colorsMapping",new Map([["CanvasText",[0,0,0]],["Canvas",[255,255,255]]]));let vg=cd;const va=class va{constructor(t,e,s,i,n,r,o,h,c,u,d,f,g){_(this,B);_(this,da,new AbortController);_(this,ns,null);_(this,Kt,new Map);_(this,ae,new Map);_(this,fa,null);_(this,Yi,null);_(this,ga,null);_(this,Ss,new Ex);_(this,Bn,null);_(this,jr,null);_(this,pa,0);_(this,Br,new Set);_(this,di,null);_(this,Xs,null);_(this,Hr,new Set);$(this,"_editorUndoBar",null);_(this,rl,!1);_(this,ol,!1);_(this,ma,!1);_(this,al,null);_(this,fi,null);_(this,Hn,null);_(this,ba,null);_(this,zn,!1);_(this,gi,null);_(this,ud,new Tx);_(this,Gn,!1);_(this,hl,!1);_(this,Vn,null);_(this,zr,null);_(this,ll,null);_(this,cl,null);_(this,ee,tt.NONE);_(this,pt,new Set);_(this,$i,null);_(this,Gr,null);_(this,ul,null);_(this,dl,{isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1});_(this,Xn,[0,0]);_(this,pi,null);_(this,qi,null);_(this,fl,null);_(this,Cs,null);const p=this._signal=l(this,da).signal;m(this,qi,t),m(this,fl,e),m(this,fa,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,B,av).call(this),w(this,B,uv).call(this),w(this,B,Jg).call(this),m(this,Yi,n.annotationStorage),m(this,al,n.filterFactory),m(this,Gr,r),m(this,ba,o||null),m(this,rl,h),m(this,ol,c),m(this,ma,u),m(this,cl,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=va.prototype,e=r=>l(r,qi).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 nt(this,"_keyboardManager",new Wh([[["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,qi).contains(o)&&!r.isEnterHandled}],[[" ","mac+ "],t.addNewEditorFromKeyboard,{checker:(r,{target:o})=>!(o instanceof HTMLButtonElement)&&l(r,qi).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,Cs))==null||t.resolve(),m(this,Cs,null),(e=l(this,da))==null||e.abort(),m(this,da,null),this._signal=null;for(const r of l(this,ae).values())r.destroy();l(this,ae).clear(),l(this,Kt).clear(),l(this,Hr).clear(),m(this,ns,null),l(this,pt).clear(),l(this,Ss).destroy(),(s=l(this,fa))==null||s.destroy(),(i=l(this,gi))==null||i.hide(),m(this,gi,null),l(this,fi)&&(clearTimeout(l(this,fi)),m(this,fi,null)),l(this,pi)&&(clearTimeout(l(this,pi)),m(this,pi,null)),(n=this._editorUndoBar)==null||n.destroy()}combinedSignal(t){return AbortSignal.any([this._signal,t.signal])}get mlManager(){return l(this,cl)}get useNewAltTextFlow(){return l(this,ol)}get useNewAltTextWhenAddingImage(){return l(this,ma)}get hcmFilter(){return nt(this,"hcmFilter",l(this,Gr)?l(this,al).addHCMFilter(l(this,Gr).foreground,l(this,Gr).background):"none")}get direction(){return nt(this,"direction",getComputedStyle(l(this,qi)).direction)}get highlightColors(){return nt(this,"highlightColors",l(this,ba)?new Map(l(this,ba).split(",").map(t=>t.split("=").map(e=>e.trim()))):null)}get highlightColorNames(){return nt(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,jr,t)}setMainHighlightColorPicker(t){m(this,ll,t)}editAltText(t,e=!1){var s;(s=l(this,fa))==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,ma,e);break}}onPageChanging({pageNumber:t}){m(this,pa,t-1)}focusMainContainer(){l(this,qi).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,fl).classList.toggle("noUserSelect",t)}addShouldRescale(t){l(this,Hr).add(t)}removeShouldRescale(t){l(this,Hr).delete(t)}onScaleChanging({scale:t}){var e;this.commitOrRemove(),this.viewParameters.realScale=t*Ln.PDF_TO_CSS_UNITS;for(const s of l(this,Hr))s.onScaleChanging();(e=l(this,jr))==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,B,Pd).call(this,e).closest(".textLayer"),u=this.getSelectionBoxes(c);if(!u)return;e.empty();const d=w(this,B,Qg).call(this,c),f=l(this,ee)===tt.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(tt.HIGHLIGHT,g);return}g()}addToAnnotationStorage(t){!t.isEmpty()&&l(this,Yi)&&!l(this,Yi).has(t.id)&&l(this,Yi).setValue(t.id,t)}blur(){if(this.isShiftKeyDown=!1,l(this,zn)&&(m(this,zn,!1),w(this,B,Od).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,zr,[e,t]),e._focusEventsAllowed=!1;break}}focus(){if(!l(this,zr))return;const[t,e]=l(this,zr);m(this,zr,null),e.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this._signal}),e.focus()}addEditListeners(){w(this,B,Jg).call(this),w(this,B,Zg).call(this)}removeEditListeners(){w(this,B,cv).call(this),w(this,B,tp).call(this)}dragOver(t){for(const{type:e}of t.dataTransfer.items)for(const s of l(this,Xs))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,Xs))if(s.isHandlingMimeForPasting(e.type)){s.paste(e,this.currentLayer),t.preventDefault();return}}copy(t){var s;if(t.preventDefault(),(s=l(this,ns))==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,Xs))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){et(`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,B,ep).call(this,h);w(this,B,sp).call(this,n)},o=()=>{for(const h of n)h.remove()};this.addCommands({cmd:r,undo:o,mustExec:!0})}catch(n){et(`paste: "${n.message}".`)}}keydown(t){!this.isShiftKeyDown&&t.key==="Shift"&&(this.isShiftKeyDown=!0),l(this,ee)!==tt.NONE&&!this.isEditorHandlingKeyboard&&va._keyboardManager.exec(this,t)}keyup(t){this.isShiftKeyDown&&t.key==="Shift"&&(this.isShiftKeyDown=!1,l(this,zn)&&(m(this,zn,!1),w(this,B,Od).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,B,hv).call(this),w(this,B,Zg).call(this),w(this,B,Ge).call(this,{isEditing:l(this,ee)!==tt.NONE,isEmpty:w(this,B,Ac).call(this),hasSomethingToUndo:l(this,Ss).hasSomethingToUndo(),hasSomethingToRedo:l(this,Ss).hasSomethingToRedo(),hasSelectedEditor:!1})):(w(this,B,lv).call(this),w(this,B,tp).call(this),w(this,B,Ge).call(this,{isEditing:!1}),this.disableUserSelect(!1))}registerEditorTypes(t){if(!l(this,Xs)){m(this,Xs,t);for(const e of l(this,Xs))w(this,B,Sn).call(this,e.defaultPropertiesToUpdate)}}getId(){return l(this,ud).id}get currentLayer(){return l(this,ae).get(l(this,pa))}getLayer(t){return l(this,ae).get(t)}get currentPageIndex(){return l(this,pa)}addLayer(t){l(this,ae).set(t.pageIndex,t),l(this,Gn)?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,Cs)&&(await l(this,Cs).promise,!l(this,Cs)))){if(m(this,Cs,Promise.withResolvers()),m(this,ee,t),t===tt.NONE){this.setEditingState(!1),w(this,B,fv).call(this),(i=this._editorUndoBar)==null||i.hide(),l(this,Cs).resolve();return}this.setEditingState(!0),await w(this,B,dv).call(this),this.unselectAll();for(const n of l(this,ae).values())n.updateMode(t);if(!e){s&&this.addNewEditorFromKeyboard(),l(this,Cs).resolve();return}for(const n of l(this,Kt).values())n.annotationElementId===e?(this.setSelected(n),n.enterInEditMode()):n.unselect();l(this,Cs).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,Xs)){switch(t){case at.CREATE:this.currentLayer.addNewEditor();return;case at.HIGHLIGHT_DEFAULT_COLOR:(s=l(this,ll))==null||s.updateColor(e);break;case at.HIGHLIGHT_SHOW_ALL:this._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:{type:"highlight",action:"toggle_visibility"}}}),(l(this,ul)||m(this,ul,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,Xs))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,ul))==null?void 0:n.get(at.HIGHLIGHT_SHOW_ALL))??!0)!==e&&w(this,B,Sn).call(this,[[at.HIGHLIGHT_SHOW_ALL,e]])}enableWaiting(t=!1){if(l(this,hl)!==t){m(this,hl,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,fi)&&clearTimeout(l(this,fi)),m(this,fi,setTimeout(()=>{this.focusMainContainer(),m(this,fi,null)},0))),l(this,Kt).delete(t.id),this.unselect(t),(!t.annotationElementId||!l(this,Br).has(t.annotationElementId))&&((e=l(this,Yi))==null||e.remove(t.id))}addDeletedAnnotationElement(t){l(this,Br).add(t.annotationElementId),this.addChangedExistingAnnotation(t),t.deleted=!0}isDeletedAnnotationElement(t){return l(this,Br).has(t)}removeDeletedAnnotationElement(t){l(this,Br).delete(t.annotationElementId),this.removeChangedExistingAnnotation(t),t.deleted=!1}setActiveEditor(t){l(this,ns)!==t&&(m(this,ns,t),t&&w(this,B,Sn).call(this,t.propertiesToUpdate))}updateUI(t){l(this,B,gv)===t&&w(this,B,Sn).call(this,t.propertiesToUpdate)}updateUIForDefaultProperties(t){w(this,B,Sn).call(this,t.defaultPropertiesToUpdate)}toggleSelected(t){if(l(this,pt).has(t)){l(this,pt).delete(t),t.unselect(),w(this,B,Ge).call(this,{hasSelectedEditor:this.hasSelection});return}l(this,pt).add(t),t.select(),w(this,B,Sn).call(this,t.propertiesToUpdate),w(this,B,Ge).call(this,{hasSelectedEditor:!0})}setSelected(t){var e;(e=l(this,jr))==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,B,Sn).call(this,t.propertiesToUpdate),w(this,B,Ge).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,B,Ge).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,Ss).undo(),w(this,B,Ge).call(this,{hasSomethingToUndo:l(this,Ss).hasSomethingToUndo(),hasSomethingToRedo:!0,isEmpty:w(this,B,Ac).call(this)}),(t=this._editorUndoBar)==null||t.hide()}redo(){l(this,Ss).redo(),w(this,B,Ge).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:l(this,Ss).hasSomethingToRedo(),isEmpty:w(this,B,Ac).call(this)})}addCommands(t){l(this,Ss).add(t),w(this,B,Ge).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:!1,isEmpty:w(this,B,Ac).call(this)})}cleanUndoStack(t){l(this,Ss).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,B,ep).call(this,r)};this.addCommands({cmd:s,undo:i,mustExec:!0})}commitOrRemove(){var t;(t=l(this,ns))==null||t.commitOrRemove()}hasSomethingToControl(){return l(this,ns)||this.hasSelection}selectAll(){for(const t of l(this,pt))t.commit();w(this,B,sp).call(this,l(this,Kt).values())}unselectAll(){var t;if(!(l(this,ns)&&(l(this,ns).commitOrRemove(),l(this,ee)!==tt.NONE))&&!((t=l(this,jr))!=null&&t.commitOrRemove())&&this.hasSelection){for(const e of l(this,pt))e.unselect();l(this,pt).clear(),w(this,B,Ge).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,pi)&&clearTimeout(l(this,pi)),m(this,pi,setTimeout(()=>{m(this,pi,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,di,new Map);for(const t of l(this,pt))l(this,di).set(t,{savedX:t.x,savedY:t.y,savedPageIndex:t.pageIndex,newX:0,newY:0,newPageIndex:-1})}}endDragSession(){if(!l(this,di))return!1;this.disableUserSelect(!1);const t=l(this,di);m(this,di,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,di))for(const s of l(this,di).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,ns)===t}getActive(){return l(this,ns)}getMode(){return l(this,ee)}get imageManager(){return nt(this,"imageManager",new bg)}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,ga)||m(this,ga,new Map)).set(t,e)}removeChangedExistingAnnotation({annotationElementId:t}){var e;(e=l(this,ga))==null||e.delete(t)}renderAnnotationElement(t){var i;const e=(i=l(this,ga))==null?void 0:i.get(t.data.id);if(!e)return;const s=l(this,Yi).getRawValue(e);s&&(l(this,ee)===tt.NONE&&!s.hasBeenModified||s.renderAnnotationElement(t))}};da=new WeakMap,ns=new WeakMap,Kt=new WeakMap,ae=new WeakMap,fa=new WeakMap,Yi=new WeakMap,ga=new WeakMap,Ss=new WeakMap,Bn=new WeakMap,jr=new WeakMap,pa=new WeakMap,Br=new WeakMap,di=new WeakMap,Xs=new WeakMap,Hr=new WeakMap,rl=new WeakMap,ol=new WeakMap,ma=new WeakMap,al=new WeakMap,fi=new WeakMap,Hn=new WeakMap,ba=new WeakMap,zn=new WeakMap,gi=new WeakMap,ud=new WeakMap,Gn=new WeakMap,hl=new WeakMap,Vn=new WeakMap,zr=new WeakMap,ll=new WeakMap,cl=new WeakMap,ee=new WeakMap,pt=new WeakMap,$i=new WeakMap,Gr=new WeakMap,ul=new WeakMap,dl=new WeakMap,Xn=new WeakMap,pi=new WeakMap,qi=new WeakMap,fl=new WeakMap,Cs=new WeakMap,B=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},rv=function(){const t=document.getSelection();if(!t||t.isCollapsed)return;const s=w(this,B,Pd).call(this,t).closest(".textLayer"),i=this.getSelectionBoxes(s);i&&(l(this,gi)||m(this,gi,new Ax(this)),l(this,gi).show(s,i,this.direction==="ltr"))},ov=function(){var n,r,o;const t=document.getSelection();if(!t||t.isCollapsed){l(this,$i)&&((n=l(this,gi))==null||n.hide(),m(this,$i,null),w(this,B,Ge).call(this,{hasSelectedText:!1}));return}const{anchorNode:e}=t;if(e===l(this,$i))return;const i=w(this,B,Pd).call(this,t).closest(".textLayer");if(!i){l(this,$i)&&((r=l(this,gi))==null||r.hide(),m(this,$i,null),w(this,B,Ge).call(this,{hasSelectedText:!1}));return}if((o=l(this,gi))==null||o.hide(),m(this,$i,e),w(this,B,Ge).call(this,{hasSelectedText:!0}),!(l(this,ee)!==tt.HIGHLIGHT&&l(this,ee)!==tt.NONE)&&(l(this,ee)===tt.HIGHLIGHT&&this.showAllEditors("highlight",!0,!0),m(this,zn,this.isShiftKeyDown),!this.isShiftKeyDown)){const h=l(this,ee)===tt.HIGHLIGHT?w(this,B,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,B,Od).call(this,"main_toolbar"))};window.addEventListener("pointerup",d,{signal:u}),window.addEventListener("blur",d,{signal:u})}},Od=function(t=""){l(this,ee)===tt.HIGHLIGHT?this.highlightSelection(t):l(this,rl)&&w(this,B,rv).call(this)},av=function(){document.addEventListener("selectionchange",w(this,B,ov).bind(this),{signal:this._signal})},hv=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})},lv=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})},cv=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)},uv=function(){const t=this._signal;document.addEventListener("dragover",this.dragOver.bind(this),{signal:t}),document.addEventListener("drop",this.drop.bind(this),{signal:t})},Ge=function(t){Object.entries(t).some(([s,i])=>l(this,dl)[s]!==i)&&(this._eventBus.dispatch("annotationeditorstateschanged",{source:this,details:Object.assign(l(this,dl),t)}),l(this,ee)===tt.HIGHLIGHT&&t.hasSelectedEditor===!1&&w(this,B,Sn).call(this,[[at.HIGHLIGHT_FREE,!0]]))},Sn=function(t){this._eventBus.dispatch("annotationeditorparamschanged",{source:this,details:t})},dv=async function(){if(!l(this,Gn)){m(this,Gn,!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()}},fv=function(){if(this.unselectAll(),l(this,Gn)){m(this,Gn,!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))},gv=function(){let t=null;for(t of l(this,pt));return t},Ac=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,B,Ge).call(this,{hasSelectedEditor:this.hasSelection})},$(va,"TRANSLATE_SMALL",1),$(va,"TRANSLATE_BIG",10);let Pr=va;const Fe=class Fe{constructor(t){_(this,Us);_(this,se,null);_(this,mi,!1);_(this,Ws,null);_(this,ya,null);_(this,bi,null);_(this,rs,null);_(this,_a,!1);_(this,vi,null);_(this,qe,null);_(this,Ki,null);_(this,Vr,null);_(this,yi,!1);m(this,qe,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,Ws,document.createElement("button"));t.className="altText",t.tabIndex="0";const e=m(this,ya,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,qe)._uiManager._signal;t.addEventListener("contextmenu",Gs,{signal:s}),t.addEventListener("pointerdown",n=>n.stopPropagation(),{signal:s});const i=n=>{n.preventDefault(),l(this,qe)._uiManager.editAltText(l(this,qe)),l(this,yi)&&l(this,qe)._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_clicked",data:{label:l(this,Us,Tc)}})};return t.addEventListener("click",i,{capture:!0,signal:s}),t.addEventListener("keydown",n=>{n.target===t&&n.key==="Enter"&&(m(this,_a,!0),i(n))},{signal:s}),await w(this,Us,Dd).call(this),t}finish(){l(this,Ws)&&(l(this,Ws).focus({focusVisible:l(this,_a)}),m(this,_a,!1))}isEmpty(){return l(this,yi)?l(this,se)===null:!l(this,se)&&!l(this,mi)}hasData(){return l(this,yi)?l(this,se)!==null||!!l(this,Ki):this.isEmpty()}get guessedText(){return l(this,Ki)}async setGuessedText(t){l(this,se)===null&&(m(this,Ki,t),m(this,Vr,await Fe._l10n.get("pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer",{generatedAltText:t})),w(this,Us,Dd).call(this))}toggleAltTextBadge(t=!1){var e;if(!l(this,yi)||l(this,se)){(e=l(this,vi))==null||e.remove(),m(this,vi,null);return}if(!l(this,vi)){const s=m(this,vi,document.createElement("div"));s.className="noAltTextBadge",l(this,qe).div.append(s)}l(this,vi).classList.toggle("hidden",!t)}serialize(t){let e=l(this,se);return!t&&l(this,Ki)===e&&(e=l(this,Vr)),{altText:e,decorative:l(this,mi),guessedText:l(this,Ki),textWithDisclaimer:l(this,Vr)}}get data(){return{altText:l(this,se),decorative:l(this,mi)}}set data({altText:t,decorative:e,guessedText:s,textWithDisclaimer:i,cancel:n=!1}){s&&(m(this,Ki,s),m(this,Vr,i)),!(l(this,se)===t&&l(this,mi)===e)&&(n||(m(this,se,t),m(this,mi,e)),w(this,Us,Dd).call(this))}toggle(t=!1){l(this,Ws)&&(!t&&l(this,rs)&&(clearTimeout(l(this,rs)),m(this,rs,null)),l(this,Ws).disabled=!t)}shown(){l(this,qe)._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_displayed",data:{label:l(this,Us,Tc)}})}destroy(){var t,e;(t=l(this,Ws))==null||t.remove(),m(this,Ws,null),m(this,ya,null),m(this,bi,null),(e=l(this,vi))==null||e.remove(),m(this,vi,null)}};se=new WeakMap,mi=new WeakMap,Ws=new WeakMap,ya=new WeakMap,bi=new WeakMap,rs=new WeakMap,_a=new WeakMap,vi=new WeakMap,qe=new WeakMap,Ki=new WeakMap,Vr=new WeakMap,yi=new WeakMap,Wn=new WeakMap,Us=new WeakSet,Tc=function(){return l(this,se)&&"added"||l(this,se)===null&&this.guessedText&&"review"||"missing"},Dd=async function(){var i,n,r;const t=l(this,Ws);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,Us,Tc)]),(i=l(this,ya))==null||i.setAttribute("data-l10n-id",l(Fe,Wn)[`${l(this,Us,Tc)}-label`]),!l(this,se)){(n=l(this,bi))==null||n.remove();return}}else{if(!l(this,se)&&!l(this,mi)){t.classList.remove("done"),(r=l(this,bi))==null||r.remove();return}t.classList.add("done"),t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-edit-button")}let e=l(this,bi);if(!e){m(this,bi,e=document.createElement("span")),e.className="tooltip",e.setAttribute("role","tooltip"),e.id=`alt-text-tooltip-${l(this,qe).id}`;const o=100,h=l(this,qe)._uiManager._signal;h.addEventListener("abort",()=>{clearTimeout(l(this,rs)),m(this,rs,null)},{once:!0}),t.addEventListener("mouseenter",()=>{m(this,rs,setTimeout(()=>{m(this,rs,null),l(this,bi).classList.add("show"),l(this,qe)._reportTelemetry({action:"alt_text_tooltip"})},o))},{signal:h}),t.addEventListener("mouseleave",()=>{var c;l(this,rs)&&(clearTimeout(l(this,rs)),m(this,rs,null)),(c=l(this,bi))==null||c.classList.remove("show")},{signal:h})}l(this,mi)?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,qe).getImageForAltText();s==null||s.setAttribute("aria-describedby",e.id)},_(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}){_(this,Ji);_(this,gl);_(this,Xr,!1);_(this,pl,null);_(this,ml);_(this,bl);_(this,vl);_(this,yl);_(this,wa);_(this,Qi,null);_(this,Wr);_(this,Un,null);m(this,gl,t),m(this,pl,s),m(this,ml,e),m(this,bl,i),m(this,vl,n),m(this,yl,r),m(this,Wr,new AbortController),m(this,wa,AbortSignal.any([o,l(this,Wr).signal])),t.addEventListener("touchstart",w(this,Ji,pv).bind(this),{passive:!1,signal:l(this,wa)})}get MIN_TOUCH_DISTANCE_TO_PINCH(){return nt(this,"MIN_TOUCH_DISTANCE_TO_PINCH",35/(window.devicePixelRatio||1))}destroy(){var t;(t=l(this,Wr))==null||t.abort(),m(this,Wr,null)}};gl=new WeakMap,Xr=new WeakMap,pl=new WeakMap,ml=new WeakMap,bl=new WeakMap,vl=new WeakMap,yl=new WeakMap,wa=new WeakMap,Qi=new WeakMap,Wr=new WeakMap,Un=new WeakMap,Ji=new WeakSet,pv=function(t){var i,n,r;if((i=l(this,ml))!=null&&i.call(this)||t.touches.length<2)return;if(!l(this,Un)){m(this,Un,new AbortController);const o=AbortSignal.any([l(this,wa),l(this,Un).signal]),h=l(this,gl),c={signal:o,passive:!1};h.addEventListener("touchmove",w(this,Ji,mv).bind(this),c),h.addEventListener("touchend",w(this,Ji,ip).bind(this),c),h.addEventListener("touchcancel",w(this,Ji,ip).bind(this),c),(n=l(this,bl))==null||n.call(this)}if(is(t),t.touches.length!==2||(r=l(this,pl))!=null&&r.call(this)){m(this,Qi,null);return}let[e,s]=t.touches;e.identifier>s.identifier&&([e,s]=[s,e]),m(this,Qi,{touch0X:e.screenX,touch0Y:e.screenY,touch1X:s.screenX,touch1Y:s.screenY})},mv=function(t){var C;if(!l(this,Qi)||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,Qi),{touch0X:c,touch0Y:u,touch1X:d,touch1Y:f}=h,g=d-c,p=f-u,b=r-i,v=o-n,y=Math.hypot(b,v)||1,x=Math.hypot(g,p)||1;if(!l(this,Xr)&&Math.abs(x-y)<=Vg.MIN_TOUCH_DISTANCE_TO_PINCH)return;if(h.touch0X=i,h.touch0Y=n,h.touch1X=r,h.touch1Y=o,t.preventDefault(),!l(this,Xr)){m(this,Xr,!0);return}const S=[(i+r)/2,(n+o)/2];(C=l(this,vl))==null||C.call(this,S,x,y)},ip=function(t){var e;l(this,Un).abort(),m(this,Un,null),(e=l(this,yl))==null||e.call(this),l(this,Qi)&&(t.preventDefault(),m(this,Qi,null),m(this,Xr,!1))};let Ku=Vg;const st=class st{constructor(t){_(this,Y);_(this,Ur,null);_(this,Ys,null);_(this,xt,null);_(this,xa,!1);_(this,Yn,null);_(this,_l,"");_(this,Yr,!1);_(this,he,null);_(this,$r,null);_(this,Zi,null);_(this,$n,null);_(this,wl,"");_(this,qr,!1);_(this,os,null);_(this,xl,!1);_(this,Kr,!1);_(this,tn,!1);_(this,_i,null);_(this,Sa,0);_(this,Ca,0);_(this,As,null);_(this,Qr,null);$(this,"_editToolbar",null);$(this,"_initialOptions",Object.create(null));$(this,"_initialData",null);$(this,"_isVisible",!0);$(this,"_uiManager",null);$(this,"_focusEventsAllowed",!0);_(this,Sl,!1);_(this,dd,st._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=st.prototype._resizeWithKeyboard,e=Pr.TRANSLATE_SMALL,s=Pr.TRANSLATE_BIG;return nt(this,"_resizerKeyboardManager",new Wh([[["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"],st.prototype._stopResizingWithKeyboard]]))}get editorType(){return Object.getPrototypeOf(this).constructor._type}static get isDrawer(){return!1}static get _defaultLineColor(){return nt(this,"_defaultLineColor",this._colorManager.getHexCode("CanvasText"))}static deleteAnnotationElement(t){const e=new kx({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(st._l10n??(st._l10n=t),st._l10nResizer||(st._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"})),st._borderLineWidth!==-1)return;const s=getComputedStyle(document.documentElement);st._borderLineWidth=parseFloat(s.getPropertyValue("--outline-width"))||0}static updateDefaultParams(t,e){}static get defaultPropertiesToUpdate(){return[]}static isHandlingMimeForPasting(t){return!1}static paste(t,e){yt("Not implemented")}get propertiesToUpdate(){return[]}get _isDraggable(){return l(this,Sl)}set _isDraggable(t){var e;m(this,Sl,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,Ec).call(this),this.parent=t}focusin(t){this._focusEventsAllowed&&(l(this,qr)?m(this,qr,!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,os)||m(this,os,[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,os)||m(this,os,[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,os)&&(l(this,os)[0]!==this.x||l(this,os)[1]!==this.y)}get _hasBeenResized(){return!!l(this,os)&&(l(this,os)[2]!==this.width||l(this,os)[3]!==this.height)}getBaseTranslation(){const[t,e]=this.parentDimensions,{_borderLineWidth:s}=st,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=st,Cl,rp).call(s,t,e,this.parentRotation)}pageTranslationToScreen(t,e){var s;return w(s=st,Cl,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,Yr)||(n.height=`${(100*e/i).toFixed(2)}%`)}fixDims(){const{style:t}=this.div,{height:e,width:s}=t,i=s.endsWith("%"),n=!l(this,Yr)&&e.endsWith("%");if(i&&n)return;const[r,o]=this.parentDimensions;i||(t.width=`${(100*parseFloat(s)/r).toFixed(2)}%`),!l(this,Yr)&&!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,Kr)?this._editToolbar:(this._editToolbar=new mg(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(st._l10n),m(this,xt,new qu(this)),l(this,Ur)&&(l(this,xt).data=l(this,Ur),m(this,Ur,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,xa)?-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,Qr)||m(this,Qr,new Ku({container:this.div,isPinchingDisabled:()=>!this.isSelected,onPinchStart:w(this,Y,yv).bind(this),onPinching:w(this,Y,_v).bind(this),onPinchEnd:w(this,Y,wv).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,qr,!0),this._isDraggable){w(this,Y,xv).call(this,t);return}w(this,Y,hp).call(this,t)}get isSelected(){return this._uiManager.isSelected(this)}_onStartDragging(){}_onStopDragging(){}moveInDOM(){l(this,_i)&&clearTimeout(l(this,_i)),m(this,_i,setTimeout(()=>{var t;m(this,_i,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,Kr,!0)}disableEditMode(){m(this,Kr,!1)}isInEditMode(){return l(this,Kr)}shouldGetKeyboardEvents(){return l(this,tn)}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){yt("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,Ur,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,_i)&&(clearTimeout(l(this,_i)),m(this,_i,null)),w(this,Y,Ec).call(this),this.removeEditToolbar(),l(this,As)){for(const s of l(this,As).values())clearTimeout(s);m(this,As,null)}this.parent=null,(e=l(this,Qr))==null||e.destroy(),m(this,Qr,null)}get isResizable(){return!1}makeResizable(){this.isResizable&&(w(this,Y,bv).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,Zi,{savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height});const e=l(this,he).children;if(!l(this,Ys)){m(this,Ys,Array.from(e));const r=w(this,Y,Sv).bind(this),o=w(this,Y,Cv).bind(this),h=this._uiManager._signal;for(const c of l(this,Ys)){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,Av).bind(this,u),{signal:h}),c.setAttribute("data-l10n-id",st._l10nResizer[u])}}const s=l(this,Ys)[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,Ys).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,Ys)[r++].getAttribute("data-resizer-name");o.setAttribute("data-l10n-id",st._l10nResizer[c])}}w(this,Y,cp).call(this,0),m(this,tn,!0),l(this,he).firstChild.focus({focusVisible:!0}),t.preventDefault(),t.stopImmediatePropagation()}_resizeWithKeyboard(t,e){l(this,tn)&&w(this,Y,ap).call(this,l(this,wl),{deltaX:t,deltaY:e,fromKeyboard:!0})}_stopResizingWithKeyboard(){w(this,Y,Ec).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,xl)}set isEditing(t){m(this,xl,t),this.parent&&(t?(this.parent.setSelected(this),this.parent.setActiveEditor(this)):this.parent.setActiveEditor(null))}setAspectRatio(t,e){m(this,Yr,!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,As)||m(this,As,new Map);const{action:s}=t;let i=l(this,As).get(s);i&&clearTimeout(i),i=setTimeout(()=>{this._reportTelemetry(t),l(this,As).delete(s),l(this,As).size===0&&m(this,As,null)},st._telemetryTimeout),l(this,As).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,xa,!1)}disable(){this.div&&(this.div.tabIndex=-1),m(this,xa,!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()}};Ur=new WeakMap,Ys=new WeakMap,xt=new WeakMap,xa=new WeakMap,Yn=new WeakMap,_l=new WeakMap,Yr=new WeakMap,he=new WeakMap,$r=new WeakMap,Zi=new WeakMap,$n=new WeakMap,wl=new WeakMap,qr=new WeakMap,os=new WeakMap,xl=new WeakMap,Kr=new WeakMap,tn=new WeakMap,_i=new WeakMap,Sa=new WeakMap,Ca=new WeakMap,As=new WeakMap,Qr=new WeakMap,Sl=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()},Cl=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]}},bv=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,vv).bind(this,s),{signal:e}),i.addEventListener("contextmenu",Gs,{signal:e}),i.tabIndex=-1}this.div.prepend(l(this,he))},vv=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,$r,[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",is,{passive:!1,signal:r}),window.addEventListener("contextmenu",Gs,{signal:r}),m(this,Zi,{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,Zi))return;const{savedX:t,savedY:e,savedWidth:s,savedHeight:i}=l(this,Zi);m(this,Zi,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=st.MIN_SIZE/s,u=st.MIN_SIZE/i,d=w(this,Y,Rd).call(this,this.rotation),f=(I,H)=>[d[0]*I+d[2]*H,d[1]*I+d[3]*H],g=w(this,Y,Rd).call(this,360-this.rotation),p=(I,H)=>[g[0]*I+g[2]*H,g[1]*I+g[3]*H];let b,v,y=!1,x=!1;switch(t){case"topLeft":y=!0,b=(I,H)=>[0,0],v=(I,H)=>[I,H];break;case"topMiddle":b=(I,H)=>[I/2,0],v=(I,H)=>[I/2,H];break;case"topRight":y=!0,b=(I,H)=>[I,0],v=(I,H)=>[0,H];break;case"middleRight":x=!0,b=(I,H)=>[I,H/2],v=(I,H)=>[0,H/2];break;case"bottomRight":y=!0,b=(I,H)=>[I,H],v=(I,H)=>[0,0];break;case"bottomMiddle":b=(I,H)=>[I/2,H],v=(I,H)=>[I/2,0];break;case"bottomLeft":y=!0,b=(I,H)=>[0,H],v=(I,H)=>[I,0];break;case"middleLeft":x=!0,b=(I,H)=>[0,H/2],v=(I,H)=>[I,H/2];break}const S=b(o,h),C=v(o,h);let E=f(...C);const P=st._round(n+E[0]),M=st._round(r+E[1]);let O=1,R=1,L,N;if(e.fromKeyboard)({deltaX:L,deltaY:N}=e);else{const{screenX:I,screenY:H}=e,[it,kt]=l(this,$r);[L,N]=this.screenToPageTranslation(I-it,H-kt),l(this,$r)[0]=I,l(this,$r)[1]=H}if([L,N]=p(L/s,N/i),y){const I=Math.hypot(o,h);O=R=Math.max(Math.min(Math.hypot(C[0]-S[0]-L,C[1]-S[1]-N)/I,1/o,1/h),c/o,u/h)}else x?O=Math.max(c,Math.min(1,Math.abs(C[0]-S[0]-L)))/o:R=Math.max(u,Math.min(1,Math.abs(C[1]-S[1]-N)))/h;const D=st._round(o*O),F=st._round(h*R);E=f(...v(D,F));const j=P-E[0],q=M-E[1];l(this,os)||m(this,os,[this.x,this.y,this.width,this.height]),this.width=D,this.height=F,this.x=j,this.y=q,this.setDims(s*D,i*F),this.fixAndSetPosition(),this._onResizing()},yv=function(){var t;m(this,Zi,{savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height}),(t=l(this,xt))==null||t.toggle(!1),this.parent.togglePointerEvents(!1)},_v=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=(P,M)=>[r[0]*P+r[2]*M,r[1]*P+r[3]*M],[h,c]=this.parentDimensions,u=this.x,d=this.y,f=this.width,g=this.height,p=st.MIN_SIZE/h,b=st.MIN_SIZE/c;n=Math.max(Math.min(n,1/f,1/g),p/f,b/g);const v=st._round(f*n),y=st._round(g*n);if(v===f&&y===g)return;l(this,os)||m(this,os,[u,d,f,g]);const x=o(f/2,g/2),S=st._round(u+x[0]),C=st._round(d+x[1]),E=o(v/2,y/2);this.x=S-E[0],this.y=C-E[1],this.width=v,this.height=y,this.setDims(h*v,c*y),this.fixAndSetPosition(),this._onResizing()},wv=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)},xv=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,qr,!1),this._uiManager.endDragSession()||w(this,Y,hp).call(this,c),s&&this._onStopDragging()};e&&(m(this,Sa,t.clientX),m(this,Ca,t.clientY),m(this,Yn,t.pointerId),m(this,_l,t.pointerType),window.addEventListener("pointermove",c=>{s||(s=!0,this._onStartDragging());const{clientX:u,clientY:d,pointerId:f}=c;if(f!==l(this,Yn)){is(c);return}const[g,p]=this.screenToPageTranslation(u-l(this,Sa),d-l(this,Ca));m(this,Sa,u),m(this,Ca,d),this._uiManager.dragSelectedEditors(g,p)},r),window.addEventListener("touchmove",is,r),window.addEventListener("pointerdown",c=>{c.pointerType===l(this,_l)&&(l(this,Qr)||c.isPrimary)&&o(c),is(c)},r));const h=c=>{if(!l(this,Yn)||l(this,Yn)===c.pointerId){o(c);return}is(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})},Sv=function(t){st._resizerKeyboardManager.exec(this,t)},Cv=function(t){var e;l(this,tn)&&((e=t.relatedTarget)==null?void 0:e.parentNode)!==l(this,he)&&w(this,Y,Ec).call(this)},Av=function(t){m(this,wl,l(this,tn)?t:"")},cp=function(t){if(l(this,Ys))for(const e of l(this,Ys))e.tabIndex=t},Ec=function(){m(this,tn,!1),w(this,Y,cp).call(this,-1),w(this,Y,Ld).call(this)},_(st,Cl),$(st,"_l10n",null),$(st,"_l10nResizer",null),$(st,"_borderLineWidth",-1),$(st,"_colorManager",new vg),$(st,"_zIndex",1),$(st,"_telemetryTimeout",1e3);let Ot=st;class kx extends Ot{constructor(t){super(t),this.annotationElementId=t.annotationElementId,this.deleted=!0}serialize(){return this.serializeDeleted()}}const sb=3285377520,xs=4294901760,ui=65535;class ib{constructor(t){this.h1=t?t&4294967295:sb,this.h2=t?t&4294967295:sb}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 y=t.charCodeAt(b);y<=255?e[s++]=y:(e[s++]=y>>>8,e[s++]=y&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&ui,p=f&ui;for(let b=0;b<i;b++)b&1?(o=r[b],o=o*d&xs|o*g&ui,o=o<<15|o>>>17,o=o*f&xs|o*p&ui,c^=o,c=c<<13|c>>>19,c=c*5+3864292196):(h=r[b],h=h*d&xs|h*g&ui,h=h<<15|h>>>17,h=h*f&xs|h*p&ui,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&xs|o*g&ui,o=o<<15|o>>>17,o=o*f&xs|o*p&ui,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&xs|t*36045&ui,e=e*4283543511&xs|((e<<16|t>>>16)*2950163797&xs)>>>16,t^=e>>>1,t=t*444984403&xs|t*60499&ui,e=e*3301882366&xs|((e<<16|t>>>16)*3120437893&xs)>>>16,t^=e>>>1,(t>>>0).toString(16).padStart(8,"0")+(e>>>0).toString(16).padStart(8,"0")}}const yg=Object.freeze({map:null,hash:"",transfer:void 0});class _g{constructor(){_(this,fd);_(this,Jr,!1);_(this,Zr,null);_(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 Ot)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,Tv).call(this),e instanceof Ot&&typeof this.onAnnotationEditor=="function"&&this.onAnnotationEditor(e.constructor._type)}has(t){return l(this,ie).has(t)}getAll(){return l(this,ie).size>0?ag(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,Jr)&&(m(this,Jr,!1),typeof this.onResetModified=="function"&&this.onResetModified())}get print(){return new nb(this)}get serializable(){if(l(this,ie).size===0)return yg;const t=new Map,e=new ib,s=[],i=Object.create(null);let n=!1;for(const[r,o]of l(this,ie)){const h=o instanceof Ot?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}:yg}get editorStats(){let t=null;const e=new Map;for(const s of l(this,ie).values()){if(!(s instanceof Ot))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,Zr,null)}get modifiedIds(){if(l(this,Zr))return l(this,Zr);const t=[];for(const e of l(this,ie).values())!(e instanceof Ot)||!e.annotationElementId||!e.serialize()||t.push(e.annotationElementId);return m(this,Zr,{ids:new Set(t),hash:t.join(",")})}}Jr=new WeakMap,Zr=new WeakMap,ie=new WeakMap,fd=new WeakSet,Tv=function(){l(this,Jr)||(m(this,Jr,!0),typeof this.onSetModified=="function"&&this.onSetModified())};class nb extends _g{constructor(e){super();_(this,Al);const{map:s,hash:i,transfer:n}=e.serializable,r=structuredClone(s,n?{transfer:n}:null);m(this,Al,{map:r,hash:i,transfer:n})}get print(){yt("Should not call PrintAnnotationStorage.print")}get serializable(){return l(this,Al)}get modifiedIds(){return nt(this,"modifiedIds",{ids:new Set,hash:""})}}Al=new WeakMap;class Mx{constructor({ownerDocument:t=globalThis.document,styleElement:e=null}){_(this,Aa,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,Aa).clear(),this.styleElement&&(this.styleElement.remove(),this.styleElement=null)}async loadSystemFont({systemFontInfo:t,_inspectFont:e}){if(!(!t||l(this,Aa).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,Aa).add(s),e==null||e(t)}catch{et(`Cannot load system font: ${t.baseFontName}, installing it could help to improve PDF rendering.`),this.removeNativeFontFace(r)}return}yt("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 et(`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 nt(this,"isFontLoadingAPISupported",t)}get isSyncFontLoadingSupported(){let t=!1;return(ve||typeof navigator<"u"&&typeof(navigator==null?void 0:navigator.userAgent)=="string"&&/Mozilla\/5.0.*?rv:\d+.*? Gecko/.test(navigator.userAgent))&&(t=!0),nt(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 nt(this,"_loadTestFont",t)}_prepareFontLoadEvent(t,e){function s(C,E){return C.charCodeAt(E)<<24|C.charCodeAt(E+1)<<16|C.charCodeAt(E+2)<<8|C.charCodeAt(E+3)&255}function i(C,E,P,M){const O=C.substring(0,E),R=C.substring(E+P);return O+M+R}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(C,E){if(++c>30){et("Load test font never loaded."),E();return}if(h.font="30px "+C,h.fillText(".",0,20),h.getImageData(0,0,1,1).data[3]>0){E();return}setTimeout(u.bind(null,C,E))}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,gx(v));const y=`url(data:font/opentype;base64,${btoa(f)});`,x=`@font-face {font-family:"${d}";src:${y}}`;this.insertRule(x);const S=this._document.createElement("div");S.style.visibility="hidden",S.style.width=S.style.height="10px",S.style.position="absolute",S.style.top=S.style.left="0px";for(const C of[t.loadedName,d]){const E=this._document.createElement("span");E.textContent="Hi",E.style.fontFamily=C,S.append(E)}this._document.body.append(S),u(d,()=>{S.remove(),e.complete()})}}Aa=new WeakMap;class Px{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,${_x(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){et(`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 rb(){}function We(a){if(a instanceof Rn||a instanceof og||a instanceof Gh||a instanceof J0||a instanceof Xu||a instanceof rg)return a;switch(a instanceof Error||typeof a=="object"&&a!==null||yt('wrapReason: Expected "reason" to be a (possibly cloned) Error.'),a.name){case"AbortException":return new Rn(a.message);case"InvalidPDFException":return new og(a.message);case"MissingPDFException":return new Gh(a.message);case"PasswordException":return new J0(a.message,a.code);case"UnexpectedResponseException":return new Xu(a.message,a.status);case"UnknownErrorException":return new rg(a.message,a.details)}return new rg(a.message,a.toString())}class Uh{constructor(t,e,s){_(this,Ts);_(this,Ta,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,Ts,Ev).bind(this),{signal:l(this,Ta).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,Ta))==null||t.abort(),m(this,Ta,null)}}Ta=new WeakMap,Ts=new WeakSet,Ev=function({data:t}){if(t.targetName!==this.sourceName)return;if(t.stream){w(this,Ts,Mv).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,Ts,kv).call(this,t);return}e(t.data)},kv=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)})})},Mv=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||rb).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,Ts,Fd).call(this,r,e);break;case Wt.ERROR:Xt(r,"error should have stream controller"),r.controller.error(We(t.reason)),w(this,Ts,Fd).call(this,r,e);break;case Wt.CANCEL_COMPLETE:t.success?r.cancelCall.resolve():r.cancelCall.reject(We(t.reason)),w(this,Ts,Fd).call(this,r,e);break;case Wt.CANCEL:if(!o)break;const h=We(t.reason);Promise.try(o.onCancel||rb,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 ob{constructor({enableHWA:t=!1}){_(this,Tl,!1);m(this,Tl,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,Tl)})}}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){yt("Abstract method `_createCanvas` called.")}}Tl=new WeakMap;class Ox extends ob{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 ab{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){yt("Abstract method `_fetch` called.")}}class hb extends ab{async _fetch(t){const e=await Uu(t,this.isCompressed?"arraybuffer":"text");return e instanceof ArrayBuffer?new Uint8Array(e):Wu(e)}}class lb{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 Dx extends lb{constructor({docId:e,ownerDocument:s=globalThis.document}){super();_(this,G);_(this,to);_(this,Ea);_(this,en);_(this,sn);_(this,xe);_(this,eo);_(this,so,0);m(this,sn,e),m(this,xe,s)}addFilter(e){if(!e)return"none";let s=l(this,G,Te).get(e);if(s)return s;const[i,n,r]=w(this,G,Id).call(this,e),o=e.length===1?i:`${i}${n}${r}`;if(s=l(this,G,Te).get(o),s)return l(this,G,Te).set(e,s),s;const h=`g_${l(this,sn)}_transfer_map_${ze(this,so)._++}`,c=w(this,G,yh).call(this,h);l(this,G,Te).set(e,c),l(this,G,Te).set(o,c);const u=w(this,G,_h).call(this,h);return w(this,G,Pc).call(this,i,n,r,u),c}addHCMFilter(e,s){var p;const i=`${e}-${s}`,n="base";let r=l(this,G,kc).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,G,kc).set(n,r)),!e||!s))return r.url;const o=w(this,G,Oc).call(this,e);e=U.makeHexColor(...o);const h=w(this,G,Oc).call(this,s);if(s=U.makeHexColor(...h),l(this,G,vh).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,sn)}_hcm_filter`,f=r.filter=w(this,G,_h).call(this,d);w(this,G,Pc).call(this,u,u,u,f),w(this,G,up).call(this,f);const g=(b,v)=>{const y=o[b]/255,x=h[b]/255,S=new Array(v+1);for(let C=0;C<=v;C++)S[C]=y+C/v*(x-y);return S.join(",")};return w(this,G,Pc).call(this,g(0,5),g(1,5),g(2,5),f),r.url=w(this,G,yh).call(this,d),r.url}addAlphaFilter(e){let s=l(this,G,Te).get(e);if(s)return s;const[i]=w(this,G,Id).call(this,[e]),n=`alpha_${i}`;if(s=l(this,G,Te).get(n),s)return l(this,G,Te).set(e,s),s;const r=`g_${l(this,sn)}_alpha_map_${ze(this,so)._++}`,o=w(this,G,yh).call(this,r);l(this,G,Te).set(e,o),l(this,G,Te).set(n,o);const h=w(this,G,_h).call(this,r);return w(this,G,dp).call(this,i,h),o}addLuminosityFilter(e){let s=l(this,G,Te).get(e||"luminosity");if(s)return s;let i,n;if(e?([i]=w(this,G,Id).call(this,[e]),n=`luminosity_${i}`):n="luminosity",s=l(this,G,Te).get(n),s)return l(this,G,Te).set(e,s),s;const r=`g_${l(this,sn)}_luminosity_map_${ze(this,so)._++}`,o=w(this,G,yh).call(this,r);l(this,G,Te).set(e,o),l(this,G,Te).set(n,o);const h=w(this,G,_h).call(this,r);return w(this,G,Pv).call(this,h),e&&w(this,G,dp).call(this,i,h),o}addHighlightHCMFilter(e,s,i,n,r){var x;const o=`${s}-${i}-${n}-${r}`;let h=l(this,G,kc).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,G,kc).set(e,h)),!s||!i))return h.url;const[c,u]=[s,i].map(w(this,G,Oc).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,G,Oc).bind(this));f<d&&([d,f,g,p]=[f,d,p,g]),l(this,G,vh).style.color="";const b=(S,C,E)=>{const P=new Array(256),M=(f-d)/E,O=S/255,R=(C-S)/(255*E);let L=0;for(let N=0;N<=E;N++){const D=Math.round(d+N*M),F=O+N*R;for(let j=L;j<=D;j++)P[j]=F;L=D+1}for(let N=L;N<256;N++)P[N]=P[L-1];return P.join(",")},v=`g_${l(this,sn)}_hcm_${e}_filter`,y=h.filter=w(this,G,_h).call(this,v);return w(this,G,up).call(this,y),w(this,G,Pc).call(this,b(g[0],p[0],5),b(g[1],p[1],5),b(g[2],p[2],5),y),h.url=w(this,G,yh).call(this,v),h.url}destroy(e=!1){var s,i,n,r;e&&((s=l(this,eo))!=null&&s.size)||((i=l(this,en))==null||i.parentNode.parentNode.remove(),m(this,en,null),(n=l(this,Ea))==null||n.clear(),m(this,Ea,null),(r=l(this,eo))==null||r.clear(),m(this,eo,null),m(this,so,0))}}to=new WeakMap,Ea=new WeakMap,en=new WeakMap,sn=new WeakMap,xe=new WeakMap,eo=new WeakMap,so=new WeakMap,G=new WeakSet,Te=function(){return l(this,Ea)||m(this,Ea,new Map)},kc=function(){return l(this,eo)||m(this,eo,new Map)},vh=function(){if(!l(this,en)){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(Vi,"svg");i.setAttribute("width",0),i.setAttribute("height",0),m(this,en,l(this,xe).createElementNS(Vi,"defs")),e.append(i),i.append(l(this,en)),l(this,xe).body.append(e)}return l(this,en)},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(",")]},yh=function(e){if(l(this,to)===void 0){m(this,to,"");const s=l(this,xe).URL;s!==l(this,xe).baseURI&&(Yu(s)?et('#createUrl: ignore "data:"-URL for performance reasons.'):m(this,to,s.split("#",1)[0]))}return`url(${l(this,to)}#${e})`},Pv=function(e){const s=l(this,xe).createElementNS(Vi,"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(Vi,"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)},_h=function(e){const s=l(this,xe).createElementNS(Vi,"filter");return s.setAttribute("color-interpolation-filters","sRGB"),s.setAttribute("id",e),l(this,G,vh).append(s),s},Mc=function(e,s,i){const n=l(this,xe).createElementNS(Vi,s);n.setAttribute("type","discrete"),n.setAttribute("tableValues",i),e.append(n)},Pc=function(e,s,i,n){const r=l(this,xe).createElementNS(Vi,"feComponentTransfer");n.append(r),w(this,G,Mc).call(this,r,"feFuncR",e),w(this,G,Mc).call(this,r,"feFuncG",s),w(this,G,Mc).call(this,r,"feFuncB",i)},dp=function(e,s){const i=l(this,xe).createElementNS(Vi,"feComponentTransfer");s.append(i),w(this,G,Mc).call(this,i,"feFuncA",e)},Oc=function(e){return l(this,G,vh).style.color=e,gg(getComputedStyle(l(this,G,vh)).getPropertyValue("color"))};class cb{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){yt("Abstract method `_fetch` called.")}}class ub extends cb{async _fetch(t){const e=await Uu(t,"arraybuffer");return new Uint8Array(e)}}ve&&et("Please use the `legacy` build in Node.js environments.");async function db(a){const e=await process.getBuiltinModule("fs").promises.readFile(a);return new Uint8Array(e)}class Rx extends lb{}class Lx extends ob{_createCanvas(t,e){return process.getBuiltinModule("module").createRequire(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Mt&&Mt.tagName.toUpperCase()==="SCRIPT"&&Mt.src||new URL("pdf-canvas.umd.js",document.baseURI).href)("@napi-rs/canvas").createCanvas(t,e)}}class Fx extends ab{async _fetch(t){return db(t)}}class Ix extends cb{async _fetch(t){return db(t)}}const _e={FILL:"Fill",STROKE:"Stroke",SHADING:"Shading"};function wg(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 xg{getPattern(){yt("Abstract method `getPattern` called.")}}class Nx extends xg{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,At(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=U.transform(s,[1,0,0,1,r[0],r[1]]),u.transform(...e.baseTransform),this.matrix&&u.transform(...this.matrix),wg(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 wg(t,this._bbox),n=this._createGradient(t);return n}}function Sg(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,y=(h[i]+t.offsetX)*t.scaleX,x=(h[i+1]+t.offsetY)*t.scaleY;if(p>=x)return;const S=c[n],C=c[n+1],E=c[n+2],P=c[r],M=c[r+1],O=c[r+2],R=c[o],L=c[o+1],N=c[o+2],D=Math.round(p),F=Math.round(x);let j,q,I,H,it,kt,te,fe;for(let Yt=D;Yt<=F;Yt++){if(Yt<v){const ft=Yt<p?0:(p-Yt)/(p-v);j=g-(g-b)*ft,q=S-(S-P)*ft,I=C-(C-M)*ft,H=E-(E-O)*ft}else{let ft;Yt>x?ft=1:v===x?ft=0:ft=(v-Yt)/(v-x),j=b-(b-y)*ft,q=P-(P-R)*ft,I=M-(M-L)*ft,H=O-(O-N)*ft}let St;Yt<p?St=0:Yt>x?St=1:St=(p-Yt)/(p-x),it=g-(g-y)*St,kt=S-(S-R)*St,te=C-(C-L)*St,fe=E-(E-N)*St;const He=Math.round(Math.min(j,it)),Pi=Math.round(Math.max(j,it));let It=d*Yt+He*4;for(let ft=He;ft<=Pi;ft++)St=(j-ft)/(j-it),St<0?St=0:St>1&&(St=1),u[It++]=q-(q-kt)*St|0,u[It++]=I-(I-te)*St|0,u[It++]=H-(H-fe)*St|0,u[It++]=255}}function jx(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++)Sg(a,e,s[u],s[u+1],s[u+o],i[u],i[u+1],i[u+o]),Sg(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)Sg(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 Bx extends xg{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,y=f+2*2,x=s.getCanvas("mesh",v,y),S=x.context,C=S.createImageData(d,f);if(e){const P=C.data;for(let M=0,O=P.length;M<O;M+=4)P[M]=e[0],P[M+1]=e[1],P[M+2]=e[2],P[M+3]=255}for(const P of this._figures)jx(C,P,b);return S.putImageData(C,2,2),{canvas:x.canvas,offsetX:o-2*g,offsetY:h-2*p,scaleX:g,scaleY:p}}getPattern(t,e,s,i){wg(t,this._bbox);let n;if(i===_e.SHADING)n=U.singularValueDecompose2dScale(At(t));else if(n=U.singularValueDecompose2dScale(e.baseTransform),this.matrix){const o=U.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 Hx extends xg{getPattern(){return"hotpink"}}function zx(a){switch(a[0]){case"RadialAxial":return new Nx(a);case"Mesh":return new Bx(a);case"Dummy":return new Hx}throw new Error(`Unknown IR type: ${a[0]}`)}const fb={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=U.singularValueDecompose2dScale(this.matrix),y=U.singularValueDecompose2dScale(this.baseTransform),x=v[0]*y[0],S=v[1]*y[1];let C=p,E=b,P=!1,M=!1;const O=Math.ceil(h*x),R=Math.ceil(c*S),L=Math.ceil(p*x),N=Math.ceil(b*S);O>=L?C=h:P=!0,R>=N?E=c:M=!0;const D=this.getSizeAndScale(C,this.ctx.canvas.width,x),F=this.getSizeAndScale(E,this.ctx.canvas.height,S),j=t.cachedCanvases.getCanvas("pattern",D.size,F.size),q=j.context,I=o.createCanvasGraphics(q);if(I.groupLevel=t.groupLevel,this.setFillAndStrokeStyleToContext(I,i,r),q.translate(-D.scale*u,-F.scale*d),I.transform(D.scale,0,0,F.scale,0,0),q.save(),this.clipBbox(I,u,d,f,g),I.baseTransform=At(I.ctx),I.executeOperatorList(s),I.endDrawing(),q.restore(),P||M){const H=j.canvas;P&&(C=h),M&&(E=c);const it=this.getSizeAndScale(C,this.ctx.canvas.width,x),kt=this.getSizeAndScale(E,this.ctx.canvas.height,S),te=it.size,fe=kt.size,Yt=t.cachedCanvases.getCanvas("pattern-workaround",te,fe),St=Yt.context,He=P?Math.floor(p/h):0,Pi=M?Math.floor(b/c):0;for(let It=0;It<=He;It++)for(let ft=0;ft<=Pi;ft++)St.drawImage(H,te*It,fe*ft,te,fe,0,0,te,fe);return{canvas:Yt.canvas,scaleX:it.scale,scaleY:kt.scale,offsetX:u,offsetY:d}}return{canvas:j.canvas,scaleX:D.scale,scaleY:F.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(At(t.ctx),[e,s,i,n]),t.clip(),t.endPath()}setFillAndStrokeStyleToContext(t,e,s){const i=t.ctx,n=t.current;switch(e){case fb.COLORED:const r=this.ctx;i.fillStyle=r.fillStyle,i.strokeStyle=r.strokeStyle,n.fillColor=r.fillStyle,n.strokeColor=r.strokeStyle;break;case fb.UNCOLORED:const o=U.makeHexColor(s[0],s[1],s[2]);i.fillStyle=o,i.strokeStyle=o,n.fillColor=o,n.strokeColor=o;break;default:throw new fx(`Unsupported paint type: ${e}`)}}getPattern(t,e,s,i){let n=s;i!==_e.SHADING&&(n=U.transform(n,e.baseTransform),this.matrix&&(n=U.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 Cg=gd;function Gx({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 y=t<f?a[t]:255;e[g++]=y&128?c:h,e[g++]=y&64?c:h,e[g++]=y&32?c:h,e[g++]=y&16?c:h,e[g++]=y&8?c:h,e[g++]=y&4?c:h,e[g++]=y&2?c:h,e[g++]=y&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 gb=16,pb=100,Vx=15,mb=10,bb=1e3,Ue=16;function Xx(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 Wx{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]=At(a);if(d===0&&f===0){const x=r*u+p,S=Math.round(x),C=o*g+b,E=Math.round(C),P=(r+h)*u+p,M=Math.abs(Math.round(P)-S)||1,O=(o+c)*g+b,R=Math.abs(Math.round(O)-E)||1;return a.setTransform(Math.sign(u),0,0,Math.sign(g),S,E),a.drawImage(t,e,s,i,n,0,0,M,R),a.setTransform(u,d,f,g,p,b),[M,R]}if(u===0&&g===0){const x=o*f+p,S=Math.round(x),C=r*d+b,E=Math.round(C),P=(o+c)*f+p,M=Math.abs(Math.round(P)-S)||1,O=(r+h)*d+b,R=Math.abs(Math.round(O)-E)||1;return a.setTransform(0,Math.sign(d),Math.sign(f),0,S,E),a.drawImage(t,e,s,i,n,0,0,R,M),a.setTransform(u,d,f,g,p,b),[R,M]}a.drawImage(t,e,s,i,n,r,o,h,c);const v=Math.hypot(u,d),y=Math.hypot(f,g);return[v*h,y*c]}function Ux(a){const{width:t,height:e}=a;if(t>bb||e>bb)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 y of a.data){let x=128;for(;x>0;)d[f++]=y&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 y=(d[f]?4:0)+(d[f-u]?8:0);for(h=1;h<t;h++)y=(y>>2)+(d[f+1]?4:0)+(d[f-u+1]?8:0),i[y]&&(r[c+h]=i[y],++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 y=o*n;const x=y+t;for(;y<x&&!r[y];)y++;if(y===x)continue;b.moveTo(y%n,o);const S=y;let C=r[y];do{const E=p[C];do y+=E;while(!r[y]);const P=r[y];P!==5&&P!==10?(C=P,r[y]=0):(C=P&51*C>>4,r[y]&=C>>2|C<<2),b.lineTo(y%n,y/n|0),r[y]||--g}while(S!==y);--o}return d=null,r=null,function(y){y.save(),y.scale(1/t,-1/e),y.translate(0,-e),y.fill(b),y.beginPath(),y.restore()}}class vb{constructor(t,e){this.alphaIsShape=!1,this.fontSize=0,this.fontSizeScale=1,this.textMatrix=Q0,this.textMatrixScale=1,this.fontMatrix=ig,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=ye.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]=U.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=U.applyTransform(e,t),i=U.applyTransform(e.slice(2),t),n=U.applyTransform([e[0],e[3]],t),r=U.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){U.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=U.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||yt("Stroke bounding box must include transform.");const i=U.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=U.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 U.intersect(this.clipBox,this.getPathBoundingBox(t,e))}}function yb(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,y=new Uint32Array(d.buffer,0,d.byteLength>>2),x=y.length,S=s+7>>3,C=4294967295,E=Re.isLittleEndian?4278190080:255;for(f=0;f<r;f++){for(p=f<n?Ue:i,c=0,g=0;g<p;g++){const P=v-h;let M=0;const O=P>S?s:P*8-7,R=O&-8;let L=0,N=0;for(;M<R;M+=8)N=u[h++],y[c++]=N&128?C:E,y[c++]=N&64?C:E,y[c++]=N&32?C:E,y[c++]=N&16?C:E,y[c++]=N&8?C:E,y[c++]=N&4?C:E,y[c++]=N&2?C:E,y[c++]=N&1?C:E;for(;M<O;M++)L===0&&(N=u[h++],L=128),y[c++]=N&L?C:E,L>>=1}for(;c<x;)y[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 _b(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}=Gx({src:c,srcPos:h,dest:u,width:s,height:f,nonBlackColor:0})),a.putImageData(o,0,d*Ue)}}function Yh(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),!ve){const{filter:t}=a;t!=="none"&&t!==""&&(a.filter="none")}}function wb(a,t){if(t)return!0;const e=U.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 Yx=["butt","round","square"],$x=["miter","round","bevel"],qx={},xb={},Xg=class Xg{constructor(t,e,s,i,n,{optionalContentConfig:r,markedContentStack:o=null},h,c){_(this,$s);this.ctx=t,this.current=new vb(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 Wx(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(...At(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=At(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>mb&&typeof s=="function",u=c?Date.now()+Vx: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!==zs.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>mb){if(Date.now()>u)return s(),o;d=0}}}endDrawing(){w(this,$s,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,$s,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=At(e);let h,c,u,d;if((t.bitmap||t.data)&&t.count>1){const O=t.bitmap||t.data.buffer;c=JSON.stringify(r?o:[o.slice(0,4),n]),h=this._cachedBitmapsMap.get(O),h||(h=new Map,this._cachedBitmapsMap.set(O,h));const R=h.get(c);if(R&&!r){const L=Math.round(Math.min(o[0],o[2])+o[4]),N=Math.round(Math.min(o[1],o[3])+o[5]);return{canvas:R,offsetX:L,offsetY:N}}u=R}u||(d=this.cachedCanvases.getCanvas("maskCanvas",s,i),_b(d.context,t));let f=U.transform(o,[1/s,0,0,-1/i,0,0]);f=U.transform(f,[1,0,0,1,0,-i]);const[g,p,b,v]=U.getAxialAlignedBoundingBox([0,0,s,i],f),y=Math.round(b-g)||1,x=Math.round(v-p)||1,S=this.cachedCanvases.getCanvas("fillCanvas",y,x),C=S.context,E=g,P=p;C.translate(-E,-P),C.transform(...f),u||(u=this._scaleImage(d.canvas,ci(C)),u=u.img,h&&r&&h.set(c,u)),C.imageSmoothingEnabled=wb(At(C),t.interpolate),Ju(C,u,0,0,u.width,u.height,0,0,s,i),C.globalCompositeOperation="source-in";const M=U.transform(ci(C),[1,0,0,1,-E,-P]);return C.fillStyle=r?n.getPattern(e,this,M,_e.FILL):n,C.fillRect(0,0,s,i),h&&!r&&(this.cachedCanvases.delete("fillCanvas"),h.set(c,S.canvas)),{canvas:S.canvas,offsetX:Math.round(E),offsetY:Math.round(P)}}setLineWidth(t){t!==this.current.lineWidth&&(this._cachedScaleForStroking[0]=-1),this.current.lineWidth=t,this.ctx.lineWidth=t}setLineCap(t){this.ctx.lineCap=Yx[t]}setLineJoin(t){this.ctx.lineJoin=$x[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(...At(this.suspendedCtx)),Yh(this.suspendedCtx,n),Xx(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(),Yh(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=U.makeHexColor(...r);if(g<0||p<0||g+s>f.width||p+i>f.height){const y=this.cachedCanvases.getCanvas("maskExtension",s,i),x=y.context;x.drawImage(f,-g,-p),x.globalCompositeOperation="destination-atop",x.fillStyle=v,x.fillRect(0,0,s,i),x.globalCompositeOperation="source-over",f=y.canvas,g=p=0}else{t.save(),t.globalAlpha=1,t.setTransform(1,0,0,1,0,0);const y=new Path2D;y.rect(g,p,s,i),t.clip(y),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?(Yh(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(),Yh(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=At(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 zs.rectangle:r=e[p++],o=e[p++];const v=e[p++],y=e[p++],x=r+v,S=o+y;i.moveTo(r,o),v===0||y===0?i.lineTo(x,S):(i.lineTo(x,o),i.lineTo(x,S),i.lineTo(r,S)),d||n.updateRectMinMax(u,[r,o,x,S]),i.closePath();break;case zs.moveTo:r=e[p++],o=e[p++],i.moveTo(r,o),d||n.updatePathMinMax(u,r,o);break;case zs.lineTo:r=e[p++],o=e[p++],i.lineTo(r,o),d||n.updatePathMinMax(u,r,o);break;case zs.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 zs.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 zs.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 zs.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,ci(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,ci(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=qx}eoClip(){this.pendingClip=xb}beginText(){this.current.textMatrix=Q0,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||ig,(i.fontMatrix[0]===0||i.fontMatrix[3]===0)&&et("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<gb?c=gb:e>pb&&(c=pb),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&ye.FILL_STROKE_MASK,f=!!(c&ye.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===ye.FILL||d===ye.FILL_STROKE)if(i){const v=r.getTransform();r.setTransform(...i),r.fill(w(this,$s,pp).call(this,b,v,i))}else r.fill(b);if(d===ye.STROKE||d===ye.FILL_STROKE)if(n){const v=r.getTransform();r.setTransform(...n),r.stroke(w(this,$s,pp).call(this,b,v,n))}else r.lineWidth/=u,r.stroke(b);r.restore()}else(d===ye.FILL||d===ye.FILL_STROKE)&&r.fillText(t,e,s),(d===ye.STROKE||d===ye.FILL_STROKE)&&r.strokeText(t,e,s);f&&(this.pendingTextPaths||(this.pendingTextPaths=[])).push({transform:At(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 nt(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===ye.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 y,x;if(e.patternFill){n.save();const M=e.fillColor.getPattern(n,this,ci(n),_e.FILL);y=At(n),n.restore(),n.fillStyle=M}if(e.patternStroke){n.save();const M=e.strokeColor.getPattern(n,this,ci(n),_e.STROKE);x=At(n),n.restore(),n.strokeStyle=M}let S=e.lineWidth;const C=e.textMatrixScale;if(C===0||S===0){const M=e.textRenderingMode&ye.FILL_STROKE_MASK;(M===ye.STROKE||M===ye.FILL_STROKE)&&(S=this.getSinglePixelWidth())}else S/=C;if(r!==1&&(n.scale(r,r),S/=r),n.lineWidth=S,s.isInvalidPDFjsFont){const M=[];let O=0;for(const R of t)M.push(R.unicode),O+=R.width;n.fillText(M.join(""),0,0),e.x+=O*b*u,n.restore(),this.compose();return}let E=0,P;for(P=0;P<d;++P){const M=t[P];if(typeof M=="number"){E+=g*M*i/1e3;continue}let O=!1;const R=(M.isSpace?h:0)+o,L=M.fontChar,N=M.accent;let D,F,j=M.width;if(f){const I=M.vmetric||p,H=-(M.vmetric?I[1]:j*.5)*b,it=I[2]*b;j=I?-I[0]:j,D=H/r,F=(E+it)/r}else D=E/r,F=0;if(s.remeasure&&j>0){const I=n.measureText(L).width*1e3/i*r;if(j<I&&this.isFontSubpixelAAEnabled){const H=j/I;O=!0,n.save(),n.scale(H,1),D/=H}else j!==I&&(D+=(j-I)/2e3*i/r)}if(this.contentVisible&&(M.isInFont||s.missingFile)){if(v&&!N)n.fillText(L,D,F);else if(this.paintChar(L,D,F,y,x),N){const I=D+i*N.offset.x/r,H=F-i*N.offset.y/r;this.paintChar(N.fontChar,I,H,y,x)}}const q=f?j*b-R*c:j*b+R*c;E+=q,O&&n.restore()}f?e.y-=E:e.x+=E*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||ig,f=t.length,g=s.textRenderingMode===ye.INVISIBLE;let p,b,v,y;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"){y=o*b*n/1e3,this.ctx.translate(y,0),s.x+=y*u;continue}const x=(b.isSpace?c:0)+h,S=i.charProcOperatorList[b.operatorListId];if(!S){et(`Type3 character "${b.operatorListId}" is not available.`);continue}this.contentVisible&&(this.processingType3=b,this.save(),e.scale(n,n),e.transform(...d),this.executeOperatorList(S),this.restore()),v=U.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||At(this.ctx),n={createCanvasGraphics:r=>new Xg(r,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:this.optionalContentConfig,markedContentStack:this.markedContentStack})};e=new Cg(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=U.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=U.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=zx(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,ci(e),_e.SHADING);const i=ci(e);if(i){const{width:n,height:r}=e.canvas,[o,h,c,u]=U.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(){yt("Should not call beginInlineImage")}beginImageData(){yt("Should not call beginImageData")}paintFormXObjectBegin(t,e){if(this.contentVisible&&(this.save(),this.baseTransformStack.push(this.baseTransform),t&&this.transform(...t),this.baseTransform=At(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(At(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&&et("Knockout groups not supported.");const s=At(e);if(t.matrix&&e.transform(...t.matrix),!t.bbox)throw new Error("Bounding box is required.");let i=U.getAxialAlignedBoundingBox(t.bbox,At(e));const n=[0,0,e.canvas.width,e.canvas.height];i=U.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()),Yh(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=At(this.ctx);this.restore(),this.ctx.save(),this.ctx.setTransform(...i);const n=U.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,$s,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]=U.singularValueDecompose2dScale(At(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 vb(this.ctx.canvas.width,this.ctx.canvas.height),this.transform(...s),this.transform(...i)}endAnnotation(){this.annotationCanvas&&(this.ctx.restore(),w(this,$s,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=Ux(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=At(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=U.transform(h,[e,s,i,n,r[u],r[u+1]]),[g,p]=U.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);_b(d,f),d.globalCompositeOperation="source-in",d.fillStyle=i?s.getPattern(d,this,ci(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){et("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){et("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(),!ve){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;yb(h,t),n=this.applyTransferMapsToCanvas(h)}const r=this._scaleImage(n,ci(i));i.imageSmoothingEnabled=wb(At(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;yb(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===xb?s.clip("evenodd"):s.clip()),this.pendingClip=null),this.current.startNewPathAndClipBox(this.current.clipBox),s.beginPath()}getSinglePixelWidth(){if(!this._cachedGetSinglePixelWidth){const t=At(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}};$s=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 aa=Xg;for(const a in zs)aa.prototype[a]!==void 0&&(aa.prototype[zs[a]]=aa.prototype[a]);class Xi{static get workerPort(){return l(this,El)}static set workerPort(t){if(!(typeof Worker<"u"&&t instanceof Worker)&&t!==null)throw new Error("Invalid `workerPort` type.");m(this,El,t)}static get workerSrc(){return l(this,kl)}static set workerSrc(t){if(typeof t!="string")throw new Error("Invalid `workerSrc` type.");m(this,kl,t)}}El=new WeakMap,kl=new WeakMap,_(Xi,El,null),_(Xi,kl,"");class Kx{constructor({parsedData:t,rawData:e}){_(this,io);_(this,Ml);m(this,io,t),m(this,Ml,e)}getRaw(){return l(this,Ml)}get(t){return l(this,io).get(t)??null}getAll(){return ag(l(this,io))}has(t){return l(this,io).has(t)}}io=new WeakMap,Ml=new WeakMap;const ha=Symbol("INTERNAL");class Qx{constructor(t,{name:e,intent:s,usage:i,rbGroups:n}){_(this,Pl,!1);_(this,Ol,!1);_(this,Dl,!1);_(this,ka,!0);m(this,Pl,!!(t&ss.DISPLAY)),m(this,Ol,!!(t&ss.PRINT)),this.name=e,this.intent=s,this.usage=i,this.rbGroups=n}get visible(){if(l(this,Dl))return l(this,ka);if(!l(this,ka))return!1;const{print:t,view:e}=this.usage;return l(this,Pl)?(e==null?void 0:e.viewState)!=="OFF":l(this,Ol)?(t==null?void 0:t.printState)!=="OFF":!0}_setVisible(t,e,s=!1){t!==ha&&yt("Internal method `_setVisible` called."),m(this,Dl,s),m(this,ka,e)}}Pl=new WeakMap,Ol=new WeakMap,Dl=new WeakMap,ka=new WeakMap;class Jx{constructor(t,e=ss.DISPLAY){_(this,Rl);_(this,qn,null);_(this,mt,new Map);_(this,Ma,null);_(this,Pa,null);if(this.renderingIntent=e,this.name=null,this.creator=null,t!==null){this.name=t.name,this.creator=t.creator,m(this,Pa,t.order);for(const s of t.groups)l(this,mt).set(s.id,new Qx(e,s));if(t.baseState==="OFF")for(const s of l(this,mt).values())s._setVisible(ha,!1);for(const s of t.on)l(this,mt).get(s)._setVisible(ha,!0);for(const s of t.off)l(this,mt).get(s)._setVisible(ha,!1);m(this,Ma,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:(et(`Optional content group not found: ${t.id}`),!0);if(t.type==="OCMD"){if(t.expression)return w(this,Rl,mp).call(this,t.expression);if(!t.policy||t.policy==="AnyOn"){for(const e of t.ids){if(!l(this,mt).has(e))return et(`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 et(`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 et(`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 et(`Optional content group not found: ${e}`),!0;if(l(this,mt).get(e).visible)return!1}return!0}return et(`Unknown optional content policy ${t.policy}.`),!0}return et(`Unknown group type ${t.type}.`),!0}setVisibility(t,e=!0,s=!0){var n;const i=l(this,mt).get(t);if(!i){et(`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(ha,!1,!0));i._setVisible(ha,!!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,Ma)===null||this.getHash()===l(this,Ma)}getOrder(){return l(this,mt).size?l(this,Pa)?l(this,Pa).slice():[...l(this,mt).keys()]:null}getGroups(){return l(this,mt).size>0?ag(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 ib;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,Ma=new WeakMap,Pa=new WeakMap,Rl=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,Rl,mp).call(this,n);else if(l(this,mt).has(n))r=l(this,mt).get(n).visible;else return et(`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 Zx{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 tS(this,t,this._progressiveDone,this._contentDispositionFilename)}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new eS(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 tS{constructor(t,e,s=!1,i=null){this._stream=t,this._done=s||!1,this._filename=dg(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 eS{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 sS(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,y]=f;if(b=parseInt(b,10),b in d){if(b===0)break;continue}d[b]=[v,y]}const p=[];for(let b=0;b<d.length&&b in d;++b){let[v,y]=d[b];y=o(y),v&&(y=unescape(y),b===0&&(y=h(y))),p.push(y)}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 Sb(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 Cb({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 Ab(a){const t=a.get("Content-Disposition");if(t){let e=sS(t);if(e.includes("%"))try{e=decodeURIComponent(e)}catch{}if(dg(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 Tb(a){return a===200||a===206}function Eb(a,t,e){return{method:"GET",headers:a,signal:e.signal,mode:"cors",credentials:t?"include":"same-origin",redirect:"follow"}}function kb(a){return a instanceof Uint8Array?a.buffer:a instanceof ArrayBuffer?a:(et(`getArrayBuffer - unexpected data format: ${a}`),new Uint8Array(a).buffer)}class Mb{constructor(t){$(this,"_responseOrigin",null);this.source=t,this.isHttp=/^https?:/i.test(t.url),this.headers=Sb(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 iS(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new nS(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 iS{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,Eb(s,this._withCredentials,this._abortController)).then(n=>{if(t._responseOrigin=td(n.url),!Tb(n.status))throw ed(n.status,i);this._reader=n.body.getReader(),this._headersCapability.resolve();const r=n.headers,{allowRangeRequests:o,suggestedLength:h}=Cb({responseHeaders:r,isHttp:t.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});this._isRangeSupported=o,this._contentLength=h||this._contentLength,this._filename=Ab(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:kb(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}class nS{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,Eb(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(!Tb(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:kb(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}const Ag=200,Tg=206;function rS(a){const t=a.response;return typeof t!="string"?t:Wu(t).buffer}class oS{constructor({url:t,httpHeaders:e,withCredentials:s}){$(this,"_responseOrigin",null);this.url=t,this.isHttp=/^https?:/i.test(t),this.headers=Sb(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=Tg):i.expectedStatus=Ag,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||Ag;if(!(n===Ag&&s.expectedStatus===Tg)&&n!==s.expectedStatus){s.onError(i.status);return}const o=rS(i);if(n===Tg){const h=i.getResponseHeader("Content-Range"),c=/bytes (\d+)-(\d+)\/(\d+)/.exec(h);c?s.onDone({begin:parseInt(c[1],10),chunk:o}):(et('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 aS{constructor(t){this._source=t,this._manager=new oS(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 hS(this._manager,this._source),this._fullRequestReader}getRangeReader(t,e){const s=new lS(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 hS{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}=Cb({responseHeaders:i,isHttp:this._manager.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});n&&(this._isRangeSupported=!0),this._contentLength=r||this._contentLength,this._filename=Ab(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 lS{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 cS=/^[a-z][a-z0-9\-+.]+:/i;function uS(a){if(cS.test(a))return new URL(a);const t=process.getBuiltinModule("url");return new URL(t.pathToFileURL(a))}class dS{constructor(t){this.source=t,this.url=uS(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 fS(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new gS(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 fS{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 gS{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 pS=1e5,Ye=30,mS=.8,Qt=class Qt{constructor({textContentSource:t,container:e,viewport:s}){_(this,rn);_(this,Kn,Promise.withResolvers());_(this,Ke,null);_(this,Ll,!1);_(this,Fl,!!((qb=globalThis.FontInspector)!=null&&qb.enabled));_(this,no,null);_(this,nn,null);_(this,Il,0);_(this,Nl,0);_(this,ro,null);_(this,Oa,null);_(this,Da,0);_(this,Qn,0);_(this,Ra,Object.create(null));_(this,jl,[]);_(this,La,null);_(this,oo,[]);_(this,Bl,new WeakMap);_(this,Hl,null);var h;if(t instanceof ReadableStream)m(this,La,t);else if(typeof t=="object")m(this,La,new ReadableStream({start(c){c.enqueue(t),c.close()}}));else throw new Error('No "textContentSource" parameter specified.');m(this,Ke,m(this,Oa,e)),m(this,Qn,s.scale*(globalThis.devicePixelRatio||1)),m(this,Da,s.rotation),m(this,nn,{div:null,properties:null,ctx:null});const{pageWidth:i,pageHeight:n,pageX:r,pageY:o}=s.rawDims;m(this,Hl,[1,0,0,-1,-r,o+n]),m(this,Nl,i),m(this,Il,n),w(h=Qt,as,Rv).call(h),Mr(e,s),l(this,Kn).promise.finally(()=>{l(Qt,Fa).delete(this),m(this,nn,null),m(this,Ra,null)}).catch(()=>{})}static get fontFamilyMap(){const{isWindows:t,isFirefox:e}=Re.platform;return nt(this,"fontFamilyMap",new Map([["sans-serif",`${t&&e?"Calibri, ":""}sans-serif`],["monospace",`${t&&e?"Lucida Console, ":""}monospace`]]))}render(){const t=()=>{l(this,ro).read().then(({value:e,done:s})=>{if(s){l(this,Kn).resolve();return}l(this,no)??m(this,no,e.lang),Object.assign(l(this,Ra),e.styles),w(this,rn,Ov).call(this,e.items),t()},l(this,Kn).reject)};return m(this,ro,l(this,La).getReader()),l(Qt,Fa).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,Da)&&(e==null||e(),m(this,Da,i),Mr(l(this,Oa),{rotation:i})),s!==l(this,Qn)){e==null||e(),m(this,Qn,s);const r={div:null,properties:null,ctx:w(n=Qt,as,Nd).call(n,l(this,no))};for(const o of l(this,oo))r.properties=l(this,Bl).get(o),r.div=o,w(this,rn,bp).call(this,r)}}cancel(){var e;const t=new Rn("TextLayer task cancelled.");(e=l(this,ro))==null||e.cancel(t).catch(()=>{}),m(this,ro,null),l(this,Kn).reject(t)}get textDivs(){return l(this,oo)}get textContentItemsStr(){return l(this,jl)}static cleanup(){if(!(l(this,Fa).size>0)){l(this,ao).clear();for(const{canvas:t}of l(this,ho).values())t.remove();l(this,ho).clear()}}};Kn=new WeakMap,Ke=new WeakMap,Ll=new WeakMap,Fl=new WeakMap,no=new WeakMap,nn=new WeakMap,Il=new WeakMap,Nl=new WeakMap,ro=new WeakMap,Oa=new WeakMap,Da=new WeakMap,Qn=new WeakMap,Ra=new WeakMap,jl=new WeakMap,La=new WeakMap,oo=new WeakMap,Bl=new WeakMap,Hl=new WeakMap,ao=new WeakMap,ho=new WeakMap,zl=new WeakMap,Jn=new WeakMap,Fa=new WeakMap,rn=new WeakSet,Ov=function(t){var i,n;if(l(this,Ll))return;(n=l(this,nn)).ctx??(n.ctx=w(i=Qt,as,Nd).call(i,l(this,no)));const e=l(this,oo),s=l(this,jl);for(const r of t){if(e.length>pS){et("Ignoring additional textDivs for performance reasons."),m(this,Ll,!0);return}if(r.str===void 0){if(r.type==="beginMarkedContentProps"||r.type==="beginMarkedContent"){const o=l(this,Ke);m(this,Ke,document.createElement("span")),l(this,Ke).classList.add("markedContent"),r.id!==null&&l(this,Ke).setAttribute("id",`${r.id}`),o.append(l(this,Ke))}else r.type==="endMarkedContent"&&m(this,Ke,l(this,Ke).parentNode);continue}s.push(r.str),w(this,rn,Dv).call(this,r)}},Dv=function(t){var b;const e=document.createElement("span"),s={angle:0,canvasWidth:0,hasText:t.str!=="",hasEOL:t.hasEOL,fontSize:0};l(this,oo).push(e);const i=U.transform(l(this,Hl),t.transform);let n=Math.atan2(i[1],i[0]);const r=l(this,Ra)[t.fontName];r.vertical&&(n+=Math.PI/2);let o=l(this,Fl)&&r.fontSubstitution||r.fontFamily;o=Qt.fontFamilyMap.get(o)||o;const h=Math.hypot(i[2],i[3]),c=h*w(b=Qt,as,Lv).call(b,o,l(this,no));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,Ke)===l(this,Oa)?(g.left=`${(100*u/l(this,Nl)).toFixed(2)}%`,g.top=`${(100*d/l(this,Il)).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,Fl)&&(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]),y=Math.abs(t.transform[3]);v!==y&&Math.max(v,y)/Math.min(v,y)>1.5&&(p=!0)}if(p&&(s.canvasWidth=r.vertical?t.height:t.width),l(this,Bl).set(e,s),l(this,nn).div=e,l(this,nn).properties=s,w(this,rn,bp).call(this,l(this,nn)),s.hasText&&l(this,Ke).append(e),s.hasEOL){const v=document.createElement("br");v.setAttribute("role","presentation"),l(this,Ke).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,as,vp).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)},as=new WeakSet,Nd=function(t=null){let e=l(this,ho).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,ho).set(t,e),l(this,zl).set(e,{size:0,family:""})}return e},vp=function(t,e,s){const i=l(this,zl).get(t);e===i.size&&s===i.family||(t.font=`${e}px ${s}`,i.size=e,i.family=s)},Rv=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()},Lv=function(t,e){const s=l(this,ao).get(t);if(s)return s;const i=w(this,as,Nd).call(this,e);i.canvas.width=i.canvas.height=Ye,w(this,as,vp).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,ao).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):mS;return l(this,ao).set(t,c),c},_(Qt,as),_(Qt,ao,new Map),_(Qt,ho,new Map),_(Qt,zl,new WeakMap),_(Qt,Jn,null),_(Qt,Fa,new Set);let $h=Qt;class qh{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(qh.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 bS=65536,vS=100,yS=5e3,_S=ve?Lx:Ox,wS=ve?Fx:hb,xS=ve?Rx:Dx,SS=ve?Ix:ub;function CS(a={}){typeof a=="string"||a instanceof URL?a={url:a}:(a instanceof ArrayBuffer||ArrayBuffer.isView(a))&&(a={data:a});const t=new Eg,{docId:e}=t,s=a.url?AS(a.url):null,i=a.data?TS(a.data):null,n=a.httpHeaders||null,r=a.withCredentials===!0,o=a.password??null,h=a.range instanceof Ob?a.range:null,c=Number.isInteger(a.rangeChunkSize)&&a.rangeChunkSize>0?a.rangeChunkSize:bS;let u=a.worker instanceof la?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||wS,v=typeof a.standardFontDataUrl=="string"?a.standardFontDataUrl:null,y=a.StandardFontDataFactory||SS,x=a.stopAtErrors!==!0,S=Number.isInteger(a.maxImageSize)&&a.maxImageSize>-1?a.maxImageSize:-1,C=a.isEvalSupported!==!1,E=typeof a.isOffscreenCanvasSupported=="boolean"?a.isOffscreenCanvasSupported:!ve,P=typeof a.isImageDecoderSupported=="boolean"?a.isImageDecoderSupported:!ve&&(Re.platform.isFirefox||!globalThis.chrome),M=Number.isInteger(a.canvasMaxAreaInBytes)?a.canvasMaxAreaInBytes:-1,O=typeof a.disableFontFace=="boolean"?a.disableFontFace:ve,R=a.fontExtraProperties===!0,L=a.enableXfa===!0,N=a.ownerDocument||globalThis.document,D=a.disableRange===!0,F=a.disableStream===!0,j=a.disableAutoFetch===!0,q=a.pdfBug===!0,I=a.CanvasFactory||_S,H=a.FilterFactory||xS,it=a.enableHWA===!0,kt=h?h.length:a.length??NaN,te=typeof a.useSystemFonts=="boolean"?a.useSystemFonts:!ve&&!O,fe=typeof a.useWorkerFetch=="boolean"?a.useWorkerFetch:b===hb&&y===ub&&g&&v&&Xh(g,document.baseURI)&&Xh(v,document.baseURI),Yt=null;lx(d);const St={canvasFactory:new I({ownerDocument:N,enableHWA:it}),filterFactory:new H({docId:e,ownerDocument:N}),cMapReaderFactory:fe?null:new b({baseUrl:g,isCompressed:p}),standardFontDataFactory:fe?null:new y({baseUrl:v})};if(!u){const It={verbosity:d,port:Xi.workerPort};u=It.port?la.fromPort(It):new la(It),t._worker=u}const He={docId:e,apiVersion:"4.10.38",data:i,password:o,disableAutoFetch:j,rangeChunkSize:c,length:kt,docBaseUrl:f,enableXfa:L,evaluatorOptions:{maxImageSize:S,disableFontFace:O,ignoreErrors:x,isEvalSupported:C,isOffscreenCanvasSupported:E,isImageDecoderSupported:P,canvasMaxAreaInBytes:M,fontExtraProperties:R,useSystemFonts:te,cMapUrl:fe?g:null,standardFontDataUrl:fe?v:null}},Pi={disableFontFace:O,fontExtraProperties:R,ownerDocument:N,pdfBug:q,styleElement:Yt,loadingParams:{disableAutoFetch:j,enableXfa:L}};return u.promise.then(function(){if(t.destroyed)throw new Error("Loading aborted");if(u.destroyed)throw new Error("Worker was destroyed");const It=u.messageHandler.sendWithPromise("GetDocRequest",He,i?[i.buffer]:null);let ft;if(h)ft=new Zx(h,{disableRange:D,disableStream:F});else if(!i){if(!s)throw new Error("getDocument - no `url` parameter provided.");let fr;if(ve)if(Xh(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=Mb}else fr=dS;else fr=Xh(s)?Mb:aS;ft=new fr({url:s,length:kt,httpHeaders:n,withCredentials:r,rangeChunkSize:c,disableRange:D,disableStream:F})}return It.then(fr=>{if(t.destroyed)throw new Error("Loading aborted");if(u.destroyed)throw new Error("Worker was destroyed");const bh=new Uh(e,fr,u.port),Oi=new PS(bh,t,ft,Pi,St);t._transport=Oi,bh.send("Ready",null)})}).catch(t._capability.reject),t}function AS(a){if(a instanceof URL)return a.href;try{return new URL(a,window.location).href}catch{if(ve&&typeof a=="string")return a}throw new Error("Invalid PDF url data: either string or URL-object is expected in the url property.")}function TS(a){if(ve&&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 Pb(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${ze(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,_(md,pd,0);let Eg=md;class Ob{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){yt("Abstract method PDFDataRangeTransport.requestDataRange")}abort(){}}class ES{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 nt(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 kS{constructor(t,e,s,i=!1){_(this,Es);_(this,Zn,null);_(this,on,!1);this._pageIndex=t,this._pageInfo=e,this._transport=s,this._stats=i?new eb:null,this._pdfBug=i,this.commonObjs=s.commonObjs,this.objs=new Db,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 Vh({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 nt(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=On.ENABLE,transform:n=null,background:r=null,optionalContentConfigPromise:o=null,annotationCanvasMap:h=null,pageColors:c=null,printAnnotationStorage:u=null,isEditing:d=!1}){var C,E;(C=this._stats)==null||C.time("Overall");const f=this._transport.getRenderingIntent(s,i,u,d),{renderingIntent:g,cacheKey:p}=f;m(this,on,!1),w(this,Es,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&ss.PRINT);b.displayReadyCapability||(b.displayReadyCapability=Promise.withResolvers(),b.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},(E=this._stats)==null||E.time("Page Request"),this._pumpOperatorList(f));const y=P=>{var M;b.renderTasks.delete(x),(this._maybeCleanupAfterRender||v)&&m(this,on,!0),w(this,Es,wh).call(this,!v),P?(x.capability.reject(P),this._abortOperatorList({intentState:b,reason:P instanceof Error?P:new Error(P)})):x.capability.resolve(),this._stats&&(this._stats.timeEnd("Rendering"),this._stats.timeEnd("Overall"),(M=globalThis.Stats)!=null&&M.enabled&&globalThis.Stats.add(this.pageNumber,this._stats))},x=new kg({callback:y,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 S=x.task;return Promise.all([b.displayReadyCapability.promise,o]).then(([P,M])=>{var O;if(this.destroyed){y();return}if((O=this._stats)==null||O.time("Rendering"),!(M.renderingIntent&g))throw new Error("Must use the same `intent`-argument when calling the `PDFPageProxy.render` and `PDFDocumentProxy.getOptionalContentConfig` methods.");x.initializeGraphics({transparency:P,optionalContentConfig:M}),x.operatorListChanged()}).catch(y),S}getOperatorList({intent:t="display",annotationMode:e=On.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=>qh.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,on,!1),w(this,Es,jd).call(this),Promise.all(t)}cleanup(t=!1){m(this,on,!0);const e=w(this,Es,wh).call(this,!1);return t&&e&&this._stats&&(this._stats=new eb),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,Es,wh).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,Es,wh).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 ug){let i=vS;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,on=new WeakMap,Es=new WeakSet,wh=function(t=!1){if(w(this,Es,jd).call(this),!l(this,on)||this.destroyed)return!1;if(t)return m(this,Zn,setTimeout(()=>{m(this,Zn,null),w(this,Es,wh).call(this,!1)},yS)),!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,on,!1),!0},jd=function(){l(this,Zn)&&(clearTimeout(l(this,Zn)),m(this,Zn,null))};class MS{constructor(){_(this,an,new Map);_(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,an))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){et("LoopbackPort - cannot use an `aborted` signal.");return}const r=()=>this.removeEventListener(t,e);i=()=>n.removeEventListener("abort",r),n.addEventListener("abort",r)}l(this,an).set(e,i)}removeEventListener(t,e){const s=l(this,an).get(e);s==null||s(),l(this,an).delete(e)}terminate(){for(const[,t]of l(this,an))t==null||t();l(this,an).clear()}}an=new WeakMap,bd=new WeakMap;const Tt=class Tt{constructor({name:t=null,port:e=null,verbosity:s=cx()}={}){_(this,Ia);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(Tt,co))!=null&&i.has(e))throw new Error("Cannot use more than one PDFWorker per port.");(l(Tt,co)||m(Tt,co,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 Uh("main","worker",t),this._messageHandler.on("ready",function(){}),w(this,Ia,Bd).call(this)}_initialize(){if(l(Tt,lo)||l(Tt,Na,Hd)){this._setupFakeWorker();return}let{workerSrc:t}=Tt;try{Tt._isSameOrigin(window.location.href,t)||(t=Tt._createCDNWrapper(new URL(t,window.location).href));const e=new Worker(t,{type:"module"}),s=new Uh("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,Ia,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(Tt,lo)||(et("Setting up fake worker."),m(Tt,lo,!0)),Tt._setupFakeWorkerGlobal.then(t=>{if(this.destroyed){this._readyCapability.reject(new Error("Worker was destroyed"));return}const e=new MS;this._port=e;const s=`fake${ze(Tt,vd)._++}`,i=new Uh(s+"_worker",s,e);t.setup(i,e),this._messageHandler=new Uh(s,s+"_worker",e),w(this,Ia,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(Tt,co))==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,co))==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 Tt(t)}static get workerSrc(){if(Xi.workerSrc)return Xi.workerSrc;throw new Error('No "GlobalWorkerOptions.workerSrc" specified.')}static get _setupFakeWorkerGlobal(){return nt(this,"_setupFakeWorkerGlobal",(async()=>l(this,Na,Hd)?l(this,Na,Hd):(await import(this.workerSrc)).WorkerMessageHandler)())}};vd=new WeakMap,lo=new WeakMap,co=new WeakMap,Ia=new WeakSet,Bd=function(){this._readyCapability.resolve(),this._messageHandler.send("configure",{verbosity:this.verbosity})},Na=new WeakSet,Hd=function(){var t;try{return((t=globalThis.pdfjsWorker)==null?void 0:t.WorkerMessageHandler)||null}catch{return null}},_(Tt,Na),_(Tt,vd,0),_(Tt,lo,!1),_(Tt,co),ve&&(m(Tt,lo,!0),Xi.workerSrc||(Xi.workerSrc="./pdf.worker.mjs")),Tt._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},Tt._createCDNWrapper=t=>{const e=`await import("${t}");`;return URL.createObjectURL(new Blob([e],{type:"text/javascript"}))};let la=Tt;class PS{constructor(t,e,s,i,n){_(this,uo);_(this,hn,new Map);_(this,wi,new Map);_(this,ja,new Map);_(this,Ba,new Map);_(this,ln,null);this.messageHandler=t,this.loadingTask=e,this.commonObjs=new Db,this.fontLoader=new Mx({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 nt(this,"annotationStorage",new _g)}getRenderingIntent(t,e=On.ENABLE,s=null,i=!1,n=!1){let r=ss.DISPLAY,o=yg;switch(t){case"any":r=ss.ANY;break;case"display":break;case"print":r=ss.PRINT;break;default:et(`getRenderingIntent - invalid intent: ${t}`)}const h=r&ss.PRINT&&s instanceof nb?s:this.annotationStorage;switch(e){case On.DISABLE:r+=ss.ANNOTATIONS_DISABLE;break;case On.ENABLE:break;case On.ENABLE_FORMS:r+=ss.ANNOTATIONS_FORMS;break;case On.ENABLE_STORAGE:r+=ss.ANNOTATIONS_STORAGE,o=h.serializable;break;default:et(`getRenderingIntent - invalid annotationMode: ${e}`)}i&&(r+=ss.IS_EDITING),n&&(r+=ss.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,ln))==null||s.reject(new Error("Worker was destroyed during onPassword callback"));const t=[];for(const i of l(this,wi).values())t.push(i._destroy());l(this,wi).clear(),l(this,ja).clear(),l(this,Ba).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,hn).clear(),this.filterFactory.destroy(),$h.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 ES(s,this))}),t.on("DocException",s=>{e._capability.reject(We(s))}),t.on("PasswordRequest",s=>{m(this,ln,Promise.withResolvers());try{if(!e.onPassword)throw We(s);const i=n=>{n instanceof Error?l(this,ln).reject(n):l(this,ln).resolve({password:n})};e.onPassword(i,s.code)}catch(i){l(this,ln).reject(i)}return l(this,ln).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,wi).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;et(`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 Px(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,wi).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,wi).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)>rx&&(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&&et("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,ja).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,Ba).set(n.refStr,t);const r=new kS(e,n,this,this._params.pdfBug);return l(this,wi).set(e,r),r});return l(this,ja).set(e,i),i}getPageIndex(t){return Pb(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,uo,Dc).call(this,"GetFieldObjects")}hasJSActions(){return w(this,uo,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,uo,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,uo,Dc).call(this,"GetOptionalContentConfig").then(e=>new Jx(e,t))}getPermissions(){return this.messageHandler.sendWithPromise("GetPermissions",null)}getMetadata(){const t="GetMetadata",e=l(this,hn).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 Kx(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,hn).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,wi).values())if(!e.cleanup())throw new Error(`startCleanup: Page ${e.pageNumber} is currently rendering.`);this.commonObjs.clear(),t||this.fontLoader.clear(),l(this,hn).clear(),this.filterFactory.destroy(!0),$h.cleanup()}}cachedPageNumber(t){if(!Pb(t))return null;const e=t.gen===0?`${t.num}R`:`${t.num}R${t.gen}`;return l(this,Ba).get(e)??null}}hn=new WeakMap,wi=new WeakMap,ja=new WeakMap,Ba=new WeakMap,ln=new WeakMap,uo=new WeakSet,Dc=function(t,e=null){const s=l(this,hn).get(t);if(s)return s;const i=this.messageHandler.sendWithPromise(t,e);return l(this,hn).set(t,i),i};const Kh=Symbol("INITIAL_DATA");class Db{constructor(){_(this,Gl);_(this,hs,Object.create(null))}get(t,e=null){if(e){const i=w(this,Gl,yp).call(this,t);return i.promise.then(()=>e(i.data)),null}const s=l(this,hs)[t];if(!s||s.data===Kh)throw new Error(`Requesting object that isn't resolved yet ${t}.`);return s.data}has(t){const e=l(this,hs)[t];return!!e&&e.data!==Kh}delete(t){const e=l(this,hs)[t];return!e||e.data===Kh?!1:(delete l(this,hs)[t],!0)}resolve(t,e=null){const s=w(this,Gl,yp).call(this,t);s.data=e,s.resolve()}clear(){var t;for(const e in l(this,hs)){const{data:s}=l(this,hs)[e];(t=s==null?void 0:s.bitmap)==null||t.close()}m(this,hs,Object.create(null))}*[Symbol.iterator](){for(const t in l(this,hs)){const{data:e}=l(this,hs)[t];e!==Kh&&(yield[t,e])}}}hs=new WeakMap,Gl=new WeakSet,yp=function(t){var e;return(e=l(this,hs))[t]||(e[t]={...Promise.withResolvers(),data:Kh})};class OS{constructor(t){_(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 go=class go{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}){_(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 OS(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(go,fo).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(go,fo).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 aa(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(go,fo).delete(this._canvas),this.callback(t||new ug(`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(go,fo).delete(this._canvas),this.callback())))}};er=new WeakMap,fo=new WeakMap,_(go,fo,new WeakSet);let kg=go;const DS="4.10.38",RS="f9bea397f";function Rb(a){return Math.floor(Math.max(0,Math.min(1,a))*255).toString(16).padStart(2,"0")}function Qh(a){return Math.max(0,Math.min(255,255*a))}class Lb{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=Qh(t),[t,t,t]}static G_HTML([t]){const e=Rb(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(Qh)}static RGB_HTML(t){return`#${t.map(Rb).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[Qh(1-Math.min(1,t+i)),Qh(1-Math.min(1,s+i)),Qh(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 LS{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){yt("Abstract method `_createSVG` called.")}}class Mg extends LS{_createSVG(t){return document.createElementNS(Vi,t)}}class Fb{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&&qh.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:y}=v;if(y==="#text"){const S=document.createTextNode(v.value);c.push(S),b.append(S);continue}const x=(d=v==null?void 0:v.attributes)!=null&&d.xmlns?document.createElementNS(v.attributes.xmlns,y):document.createElement(y);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 S=document.createTextNode(v.value);o&&qh.shouldBuildText(y)&&c.push(S),x.append(S)}}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 Jh=1e3,FS=9,Or=new WeakSet;function Fn(a){return{width:a[2]-a[0],height:a[3]-a[1]}}class IS{static create(t){switch(t.data.annotationType){case qt.LINK:return new Ib(t);case qt.TEXT:return new NS(t);case qt.WIDGET:switch(t.data.fieldType){case"Tx":return new jS(t);case"Btn":return t.data.radioButton?new Nb(t):t.data.checkBox?new HS(t):new zS(t);case"Ch":return new GS(t);case"Sig":return new BS(t)}return new Dr(t);case qt.POPUP:return new Pg(t);case qt.FREETEXT:return new jb(t);case qt.LINE:return new XS(t);case qt.SQUARE:return new WS(t);case qt.CIRCLE:return new US(t);case qt.POLYLINE:return new Bb(t);case qt.CARET:return new $S(t);case qt.INK:return new Og(t);case qt.POLYGON:return new YS(t);case qt.HIGHLIGHT:return new Hb(t);case qt.UNDERLINE:return new qS(t);case qt.SQUIGGLY:return new KS(t);case qt.STRIKEOUT:return new QS(t);case qt.STAMP:return new zb(t);case qt.FILEATTACHMENT:return new JS(t);default:return new Bt(t)}}}const Wg=class Wg{constructor(t,{isRenderable:e=!1,ignoreBorder:s=!1,createQuadrilaterals:i=!1}={}){_(this,Vl);_(this,po,null);_(this,Ha,!1);_(this,za,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,po)||m(this,po,{rect:this.data.rect.slice(0)});const{rect:e}=t;e&&w(this,Vl,_p).call(this,e),(s=l(this,za))==null||s.popup.updateEdited(t)}resetEdited(){var t;l(this,po)&&(w(this,Vl,_p).call(this,l(this,po).rect),(t=l(this,za))==null||t.popup.resetEdited(),m(this,po,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=Jh);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 Pg){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 Nb){const x=`calc(${o}px * var(--scale-factor)) / calc(${h}px * var(--scale-factor))`;r.borderRadius=x}switch(e.borderStyle.style){case zh.SOLID:r.borderStyle="solid";break;case zh.DASHED:r.borderStyle="dashed";break;case zh.BEVELED:et("Unimplemented border style: beveled");break;case zh.INSET:et("Unimplemented border style: inset");break;case zh.UNDERLINE:r.borderBottomStyle="solid";break}const y=e.borderColor||null;y?(m(this,Ha,!0),r.borderColor=U.makeHexColor(y[0]|0,y[1]|0,y[2]|0)):r.borderWidth=0}const c=U.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]=Lb[`${r}_HTML`](o),this.annotationStorage.setValue(this.data.id,{[s]:Lb[`${r}_rgb`](o)})};return nt(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,y,x]=t.subarray(2,6);if(i===b&&n===v&&e===y&&s===x)return}const{style:r}=this.container;let o;if(l(this,Ha)){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 y=t[b],x=t[b+1],S=t[b+2],C=t[b+3],E=u.createElement("rect"),P=(S-e)/h,M=(n-x)/c,O=(y-S)/h,R=(x-C)/c;E.setAttribute("x",P),E.setAttribute("y",M),E.setAttribute("width",O),E.setAttribute("height",R),g.append(E),o==null||o.push(`<rect vector-effect="non-scaling-stroke" x="${P}" y="${M}" width="${O}" height="${R}"/>`)}l(this,Ha)&&(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,za,new Pg({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(){yt("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&&!Or.has(c)){et(`_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&&Or.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})})}};po=new WeakMap,Ha=new WeakMap,za=new WeakMap,Vl=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 Bt=Wg;class Ib extends Bt{constructor(e,s=null){super(e,{isRenderable:!0,ignoreBorder:!!(s!=null&&s.ignoreBorder),createQuadrilaterals:!0});_(this,ls);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,ls,Fv).call(this,i,e.attachment,e.attachmentDest),n=!0):e.setOCGState?(w(this,ls,Iv).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,ls,zo).call(this)}_bindNamedAction(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeNamedAction(s),!1),w(this,ls,zo).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,ls,zo).call(this)}_bindResetFormAction(e,s){const i=e.onclick;if(i||(e.href=this.linkService.getAnchorUrl("")),w(this,ls,zo).call(this),!this._fieldObjects){et('_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(!Or.has(p)){et(`_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}}}ls=new WeakSet,zo=function(){this.container.setAttribute("data-internal-link","")},Fv=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,ls,zo).call(this)},Iv=function(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeSetOCGState(s),!1),w(this,ls,zo).call(this)};class NS extends Bt{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 Bt{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":U.makeHexColor(e[0],e[1],e[2])}_setTextStyle(t){const e=["left","center","right"],{fontColor:s}=this.data.defaultAppearanceData,i=this.data.defaultAppearanceData.fontSize||FS,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/(ng*i))||1,d=c/u;r=Math.min(i,h(d/ng))}else{const c=Math.abs(this.data.rect[3]-this.data.rect[1]-o);r=Math.min(i,h(c/ng))}n.fontSize=`calc(${r}px * var(--scale-factor))`,n.color=U.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 jS 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),Or.add(s),s.setAttribute("data-element-id",e),s.disabled=this.data.readOnly,s.name=this.data.fieldName,s.tabIndex=Jh,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 S;const{charLimit:v}=b.detail,{target:y}=b;if(v===0){y.removeAttribute("maxLength");return}y.setAttribute("maxLength",v);let x=u.userValue;!x||x.length<=v||(x=x.slice(0,v),y.value=u.userValue=x,t.setValue(e,{value:x}),(S=this.linkService.eventBus)==null||S.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:x,willCommit:!0,commitKey:1,selStart:y.selectionStart,selEnd:y.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 E;u.lastCommittedValue=null;const{data:p,target:b}=g,{value:v,selectionStart:y,selectionEnd:x}=b;let S=y,C=x;switch(g.inputType){case"deleteWordBackward":{const P=v.substring(0,y).match(/\w*[^\w]*$/);P&&(S-=P[0].length);break}case"deleteWordForward":{const P=v.substring(y).match(/^[^\w]*\w*/);P&&(C+=P[0].length);break}case"deleteContentBackward":y===x&&(S-=1);break;case"deleteContentForward":y===x&&(C+=1);break}g.preventDefault(),(E=this.linkService.eventBus)==null||E.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:v,change:p||"",willCommit:!1,selStart:S,selEnd:C}})}),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 BS extends Dr{constructor(t){super(t,{isRenderable:!!t.data.hasOwnCanvas})}}class HS 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 Or.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=Jh,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 Nb 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(Or.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=Jh,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 zS extends Ib{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 GS 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");Or.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=Jh;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],y=document.createElement("option");y.textContent=p,y.value=b,v?v.before(y):i.append(y),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,y=document.createElement("option");y.textContent=b,y.value=v,i.append(y)}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 Pg extends Bt{constructor(t){const{data:e,elements:s}=t;super(t,{isRenderable:Bt._hasPopupData(e)}),this.elements=s,this.popup=null}render(){this.container.classList.add("popupAnnotation");const t=this.popup=new VS({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=>`${cg}${s}`).join(",")),this.container}}class VS{constructor({container:t,color:e,elements:s,titleObj:i,modificationDate:n,contentsObj:r,richText:o,parent:h,rect:c,parentRect:u,open:d}){_(this,bt);_(this,Ga,w(this,bt,Bv).bind(this));_(this,yd,w(this,bt,xp).bind(this));_(this,_d,w(this,bt,Vd).bind(this));_(this,Va,w(this,bt,Gd).bind(this));_(this,mo,null);_(this,Ft,null);_(this,cn,null);_(this,Xa,null);_(this,Xl,null);_(this,Wl,null);_(this,Wa,null);_(this,un,!1);_(this,qs,null);_(this,dn,null);_(this,Ul,null);_(this,fn,null);_(this,Yl,null);_(this,bo,null);_(this,vo,!1);var f;m(this,Ft,t),m(this,Yl,i),m(this,cn,r),m(this,fn,o),m(this,Wl,h),m(this,mo,e),m(this,Ul,c),m(this,Wa,u),m(this,Xl,s),m(this,Xa,fg.toDateObject(n)),this.trigger=s.flatMap(g=>g.getElementsToTriggerPopup());for(const g of this.trigger)g.addEventListener("click",l(this,Va)),g.addEventListener("mouseenter",l(this,_d)),g.addEventListener("mouseleave",l(this,yd)),g.classList.add("popupTriggerArea");for(const g of s)(f=g.container)==null||f.addEventListener("keydown",l(this,Ga));l(this,Ft).hidden=!0,d&&w(this,bt,Gd).call(this)}render(){if(l(this,qs))return;const t=m(this,qs,document.createElement("div"));if(t.className="popup",l(this,mo)){const n=t.style.outlineColor=U.makeHexColor(...l(this,mo));CSS.supports("background-color","color-mix(in srgb, red 30%, white)")?t.style.backgroundColor=`color-mix(in srgb, ${n} 30%, white)`:t.style.backgroundColor=U.makeHexColor(...l(this,mo).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,Yl),t.append(e),l(this,Xa)){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,Xa).valueOf()})),e.append(n)}const i=l(this,bt,zd);if(i)Fb.render({xfaHtml:i,intent:"richText",div:t}),t.lastChild.classList.add("richText","popupContent");else{const n=this._formatContents(l(this,cn));t.append(n)}l(this,Ft).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,bo)||m(this,bo,{contentsObj:l(this,cn),richText:l(this,fn)}),t&&m(this,dn,null),e&&(m(this,fn,w(this,bt,jv).call(this,e)),m(this,cn,null)),(s=l(this,qs))==null||s.remove(),m(this,qs,null)}resetEdited(){var t;l(this,bo)&&({contentsObj:ze(this,cn)._,richText:ze(this,fn)._}=l(this,bo),m(this,bo,null),(t=l(this,qs))==null||t.remove(),m(this,qs,null),m(this,dn,null))}forceHide(){m(this,vo,this.isVisible),l(this,vo)&&(l(this,Ft).hidden=!0)}maybeShow(){l(this,vo)&&(l(this,qs)||w(this,bt,Vd).call(this),m(this,vo,!1),l(this,Ft).hidden=!1)}get isVisible(){return l(this,Ft).hidden===!1}}Ga=new WeakMap,yd=new WeakMap,_d=new WeakMap,Va=new WeakMap,mo=new WeakMap,Ft=new WeakMap,cn=new WeakMap,Xa=new WeakMap,Xl=new WeakMap,Wl=new WeakMap,Wa=new WeakMap,un=new WeakMap,qs=new WeakMap,dn=new WeakMap,Ul=new WeakMap,fn=new WeakMap,Yl=new WeakMap,bo=new WeakMap,vo=new WeakMap,bt=new WeakSet,zd=function(){const t=l(this,fn),e=l(this,cn);return t!=null&&t.str&&(!(e!=null&&e.str)||e.str===t.str)&&l(this,fn).html||null},wp=function(){var t,e,s;return((s=(e=(t=l(this,bt,zd))==null?void 0:t.attributes)==null?void 0:e.style)==null?void 0:s.fontSize)||0},Nv=function(){var t,e,s;return((s=(e=(t=l(this,bt,zd))==null?void 0:t.attributes)==null?void 0:e.style)==null?void 0:s.color)||null},jv=function(t){const e=[],s={str:t,html:{name:"div",attributes:{dir:"auto"},children:[{name:"p",children:e}]}},i={style:{color:l(this,bt,Nv),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},Bv=function(t){t.altKey||t.shiftKey||t.ctrlKey||t.metaKey||(t.key==="Enter"||t.key==="Escape"&&l(this,un))&&w(this,bt,Gd).call(this)},Hv=function(){if(l(this,dn)!==null)return;const{page:{view:t},viewport:{rawDims:{pageWidth:e,pageHeight:s,pageX:i,pageY:n}}}=l(this,Wl);let r=!!l(this,Wa),o=r?l(this,Wa):l(this,Ul);for(const p of l(this,Xl))if(!o||U.intersect(p.data.rect,o)!==null){o=p.data.rect,r=!0;break}const h=U.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,dn,[100*(d-i)/e,100*(f-n)/s]);const{style:g}=l(this,Ft);g.left=`${l(this,dn)[0]}%`,g.top=`${l(this,dn)[1]}%`},Gd=function(){m(this,un,!l(this,un)),l(this,un)?(w(this,bt,Vd).call(this),l(this,Ft).addEventListener("click",l(this,Va)),l(this,Ft).addEventListener("keydown",l(this,Ga))):(w(this,bt,xp).call(this),l(this,Ft).removeEventListener("click",l(this,Va)),l(this,Ft).removeEventListener("keydown",l(this,Ga)))},Vd=function(){l(this,qs)||this.render(),this.isVisible?l(this,un)&&l(this,Ft).classList.add("focused"):(w(this,bt,Hv).call(this),l(this,Ft).hidden=!1,l(this,Ft).style.zIndex=parseInt(l(this,Ft).style.zIndex)+1e3)},xp=function(){l(this,Ft).classList.remove("focused"),!(l(this,un)||!this.isVisible)&&(l(this,Ft).hidden=!0,l(this,Ft).style.zIndex=parseInt(l(this,Ft).style.zIndex)-1e3)};class jb extends Bt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.textContent=t.data.textContent,this.textPosition=t.data.textPosition,this.annotationEditorType=tt.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 XS extends Bt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});_(this,$l,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,$l,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,$l)}addHighlightArea(){this.container.classList.add("highlightArea")}}$l=new WeakMap;class WS extends Bt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});_(this,ql,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,ql,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,ql)}addHighlightArea(){this.container.classList.add("highlightArea")}}ql=new WeakMap;class US extends Bt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});_(this,Kl,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,Kl,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,Kl)}addHighlightArea(){this.container.classList.add("highlightArea")}}Kl=new WeakMap;class Bb extends Bt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});_(this,Ql,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,Ql,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,Ql)}addHighlightArea(){this.container.classList.add("highlightArea")}}Ql=new WeakMap;class YS extends Bb{constructor(t){super(t),this.containerClassName="polygonAnnotation",this.svgElementName="svg:polygon"}}class $S extends Bt{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 Bt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});_(this,Zl);_(this,Jl,null);_(this,yo,[]);this.containerClassName="inkAnnotation",this.svgElementName="svg:polyline",this.annotationEditorType=this.data.it==="InkHighlight"?tt.HIGHLIGHT:tt.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,Zl,Sp).call(this,s,e),u=this.svgFactory.create(h,c,!0),d=m(this,Jl,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,Jl);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,Zl,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")}}Jl=new WeakMap,yo=new WeakMap,Zl=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 Hb extends Bt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0}),this.annotationEditorType=tt.HIGHLIGHT}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("highlightAnnotation"),this._editOnDoubleClick(),this.container}}class qS extends Bt{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 KS extends Bt{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 QS extends Bt{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 zb extends Bt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.annotationEditorType=tt.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 JS extends Bt{constructor(e){var i;super(e,{isRenderable:!0});_(this,ec);_(this,tc,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,ec,Cp).bind(this)),m(this,tc,i);const{isMac:n}=Re.platform;return e.addEventListener("keydown",r=>{r.key==="Enter"&&(n?r.metaKey:r.ctrlKey)&&w(this,ec,Cp).call(this)}),!s.popupRef&&this.hasPopupData?this._createPopup():i.classList.add("popupTriggerArea"),e.append(i),e}getElementsToTriggerPopup(){return l(this,tc)}addHighlightArea(){this.container.classList.add("highlightArea")}}tc=new WeakMap,ec=new WeakSet,Cp=function(){var e;(e=this.downloadManager)==null||e.openOrDownloadData(this.content,this.filename)};class ZS{constructor({div:t,accessibilityManager:e,annotationCanvasMap:s,annotationEditorUIManager:i,page:n,viewport:r,structTreeLayer:o}){_(this,xo);_(this,sc,null);_(this,_o,null);_(this,wo,new Map);_(this,ic,null);this.div=t,m(this,sc,e),m(this,_o,s),m(this,ic,o||null),this.page=n,this.viewport=r,this.zIndex=0,this._annotationEditorUIManager=i}hasEditableAnnotations(){return l(this,wo).size>0}async render(t){var r;const{annotations:e}=t,s=this.div;Mr(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 Mg,annotationStorage:t.annotationStorage||new _g,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=IS.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,xo,zv).call(this,u,o.id),c._isEditable&&(l(this,wo).set(c.data.id,c),(r=this._annotationEditorUIManager)==null||r.renderAnnotationElement(c))}w(this,xo,Ap).call(this)}update({viewport:t}){const e=this.div;this.viewport=t,Mr(e,{rotation:t.rotation}),w(this,xo,Ap).call(this),e.hidden=!1}getEditableAnnotations(){return Array.from(l(this,wo).values())}getEditableAnnotation(t){return l(this,wo).get(t)}}sc=new WeakMap,_o=new WeakMap,wo=new WeakMap,ic=new WeakMap,xo=new WeakSet,zv=async function(t,e){var r,o;const s=t.firstChild||t,i=s.id=`${cg}${e}`,n=await((r=l(this,ic))==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,sc))==null||o.moveElementInDOM(this.div,t,s,!1)},Ap=function(){if(!l(this,_o))return;const t=this.div;for(const[e,s]of l(this,_o)){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,_o).clear()};const sd=/\r\n?|\n/g,_t=class _t extends Ot{constructor(e){super({...e,name:"freeTextEditor"});_(this,Ut);_(this,Ks);_(this,cs,"");_(this,nc,`${this.id}-editor`);_(this,So,null);_(this,us);m(this,Ks,e.color||_t._defaultColor||Ot._defaultLineColor),m(this,us,e.fontSize||_t._defaultFontSize)}static get _keyboardManager(){const e=_t.prototype,s=r=>r.isEmpty(),i=Pr.TRANSLATE_SMALL,n=Pr.TRANSLATE_BIG;return nt(this,"_keyboardManager",new Wh([[["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){Ot.initialize(e,s);const i=getComputedStyle(document.documentElement);this._internalPadding=parseFloat(i.getPropertyValue("--freetext-padding"))}static updateDefaultParams(e,s){switch(e){case at.FREETEXT_SIZE:_t._defaultFontSize=s;break;case at.FREETEXT_COLOR:_t._defaultColor=s;break}}updateParams(e,s){switch(e){case at.FREETEXT_SIZE:w(this,Ut,Gv).call(this,s);break;case at.FREETEXT_COLOR:w(this,Ut,Vv).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[at.FREETEXT_SIZE,_t._defaultFontSize],[at.FREETEXT_COLOR,_t._defaultColor||Ot._defaultLineColor]]}get propertiesToUpdate(){return[[at.FREETEXT_SIZE,l(this,us)],[at.FREETEXT_COLOR,l(this,Ks)]]}_translateEmpty(e,s){this._uiManager.translateSelectedEditors(e,s,!0)}getInitialTranslation(){const e=this.parentScale;return[-_t._internalPadding*e,-(_t._internalPadding+l(this,us))*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(tt.FREETEXT),super.enableEditMode(),this.overlayDiv.classList.remove("enabled"),this.editorDiv.contentEditable=!0,this._isDraggable=!1,this.div.removeAttribute("aria-activedescendant"),m(this,So,new AbortController);const e=this._uiManager.combinedSignal(l(this,So));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,nc)),this._isDraggable=!0,(e=l(this,So))==null||e.abort(),m(this,So,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,cs),s=m(this,cs,w(this,Ut,Xv).call(this).trimEnd());if(e===s)return;const i=n=>{if(m(this,cs,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){_t._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,nc)),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,us)}px * var(--scale-factor))`,i.color=l(this,Ks),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=_t,gn,Tp).call(p,s.getData("text")||"").replaceAll(sd,`
504
+ `}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}}E(zu,"type","Vibrance"),E(zu,"defaults",{vibrance:0}),E(zu,"uniformLocations",["uVibrance"]),z.setClass(zu);let eb=null;function ox(){const a=document.createElement("div");a.style.width="1in",document.body.append(a);const t=a.offsetWidth;return a.remove(),t}function ax(){const a=eb??ox();return eb=a,a/72}function hx(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)}}function lx(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 cx(i))}),i.addEventListener("error",n=>{window.URL.revokeObjectURL(s),e(n)})})}function cx(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))})}var Vh={};Vh.d=(a,t)=>{for(var e in t)Vh.o(t,e)&&!Vh.o(a,e)&&Object.defineProperty(a,e,{enumerable:!0,get:t[e]})},Vh.o=(a,t)=>Object.prototype.hasOwnProperty.call(a,t);var Q=globalThis.pdfjsLib={};Vh.d(Q,{AbortException:()=>Rn,AnnotationEditorLayer:()=>Gg,AnnotationEditorParamsType:()=>at,AnnotationEditorType:()=>et,AnnotationEditorUIManager:()=>Or,AnnotationLayer:()=>rC,AnnotationMode:()=>On,ColorPicker:()=>od,DOMSVGFactory:()=>Dg,DrawLayer:()=>Vg,FeatureTest:()=>Re,GlobalWorkerOptions:()=>Wi,ImageKind:()=>Gu,InvalidPDFException:()=>lg,MissingPDFException:()=>Wh,OPS:()=>Hs,OutputScale:()=>vg,PDFDataRangeTransport:()=>Ib,PDFDateString:()=>mg,PDFWorker:()=>ca,PasswordResponses:()=>gx,PermissionFlag:()=>fx,PixelsPerInch:()=>Ln,RenderingCancelledException:()=>gg,TextLayer:()=>Qh,TouchManager:()=>Ju,UnexpectedResponseException:()=>Uu,Util:()=>U,VerbosityLevel:()=>Vu,XfaLayer:()=>Hb,build:()=>BS,createValidAbsoluteUrl:()=>vx,fetchData:()=>$u,getDocument:()=>PS,getFilenameFromUrl:()=>Ex,getPdfFilenameFromUrl:()=>kx,getXfaPageViewport:()=>Mx,isDataScheme:()=>qu,isPdfFile:()=>pg,noContextMenu:()=>zs,normalizeUnicode:()=>Cx,setLayerDimensions:()=>Pr,shadow:()=>nt,stopEvent:()=>is,version:()=>jS});const ve=typeof process=="object"&&process+""=="[object process]"&&!process.versions.nw&&!(process.versions.electron&&process.type&&process.type!=="browser"),sb=[1,0,0,1,0,0],og=[.001,0,0,.001,0,0],ux=1e7,ag=1.35,ss={ANY:1,DISPLAY:2,PRINT:4,ANNOTATIONS_FORMS:16,ANNOTATIONS_STORAGE:32,ANNOTATIONS_DISABLE:64,IS_EDITING:128,OPLIST:256},On={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},dx="pdfjs_internal_editor_",et={DISABLE:-1,NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15},at={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},fx={PRINT:4,MODIFY_CONTENTS:8,COPY:16,MODIFY_ANNOTATIONS:32,FILL_INTERACTIVE_FORMS:256,COPY_FOR_ACCESSIBILITY:512,ASSEMBLE:1024,PRINT_HIGH_QUALITY:2048},ye={FILL:0,STROKE:1,FILL_STROKE:2,INVISIBLE:3,FILL_STROKE_MASK:3,ADD_TO_PATH_FLAG:4},Gu={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},Xh={SOLID:1,DASHED:2,BEVELED:3,INSET:4,UNDERLINE:5},Vu={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},gx={NEED_PASSWORD:1,INCORRECT_PASSWORD:2};let Xu=Vu.WARNINGS;function px(a){Number.isInteger(a)&&(Xu=a)}function mx(){return Xu}function Wu(a){Xu>=Vu.INFOS&&console.log(`Info: ${a}`)}function st(a){Xu>=Vu.WARNINGS&&console.log(`Warning: ${a}`)}function _t(a){throw new Error(a)}function Xt(a,t){a||_t(t)}function bx(a){switch(a==null?void 0:a.protocol){case"http:":case"https:":case"ftp:":case"mailto:":case"tel:":return!0;default:return!1}}function vx(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=Sx(a)}catch{}}const s=t?new URL(a,t):new URL(a);if(bx(s))return s}catch{}return null}function nt(a,t,e,s=!1){return Object.defineProperty(a,t,{value:e,enumerable:!s,configurable:!0,writable:!1}),e}const Dn=function(){function t(e,s){this.message=e,this.name=s}return t.prototype=new Error,t.constructor=t,t}();class ib extends Dn{constructor(t,e){super(t,"PasswordException"),this.code=e}}class hg extends Dn{constructor(t,e){super(t,"UnknownErrorException"),this.details=e}}class lg extends Dn{constructor(t){super(t,"InvalidPDFException")}}class Wh extends Dn{constructor(t){super(t,"MissingPDFException")}}class Uu extends Dn{constructor(t,e){super(t,"UnexpectedResponseException"),this.status=e}}class yx extends Dn{constructor(t){super(t,"FormatError")}}class Rn extends Dn{constructor(t){super(t,"AbortException")}}function nb(a){(typeof a!="object"||(a==null?void 0:a.length)===void 0)&&_t("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 Yu(a){typeof a!="string"&&_t("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 _x(a){return String.fromCharCode(a>>24&255,a>>16&255,a>>8&255,a&255)}function cg(a){const t=Object.create(null);for(const[e,s]of a)t[e]=s;return t}function wx(){const a=new Uint8Array(4);return a[0]=1,new Uint32Array(a.buffer,0,1)[0]===1}function xx(){try{return new Function(""),!0}catch{return!1}}class Re{static get isLittleEndian(){return nt(this,"isLittleEndian",wx())}static get isEvalSupported(){return nt(this,"isEvalSupported",xx())}static get isOffscreenCanvasSupported(){return nt(this,"isOffscreenCanvasSupported",typeof OffscreenCanvas<"u")}static get isImageDecoderSupported(){return nt(this,"isImageDecoderSupported",typeof ImageDecoder<"u")}static get platform(){return typeof navigator<"u"&&typeof(navigator==null?void 0:navigator.platform)=="string"?nt(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")}):nt(this,"platform",{isMac:!1,isWindows:!1,isFirefox:!1})}static get isCSSRoundSupported(){var t,e;return nt(this,"isCSSRoundSupported",(e=(t=globalThis.CSS)==null?void 0:t.supports)==null?void 0:e.call(t,"width: round(1.5px, 1px)"))}}const ug=Array.from(Array(256).keys(),a=>a.toString(16).padStart(2,"0"));class U{static makeHexColor(t,e,s){return`#${ug[t]}${ug[e]}${ug[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,Ui,Jg).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,Ui,Jg).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}}Ui=new WeakSet,Md=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)},Jg=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,Ui,Md).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,Ui,Md).call(this,t,e,s,i,n,r,o,h,(-u+p)/b,f),w(this,Ui,Md).call(this,t,e,s,i,n,r,o,h,(-u-p)/b,f)},_(U,Ui);function Sx(a){return decodeURIComponent(escape(a))}let dg=null,rb=null;function Cx(a){return dg||(dg=/([\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,rb=new Map([["ſt","ſt"]])),a.replaceAll(dg,(t,e,s)=>e?e.normalize("NFKC"):rb.get(s))}function Ax(){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();const a=new Uint8Array(32);return crypto.getRandomValues(a),nb(a)}const fg="pdfjs_internal_id_";function Tx(a){return Uint8Array.prototype.toBase64?a.toBase64():btoa(nb(a))}typeof Promise.try!="function"&&(Promise.try=function(a,...t){return new Promise(e=>{e(a(...t))})});const Xi="http://www.w3.org/2000/svg",Lr=class Lr{};q(Lr,"CSS",96),q(Lr,"PDF",72),q(Lr,"PDF_TO_CSS_UNITS",Lr.CSS/Lr.PDF);let Ln=Lr;async function $u(a,t="text"){if(Yh(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 Uh{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,y,v;u===0?(p=Math.abs(c-t[1])*s+n,b=Math.abs(h-t[0])*s+r,y=(t[3]-t[1])*s,v=(t[2]-t[0])*s):(p=Math.abs(h-t[0])*s+n,b=Math.abs(c-t[1])*s+r,y=(t[2]-t[0])*s,v=(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=y,this.height=v}get rawDims(){const{userUnit:t,viewBox:e}=this,s=e.map(i=>i*t);return nt(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 Uh({viewBox:this.viewBox.slice(),userUnit:this.userUnit,scale:t,rotation:e,offsetX:s,offsetY:i,dontFlip:n})}convertToViewportPoint(t,e){return U.applyTransform([t,e],this.transform)}convertToViewportRectangle(t){const e=U.applyTransform([t[0],t[1]],this.transform),s=U.applyTransform([t[2],t[3]],this.transform);return[e[0],e[1],s[0],s[1]]}convertToPdfPoint(t,e){return U.applyInverseTransform([t,e],this.transform)}}class gg extends Dn{constructor(t,e=0){super(t,"RenderingCancelledException"),this.extraDelay=e}}function qu(a){const t=a.length;let e=0;for(;e<t&&a[e].trim()==="";)e++;return a.substring(e,e+5).toLowerCase()==="data:"}function pg(a){return typeof a=="string"&&/\.pdf$/i.test(a)}function Ex(a){return[a]=a.split(/[#?]/,1),a.substring(a.lastIndexOf("/")+1)}function kx(a,t="document.pdf"){if(typeof a!="string")return t;if(qu(a))return st('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 ob{constructor(){q(this,"started",Object.create(null));q(this,"times",[])}time(t){t in this.started&&st(`Timer is already running for ${t}`),this.started[t]=Date.now()}timeEnd(t){t in this.started||st(`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
505
+ `);return t.join("")}}function Yh(a,t){try{const{protocol:e}=t?new URL(a,t):new URL(a);return e==="http:"||e==="https:"}catch{return!1}}function zs(a){a.preventDefault()}function is(a){a.preventDefault(),a.stopPropagation()}class mg{static toDateObject(t){if(!t||typeof t!="string")return null;l(this,sl)||m(this,sl,new RegExp("^D:(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?([Z|+|-])?(\\d{2})?'?(\\d{2})?'?"));const e=l(this,sl).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))}}sl=new WeakMap,_(mg,sl);function Mx(a,{scale:t=1,rotation:e=0}){const{width:s,height:i}=a.attributes.style,n=[0,0,parseInt(s),parseInt(i)];return new Uh({viewBox:n,userUnit:1,scale:t,rotation:e})}function bg(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):(st(`Not a valid color format: "${a}"`),[0,0,0])}function Px(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,bg(s))}t.remove()}function At(a){const{a:t,b:e,c:s,d:i,e:n,f:r}=a.getTransform();return[t,e,s,i,n,r]}function ui(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 Pr(a,t,e=!1,s=!0){if(t instanceof Uh){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 vg{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 Yi=class Yi{constructor(t){_(this,Le);_(this,In,null);_(this,Fr,null);_(this,Gs);_(this,Ir,null);_(this,il,null);m(this,Gs,t),l(Yi,nl)||m(Yi,nl,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,Gs)._uiManager._signal;t.addEventListener("contextmenu",zs,{signal:e}),t.addEventListener("pointerdown",w(Yi,ld,sv),{signal:e});const s=m(this,Ir,document.createElement("div"));s.className="buttons",t.append(s);const i=l(this,Gs).toolbarPosition;if(i){const{style:n}=t,r=l(this,Gs)._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,rv).call(this),t}get div(){return l(this,In)}hide(){var t;l(this,In).classList.add("hidden"),(t=l(this,Fr))==null||t.hideDropdown()}show(){var t;l(this,In).classList.remove("hidden"),(t=l(this,il))==null||t.shown()}async addAltText(t){const e=await t.render();w(this,Le,Pd).call(this,e),l(this,Ir).prepend(e,l(this,Le,Zg)),m(this,il,t)}addColorPicker(t){m(this,Fr,t);const e=t.renderButton();w(this,Le,Pd).call(this,e),l(this,Ir).prepend(e,l(this,Le,Zg))}remove(){var t;l(this,In).remove(),(t=l(this,Fr))==null||t.destroy(),m(this,Fr,null)}};In=new WeakMap,Fr=new WeakMap,Gs=new WeakMap,Ir=new WeakMap,il=new WeakMap,nl=new WeakMap,ld=new WeakSet,sv=function(t){t.stopPropagation()},Le=new WeakSet,iv=function(t){l(this,Gs)._focusEventsAllowed=!1,is(t)},nv=function(t){l(this,Gs)._focusEventsAllowed=!0,is(t)},Pd=function(t){const e=l(this,Gs)._uiManager._signal;t.addEventListener("focusin",w(this,Le,iv).bind(this),{capture:!0,signal:e}),t.addEventListener("focusout",w(this,Le,nv).bind(this),{capture:!0,signal:e}),t.addEventListener("contextmenu",zs,{signal:e})},rv=function(){const{editorType:t,_uiManager:e}=l(this,Gs),s=document.createElement("button");s.className="delete",s.tabIndex=0,s.setAttribute("data-l10n-id",l(Yi,nl)[t]),w(this,Le,Pd).call(this,s),s.addEventListener("click",i=>{e.delete()},{signal:e._signal}),l(this,Ir).append(s)},Zg=function(){const t=document.createElement("div");return t.className="divider",t},_(Yi,ld),_(Yi,nl,null);let yg=Yi;class Ox{constructor(t){_(this,Nn);_(this,rl,null);_(this,Nr,null);_(this,jr);m(this,jr,t)}show(t,e,s){const[i,n]=w(this,Nn,av).call(this,e,s),{style:r}=l(this,Nr)||m(this,Nr,w(this,Nn,ov).call(this));t.append(l(this,Nr)),r.insetInlineEnd=`${100*i}%`,r.top=`calc(${100*n}% + var(--editor-toolbar-vert-offset))`}hide(){l(this,Nr).remove()}}rl=new WeakMap,Nr=new WeakMap,jr=new WeakMap,Nn=new WeakSet,ov=function(){const t=m(this,Nr,document.createElement("div"));t.className="editToolbar",t.setAttribute("role","toolbar"),t.addEventListener("contextmenu",zs,{signal:l(this,jr)._signal});const e=m(this,rl,document.createElement("div"));return e.className="buttons",t.append(e),w(this,Nn,hv).call(this),t},av=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]},hv=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,jr)._signal;t.addEventListener("contextmenu",zs,{signal:s}),t.addEventListener("click",()=>{l(this,jr).highlightSelection("floating_button")},{signal:s}),l(this,rl).append(t)};function Ku(a,t,e){for(const s of e)t.addEventListener(s,a[s].bind(a))}class Dx{constructor(){_(this,cd,0)}get id(){return`${dx}${ze(this,cd)._++}`}}cd=new WeakMap;const Wg=class Wg{constructor(){_(this,da);_(this,ua,Ax());_(this,ol,0);_(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 nt(this,"_isSVGFittingCanvas",n)}async getFromFile(t){const{lastModified:e,name:s,size:i,type:n}=t;return w(this,da,Od).call(this,`${e}_${s}_${i}_${n}`,t)}async getFromUrl(t){return w(this,da,Od).call(this,t,t)}async getFromBlob(t,e){const s=await e;return w(this,da,Od).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,ua)}_${ze(this,ol)._++}`,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,ua)}_`)}};ua=new WeakMap,ol=new WeakMap,we=new WeakMap,da=new WeakSet,Od=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,ua)}_${ze(this,ol)._++}`,refCounter:0,isSvg:!1});let i;if(typeof e=="string"?(s.url=e,i=await $u(e,"blob")):e instanceof File?i=s.file=e:e instanceof Blob&&(i=e),i.type==="image/svg+xml"){const n=Wg._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){st(i),s=null}return l(this,we).set(t,s),s&&l(this,we).set(s.id,s),s};let _g=Wg;class Rx{constructor(t=128){_(this,Ht,[]);_(this,jn,!1);_(this,al);_(this,Dt,-1);m(this,al,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,Ht).length>0&&(l(this,Ht).length=0),m(this,Dt,0),l(this,Ht).push(h);return}if(r&&l(this,Ht)[l(this,Dt)].type===n){o&&(h.undo=l(this,Ht)[l(this,Dt)].undo),l(this,Ht)[l(this,Dt)]=h;return}const c=l(this,Dt)+1;c===l(this,al)?l(this,Ht).splice(0,1):(m(this,Dt,c),c<l(this,Ht).length&&l(this,Ht).splice(c)),l(this,Ht).push(h)}undo(){if(l(this,Dt)===-1)return;m(this,jn,!0);const{undo:t,post:e}=l(this,Ht)[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,Ht).length-1){m(this,Dt,l(this,Dt)+1),m(this,jn,!0);const{cmd:t,post:e}=l(this,Ht)[l(this,Dt)];t(),e==null||e(),m(this,jn,!1)}}hasSomethingToUndo(){return l(this,Dt)!==-1}hasSomethingToRedo(){return l(this,Dt)<l(this,Ht).length-1}cleanType(t){if(l(this,Dt)!==-1){for(let e=l(this,Dt);e>=0;e--)if(l(this,Ht)[e].type!==t){l(this,Ht).splice(e+1,l(this,Dt)-e),m(this,Dt,e);return}l(this,Ht).length=0,m(this,Dt,-1)}}destroy(){m(this,Ht,null)}}Ht=new WeakMap,jn=new WeakMap,al=new WeakMap,Dt=new WeakMap;class $h{constructor(t){_(this,ud);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,ud,lv).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||is(e))}}ud=new WeakSet,lv=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 dd=class dd{get _colors(){const t=new Map([["CanvasText",null],["Canvas",null]]);return Px(t),nt(this,"_colors",t)}convert(t){const e=bg(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 dd._colorsMapping.get(s);return e}getHexCode(t){const e=this._colors.get(t);return e?U.makeHexColor(...e):t}};q(dd,"_colorsMapping",new Map([["CanvasText",[0,0,0]],["Canvas",[255,255,255]]]));let wg=dd;const ya=class ya{constructor(t,e,s,i,n,r,o,h,c,u,d,f,g){_(this,H);_(this,fa,new AbortController);_(this,ns,null);_(this,Kt,new Map);_(this,ae,new Map);_(this,ga,null);_(this,$i,null);_(this,pa,null);_(this,xs,new Rx);_(this,Bn,null);_(this,Br,null);_(this,ma,0);_(this,Hr,new Set);_(this,fi,null);_(this,Vs,null);_(this,zr,new Set);q(this,"_editorUndoBar",null);_(this,hl,!1);_(this,ll,!1);_(this,ba,!1);_(this,cl,null);_(this,gi,null);_(this,Hn,null);_(this,va,null);_(this,zn,!1);_(this,pi,null);_(this,fd,new Dx);_(this,Gn,!1);_(this,ul,!1);_(this,Vn,null);_(this,Gr,null);_(this,dl,null);_(this,fl,null);_(this,ee,et.NONE);_(this,pt,new Set);_(this,qi,null);_(this,Vr,null);_(this,gl,null);_(this,pl,{isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1});_(this,Xn,[0,0]);_(this,mi,null);_(this,Ki,null);_(this,ml,null);_(this,Ss,null);const p=this._signal=l(this,fa).signal;m(this,Ki,t),m(this,ml,e),m(this,ga,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,H,dv).call(this),w(this,H,mv).call(this),w(this,H,ep).call(this),m(this,$i,n.annotationStorage),m(this,cl,n.filterFactory),m(this,Vr,r),m(this,va,o||null),m(this,hl,h),m(this,ll,c),m(this,ba,u),m(this,fl,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=ya.prototype,e=r=>l(r,Ki).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 nt(this,"_keyboardManager",new $h([[["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,Ki).contains(o)&&!r.isEnterHandled}],[[" ","mac+ "],t.addNewEditorFromKeyboard,{checker:(r,{target:o})=>!(o instanceof HTMLButtonElement)&&l(r,Ki).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,Ss))==null||t.resolve(),m(this,Ss,null),(e=l(this,fa))==null||e.abort(),m(this,fa,null),this._signal=null;for(const r of l(this,ae).values())r.destroy();l(this,ae).clear(),l(this,Kt).clear(),l(this,zr).clear(),m(this,ns,null),l(this,pt).clear(),l(this,xs).destroy(),(s=l(this,ga))==null||s.destroy(),(i=l(this,pi))==null||i.hide(),m(this,pi,null),l(this,gi)&&(clearTimeout(l(this,gi)),m(this,gi,null)),l(this,mi)&&(clearTimeout(l(this,mi)),m(this,mi,null)),(n=this._editorUndoBar)==null||n.destroy()}combinedSignal(t){return AbortSignal.any([this._signal,t.signal])}get mlManager(){return l(this,fl)}get useNewAltTextFlow(){return l(this,ll)}get useNewAltTextWhenAddingImage(){return l(this,ba)}get hcmFilter(){return nt(this,"hcmFilter",l(this,Vr)?l(this,cl).addHCMFilter(l(this,Vr).foreground,l(this,Vr).background):"none")}get direction(){return nt(this,"direction",getComputedStyle(l(this,Ki)).direction)}get highlightColors(){return nt(this,"highlightColors",l(this,va)?new Map(l(this,va).split(",").map(t=>t.split("=").map(e=>e.trim()))):null)}get highlightColorNames(){return nt(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,Br,t)}setMainHighlightColorPicker(t){m(this,dl,t)}editAltText(t,e=!1){var s;(s=l(this,ga))==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,ba,e);break}}onPageChanging({pageNumber:t}){m(this,ma,t-1)}focusMainContainer(){l(this,Ki).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,ml).classList.toggle("noUserSelect",t)}addShouldRescale(t){l(this,zr).add(t)}removeShouldRescale(t){l(this,zr).delete(t)}onScaleChanging({scale:t}){var e;this.commitOrRemove(),this.viewParameters.realScale=t*Ln.PDF_TO_CSS_UNITS;for(const s of l(this,zr))s.onScaleChanging();(e=l(this,Br))==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,H,Dd).call(this,e).closest(".textLayer"),u=this.getSelectionBoxes(c);if(!u)return;e.empty();const d=w(this,H,tp).call(this,c),f=l(this,ee)===et.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(et.HIGHLIGHT,g);return}g()}addToAnnotationStorage(t){!t.isEmpty()&&l(this,$i)&&!l(this,$i).has(t.id)&&l(this,$i).setValue(t.id,t)}blur(){if(this.isShiftKeyDown=!1,l(this,zn)&&(m(this,zn,!1),w(this,H,Rd).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,Gr,[e,t]),e._focusEventsAllowed=!1;break}}focus(){if(!l(this,Gr))return;const[t,e]=l(this,Gr);m(this,Gr,null),e.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this._signal}),e.focus()}addEditListeners(){w(this,H,ep).call(this),w(this,H,sp).call(this)}removeEditListeners(){w(this,H,pv).call(this),w(this,H,ip).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,ns))==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){st(`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,H,np).call(this,h);w(this,H,rp).call(this,n)},o=()=>{for(const h of n)h.remove()};this.addCommands({cmd:r,undo:o,mustExec:!0})}catch(n){st(`paste: "${n.message}".`)}}keydown(t){!this.isShiftKeyDown&&t.key==="Shift"&&(this.isShiftKeyDown=!0),l(this,ee)!==et.NONE&&!this.isEditorHandlingKeyboard&&ya._keyboardManager.exec(this,t)}keyup(t){this.isShiftKeyDown&&t.key==="Shift"&&(this.isShiftKeyDown=!1,l(this,zn)&&(m(this,zn,!1),w(this,H,Rd).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,H,fv).call(this),w(this,H,sp).call(this),w(this,H,Ge).call(this,{isEditing:l(this,ee)!==et.NONE,isEmpty:w(this,H,kc).call(this),hasSomethingToUndo:l(this,xs).hasSomethingToUndo(),hasSomethingToRedo:l(this,xs).hasSomethingToRedo(),hasSelectedEditor:!1})):(w(this,H,gv).call(this),w(this,H,ip).call(this),w(this,H,Ge).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,H,Cn).call(this,e.defaultPropertiesToUpdate)}}getId(){return l(this,fd).id}get currentLayer(){return l(this,ae).get(l(this,ma))}getLayer(t){return l(this,ae).get(t)}get currentPageIndex(){return l(this,ma)}addLayer(t){l(this,ae).set(t.pageIndex,t),l(this,Gn)?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,Ss)&&(await l(this,Ss).promise,!l(this,Ss)))){if(m(this,Ss,Promise.withResolvers()),m(this,ee,t),t===et.NONE){this.setEditingState(!1),w(this,H,vv).call(this),(i=this._editorUndoBar)==null||i.hide(),l(this,Ss).resolve();return}this.setEditingState(!0),await w(this,H,bv).call(this),this.unselectAll();for(const n of l(this,ae).values())n.updateMode(t);if(!e){s&&this.addNewEditorFromKeyboard(),l(this,Ss).resolve();return}for(const n of l(this,Kt).values())n.annotationElementId===e?(this.setSelected(n),n.enterInEditMode()):n.unselect();l(this,Ss).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 at.CREATE:this.currentLayer.addNewEditor();return;case at.HIGHLIGHT_DEFAULT_COLOR:(s=l(this,dl))==null||s.updateColor(e);break;case at.HIGHLIGHT_SHOW_ALL:this._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:{type:"highlight",action:"toggle_visibility"}}}),(l(this,gl)||m(this,gl,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,gl))==null?void 0:n.get(at.HIGHLIGHT_SHOW_ALL))??!0)!==e&&w(this,H,Cn).call(this,[[at.HIGHLIGHT_SHOW_ALL,e]])}enableWaiting(t=!1){if(l(this,ul)!==t){m(this,ul,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,gi)&&clearTimeout(l(this,gi)),m(this,gi,setTimeout(()=>{this.focusMainContainer(),m(this,gi,null)},0))),l(this,Kt).delete(t.id),this.unselect(t),(!t.annotationElementId||!l(this,Hr).has(t.annotationElementId))&&((e=l(this,$i))==null||e.remove(t.id))}addDeletedAnnotationElement(t){l(this,Hr).add(t.annotationElementId),this.addChangedExistingAnnotation(t),t.deleted=!0}isDeletedAnnotationElement(t){return l(this,Hr).has(t)}removeDeletedAnnotationElement(t){l(this,Hr).delete(t.annotationElementId),this.removeChangedExistingAnnotation(t),t.deleted=!1}setActiveEditor(t){l(this,ns)!==t&&(m(this,ns,t),t&&w(this,H,Cn).call(this,t.propertiesToUpdate))}updateUI(t){l(this,H,yv)===t&&w(this,H,Cn).call(this,t.propertiesToUpdate)}updateUIForDefaultProperties(t){w(this,H,Cn).call(this,t.defaultPropertiesToUpdate)}toggleSelected(t){if(l(this,pt).has(t)){l(this,pt).delete(t),t.unselect(),w(this,H,Ge).call(this,{hasSelectedEditor:this.hasSelection});return}l(this,pt).add(t),t.select(),w(this,H,Cn).call(this,t.propertiesToUpdate),w(this,H,Ge).call(this,{hasSelectedEditor:!0})}setSelected(t){var e;(e=l(this,Br))==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,H,Cn).call(this,t.propertiesToUpdate),w(this,H,Ge).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,H,Ge).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,xs).undo(),w(this,H,Ge).call(this,{hasSomethingToUndo:l(this,xs).hasSomethingToUndo(),hasSomethingToRedo:!0,isEmpty:w(this,H,kc).call(this)}),(t=this._editorUndoBar)==null||t.hide()}redo(){l(this,xs).redo(),w(this,H,Ge).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:l(this,xs).hasSomethingToRedo(),isEmpty:w(this,H,kc).call(this)})}addCommands(t){l(this,xs).add(t),w(this,H,Ge).call(this,{hasSomethingToUndo:!0,hasSomethingToRedo:!1,isEmpty:w(this,H,kc).call(this)})}cleanUndoStack(t){l(this,xs).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,H,np).call(this,r)};this.addCommands({cmd:s,undo:i,mustExec:!0})}commitOrRemove(){var t;(t=l(this,ns))==null||t.commitOrRemove()}hasSomethingToControl(){return l(this,ns)||this.hasSelection}selectAll(){for(const t of l(this,pt))t.commit();w(this,H,rp).call(this,l(this,Kt).values())}unselectAll(){var t;if(!(l(this,ns)&&(l(this,ns).commitOrRemove(),l(this,ee)!==et.NONE))&&!((t=l(this,Br))!=null&&t.commitOrRemove())&&this.hasSelection){for(const e of l(this,pt))e.unselect();l(this,pt).clear(),w(this,H,Ge).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,mi)&&clearTimeout(l(this,mi)),m(this,mi,setTimeout(()=>{m(this,mi,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,fi,new Map);for(const t of l(this,pt))l(this,fi).set(t,{savedX:t.x,savedY:t.y,savedPageIndex:t.pageIndex,newX:0,newY:0,newPageIndex:-1})}}endDragSession(){if(!l(this,fi))return!1;this.disableUserSelect(!1);const t=l(this,fi);m(this,fi,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,fi))for(const s of l(this,fi).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,ns)===t}getActive(){return l(this,ns)}getMode(){return l(this,ee)}get imageManager(){return nt(this,"imageManager",new _g)}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,pa)||m(this,pa,new Map)).set(t,e)}removeChangedExistingAnnotation({annotationElementId:t}){var e;(e=l(this,pa))==null||e.delete(t)}renderAnnotationElement(t){var i;const e=(i=l(this,pa))==null?void 0:i.get(t.data.id);if(!e)return;const s=l(this,$i).getRawValue(e);s&&(l(this,ee)===et.NONE&&!s.hasBeenModified||s.renderAnnotationElement(t))}};fa=new WeakMap,ns=new WeakMap,Kt=new WeakMap,ae=new WeakMap,ga=new WeakMap,$i=new WeakMap,pa=new WeakMap,xs=new WeakMap,Bn=new WeakMap,Br=new WeakMap,ma=new WeakMap,Hr=new WeakMap,fi=new WeakMap,Vs=new WeakMap,zr=new WeakMap,hl=new WeakMap,ll=new WeakMap,ba=new WeakMap,cl=new WeakMap,gi=new WeakMap,Hn=new WeakMap,va=new WeakMap,zn=new WeakMap,pi=new WeakMap,fd=new WeakMap,Gn=new WeakMap,ul=new WeakMap,Vn=new WeakMap,Gr=new WeakMap,dl=new WeakMap,fl=new WeakMap,ee=new WeakMap,pt=new WeakMap,qi=new WeakMap,Vr=new WeakMap,gl=new WeakMap,pl=new WeakMap,Xn=new WeakMap,mi=new WeakMap,Ki=new WeakMap,ml=new WeakMap,Ss=new WeakMap,H=new WeakSet,Dd=function({anchorNode:t}){return t.nodeType===Node.TEXT_NODE?t.parentElement:t},tp=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},cv=function(){const t=document.getSelection();if(!t||t.isCollapsed)return;const s=w(this,H,Dd).call(this,t).closest(".textLayer"),i=this.getSelectionBoxes(s);i&&(l(this,pi)||m(this,pi,new Ox(this)),l(this,pi).show(s,i,this.direction==="ltr"))},uv=function(){var n,r,o;const t=document.getSelection();if(!t||t.isCollapsed){l(this,qi)&&((n=l(this,pi))==null||n.hide(),m(this,qi,null),w(this,H,Ge).call(this,{hasSelectedText:!1}));return}const{anchorNode:e}=t;if(e===l(this,qi))return;const i=w(this,H,Dd).call(this,t).closest(".textLayer");if(!i){l(this,qi)&&((r=l(this,pi))==null||r.hide(),m(this,qi,null),w(this,H,Ge).call(this,{hasSelectedText:!1}));return}if((o=l(this,pi))==null||o.hide(),m(this,qi,e),w(this,H,Ge).call(this,{hasSelectedText:!0}),!(l(this,ee)!==et.HIGHLIGHT&&l(this,ee)!==et.NONE)&&(l(this,ee)===et.HIGHLIGHT&&this.showAllEditors("highlight",!0,!0),m(this,zn,this.isShiftKeyDown),!this.isShiftKeyDown)){const h=l(this,ee)===et.HIGHLIGHT?w(this,H,tp).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,H,Rd).call(this,"main_toolbar"))};window.addEventListener("pointerup",d,{signal:u}),window.addEventListener("blur",d,{signal:u})}},Rd=function(t=""){l(this,ee)===et.HIGHLIGHT?this.highlightSelection(t):l(this,hl)&&w(this,H,cv).call(this)},dv=function(){document.addEventListener("selectionchange",w(this,H,uv).bind(this),{signal:this._signal})},fv=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})},gv=function(){var t;(t=l(this,Hn))==null||t.abort(),m(this,Hn,null)},ep=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})},pv=function(){var t;(t=l(this,Vn))==null||t.abort(),m(this,Vn,null)},sp=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})},ip=function(){var t;(t=l(this,Bn))==null||t.abort(),m(this,Bn,null)},mv=function(){const t=this._signal;document.addEventListener("dragover",this.dragOver.bind(this),{signal:t}),document.addEventListener("drop",this.drop.bind(this),{signal:t})},Ge=function(t){Object.entries(t).some(([s,i])=>l(this,pl)[s]!==i)&&(this._eventBus.dispatch("annotationeditorstateschanged",{source:this,details:Object.assign(l(this,pl),t)}),l(this,ee)===et.HIGHLIGHT&&t.hasSelectedEditor===!1&&w(this,H,Cn).call(this,[[at.HIGHLIGHT_FREE,!0]]))},Cn=function(t){this._eventBus.dispatch("annotationeditorparamschanged",{source:this,details:t})},bv=async function(){if(!l(this,Gn)){m(this,Gn,!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()}},vv=function(){if(this.unselectAll(),l(this,Gn)){m(this,Gn,!1);for(const t of l(this,ae).values())t.disable();for(const t of l(this,Kt).values())t.disable()}},np=function(t){const e=l(this,ae).get(t.pageIndex);e?e.addOrRebuild(t):(this.addEditor(t),this.addToAnnotationStorage(t))},yv=function(){let t=null;for(t of l(this,pt));return t},kc=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},rp=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,H,Ge).call(this,{hasSelectedEditor:this.hasSelection})},q(ya,"TRANSLATE_SMALL",1),q(ya,"TRANSLATE_BIG",10);let Or=ya;const Fe=class Fe{constructor(t){_(this,Ws);_(this,se,null);_(this,bi,!1);_(this,Xs,null);_(this,_a,null);_(this,vi,null);_(this,rs,null);_(this,wa,!1);_(this,yi,null);_(this,qe,null);_(this,Qi,null);_(this,Xr,null);_(this,_i,!1);m(this,qe,t),m(this,_i,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,_a,document.createElement("span"));t.append(e),l(this,_i)?(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,qe)._uiManager._signal;t.addEventListener("contextmenu",zs,{signal:s}),t.addEventListener("pointerdown",n=>n.stopPropagation(),{signal:s});const i=n=>{n.preventDefault(),l(this,qe)._uiManager.editAltText(l(this,qe)),l(this,_i)&&l(this,qe)._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_clicked",data:{label:l(this,Ws,Mc)}})};return t.addEventListener("click",i,{capture:!0,signal:s}),t.addEventListener("keydown",n=>{n.target===t&&n.key==="Enter"&&(m(this,wa,!0),i(n))},{signal:s}),await w(this,Ws,Ld).call(this),t}finish(){l(this,Xs)&&(l(this,Xs).focus({focusVisible:l(this,wa)}),m(this,wa,!1))}isEmpty(){return l(this,_i)?l(this,se)===null:!l(this,se)&&!l(this,bi)}hasData(){return l(this,_i)?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,Xr,await Fe._l10n.get("pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer",{generatedAltText:t})),w(this,Ws,Ld).call(this))}toggleAltTextBadge(t=!1){var e;if(!l(this,_i)||l(this,se)){(e=l(this,yi))==null||e.remove(),m(this,yi,null);return}if(!l(this,yi)){const s=m(this,yi,document.createElement("div"));s.className="noAltTextBadge",l(this,qe).div.append(s)}l(this,yi).classList.toggle("hidden",!t)}serialize(t){let e=l(this,se);return!t&&l(this,Qi)===e&&(e=l(this,Xr)),{altText:e,decorative:l(this,bi),guessedText:l(this,Qi),textWithDisclaimer:l(this,Xr)}}get data(){return{altText:l(this,se),decorative:l(this,bi)}}set data({altText:t,decorative:e,guessedText:s,textWithDisclaimer:i,cancel:n=!1}){s&&(m(this,Qi,s),m(this,Xr,i)),!(l(this,se)===t&&l(this,bi)===e)&&(n||(m(this,se,t),m(this,bi,e)),w(this,Ws,Ld).call(this))}toggle(t=!1){l(this,Xs)&&(!t&&l(this,rs)&&(clearTimeout(l(this,rs)),m(this,rs,null)),l(this,Xs).disabled=!t)}shown(){l(this,qe)._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_displayed",data:{label:l(this,Ws,Mc)}})}destroy(){var t,e;(t=l(this,Xs))==null||t.remove(),m(this,Xs,null),m(this,_a,null),m(this,vi,null),(e=l(this,yi))==null||e.remove(),m(this,yi,null)}};se=new WeakMap,bi=new WeakMap,Xs=new WeakMap,_a=new WeakMap,vi=new WeakMap,rs=new WeakMap,wa=new WeakMap,yi=new WeakMap,qe=new WeakMap,Qi=new WeakMap,Xr=new WeakMap,_i=new WeakMap,Wn=new WeakMap,Ws=new WeakSet,Mc=function(){return l(this,se)&&"added"||l(this,se)===null&&this.guessedText&&"review"||"missing"},Ld=async function(){var i,n,r;const t=l(this,Xs);if(!t)return;if(l(this,_i)){if(t.classList.toggle("done",!!l(this,se)),t.setAttribute("data-l10n-id",l(Fe,Wn)[l(this,Ws,Mc)]),(i=l(this,_a))==null||i.setAttribute("data-l10n-id",l(Fe,Wn)[`${l(this,Ws,Mc)}-label`]),!l(this,se)){(n=l(this,vi))==null||n.remove();return}}else{if(!l(this,se)&&!l(this,bi)){t.classList.remove("done"),(r=l(this,vi))==null||r.remove();return}t.classList.add("done"),t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-edit-button")}let e=l(this,vi);if(!e){m(this,vi,e=document.createElement("span")),e.className="tooltip",e.setAttribute("role","tooltip"),e.id=`alt-text-tooltip-${l(this,qe).id}`;const o=100,h=l(this,qe)._uiManager._signal;h.addEventListener("abort",()=>{clearTimeout(l(this,rs)),m(this,rs,null)},{once:!0}),t.addEventListener("mouseenter",()=>{m(this,rs,setTimeout(()=>{m(this,rs,null),l(this,vi).classList.add("show"),l(this,qe)._reportTelemetry({action:"alt_text_tooltip"})},o))},{signal:h}),t.addEventListener("mouseleave",()=>{var c;l(this,rs)&&(clearTimeout(l(this,rs)),m(this,rs,null)),(c=l(this,vi))==null||c.classList.remove("show")},{signal:h})}l(this,bi)?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,qe).getImageForAltText();s==null||s.setAttribute("aria-describedby",e.id)},_(Fe,Wn,null),q(Fe,"_l10n",null);let Qu=Fe;const Ug=class Ug{constructor({container:t,isPinchingDisabled:e=null,isPinchingStopped:s=null,onPinchStart:i=null,onPinching:n=null,onPinchEnd:r=null,signal:o}){_(this,Zi);_(this,bl);_(this,Wr,!1);_(this,vl,null);_(this,yl);_(this,_l);_(this,wl);_(this,xl);_(this,xa);_(this,Ji,null);_(this,Ur);_(this,Un,null);m(this,bl,t),m(this,vl,s),m(this,yl,e),m(this,_l,i),m(this,wl,n),m(this,xl,r),m(this,Ur,new AbortController),m(this,xa,AbortSignal.any([o,l(this,Ur).signal])),t.addEventListener("touchstart",w(this,Zi,_v).bind(this),{passive:!1,signal:l(this,xa)})}get MIN_TOUCH_DISTANCE_TO_PINCH(){return nt(this,"MIN_TOUCH_DISTANCE_TO_PINCH",35/(window.devicePixelRatio||1))}destroy(){var t;(t=l(this,Ur))==null||t.abort(),m(this,Ur,null)}};bl=new WeakMap,Wr=new WeakMap,vl=new WeakMap,yl=new WeakMap,_l=new WeakMap,wl=new WeakMap,xl=new WeakMap,xa=new WeakMap,Ji=new WeakMap,Ur=new WeakMap,Un=new WeakMap,Zi=new WeakSet,_v=function(t){var i,n,r;if((i=l(this,yl))!=null&&i.call(this)||t.touches.length<2)return;if(!l(this,Un)){m(this,Un,new AbortController);const o=AbortSignal.any([l(this,xa),l(this,Un).signal]),h=l(this,bl),c={signal:o,passive:!1};h.addEventListener("touchmove",w(this,Zi,wv).bind(this),c),h.addEventListener("touchend",w(this,Zi,op).bind(this),c),h.addEventListener("touchcancel",w(this,Zi,op).bind(this),c),(n=l(this,_l))==null||n.call(this)}if(is(t),t.touches.length!==2||(r=l(this,vl))!=null&&r.call(this)){m(this,Ji,null);return}let[e,s]=t.touches;e.identifier>s.identifier&&([e,s]=[s,e]),m(this,Ji,{touch0X:e.screenX,touch0Y:e.screenY,touch1X:s.screenX,touch1Y:s.screenY})},wv=function(t){var S;if(!l(this,Ji)||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,Ji),{touch0X:c,touch0Y:u,touch1X:d,touch1Y:f}=h,g=d-c,p=f-u,b=r-i,y=o-n,v=Math.hypot(b,y)||1,x=Math.hypot(g,p)||1;if(!l(this,Wr)&&Math.abs(x-v)<=Ug.MIN_TOUCH_DISTANCE_TO_PINCH)return;if(h.touch0X=i,h.touch0Y=n,h.touch1X=r,h.touch1Y=o,t.preventDefault(),!l(this,Wr)){m(this,Wr,!0);return}const C=[(i+r)/2,(n+o)/2];(S=l(this,wl))==null||S.call(this,C,x,v)},op=function(t){var e;l(this,Un).abort(),m(this,Un,null),(e=l(this,xl))==null||e.call(this),l(this,Ji)&&(t.preventDefault(),m(this,Ji,null),m(this,Wr,!1))};let Ju=Ug;const it=class it{constructor(t){_(this,$);_(this,Yr,null);_(this,Us,null);_(this,xt,null);_(this,Sa,!1);_(this,Yn,null);_(this,Sl,"");_(this,$r,!1);_(this,he,null);_(this,qr,null);_(this,tn,null);_(this,$n,null);_(this,Cl,"");_(this,Kr,!1);_(this,os,null);_(this,Al,!1);_(this,Qr,!1);_(this,en,!1);_(this,wi,null);_(this,Ca,0);_(this,Aa,0);_(this,Cs,null);_(this,Jr,null);q(this,"_editToolbar",null);q(this,"_initialOptions",Object.create(null));q(this,"_initialData",null);q(this,"_isVisible",!0);q(this,"_uiManager",null);q(this,"_focusEventsAllowed",!0);_(this,Tl,!1);_(this,gd,it._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=it.prototype._resizeWithKeyboard,e=Or.TRANSLATE_SMALL,s=Or.TRANSLATE_BIG;return nt(this,"_resizerKeyboardManager",new $h([[["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"],it.prototype._stopResizingWithKeyboard]]))}get editorType(){return Object.getPrototypeOf(this).constructor._type}static get isDrawer(){return!1}static get _defaultLineColor(){return nt(this,"_defaultLineColor",this._colorManager.getHexCode("CanvasText"))}static deleteAnnotationElement(t){const e=new Lx({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(it._l10n??(it._l10n=t),it._l10nResizer||(it._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"})),it._borderLineWidth!==-1)return;const s=getComputedStyle(document.documentElement);it._borderLineWidth=parseFloat(s.getPropertyValue("--outline-width"))||0}static updateDefaultParams(t,e){}static get defaultPropertiesToUpdate(){return[]}static isHandlingMimeForPasting(t){return!1}static paste(t,e){_t("Not implemented")}get propertiesToUpdate(){return[]}get _isDraggable(){return l(this,Tl)}set _isDraggable(t){var e;m(this,Tl,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,gd)}setParent(t){t!==null?(this.pageIndex=t.pageIndex,this.pageDimensions=t.pageDimensions):w(this,$,Pc).call(this),this.parent=t}focusin(t){this._focusEventsAllowed&&(l(this,Kr)?m(this,Kr,!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,$,ap).call(this,this.parentDimensions,t,e)}translateInPage(t,e){l(this,os)||m(this,os,[this.x,this.y,this.width,this.height]),w(this,$,ap).call(this,this.pageDimensions,t,e),this.div.scrollIntoView({block:"nearest"})}drag(t,e){l(this,os)||m(this,os,[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,os)&&(l(this,os)[0]!==this.x||l(this,os)[1]!==this.y)}get _hasBeenResized(){return!!l(this,os)&&(l(this,os)[2]!==this.width||l(this,os)[3]!==this.height)}getBaseTranslation(){const[t,e]=this.parentDimensions,{_borderLineWidth:s}=it,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=it,El,hp).call(s,t,e,this.parentRotation)}pageTranslationToScreen(t,e){var s;return w(s=it,El,hp).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,$r)||(n.height=`${(100*e/i).toFixed(2)}%`)}fixDims(){const{style:t}=this.div,{height:e,width:s}=t,i=s.endsWith("%"),n=!l(this,$r)&&e.endsWith("%");if(i&&n)return;const[r,o]=this.parentDimensions;i||(t.width=`${(100*parseFloat(s)/r).toFixed(2)}%`),!l(this,$r)&&!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 yg(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(it._l10n),m(this,xt,new Qu(this)),l(this,Yr)&&(l(this,xt).data=l(this,Yr),m(this,Yr,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,Sa)?-1:0,this._isVisible||this.div.classList.add("hidden"),this.setInForeground(),w(this,$,dp).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),Ku(this,this.div,["pointerdown"]),this.isResizable&&this._uiManager._supportsPinchToZoom&&(l(this,Jr)||m(this,Jr,new Ju({container:this.div,isPinchingDisabled:()=>!this.isSelected,onPinchStart:w(this,$,Cv).bind(this),onPinching:w(this,$,Av).bind(this),onPinchEnd:w(this,$,Tv).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,Kr,!0),this._isDraggable){w(this,$,Ev).call(this,t);return}w(this,$,up).call(this,t)}get isSelected(){return this._uiManager.isSelected(this)}_onStartDragging(){}_onStopDragging(){}moveInDOM(){l(this,wi)&&clearTimeout(l(this,wi)),m(this,wi,setTimeout(()=>{var t;m(this,wi,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,en)}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,$,dp).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){_t("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,Yr,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,wi)&&(clearTimeout(l(this,wi)),m(this,wi,null)),w(this,$,Pc).call(this),this.removeEditToolbar(),l(this,Cs)){for(const s of l(this,Cs).values())clearTimeout(s);m(this,Cs,null)}this.parent=null,(e=l(this,Jr))==null||e.destroy(),m(this,Jr,null)}get isResizable(){return!1}makeResizable(){this.isResizable&&(w(this,$,xv).call(this),l(this,he).classList.remove("hidden"),Ku(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,tn,{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,$,kv).bind(this),o=w(this,$,Mv).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,$,Pv).bind(this,u),{signal:h}),c.setAttribute("data-l10n-id",it._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",it._l10nResizer[c])}}w(this,$,fp).call(this,0),m(this,en,!0),l(this,he).firstChild.focus({focusVisible:!0}),t.preventDefault(),t.stopImmediatePropagation()}_resizeWithKeyboard(t,e){l(this,en)&&w(this,$,cp).call(this,l(this,Cl),{deltaX:t,deltaY:e,fromKeyboard:!0})}_stopResizingWithKeyboard(){w(this,$,Pc).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,Al)}set isEditing(t){m(this,Al,t),this.parent&&(t?(this.parent.setSelected(this),this.parent.setActiveEditor(this)):this.parent.setActiveEditor(null))}setAspectRatio(t,e){m(this,$r,!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,Cs)||m(this,Cs,new Map);const{action:s}=t;let i=l(this,Cs).get(s);i&&clearTimeout(i),i=setTimeout(()=>{this._reportTelemetry(t),l(this,Cs).delete(s),l(this,Cs).size===0&&m(this,Cs,null)},it._telemetryTimeout),l(this,Cs).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,Sa,!1)}disable(){this.div&&(this.div.tabIndex=-1),m(this,Sa,!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()}};Yr=new WeakMap,Us=new WeakMap,xt=new WeakMap,Sa=new WeakMap,Yn=new WeakMap,Sl=new WeakMap,$r=new WeakMap,he=new WeakMap,qr=new WeakMap,tn=new WeakMap,$n=new WeakMap,Cl=new WeakMap,Kr=new WeakMap,os=new WeakMap,Al=new WeakMap,Qr=new WeakMap,en=new WeakMap,wi=new WeakMap,Ca=new WeakMap,Aa=new WeakMap,Cs=new WeakMap,Jr=new WeakMap,Tl=new WeakMap,gd=new WeakMap,$=new WeakSet,ap=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()},El=new WeakSet,hp=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]}},Fd=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]}},xv=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,$,Sv).bind(this,s),{signal:e}),i.addEventListener("contextmenu",zs,{signal:e}),i.tabIndex=-1}this.div.prepend(l(this,he))},Sv=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,qr,[e.screenX,e.screenY]);const n=new AbortController,r=this._uiManager.combinedSignal(n);this.parent.togglePointerEvents(!1),window.addEventListener("pointermove",w(this,$,cp).bind(this,t),{passive:!0,capture:!0,signal:r}),window.addEventListener("touchmove",is,{passive:!1,signal:r}),window.addEventListener("contextmenu",zs,{signal:r}),m(this,tn,{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,$,Id).call(this)};window.addEventListener("pointerup",c,{signal:r}),window.addEventListener("blur",c,{signal:r})},lp=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()},Id=function(){if(!l(this,tn))return;const{savedX:t,savedY:e,savedWidth:s,savedHeight:i}=l(this,tn);m(this,tn,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,$,lp).bind(this,n,r,o,h),undo:w(this,$,lp).bind(this,t,e,s,i),mustExec:!0})},cp=function(t,e){const[s,i]=this.parentDimensions,n=this.x,r=this.y,o=this.width,h=this.height,c=it.MIN_SIZE/s,u=it.MIN_SIZE/i,d=w(this,$,Fd).call(this,this.rotation),f=(L,B)=>[d[0]*L+d[2]*B,d[1]*L+d[3]*B],g=w(this,$,Fd).call(this,360-this.rotation),p=(L,B)=>[g[0]*L+g[2]*B,g[1]*L+g[3]*B];let b,y,v=!1,x=!1;switch(t){case"topLeft":v=!0,b=(L,B)=>[0,0],y=(L,B)=>[L,B];break;case"topMiddle":b=(L,B)=>[L/2,0],y=(L,B)=>[L/2,B];break;case"topRight":v=!0,b=(L,B)=>[L,0],y=(L,B)=>[0,B];break;case"middleRight":x=!0,b=(L,B)=>[L,B/2],y=(L,B)=>[0,B/2];break;case"bottomRight":v=!0,b=(L,B)=>[L,B],y=(L,B)=>[0,0];break;case"bottomMiddle":b=(L,B)=>[L/2,B],y=(L,B)=>[L/2,0];break;case"bottomLeft":v=!0,b=(L,B)=>[0,B],y=(L,B)=>[L,0];break;case"middleLeft":x=!0,b=(L,B)=>[0,B/2],y=(L,B)=>[L,B/2];break}const C=b(o,h),S=y(o,h);let A=f(...S);const k=it._round(n+A[0]),P=it._round(r+A[1]);let O=1,R=1,F,j;if(e.fromKeyboard)({deltaX:F,deltaY:j}=e);else{const{screenX:L,screenY:B}=e,[Z,kt]=l(this,qr);[F,j]=this.screenToPageTranslation(L-Z,B-kt),l(this,qr)[0]=L,l(this,qr)[1]=B}if([F,j]=p(F/s,j/i),v){const L=Math.hypot(o,h);O=R=Math.max(Math.min(Math.hypot(S[0]-C[0]-F,S[1]-C[1]-j)/L,1/o,1/h),c/o,u/h)}else x?O=Math.max(c,Math.min(1,Math.abs(S[0]-C[0]-F)))/o:R=Math.max(u,Math.min(1,Math.abs(S[1]-C[1]-j)))/h;const D=it._round(o*O),I=it._round(h*R);A=f(...y(D,I));const N=k-A[0],Y=P-A[1];l(this,os)||m(this,os,[this.x,this.y,this.width,this.height]),this.width=D,this.height=I,this.x=N,this.y=Y,this.setDims(s*D,i*I),this.fixAndSetPosition(),this._onResizing()},Cv=function(){var t;m(this,tn,{savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height}),(t=l(this,xt))==null||t.toggle(!1),this.parent.togglePointerEvents(!1)},Av=function(t,e,s){let n=.7*(s/e)+1-.7;if(n===1)return;const r=w(this,$,Fd).call(this,this.rotation),o=(k,P)=>[r[0]*k+r[2]*P,r[1]*k+r[3]*P],[h,c]=this.parentDimensions,u=this.x,d=this.y,f=this.width,g=this.height,p=it.MIN_SIZE/h,b=it.MIN_SIZE/c;n=Math.max(Math.min(n,1/f,1/g),p/f,b/g);const y=it._round(f*n),v=it._round(g*n);if(y===f&&v===g)return;l(this,os)||m(this,os,[u,d,f,g]);const x=o(f/2,g/2),C=it._round(u+x[0]),S=it._round(d+x[1]),A=o(y/2,v/2);this.x=C-A[0],this.y=S-A[1],this.width=y,this.height=v,this.setDims(h*y,c*v),this.fixAndSetPosition(),this._onResizing()},Tv=function(){var t;(t=l(this,xt))==null||t.toggle(!0),this.parent.togglePointerEvents(!0),w(this,$,Id).call(this)},up=function(t){const{isMac:e}=Re.platform;t.ctrlKey&&!e||t.shiftKey||t.metaKey&&e?this.parent.toggleSelected(this):this.parent.setSelected(this)},Ev=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,Kr,!1),this._uiManager.endDragSession()||w(this,$,up).call(this,c),s&&this._onStopDragging()};e&&(m(this,Ca,t.clientX),m(this,Aa,t.clientY),m(this,Yn,t.pointerId),m(this,Sl,t.pointerType),window.addEventListener("pointermove",c=>{s||(s=!0,this._onStartDragging());const{clientX:u,clientY:d,pointerId:f}=c;if(f!==l(this,Yn)){is(c);return}const[g,p]=this.screenToPageTranslation(u-l(this,Ca),d-l(this,Aa));m(this,Ca,u),m(this,Aa,d),this._uiManager.dragSelectedEditors(g,p)},r),window.addEventListener("touchmove",is,r),window.addEventListener("pointerdown",c=>{c.pointerType===l(this,Sl)&&(l(this,Jr)||c.isPrimary)&&o(c),is(c)},r));const h=c=>{if(!l(this,Yn)||l(this,Yn)===c.pointerId){o(c);return}is(c)};window.addEventListener("pointerup",h,{signal:n}),window.addEventListener("blur",h,{signal:n})},dp=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})},kv=function(t){it._resizerKeyboardManager.exec(this,t)},Mv=function(t){var e;l(this,en)&&((e=t.relatedTarget)==null?void 0:e.parentNode)!==l(this,he)&&w(this,$,Pc).call(this)},Pv=function(t){m(this,Cl,l(this,en)?t:"")},fp=function(t){if(l(this,Us))for(const e of l(this,Us))e.tabIndex=t},Pc=function(){m(this,en,!1),w(this,$,fp).call(this,-1),w(this,$,Id).call(this)},_(it,El),q(it,"_l10n",null),q(it,"_l10nResizer",null),q(it,"_borderLineWidth",-1),q(it,"_colorManager",new wg),q(it,"_zIndex",1),q(it,"_telemetryTimeout",1e3);let Ot=it;class Lx extends Ot{constructor(t){super(t),this.annotationElementId=t.annotationElementId,this.deleted=!0}serialize(){return this.serializeDeleted()}}const ab=3285377520,ws=4294901760,di=65535;class hb{constructor(t){this.h1=t?t&4294967295:ab,this.h2=t?t&4294967295:ab}update(t){let e,s;if(typeof t=="string"){e=new Uint8Array(t.length*2),s=0;for(let b=0,y=t.length;b<y;b++){const v=t.charCodeAt(b);v<=255?e[s++]=v:(e[s++]=v>>>8,e[s++]=v&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&di,p=f&di;for(let b=0;b<i;b++)b&1?(o=r[b],o=o*d&ws|o*g&di,o=o<<15|o>>>17,o=o*f&ws|o*p&di,c^=o,c=c<<13|c>>>19,c=c*5+3864292196):(h=r[b],h=h*d&ws|h*g&di,h=h<<15|h>>>17,h=h*f&ws|h*p&di,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&ws|o*g&di,o=o<<15|o>>>17,o=o*f&ws|o*p&di,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&ws|t*36045&di,e=e*4283543511&ws|((e<<16|t>>>16)*2950163797&ws)>>>16,t^=e>>>1,t=t*444984403&ws|t*60499&di,e=e*3301882366&ws|((e<<16|t>>>16)*3120437893&ws)>>>16,t^=e>>>1,(t>>>0).toString(16).padStart(8,"0")+(e>>>0).toString(16).padStart(8,"0")}}const xg=Object.freeze({map:null,hash:"",transfer:void 0});class Sg{constructor(){_(this,pd);_(this,Zr,!1);_(this,to,null);_(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 Ot)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,pd,Ov).call(this),e instanceof Ot&&typeof this.onAnnotationEditor=="function"&&this.onAnnotationEditor(e.constructor._type)}has(t){return l(this,ie).has(t)}getAll(){return l(this,ie).size>0?cg(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,Zr)&&(m(this,Zr,!1),typeof this.onResetModified=="function"&&this.onResetModified())}get print(){return new lb(this)}get serializable(){if(l(this,ie).size===0)return xg;const t=new Map,e=new hb,s=[],i=Object.create(null);let n=!1;for(const[r,o]of l(this,ie)){const h=o instanceof Ot?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}:xg}get editorStats(){let t=null;const e=new Map;for(const s of l(this,ie).values()){if(!(s instanceof Ot))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,to,null)}get modifiedIds(){if(l(this,to))return l(this,to);const t=[];for(const e of l(this,ie).values())!(e instanceof Ot)||!e.annotationElementId||!e.serialize()||t.push(e.annotationElementId);return m(this,to,{ids:new Set(t),hash:t.join(",")})}}Zr=new WeakMap,to=new WeakMap,ie=new WeakMap,pd=new WeakSet,Ov=function(){l(this,Zr)||(m(this,Zr,!0),typeof this.onSetModified=="function"&&this.onSetModified())};class lb extends Sg{constructor(e){super();_(this,kl);const{map:s,hash:i,transfer:n}=e.serializable,r=structuredClone(s,n?{transfer:n}:null);m(this,kl,{map:r,hash:i,transfer:n})}get print(){_t("Should not call PrintAnnotationStorage.print")}get serializable(){return l(this,kl)}get modifiedIds(){return nt(this,"modifiedIds",{ids:new Set,hash:""})}}kl=new WeakMap;class Fx{constructor({ownerDocument:t=globalThis.document,styleElement:e=null}){_(this,Ta,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,Ta).clear(),this.styleElement&&(this.styleElement.remove(),this.styleElement=null)}async loadSystemFont({systemFontInfo:t,_inspectFont:e}){if(!(!t||l(this,Ta).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,Ta).add(s),e==null||e(t)}catch{st(`Cannot load system font: ${t.baseFontName}, installing it could help to improve PDF rendering.`),this.removeNativeFontFace(r)}return}_t("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 st(`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 nt(this,"isFontLoadingAPISupported",t)}get isSyncFontLoadingSupported(){let t=!1;return(ve||typeof navigator<"u"&&typeof(navigator==null?void 0:navigator.userAgent)=="string"&&/Mozilla\/5.0.*?rv:\d+.*? Gecko/.test(navigator.userAgent))&&(t=!0),nt(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 nt(this,"_loadTestFont",t)}_prepareFontLoadEvent(t,e){function s(S,A){return S.charCodeAt(A)<<24|S.charCodeAt(A+1)<<16|S.charCodeAt(A+2)<<8|S.charCodeAt(A+3)&255}function i(S,A,k,P){const O=S.substring(0,A),R=S.substring(A+k);return O+P+R}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,A){if(++c>30){st("Load test font never loaded."),A();return}if(h.font="30px "+S,h.fillText(".",0,20),h.getImageData(0,0,1,1).data[3]>0){A();return}setTimeout(u.bind(null,S,A))}const d=`lt${Date.now()}${this.loadTestFontId++}`;let f=this._loadTestFont;f=i(f,976,d.length,d);const p=16,b=1482184792;let y=s(f,p);for(n=0,r=d.length-3;n<r;n+=4)y=y-b+s(d,n)|0;n<d.length&&(y=y-b+s(d+"XXX",n)|0),f=i(f,p,4,_x(y));const v=`url(data:font/opentype;base64,${btoa(f)});`,x=`@font-face {font-family:"${d}";src:${v}}`;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 A=this._document.createElement("span");A.textContent="Hi",A.style.fontFamily=S,C.append(A)}this._document.body.append(C),u(d,()=>{C.remove(),e.complete()})}}Ta=new WeakMap;class Ix{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,${Tx(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){st(`getPathGenerator - ignoring character: "${r}".`)}const n=new Path2D(i||"");return this.fontExtraProperties||t.delete(s),this.compiledGlyphs[e]=n}}const Zu={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 cb(){}function We(a){if(a instanceof Rn||a instanceof lg||a instanceof Wh||a instanceof ib||a instanceof Uu||a instanceof hg)return a;switch(a instanceof Error||typeof a=="object"&&a!==null||_t('wrapReason: Expected "reason" to be a (possibly cloned) Error.'),a.name){case"AbortException":return new Rn(a.message);case"InvalidPDFException":return new lg(a.message);case"MissingPDFException":return new Wh(a.message);case"PasswordException":return new ib(a.message,a.code);case"UnexpectedResponseException":return new Uu(a.message,a.status);case"UnknownErrorException":return new hg(a.message,a.details)}return new hg(a.message,a.toString())}class qh{constructor(t,e,s){_(this,As);_(this,Ea,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,As,Dv).bind(this),{signal:l(this,Ea).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,Ea))==null||t.abort(),m(this,Ea,null)}}Ea=new WeakMap,As=new WeakSet,Dv=function({data:t}){if(t.targetName!==this.sourceName)return;if(t.stream){w(this,As,Lv).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===Zu.DATA)i.resolve(t.data);else if(t.callback===Zu.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:Zu.DATA,callbackId:t.callbackId,data:r})},function(r){n.postMessage({sourceName:s,targetName:i,callback:Zu.ERROR,callbackId:t.callbackId,reason:We(r)})});return}if(t.streamId){w(this,As,Rv).call(this,t);return}e(t.data)},Rv=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)})})},Lv=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||cb).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,As,Nd).call(this,r,e);break;case Wt.ERROR:Xt(r,"error should have stream controller"),r.controller.error(We(t.reason)),w(this,As,Nd).call(this,r,e);break;case Wt.CANCEL_COMPLETE:t.success?r.cancelCall.resolve():r.cancelCall.reject(We(t.reason)),w(this,As,Nd).call(this,r,e);break;case Wt.CANCEL:if(!o)break;const h=We(t.reason);Promise.try(o.onCancel||cb,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")}},Nd=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 ub{constructor({enableHWA:t=!1}){_(this,Ml,!1);m(this,Ml,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,Ml)})}}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){_t("Abstract method `_createCanvas` called.")}}Ml=new WeakMap;class Nx extends ub{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 db{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){_t("Abstract method `_fetch` called.")}}class fb extends db{async _fetch(t){const e=await $u(t,this.isCompressed?"arraybuffer":"text");return e instanceof ArrayBuffer?new Uint8Array(e):Yu(e)}}class gb{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 jx extends gb{constructor({docId:e,ownerDocument:s=globalThis.document}){super();_(this,G);_(this,eo);_(this,ka);_(this,sn);_(this,nn);_(this,xe);_(this,so);_(this,io,0);m(this,nn,e),m(this,xe,s)}addFilter(e){if(!e)return"none";let s=l(this,G,Te).get(e);if(s)return s;const[i,n,r]=w(this,G,jd).call(this,e),o=e.length===1?i:`${i}${n}${r}`;if(s=l(this,G,Te).get(o),s)return l(this,G,Te).set(e,s),s;const h=`g_${l(this,nn)}_transfer_map_${ze(this,io)._++}`,c=w(this,G,_h).call(this,h);l(this,G,Te).set(e,c),l(this,G,Te).set(o,c);const u=w(this,G,wh).call(this,h);return w(this,G,Rc).call(this,i,n,r,u),c}addHCMFilter(e,s){var p;const i=`${e}-${s}`,n="base";let r=l(this,G,Oc).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,G,Oc).set(n,r)),!e||!s))return r.url;const o=w(this,G,Lc).call(this,e);e=U.makeHexColor(...o);const h=w(this,G,Lc).call(this,s);if(s=U.makeHexColor(...h),l(this,G,yh).style.color="",e==="#000000"&&s==="#ffffff"||e===s)return r.url;const c=new Array(256);for(let b=0;b<=255;b++){const y=b/255;c[b]=y<=.03928?y/12.92:((y+.055)/1.055)**2.4}const u=c.join(","),d=`g_${l(this,nn)}_hcm_filter`,f=r.filter=w(this,G,wh).call(this,d);w(this,G,Rc).call(this,u,u,u,f),w(this,G,gp).call(this,f);const g=(b,y)=>{const v=o[b]/255,x=h[b]/255,C=new Array(y+1);for(let S=0;S<=y;S++)C[S]=v+S/y*(x-v);return C.join(",")};return w(this,G,Rc).call(this,g(0,5),g(1,5),g(2,5),f),r.url=w(this,G,_h).call(this,d),r.url}addAlphaFilter(e){let s=l(this,G,Te).get(e);if(s)return s;const[i]=w(this,G,jd).call(this,[e]),n=`alpha_${i}`;if(s=l(this,G,Te).get(n),s)return l(this,G,Te).set(e,s),s;const r=`g_${l(this,nn)}_alpha_map_${ze(this,io)._++}`,o=w(this,G,_h).call(this,r);l(this,G,Te).set(e,o),l(this,G,Te).set(n,o);const h=w(this,G,wh).call(this,r);return w(this,G,pp).call(this,i,h),o}addLuminosityFilter(e){let s=l(this,G,Te).get(e||"luminosity");if(s)return s;let i,n;if(e?([i]=w(this,G,jd).call(this,[e]),n=`luminosity_${i}`):n="luminosity",s=l(this,G,Te).get(n),s)return l(this,G,Te).set(e,s),s;const r=`g_${l(this,nn)}_luminosity_map_${ze(this,io)._++}`,o=w(this,G,_h).call(this,r);l(this,G,Te).set(e,o),l(this,G,Te).set(n,o);const h=w(this,G,wh).call(this,r);return w(this,G,Fv).call(this,h),e&&w(this,G,pp).call(this,i,h),o}addHighlightHCMFilter(e,s,i,n,r){var x;const o=`${s}-${i}-${n}-${r}`;let h=l(this,G,Oc).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,G,Oc).set(e,h)),!s||!i))return h.url;const[c,u]=[s,i].map(w(this,G,Lc).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,G,Lc).bind(this));f<d&&([d,f,g,p]=[f,d,p,g]),l(this,G,yh).style.color="";const b=(C,S,A)=>{const k=new Array(256),P=(f-d)/A,O=C/255,R=(S-C)/(255*A);let F=0;for(let j=0;j<=A;j++){const D=Math.round(d+j*P),I=O+j*R;for(let N=F;N<=D;N++)k[N]=I;F=D+1}for(let j=F;j<256;j++)k[j]=k[F-1];return k.join(",")},y=`g_${l(this,nn)}_hcm_${e}_filter`,v=h.filter=w(this,G,wh).call(this,y);return w(this,G,gp).call(this,v),w(this,G,Rc).call(this,b(g[0],p[0],5),b(g[1],p[1],5),b(g[2],p[2],5),v),h.url=w(this,G,_h).call(this,y),h.url}destroy(e=!1){var s,i,n,r;e&&((s=l(this,so))!=null&&s.size)||((i=l(this,sn))==null||i.parentNode.parentNode.remove(),m(this,sn,null),(n=l(this,ka))==null||n.clear(),m(this,ka,null),(r=l(this,so))==null||r.clear(),m(this,so,null),m(this,io,0))}}eo=new WeakMap,ka=new WeakMap,sn=new WeakMap,nn=new WeakMap,xe=new WeakMap,so=new WeakMap,io=new WeakMap,G=new WeakSet,Te=function(){return l(this,ka)||m(this,ka,new Map)},Oc=function(){return l(this,so)||m(this,so,new Map)},yh=function(){if(!l(this,sn)){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(Xi,"svg");i.setAttribute("width",0),i.setAttribute("height",0),m(this,sn,l(this,xe).createElementNS(Xi,"defs")),e.append(i),i.append(l(this,sn)),l(this,xe).body.append(e)}return l(this,sn)},jd=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(",")]},_h=function(e){if(l(this,eo)===void 0){m(this,eo,"");const s=l(this,xe).URL;s!==l(this,xe).baseURI&&(qu(s)?st('#createUrl: ignore "data:"-URL for performance reasons.'):m(this,eo,s.split("#",1)[0]))}return`url(${l(this,eo)}#${e})`},Fv=function(e){const s=l(this,xe).createElementNS(Xi,"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)},gp=function(e){const s=l(this,xe).createElementNS(Xi,"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)},wh=function(e){const s=l(this,xe).createElementNS(Xi,"filter");return s.setAttribute("color-interpolation-filters","sRGB"),s.setAttribute("id",e),l(this,G,yh).append(s),s},Dc=function(e,s,i){const n=l(this,xe).createElementNS(Xi,s);n.setAttribute("type","discrete"),n.setAttribute("tableValues",i),e.append(n)},Rc=function(e,s,i,n){const r=l(this,xe).createElementNS(Xi,"feComponentTransfer");n.append(r),w(this,G,Dc).call(this,r,"feFuncR",e),w(this,G,Dc).call(this,r,"feFuncG",s),w(this,G,Dc).call(this,r,"feFuncB",i)},pp=function(e,s){const i=l(this,xe).createElementNS(Xi,"feComponentTransfer");s.append(i),w(this,G,Dc).call(this,i,"feFuncA",e)},Lc=function(e){return l(this,G,yh).style.color=e,bg(getComputedStyle(l(this,G,yh)).getPropertyValue("color"))};class pb{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){_t("Abstract method `_fetch` called.")}}class mb extends pb{async _fetch(t){const e=await $u(t,"arraybuffer");return new Uint8Array(e)}}ve&&st("Please use the `legacy` build in Node.js environments.");async function bb(a){const e=await process.getBuiltinModule("fs").promises.readFile(a);return new Uint8Array(e)}class Bx extends gb{}class Hx extends ub{_createCanvas(t,e){return process.getBuiltinModule("module").createRequire(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Mt&&Mt.tagName.toUpperCase()==="SCRIPT"&&Mt.src||new URL("pdf-canvas.umd.js",document.baseURI).href)("@napi-rs/canvas").createCanvas(t,e)}}class zx extends db{async _fetch(t){return bb(t)}}class Gx extends pb{async _fetch(t){return bb(t)}}const _e={FILL:"Fill",STROKE:"Stroke",SHADING:"Shading"};function Cg(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 Ag{getPattern(){_t("Abstract method `getPattern` called.")}}class Vx extends Ag{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,At(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=U.transform(s,[1,0,0,1,r[0],r[1]]),u.transform(...e.baseTransform),this.matrix&&u.transform(...this.matrix),Cg(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 Cg(t,this._bbox),n=this._createGradient(t);return n}}function Tg(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,y=(h[s+1]+t.offsetY)*t.scaleY,v=(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],A=c[n+2],k=c[r],P=c[r+1],O=c[r+2],R=c[o],F=c[o+1],j=c[o+2],D=Math.round(p),I=Math.round(x);let N,Y,L,B,Z,kt,te,fe;for(let Yt=D;Yt<=I;Yt++){if(Yt<y){const ft=Yt<p?0:(p-Yt)/(p-y);N=g-(g-b)*ft,Y=C-(C-k)*ft,L=S-(S-P)*ft,B=A-(A-O)*ft}else{let ft;Yt>x?ft=1:y===x?ft=0:ft=(y-Yt)/(y-x),N=b-(b-v)*ft,Y=k-(k-R)*ft,L=P-(P-F)*ft,B=O-(O-j)*ft}let St;Yt<p?St=0:Yt>x?St=1:St=(p-Yt)/(p-x),Z=g-(g-v)*St,kt=C-(C-R)*St,te=S-(S-F)*St,fe=A-(A-j)*St;const He=Math.round(Math.min(N,Z)),Oi=Math.round(Math.max(N,Z));let It=d*Yt+He*4;for(let ft=He;ft<=Oi;ft++)St=(N-ft)/(N-Z),St<0?St=0:St>1&&(St=1),u[It++]=Y-(Y-kt)*St|0,u[It++]=L-(L-te)*St|0,u[It++]=B-(B-fe)*St|0,u[It++]=255}}function Xx(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++)Tg(a,e,s[u],s[u+1],s[u+o],i[u],i[u+1],i[u+o]),Tg(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)Tg(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 Wx extends Ag{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},y=d+2*2,v=f+2*2,x=s.getCanvas("mesh",y,v),C=x.context,S=C.createImageData(d,f);if(e){const k=S.data;for(let P=0,O=k.length;P<O;P+=4)k[P]=e[0],k[P+1]=e[1],k[P+2]=e[2],k[P+3]=255}for(const k of this._figures)Xx(S,k,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){Cg(t,this._bbox);let n;if(i===_e.SHADING)n=U.singularValueDecompose2dScale(At(t));else if(n=U.singularValueDecompose2dScale(e.baseTransform),this.matrix){const o=U.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 Ux extends Ag{getPattern(){return"hotpink"}}function Yx(a){switch(a[0]){case"RadialAxial":return new Vx(a);case"Mesh":return new Wx(a);case"Dummy":return new Ux}throw new Error(`Unknown IR type: ${a[0]}`)}const vb={COLORED:1,UNCOLORED:2},md=class md{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),Wu("TilingType: "+n);const u=e[0],d=e[1],f=e[2],g=e[3],p=f-u,b=g-d,y=U.singularValueDecompose2dScale(this.matrix),v=U.singularValueDecompose2dScale(this.baseTransform),x=y[0]*v[0],C=y[1]*v[1];let S=p,A=b,k=!1,P=!1;const O=Math.ceil(h*x),R=Math.ceil(c*C),F=Math.ceil(p*x),j=Math.ceil(b*C);O>=F?S=h:k=!0,R>=j?A=c:P=!0;const D=this.getSizeAndScale(S,this.ctx.canvas.width,x),I=this.getSizeAndScale(A,this.ctx.canvas.height,C),N=t.cachedCanvases.getCanvas("pattern",D.size,I.size),Y=N.context,L=o.createCanvasGraphics(Y);if(L.groupLevel=t.groupLevel,this.setFillAndStrokeStyleToContext(L,i,r),Y.translate(-D.scale*u,-I.scale*d),L.transform(D.scale,0,0,I.scale,0,0),Y.save(),this.clipBbox(L,u,d,f,g),L.baseTransform=At(L.ctx),L.executeOperatorList(s),L.endDrawing(),Y.restore(),k||P){const B=N.canvas;k&&(S=h),P&&(A=c);const Z=this.getSizeAndScale(S,this.ctx.canvas.width,x),kt=this.getSizeAndScale(A,this.ctx.canvas.height,C),te=Z.size,fe=kt.size,Yt=t.cachedCanvases.getCanvas("pattern-workaround",te,fe),St=Yt.context,He=k?Math.floor(p/h):0,Oi=P?Math.floor(b/c):0;for(let It=0;It<=He;It++)for(let ft=0;ft<=Oi;ft++)St.drawImage(B,te*It,fe*ft,te,fe,0,0,te,fe);return{canvas:Yt.canvas,scaleX:Z.scale,scaleY:kt.scale,offsetX:u,offsetY:d}}return{canvas:N.canvas,scaleX:D.scale,scaleY:I.scale,offsetX:u,offsetY:d}}getSizeAndScale(t,e,s){const i=Math.max(md.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(At(t.ctx),[e,s,i,n]),t.clip(),t.endPath()}setFillAndStrokeStyleToContext(t,e,s){const i=t.ctx,n=t.current;switch(e){case vb.COLORED:const r=this.ctx;i.fillStyle=r.fillStyle,i.strokeStyle=r.strokeStyle,n.fillColor=r.fillStyle,n.strokeColor=r.strokeStyle;break;case vb.UNCOLORED:const o=U.makeHexColor(s[0],s[1],s[2]);i.fillStyle=o,i.strokeStyle=o,n.fillColor=o,n.strokeColor=o;break;default:throw new yx(`Unsupported paint type: ${e}`)}}getPattern(t,e,s,i){let n=s;i!==_e.SHADING&&(n=U.transform(n,e.baseTransform),this.matrix&&(n=U.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}};q(md,"MAX_PATTERN_SIZE",3e3);let Eg=md;function $x({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 y=t+u;t<y;t++){const v=t<f?a[t]:255;e[g++]=v&128?c:h,e[g++]=v&64?c:h,e[g++]=v&32?c:h,e[g++]=v&16?c:h,e[g++]=v&8?c:h,e[g++]=v&4?c:h,e[g++]=v&2?c:h,e[g++]=v&1?c:h}if(d===0)continue;const b=t<f?a[t++]:255;for(let y=0;y<d;y++)e[g++]=b&1<<7-y?c:h}return{srcPos:t,destPos:g}}const yb=16,_b=100,qx=15,wb=10,xb=1e3,Ue=16;function Kx(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 Qx{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 td(a,t,e,s,i,n,r,o,h,c){const[u,d,f,g,p,b]=At(a);if(d===0&&f===0){const x=r*u+p,C=Math.round(x),S=o*g+b,A=Math.round(S),k=(r+h)*u+p,P=Math.abs(Math.round(k)-C)||1,O=(o+c)*g+b,R=Math.abs(Math.round(O)-A)||1;return a.setTransform(Math.sign(u),0,0,Math.sign(g),C,A),a.drawImage(t,e,s,i,n,0,0,P,R),a.setTransform(u,d,f,g,p,b),[P,R]}if(u===0&&g===0){const x=o*f+p,C=Math.round(x),S=r*d+b,A=Math.round(S),k=(o+c)*f+p,P=Math.abs(Math.round(k)-C)||1,O=(r+h)*d+b,R=Math.abs(Math.round(O)-A)||1;return a.setTransform(0,Math.sign(d),Math.sign(f),0,C,A),a.drawImage(t,e,s,i,n,0,0,R,P),a.setTransform(u,d,f,g,p,b),[R,P]}a.drawImage(t,e,s,i,n,r,o,h,c);const y=Math.hypot(u,d),v=Math.hypot(f,g);return[y*h,v*c]}function Jx(a){const{width:t,height:e}=a;if(t>xb||e>xb)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 v of a.data){let x=128;for(;x>0;)d[f++]=v&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 v=(d[f]?4:0)+(d[f-u]?8:0);for(h=1;h<t;h++)v=(v>>2)+(d[f+1]?4:0)+(d[f-u+1]?8:0),i[v]&&(r[c+h]=i[v],++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 v=o*n;const x=v+t;for(;v<x&&!r[v];)v++;if(v===x)continue;b.moveTo(v%n,o);const C=v;let S=r[v];do{const A=p[S];do v+=A;while(!r[v]);const k=r[v];k!==5&&k!==10?(S=k,r[v]=0):(S=k&51*S>>4,r[v]&=S>>2|S<<2),b.lineTo(v%n,v/n|0),r[v]||--g}while(C!==v);--o}return d=null,r=null,function(v){v.save(),v.scale(1/t,-1/e),v.translate(0,-e),v.fill(b),v.beginPath(),v.restore()}}class Sb{constructor(t,e){this.alphaIsShape=!1,this.fontSize=0,this.fontSizeScale=1,this.textMatrix=sb,this.textMatrixScale=1,this.fontMatrix=og,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=ye.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]=U.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=U.applyTransform(e,t),i=U.applyTransform(e.slice(2),t),n=U.applyTransform([e[0],e[3]],t),r=U.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){U.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=U.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||_t("Stroke bounding box must include transform.");const i=U.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=U.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 U.intersect(this.clipBox,this.getPathBoundingBox(t,e))}}function Cb(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===Gu.GRAYSCALE_1BPP){const y=u.byteLength,v=new Uint32Array(d.buffer,0,d.byteLength>>2),x=v.length,C=s+7>>3,S=4294967295,A=Re.isLittleEndian?4278190080:255;for(f=0;f<r;f++){for(p=f<n?Ue:i,c=0,g=0;g<p;g++){const k=y-h;let P=0;const O=k>C?s:k*8-7,R=O&-8;let F=0,j=0;for(;P<R;P+=8)j=u[h++],v[c++]=j&128?S:A,v[c++]=j&64?S:A,v[c++]=j&32?S:A,v[c++]=j&16?S:A,v[c++]=j&8?S:A,v[c++]=j&4?S:A,v[c++]=j&2?S:A,v[c++]=j&1?S:A;for(;P<O;P++)F===0&&(j=u[h++],F=128),v[c++]=j&F?S:A,F>>=1}for(;c<x;)v[c++]=0;a.putImageData(o,0,f*Ue)}}else if(t.kind===Gu.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===Gu.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 Ab(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}=$x({src:c,srcPos:h,dest:u,width:s,height:f,nonBlackColor:0})),a.putImageData(o,0,d*Ue)}}function Kh(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 ed(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),!ve){const{filter:t}=a;t!=="none"&&t!==""&&(a.filter="none")}}function Tb(a,t){if(t)return!0;const e=U.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 Zx=["butt","round","square"],tS=["miter","round","bevel"],eS={},Eb={},Yg=class Yg{constructor(t,e,s,i,n,{optionalContentConfig:r,markedContentStack:o=null},h,c){_(this,Ys);this.ctx=t,this.current=new Sb(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 Qx(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(...At(this.compositeCtx))}this.ctx.save(),ed(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=At(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>wb&&typeof s=="function",u=c?Date.now()+qx: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 y=b.startsWith("g_")?f:g;if(!y.has(b))return y.get(b,s),o}if(o++,o===h)return o;if(c&&++d>wb){if(Date.now()>u)return s(),o;d=0}}}endDrawing(){w(this,Ys,mp).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,bp).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=At(e);let h,c,u,d;if((t.bitmap||t.data)&&t.count>1){const O=t.bitmap||t.data.buffer;c=JSON.stringify(r?o:[o.slice(0,4),n]),h=this._cachedBitmapsMap.get(O),h||(h=new Map,this._cachedBitmapsMap.set(O,h));const R=h.get(c);if(R&&!r){const F=Math.round(Math.min(o[0],o[2])+o[4]),j=Math.round(Math.min(o[1],o[3])+o[5]);return{canvas:R,offsetX:F,offsetY:j}}u=R}u||(d=this.cachedCanvases.getCanvas("maskCanvas",s,i),Ab(d.context,t));let f=U.transform(o,[1/s,0,0,-1/i,0,0]);f=U.transform(f,[1,0,0,1,0,-i]);const[g,p,b,y]=U.getAxialAlignedBoundingBox([0,0,s,i],f),v=Math.round(b-g)||1,x=Math.round(y-p)||1,C=this.cachedCanvases.getCanvas("fillCanvas",v,x),S=C.context,A=g,k=p;S.translate(-A,-k),S.transform(...f),u||(u=this._scaleImage(d.canvas,ui(S)),u=u.img,h&&r&&h.set(c,u)),S.imageSmoothingEnabled=Tb(At(S),t.interpolate),td(S,u,0,0,u.width,u.height,0,0,s,i),S.globalCompositeOperation="source-in";const P=U.transform(ui(S),[1,0,0,1,-A,-k]);return S.fillStyle=r?n.getPattern(e,this,P,_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(A),offsetY:Math.round(k)}}setLineWidth(t){t!==this.current.lineWidth&&(this._cachedScaleForStroking[0]=-1),this.current.lineWidth=t,this.ctx.lineWidth=t}setLineCap(t){this.ctx.lineCap=Zx[t]}setLineJoin(t){this.ctx.lineJoin=tS[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(...At(this.suspendedCtx)),Kh(this.suspendedCtx,n),Kx(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(),Kh(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 y=U.makeHexColor(...r);if(g<0||p<0||g+s>f.width||p+i>f.height){const v=this.cachedCanvases.getCanvas("maskExtension",s,i),x=v.context;x.drawImage(f,-g,-p),x.globalCompositeOperation="destination-atop",x.fillStyle=y,x.fillRect(0,0,s,i),x.globalCompositeOperation="source-over",f=v.canvas,g=p=0}else{t.save(),t.globalAlpha=1,t.setTransform(1,0,0,1,0,0);const v=new Path2D;v.rect(g,p,s,i),t.clip(v),t.globalCompositeOperation="destination-atop",t.fillStyle=y,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?(Kh(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(),Kh(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=At(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 y=e[p++],v=e[p++],x=r+y,C=o+v;i.moveTo(r,o),y===0||v===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,ui(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,ui(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=eS}eoClip(){this.pendingClip=Eb}beginText(){this.current.textMatrix=sb,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||og,(i.fontMatrix[0]===0||i.fontMatrix[3]===0)&&st("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<yb?c=yb:e>_b&&(c=_b),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&ye.FILL_STROKE_MASK,f=!!(c&ye.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===ye.FILL||d===ye.FILL_STROKE)if(i){const y=r.getTransform();r.setTransform(...i),r.fill(w(this,Ys,vp).call(this,b,y,i))}else r.fill(b);if(d===ye.STROKE||d===ye.FILL_STROKE)if(n){const y=r.getTransform();r.setTransform(...n),r.stroke(w(this,Ys,vp).call(this,b,y,n))}else r.lineWidth/=u,r.stroke(b);r.restore()}else(d===ye.FILL||d===ye.FILL_STROKE)&&r.fillText(t,e,s),(d===ye.STROKE||d===ye.FILL_STROKE)&&r.strokeText(t,e,s);f&&(this.pendingTextPaths||(this.pendingTextPaths=[])).push({transform:At(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 nt(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],y=e.textRenderingMode===ye.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 v,x;if(e.patternFill){n.save();const P=e.fillColor.getPattern(n,this,ui(n),_e.FILL);v=At(n),n.restore(),n.fillStyle=P}if(e.patternStroke){n.save();const P=e.strokeColor.getPattern(n,this,ui(n),_e.STROKE);x=At(n),n.restore(),n.strokeStyle=P}let C=e.lineWidth;const S=e.textMatrixScale;if(S===0||C===0){const P=e.textRenderingMode&ye.FILL_STROKE_MASK;(P===ye.STROKE||P===ye.FILL_STROKE)&&(C=this.getSinglePixelWidth())}else C/=S;if(r!==1&&(n.scale(r,r),C/=r),n.lineWidth=C,s.isInvalidPDFjsFont){const P=[];let O=0;for(const R of t)P.push(R.unicode),O+=R.width;n.fillText(P.join(""),0,0),e.x+=O*b*u,n.restore(),this.compose();return}let A=0,k;for(k=0;k<d;++k){const P=t[k];if(typeof P=="number"){A+=g*P*i/1e3;continue}let O=!1;const R=(P.isSpace?h:0)+o,F=P.fontChar,j=P.accent;let D,I,N=P.width;if(f){const L=P.vmetric||p,B=-(P.vmetric?L[1]:N*.5)*b,Z=L[2]*b;N=L?-L[0]:N,D=B/r,I=(A+Z)/r}else D=A/r,I=0;if(s.remeasure&&N>0){const L=n.measureText(F).width*1e3/i*r;if(N<L&&this.isFontSubpixelAAEnabled){const B=N/L;O=!0,n.save(),n.scale(B,1),D/=B}else N!==L&&(D+=(N-L)/2e3*i/r)}if(this.contentVisible&&(P.isInFont||s.missingFile)){if(y&&!j)n.fillText(F,D,I);else if(this.paintChar(F,D,I,v,x),j){const L=D+i*j.offset.x/r,B=I-i*j.offset.y/r;this.paintChar(j.fontChar,L,B,v,x)}}const Y=f?N*b-R*c:N*b+R*c;A+=Y,O&&n.restore()}f?e.y-=A:e.x+=A*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||og,f=t.length,g=s.textRenderingMode===ye.INVISIBLE;let p,b,y,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"){v=o*b*n/1e3,this.ctx.translate(v,0),s.x+=v*u;continue}const x=(b.isSpace?c:0)+h,C=i.charProcOperatorList[b.operatorListId];if(!C){st(`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()),y=U.applyTransform([b.width,0],d)[0]*n+x,e.translate(y,0),s.x+=y*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||At(this.ctx),n={createCanvasGraphics:r=>new Yg(r,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:this.optionalContentConfig,markedContentStack:this.markedContentStack})};e=new Eg(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=U.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=U.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=Yx(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,ui(e),_e.SHADING);const i=ui(e);if(i){const{width:n,height:r}=e.canvas,[o,h,c,u]=U.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(){_t("Should not call beginInlineImage")}beginImageData(){_t("Should not call beginImageData")}paintFormXObjectBegin(t,e){if(this.contentVisible&&(this.save(),this.baseTransformStack.push(this.baseTransform),t&&this.transform(...t),this.baseTransform=At(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(At(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||Wu("TODO: Support non-isolated groups."),t.knockout&&st("Knockout groups not supported.");const s=At(e);if(t.matrix&&e.transform(...t.matrix),!t.bbox)throw new Error("Bounding box is required.");let i=U.getAxialAlignedBoundingBox(t.bbox,At(e));const n=[0,0,e.canvas.width,e.canvas.height];i=U.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()),Kh(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=At(this.ctx);this.restore(),this.ctx.save(),this.ctx.setTransform(...i);const n=U.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,mp).call(this),ed(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]=U.singularValueDecompose2dScale(At(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),ed(this.ctx)}else ed(this.ctx),this.endPath(),this.ctx.rect(e[0],e[1],r,o),this.ctx.clip(),this.ctx.beginPath()}this.current=new Sb(this.ctx.canvas.width,this.ctx.canvas.height),this.transform(...s),this.transform(...i)}endAnnotation(){this.annotationCanvas&&(this.ctx.restore(),w(this,Ys,bp).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=Jx(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=At(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=U.transform(h,[e,s,i,n,r[u],r[u+1]]),[g,p]=U.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);Ab(d,f),d.globalCompositeOperation="source-in",d.fillStyle=i?s.getPattern(d,this,ui(e),_e.FILL):s,d.fillRect(0,0,o,h),d.restore(),e.save(),e.transform(...c),e.scale(1,-1),td(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){st("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){st("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(),!ve){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;Cb(h,t),n=this.applyTransferMapsToCanvas(h)}const r=this._scaleImage(n,ui(i));i.imageSmoothingEnabled=Tb(At(i),t.interpolate),td(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;Cb(h,t),i=this.applyTransferMapsToCanvas(h)}for(const n of e)s.save(),s.transform(...n.transform),s.scale(1,-1),td(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===Eb?s.clip("evenodd"):s.clip()),this.pendingClip=null),this.current.startNewPathAndClipBox(this.current.clipBox),s.beginPath()}getSinglePixelWidth(){if(!this._cachedGetSinglePixelWidth){const t=At(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,mp=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)},bp=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}}},vp=function(t,e,s){const i=new Path2D;return i.addPath(t,new DOMMatrix(s).invertSelf().multiplySelf(e)),i};let ha=Yg;for(const a in Hs)ha.prototype[a]!==void 0&&(ha.prototype[Hs[a]]=ha.prototype[a]);class Wi{static get workerPort(){return l(this,Pl)}static set workerPort(t){if(!(typeof Worker<"u"&&t instanceof Worker)&&t!==null)throw new Error("Invalid `workerPort` type.");m(this,Pl,t)}static get workerSrc(){return l(this,Ol)}static set workerSrc(t){if(typeof t!="string")throw new Error("Invalid `workerSrc` type.");m(this,Ol,t)}}Pl=new WeakMap,Ol=new WeakMap,_(Wi,Pl,null),_(Wi,Ol,"");class sS{constructor({parsedData:t,rawData:e}){_(this,no);_(this,Dl);m(this,no,t),m(this,Dl,e)}getRaw(){return l(this,Dl)}get(t){return l(this,no).get(t)??null}getAll(){return cg(l(this,no))}has(t){return l(this,no).has(t)}}no=new WeakMap,Dl=new WeakMap;const la=Symbol("INTERNAL");class iS{constructor(t,{name:e,intent:s,usage:i,rbGroups:n}){_(this,Rl,!1);_(this,Ll,!1);_(this,Fl,!1);_(this,Ma,!0);m(this,Rl,!!(t&ss.DISPLAY)),m(this,Ll,!!(t&ss.PRINT)),this.name=e,this.intent=s,this.usage=i,this.rbGroups=n}get visible(){if(l(this,Fl))return l(this,Ma);if(!l(this,Ma))return!1;const{print:t,view:e}=this.usage;return l(this,Rl)?(e==null?void 0:e.viewState)!=="OFF":l(this,Ll)?(t==null?void 0:t.printState)!=="OFF":!0}_setVisible(t,e,s=!1){t!==la&&_t("Internal method `_setVisible` called."),m(this,Fl,s),m(this,Ma,e)}}Rl=new WeakMap,Ll=new WeakMap,Fl=new WeakMap,Ma=new WeakMap;class nS{constructor(t,e=ss.DISPLAY){_(this,Il);_(this,qn,null);_(this,mt,new Map);_(this,Pa,null);_(this,Oa,null);if(this.renderingIntent=e,this.name=null,this.creator=null,t!==null){this.name=t.name,this.creator=t.creator,m(this,Oa,t.order);for(const s of t.groups)l(this,mt).set(s.id,new iS(e,s));if(t.baseState==="OFF")for(const s of l(this,mt).values())s._setVisible(la,!1);for(const s of t.on)l(this,mt).get(s)._setVisible(la,!0);for(const s of t.off)l(this,mt).get(s)._setVisible(la,!1);m(this,Pa,this.getHash())}}isVisible(t){if(l(this,mt).size===0)return!0;if(!t)return Wu("Optional content group not defined."),!0;if(t.type==="OCG")return l(this,mt).has(t.id)?l(this,mt).get(t.id).visible:(st(`Optional content group not found: ${t.id}`),!0);if(t.type==="OCMD"){if(t.expression)return w(this,Il,yp).call(this,t.expression);if(!t.policy||t.policy==="AnyOn"){for(const e of t.ids){if(!l(this,mt).has(e))return st(`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 st(`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 st(`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 st(`Optional content group not found: ${e}`),!0;if(l(this,mt).get(e).visible)return!1}return!0}return st(`Unknown optional content policy ${t.policy}.`),!0}return st(`Unknown group type ${t.type}.`),!0}setVisibility(t,e=!0,s=!0){var n;const i=l(this,mt).get(t);if(!i){st(`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(la,!1,!0));i._setVisible(la,!!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,Pa)===null||this.getHash()===l(this,Pa)}getOrder(){return l(this,mt).size?l(this,Oa)?l(this,Oa).slice():[...l(this,mt).keys()]:null}getGroups(){return l(this,mt).size>0?cg(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 hb;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,Pa=new WeakMap,Oa=new WeakMap,Il=new WeakSet,yp=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,Il,yp).call(this,n);else if(l(this,mt).has(n))r=l(this,mt).get(n).visible;else return st(`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 rS{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 oS(this,t,this._progressiveDone,this._contentDispositionFilename)}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new aS(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 oS{constructor(t,e,s=!1,i=null){this._stream=t,this._done=s||!1,this._filename=pg(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 aS{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 hS(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=Yu(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,y,v]=f;if(b=parseInt(b,10),b in d){if(b===0)break;continue}d[b]=[y,v]}const p=[];for(let b=0;b<d.length&&b in d;++b){let[y,v]=d[b];v=o(v),y&&(v=unescape(v),b===0&&(v=h(v))),p.push(v)}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,y){return String.fromCharCode(parseInt(y,16))}),i(f,p);try{p=atob(p)}catch{}return i(f,p)})}return""}function kb(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 sd(a){try{return new URL(a).origin}catch{}return null}function Mb({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 Pb(a){const t=a.get("Content-Disposition");if(t){let e=hS(t);if(e.includes("%"))try{e=decodeURIComponent(e)}catch{}if(pg(e))return e}return null}function id(a,t){return a===404||a===0&&t.startsWith("file:")?new Wh('Missing PDF "'+t+'".'):new Uu(`Unexpected server response (${a}) while retrieving PDF "${t}".`,a)}function Ob(a){return a===200||a===206}function Db(a,t,e){return{method:"GET",headers:a,signal:e.signal,mode:"cors",credentials:t?"include":"same-origin",redirect:"follow"}}function Rb(a){return a instanceof Uint8Array?a.buffer:a instanceof ArrayBuffer?a:(st(`getArrayBuffer - unexpected data format: ${a}`),new Uint8Array(a).buffer)}class Lb{constructor(t){q(this,"_responseOrigin",null);this.source=t,this.isHttp=/^https?:/i.test(t.url),this.headers=kb(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 lS(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new cS(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 lS{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,Db(s,this._withCredentials,this._abortController)).then(n=>{if(t._responseOrigin=sd(n.url),!Ob(n.status))throw id(n.status,i);this._reader=n.body.getReader(),this._headersCapability.resolve();const r=n.headers,{allowRangeRequests:o,suggestedLength:h}=Mb({responseHeaders:r,isHttp:t.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});this._isRangeSupported=o,this._contentLength=h||this._contentLength,this._filename=Pb(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:Rb(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}class cS{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,Db(n,this._withCredentials,this._abortController)).then(o=>{const h=sd(o.url);if(h!==t._responseOrigin)throw new Error(`Expected range response-origin "${h}" to match "${t._responseOrigin}".`);if(!Ob(o.status))throw id(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:Rb(t),done:!1})}cancel(t){var e;(e=this._reader)==null||e.cancel(t),this._abortController.abort()}}const kg=200,Mg=206;function uS(a){const t=a.response;return typeof t!="string"?t:Yu(t).buffer}class dS{constructor({url:t,httpHeaders:e,withCredentials:s}){q(this,"_responseOrigin",null);this.url=t,this.isHttp=/^https?:/i.test(t),this.headers=kb(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=Mg):i.expectedStatus=kg,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||kg;if(!(n===kg&&s.expectedStatus===Mg)&&n!==s.expectedStatus){s.onError(i.status);return}const o=uS(i);if(n===Mg){const h=i.getResponseHeader("Content-Range"),c=/bytes (\d+)-(\d+)\/(\d+)/.exec(h);c?s.onDone({begin:parseInt(c[1],10),chunk:o}):(st('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 fS{constructor(t){this._source=t,this._manager=new dS(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 gS(this._manager,this._source),this._fullRequestReader}getRangeReader(t,e){const s=new pS(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 gS{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=sd(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}=Mb({responseHeaders:i,isHttp:this._manager.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});n&&(this._isRangeSupported=!0),this._contentLength=r||this._contentLength,this._filename=Pb(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=id(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 pS{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=sd((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=id(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 mS=/^[a-z][a-z0-9\-+.]+:/i;function bS(a){if(mS.test(a))return new URL(a);const t=process.getBuiltinModule("url");return new URL(t.pathToFileURL(a))}class vS{constructor(t){this.source=t,this.url=bS(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 yS(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const s=new _S(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 yS{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 Wh(`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 _S{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 wS=1e5,Ye=30,xS=.8,Qt=class Qt{constructor({textContentSource:t,container:e,viewport:s}){_(this,on);_(this,Kn,Promise.withResolvers());_(this,Ke,null);_(this,Nl,!1);_(this,jl,!!((tv=globalThis.FontInspector)!=null&&tv.enabled));_(this,ro,null);_(this,rn,null);_(this,Bl,0);_(this,Hl,0);_(this,oo,null);_(this,Da,null);_(this,Ra,0);_(this,Qn,0);_(this,La,Object.create(null));_(this,zl,[]);_(this,Fa,null);_(this,ao,[]);_(this,Gl,new WeakMap);_(this,Vl,null);var h;if(t instanceof ReadableStream)m(this,Fa,t);else if(typeof t=="object")m(this,Fa,new ReadableStream({start(c){c.enqueue(t),c.close()}}));else throw new Error('No "textContentSource" parameter specified.');m(this,Ke,m(this,Da,e)),m(this,Qn,s.scale*(globalThis.devicePixelRatio||1)),m(this,Ra,s.rotation),m(this,rn,{div:null,properties:null,ctx:null});const{pageWidth:i,pageHeight:n,pageX:r,pageY:o}=s.rawDims;m(this,Vl,[1,0,0,-1,-r,o+n]),m(this,Hl,i),m(this,Bl,n),w(h=Qt,as,jv).call(h),Pr(e,s),l(this,Kn).promise.finally(()=>{l(Qt,Ia).delete(this),m(this,rn,null),m(this,La,null)}).catch(()=>{})}static get fontFamilyMap(){const{isWindows:t,isFirefox:e}=Re.platform;return nt(this,"fontFamilyMap",new Map([["sans-serif",`${t&&e?"Calibri, ":""}sans-serif`],["monospace",`${t&&e?"Lucida Console, ":""}monospace`]]))}render(){const t=()=>{l(this,oo).read().then(({value:e,done:s})=>{if(s){l(this,Kn).resolve();return}l(this,ro)??m(this,ro,e.lang),Object.assign(l(this,La),e.styles),w(this,on,Iv).call(this,e.items),t()},l(this,Kn).reject)};return m(this,oo,l(this,Fa).getReader()),l(Qt,Ia).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,Ra)&&(e==null||e(),m(this,Ra,i),Pr(l(this,Da),{rotation:i})),s!==l(this,Qn)){e==null||e(),m(this,Qn,s);const r={div:null,properties:null,ctx:w(n=Qt,as,Bd).call(n,l(this,ro))};for(const o of l(this,ao))r.properties=l(this,Gl).get(o),r.div=o,w(this,on,_p).call(this,r)}}cancel(){var e;const t=new Rn("TextLayer task cancelled.");(e=l(this,oo))==null||e.cancel(t).catch(()=>{}),m(this,oo,null),l(this,Kn).reject(t)}get textDivs(){return l(this,ao)}get textContentItemsStr(){return l(this,zl)}static cleanup(){if(!(l(this,Ia).size>0)){l(this,ho).clear();for(const{canvas:t}of l(this,lo).values())t.remove();l(this,lo).clear()}}};Kn=new WeakMap,Ke=new WeakMap,Nl=new WeakMap,jl=new WeakMap,ro=new WeakMap,rn=new WeakMap,Bl=new WeakMap,Hl=new WeakMap,oo=new WeakMap,Da=new WeakMap,Ra=new WeakMap,Qn=new WeakMap,La=new WeakMap,zl=new WeakMap,Fa=new WeakMap,ao=new WeakMap,Gl=new WeakMap,Vl=new WeakMap,ho=new WeakMap,lo=new WeakMap,Xl=new WeakMap,Jn=new WeakMap,Ia=new WeakMap,on=new WeakSet,Iv=function(t){var i,n;if(l(this,Nl))return;(n=l(this,rn)).ctx??(n.ctx=w(i=Qt,as,Bd).call(i,l(this,ro)));const e=l(this,ao),s=l(this,zl);for(const r of t){if(e.length>wS){st("Ignoring additional textDivs for performance reasons."),m(this,Nl,!0);return}if(r.str===void 0){if(r.type==="beginMarkedContentProps"||r.type==="beginMarkedContent"){const o=l(this,Ke);m(this,Ke,document.createElement("span")),l(this,Ke).classList.add("markedContent"),r.id!==null&&l(this,Ke).setAttribute("id",`${r.id}`),o.append(l(this,Ke))}else r.type==="endMarkedContent"&&m(this,Ke,l(this,Ke).parentNode);continue}s.push(r.str),w(this,on,Nv).call(this,r)}},Nv=function(t){var b;const e=document.createElement("span"),s={angle:0,canvasWidth:0,hasText:t.str!=="",hasEOL:t.hasEOL,fontSize:0};l(this,ao).push(e);const i=U.transform(l(this,Vl),t.transform);let n=Math.atan2(i[1],i[0]);const r=l(this,La)[t.fontName];r.vertical&&(n+=Math.PI/2);let o=l(this,jl)&&r.fontSubstitution||r.fontFamily;o=Qt.fontFamilyMap.get(o)||o;const h=Math.hypot(i[2],i[3]),c=h*w(b=Qt,as,Bv).call(b,o,l(this,ro));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,Ke)===l(this,Da)?(g.left=`${(100*u/l(this,Hl)).toFixed(2)}%`,g.top=`${(100*d/l(this,Bl)).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,jl)&&(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 y=Math.abs(t.transform[0]),v=Math.abs(t.transform[3]);y!==v&&Math.max(y,v)/Math.min(y,v)>1.5&&(p=!0)}if(p&&(s.canvasWidth=r.vertical?t.height:t.width),l(this,Gl).set(e,s),l(this,rn).div=e,l(this,rn).properties=s,w(this,on,_p).call(this,l(this,rn)),s.hasText&&l(this,Ke).append(e),s.hasEOL){const y=document.createElement("br");y.setAttribute("role","presentation"),l(this,Ke).append(y)}},_p=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,as,wp).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)},as=new WeakSet,Bd=function(t=null){let e=l(this,lo).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,lo).set(t,e),l(this,Xl).set(e,{size:0,family:""})}return e},wp=function(t,e,s){const i=l(this,Xl).get(t);e===i.size&&s===i.family||(t.font=`${e}px ${s}`,i.size=e,i.family=s)},jv=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()},Bv=function(t,e){const s=l(this,ho).get(t);if(s)return s;const i=w(this,as,Bd).call(this,e);i.canvas.width=i.canvas.height=Ye,w(this,as,wp).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,ho).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):xS;return l(this,ho).set(t,c),c},_(Qt,as),_(Qt,ho,new Map),_(Qt,lo,new Map),_(Qt,Xl,new WeakMap),_(Qt,Jn,null),_(Qt,Ia,new Set);let Qh=Qt;class Jh{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(Jh.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 SS=65536,CS=100,AS=5e3,TS=ve?Hx:Nx,ES=ve?zx:fb,kS=ve?Bx:jx,MS=ve?Gx:mb;function PS(a={}){typeof a=="string"||a instanceof URL?a={url:a}:(a instanceof ArrayBuffer||ArrayBuffer.isView(a))&&(a={data:a});const t=new Pg,{docId:e}=t,s=a.url?OS(a.url):null,i=a.data?DS(a.data):null,n=a.httpHeaders||null,r=a.withCredentials===!0,o=a.password??null,h=a.range instanceof Ib?a.range:null,c=Number.isInteger(a.rangeChunkSize)&&a.rangeChunkSize>0?a.rangeChunkSize:SS;let u=a.worker instanceof ca?a.worker:null;const d=a.verbosity,f=typeof a.docBaseUrl=="string"&&!qu(a.docBaseUrl)?a.docBaseUrl:null,g=typeof a.cMapUrl=="string"?a.cMapUrl:null,p=a.cMapPacked!==!1,b=a.CMapReaderFactory||ES,y=typeof a.standardFontDataUrl=="string"?a.standardFontDataUrl:null,v=a.StandardFontDataFactory||MS,x=a.stopAtErrors!==!0,C=Number.isInteger(a.maxImageSize)&&a.maxImageSize>-1?a.maxImageSize:-1,S=a.isEvalSupported!==!1,A=typeof a.isOffscreenCanvasSupported=="boolean"?a.isOffscreenCanvasSupported:!ve,k=typeof a.isImageDecoderSupported=="boolean"?a.isImageDecoderSupported:!ve&&(Re.platform.isFirefox||!globalThis.chrome),P=Number.isInteger(a.canvasMaxAreaInBytes)?a.canvasMaxAreaInBytes:-1,O=typeof a.disableFontFace=="boolean"?a.disableFontFace:ve,R=a.fontExtraProperties===!0,F=a.enableXfa===!0,j=a.ownerDocument||globalThis.document,D=a.disableRange===!0,I=a.disableStream===!0,N=a.disableAutoFetch===!0,Y=a.pdfBug===!0,L=a.CanvasFactory||TS,B=a.FilterFactory||kS,Z=a.enableHWA===!0,kt=h?h.length:a.length??NaN,te=typeof a.useSystemFonts=="boolean"?a.useSystemFonts:!ve&&!O,fe=typeof a.useWorkerFetch=="boolean"?a.useWorkerFetch:b===fb&&v===mb&&g&&y&&Yh(g,document.baseURI)&&Yh(y,document.baseURI),Yt=null;px(d);const St={canvasFactory:new L({ownerDocument:j,enableHWA:Z}),filterFactory:new B({docId:e,ownerDocument:j}),cMapReaderFactory:fe?null:new b({baseUrl:g,isCompressed:p}),standardFontDataFactory:fe?null:new v({baseUrl:y})};if(!u){const It={verbosity:d,port:Wi.workerPort};u=It.port?ca.fromPort(It):new ca(It),t._worker=u}const He={docId:e,apiVersion:"4.10.38",data:i,password:o,disableAutoFetch:N,rangeChunkSize:c,length:kt,docBaseUrl:f,enableXfa:F,evaluatorOptions:{maxImageSize:C,disableFontFace:O,ignoreErrors:x,isEvalSupported:S,isOffscreenCanvasSupported:A,isImageDecoderSupported:k,canvasMaxAreaInBytes:P,fontExtraProperties:R,useSystemFonts:te,cMapUrl:fe?g:null,standardFontDataUrl:fe?y:null}},Oi={disableFontFace:O,fontExtraProperties:R,ownerDocument:j,pdfBug:Y,styleElement:Yt,loadingParams:{disableAutoFetch:N,enableXfa:F}};return u.promise.then(function(){if(t.destroyed)throw new Error("Loading aborted");if(u.destroyed)throw new Error("Worker was destroyed");const It=u.messageHandler.sendWithPromise("GetDocRequest",He,i?[i.buffer]:null);let ft;if(h)ft=new rS(h,{disableRange:D,disableStream:I});else if(!i){if(!s)throw new Error("getDocument - no `url` parameter provided.");let fr;if(ve)if(Yh(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=Lb}else fr=vS;else fr=Yh(s)?Lb:fS;ft=new fr({url:s,length:kt,httpHeaders:n,withCredentials:r,rangeChunkSize:c,disableRange:D,disableStream:I})}return It.then(fr=>{if(t.destroyed)throw new Error("Loading aborted");if(u.destroyed)throw new Error("Worker was destroyed");const vh=new qh(e,fr,u.port),Di=new IS(vh,t,ft,Oi,St);t._transport=Di,vh.send("Ready",null)})}).catch(t._capability.reject),t}function OS(a){if(a instanceof URL)return a.href;try{return new URL(a,window.location).href}catch{if(ve&&typeof a=="string")return a}throw new Error("Invalid PDF url data: either string or URL-object is expected in the url property.")}function DS(a){if(ve&&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 Yu(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 Fb(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 vd=class vd{constructor(){this._capability=Promise.withResolvers(),this._transport=null,this._worker=null,this.docId=`d${ze(vd,bd)._++}`,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}};bd=new WeakMap,_(vd,bd,0);let Pg=vd;class Ib{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){_t("Abstract method PDFDataRangeTransport.requestDataRange")}abort(){}}class RS{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 nt(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 LS{constructor(t,e,s,i=!1){_(this,Ts);_(this,Zn,null);_(this,an,!1);this._pageIndex=t,this._pageInfo=e,this._transport=s,this._stats=i?new ob:null,this._pdfBug=i,this.commonObjs=s.commonObjs,this.objs=new Nb,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 Uh({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 nt(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=On.ENABLE,transform:n=null,background:r=null,optionalContentConfigPromise:o=null,annotationCanvasMap:h=null,pageColors:c=null,printAnnotationStorage:u=null,isEditing:d=!1}){var S,A;(S=this._stats)==null||S.time("Overall");const f=this._transport.getRenderingIntent(s,i,u,d),{renderingIntent:g,cacheKey:p}=f;m(this,an,!1),w(this,Ts,Hd).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 y=!!(g&ss.PRINT);b.displayReadyCapability||(b.displayReadyCapability=Promise.withResolvers(),b.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},(A=this._stats)==null||A.time("Page Request"),this._pumpOperatorList(f));const v=k=>{var P;b.renderTasks.delete(x),(this._maybeCleanupAfterRender||y)&&m(this,an,!0),w(this,Ts,xh).call(this,!y),k?(x.capability.reject(k),this._abortOperatorList({intentState:b,reason:k instanceof Error?k:new Error(k)})):x.capability.resolve(),this._stats&&(this._stats.timeEnd("Rendering"),this._stats.timeEnd("Overall"),(P=globalThis.Stats)!=null&&P.enabled&&globalThis.Stats.add(this.pageNumber,this._stats))},x=new Og({callback:v,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:!y,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(([k,P])=>{var O;if(this.destroyed){v();return}if((O=this._stats)==null||O.time("Rendering"),!(P.renderingIntent&g))throw new Error("Must use the same `intent`-argument when calling the `PDFPageProxy.render` and `PDFDocumentProxy.getOptionalContentConfig` methods.");x.initializeGraphics({transparency:k,optionalContentConfig:P}),x.operatorListChanged()}).catch(v),C}getOperatorList({intent:t="display",annotationMode:e=On.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=>Jh.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,an,!1),w(this,Ts,Hd).call(this),Promise.all(t)}cleanup(t=!1){m(this,an,!0);const e=w(this,Ts,xh).call(this,!1);return t&&e&&this._stats&&(this._stats=new ob),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,Ts,xh).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,Ts,xh).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 gg){let i=CS;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,an=new WeakMap,Ts=new WeakSet,xh=function(t=!1){if(w(this,Ts,Hd).call(this),!l(this,an)||this.destroyed)return!1;if(t)return m(this,Zn,setTimeout(()=>{m(this,Zn,null),w(this,Ts,xh).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,an,!1),!0},Hd=function(){l(this,Zn)&&(clearTimeout(l(this,Zn)),m(this,Zn,null))};class FS{constructor(){_(this,hn,new Map);_(this,yd,Promise.resolve())}postMessage(t,e){const s={data:structuredClone(t,e?{transfer:e}:null)};l(this,yd).then(()=>{for(const[i]of l(this,hn))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){st("LoopbackPort - cannot use an `aborted` signal.");return}const r=()=>this.removeEventListener(t,e);i=()=>n.removeEventListener("abort",r),n.addEventListener("abort",r)}l(this,hn).set(e,i)}removeEventListener(t,e){const s=l(this,hn).get(e);s==null||s(),l(this,hn).delete(e)}terminate(){for(const[,t]of l(this,hn))t==null||t();l(this,hn).clear()}}hn=new WeakMap,yd=new WeakMap;const Tt=class Tt{constructor({name:t=null,port:e=null,verbosity:s=mx()}={}){_(this,Na);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(Tt,uo))!=null&&i.has(e))throw new Error("Cannot use more than one PDFWorker per port.");(l(Tt,uo)||m(Tt,uo,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 qh("main","worker",t),this._messageHandler.on("ready",function(){}),w(this,Na,zd).call(this)}_initialize(){if(l(Tt,co)||l(Tt,ja,Gd)){this._setupFakeWorker();return}let{workerSrc:t}=Tt;try{Tt._isSameOrigin(window.location.href,t)||(t=Tt._createCDNWrapper(new URL(t,window.location).href));const e=new Worker(t,{type:"module"}),s=new qh("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,Na,zd).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{Wu("The worker has been disabled.")}this._setupFakeWorker()}_setupFakeWorker(){l(Tt,co)||(st("Setting up fake worker."),m(Tt,co,!0)),Tt._setupFakeWorkerGlobal.then(t=>{if(this.destroyed){this._readyCapability.reject(new Error("Worker was destroyed"));return}const e=new FS;this._port=e;const s=`fake${ze(Tt,_d)._++}`,i=new qh(s+"_worker",s,e);t.setup(i,e),this._messageHandler=new qh(s,s+"_worker",e),w(this,Na,zd).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(Tt,uo))==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,uo))==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 Tt(t)}static get workerSrc(){if(Wi.workerSrc)return Wi.workerSrc;throw new Error('No "GlobalWorkerOptions.workerSrc" specified.')}static get _setupFakeWorkerGlobal(){return nt(this,"_setupFakeWorkerGlobal",(async()=>l(this,ja,Gd)?l(this,ja,Gd):(await import(this.workerSrc)).WorkerMessageHandler)())}};_d=new WeakMap,co=new WeakMap,uo=new WeakMap,Na=new WeakSet,zd=function(){this._readyCapability.resolve(),this._messageHandler.send("configure",{verbosity:this.verbosity})},ja=new WeakSet,Gd=function(){var t;try{return((t=globalThis.pdfjsWorker)==null?void 0:t.WorkerMessageHandler)||null}catch{return null}},_(Tt,ja),_(Tt,_d,0),_(Tt,co,!1),_(Tt,uo),ve&&(m(Tt,co,!0),Wi.workerSrc||(Wi.workerSrc="./pdf.worker.mjs")),Tt._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},Tt._createCDNWrapper=t=>{const e=`await import("${t}");`;return URL.createObjectURL(new Blob([e],{type:"text/javascript"}))};let ca=Tt;class IS{constructor(t,e,s,i,n){_(this,fo);_(this,ln,new Map);_(this,xi,new Map);_(this,Ba,new Map);_(this,Ha,new Map);_(this,cn,null);this.messageHandler=t,this.loadingTask=e,this.commonObjs=new Nb,this.fontLoader=new Fx({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 nt(this,"annotationStorage",new Sg)}getRenderingIntent(t,e=On.ENABLE,s=null,i=!1,n=!1){let r=ss.DISPLAY,o=xg;switch(t){case"any":r=ss.ANY;break;case"display":break;case"print":r=ss.PRINT;break;default:st(`getRenderingIntent - invalid intent: ${t}`)}const h=r&ss.PRINT&&s instanceof lb?s:this.annotationStorage;switch(e){case On.DISABLE:r+=ss.ANNOTATIONS_DISABLE;break;case On.ENABLE:break;case On.ENABLE_FORMS:r+=ss.ANNOTATIONS_FORMS;break;case On.ENABLE_STORAGE:r+=ss.ANNOTATIONS_STORAGE,o=h.serializable;break;default:st(`getRenderingIntent - invalid annotationMode: ${e}`)}i&&(r+=ss.IS_EDITING),n&&(r+=ss.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,cn))==null||s.reject(new Error("Worker was destroyed during onPassword callback"));const t=[];for(const i of l(this,xi).values())t.push(i._destroy());l(this,xi).clear(),l(this,Ba).clear(),l(this,Ha).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,ln).clear(),this.filterFactory.destroy(),Qh.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 RS(s,this))}),t.on("DocException",s=>{e._capability.reject(We(s))}),t.on("PasswordRequest",s=>{m(this,cn,Promise.withResolvers());try{if(!e.onPassword)throw We(s);const i=n=>{n instanceof Error?l(this,cn).reject(n):l(this,cn).resolve({password:n})};e.onPassword(i,s.code)}catch(i){l(this,cn).reject(i)}return l(this,cn).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,xi).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;st(`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 Ix(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,xi).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,xi).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)>ux&&(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&&st("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,Ba).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,Ha).set(n.refStr,t);const r=new LS(e,n,this,this._params.pdfBug);return l(this,xi).set(e,r),r});return l(this,Ba).set(e,i),i}getPageIndex(t){return Fb(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,fo,Fc).call(this,"GetFieldObjects")}hasJSActions(){return w(this,fo,Fc).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,fo,Fc).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,fo,Fc).call(this,"GetOptionalContentConfig").then(e=>new nS(e,t))}getPermissions(){return this.messageHandler.sendWithPromise("GetPermissions",null)}getMetadata(){const t="GetMetadata",e=l(this,ln).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 sS(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,ln).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,xi).values())if(!e.cleanup())throw new Error(`startCleanup: Page ${e.pageNumber} is currently rendering.`);this.commonObjs.clear(),t||this.fontLoader.clear(),l(this,ln).clear(),this.filterFactory.destroy(!0),Qh.cleanup()}}cachedPageNumber(t){if(!Fb(t))return null;const e=t.gen===0?`${t.num}R`:`${t.num}R${t.gen}`;return l(this,Ha).get(e)??null}}ln=new WeakMap,xi=new WeakMap,Ba=new WeakMap,Ha=new WeakMap,cn=new WeakMap,fo=new WeakSet,Fc=function(t,e=null){const s=l(this,ln).get(t);if(s)return s;const i=this.messageHandler.sendWithPromise(t,e);return l(this,ln).set(t,i),i};const Zh=Symbol("INITIAL_DATA");class Nb{constructor(){_(this,Wl);_(this,hs,Object.create(null))}get(t,e=null){if(e){const i=w(this,Wl,xp).call(this,t);return i.promise.then(()=>e(i.data)),null}const s=l(this,hs)[t];if(!s||s.data===Zh)throw new Error(`Requesting object that isn't resolved yet ${t}.`);return s.data}has(t){const e=l(this,hs)[t];return!!e&&e.data!==Zh}delete(t){const e=l(this,hs)[t];return!e||e.data===Zh?!1:(delete l(this,hs)[t],!0)}resolve(t,e=null){const s=w(this,Wl,xp).call(this,t);s.data=e,s.resolve()}clear(){var t;for(const e in l(this,hs)){const{data:s}=l(this,hs)[e];(t=s==null?void 0:s.bitmap)==null||t.close()}m(this,hs,Object.create(null))}*[Symbol.iterator](){for(const t in l(this,hs)){const{data:e}=l(this,hs)[t];e!==Zh&&(yield[t,e])}}}hs=new WeakMap,Wl=new WeakSet,xp=function(t){var e;return(e=l(this,hs))[t]||(e[t]={...Promise.withResolvers(),data:Zh})};class NS{constructor(t){_(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 po=class po{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}){_(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 NS(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(po,go).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(po,go).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 ha(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(po,go).delete(this._canvas),this.callback(t||new gg(`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(po,go).delete(this._canvas),this.callback())))}};er=new WeakMap,go=new WeakMap,_(po,go,new WeakSet);let Og=po;const jS="4.10.38",BS="f9bea397f";function jb(a){return Math.floor(Math.max(0,Math.min(1,a))*255).toString(16).padStart(2,"0")}function tl(a){return Math.max(0,Math.min(255,255*a))}class Bb{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=tl(t),[t,t,t]}static G_HTML([t]){const e=jb(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(tl)}static RGB_HTML(t){return`#${t.map(jb).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[tl(1-Math.min(1,t+i)),tl(1-Math.min(1,s+i)),tl(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 HS{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){_t("Abstract method `_createSVG` called.")}}class Dg extends HS{_createSVG(t){return document.createElementNS(Xi,t)}}class Hb{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&&Jh.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 y=g.children[++u.at(-1)[1]];if(y===null)continue;const{name:v}=y;if(v==="#text"){const C=document.createTextNode(y.value);c.push(C),b.append(C);continue}const x=(d=y==null?void 0:y.attributes)!=null&&d.xmlns?document.createElementNS(y.attributes.xmlns,v):document.createElement(v);if(b.append(x),y.attributes&&this.setAttributes({html:x,element:y,storage:e,intent:n,linkService:s}),((f=y.children)==null?void 0:f.length)>0)u.push([y,-1,x]);else if(y.value){const C=document.createTextNode(y.value);o&&Jh.shouldBuildText(v)&&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 el=1e3,zS=9,Dr=new WeakSet;function Fn(a){return{width:a[2]-a[0],height:a[3]-a[1]}}class GS{static create(t){switch(t.data.annotationType){case qt.LINK:return new zb(t);case qt.TEXT:return new VS(t);case qt.WIDGET:switch(t.data.fieldType){case"Tx":return new XS(t);case"Btn":return t.data.radioButton?new Gb(t):t.data.checkBox?new US(t):new YS(t);case"Ch":return new $S(t);case"Sig":return new WS(t)}return new Rr(t);case qt.POPUP:return new Rg(t);case qt.FREETEXT:return new Vb(t);case qt.LINE:return new KS(t);case qt.SQUARE:return new QS(t);case qt.CIRCLE:return new JS(t);case qt.POLYLINE:return new Xb(t);case qt.CARET:return new tC(t);case qt.INK:return new Lg(t);case qt.POLYGON:return new ZS(t);case qt.HIGHLIGHT:return new Wb(t);case qt.UNDERLINE:return new eC(t);case qt.SQUIGGLY:return new sC(t);case qt.STRIKEOUT:return new iC(t);case qt.STAMP:return new Ub(t);case qt.FILEATTACHMENT:return new nC(t);default:return new Bt(t)}}}const $g=class $g{constructor(t,{isRenderable:e=!1,ignoreBorder:s=!1,createQuadrilaterals:i=!1}={}){_(this,Ul);_(this,mo,null);_(this,za,!1);_(this,Ga,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 $g._hasPopupData(this.data)}updateEdited(t){var s;if(!this.container)return;l(this,mo)||m(this,mo,{rect:this.data.rect.slice(0)});const{rect:e}=t;e&&w(this,Ul,Sp).call(this,e),(s=l(this,Ga))==null||s.popup.updateEdited(t)}resetEdited(){var t;l(this,mo)&&(w(this,Ul,Sp).call(this,l(this,mo).rect),(t=l(this,Ga))==null||t.popup.resetEdited(),m(this,mo,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 Rr||(n.tabIndex=el);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 Rg){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,y=e.borderStyle.verticalCornerRadius;if(b>0||y>0){const x=`calc(${b}px * var(--scale-factor)) / calc(${y}px * var(--scale-factor))`;r.borderRadius=x}else if(this instanceof Gb){const x=`calc(${o}px * var(--scale-factor)) / calc(${h}px * var(--scale-factor))`;r.borderRadius=x}switch(e.borderStyle.style){case Xh.SOLID:r.borderStyle="solid";break;case Xh.DASHED:r.borderStyle="dashed";break;case Xh.BEVELED:st("Unimplemented border style: beveled");break;case Xh.INSET:st("Unimplemented border style: inset");break;case Xh.UNDERLINE:r.borderBottomStyle="solid";break}const v=e.borderColor||null;v?(m(this,za,!0),r.borderColor=U.makeHexColor(v[0]|0,v[1]|0,v[2]|0)):r.borderWidth=0}const c=U.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]=Bb[`${r}_HTML`](o),this.annotationStorage.setValue(this.data.id,{[s]:Bb[`${r}_rgb`](o)})};return nt(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,y,v,x]=t.subarray(2,6);if(i===b&&n===y&&e===v&&s===x)return}const{style:r}=this.container;let o;if(l(this,za)){const{borderColor:b,borderWidth:y}=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="${y}">`],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,y=t.length;b<y;b+=8){const v=t[b],x=t[b+1],C=t[b+2],S=t[b+3],A=u.createElement("rect"),k=(C-e)/h,P=(n-x)/c,O=(v-C)/h,R=(x-S)/c;A.setAttribute("x",k),A.setAttribute("y",P),A.setAttribute("width",O),A.setAttribute("height",R),g.append(A),o==null||o.push(`<rect vector-effect="non-scaling-stroke" x="${k}" y="${P}" width="${O}" height="${R}"/>`)}l(this,za)&&(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,Ga,new Rg({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(){_t("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&&!Dr.has(c)){st(`_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&&Dr.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})})}};mo=new WeakMap,za=new WeakMap,Ga=new WeakMap,Ul=new WeakSet,Sp=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 Bt=$g;class zb extends Bt{constructor(e,s=null){super(e,{isRenderable:!0,ignoreBorder:!!(s!=null&&s.ignoreBorder),createQuadrilaterals:!0});_(this,ls);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,ls,Hv).call(this,i,e.attachment,e.attachmentDest),n=!0):e.setOCGState?(w(this,ls,zv).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,ls,Go).call(this)}_bindNamedAction(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeNamedAction(s),!1),w(this,ls,Go).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,ls,Go).call(this)}_bindResetFormAction(e,s){const i=e.onclick;if(i||(e.href=this.linkService.getAnchorUrl("")),w(this,ls,Go).call(this),!this._fieldObjects){st('_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(!Dr.has(p)){st(`_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}}}ls=new WeakSet,Go=function(){this.container.setAttribute("data-internal-link","")},Hv=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,ls,Go).call(this)},zv=function(e,s){e.href=this.linkService.getAnchorUrl(""),e.onclick=()=>(this.linkService.executeSetOCGState(s),!1),w(this,ls,Go).call(this)};class VS extends Bt{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 Rr extends Bt{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":U.makeHexColor(e[0],e[1],e[2])}_setTextStyle(t){const e=["left","center","right"],{fontColor:s}=this.data.defaultAppearanceData,i=this.data.defaultAppearanceData.fontSize||zS,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/(ag*i))||1,d=c/u;r=Math.min(i,h(d/ag))}else{const c=Math.abs(this.data.rect[3]-this.data.rect[1]-o);r=Math.min(i,h(c/ag))}n.fontSize=`calc(${r}px * var(--scale-factor))`,n.color=U.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 XS extends Rr{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(`
506
+ `))||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),Dr.add(s),s.setAttribute("data-element-id",e),s.disabled=this.data.readOnly,s.name=this.data.fieldName,s.tabIndex=el,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:y}=b.detail;u.formattedValue=y,y!=null&&b.target!==document.activeElement&&(b.target.value=y),t.setValue(e,{formattedValue:y})},selRange(b){b.target.setSelectionRange(...b.detail.selRange)},charLimit:b=>{var C;const{charLimit:y}=b.detail,{target:v}=b;if(y===0){v.removeAttribute("maxLength");return}v.setAttribute("maxLength",y);let x=u.userValue;!x||x.length<=y||(x=x.slice(0,y),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:v.selectionStart,selEnd:v.selectionEnd}}))}};this._dispatchEventFromSandbox(p,g)}),s.addEventListener("keydown",g=>{var y;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,(y=this.linkService.eventBus)==null||y.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,y;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&&((y=this.linkService.eventBus)==null||y.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 A;u.lastCommittedValue=null;const{data:p,target:b}=g,{value:y,selectionStart:v,selectionEnd:x}=b;let C=v,S=x;switch(g.inputType){case"deleteWordBackward":{const k=y.substring(0,v).match(/\w*[^\w]*$/);k&&(C-=k[0].length);break}case"deleteWordForward":{const k=y.substring(v).match(/^[^\w]*\w*/);k&&(S+=k[0].length);break}case"deleteContentBackward":v===x&&(C-=1);break;case"deleteContentForward":v===x&&(S+=1);break}g.preventDefault(),(A=this.linkService.eventBus)==null||A.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:y,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 WS extends Rr{constructor(t){super(t,{isRenderable:!!t.data.hasOwnCanvas})}}class US extends Rr{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 Dr.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=el,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 Gb extends Rr{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(Dr.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=el,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 YS extends zb{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 $S extends Rr{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");Dr.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=el;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,y=>y.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,y=i.children[g],v=document.createElement("option");v.textContent=p,v.value=b,y?y.before(v):i.append(v),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:y}=p,v=document.createElement("option");v.textContent=b,v.value=y,i.append(v)}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 Rg extends Bt{constructor(t){const{data:e,elements:s}=t;super(t,{isRenderable:Bt._hasPopupData(e)}),this.elements=s,this.popup=null}render(){this.container.classList.add("popupAnnotation");const t=this.popup=new qS({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=>`${fg}${s}`).join(",")),this.container}}class qS{constructor({container:t,color:e,elements:s,titleObj:i,modificationDate:n,contentsObj:r,richText:o,parent:h,rect:c,parentRect:u,open:d}){_(this,bt);_(this,Va,w(this,bt,Xv).bind(this));_(this,wd,w(this,bt,Ap).bind(this));_(this,xd,w(this,bt,Wd).bind(this));_(this,Xa,w(this,bt,Xd).bind(this));_(this,bo,null);_(this,Ft,null);_(this,un,null);_(this,Wa,null);_(this,Yl,null);_(this,$l,null);_(this,Ua,null);_(this,dn,!1);_(this,$s,null);_(this,fn,null);_(this,ql,null);_(this,gn,null);_(this,Kl,null);_(this,vo,null);_(this,yo,!1);var f;m(this,Ft,t),m(this,Kl,i),m(this,un,r),m(this,gn,o),m(this,$l,h),m(this,bo,e),m(this,ql,c),m(this,Ua,u),m(this,Yl,s),m(this,Wa,mg.toDateObject(n)),this.trigger=s.flatMap(g=>g.getElementsToTriggerPopup());for(const g of this.trigger)g.addEventListener("click",l(this,Xa)),g.addEventListener("mouseenter",l(this,xd)),g.addEventListener("mouseleave",l(this,wd)),g.classList.add("popupTriggerArea");for(const g of s)(f=g.container)==null||f.addEventListener("keydown",l(this,Va));l(this,Ft).hidden=!0,d&&w(this,bt,Xd).call(this)}render(){if(l(this,$s))return;const t=m(this,$s,document.createElement("div"));if(t.className="popup",l(this,bo)){const n=t.style.outlineColor=U.makeHexColor(...l(this,bo));CSS.supports("background-color","color-mix(in srgb, red 30%, white)")?t.style.backgroundColor=`color-mix(in srgb, ${n} 30%, white)`:t.style.backgroundColor=U.makeHexColor(...l(this,bo).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,Kl),t.append(e),l(this,Wa)){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,Wa).valueOf()})),e.append(n)}const i=l(this,bt,Vd);if(i)Hb.render({xfaHtml:i,intent:"richText",div:t}),t.lastChild.classList.add("richText","popupContent");else{const n=this._formatContents(l(this,un));t.append(n)}l(this,Ft).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,vo)||m(this,vo,{contentsObj:l(this,un),richText:l(this,gn)}),t&&m(this,fn,null),e&&(m(this,gn,w(this,bt,Vv).call(this,e)),m(this,un,null)),(s=l(this,$s))==null||s.remove(),m(this,$s,null)}resetEdited(){var t;l(this,vo)&&({contentsObj:ze(this,un)._,richText:ze(this,gn)._}=l(this,vo),m(this,vo,null),(t=l(this,$s))==null||t.remove(),m(this,$s,null),m(this,fn,null))}forceHide(){m(this,yo,this.isVisible),l(this,yo)&&(l(this,Ft).hidden=!0)}maybeShow(){l(this,yo)&&(l(this,$s)||w(this,bt,Wd).call(this),m(this,yo,!1),l(this,Ft).hidden=!1)}get isVisible(){return l(this,Ft).hidden===!1}}Va=new WeakMap,wd=new WeakMap,xd=new WeakMap,Xa=new WeakMap,bo=new WeakMap,Ft=new WeakMap,un=new WeakMap,Wa=new WeakMap,Yl=new WeakMap,$l=new WeakMap,Ua=new WeakMap,dn=new WeakMap,$s=new WeakMap,fn=new WeakMap,ql=new WeakMap,gn=new WeakMap,Kl=new WeakMap,vo=new WeakMap,yo=new WeakMap,bt=new WeakSet,Vd=function(){const t=l(this,gn),e=l(this,un);return t!=null&&t.str&&(!(e!=null&&e.str)||e.str===t.str)&&l(this,gn).html||null},Cp=function(){var t,e,s;return((s=(e=(t=l(this,bt,Vd))==null?void 0:t.attributes)==null?void 0:e.style)==null?void 0:s.fontSize)||0},Gv=function(){var t,e,s;return((s=(e=(t=l(this,bt,Vd))==null?void 0:t.attributes)==null?void 0:e.style)==null?void 0:s.color)||null},Vv=function(t){const e=[],s={str:t,html:{name:"div",attributes:{dir:"auto"},children:[{name:"p",children:e}]}},i={style:{color:l(this,bt,Gv),fontSize:l(this,bt,Cp)?`calc(${l(this,bt,Cp)}px * var(--scale-factor))`:""}};for(const n of t.split(`
507
+ `))e.push({name:"span",value:n,attributes:i});return s},Xv=function(t){t.altKey||t.shiftKey||t.ctrlKey||t.metaKey||(t.key==="Enter"||t.key==="Escape"&&l(this,dn))&&w(this,bt,Xd).call(this)},Wv=function(){if(l(this,fn)!==null)return;const{page:{view:t},viewport:{rawDims:{pageWidth:e,pageHeight:s,pageX:i,pageY:n}}}=l(this,$l);let r=!!l(this,Ua),o=r?l(this,Ua):l(this,ql);for(const p of l(this,Yl))if(!o||U.intersect(p.data.rect,o)!==null){o=p.data.rect,r=!0;break}const h=U.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,fn,[100*(d-i)/e,100*(f-n)/s]);const{style:g}=l(this,Ft);g.left=`${l(this,fn)[0]}%`,g.top=`${l(this,fn)[1]}%`},Xd=function(){m(this,dn,!l(this,dn)),l(this,dn)?(w(this,bt,Wd).call(this),l(this,Ft).addEventListener("click",l(this,Xa)),l(this,Ft).addEventListener("keydown",l(this,Va))):(w(this,bt,Ap).call(this),l(this,Ft).removeEventListener("click",l(this,Xa)),l(this,Ft).removeEventListener("keydown",l(this,Va)))},Wd=function(){l(this,$s)||this.render(),this.isVisible?l(this,dn)&&l(this,Ft).classList.add("focused"):(w(this,bt,Wv).call(this),l(this,Ft).hidden=!1,l(this,Ft).style.zIndex=parseInt(l(this,Ft).style.zIndex)+1e3)},Ap=function(){l(this,Ft).classList.remove("focused"),!(l(this,dn)||!this.isVisible)&&(l(this,Ft).hidden=!0,l(this,Ft).style.zIndex=parseInt(l(this,Ft).style.zIndex)-1e3)};class Vb extends Bt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.textContent=t.data.textContent,this.textPosition=t.data.textPosition,this.annotationEditorType=et.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 KS extends Bt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});_(this,Ql,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,Ql,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,Ql)}addHighlightArea(){this.container.classList.add("highlightArea")}}Ql=new WeakMap;class QS extends Bt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});_(this,Jl,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,Jl,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,Jl)}addHighlightArea(){this.container.classList.add("highlightArea")}}Jl=new WeakMap;class JS extends Bt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});_(this,Zl,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,Zl,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,Zl)}addHighlightArea(){this.container.classList.add("highlightArea")}}Zl=new WeakMap;class Xb extends Bt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});_(this,tc,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,tc,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,tc)}addHighlightArea(){this.container.classList.add("highlightArea")}}tc=new WeakMap;class ZS extends Xb{constructor(t){super(t),this.containerClassName="polygonAnnotation",this.svgElementName="svg:polygon"}}class tC extends Bt{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 Lg extends Bt{constructor(e){super(e,{isRenderable:!0,ignoreBorder:!0});_(this,sc);_(this,ec,null);_(this,_o,[]);this.containerClassName="inkAnnotation",this.svgElementName="svg:polyline",this.annotationEditorType=this.data.it==="InkHighlight"?et.HIGHLIGHT:et.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,sc,Tp).call(this,s,e),u=this.svgFactory.create(h,c,!0),d=m(this,ec,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,_o).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,ec);if(s>=0&&r.setAttribute("stroke-width",s||1),i)for(let o=0,h=l(this,_o).length;o<h;o++)l(this,_o)[o].setAttribute("points",i[o].join(","));if(n){const{transform:o,width:h,height:c}=w(this,sc,Tp).call(this,this.data.rotation,n);r.parentElement.setAttribute("viewBox",`0 0 ${h} ${c}`),r.setAttribute("transform",o)}}getElementsToTriggerPopup(){return l(this,_o)}addHighlightArea(){this.container.classList.add("highlightArea")}}ec=new WeakMap,_o=new WeakMap,sc=new WeakSet,Tp=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 Wb extends Bt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0}),this.annotationEditorType=et.HIGHLIGHT}render(){return!this.data.popupRef&&this.hasPopupData&&this._createPopup(),this.container.classList.add("highlightAnnotation"),this._editOnDoubleClick(),this.container}}class eC extends Bt{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 sC extends Bt{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 iC extends Bt{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 Ub extends Bt{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.annotationEditorType=et.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 nC extends Bt{constructor(e){var i;super(e,{isRenderable:!0});_(this,nc);_(this,ic,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,nc,Ep).bind(this)),m(this,ic,i);const{isMac:n}=Re.platform;return e.addEventListener("keydown",r=>{r.key==="Enter"&&(n?r.metaKey:r.ctrlKey)&&w(this,nc,Ep).call(this)}),!s.popupRef&&this.hasPopupData?this._createPopup():i.classList.add("popupTriggerArea"),e.append(i),e}getElementsToTriggerPopup(){return l(this,ic)}addHighlightArea(){this.container.classList.add("highlightArea")}}ic=new WeakMap,nc=new WeakSet,Ep=function(){var e;(e=this.downloadManager)==null||e.openOrDownloadData(this.content,this.filename)};class rC{constructor({div:t,accessibilityManager:e,annotationCanvasMap:s,annotationEditorUIManager:i,page:n,viewport:r,structTreeLayer:o}){_(this,So);_(this,rc,null);_(this,wo,null);_(this,xo,new Map);_(this,oc,null);this.div=t,m(this,rc,e),m(this,wo,s),m(this,oc,o||null),this.page=n,this.viewport=r,this.zIndex=0,this._annotationEditorUIManager=i}hasEditableAnnotations(){return l(this,xo).size>0}async render(t){var r;const{annotations:e}=t,s=this.div;Pr(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 Dg,annotationStorage:t.annotationStorage||new Sg,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=GS.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,So,Uv).call(this,u,o.id),c._isEditable&&(l(this,xo).set(c.data.id,c),(r=this._annotationEditorUIManager)==null||r.renderAnnotationElement(c))}w(this,So,kp).call(this)}update({viewport:t}){const e=this.div;this.viewport=t,Pr(e,{rotation:t.rotation}),w(this,So,kp).call(this),e.hidden=!1}getEditableAnnotations(){return Array.from(l(this,xo).values())}getEditableAnnotation(t){return l(this,xo).get(t)}}rc=new WeakMap,wo=new WeakMap,xo=new WeakMap,oc=new WeakMap,So=new WeakSet,Uv=async function(t,e){var r,o;const s=t.firstChild||t,i=s.id=`${fg}${e}`,n=await((r=l(this,oc))==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,rc))==null||o.moveElementInDOM(this.div,t,s,!1)},kp=function(){if(!l(this,wo))return;const t=this.div;for(const[e,s]of l(this,wo)){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,wo).clear()};const nd=/\r\n?|\n/g,wt=class wt extends Ot{constructor(e){super({...e,name:"freeTextEditor"});_(this,Ut);_(this,qs);_(this,cs,"");_(this,ac,`${this.id}-editor`);_(this,Co,null);_(this,us);m(this,qs,e.color||wt._defaultColor||Ot._defaultLineColor),m(this,us,e.fontSize||wt._defaultFontSize)}static get _keyboardManager(){const e=wt.prototype,s=r=>r.isEmpty(),i=Or.TRANSLATE_SMALL,n=Or.TRANSLATE_BIG;return nt(this,"_keyboardManager",new $h([[["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){Ot.initialize(e,s);const i=getComputedStyle(document.documentElement);this._internalPadding=parseFloat(i.getPropertyValue("--freetext-padding"))}static updateDefaultParams(e,s){switch(e){case at.FREETEXT_SIZE:wt._defaultFontSize=s;break;case at.FREETEXT_COLOR:wt._defaultColor=s;break}}updateParams(e,s){switch(e){case at.FREETEXT_SIZE:w(this,Ut,Yv).call(this,s);break;case at.FREETEXT_COLOR:w(this,Ut,$v).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[at.FREETEXT_SIZE,wt._defaultFontSize],[at.FREETEXT_COLOR,wt._defaultColor||Ot._defaultLineColor]]}get propertiesToUpdate(){return[[at.FREETEXT_SIZE,l(this,us)],[at.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,us))*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(et.FREETEXT),super.enableEditMode(),this.overlayDiv.classList.remove("enabled"),this.editorDiv.contentEditable=!0,this._isDraggable=!1,this.div.removeAttribute("aria-activedescendant"),m(this,Co,new AbortController);const e=this._uiManager.combinedSignal(l(this,Co));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,ac)),this._isDraggable=!0,(e=l(this,Co))==null||e.abort(),m(this,Co,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,cs),s=m(this,cs,w(this,Ut,qv).call(this).trimEnd());if(e===s)return;const i=n=>{if(m(this,cs,n),!n){this.remove();return}w(this,Ut,$d).call(this),this._uiManager.rebuild(this),w(this,Ut,Ud).call(this)};this.addCommands({cmd:()=>{i(s)},undo:()=>{i(e)},mustExec:!1}),w(this,Ut,Ud).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,ac)),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,us)}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),Ku(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,$d).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,y;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,pn,Mp).call(p,s.getData("text")||"").replaceAll(nd,`
502
508
  `);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
- `)){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 y=h.parentElement;if(d.push(h.nodeValue.slice(c).replaceAll(sd,"")),y!==this.editorDiv){let x=u;for(const S of this.editorDiv.childNodes){if(S===y){x=d;continue}x.push(w(b=_t,gn,Wd).call(b,S))}}u.push(h.nodeValue.slice(0,c).replaceAll(sd,""))}else if(h===this.editorDiv){let y=u,x=0;for(const S of this.editorDiv.childNodes)x++===c&&(y=d),y.push(w(v=_t,gn,Wd).call(v,S))}m(this,cs,`${u.join(`
509
+ `)){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 v=h.parentElement;if(d.push(h.nodeValue.slice(c).replaceAll(nd,"")),v!==this.editorDiv){let x=u;for(const C of this.editorDiv.childNodes){if(C===v){x=d;continue}x.push(w(b=wt,pn,Yd).call(b,C))}}u.push(h.nodeValue.slice(0,c).replaceAll(nd,""))}else if(h===this.editorDiv){let v=u,x=0;for(const C of this.editorDiv.childNodes)x++===c&&(v=d),v.push(w(y=wt,pn,Yd).call(y,C))}m(this,cs,`${u.join(`
504
510
  `)}${n}${d.join(`
505
- `)}`),w(this,Ut,Ud).call(this);const f=new Range;let g=u.reduce((y,x)=>y+x.length,0);for(const{firstChild:y}of this.editorDiv.childNodes)if(y.nodeType===Node.TEXT_NODE){const x=y.nodeValue.length;if(g<=x){f.setStart(y,g),f.setEnd(y,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 jb){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:tt.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,us,e.fontSize),m(r,Ks,U.makeHexColor(...e.color)),m(r,cs,w(o=_t,gn,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=_t._internalPadding*this.parentScale,i=this.getRect(s,s),n=Ot._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:l(this,Ks)),r={annotationType:tt.FREETEXT,color:n,fontSize:l(this,us),value:w(this,Ut,Wv).call(this),pageIndex:this.pageIndex,rect:i,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?r:this.annotationElementId&&!w(this,Ut,Uv).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,us)}px * var(--scale-factor))`,i.color=l(this,Ks),s.replaceChildren();for(const r of l(this,cs).split(`
507
- `)){const o=document.createElement("div");o.append(r?document.createTextNode(r):document.createElement("br")),s.append(o)}const n=_t._internalPadding*this.parentScale;return e.updateEdited({rect:this.getRect(n,n),popupContent:l(this,cs)}),s}resetAnnotationElement(e){super.resetAnnotationElement(e),e.resetEdited()}};Ks=new WeakMap,cs=new WeakMap,nc=new WeakMap,So=new WeakMap,us=new WeakMap,Ut=new WeakSet,Gv=function(e){const s=n=>{this.editorDiv.style.fontSize=`calc(${n}px * var(--scale-factor))`,this.translate(0,-(n-l(this,us))*this.parentScale),m(this,us,n),w(this,Ut,Xd).call(this)},i=l(this,us);this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:at.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})},Vv=function(e){const s=n=>{m(this,Ks,this.editorDiv.style.color=n)},i=l(this,Ks);this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:at.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})},Xv=function(){var i;const e=[];this.editorDiv.normalize();let s=null;for(const n of this.editorDiv.childNodes)(s==null?void 0:s.nodeType)===Node.TEXT_NODE&&n.nodeName==="BR"||(e.push(w(i=_t,gn,Wd).call(i,n)),s=n);return e.join(`
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()},gn=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,cs))for(const e of l(this,cs).split(`
509
- `)){const s=document.createElement("div");s.append(e?document.createTextNode(e):document.createElement("br")),this.editorDiv.append(s)}},Wv=function(){return l(this,cs).replaceAll(" "," ")},Tp=function(e){return e.replaceAll(" "," ")},Uv=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},_(_t,gn),$(_t,"_freeTextDefaultContent",""),$(_t,"_internalPadding",0),$(_t,"_defaultColor",null),$(_t,"_defaultFontSize",10),$(_t,"_type","freetext"),$(_t,"_editorType",tt.FREETEXT);let Dg=_t;class V{toSVGPath(){yt("Abstract method `toSVGPath` must be implemented.")}get box(){yt("Abstract getter `box` must be implemented.")}serialize(t,e){yt("Abstract method `serialize` must be implemented.")}static _rescale(t,e,s,i,n,r){r||(r=new Float32Array(t.length));for(let o=0,h=t.length;o<h;o+=2)r[o]=e+t[o]*i,r[o+1]=s+t[o+1]*n;return r}static _rescaleAndSwap(t,e,s,i,n,r){r||(r=new Float32Array(t.length));for(let o=0,h=t.length;o<h;o+=2)r[o]=e+t[o+1]*i,r[o+1]=s+t[o]*n;return r}static _translate(t,e,s,i){i||(i=new Float32Array(t.length));for(let n=0,r=t.length;n<r;n+=2)i[n]=e+t[n],i[n+1]=s+t[n+1];return i}static svgRound(t){return Math.round(t*1e4)}static _normalizePoint(t,e,s,i,n){switch(n){case 90:return[1-e/s,t/i];case 180:return[1-t/s,1-e/i];case 270:return[e/s,1-t/i];default:return[t/s,e/i]}}static _normalizePagePoint(t,e,s){switch(s){case 90:return[1-e,t];case 180:return[1-t,1-e];case 270:return[e,1-t];default:return[t,e]}}static createBezierPoints(t,e,s,i,n,r){return[(t+5*s)/6,(e+5*i)/6,(5*s+n)/6,(5*i+r)/6,(s+n)/2,(i+r)/2]}}$(V,"PRECISION",1e-4);const pn=class pn{constructor({x:t,y:e},s,i,n,r,o=0){_(this,Jt);_(this,ds);_(this,Qs,[]);_(this,Ua);_(this,Ya);_(this,xi,[]);_(this,rt,new Float32Array(18));_(this,Co);_(this,Ao);_(this,rc);_(this,oc);_(this,$a);_(this,qa);_(this,sr,[]);m(this,ds,s),m(this,qa,n*i),m(this,Ya,r),l(this,rt).set([NaN,NaN,NaN,NaN,t,e],6),m(this,Ua,o),m(this,oc,l(pn,ac)*i),m(this,rc,l(pn,xd)*i),m(this,$a,i),l(this,sr).push(t,e)}isEmpty(){return isNaN(l(this,rt)[8])}add({x:t,y:e}){var R;m(this,Co,t),m(this,Ao,e);const[s,i,n,r]=l(this,ds);let[o,h,c,u]=l(this,rt).subarray(8,12);const d=t-c,f=e-u,g=Math.hypot(d,f);if(g<l(this,rc))return!1;const p=g-l(this,oc),b=p/g,v=b*d,y=b*f;let x=o,S=h;o=c,h=u,c+=v,u+=y,(R=l(this,sr))==null||R.push(t,e);const C=-y/p,E=v/p,P=C*l(this,qa),M=E*l(this,qa);return l(this,rt).set(l(this,rt).subarray(2,8),0),l(this,rt).set([c+P,u+M],4),l(this,rt).set(l(this,rt).subarray(14,18),12),l(this,rt).set([c-P,u-M],16),isNaN(l(this,rt)[6])?(l(this,xi).length===0&&(l(this,rt).set([o+P,h+M],2),l(this,xi).push(NaN,NaN,NaN,NaN,(o+P-s)/n,(h+M-i)/r),l(this,rt).set([o-P,h-M],14),l(this,Qs).push(NaN,NaN,NaN,NaN,(o-P-s)/n,(h-M-i)/r)),l(this,rt).set([x,S,o,h,c,u],6),!this.isEmpty()):(l(this,rt).set([x,S,o,h,c,u],6),Math.abs(Math.atan2(S-h,x-o)-Math.atan2(y,v))<Math.PI/2?([o,h,c,u]=l(this,rt).subarray(2,6),l(this,xi).push(NaN,NaN,NaN,NaN,((o+c)/2-s)/n,((h+u)/2-i)/r),[o,h,x,S]=l(this,rt).subarray(14,18),l(this,Qs).push(NaN,NaN,NaN,NaN,((x+o)/2-s)/n,((S+h)/2-i)/r),!0):([x,S,o,h,c,u]=l(this,rt).subarray(0,6),l(this,xi).push(((x+5*o)/6-s)/n,((S+5*h)/6-i)/r,((5*o+c)/6-s)/n,((5*h+u)/6-i)/r,((o+c)/2-s)/n,((h+u)/2-i)/r),[c,u,o,h,x,S]=l(this,rt).subarray(12,18),l(this,Qs).push(((x+5*o)/6-s)/n,((S+5*h)/6-i)/r,((5*o+c)/6-s)/n,((5*h+u)/6-i)/r,((o+c)/2-s)/n,((h+u)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";const t=l(this,xi),e=l(this,Qs);if(isNaN(l(this,rt)[6])&&!this.isEmpty())return w(this,Jt,Yv).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,qv).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,$v).call(this,s),s.join(" ")}newFreeDrawOutline(t,e,s,i,n,r){return new Gb(t,e,s,i,n,r)}getOutlines(){var d;const t=l(this,xi),e=l(this,Qs),s=l(this,rt),[i,n,r,o]=l(this,ds),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,Co)-i)/r,h[h.length-1]=(l(this,Ao)-n)/o,isNaN(s[6])&&!this.isEmpty())return w(this,Jt,Kv).call(this,h);const c=new Float32Array(l(this,xi).length+24+l(this,Qs).length);let u=t.length;for(let f=0;f<u;f+=2){if(isNaN(t[f])){c[f]=c[f+1]=NaN;continue}c[f]=t[f],c[f+1]=t[f+1]}u=w(this,Jt,Jv).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,Qv).call(this,c,u),this.newFreeDrawOutline(c,h,l(this,ds),l(this,$a),l(this,Ua),l(this,Ya))}};ds=new WeakMap,Qs=new WeakMap,Ua=new WeakMap,Ya=new WeakMap,xi=new WeakMap,rt=new WeakMap,Co=new WeakMap,Ao=new WeakMap,rc=new WeakMap,oc=new WeakMap,$a=new WeakMap,qa=new WeakMap,sr=new WeakMap,ac=new WeakMap,wd=new WeakMap,xd=new WeakMap,Jt=new WeakSet,Rc=function(){const t=l(this,rt).subarray(4,6),e=l(this,rt).subarray(16,18),[s,i,n,r]=l(this,ds);return[(l(this,Co)+(t[0]-e[0])/2-s)/n,(l(this,Ao)+(t[1]-e[1])/2-i)/r,(l(this,Co)+(e[0]-t[0])/2-s)/n,(l(this,Ao)+(e[1]-t[1])/2-i)/r]},Yv=function(){const[t,e,s,i]=l(this,ds),[n,r,o,h]=w(this,Jt,Rc).call(this);return`M${(l(this,rt)[2]-t)/s} ${(l(this,rt)[3]-e)/i} L${(l(this,rt)[4]-t)/s} ${(l(this,rt)[5]-e)/i} L${n} ${r} L${o} ${h} L${(l(this,rt)[16]-t)/s} ${(l(this,rt)[17]-e)/i} L${(l(this,rt)[14]-t)/s} ${(l(this,rt)[15]-e)/i} Z`},$v=function(t){const e=l(this,Qs);t.push(`L${e[4]} ${e[5]} Z`)},qv=function(t){const[e,s,i,n]=l(this,ds),r=l(this,rt).subarray(4,6),o=l(this,rt).subarray(16,18),[h,c,u,d]=w(this,Jt,Rc).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}`)},Kv=function(t){const e=l(this,rt),[s,i,n,r]=l(this,ds),[o,h,c,u]=w(this,Jt,Rc).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,ds),l(this,$a),l(this,Ua),l(this,Ya))},Qv=function(t,e){const s=l(this,Qs);return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6},Jv=function(t,e){const s=l(this,rt).subarray(4,6),i=l(this,rt).subarray(16,18),[n,r,o,h]=l(this,ds),[c,u,d,f]=w(this,Jt,Rc).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},_(pn,ac,8),_(pn,wd,2),_(pn,xd,l(pn,ac)+l(pn,wd));let id=pn;class Gb extends V{constructor(e,s,i,n,r,o){super();_(this,Sd);_(this,Ka);_(this,To,new Float32Array(4));_(this,mn);_(this,hc);_(this,fs);_(this,lc);_(this,zt);m(this,zt,e),m(this,fs,s),m(this,Ka,i),m(this,lc,n),m(this,mn,r),m(this,hc,o),this.lastPoint=[NaN,NaN],w(this,Sd,Zv).call(this,o);const[h,c,u,d]=l(this,To);for(let f=0,g=e.length;f<g;f+=2)e[f]=(e[f]-h)/u,e[f+1]=(e[f+1]-c)/d;for(let f=0,g=s.length;f<g;f+=2)s[f]=(s[f]-h)/u,s[f+1]=(s[f+1]-c)/d}toSVGPath(){const e=[`M${l(this,zt)[4]} ${l(this,zt)[5]}`];for(let s=6,i=l(this,zt).length;s<i;s+=6){if(isNaN(l(this,zt)[s])){e.push(`L${l(this,zt)[s+4]} ${l(this,zt)[s+5]}`);continue}e.push(`C${l(this,zt)[s]} ${l(this,zt)[s+1]} ${l(this,zt)[s+2]} ${l(this,zt)[s+3]} ${l(this,zt)[s+4]} ${l(this,zt)[s+5]}`)}return e.push("Z"),e.join(" ")}serialize([e,s,i,n],r){const o=i-e,h=n-s;let c,u;switch(r){case 0:c=V._rescale(l(this,zt),e,n,o,-h),u=V._rescale(l(this,fs),e,n,o,-h);break;case 90:c=V._rescaleAndSwap(l(this,zt),e,s,o,h),u=V._rescaleAndSwap(l(this,fs),e,s,o,h);break;case 180:c=V._rescale(l(this,zt),i,s,-o,h),u=V._rescale(l(this,fs),i,s,-o,h);break;case 270:c=V._rescaleAndSwap(l(this,zt),i,n,-o,-h),u=V._rescaleAndSwap(l(this,fs),i,n,-o,-h);break}return{outline:Array.from(c),points:[Array.from(u)]}}get box(){return l(this,To)}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,To),[h,c,u,d]=l(this,Ka),f=r*u,g=o*d,p=i*u+h,b=n*d+c,v=this.newOutliner({x:l(this,fs)[0]*f+p,y:l(this,fs)[1]*g+b},l(this,Ka),l(this,lc),e,l(this,hc),s??l(this,mn));for(let y=2;y<l(this,fs).length;y+=2)v.add({x:l(this,fs)[y]*f+p,y:l(this,fs)[y+1]*g+b});return v.getOutlines()}}Ka=new WeakMap,To=new WeakMap,mn=new WeakMap,hc=new WeakMap,fs=new WeakMap,lc=new WeakMap,zt=new WeakMap,Sd=new WeakSet,Zv=function(e){const s=l(this,zt);let i=s[4],n=s[5],r=i,o=n,h=i,c=n,u=i,d=n;const f=e?Math.max:Math.min;for(let p=6,b=s.length;p<b;p+=6){if(isNaN(s[p]))r=Math.min(r,s[p+4]),o=Math.min(o,s[p+5]),h=Math.max(h,s[p+4]),c=Math.max(c,s[p+5]),d<s[p+5]?(u=s[p+4],d=s[p+5]):d===s[p+5]&&(u=f(u,s[p+4]));else{const v=U.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,To);g[0]=r-l(this,mn),g[1]=o-l(this,mn),g[2]=h-r+2*l(this,mn),g[3]=c-o+2*l(this,mn),this.lastPoint=[u,d]};class Rg{constructor(t,e=0,s=0,i=!0){_(this,Ie);_(this,cc);_(this,uc);_(this,ir,[]);_(this,Js,[]);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:S}of t){const C=Math.floor((v-e)/c)*c,E=Math.ceil((v+x+e)/c)*c,P=Math.floor((y-e)/c)*c,M=Math.ceil((y+S+e)/c)*c,O=[C,P,M,!0],R=[E,P,M,!1];l(this,ir).push(O,R),n=Math.min(n,C),r=Math.max(r,E),o=Math.min(o,P),h=Math.max(h,M)}const u=r-n+2*s,d=h-o+2*s,f=n-s,g=o-s,p=l(this,ir).at(i?-1:-2),b=[p[0],p[2]];for(const v of l(this,ir)){const[y,x,S]=v;v[0]=(y-f)/u,v[1]=(x-g)/d,v[2]=(S-g)/d}m(this,cc,new Float32Array([f,g,u,d])),m(this,uc,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,ey).call(this,e)):(w(this,Ie,sy).call(this,e),t.push(...w(this,Ie,Ep).call(this,e)));return w(this,Ie,ty).call(this,t)}}cc=new WeakMap,uc=new WeakMap,ir=new WeakMap,Js=new WeakMap,Ie=new WeakSet,ty=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 tC(i,l(this,cc),l(this,uc))},Yd=function(t){const e=l(this,Js);let s=0,i=e.length-1;for(;s<=i;){const n=s+i>>1,r=e[n][0];if(r===t)return n;r<t?s=n+1:i=n-1}return i+1},ey=function([,t,e]){const s=w(this,Ie,Yd).call(this,t);l(this,Js).splice(s,0,[t,e])},sy=function([,t,e]){const s=w(this,Ie,Yd).call(this,t);for(let i=s;i<l(this,Js).length;i++){const[n,r]=l(this,Js)[i];if(n!==t)break;if(n===t&&r===e){l(this,Js).splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=l(this,Js)[i];if(n!==t)break;if(n===t&&r===e){l(this,Js).splice(i,1);return}}},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,Js)[o];for(let u=0,d=n.length;u<d;u++){const[,f,g]=n[u];if(!(c<=f||g<=h)){if(f>=h){if(g>c)n[u][1]=c;else{if(d===1)return[];n.splice(u,1),u--,d--}continue}n[u][2]=h,g>c&&n.push([e,c,g])}}}return n};class tC extends V{constructor(e,s,i){super();_(this,dc);_(this,Qa);m(this,Qa,e),m(this,dc,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,dc)}get classNamesForOutlining(){return["highlightOutline"]}}dc=new WeakMap,Qa=new WeakMap;class Lg extends id{newFreeDrawOutline(t,e,s,i,n,r){return new eC(t,e,s,i,n,r)}}class eC extends Gb{newOutliner(t,e,s,i,n,r=0){return new Lg(t,e,s,i,n,r)}}const Qe=class Qe{constructor({editor:t=null,uiManager:e=null}){_(this,vt);_(this,Zs,null);_(this,Eo,null);_(this,Ja);_(this,Zt,null);_(this,fc,!1);_(this,Za,!1);_(this,gc,null);_(this,pc);_(this,nr,null);_(this,ti,null);_(this,th);var s;t?(m(this,Za,!1),m(this,th,at.HIGHLIGHT_COLOR),m(this,gc,t)):(m(this,Za,!0),m(this,th,at.HIGHLIGHT_DEFAULT_COLOR)),m(this,ti,(t==null?void 0:t._uiManager)||e),m(this,pc,l(this,ti)._eventBus),m(this,Ja,(t==null?void 0:t.color)||((s=l(this,ti))==null?void 0:s.highlightColors.values().next().value)||"#FFFF98"),l(Qe,mc)||m(Qe,mc,Object.freeze({blue:"pdfjs-editor-colorpicker-blue",green:"pdfjs-editor-colorpicker-green",pink:"pdfjs-editor-colorpicker-pink",red:"pdfjs-editor-colorpicker-red",yellow:"pdfjs-editor-colorpicker-yellow"}))}static get _keyboardManager(){return nt(this,"_keyboardManager",new Wh([[["Escape","mac+Escape"],Qe.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],Qe.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],Qe.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],Qe.prototype._moveToPrevious],[["Home","mac+Home"],Qe.prototype._moveToBeginning],[["End","mac+End"],Qe.prototype._moveToEnd]]))}renderButton(){const t=m(this,Zs,document.createElement("button"));t.className="colorPicker",t.tabIndex="0",t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-button"),t.setAttribute("aria-haspopup",!0);const e=l(this,ti)._signal;t.addEventListener("click",w(this,vt,Go).bind(this),{signal:e}),t.addEventListener("keydown",w(this,vt,Pp).bind(this),{signal:e});const s=m(this,Eo,document.createElement("span"));return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=l(this,Ja),t.append(s),t}renderMainDropdown(){const t=m(this,Zt,w(this,vt,kp).call(this));return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}_colorSelectFromKeyboard(t){if(t.target===l(this,Zs)){w(this,vt,Go).call(this,t);return}const e=t.target.getAttribute("data-color");e&&w(this,vt,Mp).call(this,e,t)}_moveToNext(t){var e,s;if(!l(this,vt,gr)){w(this,vt,Go).call(this,t);return}if(t.target===l(this,Zs)){(e=l(this,Zt).firstChild)==null||e.focus();return}(s=t.target.nextSibling)==null||s.focus()}_moveToPrevious(t){var e,s;if(t.target===((e=l(this,Zt))==null?void 0:e.firstChild)||t.target===l(this,Zs)){l(this,vt,gr)&&this._hideDropdownFromKeyboard();return}l(this,vt,gr)||w(this,vt,Go).call(this,t),(s=t.target.previousSibling)==null||s.focus()}_moveToBeginning(t){var e;if(!l(this,vt,gr)){w(this,vt,Go).call(this,t);return}(e=l(this,Zt).firstChild)==null||e.focus()}_moveToEnd(t){var e;if(!l(this,vt,gr)){w(this,vt,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,Za)){if(!l(this,vt,gr)){(t=l(this,gc))==null||t.unselect();return}this.hideDropdown(),l(this,Zs).focus({preventScroll:!0,focusVisible:l(this,fc)})}}updateColor(t){if(l(this,Eo)&&(l(this,Eo).style.backgroundColor=t),!l(this,Zt))return;const e=l(this,ti).highlightColors.values();for(const s of l(this,Zt).children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){var t,e;(t=l(this,Zs))==null||t.remove(),m(this,Zs,null),m(this,Eo,null),(e=l(this,Zt))==null||e.remove(),m(this,Zt,null)}};Zs=new WeakMap,Eo=new WeakMap,Ja=new WeakMap,Zt=new WeakMap,fc=new WeakMap,Za=new WeakMap,gc=new WeakMap,pc=new WeakMap,nr=new WeakMap,ti=new WeakMap,th=new WeakMap,mc=new WeakMap,vt=new WeakSet,kp=function(){const t=document.createElement("div"),e=l(this,ti)._signal;t.addEventListener("contextmenu",Gs,{signal:e}),t.className="dropdown",t.role="listbox",t.setAttribute("aria-multiselectable",!1),t.setAttribute("aria-orientation","vertical"),t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown");for(const[s,i]of l(this,ti).highlightColors){const n=document.createElement("button");n.tabIndex="0",n.role="option",n.setAttribute("data-color",i),n.title=s,n.setAttribute("data-l10n-id",l(Qe,mc)[s]);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===l(this,Ja)),n.addEventListener("click",w(this,vt,Mp).bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",w(this,vt,Pp).bind(this),{signal:e}),t},Mp=function(t,e){e.stopPropagation(),l(this,pc).dispatch("switchannotationeditorparams",{source:this,type:l(this,th),value:t})},Pp=function(t){Qe._keyboardManager.exec(this,t)},Go=function(t){if(l(this,vt,gr)){this.hideDropdown();return}if(m(this,fc,t.detail===0),l(this,nr)||(m(this,nr,new AbortController),window.addEventListener("pointerdown",w(this,vt,iy).bind(this),{signal:l(this,ti).combinedSignal(l(this,nr))})),l(this,Zt)){l(this,Zt).classList.remove("hidden");return}const e=m(this,Zt,w(this,vt,kp).call(this));l(this,Zs).append(e)},iy=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")},_(Qe,mc,null);let nd=Qe;const ut=class ut extends Ot{constructor(e){super({...e,name:"highlightEditor"});_(this,Z);_(this,eh,null);_(this,bc,0);_(this,bn);_(this,ko,null);_(this,sh,null);_(this,Je,null);_(this,vc,null);_(this,yc,0);_(this,Mo,null);_(this,ks,null);_(this,gs,null);_(this,le,!1);_(this,ih,null);_(this,vn);_(this,Se,null);_(this,nh,"");_(this,Ms);_(this,_c,"");this.color=e.color||ut._defaultColor,m(this,Ms,e.thickness||ut._defaultThickness),m(this,vn,e.opacity||ut._defaultOpacity),m(this,bn,e.boxes||null),m(this,_c,e.methodOfCreation||""),m(this,nh,e.text||""),this._isDraggable=!1,e.highlightId>-1?(m(this,le,!0),w(this,Z,$d).call(this,e),w(this,Z,Vo).call(this)):l(this,bn)&&(m(this,eh,e.anchorNode),m(this,bc,e.anchorOffset),m(this,vc,e.focusNode),m(this,yc,e.focusOffset),w(this,Z,Op).call(this),w(this,Z,Vo).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const e=ut.prototype;return nt(this,"_keyboardManager",new Wh([[["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,Ms),methodOfCreation:l(this,_c)}}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;Ot.initialize(e,s),ut._defaultColor||(ut._defaultColor=((i=s.highlightColors)==null?void 0:i.values().next().value)||"#fff066")}static updateDefaultParams(e,s){switch(e){case at.HIGHLIGHT_DEFAULT_COLOR:ut._defaultColor=s;break;case at.HIGHLIGHT_THICKNESS:ut._defaultThickness=s;break}}translateInPage(e,s){}get toolbarPosition(){return l(this,ih)}updateParams(e,s){switch(e){case at.HIGHLIGHT_COLOR:w(this,Z,ny).call(this,s);break;case at.HIGHLIGHT_THICKNESS:w(this,Z,ry).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[at.HIGHLIGHT_DEFAULT_COLOR,ut._defaultColor],[at.HIGHLIGHT_THICKNESS,ut._defaultThickness]]}get propertiesToUpdate(){return[[at.HIGHLIGHT_COLOR,this.color||ut._defaultColor],[at.HIGHLIGHT_THICKNESS,l(this,Ms)||ut._defaultThickness],[at.HIGHLIGHT_FREE,l(this,le)]]}async addEditToolbar(){const e=await super.addEditToolbar();return e?(this._uiManager.highlightColors&&(m(this,sh,new nd({editor:this})),e.addColorPicker(l(this,sh))),e):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(w(this,Z,Lc).call(this))}getBaseTranslation(){return[0,0]}getRect(e,s){return super.getRect(e,s,w(this,Z,Lc).call(this))}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),e&&this.div.focus()}remove(){w(this,Z,Dp).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,Z,Vo).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?w(this,Z,Dp).call(this):e&&(w(this,Z,Vo).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,Ps,xh).call(n,l(this,ks).box,e)):i=w(r=ut,Ps,xh).call(r,[this.x,this.y,this.width,this.height],e),s.updateProperties(l(this,gs),{bbox:i,root:{"data-main-rotation":e}}),s.updateProperties(l(this,Se),{bbox:w(o=ut,Ps,xh).call(o,l(this,Je).box,e),root:{"data-main-rotation":e}})}render(){if(this.div)return this.div;const e=super.render();l(this,nh)&&(e.setAttribute("aria-label",l(this,nh)),e.setAttribute("role","mark")),l(this,le)?e.classList.add("free"):this.div.addEventListener("keydown",w(this,Z,ay).bind(this),{signal:this._uiManager._signal});const s=m(this,Mo,document.createElement("div"));e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",s.style.clipPath=l(this,ko);const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),$u(this,l(this,Mo),["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Se),{rootClass:{hovered:!0}})}pointerleave(){var e;this.isSelected||(e=this.parent)==null||e.drawLayer.updateProperties(l(this,Se),{rootClass:{hovered:!1}})}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:w(this,Z,qd).call(this,!0);break;case 1:case 3:w(this,Z,qd).call(this,!1);break}}select(){var e;super.select(),l(this,Se)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Se),{rootClass:{hovered:!1,selected:!0}}))}unselect(){var e;super.unselect(),l(this,Se)&&((e=this.parent)==null||e.drawLayer.updateProperties(l(this,Se),{rootClass:{selected:!1}}),l(this,le)||w(this,Z,qd).call(this,!1))}get _mustFixPosition(){return!l(this,le)}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.updateProperties(l(this,gs),{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,Ps,uy).call(this,e,p)};window.addEventListener("blur",g,{signal:f}),window.addEventListener("pointerup",g,{signal:f}),window.addEventListener("pointerdown",is,{capture:!0,passive:!1,signal:f}),window.addEventListener("contextmenu",Gs,{signal:f}),i.addEventListener("pointermove",w(this,Ps,cy).bind(this,e),{signal:f}),this._freeHighlight=new Lg({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,y,x;let n=null;if(e instanceof Hb){const{data:{quadPoints:S,rect:C,rotation:E,id:P,color:M,opacity:O,popupRef:R},parent:{page:{pageNumber:L}}}=e;n=e={annotationType:tt.HIGHLIGHT,color:Array.from(M),opacity:O,quadPoints:S,boxes:null,pageIndex:L-1,rect:C.slice(0),rotation:E,id:P,deleted:!1,popupRef:R}}else if(e instanceof Og){const{data:{inkLists:S,rect:C,rotation:E,id:P,color:M,borderStyle:{rawWidth:O},popupRef:R},parent:{page:{pageNumber:L}}}=e;n=e={annotationType:tt.HIGHLIGHT,color:Array.from(M),thickness:O,inkLists:S,boxes:null,pageIndex:L-1,rect:C.slice(0),rotation:E,id:P,deleted:!1,popupRef:R}}const{color:r,quadPoints:o,inkLists:h,opacity:c}=e,u=await super.deserialize(e,s,i);u.color=U.makeHexColor(...r),m(u,vn,c||1),h&&m(u,Ms,e.thickness),u.annotationElementId=e.id||null,u._initialData=n;const[d,f]=u.pageDimensions,[g,p]=u.pageTranslation;if(o){const S=m(u,bn,[]);for(let C=0;C<o.length;C+=8)S.push({x:(o[C]-g)/d,y:1-(o[C+1]-p)/f,width:(o[C+2]-o[C])/d,height:(o[C+1]-o[C+5])/f});w(b=u,Z,Op).call(b),w(v=u,Z,Vo).call(v),u.rotate(u.rotation)}else if(h){m(u,le,!0);const S=h[0],C={x:S[0]-g,y:f-(S[1]-p)},E=new Lg(C,[0,0,d,f],1,l(u,Ms)/2,!0,.001);for(let O=0,R=S.length;O<R;O+=2)C.x=S[O]-g,C.y=f-(S[O+1]-p),E.add(C);const{id:P,clipPathId:M}=s.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:u.color,"fill-opacity":u._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:E.toSVGPath()}},!0,!0);w(y=u,Z,$d).call(y,{highlightOutlines:E.getOutlines(),highlightId:P,clipPathId:M}),w(x=u,Z,Vo).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=Ot._colorManager.convert(this.color),n={annotationType:tt.HIGHLIGHT,color:i,opacity:l(this,vn),thickness:l(this,Ms),quadPoints:w(this,Z,hy).call(this),outlines:w(this,Z,ly).call(this,s),pageIndex:this.pageIndex,rect:s,rotation:w(this,Z,Lc).call(this),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!w(this,Z,dy).call(this,n)?null:(n.id=this.annotationElementId,n)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};eh=new WeakMap,bc=new WeakMap,bn=new WeakMap,ko=new WeakMap,sh=new WeakMap,Je=new WeakMap,vc=new WeakMap,yc=new WeakMap,Mo=new WeakMap,ks=new WeakMap,gs=new WeakMap,le=new WeakMap,ih=new WeakMap,vn=new WeakMap,Se=new WeakMap,nh=new WeakMap,Ms=new WeakMap,_c=new WeakMap,Z=new WeakSet,Op=function(){const e=new Rg(l(this,bn),.001);m(this,ks,e.getOutlines()),[this.x,this.y,this.width,this.height]=l(this,ks).box;const s=new Rg(l(this,bn),.0025,.001,this._uiManager.direction==="ltr");m(this,Je,s.getOutlines());const{lastPoint:i}=l(this,Je);m(this,ih,[(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,ks,e),m(this,Je,e.getNewOutline(l(this,Ms)/2+1.5,.0025)),s>=0)m(this,gs,s),m(this,ko,i),this.parent.drawLayer.finalizeDraw(s,{bbox:e.box,path:{d:e.toSVGPath()}}),m(this,Se,this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:l(this,Je).box,path:{d:l(this,Je).toSVGPath()}},!0));else if(this.parent){const g=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(l(this,gs),{bbox:w(d=ut,Ps,xh).call(d,l(this,ks).box,(g-this.rotation+360)%360),path:{d:e.toSVGPath()}}),this.parent.drawLayer.updateProperties(l(this,Se),{bbox:w(f=ut,Ps,xh).call(f,l(this,Je).box,g),path:{d:l(this,Je).toSVGPath()}})}const[r,o,h,c]=e.box;switch(this.rotation){case 0:this.x=r,this.y=o,this.width=h,this.height=c;break;case 90:{const[g,p]=this.parentDimensions;this.x=o,this.y=1-r,this.width=h*p/g,this.height=c*g/p;break}case 180:this.x=1-r,this.y=1-o,this.width=h,this.height=c;break;case 270:{const[g,p]=this.parentDimensions;this.x=1-o,this.y=r,this.width=h*p/g,this.height=c*g/p;break}}const{lastPoint:u}=l(this,Je);m(this,ih,[(u[0]-r)/h,(u[1]-o)/c])},ny=function(e){const s=(r,o)=>{var h,c;this.color=r,m(this,vn,o),(h=this.parent)==null||h.drawLayer.updateProperties(l(this,gs),{root:{fill:r,"fill-opacity":o}}),(c=l(this,sh))==null||c.updateColor(r)},i=this.color,n=l(this,vn);this.addCommands({cmd:s.bind(this,e,ut._defaultOpacity),undo:s.bind(this,i,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:at.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(e)},!0)},ry=function(e){const s=l(this,Ms),i=n=>{m(this,Ms,n),w(this,Z,oy).call(this,n)};this.addCommands({cmd:i.bind(this,e),undo:i.bind(this,s),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:at.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)},oy=function(e){if(!l(this,le))return;w(this,Z,$d).call(this,{highlightOutlines:l(this,ks).getNewOutline(e/2)}),this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)},Dp=function(){l(this,gs)===null||!this.parent||(this.parent.drawLayer.remove(l(this,gs)),m(this,gs,null),this.parent.drawLayer.remove(l(this,Se)),m(this,Se,null))},Vo=function(e=this.parent){l(this,gs)===null&&({id:ze(this,gs)._,clipPathId:ze(this,ko)._}=e.drawLayer.draw({bbox:l(this,ks).box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":l(this,vn)},rootClass:{highlight:!0,free:l(this,le)},path:{d:l(this,ks).toSVGPath()}},!1,!0),m(this,Se,e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:l(this,le)},bbox:l(this,Je).box,path:{d:l(this,Je).toSVGPath()}},l(this,le))),l(this,Mo)&&(l(this,Mo).style.clipPath=l(this,ko)))},Ps=new WeakSet,xh=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]},ay=function(e){ut._keyboardManager.exec(this,e)},qd=function(e){if(!l(this,eh))return;const s=window.getSelection();e?s.setPosition(l(this,eh),l(this,bc)):s.setPosition(l(this,vc),l(this,yc))},Lc=function(){return l(this,le)?this.rotation:0},hy=function(){if(l(this,le))return null;const[e,s]=this.pageDimensions,[i,n]=this.pageTranslation,r=l(this,bn),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},ly=function(e){return l(this,ks).serialize(e,w(this,Z,Lc).call(this))},cy=function(e,s){this._freeHighlight.add(s)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})},uy=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=""},dy=function(e){const{color:s}=this._initialData;return e.color.some((i,n)=>i!==s[n])},_(ut,Ps),$(ut,"_defaultColor",null),$(ut,"_defaultOpacity",1),$(ut,"_defaultThickness",12),$(ut,"_type","highlight"),$(ut,"_editorType",tt.HIGHLIGHT),$(ut,"_freeHighlightId",-1),$(ut,"_freeHighlight",null),$(ut,"_freeHighlightClipId","");let rd=ut;class sC{constructor(){_(this,Po,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,Po)[t]=e}toSVGProperties(){const t=l(this,Po);return m(this,Po,Object.create(null)),{root:t}}reset(){m(this,Po,Object.create(null))}updateAll(t=this){this.updateProperties(t)}clone(){yt("Not implemented")}}Po=new WeakMap;const X=class X extends Ot{constructor(e){super(e);_(this,ht);_(this,ps,null);_(this,rh);$(this,"_drawId",null);m(this,rh,e.mustBeCommitted||!1),e.drawOutlines&&(w(this,ht,Rp).call(this,e),w(this,ht,Fc).call(this))}static _mergeSVGProperties(e,s){const i=new Set(Object.keys(e));for(const[n,r]of Object.entries(s))i.has(n)?Object.assign(e[n],r):e[n]=r;return e}static getDefaultDrawingOptions(e){yt("Not implemented")}static get typesMap(){yt("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(e,s){const i=this.typesMap.get(e);i&&this._defaultDrawingOptions.updateProperty(i,s),this._currentParent&&(l(X,ne).updateProperty(i,s),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(e,s){const i=this.constructor.typesMap.get(e);i&&this._updateProperty(e,i,s)}static get defaultPropertiesToUpdate(){const e=[],s=this._defaultDrawingOptions;for(const[i,n]of this.typesMap)e.push([i,s[n]]);return e}get propertiesToUpdate(){const e=[],{_drawingOptions:s}=this;for(const[i,n]of this.constructor.typesMap)e.push([i,s[n]]);return e}_updateProperty(e,s,i){const n=this._drawingOptions,r=n[s],o=h=>{var u;n.updateProperty(s,h);const c=l(this,ps).updateProperty(s,h);c&&w(this,ht,Ic).call(this,c),(u=this.parent)==null||u.drawLayer.updateProperties(this._drawId,n.toSVGProperties())};this.addCommands({cmd:o.bind(this,i),undo:o.bind(this,r),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:e,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,X._mergeSVGProperties(l(this,ps).getPathResizingSVGProperties(w(this,ht,Kd).call(this)),{bbox:w(this,ht,Sh).call(this)}))}_onResized(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,X._mergeSVGProperties(l(this,ps).getPathResizedSVGProperties(w(this,ht,Kd).call(this)),{bbox:w(this,ht,Sh).call(this)}))}_onTranslating(e,s){var i;(i=this.parent)==null||i.drawLayer.updateProperties(this._drawId,{bbox:w(this,ht,Sh).call(this,e,s)})}_onTranslated(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,X._mergeSVGProperties(l(this,ps).getPathTranslatedSVGProperties(w(this,ht,Kd).call(this),this.parentDimensions),{bbox:w(this,ht,Sh).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,rh)&&(m(this,rh,!1),this.commit(),this.parent.setSelected(this),e&&this.isOnScreen&&this.div.focus())}remove(){w(this,ht,Fp).call(this),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,ht,Fc).call(this),w(this,ht,Ic).call(this,l(this,ps).box),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?(this._uiManager.removeShouldRescale(this),w(this,ht,Fp).call(this)):e&&(this._uiManager.addShouldRescale(this),w(this,ht,Fc).call(this,e),s=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),s&&this.select()}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,X._mergeSVGProperties({bbox:w(this,ht,Sh).call(this)},l(this,ps).updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&w(this,ht,Ic).call(this,l(this,ps).updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;const e=super.render();e.classList.add("draw");const s=document.createElement("div");e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal";const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),this._uiManager.addShouldRescale(this),this.disableEditing(),e}static createDrawerInstance(e,s,i,n,r){yt("Not implemented")}static startDrawing(e,s,i,n){var v;const{target:r,offsetX:o,offsetY:h,pointerId:c,pointerType:u}=n;if(l(X,or)&&l(X,or)!==u)return;const{viewport:{rotation:d}}=e,{width:f,height:g}=r.getBoundingClientRect(),p=m(X,Oo,new AbortController),b=e.combinedSignal(p);if(l(X,rr)||m(X,rr,c),l(X,or)??m(X,or,u),window.addEventListener("pointerup",y=>{var x;l(X,rr)===y.pointerId?this._endDraw(y):(x=l(X,ar))==null||x.delete(y.pointerId)},{signal:b}),window.addEventListener("pointercancel",y=>{var x;l(X,rr)===y.pointerId?this._currentParent.endDrawingSession():(x=l(X,ar))==null||x.delete(y.pointerId)},{signal:b}),window.addEventListener("pointerdown",y=>{l(X,or)===y.pointerType&&((l(X,ar)||m(X,ar,new Set)).add(y.pointerId),l(X,ne).isCancellable()&&(l(X,ne).removeLastElement(),l(X,ne).isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:b}),window.addEventListener("contextmenu",Gs,{signal:b}),r.addEventListener("pointermove",this._drawMove.bind(this),{signal:b}),r.addEventListener("touchmove",y=>{y.timeStamp===l(X,Ro)&&is(y)},{signal:b}),e.toggleDrawing(),(v=s._editorUndoBar)==null||v.hide(),l(X,ne)){e.drawLayer.updateProperties(this._currentDrawId,l(X,ne).startNew(o,h,f,g,d));return}s.updateUIForDefaultProperties(this),m(X,ne,this.createDrawerInstance(o,h,f,g,d)),m(X,Do,this.getDefaultDrawingOptions()),this._currentParent=e,{id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties(l(X,Do).toSVGProperties(),l(X,ne).defaultSVGProperties),!0,!1)}static _drawMove(e){var r;if(m(X,Ro,-1),!l(X,ne))return;const{offsetX:s,offsetY:i,pointerId:n}=e;if(l(X,rr)===n){if(((r=l(X,ar))==null?void 0:r.size)>=1){this._endDraw(e);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,l(X,ne).add(s,i)),m(X,Ro,e.timeStamp),is(e)}}static _cleanup(e){e&&(this._currentDrawId=-1,this._currentParent=null,m(X,ne,null),m(X,Do,null),m(X,or,null),m(X,Ro,NaN)),l(X,Oo)&&(l(X,Oo).abort(),m(X,Oo,null),m(X,rr,NaN),m(X,ar,null))}static _endDraw(e){const s=this._currentParent;if(s){if(s.toggleDrawing(!0),this._cleanup(!1),e&&s.drawLayer.updateProperties(this._currentDrawId,l(X,ne).end(e.offsetX,e.offsetY)),this.supportMultipleDrawings){const i=l(X,ne),n=this._currentDrawId,r=i.getLastElement();s.addCommands({cmd:()=>{s.drawLayer.updateProperties(n,i.setLastElement(r))},undo:()=>{s.drawLayer.updateProperties(n,i.removeLastElement())},mustExec:!1,type:at.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(e){const s=this._currentParent;if(!s)return null;if(s.toggleDrawing(!0),s.cleanUndoStack(at.DRAW_STEP),!l(X,ne).isEmpty()){const{pageDimensions:[i,n],scale:r}=s,o=s.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:l(X,ne).getOutlines(i*r,n*r,r,this._INNER_MARGIN),drawingOptions:l(X,Do),mustBeCommitted:!e});return this._cleanup(!0),o}return s.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(e){}static deserializeDraw(e,s,i,n,r,o){yt("Not implemented")}static async deserialize(e,s,i){var d,f;const{rawDims:{pageWidth:n,pageHeight:r,pageX:o,pageY:h}}=s.viewport,c=this.deserializeDraw(o,h,n,r,this._INNER_MARGIN,e),u=await super.deserialize(e,s,i);return u.createDrawingOptions(e),w(d=u,ht,Rp).call(d,{drawOutlines:c}),w(f=u,ht,Fc).call(f),u.onScaleChanging(),u.rotate(),u}serializeDraw(e){const[s,i]=this.pageTranslation,[n,r]=this.pageDimensions;return l(this,ps).serialize([s,i,n,r],e)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};ps=new WeakMap,rh=new WeakMap,ne=new WeakMap,Oo=new WeakMap,Do=new WeakMap,rr=new WeakMap,or=new WeakMap,ar=new WeakMap,Ro=new WeakMap,ht=new WeakSet,Rp=function({drawOutlines:e,drawId:s,drawingOptions:i}){m(this,ps,e),this._drawingOptions||(this._drawingOptions=i),s>=0?(this._drawId=s,this.parent.drawLayer.finalizeDraw(s,e.defaultProperties)):this._drawId=w(this,ht,Lp).call(this,e,this.parent),w(this,ht,Ic).call(this,e.box)},Lp=function(e,s){const{id:i}=s.drawLayer.draw(X._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())},Fc=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,ht,Lp).call(this,l(this,ps),e)}},fy=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]}},Ic=function(e){if([this.x,this.y,this.width,this.height]=w(this,ht,fy).call(this,e),this.div){this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)}this._onResized()},Sh=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]}},$(X,"_currentDrawId",-1),$(X,"_currentParent",null),_(X,ne,null),_(X,Oo,null),_(X,Do,null),_(X,rr,NaN),_(X,or,null),_(X,ar,null),_(X,Ro,NaN),$(X,"_INNER_MARGIN",3);let Fg=X;class iC{constructor(t,e,s,i,n,r){_(this,ah);_(this,Si,new Float64Array(6));_(this,re);_(this,oe);_(this,Lo);_(this,oh);_(this,Ne);_(this,ce,"");_(this,Os,0);_(this,Fo,new od);_(this,Io);_(this,No);m(this,Io,s),m(this,No,i),m(this,Lo,n),m(this,oh,r),[t,e]=w(this,ah,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,Si).set(o,0)}updateProperty(t,e){t==="stroke-width"&&m(this,oh,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,ah,Qd).call(this,t,e);const[s,i,n,r]=l(this,Si).subarray(2,6),o=t-n,h=e-r;return Math.hypot(l(this,Io)*o,l(this,No)*h)<=2?null:(l(this,Ne).push(t,e),isNaN(s)?(l(this,Si).set([n,r,t,e],2),l(this,re).push(NaN,NaN,NaN,NaN,t,e),{path:{d:this.toSVGPath()}}):(isNaN(l(this,Si)[0])&&l(this,re).splice(6,6),l(this,Si).set([s,i,n,r,t,e],0),l(this,re).push(...V.createBezierPoints(s,i,n,r,t,e)),{path:{d:this.toSVGPath()}}))}end(t,e){const s=this.add(t,e);return s||(l(this,Ne).length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,s,i,n){m(this,Io,s),m(this,No,i),m(this,Lo,n),[t,e]=w(this,ah,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,Si).set(r,0),m(this,Os,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,Os,0),{path:{d:this.toSVGPath()}}):l(this,Fo).setLastElement(t)}removeLastElement(){if(!l(this,oe))return l(this,Fo).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,Os,0),this.toSVGPath()}return{path:{d:l(this,ce)}}}toSVGPath(){const t=V.svgRound(l(this,re)[4]),e=V.svgRound(l(this,re)[5]);if(l(this,Ne).length===2)return m(this,ce,`${l(this,ce)} M ${t} ${e} Z`),l(this,ce);if(l(this,Ne).length<=6){const i=l(this,ce).lastIndexOf("M");m(this,ce,`${l(this,ce).slice(0,i)} M ${t} ${e}`),m(this,Os,6)}if(l(this,Ne).length===4){const i=V.svgRound(l(this,re)[10]),n=V.svgRound(l(this,re)[11]);return m(this,ce,`${l(this,ce)} L ${i} ${n}`),m(this,Os,12),l(this,ce)}const s=[];l(this,Os)===0&&(s.push(`M ${t} ${e}`),m(this,Os,6));for(let i=l(this,Os),n=l(this,re).length;i<n;i+=6){const[r,o,h,c,u,d]=l(this,re).slice(i,i+6).map(V.svgRound);s.push(`C${r} ${o} ${h} ${c} ${u} ${d}`)}return m(this,ce,l(this,ce)+s.join(" ")),m(this,Os,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,Fo).build(l(this,oe),t,e,s,l(this,Lo),l(this,oh),i),m(this,Si,null),m(this,re,null),m(this,oe,null),m(this,ce,null),l(this,Fo)}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}Si=new WeakMap,re=new WeakMap,oe=new WeakMap,Lo=new WeakMap,oh=new WeakMap,Ne=new WeakMap,ce=new WeakMap,Os=new WeakMap,Fo=new WeakMap,Io=new WeakMap,No=new WeakMap,ah=new WeakSet,Qd=function(t,e){return V._normalizePoint(t,e,l(this,Io),l(this,No),l(this,Lo))};const Ug=class Ug extends V{constructor(){super(...arguments);_(this,ue);_(this,je);_(this,wc,0);_(this,xc);_(this,ms);_(this,Ci);_(this,Ai);_(this,hh);_(this,lh);_(this,ch)}build(e,s,i,n,r,o,h){m(this,Ci,s),m(this,Ai,i),m(this,hh,n),m(this,lh,r),m(this,ch,o),m(this,xc,h??0),m(this,ms,e),w(this,ue,py).call(this)}setLastElement(e){return l(this,ms).push(e),{path:{d:this.toSVGPath()}}}removeLastElement(){return l(this,ms).pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const e=[];for(const{line:s}of l(this,ms)){if(e.push(`M${V.svgRound(s[4])} ${V.svgRound(s[5])}`),s.length===6){e.push("Z");continue}if(s.length===12){e.push(`L${V.svgRound(s[10])} ${V.svgRound(s[11])}`);continue}for(let i=6,n=s.length;i<n;i+=6){const[r,o,h,c,u,d]=s.subarray(i,i+6).map(V.svgRound);e.push(`C${r} ${o} ${h} ${c} ${u} ${d}`)}}return e.join("")}serialize([e,s,i,n],r){const o=[],h=[],[c,u,d,f]=w(this,ue,gy).call(this);let g,p,b,v,y,x,S,C,E;switch(l(this,lh)){case 0:E=V._rescale,g=e,p=s+n,b=i,v=-n,y=e+c*i,x=s+(1-u-f)*n,S=e+(c+d)*i,C=s+(1-u)*n;break;case 90:E=V._rescaleAndSwap,g=e,p=s,b=i,v=n,y=e+u*i,x=s+c*n,S=e+(u+f)*i,C=s+(c+d)*n;break;case 180:E=V._rescale,g=e+i,p=s,b=-i,v=n,y=e+(1-c-d)*i,x=s+u*n,S=e+(1-c)*i,C=s+(u+f)*n;break;case 270:E=V._rescaleAndSwap,g=e+i,p=s+n,b=-i,v=-n,y=e+(1-u-f)*i,x=s+(1-c-d)*n,S=e+(1-u)*i,C=s+(1-c)*n;break}for(const{line:P,points:M}of l(this,ms))o.push(E(P,g,p,b,v,r?new Array(P.length):null)),h.push(E(M,g,p,b,v,r?new Array(M.length):null));return{lines:o,points:h,rect:[y,x,S,C]}}static deserialize(e,s,i,n,r,{paths:{lines:o,points:h},rotation:c,thickness:u}){const d=[];let f,g,p,b,v;switch(c){case 0:v=V._rescale,f=-e/i,g=s/n+1,p=1/i,b=-1/n;break;case 90:v=V._rescaleAndSwap,f=-s/n,g=-e/i,p=1/n,b=1/i;break;case 180:v=V._rescale,f=e/i+1,g=-s/n,p=-1/i,b=1/n;break;case 270:v=V._rescaleAndSwap,f=s/n+1,g=e/i+1,p=-1/n,b=-1/i;break}if(!o){o=[];for(const x of h){const S=x.length;if(S===2){o.push(new Float32Array([NaN,NaN,NaN,NaN,x[0],x[1]]));continue}if(S===4){o.push(new Float32Array([NaN,NaN,NaN,NaN,x[0],x[1],NaN,NaN,NaN,NaN,x[2],x[3]]));continue}const C=new Float32Array(3*(S-2));o.push(C);let[E,P,M,O]=x.subarray(0,4);C.set([NaN,NaN,NaN,NaN,E,P],0);for(let R=4;R<S;R+=2){const L=x[R],N=x[R+1];C.set(V.createBezierPoints(E,P,M,O,L,N),(R-2)*3),[E,P,M,O]=[M,O,L,N]}}}for(let x=0,S=o.length;x<S;x++)d.push({line:v(o[x].map(C=>C??NaN),f,g,p,b),points:v(h[x].map(C=>C??NaN),f,g,p,b)});const y=new Ug;return y.build(d,i,n,1,c,u,r),y}get box(){return l(this,je)}updateProperty(e,s){return e==="stroke-width"?w(this,ue,my).call(this,s):null}updateParentDimensions([e,s],i){const[n,r]=w(this,ue,Cn).call(this);m(this,Ci,e),m(this,Ai,s),m(this,hh,i);const[o,h]=w(this,ue,Cn).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,wc,e),{path:{transform:this.rotationTransform}}}get viewBox(){return l(this,je).map(V.svgRound).join(" ")}get defaultProperties(){const[e,s]=l(this,je);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${V.svgRound(e)} ${V.svgRound(s)}`}}}get rotationTransform(){const[,,e,s]=l(this,je);let i=0,n=0,r=0,o=0,h=0,c=0;switch(l(this,wc)){case 90:n=s/e,r=-e/s,h=e;break;case 180:i=-1,o=-1,h=e,c=s;break;case 270:n=-s/e,r=e/s,c=s;break;default:return""}return`matrix(${i} ${n} ${r} ${o} ${V.svgRound(h)} ${V.svgRound(c)})`}getPathResizingSVGProperties([e,s,i,n]){const[r,o]=w(this,ue,Cn).call(this),[h,c,u,d]=l(this,je);if(Math.abs(u-r)<=V.PRECISION||Math.abs(d-o)<=V.PRECISION){const v=e+i/2-(h+u/2),y=s+n/2-(c+d/2);return{path:{"transform-origin":`${V.svgRound(e)} ${V.svgRound(s)}`,transform:`${this.rotationTransform} translate(${v} ${y})`}}}const f=(i-2*r)/(u-2*r),g=(n-2*o)/(d-2*o),p=u/i,b=d/n;return{path:{"transform-origin":`${V.svgRound(h)} ${V.svgRound(c)}`,transform:`${this.rotationTransform} scale(${p} ${b}) translate(${V.svgRound(r)} ${V.svgRound(o)}) scale(${f} ${g}) translate(${V.svgRound(-r)} ${V.svgRound(-o)})`}}}getPathResizedSVGProperties([e,s,i,n]){const[r,o]=w(this,ue,Cn).call(this),h=l(this,je),[c,u,d,f]=h;if(h[0]=e,h[1]=s,h[2]=i,h[3]=n,Math.abs(d-r)<=V.PRECISION||Math.abs(f-o)<=V.PRECISION){const y=e+i/2-(c+d/2),x=s+n/2-(u+f/2);for(const{line:S,points:C}of l(this,ms))V._translate(S,y,x,S),V._translate(C,y,x,C);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${V.svgRound(e)} ${V.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const g=(i-2*r)/(d-2*r),p=(n-2*o)/(f-2*o),b=-g*(c+r)+e+r,v=-p*(u+o)+s+o;if(g!==1||p!==1||b!==0||v!==0)for(const{line:y,points:x}of l(this,ms))V._rescale(y,b,v,g,p,y),V._rescale(x,b,v,g,p,x);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${V.svgRound(e)} ${V.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,s],i){const[n,r]=i,o=l(this,je),h=e-o[0],c=s-o[1];if(l(this,Ci)===n&&l(this,Ai)===r)for(const{line:u,points:d}of l(this,ms))V._translate(u,h,c,u),V._translate(d,h,c,d);else{const u=l(this,Ci)/n,d=l(this,Ai)/r;m(this,Ci,n),m(this,Ai,r);for(const{line:f,points:g}of l(this,ms))V._rescale(f,h,c,u,d,f),V._rescale(g,h,c,u,d,g);o[2]*=u,o[3]*=d}return o[0]=e,o[1]=s,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${V.svgRound(e)} ${V.svgRound(s)}`}}}get defaultSVGProperties(){const e=l(this,je);return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${V.svgRound(e[0])} ${V.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}};je=new WeakMap,wc=new WeakMap,xc=new WeakMap,ms=new WeakMap,Ci=new WeakMap,Ai=new WeakMap,hh=new WeakMap,lh=new WeakMap,ch=new WeakMap,ue=new WeakSet,Cn=function(e=l(this,ch)){const s=l(this,xc)+e/2*l(this,hh);return l(this,lh)%180===0?[s/l(this,Ci),s/l(this,Ai)]:[s/l(this,Ai),s/l(this,Ci)]},gy=function(){const[e,s,i,n]=l(this,je),[r,o]=w(this,ue,Cn).call(this,0);return[e+r,s+o,i-2*r,n-2*o]},py=function(){const e=m(this,je,new Float32Array([1/0,1/0,-1/0,-1/0]));for(const{line:n}of l(this,ms)){if(n.length<=12){for(let h=4,c=n.length;h<c;h+=6){const[u,d]=n.subarray(h,h+2);e[0]=Math.min(e[0],u),e[1]=Math.min(e[1],d),e[2]=Math.max(e[2],u),e[3]=Math.max(e[3],d)}continue}let r=n[4],o=n[5];for(let h=6,c=n.length;h<c;h+=6){const[u,d,f,g,p,b]=n.subarray(h,h+6);U.bezierBoundingBox(r,o,u,d,f,g,p,b,e),r=p,o=b}}const[s,i]=w(this,ue,Cn).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]},my=function(e){const[s,i]=w(this,ue,Cn).call(this);m(this,ch,e);const[n,r]=w(this,ue,Cn).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 sC{constructor(e){super();_(this,uh);m(this,uh,e),super.updateProperties({fill:"none",stroke:Ot._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,uh).realScale),super.updateSVGProperty(e,s)}clone(){const e=new Yg(l(this,uh));return e.updateAll(this),e}};uh=new WeakMap;let Ig=Yg;const dh=class dh extends Fg{constructor(e){super({...e,name:"inkEditor"});_(this,Cd);this._willKeepAspectRatio=!0}static initialize(e,s){Ot.initialize(e,s),this._defaultDrawingOptions=new Ig(s.viewParameters)}static getDefaultDrawingOptions(e){const s=this._defaultDrawingOptions.clone();return s.updateProperties(e),s}static get supportMultipleDrawings(){return!0}static get typesMap(){return nt(this,"typesMap",new Map([[at.INK_THICKNESS,"stroke-width"],[at.INK_COLOR,"stroke"],[at.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(e,s,i,n,r){return new iC(e,s,i,n,r,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(e,s,i,n,r,o){return od.deserialize(e,s,i,n,r,o)}static async deserialize(e,s,i){let n=null;if(e instanceof Og){const{data:{inkLists:o,rect:h,rotation:c,id:u,color:d,opacity:f,borderStyle:{rawWidth:g},popupRef:p},parent:{page:{pageNumber:b}}}=e;n=e={annotationType:tt.INK,color:Array.from(d),thickness:g,opacity:f,paths:{points:o},boxes:null,pageIndex:b-1,rect:h.slice(0),rotation:c,id:u,deleted:!1,popupRef:p}}const r=await super.deserialize(e,s,i);return r.annotationElementId=e.id||null,r._initialData=n,r}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();const{_drawId:e,_drawingOptions:s,parent:i}=this;s.updateSVGProperty("stroke-width"),i.drawLayer.updateProperties(e,s.toSVGProperties())}static onScaleChangingWhenDrawing(){const e=this._currentParent;e&&(super.onScaleChangingWhenDrawing(),this._defaultDrawingOptions.updateSVGProperty("stroke-width"),e.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}createDrawingOptions({color:e,thickness:s,opacity:i}){this._drawingOptions=dh.getDefaultDrawingOptions({stroke:U.makeHexColor(...e),"stroke-width":s,"stroke-opacity":i})}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:s,points:i,rect:n}=this.serializeDraw(e),{_drawingOptions:{stroke:r,"stroke-opacity":o,"stroke-width":h}}=this,c={annotationType:tt.INK,color:Ot._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,by).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,by=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},$(dh,"_type","ink"),$(dh,"_editorType",tt.INK),$(dh,"_defaultDrawingOptions",null);let Ng=dh;const Sc=class Sc extends Ot{constructor(e){super({...e,name:"stampEditor"});_(this,lt);_(this,Rt,null);_(this,de,null);_(this,hr,null);_(this,yn,null);_(this,lr,null);_(this,fh,"");_(this,Ti,null);_(this,Ei,null);_(this,bs,!1);_(this,gh,!1);m(this,yn,e.bitmapUrl),m(this,lr,e.bitmapFile)}static initialize(e,s){Ot.initialize(e,s)}static get supportedTypes(){return nt(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(s=>`image/${s}`))}static get supportedTypesStr(){return nt(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(e){return this.supportedTypes.includes(e)}static paste(e,s){s.pasteEditor(tt.STAMP,{bitmapFile:e.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){var e;return{type:"stamp",hasAltText:!!((e=this.altTextData)!=null&&e.altText)}}static computeTelemetryFinalData(e){const s=e.get("hasAltText");return{hasAltText:s.get(!0)??0,hasNoAltText:s.get(!1)??0}}async mlGuessAltText(e=null,s=!0){if(this.hasAltTextData())return null;const{mlManager:i}=this._uiManager;if(!i)throw new Error("No ML.");if(!await i.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:n,width:r,height:o}=e||this.copyCanvas(null,null,!0).imageData,h=await i.guess({name:"altText",request:{data:n,width:r,height:o,channels:n.length/(r*o)}});if(!h)throw new Error("No response from the AI service.");if(h.error)throw new Error("Error from the AI service.");if(h.cancel)return null;if(!h.output)throw new Error("No valid response from the AI service.");const c=h.output;return await this.setGuessedAltText(c),s&&!this.hasAltTextData()&&(this.altTextData={alt:c,decorative:!1}),c}remove(){var e;l(this,de)&&(m(this,Rt,null),this._uiManager.imageManager.deleteId(l(this,de)),(e=l(this,Ti))==null||e.remove(),m(this,Ti,null),l(this,Ei)&&(clearTimeout(l(this,Ei)),m(this,Ei,null))),super.remove()}rebuild(){if(!this.parent){l(this,de)&&w(this,lt,Jd).call(this);return}super.rebuild(),this.div!==null&&(l(this,de)&&l(this,Ti)===null&&w(this,lt,Jd).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(e){this._isDraggable=!0,e&&this.div.focus()}isEmpty(){return!(l(this,hr)||l(this,Rt)||l(this,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,Rt)?w(this,lt,Ip).call(this):w(this,lt,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,Ei)!==null&&clearTimeout(l(this,Ei)),m(this,Ei,setTimeout(()=>{m(this,Ei,null),w(this,lt,Np).call(this)},200))}copyCanvas(e,s,i=!1){var g;e||(e=224);const{width:n,height:r}=l(this,Rt),o=new pg;let h=l(this,Rt),c=n,u=r,d=null;if(s){if(n>s||r>s){const O=Math.min(s/n,s/r);c=Math.floor(n*O),u=Math.floor(r*O)}d=document.createElement("canvas");const p=d.width=Math.ceil(c*o.sx),b=d.height=Math.ceil(u*o.sy);l(this,bs)||(h=w(this,lt,Zd).call(this,p,b));const v=d.getContext("2d");v.filter=this._uiManager.hcmFilter;let y="white",x="#cfcfd8";this._uiManager.hcmFilter!=="none"?x="black":(g=window.matchMedia)!=null&&g.call(window,"(prefers-color-scheme: dark)").matches&&(y="#8f8f9d",x="#42414d");const S=15,C=S*o.sx,E=S*o.sy,P=new OffscreenCanvas(C*2,E*2),M=P.getContext("2d");M.fillStyle=y,M.fillRect(0,0,C*2,E*2),M.fillStyle=x,M.fillRect(0,0,C,E),M.fillRect(C,E,C,E),v.fillStyle=v.createPattern(P,"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,Rt),n>e||r>e){const x=Math.min(e/n,e/r);p=Math.floor(n*x),b=Math.floor(r*x),l(this,bs)||(h=w(this,lt,Zd).call(this,p,b))}const y=new OffscreenCanvas(p,b).getContext("2d",{willReadFrequently:!0});y.drawImage(h,0,0,h.width,h.height,0,0,p,b),f={width:p,height:b,data:y.getImageData(0,0,p,b).data}}return{canvas:d,width:c,height:u,imageData:f}}getImageForAltText(){return l(this,Ti)}static async deserialize(e,s,i){var b;let n=null;if(e instanceof zb){const{data:{rect:v,rotation:y,id:x,structParent:S,popupRef:C},container:E,parent:{page:{pageNumber:P}}}=e,M=E.querySelector("canvas"),O=i.imageManager.getFromCanvas(E.id,M);M.remove();const R=((b=await s._structTree.getAriaAttributes(`${cg}${x}`))==null?void 0:b.get("aria-label"))||"";n=e={annotationType:tt.STAMP,bitmapId:O.id,bitmap:O.bitmap,pageIndex:P-1,rect:v.slice(0),rotation:y,id:x,deleted:!1,accessibilityData:{decorative:!1,altText:R},isSvg:!1,structParent:S,popupRef:C}}const r=await super.deserialize(e,s,i),{rect:o,bitmap:h,bitmapUrl:c,bitmapId:u,isSvg:d,accessibilityData:f}=e;u&&i.imageManager.isValidId(u)?(m(r,de,u),h&&m(r,Rt,h)):m(r,yn,c),m(r,bs,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,gh,!!n),r}serialize(e=!1,s=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const i={annotationType:tt.STAMP,bitmapId:l(this,de),pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:l(this,bs),structTreeParentId:this._structTreeParentId};if(e)return i.bitmapUrl=w(this,lt,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,lt,vy).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,bs)?(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,lt,tf).call(this,!1);else if(l(this,bs)){const h=s.stamps.get(l(this,de));o>h.area&&(h.area=o,h.serialized.bitmap.close(),h.serialized.bitmap=w(this,lt,tf).call(this,!1))}return i}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}};Rt=new WeakMap,de=new WeakMap,hr=new WeakMap,yn=new WeakMap,lr=new WeakMap,fh=new WeakMap,Ti=new WeakMap,Ei=new WeakMap,bs=new WeakMap,gh=new WeakMap,lt=new WeakSet,Nc=function(e,s=!1){if(!e){this.remove();return}m(this,Rt,e.bitmap),s||(m(this,de,e.id),m(this,bs,e.isSvg)),e.file&&m(this,fh,e.file.name),w(this,lt,Ip).call(this)},jc=function(){if(m(this,hr,null),this._uiManager.enableWaiting(!1),!!l(this,Ti)){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Rt)){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Rt)){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}},Jd=function(){if(l(this,de)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(l(this,de)).then(i=>w(this,lt,Nc).call(this,i,!0)).finally(()=>w(this,lt,jc).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,lt,Nc).call(this,n)).finally(()=>w(this,lt,jc).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,lt,Nc).call(this,n)).finally(()=>w(this,lt,jc).call(this)));return}const e=document.createElement("input");e.type="file",e.accept=Sc.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,lt,Nc).call(this,n)}i()},{signal:s}),e.addEventListener("cancel",()=>{this.remove(),i()},{signal:s})}).finally(()=>w(this,lt,jc).call(this))),e.click()},Ip=function(){var d;const{div:e}=this;let{width:s,height:i}=l(this,Rt);const[n,r]=this.pageDimensions,o=.75;if(this.width)s=this.width*n,i=this.height*r;else if(s>o*n||i>o*r){const f=Math.min(o*n/s,o*r/i);s*=f,i*=f}const[h,c]=this.parentDimensions;this.setDims(s*h/n,i*c/r),this._uiManager.enableWaiting(!1);const u=m(this,Ti,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,lt,Np).call(this),l(this,gh)||(this.parent.addUndoableEditor(this),m(this,gh,!0)),this._reportTelemetry({action:"inserted_image"}),l(this,fh)&&u.setAttribute("aria-label",l(this,fh))},Zd=function(e,s){const{width:i,height:n}=l(this,Rt);let r=i,o=n,h=l(this,Rt);for(;r>2*e||o>2*s;){const c=r,u=o;r>2*e&&(r=r>=16384?Math.floor(r/2)-1:Math.ceil(r/2)),o>2*s&&(o=o>=16384?Math.floor(o/2)-1:Math.ceil(o/2));const d=new OffscreenCanvas(r,o);d.getContext("2d").drawImage(h,0,0,c,u,0,0,r,o),h=d.transferToImageBitmap()}return h},Np=function(){const[e,s]=this.parentDimensions,{width:i,height:n}=this,r=new pg,o=Math.ceil(i*e*r.sx),h=Math.ceil(n*s*r.sy),c=l(this,Ti);if(!c||c.width===o&&c.height===h)return;c.width=o,c.height=h;const u=l(this,bs)?l(this,Rt):w(this,lt,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,bs)){const n=this._uiManager.imageManager.getSvgUrl(l(this,de));if(n)return n}const s=document.createElement("canvas");return{width:s.width,height:s.height}=l(this,Rt),s.getContext("2d").drawImage(l(this,Rt),0,0),s.toDataURL()}if(l(this,bs)){const[s,i]=this.pageDimensions,n=Math.round(this.width*s*Ln.PDF_TO_CSS_UNITS),r=Math.round(this.height*i*Ln.PDF_TO_CSS_UNITS),o=new OffscreenCanvas(n,r);return o.getContext("2d").drawImage(l(this,Rt),0,0,l(this,Rt).width,l(this,Rt).height,0,0,n,r),o.transferToImageBitmap()}return structuredClone(l(this,Rt))},vy=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}},$(Sc,"_type","stamp"),$(Sc,"_editorType",tt.STAMP);let jg=Sc;const si=class si{constructor({uiManager:t,pageIndex:e,div:s,structTreeLayer:i,accessibilityManager:n,annotationLayer:r,drawLayer:o,textLayer:h,viewport:c,l10n:u}){_(this,Et);_(this,jo);_(this,ph,!1);_(this,ki,null);_(this,cr,null);_(this,_n,null);_(this,Ds,new Map);_(this,ur,!1);_(this,mh,!1);_(this,Bo,!1);_(this,ei,null);_(this,wn,null);_(this,Ce,null);_(this,xn,null);_(this,W);const d=[...l(si,dr).values()];if(!si._initialized){si._initialized=!0;for(const f of d)f.initialize(u,t)}t.registerEditorTypes(d),m(this,W,t),this.pageIndex=e,this.div=s,m(this,jo,n),m(this,ki,r),this.viewport=c,m(this,Ce,h),this.drawLayer=o,this._structTree=i,l(this,W).addLayer(this)}get isEmpty(){return l(this,Ds).size===0}get isInvisible(){return this.isEmpty&&l(this,W).getMode()===tt.NONE}updateToolbar(t){l(this,W).updateToolbar(t)}updateMode(t=l(this,W).getMode()){switch(w(this,Et,ef).call(this),t){case tt.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case tt.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case tt.HIGHLIGHT:this.enableTextSelection(),this.togglePointerEvents(!1),this.disableClick();break;default:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);const{classList:e}=this.div;for(const s of l(si,dr).values())e.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){var e;return t===((e=l(this,Ce))==null?void 0:e.div)}setEditingState(t){l(this,W).setEditingState(t)}addCommands(t){l(this,W).addCommands(t)}cleanUndoStack(t){l(this,W).cleanUndoStack(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){var e;(e=l(this,ki))==null||e.div.classList.toggle("disabled",!t)}async enable(){m(this,Bo,!0),this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const s of l(this,Ds).values())s.enableEditing(),s.show(!0),s.annotationElementId&&(l(this,W).removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!l(this,ki)){m(this,Bo,!1);return}const e=l(this,ki).getEditableAnnotations();for(const s of e){if(s.hide(),l(this,W).isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;const i=await this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}m(this,Bo,!1)}disable(){var i;m(this,mh,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,e=new Map;for(const n of l(this,Ds).values())if(n.disableEditing(),!!n.annotationElementId){if(n.serialize()!==null){t.set(n.annotationElementId,n);continue}else e.set(n.annotationElementId,n);(i=this.getEditableAnnotation(n.annotationElementId))==null||i.show(),n.remove()}if(l(this,ki)){const n=l(this,ki).getEditableAnnotations();for(const r of n){const{id:o}=r.data;if(l(this,W).isDeletedAnnotationElement(o))continue;let h=e.get(o);if(h){h.resetAnnotationElement(r),h.show(!1),r.show();continue}h=t.get(o),h&&(l(this,W).addChangedExistingAnnotation(h),h.renderAnnotationElement(r)&&h.show(!1)),r.show()}}w(this,Et,ef).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const n of l(si,dr).values())s.remove(`${n._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),m(this,mh,!1)}getEditableAnnotation(t){var e;return((e=l(this,ki))==null?void 0:e.getEditableAnnotation(t))||null}setActiveEditor(t){l(this,W).getActive()!==t&&l(this,W).setActiveEditor(t)}enableTextSelection(){var t;if(this.div.tabIndex=-1,(t=l(this,Ce))!=null&&t.div&&!l(this,xn)){m(this,xn,new AbortController);const e=l(this,W).combinedSignal(l(this,xn));l(this,Ce).div.addEventListener("pointerdown",w(this,Et,yy).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,xn)&&(l(this,xn).abort(),m(this,xn,null),l(this,Ce).div.classList.remove("highlighting"))}enableClick(){if(l(this,cr))return;m(this,cr,new AbortController);const t=l(this,W).combinedSignal(l(this,cr));this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t});const e=this.pointerup.bind(this);this.div.addEventListener("pointerup",e,{signal:t}),this.div.addEventListener("pointercancel",e,{signal:t})}disableClick(){var t;(t=l(this,cr))==null||t.abort(),m(this,cr,null)}attach(t){l(this,Ds).set(t.id,t);const{annotationElementId:e}=t;e&&l(this,W).isDeletedAnnotationElement(e)&&l(this,W).removeDeletedAnnotationElement(t)}detach(t){var e;l(this,Ds).delete(t.id),(e=l(this,jo))==null||e.removePointerInTextLayer(t.contentDiv),!l(this,mh)&&t.annotationElementId&&l(this,W).addDeletedAnnotationElement(t)}remove(t){this.detach(t),l(this,W).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){var e;t.parent!==this&&(t.parent&&t.annotationElementId&&(l(this,W).addDeletedAnnotationElement(t.annotationElementId),Ot.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),(e=t.parent)==null||e.detach(t),t.setParent(this),t.div&&t.isAttachedToDOM&&(t.div.remove(),this.div.append(t.div)))}add(t){if(!(t.parent===this&&t.isAttachedToDOM)){if(this.changeParent(t),l(this,W).addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!l(this,Bo)),l(this,W).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var s;if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!l(this,_n)&&(t._focusEventsAllowed=!1,m(this,_n,setTimeout(()=>{m(this,_n,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:l(this,W)._signal}),e.focus())},0))),t._structTreeParentId=(s=l(this,jo))==null?void 0:s.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){t.needsToBeRebuilt()?(t.parent||(t.parent=this),t.rebuild(),t.show()):this.add(t)}addUndoableEditor(t){const e=()=>t._uiManager.rebuild(t),s=()=>{t.remove()};this.addCommands({cmd:e,undo:s,mustExec:!1})}getNextId(){return l(this,W).getId()}combinedSignal(t){return l(this,W).combinedSignal(t)}canCreateNewEmptyEditor(){var t;return(t=l(this,Et,Di))==null?void 0:t.canCreateNewEmptyEditor()}pasteEditor(t,e){l(this,W).updateToolbar(t),l(this,W).updateMode(t);const{offsetX:s,offsetY:i}=w(this,Et,Bp).call(this),n=this.getNextId(),r=w(this,Et,jp).call(this,{parent:this,id:n,x:s,y:i,uiManager:l(this,W),isCentered:!0,...e});r&&this.add(r)}async deserialize(t){var e;return await((e=l(si,dr).get(t.annotationType??t.annotationEditorType))==null?void 0:e.deserialize(t,this,l(this,W)))||null}createAndAddNewEditor(t,e,s={}){const i=this.getNextId(),n=w(this,Et,jp).call(this,{parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:l(this,W),isCentered:e,...s});return n&&this.add(n),n}addNewEditor(){this.createAndAddNewEditor(w(this,Et,Bp).call(this),!0)}setSelected(t){l(this,W).setSelected(t)}toggleSelected(t){l(this,W).toggleSelected(t)}unselect(t){l(this,W).unselect(t)}pointerup(t){var s;const{isMac:e}=Re.platform;if(!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&l(this,ur)&&(m(this,ur,!1),!((s=l(this,Et,Di))!=null&&s.isDrawer&&l(this,Et,Di).supportMultipleDrawings))){if(!l(this,ph)){m(this,ph,!0);return}if(l(this,W).getMode()===tt.STAMP){l(this,W).unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){var i;if(l(this,W).getMode()===tt.HIGHLIGHT&&this.enableTextSelection(),l(this,ur)){m(this,ur,!1);return}const{isMac:e}=Re.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;if(m(this,ur,!0),(i=l(this,Et,Di))!=null&&i.isDrawer){this.startDrawingSession(t);return}const s=l(this,W).getActive();m(this,ph,!s||s.isEmpty())}startDrawingSession(t){if(this.div.focus(),l(this,ei)){l(this,Et,Di).startDrawing(this,l(this,W),!1,t);return}l(this,W).setCurrentDrawingSession(this),m(this,ei,new AbortController);const e=l(this,W).combinedSignal(l(this,ei));this.div.addEventListener("blur",({relatedTarget:s})=>{s&&!this.div.contains(s)&&(m(this,wn,null),this.commitOrRemove())},{signal:e}),l(this,Et,Di).startDrawing(this,l(this,W),!1,t)}pause(t){if(t){const{activeElement:e}=document;this.div.contains(e)&&m(this,wn,e);return}l(this,wn)&&setTimeout(()=>{var e;(e=l(this,wn))==null||e.focus(),m(this,wn,null)},0)}endDrawingSession(t=!1){return l(this,ei)?(l(this,W).setCurrentDrawingSession(null),l(this,ei).abort(),m(this,ei,null),m(this,wn,null),l(this,Et,Di).endDrawing(t)):null}findNewParent(t,e,s){const i=l(this,W).findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}commitOrRemove(){return l(this,ei)?(this.endDrawingSession(),!0):!1}onScaleChanging(){l(this,ei)&&l(this,Et,Di).onScaleChangingWhenDrawing(this)}destroy(){var t,e;this.commitOrRemove(),((t=l(this,W).getActive())==null?void 0:t.parent)===this&&(l(this,W).commitOrRemove(),l(this,W).setActiveEditor(null)),l(this,_n)&&(clearTimeout(l(this,_n)),m(this,_n,null));for(const s of l(this,Ds).values())(e=l(this,jo))==null||e.removePointerInTextLayer(s.contentDiv),s.setParent(null),s.isAttachedToDOM=!1,s.div.remove();this.div=null,l(this,Ds).clear(),l(this,W).removeLayer(this)}render({viewport:t}){this.viewport=t,Mr(this.div,t);for(const e of l(this,W).getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){l(this,W).commitOrRemove(),w(this,Et,ef).call(this);const e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,Mr(this.div,{rotation:s}),e!==s)for(const i of l(this,Ds).values())i.rotate(s)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return l(this,W).viewParameters.realScale}};jo=new WeakMap,ph=new WeakMap,ki=new WeakMap,cr=new WeakMap,_n=new WeakMap,Ds=new WeakMap,ur=new WeakMap,mh=new WeakMap,Bo=new WeakMap,ei=new WeakMap,wn=new WeakMap,Ce=new WeakMap,xn=new WeakMap,W=new WeakMap,dr=new WeakMap,Et=new WeakSet,yy=function(t){l(this,W).unselectAll();const{target:e}=t;if(e===l(this,Ce).div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&l(this,Ce).div.contains(e)){const{isMac:s}=Re.platform;if(t.button!==0||t.ctrlKey&&s)return;l(this,W).showAllEditors("highlight",!0,!0),l(this,Ce).div.classList.add("free"),this.toggleDrawing(),rd.startHighlighting(this,l(this,W).direction==="ltr",{target:l(this,Ce).div,x:t.x,y:t.y}),l(this,Ce).div.addEventListener("pointerup",()=>{l(this,Ce).div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:l(this,W)._signal}),t.preventDefault()}},Di=function(){return l(si,dr).get(l(this,W).getMode())},jp=function(t){const e=l(this,Et,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,Ds).values())t.isEmpty()&&t.remove()},$(si,"_initialized",!1),_(si,dr,new Map([Dg,Ng,jg,rd].map(t=>[t._editorType,t])));let Bg=si;const Ae=class Ae{constructor({pageIndex:t}){_(this,Mi);_(this,ii,null);_(this,Cc,0);_(this,Be,new Map);_(this,Ho,new Map);this.pageIndex=t}setParent(t){if(!l(this,ii)){m(this,ii,t);return}if(l(this,ii)!==t){if(l(this,Be).size>0)for(const e of l(this,Be).values())e.remove(),t.append(e);m(this,ii,t)}}static get _svgFactory(){return nt(this,"_svgFactory",new Mg)}draw(t,e=!1,s=!1){const i=ze(this,Cc)._++,n=w(this,Mi,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,Ho).set(i,o);const c=s?w(this,Mi,wy).call(this,r,h):null,u=Ae._svgFactory.createElement("use");return n.append(u),u.setAttribute("href",`#${h}`),this.updateProperties(n,t),l(this,Be).set(i,n),{id:i,clipPathId:`url(#${c})`}}drawOutline(t,e){const s=ze(this,Cc)._++,i=w(this,Mi,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,Ho).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,Mi,zp).call(this,o,s),i&&w(h=Ae,Ad,_y).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,Mi,zp).call(this,u,r)}}}updateParent(t,e){if(e===this)return;const s=l(this,Be).get(t);s&&(l(e,ii).append(s),l(this,Be).delete(t),l(e,Be).set(t,s))}remove(t){l(this,Ho).delete(t),l(this,ii)!==null&&(l(this,Be).get(t).remove(),l(this,Be).delete(t))}destroy(){m(this,ii,null);for(const t of l(this,Be).values())t.remove();l(this,Be).clear(),l(this,Ho).clear()}};ii=new WeakMap,Cc=new WeakMap,Be=new WeakMap,Ho=new WeakMap,Ad=new WeakSet,_y=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}%`},Mi=new WeakSet,Hp=function(){const t=Ae._svgFactory.create(1,1,!0);return l(this,ii).append(t),t.setAttribute("aria-hidden",!0),t},wy=function(t,e){const s=Ae._svgFactory.createElement("clipPath");t.append(s);const i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=Ae._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i},zp=function(t,e){for(const[s,i]of Object.entries(e))i===null?t.removeAttribute(s):t.setAttribute(s,i)},_(Ae,Ad);let Hg=Ae;globalThis.pdfjsTestingUtils={HighlightOutliner:Rg},Q.AbortException,Q.AnnotationEditorLayer,Q.AnnotationEditorParamsType,Q.AnnotationEditorType,Q.AnnotationEditorUIManager,Q.AnnotationLayer,Q.AnnotationMode,Q.ColorPicker,Q.DOMSVGFactory,Q.DrawLayer,Q.FeatureTest;var nC=Q.GlobalWorkerOptions;Q.ImageKind,Q.InvalidPDFException,Q.MissingPDFException,Q.OPS,Q.OutputScale,Q.PDFDataRangeTransport,Q.PDFDateString,Q.PDFWorker,Q.PasswordResponses,Q.PermissionFlag,Q.PixelsPerInch,Q.RenderingCancelledException,Q.TextLayer,Q.TouchManager,Q.UnexpectedResponseException,Q.Util,Q.VerbosityLevel,Q.XfaLayer,Q.build,Q.createValidAbsoluteUrl,Q.fetchData;var rC=Q.getDocument;Q.getFilenameFromUrl,Q.getPdfFilenameFromUrl,Q.getXfaPageViewport,Q.isDataScheme,Q.isPdfFile,Q.noContextMenu,Q.normalizeUnicode,Q.setLayerDimensions,Q.shadow,Q.stopEvent,Q.version;const oC={"pdfjs-dist":"4.10.38"};function aC(a){return new Promise((t,e)=>{const s=new FileReader;s.addEventListener("load",()=>t(s.result)),s.addEventListener("error",e),s.readAsDataURL(a)})}const hC=oC["pdfjs-dist"].replace("^","");nC.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${hC}/pdf.worker.min.mjs`;async function lC(a){const t="data:application/pdf;base64,",e=await aC(a);if(typeof e=="string")return window.atob(e.slice(t.length))}function cC(a,t){return rC({data:a,password:t}).promise}const $e=new Map;function uC(a){const t=new Wf(a);return $e.set(a,t),t}function dC(a,t){const e=Date.now();return{PDFId:`${a.name}-${e}`,name:a.name.replace(/.pdf/,""),updateDate:e,PDFBase64:t}}function fC(a,t){const e=a.getViewport({scale:t}),s=document.createElement("canvas"),i=s.getContext("2d"),n=ex()/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 gC({src:a},t,e){if(!a||!e)return null;const{objects:s,options:i}=await Vw(a),n=s.filter(o=>o!==null),r=iw.groupSVGElements(n,i);return n.forEach(o=>{o.stroke=e}),r.hoverCursor="pointer",r.stroke=`${e}-${t}`,r}function pC(a,t){if(!$e.get(a))return;const s=1/3,i=xC(t,s);Xb(a,i,s)}async function mC(a,t){const e=await ix(t),s=Date.now(),n={PDFId:`${t.name}${s}`,name:t.name.replace(/.png|.jpg|.jpeg/,""),updateDate:s,PDFBase64:e};return Vb(a,{url:e}),{...n,pages:1}}async function Vb(a,{url:t,scale:e=.5}){if(!$e.get(a))return;const i=await be.fromURL(t);i.scale(e),Xb(a,i,e)}function Xb(a,t,e){const s=$e.get(a);s&&(s.setWidth(t.width*e),s.setHeight(t.height*e),s.backgroundImage=t,s.renderAll())}function bC(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 vC(a,t,e){!e||!a||(e.scale(1/t),bC(a,e))}function yC(a,t){if(!a)return;const e=a._cornerSize||6;a.borderScaleFactor=1/t,a.cornerSize=e*(1/t),a.touchCornerSize=e*4*(1/t),a.setCoords()}function _C(a){const t=$e.get(a);t&&(t.discardActiveObject(),t.renderAll())}function wC(a){const t=$e.get(a);t&&(t.clear(),$e.delete(a))}function xC(a,t){return new be(a,{scaleX:t,scaleY:t})}function zg(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 Wb(a,t,e){var n;const s=a.type,i={"application/pdf":SC,"image/png":Yb,"image/jpeg":Yb};return((n=i[s])==null?void 0:n.call(i,a,t,e))??Promise.reject(new Error(`Unsupported ${s} file type.`))}async function SC(a,t,e){const s=await lC(a);if(!s)return;const i=dC(a,s);try{const n=await Ub({page:1,PDFBase64:s,scale:.8,password:t},e);return{...i,pages:n}}catch(n){return Promise.reject(n)}}async function Ub({page:a,PDFBase64:t,scale:e,password:s},i){try{const n=await cC(t,s),r=await n.getPage(a),{renderTask:o,canvas:h}=fC(r,e);return o.promise.then(()=>(i&&pC(i,h),n.numPages))}catch(n){return Promise.reject(n)}}async function Yb(a,t,e){if(e)return await mC(e,a)}async function CC(a,t){const e=$e.get(a);if(!e)return;const s=e==null?void 0:e.getActiveObject();if(!s)return;const i=await s.clone(Ay);i instanceof _s?i.forEachObject(n=>{e.add(n),t(e,n)}):(e.add(i),t(e,i)),zg(i,{x:-.1,y:-.1}),e.setActiveObject(i)}function AC(a){const t=$e.get(a);if(!t)return;const e=t.getActiveObject();e&&(e instanceof _s?(e.forEachObject(s=>{t.remove(s)}),t.discardActiveObject()):t.remove(e))}function $b(a){const{id:t="",selectionOptions:e,pointerDown:s,pointerMove:i,pointerUp:n,selectionCreated:r,selectionCleared:o}=a||{};let h=null,c=null,u=1,d={...Cy};function f(){if(!t||$e.has(t))return;const D=uC(t);return D.on("selection:created",F=>{if(r==null||r(F),F.selected.length<=1)return;const j=D.getActiveObject();j&&(c=j,e!=null&&e.value&&c.set(e.value),c._cornerSize=c.cornerSize,E(u))}),D.on("selection:cleared",F=>{o==null||o(F),M(D)}),s&&D.on("mouse:down",s),i&&D.on("mouse:move",i),n&&D.on("mouse:up",n),D}function g(D,F){return Wb(D,F,t)}function p(D){return Ub(D,t)}function b({url:D,scale:F=.5}){return Vb(t,{url:D,scale:F})}async function v(D,F,j){const q=$e.get(t);if(!q)return;const I=await be.fromURL(D,{},{...sf,...F});zg(I,j),q.add(I),x(q,I),q.setActiveObject(I)}function y(D,F,j){const q=$e.get(t);if(!q)return;const I=new me(D,{...xy,...F});zg(I,j),q.add(I),x(q,I),q.setActiveObject(I)}function x(D,F){F.on("selected",j=>S({canvas:D,target:j.target})),F.on("modified",j=>S({canvas:D,target:j.target})),F.on("scaling",()=>M(D)),F.on("moving",()=>M(D)),F.on("rotating",()=>M(D)),F._cornerSize=F._cornerSize??F.cornerSize}async function S({canvas:D,target:F,stroke:j=d.stroke,uuid:q=Date.now()}){if(D.getActiveObjects().length>1||(h==null?void 0:h.stroke)===`${j}-${q}`)return;const H=await gC(d,q,j);M(D),h=H,c=F,C(D,F,q),E(u,!0),H&&D.add(H)}function C(D,F,j){h&&(h.on("selected",()=>{D.remove(F),M(D)}),h.on("mouseover",()=>{S({canvas:D,target:F,stroke:d.hoverStroke,uuid:j})}),h.on("mouseout",()=>{S({canvas:D,target:F,stroke:d.stroke,uuid:j})}))}function E(D,F=!1){const j=$e.get(t);u=D,j&&(yC(c,D),vC(c,D,h),!F&&j.renderAll())}function P(D){if(!D)return;d={...d,...D};const F=$e.get(t);!h||!c||!F||S({target:c,canvas:F})}function M(D){c=null,h&&(D.remove(h),h=null)}function O(){_C(t)}function R(){wC(t)}function L(){return CC(t,x)}function N(){AC(t)}return{createCanvas:f,loadFile:g,specifyPage:p,renderImage:b,addFabric:v,addTextFabric:y,clearActive:O,deleteCanvas:R,scaleFabric:E,setCloseSvgOptions:P,copyActiveFabric:L,deleteActiveFabric:N}}function TC(a){let t=0;const e=sx(()=>{t!==window.innerWidth&&(t=window.innerWidth,a())});K.onMounted(()=>{window.addEventListener("resize",e)}),K.onBeforeUnmount(()=>{window.removeEventListener("resize",e)})}const EC=K.defineComponent({__name:"pdf-canvas",props:{file:{},page:{default:1},canvasId:{default:"PDF-canvas"},fileZoom:{default:1},fileScale:{default:1},canvasScale:{default:1},canvasClass:{default:""},isDrop:{type:Boolean,default:!1},password:{},dropTextOptions:{},dropImageOptions:{},selectionOptions:{},closeSvgOptions:{},manualReload:{type:Boolean},onDestroy:{type:Function,default:K.onBeforeUnmount}},emits:["loaded","reload","pointerDown","pointerMove","pointerUp","selectionCreated","selectionCleared"],setup(a,{expose:t,emit:e}){const s=a,i=e,{onDestroy:n}=s,r=K.ref(null),o=`${s.canvasId}-${s.page-1}`,h=K.computed(()=>s.fileZoom*s.canvasScale),c=K.computed(()=>({...Sy,...s.selectionOptions})),{createCanvas:u,specifyPage:d,addFabric:f,addTextFabric:g,renderImage:p,clearActive:b,deleteCanvas:v,scaleFabric:y,setCloseSvgOptions:x,copyActiveFabric:S,deleteActiveFabric:C}=$b({id:o,selectionOptions:c,pointerDown:L=>i("pointerDown",L),pointerMove:L=>i("pointerMove",L),pointerUp:L=>i("pointerUp",L),selectionCreated:L=>i("selectionCreated",L),selectionCleared:L=>i("selectionCleared",L)});E(),TC(R);async function E(){const{file:L,page:N,fileScale:D}=s;window.requestAnimationFrame(async()=>{if(await K.nextTick(),u(),L.PDFBase64.startsWith("data:image")||L.canvas){const{canvas:F}=L,j=F?7:3,q=F!=null&&F.length?F[N-1]:L.PDFBase64;p({url:q,scale:D/j}),i("loaded");return}await d({page:N,PDFBase64:L.PDFBase64,scale:D,password:s.password}),i("loaded")})}function P(L){if(!s.isDrop||!L.dataTransfer)return;const{dataTransfer:N,offsetX:D,offsetY:F}=L,j=N.getData("text/plain"),q=N.getData("text/uri-list"),I=N.getData("custom/offset"),H=I?JSON.parse(I):null,it={top:F,left:D},kt={x:(H==null?void 0:H.offsetX)??0,y:(H==null?void 0:H.offsetY)??0};q?M(q,it,kt):j&&O(j,it,kt)}function M(L,N,D){f(L,{...s.dropImageOptions,...N},D)}function O(L,N,D){g(L,{...s.dropTextOptions,...N},D)}function R(){s.manualReload||E(),i("reload")}return K.watch([()=>s.fileScale,()=>s.page,()=>s.file,()=>s.password],R),K.watch(h,L=>y(L),{immediate:!0}),K.watch(()=>s.closeSvgOptions,x,{immediate:!0}),n(v),t({reload:E,addImage:M,addText:O,clearActive:b,deleteCanvas:v,copyActiveFabric:S,deleteActiveFabric:C,canvasRef:r}),(L,N)=>(K.openBlock(),K.createElementBlock("div",{style:K.normalizeStyle({transform:`scale(${h.value})`}),onDragover:N[0]||(N[0]=K.withModifiers(()=>{},["prevent"])),onDragenter:N[1]||(N[1]=K.withModifiers(()=>{},["prevent"])),onDrop:K.withModifiers(P,["stop","prevent"])},[K.createElementVNode("canvas",{id:o,ref_key:"canvasRef",ref:r,class:K.normalizeClass(L.canvasClass)},null,2)],36))}});ot.default=EC,ot.loadFile=Wb,ot.useFabric=$b,Object.defineProperties(ot,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
511
+ `)}`),w(this,Ut,$d).call(this);const f=new Range;let g=u.reduce((v,x)=>v+x.length,0);for(const{firstChild:v}of this.editorDiv.childNodes)if(v.nodeType===Node.TEXT_NODE){const x=v.nodeValue.length;if(g<=x){f.setStart(v,g),f.setEnd(v,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 Vb){const{data:{defaultAppearanceData:{fontSize:h,fontColor:c},rect:u,rotation:d,id:f,popupRef:g},textContent:p,textPosition:b,parent:{page:{pageNumber:y}}}=e;if(!p||p.length===0)return null;n=e={annotationType:et.FREETEXT,color:Array.from(c),fontSize:h,value:p.join(`
512
+ `),position:b,pageIndex:y-1,rect:u.slice(0),rotation:d,id:f,deleted:!1,popupRef:g}}const r=await super.deserialize(e,s,i);return m(r,us,e.fontSize),m(r,qs,U.makeHexColor(...e.color)),m(r,cs,w(o=wt,pn,Mp).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=Ot._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:l(this,qs)),r={annotationType:et.FREETEXT,color:n,fontSize:l(this,us),value:w(this,Ut,Kv).call(this),pageIndex:this.pageIndex,rect:i,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?r:this.annotationElementId&&!w(this,Ut,Qv).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,us)}px * var(--scale-factor))`,i.color=l(this,qs),s.replaceChildren();for(const r of l(this,cs).split(`
513
+ `)){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,cs)}),s}resetAnnotationElement(e){super.resetAnnotationElement(e),e.resetEdited()}};qs=new WeakMap,cs=new WeakMap,ac=new WeakMap,Co=new WeakMap,us=new WeakMap,Ut=new WeakSet,Yv=function(e){const s=n=>{this.editorDiv.style.fontSize=`calc(${n}px * var(--scale-factor))`,this.translate(0,-(n-l(this,us))*this.parentScale),m(this,us,n),w(this,Ut,Ud).call(this)},i=l(this,us);this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:at.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})},$v=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:at.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})},qv=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,pn,Yd).call(i,n)),s=n);return e.join(`
514
+ `)},Ud=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()},pn=new WeakSet,Yd=function(e){return(e.nodeType===Node.TEXT_NODE?e.nodeValue:e.innerText).replaceAll(nd,"")},$d=function(){if(this.editorDiv.replaceChildren(),!!l(this,cs))for(const e of l(this,cs).split(`
515
+ `)){const s=document.createElement("div");s.append(e?document.createTextNode(e):document.createElement("br")),this.editorDiv.append(s)}},Kv=function(){return l(this,cs).replaceAll(" "," ")},Mp=function(e){return e.replaceAll(" "," ")},Qv=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},_(wt,pn),q(wt,"_freeTextDefaultContent",""),q(wt,"_internalPadding",0),q(wt,"_defaultColor",null),q(wt,"_defaultFontSize",10),q(wt,"_type","freetext"),q(wt,"_editorType",et.FREETEXT);let Fg=wt;class V{toSVGPath(){_t("Abstract method `toSVGPath` must be implemented.")}get box(){_t("Abstract getter `box` must be implemented.")}serialize(t,e){_t("Abstract method `serialize` must be implemented.")}static _rescale(t,e,s,i,n,r){r||(r=new Float32Array(t.length));for(let o=0,h=t.length;o<h;o+=2)r[o]=e+t[o]*i,r[o+1]=s+t[o+1]*n;return r}static _rescaleAndSwap(t,e,s,i,n,r){r||(r=new Float32Array(t.length));for(let o=0,h=t.length;o<h;o+=2)r[o]=e+t[o+1]*i,r[o+1]=s+t[o]*n;return r}static _translate(t,e,s,i){i||(i=new Float32Array(t.length));for(let n=0,r=t.length;n<r;n+=2)i[n]=e+t[n],i[n+1]=s+t[n+1];return i}static svgRound(t){return Math.round(t*1e4)}static _normalizePoint(t,e,s,i,n){switch(n){case 90:return[1-e/s,t/i];case 180:return[1-t/s,1-e/i];case 270:return[e/s,1-t/i];default:return[t/s,e/i]}}static _normalizePagePoint(t,e,s){switch(s){case 90:return[1-e,t];case 180:return[1-t,1-e];case 270:return[e,1-t];default:return[t,e]}}static createBezierPoints(t,e,s,i,n,r){return[(t+5*s)/6,(e+5*i)/6,(5*s+n)/6,(5*i+r)/6,(s+n)/2,(i+r)/2]}}q(V,"PRECISION",1e-4);const mn=class mn{constructor({x:t,y:e},s,i,n,r,o=0){_(this,Jt);_(this,ds);_(this,Ks,[]);_(this,Ya);_(this,$a);_(this,Si,[]);_(this,rt,new Float32Array(18));_(this,Ao);_(this,To);_(this,hc);_(this,lc);_(this,qa);_(this,Ka);_(this,sr,[]);m(this,ds,s),m(this,Ka,n*i),m(this,$a,r),l(this,rt).set([NaN,NaN,NaN,NaN,t,e],6),m(this,Ya,o),m(this,lc,l(mn,cc)*i),m(this,hc,l(mn,Cd)*i),m(this,qa,i),l(this,sr).push(t,e)}isEmpty(){return isNaN(l(this,rt)[8])}add({x:t,y:e}){var R;m(this,Ao,t),m(this,To,e);const[s,i,n,r]=l(this,ds);let[o,h,c,u]=l(this,rt).subarray(8,12);const d=t-c,f=e-u,g=Math.hypot(d,f);if(g<l(this,hc))return!1;const p=g-l(this,lc),b=p/g,y=b*d,v=b*f;let x=o,C=h;o=c,h=u,c+=y,u+=v,(R=l(this,sr))==null||R.push(t,e);const S=-v/p,A=y/p,k=S*l(this,Ka),P=A*l(this,Ka);return l(this,rt).set(l(this,rt).subarray(2,8),0),l(this,rt).set([c+k,u+P],4),l(this,rt).set(l(this,rt).subarray(14,18),12),l(this,rt).set([c-k,u-P],16),isNaN(l(this,rt)[6])?(l(this,Si).length===0&&(l(this,rt).set([o+k,h+P],2),l(this,Si).push(NaN,NaN,NaN,NaN,(o+k-s)/n,(h+P-i)/r),l(this,rt).set([o-k,h-P],14),l(this,Ks).push(NaN,NaN,NaN,NaN,(o-k-s)/n,(h-P-i)/r)),l(this,rt).set([x,C,o,h,c,u],6),!this.isEmpty()):(l(this,rt).set([x,C,o,h,c,u],6),Math.abs(Math.atan2(C-h,x-o)-Math.atan2(v,y))<Math.PI/2?([o,h,c,u]=l(this,rt).subarray(2,6),l(this,Si).push(NaN,NaN,NaN,NaN,((o+c)/2-s)/n,((h+u)/2-i)/r),[o,h,x,C]=l(this,rt).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,rt).subarray(0,6),l(this,Si).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,rt).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,Si),e=l(this,Ks);if(isNaN(l(this,rt)[6])&&!this.isEmpty())return w(this,Jt,Jv).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,ty).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,Zv).call(this,s),s.join(" ")}newFreeDrawOutline(t,e,s,i,n,r){return new Yb(t,e,s,i,n,r)}getOutlines(){var d;const t=l(this,Si),e=l(this,Ks),s=l(this,rt),[i,n,r,o]=l(this,ds),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,Ao)-i)/r,h[h.length-1]=(l(this,To)-n)/o,isNaN(s[6])&&!this.isEmpty())return w(this,Jt,ey).call(this,h);const c=new Float32Array(l(this,Si).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,iy).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,sy).call(this,c,u),this.newFreeDrawOutline(c,h,l(this,ds),l(this,qa),l(this,Ya),l(this,$a))}};ds=new WeakMap,Ks=new WeakMap,Ya=new WeakMap,$a=new WeakMap,Si=new WeakMap,rt=new WeakMap,Ao=new WeakMap,To=new WeakMap,hc=new WeakMap,lc=new WeakMap,qa=new WeakMap,Ka=new WeakMap,sr=new WeakMap,cc=new WeakMap,Sd=new WeakMap,Cd=new WeakMap,Jt=new WeakSet,Ic=function(){const t=l(this,rt).subarray(4,6),e=l(this,rt).subarray(16,18),[s,i,n,r]=l(this,ds);return[(l(this,Ao)+(t[0]-e[0])/2-s)/n,(l(this,To)+(t[1]-e[1])/2-i)/r,(l(this,Ao)+(e[0]-t[0])/2-s)/n,(l(this,To)+(e[1]-t[1])/2-i)/r]},Jv=function(){const[t,e,s,i]=l(this,ds),[n,r,o,h]=w(this,Jt,Ic).call(this);return`M${(l(this,rt)[2]-t)/s} ${(l(this,rt)[3]-e)/i} L${(l(this,rt)[4]-t)/s} ${(l(this,rt)[5]-e)/i} L${n} ${r} L${o} ${h} L${(l(this,rt)[16]-t)/s} ${(l(this,rt)[17]-e)/i} L${(l(this,rt)[14]-t)/s} ${(l(this,rt)[15]-e)/i} Z`},Zv=function(t){const e=l(this,Ks);t.push(`L${e[4]} ${e[5]} Z`)},ty=function(t){const[e,s,i,n]=l(this,ds),r=l(this,rt).subarray(4,6),o=l(this,rt).subarray(16,18),[h,c,u,d]=w(this,Jt,Ic).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}`)},ey=function(t){const e=l(this,rt),[s,i,n,r]=l(this,ds),[o,h,c,u]=w(this,Jt,Ic).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,ds),l(this,qa),l(this,Ya),l(this,$a))},sy=function(t,e){const s=l(this,Ks);return t.set([NaN,NaN,NaN,NaN,s[4],s[5]],e),e+=6},iy=function(t,e){const s=l(this,rt).subarray(4,6),i=l(this,rt).subarray(16,18),[n,r,o,h]=l(this,ds),[c,u,d,f]=w(this,Jt,Ic).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},_(mn,cc,8),_(mn,Sd,2),_(mn,Cd,l(mn,cc)+l(mn,Sd));let rd=mn;class Yb extends V{constructor(e,s,i,n,r,o){super();_(this,Ad);_(this,Qa);_(this,Eo,new Float32Array(4));_(this,bn);_(this,uc);_(this,fs);_(this,dc);_(this,zt);m(this,zt,e),m(this,fs,s),m(this,Qa,i),m(this,dc,n),m(this,bn,r),m(this,uc,o),this.lastPoint=[NaN,NaN],w(this,Ad,ny).call(this,o);const[h,c,u,d]=l(this,Eo);for(let f=0,g=e.length;f<g;f+=2)e[f]=(e[f]-h)/u,e[f+1]=(e[f+1]-c)/d;for(let f=0,g=s.length;f<g;f+=2)s[f]=(s[f]-h)/u,s[f+1]=(s[f+1]-c)/d}toSVGPath(){const e=[`M${l(this,zt)[4]} ${l(this,zt)[5]}`];for(let s=6,i=l(this,zt).length;s<i;s+=6){if(isNaN(l(this,zt)[s])){e.push(`L${l(this,zt)[s+4]} ${l(this,zt)[s+5]}`);continue}e.push(`C${l(this,zt)[s]} ${l(this,zt)[s+1]} ${l(this,zt)[s+2]} ${l(this,zt)[s+3]} ${l(this,zt)[s+4]} ${l(this,zt)[s+5]}`)}return e.push("Z"),e.join(" ")}serialize([e,s,i,n],r){const o=i-e,h=n-s;let c,u;switch(r){case 0:c=V._rescale(l(this,zt),e,n,o,-h),u=V._rescale(l(this,fs),e,n,o,-h);break;case 90:c=V._rescaleAndSwap(l(this,zt),e,s,o,h),u=V._rescaleAndSwap(l(this,fs),e,s,o,h);break;case 180:c=V._rescale(l(this,zt),i,s,-o,h),u=V._rescale(l(this,fs),i,s,-o,h);break;case 270:c=V._rescaleAndSwap(l(this,zt),i,n,-o,-h),u=V._rescaleAndSwap(l(this,fs),i,n,-o,-h);break}return{outline:Array.from(c),points:[Array.from(u)]}}get box(){return l(this,Eo)}newOutliner(e,s,i,n,r,o=0){return new rd(e,s,i,n,r,o)}getNewOutline(e,s){const[i,n,r,o]=l(this,Eo),[h,c,u,d]=l(this,Qa),f=r*u,g=o*d,p=i*u+h,b=n*d+c,y=this.newOutliner({x:l(this,fs)[0]*f+p,y:l(this,fs)[1]*g+b},l(this,Qa),l(this,dc),e,l(this,uc),s??l(this,bn));for(let v=2;v<l(this,fs).length;v+=2)y.add({x:l(this,fs)[v]*f+p,y:l(this,fs)[v+1]*g+b});return y.getOutlines()}}Qa=new WeakMap,Eo=new WeakMap,bn=new WeakMap,uc=new WeakMap,fs=new WeakMap,dc=new WeakMap,zt=new WeakMap,Ad=new WeakSet,ny=function(e){const s=l(this,zt);let i=s[4],n=s[5],r=i,o=n,h=i,c=n,u=i,d=n;const f=e?Math.max:Math.min;for(let p=6,b=s.length;p<b;p+=6){if(isNaN(s[p]))r=Math.min(r,s[p+4]),o=Math.min(o,s[p+5]),h=Math.max(h,s[p+4]),c=Math.max(c,s[p+5]),d<s[p+5]?(u=s[p+4],d=s[p+5]):d===s[p+5]&&(u=f(u,s[p+4]));else{const y=U.bezierBoundingBox(i,n,...s.slice(p,p+6));r=Math.min(r,y[0]),o=Math.min(o,y[1]),h=Math.max(h,y[2]),c=Math.max(c,y[3]),d<y[3]?(u=y[2],d=y[3]):d===y[3]&&(u=f(u,y[2]))}i=s[p+4],n=s[p+5]}const g=l(this,Eo);g[0]=r-l(this,bn),g[1]=o-l(this,bn),g[2]=h-r+2*l(this,bn),g[3]=c-o+2*l(this,bn),this.lastPoint=[u,d]};class Ig{constructor(t,e=0,s=0,i=!0){_(this,Ie);_(this,fc);_(this,gc);_(this,ir,[]);_(this,Qs,[]);let n=1/0,r=-1/0,o=1/0,h=-1/0;const c=10**-4;for(const{x:y,y:v,width:x,height:C}of t){const S=Math.floor((y-e)/c)*c,A=Math.ceil((y+x+e)/c)*c,k=Math.floor((v-e)/c)*c,P=Math.ceil((v+C+e)/c)*c,O=[S,k,P,!0],R=[A,k,P,!1];l(this,ir).push(O,R),n=Math.min(n,S),r=Math.max(r,A),o=Math.min(o,k),h=Math.max(h,P)}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 y of l(this,ir)){const[v,x,C]=y;y[0]=(v-f)/u,y[1]=(x-g)/d,y[2]=(C-g)/d}m(this,fc,new Float32Array([f,g,u,d])),m(this,gc,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,Pp).call(this,e)),w(this,Ie,oy).call(this,e)):(w(this,Ie,ay).call(this,e),t.push(...w(this,Ie,Pp).call(this,e)));return w(this,Ie,ry).call(this,t)}}fc=new WeakMap,gc=new WeakMap,ir=new WeakMap,Qs=new WeakMap,Ie=new WeakSet,ry=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 oC(i,l(this,fc),l(this,gc))},qd=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},oy=function([,t,e]){const s=w(this,Ie,qd).call(this,t);l(this,Qs).splice(s,0,[t,e])},ay=function([,t,e]){const s=w(this,Ie,qd).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}}},Pp=function(t){const[e,s,i]=t,n=[[e,s,i]],r=w(this,Ie,qd).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 oC extends V{constructor(e,s,i){super();_(this,pc);_(this,Ja);m(this,Ja,e),m(this,pc,s),this.lastPoint=i}toSVGPath(){const e=[];for(const s of l(this,Ja)){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,Ja)){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,pc)}get classNamesForOutlining(){return["highlightOutline"]}}pc=new WeakMap,Ja=new WeakMap;class Ng extends rd{newFreeDrawOutline(t,e,s,i,n,r){return new aC(t,e,s,i,n,r)}}class aC extends Yb{newOutliner(t,e,s,i,n,r=0){return new Ng(t,e,s,i,n,r)}}const Qe=class Qe{constructor({editor:t=null,uiManager:e=null}){_(this,vt);_(this,Js,null);_(this,ko,null);_(this,Za);_(this,Zt,null);_(this,mc,!1);_(this,th,!1);_(this,bc,null);_(this,vc);_(this,nr,null);_(this,Zs,null);_(this,eh);var s;t?(m(this,th,!1),m(this,eh,at.HIGHLIGHT_COLOR),m(this,bc,t)):(m(this,th,!0),m(this,eh,at.HIGHLIGHT_DEFAULT_COLOR)),m(this,Zs,(t==null?void 0:t._uiManager)||e),m(this,vc,l(this,Zs)._eventBus),m(this,Za,(t==null?void 0:t.color)||((s=l(this,Zs))==null?void 0:s.highlightColors.values().next().value)||"#FFFF98"),l(Qe,yc)||m(Qe,yc,Object.freeze({blue:"pdfjs-editor-colorpicker-blue",green:"pdfjs-editor-colorpicker-green",pink:"pdfjs-editor-colorpicker-pink",red:"pdfjs-editor-colorpicker-red",yellow:"pdfjs-editor-colorpicker-yellow"}))}static get _keyboardManager(){return nt(this,"_keyboardManager",new $h([[["Escape","mac+Escape"],Qe.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],Qe.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],Qe.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],Qe.prototype._moveToPrevious],[["Home","mac+Home"],Qe.prototype._moveToBeginning],[["End","mac+End"],Qe.prototype._moveToEnd]]))}renderButton(){const t=m(this,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,vt,Vo).bind(this),{signal:e}),t.addEventListener("keydown",w(this,vt,Rp).bind(this),{signal:e});const s=m(this,ko,document.createElement("span"));return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=l(this,Za),t.append(s),t}renderMainDropdown(){const t=m(this,Zt,w(this,vt,Op).call(this));return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}_colorSelectFromKeyboard(t){if(t.target===l(this,Js)){w(this,vt,Vo).call(this,t);return}const e=t.target.getAttribute("data-color");e&&w(this,vt,Dp).call(this,e,t)}_moveToNext(t){var e,s;if(!l(this,vt,gr)){w(this,vt,Vo).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,vt,gr)&&this._hideDropdownFromKeyboard();return}l(this,vt,gr)||w(this,vt,Vo).call(this,t),(s=t.target.previousSibling)==null||s.focus()}_moveToBeginning(t){var e;if(!l(this,vt,gr)){w(this,vt,Vo).call(this,t);return}(e=l(this,Zt).firstChild)==null||e.focus()}_moveToEnd(t){var e;if(!l(this,vt,gr)){w(this,vt,Vo).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,th)){if(!l(this,vt,gr)){(t=l(this,bc))==null||t.unselect();return}this.hideDropdown(),l(this,Js).focus({preventScroll:!0,focusVisible:l(this,mc)})}}updateColor(t){if(l(this,ko)&&(l(this,ko).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,ko,null),(e=l(this,Zt))==null||e.remove(),m(this,Zt,null)}};Js=new WeakMap,ko=new WeakMap,Za=new WeakMap,Zt=new WeakMap,mc=new WeakMap,th=new WeakMap,bc=new WeakMap,vc=new WeakMap,nr=new WeakMap,Zs=new WeakMap,eh=new WeakMap,yc=new WeakMap,vt=new WeakSet,Op=function(){const t=document.createElement("div"),e=l(this,Zs)._signal;t.addEventListener("contextmenu",zs,{signal:e}),t.className="dropdown",t.role="listbox",t.setAttribute("aria-multiselectable",!1),t.setAttribute("aria-orientation","vertical"),t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown");for(const[s,i]of l(this,Zs).highlightColors){const n=document.createElement("button");n.tabIndex="0",n.role="option",n.setAttribute("data-color",i),n.title=s,n.setAttribute("data-l10n-id",l(Qe,yc)[s]);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===l(this,Za)),n.addEventListener("click",w(this,vt,Dp).bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",w(this,vt,Rp).bind(this),{signal:e}),t},Dp=function(t,e){e.stopPropagation(),l(this,vc).dispatch("switchannotationeditorparams",{source:this,type:l(this,eh),value:t})},Rp=function(t){Qe._keyboardManager.exec(this,t)},Vo=function(t){if(l(this,vt,gr)){this.hideDropdown();return}if(m(this,mc,t.detail===0),l(this,nr)||(m(this,nr,new AbortController),window.addEventListener("pointerdown",w(this,vt,hy).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,vt,Op).call(this));l(this,Js).append(e)},hy=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")},_(Qe,yc,null);let od=Qe;const ut=class ut extends Ot{constructor(e){super({...e,name:"highlightEditor"});_(this,tt);_(this,sh,null);_(this,_c,0);_(this,vn);_(this,Mo,null);_(this,ih,null);_(this,Je,null);_(this,wc,null);_(this,xc,0);_(this,Po,null);_(this,Es,null);_(this,gs,null);_(this,le,!1);_(this,nh,null);_(this,yn);_(this,Se,null);_(this,rh,"");_(this,ks);_(this,Sc,"");this.color=e.color||ut._defaultColor,m(this,ks,e.thickness||ut._defaultThickness),m(this,yn,e.opacity||ut._defaultOpacity),m(this,vn,e.boxes||null),m(this,Sc,e.methodOfCreation||""),m(this,rh,e.text||""),this._isDraggable=!1,e.highlightId>-1?(m(this,le,!0),w(this,tt,Kd).call(this,e),w(this,tt,Xo).call(this)):l(this,vn)&&(m(this,sh,e.anchorNode),m(this,_c,e.anchorOffset),m(this,wc,e.focusNode),m(this,xc,e.focusOffset),w(this,tt,Lp).call(this),w(this,tt,Xo).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const e=ut.prototype;return nt(this,"_keyboardManager",new $h([[["ArrowLeft","mac+ArrowLeft"],e._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],e._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],e._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],e._moveCaret,{args:[3]}]]))}get telemetryInitialData(){return{action:"added",type:l(this,le)?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:l(this,ks),methodOfCreation:l(this,Sc)}}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;Ot.initialize(e,s),ut._defaultColor||(ut._defaultColor=((i=s.highlightColors)==null?void 0:i.values().next().value)||"#fff066")}static updateDefaultParams(e,s){switch(e){case at.HIGHLIGHT_DEFAULT_COLOR:ut._defaultColor=s;break;case at.HIGHLIGHT_THICKNESS:ut._defaultThickness=s;break}}translateInPage(e,s){}get toolbarPosition(){return l(this,nh)}updateParams(e,s){switch(e){case at.HIGHLIGHT_COLOR:w(this,tt,ly).call(this,s);break;case at.HIGHLIGHT_THICKNESS:w(this,tt,cy).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[at.HIGHLIGHT_DEFAULT_COLOR,ut._defaultColor],[at.HIGHLIGHT_THICKNESS,ut._defaultThickness]]}get propertiesToUpdate(){return[[at.HIGHLIGHT_COLOR,this.color||ut._defaultColor],[at.HIGHLIGHT_THICKNESS,l(this,ks)||ut._defaultThickness],[at.HIGHLIGHT_FREE,l(this,le)]]}async addEditToolbar(){const e=await super.addEditToolbar();return e?(this._uiManager.highlightColors&&(m(this,ih,new od({editor:this})),e.addColorPicker(l(this,ih))),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,tt,Nc).call(this))}getBaseTranslation(){return[0,0]}getRect(e,s){return super.getRect(e,s,w(this,tt,Nc).call(this))}onceAdded(e){this.annotationElementId||this.parent.addUndoableEditor(this),e&&this.div.focus()}remove(){w(this,tt,Fp).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,tt,Xo).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?w(this,tt,Fp).call(this):e&&(w(this,tt,Xo).call(this,e),s=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),this.show(this._isVisible),s&&this.select()}rotate(e){var n,r,o;const{drawLayer:s}=this.parent;let i;l(this,le)?(e=(e-this.rotation+360)%360,i=w(n=ut,Ms,Sh).call(n,l(this,Es).box,e)):i=w(r=ut,Ms,Sh).call(r,[this.x,this.y,this.width,this.height],e),s.updateProperties(l(this,gs),{bbox:i,root:{"data-main-rotation":e}}),s.updateProperties(l(this,Se),{bbox:w(o=ut,Ms,Sh).call(o,l(this,Je).box,e),root:{"data-main-rotation":e}})}render(){if(this.div)return this.div;const e=super.render();l(this,rh)&&(e.setAttribute("aria-label",l(this,rh)),e.setAttribute("role","mark")),l(this,le)?e.classList.add("free"):this.div.addEventListener("keydown",w(this,tt,dy).bind(this),{signal:this._uiManager._signal});const s=m(this,Po,document.createElement("div"));e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",s.style.clipPath=l(this,Mo);const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),Ku(this,l(this,Po),["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,tt,Qd).call(this,!0);break;case 1:case 3:w(this,tt,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,tt,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,gs),{rootClass:{hidden:!e}}),this.parent.drawLayer.updateProperties(l(this,Se),{rootClass:{hidden:!e}}))}static startHighlighting(e,s,{target:i,x:n,y:r}){const{x:o,y:h,width:c,height:u}=i.getBoundingClientRect(),d=new AbortController,f=e.combinedSignal(d),g=p=>{d.abort(),w(this,Ms,my).call(this,e,p)};window.addEventListener("blur",g,{signal:f}),window.addEventListener("pointerup",g,{signal:f}),window.addEventListener("pointerdown",is,{capture:!0,passive:!1,signal:f}),window.addEventListener("contextmenu",zs,{signal:f}),i.addEventListener("pointermove",w(this,Ms,py).bind(this,e),{signal:f}),this._freeHighlight=new Ng({x:n,y:r},[o,h,c,u],e.scale,this._defaultThickness/2,s,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0)}static async deserialize(e,s,i){var b,y,v,x;let n=null;if(e instanceof Wb){const{data:{quadPoints:C,rect:S,rotation:A,id:k,color:P,opacity:O,popupRef:R},parent:{page:{pageNumber:F}}}=e;n=e={annotationType:et.HIGHLIGHT,color:Array.from(P),opacity:O,quadPoints:C,boxes:null,pageIndex:F-1,rect:S.slice(0),rotation:A,id:k,deleted:!1,popupRef:R}}else if(e instanceof Lg){const{data:{inkLists:C,rect:S,rotation:A,id:k,color:P,borderStyle:{rawWidth:O},popupRef:R},parent:{page:{pageNumber:F}}}=e;n=e={annotationType:et.HIGHLIGHT,color:Array.from(P),thickness:O,inkLists:C,boxes:null,pageIndex:F-1,rect:S.slice(0),rotation:A,id:k,deleted:!1,popupRef:R}}const{color:r,quadPoints:o,inkLists:h,opacity:c}=e,u=await super.deserialize(e,s,i);u.color=U.makeHexColor(...r),m(u,yn,c||1),h&&m(u,ks,e.thickness),u.annotationElementId=e.id||null,u._initialData=n;const[d,f]=u.pageDimensions,[g,p]=u.pageTranslation;if(o){const C=m(u,vn,[]);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,tt,Lp).call(b),w(y=u,tt,Xo).call(y),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)},A=new Ng(S,[0,0,d,f],1,l(u,ks)/2,!0,.001);for(let O=0,R=C.length;O<R;O+=2)S.x=C[O]-g,S.y=f-(C[O+1]-p),A.add(S);const{id:k,clipPathId:P}=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:A.toSVGPath()}},!0,!0);w(v=u,tt,Kd).call(v,{highlightOutlines:A.getOutlines(),highlightId:k,clipPathId:P}),w(x=u,tt,Xo).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=Ot._colorManager.convert(this.color),n={annotationType:et.HIGHLIGHT,color:i,opacity:l(this,yn),thickness:l(this,ks),quadPoints:w(this,tt,fy).call(this),outlines:w(this,tt,gy).call(this,s),pageIndex:this.pageIndex,rect:s,rotation:w(this,tt,Nc).call(this),structTreeParentId:this._structTreeParentId};return this.annotationElementId&&!w(this,tt,by).call(this,n)?null:(n.id=this.annotationElementId,n)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};sh=new WeakMap,_c=new WeakMap,vn=new WeakMap,Mo=new WeakMap,ih=new WeakMap,Je=new WeakMap,wc=new WeakMap,xc=new WeakMap,Po=new WeakMap,Es=new WeakMap,gs=new WeakMap,le=new WeakMap,nh=new WeakMap,yn=new WeakMap,Se=new WeakMap,rh=new WeakMap,ks=new WeakMap,Sc=new WeakMap,tt=new WeakSet,Lp=function(){const e=new Ig(l(this,vn),.001);m(this,Es,e.getOutlines()),[this.x,this.y,this.width,this.height]=l(this,Es).box;const s=new Ig(l(this,vn),.0025,.001,this._uiManager.direction==="ltr");m(this,Je,s.getOutlines());const{lastPoint:i}=l(this,Je);m(this,nh,[(i[0]-this.x)/this.width,(i[1]-this.y)/this.height])},Kd=function({highlightOutlines:e,highlightId:s,clipPathId:i}){var d,f;if(m(this,Es,e),m(this,Je,e.getNewOutline(l(this,ks)/2+1.5,.0025)),s>=0)m(this,gs,s),m(this,Mo,i),this.parent.drawLayer.finalizeDraw(s,{bbox:e.box,path:{d:e.toSVGPath()}}),m(this,Se,this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:l(this,Je).box,path:{d:l(this,Je).toSVGPath()}},!0));else if(this.parent){const g=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(l(this,gs),{bbox:w(d=ut,Ms,Sh).call(d,l(this,Es).box,(g-this.rotation+360)%360),path:{d:e.toSVGPath()}}),this.parent.drawLayer.updateProperties(l(this,Se),{bbox:w(f=ut,Ms,Sh).call(f,l(this,Je).box,g),path:{d:l(this,Je).toSVGPath()}})}const[r,o,h,c]=e.box;switch(this.rotation){case 0:this.x=r,this.y=o,this.width=h,this.height=c;break;case 90:{const[g,p]=this.parentDimensions;this.x=o,this.y=1-r,this.width=h*p/g,this.height=c*g/p;break}case 180:this.x=1-r,this.y=1-o,this.width=h,this.height=c;break;case 270:{const[g,p]=this.parentDimensions;this.x=1-o,this.y=r,this.width=h*p/g,this.height=c*g/p;break}}const{lastPoint:u}=l(this,Je);m(this,nh,[(u[0]-r)/h,(u[1]-o)/c])},ly=function(e){const s=(r,o)=>{var h,c;this.color=r,m(this,yn,o),(h=this.parent)==null||h.drawLayer.updateProperties(l(this,gs),{root:{fill:r,"fill-opacity":o}}),(c=l(this,ih))==null||c.updateColor(r)},i=this.color,n=l(this,yn);this.addCommands({cmd:s.bind(this,e,ut._defaultOpacity),undo:s.bind(this,i,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:at.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(e)},!0)},cy=function(e){const s=l(this,ks),i=n=>{m(this,ks,n),w(this,tt,uy).call(this,n)};this.addCommands({cmd:i.bind(this,e),undo:i.bind(this,s),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:at.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)},uy=function(e){if(!l(this,le))return;w(this,tt,Kd).call(this,{highlightOutlines:l(this,Es).getNewOutline(e/2)}),this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)},Fp=function(){l(this,gs)===null||!this.parent||(this.parent.drawLayer.remove(l(this,gs)),m(this,gs,null),this.parent.drawLayer.remove(l(this,Se)),m(this,Se,null))},Xo=function(e=this.parent){l(this,gs)===null&&({id:ze(this,gs)._,clipPathId:ze(this,Mo)._}=e.drawLayer.draw({bbox:l(this,Es).box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":l(this,yn)},rootClass:{highlight:!0,free:l(this,le)},path:{d:l(this,Es).toSVGPath()}},!1,!0),m(this,Se,e.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:l(this,le)},bbox:l(this,Je).box,path:{d:l(this,Je).toSVGPath()}},l(this,le))),l(this,Po)&&(l(this,Po).style.clipPath=l(this,Mo)))},Ms=new WeakSet,Sh=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]},dy=function(e){ut._keyboardManager.exec(this,e)},Qd=function(e){if(!l(this,sh))return;const s=window.getSelection();e?s.setPosition(l(this,sh),l(this,_c)):s.setPosition(l(this,wc),l(this,xc))},Nc=function(){return l(this,le)?this.rotation:0},fy=function(){if(l(this,le))return null;const[e,s]=this.pageDimensions,[i,n]=this.pageTranslation,r=l(this,vn),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},gy=function(e){return l(this,Es).serialize(e,w(this,tt,Nc).call(this))},py=function(e,s){this._freeHighlight.add(s)&&e.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})},my=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=""},by=function(e){const{color:s}=this._initialData;return e.color.some((i,n)=>i!==s[n])},_(ut,Ms),q(ut,"_defaultColor",null),q(ut,"_defaultOpacity",1),q(ut,"_defaultThickness",12),q(ut,"_type","highlight"),q(ut,"_editorType",et.HIGHLIGHT),q(ut,"_freeHighlightId",-1),q(ut,"_freeHighlight",null),q(ut,"_freeHighlightClipId","");let ad=ut;class hC{constructor(){_(this,Oo,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,Oo)[t]=e}toSVGProperties(){const t=l(this,Oo);return m(this,Oo,Object.create(null)),{root:t}}reset(){m(this,Oo,Object.create(null))}updateAll(t=this){this.updateProperties(t)}clone(){_t("Not implemented")}}Oo=new WeakMap;const X=class X extends Ot{constructor(e){super(e);_(this,lt);_(this,ps,null);_(this,oh);q(this,"_drawId",null);m(this,oh,e.mustBeCommitted||!1),e.drawOutlines&&(w(this,lt,Ip).call(this,e),w(this,lt,jc).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){_t("Not implemented")}static get typesMap(){_t("Not implemented")}static get isDrawer(){return!0}static get supportMultipleDrawings(){return!1}static updateDefaultParams(e,s){const i=this.typesMap.get(e);i&&this._defaultDrawingOptions.updateProperty(i,s),this._currentParent&&(l(X,ne).updateProperty(i,s),this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties()))}updateParams(e,s){const i=this.constructor.typesMap.get(e);i&&this._updateProperty(e,i,s)}static get defaultPropertiesToUpdate(){const e=[],s=this._defaultDrawingOptions;for(const[i,n]of this.typesMap)e.push([i,s[n]]);return e}get propertiesToUpdate(){const e=[],{_drawingOptions:s}=this;for(const[i,n]of this.constructor.typesMap)e.push([i,s[n]]);return e}_updateProperty(e,s,i){const n=this._drawingOptions,r=n[s],o=h=>{var u;n.updateProperty(s,h);const c=l(this,ps).updateProperty(s,h);c&&w(this,lt,Bc).call(this,c),(u=this.parent)==null||u.drawLayer.updateProperties(this._drawId,n.toSVGProperties())};this.addCommands({cmd:o.bind(this,i),undo:o.bind(this,r),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:e,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,X._mergeSVGProperties(l(this,ps).getPathResizingSVGProperties(w(this,lt,Jd).call(this)),{bbox:w(this,lt,Ch).call(this)}))}_onResized(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,X._mergeSVGProperties(l(this,ps).getPathResizedSVGProperties(w(this,lt,Jd).call(this)),{bbox:w(this,lt,Ch).call(this)}))}_onTranslating(e,s){var i;(i=this.parent)==null||i.drawLayer.updateProperties(this._drawId,{bbox:w(this,lt,Ch).call(this,e,s)})}_onTranslated(){var e;(e=this.parent)==null||e.drawLayer.updateProperties(this._drawId,X._mergeSVGProperties(l(this,ps).getPathTranslatedSVGProperties(w(this,lt,Jd).call(this),this.parentDimensions),{bbox:w(this,lt,Ch).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,oh)&&(m(this,oh,!1),this.commit(),this.parent.setSelected(this),e&&this.isOnScreen&&this.div.focus())}remove(){w(this,lt,jp).call(this),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(w(this,lt,jc).call(this),w(this,lt,Bc).call(this,l(this,ps).box),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?(this._uiManager.removeShouldRescale(this),w(this,lt,jp).call(this)):e&&(this._uiManager.addShouldRescale(this),w(this,lt,jc).call(this,e),s=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),s&&this.select()}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,X._mergeSVGProperties({bbox:w(this,lt,Ch).call(this)},l(this,ps).updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&w(this,lt,Bc).call(this,l(this,ps).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){_t("Not implemented")}static startDrawing(e,s,i,n){var y;const{target:r,offsetX:o,offsetY:h,pointerId:c,pointerType:u}=n;if(l(X,or)&&l(X,or)!==u)return;const{viewport:{rotation:d}}=e,{width:f,height:g}=r.getBoundingClientRect(),p=m(X,Do,new AbortController),b=e.combinedSignal(p);if(l(X,rr)||m(X,rr,c),l(X,or)??m(X,or,u),window.addEventListener("pointerup",v=>{var x;l(X,rr)===v.pointerId?this._endDraw(v):(x=l(X,ar))==null||x.delete(v.pointerId)},{signal:b}),window.addEventListener("pointercancel",v=>{var x;l(X,rr)===v.pointerId?this._currentParent.endDrawingSession():(x=l(X,ar))==null||x.delete(v.pointerId)},{signal:b}),window.addEventListener("pointerdown",v=>{l(X,or)===v.pointerType&&((l(X,ar)||m(X,ar,new Set)).add(v.pointerId),l(X,ne).isCancellable()&&(l(X,ne).removeLastElement(),l(X,ne).isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:b}),window.addEventListener("contextmenu",zs,{signal:b}),r.addEventListener("pointermove",this._drawMove.bind(this),{signal:b}),r.addEventListener("touchmove",v=>{v.timeStamp===l(X,Lo)&&is(v)},{signal:b}),e.toggleDrawing(),(y=s._editorUndoBar)==null||y.hide(),l(X,ne)){e.drawLayer.updateProperties(this._currentDrawId,l(X,ne).startNew(o,h,f,g,d));return}s.updateUIForDefaultProperties(this),m(X,ne,this.createDrawerInstance(o,h,f,g,d)),m(X,Ro,this.getDefaultDrawingOptions()),this._currentParent=e,{id:this._currentDrawId}=e.drawLayer.draw(this._mergeSVGProperties(l(X,Ro).toSVGProperties(),l(X,ne).defaultSVGProperties),!0,!1)}static _drawMove(e){var r;if(m(X,Lo,-1),!l(X,ne))return;const{offsetX:s,offsetY:i,pointerId:n}=e;if(l(X,rr)===n){if(((r=l(X,ar))==null?void 0:r.size)>=1){this._endDraw(e);return}this._currentParent.drawLayer.updateProperties(this._currentDrawId,l(X,ne).add(s,i)),m(X,Lo,e.timeStamp),is(e)}}static _cleanup(e){e&&(this._currentDrawId=-1,this._currentParent=null,m(X,ne,null),m(X,Ro,null),m(X,or,null),m(X,Lo,NaN)),l(X,Do)&&(l(X,Do).abort(),m(X,Do,null),m(X,rr,NaN),m(X,ar,null))}static _endDraw(e){const s=this._currentParent;if(s){if(s.toggleDrawing(!0),this._cleanup(!1),e&&s.drawLayer.updateProperties(this._currentDrawId,l(X,ne).end(e.offsetX,e.offsetY)),this.supportMultipleDrawings){const i=l(X,ne),n=this._currentDrawId,r=i.getLastElement();s.addCommands({cmd:()=>{s.drawLayer.updateProperties(n,i.setLastElement(r))},undo:()=>{s.drawLayer.updateProperties(n,i.removeLastElement())},mustExec:!1,type:at.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(e){const s=this._currentParent;if(!s)return null;if(s.toggleDrawing(!0),s.cleanUndoStack(at.DRAW_STEP),!l(X,ne).isEmpty()){const{pageDimensions:[i,n],scale:r}=s,o=s.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:l(X,ne).getOutlines(i*r,n*r,r,this._INNER_MARGIN),drawingOptions:l(X,Ro),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){_t("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,Ip).call(d,{drawOutlines:c}),w(f=u,lt,jc).call(f),u.onScaleChanging(),u.rotate(),u}serializeDraw(e){const[s,i]=this.pageTranslation,[n,r]=this.pageDimensions;return l(this,ps).serialize([s,i,n,r],e)}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}static canCreateNewEmptyEditor(){return!1}};ps=new WeakMap,oh=new WeakMap,ne=new WeakMap,Do=new WeakMap,Ro=new WeakMap,rr=new WeakMap,or=new WeakMap,ar=new WeakMap,Lo=new WeakMap,lt=new WeakSet,Ip=function({drawOutlines:e,drawId:s,drawingOptions:i}){m(this,ps,e),this._drawingOptions||(this._drawingOptions=i),s>=0?(this._drawId=s,this.parent.drawLayer.finalizeDraw(s,e.defaultProperties)):this._drawId=w(this,lt,Np).call(this,e,this.parent),w(this,lt,Bc).call(this,e.box)},Np=function(e,s){const{id:i}=s.drawLayer.draw(X._mergeSVGProperties(this._drawingOptions.toSVGProperties(),e.defaultSVGProperties),!1,!1);return i},jp=function(){this._drawId===null||!this.parent||(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())},jc=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,Np).call(this,l(this,ps),e)}},vy=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]}},Jd=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]}},Bc=function(e){if([this.x,this.y,this.width,this.height]=w(this,lt,vy).call(this,e),this.div){this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)}this._onResized()},Ch=function(){const{x:e,y:s,width:i,height:n,rotation:r,parentRotation:o,parentDimensions:[h,c]}=this;switch((r*4+o)/90){case 1:return[1-s-n,e,n,i];case 2:return[1-e-i,1-s-n,i,n];case 3:return[s,1-e-i,n,i];case 4:return[e,s-i*(h/c),n*(c/h),i*(h/c)];case 5:return[1-s,e,i*(h/c),n*(c/h)];case 6:return[1-e-n*(c/h),1-s,n*(c/h),i*(h/c)];case 7:return[s-i*(h/c),1-e-n*(c/h),i*(h/c),n*(c/h)];case 8:return[e-i,s-n,i,n];case 9:return[1-s,e-i,n,i];case 10:return[1-e,1-s,i,n];case 11:return[s-n,1-e,n,i];case 12:return[e-n*(c/h),s,n*(c/h),i*(h/c)];case 13:return[1-s-i*(h/c),e-n*(c/h),i*(h/c),n*(c/h)];case 14:return[1-e,1-s-i*(h/c),n*(c/h),i*(h/c)];case 15:return[s,1-e,i*(h/c),n*(c/h)];default:return[e,s,i,n]}},q(X,"_currentDrawId",-1),q(X,"_currentParent",null),_(X,ne,null),_(X,Do,null),_(X,Ro,null),_(X,rr,NaN),_(X,or,null),_(X,ar,null),_(X,Lo,NaN),q(X,"_INNER_MARGIN",3);let jg=X;class lC{constructor(t,e,s,i,n,r){_(this,hh);_(this,Ci,new Float64Array(6));_(this,re);_(this,oe);_(this,Fo);_(this,ah);_(this,Ne);_(this,ce,"");_(this,Ps,0);_(this,Io,new hd);_(this,No);_(this,jo);m(this,No,s),m(this,jo,i),m(this,Fo,n),m(this,ah,r),[t,e]=w(this,hh,Zd).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,Ci).set(o,0)}updateProperty(t,e){t==="stroke-width"&&m(this,ah,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,hh,Zd).call(this,t,e);const[s,i,n,r]=l(this,Ci).subarray(2,6),o=t-n,h=e-r;return Math.hypot(l(this,No)*o,l(this,jo)*h)<=2?null:(l(this,Ne).push(t,e),isNaN(s)?(l(this,Ci).set([n,r,t,e],2),l(this,re).push(NaN,NaN,NaN,NaN,t,e),{path:{d:this.toSVGPath()}}):(isNaN(l(this,Ci)[0])&&l(this,re).splice(6,6),l(this,Ci).set([s,i,n,r,t,e],0),l(this,re).push(...V.createBezierPoints(s,i,n,r,t,e)),{path:{d:this.toSVGPath()}}))}end(t,e){const s=this.add(t,e);return s||(l(this,Ne).length===2?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,s,i,n){m(this,No,s),m(this,jo,i),m(this,Fo,n),[t,e]=w(this,hh,Zd).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,Ci).set(r,0),m(this,Ps,0),this.toSVGPath(),null}getLastElement(){return l(this,oe).at(-1)}setLastElement(t){return l(this,oe)?(l(this,oe).push(t),m(this,re,t.line),m(this,Ne,t.points),m(this,Ps,0),{path:{d:this.toSVGPath()}}):l(this,Io).setLastElement(t)}removeLastElement(){if(!l(this,oe))return l(this,Io).removeLastElement();l(this,oe).pop(),m(this,ce,"");for(let t=0,e=l(this,oe).length;t<e;t++){const{line:s,points:i}=l(this,oe)[t];m(this,re,s),m(this,Ne,i),m(this,Ps,0),this.toSVGPath()}return{path:{d:l(this,ce)}}}toSVGPath(){const t=V.svgRound(l(this,re)[4]),e=V.svgRound(l(this,re)[5]);if(l(this,Ne).length===2)return m(this,ce,`${l(this,ce)} M ${t} ${e} Z`),l(this,ce);if(l(this,Ne).length<=6){const i=l(this,ce).lastIndexOf("M");m(this,ce,`${l(this,ce).slice(0,i)} M ${t} ${e}`),m(this,Ps,6)}if(l(this,Ne).length===4){const i=V.svgRound(l(this,re)[10]),n=V.svgRound(l(this,re)[11]);return m(this,ce,`${l(this,ce)} L ${i} ${n}`),m(this,Ps,12),l(this,ce)}const s=[];l(this,Ps)===0&&(s.push(`M ${t} ${e}`),m(this,Ps,6));for(let i=l(this,Ps),n=l(this,re).length;i<n;i+=6){const[r,o,h,c,u,d]=l(this,re).slice(i,i+6).map(V.svgRound);s.push(`C${r} ${o} ${h} ${c} ${u} ${d}`)}return m(this,ce,l(this,ce)+s.join(" ")),m(this,Ps,l(this,re).length),l(this,ce)}getOutlines(t,e,s,i){const n=l(this,oe).at(-1);return n.line=new Float32Array(n.line),n.points=new Float32Array(n.points),l(this,Io).build(l(this,oe),t,e,s,l(this,Fo),l(this,ah),i),m(this,Ci,null),m(this,re,null),m(this,oe,null),m(this,ce,null),l(this,Io)}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}Ci=new WeakMap,re=new WeakMap,oe=new WeakMap,Fo=new WeakMap,ah=new WeakMap,Ne=new WeakMap,ce=new WeakMap,Ps=new WeakMap,Io=new WeakMap,No=new WeakMap,jo=new WeakMap,hh=new WeakSet,Zd=function(t,e){return V._normalizePoint(t,e,l(this,No),l(this,jo),l(this,Fo))};const qg=class qg extends V{constructor(){super(...arguments);_(this,ue);_(this,je);_(this,Cc,0);_(this,Ac);_(this,ms);_(this,Ai);_(this,Ti);_(this,lh);_(this,ch);_(this,uh)}build(e,s,i,n,r,o,h){m(this,Ai,s),m(this,Ti,i),m(this,lh,n),m(this,ch,r),m(this,uh,o),m(this,Ac,h??0),m(this,ms,e),w(this,ue,_y).call(this)}setLastElement(e){return l(this,ms).push(e),{path:{d:this.toSVGPath()}}}removeLastElement(){return l(this,ms).pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const e=[];for(const{line:s}of l(this,ms)){if(e.push(`M${V.svgRound(s[4])} ${V.svgRound(s[5])}`),s.length===6){e.push("Z");continue}if(s.length===12){e.push(`L${V.svgRound(s[10])} ${V.svgRound(s[11])}`);continue}for(let i=6,n=s.length;i<n;i+=6){const[r,o,h,c,u,d]=s.subarray(i,i+6).map(V.svgRound);e.push(`C${r} ${o} ${h} ${c} ${u} ${d}`)}}return e.join("")}serialize([e,s,i,n],r){const o=[],h=[],[c,u,d,f]=w(this,ue,yy).call(this);let g,p,b,y,v,x,C,S,A;switch(l(this,ch)){case 0:A=V._rescale,g=e,p=s+n,b=i,y=-n,v=e+c*i,x=s+(1-u-f)*n,C=e+(c+d)*i,S=s+(1-u)*n;break;case 90:A=V._rescaleAndSwap,g=e,p=s,b=i,y=n,v=e+u*i,x=s+c*n,C=e+(u+f)*i,S=s+(c+d)*n;break;case 180:A=V._rescale,g=e+i,p=s,b=-i,y=n,v=e+(1-c-d)*i,x=s+u*n,C=e+(1-c)*i,S=s+(u+f)*n;break;case 270:A=V._rescaleAndSwap,g=e+i,p=s+n,b=-i,y=-n,v=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:k,points:P}of l(this,ms))o.push(A(k,g,p,b,y,r?new Array(k.length):null)),h.push(A(P,g,p,b,y,r?new Array(P.length):null));return{lines:o,points:h,rect:[v,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,y;switch(c){case 0:y=V._rescale,f=-e/i,g=s/n+1,p=1/i,b=-1/n;break;case 90:y=V._rescaleAndSwap,f=-s/n,g=-e/i,p=1/n,b=1/i;break;case 180:y=V._rescale,f=e/i+1,g=-s/n,p=-1/i,b=1/n;break;case 270:y=V._rescaleAndSwap,f=s/n+1,g=e/i+1,p=-1/n,b=-1/i;break}if(!o){o=[];for(const x of h){const 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[A,k,P,O]=x.subarray(0,4);S.set([NaN,NaN,NaN,NaN,A,k],0);for(let R=4;R<C;R+=2){const F=x[R],j=x[R+1];S.set(V.createBezierPoints(A,k,P,O,F,j),(R-2)*3),[A,k,P,O]=[P,O,F,j]}}}for(let x=0,C=o.length;x<C;x++)d.push({line:y(o[x].map(S=>S??NaN),f,g,p,b),points:y(h[x].map(S=>S??NaN),f,g,p,b)});const v=new qg;return v.build(d,i,n,1,c,u,r),v}get box(){return l(this,je)}updateProperty(e,s){return e==="stroke-width"?w(this,ue,wy).call(this,s):null}updateParentDimensions([e,s],i){const[n,r]=w(this,ue,An).call(this);m(this,Ai,e),m(this,Ti,s),m(this,lh,i);const[o,h]=w(this,ue,An).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,Cc,e),{path:{transform:this.rotationTransform}}}get viewBox(){return l(this,je).map(V.svgRound).join(" ")}get defaultProperties(){const[e,s]=l(this,je);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${V.svgRound(e)} ${V.svgRound(s)}`}}}get rotationTransform(){const[,,e,s]=l(this,je);let i=0,n=0,r=0,o=0,h=0,c=0;switch(l(this,Cc)){case 90:n=s/e,r=-e/s,h=e;break;case 180:i=-1,o=-1,h=e,c=s;break;case 270:n=-s/e,r=e/s,c=s;break;default:return""}return`matrix(${i} ${n} ${r} ${o} ${V.svgRound(h)} ${V.svgRound(c)})`}getPathResizingSVGProperties([e,s,i,n]){const[r,o]=w(this,ue,An).call(this),[h,c,u,d]=l(this,je);if(Math.abs(u-r)<=V.PRECISION||Math.abs(d-o)<=V.PRECISION){const y=e+i/2-(h+u/2),v=s+n/2-(c+d/2);return{path:{"transform-origin":`${V.svgRound(e)} ${V.svgRound(s)}`,transform:`${this.rotationTransform} translate(${y} ${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":`${V.svgRound(h)} ${V.svgRound(c)}`,transform:`${this.rotationTransform} scale(${p} ${b}) translate(${V.svgRound(r)} ${V.svgRound(o)}) scale(${f} ${g}) translate(${V.svgRound(-r)} ${V.svgRound(-o)})`}}}getPathResizedSVGProperties([e,s,i,n]){const[r,o]=w(this,ue,An).call(this),h=l(this,je),[c,u,d,f]=h;if(h[0]=e,h[1]=s,h[2]=i,h[3]=n,Math.abs(d-r)<=V.PRECISION||Math.abs(f-o)<=V.PRECISION){const v=e+i/2-(c+d/2),x=s+n/2-(u+f/2);for(const{line:C,points:S}of l(this,ms))V._translate(C,v,x,C),V._translate(S,v,x,S);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${V.svgRound(e)} ${V.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const g=(i-2*r)/(d-2*r),p=(n-2*o)/(f-2*o),b=-g*(c+r)+e+r,y=-p*(u+o)+s+o;if(g!==1||p!==1||b!==0||y!==0)for(const{line:v,points:x}of l(this,ms))V._rescale(v,b,y,g,p,v),V._rescale(x,b,y,g,p,x);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${V.svgRound(e)} ${V.svgRound(s)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([e,s],i){const[n,r]=i,o=l(this,je),h=e-o[0],c=s-o[1];if(l(this,Ai)===n&&l(this,Ti)===r)for(const{line:u,points:d}of l(this,ms))V._translate(u,h,c,u),V._translate(d,h,c,d);else{const u=l(this,Ai)/n,d=l(this,Ti)/r;m(this,Ai,n),m(this,Ti,r);for(const{line:f,points:g}of l(this,ms))V._rescale(f,h,c,u,d,f),V._rescale(g,h,c,u,d,g);o[2]*=u,o[3]*=d}return o[0]=e,o[1]=s,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${V.svgRound(e)} ${V.svgRound(s)}`}}}get defaultSVGProperties(){const e=l(this,je);return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${V.svgRound(e[0])} ${V.svgRound(e[1])}`,transform:this.rotationTransform||null},bbox:e}}};je=new WeakMap,Cc=new WeakMap,Ac=new WeakMap,ms=new WeakMap,Ai=new WeakMap,Ti=new WeakMap,lh=new WeakMap,ch=new WeakMap,uh=new WeakMap,ue=new WeakSet,An=function(e=l(this,uh)){const s=l(this,Ac)+e/2*l(this,lh);return l(this,ch)%180===0?[s/l(this,Ai),s/l(this,Ti)]:[s/l(this,Ti),s/l(this,Ai)]},yy=function(){const[e,s,i,n]=l(this,je),[r,o]=w(this,ue,An).call(this,0);return[e+r,s+o,i-2*r,n-2*o]},_y=function(){const e=m(this,je,new Float32Array([1/0,1/0,-1/0,-1/0]));for(const{line:n}of l(this,ms)){if(n.length<=12){for(let h=4,c=n.length;h<c;h+=6){const[u,d]=n.subarray(h,h+2);e[0]=Math.min(e[0],u),e[1]=Math.min(e[1],d),e[2]=Math.max(e[2],u),e[3]=Math.max(e[3],d)}continue}let r=n[4],o=n[5];for(let h=6,c=n.length;h<c;h+=6){const[u,d,f,g,p,b]=n.subarray(h,h+6);U.bezierBoundingBox(r,o,u,d,f,g,p,b,e),r=p,o=b}}const[s,i]=w(this,ue,An).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]},wy=function(e){const[s,i]=w(this,ue,An).call(this);m(this,uh,e);const[n,r]=w(this,ue,An).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 hd=qg;const Kg=class Kg extends hC{constructor(e){super();_(this,dh);m(this,dh,e),super.updateProperties({fill:"none",stroke:Ot._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,dh).realScale),super.updateSVGProperty(e,s)}clone(){const e=new Kg(l(this,dh));return e.updateAll(this),e}};dh=new WeakMap;let Bg=Kg;const fh=class fh extends jg{constructor(e){super({...e,name:"inkEditor"});_(this,Td);this._willKeepAspectRatio=!0}static initialize(e,s){Ot.initialize(e,s),this._defaultDrawingOptions=new Bg(s.viewParameters)}static getDefaultDrawingOptions(e){const s=this._defaultDrawingOptions.clone();return s.updateProperties(e),s}static get supportMultipleDrawings(){return!0}static get typesMap(){return nt(this,"typesMap",new Map([[at.INK_THICKNESS,"stroke-width"],[at.INK_COLOR,"stroke"],[at.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(e,s,i,n,r){return new lC(e,s,i,n,r,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(e,s,i,n,r,o){return hd.deserialize(e,s,i,n,r,o)}static async deserialize(e,s,i){let n=null;if(e instanceof Lg){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:et.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=fh.getDefaultDrawingOptions({stroke:U.makeHexColor(...e),"stroke-width":s,"stroke-opacity":i})}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:s,points:i,rect:n}=this.serializeDraw(e),{_drawingOptions:{stroke:r,"stroke-opacity":o,"stroke-width":h}}=this,c={annotationType:et.INK,color:Ot._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,Td,xy).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}};Td=new WeakSet,xy=function(e){const{color:s,thickness:i,opacity:n,pageIndex:r}=this._initialData;return this._hasBeenMoved||this._hasBeenResized||e.color.some((o,h)=>o!==s[h])||e.thickness!==i||e.opacity!==n||e.pageIndex!==r},q(fh,"_type","ink"),q(fh,"_editorType",et.INK),q(fh,"_defaultDrawingOptions",null);let Hg=fh;const Tc=class Tc extends Ot{constructor(e){super({...e,name:"stampEditor"});_(this,ct);_(this,Rt,null);_(this,de,null);_(this,hr,null);_(this,_n,null);_(this,lr,null);_(this,gh,"");_(this,Ei,null);_(this,ki,null);_(this,bs,!1);_(this,ph,!1);m(this,_n,e.bitmapUrl),m(this,lr,e.bitmapFile)}static initialize(e,s){Ot.initialize(e,s)}static get supportedTypes(){return nt(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(s=>`image/${s}`))}static get supportedTypesStr(){return nt(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(e){return this.supportedTypes.includes(e)}static paste(e,s){s.pasteEditor(et.STAMP,{bitmapFile:e.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1),super.altTextFinish()}get telemetryFinalData(){var e;return{type:"stamp",hasAltText:!!((e=this.altTextData)!=null&&e.altText)}}static computeTelemetryFinalData(e){const s=e.get("hasAltText");return{hasAltText:s.get(!0)??0,hasNoAltText:s.get(!1)??0}}async mlGuessAltText(e=null,s=!0){if(this.hasAltTextData())return null;const{mlManager:i}=this._uiManager;if(!i)throw new Error("No ML.");if(!await i.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:n,width:r,height:o}=e||this.copyCanvas(null,null,!0).imageData,h=await i.guess({name:"altText",request:{data:n,width:r,height:o,channels:n.length/(r*o)}});if(!h)throw new Error("No response from the AI service.");if(h.error)throw new Error("Error from the AI service.");if(h.cancel)return null;if(!h.output)throw new Error("No valid response from the AI service.");const c=h.output;return await this.setGuessedAltText(c),s&&!this.hasAltTextData()&&(this.altTextData={alt:c,decorative:!1}),c}remove(){var e;l(this,de)&&(m(this,Rt,null),this._uiManager.imageManager.deleteId(l(this,de)),(e=l(this,Ei))==null||e.remove(),m(this,Ei,null),l(this,ki)&&(clearTimeout(l(this,ki)),m(this,ki,null))),super.remove()}rebuild(){if(!this.parent){l(this,de)&&w(this,ct,tf).call(this);return}super.rebuild(),this.div!==null&&(l(this,de)&&l(this,Ei)===null&&w(this,ct,tf).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(e){this._isDraggable=!0,e&&this.div.focus()}isEmpty(){return!(l(this,hr)||l(this,Rt)||l(this,_n)||l(this,lr)||l(this,de))}get isResizable(){return!0}render(){if(this.div)return this.div;let e,s;if(this.width&&(e=this.x,s=this.y),super.render(),this.div.hidden=!0,this.div.setAttribute("role","figure"),this.addAltTextButton(),l(this,Rt)?w(this,ct,Bp).call(this):w(this,ct,tf).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,ki)!==null&&clearTimeout(l(this,ki)),m(this,ki,setTimeout(()=>{m(this,ki,null),w(this,ct,Hp).call(this)},200))}copyCanvas(e,s,i=!1){var g;e||(e=224);const{width:n,height:r}=l(this,Rt),o=new vg;let h=l(this,Rt),c=n,u=r,d=null;if(s){if(n>s||r>s){const O=Math.min(s/n,s/r);c=Math.floor(n*O),u=Math.floor(r*O)}d=document.createElement("canvas");const p=d.width=Math.ceil(c*o.sx),b=d.height=Math.ceil(u*o.sy);l(this,bs)||(h=w(this,ct,ef).call(this,p,b));const y=d.getContext("2d");y.filter=this._uiManager.hcmFilter;let v="white",x="#cfcfd8";this._uiManager.hcmFilter!=="none"?x="black":(g=window.matchMedia)!=null&&g.call(window,"(prefers-color-scheme: dark)").matches&&(v="#8f8f9d",x="#42414d");const C=15,S=C*o.sx,A=C*o.sy,k=new OffscreenCanvas(S*2,A*2),P=k.getContext("2d");P.fillStyle=v,P.fillRect(0,0,S*2,A*2),P.fillStyle=x,P.fillRect(0,0,S,A),P.fillRect(S,A,S,A),y.fillStyle=y.createPattern(k,"repeat"),y.fillRect(0,0,p,b),y.drawImage(h,0,0,h.width,h.height,0,0,p,b)}let f=null;if(i){let p,b;if(o.symmetric&&h.width<e&&h.height<e)p=h.width,b=h.height;else if(h=l(this,Rt),n>e||r>e){const x=Math.min(e/n,e/r);p=Math.floor(n*x),b=Math.floor(r*x),l(this,bs)||(h=w(this,ct,ef).call(this,p,b))}const v=new OffscreenCanvas(p,b).getContext("2d",{willReadFrequently:!0});v.drawImage(h,0,0,h.width,h.height,0,0,p,b),f={width:p,height:b,data:v.getImageData(0,0,p,b).data}}return{canvas:d,width:c,height:u,imageData:f}}getImageForAltText(){return l(this,Ei)}static async deserialize(e,s,i){var b;let n=null;if(e instanceof Ub){const{data:{rect:y,rotation:v,id:x,structParent:C,popupRef:S},container:A,parent:{page:{pageNumber:k}}}=e,P=A.querySelector("canvas"),O=i.imageManager.getFromCanvas(A.id,P);P.remove();const R=((b=await s._structTree.getAriaAttributes(`${fg}${x}`))==null?void 0:b.get("aria-label"))||"";n=e={annotationType:et.STAMP,bitmapId:O.id,bitmap:O.bitmap,pageIndex:k-1,rect:y.slice(0),rotation:v,id:x,deleted:!1,accessibilityData:{decorative:!1,altText:R},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,Rt,h)):m(r,_n,c),m(r,bs,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,ph,!!n),r}serialize(e=!1,s=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const i={annotationType:et.STAMP,bitmapId:l(this,de),pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:l(this,bs),structTreeParentId:this._structTreeParentId};if(e)return i.bitmapUrl=w(this,ct,sf).call(this,!0),i.accessibilityData=this.serializeAltText(!0),i;const{decorative:n,altText:r}=this.serializeAltText(!1);if(!n&&r&&(i.accessibilityData={type:"Figure",alt:r}),this.annotationElementId){const h=w(this,ct,Sy).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,bs)?(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,sf).call(this,!1);else if(l(this,bs)){const h=s.stamps.get(l(this,de));o>h.area&&(h.area=o,h.serialized.bitmap.close(),h.serialized.bitmap=w(this,ct,sf).call(this,!1))}return i}renderAnnotationElement(e){return e.updateEdited({rect:this.getRect(0,0)}),null}};Rt=new WeakMap,de=new WeakMap,hr=new WeakMap,_n=new WeakMap,lr=new WeakMap,gh=new WeakMap,Ei=new WeakMap,ki=new WeakMap,bs=new WeakMap,ph=new WeakMap,ct=new WeakSet,Hc=function(e,s=!1){if(!e){this.remove();return}m(this,Rt,e.bitmap),s||(m(this,de,e.id),m(this,bs,e.isSvg)),e.file&&m(this,gh,e.file.name),w(this,ct,Bp).call(this)},zc=function(){if(m(this,hr,null),this._uiManager.enableWaiting(!1),!!l(this,Ei)){if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Rt)){this._editToolbar.hide(),this._uiManager.editAltText(this,!0);return}if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&l(this,Rt)){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}},tf=function(){if(l(this,de)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(l(this,de)).then(i=>w(this,ct,Hc).call(this,i,!0)).finally(()=>w(this,ct,zc).call(this));return}if(l(this,_n)){const i=l(this,_n);m(this,_n,null),this._uiManager.enableWaiting(!0),m(this,hr,this._uiManager.imageManager.getFromUrl(i).then(n=>w(this,ct,Hc).call(this,n)).finally(()=>w(this,ct,zc).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,Hc).call(this,n)).finally(()=>w(this,ct,zc).call(this)));return}const e=document.createElement("input");e.type="file",e.accept=Tc.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,Hc).call(this,n)}i()},{signal:s}),e.addEventListener("cancel",()=>{this.remove(),i()},{signal:s})}).finally(()=>w(this,ct,zc).call(this))),e.click()},Bp=function(){var d;const{div:e}=this;let{width:s,height:i}=l(this,Rt);const[n,r]=this.pageDimensions,o=.75;if(this.width)s=this.width*n,i=this.height*r;else if(s>o*n||i>o*r){const f=Math.min(o*n/s,o*r/i);s*=f,i*=f}const[h,c]=this.parentDimensions;this.setDims(s*h/n,i*c/r),this._uiManager.enableWaiting(!1);const u=m(this,Ei,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,Hp).call(this),l(this,ph)||(this.parent.addUndoableEditor(this),m(this,ph,!0)),this._reportTelemetry({action:"inserted_image"}),l(this,gh)&&u.setAttribute("aria-label",l(this,gh))},ef=function(e,s){const{width:i,height:n}=l(this,Rt);let r=i,o=n,h=l(this,Rt);for(;r>2*e||o>2*s;){const c=r,u=o;r>2*e&&(r=r>=16384?Math.floor(r/2)-1:Math.ceil(r/2)),o>2*s&&(o=o>=16384?Math.floor(o/2)-1:Math.ceil(o/2));const d=new OffscreenCanvas(r,o);d.getContext("2d").drawImage(h,0,0,c,u,0,0,r,o),h=d.transferToImageBitmap()}return h},Hp=function(){const[e,s]=this.parentDimensions,{width:i,height:n}=this,r=new vg,o=Math.ceil(i*e*r.sx),h=Math.ceil(n*s*r.sy),c=l(this,Ei);if(!c||c.width===o&&c.height===h)return;c.width=o,c.height=h;const u=l(this,bs)?l(this,Rt):w(this,ct,ef).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)},sf=function(e){if(e){if(l(this,bs)){const n=this._uiManager.imageManager.getSvgUrl(l(this,de));if(n)return n}const s=document.createElement("canvas");return{width:s.width,height:s.height}=l(this,Rt),s.getContext("2d").drawImage(l(this,Rt),0,0),s.toDataURL()}if(l(this,bs)){const[s,i]=this.pageDimensions,n=Math.round(this.width*s*Ln.PDF_TO_CSS_UNITS),r=Math.round(this.height*i*Ln.PDF_TO_CSS_UNITS),o=new OffscreenCanvas(n,r);return o.getContext("2d").drawImage(l(this,Rt),0,0,l(this,Rt).width,l(this,Rt).height,0,0,n,r),o.transferToImageBitmap()}return structuredClone(l(this,Rt))},Sy=function(e){var o;const{pageIndex:s,accessibilityData:{altText:i}}=this._initialData,n=e.pageIndex===s,r=(((o=e.accessibilityData)==null?void 0:o.alt)||"")===i;return{isSame:!this._hasBeenMoved&&!this._hasBeenResized&&n&&r,isSameAltText:r}},q(Tc,"_type","stamp"),q(Tc,"_editorType",et.STAMP);let zg=Tc;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}){_(this,Et);_(this,Bo);_(this,mh,!1);_(this,Mi,null);_(this,cr,null);_(this,wn,null);_(this,Os,new Map);_(this,ur,!1);_(this,bh,!1);_(this,Ho,!1);_(this,ti,null);_(this,xn,null);_(this,Ce,null);_(this,Sn,null);_(this,W);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,W,t),this.pageIndex=e,this.div=s,m(this,Bo,n),m(this,Mi,r),this.viewport=c,m(this,Ce,h),this.drawLayer=o,this._structTree=i,l(this,W).addLayer(this)}get isEmpty(){return l(this,Os).size===0}get isInvisible(){return this.isEmpty&&l(this,W).getMode()===et.NONE}updateToolbar(t){l(this,W).updateToolbar(t)}updateMode(t=l(this,W).getMode()){switch(w(this,Et,nf).call(this),t){case et.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case et.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case et.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,W).setEditingState(t)}addCommands(t){l(this,W).addCommands(t)}cleanUndoStack(t){l(this,W).cleanUndoStack(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){var e;(e=l(this,Mi))==null||e.div.classList.toggle("disabled",!t)}async enable(){m(this,Ho,!0),this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const s of l(this,Os).values())s.enableEditing(),s.show(!0),s.annotationElementId&&(l(this,W).removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!l(this,Mi)){m(this,Ho,!1);return}const e=l(this,Mi).getEditableAnnotations();for(const s of e){if(s.hide(),l(this,W).isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;const i=await this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}m(this,Ho,!1)}disable(){var i;m(this,bh,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,e=new Map;for(const n of l(this,Os).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,Mi)){const n=l(this,Mi).getEditableAnnotations();for(const r of n){const{id:o}=r.data;if(l(this,W).isDeletedAnnotationElement(o))continue;let h=e.get(o);if(h){h.resetAnnotationElement(r),h.show(!1),r.show();continue}h=t.get(o),h&&(l(this,W).addChangedExistingAnnotation(h),h.renderAnnotationElement(r)&&h.show(!1)),r.show()}}w(this,Et,nf).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,bh,!1)}getEditableAnnotation(t){var e;return((e=l(this,Mi))==null?void 0:e.getEditableAnnotation(t))||null}setActiveEditor(t){l(this,W).getActive()!==t&&l(this,W).setActiveEditor(t)}enableTextSelection(){var t;if(this.div.tabIndex=-1,(t=l(this,Ce))!=null&&t.div&&!l(this,Sn)){m(this,Sn,new AbortController);const e=l(this,W).combinedSignal(l(this,Sn));l(this,Ce).div.addEventListener("pointerdown",w(this,Et,Cy).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,Sn)&&(l(this,Sn).abort(),m(this,Sn,null),l(this,Ce).div.classList.remove("highlighting"))}enableClick(){if(l(this,cr))return;m(this,cr,new AbortController);const t=l(this,W).combinedSignal(l(this,cr));this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t});const e=this.pointerup.bind(this);this.div.addEventListener("pointerup",e,{signal:t}),this.div.addEventListener("pointercancel",e,{signal:t})}disableClick(){var t;(t=l(this,cr))==null||t.abort(),m(this,cr,null)}attach(t){l(this,Os).set(t.id,t);const{annotationElementId:e}=t;e&&l(this,W).isDeletedAnnotationElement(e)&&l(this,W).removeDeletedAnnotationElement(t)}detach(t){var e;l(this,Os).delete(t.id),(e=l(this,Bo))==null||e.removePointerInTextLayer(t.contentDiv),!l(this,bh)&&t.annotationElementId&&l(this,W).addDeletedAnnotationElement(t)}remove(t){this.detach(t),l(this,W).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){var e;t.parent!==this&&(t.parent&&t.annotationElementId&&(l(this,W).addDeletedAnnotationElement(t.annotationElementId),Ot.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),(e=t.parent)==null||e.detach(t),t.setParent(this),t.div&&t.isAttachedToDOM&&(t.div.remove(),this.div.append(t.div)))}add(t){if(!(t.parent===this&&t.isAttachedToDOM)){if(this.changeParent(t),l(this,W).addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!l(this,Ho)),l(this,W).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var s;if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!l(this,wn)&&(t._focusEventsAllowed=!1,m(this,wn,setTimeout(()=>{m(this,wn,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:l(this,W)._signal}),e.focus())},0))),t._structTreeParentId=(s=l(this,Bo))==null?void 0:s.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){t.needsToBeRebuilt()?(t.parent||(t.parent=this),t.rebuild(),t.show()):this.add(t)}addUndoableEditor(t){const e=()=>t._uiManager.rebuild(t),s=()=>{t.remove()};this.addCommands({cmd:e,undo:s,mustExec:!1})}getNextId(){return l(this,W).getId()}combinedSignal(t){return l(this,W).combinedSignal(t)}canCreateNewEmptyEditor(){var t;return(t=l(this,Et,Ri))==null?void 0:t.canCreateNewEmptyEditor()}pasteEditor(t,e){l(this,W).updateToolbar(t),l(this,W).updateMode(t);const{offsetX:s,offsetY:i}=w(this,Et,Gp).call(this),n=this.getNextId(),r=w(this,Et,zp).call(this,{parent:this,id:n,x:s,y:i,uiManager:l(this,W),isCentered:!0,...e});r&&this.add(r)}async deserialize(t){var e;return await((e=l(ei,dr).get(t.annotationType??t.annotationEditorType))==null?void 0:e.deserialize(t,this,l(this,W)))||null}createAndAddNewEditor(t,e,s={}){const i=this.getNextId(),n=w(this,Et,zp).call(this,{parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:l(this,W),isCentered:e,...s});return n&&this.add(n),n}addNewEditor(){this.createAndAddNewEditor(w(this,Et,Gp).call(this),!0)}setSelected(t){l(this,W).setSelected(t)}toggleSelected(t){l(this,W).toggleSelected(t)}unselect(t){l(this,W).unselect(t)}pointerup(t){var s;const{isMac:e}=Re.platform;if(!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&l(this,ur)&&(m(this,ur,!1),!((s=l(this,Et,Ri))!=null&&s.isDrawer&&l(this,Et,Ri).supportMultipleDrawings))){if(!l(this,mh)){m(this,mh,!0);return}if(l(this,W).getMode()===et.STAMP){l(this,W).unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){var i;if(l(this,W).getMode()===et.HIGHLIGHT&&this.enableTextSelection(),l(this,ur)){m(this,ur,!1);return}const{isMac:e}=Re.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;if(m(this,ur,!0),(i=l(this,Et,Ri))!=null&&i.isDrawer){this.startDrawingSession(t);return}const s=l(this,W).getActive();m(this,mh,!s||s.isEmpty())}startDrawingSession(t){if(this.div.focus(),l(this,ti)){l(this,Et,Ri).startDrawing(this,l(this,W),!1,t);return}l(this,W).setCurrentDrawingSession(this),m(this,ti,new AbortController);const e=l(this,W).combinedSignal(l(this,ti));this.div.addEventListener("blur",({relatedTarget:s})=>{s&&!this.div.contains(s)&&(m(this,xn,null),this.commitOrRemove())},{signal:e}),l(this,Et,Ri).startDrawing(this,l(this,W),!1,t)}pause(t){if(t){const{activeElement:e}=document;this.div.contains(e)&&m(this,xn,e);return}l(this,xn)&&setTimeout(()=>{var e;(e=l(this,xn))==null||e.focus(),m(this,xn,null)},0)}endDrawingSession(t=!1){return l(this,ti)?(l(this,W).setCurrentDrawingSession(null),l(this,ti).abort(),m(this,ti,null),m(this,xn,null),l(this,Et,Ri).endDrawing(t)):null}findNewParent(t,e,s){const i=l(this,W).findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}commitOrRemove(){return l(this,ti)?(this.endDrawingSession(),!0):!1}onScaleChanging(){l(this,ti)&&l(this,Et,Ri).onScaleChangingWhenDrawing(this)}destroy(){var t,e;this.commitOrRemove(),((t=l(this,W).getActive())==null?void 0:t.parent)===this&&(l(this,W).commitOrRemove(),l(this,W).setActiveEditor(null)),l(this,wn)&&(clearTimeout(l(this,wn)),m(this,wn,null));for(const s of l(this,Os).values())(e=l(this,Bo))==null||e.removePointerInTextLayer(s.contentDiv),s.setParent(null),s.isAttachedToDOM=!1,s.div.remove();this.div=null,l(this,Os).clear(),l(this,W).removeLayer(this)}render({viewport:t}){this.viewport=t,Pr(this.div,t);for(const e of l(this,W).getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){l(this,W).commitOrRemove(),w(this,Et,nf).call(this);const e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,Pr(this.div,{rotation:s}),e!==s)for(const i of l(this,Os).values())i.rotate(s)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return l(this,W).viewParameters.realScale}};Bo=new WeakMap,mh=new WeakMap,Mi=new WeakMap,cr=new WeakMap,wn=new WeakMap,Os=new WeakMap,ur=new WeakMap,bh=new WeakMap,Ho=new WeakMap,ti=new WeakMap,xn=new WeakMap,Ce=new WeakMap,Sn=new WeakMap,W=new WeakMap,dr=new WeakMap,Et=new WeakSet,Cy=function(t){l(this,W).unselectAll();const{target:e}=t;if(e===l(this,Ce).div||(e.getAttribute("role")==="img"||e.classList.contains("endOfContent"))&&l(this,Ce).div.contains(e)){const{isMac:s}=Re.platform;if(t.button!==0||t.ctrlKey&&s)return;l(this,W).showAllEditors("highlight",!0,!0),l(this,Ce).div.classList.add("free"),this.toggleDrawing(),ad.startHighlighting(this,l(this,W).direction==="ltr",{target:l(this,Ce).div,x:t.x,y:t.y}),l(this,Ce).div.addEventListener("pointerup",()=>{l(this,Ce).div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:l(this,W)._signal}),t.preventDefault()}},Ri=function(){return l(ei,dr).get(l(this,W).getMode())},zp=function(t){const e=l(this,Et,Ri);return e?new e.prototype.constructor(t):null},Gp=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}},nf=function(){for(const t of l(this,Os).values())t.isEmpty()&&t.remove()},q(ei,"_initialized",!1),_(ei,dr,new Map([Fg,Hg,zg,ad].map(t=>[t._editorType,t])));let Gg=ei;const Ae=class Ae{constructor({pageIndex:t}){_(this,Pi);_(this,si,null);_(this,Ec,0);_(this,Be,new Map);_(this,zo,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 nt(this,"_svgFactory",new Dg)}draw(t,e=!1,s=!1){const i=ze(this,Ec)._++,n=w(this,Pi,Vp).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,zo).set(i,o);const c=s?w(this,Pi,Ty).call(this,r,h):null,u=Ae._svgFactory.createElement("use");return n.append(u),u.setAttribute("href",`#${h}`),this.updateProperties(n,t),l(this,Be).set(i,n),{id:i,clipPathId:`url(#${c})`}}drawOutline(t,e){const s=ze(this,Ec)._++,i=w(this,Pi,Vp).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,zo).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,Pi,Xp).call(this,o,s),i&&w(h=Ae,Ed,Ay).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,Pi,Xp).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,zo).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,zo).clear()}};si=new WeakMap,Ec=new WeakMap,Be=new WeakMap,zo=new WeakMap,Ed=new WeakSet,Ay=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}%`},Pi=new WeakSet,Vp=function(){const t=Ae._svgFactory.create(1,1,!0);return l(this,si).append(t),t.setAttribute("aria-hidden",!0),t},Ty=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},Xp=function(t,e){for(const[s,i]of Object.entries(e))i===null?t.removeAttribute(s):t.setAttribute(s,i)},_(Ae,Ed);let Vg=Ae;globalThis.pdfjsTestingUtils={HighlightOutliner:Ig},Q.AbortException,Q.AnnotationEditorLayer,Q.AnnotationEditorParamsType,Q.AnnotationEditorType,Q.AnnotationEditorUIManager,Q.AnnotationLayer,Q.AnnotationMode,Q.ColorPicker,Q.DOMSVGFactory,Q.DrawLayer,Q.FeatureTest;var cC=Q.GlobalWorkerOptions;Q.ImageKind,Q.InvalidPDFException,Q.MissingPDFException,Q.OPS,Q.OutputScale,Q.PDFDataRangeTransport,Q.PDFDateString,Q.PDFWorker,Q.PasswordResponses,Q.PermissionFlag,Q.PixelsPerInch,Q.RenderingCancelledException,Q.TextLayer,Q.TouchManager,Q.UnexpectedResponseException,Q.Util,Q.VerbosityLevel,Q.XfaLayer,Q.build,Q.createValidAbsoluteUrl,Q.fetchData;var uC=Q.getDocument;Q.getFilenameFromUrl,Q.getPdfFilenameFromUrl,Q.getXfaPageViewport,Q.isDataScheme,Q.isPdfFile,Q.noContextMenu,Q.normalizeUnicode,Q.setLayerDimensions,Q.shadow,Q.stopEvent,Q.version;const dC={"pdfjs-dist":"4.10.38"};function fC(a){return new Promise((t,e)=>{const s=new FileReader;s.addEventListener("load",()=>t(s.result)),s.addEventListener("error",e),s.readAsDataURL(a)})}const gC=dC["pdfjs-dist"].replace("^","");cC.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${gC}/pdf.worker.min.mjs`;async function pC(a){const t="data:application/pdf;base64,",e=await fC(a);if(typeof e=="string")return window.atob(e.slice(t.length))}function mC(a,t){return uC({data:a,password:t}).promise}const $e=new Map;function bC(a){const t=new $f(a);return $e.set(a,t),t}function vC(a,t){const e=Date.now();return{PDFId:`${a.name}-${e}`,name:a.name.replace(/.pdf/,""),updateDate:e,PDFBase64:t}}function yC(a,t){const e=a.getViewport({scale:t}),s=document.createElement("canvas"),i=s.getContext("2d"),n=ax()/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 _C({src:a},t,e){if(!a||!e)return null;const{objects:s,options:i}=await qw(a),n=s.filter(o=>o!==null),r=uw.groupSVGElements(n,i);return n.forEach(o=>{o.stroke=e}),r.hoverCursor="pointer",r.stroke=`${e}-${t}`,r}function wC(a,t){if(!$e.get(a))return;const s=1/3,i=kC(t,s);qb(a,i,s)}async function xC(a,t){const e=await lx(t),s=Date.now(),n={PDFId:`${t.name}${s}`,name:t.name.replace(/.png|.jpg|.jpeg/,""),updateDate:s,PDFBase64:e};return $b(a,{url:e}),{...n,pages:1}}async function $b(a,{url:t,scale:e=.5}){if(!$e.get(a))return;const i=await be.fromURL(t);i.scale(e),qb(a,i,e)}function qb(a,t,e){const s=$e.get(a);s&&(s.setWidth(t.width*e),s.setHeight(t.height*e),s.backgroundImage=t,s.renderAll())}function SC(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 CC(a,t,e){!e||!a||(e.scale(1/t),SC(a,e))}function AC(a,t){if(!a)return;const e=a._cornerSize||6;a.borderScaleFactor=1/t,a.cornerSize=e*(1/t),a.touchCornerSize=e*4*(1/t),a.setCoords()}function TC(a){const t=$e.get(a);t&&(t.discardActiveObject(),t.renderAll())}function EC(a){const t=$e.get(a);t&&(t.clear(),$e.delete(a))}function kC(a,t){return new be(a,{scaleX:t,scaleY:t})}function Xg(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 Kb(a,t,e){var n;const s=a.type,i={"application/pdf":MC,"image/png":Jb,"image/jpeg":Jb};return((n=i[s])==null?void 0:n.call(i,a,t,e))??Promise.reject(new Error(`Unsupported ${s} file type.`))}async function MC(a,t,e){const s=await pC(a);if(!s)return;const i=vC(a,s);try{const n=await Qb({page:1,PDFBase64:s,scale:.8,password:t},e);return{...i,pages:n}}catch(n){return Promise.reject(n)}}async function Qb({page:a,PDFBase64:t,scale:e,password:s},i){try{const n=await mC(t,s),r=await n.getPage(a),{renderTask:o,canvas:h}=yC(r,e);return o.promise.then(()=>(i&&wC(i,h),n.numPages))}catch(n){return Promise.reject(n)}}async function Jb(a,t,e){if(e)return await xC(e,a)}async function PC(a,t){const e=$e.get(a);if(!e)return;const s=e==null?void 0:e.getActiveObject();if(!s)return;const i=await s.clone(Py);i instanceof ys?i.forEachObject(n=>{e.add(n),t(e,n)}):(e.add(i),t(e,i)),Xg(i,{x:-.1,y:-.1}),e.setActiveObject(i)}function OC(a){const t=$e.get(a);if(!t)return;const e=t.getActiveObject();e&&(e instanceof ys?(e.forEachObject(s=>{t.remove(s)}),t.discardActiveObject()):t.remove(e))}function Zb(a){const{id:t="",selectionOptions:e,pointerDown:s,pointerMove:i,pointerUp:n,selectionCreated:r,selectionCleared:o}=a||{};let h=null,c=null,u=1,d={...My};function f(){if(!t||$e.has(t))return;const D=bC(t);return D.on("selection:created",I=>{if(r==null||r(I),I.selected.length<=1)return;const N=D.getActiveObject();N&&(c=N,e!=null&&e.value&&c.set(e.value),c._cornerSize=c.cornerSize,A(u))}),D.on("selection:cleared",I=>{o==null||o(I),P(D)}),s&&D.on("mouse:down",s),i&&D.on("mouse:move",i),n&&D.on("mouse:up",n),D}function g(D,I){return Kb(D,I,t)}function p(D){return Qb(D,t)}function b({url:D,scale:I=.5}){return $b(t,{url:D,scale:I})}async function y(D,I,N){const Y=$e.get(t);if(!Y)return;const L=await be.fromURL(D,{},{...rf,...I});Xg(L,N),Y.add(L),x(Y,L),Y.setActiveObject(L)}function v(D,I,N){const Y=$e.get(t);if(!Y)return;const L=new me(D,{...Ey,...I});Xg(L,N),Y.add(L),x(Y,L),Y.setActiveObject(L)}function x(D,I){I.on("selected",N=>C({canvas:D,target:N.target})),I.on("modified",N=>C({canvas:D,target:N.target})),I.on("scaling",()=>P(D)),I.on("moving",()=>P(D)),I.on("rotating",()=>P(D)),I._cornerSize=I._cornerSize??I.cornerSize}async function C({canvas:D,target:I,stroke:N=d.stroke,uuid:Y=Date.now()}){if(D.getActiveObjects().length>1||(h==null?void 0:h.stroke)===`${N}-${Y}`)return;const B=await _C(d,Y,N);P(D),h=B,c=I,S(D,I,Y),A(u,!0),B&&D.add(B)}function S(D,I,N){h&&(h.on("selected",()=>{D.remove(I),P(D)}),h.on("mouseover",()=>{C({canvas:D,target:I,stroke:d.hoverStroke,uuid:N})}),h.on("mouseout",()=>{C({canvas:D,target:I,stroke:d.stroke,uuid:N})}))}function A(D,I=!1){const N=$e.get(t);u=D,N&&(AC(c,D),CC(c,D,h),!I&&N.renderAll())}function k(D){if(!D)return;d={...d,...D};const I=$e.get(t);!h||!c||!I||C({target:c,canvas:I})}function P(D){c=null,h&&(D.remove(h),h=null)}function O(){TC(t)}function R(){EC(t)}function F(){return PC(t,x)}function j(){OC(t)}return{createCanvas:f,loadFile:g,specifyPage:p,renderImage:b,addFabric:y,addTextFabric:v,clearActive:O,deleteCanvas:R,scaleFabric:A,setCloseSvgOptions:k,copyActiveFabric:F,deleteActiveFabric:j}}function DC(a){let t=0;const e=hx(()=>{t!==window.innerWidth&&(t=window.innerWidth,a())});K.onMounted(()=>{window.addEventListener("resize",e)}),K.onBeforeUnmount(()=>{window.removeEventListener("resize",e)})}const RC=K.defineComponent({__name:"pdf-canvas",props:{file:{},page:{default:1},canvasId:{default:"PDF-canvas"},fileZoom:{default:1},fileScale:{default:1},canvasScale:{default:1},canvasClass:{default:""},isDrop:{type:Boolean,default:!1},password:{},dropTextOptions:{},dropImageOptions:{},selectionOptions:{},closeSvgOptions:{},manualReload:{type:Boolean},onDestroy:{type:Function,default:K.onBeforeUnmount}},emits:["loaded","reload","pointerDown","pointerMove","pointerUp","selectionCreated","selectionCleared"],setup(a,{expose:t,emit:e}){const s=a,i=e,{onDestroy:n}=s,r=K.ref(null),o=`${s.canvasId}-${s.page-1}`,h=K.computed(()=>s.fileZoom*s.canvasScale),c=K.computed(()=>({...ky,...s.selectionOptions})),{createCanvas:u,specifyPage:d,addFabric:f,addTextFabric:g,renderImage:p,clearActive:b,deleteCanvas:y,scaleFabric:v,setCloseSvgOptions:x,copyActiveFabric:C,deleteActiveFabric:S}=Zb({id:o,selectionOptions:c,pointerDown:F=>i("pointerDown",F),pointerMove:F=>i("pointerMove",F),pointerUp:F=>i("pointerUp",F),selectionCreated:F=>i("selectionCreated",F),selectionCleared:F=>i("selectionCleared",F)});A(),DC(R);async function A(){const{file:F,page:j,fileScale:D}=s;window.requestAnimationFrame(async()=>{if(await K.nextTick(),u(),F.PDFBase64.startsWith("data:image")||F.canvas){const{canvas:I}=F,N=I?7:3,Y=I!=null&&I.length?I[j-1]:F.PDFBase64;p({url:Y,scale:D/N}),i("loaded");return}await d({page:j,PDFBase64:F.PDFBase64,scale:D,password:s.password}),i("loaded")})}function k(F){if(!s.isDrop||!F.dataTransfer)return;const{dataTransfer:j,offsetX:D,offsetY:I}=F,N=j.getData("text/plain"),Y=j.getData("text/uri-list"),L=j.getData("custom/offset"),B=L?JSON.parse(L):null,Z={top:I,left:D},kt={x:(B==null?void 0:B.offsetX)??0,y:(B==null?void 0:B.offsetY)??0};Y?P(Y,Z,kt):N&&O(N,Z,kt)}function P(F,j,D){f(F,{...s.dropImageOptions,...j},D)}function O(F,j,D){g(F,{...s.dropTextOptions,...j},D)}function R(){s.manualReload||A(),i("reload")}return K.watch([()=>s.fileScale,()=>s.page,()=>s.file,()=>s.password],R),K.watch(h,F=>v(F),{immediate:!0}),K.watch(()=>s.closeSvgOptions,x,{immediate:!0}),n(y),t({reload:A,addImage:P,addText:O,clearActive:b,deleteCanvas:y,copyActiveFabric:C,deleteActiveFabric:S,canvasRef:r}),(F,j)=>(K.openBlock(),K.createElementBlock("div",{style:K.normalizeStyle({transform:`scale(${h.value})`}),onDragover:j[0]||(j[0]=K.withModifiers(()=>{},["prevent"])),onDragenter:j[1]||(j[1]=K.withModifiers(()=>{},["prevent"])),onDrop:K.withModifiers(k,["stop","prevent"])},[K.createElementVNode("canvas",{id:o,ref_key:"canvasRef",ref:r,class:K.normalizeClass(F.canvasClass)},null,2)],36))}});ot.default=RC,ot.loadFile=Kb,ot.useFabric=Zb,Object.defineProperties(ot,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});